Beispiel #1
0
 public function execute($command)
 {
     if (stristr(PHP_OS, 'WIN') && !stristr(PHP_OS, 'DARWIN')) {
         // Windows; do nothing.
     } else {
         // Linux/Mac
         $command = 'PATH=$PATH:/usr/bin/:/usr/local/bin/:usr/local/bin:/usr/local/sbin/:/usr/sbin/:/sbin/:/usr/:/bin/' . '; ' . $command;
     }
     // Output command (strips mysqldump passwords).
     if (strstr($command, '--password='******'--password='******' ', $password_portion_begin);
         //pb_backupbuddy::status( 'details', 'pass start: `' . $password_portion_begin . '`. pass end: `' . $password_portion_end . '`' );
         $password_portion = substr($command, $password_portion_begin, $password_portion_end - $password_portion_begin);
         //pb_backupbuddy::status( 'details', 'pass portion: `' . $password_portion . '`.' );
         $unpassworded_command = str_replace($password_portion, '--password=*HIDDEN*', $command);
         pb_backupbuddy::status('details', 'exec() command (password hidden) `' . $unpassworded_command . '` (with path definition).');
         unset($unpassworded_command);
     } else {
         pb_backupbuddy::status('details', 'exec() command `' . $command . '` (with path definition).');
     }
     @exec($command, $exec_output, $exec_exit_code);
     pb_backupbuddy::status('details', 'exec() command output: `' . implode(',', $exec_output) . '`; Exit code: `' . $exec_exit_code . '`; Exit code description: `' . pb_backupbuddy::$filesystem->exit_code_lookup($exec_exit_code) . '`');
     return array($exec_output, $exec_exit_code);
 }
Beispiel #2
0
function finalActions($restore)
{
    // Rename .htaccess.bb_temp back to .htaccess.
    $restore->renameHtaccessTempBack();
    // Remove any temporary .maintenance file created by ImportBuddy.
    $restore->maintenanceOff($onlyOurCreatedFile = true);
    // Remove any temporary index.htm file created by ImportBuddy.
    $restore->scrubIndexFiles();
    // TODO: Make these thnings be able to output stuff into the cleanupSettings.ejs template. Add functions?
    // Update wpconfig if needed.
    $wpconfig_result = $restore->migrateWpConfig();
    if ($wpconfig_result !== true) {
        pb_backupbuddy::alert('Error: Unable to update wp-config.php file. Verify write permissions for the wp-config.php file then refresh this page. You may manually update your wp-config.php file by changing it to the following:<textarea readonly="readonly" style="width: 80%;">' . $wpconfig_result . '</textarea>');
    }
    // Scan for 'trouble' such as a remaining .maintenance file, index.htm, index.html, missing wp-config.php, missing .htaccess, etc etc.
    $problems = $restore->troubleScan();
    if (count($problems) > 0) {
        $restore->_state['potentialProblems'] = $problems;
        $trouble_text = '';
        foreach ($problems as $problem) {
            $trouble_text .= '<li>' . $problem . '</li>';
        }
        $trouble_text = '<ul>' . $trouble_text . '</ul>';
        pb_backupbuddy::status('warning', 'One or more potential issues detected that may require your attention: ' . $trouble_text);
    }
    pb_backupbuddy::status('details', 'Finished final actions function.');
}
Beispiel #3
0
 public function backup_status()
 {
     // Make sure the serial exists.
     if (pb_backupbuddy::_POST('serial') == '' || empty(pb_backupbuddy::$options['backups'][$_POST['serial']])) {
         echo '!' . pb_backupbuddy::$format->localize_time(time()) . '|~|0|~|' . round(memory_get_peak_usage() / 1048576, 2) . '|~|error|~|Error #5445589. Invalid backup serial (' . htmlentities(pb_backupbuddy::_POST('serial')) . '). Please check directory permissions and your PHP error_log as an early backup function (such as pre_backup) may have failed. Fatal error.' . "\n";
         echo '!' . pb_backupbuddy::$format->localize_time(time()) . '|~|0|~|' . round(memory_get_peak_usage() / 1048576, 2) . '|~|action|~|halt_script' . "\n";
     } else {
         // Return the status information since last retrieval.
         $return_status = '!' . pb_backupbuddy::$format->localize_time(time()) . "|~|0|~|0|~|ping\n";
         //error_log( print_r( pb_backupbuddy::$options['backups'], true ) );
         foreach (pb_backupbuddy::$options['backups'][$_POST['serial']]['steps'] as $step) {
             if ($step['start_time'] != 0 && $step['finish_time'] == 0) {
                 // A step has begun but has not finished. This should not happen but the WP cron is funky. Wait a while before continuing.
                 pb_backupbuddy::status('details', 'Waiting for function `' . $step['function'] . '` to complete. Started ' . (time() - $step['start_time']) . ' seconds ago.', $_POST['serial']);
                 if (time() - $step['start_time'] > 300) {
                     pb_backupbuddy::status('warning', 'The function `' . $step['function'] . '` is taking an abnormally long time to complete (' . (time() - $step['start_time']) . ' seconds). The backup may have stalled.', $_POST['serial']);
                 }
             } elseif ($step['start_time'] == 0) {
                 // Step that has not started yet.
             } else {
                 // Last case: Finished. Skip.
                 // Do nothing.
             }
         }
         /********** Begin file sizes for status updates. *********/
         $temporary_zip_directory = pb_backupbuddy::$options['backup_directory'] . 'temp_zip_' . $_POST['serial'] . '/';
         if (file_exists($temporary_zip_directory)) {
             // Temp zip file.
             $directory = opendir($temporary_zip_directory);
             while ($file = readdir($directory)) {
                 if ($file != '.' && $file != '..') {
                     $stats = stat($temporary_zip_directory . $file);
                     $return_status .= '!' . pb_backupbuddy::$format->localize_time(time()) . '|~|' . round(microtime(true) - pb_backupbuddy::$start_time, 2) . '|~|' . round(memory_get_peak_usage() / 1048576, 2) . '|~|details|~|' . __('Temporary ZIP file size', 'it-l10n-backupbuddy') . ': ' . pb_backupbuddy::$format->file_size($stats['size']) . "\n";
                     $return_status .= '!' . pb_backupbuddy::$format->localize_time(time()) . '|~|' . round(microtime(true) - pb_backupbuddy::$start_time, 2) . '|~|' . round(memory_get_peak_usage() / 1048576, 2) . '|~|action|~|archive_size^' . pb_backupbuddy::$format->file_size($stats['size']) . "\n";
                 }
             }
             closedir($directory);
             unset($directory);
         }
         if (file_exists(pb_backupbuddy::$options['backups'][$_POST['serial']]['archive_file'])) {
             // Final zip file.
             $stats = stat(pb_backupbuddy::$options['backups'][$_POST['serial']]['archive_file']);
             $return_status .= '!' . pb_backupbuddy::$format->localize_time(time()) . '|~|' . round(microtime(true) - pb_backupbuddy::$start_time, 2) . '|~|' . round(memory_get_peak_usage() / 1048576, 2) . '|~|details|~|' . __('Final ZIP file size', 'it-l10n-backupbuddy') . ': ' . pb_backupbuddy::$format->file_size($stats['size']) . "\n";
             $return_status .= '!' . pb_backupbuddy::$format->localize_time(time()) . '|~|' . round(microtime(true) - pb_backupbuddy::$start_time, 2) . '|~|' . round(memory_get_peak_usage() / 1048576, 2) . '|~|action|~|archive_size^' . pb_backupbuddy::$format->file_size($stats['size']) . "\n";
         }
         /********** End file sizes for status updates. *********/
         $status_lines = pb_backupbuddy::get_status(pb_backupbuddy::_POST('serial'), true, false, true);
         // Clear file, dont unlink file (pclzip cant handle files unlinking mid-zip), dont show getting status message.
         if ($status_lines !== false) {
             // Only add lines if there is status contents.
             foreach ($status_lines as $status_line) {
                 //$return_status .= '!' . $status_line[0] . '|' . $status_line[3] . '|' . $status_line[4] . '( ' . $status_line[1] . 'secs / ' . $status_line[2] . 'MB )' . "\n";
                 $return_status .= '!' . implode('|~|', $status_line) . "\n";
             }
         }
         // Return messages.
         echo $return_status;
     }
     die;
 }
