我做了很多研究来找到实现这一点的方法,但我做得不够。我正在寻找一种方法,用随机生成的盐代替所有的'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');
这个问题(这里)接近于我想要的,但希望对标准的wp-config-sample.php进行编辑。我不知道是删除整个部分并替换它更容易,还是只是在每一行上进行某种查找和替换。
更新:
这是我当前脚本的一个代码示例(以及尝试合并下面的答案..)
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.
如有任何帮助,我们将不胜感激!
谢谢。
尝试:
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
作为外部命令来获取salts,然后使用flip-flop
逐行解析输入文件,将defines
的部分替换为具有随机salts的部分。
它产生(部分输出):
...
/** 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_';
...