Beispiel #1
0
 private static function _init($settings)
 {
     pb_backupbuddy::status('details', 'Loading AWS SDK...');
     require_once dirname(dirname(__FILE__)) . '/_s3lib2/aws-autoloader.php';
     pb_backupbuddy::status('details', 'SDK loaded.');
     // Format all settings.
     $settings = self::_formatSettings($settings);
     // If not connected with these exact settings (by comparisong signatue of $settings ) then connect & prepare bucket.
     //if ( ! isset( self::$_client ) ) {
     $newSignature = md5(serialize($settings));
     if ($newSignature != self::$_client_signature) {
         self::$_client_signature = md5(serialize($settings));
         $s3Config = self::getCredentials($settings);
         if ('0' == $settings['ssl']) {
             $s3Config['scheme'] = 'http';
             pb_backupbuddy::status('details', 'SSL disabled.');
         }
         self::$_client = S3Client::factory($s3Config);
         // Verify bucket exists; create if not. Also set region to the region bucket exists in.
         if (false === self::_prepareBucketAndRegion($settings)) {
             return self::_error('Error #983483437: Could not prepare bucket `' . $settings['bucket'] . '` in region `' . $settings['regision'] . '`.');
         }
     }
     return $settings;
     // Formatted & updated settings.
 }
Beispiel #2
0
 private static function _init($settings)
 {
     pb_backupbuddy::status('details', 'Loading AWS SDK in _init.');
     require_once dirname(dirname(__FILE__)) . '/_s3lib2/aws-autoloader.php';
     pb_backupbuddy::status('details', 'SDK loaded.');
     $settings = self::_formatSettings($settings);
     // Format all settings.
     /*
     echo '<pre>';
     print_r( $settings );
     echo '</pre>';
     */
     // If not connected with these exact settings (by comparisong signatue of $settings ) then connect & prepare bucket.
     //if ( ! isset( self::$_client ) ) {
     $newSignature = md5(serialize($settings));
     if ($newSignature != self::$_client_signature) {
         self::$_client_signature = md5(serialize($settings));
         // Base credentials.
         $s3Config = self::getCredentials($settings);
         // SSL option.
         if ('0' == $settings['ssl']) {
             $s3Config['scheme'] = 'http';
             pb_backupbuddy::status('details', 'SSL disabled.');
         }
         // Proxy (if applicable)
         if (defined('WP_PROXY_HOST')) {
             pb_backupbuddy::status('details', 'WordPress proxy setting detecred since WP_PROXY_HOST defined.');
             if (!is_array($s3config['request.options'])) {
                 $s3config['request.options'] = array();
             }
             $s3config['request.options']['proxy'] = WP_PROXY_HOST;
             if (defined('WP_PROXY_PORT')) {
                 $s3config['request.options']['proxy'] .= ':' . WP_PROXY_PORT;
             }
             pb_backupbuddy::status('details', 'Calculated proxy URL (before user/pass added): `' . $s3config['request.options']['proxy'] . '`.');
             if (defined('WP_PROXY_USERNAME')) {
                 $s3config['request.options']['proxy'] = WP_PROXY_USERNAME . ':' . WP_PROXY_PASSWORD . '@' . $s3config['request.options']['proxy'];
             }
         }
         $s3Config['signature'] = 'v4';
         $s3Config['region'] = str_replace(array('.amazonaws.com', 's3-'), '', $settings['region']);
         if ('s3' == $s3Config['region']) {
             $s3Config['region'] = 'us-east-1';
         }
         // Cannot use this since we STILL need to know the correct region so that v4 signature signing can occur. Catch-22.
         //$s3Config['endpoint'] = 'https://' . $settings['bucket'] . '.s3.amazonaws.com';
         //pb_backupbuddy::status( 'details', 'Using specified region results in endpoint: `' . $s3Config['endpoint'] . '` to connect to.' );
         /*
         echo 's3config:<pre>';
         print_r( $s3Config );
         echo '</pre>';
         */
         if (pb_backupbuddy::$options['log_level'] == '3') {
             // Full logging enabled.
             //error_log( print_r( $s3Config, true ) );
         }
         self::$_client = S3Client::factory($s3Config);
         self::$_client->getConfig()->set('curl.options', array('body_as_string' => true));
         // Work around "[curl] 65: necessary data rewind wasn't possible" issue. See https://github.com/aws/aws-sdk-php/issues/284
         // Verify bucket exists; create if not. Also set region to the region bucket exists in.
         /*
         $prepareBucket = false;
         if ( ( true === $prepareBucket ) && ( false === self::_prepareBucketAndRegion( $settings ) ) ) {
         	return self::_error( 'Error #983483437: Could not prepare bucket `' . $settings['bucket'] . '` in region `' . $settings['region'] . '`.' );
         } else {
         	pb_backupbuddy::status( 'details', 'Skipping bucket prepare.' );
         }
         */
     }
     return $settings;
     // Formatted & updated settings.
 }