function backupbuddy_dbMediaSince($includeThumbs = true)
{
    global $wpdb;
    $wpdb->show_errors();
    // Turn on error display.
    $mediaFiles = array();
    // Select all media attachments.
    $sql = "select " . $wpdb->prefix . "postmeta.meta_value as file," . $wpdb->prefix . "posts.post_modified as file_modified," . $wpdb->prefix . "postmeta.meta_key as meta_key from " . $wpdb->prefix . "postmeta," . $wpdb->prefix . "posts WHERE ( meta_key='_wp_attached_file' OR meta_key='_wp_attachment_metadata' ) AND " . $wpdb->prefix . "postmeta.post_id = " . $wpdb->prefix . "posts.id ORDER BY meta_key ASC";
    $results = $wpdb->get_results($sql, ARRAY_A);
    if (null === $results || false === $results) {
        pb_backupbuddy::status('error', 'Error #238933: Unable to calculate media with query `' . $sql . '`. Check database permissions or contact host.');
    }
    foreach ((array) $results as $result) {
        if ($result['meta_key'] == '_wp_attached_file') {
            $mediaFiles[$result['file']] = array('modified' => $result['file_modified']);
        }
        // Include thumbnail image files.
        if (true === $includeThumbs) {
            if ($result['meta_key'] == '_wp_attachment_metadata') {
                $data = unserialize($result['file']);
                foreach ($data['sizes'] as $size) {
                    // Go through each sized thumbnail file.
                    $mediaFiles[$size['file']] = array('modified' => $mediaFiles[$data['file']]['modified']);
                }
            }
        }
    }
    // end foreach $results.
    unset($results);
    return $mediaFiles;
}
Beispiel #5
0
function remove_file($file, $description, $error_on_missing = false)
{
    pb_backupbuddy::status('message', 'Deleting `' . $description . '`...');
    @chmod($file, 0755);
    // High permissions to delete.
    if (is_dir($file)) {
        // directory.
        pb_backupbuddy::$filesystem->unlink_recursive($file);
        if (file_exists($file)) {
            pb_backupbuddy::status('error', 'Unable to delete directory: `' . $description . '`. You should manually delete it.');
        } else {
            pb_backupbuddy::status('message', 'Deleted.', false);
            // No logging of this action to prevent recreating log.
        }
    } else {
        // file
        if (file_exists($file)) {
            if (@unlink($file) != 1) {
                pb_backupbuddy::status('error', 'Unable to delete file: `' . $description . '`. You should manually delete it.');
            } else {
                pb_backupbuddy::status('message', 'Deleted.', false);
                // No logging of this action to prevent recreating log.
            }
        }
    }
}
Beispiel #6
0
 public function log($level, $message, $prefix = null, $suffix = null)
 {
     $prefix_to_use = is_null($prefix) ? $this->_prefix : (is_string($prefix) ? $prefix : "");
     $suffix_to_use = is_null($suffix) ? $this->_suffix : (is_string($suffix) ? $suffix : "");
     pb_backupbuddy::status($level, $prefix_to_use . $message . $suffix_to_use);
     return $this;
 }
Beispiel #7
0
 public static function test($settings)
 {
     $email = $settings['address'];
     pb_backupbuddy::status('details', 'Testing email destination. Sending ImportBuddy.php.');
     $importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy_' . pb_backupbuddy::random_string(10) . '.php.tmp';
     // Full path & filename to temporary importbuddy
     backupbuddy_core::importbuddy($importbuddy_temp);
     // Create temporary importbuddy.
     $files = array($importbuddy_temp);
     if (pb_backupbuddy::$options['email_return'] != '') {
         $email_return = pb_backupbuddy::$options['email_return'];
     } else {
         $email_return = get_option('admin_email');
     }
     $headers = 'From: BackupBuddy <' . $email_return . '>' . "\r\n";
     $wp_mail_result = wp_mail($email, 'BackupBuddy Test', 'BackupBuddy destination test for ' . site_url(), $headers, $files);
     pb_backupbuddy::status('details', 'Sent test email.');
     @unlink($importbuddy_temp);
     if ($wp_mail_result === true) {
         // WP sent. Hopefully it makes it!
         return true;
     } else {
         // WP couldn't try to send.
         echo 'WordPress was unable to attempt to send email. Check your WordPress & server settings.';
         return false;
     }
 }
 public function execute($command)
 {
     if (stristr(PHP_OS, 'WIN') && !stristr(PHP_OS, 'DARWIN')) {
         // Windows; do nothing.
     } else {
         // Linux/Mac
         if (ini_get('exec_dir') !== false && ini_get('exec_dir') != '') {
             // exec_dir PHP patch in place: http://www.kyberdigi.cz/projects/execdir/
             pb_backupbuddy::status('details', 'exec_dir detected. Skipping path assignment.');
         } else {
             pb_backupbuddy::status('details', 'exec_dir not detected. Proceeding normally.');
             $command = 'PATH=$PATH:/usr/bin/:/usr/local/bin/:usr/local/bin:/usr/local/sbin/:/usr/sbin/:/sbin/:/usr/:/bin/' . '; ' . $command;
         }
     }
     // Output command (strips mysqldump passwords).
     if (strstr($command, '--password='******'--password='******' ', $password_portion_begin);
         //pb_backupbuddy::status( 'details', 'pass start: `' . $password_portion_begin . '`. pass end: `' . $password_portion_end . '`' );
         $password_portion = substr($command, $password_portion_begin, $password_portion_end - $password_portion_begin);
         //pb_backupbuddy::status( 'details', 'pass portion: `' . $password_portion . '`.' );
         $unpassworded_command = str_replace($password_portion, '--password=*HIDDEN*', $command);
         pb_backupbuddy::status('details', 'exec() command (password hidden) `' . $unpassworded_command . '` (with path definition).');
         unset($unpassworded_command);
     } else {
         pb_backupbuddy::status('details', 'exec() command `' . $command . '` (with path definition).');
     }
     $exec_output = array();
     @exec($command, $exec_output, $exec_exit_code);
     pb_backupbuddy::status('details', 'exec() command output: `' . implode(',', $exec_output) . '`; Exit code: `' . $exec_exit_code . '`; Exit code description: `' . pb_backupbuddy::$filesystem->exit_code_lookup($exec_exit_code) . '`');
     return array($exec_output, $exec_exit_code);
 }
