Пример #1
0
/**
 *	extract()
 *
 *	Extract backup zip file.
 *
 *	@return		array		True if the extraction was a success OR skipping of extraction is set.
 */
function extract_files() {
	if ( true === pb_backupbuddy::$options['skip_files'] ) { // Option to skip all file updating / extracting.
		pb_backupbuddy::status( 'message', 'Skipped extracting files based on debugging options.' );
		return true;
	} else {
		pb_backupbuddy::set_greedy_script_limits();
		
		pb_backupbuddy::status( 'message', 'Unzipping into `' . ABSPATH . '`' );
		
		$backup_archive = ABSPATH . pb_backupbuddy::$options['file'];
		$destination_directory = ABSPATH;
		
		// Set compatibility mode if defined in advanced options.
		$compatibility_mode = false; // Default to no compatibility mode.
		if ( pb_backupbuddy::$options['force_compatibility_medium'] != false ) {
			$compatibility_mode = 'ziparchive';
		} elseif ( pb_backupbuddy::$options['force_compatibility_slow'] != false ) {
			$compatibility_mode = 'pclzip';
		}
		
		// Zip & Unzip library setup.
		require_once( ABSPATH . 'importbuddy/lib/zipbuddy/zipbuddy.php' );
		$_zipbuddy = new pluginbuddy_zipbuddy( ABSPATH, '', 'unzip' );
		
		// Extract zip file & verify it worked.
		if ( true !== ( $result = $_zipbuddy->unzip( $backup_archive, $destination_directory, $compatibility_mode ) ) ) {
			pb_backupbuddy::status( 'error', 'Failed unzipping archive.' );
			pb_backupbuddy::alert( 'Failed unzipping archive.', true );
			return false;
		} else { // Reported success; verify extraction.
			$_backupdata_file = ABSPATH . 'wp-content/uploads/temp_' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php'; // Full backup dat file location
			$_backupdata_file_dbonly = ABSPATH . 'backupbuddy_dat.php'; // DB only dat file location
			$_backupdata_file_new = ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php'; // Full backup dat file location
			if ( !file_exists( $_backupdata_file ) && !file_exists( $_backupdata_file_dbonly ) && !file_exists( $_backupdata_file_new ) ) {
				pb_backupbuddy::status( 'error', 'Error #9004: Key files missing.', 'The unzip process reported success but the backup data file, backupbuddy_dat.php was not found in the extracted files. The unzip process either failed (most likely) or the zip file is not a proper BackupBuddy backup.' );
				pb_backupbuddy::alert( 'Error: Key files missing. The unzip process reported success but the backup data file, backupbuddy_dat.php was not found in the extracted files. The unzip process either failed (most likely) or the zip file is not a proper BackupBuddy backup.', true, '9004' );
				return false;
			}
			pb_backupbuddy::status( 'details', 'Success extracting Zip File "' . ABSPATH . pb_backupbuddy::$options['file'] . '" into "' . ABSPATH . '".' );
			return true;
		}
	}
}
Пример #2
0
 public function extractDatabase()
 {
     $this->_before(__FUNCTION__);
     die(' ERROR #348437843784: DEPRECATED FUNCTION CALL! ');
     $this->_priorRollbackCleanup();
     pb_backupbuddy::status('details', 'Loading zipbuddy.');
     require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
     $zipbuddy = new pluginbuddy_zipbuddy(dirname($this->_state['archive']));
     pb_backupbuddy::status('details', 'Zipbuddy loaded.');
     // Find SQL file location in archive.
     pb_backupbuddy::status('details', 'Calculating possible SQL file locations.');
     $detectedSQLLocation = '';
     $possibleSQLLocations = array();
     $possibleSQLLocations[] = trim(rtrim(str_replace('backupbuddy_dat.php', '', $this->_state['datLocation']), '\\/') . '/db_1.sql', '\\/');
     // SQL file most likely is in the same spot the dat file was.
     $possibleSQLLocations[] = 'db_1.sql';
     // DB backup. v2.x+
     $possibleSQLLocations[] = 'wp-content/uploads/backupbuddy_temp/' . $this->_state['serial'] . '/db_1.sql';
     // Full backup.
     $possibleSQLLocations[] = 'db.sql';
     // DB backup. v1.x
     $possibleSQLLocations[] = 'wp-content/uploads/backupbuddy_temp/' . $this->_state['serial'] . '/db.sql';
     // Full backup v1.x.
     pb_backupbuddy::status('details', 'Possible SQL file locations: `' . implode(';', $possibleSQLLocations) . '`.');
     $possibleSQLLocations = array_unique($possibleSQLLocations);
     foreach ($possibleSQLLocations as $possibleSQLLocation) {
         if (true === $zipbuddy->file_exists($this->_state['archive'], $possibleSQLLocation, $leave_open = true)) {
             $detectedSQLLocation = $possibleSQLLocation;
             break;
         }
     }
     // end foreach.
     if ('' == $detectedSQLLocation) {
         $this->_error('Error #8483783: Unable to find SQL file(s) location.');
         return false;
     }
     pb_backupbuddy::status('details', 'Confirmed SQL file location: `' . $detectedSQLLocation . '`.');
     $this->_state['databaseSettings']['sqlFile'] = $detectedSQLLocation;
     // Get SQL file.
     $files = array($detectedSQLLocation => 'db_1.sql');
     pb_backupbuddy::$filesystem->unlink_recursive($this->_state['tempPath']);
     // Remove if already exists.
     mkdir($this->_state['tempPath']);
     // Make empty directory.
     require pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
     // Extract SQL file.
     pb_backupbuddy::status('details', 'Extracting SQL file(s).');
     if (false === backupbuddy_restore_files::restore($this->_state['archive'], $files, $this->_state['tempPath'], $zipbuddy)) {
         $this->_error('Error #85384: Unable to restore one or more database files.');
         return false;
     }
     pb_backupbuddy::status('details', 'Finished database extraction function.');
     return true;
 }
