Exemplo n.º 1
0
 protected function touch($bucket, $uri)
 {
     $storage = new binarypool_storage($bucket);
     $assetFile = $uri;
     if (!$storage->isFile($assetFile)) {
         $assetFile .= '/index.xml';
         if (!$storage->isFile($assetFile)) {
             return false;
         }
     }
     // Get TTL from request
     $buckets = binarypool_config::getBuckets();
     $ttl = $buckets[$bucket]['ttl'];
     if ($this->request->getParam('TTL')) {
         $newttl = intval($this->request->getParam('TTL'));
         if ($newttl <= $ttl) {
             // Don't allow higher TTL than bucket configuration
             $ttl = $newttl;
         }
     }
     // Set TTL
     $oldAsset = $storage->getAssetObject($assetFile);
     $asset = $storage->getAssetObject($assetFile);
     $asset->setExpiry(time() + $ttl * 24 * 60 * 60);
     $storage->saveAsset($asset, $assetFile);
     // Update views
     binarypool_views::updated($bucket, $assetFile, $oldAsset);
     $this->setResponseCode(204);
     return true;
 }
Exemplo n.º 2
0
 protected function execute()
 {
     $xml = "<status method='get'>";
     $buckets = binarypool_config::getBuckets();
     foreach (array_keys($buckets) as $bucket) {
         $xml .= '<bucket id="' . htmlspecialchars($bucket) . '" />';
     }
     $xml .= "</status>";
     array_push($this->data, new api_model_xml($xml));
 }
Exemplo n.º 3
0
 public function __construct($bucket)
 {
     $buckets = binarypool_config::getBuckets();
     if (!isset($buckets[$bucket])) {
         throw new binarypool_exception(100, 404, "Bucket not defined: {$bucket}");
     }
     $this->bucketName = $bucket;
     $this->bucketConfig = $buckets[$bucket];
     $this->storage = $this->getStorage($this->bucketConfig);
 }
Exemplo n.º 4
0
 /**
  * Validate original uploaded files and throw exceptions if they are
  * invalid.
  *
  * @param $type: Type - the validation method is chosen based on this type.
  * @param $bucket: Bucket and type define the validations that apply.
  * @param $original: Absolute path to the original file.
  * @return Boolean
  */
 public static function validate($type, $bucket, $original)
 {
     $validationClass = "binarypool_validate_" . strtolower($type);
     if (!class_exists($validationClass)) {
         return true;
     }
     $config = null;
     $buckets = binarypool_config::getBuckets();
     if (isset($buckets[$bucket]['validations']) && isset($buckets[$bucket]['validations'][$type])) {
         $config = $buckets[$bucket]['validations'][$type];
     }
     return call_user_func($validationClass . '::validate', $original, $config);
 }
Exemplo n.º 5
0
 protected function execute()
 {
     $uri = $this->request->getPath();
     // Deletions allowed on bucket?
     $buckets = binarypool_config::getBuckets();
     if (!isset($buckets[$this->bucket]['allowDeletions']) || $buckets[$this->bucket]['allowDeletions'] == false) {
         throw new binarypool_exception(108, 403, "Deletions not allowed on this bucket.");
     }
     $storage = new binarypool_storage($this->bucket);
     $storage->delete($uri);
     $this->setResponseCode(204);
     $this->response->send();
     $this->ignoreView = true;
 }