Beispiel #9
0
 /**
  * Constructor - if you're not using the class statically
  *
  * @param string $accessKey Access key
  * @param string $secretKey Secret key
  * @param boolean $useSSL Enable SSL
  * @return void
  */
 public function __construct($accessKey = null, $secretKey = null, $useSSL = true)
 {
     if ($accessKey !== null && $secretKey !== null) {
         self::setAuth($accessKey, $secretKey);
     }
     self::$useSSL = $useSSL;
     if ($useSSL === true) {
         pb_backupbuddy::status('details', 'Instantiated S3 with SSL enabled.');
     } else {
         pb_backupbuddy::status('details', 'Instantiated S3 with SSL disabled.');
     }
 }
Beispiel #10
0
 function process_scheduled_backup($cron_id)
 {
     if (!isset(pb_backupbuddy::$options)) {
         $this->load();
     }
     pb_backupbuddy::status('details', 'cron_process_scheduled_backup: ' . $cron_id);
     if (!isset(pb_backupbuddy::$classes['core'])) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
         pb_backupbuddy::$classes['core'] = new pb_backupbuddy_core();
     }
     $preflight_message = '';
     $preflight_checks = pb_backupbuddy::$classes['core']->preflight_check();
     foreach ($preflight_checks as $preflight_check) {
         if ($preflight_check['success'] !== true) {
             pb_backupbuddy::status('warning', $preflight_check['message']);
         }
     }
     if (is_array(pb_backupbuddy::$options['schedules'][$cron_id])) {
         // If schedule is disabled then just return. Bail out!
         if (isset(pb_backupbuddy::$options['schedules'][$cron_id]['on_off']) && pb_backupbuddy::$options['schedules'][$cron_id]['on_off'] == '0') {
             pb_backupbuddy::status('message', 'Schedule `' . $cron_id . '` NOT run due to being disabled based on this schedule\'s settings.');
             return;
         }
         pb_backupbuddy::$options['schedules'][$cron_id]['last_run'] = time();
         // update last run time.
         pb_backupbuddy::save();
         if (!isset(pb_backupbuddy::$classes['backup'])) {
             require_once pb_backupbuddy::plugin_path() . '/classes/backup.php';
             pb_backupbuddy::$classes['backup'] = new pb_backupbuddy_backup();
         }
         // If any remote destinations are set then add these to the steps to perform after the backup.
         $post_backup_steps = array();
         $destinations = explode('|', pb_backupbuddy::$options['schedules'][$cron_id]['remote_destinations']);
         foreach ($destinations as $destination) {
             if (isset($destination) && $destination != '') {
                 array_push($post_backup_steps, array('function' => 'send_remote_destination', 'args' => array($destination), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0));
             }
         }
         if (pb_backupbuddy::$options['schedules'][$cron_id]['delete_after'] == '1') {
             array_push($post_backup_steps, array('function' => 'post_remote_delete', 'args' => array(), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0));
         }
         if (pb_backupbuddy::$classes['backup']->start_backup_process(pb_backupbuddy::$options['schedules'][$cron_id]['type'], 'scheduled', array(), $post_backup_steps, pb_backupbuddy::$options['schedules'][$cron_id]['title']) !== true) {
             error_log('FAILURE #4455484589 IN BACKUPBUDDY.');
             echo __('Error #4564658344443: Backup failure', 'it-l10n-backupbuddy');
             echo pb_backupbuddy::$classes['backup']->get_errors();
         }
     }
     pb_backupbuddy::status('details', 'Finished cron_process_scheduled_backup.');
 }
Beispiel #11
0
function backupbuddy_dbMediaSince()
{
    global $wpdb;
    $wpdb->show_errors();
    // Turn on error display.
    $mediaFiles = array();
    $sql = "select " . $wpdb->prefix . "postmeta.meta_value as file," . $wpdb->prefix . "posts.post_modified as file_modified from " . $wpdb->prefix . "postmeta," . $wpdb->prefix . "posts WHERE meta_key='_wp_attached_file' AND " . $wpdb->prefix . "postmeta.post_id = " . $wpdb->prefix . "posts.id";
    $results = $wpdb->get_results($sql, ARRAY_A);
    if (null === $results || false === $results) {
        pb_backupbuddy::status('error', 'Error #238933: Unable to calculate media with query `' . $sql . '`. Check database permissions or contact host.');
    }
    foreach ((array) $results as $result) {
        $mediaFiles[$result['file']] = array('modified' => $result['file_modified']);
    }
    unset($results);
    return $mediaFiles;
}
Beispiel #12
0
 /**
  *	wipeDatabase()
  *
  *	Clear out the existing database to prepare for importing new data.
  *
  *	@return			boolean		Currently always true.
  */
 function wipeDatabase($confirm = false)
 {
     if ($confirm !== true) {
         die('Error #5466566a: Parameter 1 to wipeDdatabase() must be boolean true to proceed.');
     }
     pb_backupbuddy::status('message', 'Beginning wipe of ALL database tables...');
     // Connect to database.
     //$this->connect_database();
     global $wpdb;
     $rows = $wpdb->get_results("SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE()", ARRAY_A);
     $table_wipe_count = count($rows);
     foreach ($rows as $row) {
         pb_backupbuddy::status('details', 'Dropping table `' . $row['table_name'] . '`.');
         $wpdb->query('DROP TABLE `' . $row['table_name'] . '`');
     }
     unset($rows);
     pb_backupbuddy::status('message', 'Wiped database of ' . $table_wipe_count . ' tables.');
     return true;
 }
