在wp-config-sample.php上生成Perl Salt

时间:2014-01-28 21:49:47

标签: wordpress perl bash shell sed

我已经做了很多研究以找到一种方法来做到这一点,但我很快就会出现。我正在寻找一种用随机生成的盐替换所有'put your unique phrase here'的方法。

以下是我需要编辑的配置部分:

define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

这个问题(here)接近我想要的但是期望编辑标准的wp-config-sample.php。我不知道是否更容易删除整个部分并替换它,或者只是在每一行上进行某种查找和替换。

<小时/>

UPDATE:

以下是我当前脚本的代码示例(并尝试合并以下答案..)。

sub modify_configs {
    my $shell   = $_[0];
    my $dbname  = $_[1];
    my $dbuser  = $_[2];
    my $siteurl = $_[3];

    # modify wp-config.php
    print BOLD "Modifying configuration files...\n";
    chdir($local_dir);
    system('perl -pi -e "s/database_name_here/'.$dbname.'/g" wp-config-sample.php');
    system('perl -pi -e "s/username_here/'.$dbuser.'/g" wp-config-sample.php');
    system('perl -pi -e "s/password_here/'.$pass.'/g" wp-config-sample.php');
    my ($keysalts, $flipflop);
    `perl -ne 'BEGIN { $keysalts = qx(curl -sS https://api.wordpress.org/secret-key/1.1/salt) } if ( $flipflop = ( m/AUTH_KEY/ .. m/NONCE_SALT/ ) ) {if ( $flipflop =~ /E0$/ ) { printf qq|%s|, $keysalts; } next; } printf qq|%s|, $_;' wp-config-sample.php`;
    # rename('wp-config-sample.php', 'wp-config.php');
    ...
}

这失败了:

Use of uninitialized value $keysalts in concatenation (.) or string at ./gen.pl line 101, <MYFILE> line 3.
Use of uninitialized value $flipflop in concatenation (.) or string at ./gen.pl line 101, <MYFILE> line 3.
Use of uninitialized value $flipflop in concatenation (.) or string at ./gen.pl line 101, <MYFILE> line 3.
Use of uninitialized value $keysalts in concatenation (.) or string at ./gen.pl line 101, <MYFILE> line 3.
syntax error at -e line 1, near "{  ="
BEGIN not safe after errors--compilation aborted at -e line 1.

任何帮助都将不胜感激!

感谢。

1 个答案:

答案 0 :(得分:2)

尝试:

perl -ne '
    BEGIN { 
        $keysalts = qx(curl -sS https://api.wordpress.org/secret-key/1.1/salt) 
    } 
    if ( $flipflop = ( m/AUTH_KEY/ .. m/NONCE_SALT/ ) ) {
        if ( $flipflop =~ /E0$/ ) {
            printf qq|%s|, $keysalts;
        }
        next;
    }
    printf qq|%s|, $_;
' wp-config-sample.php

使用curl作为外部命令获取salt,然后使用flip-flop逐行解析输入文件,将defines的部分替换为具有随机盐的部分。

它产生(输出的一部分):

...
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         'CQVDYWT|G!9/ZXd>#}/MB>n?`enZrpx#h,,4/=ev/@4|>H(0vkDDd~Pp!+R-#!4-');
define('SECURE_AUTH_KEY',  'peCpNn5f6c=T$%]@=Lx}C_aQhp;.%aTgrrAyQE 1476!<e%5Ys)0Zab OZtAM7?V');
define('LOGGED_IN_KEY',    '.}$YwXKsx|c(k(xZ.Tk{eGMt]#cOM8g,7Z?H{UKQzK1KN8rsIVZuddkW21E{(+q$');
define('NONCE_KEY',        'h]>4cN[U+O>xcQ;H#C+2ZvmOK4oC)TY[|5e(EsT,n+~+aOd+|~e/PN5%N$:7c90/');
define('AUTH_SALT',        '1U@V&Fp-v&epA,lzws>GrB]MuG.6[Wdnb:n;FY8Kqn~`1~4_} 3D)o6PzGBeIm-)');
define('SECURE_AUTH_SALT', '2!.I5D<JCo+4UIh>h~3PM?;.]$67;y-t3jp;PzKBNjd(!*6&>6gteX$@fGp_-Q;N');
define('LOGGED_IN_SALT',   '%>|}J%O]W><VWQ#x:BAfMPT:2O|a|VeQE0vK:<.dCW5WW9U3=-1fm]{eg3O~N*al');
define('NONCE_SALT',       '-G:lv+cuSpClI!.^W[)WfcFN.#HSv 7bA:W*<+A^%<ApQ7DmC?A[uTu+jk0~%:of');

/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';
...