Exemple #1
0
 /**
  * Construct the class; set defaults
  *
  * @access	public
  * @return	void
  *
  **/
 public function __construct()
 {
     parent::__construct();
     // --------------------------------------------------------------------------
     //	Work out some variables
     $_token = $this->input->get('token');
     if ($_token) {
         //	Encrypted token/expiring URL
         $_token = $this->encrypt->decode($_token, APP_PRIVATE_KEY);
         $_token = explode('|', $_token);
         if (count($_token) == 5) {
             $this->_bad_token = FALSE;
             //	Seems to be ok, but verify the different parts
             list($_bucket, $_object, $_expires, $_time, $_hash) = $_token;
             if (md5($_time . $_bucket . $_object . $_expires . APP_PRIVATE_KEY) == $_hash) {
                 //	Hash validates, URL expired?
                 if (time() <= $_time + $_expires) {
                     $this->_bucket = $_bucket;
                     $this->_object = $_object;
                     $this->_bad_token = FALSE;
                 } else {
                     $this->_bad_token = TRUE;
                 }
             } else {
                 $this->_bad_token = TRUE;
             }
         } else {
             $this->_bad_token = TRUE;
         }
     } else {
         $this->_bad_token = FALSE;
         $this->_bucket = $this->uri->segment(3);
         $this->_object = urldecode($this->uri->segment(4));
     }
 }
Exemple #2
0
 /**
  * Construct the class; set defaults
  *
  * @access	public
  * @return	void
  *
  **/
 public function __construct()
 {
     parent::__construct();
     // --------------------------------------------------------------------------
     //	Determine dynamic values
     $this->_width = $this->uri->segment(3, 100);
     $this->_height = $this->uri->segment(4, 100);
     $this->_bucket = $this->uri->segment(5);
     $this->_object = urldecode($this->uri->segment(6));
     $this->_extension = !empty($this->_object) ? strtolower(substr($this->_object, strrpos($this->_object, '.'))) : FALSE;
 }
Exemple #3
0
 /**
  * Construct the class; set defaults
  *
  * @access	public
  * @return	void
  *
  **/
 public function __construct()
 {
     parent::__construct();
     // --------------------------------------------------------------------------
     //	'Constant' variables
     $this->_man = $this->_cdn_root . '_resources/img/avatar_man.png';
     $this->_woman = $this->_cdn_root . '_resources/img/avatar_woman.png';
     // --------------------------------------------------------------------------
     //	Determine dynamic values
     $this->_width = $this->uri->segment(3, 100);
     $this->_height = $this->uri->segment(4, 100);
     $this->_sex = $this->uri->segment(5, 'man');
     //	Set a unique filename (but one which is constant if requested twice, i.e
     //	no random values)
     $this->_cache_file = 'blank_avatar-' . $this->_width . 'x' . $this->_height . '-' . $this->_sex . '.png';
 }
Exemple #4
0
 public function __construct()
 {
     parent::__construct();
     // --------------------------------------------------------------------------
     //	'Constant' variables
     $this->_tile = $this->_cdn_root . '_resources/img/placeholder.png';
     //	Determine dynamic values
     $this->_width = $this->uri->segment(3, 100);
     $this->_height = $this->uri->segment(4, 100);
     $this->_border = $this->uri->segment(5, 1);
     //	Apply limits (prevent DOS)
     $this->_width = $this->_width > 2000 ? 2000 : $this->_width;
     $this->_height = $this->_height > 2000 ? 2000 : $this->_height;
     $this->_border = $this->_border > 2000 ? 2000 : $this->_border;
     //	Set a unique filename (but one which is constant if requested twice, i.e
     //	no random values)
     $this->_cache_file = 'placeholder-' . $this->_width . 'x' . $this->_height . '-' . $this->_border . '.png';
 }
Exemple #5
0
 /**
  * Construct the class; set defaults
  *
  * @access	public
  * @return	void
  *
  **/
 public function __construct()
 {
     parent::__construct();
     // --------------------------------------------------------------------------
     //	Module enabled?
     if (!module_is_enabled('cdn')) {
         show_404();
     }
     // --------------------------------------------------------------------------
     //	Determine if browsing/uploading is permitted
     $this->data['enabled'] = $this->user_model->is_logged_in() ? TRUE : FALSE;
     $this->data['enabled'] = TRUE;
     // --------------------------------------------------------------------------
     //	Load CDN library
     $this->load->library('cdn');
     // --------------------------------------------------------------------------
     if ($this->data['enabled']) {
         //	Define the directory, if a bucket has been specified use that, if not
         //	then use the user's upload directory
         if ($this->input->get('bucket') && $this->input->get('hash')) {
             //	Decrypt the bucket and cross reference with the hash. Doing this so
             //	That users can't casually specify a bucket and upload willy nilly.
             $_bucket = $this->input->get('bucket');
             $_hash = $this->input->get('hash');
             $_decrypted = $this->encrypt->decode($_bucket, APP_PRIVATE_KEY);
             if ($_decrypted) {
                 $_bucket = explode('|', $_decrypted);
                 if ($_bucket[0] && isset($_bucket[1])) {
                     //	Bucket and nonce set, cross-check
                     if (md5($_bucket[0] . '|' . $_bucket[1] . '|' . APP_PRIVATE_KEY) === $_hash) {
                         $this->data['bucket'] = $this->cdn->get_bucket($_bucket[0], TRUE, $this->input->get('filter-tag'));
                         if ($this->data['bucket']) {
                             $_test_ok = TRUE;
                         } else {
                             //	Bucket doesn't exist - attempt to create it
                             if ($this->cdn->bucket_create($_bucket[0])) {
                                 $_test_ok = TRUE;
                                 $this->data['bucket'] = $this->cdn->get_bucket($_bucket[0], TRUE, $this->input->get('filter-tag'));
                             } else {
                                 $_test_ok = FALSE;
                                 $_error = 'Bucket <strong>"' . $_bucket[0] . '"</strong> does not exist';
                                 $_error .= '<small>Additionally, the following error occured while attempting to create the bucket:<br />' . $this->cdn->last_error() . '</small>';
                             }
                         }
                     } else {
                         $_test_ok = FALSE;
                         $_error = 'Could not verify bucket hash';
                     }
                 } else {
                     $_test_ok = FALSE;
                     $_error = 'Incomplete bucket hash';
                 }
             } else {
                 $_test_ok = FALSE;
                 $_error = 'Could not decrypt bucket hash';
             }
             // --------------------------------------------------------------------------
             if (!$_test_ok) {
                 $this->data['enabled'] = FALSE;
                 $this->data['bad_bucket'] = $_error;
             }
         } else {
             //	No bucket specified, use the user's upload bucket
             $_slug = 'user-' . active_user('id');
             $_label = 'User Upload Directory';
             // --------------------------------------------------------------------------
             //	Test bucket, if it doesn't exist, create it
             $this->data['bucket'] = $this->cdn->get_bucket($_slug, TRUE, $this->input->get('filter-tag'));
             if (!$this->data['bucket']) {
                 $_bucket_id = $this->cdn->bucket_create($_slug, $_label);
                 if (!$_bucket_id) {
                     $this->data['enabled'] = FALSE;
                     $this->data['bad_bucket'] = 'Unable to create upload bucket: ' . $this->cdn->last_error();
                 } else {
                     $this->data['bucket'] = $this->cdn->get_bucket($_bucket_id, TRUE, $this->input->get('filter-tag'));
                 }
             }
         }
     }
 }