/** * Constructor for OpenCloud Utility Helper * @param string $username Openstack Username * @param string $apiKey Openstack APIKey * @param boolean $useRackspace Whether or not we should use Rackspace CLoudfiles * @param url $identity Identity URL * @param string $region Default region we should store assets in */ public function __construct($username, $apiKey, $useRackspace = false, $identity = NULL, $region = 'IAD') { $this->identity = $identity; $this->username = $username; $this->apiKey = $apiKey; $this->useRackspace = $useRackspace; $this->region = $region; $this->_overrideControl = Cii::getCiiConfig(); }
/** * Uploads a file to the CiiMS File CDN * @return string */ private function _uploadCiiMSFile() { $args = array('file' => new CurlFile($_FILES['file']['tmp_name'], $_FILES['file']['type'], $_FILES['file']['name']), 'token' => Cii::get(Cii::getCiiConfig(), 'token', NULL), 'container' => Cii::get(Cii::getCiiConfig(), 'container')); $resource = curl_init(Cii::get(Cii::getCiiConfig(), 'file_api_endpoint')); curl_setopt($resource, CURLOPT_POST, 1); curl_setopt($resource, CURLOPT_POSTFIELDS, $args); curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1); curl_setopt($resource, CURLOPT_FOLLOWLOCATION, 1); $this->_result = CJSON::decode(curl_exec($resource)); if ($this->_result == false || $this->_result == NULL) { throw new CHttpException(500, curl_error($resource)); } curl_close($resource); $this->_result = $this->_result['response']; return $this->_handleResourceUpload($this->_result['url'] . '/' . $this->_result['filename']); }
/** * Allow some override values * @return parent::beforeSave(); */ public function beforeSave() { if (($allow_api = Cii::get(Cii::getCiiConfig(), 'allow_api', true)) == false) { $this->attributes['enableAPI'] = $this->enableAPI = (int) $allow_api; } // Encrypt the Openstack API Key if ($this->attributes['openstack_apikey'] != NULL && $this->attributes['openstack_apikey'] != "") { $this->attributes['openstack_apikey'] = $this->openstack_apikey = Cii::encrypt($this->attributes['openstack_apikey']); } return parent::beforeSave(); }
/** * BeforeAction, validates that there is a valid response body * @param CAction $action The action we want to run */ public function beforeAction($action) { if (Cii::getConfig('enableAPI') != true || Cii::get(Cii::getCiiConfig(), 'allow_api', true) == false) { header('HTTP/1.1 403 Access Denied'); $this->status = 403; $this->message = Yii::t('Api.main', 'The CiiMS API is not enabled.'); return null; } // If content was sent as application/x-www-form-urlencoded, use it. Otherwise, assume raw JSON was sent and convert it into // the $_POST variable for ease of use if (Yii::app()->request->rawBody != "" && empty($_POST)) { // IF the rawBody is malformed, throw an HTTP 500 error. Use json_encode so that we can get json_last_error $_POST = json_decode(Yii::app()->request->rawBody); if (json_last_error() != JSON_ERROR_NONE) { header('HTTP/1.1 400 Bad Request'); $this->status = 400; $this->message = Yii::t('Api.main', 'Request payload not properly formed JSON.'); return null; } $_POST = CJSON::decode(Yii::app()->request->rawBody); } return true; }