protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration($options['app'], $options['env'], true);
     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'));
     $this->s3_response = $s3->create_bucket($arguments['bucket'], $options['region'], $options['acl']);
     if ($this->s3_response->isOk()) {
         $this->log('Bucketed is being created...');
         /* Since AWS follows an "eventual consistency" model, sleep and poll
            until the bucket is available. */
         $exists = $s3->if_bucket_exists($arguments['bucket']);
         while (!$exists) {
             // Not yet? Sleep for 1 second, then check again
             sleep(1);
             $exists = $s3->if_bucket_exists($arguments['bucket']);
         }
         $this->logSection('Bucket+', sprintf('"%s" created successfully', $arguments['bucket']));
     } else {
         throw new sfException($this->s3_response->body->Message);
     }
 }
Exemplo n.º 2
0
 public function tearDown()
 {
     if ($this->instance) {
         $s3 = new AmazonS3(array('key' => $this->config['amazons3']['key'], 'secret' => $this->config['amazons3']['secret']));
         if ($s3->delete_all_objects($this->id)) {
             $s3->delete_bucket($this->id);
         }
     }
 }
Exemplo n.º 3
0
 public function getFileUrl($remotePath)
 {
     $response = $this->_s3->update_object($this->_bucket, $remotePath, array('acl' => AmazonS3::ACL_PUBLIC));
     if (!$response->isOK()) {
         return false;
     } else {
         return $response->header['_info']['url'];
     }
 }
 public static function deleteBucket($app)
 {
     $user_storage_s3 = Doctrine::getTable('GcrUserStorageS3')->findOneByAppId($app->getShortName());
     if ($user_storage_s3) {
         $account = GcrUserStorageS3Table::getAccount($app);
         define('AWS_KEY', $account->getAccessKeyId());
         define('AWS_SECRET_KEY', $account->getSecretAccessKey());
         gcr::loadSdk('aws');
         $api = new AmazonS3();
         $api->delete_bucket($user_storage_s3->getBucketName(), true);
         $user_storage_s3->delete();
     }
 }
Exemplo n.º 5
0
function delete_xid($db, $xid)
{
    $data = $db->Raw("SELECT server, link FROM userdb_uploads WHERE xid='{$xid}'");
    $server = $data[0]['server'];
    $link = $data[0]['link'];
    if ($server == 's3') {
        $s3 = new AmazonS3();
        $s3->delete_object('fb-music', $link);
    } else {
        $split = split("/", $data[0]['link']);
        $link = "/var/www/music/users/" . $split[4] . "/" . $split[5] . "/" . $split[6];
        unlink($link);
    }
    $db->Raw("DELETE FROM userdb_uploads WHERE xid='{$xid}'");
}
 /**
  * Move a file or folder to a specific location
  *
  * @param string $from The location to move from
  * @param string $to The location to move to
  * @param string $point
  * @return boolean
  */
 public function moveObject($from, $to, $point = 'append')
 {
     $this->xpdo->lexicon->load('source');
     $success = false;
     if (substr(strrev($from), 0, 1) == '/') {
         $this->xpdo->error->message = $this->xpdo->lexicon('s3_no_move_folder', array('from' => $from));
         return $success;
     }
     if (!$this->driver->if_object_exists($this->bucket, $from)) {
         $this->xpdo->error->message = $this->xpdo->lexicon('file_err_ns') . ': ' . $from;
         return $success;
     }
     if ($to != '/') {
         if (!$this->driver->if_object_exists($this->bucket, $to)) {
             $this->xpdo->error->message = $this->xpdo->lexicon('file_err_ns') . ': ' . $to;
             return $success;
         }
         $toPath = rtrim($to, '/') . '/' . basename($from);
     } else {
         $toPath = basename($from);
     }
     $response = $this->driver->copy_object(array('bucket' => $this->bucket, 'filename' => $from), array('bucket' => $this->bucket, 'filename' => $toPath), array('acl' => AmazonS3::ACL_PUBLIC));
     $success = $response->isOK();
     if ($success) {
         $deleteResponse = $this->driver->delete_object($this->bucket, $from);
         $success = $deleteResponse->isOK();
     } else {
         $this->xpdo->error->message = $this->xpdo->lexicon('file_folder_err_rename') . ': ' . $to . ' -> ' . $from;
     }
     return $success;
 }
