getAuthenticatedURL() public static method

Get a query string authenticated URL
public static getAuthenticatedURL ( string $bucket, string $uri, integer $lifetime, boolean $hostBucket = false, boolean $https = false ) : string
$bucket string Bucket name
$uri string Object URI
$lifetime integer Lifetime in seconds
$hostBucket boolean Use the bucket name as the hostname
$https boolean Use HTTPS ($hostBucket should be false for SSL verification)
return string
Esempio n. 1
0
 public static function getDownloadURL($item, $ttl = false)
 {
     self::requireLibrary();
     S3::setAuth(Z_CONFIG::$S3_ACCESS_KEY, Z_CONFIG::$S3_SECRET_KEY);
     if (!$item->isAttachment()) {
         throw new Exception("Item {$item->id} is not an attachment");
     }
     $info = self::getLocalFileItemInfo($item);
     if (!$info) {
         return false;
     }
     // Create expiring URL on Amazon and return
     $url = S3::getAuthenticatedURL(Z_CONFIG::$S3_BUCKET, self::getPathPrefix($info['hash'], $info['zip']) . $info['filename'], $ttl, false, true);
     return $url;
 }
Esempio n. 2
0
 function get($path)
 {
     $filenumber = intval($_GET['file']);
     $file = DB::get()->row('SELECT * FROM files WHERE id = :id', array('id' => $filenumber));
     if ($file) {
         header('Content-Type: application/octet-stream');
         header('Content-Disposition: attachment; filename=' . urlencode($file->filename) . ';');
         $url = parse_url($file->url);
         $bucket = str_replace('.s3.amazonaws.com', '', $url['host']);
         $access = DB::get()->assoc("SELECT name, value FROM options WHERE grouping = 'Amazon Web Services'");
         $s3 = new S3($access['AWS Access Key ID'], $access['AWS Secret Access Key']);
         $uri = $s3->getAuthenticatedURL($bucket, trim($url['path'], '/'), 3600);
         //readfile($file->url);
         header('location: ' . $uri);
         exit;
     }
 }
 public function getAttachmentURL($attachment_id)
 {
     if (!$attachment_id) {
         throw new NotFoundException();
     }
     $attachment_id = (int) $attachment_id;
     $filename = $this->Response->query("\n            SELECT filename\n            FROM letters_responses_files\n            INNER JOIN\n              letters_responses\n                ON letters_responses.id = letters_responses_files.letter_response_id\n            WHERE\n              letters_responses_files.id = {$attachment_id} AND\n              letters_responses.user_id = " . $this->Auth->user('id') . "\n        ");
     if (!empty($filename[0]['letters_responses_files']['filename'])) {
         $filename = $filename[0]['letters_responses_files']['filename'];
     } else {
         throw new NotFoundException();
     }
     App::uses('S3', 'Vendor');
     $S3 = new S3(S3_LOGIN, S3_SECRET, null, S3_ENDPOINT);
     $bucket = 'portal';
     $file = 'letters/responses/' . $filename;
     $url = $S3->getAuthenticatedURL($bucket, $file, 60);
     if ($url) {
         $url = str_replace('s3.amazonaws.com/' . $bucket, $bucket . '.sds.tiktalik.com', $url);
     } else {
         throw new NotFoundException();
     }
     $this->setSerialized('url', $url);
 }
Esempio n. 4
0
<?php

$contentEncoding = "UTF-8";
//include the S3 stuff
require_once 'myS3.php';
//instantiate the class
$s3 = new S3();
//create a new bucket (this will be ignored if bucket is already there)
$myBucketName = "robs-1st-bucket";
// Get the contents of our bucket
$bucket_contents = $s3->getBucket($myBucketName);
// Disable any caching in the brwoser.
header("Cache-Control: no-cache, no-store, max-age=0, must-revalidate");
header("Sat, 1 Jan 2000 00:00:00 GMT");
header("Pragma: no-cache");
header("Content-encoding: " . $contentEncoding);
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='" . $contentEncoding . "'?>";
echo "<images>";
foreach ($bucket_contents as $file) {
    $fname = $file['name'];
    $furl = S3::getAuthenticatedURL($myBucketName, $fname, 60, false, true);
    //$furl = "http://$myBucketName.s3.amazonaws.com/$fname";
    //output a link to each file
    echo "<image filename='{$fname}' url='{$furl}'/>";
}
echo "</images>";
Esempio n. 5
0
 /**
  * Get a query string authenticated URL
  *
  * @param array $credentials AWS credentials
  * @param string $bucket Bucket name
  * @param string $uri Object URI
  * @param integer $lifetime Lifetime in seconds
  * @param boolean $hostBucket Use the bucket name as the hostname
  * @return string
  */
 public static function getAuthenticatedURL($credentials, $bucket, $uri, $lifetime, $hostBucket = false)
 {
     $s3 = new S3($credentials['AWS_ACCESS_KEY'], $credentials['AWS_SECRET_KEY'], $credentials['AWS_S3_SSL']);
     return $s3->getAuthenticatedURL($bucket, $uri, $lifetime, $hostBucket, $credentials['AWS_S3_SSL']);
 }
<?php

