0

我不是编码员,但一直在尝试修改 Chris Gilligan 的脚本,该脚本可自动在 Virtualmin(类似于 cPanel 的 Webmin 模块)服务器上安装 WordPress。

Chris 的脚本在他的网站上进行了详细描述,并且效果非常好。可以从这里下载查看

我已经阅读了 bit.ly/1dYlL81 上的 Virtualmin 脚本指南以及有关 perl 的各种教程,但我没有得到任何结果。

我还问过脚本作者克里斯本人,他建议我在这里问,因为他也不知道如何实现这一点。

我想添加到脚本中的两件事与标准 WordPress wp-config.php 文件有关:

  1. Chris 的脚本不会生成随机键/盐,并保持文件的该部分完好无损,因此它看起来像:

    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');
    

如何修改脚本以将上述内容替换为http://api.wordpress.org/secret-key/1.1/salt的 WordPress 密钥/生成器网页的输出

  1. 该脚本将 MySQL 数据库表前缀保留为:

    $table_prefix  = 'wp_';
    

但我希望将其替换为稍微随机的 'wp_???_' 其中 ??? 是一个随机的三字符字母数字字符串。为了实现这一目标,对脚本进行必要的修改是什么?

4

1 回答 1

0

Just for your information this is not tested code so don't hold it against me but here is a thought on how you may be able to achieve what you are looking for.

After line 220 you could try to do something like this

if ($l =~ /^define\('AUTH_KEY',/) { $l = ""; }
if ($l =~ /^define\('SECURE_AUTH_KEY',/) { $l = ""; }
if ($l =~ /^define\('LOGGED_IN_KEY',/) { $l = ""; }
if ($l =~ /^define\('NONCE_KEY',/) { $l = ""; }
if ($l =~ /^define\('AUTH_SALT',/) { $l = ""; }
if ($l =~ /^define\('SECURE_AUTH_SALT',/) { $l = ""; }
if ($l =~ /^define\('LOGGED_IN_SALT',/) { $l = ""; }
if ($l =~ /^define\('NONCE_SALT',/) {  
  use LWP::Simple;
  my $salt_info = get('http://api.wordpress.org/secret-key/1.1/salt')
    or die 'Unable to get salt info';
  $l = $salt_info;
}                                      
if ($l =~ /^\$table_prefix/) {
  my @chars = ('0'..'9', 'A'..'Z', 'a'..'z');
  my $len = 3;

  my $wp_random;
  while ($len--) {
          $wp_random .= $chars[rand @chars];
  };                                    
  $wp_db_prefix = "wp_" . $wp_random . "_";
  $l = "\$table_prefix  = '".$wp_db_prefix."';";
}

You could also do something like this to ensure that you may be able to pull information prior to making the changes in a test.pl file and run perl test.pl

#!/usr/bin/perl  
print "LWP Version: ". LWP->VERSION;     

print "\n\nSalt Info: \n";
use LWP::Simple;
my $salt_info = get('http://api.wordpress.org/secret-key/1.1/salt')
        or die 'Unable to get salt info';
print $salt_info;

my @chars = ('0'..'9', 'A'..'Z', 'a'..'z');
my $len = 3;

my $wp_random;
while ($len--) {
        $wp_random .= $chars[rand @chars];
};

print "\n\nRandom String: $wp_random \n\n";

My old answer did not consider removing the old values of the salt keys as well as if statement for the table_prefix and rndStr not functioning properly.

if ($l =~ /^define\('DB_COLLATE',/) { 
use strict;
use warnings;
use LWP::Simple;

  my $salt_info = get('http://api.wordpress.org/secret-key/1.1/salt') or die 'Unable to get salt info';
    $l = "('DB_COLLATE', '');\n\n" . $salt_info;
}

if ($l =~ /^\\$table_prefix/) {   
     $wp_random = rndStr 3, 'a'..'z', 0..9;
     $wp_db_prefix = "wp_" . $wp_random . "_";
     $l = "\\$table_prefix  = '".
             $wp_db_prefix."';";

  }  
于 2014-03-30T08:42:01.583 回答