コード例 #1
0
ファイル: init.php プロジェクト: adrianjonmiller/animalhealth
 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
ファイル: cron.php プロジェクト: netfor/nextrading
 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;
     }
 }
コード例 #3
0
ファイル: cron.php プロジェクト: elephantcode/elephantcode
 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;
     }
 }
コード例 #4
0
ファイル: init.php プロジェクト: Offirmo/base-wordpress
 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;
 }