/wp-snapshots/511a4b30d372c5933_20130212_wastark_installer.php
PHP | 3222 lines | 2522 code | 365 blank | 335 comment | 258 complexity | 022e0d5132ab95cfeae8e25c4fddf91e MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- Copyright 2011-12 Cory Lamle lifeinthegrid.com
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 2, as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- SOURCE CONTRIBUTORS:
- Gaurav Aggarwal
- David Coveney of Interconnect IT Ltd
- https://github.com/interconnectit/Search-Replace-DB/
- */
-
- //DOWNLOAD ONLY:
- if ( isset($_GET['get']) && file_exists($_GET['file'])) {
- if (strstr($_GET['file'], '_installer.php') || strstr($_GET['file'], 'installer.rescue.php')) {
- header('Content-Description: File Transfer');
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename=installer.php');
- header('Content-Transfer-Encoding: binary');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- header('Content-Length: ' . filesize($_GET['file']));
- @ob_clean();
- @flush();
- if (@readfile($_GET['file']) == false) {
- $data = file_get_contents($_GET['file']);
- if ($data == false) {
- die("Unable to read installer file. The server currently has readfile and file_get_contents disabled on this server. Please contact your server admin to remove this restriction");
- } else {
- print $data;
- }
- }
- exit;
- } else {
- header("HTML/1.1 404 Not Found", true, 404);
- header("Status: 404 Not Found");
- }
- }
-
- //Prevent Access from rovers or direct browsing in snapshop directory
- if (file_exists('dtoken.php')) {
- exit;
- }
- ?>
-
- <?php if ( false ) :?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Error: PHP is not running</title>
- </head>
- <body>
- <h2>Error: PHP is not running</h2>
- <p>Duplicator requires that your web server is running PHP. Your server does not have PHP installed, or PHP is turned off.</p>
- </body>
- </html>
- <?php endif; ?>
-
-
- <?php
- /* ==============================================================================================
- ADVANCED FEATURES - Allows admins to perform aditional logic on the import.
-
- $GLOBALS['TABLES_SKIP_COLS']
- Add Known column names of tables you don't want the search and replace logic to run on.
- $GLOBALS['REPLACE_LIST']
- Add additional search and replace items add list here
- Example: array(array('search'=> '/html/oldpath/images', 'replace'=> '/html/newpath/images'));
- ================================================================================================= */
-
- $GLOBALS['FW_TABLEPREFIX'] = 'wp_';
- $GLOBALS['FW_URL_OLD'] = 'http://wastark.com';
- $GLOBALS['FW_URL_NEW'] = '';
- $GLOBALS['FW_PACKAGE_NAME'] = '511a4b30d372c5933_20130212_wastark_package.zip';
- $GLOBALS['FW_SECURE_NAME'] = '511a4b30d372c5933_20130212_wastark';
- $GLOBALS['FW_DBHOST'] = 'localhost';
- $GLOBALS['FW_DBNAME'] = '';
- $GLOBALS['FW_DBUSER'] = '';
- $GLOBALS['FW_BLOGNAME'] = 'W. A. Stark';
- $GLOBALS['FW_RESCUE_FLAG'] = '';
- $GLOBALS['FW_WPROOT'] = '/home/starehcf/public_html/wastark.com/';
-
- //DATABASE SETUP: all time in seconds
- $GLOBALS['DB_MAX_TIME'] = 5000;
- $GLOBALS['DB_MAX_PACKETS'] = 268435456;
- ini_set('mysql.connect_timeout', '5000');
-
- //PHP SETUP: all time in seconds
- ini_set('memory_limit', '5000M');
- ini_set("max_execution_time", '5000');
- ini_set("max_input_time", '5000');
- ini_set('default_socket_timeout', '5000');
- @set_time_limit(0);
-
- $GLOBALS['DBCHARSET_DEFAULT'] = 'utf8';
- $GLOBALS['DBCOLLATE_DEFAULT'] = 'utf8_general_ci';
-
- //UPDATE TABLE SETTINGS
- $GLOBALS['TABLES_SKIP_COLS'] = array('');
- $GLOBALS['REPLACE_LIST'] = array();
-
-
- /* ================================================================================================
- END ADVANCED FEATURES: Do not edit below here.
- =================================================================================================== */
-
- //CONSTANTS
- define("DUPLICATOR_SSDIR_NAME", 'wp-snapshots'); //This should match DUPLICATOR_SSDIR_NAME in duplicator.php
-
- //GLOBALS
- $GLOBALS['DUPLICATOR_INSTALLER_VERSION'] = '0.4.2';
- $GLOBALS["SQL_FILE_NAME"] = "installer-data.sql";
- $GLOBALS["LOG_FILE_NAME"] = "installer-log.txt";
- $GLOBALS['SEPERATOR1'] = str_repeat("********", 10);
- $GLOBALS['LOGGING'] = isset($_POST['logging']) ? $_POST['logging'] : 1;
-
- $GLOBALS['CURRENT_ROOT_PATH'] = dirname(__FILE__);
- $GLOBALS['CHOWN_ROOT_PATH'] = @chmod("{$GLOBALS['CURRENT_ROOT_PATH']}", 0755);
- $GLOBALS['CHOWN_LOG_PATH'] = @chmod("{$GLOBALS['CURRENT_ROOT_PATH']}/{$GLOBALS['LOG_FILE_NAME']}", 0644);
- $GLOBALS['URL_SSL'] = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') ? true : false;
- $GLOBALS['URL_PATH'] = ($GLOBALS['URL_SSL'])
- ? "https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"
- : "http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}";
-
- //SHARED POST PARMS
- $_POST['action_step'] = isset($_POST['action_step']) ? $_POST['action_step'] : "0";
- $_POST['dbhost'] = isset($_POST['dbhost']) ? trim($_POST['dbhost']) : null;
- $_POST['dbuser'] = isset($_POST['dbuser']) ? trim($_POST['dbuser']) : null;
- $_POST['dbpass'] = isset($_POST['dbpass']) ? trim($_POST['dbpass']) : null;
- $_POST['dbname'] = isset($_POST['dbname']) ? trim($_POST['dbname']) : null;
- $_POST['dbcharset'] = isset($_POST['dbcharset']) ? trim($_POST['dbcharset']) : $GLOBALS['DBCHARSET_DEFAULT'];
- $_POST['dbcollate'] = isset($_POST['dbcollate']) ? trim($_POST['dbcollate']) : $GLOBALS['DBCOLLATE_DEFAULT'];
-
-
- //Restart log if user starts from step 1
- if ($_POST['action_step'] == 1) {
- $GLOBALS['LOG_FILE_HANDLE'] = @fopen($GLOBALS['LOG_FILE_NAME'], "w+");
- } else {
- $GLOBALS['LOG_FILE_HANDLE'] = @fopen($GLOBALS['LOG_FILE_NAME'], "a+");
- }
-
- ?>
-
- <?php
-
- /** ******************************************************
- * CLASS::DupUtil
- * Various Static Utility methods for working with the installer */
- class DupUtil {
-
- /** METHOD: LOG
- * Used to write debug info to the output page
- * @param string $msg A a message that belongs to a unique title block
- * @param int $loglevel Log level
- * @param bool $newline Insert a newline
- */
- static public function log ($msg, $logging = 1) {
- if ($logging <= $GLOBALS["LOGGING"] ) {
- @fwrite($GLOBALS["LOG_FILE_HANDLE"], "{$msg}\n");
- }
- }
-
- /** METHOD: GET_MICROTIME
- * Get current microtime as a float. Can be used for simple profiling.
- */
- static public function get_microtime() {
- return microtime(true);
- }
-
- /** METHOD: ELAPSED_TIME
- * Return a string with the elapsed time.
- * Order of $end and $start can be switched.
- */
- static public function elapsed_time($end, $start) {
- return sprintf("%.4f sec.", abs($end - $start));
- }
-
- /** METHOD: ESC_HTML_ATTR
- * @param string $string Thing that needs escaping
- * @param bool $echo Do we echo or return?
- * @return string Escaped string.
- */
- static public function esc_html_attr( $string = '', $echo = false ) {
- $output = htmlentities( $string, ENT_QUOTES, 'UTF-8' );
- if ( $echo )
- echo $output;
- else
- return $output;
- }
-
- /** METHOD: TABLE_COUNT
- * Count the tables in a given database
- * @param string $_POST['dbname'] Database to count tables in
- */
- static public function dbtable_count($conn, $dbname) {
- $res = mysqli_query($conn, "SELECT COUNT(*) AS count FROM information_schema.tables WHERE table_schema = '{$dbname}' ");
- $row = mysqli_fetch_row($res);
- return is_null($row) ? 0 : $row[0];
- }
-
- /** METHOD: TABLE_ROW_COUNT
- * Returns the table count
- * @param string $conn A valid link resource
- * @param string $table_name A valid table name
- */
- static public function table_row_count($conn, $table_name) {
- $total = mysqli_query($conn, "SELECT COUNT(*) FROM `$table_name`");
- if ($total) {
- $total = @mysqli_fetch_array($total);
- return $total[0];
- } else {
- return 0;
- }
- }
-
- /** METHOD: ADD_ENDING_SLASH
- * Adds a slash to the end of a path
- * @param string $path A path
- */
- static public function add_slash($path){
- $last_char = substr($path, strlen($path)-1, 1);
- if ($last_char != '/' ) {
- $path .= '/';
- }
- return $path;
- }
-
-
- /** METHOD: SET_SAFE_PATH
- * Makes path safe for any OS
- * Paths should ALWAYS READ be "/"
- * uni: /home/path/file.xt
- * win: D:/home/path/file.txt
- * @param string $path The path to make safe
- */
- static public function set_safe_path($path) {
- return str_replace("\\", "/", $path);
- }
-
- static public function unset_safe_path($path) {
- return str_replace("/", "\\", $path);
- }
-
- /** METHOD: FCGI_FLUSH
- * PHP_SAPI for fcgi requires a data flush of at least 256
- * bytes every 40 seconds or else it forces a script hault
- */
- static public function fcgi_flush() {
- echo(str_repeat(' ',256));
- @flush();
- }
-
- /** METHOD: COPY_FILE
- * A safe method used to copy larger files
- * @param string $source The path to the file being copied
- * @param string $destination The path to the file being made
- */
- static public function copy_file($source, $destination) {
- $sp = fopen($source, 'r');
- $op = fopen($destination, 'w');
-
- while (!feof($sp)) {
- $buffer = fread($sp, 512); // use a buffer of 512 bytes
- fwrite($op, $buffer);
- }
- // close handles
- fclose($op);
- fclose($sp);
- }
-
- /** METHOD: string_has_value
- * Finds a string in a file and returns true if found
- * @param array $list A list of strings to search for
- * @param string $haystack The string to search in
- */
- static public function string_has_value($list, $file) {
- foreach($list as $var) {
- if (strstr($file, $var) !== false ) {
- return true;
- }
- }
- return false;
- }
-
- /** METHOD: get_active_plugins
- * Returns the active plugins for a package
- * @param conn $dbh A database connection handle
- * @return array $list A list of active plugins
- */
- static public function get_active_plugins($dbh) {
- $query = @mysqli_query($dbh, "SELECT option_value FROM `{$GLOBALS['FW_TABLEPREFIX']}options` WHERE option_name = 'active_plugins' ");
- if ($query) {
- $row = mysqli_fetch_array($query);
- $all_plugins = unserialize($row[0]);
- if (is_array($all_plugins)) {
- return $all_plugins;
- }
- }
- return array();
- }
-
- /** METHOD: get_database_tables
- * Returns the tables for a database
- * @param conn $dbh A database connection handle
- * @return array $list A list of all table names
- */
- static public function get_database_tables($dbh) {
- $query = @mysqli_query($dbh, 'SHOW TABLES');
- if ($query ) {
- while ($table = mysqli_fetch_array($query )) {
- $all_tables[] = $table[ 0 ];
- }
- if (is_array($all_tables)) {
- return $all_tables;
- }
- }
- return array();
- }
-
-
- /**
- * MySQL database version number
- * @param conn $dbh Database connection handle
- * @return false|string false on failure, version number on success
- */
- static public function mysql_version($dbh) {
- if (function_exists( 'mysqli_get_server_info' ) ) {
- return preg_replace( '/[^0-9.].*/', '', mysqli_get_server_info( $dbh ) );
- } else {
- return 0;
- }
- }
-
- /**
- * MySQL server variable
- * @param conn $dbh Database connection handle
- * @return string the server variable to query for
- */
- static public function mysql_variable_value($dbh, $variable) {
- $result = @mysqli_query($dbh, "SHOW VARIABLES LIKE '{$variable}'");
- $row = mysqli_fetch_array($result);
- @mysqli_free_result($result);
- return isset($row[1]) ? $row[1] : null;
- }
-
- /**
- * Determine if a MySQL database supports a particular feature
- * @param conn $dbh Database connection handle
- * @param string $feature the feature to check for
- * @return bool
- */
- static public function mysql_has_ability($dbh, $feature) {
- $version = self::mysql_version($dbh);
-
- switch ( strtolower( $feature ) ) {
- case 'collation' :
- case 'group_concat' :
- case 'subqueries' :
- return version_compare( $version, '4.1', '>=' );
- case 'set_charset' :
- return version_compare($version, '5.0.7', '>=');
- };
- return false;
- }
-
- /**
- * Sets the MySQL connection's character set.
- * @param resource $dbh The resource given by mysqli_connect
- * @param string $charset The character set (optional)
- * @param string $collate The collation (optional)
- */
- static public function mysql_set_charset($dbh, $charset = null, $collate = null) {
-
- $charset = ( !isset($charset) ) ? $GLOBALS['DBCHARSET_DEFAULT'] : $charset;
- $collate = ( !isset($collate) ) ? $GLOBALS['DBCOLLATE_DEFAULT'] : $collate;
-
- if ( self::mysql_has_ability($dbh, 'collation') && !empty( $charset ) ) {
- if ( function_exists( 'mysqli_set_charset' ) && self::mysql_has_ability($dbh, 'set_charset') ) {
- return mysqli_set_charset($dbh, $charset);
- } else {
- $sql = " SET NAMES {$charset}";
- if ( ! empty( $collate ) )
- $sql .= " COLLATE {$collate}";
- return mysqli_query($dbh, $sql);
- }
- }
- }
-
-
- /**
- * READABLE_BYTESIZE
- * Display human readable byte sizes
- * @param string $size The size in bytes
- */
- static public function readable_bytesize($size) {
- try {
- $units = array('B', 'KB', 'MB', 'GB', 'TB');
- for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024;
- return round($size, 2).$units[$i];
- } catch (Exception $e) {
- return "n/a";
- }
- }
-
-
- }
-
- ?>
-
-
- <?php
- if (isset($_POST['action_ajax'])) {
- switch ( $_POST['action_ajax'] ) {
- case "1" :?> <?php
- //====================================================================================================
- //PRECHECKS - Validate and make sure to have a clean enviroment
- //====================================================================================================
- define('MSG_ERR_CONFIG_FOUND', '<div class="error"><b style="color:#C16C1D;">INSTALL ERROR!</b><br/> A wp-config.php already exists in this location. This error prevents users from accidentally overwriting the wrong directories contents. You have two options: <ul><li>Empty this root directory except for the package and installer and try again.</li><li>Delete just the wp-config.php file and try again. This will over-write all other files in the directory.</li></ul></div>');
- define('MSG_ERR_ZIPNOTFOUND', '<div class="error"><b style="color:#C16C1D;">INSTALL ERROR!</b><br/> The packaged zip file was not found. Be sure the zip package is in the same directory as the installer file. If you are trying to reinstall a package you can copy the package from the "' . DUPLICATOR_SSDIR_NAME . '" directory back up to your root which is the same location as your installer.php file. </div>');
- define('MSG_ERR_ZIPEXTRACTION', '<div class="error"><b style="color:#C16C1D;">INSTALL ERROR!</b><br/> Failed in extracting zip file. Please be sure the archive is completely downloaded. Try to extract the archive manually to make sure the file is not corrupted. </div>');
- define('MSG_ERR_ZIPMANUAL', '<div class="error"><b style="color:#C16C1D;">INSTALL ERROR!</b><br/> When choosing manual package extraction, the contents of the package must already be extracted and the wp-config.php and database.sql files must be present in the same directory as the installer.php for the process to continue. Please manually extract the package into the current directory before continuing in manual extraction mode. Also validate that the wp-config.php and database.sql files are present. </div>');
- define('MSG_ERR_MAKELOG', '<div class="error"><b style="color:#C16C1D;">INSTALL ERROR!</b><br/> PHP is having issues writing to the log file <b>' . DupUtil::set_safe_path($GLOBALS['CURRENT_ROOT_PATH']) . '\installer-log.txt .</b> In order for the Duplicator to proceed validate your owner/group and permission settings for PHP on this path. Try temporarily setting you permissions to 777 to see if the issue gets resolved. If you are on a shared hosting environment please contact your hosting company and tell them you are getting errors writing files to the path above when using PHP. </div>');
- define('MSG_FAIL_MYSQLI_SUPPORT', '<div class="error"><b style="color:#B80000;">PHP MYSQLI NOT ENABLED!</b><br/>In order to complete an install the mysqli extension for PHP is required. If you are on a hosted server please contact your host and request that mysqli be enabled. For more information visit: http://php.net/manual/en/mysqli.installation.php</div>');
- define('MSG_FAIL_DBCONNECT', '<div class="error"><b style="color:#B80000;">DATABASE CONNECTION FAILED!</b><br/></div>');
- define('MSG_FAIL_DBCONNECT_CREATE', '<div class="error"><b style="color:#B80000;">DATABASE CREATION FAILURE!</b><br/> Unable to create database "%s".<br/> Please try creating the database manually to proceed with installation</div>');
- define('MSG_FAIL_DBTRYCLEAN', '<div class="error"><b style="color:#C16C1D;">DATABASE CREATION FAILURE!</b><br/> Unable to remove all tables from database "%s".<br/> Please remove all tables from this database and try the installation again.</div>');
- define('MSG_ERR_DBCREATE', '<div class="error"><b style="color:#C16C1D;">INSTALL ERROR!</b><br/> The database "%s" does not exists.<br/> Enable allow database creation to proceed with the installation.</div>');
- define('MSG_ERR_DBCLEANCHECK', '<div class="error"><b style="color:#C16C1D;">INSTALL ERROR!</b><br/> The database "%s" has %s tables. The Duplicator only works with an EMPTY database. Enable the "Table Removal" checkbox to delete all tables and proceed with installation. Please backup all your data before proceeding!<br/><br/> Some hosting providers do not allow table removal from scripts like the Duplicator. In this case you will need to login to your hosting providers control panel and remove the tables manually. Please contact your hosting provider for further details. </div>');
- define('MSG_OK_DBPASS', '<div class="error"><b style="color:#006E32;">CONNECTION SUCCESSFUL!</b><br/> With the parameters provided.</div>');
-
-
- //POST PARAMS
- $_POST['dbmake'] = (isset($_POST['dbmake']) && $_POST['dbmake'] == '1') ? true : false;
- $_POST['dbclean'] = (isset($_POST['dbclean']) && $_POST['dbclean'] == '1') ? true : false;
- $_POST['dbnbsp'] = (isset($_POST['dbnbsp']) && $_POST['dbnbsp'] == '1') ? true : false;
- $_POST['no_ssl'] = (isset($_POST['no_ssl']) && $_POST['no_ssl'] == '1') ? true : false;
- $_POST['package_name'] = isset($_POST['package_name']) ? $_POST['package_name'] : null;
- $_POST['zip_manual'] = (isset($_POST['zip_manual']) && $_POST['zip_manual'] == '1') ? true : false;
-
- //LOGGING
- $POST_LOG = $_POST;
- unset($POST_LOG['dbpass']);
- ksort($POST_LOG);
-
- //PAGE VARS
- $back_link = "<div class='tryagain'><a href='javascript:void(0)' onclick='Duplicator.hideErrorResult()' style='color:#444; font-weight:bold'>« Try Again</a></div>";
- $root_path = DupUtil::set_safe_path($GLOBALS['CURRENT_ROOT_PATH']);
- $package_path = "{$root_path}/{$_POST['package_name']}";
- $package_size = @filesize($package_path);
- $ajax1_start = DupUtil::get_microtime();
- $JSON = array();
- $JSON['pass'] = 0;
-
-
- //===============================
- //DATABASE TEST CONNECTION
- //===============================
- if (isset($_GET['dbtest'])) {
-
- if (! is_null($_POST['dbname'])) {
- $dbh = @mysqli_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass'], $_POST['dbname']);
- } else {
- $dbh = @mysqli_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass']);
- }
-
- if (! $dbh) {
- die(MSG_FAIL_DBCONNECT . mysqli_connect_error());
- }
-
- if (! $_POST['dbmake']) {
- mysqli_select_db($dbh, $_POST['dbname']) or die(sprintf(MSG_ERR_DBCREATE, $_POST['dbname']));
- }
-
- if (! $_POST['dbclean']) {
- $tblcount = DupUtil::dbtable_count($dbh, $_POST['dbname']);
- if ($tblcount > 0) {
- die(sprintf(MSG_ERR_DBCLEANCHECK, $_POST['dbname'], $tblcount ));
- }
- }
- die(MSG_OK_DBPASS);
- }
-
- //===============================
- //VALIDATION MESSAGES
- //===============================
- //MSG_ERR_MAKELOG
- ($GLOBALS['LOG_FILE_HANDLE'] != false) or die(MSG_ERR_MAKELOG . $back_link);
-
-
- //MSG_FAIL_MYSQLI_SUPPORT
- function_exists('mysqli_connect') or die(MSG_FAIL_MYSQLI_SUPPORT);
-
- //MSG_FAIL_DBCONNECT
- $dbh = @mysqli_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass']);
- ($dbh) or die(MSG_FAIL_DBCONNECT . mysqli_connect_error() . $back_link);
- if (! $_POST['dbmake']) {
- mysqli_select_db($dbh, $_POST['dbname']) or die(sprintf(MSG_ERR_DBCREATE, $_POST['dbname']) . $back_link);
- }
- //MSG_ERR_DBCLEANCHECK
- if (! $_POST['dbclean']) {
- $tblcount = DupUtil::dbtable_count($dbh, $_POST['dbname']);
- if ($tblcount > 0) {
- die(sprintf(MSG_ERR_DBCLEANCHECK, $_POST['dbname'], $tblcount ) . $back_link);
- }
- }
-
- //MSG_ERR_ZIPMANUAL
- if ($_POST['zip_manual']) {
- if (! file_exists("wp-config.php") && ! file_exists("database.sql")) {
- die(MSG_ERR_ZIPMANUAL . $back_link);
- }
- } else {
- //MSG_ERR_CONFIG_FOUND
- (! file_exists('wp-config.php')) or die(MSG_ERR_CONFIG_FOUND . $back_link);
- //MSG_ERR_ZIPNOTFOUND
- (is_readable("{$package_path}")) or die(MSG_ERR_ZIPNOTFOUND . $back_link);
- }
-
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
- DupUtil::log('DUPLICATOR INSTALL-LOG');
- DupUtil::log('STEP1 START @ ' . @date('h:i:s') );
- DupUtil::log('NOTICE: Do not post to public sites or forums');
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
- DupUtil::log("VERSION:\t{$GLOBALS['DUPLICATOR_INSTALLER_VERSION']}");
- DupUtil::log("PHP:\t\t" . phpversion());
- DupUtil::log("PHP SAPI:\t" . php_sapi_name());
- DupUtil::log("ZIPARCHIVE:\t" . var_export(class_exists('ZipArchive'), true));
- DupUtil::log("SERVER:\t\t{$_SERVER['SERVER_SOFTWARE']}");
- DupUtil::log("DOC ROOT:\t{$root_path}");
- DupUtil::log("DOC ROOT 755:\t" . var_export($GLOBALS['CHOWN_ROOT_PATH'], true));
- DupUtil::log("LOG FILE 644:\t" . var_export($GLOBALS['CHOWN_LOG_PATH'], true));
- DupUtil::log("BUILD NAME:\t{$GLOBALS['FW_SECURE_NAME']}");
- DupUtil::log("REQUEST URL:\t{$GLOBALS['URL_PATH']}");
- DupUtil::log("--------------------------------------");
- DupUtil::log("POST DATA");
- DupUtil::log("--------------------------------------");
- DupUtil::log(print_r($POST_LOG, true));
-
-
- //====================================================================================================
- //UNZIP & FILE SETUP - Extract the zip file and prep files
- //====================================================================================================
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
- DupUtil::log('UNZIP & FILE SETUP');
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
- DupUtil::log("PACKAGE:\t" . $_POST['package_name'] );
- DupUtil::log("SIZE:\t\t" . DupUtil::readable_bytesize(@filesize($_POST['package_name'])));
-
- $zip_start = DupUtil::get_microtime();
-
- if ($_POST['zip_manual']) {
- DupUtil::log("\n-package extraction is in manual mode-\n");
- } else {
- if ($GLOBALS['FW_PACKAGE_NAME'] != $_POST['package_name']) {
- DupUtil::log("WARNING: This Package Set may be incompatible! \nBelow is a summary of the package this installer was built with and the package used. \nTo guarantee accuracy make sure the installer and package match. For more details see the online FAQs. \ncreated with: {$GLOBALS['FW_PACKAGE_NAME']} \nprocessed with: {$_POST['package_name']} \n");
- }
-
- $target = $root_path;
- $zip = new ZipArchive();
- if ($zip->open($_POST['package_name']) === TRUE) {
- @$zip->extractTo($target);
- DupUtil::log("INFORMATION:\t" . print_r($zip, true));
- $close_response = $zip->close();
- DupUtil::log("ZIP CLOSE: " . var_export($close_response, true));
- } else {
- die(MSG_ERR_ZIPEXTRACTION . $back_link );
- }
- $zip = null;
- }
-
- //===============================
- //SCRIPTS: wp-config/database.sql
- //===============================
-
- //WP-CONFIG
- $patterns = array("/'DB_NAME',\s*'.*?'/",
- "/'DB_USER',\s*'.*?'/",
- "/'DB_PASSWORD',\s*'.*?'/",
- "/'DB_HOST',\s*'.*?'/");
-
- $replace = array("'DB_NAME', " . '\''.$_POST['dbname'].'\'',
- "'DB_USER', " . '\''.$_POST['dbuser'].'\'',
- "'DB_PASSWORD', " . '\''.$_POST['dbpass'].'\'',
- "'DB_HOST', " . '\''.$_POST['dbhost'].'\'');
-
- if ($_POST['no_ssl']) {
- array_push($patterns, "/'FORCE_SSL_ADMIN',\s*true/");
- array_push($replace, "'FORCE_SSL_ADMIN', false");
- }
-
- $wpconfig = @file_get_contents('wp-config.php', true);
- $wpconfig = preg_replace($patterns, $replace, $wpconfig);
- file_put_contents('wp-config.php', $wpconfig);
- $wpconfig = null;
-
-
- //DATABASE SCRIPT
- @chmod("{$root_path}/database.sql", 0777);
- $sql_file = @file_get_contents('database.sql', true);
- if ($sql_file == false || strlen($sql_file) < 10) {
- $sql_file = file_get_contents('installer-data.sql', true);
- if ($sql_file == false || strlen($sql_file) < 10) {
- DupUtil::log("ERROR: Unable to read from the extracted database.sql file .\nValidate the permissions and/or group-owner rights on directory '{$root_path}'\n");
- }
- }
-
- //Complex Subject See: http://webcollab.sourceforge.net/unicode.html
- //Removes invalid space characters
- if ($_POST['dbnbsp']) {
- DupUtil::log("ran fix non-breaking space characters\n" );
- $sql_file = preg_replace('/\xC2\xA0/',' ',$sql_file);
- }
-
- //Write new contents to install-data.sql
- @chmod($sql_result_file_path, 0777);
- file_put_contents($GLOBALS['SQL_FILE_NAME'], $sql_file);
-
- $sql_result_file_data = explode(";\n", $sql_file);
- $sql_result_file_length = count($sql_result_file_data);
- $sql_result_file_path = "{$root_path}/{$GLOBALS['SQL_FILE_NAME']}";
- $sql_file = null;
-
- if (! is_readable($sql_result_file_path) || filesize($sql_result_file_path) == 0) {
- DupUtil::log("ERROR: Unable to create new sql file {$GLOBALS['SQL_FILE_NAME']}.\nValidate the permissions and/or group-owner rights on directory '{$root_path}' and file '{$GLOBALS['SQL_FILE_NAME']}'\n");
- }
-
- DupUtil::log("UPDATED SCRIPTS:");
- DupUtil::log("\tsql file: '{$sql_result_file_path}'");
- DupUtil::log("\twp-config: '{$root_path}/wp-config.php'");
- $zip_end = DupUtil::get_microtime();
- DupUtil::log("\nSECTION RUNTIME: " . DupUtil::elapsed_time($zip_end, $zip_start));
- DupUtil::log("\n");
- DupUtil::fcgi_flush();
-
-
- //====================================================================================================
- //DATABASE ROUTINES
- //====================================================================================================
-
- @mysqli_query($dbh, "SET wait_timeout = {$GLOBALS['DB_MAX_TIME']}");
- @mysqli_query($dbh, "SET max_allowed_packet = {$GLOBALS['DB_MAX_PACKETS']}");
- DupUtil::mysql_set_charset($dbh, $_POST['dbcharset'], $_POST['dbcollate']);
-
- //Set defaults incase the variable could not be read
- $dbvar_maxtime = DupUtil::mysql_variable_value($dbh, 'wait_timeout');
- $dbvar_maxpacks = DupUtil::mysql_variable_value($dbh, 'max_allowed_packet');
- $dbvar_maxtime = is_null($dbvar_maxtime) ? 300 : $dbvar_maxtime;
- $dbvar_maxpacks = is_null($dbvar_maxpacks) ? 1048576 : $dbvar_maxpacks;
-
-
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
- DupUtil::log('DATABASE-ROUTINES');
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
- DupUtil::log("--------------------------------------");
- DupUtil::log("SERVER ENVIROMENT");
- DupUtil::log("--------------------------------------");
- DupUtil::log("MYSQL VERSION:\t" . mysqli_get_server_info($dbh));
- DupUtil::log("TIMEOUT:\t{$dbvar_maxtime}");
- DupUtil::log("MAXPACK:\t{$dbvar_maxpacks}");
-
- //CREATE DB
- if ($_POST['dbmake']) {
- mysqli_query($dbh, "CREATE DATABASE IF NOT EXISTS `{$_POST['dbname']}`");
- mysqli_select_db($dbh, $_POST['dbname'])
- or die(sprintf(MSG_FAIL_DBCONNECT_CREATE, $_POST['dbname']) . $back_link);
- }
-
- //DROP DB TABLES
- $drop_log = "Database already empty. Ready for install.";
- if ($_POST['dbclean']) {
- $sql = "SHOW TABLES FROM `{$_POST['dbname']}`";
- $found_tables = null;
- if($result = mysqli_query($dbh, $sql)){
- while($row = mysqli_fetch_row($result)){
- $found_tables[] = $row[0];
- }
- if (count($found_tables) > 0) {
- foreach($found_tables as $table_name){
- $sql = "DROP TABLE `{$_POST['dbname']}`.{$table_name}";
- if(! $result = mysqli_query($dbh, $sql)){
- die(sprintf(MSG_FAIL_DBTRYCLEAN, $_POST['dbname']) . $back_link);
- }
- }
- }
- $drop_log = 'removed (' . count($found_tables) . ') tables';
- }
- }
-
- //WRITE DATA
- DupUtil::log("--------------------------------------");
- DupUtil::log("DATABASE RESULTS");
- DupUtil::log("--------------------------------------");
- $profile_start = DupUtil::get_microtime();
- $fcgi_buffer_pool = 5000;
- $fcgi_buffer_count = 0;
- $dbquery_rows = 0;
- $dbquery_errs = 0;
- $counter = 0;
- @mysqli_autocommit($dbh, false);
- while ($counter < $sql_result_file_length) {
-
- $query_strlen = strlen(trim($sql_result_file_data[$counter]));
- if ($dbvar_maxpacks < $query_strlen) {
- DupUtil::log("**ERROR** Query size limit [length={$query_strlen}] [sql=" . substr($sql_result_file_data[$counter], 75) . "...]");
- $dbquery_errs++;
- }
- elseif ($query_strlen > 0) {
- @mysqli_free_result(@mysqli_query($dbh, ($sql_result_file_data[$counter])));
- $err = mysqli_error($dbh);
- //Check to make sure the connection is alive
- if (! empty($err)){
-
- if (!mysqli_ping ($dbh)) {
- mysqli_close($dbh);
- $dbh = mysqli_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass'], $_POST['dbname']);
- }
- DupUtil::log("**ERROR** database error write '{$err}' - [sql=" . substr($sql_result_file_data[$counter], 0, 75) . "...]");
- $dbquery_errs++;
-
- //Buffer data to browser to keep connection open
- } else {
- if ($fcgi_buffer_count++ > $fcgi_buffer_pool) {
- $fcgi_buffer_count = 0;
- DupUtil::fcgi_flush();
- }
- $dbquery_rows++;
- }
- }
- $counter++;
- }
- @mysqli_commit($dbh);
- @mysqli_autocommit($dbh, true);
-
- DupUtil::log("ERRORS FOUND:\t{$dbquery_errs}");
- DupUtil::log("DROP TABLE:\t{$drop_log}");
- DupUtil::log("QUERIES RAN:\t{$dbquery_rows}\n");
-
- $dbtable_count = 0;
- if ($result = mysqli_query($dbh, "SHOW TABLES")) {
- while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
- $table_rows = DupUtil::table_row_count($dbh, $row[0]);
- DupUtil::log("{$row[0]}: ({$table_rows})");
- $dbtable_count++;
- }
- @mysqli_free_result($result);
- }
-
- if ($dbtable_count == 0) {
- DupUtil::log("NOTICE: You may have to manually run the installer-data.sql to validate data input. Also check to make sure your installer file is correct and the
- table prefix '{$GLOBALS['FW_TABLEPREFIX']}' is correct for this particular version of WordPress. \n");
- }
-
- //DATA CLEANUP: Perform Transient Cache Cleanup
- //Remove all duplicator entries and record this one since this is a new install.
- $dbdelete_count = 0;
- @mysqli_query($dbh, "DELETE FROM `{$GLOBALS['FW_TABLEPREFIX']}duplicator`");
- $dbdelete_count1 = @mysqli_affected_rows($dbh) or 0;
- @mysqli_query($dbh, "DELETE FROM `{$GLOBALS['FW_TABLEPREFIX']}options` WHERE `option_name` LIKE ('_transient%') OR `option_name` LIKE ('_site_transient%')");
- $dbdelete_count2 = @mysqli_affected_rows($dbh) or 0;
- $dbdelete_count = (abs($dbdelete_count1) + abs($dbdelete_count2));
- DupUtil::log("Removed '{$dbdelete_count}' cache/transient rows");
- @mysqli_close($dbh);
-
- $profile_end = DupUtil::get_microtime();
- DupUtil::log("\nSECTION RUNTIME: " . DupUtil::elapsed_time($profile_end, $profile_start));
-
- $ajax1_end = DupUtil::get_microtime();
- $ajax1_sum = DupUtil::elapsed_time($ajax1_end, $ajax1_start);
- DupUtil::log("\n{$GLOBALS['SEPERATOR1']}");
- DupUtil::log('STEP1 COMPLETE @ ' . @date('h:i:s') . " - TOTAL RUNTIME: {$ajax1_sum}");
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
-
- $JSON['pass'] = 1;
- $JSON['table_count'] = $dbtable_count;
- $JSON['table_rows'] = ($dbquery_rows - ($dbtable_count + $dbdelete_count + $dbquery_errs));
- $JSON['query_errs'] = $dbquery_errs;
- echo json_encode($JSON);
- die('');
- ?> <?php break;
- case "2" :?> <?php
-
- /** ******************************************************
- * CLASS::DUPDBTEXTSWAP
- * Walks every table in db that then walks every row and column replacing searches with replaces
- * large tables are split into 50k row blocks to save on memory. */
- class DupDBTextSwap {
-
- /**
- * LOG ERRORS
- */
- static public function log_errors($report) {
- if ( ! empty($report['errsql']) ) {
- DupUtil::log("====================================");
- DupUtil::log("DATA-REPLACE ERRORS (MySQL)");
- foreach( $report['errsql'] as $error ) {DupUtil::log($error);}
- DupUtil::log("");
- }
- if ( ! empty($report['errser']) ) {
- DupUtil::log("====================================");
- DupUtil::log("DATA-REPLACE ERRORS (Serialization):");
- foreach( $report['errser'] as $error ) {DupUtil::log($error);}
- DupUtil::log("");
- }
- if ( ! empty($report['errkey']) ) {
- DupUtil::log("====================================");
- DupUtil::log("DATA-REPLACE ERRORS (Key):");
- DupUtil::log('Use SQL: SELECT @row := @row + 1 as row, t.* FROM some_table t, (SELECT @row := 0) r');
- foreach( $report['errkey'] as $error ) {DupUtil::log($error);}
- DupUtil::log("");
- }
- }
-
- /**
- * LOG STATS
- */
- static public function log_stats($report) {
- if ( ! empty( $report ) && is_array( $report ) ) {
- $stats = sprintf("SEARCH1:\t'%s' \nREPLACE1:\t'%s' \n", $_POST['url_old'], $_POST['url_new']);
- $stats .= sprintf("SEARCH2:\t'%s' \nREPLACE2:\t'%s' \n", $_POST['path_old'], $_POST['path_new']);
- $stats .= sprintf("SCANNED:\tTables:%d | Rows:%d | Cells:%d \n", $report['scan_tables'], $report['scan_rows'], $report['scan_cells']);
- $stats .= sprintf("UPDATED:\tTables:%d | Rows:%d |Cells:%d \n", $report['updt_tables'], $report['updt_rows'], $report['updt_cells']);
- $stats .= sprintf("ERRORS:\t\t%d \nRUNTIME:\t%f sec", $report['err_all'], $report['time'] );
- DupUtil::log($stats);
- }
- }
-
- /**
- * LOAD
- * Begins the processing for replace logic
- * @param mysql $conn The db connection object
- * @param array $list Key value pair of 'search' and 'replace' arrays
- * @param array $tables The tables we want to look at.
- * @return array Collection of information gathered during the run.
- */
- static public function load($conn, $list=array(), $tables=array(), $cols=array()) {
- $exclude_cols = $cols;
-
- $report = array('scan_tables'=>0, 'scan_rows'=>0, 'scan_cells'=>0,
- 'updt_tables'=>0, 'updt_rows'=>0, 'updt_cells'=>0,
- 'errsql'=>array(), 'errser'=>array(), 'errkey'=>array(),
- 'errsql_sum'=>0, 'errser_sum'=>0, 'errkey_sum'=>0,
- 'time'=>'', 'err_all'=>0);
-
- $profile_start = DupUtil::get_microtime();
- if ( is_array( $tables ) && ! empty( $tables ) ) {
-
- foreach ($tables as $table) {
- $report['scan_tables']++;
- $columns = array( );
-
- // Get a list of columns in this table
- $fields = mysqli_query($conn, 'DESCRIBE ' . $table);
- while ($column = mysqli_fetch_array( $fields )) {
- $columns[ $column[ 'Field' ] ] = $column[ 'Key' ] == 'PRI' ? true : false;
- }
-
- // Count the number of rows we have in the table if large we'll split into blocks, This is a mod from Simon Wheatley
- $row_count = mysqli_query($conn, 'SELECT COUNT(*) FROM ' . $table);
- $rows_result = mysqli_fetch_array( $row_count );
- @mysqli_free_result($row_count);
- $row_count = $rows_result[ 0 ];
- if ( $row_count == 0 )
- continue;
-
- $page_size = 25000;
- $pages = ceil($row_count / $page_size);
-
- for ($page = 0; $page < $pages; $page++) {
-
- $current_row = 0;
- $start = $page * $page_size;
- $end = $start + $page_size;
- // Grab the content of the table
- $data = mysqli_query($conn, sprintf( 'SELECT * FROM %s LIMIT %d, %d', $table, $start, $end ) );
-
- if (! $data)
- $report['errsql'][] = mysqli_error($conn);
-
- //Loops every row
- while ($row = mysqli_fetch_array($data)) {
- $report['scan_rows']++;
- $current_row++;
- $upd_col = array();
- $upd_sql = array();
- $where_sql = array();
- $upd = false;
- $serial_err = 0;
-
- //Loops every cell
- foreach( $columns as $column => $primary_key ) {
- if (in_array( $column, $exclude_cols ) ) {
- continue;
- }
-
- $report['scan_cells']++;
- $edited_data = $data_to_fix = $row[$column];
- $base64coverted = false;
-
- //Only replacing string values
- if (! is_numeric($row[$column])) {
-
- //Base 64 detection
- if (base64_decode($row[$column], true)) {
- $decoded = base64_decode($row[$column], true);
- if(self::is_serialized($decoded)) {
- $edited_data = $decoded;
- $base64coverted = true;
- }
- }
-
- //Replace logic - level 1: simple check on basic serilized strings
- foreach($list as $item) {
- $edited_data = self::recursive_unserialize_replace($item['search'], $item['replace'], $edited_data);
- }
-
- //Replace logic - level 2: repair larger/complex serilized strings
- $serial_check = self::fix_serial_string($edited_data);
- if ($serial_check['fixed']) {
- $edited_data = $serial_check['data'];
- }
- elseif ($serial_check['tried'] && ! $serial_check['fixed']) {
- $serial_err++;
- }
- }
-
- //Change was made
- if ( $edited_data != $data_to_fix || $serial_err > 0) {
- $report['updt_cells']++;
- //Base 64 encode
- if ($base64coverted) {
- $edited_data = base64_encode($edited_data);
- }
- $upd_col[] = $column;
- $upd_sql[] = $column . ' = "' . mysqli_real_escape_string($conn, $edited_data) . '"';
- $upd = true;
- }
-
- if ($primary_key) {
- $where_sql[] = $column . ' = "' . mysqli_real_escape_string($conn, $data_to_fix) . '"';
- }
- }
-
- //PERFORM ROW UPDATE
- if ($upd && ! empty($where_sql)) {
-
- $sql = "UPDATE `{$table}` SET " . implode( ', ', $upd_sql ) . ' WHERE ' . implode( ' AND ', array_filter( $where_sql ) );
- $result = mysqli_query($conn, $sql) or $report['errsql'][] = mysqli_error($conn);
- if ($result) {
- if ($serial_err > 0) {
- $report['errser'][] = "SELECT " . implode( ', ', $upd_col ) ." FROM `{$table}` WHERE " . implode(' AND ', array_filter( $where_sql )) . ';';
- }
- $report['updt_rows']++;
- }
-
- } elseif ($upd) {
- $report['errkey'][] = sprintf("Row [%s] on Table [%s] requires a manual update.", $current_row, $table);
- }
- DupUtil::fcgi_flush();
- }
- @mysqli_free_result($data);
- }
-
- if ($upd) {
- $report['updt_tables']++;
- }
- }
- }
- $profile_end = DupUtil::get_microtime();
- $report['time'] = DupUtil::elapsed_time($profile_end, $profile_start);
- $report['errsql_sum'] = empty($report['errsql']) ? 0 : count($report['errsql']);
- $report['errser_sum'] = empty($report['errser']) ? 0 : count($report['errser']);
- $report['errkey_sum'] = empty($report['errkey']) ? 0 : count($report['errkey']);
- $report['err_all'] = $report['errsql_sum'] + $report['errser_sum'] + $report['errkey_sum'];
- return $report;
- }
-
- /**
- * Take a serialised array and unserialise it replacing elements and
- * unserialising any subordinate arrays and performing the replace.
- * @param string $from String we're looking to replace.
- * @param string $to What we want it to be replaced with
- * @param array $data Used to pass any subordinate arrays back to in.
- * @param bool $serialised Does the array passed via $data need serialising.
- * @return array The original array with all elements replaced as needed.
- */
- static private function recursive_unserialize_replace($from = '', $to = '', $data = '', $serialised = false) {
-
- // some unseriliased data cannot be re-serialised eg. SimpleXMLElements
- try {
-
- if (is_string($data) && ($unserialized = @unserialize( $data )) !== false) {
- $data = self::recursive_unserialize_replace($from, $to, $unserialized, true);
- }
- elseif (is_array($data)) {
- $_tmp = array();
- foreach ($data as $key => $value) {
- $_tmp[$key] = self::recursive_unserialize_replace($from, $to, $value, false);
- }
- $data = $_tmp;
- unset($_tmp);
- }
- elseif (is_object($data)) {
- $dataClass = get_class($data);
- $_tmp = new $dataClass();
- foreach ($data as $key => $value) {
- $_tmp->$key = self::recursive_unserialize_replace($from, $to, $value, false);
- }
- $data = $_tmp;
- unset($_tmp);
- }
- else {
- if (is_string($data)) {
- $data = str_replace($from, $to, $data);
- }
- }
-
- if ($serialised)
- return serialize($data);
-
- } catch(Exception $error) {
- DupUtil::log("\nRECURSIVE UNSERIALIZE ERROR: With string\n". $error, 2);
- }
- return $data;
- }
-
-
- /**
- * IS_SERIALIZED
- * Test if a string in properly serialized */
- static public function is_serialized($data) {
- $test = @unserialize(($data));
- return ($test !== false || $test === 'b:0;') ? true : false;
- }
-
- /**
- * FIX_STRING
- * Fixes the string length of a string object that has been serialized but the length is broken
- * @param string $data The string ojbect to recalculate the size on.
- * @return
- */
- static private function fix_serial_string($data) {
-
- $result = array('data'=>$data, 'fixed'=>false, 'tried'=>false);
-
- if (preg_match("/s:[0-9]+:/", $data)) {
- if (! self::is_serialized($data) ) {
- $regex = '!(?<=^|;)s:(\d+)(?=:"(.*?)";(?:}|a:|s:|b:|d:|i:|o:|N;))!s';
- $serial_string = preg_match( '/^s:[0-9]+:"(.*$)/s', trim($data), $matches);
- //Nested serial string
- if ($serial_string) {
- $inner = preg_replace_callback($regex, 'DupDBTextSwap::fix_string_callback', rtrim($matches[1], '";'));
- $serialized_fixed = 's:' . strlen($inner) . ':"' . $inner . '";' ;
- } else {
- $serialized_fixed = preg_replace_callback($regex, 'DupDBTextSwap::fix_string_callback', $data);
- }
-
- if (self::is_serialized($serialized_fixed) ) {
- $result['data'] = $serialized_fixed;
- $result['fixed'] = true;
- }
- $result['tried'] = true;
- }
- }
- return $result;
- }
-
- static private function fix_string_callback($matches) {
- return 's:' . strlen(($matches[2]));
- }
-
- }
-
- //====================================================================================================
- //DATABASE UPDATES
- //====================================================================================================
-
- $ajax2_start = DupUtil::get_microtime();
-
- //MYSQL CONNECTION
- $dbh = @mysqli_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass'], $_POST['dbname']);
- $charset_server = @mysqli_character_set_name($dbh);
- @mysqli_query($dbh, "SET wait_timeout = {$GLOBALS['DB_MAX_TIME']}");
- DupUtil::mysql_set_charset($dbh, $_POST['dbcharset'], $_POST['dbcollate']);
-
- //POST PARAMS
- $_POST['blogname'] = mysqli_real_escape_string($dbh, $_POST['blogname']);
- $_POST['postguid'] = isset($_POST['postguid']) && $_POST['postguid'] == 1 ? 1 : 0;
- $_POST['path_old'] = isset($_POST['path_old']) ? trim($_POST['path_old']) : null;
- $_POST['path_new'] = isset($_POST['path_new']) ? trim($_POST['path_new']) : null;
- $_POST['siteurl'] = isset($_POST['siteurl']) ? rtrim(trim($_POST['siteurl']), '/') : null;
- $_POST['tables'] = isset($_POST['tables']) && is_array($_POST['tables']) ? array_map('stripcslashes', $_POST['tables']) : array();
- $_POST['url_old'] = isset($_POST['url_old']) ? trim($_POST['url_old']) : null;
- $_POST['url_new'] = isset($_POST['url_new']) ? rtrim(trim($_POST['url_new']), '/') : null;
-
- //LOGGING
- $POST_LOG = $_POST;
- unset($POST_LOG['tables']);
- unset($POST_LOG['plugins']);
- unset($POST_LOG['dbpass']);
- ksort($POST_LOG);
-
- //GLOBAL DB-REPLACE
- DupUtil::log("\n\n\n{$GLOBALS['SEPERATOR1']}");
- DupUtil::log('DUPLICATOR INSTALL-LOG');
- DupUtil::log('STEP2 START @ ' . @date('h:i:s') );
- DupUtil::log('NOTICE: NOTICE: Do not post to public sites or forums');
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
- DupUtil::log("CHARSET SERVER:\t{$charset_server}");
- DupUtil::log("CHARSET CLIENT:\t" . @mysqli_character_set_name($dbh));
- DupUtil::log("--------------------------------------");
- DupUtil::log("POST DATA");
- DupUtil::log("--------------------------------------");
- DupUtil::log(print_r($POST_LOG, true));
-
- DupUtil::log("--------------------------------------");
- DupUtil::log("SCANNED TABLES");
- DupUtil::log("--------------------------------------");
- $msg = (isset($_POST['tables']) && count($_POST['tables'] > 0)) ? print_r($_POST['tables'], true) : 'No tables selected to update';
- DupUtil::log($msg);
-
- DupUtil::log("--------------------------------------");
- DupUtil::log("KEEP PLUGINS ACTIVE");
- DupUtil::log("--------------------------------------");
- $msg = (isset($_POST['plugins']) && count($_POST['plugins'] > 0)) ? print_r($_POST['plugins'], true) : 'No plugins selected for activation';
- DupUtil::log($msg);
-
-
- //UPDATE SETTINGS
- $serial_plugin_list = (isset($_POST['plugins']) && count($_POST['plugins'] > 0)) ? @serialize($_POST['plugins']) : '';
- mysqli_query($dbh, "UPDATE `{$GLOBALS['FW_TABLEPREFIX']}options` SET option_value = '{$_POST['blogname']}' WHERE option_name = 'blogname' ");
- mysqli_query($dbh, "UPDATE `{$GLOBALS['FW_TABLEPREFIX']}options` SET option_value = '{$_POST['url_new']}' WHERE option_name = 'home' ");
- mysqli_query($dbh, "UPDATE `{$GLOBALS['FW_TABLEPREFIX']}options` SET option_value = '{$_POST['siteurl']}' WHERE option_name = 'siteurl' ");
- mysqli_query($dbh, "UPDATE `{$GLOBALS['FW_TABLEPREFIX']}options` SET option_value = '{$serial_plugin_list}' WHERE option_name = 'active_plugins' ");
-
- DupUtil::log("--------------------------------------");
- DupUtil::log("GLOBAL DB-REPLACE");
- DupUtil::log("--------------------------------------");
-
- array_push($GLOBALS['REPLACE_LIST'],
- array('search' =>$_POST['url_old'], 'replace'=>$_POST['url_new']),
- array('search' =>$_POST['path_old'], 'replace'=>$_POST['path_new']),
- array('search' =>rtrim(DupUtil::unset_safe_path($_POST['path_old']), '\\'), 'replace'=>rtrim($_POST['path_new'], '/'))
- );
-
- @mysqli_autocommit($dbh, false);
- $report = DupDBTextSwap::load( $dbh, $GLOBALS['REPLACE_LIST'], $_POST['tables'], $GLOBALS['TABLES_SKIP_COLS']);
- @mysqli_commit($dbh);
- @mysqli_autocommit($dbh, true);
-
-
- //BUILD JSON RESPONSE
- $JSON = array();
- $JSON['step1'] = json_decode(urldecode($_POST['json']));
- $JSON['step2'] = $report;
- $JSON['step2']['warn_all'] = 0;
- $JSON['step2']['warnlist'] = array();
-
- DupDBTextSwap::log_stats($report);
- DupDBTextSwap::log_errors($report);
-
- //Reset the postguid data
- if ($_POST['postguid']) {
- mysqli_query($dbh, "UPDATE `{$GLOBALS['FW_TABLEPREFIX']}posts` SET guid = REPLACE(guid, '{$_POST['url_new']}', '{$_POST['url_old']}')");
- $update_guid = @mysqli_affected_rows($dbh) or 0;
- DupUtil::log("Reverted '{$update_guid}' post guid columns back to '{$_POST['url_old']}'");
- }
-
-
- //====================================================================================================
- //FINAL CLEANUP
- //====================================================================================================
- DupUtil::log("\n{$GLOBALS['SEPERATOR1']}");
- DupUtil::log('START FINAL CLEANUP: ' . @date('h:i:s') );
- DupUtil::log("{$GLOBALS['SEPERATOR1']}");
-
- $patterns = array("/'WP_HOME',\s*'.*?'/",
- "/'WP_SITEURL',\s*'.*?'/");
-
- $replace = array("'WP_HOME', " . '\''.$_POST['url_new'].'\'',
- "'WP_SITEURL', " . '\''.$_POST['url_new'].'\'');
-
- $config_file = @file_get_contents('wp-config.php', true);
- $config_file = preg_replace($patterns, $replace, $config_file);
- file_put_contents('wp-config.php', $config_file);
-
-
- //Create Snapshots directory
- if(!file_exists(DUPLICATOR_SSDIR_NAME)) {
- mkdir(DUPLICATOR_SSDIR_NAME, 0755);
- }
- $fp = fopen(DUPLICATOR_SSDIR_NAME . '/index.php', 'w');
- fclose($fp);
-
-
- //WEB CONFIG FILE
- $currdata = parse_url($_POST['url_old']);
- $newdata = parse_url($_POST['url_new']);
- $currpath = DupUtil::add_slash(isset($currdata['path']) ? $currdata['path'] : "");
- $newpath = DupUtil::add_slash(isset($newdata['path']) ? $newdata['path'] : "");
-
- if ($currpath != $newpath) {
- DupUtil::log("HTACCESS CHANGES:");
- @copy('.htaccess', '.htaccess.orig');
- @copy('web.config', 'web.config.orig');
- @unlink('.htaccess');
- @unlink('web.config');
- DupUtil::log("created backup of original .htaccess to htaccess.orig and web.config to web…
Large files files are truncated, but you can click here to view the full file