Exemplo n.º 7
0
 /**
  * Gets s3 object
  *
  * @param  boolean   $debug return error message instead of script stop
  * @return \AmazonS3 s3 object
  */
 public function s3($debug = false)
 {
     // This is workaround to composer autoloader
     if (!class_exists('CFLoader')) {
         throw new ClassNotFoundException('Amazon: autoload failed');
     }
     if (empty($this->_s3)) {
         \CFCredentials::set(array('@default' => array('key' => $this->getOption('key'), 'secret' => $this->getOption('secret'))));
         $this->_s3 = new \AmazonS3();
         $this->_s3->use_ssl = false;
         $this->_buckets = fn_array_combine($this->_s3->get_bucket_list(), true);
     }
     $message = '';
     $bucket = $this->getOption('bucket');
     if (empty($this->_buckets[$bucket])) {
         $res = $this->_s3->create_bucket($bucket, $this->getOption('region'));
         if ($res->isOK()) {
             $res = $this->_s3->create_cors_config($bucket, array('cors_rule' => array(array('allowed_origin' => '*', 'allowed_method' => 'GET'))));
             if ($res->isOK()) {
                 $this->_buckets[$bucket] = true;
             } else {
                 $message = (string) $res->body->Message;
             }
         } else {
             $message = (string) $res->body->Message;
         }
     }
     if (!empty($message)) {
         if ($debug == true) {
             return $message;
         }
         throw new ExternalException('Amazon: ' . $message);
     }
     return $this->_s3;
 }
Exemplo n.º 8
0
 /**
  * @covers mychaelstyle\storage\providers\AmazonS3::remove
  * @covers mychaelstyle\storage\providers\AmazonS3::__mergePutOptions
  * @covers mychaelstyle\storage\providers\AmazonS3::__formatUri
  * @depends testPut
  */
 public function testRemove()
 {
     if ($this->markIncompleteIfNoNetwork()) {
         return true;
     }
     // remove
     $this->object->remove($this->uri);
 }
 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration($options['app'], $options['env'], true);
     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->delete_bucket($arguments['bucket'], $options['force']);
     if ($response->isOk()) {
         $this->logSection('Bucket-', sprintf('"%s" bucket has been deleted', $arguments['bucket']));
     } else {
         throw new sfException($this->body->Message);
     }
 }
Exemplo n.º 10
0
 /**
  * Store Upload file to S3.
  * @param CUploadedFile $uploadedFile
  * @param string $bucket The file to create the object
  * @return string url to the file.
  */
 public function store($uploadedFile, $bucket = NULL)
 {
     if ($this->config['randomPath']) {
         $filePath = $this->config['pathPrefix'] . md5(date('His')) . '/' . $uploadedFile->getName();
     } else {
         $filePath = $this->config['pathPrefix'] . $uploadedFile->getName();
     }
     if ($bucket === NULL) {
         $bucket = $this->config['defaultBucket'];
     }
     /** @var CFResponse $result */
     $result = $this->s3->create_object($bucket, $filePath, array('fileUpload' => $uploadedFile->getTempName(), 'acl' => $this->config['defaultACL']));
     if ($result->isOk()) {
         return urldecode($this->s3->get_object_url($bucket, $filePath));
     } else {
         Yii::log("STATUS:" . $result->status . "\nHEDAER:" . $result->header . "\nBODY:" . $result->body, CLogger::LEVEL_ERROR, "application");
         throw new CException($result->status);
     }
 }
 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));
     }
 }
Exemplo n.º 12
0
 public function __construct(array $options = array())
 {
     if (!isset($options['default_cache_config'])) {
         $options['default_cache_config'] = 'cache/aws';
     }
     if (!isset($options['key']) && Kwf_Config::getValue('aws.key')) {
         $options['key'] = Kwf_Config::getValue('aws.key');
     }
     if (!isset($options['secret']) && Kwf_Config::getValue('aws.secret')) {
         $options['secret'] = Kwf_Config::getValue('aws.secret');
     }
     parent::__construct($options);
 }
