public function run($arguments)
 {
     $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
     pb_backupbuddy::$options['remote_destinations'][] = $arguments['settings'];
     pb_backupbuddy::save();
     return array('api' => '0', 'status' => 'ok', 'message' => 'Destination added.');
 }
Exemple #2
0
/**
 *	parse_options()
 *
 *	Parses various submitted options and settings from step 1.
 *
 *	@return		null
 */
function parse_options()
{
    if (isset($_POST['siteurl'])) {
        pb_backupbuddy::$options['siteurl'] = $_POST['siteurl'];
    }
    if (isset($_POST['custom_home'])) {
        pb_backupbuddy::$options['home'] = $_POST['home'];
    } else {
        pb_backupbuddy::$options['home'] = $_POST['siteurl'];
    }
    // Multisite domain.
    if (isset($_POST['domain'])) {
        pb_backupbuddy::$options['domain'] = $_POST['domain'];
    }
    if (isset($_POST['db_server'])) {
        pb_backupbuddy::$options['db_server'] = $_POST['db_server'];
    }
    if (isset($_POST['db_user'])) {
        pb_backupbuddy::$options['db_user'] = $_POST['db_user'];
    }
    if (isset($_POST['db_password'])) {
        pb_backupbuddy::$options['db_password'] = $_POST['db_password'];
    }
    if (isset($_POST['db_name'])) {
        pb_backupbuddy::$options['db_name'] = $_POST['db_name'];
    }
    if (isset($_POST['db_prefix'])) {
        pb_backupbuddy::$options['db_prefix'] = $_POST['db_prefix'];
    }
    if (!preg_match('/^[a-z0-9_]+$/i', $_POST['db_prefix'])) {
        pb_backupbuddy::alert('ERROR: Invalid characters in database prefix. Please use your browser\'s back button to correct the error. Prefixes should only contain letters (xyz), numbers (123), and underscores (_).', true);
        die;
    }
    pb_backupbuddy::save();
}
 public function run($arguments)
 {
     $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
     pb_backupbuddy::$options['remote_destinations'][] = $arguments['settings'];
     pb_backupbuddy::save();
     $highest_destination_index = end(array_keys(pb_backupbuddy::$options['remote_destinations']));
     return array('api' => '1', 'status' => 'ok', 'message' => 'Destination added.', 'destination_id' => $highest_destination_index);
 }
Exemple #4
0
 function get_authorize_url()
 {
     $oauth = new Dropbox_OAuth_PEAR($this->_key, $this->_secret);
     $this->_token['request'] = $oauth->getRequestToken();
     pb_backupbuddy::save();
     //echo 'authorizeurltoken:<pre>';
     //print_r( $this->_token );
     //echo '</pre>';
     return str_replace('api.', 'www.', $oauth->getAuthorizeUrl());
 }
 public function run($arguments)
 {
     $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
     if (!isset(pb_backupbuddy::$options['remote_destinations'][$arguments['id']])) {
         return array('api' => '1', 'status' => 'error', 'message' => 'Error #847383: Invalid destination ID. Not found.');
     }
     unset(pb_backupbuddy::$options['remote_destinations'][$arguments['id']]);
     pb_backupbuddy::save();
     return array('api' => '1', 'status' => 'ok', 'message' => 'Destination deleted.', 'destination_id' => $arguments['id']);
 }
 public function run($arguments)
 {
     $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
     pb_backupbuddy::$options['remote_destinations'][] = $arguments['settings'];
     pb_backupbuddy::save();
     $newDestination = array();
     $newDestination['title'] = $arguments['settings']['title'];
     $newDestination['type'] = $arguments['settings']['type'];
     backupbuddy_core::addNotification('destination_created', 'Remote destination created', 'A new remote destination "' . $newDestination['title'] . '" has been created.', $newDestination);
     $highest_destination_index = end(array_keys(pb_backupbuddy::$options['remote_destinations']));
     return array('api' => '1', 'status' => 'ok', 'message' => 'Destination added.', 'destination_id' => $highest_destination_index);
 }
 public function run($arguments)
 {
     $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
     if ('' == $arguments['id'] || !is_numeric($arguments['id'])) {
         return array('api' => '1', 'status' => 'error', 'message' => 'Missing destination ID setting or not numeric.');
     }
     if (!isset(pb_backupbuddy::$options['remote_destinations'][$arguments['id']])) {
         return array('api' => '1', 'status' => 'error', 'message' => 'Invalid destination ID. Not found.');
     }
     // Merge passed settings over current ones.
     pb_backupbuddy::$options['remote_destinations'][$arguments['id']] = array_merge(pb_backupbuddy::$options['remote_destinations'][$arguments['id']], $arguments['settings']);
     pb_backupbuddy::save();
     return array('api' => '1', 'status' => 'ok', 'message' => 'Destination updated.', 'destination_id' => $arguments['id']);
 }
 private static function _verb_renderImportBuddy()
 {
     $backupFile = pb_backupbuddy::_POST('backupFile');
     $password = md5(md5(pb_backupbuddy::_POST('backupbuddy_api_key')));
     // Store this serial in settings to cleanup any temp db tables in the future with this serial with periodic cleanup.
     $backupSerial = backupbuddy_core::get_serial_from_file($backupFile);
     pb_backupbuddy::$options['rollback_cleanups'][$backupSerial] = time();
     pb_backupbuddy::save();
     $importFileSerial = backupbuddy_core::deploymentImportBuddy($password, backupbuddy_core::getBackupDirectory() . $backupFile);
     if (is_array($importFileSerial)) {
         die(json_encode(array('success' => false, 'error' => $importFileSerial[1])));
     } else {
         die(json_encode(array('success' => true, 'importFileSerial' => $importFileSerial)));
     }
 }
/**
 *	savesettings()
 *	
 *	Saves a form into the _options array.
 *	
 *	Use savepoint to set the root array key path. Accepts variable depth, dividing array keys with pound signs.
 *	Ex:	$_POST['savepoint'] value something like array_key_name#subkey
 *		<input type="hidden" name="savepoint" value="files#exclusions" /> to set the root to be $this->_options['files']['exclusions']
 *	
 *	All inputs with the name beginning with pound will act as the array keys to be set in the _options with the associated posted value.
 *	Ex:	$_POST['#key_name'] or $_POST['#key_name#subarray_key_name'] value is the array value to set.
 *		<input type="text" name="#name" /> will save to $this->_options['name']
 *		<input type="text" name="#group#17#name" /> will save to $this->_options['groups'][17]['name']
 *
 *	$savepoint_root		string		Override the savepoint. Same format as the form savepoint.
 */
function savesettings($savepoint_root = '')
{
    //check_admin_referer( 'backupbuddy-nonce' );
    foreach ($_POST as $post_index => $post_value) {
        $_POST[$post_index] = strip_tags_deep($post_value);
        // Do not use just strip_tags as it breaks array post vars.
    }
    if (!empty($savepoint_root)) {
        // Override savepoint.
        $_POST['savepoint'] = $savepoint_root;
    }
    if (!empty($_POST['savepoint'])) {
        $savepoint_root = stripslashes($_POST['savepoint']) . '#';
    } else {
        $savepoint_root = '';
    }
    $posted = stripslashes_deep($_POST);
    // Unescape all the stuff WordPress escaped. Sigh @ WordPress for being like PHP magic quotes.
    foreach ($posted as $index => $item) {
        if (substr($index, 0, 1) == '#') {
            $savepoint_subsection =& pb_backupbuddy::$options;
            $savepoint_levels = explode('#', $savepoint_root . substr($index, 1));
            foreach ($savepoint_levels as $savepoint_level) {
                $savepoint_subsection =& $savepoint_subsection[$savepoint_level];
            }
            $savepoint_subsection = $item;
        }
    }
    pb_backupbuddy::save();
}
Exemple #10
0
 function quickstart_form()
 {
     $errors = array();
     $form = pb_backupbuddy::_POST();
     //print_r( $form );
     if ('' != $form['email'] && false !== stristr($form['email'], '@')) {
         pb_backupbuddy::$options['email_notify_error'] = strip_tags($form['email']);
     } else {
         $errors[] = 'Invalid email address.';
     }
     if ('' != $form['password'] && $form['password'] == $form['password_confirm']) {
         pb_backupbuddy::$options['importbuddy_pass_hash'] = md5($form['password']);
         pb_backupbuddy::$options['importbuddy_pass_length'] = strlen($form['password']);
     } elseif ('' == $form['password']) {
         $errors[] = 'Please enter a password for restoring / migrating.';
     } else {
         $errors[] = 'Passwords do not match.';
     }
     if ('' != $form['schedule']) {
         $destination_id = '';
         if ('' != $form['destination_id']) {
             // Dest id explicitly set.
             $destination_id = $form['destination_id'];
         } else {
             // No explicit destination ID; deduce it.
             if ('' != $form['destination']) {
                 foreach (pb_backupbuddy::$options['remote_destinations'] as $destination_index => $destination) {
                     // Loop through ending with the last created destination of this type.
                     if ($destination['type'] == $form['destination']) {
                         $destination_id = $destination_index;
                     }
                 }
             }
         }
         function pb_backupbuddy_schedule_exist_by_title($title)
         {
             foreach (pb_backupbuddy::$options['schedules'] as $schedule) {
                 if ($schedule['title'] == $title) {
                     return true;
                 }
             }
             return false;
         }
         // STARTER
         if ('starter' == $form['schedule']) {
             $title = 'Weekly Database (Quick Setup - Starter)';
             if (false === pb_backupbuddy_schedule_exist_by_title($title)) {
                 $add_response = backupbuddy_core::add_backup_schedule($title, $profile = '1', $interval = 'weekly', $first_run = time() + get_option('gmt_offset') * 3600 + 86400, $remote_destinations = array($destination_id));
                 if (true !== $add_response) {
                     $errors[] = $add_response;
                 }
             }
             $title = 'Monthly Full (Quick Setup - Starter)';
             if (false === pb_backupbuddy_schedule_exist_by_title($title)) {
                 $add_response = backupbuddy_core::add_backup_schedule($title, $profile = '2', $interval = 'monthly', $first_run = time() + get_option('gmt_offset') * 3600 + 86400 + 18000, $remote_destinations = array($destination_id));
                 if (true !== $add_response) {
                     $errors[] = $add_response;
                 }
             }
         }
         // BLOGGER
         if ('blogger' == $form['schedule']) {
             $title = 'Daily Database (Quick Setup - Blogger)';
             if (false === pb_backupbuddy_schedule_exist_by_title($title)) {
                 $add_response = backupbuddy_core::add_backup_schedule($title, $profile = '1', $interval = 'daily', $first_run = time() + get_option('gmt_offset') * 3600 + 86400, $remote_destinations = array($destination_id));
                 if (true !== $add_response) {
                     $errors[] = $add_response;
                 }
             }
             $title = 'Weekly Full (Quick Setup - Blogger)';
             if (false === pb_backupbuddy_schedule_exist_by_title($title)) {
                 $add_response = backupbuddy_core::add_backup_schedule($title, $profile = '2', $interval = 'weekly', $first_run = time() + get_option('gmt_offset') * 3600 + 86400 + 18000, $remote_destinations = array($destination_id));
                 if (true !== $add_response) {
                     $errors[] = $add_response;
                 }
             }
         }
     }
     // end set schedule.
     if (0 == count($errors)) {
         pb_backupbuddy::save();
         die('Success.');
     } else {
         die(implode("\n", $errors));
     }
 }