$success = false;
$result = array('status' => false);
if ($id = $this->DB->selectValue("SELECT `id` FROM `krs_files` WHERE `krs_pozycje_id`='" . addslashes($id) . "' AND `complete`='1' ORDER BY `complete_ts` DESC LIMIT 1")) {
    App::uses('S3', 'Vendor');
    $S3 = new S3(S3_LOGIN, S3_SECRET, null, S3_ENDPOINT);
    $bucket = 'resources';
    $file = 'KRS/' . $id . '.pdf';
    $url = $S3->getAuthenticatedURL($bucket, $file, 60);
    if ($url) {
        $url = str_replace('s3.amazonaws.com/' . $bucket, $bucket . '.sds.tiktalik.com', $url);
        $success = true;
    }
}
if ($success) {
    $result = array_merge($result, array('status' => true, 'url' => $url));
}
return $result;
} else {
    $returnurl = '/';
}
require_once 'config.php';
require_once './lib/facebook.php';
$okaytodownload = false;
// initialize the facebook API with your application API Key and Secret
$facebook = new Facebook(array('appId' => FACEBOOK_APPID, 'secret' => FACEBOOK_SECRET, 'cookie' => true));
$session = $facebook->getSession();
$fb_user = $session['uid'];
try {
    $testLikeStatus = $facebook->api(array('method' => 'pages.isfan', 'uid' => $fb_user, 'page_id' => FACEBOOK_FANPAGE_ID));
    if ($testLikeStatus) {
        if (SECURE_DOWNLOAD) {
            // use S3 secured download:
            require_once './lib/S3.php';
            if (!defined('AMAZONS3_KEY') || !defined('AMAZONS3_SECRET')) {
                header('Location: ./');
            }
            $s3 = new S3(AMAZONS3_KEY, AMAZONS3_SECRET);
            header("Location: " . S3::getAuthenticatedURL(AMAZONS3_BUCKET, DOWNLOAD_URI, 120));
        } else {
            // simple redirect:
            header('Location: ' . DOWNLOAD_URI);
        }
    } else {
        header('Location: ' . $returnurl . '?logout=1');
    }
} catch (FacebookApiException $e) {
    echo "There seems to be an error on the Facebook servers.";
}
 public function getAuthenticatedUrl()
 {
     $s3 = new S3('csub001050', 'studiomaiocchi', true, 'seewebstorage.it');
     $res = $s3->getAuthenticatedURL('studiomaiocchistaging', 'file.mp4', 60);
     return $res;
 }
Esempio n. 9
0
 /**
  * generate a url to authenticated content on S3
  * @param string $uri - Full URL to the S3 resource
  * @param integer $lifetime - number of seconds this url will be valid
  * @return string - Authenticated URL to access resource
  * @access public
  */
 public function authenticatedUrl($uri, $lifetime = 60)
 {
     $url = S3::getAuthenticatedURL($this->bucket, $this->relativePath($uri), $lifetime, false, $this->useSsl);
     return $url;
 }
Esempio n. 10
0
 static function getAuthenticatedURL($bucket, $uri)
 {
     self::get_s3();
     return S3::getAuthenticatedURL($bucket, $uri, 60);
 }
 /**
  * Returns a signed Amazon S3 download URL.
  *
  * @param $key          string  AWS key
  * @param $secret       string  AWS secret
  * @param $bucket       string  Bucket name
  * @param $file_name    string  File name (URI)
  * @return string       The signed download URL
  */
 public static function get_s3_url($key, $secret, $bucket, $file_name)
 {
     $s3 = new S3($key, $secret);
     // Duration 600 seconds (= 10 minutes)
     return $s3->getAuthenticatedURL($bucket, $file_name, 600);
 }
Esempio n. 12
0
 public static function s3AuthenticatedURL($uri)
 {
     S3::setAuth(S3_ACCESS_KEY, S3_SECRET_KEY);
     //Save logging status
     $save_logging = error_reporting();
     // Turn off logging for S3
     error_reporting(0);
     $authUrl = S3::getAuthenticatedURL(S3_BUCKET, $uri, 10 * 24 * 60 * 60, false, true);
     //10 days
     // Restore logging status
     error_reporting($save_logging);
     //Debug results from Auth access
     //error_log("s3Auth: $uri $authUrl");
     return $authUrl;
 }
 function mapQBAttachment($name, $qb_rec, $field_name, &$data)
 {
     $s3 = new S3(AWS_ACCESS_KEY, AWS_SECRET_KEY);
     $url = $s3->getAuthenticatedURL('hipaasecurenow', $this->qbDbid . '_' . $qb_rec[RECORD_ID], 3600);
     $socket = new HttpSocket();
     $response = $socket->get($url);
     $tmp_name = sys_get_temp_dir() . '/' . $name;
     file_put_contents($tmp_name, $response->body);
     $attachment = array('name' => $name, 'type' => $response->getHeader('Content-Type'), 'tmp_name' => $tmp_name, 'error' => 0, 'size' => strlen($response->body));
     $data[$field_name] = $attachment;
 }
 public function odpisy()
 {
     $id = (int) @$this->request->params['id'];
     $url = false;
     App::uses('S3', 'Vendor');
     $S3 = new S3(S3_LOGIN, S3_SECRET, null, S3_ENDPOINT);
     $bucket = 'resources';
     $file = 'KRS/' . $id . '.pdf';
     $url = $S3->getAuthenticatedURL($bucket, $file, 60);
     if ($url) {
         $url = str_replace('s3.amazonaws.com/' . $bucket, $bucket . '.sds.tiktalik.com', $url);
         $success = true;
     }
     $this->set('url', $url);
     $this->set('_serialize', array('url'));
 }