Exemplo n.º 13
0
 protected function syncToS3($arguments = array(), $options = array())
 {
     list($bucket, $prefix) = explode(':', $arguments['destination']);
     $file_list = sfFinder::type('file')->in($arguments['source']);
     $object_list_response = $this->s3->list_objects($bucket);
     if (!$object_list_response->isOk()) {
         throw new sfException($object_list_response->body->Message);
     }
     if (isset($object_list_response->body->Contents)) {
         foreach ($object_list_response->body->Contents as $object) {
             // var_dump($object->LastModified);
             $object_list[] = $object->Key;
         }
     }
     $files_queued = 0;
     foreach ($file_list as $file) {
         $filename = explode(DIRECTORY_SEPARATOR, $file);
         $filename = array_pop($filename);
         $offset = strpos($file, $arguments['source']);
         $s3_location = substr(str_replace($arguments['source'], '', substr($file, $offset)), 1);
         if (in_array($s3_location, $object_list)) {
             continue;
         }
         $this->s3->batch()->create_object($bucket, $s3_location, array('fileUpload' => $file));
         $files_queued++;
         $this->logSection('file+', $bucket . ':' . $s3_location);
     }
     if ($files_queued <= 0) {
         $this->log('All files have already been synced, no need to upload any files');
         return;
     }
     $upload_response = $this->s3->batch()->send();
     if (!$upload_response->areOk()) {
         throw new sfException($upload_response->body->Message);
     }
     $this->log('Files synced to bucket');
 }
 /**
  * testSetDate
  *
  * @return void
  * @author Rob Mcvey
  **/
 public function testSignature()
 {
     $this->AmazonS3->setDate('Sun, 22 Sep 2013 14:43:04 GMT');
     $stringToSign = "PUT" . "\n";
     $stringToSign .= "aUIOL+kLNYqj1ZPXnf8+yw==" . "\n";
     $stringToSign .= "image/png" . "\n";
     $stringToSign .= "Sun, 22 Sep 2013 14:43:04 GMT";
     $stringToSign .= "\n";
     $stringToSign .= "x-amz-acl:public-read" . "\n";
     $stringToSign .= "x-amz-meta-reviewedby:john.doe@yahoo.biz" . "\n";
     $stringToSign .= "/bucket/copify.png";
     $signature = $this->AmazonS3->signature($stringToSign);
     $this->assertEqual('gbcL98O77pVLUSdcSIz4RCAots4=', $signature);
     $this->AmazonS3 = new AmazonS3(array('bang', 'fizz', 'lulz'));
     $signature = $this->AmazonS3->signature($stringToSign);
     $this->assertEqual('dF2swNTRWEs9LiMxdxiVeWPwCR0=', $signature);
 }
 /**
  * Ensure that an uploaded file is unique
  *
  * @param string  $prefix
  * @param string  $fileName
  */
 protected function uniqueFile($prefix, $fileName)
 {
     // request a list of objects filtered by prefix
     $list = $this->s3->get_object_list($this->bucket, compact('prefix'));
     $path = join('/', array($prefix, $fileName));
     $i = 0;
     while (in_array($path, $list)) {
         $i++;
         $parts = explode('.', $fileName);
         $ext = array_pop($parts);
         $parts = array_diff($parts, array("copy{$i}", "copy" . ($i - 1)));
         $parts[] = "copy{$i}";
         $parts[] = $ext;
         $path = join('/', array($prefix, implode('.', $parts)));
     }
     if (isset($parts)) {
         $_FILES['newfile']['name'] = implode('.', $parts);
     }
 }
Exemplo n.º 16
0
 function _testS3Bucket()
 {
     $AmazonS3 = new AmazonS3("", "");
     $res = $AmazonS3->ListBuckets();
     $this->assertTrue(is_array($res->Bucket), "ListBuckets returned array");
     $res = $AmazonS3->CreateBucket("MySQLDumps");
     $this->assertTrue($res, "Bucket successfull created");
     $res = $AmazonS3->CreateObject("fonts/test.ttf", "offload-public", "/tmp/PhotoEditService.wsdl", "plain/text");
     $this->assertTrue($res, "Object successfull created");
     $res = $AmazonS3->DownloadObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull downloaded");
     $res = $AmazonS3->DeleteObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull removed");
 }