*
* View contents of a file (text) that is inside a zip archive.
*
*/
pb_backupbuddy::$ui->ajax_header(true, false);
// js, no padding
$archive_file = pb_backupbuddy::_GET('archive');
// archive to extract from.
$file = pb_backupbuddy::_GET('file');
// file to extract.
$serial = backupbuddy_core::get_serial_from_file($archive_file);
// serial of archive.
$temp_file = uniqid();
// temp filename to extract into.
require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
$zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
// Calculate temp directory & lock it down.
$temp_dir = get_temp_dir();
$destination = $temp_dir . 'backupbuddy-' . $serial;
if (!file_exists($destination) && false === mkdir($destination)) {
    $error = 'Error #458485945b: Unable to create temporary location.';
    pb_backupbuddy::status('error', $error);
    die($error);
}
// If temp directory is within webroot then lock it down.
$temp_dir = str_replace('\\', '/', $temp_dir);
// Normalize for Windows.
$temp_dir = rtrim($temp_dir, '/\\') . '/';
// Enforce single trailing slash.
if (FALSE !== stristr($temp_dir, ABSPATH)) {
    // Temp dir is within webroot.
Пример #4
0
 public static function restore($archive_file, $files, $finalPath, &$zipbuddy = null)
 {
     if (!current_user_can(pb_backupbuddy::$options['role_access'])) {
         die('Error #473623. Access Denied.');
     }
     $serial = backupbuddy_core::get_serial_from_file($archive_file);
     // serial of archive.
     $success = false;
     foreach ($files as $file) {
         $file = str_replace('*', '', $file);
         // Remove any wildcard.
         if (file_exists($finalPath . $file) && is_dir($finalPath . $file)) {
             if (($file_count = @scandir($finalPath . $file)) && count($file_count) > 2) {
                 pb_backupbuddy::status('error', __('Error #9036. The destination directory being restored already exists and is NOT empty. The directory will not be restored to prevent inadvertently losing files within the existing directory. Delete existing directory first if you wish to proceed or restore individual files.', 'it-l10n-backupbuddy') . ' Existing directory: `' . $finalPath . $file . '`.');
                 return false;
             }
         }
     }
     if (null === $zipbuddy) {
         require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
         $zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
     }
     // Calculate temp directory & lock it down.
     $temp_dir = get_temp_dir();
     $destination = $temp_dir . 'backupbuddy-' . $serial;
     if (!file_exists($destination) && false === mkdir($destination, 0777, true)) {
         $error = 'Error #458485945: Unable to create temporary location.';
         pb_backupbuddy::status('error', $error);
         return false;
     }
     // If temp directory is within webroot then lock it down.
     $temp_dir = str_replace('\\', '/', $temp_dir);
     // Normalize for Windows.
     $temp_dir = rtrim($temp_dir, '/\\') . '/';
     // Enforce single trailing slash.
     if (FALSE !== stristr($temp_dir, ABSPATH)) {
         // Temp dir is within webroot.
         pb_backupbuddy::anti_directory_browsing($destination);
     }
     unset($temp_dir);
     pb_backupbuddy::status('details', 'Extracting into temporary directory "' . $destination . '".');
     $prettyFilesList = array();
     foreach ($files as $fileSource => $fileDestination) {
         $prettyFilesList[] = $fileSource . ' => ' . $fileDestination;
     }
     pb_backupbuddy::status('details', 'Files to extract: `' . htmlentities(implode(', ', $prettyFilesList)) . '`.');
     unset($prettyFilesList);
     pb_backupbuddy::flush();
     // Do the actual extraction.
     $extract_success = true;
     if (false === $zipbuddy->extract($archive_file, $destination, $files)) {
         pb_backupbuddy::status('error', 'Error #584984458b. Unable to extract.');
         $extract_success = false;
     }
     if (true === $extract_success) {
         // Verify all files/directories to be extracted exist in temp destination directory. If any missing then delete everything and bail out.
         foreach ($files as &$file) {
             $file = str_replace('*', '', $file);
             // Remove any wildcard.
             if (!file_exists($destination . '/' . $file)) {
                 // Cleanup.
                 foreach ($files as $file) {
                     @trigger_error('');
                     // Clear out last error.
                     @unlink($destination . '/' . $file);
                     $last_error = error_get_last();
                     if (is_array($last_error)) {
                         pb_backupbuddy::status('error', $last_error['message'] . ' File: `' . $last_error['file'] . '`. Line: `' . $last_error['line'] . '`.');
                     }
                 }
                 pb_backupbuddy::status('error', 'Error #854783474. One or more expected files / directories missing.');
                 $extract_success = false;
                 break;
             }
         }
         unset($file);
         // Made it this far so files all exist. Move them all.
         foreach ($files as $file) {
             @trigger_error('');
             // Clear out last error.
             if (false === @rename($destination . '/' . $file, $finalPath . $file)) {
                 $last_error = error_get_last();
                 if (is_array($last_error)) {
                     //print_r( $last_error );
                     pb_backupbuddy::status('error', $last_error['message'] . ' File: `' . $last_error['file'] . '`. Line: `' . $last_error['line'] . '`.');
                 }
                 $error = 'Error #9035. Unable to move restored file `' . $destination . '/' . $file . '` to `' . $finalPath . $file . '`. Verify permissions on destination location & that the destination directory/file does not already exist.';
                 pb_backupbuddy::status('error', $error);
             } else {
                 $details = 'Moved `' . $destination . '/' . $file . '` to `' . $finalPath . $file . '`.<br>';
                 pb_backupbuddy::status('details', $details);
                 $success = true;
             }
         }
     }
     // end extract success.
     // Try to cleanup.
     if (file_exists($destination)) {
         if (false === pb_backupbuddy::$filesystem->unlink_recursive($destination)) {
             pb_backupbuddy::status('details', 'Unable to delete temporary holding directory `' . $destination . '`.');
         } else {
             pb_backupbuddy::status('details', 'Cleaned up temporary files.');
         }
     }
     if (true === $success) {
         pb_backupbuddy::status('message', 'File retrieval completed successfully.');
         return true;
     } else {
         return false;
     }
 }
Пример #5
0
 public static function getDatArrayFromZip($file)
 {
     require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
     $zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
     $serial = self::get_serial_from_file($file);
     if (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, $find = 'wp-content/uploads/backupbuddy_temp/' . $serial . '/backupbuddy_dat.php') === true) {
         // Post 2.0 full backup
     } elseif (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, $find = 'wp-content/uploads/temp_' . $serial . '/backupbuddy_dat.php') === true) {
         // Pre 2.0 full backup
     } elseif (pb_backupbuddy::$classes['zipbuddy']->file_exists($file, $find = 'backupbuddy_dat.php') === true) {
         // DB backup
     } else {
         // Could not find DAt file.
         return false;
     }
     // Calculate temp directory & lock it down.
     $temp_dir = get_temp_dir();
     $destination = $temp_dir;
     if (!file_exists($destination) && false === mkdir($destination)) {
         $error = 'Error #458485945b: Unable to create temporary location.';
         pb_backupbuddy::status('error', $error);
         die($error);
     }
     // If temp directory is within webroot then lock it down.
     $temp_dir = str_replace('\\', '/', $temp_dir);
     // Normalize for Windows.
     $temp_dir = rtrim($temp_dir, '/\\') . '/';
     // Enforce single trailing slash.
     if (FALSE !== stristr($temp_dir, ABSPATH)) {
         // Temp dir is within webroot.
         pb_backupbuddy::anti_directory_browsing($destination);
     }
     unset($temp_dir);
     $destFilename = 'temp_dat_read-' . $serial . '.php';
     $extractions = array($find => $destFilename);
     $extract_result = $zipbuddy->extract($file, $destination, $extractions);
     if (false === $extract_result) {
         // failed.
         return array();
     } else {
         $datArray = self::get_dat_file_array($destination . 'temp_dat_read-' . $serial . '.php');
         @unlink($temp_dir . $destFilename);
         if (is_array($datArray)) {
             return $datArray;
         } else {
             return array();
         }
     }
 }
