Пример #1
0
 public static function get_manage_data($settings)
 {
     $itxapi_username = $settings['itxapi_username'];
     $itxapi_password = $settings['itxapi_password'];
     require_once dirname(__FILE__) . '/lib/class.itx_helper.php';
     require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php';
     $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
     //  get the url to use to request management credentials
     //  url looks something like this - http://api.ithemes.com/stash/upload?apikey=sb31kesem0c879m0&expires=1347439653&subscriber=jwooley&signature=VFMbmXb5OorWwqE0iedOCsDtSgs%3D
     $manage_url = $stash->get_manage_url();
     //  create a new RequestCore to get the credentials
     //  NOTE: RequestCore is part of the AWS SDK, it's a generic http request class.
     //        You can use any available function to make the api request, the wordpress http class for example,
     //        or even just the basic file_get_contents()
     $request = new RequestCore($manage_url);
     //  send the api request
     $response = $request->send_request(true);
     //  see if the request was successful
     if (!$response->isOK()) {
         //throw new Exception('Request for management credentials failed.');
         $error = 'Request for management credentials failed.';
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     //  see if we got a json response
     if (!($manage_data = json_decode($response->body, true))) {
         $error = 'Did not get valid JSON response.';
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     //  finally see if the API returned an error
     if (isset($manage_data['error'])) {
         $error = 'Error: ' . implode(' - ', $manage_data['error']);
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     return $manage_data;
 }
Пример #2
0
            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);
// Re-authenticating to Stash.
if ('1' == pb_backupbuddy::_POST('stash_reauth')) {
    $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')) {
Пример #3
0
        return;
    } else {
        // Form submitted.
        if (count($settings_result['errors']) > 0) {
            // Form errors.
            echo $login_welcome;
            pb_backupbuddy::alert(implode('<br>', $settings_result['errors']));
            $credentials_form->display_settings('Submit');
            $pb_hide_test = true;
            $pb_hide_save = true;
            return;
        } else {
            // 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 != '') {
Пример #4
0
 function process_remote_copy($destination_type, $file, $settings)
 {
     pb_backupbuddy::status('details', 'Copying remote `' . $destination_type . '` file `' . $file . '` down to local.');
     pb_backupbuddy::set_greedy_script_limits();
     if (!class_exists('backupbuddy_core')) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     }
     // Determine destination filename.
     $destination_file = backupbuddy_core::getBackupDirectory() . basename($file);
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     pb_backupbuddy::status('details', 'Filename of resulting local copy: `' . $destination_file . '`.');
     if ($destination_type == 'stash2') {
         require_once ABSPATH . 'wp-admin/includes/file.php';
         pb_backupbuddy::status('details', 'About to begin downloading from URL.');
         $download = download_url($url);
         pb_backupbuddy::status('details', 'Download process complete.');
         if (is_wp_error($download)) {
             $error = 'Error #832989323: Unable to download file `' . $file . '` from URL: `' . $url . '`. Details: `' . $download->get_error_message() . '`.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         } else {
             if (false === copy($download, $destination_file)) {
                 $error = 'Error #3329383: Unable to copy file from `' . $download . '` to `' . $destination_file . '`.';
                 pb_backupbuddy::status('error', $error);
                 pb_backupbuddy::alert($error);
                 @unlink($download);
                 return false;
             } else {
                 pb_backupbuddy::status('details', 'File saved to `' . $destination_file . '`.');
                 @unlink($download);
                 return true;
             }
         }
     }
     // end stash2.
     if ($destination_type == 'stash') {
         $itxapi_username = $settings['itxapi_username'];
         $itxapi_password = $settings['itxapi_password'];
         // Load required files.
         pb_backupbuddy::status('details', 'Load Stash files.');
         require_once pb_backupbuddy::plugin_path() . '/destinations/stash/init.php';
         require_once dirname(dirname(__FILE__)) . '/destinations/_s3lib/aws-sdk/sdk.class.php';
         require_once pb_backupbuddy::plugin_path() . '/destinations/stash/lib/class.itx_helper.php';
         // Talk with the Stash API to get access to do things.
         pb_backupbuddy::status('details', 'Authenticating Stash for remote copy to local.');
         $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
         $manage_url = $stash->get_manage_url();
         $request = new RequestCore($manage_url);
         $response = $request->send_request(true);
         // Validate response.
         if (!$response->isOK()) {
             $error = 'Request for management credentials failed.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         if (!($manage_data = json_decode($response->body, true))) {
             $error = 'Did not get valid JSON response.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         if (isset($manage_data['error'])) {
             $error = 'Error: ' . implode(' - ', $manage_data['error']);
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         // Connect to S3.
         pb_backupbuddy::status('details', 'Instantiating S3 object.');
         $s3 = new AmazonS3($manage_data['credentials']);
         pb_backupbuddy::status('details', 'About to get Stash object `' . $file . '`...');
         try {
             $response = $s3->get_object($manage_data['bucket'], $manage_data['subkey'] . pb_backupbuddy_destination_stash::get_remote_path() . $file, array('fileDownload' => $destination_file));
         } catch (Exception $e) {
             pb_backupbuddy::status('error', 'Error #5443984: ' . $e->getMessage());
             error_log('err:' . $e->getMessage());
             return false;
         }
         if ($response->isOK()) {
             pb_backupbuddy::status('details', 'Stash copy to local success.');
             return true;
         } else {
             pb_backupbuddy::status('error', 'Error #894597845. Stash copy to local FAILURE. Details: `' . print_r($response, true) . '`.');
             return false;
         }
     } elseif ($destination_type == 'gdrive') {
         die('Not implemented here.');
         require_once pb_backupbuddy::plugin_path() . '/destinations/gdrive/init.php';
         $settings = array_merge(pb_backupbuddy_destination_gdrive::$default_settings, $settings);
         if (true === pb_backupbuddy_destination_gdrive::getFile($settings, $file, $destination_file)) {
             // success
             pb_backupbuddy::status('details', 'Google Drive copy to local success.');
             return true;
         } else {
             // fail
             pb_backupbuddy::status('details', 'Error #2332903. Google Drive copy to local FAILURE.');
             return false;
         }
     } elseif ($destination_type == 's3') {
         require_once pb_backupbuddy::plugin_path() . '/destinations/s3/init.php';
         if (true === pb_backupbuddy_destination_s3::download_file($settings, $file, $destination_file)) {
             // success
             pb_backupbuddy::status('details', 'S3 copy to local success.');
             return true;
         } else {
             // fail
             pb_backupbuddy::status('details', 'Error #85448774. S3 copy to local FAILURE.');
             return false;
         }
     } else {
         pb_backupbuddy::status('error', 'Error #859485. Unknown destination type for remote copy `' . $destination_type . '`.');
         return false;
     }
 }
Пример #5
0
 function process_remote_copy($destination_type, $file, $settings)
 {
     pb_backupbuddy::status('details', 'Copying remote `' . $destination_type . '` file `' . $file . '` down to local.');
     pb_backupbuddy::set_greedy_script_limits();
     if (!class_exists('backupbuddy_core')) {
         require_once pb_backupbuddy::plugin_path() . '/classes/core.php';
     }
     // Determine destination filename.
     $destination_file = backupbuddy_core::getBackupDirectory() . basename($file);
     if (file_exists($destination_file)) {
         $destination_file = str_replace('backup-', 'backup_copy_' . pb_backupbuddy::random_string(5) . '-', $destination_file);
     }
     pb_backupbuddy::status('details', 'Filename of resulting local copy: `' . $destination_file . '`.');
     if ($destination_type == 'stash') {
         $itxapi_username = $settings['itxapi_username'];
         $itxapi_password = $settings['itxapi_password'];
         // Load required files.
         require_once pb_backupbuddy::plugin_path() . '/destinations/stash/init.php';
         require_once pb_backupbuddy::plugin_path() . '/destinations/stash/lib/class.itx_helper.php';
         // 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_url = $stash->get_manage_url();
         $request = new RequestCore($manage_url);
         $response = $request->send_request(true);
         // Validate response.
         if (!$response->isOK()) {
             $error = 'Request for management credentials failed.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         if (!($manage_data = json_decode($response->body, true))) {
             $error = 'Did not get valid JSON response.';
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         if (isset($manage_data['error'])) {
             $error = 'Error: ' . implode(' - ', $manage_data['error']);
             pb_backupbuddy::status('error', $error);
             pb_backupbuddy::alert($error);
             return false;
         }
         // Connect to Amazon S3.
         pb_backupbuddy::status('details', 'Instantiating S3 object.');
         $s3 = new AmazonS3($manage_data['credentials']);
         pb_backupbuddy::status('details', 'About to get Stash object `' . $file . '`...');
         $response = $s3->get_object($manage_data['bucket'], $manage_data['subkey'] . '/' . $file, array('fileDownload' => $destination_file));
         if ($response->isOK()) {
             pb_backupbuddy::status('details', 'Stash copy to local success.');
             return true;
         } else {
             pb_backupbuddy::status('error', 'Error #894597845. Stash copy to local FAILURE. Details: `' . print_r($response, true) . '`.');
             return false;
         }
     } elseif ($destination_type == 's3') {
         require_once pb_backupbuddy::plugin_path() . '/destinations/s3/init.php';
         if (true === pb_backupbuddy_destination_s3::download_file($settings, $file, $destination_file)) {
             // success
             pb_backupbuddy::status('details', 'S3 copy to local success.');
             return true;
         } else {
             // fail
             pb_backupbuddy::status('details', 'Error #85448774. S3 copy to local FAILURE.');
             return false;
         }
     } else {
         pb_backupbuddy::status('error', 'Error #859485. Unknown destination type for remote copy `' . $destination_type . '`.');
         return false;
     }
 }
Пример #6
0
    /*
    $stash_password = get_transient( 'pb_backupbuddy_stashallfiles_' . $current_user->user_login );
    echo 'pass: '******'';
    if (pb_backupbuddy::_POST('stash_password') != '') {
        $stash_password = pb_backupbuddy::_POST('stash_password');
    }
    if ($stash_password == '' && pb_backupbuddy::_GET('stashhash') == '') {
        pb_backupbuddy_stash_pass_form();
        return;
    } else {
        if (pb_backupbuddy::_GET('stashhash') != '') {
            $itxapi_password = pb_backupbuddy::_GET('stashhash');
        } else {
            $itxapi_password = ITXAPI_Helper::get_password_hash($itxapi_username, $stash_password);
            // 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) {
            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;
        }
    }
}
Пример #7
0
 public static function get_manage_data($settings, $suppressAuthAlert = false)
 {
     $itxapi_username = $settings['itxapi_username'];
     $itxapi_password = $settings['itxapi_password'];
     require_once dirname(__FILE__) . '/lib/class.itx_helper.php';
     require_once dirname(dirname(__FILE__)) . '/_s3lib/aws-sdk/sdk.class.php';
     $stash = new ITXAPI_Helper(pb_backupbuddy_destination_stash::ITXAPI_KEY, pb_backupbuddy_destination_stash::ITXAPI_URL, $itxapi_username, $itxapi_password);
     //  get the url to use to request management credentials
     //  url looks something like this - http://api.ithemes.com/stash/upload?apikey=sb31kesem0c879m0&expires=1347439653&subscriber=jwooley&signature=VFMbmXb5OorWwqE0iedOCsDtSgs%3D
     $manage_url = $stash->get_manage_url();
     //  create a new RequestCore to get the credentials
     //  NOTE: RequestCore is part of the AWS SDK, it's a generic http request class.
     //        You can use any available function to make the api request, the wordpress http class for example,
     //        or even just the basic file_get_contents()
     $request = new RequestCore($manage_url);
     //  send the api request
     try {
         $response = $request->send_request(true);
     } catch (Exception $e) {
         $error = 'Error #23873631: Unable to initiate Stash request. Details:`' . $e->getMessage() . '`.';
         pb_backupbuddy::status('error', $error);
         echo $error;
         return false;
     }
     //  see if the request was successful
     if (!$response->isOK()) {
         //throw new Exception('Request for management credentials failed.');
         $error = 'Request for management credentials failed.';
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     //  see if we got a json response
     if (!($manage_data = json_decode($response->body, true))) {
         $error = 'Did not get valid JSON response.';
         pb_backupbuddy::status('error', $error);
         pb_backupbuddy::alert($error);
         return false;
     }
     //  finally see if the API returned an error
     if (isset($manage_data['error'])) {
         $error = 'Error: ' . implode(' - ', $manage_data['error']);
         pb_backupbuddy::status('error', $error);
         if (true === $suppressAuthAlert && '3002' == $manage_data['error']['code']) {
             // Alert suppressed.
         } else {
             pb_backupbuddy::alert($error);
         }
         return false;
     }
     if ('1' == $settings['use_packaged_cert']) {
         pb_backupbuddy::status('details', 'Using packaged cacert.pem file based on destination settings.');
         $manage_data['ssl.certificate_authority'] = pb_backupbuddy::plugin_path() . '/destinations/_s3lib/aws-sdk/lib/requestcore/cacert.pem';
     }
     return $manage_data;
 }
 // Form submitted.
 if (count($settings_result['errors']) > 0) {
     // Form errors.
     echo $login_welcome;
     pb_backupbuddy::alert(implode('<br>', $settings_result['errors']));
     $credentials_form->display_settings('Connect to Stash');
 } else {
     // No form errors; process!
     $itx_helper_file = dirname(dirname(__FILE__)) . '/classes/class.itx_helper.php';
     require_once $itx_helper_file;
     $itxapi_username = $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.
     $requestcore_file = dirname(dirname(__FILE__)) . '/lib/requestcore/requestcore.class.php';
     require_once $requestcore_file;
     $stash = new ITXAPI_Helper($ITXAPI_KEY, $ITXAPI_URL, $itxapi_username, $itxapi_password);
     $files_url = $stash->get_files_url();
     $request = new RequestCore($files_url);
     $response = $request->send_request(true);
     // See if the request was successful.
     if (!$response->isOK()) {
         pb_backupbuddy::status('error', 'Stash request for files failed.');
     }
     // See if we got a json response.
     if (!($stash_files = json_decode($response->body, true))) {
         pb_backupbuddy::status('error', 'Stash did not get valid json response.');
     }
     // Finally see if the API returned an error.
     if (isset($stash_files['error'])) {
         if ($stash_files['error']['code'] == '3002') {
             pb_backupbuddy::alert('Invalid iThemes.com Member account password. Please verify your password. <a href="http://ithemes.com/member/member.php" target="_new">Forget your password?</a>');