Beispiel #13
0
 function file_stats($zip_file, $locate_file, $leave_open = false)
 {
     if (in_array('ziparchive', $this->_zip_methods)) {
         $this->_zip = new ZipArchive();
         if ($this->_zip->open($zip_file) === true) {
             if (($stats = $this->_zip->statName($locate_file)) === false) {
                 // File not found in zip.
                 $this->_zip->close();
                 pb_backupbuddy::status('details', __('File not found (ziparchive) for stats', 'it-l10n-backupbuddy') . ': ' . $locate_file);
                 return false;
             }
             $this->_zip->close();
             return $stats;
         } else {
             pb_backupbuddy::status('details', sprintf(__('ZipArchive failed to open file to check stats (looking in %1$s).', 'it-l10n-backupbuddy'), $zip_file));
             return false;
         }
     }
     // If we made it this far then ziparchive not available/failed.
     if (in_array('pclzip', $this->_zip_methods)) {
         require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
         $this->_zip = new PclZip($zip_file);
         if (($file_list = $this->_zip->listContent()) == 0) {
             // If zero, zip is corrupt or empty.
             pb_backupbuddy::status('details', $this->_zip->errorInfo(true));
         } else {
             foreach ($file_list as $file) {
                 if ($file['filename'] == $locate_file) {
                     // Found file.
                     return true;
                 }
             }
             pb_backupbuddy::status('details', __('File not found (pclzip)', 'it-l10n-backupbuddy') . ': ' . $locate_file);
             return false;
         }
     } else {
         pb_backupbuddy::status('details', __('Unable to check if file exists: No compatible zip method found.', 'it-l10n-backupbuddy'));
         return false;
     }
 }
            unset($item);
            unset($item_name);
        }
        // End foreach.
        unset($event);
        unset($hook_name);
    }
    // End if is_numeric.
}
// End foreach.
unset($cron_item);
unset($time);
// Cleanup any old notifications.
$notifications = backupbuddy_core::getNotifications();
// Load notifications.
$updateNotifications = false;
$maxTimeDiff = pb_backupbuddy::$options['max_notifications_age_days'] * 24 * 60 * 60;
foreach ($notifications as $i => $notification) {
    if (time() - $notification['time'] > $maxTimeDiff) {
        unset($notifications[$i]);
        $updateNotifications = true;
    }
}
if (true === $updateNotifications) {
    pb_backupbuddy::status('details', 'Periodic cleanup: Replacing notifications.');
    backupbuddy_core::replaceNotifications($notifications);
}
@clearstatcache();
// Clears file info stat cache.
pb_backupbuddy::status('message', 'Finished cleanup procedure.');
Beispiel #15
0
 /**
  *	_import_sql_dump_line()
  *
  *	Imports a line/query into the database.
  *	Handles using the specified table prefix.
  *	@since 2.x.
  *
  *	@param		string		$query			Query string to run for importing.
  *	@param		string		$old_prefix		Old prefix. (new prefix was passed in constructor).
  *	@return		boolean						True=success, False=failed.
  *
  */
 function _import_sql_dump_line($query, $old_prefix, $ignore_existing)
 {
     $new_prefix = $this->_database_prefix;
     $query_operators = 'INSERT INTO|CREATE TABLE|REFERENCES|CONSTRAINT|ALTER TABLE|\\/\\*!\\d+\\s+ALTER TABLE';
     // Replace database prefix in query.
     if ($old_prefix !== $new_prefix) {
         $query = preg_replace("/^({$query_operators})(\\s+`?){$old_prefix}/i", "\${1}\${2}{$new_prefix}", $query);
         // 4-29-11
     }
     // Output which table we are able to create to help get an idea where we are in the import.
     if (1 == preg_match("/^CREATE TABLE `?((\\w|-)+)`?/i", $query, $matches)) {
         pb_backupbuddy::status('details', 'Creating table `' . $matches[1] . '`.');
         if (defined('PB_IMPORTBUDDY')) {
             echo "<script>bb_action( 'importingTable', '" . $matches[1] . "' );</script>";
         }
     }
     global $wpdb;
     // Run the query
     $results = $wpdb->query($query);
     if (false === $results) {
         if ($ignore_existing !== true) {
             $mysql_error = @mysql_error($wpdb->dbh);
             if ('' == $mysql_error) {
                 $mysql_error = $wpdb->last_error;
             }
             $mysql_errno = @mysql_errno($wpdb->dbh);
             $mysql_9010_log = ABSPATH . 'importbuddy/mysql_9010_log-' . pb_backupbuddy::$options['log_serial'] . '.txt';
             if (0 == $this->_9010s_encountered) {
                 // Place a header at the top of this log with some debugging info.
                 //@unlink( $mysql_9010_log ); // Delete if already exists to avoid multiple logging of entire process. NO LONGER DELETED since this may be multipart chunked.
                 @file_put_contents($mysql_9010_log, "#####\n# This log contains all 9010 errors encountered.\n# Old prefix: `{$old_prefix}`.\n# New prefix: `{$new_prefix}`.\n# Time: `" . time() . "`.\n#####\n{$test}\n", FILE_APPEND);
             }
             @file_put_contents($mysql_9010_log, "QUERY:\n" . $query . "ERROR:\n" . $mysql_error . "\n\n", FILE_APPEND);
             $this->_9010s_encountered++;
             if ($this->_9010s_encountered > $this->_max_9010s_allowed) {
                 // Too many, don't show more.
                 if ($this->_9010s_encountered == $this->_max_9010s_allowed + 1) {
                     pb_backupbuddy::status('error', 'Additional 9010 errors were encountered but have not been displayed to avoid flooding the screen. All 9010 errors are logged to `' . $mysql_9010_log . '` if possible.');
                 }
             } else {
                 // Show error.
                 pb_backupbuddy::status('error', 'Error #9010: Unable to import SQL query. Error: `' . $mysql_error . '` Errno: `' . $mysql_errno . '`.');
                 if (false !== stristr($mysql_error, 'server has gone away')) {
                     // if string denotes that mysql server has gone away bail since it will likely just flood user with errors...
                     pb_backupbuddy::status('error', 'Error #9010b: Halting backup process as mysql server has gone away and database data could not be imported. Typically the restore cannot continue so the process has been halted. This is usually caused by a problematic mysql server at your hosting provider, low mysql timeouts, etc. Contact your hosting company for support.');
                     pb_backupbuddy::status('details', 'Last query attempted: `' . $query . '`.');
                     die('Error #948343: FATAL ERROR - IMPORT HALTED');
                 }
             }
         }
         return false;
     } else {
         return true;
     }
 }
Beispiel #16
0
 function recursive_copy($src, $dst)
 {
     //pb_backupbuddy::status( 'details', 'Copying `' . $src . '` to `' . $dst . '`.' );
     if (is_dir($src)) {
         pb_backupbuddy::status('details', 'Copying directory `' . $src . '` to `' . $dst . '` recursively.');
         @$this->mkdir($dst, 0777);
         $files = scandir($src);
         foreach ($files as $file) {
             if ($file != "." && $file != "..") {
                 $this->recursive_copy("{$src}/{$file}", "{$dst}/{$file}");
             }
         }
     } elseif (file_exists($src)) {
         @copy($src, $dst);
         // Todo: should this need suppression? Media copying was throwing $dst is directory errors.
     }
 }