Exemple #11
0
 public static function reset_defaults()
 {
     if (isset(pb_backupbuddy::$_settings['default_options'])) {
         pb_backupbuddy::$options = pb_backupbuddy::$_settings['default_options'];
         pb_backupbuddy::save();
         return true;
     } else {
         return false;
     }
 }
 public function deploy_pull_renderImportBuddy($state)
 {
     if (!file_exists($state['pullLocalArchiveFile'])) {
         pb_backupbuddy::status('error', 'Error #32783732: Backup file `' . $state['pullLocalArchiveFile'] . '` not found.');
         return false;
     }
     $backupSerial = backupbuddy_core::get_serial_from_file($state['pullLocalArchiveFile']);
     $importbuddyPassword = md5(md5($state['destination']['key_public']));
     $siteurl = site_url();
     $additionalStateInfo = array();
     $importFileSerial = backupbuddy_core::deploymentImportBuddy($importbuddyPassword, $state['pullLocalArchiveFile'], $additionalStateInfo);
     if (is_array($importFileSerial)) {
         // Could not generate importbuddy file.
         return false;
     }
     // Store this serial in settings to cleanup any temp db tables in the future with this serial with periodic cleanup.
     pb_backupbuddy::$options['rollback_cleanups'][$backupSerial] = time();
     pb_backupbuddy::save();
     // Create undo file.
     $undoFile = 'backupbuddy_deploy_undo-' . $backupSerial . '.php';
     if (false === copy(pb_backupbuddy::plugin_path() . '/classes/_rollback_undo.php', ABSPATH . $undoFile)) {
         $error = 'Error #3289447: Unable to write undo file `' . ABSPATH . $undoFile . '`. Check permissions on directory.';
         pb_backupbuddy::status('error', $error);
         return false;
     }
     // Start pulling importbuddy log.
     $importbuddyURLRoot = $siteurl . '/importbuddy-' . $importFileSerial . '.php';
     $importbuddyLogURL = $importbuddyURLRoot . '?ajax=getDeployLog&v=' . $importbuddyPassword . '&deploy=true';
     //$state['destination']['siteurl'] . '/importbuddy/'?ajax=2&v=' . $importbuddyPassword . '&deploy=true; //status-' . $response['importFileSerial'] . '.txt';
     $importbuddyURL = $importbuddyURLRoot . '?ajax=2&v=' . $importbuddyPassword . '&deploy=true&direction=pull&file=' . basename($state['pullLocalArchiveFile']);
     pb_backupbuddy::status('details', 'Load importbuddy at `' . $importbuddyURLRoot . '` with verifier `' . $importbuddyPassword . '`.');
     pb_backupbuddy::status('loadImportBuddy', json_encode(array('url' => $importbuddyURL, 'logurl' => $importbuddyLogURL)));
     // Calculate undo URL.
     $undoDeployURL = $siteurl . '/backupbuddy_deploy_undo-' . $this->_backup['serial'] . '.php';
     pb_backupbuddy::status('details', 'To undo deployment of database contents go to the URL: ' . $undoDeployURL);
     pb_backupbuddy::status('undoDeployURL', $undoDeployURL);
     // Pull importbuddy log instead of remote backup log. Nothing else is going to be done on remote server.
     $this->_backup_options->options['deployment_log'] = $importbuddyLogURL;
     $this->_backup_options->save();
     // Next step.
     pb_backupbuddy::status('details', 'Inserting deploy step to run importbuddy steps on remote server.');
     $newStep = array('function' => 'deploy_runningImportBuddy', 'args' => array($state), 'start_time' => 0, 'finish_time' => 0, 'attempts' => 0);
     $this->insert_next_step($newStep);
     return true;
 }
Exemple #13
0
 public static function verify_directories($skipTempGeneration = false)
 {
     $success = true;
     // Update backup directory if unable to write to the defined one.
     if (!@is_writable(backupbuddy_core::getBackupDirectory())) {
         pb_backupbuddy::status('details', 'Backup directory invalid. Updating from `' . backupbuddy_core::getBackupDirectory() . '` to default.');
         pb_backupbuddy::$options['backup_directory'] = '';
         // Reset to default (blank).
         pb_backupbuddy::save();
     }
     $response = pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getBackupDirectory(), $die = false);
     if (false === $response) {
         $success = false;
     }
     // Update log directory if unable to write to the defined one.
     if (!@is_writable(backupbuddy_core::getLogDirectory())) {
         pb_backupbuddy::status('details', 'Log directory invalid. Updating from `' . backupbuddy_core::getLogDirectory() . '` to default.');
         pb_backupbuddy::$options['log_directory'] = '';
         // Reset to default (blank).
         pb_backupbuddy::save();
     }
     pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getLogDirectory(), $die = false);
     if (false === $response) {
         $success = false;
     }
     // Update temp directory if unable to write to the defined one.
     if (true !== $skipTempGeneration) {
         if (!@is_writable(backupbuddy_core::getTempDirectory())) {
             pb_backupbuddy::status('details', 'Temporary directory invalid. Updating from `' . backupbuddy_core::getTempDirectory() . '` to default.');
             pb_backupbuddy::$options['temp_directory'] = '';
             pb_backupbuddy::save();
         }
         pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false);
         if (false === $response) {
             $success = false;
         }
     }
     // If temp directory exists (should only be transient but just in case it is hanging around) make sure it's secured. BB will try to delete this directory but if it can't it will at least be checked to be secure.
     if (file_exists(backupbuddy_core::getTempDirectory())) {
         pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false);
     }
     global $pb_backupbuddy_directory_verification;
     $pb_backupbuddy_directory_verification = $success;
     return $success;
 }