Пример #6
0
    function restore_file_view()
    {
        pb_backupbuddy::$ui->ajax_header(true, false);
        // js, no padding
        $archive_file = pb_backupbuddy::_GET('archive');
        // archive to extract from.
        $file = pb_backupbuddy::_GET('file');
        // file to extract.
        $serial = backupbuddy_core::get_serial_from_file($archive_file);
        // serial of archive.
        $temp_file = uniqid();
        // temp filename to extract into.
        require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
        $zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
        // Calculate temp directory & lock it down.
        $temp_dir = get_temp_dir();
        $destination = $temp_dir . 'backupbuddy-' . $serial;
        if (!file_exists($destination) && false === mkdir($destination)) {
            $error = 'Error #458485945: Unable to create temporary location.';
            pb_backupbuddy::status('error', $error);
            die($error);
        }
        // If temp directory is within webroot then lock it down.
        $temp_dir = str_replace('\\', '/', $temp_dir);
        // Normalize for Windows.
        $temp_dir = rtrim($temp_dir, '/\\') . '/';
        // Enforce single trailing slash.
        if (FALSE !== stristr($temp_dir, ABSPATH)) {
            // Temp dir is within webroot.
            pb_backupbuddy::anti_directory_browsing($destination);
        }
        unset($temp_dir);
        $message = 'Extracting "' . $file . '" from archive "' . $archive_file . '" into temporary file "' . $destination . '". ';
        echo '<!-- ';
        pb_backupbuddy::status('details', $message);
        echo $message;
        $extractions = array($file => $temp_file);
        $extract_result = $zipbuddy->extract(backupbuddy_core::getBackupDirectory() . $archive_file, $destination, $extractions);
        if (false === $extract_result) {
            // failed.
            echo ' -->';
            $error = 'Error #584984458. Unable to extract.';
            pb_backupbuddy::status('error', $error);
            die($error);
        } else {
            // success.
            _e('Success.', 'it-l10n-backupbuddy');
            echo ' -->';
            ?>
			<textarea readonly="readonly" wrap="off" style="width: 100%; min-height: 175px; height: 100%; margin: 0;"><?php 
            echo file_get_contents($destination . '/' . $temp_file);
            ?>
</textarea>
			<?php 
            //unlink( $destination . '/' . $temp_file );
        }
        // Try to cleanup.
        if (file_exists($destination)) {
            if (false === pb_backupbuddy::$filesystem->unlink_recursive($destination)) {
                pb_backupbuddy::status('details', 'Unable to delete temporary holding directory `' . $destination . '`.');
            } else {
                pb_backupbuddy::status('details', 'Cleaned up temporary files.');
            }
        }
        pb_backupbuddy::$ui->ajax_footer();
        die;
    }