Beispiel #17
0
 public function get_comment_linux($zip_file)
 {
     $output = array();
     $result = false;
     $comment = "";
     $zippath = '';
     $command = '';
     if (function_exists('exec')) {
         // Get the command path for the unzip command - should return a trimmed string
         $zippath = $this->get_command_path(self::COMMAND_UNZIP_PATH);
         // Determine if we are using an absolute path
         if (!empty($zippath)) {
             pb_backupbuddy::status('details', __('Using absolute unzip path: ', 'it-l10n-backupbuddy') . $zippath);
         }
         // Add the trailing slash if required
         $command = $this->slashify($zippath) . 'unzip';
         // We expect two lines of output - the first shpuld be the archive name and the second comment if present
         $command .= " -z '{$zip_file}'";
         @exec($command, $output, $exit_code);
         // Note: we don't open the file and then do stuff but it's all done in one action
         // so we need to interpret the return code to dedide what to do
         switch ((int) $exit_code) {
             case 0:
                 // Handled archive and apparently got a comment so try and process it
                 // Should be one file per line, no more no less
                 $line_count = sizeof($output);
                 // Must have at least 2 lines for there to be a non-empty comment
                 if ($line_count > 1) {
                     // Simple criteria for now - just take the final line
                     // Note that if there is no comment this is still valid as an empty comment
                     // so we don't treat this as an error
                     //$comment = $output[ $line_count - 1];
                     unset($output[0]);
                     $comment = implode('', $output);
                 }
                 pb_backupbuddy::status('details', sprintf(__('exec (unzip) retrieved comment in file %1$s', 'it-l10n-backupbuddy'), $zip_file));
                 $result = $comment;
                 break;
             default:
                 // For now let's just print the error code and drop through
                 $error_string = $exit_code;
                 pb_backupbuddy::status('details', sprintf(__('exec (unzip) failed to open/process get comment in file %1$s - Error Info: %2$s.', 'it-l10n-backupbuddy'), $zip_file, $error_string));
                 // Return an error code and a description - this needs to be handled more generically
                 //$result = array( 1, "Unable to get archive contents" );
                 // Currently as we are returning a string as a valid result we just return false on failure
                 $result = false;
         }
     } else {
         // Something fishy - the methods indicated exec but we couldn't find the function
         pb_backupbuddy::status('details', __('exec indicated as available method but exec function non-existent', 'it-l10n-backupbuddy'));
         // Return an error code and a description - this needs to be handled more generically
         //$result = array( 1, "Class not available to match method" );
         // Currently as we are returning a string as a valid result we just return false on failure
         $result = false;
     }
     return $result;
 }
