Exemplo n.º 1
0
 /**
  * Class Constructor
  */
 public function __construct($options)
 {
     // init vars
     $this->app = App::getInstance('zoo');
     // init S3 Utility
     $this->s3 = AEUtilAmazons3::getInstance($options['accesskey'], $options['secretkey'], false);
     // store bucket reference
     $this->bucket = $options['bucket'];
 }
Exemplo n.º 2
0
 private function _getS3Object()
 {
     static $s3 = null;
     if (!is_object($s3)) {
         $s3Access = $this->getState('s3access');
         $s3Secret = $this->getState('s3secret');
         $s3 = AEUtilAmazons3::getInstance($s3Access, $s3Secret, false);
     }
     return $s3;
 }
Exemplo n.º 3
0
 public function _S3()
 {
     if ($this->_s3 == null) {
         $bucket = $this->config->find('files._s3bucket');
         $accesskey = trim($this->app->zlfw->decryptPassword($this->config->find('files._awsaccesskey')));
         $secretkey = trim($this->app->zlfw->decryptPassword($this->config->find('files._awssecretkey')));
         // register s3 class
         $this->app->loader->register('AEUtilAmazons3', 'classes:amazons3.php');
         // init S3 Utility
         $this->_s3 = AEUtilAmazons3::getInstance($accesskey, $secretkey, false);
     }
     return $this->_s3;
 }
Exemplo n.º 4
0
 public function downloadToFile($remotePath, $localFile, $fromOffset = null, $length = null)
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $accesskey = trim($config->get('engine.postproc.googlestorage.accesskey', ''));
     $secret = trim($config->get('engine.postproc.googlestorage.secretkey', ''));
     $usessl = $config->get('engine.postproc.googlestorage.usessl', 0) == 0 ? false : true;
     $bucket = $config->get('engine.postproc.googlestorage.bucket', '');
     // Sanity checks
     if (empty($accesskey)) {
         $this->setError('You have not set up your Google Storage Access Key');
         return false;
     }
     if (empty($secret)) {
         $this->setError('You have not set up your Google Storage Secret Key');
         return false;
     }
     if (empty($bucket)) {
         $this->setError('You have not set up your Google Storage Bucket');
         return false;
     } else {
         // Remove any slashes from the bucket
         $bucket = str_replace('/', '', $bucket);
         if ($lowercase) {
             $bucket = strtolower($bucket);
         }
     }
     // Create an S3 instance with the required credentials
     $s3 = AEUtilAmazons3::getInstance($accesskey, $secret, $usessl);
     $s3->defaultHost = 'commondatastorage.googleapis.com';
     if ($fromOffset && $length) {
         $toOffset = $fromOffset + $length - 1;
     } else {
         $toOffset = null;
     }
     $result = $s3->getObject($bucket, $remotePath, $localFile, $fromOffset, $toOffset);
     // Return the result
     $this->propagateFromObject($s3);
     return $result;
 }
 public function downloadToBrowser($remotePath)
 {
     // Retrieve engine configuration data
     $config = AEFactory::getConfiguration();
     $accesskey = trim($config->get('engine.postproc.s3.accesskey', ''));
     $secret = trim($config->get('engine.postproc.s3.secretkey', ''));
     $usessl = $config->get('engine.postproc.s3.usessl', 0) == 0 ? false : true;
     $bucket = $config->get('engine.postproc.s3.bucket', '');
     $lowercase = $config->get('engine.postproc.s3.lowercase', 1);
     $rrs = $config->get('engine.postproc.s3.rrs', 1);
     $endpoint = $config->get('engine.postproc.s3.customendpoint', '');
     $endpoint = trim($endpoint);
     if (!empty($endpoint)) {
         $protoPos = strpos($endpoint, ':\\');
         if ($protoPos !== false) {
             $endpoint = substr($endpoint, $protoPos + 3);
         }
         $slashPos = strpos($endpoint, '/');
         if ($slashPos !== false) {
             $endpoint = substr($endpoint, $slashPos + 1);
         }
     }
     // Sanity checks
     if (empty($accesskey)) {
         $this->setError('You have not set up your Amazon S3 Access Key');
         return false;
     }
     if (empty($secret)) {
         $this->setError('You have not set up your Amazon S3 Secret Key');
         return false;
     }
     if (empty($bucket)) {
         $this->setError('You have not set up your Amazon S3 Bucket');
         return false;
     } else {
         // Remove any slashes from the bucket
         $bucket = str_replace('/', '', $bucket);
         if ($lowercase) {
             $bucket = strtolower($bucket);
         }
     }
     // Create an S3 instance with the required credentials
     $s3 = AEUtilAmazons3::getInstance($accesskey, $secret, $usessl);
     if (!empty($endpoint)) {
         $s3->defaultHost = $endpoint;
     }
     $expires = time() + 10;
     // Should be plenty of time for a simple redirection!
     $stringToSign = "GET\n\n\n{$expires}\n/{$bucket}/{$remotePath}";
     $signature = AEUtilAmazons3::__getHash($stringToSign);
     $url = $usessl ? 'https://' : 'http://';
     $url .= "{$bucket}.s3.amazonaws.com/{$remotePath}?AWSAccessKeyId=" . urlencode($accesskey) . "&Expires={$expires}&Signature=" . urlencode($signature);
     return $url;
 }
Exemplo n.º 6
0
 /**
  * Test Authentication
  */
 public static function testAuth()
 {
     $rest = new AEUtilsS3Request('GET', '', '', AEUtilAmazons3::getInstance()->defaultHost);
     $rest = $rest->getResponse();
     if ($rest->error === false && $rest->code !== 200) {
         $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
     }
     if ($rest->error !== false) {
         $o = self::getInstance();
         $o->setError(sprintf(__CLASS__ . '::' . __METHOD__ . "(): [%s] %s", $rest->error['code'], $rest->error['message']));
         return false;
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * Get a list of buckets
  *
  * @param boolean $detailed Returns detailed bucket list when true
  * @return array | false
  */
 public static function listBuckets($detailed = false)
 {
     $rest = new AEUtilsS3Request('GET', '', '', AEUtilAmazons3::getInstance()->defaultHost);
     $rest = $rest->getResponse();
     if ($rest->error === false && $rest->code !== 200) {
         $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
     }
     if ($rest->error !== false) {
         $o = self::getInstance();
         $o->setError(sprintf(__CLASS__ . '::' . __METHOD__ . "(): [%s] %s", $rest->error['code'], $rest->error['message']));
         return false;
     }
     $results = array();
     if (!isset($rest->body->Buckets)) {
         return $results;
     }
     if ($detailed) {
         if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName)) {
             $results['owner'] = array('id' => (string) $rest->body->Owner->ID, 'name' => (string) $rest->body->Owner->ID);
         }
         $results['buckets'] = array();
         foreach ($rest->body->Buckets->Bucket as $b) {
             $results['buckets'][] = array('name' => (string) $b->Name, 'time' => strtotime((string) $b->CreationDate));
         }
     } else {
         foreach ($rest->body->Buckets->Bucket as $b) {
             $results[] = (string) $b->Name;
         }
     }
     return $results;
 }