Пример #1
0
 /**
  *	PluginBuddyImportBuddy()
  *
  *	Default constructor.
  *
  */
 function PluginBuddyImportBuddy()
 {
     // Prevent access to importbuddy.php if it is still in plugin directory.
     if (file_exists(dirname(__FILE__) . '/backupbuddy.php')) {
         echo 'The BackupBuddy importer, ImportBuddy, can ONLY be accessed on the destination server that you wish to import your backup to.<br />';
         echo 'Upload the importer in the root web directory on the destination server and try again.<br /><br />';
         echo 'If you need assistance visit <a href="http://pluginbuddy.com">http://pluginbuddy.com</a>';
         die;
     }
     // Return image if requested.
     if (isset($_GET['ezimg'])) {
         ezimg::showImg($_GET['ezimg']);
     }
     if (isset($_POST['action']) && $_POST['action'] == 'mysql_test') {
         $connect_status = '<font color=red>Failed</font>';
         $connect_status_error = '';
         $select_status = 'N/A';
         $select_status_error = '';
         $overall_status = '<font color=red>Failed</font>';
         $existing_status = 'N/A';
         if (false === @mysql_connect($_POST['server'], $_POST['user'], $_POST['pass'])) {
             // Couldnt connect to server or invalid credentials.
             $connect_status = '<font color=red>Failed</font>';
             $connect_status_error = mysql_error();
             $this->log('mysql ajax test FAILED: Connection failed. Error: ' . mysql_error(), true);
         } else {
             $connect_status = 'Success';
             if (false === @mysql_select_db($_POST['name'])) {
                 $select_status = '<font color=red>Failed</font>';
                 $select_status_error = mysql_error();
                 $this->log('mysql ajax test FAILED: Connected but database access denied. Error: ' . mysql_error(), true);
             } else {
                 $select_status = 'Success';
                 // Check number of tables already existing with this prefix.
                 $result = mysql_query("SHOW TABLES LIKE '" . mysql_real_escape_string($_POST['prefix']) . "%'");
                 if (mysql_num_rows($result) > 0) {
                     $this->log('Database already contains a WordPress installation with this prefix (' . mysql_num_rows($result) . ' tables). Restore halted.', 'error');
                     $existing_status = '<font color=red>Failed</font>';
                     $exiting_status_error = mysql_error();
                 } else {
                     $existing_status = 'Success';
                     $overall_status = 'Success';
                     $this->log('mysql ajax test SUCCESS');
                 }
                 unset($result);
             }
         }
         echo '1. Logging in to server ... ' . $connect_status . '.<br />';
         if ($connect_status != 'Success') {
             echo '&nbsp;&nbsp;&nbsp;&nbsp;Error: ' . $connect_status_error . '<br />';
         }
         echo '2. Verifying database access & permission ... ' . $select_status . '.<br />';
         if ($select_status != 'Success' && $select_status != 'N/A') {
             echo '&nbsp;&nbsp;&nbsp;&nbsp;Error: ' . $select_status_error . '<br />';
         }
         echo '3. Verifying no existing WP data ... ' . $existing_status . '.<br />';
         if ($existing_status != 'Success') {
             echo '&nbsp;&nbsp;&nbsp;&nbsp;Error: WordPress already exists in this database with this prefix.<br />';
         }
         echo '4. Overall mySQL test result ... ' . $overall_status . '.<br />';
         die;
     }
     define('ABSPATH', dirname(__FILE__));
     // Set up options.
     if (isset($_POST['options'])) {
         $this->_options = unserialize(stripslashes(htmlspecialchars_decode($_POST['options'])));
         $this->_options = array_merge($this->_defaults, (array) $this->_options);
         // Add in any defaults not explicitly set yet.
     } else {
         $this->_options = $this->_defaults;
     }
     // If we know the backup file then do some set-up...
     if ($this->_options['file'] != '') {
         // Extract ZIP ID from the ZIP filename.  This is used to find the temp directory in the wp-uploads directory of the backup.
         if ($this->_options['zip_id'] == '') {
             $this->_options['zip_id'] = $this->get_zip_id($this->_options['file']);
         }
     }
     // Set up PHP error levels.
     if ($this->_options['show_php_warnings'] === true) {
         error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
         // HIGH
         $this->log('PHP error reporting set HIGH.');
     } else {
         error_reporting(E_ALL ^ E_NOTICE);
         // LOW
     }
     // Try to set timeouts to 30 minutes.
     header('Keep-Alive: 3600');
     header('Connection: keep-alive');
     ini_set('default_socket_timeout', '3600');
     set_time_limit('3600');
     // Determine the current step.
     if (isset($_GET['step']) && is_numeric($_GET['step'])) {
         $this->_step = $_GET['step'];
     } else {
         $this->_step = 1;
     }
     // Run function for the requested step.
     if (method_exists($this, 'view_step_' . $this->_step)) {
         $this->log('Initiating step #' . $this->_step . '.');
         $this->print_html_header();
         echo "\n\n<!--\n\n";
         print_r($this->_options);
         echo "\n\n-->\n\n";
         call_user_func(array(&$this, 'view_step_' . $this->_step));
         $this->print_html_footer();
         $this->log('Completed step #' . $this->_step . '.');
     } else {
         $this->log('Unable to initiate step #' . $this->_step . '. Halted.', 'error');
         die('ERROR #546542. Invalid step "' . $this->_step . '".');
     }
 }