function wp_die($message)
{
    pb_backupbuddy::status('error', 'wp_die() called with message: ' . $message);
    echo $message;
    die;
}
    if (!isset(pb_backupbuddy::$options['remote_destinations'][$destinationID])) {
        die('Error #8383983: Invalid destination ID `' . htmlentities($destinationID) . '`.');
    }
    $destinationArray = pb_backupbuddy::$options['remote_destinations'][$destinationID];
    if ('site' != $destinationArray['type']) {
        die('Error #8378332: Destination with ID `' . htmlentities($destinationID) . '` not of "site" type.');
    }
    $apiKey = $destinationArray['api_key'];
    $apiSettings = backupbuddy_remote_api::key_to_array($apiKey);
    if (false === ($response = backupbuddy_remote_api::remoteCall($apiSettings, 'confirmDeployment', array('serial' => $serial), 10, null, null, null, null, null, null, null, $returnRaw = true))) {
        $message = 'Error #2378378324. Unable to confirm remote deployment with serial `' . $serial . '` via remote API.';
        pb_backupbuddy::status('error', $message);
        die($message);
    } else {
        if (false === ($response = json_decode($response, true))) {
            $message = 'Error #239872373. Unable to decode remote deployment response with serial `' . $serial . '` via remote API. Remote server response: `' . print_r($response) . '`.';
            pb_backupbuddy::status('error', $message);
            die($message);
        }
        if (true === $response['success']) {
            die('1');
        } else {
            $message = 'Error #839743. Unable to confirm remote deployment with serial `' . $serial . '` via remote API. Server response: `' . print_r($response) . '`.';
            pb_backupbuddy::status('error', $message);
            die($message);
        }
    }
} else {
    // Unknown; error.
    die('Error #8383293: Unknown direction `' . $direction . '` for deployment confirmation.');
}
Beispiel #20
0
 public static function send($settings = array(), $files = array(), $send_id = '', $delete_after = false)
 {
     global $pb_backupbuddy_destination_errors;
     if ('1' == $settings['disabled']) {
         $pb_backupbuddy_destination_errors[] = __('Error #48933: This destination is currently disabled. Enable it under this destination\'s Advanced Settings.', 'it-l10n-backupbuddy');
         return false;
     }
     if (!is_array($files)) {
         $files = array($files);
     }
     self::$_timeStart = microtime(true);
     if (count($files) > 1) {
         $message = 'Error #84545894585: This destination currently only supports one file per send.';
         pb_backupbuddy::status('error', $message);
         global $pb_backupbuddy_destination_errors;
         $pb_backupbuddy_destination_errors[] = $message;
         return false;
     }
     require_once pb_backupbuddy::plugin_path() . '/classes/remote_api.php';
     $apiSettings = backupbuddy_remote_api::key_to_array($settings['api_key']);
     if (site_url() == $apiSettings['siteurl']) {
         $message = 'Error #4389843. You are trying to use this site\'s own API key. You must use the API key from the remote destination site.';
         pb_backupbuddy::status('error', $message);
         global $pb_backupbuddy_destination_errors;
         $pb_backupbuddy_destination_errors[] = $message;
         return false;
     }
     $apiURL = $apiSettings['siteurl'];
     $file = $files[0];
     $filePath = '';
     if ('' != $settings['sendFilePath']) {
         $filePath = $settings['sendFilePath'];
     }
     $maxPayload = $settings['max_payload'] * 1024 * 1024;
     // Convert to bytes.
     $encodeReducedPayload = floor(($settings['max_payload'] - $settings['max_payload'] * 0.37) * 1024 * 1024);
     // Take into account 37% base64 encoding overhead. Convert to bytes. Remove any decimals down via floor.
     // Open file for reading.
     if (FALSE === ($fs = @fopen($file, 'r'))) {
         pb_backupbuddy::status('error', 'Error #438934894: Unable to open file `' . $file . '` for reading.');
         return false;
     }
     // If chunked resuming then seek to the correct place in the file.
     if ('' != $settings['resume_point'] && $settings['resume_point'] > 0) {
         // Resuming send of a partially transferred file.
         if (0 !== fseek($fs, $settings['resume_point'])) {
             // Returns 0 on success.
             pb_backupbuddy::status('error', 'Error #327834783: Failed to seek file to resume point `' . $settings['resume_point'] . '` via fseek().');
             return false;
         }
         $prevPointer = $settings['resume_point'];
     } else {
         // New file send.
         $size = filesize($file);
         $encodedSize = $size * 0.37 + $size;
         pb_backupbuddy::status('details', 'File size of file to send: ' . pb_backupbuddy::$format->file_size($size) . '. After encoding overhead: ' . pb_backupbuddy::$format->file_size($encodedSize));
         if ($encodedSize > $maxPayload) {
             $settings['chunks_total'] = ceil($encodedSize / $maxPayload);
             // $maxPayload );
             pb_backupbuddy::status('details', 'This file + encoding exceeds the maximum per-chunk payload size so will be read in and sent in chunks of ' . $settings['max_payload'] . 'MB (' . $maxPayload . ' bytes) totaling approximately ' . $settings['chunks_total'] . ' chunks.');
         } else {
             pb_backupbuddy::status('details', 'This file + encoding does not exceed per-chunk payload size of ' . $settings['max_payload'] . 'MB (' . $maxPayload . ' bytes) so sending in one pass.');
         }
         $prevPointer = 0;
     }
     pb_backupbuddy::status('details', 'Reading in `' . $encodeReducedPayload . '` bytes at a time to send.');
     $dataRemains = true;
     //$loopCount = 0;
     //$loopTimeSum = 0; // Used for average send time per chunk.
     while (TRUE === $dataRemains && FALSE !== ($fileData = fread($fs, $encodeReducedPayload))) {
         // Grab one chunk of data at a time.
         pb_backupbuddy::status('details', 'Read in file data.');
         if (feof($fs)) {
             pb_backupbuddy::status('details', 'Read to end of file (feof true). No more chunks left after this send.');
             $dataRemains = false;
         }
         $isFileTest = false;
         if (false !== stristr(basename($file), 'remote-send-test.php')) {
             $isFileTest = true;
             $settings['sendType'] = 'test';
         }
         if (true === $dataRemains) {
             $isFileDone = false;
         } else {
             $isFileDone = true;
         }
         if (!isset($size)) {
             $size = '';
         }
         pb_backupbuddy::status('details', 'Connecting to remote server to send data.');
         $response = backupbuddy_remote_api::remoteCall($apiSettings, 'sendFile_' . $settings['sendType'], array(), $settings['max_time'], $file, $fileData, $prevPointer, $isFileTest, $isFileDone, $size, $filePath);
         unset($fileData);
         // Free up memory.
         $settings['chunks_sent']++;
         if (true === $dataRemains) {
             // More chunks remain.
             pb_backupbuddy::status('details', 'Connection finished sending part ' . $settings['chunks_sent'] . ' of ~' . $settings['chunks_total'] . '.');
         } else {
             // No more chunks remain.
             pb_backupbuddy::status('details', 'Connection finished sending final part ' . $settings['chunks_sent'] . '.');
         }
         if (false === $response) {
             echo implode(', ', backupbuddy_remote_api::getErrors()) . ' ';
             pb_backupbuddy::status('error', 'Errors encountered details: ' . implode(', ', backupbuddy_remote_api::getErrors()));
             global $pb_backupbuddy_destination_errors;
             $pb_backupbuddy_destination_errors[] = backupbuddy_remote_api::getErrors();
             return false;
             //implode( ', ', backupbuddy_remote_api::getErrors() );
         }
         if (FALSE === ($prevPointer = ftell($fs))) {
             pb_backupbuddy::status('error', 'Error #438347844: Unable to get ftell pointer of file handle for passing to prevPointer.');
             @fclose($fs);
             return false;
         } else {
             pb_backupbuddy::status('details', 'File pointer: `' . $prevPointer . '`.');
         }
         if (true === $dataRemains) {
             // More data remains so see if we need to consider chunking to a new PHP process.
             // If we are within X second of reaching maximum PHP runtime then stop here so that it can be picked up in another PHP process...
             if (microtime(true) - self::$_timeStart + self::TIME_WIGGLE_ROOM >= $settings['max_time']) {
                 pb_backupbuddy::status('message', 'Approaching limit of available PHP chunking time of `' . $settings['max_time'] . '` sec. Ran for ' . round(microtime(true) - self::$_timeStart, 3) . ' sec. Proceeding to use chunking.');
                 @fclose($fs);
                 // Tells next chunk where to pick up.
                 $settings['resume_point'] = $prevPointer;
                 // Schedule cron.
                 $cronTime = time();
                 $cronArgs = array($settings, $files, $send_id, $delete_after);
                 $cronHashID = md5($cronTime . serialize($cronArgs));
                 $cronArgs[] = $cronHashID;
                 $schedule_result = backupbuddy_core::schedule_single_event($cronTime, pb_backupbuddy::cron_tag('destination_send'), $cronArgs);
                 if (true === $schedule_result) {
                     pb_backupbuddy::status('details', 'Next Site chunk step cron event scheduled.');
                 } else {
                     pb_backupbuddy::status('error', 'Next Site chunk step cron even FAILED to be scheduled.');
                 }
                 spawn_cron(time() + 150);
                 // Adds > 60 seconds to get around once per minute cron running limit.
                 update_option('_transient_doing_cron', 0);
                 // Prevent cron-blocking for next item.
                 return array($prevPointer, 'Sent part ' . $settings['chunks_sent'] . ' of ~' . $settings['chunks_total'] . ' parts.');
                 // filepointer location, elapsed time during the import
             } else {
                 // End if.
                 pb_backupbuddy::status('details', 'Not approaching time limit.');
             }
         } else {
             pb_backupbuddy::status('details', 'No more data remains (eg for chunking) so finishing up.');
         }
     }
     // end while data remains in file.
     // Update fileoptions stats.
     pb_backupbuddy::status('details', 'About to load fileoptions data.');
     require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
     pb_backupbuddy::status('details', 'Fileoptions instance #20.');
     $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false);
     if (true !== ($result = $fileoptions_obj->is_ok())) {
         pb_backupbuddy::status('error', __('Fatal Error #9034.279327. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
         return false;
     }
     pb_backupbuddy::status('details', 'Fileoptions data loaded.');
     $fileoptions =& $fileoptions_obj->options;
     $fileoptions['finish_time'] = microtime(true);
     $fileoptions['status'] = 'success';
     $fileoptions['_multipart_status'] = 'Sent all parts.';
     if (isset($uploaded_speed)) {
         $fileoptions['write_speed'] = $uploaded_speed;
     }
     $fileoptions_obj->save();
     unset($fileoptions);
     // Made it this far so completed!
     pb_backupbuddy::status('message', 'Finished sending file. Took ' . round(microtime(true) - self::$_timeStart, 3) . ' seconds this round.');
     pb_backupbuddy::status('deployFileSent', 'File sent.');
     return true;
 }
            if ($multisite_export == '1') {
                // Settings enable admins to export. Set capability to admin and higher only.
                $capability = pb_backupbuddy::$options['role_access'];
                $export_title = '<span title="Note: Enabled for both subsite Admins and Network Superadmins based on BackupBuddy settings">' . __('MS Export (experimental)', 'it-l10n-backupbuddy') . '</span>';
            } else {
                // Settings do NOT allow admins to export; set capability for superadmins only.
                $capability = 'manage_network';
                $export_title = '<span title="Note: Enabled for Network Superadmins only based on BackupBuddy settings">' . __('MS Export SA (experimental)', 'it-l10n-backupbuddy') . '</span>';
            }
            //pb_backupbuddy::add_page( '', 'getting_started', array( pb_backupbuddy::settings( 'name' ), 'Getting Started' . $export_note ), $capability );
            pb_backupbuddy::add_page('', 'multisite_export', $export_title, $capability, $icon);
            pb_backupbuddy::add_page('multisite_export', 'malware_scan', __('Malware Scan', 'it-l10n-backupbuddy'), $capability);
        }
    } else {
        // PB_BACKUPBUDDY_MULTISITE_EXPERIMENT not in wp-config / set to TRUE.
        pb_backupbuddy::status('error', 'Multisite detected but PB_BACKUPBUDDY_MULTISITE_EXPERIMENT definition not found in wp-config.php / not defined to boolean TRUE.');
    }
} else {
    // Standalone site.
    pb_backupbuddy::add_page('', 'backup', array(pb_backupbuddy::settings('name'), __('Backup', 'it-l10n-backupbuddy')), pb_backupbuddy::$options['role_access'], $icon);
    pb_backupbuddy::add_page('backup', 'migrate_restore', __('Restore / Migrate', 'it-l10n-backupbuddy'), pb_backupbuddy::$options['role_access']);
    pb_backupbuddy::add_page('backup', 'destinations', __('Remote Destinations', 'it-l10n-backupbuddy'), pb_backupbuddy::$options['role_access']);
    //pb_backupbuddy::add_page( 'backup', 'deploy', __( 'Deployments', 'it-l10n-backupbuddy' ), pb_backupbuddy::$options['role_access'] );
    pb_backupbuddy::add_page('backup', 'server_tools', __('Server Tools', 'it-l10n-backupbuddy'), pb_backupbuddy::$options['role_access']);
    pb_backupbuddy::add_page('backup', 'malware_scan', __('Malware Scan', 'it-l10n-backupbuddy'), pb_backupbuddy::$options['role_access']);
    pb_backupbuddy::add_page('backup', 'scheduling', __('Schedules', 'it-l10n-backupbuddy'), pb_backupbuddy::$options['role_access']);
    pb_backupbuddy::add_page('backup', 'settings', __('Settings', 'it-l10n-backupbuddy'), pb_backupbuddy::$options['role_access']);
}
/********** LIBRARIES & CLASSES (admin) **********/
/********** OTHER (admin) **********/
add_filter('contextual_help', 'pb_backupbuddy_contextual_help', 10, 3);
Beispiel #22
0
 *	@return		boolean		True if WordPress already exists; false otherwise.
 */