Exemplo n.º 6
0
require_once dirname(__FILE__) . '/../localinc/binarypool/config.php';
require_once dirname(__FILE__) . '/../localinc/binarypool/browser.php';
require_once dirname(__FILE__) . '/../localinc/binarypool/storage.php';
require_once dirname(__FILE__) . '/../localinc/binarypool/expiry.php';
function cleanSymlinks()
{
    // Do symlink cleanup
    printf("[%10s] Cleaning up symlinks.\n", 'FINAL');
    $cmd = binarypool_config::getUtilityPath('symlinks');
    system("{$cmd} -cdrs " . binarypool_config::getRoot() . "*/created");
    system("{$cmd} -cdrs " . binarypool_config::getRoot() . "*/expiry");
    system("{$cmd} -cdrsv " . binarypool_config::getRoot() . "*/downloaded |grep '/dev/null' |xargs -0 rm");
}
cleanSymlinks();
// Walk through each bucket
$buckets = binarypool_config::getBuckets();
foreach (array_keys($buckets) as $bucket) {
    $storage = new binarypool_storage($bucket);
    printf("[%10s] Fetching list of expired binaries.\n", $bucket);
    $expired = binarypool_browser::getExpired($bucket);
    printf("[%10s] %d expired.\n", $bucket, $expired);
    foreach ($expired as $asset) {
        try {
            if (binarypool_expiry::isExpired($bucket, $asset)) {
                printf("[%10s] Deleting %s\n", $bucket, $asset);
                $storage->delete($asset);
            }
        } catch (binarypool_exception $e) {
            if ($e->getCode() == 112) {
                printf("[%10s] Asset does not exist %s\n", $bucket, $asset);
            } else {
Exemplo n.º 7
0
 /**
  * Calculates the renditions for the given file.
  *
  * @param $type: Type - the renderer is chosen based on this type.
  * @param $bucket: Bucket and type define the renditions which have
  *                 to be generated.
  * @param $original: Absolute path to the original file.
  * @param $outputPath: Directory where the renditions are written to.
  * @param $exclude: Renditions which don't have to be calculated.
  * @param $assetFile: Path to the asset file. Needed for asynchronous
  *                    rendition processes.
  * @return Associative array of hashes. The key is the rendition name,
  *         the path is the relative path of the file.
  */
 public static function render($type, $bucket, $original, $outputPath, $exclude = array(), $assetFile = null)
 {
     // Get configured renditions for this type
     $buckets = binarypool_config::getBuckets();
     $renditions = array();
     if (!isset($buckets[$bucket]['renditions'][$type])) {
         return $renditions;
     }
     // Information about the original file
     $mime = binarypool_mime::getMimeType($original);
     // Loops through the renditions configuration and generates the
     // renditions as specified.
     //
     // The following keys of each rendition config are considered:
     //    - _sources: Ordered array of rendition names that should be
     //                used as input for this rendition. If not present
     //                of empty elements mean that the original
     //                binary is used.
     //    - _class:   The render_base subclass to use. The class is
     //                prefixed with 'binarypool_render_' to get the
     //                definitive PHP class name.
     //    - _mimes:   MIME type of the original binary for which this
     //                rendition is calculated.
     //
     // This three keys are removed from the array and the modified
     // array is then passed to the render class as configuration.
     //
     // The list of renditions needs to be in the correct dependency
     // order. If rendition `B' uses rendition `A' as a source, then
     // rendition `A' must come before `B'.
     foreach ($buckets[$bucket]['renditions'][$type] as $rendition => $renditionConfig) {
         // Renditions that the user uploaded are not calculated
         if (in_array($rendition, $exclude)) {
             continue;
         }
         // Rendition to be calculated?
         if (isset($renditionConfig['_mimes'])) {
             $mimesCfg = $renditionConfig['_mimes'];
             if (!is_array($mimesCfg)) {
                 $mimesCfg = array($mimesCfg);
             }
             if (!in_array($mime, $mimesCfg)) {
                 continue;
             }
             unset($renditionConfig['_mimes']);
         }
         // Get correct source file name
         $sourceFile = null;
         if (isset($renditionConfig['_sources'])) {
             foreach ($renditionConfig['_sources'] as $sourceRendition) {
                 if (isset($renditions[$sourceRendition])) {
                     $sourceFile = $renditions[$sourceRendition];
                     break;
                 } else {
                     if ($sourceRendition === '') {
                         $sourceFile = $original;
                         break;
                     }
                 }
             }
             unset($renditionConfig['_sources']);
         } else {
             $sourceFile = $original;
         }
         if (is_null($sourceFile)) {
             throw new binarypool_exception(106, 500, "Missing source rendition for rendition {$rendition}");
         }
         $renditionConfig['_bucket'] = $bucket;
         // Get correct class name
         $renditionType = strtolower($type);
         if (isset($renditionConfig['_class'])) {
             $renditionType = $renditionConfig['_class'];
             unset($renditionConfig['_class']);
         }
         $renderingClass = "binarypool_render_" . $renditionType;
         // Filenames
         $renditionFile = $rendition;
         $absoluteRendition = $outputPath . $renditionFile;
         // Render image. Return value of rendering is the absolute path to the
         // rendition including file extensions.
         $absoluteRendition = call_user_func($renderingClass . '::render', $sourceFile, $absoluteRendition, $assetFile, $renditionConfig);
         if (!is_null($absoluteRendition)) {
             if (!file_exists($absoluteRendition)) {
                 throw new binarypool_exception(106, 500, "Could not create rendition: {$rendition}");
             }
             $renditions[$rendition] = $absoluteRendition;
         }
     }
     return $renditions;
 }
Exemplo n.º 8
0
 function testBuckets()
 {
     $buckets = binarypool_config::getBuckets();
     $this->assertTrue(isset($buckets['test']), "Test bucket is not defined in configuration.");
     $this->assertTrue(isset($buckets['test']['renditions']), "Test bucket does not have any renditions.");
 }
 protected function getS3Bucket()
 {
     $buckets = binarypool_config::getBuckets();
     return $buckets['test_s3'];
 }