// Server info page available zip methods update.
/* refresh_zip_methods()
*
* Server Info page refreshing available zip methods. Useful since these are normally cached.
*
*/
// Make sure the legacy method transient is gone
delete_transient('pb_backupbuddy_avail_zip_methods_classic');
if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
    // We don't have an instance of zipbuddy so make sure we can create one
    require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
    // Find out the transient name(s) and delete them
    $transients = pluginbuddy_zipbuddy::get_transient_names_static();
    foreach ($transients as $transient) {
        delete_transient($transient);
    }
    // Instantiating a class object will renew the deleted method transient
    pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(ABSPATH);
} else {
    // We have an instance of zipbuddy so we can use it
    // Find out the transient name(s) and delete them
    $transients = pluginbuddy_zipbuddy::get_transient_names_static();
    foreach ($transients as $transient) {
        delete_transient($transient);
    }
    // Just call the refresh function
    pb_backupbuddy::$classes['zipbuddy']->refresh_zip_methods();
}
// Now simply provide the list of methods
echo implode(', ', pb_backupbuddy::$classes['zipbuddy']->_zip_methods);
die;
Пример #8
0
    public function restore_file_restore()
    {
        $success = false;
        pb_backupbuddy::$ui->ajax_header(true, false);
        // js, no padding
        ?>
		<script type="text/javascript">
			function pb_status_append( status_string ) {
				target_id = 'pb_backupbuddy_status'; // importbuddy_status or pb_backupbuddy_status
				if( jQuery( '#' + target_id ).length == 0 ) { // No status box yet so suppress.
					return;
				}
				jQuery( '#' + target_id ).append( "\n" + status_string );
				textareaelem = document.getElementById( target_id );
				textareaelem.scrollTop = textareaelem.scrollHeight;
			}
		</script>
		<?php 
        global $pb_backupbuddy_js_status;
        $pb_backupbuddy_js_status = true;
        echo pb_backupbuddy::status_box('Restoring . . .');
        echo '<div id="pb_backupbuddy_working" style="width: 100px;"><br><center><img src="' . pb_backupbuddy::plugin_url() . '/images/working.gif" title="Working... Please wait as this may take a moment..."></center></div>';
        pb_backupbuddy::set_status_serial('restore');
        global $wp_version;
        pb_backupbuddy::status('details', 'BackupBuddy v' . pb_backupbuddy::settings('version') . ' using WordPress v' . $wp_version . ' on ' . PHP_OS . '.');
        $archive_file = pb_backupbuddy::_GET('archive');
        // archive to extract from.
        $files = pb_backupbuddy::_GET('files');
        // file to extract.
        $files_array = explode(',', $files);
        $files = array();
        foreach ($files_array as $file) {
            if (substr($file, -1) == '/') {
                // If directory then add wildcard.
                $file = $file . '*';
            }
            $files[$file] = $file;
        }
        unset($files_array);
        $serial = backupbuddy_core::get_serial_from_file($archive_file);
        // serial of archive.
        foreach ($files as $file) {
            $file = str_replace('*', '', $file);
            // Remove any wildcard.
            if (file_exists(ABSPATH . $file) && is_dir(ABSPATH . $file)) {
                if (($file_count = @scandir(ABSPATH . $file)) && count($file_count) > 2) {
                    pb_backupbuddy::status('error', __('Error #9036. The destination directory being restored already exists and is NOT empty. The directory will not be restored to prevent inadvertently losing files within the existing directory. Delete existing directory first if you wish to proceed or restore individual files.', 'it-l10n-backupbuddy') . ' Existing directory: `' . ABSPATH . $file . '`.');
                    echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
                    pb_backupbuddy::flush();
                    pb_backupbuddy::$ui->ajax_footer();
                    die;
                }
            }
        }
        require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
        $zipbuddy = new pluginbuddy_zipbuddy(backupbuddy_core::getBackupDirectory());
        // Calculate temp directory & lock it down.
        $temp_dir = get_temp_dir();
        $destination = $temp_dir . 'backupbuddy-' . $serial;
        if (!file_exists($destination) && false === mkdir($destination, 0777, true)) {
            $error = 'Error #458485945: Unable to create temporary location.';
            pb_backupbuddy::status('error', $error);
            echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
            pb_backupbuddy::flush();
            pb_backupbuddy::$ui->ajax_footer();
            die;
        }
        // If temp directory is within webroot then lock it down.
        $temp_dir = str_replace('\\', '/', $temp_dir);
        // Normalize for Windows.
        $temp_dir = rtrim($temp_dir, '/\\') . '/';
        // Enforce single trailing slash.
        if (FALSE !== stristr($temp_dir, ABSPATH)) {
            // Temp dir is within webroot.
            pb_backupbuddy::anti_directory_browsing($destination);
        }
        unset($temp_dir);
        pb_backupbuddy::status('details', 'Extracting into temporary directory "' . $destination . '".');
        pb_backupbuddy::status('details', 'Files to extract: `' . htmlentities(pb_backupbuddy::_GET('files')) . '`.');
        // Make sure temp subdirectories exist.
        /*
        foreach( $files as $file => $null ) {
        	mkdir( $destination . '/' . basename( $file ), 0777, true );
        }
        */
        pb_backupbuddy::flush();
        $extract_success = true;
        $extract_result = $zipbuddy->extract(backupbuddy_core::getBackupDirectory() . $archive_file, $destination, $files);
        if (false === $extract_result) {
            // failed.
            pb_backupbuddy::status('error', 'Error #584984458b. Unable to extract.');
            $extract_success = false;
        } else {
            // success.
            // Verify all files/directories to be extracted exist in temp destination directory. If any missing then delete everything and bail out.
            foreach ($files as &$file) {
                $file = str_replace('*', '', $file);
                // Remove any wildcard.
                if (!file_exists($destination . '/' . $file)) {
                    // Cleanup.
                    foreach ($files as $file) {
                        @trigger_error('');
                        // Clear out last error.
                        @unlink($destination . '/' . $file);
                        $last_error = error_get_last();
                        if (is_array($last_error)) {
                            pb_backupbuddy::status('error', $last_error['message'] . ' File: `' . $last_error['file'] . '`. Line: `' . $last_error['line'] . '`.');
                        }
                    }
                    pb_backupbuddy::status('error', 'Error #854783474. One or more expected files / directories missing.');
                    $extract_success = false;
                    break;
                }
            }
            unset($file);
        }
        if (true === $extract_success) {
            // Made it this far so files all exist. Move them all.
            foreach ($files as $file) {
                @trigger_error('');
                // Clear out last error.
                if (false === @rename($destination . '/' . $file, ABSPATH . $file)) {
                    $last_error = error_get_last();
                    if (is_array($last_error)) {
                        //print_r( $last_error );
                        pb_backupbuddy::status('error', $last_error['message'] . ' File: `' . $last_error['file'] . '`. Line: `' . $last_error['line'] . '`.');
                    }
                    $error = 'Error #9035. Unable to move restored file `' . $destination . '/' . $file . '` to `' . ABSPATH . $file . '`. Verify permissions on destination location & that the destination directory/file does not already exist.';
                    pb_backupbuddy::status('error', $error);
                } else {
                    $details = 'Moved `' . $destination . '/' . $file . '` to `' . ABSPATH . $file . '`.<br>';
                    pb_backupbuddy::status('details', $details);
                    $success = true;
                }
            }
        }
        // end extract succeeded.
        // Try to cleanup.
        if (file_exists($destination)) {
            if (false === pb_backupbuddy::$filesystem->unlink_recursive($destination)) {
                pb_backupbuddy::status('details', 'Unable to delete temporary holding directory `' . $destination . '`.');
            } else {
                pb_backupbuddy::status('details', 'Cleaned up temporary files.');
            }
        }
        if (true === $success) {
            pb_backupbuddy::status('message', 'Restore completed successfully.');
        }
        echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
        pb_backupbuddy::flush();
        pb_backupbuddy::$ui->ajax_footer();
        die;
    }