function wordpress_exists()
{
    if (file_exists(ABSPATH . 'wp-config.php')) {
        return true;
    } else {
        return false;
    }
}
function phpini_exists()
{
    return file_exists(ABSPATH . 'php.ini');
}
function htaccess_exists()
{
    return file_exists(ABSPATH . '.htaccess');
}
function index_exists()
{
    if (file_exists(ABSPATH . 'index.htm') === true) {
        return true;
    }
    if (file_exists(ABSPATH . 'index.html') === true) {
        return true;
    }
}
pb_backupbuddy::load_view('html_1');
// LOG IMPORTBUDDY VERSION INFORMATION.
pb_backupbuddy::status('details', 'Running ImportBuddy v' . pb_backupbuddy::$options['bb_version'] . '.');
Beispiel #23
0
 public function shutdown_function()
 {
     // Get error message.
     // Error types: http://php.net/manual/en/errorfunc.constants.php
     $e = error_get_last();
     if ($e === NULL) {
         // No error of any kind.
         return;
     } else {
         // Some type of error.
         if (!is_array($e) || $e['type'] != E_ERROR && $e['type'] != E_USER_ERROR) {
             // Return if not a fatal error.
             return;
         }
     }
     $e_string = '';
     foreach ((array) $e as $e_line_title => $e_line) {
         $e_string .= $e_line_title . ' => ' . $e_line . "\n";
     }
     pb_backupbuddy::status('error', 'FATAL PHP ERROR: ' . $e_string);
 }
Beispiel #24
0
// Download link
if ('' != pb_backupbuddy::_GET('downloadlink_file')) {
    $fileMeta = pb_backupbuddy_destination_gdrive::getFileMeta($settings, pb_backupbuddy::_GET('downloadlink_file'));
    pb_backupbuddy::alert('<a href="' . $fileMeta->alternateLink . '" target="_new">Click here</a> to view & download this file from Google Drive. You must log in to Google to access it.');
}
// Copy file to local
if ('' != pb_backupbuddy::_GET('cpy_file')) {
    $destinationFile = $fileMeta = pb_backupbuddy_destination_gdrive::getFileMeta($settings, pb_backupbuddy::_GET('cpy_file'));
    /*
    echo '<pre>';
    print_r( $fileMeta );
    echo '</pre>';
    */
    pb_backupbuddy::alert('The remote file is now being copied to your local backups. If the backup gets marked as bad during copying, please wait a bit then click the `Refresh` icon to rescan after the transfer is complete.');
    echo '<br>';
    pb_backupbuddy::status('details', 'Scheduling Cron for creating Google Drive copy.');
    backupbuddy_core::schedule_single_event(time(), pb_backupbuddy::cron_tag('process_destination_copy'), array($destination, $fileMeta->originalFilename, pb_backupbuddy::_GET('cpy_file')));
    spawn_cron(time() + 150);
    // Adds > 60 seconds to get around once per minute cron running limit.
    update_option('_transient_doing_cron', 0);
    // Prevent cron-blocking for next item.
}
?>