Exemple #14
0
    public function site_size_listing()
    {
        $exclusions = pb_backupbuddy_core::get_directory_exclusions();
        $result = pb_backupbuddy::$filesystem->dir_size_map(ABSPATH, ABSPATH, $exclusions, $dir_array);
        $total_size = pb_backupbuddy::$options['stats']['site_size'] = $result[0];
        $total_size_excluded = pb_backupbuddy::$options['stats']['site_size_excluded'] = $result[1];
        pb_backupbuddy::$options['stats']['site_size_updated'] = time();
        pb_backupbuddy::save();
        arsort($dir_array);
        ?>
		<table class="widefat">
			<thead>
				<tr class="thead">
					<?php 
        echo '<th>', __('Directory', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size with Children', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size with Exclusions', 'it-l10n-backupbuddy'), '</th>';
        ?>
				</tr>
			</thead>
			<tfoot>
				<tr class="thead">
					<?php 
        echo '<th>', __('Directory', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size with Children', 'it-l10n-backupbuddy'), '</th>', '<th>', __('Size with Exclusions', 'it-l10n-backupbuddy'), '</th>';
        ?>
				</tr>
			</tfoot>
			<tbody>
		<?php 
        echo '<tr><td align="right"><b>' . __('TOTALS', 'it-l10n-backupbuddy') . ':</b></td><td><b>' . pb_backupbuddy::$format->file_size($total_size) . '</b></td><td><b>' . pb_backupbuddy::$format->file_size($total_size_excluded) . '</b></td></tr>';
        $item_count = 0;
        foreach ($dir_array as $id => $item) {
            // Each $item is in format array( TOTAL_SIZE, TOTAL_SIZE_TAKING_EXCLUSIONS_INTO_ACCOUNT );
            $item_count++;
            if ($item_count > 100) {
                flush();
                $item_count = 0;
            }
            if ($item[1] === false) {
                $excluded_size = '<i>Excluded</i>';
                echo '<tr style="background: #F9B6B6;">';
            } else {
                $excluded_size = pb_backupbuddy::$format->file_size($item[1]);
                echo '<tr>';
            }
            echo '<td>' . $id . '</td><td>' . pb_backupbuddy::$format->file_size($item[0]) . '</td><td>' . $excluded_size . '</td></tr>';
        }
        echo '<tr><td align="right"><b>' . __('TOTALS', 'it-l10n-backupbuddy') . ':</b></td><td><b>' . pb_backupbuddy::$format->file_size($total_size) . '</b></td><td><b>' . pb_backupbuddy::$format->file_size($total_size_excluded) . '</b></td></tr>';
        echo '</tbody>';
        echo '</table>';
        echo '<br>';
        echo 'Exclusions';
        pb_backupbuddy::tip('List of directories that will be excluded in an actual backup. This includes user-defined directories and BackupBuddy directories such as the archive directory and temporary directories.');
        echo '<div id="pb_backupbuddy_serverinfo_exclusions" style="background-color: #EEEEEE; padding: 4px; float: right; white-space: nowrap; height: 90px; width: 70%; min-width: 400px; overflow: auto;"><i>' . implode("<br>", $exclusions) . '</i></div>';
        echo '<br style="clear: both;">';
        die;
    }
Exemple #15
0
 public static function send($settings = array(), $files = array(), $clear_uploads = false)
 {
     global $pb_backupbuddy_destination_errors;
     if (!is_array($files)) {
         $files = array($files);
     }
     if ($clear_uploads === false) {
         // Uncomment the following line to override and always clear.
         //$clear_uploads = true;
     }
     $itxapi_username = $settings['itxapi_username'];
     $itxapi_password = $settings['itxapi_password'];
     $db_archive_limit = $settings['db_archive_limit'];
     $full_archive_limit = $settings['full_archive_limit'];
     $max_chunk_size = $settings['max_chunk_size'];
     $remote_path = self::get_remote_path($settings['directory']);
     // Has leading and trailng slashes.
     if ($settings['ssl'] == '0') {
         $disable_ssl = true;
     } else {
         $disable_ssl = false;
     }
     $multipart_id = $settings['_multipart_id'];
     $multipart_counts = $settings['_multipart_counts'];
     pb_backupbuddy::status('details', 'Stash remote path set to `' . $remote_path . '`.');
     require_once dirname(__FILE__) . '/lib/class.itx_helper.php';
     require_once dirname(__FILE__) . '/lib/aws-sdk/sdk.class.php';
     // Stash API talk.
     $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
     $manage_data = pb_backupbuddy_destination_stash::get_manage_data($settings);
     // Wipe all current uploads.
     if ($clear_uploads === true) {
         pb_backupbuddy::status('details', 'Clearing any current uploads via Stash call to `abort-all`.');
         $abort_url = $stash->get_upload_url(null, 'abort-all');
         $request = new RequestCore($abort_url);
         //pb_backupbuddy::status('details', print_r( $request , true ) );
         $response = $request->send_request(true);
     }
     // Process multipart transfer that we already initiated in a previous PHP load.
     if ($multipart_id != '') {
         // Multipart upload initiated and needs parts sent.
         // Create S3 instance.
         pb_backupbuddy::status('details', 'Creating Stash S3 instance.');
         $s3 = new AmazonS3($settings['_multipart_upload_data']['credentials']);
         // the key, secret, token
         if ($disable_ssl === true) {
             @$s3->disable_ssl(true);
         }
         pb_backupbuddy::status('details', 'Stash S3 instance created.');
         $this_part_number = $settings['_multipart_partnumber'] + 1;
         pb_backupbuddy::status('details', 'Stash beginning upload of part `' . $this_part_number . '` of `' . count($settings['_multipart_counts']) . '` parts of file `' . $settings['_multipart_file'] . '` with multipart ID `' . $settings['_multipart_id'] . '`.');
         $response = $s3->upload_part($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id'], array('expect' => '100-continue', 'fileUpload' => $settings['_multipart_file'], 'partNumber' => $this_part_number, 'seekTo' => (int) $settings['_multipart_counts'][$settings['_multipart_partnumber']]['seekTo'], 'length' => (int) $settings['_multipart_counts'][$settings['_multipart_partnumber']]['length']));
         if (!$response->isOK()) {
             $this_error = 'Stash unable to upload file part for multipart upload `' . $settings['_multipart_id'] . '`. Details: `' . print_r($response, true) . '`.';
             $pb_backupbuddy_destination_errors[] = $this_error;
             pb_backupbuddy::status('error', $this_error);
             return false;
         }
         // Update stats.
         foreach (pb_backupbuddy::$options['remote_sends'] as $identifier => $remote_send) {
             if (isset($remote_send['_multipart_id']) && $remote_send['_multipart_id'] == $multipart_id) {
                 // this item.
                 pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = 'Sent part ' . $this_part_number . ' of ' . count($settings['_multipart_counts']) . '.';
                 if ($this_part_number == count($settings['_multipart_counts'])) {
                     pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] .= '<br>Success.';
                     pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time();
                 }
                 pb_backupbuddy::save();
                 break;
             }
         }
         // Made it here so success sending part. Increment for next part to send.
         $settings['_multipart_partnumber']++;
         if (!isset($settings['_multipart_counts'][$settings['_multipart_partnumber']])) {
             // No more parts exist for this file. Tell S3 the multipart upload is complete and move on.
             pb_backupbuddy::status('details', 'Stash getting parts with etags to notify S3 of completed multipart send.');
             $etag_parts = $s3->list_parts($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id']);
             pb_backupbuddy::status('details', 'Stash got parts list. Notifying S3 of multipart upload completion.');
             $response = $s3->complete_multipart_upload($settings['_multipart_upload_data']['bucket'], $settings['_multipart_upload_data']['object'], $settings['_multipart_id'], $etag_parts);
             if (!$response->isOK()) {
                 $this_error = 'Stash unable to notify S3 of completion of all parts for multipart upload `' . $settings['_multipart_id'] . '`.';
                 $pb_backupbuddy_destination_errors[] = $this_error;
                 pb_backupbuddy::status('error', $this_error);
                 return false;
             } else {
                 pb_backupbuddy::status('details', 'Stash notified S3 of multipart completion.');
             }
             // Notify Stash API that things were succesful.
             $done_url = $stash->get_upload_url($settings['_multipart_file'], 'done', $remote_path . $settings['_multipart_backup_type_dir'] . basename($settings['_multipart_file']));
             pb_backupbuddy::status('details', 'Notifying Stash of completed multipart upload with done url `' . $done_url . '`.');
             $request = new RequestCore($done_url);
             $response = $request->send_request(true);
             if (!$response->isOK()) {
                 $this_error = 'Error #756834682. Could not finalize Stash upload. Response code: `' . $response->get_response_code() . '`; Response body: `' . $response->get_response_body() . '`; Response headers: `' . $response->get_response_header() . '`.';
                 $pb_backupbuddy_destination_errors[] = $this_error;
                 pb_backupbuddy::status('error', $this_error);
                 return false;
             } else {
                 // Good server response.
                 // See if we got an optional json response.
                 $upload_data = @json_decode($response->body, true);
                 if (isset($upload_data['error'])) {
                     $this_error = 'Stash error(s): `' . implode(' - ', $upload_data['error']) . '`.';
                     $pb_backupbuddy_destination_errors[] = $this_error;
                     pb_backupbuddy::status('error', $this_error);
                     return false;
                 }
                 pb_backupbuddy::status('details', 'Stash success sending file `' . basename($settings['_multipart_file']) . '`. File uploaded via multipart across `' . $this_part_number . '` parts and reported to Stash as completed.');
             }
             pb_backupbuddy::status('details', 'Stash has no more parts left for this multipart upload. Clearing multipart instance variables.');
             $settings['_multipart_partnumber'] = 0;
             $settings['_multipart_id'] = '';
             $settings['_multipart_file'] = '';
             $settings['_multipart_counts'] = array();
             $settings['_multipart_upload_data'] = array();
         }
         delete_transient('pb_backupbuddy_stashquota_' . $settings['itxapi_username']);
         // Delete quota transient since it probably has changed now.
         // Schedule to continue if anything is left to upload for this multipart of any individual files.
         if ($settings['_multipart_id'] != '' || count($files) > 0) {
             pb_backupbuddy::status('details', 'Stash multipart upload has more parts left. Scheduling next part send.');
             wp_schedule_single_event(time(), pb_backupbuddy::cron_tag('destination_send'), array($settings, $files, 'multipart', false));
             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.
             pb_backupbuddy::status('details', 'Stash scheduled send of next part(s). Done for this cycle.');
             return array($settings['_multipart_id'], 'Sent ' . $this_part_number . ' of ' . count($multipart_destination_settings['_multipart_counts'] . ' parts.'));
         }
     }
     // Upload each file.
     foreach ($files as $file_id => $file) {
         // Determine backup type directory (if zip).
         $backup_type_dir = '';
         $backup_type = '';
         if (stristr($file, '.zip') !== false) {
             // If a zip try to determine backup type.
             pb_backupbuddy::status('details', 'Stash: Zip file. Detecting backup type if possible.');
             $serial = pb_backupbuddy::$classes['core']->get_serial_from_file($file);
             if (isset(pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'])) {
                 pb_backupbuddy::status('details', 'Stash: Detected backup type as `' . pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'] . '` via integrity check data.');
                 $backup_type_dir = pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'] . '/';
                 $backup_type = pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'];
             } else {
                 if (stristr($file, '-db-') !== false) {
                     pb_backupbuddy::status('details', 'Stash: Detected backup type as `db` via filename.');
                     $backup_type_dir = 'db/';
                     $backup_type = 'db';
                 } elseif (stristr($file, '-full-') !== false) {
                     pb_backupbuddy::status('details', 'Stash: Detected backup type as `full` via filename.');
                     $backup_type_dir = 'full/';
                     $backup_type = 'full';
                 } else {
                     pb_backupbuddy::status('details', 'Stash: Could not detect backup type via integrity details nor filename.');
                 }
             }
         }
         // Interact with Stash API.
         pb_backupbuddy::status('details', 'Determining Stash upload URL for `' . $file . '`.` with destination remote path `' . $remote_path . $backup_type_dir . basename($file) . '`.');
         $upload_url = $stash->get_upload_url($file, 'request', $remote_path . $backup_type_dir . basename($file));
         pb_backupbuddy::status('details', 'Determined upload url: `' . $upload_url . '`.');
         $request = new RequestCore($upload_url);
         pb_backupbuddy::status('details', 'Sending Stash API request.');
         $response = $request->send_request(true);
         // Validate response.
         if (!$response->isOK()) {
             $this_error = 'Stash request for upload credentials failed.';
             $pb_backupbuddy_destination_errors[] = $this_error;
             pb_backupbuddy::status('error', $this_error);
             return false;
         }
         if (!($upload_data = json_decode($response->body, true))) {
             $this_error = 'Stash API did not give a valid JSON response.';
             $pb_backupbuddy_destination_errors[] = $this_error;
             pb_backupbuddy::status('error', $this_error);
             return false;
         }
         if (isset($upload_data['error'])) {
             $this_error = 'Stash error(s): `' . implode(' - ', $upload_data['error']) . '`.';
             $pb_backupbuddy_destination_errors[] = $this_error;
             pb_backupbuddy::status('error', $this_error);
             return false;
         }
         // Calculate meta data to send.
         /*
         $meta_array = array();
         if ( stristr( $file, '.zip' ) !== false ) { // If a zip try to determine backup type.
         	pb_backupbuddy::status( 'details', 'Stash: Zip file. Detecting backup type if possible.' );
         	$serial = pb_backupbuddy::$classes['core']->get_serial_from_file( $file );
         	if ( isset( pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'] ) ) {
         		pb_backupbuddy::status( 'details', 'Stash: Detected backup type as `' . pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'] . '` via integrity check data.' );
         		$meta_array['backup_type'] = pb_backupbuddy::$options['backups'][$serial]['integrity']['detected_type'];
         	} else {
         		if ( stristr( $file, '-db-' ) !== false ) {
         			pb_backupbuddy::status( 'details', 'Stash: Detected backup type as `db` via filename.' );
         			$meta_array['backup_type'] = 'db';
         		} elseif ( stristr( $file, '-full-' ) !== false ) {
         			pb_backupbuddy::status( 'details', 'Stash: Detected backup type as `full` via filename.' );
         			$meta_array['backup_type'] = 'full';
         		} else {
         			pb_backupbuddy::status( 'details', 'Stash: Could not detect backup type via integrity details nor filename.' );
         		}
         	}
         }
         */
         // Create S3 instance.
         pb_backupbuddy::status('details', 'Creating Stash S3 instance.');
         $s3 = new AmazonS3($upload_data['credentials']);
         // the key, secret, token
         if ($disable_ssl === true) {
             @$s3->disable_ssl(true);
         }
         pb_backupbuddy::status('details', 'Stash S3 instance created.');
         // Handle chunking of file into a multipart upload (if applicable).
         $file_size = filesize($file);
         if ($max_chunk_size >= 5 && $file_size / 1024 / 1024 > $max_chunk_size) {
             // minimum chunk size is 5mb. Anything under 5mb we will not chunk.
             pb_backupbuddy::status('details', 'Stash file size of ' . $file_size / 1024 / 1024 . 'MB exceeds max chunk size of ' . $max_chunk_size . 'MB set in settings for sending file as multipart upload.');
             // Initiate multipart upload with S3.
             pb_backupbuddy::status('details', 'Initiating Stash multipart upload.');
             $response = $s3->initiate_multipart_upload($upload_data['bucket'], $upload_data['object'], array('encryption' => 'AES256'));
             if (!$response->isOK()) {
                 $this_error = 'Stash was unable to initiate multipart upload.';
                 $pb_backupbuddy_destination_errors[] = $this_error;
                 pb_backupbuddy::status('error', $this_error);
                 return false;
             } else {
                 $upload_id = (string) $response->body->UploadId;
                 pb_backupbuddy::status('details', 'Stash initiated multipart upload with ID `' . $upload_id . '`.');
             }
             // Get chunk parts for multipart transfer.
             pb_backupbuddy::status('details', 'Stash getting multipart counts.');
             $parts = $s3->get_multipart_counts($file_size, $max_chunk_size * 1024 * 1024);
             // Size of chunks expected to be in bytes.
             $multipart_destination_settings = $settings;
             $multipart_destination_settings['_multipart_id'] = $upload_id;
             $multipart_destination_settings['_multipart_partnumber'] = 0;
             $multipart_destination_settings['_multipart_file'] = $file;
             $multipart_destination_settings['_multipart_counts'] = $parts;
             $multipart_destination_settings['_multipart_upload_data'] = $upload_data;
             $multipart_destination_settings['_multipart_backup_type_dir'] = $backup_type_dir;
             pb_backupbuddy::status('details', 'Stash multipart settings to pass:'******'details', 'Stash scheduling send of next part(s).');
             wp_schedule_single_event(time(), pb_backupbuddy::cron_tag('destination_send'), array($multipart_destination_settings, $files, 'multipart', false));
             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.
             pb_backupbuddy::status('details', 'Stash scheduled send of next part(s). Done for this cycle.');
             return array($upload_id, 'Starting send of ' . count($multipart_destination_settings['_multipart_counts']) . ' parts.');
         } else {
             if ($max_chunk_size != '0') {
                 pb_backupbuddy::status('details', 'File size of ' . $file_size / 1024 / 1024 . 'MB is less than the max chunk size of ' . $max_chunk_size . 'MB; not chunking into multipart upload.');
             } else {
                 pb_backupbuddy::status('details', 'Max chunk size set to zero so not chunking into multipart upload.');
             }
         }
         // SEND file.
         pb_backupbuddy::status('details', 'About to put (upload) object to Stash.');
         $response = $s3->create_object($upload_data['bucket'], $upload_data['object'], array('fileUpload' => $file, 'encryption' => 'AES256'));
         //  we can also utilize the multi-part-upload to create an object
         //  $response = $s3->create_mpu_object($upload_data['bucket'], $upload_data['object'], array('fileUpload'=>$upload_file));
         // Validate response. On failure notify Stash API that things went wrong.
         if (!$response->isOK()) {
             pb_backupbuddy::status('details', 'Sending upload abort.');
             $request = new RequestCore($abort_url);
             $response = $request->send_request(true);
             $this_error = 'Could not upload to Stash, attempt aborted.';
             $pb_backupbuddy_destination_errors[] = $this_error;
             pb_backupbuddy::status('error', $this_error);
             return false;
         } else {
             //	pb_backupbuddy::status( 'details', 'Stash file upload speed: ' . ( $response->header['_info']['speed_upload'] / 1024 / 1024 ) . 'MB/sec. This number may be invalid for small file transfers.' );
             pb_backupbuddy::status('details', 'Stash put success. Need to nofity Stash of upload completion. Details: `' . print_r($response, true) . '`.');
         }
         delete_transient('pb_backupbuddy_stashquota_' . $settings['itxapi_username']);
         // Delete quota transient since it probably has changed now.
         // Notify Stash API that things were succesful.
         $done_url = $stash->get_upload_url($file, 'done', $remote_path . $backup_type_dir . basename($file));
         pb_backupbuddy::status('details', 'Notifying Stash of completed upload with done url `' . $done_url . '`.');
         $request = new RequestCore($done_url);
         $response = $request->send_request(true);
         if (!$response->isOK()) {
             $this_error = 'Error #756834682. Could not finalize Stash upload. Response code: `' . $response->get_response_code() . '`; Response body: `' . $response->get_response_body() . '`; Response headers: `' . $response->get_response_header() . '`.';
             $pb_backupbuddy_destination_errors[] = $this_error;
             pb_backupbuddy::status('error', $this_error);
             return false;
         } else {
             // Good server response.
             // See if we got an optional json response.
             $upload_data = @json_decode($response->body, true);
             if (isset($upload_data['error'])) {
                 // Some kind of error.
                 $this_error = 'Stash error(s): `' . implode(' - ', $upload_data['error']) . '`.';
                 $pb_backupbuddy_destination_errors[] = $this_error;
                 pb_backupbuddy::status('error', $this_error);
                 return false;
             }
             unset($files[$file_id]);
             // Remove from list of files we have not sent yet.
             pb_backupbuddy::status('details', 'Stash success sending file `' . basename($file) . '`. File uploaded and reported to Stash as completed.');
         }
         // Enforce archive limits if applicable.
         if ($backup_type == 'full') {
             $limit = $full_archive_limit;
             pb_backupbuddy::status('details', 'Stash full backup archive limit of `' . $limit . '` based on destination settings.');
         } elseif ($backup_type == 'db') {
             $limit = $db_archive_limit;
             pb_backupbuddy::status('details', 'Stash database backup archive limit of `' . $limit . '` based on destination settings.');
         } else {
             $limit = 0;
             pb_backupbuddy::status('error', 'Error #54854895. Stash was unable to determine backup type so archive limits NOT enforced for this backup.');
         }
         if ($limit > 0) {
             pb_backupbuddy::status('details', 'Stash archive limit enforcement beginning.');
             // S3 object for managing files.
             $s3_manage = new AmazonS3($manage_data['credentials']);
             if ($disable_ssl === true) {
                 @$s3_manage->disable_ssl(true);
             }
             // Get file listing.
             $response_manage = $s3_manage->list_objects($manage_data['bucket'], array('prefix' => $manage_data['subkey'] . $remote_path . $backup_type_dir));
             // list all the files in the subscriber account
             // Create array of backups and organize by date
             $prefix = pb_backupbuddy::$classes['core']->backup_prefix();
             // List backups associated with this site by date.
             $backups = array();
             foreach ($response_manage->body->Contents as $object) {
                 $file = str_replace($manage_data['subkey'] . $remote_path . $backup_type_dir, '', $object->Key);
                 // Stash stores files in a directory per site so no need to check prefix here! if ( false !== strpos( $file, 'backup-' . $prefix . '-' ) ) { // if backup has this site prefix...
                 $backups[$file] = strtotime($object->LastModified);
                 //}
             }
             arsort($backups);
             //error_log( 'backups: ' . print_r( $backups, true ) );
             pb_backupbuddy::status('details', 'Stash found `' . count($backups) . '` backups of this type when checking archive limits.');
             if (count($backups) > $limit) {
                 pb_backupbuddy::status('details', 'More archives (' . count($backups) . ') than limit (' . $limit . ') allows. Trimming...');
                 $i = 0;
                 $delete_fail_count = 0;
                 foreach ($backups as $buname => $butime) {
                     $i++;
                     if ($i > $limit) {
                         pb_backupbuddy::status('details', 'Trimming excess file `' . $buname . '`...');
                         $response = $s3_manage->delete_object($manage_data['bucket'], $manage_data['subkey'] . $remote_path . $backup_type_dir . $buname);
                         if (!$response->isOK()) {
                             pb_backupbuddy::status('details', 'Unable to delete excess Stash file `' . $buname . '`. Details: `' . print_r($response, true) . '`.');
                             $delete_fail_count++;
                         }
                     }
                 }
                 pb_backupbuddy::status('details', 'Finished trimming excess backups.');
                 if ($delete_fail_count !== 0) {
                     $error_message = 'Stash remote limit could not delete ' . $delete_fail_count . ' backups.';
                     pb_backupbuddy::status('error', $error_message);
                     pb_backupbuddy::$classes['core']->mail_error($error_message);
                 }
             }
             pb_backupbuddy::status('details', 'Stash completed archive limiting.');
         } else {
             pb_backupbuddy::status('details', 'No Stash archive file limit to enforce.');
         }
         // End remote backup limit
     }
     // end foreach.
     // Success if we made it this far.
     return true;
 }
Exemple #16
0
 public function get_database_size()
 {
     global $wpdb;
     $prefix = $wpdb->prefix;
     $prefix_length = strlen($wpdb->prefix);
     $additional_includes = explode("\n", pb_backupbuddy::$options['mysqldump_additional_includes']);
     array_walk($additional_includes, create_function('&$val', '$val = trim($val);'));
     $additional_excludes = explode("\n", pb_backupbuddy::$options['mysqldump_additional_excludes']);
     array_walk($additional_excludes, create_function('&$val', '$val = trim($val);'));
     $total_size = 0;
     $total_size_with_exclusions = 0;
     $result = mysql_query("SHOW TABLE STATUS");
     while ($rs = mysql_fetch_array($result)) {
         $excluded = true;
         // Default.
         // TABLE STATUS.
         $resultb = mysql_query("CHECK TABLE `{$rs['Name']}`");
         while ($rsb = mysql_fetch_array($resultb)) {
             if ($rsb['Msg_type'] == 'status') {
                 $status = $rsb['Msg_text'];
             }
         }
         mysql_free_result($resultb);
         // TABLE SIZE.
         $size = $rs['Data_length'] + $rs['Index_length'];
         $total_size += $size;
         // HANDLE EXCLUSIONS.
         if (pb_backupbuddy::$options['backup_nonwp_tables'] == 0) {
             // Only matching prefix.
             if (substr($rs['Name'], 0, $prefix_length) == $prefix or in_array($rs['Name'], $additional_includes)) {
                 if (!in_array($rs['Name'], $additional_excludes)) {
                     $total_size_with_exclusions += $size;
                     $excluded = false;
                 }
             }
         } else {
             // All tables.
             if (!in_array($rs['Name'], $additional_excludes)) {
                 $total_size_with_exclusions += $size;
                 $excluded = false;
             }
         }
     }
     pb_backupbuddy::$options['stats']['db_size'] = $total_size;
     pb_backupbuddy::$options['stats']['db_size_excluded'] = $total_size_with_exclusions;
     pb_backupbuddy::$options['stats']['db_size_updated'] = time();
     pb_backupbuddy::save();
     mysql_free_result($result);
     return array($total_size, $total_size_with_exclusions);
 }
Exemple #17
0
 public function add_backup_schedule($title, $profile, $interval, $first_run, $remote_destinations = array(), $delete_after = false, $enabled = true)
 {
     $schedule = pb_backupbuddy::settings('schedule_defaults');
     $schedule['title'] = $title;
     $schedule['profile'] = (int) $profile;
     $schedule['interval'] = $interval;
     $schedule['first_run'] = $first_run;
     $schedule['remote_destinations'] = implode('|', $remote_destinations);
     if (true == $delete_after) {
         $schedule['delete_after'] = '1';
     } else {
         $schedule['delete_after'] = '0';
     }
     if (false == $enabled) {
         $schedule['on_off'] = '0';
     } else {
         $schedule['on_off'] = '1';
     }
     $next_index = pb_backupbuddy::$options['next_schedule_index'];
     // v2.1.3: $next_index = end( array_keys( pb_backupbuddy::$options['schedules'] ) ) + 1;
     pb_backupbuddy::$options['next_schedule_index']++;
     // This change will be saved in savesettings function below.
     pb_backupbuddy::$options['schedules'][$next_index] = $schedule;
     $result = pb_backupbuddy::$classes['core']->schedule_event($schedule['first_run'], $schedule['interval'], 'pb_backupbuddy-cron_scheduled_backup', array($next_index));
     if ($result === false) {
         return 'Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439b. Check your BackupBuddy error log for details.';
     } else {
         pb_backupbuddy::save();
         return true;
     }
 }
Exemple #18
0
/**
 *	extract()
 *
 *	Extract backup zip file.
 *
 *	@return		array		True if the extraction was a success OR skipping of extraction is set.
 */
function extract_files()
{
    // Zip & Unzip library setup.
    require_once ABSPATH . 'importbuddy/lib/zipbuddy/zipbuddy.php';
    pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(ABSPATH, array(), 'unzip');
    $backup_archive = ABSPATH . pb_backupbuddy::$options['file'];
    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.');
    } else {
        pb_backupbuddy::set_greedy_script_limits();
        pb_backupbuddy::status('message', 'Unzipping into `' . ABSPATH . '`');
        $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';
        }
        // Extract zip file & verify it worked.
        if (true !== ($result = pb_backupbuddy::$classes['zipbuddy']->unzip($backup_archive, $destination_directory, $compatibility_mode))) {
            pb_backupbuddy::status('error', 'Failed unzipping archive.');
            pb_backupbuddy::alert('Failed unzipping archive.', true);
            return false;
        }
        pb_backupbuddy::status('details', 'Success extracting Zip File "' . ABSPATH . pb_backupbuddy::$options['file'] . '" into "' . ABSPATH . '".');
    }
    // End extraction not skipped.
    // Made it here so zip returned true OR skipped unzip step.
    // Handle meta data in comment.
    pb_backupbuddy::status('details', 'Retrieving meta data from ZIP file (if any).');
    $comment = pb_backupbuddy::$classes['zipbuddy']->get_comment($backup_archive);
    $comment = pb_backupbuddy::$classes['core']->normalize_comment_data($comment);
    $comment_text = print_r($comment, true);
    $comment_text = str_replace(array("\n", "\r"), '; ', $comment_text);
    pb_backupbuddy::status('details', 'Backup meta data: `' . $comment_text . '`.');
    // Use meta to find DAT file (if possible). BB v3.3+.
    $dat_file = '';
    if ('' != $comment['dat_path']) {
        // Specific DAT location is known.
        pb_backupbuddy::status('details', 'Checking for DAT file as reported by meta data as file `' . ABSPATH . $comment['dat_path'] . '`.');
        if (file_exists(ABSPATH . $comment['dat_path'])) {
            $dat_file = ABSPATH . $comment['dat_path'];
            pb_backupbuddy::status('details', 'DAT file found based on meta path.');
        } else {
            pb_backupbuddy::status('warning', 'DAT file was not found as reported by meta data. This is unusual but may not be fatal. Commencing search for file...');
        }
    }
    // Deduce DAT file location based on backup filename. BB < v3.3.
    if ('' == $dat_file) {
        pb_backupbuddy::status('details', 'Scanning for DAT file based on backup file name.');
        $dat_file_locations = array(ABSPATH . 'wp-content/uploads/temp_' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php', ABSPATH . 'wp-content/uploads/backupbuddy_temp/' . pb_backupbuddy::$options['zip_id'] . '/backupbuddy_dat.php', ABSPATH . 'backupbuddy_dat.php');
        $dat_file = '';
        foreach ($dat_file_locations as $dat_file_location) {
            if (file_exists($dat_file_location)) {
                $dat_file = $dat_file_location;
                break;
            }
        }
        if ('' == $dat_file) {
            // DAT not found.
            $error_message = 'Error #9004: Key files missing. Backup data file, backupbuddy_dat.php was not found in the extracted files in any expected location. The unzip process either failed to fully complete, you renamed the backup ZIP file (rename it back to correct this), or the zip file is not a proper BackupBuddy backup.';
            pb_backupbuddy::status('error', $error_message);
            pb_backupbuddy::alert($error_message, true, '9004');
            return false;
        }
        pb_backupbuddy::status('details', 'Successfully found DAT file based on backup file name: `' . $dat_file . '`.');
    }
    // Get DAT file contents & save into options..
    pb_backupbuddy::$options['dat_file'] = pb_backupbuddy::$classes['import']->get_dat_file_array($dat_file);
    pb_backupbuddy::save();
    return true;
}
Exemple #19
0
 function post_backup($fail_mode = false, $cancel_backup = false)
 {
     pb_backupbuddy::status('message', __('Cleaning up after backup.', 'it-l10n-backupbuddy'));
     // Delete temporary data directory.
     if (file_exists($this->_backup['temp_directory'])) {
         pb_backupbuddy::status('details', __('Removing temp data directory.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temp_directory']);
     }
     // Delete temporary ZIP directory.
     if (file_exists(pb_backupbuddy::$options['backup_directory'] . 'temp_zip_' . $this->_backup['serial'] . '/')) {
         pb_backupbuddy::status('details', __('Removing temp zip directory.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::$filesystem->unlink_recursive(pb_backupbuddy::$options['backup_directory'] . 'temp_zip_' . $this->_backup['serial'] . '/');
     }
     if (true === $fail_mode) {
         pb_backupbuddy::status('warning', 'Backup archive limiting has been skipped since there was an error to avoid deleting potentially good backups to make room for a potentially bad backup.');
     } else {
         $this->trim_old_archives();
         // Clean up any old excess archives pushing us over defined limits in settings.
     }
     if (true === $cancel_backup) {
         pb_backupbuddy::status('details', 'Backup stopped so deleting backup ZIP file.');
         $unlink_result = @unlink($this->_backup['archive_file']);
         if (true === $unlink_result) {
             pb_backupbuddy::status('details', 'Deleted stopped backup file.');
         } else {
             pb_backupbuddy::status('error', 'Unable to delete stopped backup file. You should delete it manually as it may be damaged from stopping mid-backup. File to delete: `' . $this->_backup['archive_file'] . '`.');
         }
         $this->_backup['finish_time'] = -1;
         //pb_backupbuddy::save();
         $this->_backup_options->save();
     } else {
         // Not cancelled.
         $this->_backup['archive_size'] = filesize($this->_backup['archive_file']);
         pb_backupbuddy::status('details', __('Final ZIP file size', 'it-l10n-backupbuddy') . ': ' . pb_backupbuddy::$format->file_size($this->_backup['archive_size']));
         pb_backupbuddy::status('action', 'archive_size^' . pb_backupbuddy::$format->file_size($this->_backup['archive_size']));
         if ($fail_mode === false) {
             // Not cancelled and did not fail so mark finish time.
             pb_backupbuddy::$options['last_backup_finish'] = time();
             pb_backupbuddy::save();
         }
     }
     if ($this->_backup['trigger'] == 'manual') {
         // No more manual notifications. Removed Feb 2012 before 3.0.
     } elseif ($this->_backup['trigger'] == 'scheduled') {
         // Load core if it has not been instantiated yet.
         if (!isset(pb_backupbuddy::$classes['core'])) {
             require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
             pb_backupbuddy::$classes['core'] = new pb_backupbuddy_core();
         }
         if (false === $fail_mode && false === $cancel_backup) {
             pb_backupbuddy::status('details', __('Sending scheduled backup complete email notification.', 'it-l10n-backupbuddy'));
             $message = 'completed successfully in ' . pb_backupbuddy::$format->time_duration(time() - $this->_backup['start_time']) . ".\n";
             pb_backupbuddy::$classes['core']->mail_notify_scheduled($this->_backup['serial'], 'complete', __('Scheduled backup', 'it-l10n-backupbuddy') . ' "' . $this->_backup['schedule_title'] . '" ' . $message);
         }
     } else {
         pb_backupbuddy::status('error', 'Error #4343434. Unknown backup trigger.');
     }
     pb_backupbuddy::status('message', __('Finished cleaning up.', 'it-l10n-backupbuddy'));
     if (true === $cancel_backup) {
         pb_backupbuddy::status('details', 'Backup cancellation complete.');
         return false;
     } else {
         if (true === $fail_mode) {
             pb_backupbuddy::status('details', __('As this backup did not pass the integrity check you should verify it manually or re-scan. Integrity checks can fail on good backups due to permissions, large file size exceeding memory limits, etc. You may manually disable integrity check on the Settings page but you will no longer be notified of potentially bad backups.', 'it-l10n-backupbuddy'));
         } else {
             pb_backupbuddy::status('action', 'archive_url^' . basename($this->_backup['archive_file']));
         }
     }
     return true;
 }
Exemple #20
0
 function post_backup($fail_mode = false, $cancel_backup = false)
 {
     pb_backupbuddy::status('message', __('Cleaning up after backup.', 'it-l10n-backupbuddy'));
     // Delete temporary data directory.
     if (file_exists($this->_backup['temp_directory'])) {
         pb_backupbuddy::status('details', __('Removing temp data directory.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::$filesystem->unlink_recursive($this->_backup['temp_directory']);
     }
     // Delete temporary ZIP directory.
     if (file_exists(backupbuddy_core::getBackupDirectory() . 'temp_zip_' . $this->_backup['serial'] . '/')) {
         pb_backupbuddy::status('details', __('Removing temp zip directory.', 'it-l10n-backupbuddy'));
         pb_backupbuddy::$filesystem->unlink_recursive(backupbuddy_core::getBackupDirectory() . 'temp_zip_' . $this->_backup['serial'] . '/');
     }
     if (true === $fail_mode) {
         pb_backupbuddy::status('warning', 'Backup archive limiting has been skipped since there was an error to avoid deleting potentially good backups to make room for a potentially bad backup.');
     } else {
         $this->trim_old_archives();
         // Clean up any old excess archives pushing us over defined limits in settings.
     }
     if (true === $cancel_backup) {
         pb_backupbuddy::status('details', 'Backup stopped so deleting backup ZIP file.');
         $unlink_result = @unlink($this->_backup['archive_file']);
         if (true === $unlink_result) {
             pb_backupbuddy::status('details', 'Deleted stopped backup file.');
         } else {
             pb_backupbuddy::status('error', 'Unable to delete stopped backup file. You should delete it manually as it may be damaged from stopping mid-backup. File to delete: `' . $this->_backup['archive_file'] . '`.');
         }
         $this->_backup['finish_time'] = -1;
         //pb_backupbuddy::save();
         $this->_backup_options->save();
     } else {
         // Not cancelled.
         $this->_backup['archive_size'] = filesize($this->_backup['archive_file']);
         pb_backupbuddy::status('details', __('Final ZIP file size', 'it-l10n-backupbuddy') . ': ' . pb_backupbuddy::$format->file_size($this->_backup['archive_size']));
         pb_backupbuddy::status('action', 'archive_size^' . pb_backupbuddy::$format->file_size($this->_backup['archive_size']));
         if ($fail_mode === false) {
             // Not cancelled and did not fail so mark finish time.
             //error_log( print_r( $this->_backup_options->options, true ) );
             $archiveFile = basename($this->_backup_options->options['archive_file']);
             // Calculate backup download URL, if any.
             //$downloadURL = pb_backupbuddy::ajax_url( 'download_archive' ) . '&backupbuddy_backup=' . $archiveFile;
             $downloadURL = '';
             $abspath = str_replace('\\', '/', ABSPATH);
             // Change slashes to handle Windows as we store backup_directory with Linux-style slashes even on Windows.
             $backup_dir = str_replace('\\', '/', backupbuddy_core::getBackupDirectory());
             if (FALSE !== stristr($backup_dir, $abspath)) {
                 // Make sure file to download is in a publicly accessible location (beneath WP web root technically).
                 //pb_backupbuddy::status( 'details', 'mydir: `' . $backup_dir . '`, abs: `' . $abspath . '`.');
                 $sitepath = str_replace($abspath, '', $backup_dir);
                 $downloadURL = rtrim(site_url(), '/\\') . '/' . trim($sitepath, '/\\') . '/' . $archiveFile;
             }
             $integrityIsOK = '-1';
             if (isset($this->_backup_options->options['integrity']['is_ok'])) {
                 $integrityIsOK = $this->_backup_options->options['integrity']['is_ok'];
             }
             $destinations = array();
             foreach ($this->_backup_options->options['steps'] as $step) {
                 if ('send_remote_destination' == $step['function']) {
                     $destinations[] = array('id' => $step['args'][0], 'title' => pb_backupbuddy::$options['remote_destinations'][$step['args'][0]]['title'], 'type' => pb_backupbuddy::$options['remote_destinations'][$step['args'][0]]['type']);
                 }
             }
             $finishTime = time();
             pb_backupbuddy::$options['last_backup_finish'] = $finishTime;
             pb_backupbuddy::$options['last_backup_stats'] = array('archiveFile' => $archiveFile, 'archiveURL' => $downloadURL, 'archiveSize' => $this->_backup['archive_size'], 'start' => pb_backupbuddy::$options['last_backup_start'], 'finish' => $finishTime, 'type' => $this->_backup_options->options['profile']['type'], 'profileTitle' => htmlentities($this->_backup_options->options['profile']['title']), 'scheduleTitle' => $this->_backup_options->options['schedule_title'], 'integrityStatus' => $integrityIsOK, 'destinations' => $destinations);
             //error_log( print_r( pb_backupbuddy::$options['last_backup_stats'], true ) );
             pb_backupbuddy::save();
         }
     }
     if ($this->_backup['trigger'] == 'manual') {
         // No more manual notifications. Removed Feb 2012 before 3.0.
     } elseif ($this->_backup['trigger'] == 'scheduled') {
         if (false === $fail_mode && false === $cancel_backup) {
             pb_backupbuddy::status('details', __('Sending scheduled backup complete email notification.', 'it-l10n-backupbuddy'));
             $message = 'completed successfully in ' . pb_backupbuddy::$format->time_duration(time() - $this->_backup['start_time']) . ".\n";
             backupbuddy_core::mail_notify_scheduled($this->_backup['serial'], 'complete', __('Scheduled backup', 'it-l10n-backupbuddy') . ' "' . $this->_backup['schedule_title'] . '" ' . $message);
         }
     } else {
         pb_backupbuddy::status('error', 'Error #4343434. Unknown backup trigger.');
     }
     pb_backupbuddy::status('message', __('Finished cleaning up.', 'it-l10n-backupbuddy'));
     if (true === $cancel_backup) {
         pb_backupbuddy::status('details', 'Backup cancellation complete.');
         return false;
     } else {
         if (true === $fail_mode) {
             pb_backupbuddy::status('details', __('As this backup did not pass the integrity check you should verify it manually or re-scan. Integrity checks can fail on good backups due to permissions, large file size exceeding memory limits, etc. You may manually disable integrity check on the Settings page but you will no longer be notified of potentially bad backups.', 'it-l10n-backupbuddy'));
         } else {
             pb_backupbuddy::status('action', 'archive_url^' . basename($this->_backup['archive_file']));
         }
     }
     return true;
 }
Exemple #21
0
 public function set_backup_note()
 {
     if (!isset(pb_backupbuddy::$classes['zipbuddy'])) {
         require_once pb_backupbuddy::plugin_path() . '/lib/zipbuddy/zipbuddy.php';
         pb_backupbuddy::$classes['zipbuddy'] = new pluginbuddy_zipbuddy(pb_backupbuddy::$options['backup_directory']);
     }
     $backup_file = pb_backupbuddy::$options['backup_directory'] . pb_backupbuddy::_POST('backup_file');
     $note = pb_backupbuddy::_POST('note');
     $note = ereg_replace("[[:space:]]+", ' ', $note);
     $note = ereg_replace("[^[:print:]]", '', $note);
     $note = htmlentities(substr($note, 0, 200));
     // Returns true on success, else the error message.
     $comment_result = pb_backupbuddy::$classes['zipbuddy']->set_comment($backup_file, $note);
     if ($comment_result !== true) {
         echo $comment_result;
     } else {
         echo '1';
     }
     // Even if we cannot save the note into the archive file, store it in internal settings.
     $serial = pb_backupbuddy::$classes['core']->get_serial_from_file($backup_file);
     pb_backupbuddy::$options['backups'][$serial]['integrity']['comment'] = $note;
     pb_backupbuddy::save();
     die;
 }
Exemple #22
0
 public static function verify_directories($skipTempGeneration = false)
 {
     $success = true;
     // Update backup directory if unable to write to the defined one.
     if (!@is_writable(backupbuddy_core::getBackupDirectory())) {
         pb_backupbuddy::status('details', 'Backup directory invalid. Updating from `' . backupbuddy_core::getBackupDirectory() . '` to default.');
         pb_backupbuddy::$options['backup_directory'] = '';
         // Reset to default (blank).
         pb_backupbuddy::save();
     }
     $response = pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getBackupDirectory(), $die = false);
     if (false === $response) {
         $success = false;
     }
     // Update log directory if unable to write to the defined one.
     if (!@is_writable(backupbuddy_core::getLogDirectory())) {
         pb_backupbuddy::status('details', 'Log directory invalid. Updating from `' . backupbuddy_core::getLogDirectory() . '` to default.');
         pb_backupbuddy::$options['log_directory'] = '';
         // Reset to default (blank).
         pb_backupbuddy::save();
     }
     pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getLogDirectory(), $die = false);
     if (false === $response) {
         $success = false;
     }
     // Update temp directory if unable to write to the defined one.
     if (true !== $skipTempGeneration) {
         if (!@is_writable(backupbuddy_core::getTempDirectory())) {
             pb_backupbuddy::status('details', 'Temporary directory invalid. Updating from `' . backupbuddy_core::getTempDirectory() . '` to default.');
             pb_backupbuddy::$options['temp_directory'] = '';
             pb_backupbuddy::save();
         }
         pb_backupbuddy::anti_directory_browsing(backupbuddy_core::getTempDirectory(), $die = false);
         if (false === $response) {
             $success = false;
         }
     }
     global $pb_backupbuddy_directory_verification;
     $pb_backupbuddy_directory_verification = $success;
     return $success;
 }
 function content_editor_backup_reminder_on_update($messages)
 {
     if (!isset($messages['post'])) {
         // Fixes conflict with Simpler CSS plugin. Issue #226.
         return $messages;
     }
     pb_backupbuddy::$options['edits_since_last']++;
     pb_backupbuddy::save();
     $admin_url = '';
     //Only show the backup message for network admins or adminstrators
     if (is_multisite() && current_user_can('manage_network')) {
         // Network Admin in multisite. Don't show messages in this case.
         //$admin_url = admin_url( 'network/admin.php' );
         return $messages;
     } elseif (!is_multisite() && current_user_can(pb_backupbuddy::$options['role_access'])) {
         // User with access in standalone.
         $admin_url = admin_url('admin.php');
     } else {
         return $messages;
     }
     $fullbackup = esc_url(add_query_arg(array('page' => 'pb_backupbuddy_backup', 'backupbuddy_backup' => '2'), $admin_url));
     $dbbackup = esc_url(add_query_arg(array('page' => 'pb_backupbuddy_backup', 'backupbuddy_backup' => '1'), $admin_url));
     $backup_message = " | <a href='{$dbbackup}'>" . __('Database Backup', 'it-l10n-backupbuddy') . "</a> | <a href='{$fullbackup}'>" . __('Full Backup', 'it-l10n-backupbuddy') . "</a>";
     $reminder_posts = array();
     // empty array to store customized post messages array
     $reminder_pages = array();
     // empty array to store customized page messages array
     $others = array();
     // An empty array to store the array for custom post types
     foreach ($messages['post'] as $num => $message) {
         $message .= $backup_message;
         if ($num == 0) {
             $message = '';
             // The first element in the messages['post'] array is always empty
         }
         array_push($reminder_posts, $message);
         // Insert/copy the modified message value to the last element of reminder array
     }
     $reminder_posts = array('post' => $reminder_posts);
     // Apply the post key to the first dimension of messages array
     foreach ($messages['page'] as $num => $message) {
         $message .= $backup_message;
         if ($num == 0) {
             $message = '';
             // The first element in the messages['page'] array is always empty
         }
         array_push($reminder_pages, $message);
         // Insert/copy the modified message value to the last element of reminder array
     }
     $reminder_pages = array('page' => $reminder_pages);
     // Apply the page key to the first dimension of messages array
     $reminder = array_merge($reminder_posts, $reminder_pages);
     foreach ($messages as $type => $message) {
         if ($type == 'post' || $type == 'page') {
             // Skip the post key since it is already defined
             continue;
         }
         $others[$type] = $message;
         // Since message is an array, this statement forms 2D array
     }
     $reminder = array_merge($reminder, $others);
     // Merge the arrays in the others array with reminder array in order to form an appropriate format for messages array
     return $reminder;
 }
Exemple #24
0
 public function verify_directories()
 {
     // Keep backup directory up to date.
     //if ( pb_backupbuddy::$options['backup_directory'] != ( ABSPATH . 'wp-content/uploads/backupbuddy_backups/' ) ) {
     if (pb_backupbuddy::$options['backup_directory'] == '' || !@is_writable(pb_backupbuddy::$options['backup_directory'])) {
         $default_backup_dir = ABSPATH . 'wp-content/uploads/backupbuddy_backups/';
         pb_backupbuddy::status('details', 'Backup directory invalid. Updating from `' . pb_backupbuddy::$options['backup_directory'] . '` to the default `' . $default_backup_dir . '`.');
         pb_backupbuddy::$options['backup_directory'] = $default_backup_dir;
         pb_backupbuddy::save();
     }
     // Make backup directory if it does not exist yet.
     //pb_backupbuddy::status( 'details', 'Verifying backup directory `' . pb_backupbuddy::$options['backup_directory'] . '` exists.' );
     if (!file_exists(pb_backupbuddy::$options['backup_directory'])) {
         pb_backupbuddy::status('details', 'Backup directory does not exist. Attempting to create.');
         if (pb_backupbuddy::$filesystem->mkdir(pb_backupbuddy::$options['backup_directory']) === false) {
             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');
         }
     }
 }
Exemple #25
0
 public static function delete_destination($destination_id, $confirm = false)
 {
     if ($confirm === false) {
         return 'Error #54858597. Not deleted. Confirmation parameter missing.';
     }
     // Delete destination.
     unset(pb_backupbuddy::$options['remote_destinations'][$destination_id]);
     // Remove this destination from all schedules using it.
     foreach (pb_backupbuddy::$options['schedules'] as $schedule_id => $schedule) {
         $remote_list = '';
         $trimmed_destination = false;
         $remote_destinations = explode('|', $schedule['remote_destinations']);
         foreach ($remote_destinations as $remote_destination) {
             if ($remote_destination == $destination_id) {
                 $trimmed_destination = true;
             } else {
                 $remote_list .= $remote_destination . '|';
             }
         }
         if ($trimmed_destination === true) {
             pb_backupbuddy::$options['schedules'][$schedule_id]['remote_destinations'] = $remote_list;
         }
     }
     // end foreach.
     pb_backupbuddy::save();
     return true;
 }
Exemple #26
0
 function quickstart_skip()
 {
     pb_backupbuddy::$options['skip_quicksetup'] = '1';
     pb_backupbuddy::save();
     die('1');
 }
Exemple #27
0
 public function start($backupFile, $skipUnzip = false)
 {
     $this->_before(__FUNCTION__);
     if (!file_exists($backupFile)) {
         return $this->_error('Unable to access backup file `' . $backupFile . '`. Verify it still exists and has proper read permissions.');
     }
     $this->_state['archive'] = $backupFile;
     $serial = backupbuddy_core::get_serial_from_file(basename($backupFile));
     $this->_state['serial'] = $serial;
     unset($backupFile);
     unset($serial);
     if (defined('PB_STANDALONE') && true === PB_STANDALONE) {
         $mysql_9010_log = ABSPATH . 'importbuddy/mysql_9010_log-' . pb_backupbuddy::$options['log_serial'] . '.txt';
         if (file_exists($mysql_9010_log)) {
             @unlink($mysql_9010_log);
         }
     }
     if (true !== $skipUnzip) {
         // Get zip meta information.
         $customTitle = 'Backup Details';
         pb_backupbuddy::status('details', 'Attempting to retrieve zip meta data from comment.');
         if (false !== ($metaInfo = backupbuddy_core::getZipMeta($this->_state['archive']))) {
             pb_backupbuddy::status('details', 'Found zip meta data.');
         } else {
             pb_backupbuddy::status('details', 'Did not find zip meta data.');
         }
         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 DAT file.
     pb_backupbuddy::status('details', 'Calculating possible DAT file locations.');
     $detectedDatLocation = '';
     $possibleDatLocations = array();
     if (isset($metaInfo['dat_path'])) {
         $possibleDatLocations[] = $metaInfo['dat_path'][1];
         // DAT file location encoded in meta info. Should always be valid.
     }
     $possibleDatLocations[] = 'wp-content/uploads/backupbuddy_temp/' . $this->_state['serial'] . '/backupbuddy_dat.php';
     // Full backup.
     $possibleDatLocations[] = 'backupbuddy_dat.php';
     // DB backup. (look for this second in case user left an old dat file in root).
     pb_backupbuddy::status('details', 'Possible DAT file locations: `' . implode(';', $possibleDatLocations) . '`.');
     $possibleDatLocations = array_unique($possibleDatLocations);
     if (true === $skipUnzip) {
         // Only look for DAT file in filesystem. Zip should be pre-extracted, eg by the user manually.
         pb_backupbuddy::status('details', 'Looking for DAT file in local filesystem (instead of in zip) since advanced skip unzip option set.');
         foreach ($possibleDatLocations as $possibleDatLocation) {
             // Look for DAT file in filesystem.
             pb_backupbuddy::status('details', 'Does `' . ABSPATH . $possibleDatLocation . '` exist?');
             if (true === file_exists(ABSPATH . $possibleDatLocation)) {
                 pb_backupbuddy::status('details', 'Yes, exists.');
                 $detectedDatLocation = $possibleDatLocation;
                 break;
             } else {
                 pb_backupbuddy::status('details', 'No, does not exist.');
             }
         }
         if ('' == $detectedDatLocation) {
             $message = 'Unable to find the DAT file for this backup archive pre-extracted in the filesystem. Make sure you have already unzipped this backup into the same directory as importbuddy.php.';
             return $this->_error($message);
         }
     } else {
         // Look for DAT file inside of zip archive.
         pb_backupbuddy::status('details', 'Looking for DAT file in zip archive itself.');
         foreach ($possibleDatLocations as $possibleDatLocation) {
             // Look for DAT file in zip.
             if (true === $zipbuddy->file_exists($this->_state['archive'], $possibleDatLocation, $leave_open = true)) {
                 $detectedDatLocation = $possibleDatLocation;
                 break;
             }
         }
         // end foreach.
     }
     if ('' == $detectedDatLocation) {
         return $this->_error('Unable to determine DAT file location. It may be missing OR the backup zip file may be incomplete or corrupted. Verify the backup zip has fully uploaded or re-upload it. You can try manually unzipping then selecting the advanced option to skip unzip.');
     }
     pb_backupbuddy::status('details', 'Confirmed DAT file location: `' . $detectedDatLocation . '`.');
     $this->_state['datLocation'] = $detectedDatLocation;
     unset($metaInfo);
     // No longer need anything from the meta information.
     if (true !== $skipUnzip) {
         function mkdir_recursive($path)
         {
             if (empty($path)) {
                 // prevent infinite loop on bad path
                 return;
             }
             is_dir(dirname($path)) || mkdir_recursive(dirname($path));
             return is_dir($path) || mkdir($path);
         }
         // Load DAT file contents.
         pb_backupbuddy::status('details', 'Creating temporary file directory `' . $this->_state['tempPath'] . '`.');
         pb_backupbuddy::$filesystem->unlink_recursive($this->_state['tempPath']);
         // Remove if already exists.
         mkdir_recursive($this->_state['tempPath']);
         // Make empty directory.
         // Restore DAT file.
         pb_backupbuddy::status('details', 'Extracting DAT file.');
         $files = array($detectedDatLocation => 'backupbuddy_dat.php');
         require pb_backupbuddy::plugin_path() . '/classes/_restoreFiles.php';
         $result = backupbuddy_restore_files::restore($this->_state['archive'], $files, $this->_state['tempPath'], $zipbuddy);
         echo '<script type="text/javascript">jQuery("#pb_backupbuddy_working").hide();</script>';
         pb_backupbuddy::flush();
         if (false === $result) {
             $this->_error('Error #85484: Unable to retrieve DAT file. This is a fatal error.');
             return false;
         }
         $datFile = $this->_state['tempPath'] . 'backupbuddy_dat.php';
     } else {
         $datFile = $this->_state['datLocation'];
     }
     if (false === ($datData = backupbuddy_core::get_dat_file_array($datFile))) {
         $this->_error('Error #4839484: Unable to retrieve DAT file. The backup may have failed opening due to lack of memory, permissions issues, or other reason. Use ImportBuddy to restore or check the Advanced Log above for details.');
         return false;
     }
     $this->_state['dat'] = $datData;
     pb_backupbuddy::status('details', 'DAT file extracted.');
     if (defined('PB_STANDALONE') && true === PB_STANDALONE) {
         $simpleVersion = substr(pb_backupbuddy::$options['bb_version'], 0, strpos(pb_backupbuddy::$options['bb_version'], ' '));
         if (isset($this->_state['dat']['backupbuddy_version']) && version_compare($this->_state['dat']['backupbuddy_version'], $simpleVersion, '>')) {
             pb_backupbuddy::status('error', 'Warning: You are attempting to restore an archive which was created with a newer version of BackupBuddy (' . $this->_state['dat']['backupbuddy_version'] . ') than this ImportBuddy (' . $simpleVersion . '). For best results use an ImportBuddy that is as least as up to date as the BackupBuddy which created the archive.');
         }
     }
     if ('rollback' == $this->_state['type']) {
         if (site_url() != $this->_state['dat']['siteurl']) {
             $this->_error(__('Error #5849843: Site URL does not match. You cannot roll back the database if the URL has changed or for backups or another site. Use importbuddy.php to restore or migrate instead.', 'it-l10n-backupbuddy'));
             return false;
         }
         global $wpdb;
         if ($this->_state['dat']['db_prefix'] != $wpdb->prefix) {
             $this->_error(__('Error #2389394: Database prefix does not match. You cannot roll back the database if the database prefix has changed or for backups or another site. Use importbuddy.php to restore or migrate instead.', 'it-l10n-backupbuddy'));
             return false;
         }
         pb_backupbuddy::$options['rollback_cleanups'][$this->_state['serial']] = time();
         pb_backupbuddy::save();
         // Generate UNDO script.
         pb_backupbuddy::status('details', 'Generating undo script.');
         $this->_state['undoFile'] = 'backupbuddy_rollback_undo-' . $this->_state['serial'] . '.php';
         $undoURL = rtrim(site_url(), '/\\') . '/' . $this->_state['undoFile'];
         if (false === copy(dirname(__FILE__) . '/_rollback_undo.php', ABSPATH . $this->_state['undoFile'])) {
             $this->_error(__('Warning: Unable to create undo script in site root. You will not be able to automated undoing the rollback if something fails so BackupBuddy will not continue.', 'it-l10n-backupbuddy'));
             return false;
         }
         $this->_state['undoURL'] = $undoURL;
     }
     pb_backupbuddy::status('details', 'Finished starting function.');
     return true;
 }
Exemple #28
0
 public function process()
 {
     if ('' != ($form_name = pb_backupbuddy::_POST($this->_prefix)) && pb_backupbuddy::_POST($this->_prefix) == $this->_form_name) {
         // This form was indeed submitted. PROCESS IT!
         // TODO:
         $errors = array();
         $_posts = pb_backupbuddy::_POST();
         // loop through all posted variables, if its prefix matches this form's name then
         foreach ($_posts as $post_name => $post_value) {
             if (substr($post_name, 0, strlen($this->_prefix)) == $this->_prefix) {
                 // This settings form.
                 $item_name = substr($post_name, strlen($this->_prefix));
                 if ($item_name != '' && $item_name != 'settings_submit') {
                     // Skip the form name input; also settings submit button since it is not registered until view.
                     if (true !== ($test_result = $this->_form->test($item_name, $post_value))) {
                         foreach ($this->_settings as $setting_index => $setting) {
                             if ($setting['type'] == 'title') {
                                 continue;
                             }
                             if ($setting['name'] == $item_name) {
                                 $this->_settings[$setting_index]['error'] = true;
                                 $item_title = $this->_settings[$setting_index]['title'];
                             }
                         }
                         $errors[] = 'Validation failure on `' . $item_title . '`: ' . implode(' ', $test_result);
                         unset($_posts[$post_name]);
                         // Removes this form item so it will not be updated during save later.
                     } else {
                         // Item validated. Remove prefix for later processing.
                         $_posts[$item_name] = $_posts[$post_name];
                         $this->_form->set_value($item_name, $post_value);
                         // Set value to be equal to submitted value so if one or more item failed validation the entire form is not wiped out. Don't want user to have to re-enter valid data.
                         unset($_posts[$post_name]);
                     }
                 } else {
                     // Submit button. Can unset it to clean up array for later.
                     unset($_posts[$post_name]);
                 }
             } else {
                 // Not for this form. Can unset it to clean up array for later.
                 unset($_posts[$post_name]);
             }
         }
         // Process!
         // Only save if in normal settings mode; if savepoint === false no saving here.
         if ($this->_savepoint === false || is_array($this->_savepoint)) {
             //foreach( $_posts as $post_name => $post_value ) { // Validation above should haveo only left items for this form. Strip prefixes before passing on.
             //	$post_name = substr( $post_name, strlen( $this->_prefix ) );
             //}
             $return = array('errors' => $errors, 'data' => $_posts);
             return $return;
         } else {
             // Normal settings since savepoint !== false. Save into savepoint!
             if (count($errors) > 0) {
                 // Errors.
                 pb_backupbuddy::alert('Error validating one or more fields as indicated below. Error(s):<br>' . implode('<br>', $errors), true);
             }
             // Prepare savepoint.
             if ($this->_savepoint != '') {
                 $savepoint_root = $this->_savepoint . '#';
             } else {
                 $savepoint_root = '';
             }
             // The hard work.
             foreach ($_posts as $post_name => $post_value) {
                 // Loop through all post items (not all may be our form). @see 83429594837534987.
                 //if ( substr( $post_name, 0, strlen( $this->_prefix ) ) == $this->_prefix ) { // If prefix matches, its this form.
                 //$post_name = substr( $post_name, strlen( $this->_prefix ) ); // Set stripped prefix.
                 //if ( $post_name != '' ) { // Skips the empty prefix name we used for verifying form. @see 83429594837534987.
                 // Update form item value.
                 $this->_form->set_value($post_name, $post_value);
                 // From old save_settings():
                 $savepoint_subsection =& pb_backupbuddy::$options;
                 $savepoint_levels = explode('#', $savepoint_root . $post_name);
                 foreach ($savepoint_levels as $savepoint_level) {
                     $savepoint_subsection =& $savepoint_subsection[$savepoint_level];
                 }
                 // Apply settings.
                 $savepoint_subsection = stripslashes_deep($post_value);
                 // Remove WordPress' magic-quotes-nonsense.
                 //}
                 //}
             }
             // Add a note to the save alert that some values are skipped due to errors.
             $error_note = '';
             if (count($errors) > 0) {
                 $error_note = ' One or more fields skipped due to error.';
             }
             pb_backupbuddy::save();
             pb_backupbuddy::alert(__('Settings saved.' . $error_note, 'it-l10n-backupbuddy'));
             $return = array('errors' => $errors, 'data' => $_posts);
             return $return;
             //} // end no errors.
         }
         // End if savepoint !=== false.
     }
     // end submitted form.
 }
Exemple #29
0
pb_backupbuddy::$ui->title(__('Deploy Database', 'it-l10n-backupbuddy') . ' &nbsp;&nbsp; <a style="font-size: 0.6em;" href="#" onClick="jQuery(\'#pb_backupbuddy_status_wrap\').toggle();">Display Status Log</a>');
if (!defined('BACKUPBUDDY_API_ENABLE') || TRUE != BACKUPBUDDY_API_ENABLE) {
    pb_backupbuddy::alert("Make sure the following is in your wp-config.php file on this server:<br><textarea style='width: 100%;' disabled='disabled'>define( 'BACKUPBUDDY_API_ENABLE', true ); // Requires API key to access.</textarea>");
    return false;
}
/*
if ( ! defined( 'BACKUPBUDDY_API_SALT' ) || ( 'CHANGEME' == BACKUPBUDDY_API_SALT ) || ( strlen( BACKUPBUDDY_API_SALT ) < 5 ) ) {
	pb_backupbuddy::alert( "Make sure the following is in your wp-config.php file on this server:<br><textarea style='width: 100%;' disabled='disabled'>define( 'BACKUPBUDDY_API_SALT', 'CHANGEME' ); // !!! IMPORTANT !!! Change CHANGEME to the left to a unique password/phrase for generating API keys. 5+ characters.</textarea>" );
	return false;
}
*/
if ('1' == pb_backupbuddy::_POST('regenerate_api_key')) {
    pb_backupbuddy::verify_nonce();
    // Security check.
    pb_backupbuddy::$options['api_key'] = backupbuddy_core::generate_api_key();
    pb_backupbuddy::save();
}
?>

<b>Note:</b> wp-config.php files as well as BackupBuddy settings will NOT be transferred in either direction. Your current BackupBuddy settings, destinations, API keys etc. will remain as they are on both sites.<br><br>

<form method="post">
	<?php 
pb_backupbuddy::nonce();
?>
	<input type="hidden" name="regenerate_api_key" value="1">
	<button class="button secondary-button" onClick="jQuery('.backupbuddy_api_key-hide').toggle(); return false;">Show API Key</button><span class="backupbuddy_api_key-hide" style="display: none;">&nbsp;&nbsp;<input type="submit" name="submit" value="Generate New API Key" class="button button-primary"></span>
	<br>
	<br>
	<div class="backupbuddy_api_key-hide" style="display: none;">
		<b>Api Key:</b><br>
Exemple #30
0
/**
 *	parse_options()
 *
 *	Parses various submitted options and settings from step 1.
 *
 *	@return		null
 */
function parse_options()
{
    if (isset($_POST['siteurl'])) {
        pb_backupbuddy::$options['siteurl'] = $_POST['siteurl'];
        if (isset($_POST['custom_home'])) {
            pb_backupbuddy::$options['home'] = $_POST['home'];
        } else {
            pb_backupbuddy::$options['home'] = $_POST['siteurl'];
        }
    }
    // end isset post siteurl.
    if (isset($_POST['skip_database_import']) && $_POST['skip_database_import'] == 'on') {
        pb_backupbuddy::$options['skip_database_import'] = true;
    } else {
        pb_backupbuddy::$options['skip_database_import'] = false;
    }
    if (isset($_POST['skip_database_migration']) && $_POST['skip_database_migration'] == 'on') {
        pb_backupbuddy::$options['skip_database_migration'] = true;
    } else {
        pb_backupbuddy::$options['skip_database_migration'] = false;
    }
    if (isset($_POST['skip_database_bruteforce']) && $_POST['skip_database_bruteforce'] == 'on') {
        pb_backupbuddy::$options['skip_database_bruteforce'] = true;
    } else {
        pb_backupbuddy::$options['skip_database_bruteforce'] = false;
    }
    if (isset($_POST['mysqlbuddy_compatibility']) && $_POST['mysqlbuddy_compatibility'] == 'on') {
        pb_backupbuddy::$options['mysqlbuddy_compatibility'] = true;
    } else {
        pb_backupbuddy::$options['mysqlbuddy_compatibility'] = false;
    }
    if (isset($_POST['wipe_database']) && $_POST['wipe_database'] == 'on') {
        pb_backupbuddy::$options['wipe_database'] = true;
    } else {
        pb_backupbuddy::$options['wipe_database'] = false;
    }
    if (isset($_POST['wipe_database_all']) && $_POST['wipe_database_all'] == 'on') {
        pb_backupbuddy::$options['wipe_database_all'] = true;
    } else {
        pb_backupbuddy::$options['wipe_database_all'] = false;
    }
    if (isset($_POST['ignore_sql_errors']) && $_POST['ignore_sql_errors'] == 'on') {
        pb_backupbuddy::$options['ignore_sql_errors'] = true;
    } else {
        pb_backupbuddy::$options['ignore_sql_errors'] = false;
    }
    if (isset($_POST['max_execution_time']) && is_numeric($_POST['max_execution_time'])) {
        pb_backupbuddy::$options['max_execution_time'] = $_POST['max_execution_time'];
    } else {
        pb_backupbuddy::$options['max_execution_time'] = 30;
    }
    // Multisite domain.
    if (isset($_POST['domain'])) {
        pb_backupbuddy::$options['domain'] = $_POST['domain'];
    }
    if (isset($_POST['db_server'])) {
        pb_backupbuddy::$options['db_server'] = $_POST['db_server'];
    }
    if (isset($_POST['db_user'])) {
        pb_backupbuddy::$options['db_user'] = $_POST['db_user'];
    }
    if (isset($_POST['db_password'])) {
        pb_backupbuddy::$options['db_password'] = $_POST['db_password'];
    }
    if (isset($_POST['db_name'])) {
        pb_backupbuddy::$options['db_name'] = $_POST['db_name'];
    }
    if (isset($_POST['db_prefix'])) {
        if (!preg_match('/^[a-z0-9_]+$/i', $_POST['db_prefix'])) {
            pb_backupbuddy::alert('ERROR: Invalid characters in database prefix. Please use your browser\'s back button to correct the error. Prefixes should only contain letters (xyz), numbers (123), and underscores (_).', true);
            die;
        }
        pb_backupbuddy::$options['db_prefix'] = $_POST['db_prefix'];
    }
    pb_backupbuddy::save();
}