Exemplo n.º 17
0
 function _testS3Bucket()
 {
     $AmazonS3 = new AmazonS3("0EJNVE9QFYY3TD554T02", "VOtWnbI2PmsqKOqDNVVgfLVsEnGD/6miiYDY552S");
     $res = $AmazonS3->ListBuckets();
     $this->assertTrue(is_array($res->Bucket), "ListBuckets returned array");
     $res = $AmazonS3->CreateBucket("MySQLDumps");
     $this->assertTrue($res, "Bucket successfull created");
     $res = $AmazonS3->CreateObject("fonts/test.ttf", "offload-public", "/tmp/PhotoEditService.wsdl", "plain/text");
     $this->assertTrue($res, "Object successfull created");
     $res = $AmazonS3->DownloadObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull downloaded");
     $res = $AmazonS3->DeleteObject("fonts/test.ttf", "offload-public");
     $this->assertTrue($res, "Object successfull removed");
 }
Exemplo n.º 18
0
 public function getMd5($path)
 {
     $v = null;
     $retries = 3;
     do {
         try {
             $v = $this->_s3->get_object_headers($this->getBucket(), $path);
             $retries = 0;
         } catch (Exception $e) {
             $this->_out->logWarning("retry S3::getMd5() for {$path}");
             usleep(200);
             $retries--;
         }
     } while ($retries !== 0);
     if ($v === null || !array_key_exists('etag', $v->header)) {
         return false;
     }
     $md5 = str_replace('"', '', (string) $v->header['etag']);
     return $md5;
 }
Exemplo n.º 19
0
 * v1. 22 June 2012
 *
 * what this script does?
 *
 * add caching  headers to an existing object
 *
 */
require_once "sdk-1.5.7/sdk.class.php";
error_reporting(-1);
$config = parse_ini_file("aws.ini");
$awsKey = $config["aws.key"];
$awsSecret = $config["aws.secret"];
$bucket = "test.indigloo";
$name = "garbage_bin_wallpaper.jpg";
$options = array("key" => $awsKey, "secret" => $awsSecret, "default_cache_config" => '', "certificate_authority" => true);
$s3 = new AmazonS3($options);
$exists = $s3->if_bucket_exists($bucket);
if (!$exists) {
    printf("S3 bucket %s does not exists \n", $bucket);
    exit;
}
$mime = NULL;
$response = $s3->get_object_metadata($bucket, $name);
//get content-type of existing object
if ($response) {
    $mime = $response["ContentType"];
}
if (empty($mime)) {
    printf("No mime found for object \n");
    exit;
}
Exemplo n.º 20
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;
     }
 }
Exemplo n.º 21
0
<?php