<span id="backupbuddy_gdrive_loading"><h3><img src="<?php 
echo pb_backupbuddy::plugin_url();
?>
/images/loading.gif" alt="' . __('Loading...', 'it-l10n-backupbuddy' ) . '" title="' . __('Loading...', 'it-l10n-backupbuddy' ) . '" width="16" height="16" style="vertical-align: -3px;"> <?php 
_e('Loading...', 'it-l10n-backupbuddy');
?>
Beispiel #25
0
		pb_backupbuddy::status( 'error', sprintf( __('Unable to create backup storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['backup_directory'] ) );
		pb_backupbuddy::alert( sprintf( __('Unable to create backup storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['backup_directory'] ), true, '9002' );
	}
}

// Keep temp directory up to date.
if ( pb_backupbuddy::$options['temp_directory'] != ( ABSPATH . 'wp-content/uploads/backupbuddy_temp/' ) ) {
	pb_backupbuddy::status( 'details', 'Temporary directory has changed. Updating from `' . pb_backupbuddy::$options['temp_directory'] . '` to `' . ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . '`.' );
	pb_backupbuddy::$options['temp_directory'] = ABSPATH . 'wp-content/uploads/backupbuddy_temp/';
	pb_backupbuddy::save();
}
// Make backup directory if it does not exist yet.
if ( !file_exists( pb_backupbuddy::$options['temp_directory'] ) ) {
	pb_backupbuddy::status( 'details', 'Temporary directory does not exist. Attempting to create.' );
	if ( pb_backupbuddy::$filesystem->mkdir( pb_backupbuddy::$options['temp_directory'] ) === false ) {
		pb_backupbuddy::status( 'error', sprintf( __('Unable to create temporary storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['temp_directory'] ) );
		pb_backupbuddy::alert( sprintf( __('Unable to create temporary storage directory (%s)', 'it-l10n-backupbuddy' ) , pb_backupbuddy::$options['temp_directory'] ), true, '9002' );
	}
}
/********** End directory checking. **********/


// The below is no longer needed? - Dustin May 12, 2012:
// ZipBuddy handles all zipping, testing available zip methods, etc. Only runs on backupbuddy pages here.
// TODO: Make sure zipbuddy testing is cached.
/*
//todo: add this back in. temp disabled just for some testing jan 25, 11am.
if ( strstr( pb_backupbuddy::_GET( 'page' ), 'backupbuddy' ) && !isset( pb_backupbuddy::$classes['zipbuddy'] ) ) { // Only run if zipbuddy object not already loaded.
	require_once( pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php' );
	pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy( pb_backupbuddy::$options['backup_directory'] );
}
Beispiel #26
0
        } else {
            pb_backupbuddy::alert('Error: Unable to delete `' . $item . '`. Verify permissions.');
        }
    }
    if (count($deleted_files) > 0) {
        pb_backupbuddy::alert('Deleted ' . implode(', ', $deleted_files) . '.');
        delete_transient('pb_backupbuddy_stashquota_' . $itxapi_username);
        // Delete quota transient since it probably has changed now.
    }
    echo '<br>';
}
// Handle copying files to local
if (pb_backupbuddy::_GET('cpy_file') != '') {
    pb_backupbuddy::alert('The remote file is now being copied to your local backups. If the backup gets marked as bad during copying, please wait a bit then click the `Refresh` icon to rescan after the transfer is complete.');
    echo '<br>';
    pb_backupbuddy::status('details', 'Scheduling Cron for creating Stash copy.');
    backupbuddy_core::schedule_single_event(time(), 'process_remote_copy', array('stash', pb_backupbuddy::_GET('cpy_file'), $settings));
    spawn_cron(time() + 150);
    // Adds > 60 seconds to get around once per minute cron running limit.
    update_option('_transient_doing_cron', 0);
    // Prevent cron-blocking for next item.
}
// Handle download link
if (pb_backupbuddy::_GET('downloadlink_file') != '') {
    $link = $s3->get_object($manage_data['bucket'], $manage_data['subkey'] . $remote_path . pb_backupbuddy::_GET('downloadlink_file'), array('preauth' => time() + 3600));
    pb_backupbuddy::alert('You may download this backup (' . pb_backupbuddy::_GET('downloadlink_file') . ') with <a href="' . $link . '">this link</a>. The link is valid for one hour.');
    echo '<br>';
}
// QUOTA INFORMATION.
$account_info = pb_backupbuddy_destination_stash::get_quota(array('itxapi_username' => $itxapi_username, 'itxapi_password' => $itxapi_password), false);
/*
		if( jQuery( '#' + target_id ).length == 0 ) { // No status box yet so suppress.
			return;
		}
		jQuery( '#' + target_id ).append( "\n" + message );
		textareaelem = document.getElementById( target_id );
		textareaelem.scrollTop = textareaelem.scrollHeight;
	}
	
	function backupbuddy_hourpad(n) { return ("0" + n).slice(-2); }
</script>
<?php 
$success = false;
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.
require pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
$result = backupbuddy_restore_files::restore(backupbuddy_core::getBackupDirectory() . $archive_file, $files, $finalPath = ABSPATH);
echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
pb_backupbuddy::flush();
if (false === $result) {
} else {
}
pb_backupbuddy::$ui->ajax_footer();
pb_backupbuddy::$ui->ajax_footer();
die;
Beispiel #28
0
 public function trim_backups_integrity_stats()
 {
     pb_backupbuddy::status('details', 'Trimming backup integrity stats.');
     $minimum = 10;
     // Minimum number of backups' integrity to keep track of.
     if (!isset(pb_backupbuddy::$options['backups'])) {
         // No integrity checks yet.
         return;
     }
     // Put newest backups first.
     $existing_backups = array_reverse(pb_backupbuddy::$options['backups']);
     // Remove any backup integrity stats for deleted backups. Will re-add from temp array if we drop under the minimum.
     foreach ($existing_backups as $backup_serial => $existing_backup) {
         if (!isset($existing_backup['archive_file']) || !file_exists($existing_backup['archive_file'])) {
             unset(pb_backupbuddy::$options['backups'][$backup_serial]);
             // File gone so erase from options. Will re-add if we go under our minimum.
         }
     }
     // End foreach.
     // If dropped under the minimum try to add back in some to get enough sample points.
     if (count(pb_backupbuddy::$options['backups']) < $minimum) {
         foreach ($existing_backups as $backup_serial => $existing_backup) {
             if (!isset(pb_backupbuddy::$options['backups'][$backup_serial])) {
                 pb_backupbuddy::$options['backups'][$backup_serial] = $existing_backup;
                 // Add item.
             }
             // If hit minimum then stop looping to add.
             if (count(pb_backupbuddy::$options['backups']) >= $minimum) {
                 break;
             }
         }
         // Put array back in normal order.
         pb_backupbuddy::$options['backups'] = array_reverse(pb_backupbuddy::$options['backups']);
         pb_backupbuddy::save();
     } else {
         // Still have enough stats. Save.
         pb_backupbuddy::$options['backups'] = array_reverse(pb_backupbuddy::$options['backups']);
         pb_backupbuddy::save();
     }
 }
Beispiel #29
0
 public static function get_manage_data($settings)
 {
     $itxapi_username = $settings['itxapi_username'];
     $itxapi_password = $settings['itxapi_password'];
     require_once dirname(__FILE__) . '/lib/class.itx_helper.php';
     require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php';
     $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
     //  get the url to use to request management credentials
     //  url looks something like this - http://api.ithemes.com/stash/upload?apikey=sb31kesem0c879m0&expires=1347439653&subscriber=jwooley&signature=VFMbmXb5OorWwqE0iedOCsDtSgs%3D
     $manage_url = $stash->get_manage_url();
     //  create a new RequestCore to get the credentials
     //  NOTE: RequestCore is part of the AWS SDK, it's a generic http request class.
     //        You can use any available function to make the api request, the wordpress http class for example,
     //        or even just the basic file_get_contents()
     $request = new RequestCore($manage_url);
     //  send the api request
     $response = $request->send_request(true);
     //  see if the request was successful
     if (!$response->isOK()) {
         //throw new Exception('Request for management credentials failed.');
         $error = 'Request for management credentials failed.';
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     //  see if we got a json response
     if (!($manage_data = json_decode($response->body, true))) {
         $error = 'Did not get valid JSON response.';
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     //  finally see if the API returned an error
     if (isset($manage_data['error'])) {
         $error = 'Error: ' . implode(' - ', $manage_data['error']);
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     return $manage_data;
 }
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;