Пример #9
0
$this->status('message', 'Unzipping `' . $backup_archive . '` into `' . $destination_directory . '`');
if (isset($this->advanced_options['skip_files']) && $this->advanced_options['skip_files'] == 'true') {
    $this->status('message', 'Skipping file extraction based on advanced settings.');
    $result = true;
} else {
    // Set compatibility mode if defined in advanced options.
    $compatibility_mode = false;
    // Default to no compatibility mode.
    if (isset($this->advanced_options['force_compatibility_medium']) && $this->advanced_options['force_compatibility_medium'] == "true") {
        $compatibility_mode = 'ziparchive';
    } elseif (isset($this->advanced_options['force_compatibility_slow']) && $this->advanced_options['force_compatibility_slow'] == "true") {
        $compatibility_mode = 'pclzip';
    }
    // Zip & Unzip library setup.
    require_once $this->_pluginPath . '/lib/zipbuddy/zipbuddy.php';
    $_zipbuddy = new pluginbuddy_zipbuddy(ABSPATH, '', 'unzip');
    $_zipbuddy->set_status_callback(array(&$this, 'status'));
    $result = $_zipbuddy->unzip($backup_archive, $destination_directory, $compatibility_mode);
}
echo '<script type="text/javascript">jQuery("#pb_importbuddy_working").hide();</script>';
flush();
// Extract zip file & verify it worked.
if (true !== $result) {
    $this->status('error', 'Failed unzipping archive.');
    $this->alert('Failed unzipping archive.');
    $failed = true;
} else {
    // Reported success; verify extraction.
    if (!file_exists($destination_directory . 'wp-config.php')) {
        $this->status('error', 'Error #9004: Key files missing.', 'The unzip process reported success but the backup data file, backupbuddy_dat.php was not found in the extracted files. The unzip process either failed (most likely) or the zip file is not a proper BackupBuddy backup.');
        $this->alert('Error: Key files missing.', 'The unzip process reported success but the backup data file, backupbuddy_dat.php was not found in the extracted files. The unzip process either failed (most likely) or the zip file is not a proper BackupBuddy backup.', '9004');
Пример #10
0
 public function refresh_zip_methods()
 {
     // Make sure the legacy method transient is gone
     delete_transient('pb_backupbuddy_avail_zip_methods_classic');
     if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
         // We don't have an instance of zipbuddy so make sure we can create one
         require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
         // Find out the transient name(s) and delete them
         $transients = pluginbuddy_zipbuddy::get_transient_names_static();
         foreach ($transients as $transient) {
             delete_transient($transient);
         }
         // Instantiating a class object will renew the deleted method transient
         pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(ABSPATH);
     } else {
         // We have an instance of zipbuddy so we can use it
         // Find out the transient name(s) and delete them
         $transients = pluginbuddy_zipbuddy::get_transient_names_static();
         foreach ($transients as $transient) {
             delete_transient($transient);
         }
         // Just call the refresh function
         pb_backupbuddy::$classes['zipbuddy']->refresh_zip_methods();
     }
     // Now simply provide the list of methods
     echo implode(', ', pb_backupbuddy::$classes['zipbuddy']->_zip_methods);
     die;
 }
Пример #11
0
 function ajax_site_export()
 {
     $this->_parent->set_greedy_script_limits();
     global $wpdb, $current_site, $current_blog;
     $blog_id = absint($current_blog->blog_id);
     check_ajax_referer('export-site');
     $return_args = array('completion' => 0, 'message' => '', 'errors' => false);
     require_once $this->_parent->_pluginPath . '/lib/zipbuddy/zipbuddy.php';
     $step = absint($_POST['step']);
     $zip_id = sanitize_text_field($_POST['zip_id']);
     $upload_dir = wp_upload_dir();
     $original_upload_base_dir = $upload_dir['basedir'];
     $extract_files_to = $original_upload_base_dir . '/' . $zip_id;
     switch ($step) {
         case 1:
             //Step 1 - Download a copy of WordPress
             $wp_url = 'http://wordpress.org/latest.zip';
             $wp_file = download_url($wp_url);
             if (is_wp_error($wp_file)) {
                 $return_args['errors'] = true;
                 $return_args['message'] = $wp_file->get_error_message();
                 $this->log('MS-MS Step 1 - ' . $wp_file->get_error_message(), 'error');
             } else {
                 $return_args['message'] = __('WordPress Successfully Downloaded - Extracting WordPress to a Temporary Directory', 'it-l10n-backupbuddy');
                 $return_args['completion'] = 5;
                 $return_args['wp_file'] = $wp_file;
             }
             break;
         case 2:
             //Step 2 - Extract WP into a separate directory
             $wp_file = file_exists($_POST['wp_file']) ? $_POST['wp_file'] : false;
             if (!$wp_file) {
                 $return_args['errors'] = true;
                 $return_args['message'] = __('WordPress file could not be located', 'it-l10n-backupbuddy');
                 $this->log('MS-MS Step 2 - ' . __('WordPress file could not be located', 'it-l10n-backupbuddy'), 'error');
             } else {
                 $return_args['debug'] = $extract_files_to;
                 $return_args['message'] = __('WordPress extracted - Creating installation file', 'it-l10n-backupbuddy');
                 $return_args['completion'] = 15;
                 $zipbuddy = new pluginbuddy_zipbuddy($extract_files_to);
                 ob_start();
                 //todo - upload to wp-contennt
                 //when merging, update extract_files to use new importbuddy version of zip / unzip functionality
                 $zipbuddy->unzip($wp_file, $extract_files_to);
                 $return_args['debug'] = ob_get_clean();
                 unlink($wp_file);
             }
             break;
         case 3:
             //Step 3 - Create new WP-Config File
             $wp_config_path = $extract_files_to . '/wordpress/';
             if (!file_exists($wp_config_path)) {
                 $return_args['errors'] = true;
                 $return_args['message'] = __('Temporary WordPress installation not found', 'it-l10n-backupbuddy');
                 $return_args['debug'] = $wp_config_path;
                 $this->log('MS-MS Step 3 - ' . __('Temporary WordPress installation file could not be located', 'it-l10n-backupbuddy') . $wp_config_path, 'error');
             } else {
                 $to_file = "<?php\n";
                 $to_file .= sprintf("define( 'DB_NAME', '%s' );\n", '');
                 $to_file .= sprintf("define( 'DB_USER', '%s' );\n", '');
                 $to_file .= sprintf("define( 'DB_PASSWORD', '%s' );\n", '');
                 $to_file .= sprintf("define( 'DB_HOST', '%s' );\n", '');
                 $charset = defined('DB_CHARSET') ? DB_CHARSET : '';
                 $collate = defined('DB_COLLATE') ? DB_COLLATE : '';
                 $to_file .= sprintf("define( 'DB_CHARSET', '%s' );\n", $charset);
                 $to_file .= sprintf("define( 'DB_COLLATE', '%s' );\n", $collate);
                 //Attempt to remotely retrieve salts
                 $salts = wp_remote_get('https://api.wordpress.org/secret-key/1.1/salt/');
                 if (!is_wp_error($salts)) {
                     $to_file .= wp_remote_retrieve_body($salts) . "\n";
                 }
                 $to_file .= sprintf("define( 'WPLANG', '%s' );\n", WPLANG);
                 $to_file .= sprintf('$table_prefix = \'%s\';' . "\n", 'bbms' . $blog_id . '_');
                 $to_file .= "if ( !defined('ABSPATH') ) { \n\tdefine('ABSPATH', dirname(__FILE__) . '/'); }";
                 $to_file .= "/** Sets up WordPress vars and included files. */\n\n\t\t\t\t\t\trequire_once(ABSPATH . 'wp-settings.php');";
                 $to_file .= "\n?>";
                 $wp_config_path .= 'wp-config.php';
                 //Create the file, save, and close
                 $file_handle = fopen($wp_config_path, 'w');
                 fwrite($file_handle, $to_file);
                 fclose($file_handle);
                 //Prepare the response
                 $return_args['debug'] = $extract_files_to;
                 $return_args['message'] = __('Installation file created - Copying Over Plugins.', 'it-l10n-backupbuddy');
                 $return_args['completion'] = 25;
             }
             break;
         case 4:
             //Step 4 - Copy over plugins
             //Move over plugins
             $plugin_items = get_transient($zip_id);
             //Populate $items_to_copy for all plugins to copy over
             if (is_array($plugin_items)) {
                 $items_to_copy = array();
                 //Get content directories by using this plugin as a base
                 $content_dir = $dropin_plugins_dir = dirname(dirname(dirname(rtrim(plugin_dir_path(__FILE__), '/'))));
                 $mu_plugins_dir = $content_dir . '/mu-plugins';
                 $plugins_dir = $content_dir . '/plugins';
                 //Get the special plugins (mu, dropins, network activated)
                 foreach ($plugin_items as $type => $plugins) {
                     foreach ($plugins as $plugin) {
                         if ($type == 'mu') {
                             $items_to_copy[$plugin] = $mu_plugins_dir . '/' . $plugin;
                         } elseif ($type == 'dropin') {
                             $items_to_copy[$plugin] = $dropin_plugins_dir . '/' . $plugin;
                         } elseif ($type == 'network' || $type == 'site') {
                             //Determine if we're a folder-based plugin, or a file-based plugin (such as hello.php)
                             $plugin_path = dirname($plugins_dir . '/' . $plugin);
                             if (basename($plugin_path) == 'plugins') {
                                 $plugin_path = $plugins_dir . '/' . $plugin;
                             }
                             $items_to_copy[basename($plugin_path)] = $plugin_path;
                         }
                     }
                     //end foreach $plugins
                 }
                 //end foreach special plugins
                 //Copy the files over
                 $wp_dir = '';
                 if (count($items_to_copy) > 0) {
                     $wp_dir = $extract_files_to . '/wordpress/';
                     $wp_plugin_dir = $wp_dir . '/wp-content/plugins/';
                     foreach ($items_to_copy as $file => $original_destination) {
                         if (file_exists($original_destination) && file_exists($wp_plugin_dir)) {
                             $this->copy($original_destination, $wp_plugin_dir . $file);
                         }
                     }
                 }
                 //Prepare the response
                 $return_args['debug'] = $wp_dir;
                 $return_args['message'] = __('Plugins copied over.  Now copying over the active theme.', 'it-l10n-backupbuddy');
                 $return_args['completion'] = 50;
             } else {
                 //Nothing has technically failed at this point - There just aren't any plugins to copy over
                 $return_args['message'] = __('Plugins copied over.  Now copying over the active theme.', 'it-l10n-backupbuddy');
                 $return_args['completion'] = 50;
                 $this->log('MS-MS Step 4 - ' . __('No plugins to copy over', 'it-l10n-backupbuddy'), 'error');
             }
             break;
         case 5:
             //Step 5 - Copy over themes
             $current_theme = current_theme_info();
             $template_dir = $current_theme->template_dir;
             $stylesheet_dir = $current_theme->stylesheet_dir;
             //If $template_dir and $stylesheet_dir don't match, that means we have a child theme and need to copy over the parent also
             $items_to_copy = array();
             $items_to_copy[basename($template_dir)] = $template_dir;
             if ($template_dir != $stylesheet_dir) {
                 $items_to_copy[basename($stylesheet_dir)] = $stylesheet_dir;
             }
             //Copy the files over
             if (count($items_to_copy) > 0) {
                 $wp_dir = $extract_files_to . '/wordpress/';
                 $wp_theme_dir = $wp_dir . '/wp-content/themes/';
                 foreach ($items_to_copy as $file => $original_destination) {
                     if (file_exists($original_destination) && file_exists($wp_theme_dir)) {
                         $this->copy($original_destination, $wp_theme_dir . $file);
                     }
                 }
             }
             $return_args['debug'] = $wp_dir;
             $return_args['message'] = __('Theme has been copied over.  Now copying over media files.', 'it-l10n-backupbuddy');
             $return_args['completion'] = 60;
             break;
         case 6:
             //Step 6 - Copy over media/upload files
             $upload_dir = wp_upload_dir();
             $original_upload_base_dir = $upload_dir['basedir'];
             $destination_upload_base_dir = $extract_files_to . '/wordpress/wp-content/uploads';
             $this->copy($original_upload_base_dir, $destination_upload_base_dir, array('ignore_files' => array($zip_id)));
             $return_args['debug'] = $destination_upload_base_dir;
             $return_args['message'] = __('Media has been copied over.  Now preparing the export.', 'it-l10n-backupbuddy');
             $return_args['completion'] = 70;
             break;
         case 7:
             //Step 7 - Create Users Table
             //Get users of current site
             global $wpdb, $current_blog;
             $user_args = array('blog_id' => $current_blog->blog_id);
             $users = get_users($user_args);
             //Copy over the user and usermeta tables
             $found_tables = array($wpdb->users, $wpdb->usermeta);
             $user_tablename = $usermeta_tablename = '';
             $sql_to_execute = array();
             if ($found_tables) {
                 foreach ($found_tables as $index => $tablename) {
                     $new_table = '';
                     if (strstr($tablename, 'users')) {
                         $new_table = $user_tablename = $wpdb->prefix . 'users';
                     }
                     if (strstr($tablename, 'usermeta')) {
                         $new_table = $usermeta_tablename = $wpdb->prefix . 'usermeta';
                     }
                     $sql_to_execute[] = sprintf('CREATE TABLE %1$s LIKE %2$s', $new_table, $tablename);
                     $sql_to_execute[] = sprintf('INSERT %1$s SELECT * FROM %2$s', $new_table, $tablename);
                     //Couldn't use $wpdb->prepare here because sql doesn't like quotes around the tablenames
                 }
             }
             //Tables have been created, now execute a query to remove the users and user data that doesn't matter
             $users_to_capture = array();
             if ($users) {
                 foreach ($users as $user) {
                     array_push($users_to_capture, $user->ID);
                 }
             }
             $users_to_capture = implode(',', $users_to_capture);
             $sql_to_execute[] = sprintf("DELETE from %s WHERE ID NOT IN( %s )", $user_tablename, $users_to_capture);
             $sql_to_execute[] = sprintf("DELETE from %s WHERE user_id NOT IN( %s )", $usermeta_tablename, $users_to_capture);
             //Execute queries
             foreach ($sql_to_execute as $sql) {
                 $wpdb->query($sql);
             }
             //Return the response
             $return_args['message'] = __('Building the export file and cleaning up.', 'it-l10n-backupbuddy');
             $return_args['completion'] = 80;
             break;
         case 8:
             //Step 8 - Backup
             global $current_site, $wpdb;
             require_once $this->_parent->_pluginPath . '/classes/backup.php';
             $backup_directory = $extract_files_to . '/wordpress/';
             $temp_directory = $backup_directory . '/wp-content/uploads/backupbuddy_temp/';
             $prefix = $wpdb->prefix;
             $pluginbuddy_backup = new pluginbuddy_backupbuddy_backup($this->_parent);
             //Get a list of tables to backup
             $query = "SHOW TABLES LIKE '{$prefix}%'";
             $results = $wpdb->get_results($query, ARRAY_A);
             $tables_to_ignore = array($prefix . 'blogs', $prefix . 'blog_versions', $prefix . 'site', $prefix . 'sitemeta', $prefix . 'registration_log', $prefix . 'signups', $prefix . 'sitecategories');
             $list_of_tables = array();
             foreach ($results as $results_key => $table_array) {
                 foreach ($table_array as $key => $tablename) {
                     if (preg_match("/^{$prefix}(?!\\d+)/", $tablename) && !in_array($tablename, $tables_to_ignore)) {
                         array_push($list_of_tables, $tablename);
                     }
                 }
             }
             //Do the database dump
             $backup_serial = $pluginbuddy_backup->rand_string(10);
             $dat_directory = $temp_directory . '/' . $backup_serial . '/';
             $backup = array('backup_time' => time(), 'serial' => $backup_serial, 'backup_type' => 'full', 'temp_directory' => $dat_directory, 'backup_mode' => '2');
             $options = array('include_tables' => array(), 'temp_directory' => $dat_directory, 'high_security' => '1', 'backup_nonwp_tables' => '0');
             //Create the temp directory
             $this->_parent->mkdir_recursive($dat_directory);
             $pluginbuddy_backup->anti_directory_browsing($temp_directory);
             //Create the dat file
             $pluginbuddy_backup->backup_create_dat_file($backup, $options, true);
             //Create the database dump
             $pluginbuddy_backup->backup_create_database_dump($backup, $options, $list_of_tables, true);
             //Archive the file
             require_once $this->_parent->_pluginPath . '/lib/zipbuddy/zipbuddy.php';
             $zipbuddy = new pluginbuddy_zipbuddy($backup_directory);
             $archive_directory = $this->_parent->_options['backup_directory'];
             $this->_parent->mkdir_recursive($archive_directory);
             $pluginbuddy_backup->anti_directory_browsing($archive_directory);
             $archive_file = $archive_directory . 'backup-' . $this->_parent->backup_prefix() . '-' . str_replace('-', '_', date('Y-m-d')) . '-' . $backup_serial . '.zip';
             $zipbuddy->add_directory_to_zip($archive_file, $backup_directory, true);
             //Return the response
             $archive_file_url = str_replace(ABSPATH, '', $archive_file);
             $archive_file_url = site_url($archive_file_url);
             $file_args = sprintf('<a href="%s">%s</a>', $archive_file_url, __('Download Now', 'it-l10n-backupbuddy'));
             $return_args['message'] = sprintf(__('You\'re done!  The export file is ready for download. %s', 'it-l10n-backupbuddy'), $file_args);
             $return_args['completion'] = 100;
             //Cleanup
             $this->_parent->delete_directory_recursive($extract_files_to);
             break;
     }
     //end switch
     die(json_encode($return_args));
 }