Example #1
0
 public static function test($settings)
 {
     $remote_path = self::get_remote_path($settings['directory']);
     // Has leading and trailng slashes.
     $manage_data = pb_backupbuddy_destination_stash::get_manage_data($settings);
     if (!is_array($manage_data['credentials'])) {
         // Credentials were somehow faulty. User changed password after prior page? Unlikely but you never know...
         $error_msg = 'Error #8484383c: Your authentication credentials for Stash failed. Verify your login and password to Stash. You may need to update the Stash destination settings. Perhaps you recently changed your password?';
         pb_backupbuddy::status('error', $error_msg);
         return $error_msg;
     }
     // Try sending a file.
     $send_response = pb_backupbuddy_destinations::send($settings, dirname(dirname(__FILE__)) . '/remote-send-test.php', $send_id = 'TEST-' . pb_backupbuddy::random_string(12));
     // 3rd param true forces clearing of any current uploads.
     if (false === $send_response) {
         $send_response = 'Error sending test file to Stash.';
     } else {
         $send_response = 'Success.';
     }
     // S3 object for managing files.
     $credentials = pb_backupbuddy_destination_stash::get_manage_data($settings);
     $s3_manage = new AmazonS3($manage_data['credentials']);
     if ($settings['ssl'] == 0) {
         @$s3_manage->disable_ssl(true);
     }
     // Delete sent file.
     $delete_response = 'Success.';
     $delete_response = $s3_manage->delete_object($manage_data['bucket'], $manage_data['subkey'] . $remote_path . 'remote-send-test.php');
     if (!$delete_response->isOK()) {
         $delete_response = 'Unable to delete test Stash file `remote-send-test.php`. Details: `' . print_r($response, true) . '`.';
         pb_backupbuddy::status('details', $delete_response);
     } else {
         $delete_response = 'Success.';
     }
     // Load destination fileoptions.
     pb_backupbuddy::status('details', 'About to load fileoptions data.');
     require_once pb_backupbuddy::plugin_path() . '/classes/fileoptions.php';
     $fileoptions_obj = new pb_backupbuddy_fileoptions(backupbuddy_core::getLogDirectory() . 'fileoptions/send-' . $send_id . '.txt', $read_only = false, $ignore_lock = false, $create_file = false);
     if (true !== ($result = $fileoptions_obj->is_ok())) {
         pb_backupbuddy::status('error', __('Fatal Error #9034.84838. Unable to access fileoptions data.', 'it-l10n-backupbuddy') . ' Error: ' . $result);
         return false;
     }
     pb_backupbuddy::status('details', 'Fileoptions data loaded.');
     $fileoptions =& $fileoptions_obj->options;
     if ('Success.' != $send_response || 'Success.' != $delete_response) {
         $fileoptions['status'] = 'failure';
         $fileoptions_obj->save();
         unset($fileoptions_obj);
         return 'Send details: `' . $send_response . '`. Delete details: `' . $delete_response . '`.';
     } else {
         $fileoptions['status'] = 'success';
         $fileoptions['finish_time'] = time();
     }
     $fileoptions_obj->save();
     unset($fileoptions_obj);
     return true;
 }
Example #2
0
 public static function test($settings)
 {
     $remote_path = self::get_remote_path($settings['directory']);
     // Has leading and trailng slashes.
     // Try sending a file.
     $test_result = self::send($settings, dirname(__FILE__) . '/icon.png', true);
     // 3rd param true forces clearing of any current uploads.
     // S3 object for managing files.
     $manage_data = pb_backupbuddy_destination_stash::get_manage_data($settings);
     $s3_manage = new AmazonS3($manage_data['credentials']);
     if ($settings['ssl'] == 0) {
         @$s3_manage->disable_ssl(true);
     }
     // Delete sent file.
     $response = $s3_manage->delete_object($manage_data['bucket'], $manage_data['subkey'] . $remote_path . 'icon.png');
     if (!$response->isOK()) {
         pb_backupbuddy::status('details', 'Unable to delete test Stash file `' . $buname . '`. Details: `' . print_r($response, true) . '`.');
     }
     delete_transient('pb_backupbuddy_stashquota_' . $settings['itxapi_username']);
     // Delete quota transient since it probably has changed now.
     return $test_result;
 }