// Inizializzo la classe AmazonS3
$s3 = new AmazonS3();
// Creo un bucket per la memorizzazione di un file
$response = $s3->create_bucket('my-bucket', AmazonS3::REGION_US_E1);
if (!$response->isOK()) {
    die('Errore durante la creazione del bucket');
}
$data = file_get_contents('/my/local/dir/picture.jpg');
$response = $s3->create_object('my-bucket', 'picture.jpg', array('body' => $data));
if (!$response->isOK()) {
    die('Errore durante la memorizzazione del file');
}
echo "Il file è stato memorizzato con successo";
#!/usr/bin/php
<?php 
/*
 * list_bucket_objects_raw.php
 *
 * Display the raw bucket data returned by list_objects
 *
 * Copyright 2009-2010 Amazon.com, Inc. or its affiliates. All Rights
 * Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"). You
 * may not use this file except in compliance with the License. A copy
 * of the License is located at
 *
 *       http://aws.amazon.com/apache2.0/
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 */
error_reporting(E_ALL);
require_once 'sdk.class.php';
require_once 'include/book.inc.php';
// Create the S3 access object
$s3 = new AmazonS3();
// List the bucket
$res = $s3->list_objects(BOOK_BUCKET);
// Display the resulting object tree
print_r($res);
Exemplo n.º 23
0
$region = "";
if (!empty($authToken) && !empty($deviceID)) {
    $conn = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die("Error:Couldn't connect to server");
    $db = mysql_select_db(DB_DBNAME, $conn) or die("Error:Couldn't select database");
    $query = "SELECT * FROM users WHERE authToken = '{$authToken}'";
    $result = mysql_query($query) or die("Error:Query Failed-1");
    if (mysql_num_rows($result) == 1) {
        $row = mysql_fetch_array($result);
        $username = $row["email"];
        $region = $row["region"];
    } else {
        die("Error: Incorrect authToken");
    }
    mysql_close($conn);
    $newFileName = md5($username . $deviceID) . "_";
    $s3 = new AmazonS3();
    $bucket = 'com.sanchitkarve.tb.usor';
    $response = $s3->get_object_list($bucket);
    $userFiles = array();
    $foundFiles = false;
    foreach ($response as $item) {
        if (startsWith($item, $newFileName)) {
            $userfiles[] = $item;
            $foundFiles = true;
        }
    }
    // create cloudfront link if possible
    $urls = "";
    //print_r($response);
    if ($foundFiles) {
        foreach ($userfiles as $uitem) {
Exemplo n.º 24
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;
 }
Exemplo n.º 25
0
 function get_amazons3_backup_bwd_comp($args)
 {
     if ($this->iwp_mmb_function_exists('curl_init')) {
         require_once $GLOBALS['iwp_mmb_plugin_dir'] . '/lib/amazon_s3_bwd_comp/sdk.class.php';
         extract($args);
         $temp = '';
         try {
             CFCredentials::set(array('development' => array('key' => trim($as3_access_key), 'secret' => trim(str_replace(' ', '+', $as3_secure_key)), 'default_cache_config' => '', 'certificate_authority' => true), '@default' => 'development'));
             $s3 = new AmazonS3();
             if ($as3_site_folder == true) {
                 if (!empty($as3_directory)) {
                     $as3_directory .= '/' . $this->site_name;
                 } else {
                     $as3_directory = $this->site_name;
                 }
             }
             if (empty($as3_directory)) {
                 $single_as3_file = $backup_file;
             } else {
                 $single_as3_file = $as3_directory . '/' . $backup_file;
             }
             //$temp = ABSPATH . 'iwp_temp_backup.zip';
             $temp = wp_tempnam('iwp_temp_backup.zip');
             $s3->get_object($as3_bucket, $single_as3_file, array("fileDownload" => $temp));
         } catch (Exception $e) {
             return false;
         }
         return $temp;
     } else {
         return array('error' => 1);
     }
 }
Exemplo n.º 26
0
			</tr>
			<tr>
				<th>iThemes password</th>
				<td><input type="password" name="itxapi_password_raw"></td>
			</tr>
			<tr>
				<th>&nbsp;</th>
				<td><input type="submit" name="submit" value="Re-Authenticate" class="button button-primary"></td>
			</tr>
		</table>
	</form>
	
	<?php 
    die;
}
$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('Error: Unable to delete `' . $item . '`. Verify permissions.');
        }
Exemplo n.º 27
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;
     }
 }
Exemplo n.º 28
0
 * License.
 */
error_reporting(E_ALL);
require_once 'sdk.class.php';
require_once 'include/book.inc.php';
// Define image layout constants
define('BORDER_LEFT', 12);
define('BORDER_RIGHT', 12);
define('BORDER_TOP', 12);
define('BORDER_BOTTOM', 12);
define('IMAGES_ACROSS', 4);
define('IMAGES_DOWN', 4);
define('GAP_SIZE', 6);
// Create the SQS and S3 access objects
$sqs = new AmazonSQS();
$s3 = new AmazonS3();
// Get the queue URL
$queueURL_Render = $sqs->create_queue(RENDER_QUEUE)->body->CreateQueueResult->QueueUrl;
// Pull, process
while (true) {
    // Pull the message from the queue
    $message = pullMessage($sqs, $queueURL_Render);
    if ($message != null) {
        // Extract message detail
        $messageDetail = $message['MessageDetail'];
        $receiptHandle = (string) $message['ReceiptHandle'];
        $imageKeys = $messageDetail['Data'];
        $pageTitle = $messageDetail['PageTitle'];
        print "Processing message with " . count($imageKeys) . " images:\n";
        // Create destination image
        $outX = BORDER_LEFT + BORDER_RIGHT + IMAGES_ACROSS * THUMB_SIZE + (IMAGES_ACROSS - 1) * GAP_SIZE;
Exemplo n.º 29
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;
 }
Exemplo n.º 30
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;
     }
 }