protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration($options['app'], $options['env'], true);
     // initialize the database connection
     //    $databaseManager = new sfDatabaseManager($this->configuration);
     //    $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     if (!sfConfig::get('app_sf_amazon_plugin_access_key', false)) {
         throw new sfException(sprintf('You have not set an amazon access key'));
     }
     if (!sfConfig::get('app_sf_amazon_plugin_secret_key', false)) {
         throw new sfException(sprintf('You have not set an amazon secret key'));
     }
     $s3 = new AmazonS3(sfConfig::get('app_sf_amazon_plugin_access_key'), sfConfig::get('app_sf_amazon_plugin_secret_key'));
     $response = $s3->list_buckets();
     if (!isset($response->body->Buckets->Bucket)) {
         throw new sfException($response->body->Message);
     }
     foreach ($response->body->Buckets->Bucket as $bucket) {
         $this->logSection(sprintf('%s', $bucket->Name), sprintf('created at "%s"', $bucket->Name, $bucket->CreationDate));
     }
 }
Ejemplo n.º 2
0
 /**
  * @param string $args
  */
 public function edit_ajax($args = '')
 {
     $error = '';
     if (is_array($args)) {
         $ajax = FALSE;
     } else {
         if (!current_user_can('backwpup_jobs_edit')) {
             wp_die(-1);
         }
         check_ajax_referer('backwpup_ajax_nonce');
         $args['s3accesskey'] = $_POST['s3accesskey'];
         $args['s3secretkey'] = $_POST['s3secretkey'];
         $args['s3bucketselected'] = $_POST['s3bucketselected'];
         $args['s3base_url'] = $_POST['s3base_url'];
         $args['s3region'] = $_POST['s3region'];
         $ajax = TRUE;
     }
     echo '<span id="s3bucketerror" style="color:red;">';
     if (!empty($args['s3accesskey']) && !empty($args['s3secretkey'])) {
         try {
             $s3 = new AmazonS3(array('key' => $args['s3accesskey'], 'secret' => BackWPup_Encryption::decrypt($args['s3secretkey']), 'certificate_authority' => TRUE));
             $base_url = $this->get_s3_base_url($args['s3region'], $args['s3base_url']);
             if (stristr($base_url, 'amazonaws.com')) {
                 $s3->set_region(str_replace(array('http://', 'https://'), '', $base_url));
             } else {
                 $s3->set_hostname(str_replace(array('http://', 'https://'), '', $base_url));
                 $s3->allow_hostname_override(FALSE);
                 if (substr($base_url, -1) == '/') {
                     $s3->enable_path_style(TRUE);
                 }
             }
             if (stristr($base_url, 'http://')) {
                 $s3->disable_ssl();
             }
             $buckets = $s3->list_buckets();
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (empty($args['s3accesskey'])) {
         _e('Missing access key!', 'backwpup');
     } elseif (empty($args['s3secretkey'])) {
         _e('Missing secret access key!', 'backwpup');
     } elseif (!empty($error) && $error == 'Access Denied') {
         echo '<input type="text" name="s3bucket" id="s3bucket" value="' . esc_attr($args['s3bucketselected']) . '" >';
     } elseif (!empty($error)) {
         echo esc_html($error);
     } elseif (!isset($buckets) || count($buckets->body->Buckets->Bucket) < 1) {
         _e('No bucket found!', 'backwpup');
     }
     echo '</span>';
     if (!empty($buckets->body->Buckets->Bucket)) {
         echo '<select name="s3bucket" id="s3bucket">';
         foreach ($buckets->body->Buckets->Bucket as $bucket) {
             echo "<option " . selected($args['s3bucketselected'], esc_attr($bucket->Name), FALSE) . ">" . esc_attr($bucket->Name) . "</option>";
         }
         echo '</select>';
     }
     if ($ajax) {
         die;
     }
 }
Ejemplo n.º 3
0
function backwpup_get_gstorage_buckets($args = '')
{
    if (is_array($args)) {
        extract($args);
        $ajax = false;
    } else {
        check_ajax_referer('backwpupeditjob_ajax_nonce');
        if (!current_user_can(BACKWPUP_USER_CAPABILITY)) {
            die('-1');
        }
        $GStorageAccessKey = $_POST['GStorageAccessKey'];
        $GStorageSecret = $_POST['GStorageSecret'];
        $GStorageselected = $_POST['GStorageselected'];
        $ajax = true;
    }
    if (!class_exists('CFRuntime')) {
        require_once dirname(__FILE__) . '/../libs/aws/sdk.class.php';
    }
    if (empty($GStorageAccessKey)) {
        echo '<span id="GStorageBucket" style="color:red;">' . __('Missing access key!', 'backwpup') . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    if (empty($GStorageSecret)) {
        echo '<span id="GStorageBucket" style="color:red;">' . __('Missing secret access key!', 'backwpup') . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    try {
        $gstorage = new AmazonS3(array('key' => $GStorageAccessKey, 'secret' => $GStorageSecret, 'certificate_authority' => true));
        $gstorage->set_hostname('storage.googleapis.com');
        $gstorage->allow_hostname_override(false);
        $buckets = $gstorage->list_buckets();
    } catch (Exception $e) {
        echo '<span id="GStorageBucket" style="color:red;">' . $e->getMessage() . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    if ($buckets->status < 200 or $buckets->status >= 300) {
        echo '<span id="GStorageBucket" style="color:red;">' . $buckets->status . ': ' . $buckets->body->Message . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    if (count($buckets->body->Buckets->Bucket) < 1) {
        echo '<span id="GStorageBucket" style="color:red;">' . __('No bucket found!', 'backwpup') . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    echo '<select name="GStorageBucket" id="GStorageBucket">';
    foreach ($buckets->body->Buckets->Bucket as $bucket) {
        echo "<option " . selected(strtolower($GStorageselected), strtolower($bucket->Name), false) . ">" . $bucket->Name . "</option>";
    }
    echo '</select>';
    if ($ajax) {
        die;
    } else {
        return;
    }
}