// No form errors; process! require_once dirname(__FILE__) . '/lib/class.itx_helper.php'; $itxapi_username = strtolower($settings_result['data']['itxapi_username']); $itxapi_password = ITXAPI_Helper::get_password_hash($itxapi_username, $settings_result['data']['itxapi_password_raw']); // Generates hash for use as password for API. $account_info = pb_backupbuddy_destination_stash::get_quota(array('itxapi_username' => $itxapi_username, 'itxapi_password' => $itxapi_password), true); if ($account_info === false) { $credentials_form->display_settings('Submit'); } } } // end form submitted. } elseif ($mode == 'edit') { // EDIT MODE. //echo 'editmode?'; $account_info = pb_backupbuddy_destination_stash::get_quota(array('itxapi_username' => $destination_settings['itxapi_username'], 'itxapi_password' => $destination_settings['itxapi_password'])); $itxapi_username = $destination_settings['itxapi_username']; } if ($mode == 'save' || $mode == 'edit' || $itxapi_username != '') { $default_name = NULL; if ($mode != 'save' && 'edit' != $mode) { if ($account_info === false) { $pb_hide_test = true; $pb_hide_save = true; return false; } $account_details = 'Welcome to your BackupBuddy Stash, <b>' . $itxapi_username . '</b>. Your account is '; if ($account_info['subscriber_locked'] == '1') { $account_details .= 'LOCKED'; } elseif ($account_info['subscriber_expired'] == '1') { $account_details .= 'EXPIRED';
public function remote_send() { if (defined('PB_DEMO_MODE')) { die('Access denied in demo mode.'); } $success_output = false; // Set to true onece a leading 1 has been sent to the javascript to indicate success. $destination_id = pb_backupbuddy::_POST('destination_id'); if (pb_backupbuddy::_POST('file') != 'importbuddy.php') { $backup_file = pb_backupbuddy::$options['backup_directory'] . pb_backupbuddy::_POST('file'); } else { $backup_file = ''; } if (pb_backupbuddy::_POST('send_importbuddy') == '1') { $send_importbuddy = true; pb_backupbuddy::status('details', 'Cron send to be scheduled with importbuddy sending.'); } else { $send_importbuddy = false; pb_backupbuddy::status('details', 'Cron send to be scheduled WITHOUT importbuddy sending.'); } // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); //print_r( $stash_quota ); if ($backup_file != '') { $backup_file_size = filesize($backup_file); } else { $backip_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { echo "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage or delete files to make space.\n\n"; echo 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; echo 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; die; } else { if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') { echo '1Warning: ' . $stash_quota['quota_warning'] . "\n\n"; $success_output = true; } } } wp_schedule_single_event(time(), pb_backupbuddy::cron_tag('remote_send'), array($destination_id, $backup_file, pb_backupbuddy::_POST('trigger'), $send_importbuddy)); 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. // SEE cron.php remote_send() for sending function that we pass to via the cron above. if ($success_output === false) { echo 1; } die; }
echo '<br>'; pb_backupbuddy::status('details', 'Scheduling Cron for creating Stash copy.'); backupbuddy_core::schedule_single_event(time(), 'process_remote_copy', array('stash', pb_backupbuddy::_GET('cpy_file'), $settings)); spawn_cron(time() + 150); // Adds > 60 seconds to get around once per minute cron running limit. update_option('_transient_doing_cron', 0); // Prevent cron-blocking for next item. } // Handle download link if (pb_backupbuddy::_GET('downloadlink_file') != '') { $link = $s3->get_object($manage_data['bucket'], $manage_data['subkey'] . $remote_path . pb_backupbuddy::_GET('downloadlink_file'), array('preauth' => time() + 3600)); pb_backupbuddy::alert('You may download this backup (' . pb_backupbuddy::_GET('downloadlink_file') . ') with <a href="' . $link . '">this link</a>. The link is valid for one hour.'); echo '<br>'; } // QUOTA INFORMATION. $account_info = pb_backupbuddy_destination_stash::get_quota(array('itxapi_username' => $itxapi_username, 'itxapi_password' => $itxapi_password), false); /* echo '<pre>'; print_r( $account_info ); echo '</pre>'; */ echo pb_backupbuddy_destination_stash::get_quota_bar($account_info); echo '<div style="text-align: center;">'; echo ' <b>Upgrade to get more Stash space:</b> <a href="https://ithemes.com/member/cart.php?action=add&id=290" target="_blank" style="text-decoration: none; font-weight: 300;">+ 5GB</a>, <a href="https://ithemes.com/member/cart.php?action=add&id=291" target="_blank" style="text-decoration: none; font-weight: 600; font-size: 1.1em;">+ 10GB</a>, <a href="https://ithemes.com/member/cart.php?action=add&id=292" target="_blank" style="text-decoration: none; font-weight: 800; font-size: 1.2em;">+ 25GB</a> | <a href="https://sync.ithemes.com/stash/" target="_blank" style="text-decoration: none;"><b>Manage Files & Account</b></a> ';
public static function send_remote_destination($destination_id, $file, $trigger = '', $send_importbuddy = false, $delete_after = false, $identifier = '', $destination_settings = '') { if (defined('PB_DEMO_MODE')) { return false; } if (!file_exists($file)) { pb_backupbuddy::status('error', 'Error #8583489734: Unable to send file `' . $file . '` to remote destination as it no longer exists. It may have been deleted or permissions are invalid.'); return false; } $migrationkey_transient_time = 60 * 60 * 24; if ('' == $file) { $backup_file_size = 50000; // not sure why anything current would be sending importbuddy but NOT sending a backup but just in case... } else { $backup_file_size = filesize($file); } // Generate remote send ID for reference and add it as a new logging serial for better recording details. if ('' == $identifier) { $identifier = pb_backupbuddy::random_string(12); } // Set migration key for later determining last initiated migration. if ('migration' == $trigger) { set_transient('pb_backupbuddy_migrationkey', $identifier, $migrationkey_transient_time); } pb_backupbuddy::status('details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` with ID `' . $identifier . '` triggered by `' . $trigger . '`.'); //pb_backupbuddy::status( 'details', 'About to create initial fileoptions data.' ); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #35.'); $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $identifier . '.txt', $read_only = false, $ignore_lock = true, $create_file = true); if (true !== ($result = $fileoptions_obj->is_ok())) { pb_backupbuddy::status('error', __('Fatal Error #9034 A. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); return false; } //pb_backupbuddy::status( 'details', 'Fileoptions data loaded.' ); $fileoptions =& $fileoptions_obj->options; // Set reference. // Record some statistics. $fileoptions = array_merge(self::get_remote_send_defaults(), array('destination' => $destination_id, 'file' => $file, 'file_size' => $backup_file_size, 'trigger' => $trigger, 'send_importbuddy' => $send_importbuddy, 'start_time' => time(), 'finish_time' => 0, 'status' => 'running', 'write_speed' => 0)); pb_backupbuddy::save(); // Destination settings were not passed so get them based on the destination ID provided. if (!is_array($destination_settings)) { $destination_settings =& pb_backupbuddy::$options['remote_destinations'][$destination_id]; } // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); if ($file != '') { $backup_file_size = filesize($file); } else { $backup_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { $message = ''; $message .= "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage at http://ithemes.com/member/panel/stash.php or delete files to make space.\n\n"; $message .= 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('error', $message); backupbuddy_core::mail_error($message); $fileoptions['status'] = 'Failure. Insufficient destination space.'; $fileoptions_obj->save(); return false; } else { if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') { // We log warning of usage but dont send error email. $message = ''; $message .= 'WARNING: ' . $stash_quota['quota_warning'] . "\n\nPlease upgrade your Stash storage at http://ithemes.com/member/panel/stash.php or delete files to make space.\n\n"; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('details', $message); //backupbuddy_core::mail_error( $message ); } } } // end if stash. /* if ( $send_importbuddy === true ) { pb_backupbuddy::status( 'details', 'Generating temporary importbuddy.php file for remote send.' ); pb_backupbuddy::anti_directory_browsing( backupbuddy_core::getTempDirectory(), $die = false ); $importbuddy_temp = backupbuddy_core::getTempDirectory() . 'importbuddy.php'; // Full path & filename to temporary importbuddy self::importbuddy( $importbuddy_temp ); // Create temporary importbuddy. pb_backupbuddy::status( 'details', 'Generated temporary importbuddy.' ); $files[] = $importbuddy_temp; // Add importbuddy file to the list of files to send. $send_importbuddy = true; // Track to delete after finished. } else { pb_backupbuddy::status( 'details', 'Not sending importbuddy.' ); } */ // Clear fileoptions so other stuff can access it if needed. $fileoptions_obj->save(); $fileoptions_obj->unlock(); unset($fileoptions_obj); // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; pb_backupbuddy::status('details', 'Calling destination send() function.'); $send_result = pb_backupbuddy_destinations::send($destination_settings, $file, $identifier, $delete_after); pb_backupbuddy::status('details', 'Finished destination send() function.'); self::kick_db(); // Kick the database to make sure it didn't go away, preventing options saving. // Reload fileoptions. pb_backupbuddy::status('details', 'About to load fileoptions data for saving send status.'); require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php'; pb_backupbuddy::status('details', 'Fileoptions instance #34.'); $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $identifier . '.txt', $read_only = false, $ignore_lock = false, $create_file = false); if (true !== ($result = $fileoptions_obj->is_ok())) { pb_backupbuddy::status('error', __('Fatal Error #9034 G. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result); return false; } pb_backupbuddy::status('details', 'Fileoptions data loaded for ID `' . $identifier . '`.'); $fileoptions =& $fileoptions_obj->options; // Set reference. // Update stats. $fileoptions[$identifier]['finish_time'] = microtime(true); if ($send_result === true) { // succeeded. $fileoptions['status'] = 'success'; $fileoptions['finish_time'] = microtime(true); pb_backupbuddy::status('details', 'Remote send SUCCESS.'); } elseif ($send_result === false) { // failed. $fileoptions['status'] = 'failure'; pb_backupbuddy::status('details', 'Remote send FAILURE.'); } elseif (is_array($send_result)) { // Array so multipart. $fileoptions['status'] = 'multipart'; $fileoptions['finish_time'] = 0; $fileoptions['_multipart_id'] = $send_result[0]; $fileoptions['_multipart_status'] = $send_result[1]; pb_backupbuddy::status('details', 'Multipart send in progress.'); } else { pb_backupbuddy::status('error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.'); } $fileoptions_obj->save(); // If we sent importbuddy then delete the local copy to clean up. if ($send_importbuddy !== false) { @unlink($importbuddy_temp); // Delete temporary importbuddy. } // As of v5.0: Post-send deletion now handled within destinations/bootstrap.php send() to support chunked sends. return $send_result; }
public function remote_send() { $success_output = false; // Set to true onece a leading 1 has been sent to the javascript to indicate success. $destination_id = pb_backupbuddy::_POST('destination_id'); if (pb_backupbuddy::_POST('file') != 'importbuddy.php') { $backup_file = backupbuddy_core::getBackupDirectory() . pb_backupbuddy::_POST('file'); if (!file_exists($backup_file)) { // Error if file to send did not exist! $error_message = 'Unable to find file `' . $backup_file . '` to send. File does not appear to exist. You can try again in a moment or turn on full error logging and try again to log for support.'; pb_backupbuddy::status('error', $error_message); pb_backupbuddy::alert($error_message, true); die; } } else { $backup_file = ''; } // Send ImportBuddy along-side? if (pb_backupbuddy::_POST('send_importbuddy') == '1') { $send_importbuddy = true; pb_backupbuddy::status('details', 'Cron send to be scheduled with importbuddy sending.'); } else { $send_importbuddy = false; pb_backupbuddy::status('details', 'Cron send to be scheduled WITHOUT importbuddy sending.'); } // Delete local copy after send completes? if (pb_backupbuddy::_POST('delete_after') == 'true') { $delete_after = true; pb_backupbuddy::status('details', 'Remote send set to delete after successful send.'); } else { $delete_after = false; pb_backupbuddy::status('details', 'Remote send NOT set to delete after successful send.'); } // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); if (isset($stash_quota['error'])) { echo ' Error accessing Stash account. Send aborted. Details: `' . implode(' - ', $stash_quota['error']) . '`.'; die; } if ($backup_file != '') { $backup_file_size = filesize($backup_file); } else { $backup_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { echo "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage or delete files to make space.\n\n"; echo 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; echo 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; die; } else { if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') { echo '1Warning: ' . $stash_quota['quota_warning'] . "\n\n"; $success_output = true; } } } // end if Stash. pb_backupbuddy::status('details', 'Scheduling cron to send to this remote destination...'); $schedule_result = backupbuddy_core::schedule_single_event(time(), pb_backupbuddy::cron_tag('remote_send'), array($destination_id, $backup_file, pb_backupbuddy::_POST('trigger'), $send_importbuddy, $delete_after)); if ($schedule_result === FALSE) { $error = 'Error scheduling file transfer. Please check your BackupBuddy error log for details. A plugin may have prevented scheduling or the database rejected it.'; pb_backupbuddy::status('error', $error); echo $error; } else { pb_backupbuddy::status('details', 'Cron to send to remote destination scheduled.'); } spawn_cron(time() + 150); // Adds > 60 seconds to get around once per minute cron running limit. update_option('_transient_doing_cron', 0); // Prevent cron-blocking for next item. // SEE cron.php remote_send() for sending function that we pass to via the cron above. if ($success_output === false) { echo 1; } die; }
$delete_after = true; pb_backupbuddy::status('details', 'Remote send set to delete after successful send.'); } else { $delete_after = false; pb_backupbuddy::status('details', 'Remote send NOT set to delete after successful send.'); } if (!isset(pb_backupbuddy::$options['remote_destinations'][$destination_id])) { die('Error #833383: Invalid destination ID `' . htmlentities($destination_id) . '`.'); } // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); if (isset($stash_quota['error'])) { echo ' Error accessing Stash account. Send aborted. Details: `' . implode(' - ', $stash_quota['error']) . '`.'; die; } if ($backup_file != '') { $backup_file_size = filesize($backup_file); } else { $backup_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { echo "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage or delete files to make space.\n\n"; echo 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; echo 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; die; } else {
function send_remote_destination($destination_id, $file, $trigger = '', $send_importbuddy = false) { pb_backupbuddy::status('details', 'Sending file `' . $file . '` to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.'); if (defined('PB_DEMO_MODE')) { return false; } // Record some statistics. $identifier = pb_backupbuddy::random_string(12); pb_backupbuddy::$options['remote_sends'][$identifier] = array('destination' => $destination_id, 'file' => $file, 'file_size' => filesize($file), 'trigger' => $trigger, 'send_importbuddy' => $send_importbuddy, 'start_time' => time(), 'finish_time' => 0, 'status' => 'timeout'); pb_backupbuddy::save(); // Prepare variables to pass to remote destination handler. $files = array($file); $destination_settings =& pb_backupbuddy::$options['remote_destinations'][$destination_id]; // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); if ($file != '') { $backup_file_size = filesize($file); } else { $backip_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { $message = ''; $message .= "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n"; $message .= 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('error', $message); pb_backupbuddy::$classes['core']->mail_error($message); pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'Failure. Insufficient destination space.'; pb_backupbuddy::save(); return false; } else { if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') { // We log warning of usage but dont send error email. $message = ''; $message .= 'WARNING: ' . $stash_quota['quota_warning'] . "\n\nPlease upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n"; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('details', $message); //pb_backupbuddy::$classes['core']->mail_error( $message ); } } } if ($send_importbuddy === true) { pb_backupbuddy::status('details', 'Generating temporary importbuddy.php file for remote send.'); $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy.php'; // Full path & filename to temporary importbuddy $this->importbuddy($importbuddy_temp); // Create temporary importbuddy. pb_backupbuddy::status('details', 'Generated temporary importbuddy.'); $files[] = $importbuddy_temp; // Add importbuddy file to the list of files to send. $send_importbuddy = true; // Track to delete after finished. } else { pb_backupbuddy::status('details', 'Not sending importbuddy.'); } // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::send($destination_settings, $files); $this->kick_db(); // Kick the database to make sure it didn't go away, preventing options saving. // Update stats. pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time(); if ($send_result === true) { // succeeded. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'success'; pb_backupbuddy::status('details', 'Remote send SUCCESS.'); } elseif ($send_result === false) { // failed. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'failure'; pb_backupbuddy::status('details', 'Remote send FAILURE.'); } elseif (is_array($send_result)) { // Array so multipart. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'multipart'; pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = 0; pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_id'] = $send_result[0]; pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = $send_result[1]; pb_backupbuddy::status('details', 'Multipart send in progress.'); } else { pb_backupbuddy::status('error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.'); } pb_backupbuddy::save(); // If we sent importbuddy then delete the local copy to clean up. if ($send_importbuddy !== false) { @unlink($importbuddy_temp); // Delete temporary importbuddy. } return $send_result; }
function send_remote_destination($destination_id, $file, $trigger = '', $send_importbuddy = false, $delete_after = false) { if (defined('PB_DEMO_MODE')) { return false; } if ('' == $file) { $backup_file_size = 50000; // not sure why anything current would be sending importbuddy but NOT sending a backup but just in case... } else { $backup_file_size = filesize($file); } pb_backupbuddy::status('details', 'Sending file `' . $file . '` (size: `' . $backup_file_size . '`) to remote destination `' . $destination_id . '` triggered by `' . $trigger . '`.'); // Record some statistics. $identifier = pb_backupbuddy::random_string(12); pb_backupbuddy::$options['remote_sends'][$identifier] = array('destination' => $destination_id, 'file' => $file, 'file_size' => $backup_file_size, 'trigger' => $trigger, 'send_importbuddy' => $send_importbuddy, 'start_time' => time(), 'finish_time' => 0, 'status' => 'timeout'); pb_backupbuddy::save(); // Prepare variables to pass to remote destination handler. if ('' == $file) { // No file to send (blank string file typically happens when just sending importbuddy). $files = array(); } else { $files = array($file); } $destination_settings =& pb_backupbuddy::$options['remote_destinations'][$destination_id]; // For Stash we will check the quota prior to initiating send. if (pb_backupbuddy::$options['remote_destinations'][$destination_id]['type'] == 'stash') { // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::get_info('stash'); // Used to kick the Stash destination into life. $stash_quota = pb_backupbuddy_destination_stash::get_quota(pb_backupbuddy::$options['remote_destinations'][$destination_id], true); if ($file != '') { $backup_file_size = filesize($file); } else { $backup_file_size = 50000; } if ($backup_file_size + $stash_quota['quota_used'] > $stash_quota['quota_total']) { $message = ''; $message .= "You do not have enough Stash storage space to send this file. Please upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n"; $message .= 'Attempting to send file of size ' . pb_backupbuddy::$format->file_size($backup_file_size) . ' but you only have ' . $stash_quota['quota_available_nice'] . ' available. '; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('error', $message); pb_backupbuddy::$classes['core']->mail_error($message); pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'Failure. Insufficient destination space.'; pb_backupbuddy::save(); return false; } else { if (isset($stash_quota['quota_warning']) && $stash_quota['quota_warning'] != '') { // We log warning of usage but dont send error email. $message = ''; $message .= 'WARNING: ' . $stash_quota['quota_warning'] . "\n\nPlease upgrade your Stash storage at http://ithemes.com/member/stash.php or delete files to make space.\n\n"; $message .= 'Currently using ' . $stash_quota['quota_used_nice'] . ' of ' . $stash_quota['quota_total_nice'] . ' (' . $stash_quota['quota_used_percent'] . '%).'; pb_backupbuddy::status('details', $message); //pb_backupbuddy::$classes['core']->mail_error( $message ); } } } if ($send_importbuddy === true) { pb_backupbuddy::status('details', 'Generating temporary importbuddy.php file for remote send.'); $importbuddy_temp = pb_backupbuddy::$options['temp_directory'] . 'importbuddy.php'; // Full path & filename to temporary importbuddy $this->importbuddy($importbuddy_temp); // Create temporary importbuddy. pb_backupbuddy::status('details', 'Generated temporary importbuddy.'); $files[] = $importbuddy_temp; // Add importbuddy file to the list of files to send. $send_importbuddy = true; // Track to delete after finished. } else { pb_backupbuddy::status('details', 'Not sending importbuddy.'); } // Pass off to destination handler. require_once pb_backupbuddy::plugin_path() . '/destinations/bootstrap.php'; $send_result = pb_backupbuddy_destinations::send($destination_settings, $files); $this->kick_db(); // Kick the database to make sure it didn't go away, preventing options saving. // Update stats. pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = time(); if ($send_result === true) { // succeeded. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'success'; pb_backupbuddy::status('details', 'Remote send SUCCESS.'); } elseif ($send_result === false) { // failed. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'failure'; pb_backupbuddy::status('details', 'Remote send FAILURE.'); } elseif (is_array($send_result)) { // Array so multipart. pb_backupbuddy::$options['remote_sends'][$identifier]['status'] = 'multipart'; pb_backupbuddy::$options['remote_sends'][$identifier]['finish_time'] = 0; pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_id'] = $send_result[0]; pb_backupbuddy::$options['remote_sends'][$identifier]['_multipart_status'] = $send_result[1]; pb_backupbuddy::status('details', 'Multipart send in progress.'); } else { pb_backupbuddy::status('error', 'Error #5485785576463. Invalid status send result: `' . $send_result . '`.'); } pb_backupbuddy::save(); // If we sent importbuddy then delete the local copy to clean up. if ($send_importbuddy !== false) { @unlink($importbuddy_temp); // Delete temporary importbuddy. } // Handle post-send deletion on success. pb_backupbuddy::status('details', 'Checking if local file should be deleted after remote send based on settings.'); if (true === $send_result) { // Success; only continue on bool true. false indicates failure, array chunking. if (true == $delete_after) { // Delete enabled so delete file. pb_backupbuddy::status('details', 'Local file should be deleted based on settings & success. Deleting local copy of file sent to destination.'); if (file_exists($file)) { $unlink_result = @unlink($file); if (true !== $unlink_result) { pb_backupbuddy::status('error', 'Unable to unlink local file `' . $file . '`.'); } } if (file_exists($file)) { // File still exists. pb_backupbuddy::status('details', __('Error. Unable to delete local file `' . $file . '` after send as set in settings.', 'it-l10n-backupbuddy')); $this->mail_error('BackupBuddy was unable to delete local file `' . $file . '` after successful remove transfer though post-remote send deletion is enabled. You may want to delete it manually. This can be caused by permission problems or improper server configuration.'); } else { // Deleted. pb_backupbuddy::status('details', __('Deleted local archive after successful remote destination send based on settings.', 'it-l10n-backupbuddy')); pb_backupbuddy::status('action', 'archive_deleted'); } } else { // Delete after disabled. pb_backupbuddy::status('details', 'Post-send local file deletion disabled so skipping.'); } } else { // Send failed or not complete (chunking). pb_backupbuddy::status('details', 'Remote send not completed so skipping post-send deletion check.'); } return $send_result; }