Пример #2
0
 /**
  *	pluginbuddy_importbuddy()
  *
  *	Default constructor.
  *
  */
 function __construct()
 {
     // Prevent access to importbuddy.php if it is still in plugin directory.
     if (file_exists(dirname(__FILE__) . '/backupbuddy.php')) {
         echo 'The BackupBuddy importer, ImportBuddy, can ONLY be accessed on the destination server that you wish to import your backup to.<br>';
         echo 'Upload the importer in the root web directory on the destination server and try again.<br><br>';
         echo 'If you need assistance visit <a href="http://pluginbuddy.com">http://pluginbuddy.com</a>';
         die;
     }
     define('ABSPATH', dirname(__FILE__) . '/');
     date_default_timezone_set(@date_default_timezone_get());
     // Prevents date() from throwing a warning if the default timezone has not been set.
     // Unpack importbuddy files into importbuddy directory.
     if (!file_exists(ABSPATH . 'importbuddy')) {
         unpack_importbuddy();
     }
     // Return image if requested.
     if (isset($_GET['ezimg'])) {
         require_once 'importbuddy/classes/ezimg.php';
         ezimg::showImg($_GET['ezimg']);
     }
     // Start logging time for steps that report how long they took.
     $this->time_start = microtime(true);
     // Try to prevent browser timeouts. Greedy script limits are handled on the steps that need them.
     header('Keep-Alive: 3600');
     header('Connection: keep-alive');
     // Set up options.
     if (isset($_POST['options'])) {
         $this->_options = unserialize(stripslashes(htmlspecialchars_decode($_POST['options'])));
         $this->_options = array_merge($this->_defaults, (array) $this->_options);
         // Add in any defaults not explicitly set yet.
     } else {
         $this->_options = $this->_defaults;
     }
     if ($this->_options['log_serial'] == '') {
         $this->_options['log_serial'] = $this->rand_string(10);
     }
     // Database step's AJAX-based tester.
     if (isset($_POST['action']) && $_POST['action'] == 'mysql_test') {
         require_once 'importbuddy/classes/mysql_test.php';
     }
     // Set up PHP error levels.
     if ($this->debug === true || $this->_options['show_php_warnings'] === true) {
         error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
         // HIGH
         $this->log('PHP error reporting set HIGH.');
     } else {
         error_reporting(E_ALL ^ E_NOTICE);
         // LOW
     }
     // Detect max execution time for database steps so they can pause when needed for additional PHP processes.
     $this->detected_max_execution_time = str_ireplace('s', '', ini_get('max_execution_time'));
     if (is_numeric($this->detected_max_execution_time) === false) {
         $detected_max_execution_time = 30;
     }
     // Determine the current step.
     if (isset($_GET['step']) && is_numeric($_GET['step'])) {
         $this->_step = $_GET['step'];
     } else {
         $this->_step = 1;
     }
     // Handle importbuddy authentication (if needed).
     $this->has_access = false;
     // default
     if ($this->_defaults['import_password'] == '#PASSWORD#') {
         //$this->has_access = true;
         die('ERROR: A password is required to be set to use this script for security purposes.  This prevents unauthorized usage of the script.');
     } else {
         if (md5($this->_options['password']) == $this->_defaults['import_password']) {
             $this->has_access = true;
         }
         if (isset($_POST['password']) || isset($_GET['v'])) {
             if (md5($_POST['password']) == $this->_defaults['import_password']) {
                 $this->_options['password'] = $_POST['password'];
                 $this->has_access = true;
             }
             if (isset($_GET['v']) && $_GET['v'] == 'xv' . md5($this->_defaults['import_password'] . 'importbuddy')) {
                 $this->has_access = true;
             }
         }
     }
     // Run function for the requested step.
     require_once 'importbuddy/classes/ezimg.php';
     // Handles displaying the current page and running the needed code for that step.
     $mode = 'html';
     if ($mode == 'html') {
         require_once 'importbuddy/classes/view_page.php';
     } elseif ($mode == 'api_1') {
         die('API not implemented yet.');
         if ($this->has_access === true) {
             require_once 'step_' . $this->_step . '_api.php';
         } else {
             $this->status('error', 'Access Denied. You must authenticate first.');
             die("Access Denied.\n");
         }
     }
 }