Example #3
0
    $itxapi_username = strtolower(pb_backupbuddy::_POST('itxapi_username'));
    $itxapi_password = ITXAPI_Helper::get_password_hash($itxapi_username, pb_backupbuddy::_POST('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 (false !== $account_info) {
        // New credentials are good. Update destination settings.
        $settings['itxapi_username'] = $itxapi_username;
        $settings['itxapi_password'] = $itxapi_password;
        pb_backupbuddy::save();
        // $settings is a reference so this will save the propr destination settings.
        pb_backupbuddy::alert(__('Success re-authenticating to your Stash account.', 'it-l10n-backupbuddy'));
        echo '<br>';
    }
}
// Validate authentication with Stash.
$manage_data = pb_backupbuddy_destination_stash::get_manage_data($settings, $suppressAuthAlert = true);
if (!is_array($manage_data['credentials']) || '1' == pb_backupbuddy::_GET('force_stash_reauth')) {
    // If not array it's because auth is invalid.
    if (!is_array($manage_data['credentials'])) {
        // Re-auth due to authentication failure. Other case could be a manual re-auth.
        echo '<h3>' . __('Stash Authentication Failed - Please log back in', 'it-l10n-backupbuddy') . '</h3>';
        _e('This is most often caused by changing your password.', 'it-l10n-backupbuddy');
        echo ' ';
    }
    _e('Log back in with your iThemes.com member account below.', 'it-l10n-backupbuddy');
    ?>
	
	<form method="post" action="<?php 
    echo pb_backupbuddy::ajax_url('remoteClient') . '&destination_id=' . htmlentities(pb_backupbuddy::_GET('destination_id'));
    ?>
">
Example #4
0
        if ($account_info === false) {
            pb_backupbuddy_stash_pass_form();
            delete_transient('pb_backupbuddy_stashallfiles_' . $current_user->user_login);
            return;
        } else {
            // Valid login. Cache access for 1hr for this user.
            //echo 'settrans';
            //set_transient( 'pb_backupbuddy_stashallfiles_' . $current_user->user_login, $itxapi_password, $stash_allfiles_access_timelimit );
            $stash_hash = $itxapi_password;
        }
    }
}
echo '<span id="pb_backupbuddy_stashhash" rel="' . $itxapi_password . '" style="display: none;"></span>';
// Talk with the Stash API to get access to do things.
$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);
// Connect to S3.
$s3 = new AmazonS3($manage_data['credentials']);
// the key, secret, token
if ($settings['ssl'] == '0') {
    @$s3->disable_ssl(true);
}
// Handle deletion.
if (pb_backupbuddy::_POST('bulk_action') == 'delete_backup') {
    pb_backupbuddy::verify_nonce();
    $deleted_files = array();
    foreach ((array) pb_backupbuddy::_POST('items') as $item) {
        $response = $s3->delete_object($manage_data['bucket'], $manage_data['subkey'] . $remote_path . $item);
        if ($response->isOK()) {
            $deleted_files[] = $item;
        } else {
                pb_backupbuddy::alert(__('Deployments have been enabled for this site. Other sites sharing this Stash account may Push to or Pull from this site as long as your iThemes Member password is correctly provided.', 'it-l10n-backupbuddy'));
            } else {
                pb_backupbuddy::alert(__('Error #84838: Failure notifying Stash of new deployment site. See Remote Destinations page Recent Transfers listing for details.', 'it-l10n-backupbuddy'));
            }
        }
    } elseif ('disable' == pb_backupbuddy::_GET('deploy')) {
        pb_backupbuddy::$options['deployment_allowed'] = '0';
        pb_backupbuddy::save();
        pb_backupbuddy::alert(__('Deployments have been disabled for this site.', 'it-l10n-backupbuddy'));
    }
}
if (false !== $stashDestination) {
    require_once pb_backupbuddy::plugin_path() . '/destinations/stash/lib/class.itx_helper.php';
    require_once pb_backupbuddy::plugin_path() . '/destinations/stash/init.php';
    //$stash = new ITXAPI_Helper( pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, pb_backupbuddy::$options['remote_destinations'][ $stashDestination ]['itxapi_username'], pb_backupbuddy::$options['remote_destinations'][ $stashDestination ]['itxapi_password'] );
    $manage_data = pb_backupbuddy_destination_stash::get_manage_data(pb_backupbuddy::$options['remote_destinations'][$stashDestination]);
    // Connect to S3.
    if (!is_array($manage_data['credentials'])) {
        die('Error #8484383c: Your authentication credentials for Stash failed. Verify your login and password to Stash. You may need to update the Stash destination settings. Perhaps you recently changed your password?');
    }
    $s3 = new AmazonS3($manage_data['credentials']);
    // the key, secret, token
    if (pb_backupbuddy::$options['remote_destinations'][$stashDestination]['ssl'] == '0') {
        @$s3->disable_ssl(true);
    }
    $response = $s3->list_objects($manage_data['bucket'], array('prefix' => $manage_data['subkey'] . '/deploy'));
    // list all the files in the subscriber account
    echo '<pre>';
    print_r($response);
    echo '</pre>';
    foreach ($response->body->Contents as $object) {
Example #6
0
 public static function send($settings = array(), $file, $send_id = '', $delete_after = false, $clear_uploads = false)
 {
     global $pb_backupbuddy_destination_errors;
     if ('1' == $settings['disabled']) {
         $pb_backupbuddy_destination_errors[] = __('Error #48933: This destination is currently disabled. Enable it under this destination\'s Advanced Settings.', 'it-l10n-backupbuddy');
         return false;
     }
     if (is_array($file)) {
         $file = $files[0];
     }
     $remote_path = self::get_remote_path();
     // Has leading and trailng slashes.
     $additionalParams = array('filename' => $remote_path . '/' . basename($file), 'size' => filesize($file), 'timezone' => get_option('timezone_string'));
     $response = self::stashAPI($settings, 'upload', $additionalParams);
     echo '<pre>';
     print_r($response);
     echo '</pre>';
     die;
     pb_backupbuddy::status('details', 'Post-send deletion: ' . $delete_after);
     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;
     }
     $meta = array();
     if (isset($settings['meta'])) {
         pb_backupbuddy::status('details', 'Meta setting passed. Applying to all files in this pass.');
         $meta = $settings['meta'];
     }
     $forceRootUpload = false;
     if (isset($settings['forceRootUpload'])) {
         $forceRootUpload = $settings['forceRootUpload'];
     }
     $itxapi_username = $settings['itxapi_username'];
     $itxapi_password = $settings['itxapi_password'];
     if (true === $forceRootUpload) {
         pb_backupbuddy::status('details', 'Forcing root upload.');
         $remote_path = '/';
     } else {
         pb_backupbuddy::status('details', 'Not forcing root upload. Calculting root path.');
         $remote_path = self::get_remote_path($settings['directory']);
         // Has leading and trailng slashes.
     }
     pb_backupbuddy::status('details', 'Stash remote path set to `' . $remote_path . '`.');
     require_once dirname(__FILE__) . '/lib/class.itx_helper.php';
     require_once pb_backupbuddy::plugin_path() . '/_s3lib2/aws-autoloader.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);
     if (!is_array($manage_data['credentials'])) {
         pb_backupbuddy::status('error', 'Error #8484383b: Your authentication credentials for Stash failed. Verify your login and password to Stash. You may need to update the Stash destination settings. Perhaps you recently changed your password?');
         return false;
     }
     // 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);
     	try {
     		$response = $request->send_request( true );
     	} catch (Exception $e) {
     		$error = 'Error #237836: Unable to clear Stash quota information. Details:`' . $e->getMessage() . '`.';
     		pb_backupbuddy::status( 'error', $error );
     		echo $error;
     		return false;
     	        }
     }
     */
     delete_transient('pb_backupbuddy_stash2quota_' . $settings['itxapi_username']);
     // Delete quota transient since it probably has changed now.
     // Success if we made it this far.
     return true;
 }