orcun adlı üyeden alıntı:
mesajı görüntüle
Alıntı
104
●23.964
#!/usr/bin/perl
#################################################################################################
## WP-Super-Cache installer
##
## Usage: $0 path/to/index.php
#################################################################################################
# TODO:
# - add .htaccess file so that it correctly works
if ($#ARGV < 0) {
print "Usage: $0 /home/user/path_to_installation/index.php\n";
exit;
}
use File::Copy;
use LWP;
my $supercacheinstall = $0;
my $ver="0.9.9";
my $supercacheurl="http://hgfix.net/shaun/wp-super-cache.$ver.zip";
# This is the PHP script that activates the plugin
my $activatesupercache = <<END;
<?php
include_once( dirname(__FILE__) . '/wp-load.php' );
include("wp-admin/includes/plugin.php");
if (is_plugin_active("wp-cache.php")) {
print "Already active\n";
} else {
if (activate_plugins("wp-super-cache/wp-cache.php")) {
print "Activated!\n";
} else {
print "Error Activating!\n";
}
}
require_once( dirname(__FILE__) . '/wp-content/plugins/wp-super-cache/wp-cache.php');
wp_cache_restore();
wp_cache_enable();
wp_cache_create_advanced_cache();
?>
END
my $htaccess=<<'END';
# WordPress SuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*s=.*
RewriteCond %{QUERY_STRING} !.*attachment_id=.*
RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*s=.*
RewriteCond %{QUERY_STRING} !.*wp-subscription-manager=.*
RewriteCond %{QUERY_STRING} !.*attachment_id=.*
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
END
# Variables that you should not need to change
my ($instdir,$wpconfig,$plugindir,$user,$pfft,$response,$add_cache);
my ($login,$pass,$uid,$gid);
my ($insturl,$dbname,$dbuser,$dbpass,$tableprefix,$wpoption,@wp_config);
my ($ps,$mysql,$scoreboard,$command);
my $ua = LWP::UserAgent->new;
# Grab the script that is set
my $index = shift;
my $add_cache = 1;
# Figure out where wp-config.php is and the base of the installation
$instdir = $index;
$instdir =~ s#index.php##s;
$wpconfig = $instdir."wp-config.php";
if ( -f "$instdir/wp-config.php") {
$wpconfig = $instdir."wp-config.php";
}
else {
print "Can not find the wp-config.php file! You are on your own!\n";
exit;
}
unless ( -f "$instdir/wp-load.php") {
$activatesupercache = <<END;
<?php
include_once( .'/wp-blog-header.php' );
include("wp-admin/includes/plugin.php");
if (is_plugin_active("wp-cache.php")) {
print "Already active\n";
} else {
if (activate_plugins("wp-super-cache/wp-cache.php")) {
print "Activated!\n";
} else {
print "Error Activating!\n";
}
}
require_once( dirname(__FILE__) . '/wp-content/plugins/wp-super-cache/wp-cache.php');
wp_cache_restore();
wp_cache_enable();
wp_cache_create_advanced_cache();
?>
END
}
$plugindir = $instdir."wp-content/plugins";
($pfft,$pfft,$user,$pfft) = split /\//, $instdir;
# Read in the configuration from wp-config.php
open WPCONFIG, "<", $wpconfig or die $1;
while ( <WPCONFIG> ) {
if (/DB_NAME/) {
($pfft,$pfft,$pfft,$dbname,$pfft)=split "'";
}
elsif (/DB_PASS/) {
($pfft,$pfft,$pfft,$dbpass,$pfft)=split "'";
}
elsif (/DB_USER/) {
($pfft,$pfft,$pfft,$dbuser,$pfft)=split "'";
}
elsif(/table_prefix/) {
($pfft,$tableprefix)=split "'";
}
elsif(/WP_CACHE/) {
$add_cache = undef;
}
push(@wp_config,$_);
}
close WPCONFIG or die $1;
$dbpass =~ s/([!&@|;~\)\(\>\<])/\\$1/g;
$wpoption=$tableprefix."options";
$insturl=`mysql -u $dbuser -p$dbpass $dbname --batch -e "SELECT option_value FROM $wpoption WHERE option_name like '%siteurl%'" | grep -v option_value`;
chomp($insturl);
$command = "ps aux | grep ^$user";
$ps =`$command`;
$command = "mysqladmin proc | grep $user"."_";
$mysql = `$command`;
$scorebaord = "";
#print "DBNAME: $dbname\nDBPASS: $dbpass\nDBUSER: $dbuser\nTABLE PREFIX: $tableprefix\n";
print "Wordpress installation at: $instdir\n";
print "Config file at: $wpconfig\n";
print "Plugin directory at: $plugindir\n";
print "Table prefix: $wpoption\n";
print "User: $user\n";
print "Installation URL: $insturl\n\n";
($login,$pass,$uid,$gid) = getpwnam($user);
# Unchattr chmod the index file
system "chattr -ai $index";
system "chmod 644 $index";
chdir($plugindir);
# Add a WP-Cache define line
copy("$wpconfig","$wpconfig.bak");
if ($add_cache) {
#print "Modifying $wpconfig file...";
open WPCONFIGW, ">","$wpconfig" or die $1;
foreach $line (@wp_config) {
if ($line =~ m/DB_NAME/) {
print WPCONFIGW "define ('WP_CACHE','true');\n";
}
print WPCONFIGW "$line";
}
close WPCONFIGW or die $1;
#print "done!\n";
}
system("wget -q http://downloads.wordpress.org/plugin/wp-super-cache.$ver.zip");
# Unzip the file
system("unzip -qq wp-super-cache.$ver");
# Remove the .zip file
unlink("wp-super-cache.$ver.zip");
# Open up and write the script to preform the installation
chdir($instdir);
open PHPFILE, ">", "$instdir/activatewpsupercache.php" or die $!;
print PHPFILE $activatesupercache;
close PHPFILE or die $!;
copy("$plugindir/wp-super-cache/wp-cache-config-sample.php","$instdir/wp-content/wp-cache-config.php");
#system("sed -i 's/$super_cache_enabled = false/$super_cache_enabled = true/g' wp-content/wp-cache-config.php");
#system("sed -i 's/$cache_enabled = false/$cache_enabled = true/g' wp-content/wp-cache-config.php");
# Chown the new folder
system("chown -R $user. $instdir/wp-content");
system("chown $user. -R $instdir");
system("chmod go-w -R $instdir/wp-content");
system("chown $user:nobody /home/$user/public_html");
# Run the script to activate the plugin
$response = $ua->get("$insturl/activatewpsupercache.php");
$response = $ua->get("$insturl");
if ($response->is_error) {
print "Unable to reach their domain! Something is up!\n";
exit;
}
print "Activating plugin... ";
$response = $ua->get("$insturl/activatewpsupercache.php");
if ($response->is_error) {
print "Unable to activate plugin! Received error code connecting to $insturl/activatewpsupercache.php!\n";
exit;
}
# Grab it again and check to see if the page is cached
print "Checking $insturl... ";
$response = $ua->get("$insturl");
if ($response->content =~ m/Cached page generated by WP-Super-Cache/) {
print "It works!\n";
print "=" x 60 . "\n";
print "PLEASE NOTE THAT THE .HTACCESS DIRECTIVES WHERE NOT YET PUT IN PLACE!\n";
print "=" x 60 . "\n";
print "If the installation worked you can add the following for the pages to be served from the cache\n";
print $htaccess;
print "\n\n";
print "Hello,\n\n";
print "A WordPress installation located at $insturl was causing some issues on the server that it was on. Instead of suspending the site, the plugin WP-Super-Cache was installed to greatly reduce the load that is caused by this particular installation. We determined that this was not in place by checking the .htaccess directives, so though you may already have had this plug-in it was not fully configured. Please let us know if you see any issues, or if you have any questions regarding this and we will be happy to assist!\n\n";
print "Here is why we were forced to take this action:\n";
}
else {
print "Did not work, check to see if there are any errors in the admin panel!";
exit;
}
# Remove the script that activates the plugin
unlink("$instdir/activatewpsupercache.php");