getInstance() public static method

public static getInstance ( ) : Scalr_UI_Request
return Scalr_UI_Request
示例#1
0
 /**
  * Converts Time according to timezone settings of current user.
  *
  * @param   DateTime|string|int  $value  DateTime object or Unix Timestamp or string that represents time.
  * @param   string               $format  Format
  * @return  string               Returns updated time in given format.
  */
 public static function convertTz($value, $format = 'M j, Y H:i:s')
 {
     $timezone = '';
     if (Scalr_UI_Request::getInstance()->getUser()) {
         $timezone = Scalr_UI_Request::getInstance()->getUser()->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE);
         if (!$timezone) {
             $timezone = 'UTC';
         }
     }
     return self::convertDateTime($value, $timezone, $format);
 }
示例#2
0
 public function getLocations()
 {
     try {
         $envId = Scalr_UI_Request::getInstance()->getEnvironment()->id;
     } catch (Exception $e) {
         return array();
     }
     $db = \Scalr::getDb();
     $locations = $db->GetAll("SELECT DISTINCT(`group`) as `name` FROM client_environment_properties WHERE `name` = ? AND env_id = ?", array(self::API_KEY, $envId));
     $retval = array();
     foreach ($locations as $location) {
         $retval[$location['name']] = "Rackspace / {$location['name']}";
     }
     return $retval;
 }
示例#3
0
 public function getLocations()
 {
     try {
         $envId = Scalr_UI_Request::getInstance()->getEnvironment()->id;
     } catch (Exception $e) {
         return array();
     }
     //Eucalyptus locations defined by client. Admin cannot get them
     $db = Core::GetDBInstance();
     $locations = $db->GetAll("SELECT DISTINCT(`group`) as `name` FROM client_environment_properties WHERE `name` = ? AND env_id = ?", array(self::API_URL, $envId));
     $retval = array();
     foreach ($locations as $location) {
         $retval[$location['name']] = "Openstack / {$location['name']}";
     }
     return $retval;
 }
示例#4
0
 public function create($farmRoleId, $applicationId, $serverId, $type, $remotePath, $envId = null, $status = Scalr_Dm_DeploymentTask::STATUS_PENDING)
 {
     $this->farmRoleId = $farmRoleId;
     $this->applicationId = $applicationId;
     $this->serverId = $serverId;
     $this->type = $type;
     $this->remotePath = $remotePath;
     if (!$envId) {
         $this->envId = Scalr_UI_Request::getInstance()->getEnvironment()->id;
     } else {
         $this->envId = $envId;
     }
     $this->log("Deployment task created. Status: pending");
     $this->status = $status;
     $this->save();
 }
示例#5
0
文件: Idcf.php 项目: recipe/scalr
 public function getLocations()
 {
     try {
         $environment = Scalr_UI_Request::getInstance()->getEnvironment();
         if ($environment && $environment->isPlatformEnabled($this->platform)) {
             $cs = Scalr_Service_Cloud_Cloudstack::newCloudstack($this->getConfigVariable(self::API_URL, $environment), $this->getConfigVariable(self::API_KEY, $environment), $this->getConfigVariable(self::SECRET_KEY, $environment), $this->platform);
             $retval = array();
             foreach ($cs->listZones() as $zone) {
                 $retval[$zone->name] = strtoupper($this->platform) . " / {$zone->name}";
             }
             return $retval;
         }
     } catch (Exception $e) {
     }
     return array("jp-east-t1v" => "IDCF / jp-east-t1v", "jp-east-f2v" => "IDCF / jp-east-f2v");
 }
示例#6
0
 public function check($object)
 {
     $cls = get_class($object);
     switch ($cls) {
         case 'Scalr_Environment':
             $flag = false;
             foreach ($this->user->getEnvironments() as $env) {
                 if ($env['id'] == $object->id) {
                     $flag = true;
                     break;
                 }
             }
             return $flag;
         case 'DBFarm':
             return $this->hasAccessFarm($object);
         case 'Scalr_Account_User':
             return $object->getAccountId() == $this->user->getAccountId();
         case 'Scalr_Account_Team':
             return $object->accountId == $this->user->getAccountId();
         case 'DBServer':
             return $this->hasAccessServer($object);
         case 'DBRole':
         case 'BundleTask':
         case 'DBDNSZone':
         case 'Scalr_Dm_Application':
         case 'Scalr_Dm_Source':
         case 'Scalr_Dm_DeploymentTask':
         case 'Scalr\\Model\\Entity\\ScalingMetric':
         case 'Scalr_ServiceConfiguration':
         case 'Scalr_Service_Apache_Vhost':
         case 'Scalr_SchedulerTask':
         case 'Scalr\\Model\\Entity\\SslCertificate':
         case 'Scalr_Db_Backup':
         case 'DBEBSVolume':
         case 'Scalr\\Model\\Entity\\Role':
         case 'Scalr\\Model\\Entity\\Image':
             return $this->hasAccessEnvironment($object->envId) && (method_exists($object, 'getFarmObject') ? $this->hasAccessFarm($object->getFarmObject()) : true);
         case 'DBFarmRole':
             return $this->hasAccessFarm($object->GetFarmObject());
         case 'Scalr\\Acl\\Role\\AccountRoleObject':
             return $this->user->canManageAcl() && $object->getAccountId() == $this->user->getAccountId();
         default:
             if ($object instanceof AccessPermissionsInterface) {
                 return $object->hasAccessPermissions($this->user, Scalr_UI_Request::getInstance()->getEnvironment());
             }
     }
 }
示例#7
0
 public static function convertTz($value, $format = 'M j, Y H:i:s')
 {
     if (is_integer($value)) {
         $value = "@{$value}";
     }
     $dt = new DateTime($value);
     if ($dt && $dt->getTimestamp()) {
         if (Scalr_UI_Request::getInstance()->getEnvironment()) {
             $timezone = Scalr_UI_Request::getInstance()->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_TIMEZONE);
             if (!$timezone) {
                 $timezone = 'UTC';
             }
             self::convertDateTime($dt, $timezone, $dt->getTimezone());
         }
         return $dt->format($format);
     } else {
         return NULL;
     }
 }
示例#8
0
 public function getLocations()
 {
     try {
         $environment = Scalr_UI_Request::getInstance()->getEnvironment();
     } catch (Exception $e) {
         return array();
     }
     if (!$environment || !$environment->isPlatformEnabled($this->platform)) {
         return array();
     }
     try {
         $cs = Scalr_Service_Cloud_Cloudstack::newCloudstack($this->getConfigVariable(self::API_URL, $environment), $this->getConfigVariable(self::API_KEY, $environment), $this->getConfigVariable(self::SECRET_KEY, $environment), $this->platform);
         foreach ($cs->listZones() as $zone) {
             $retval[$zone->name] = ucfirst($this->platform) . " / {$zone->name}";
         }
     } catch (Exception $e) {
         return array();
     }
     return $retval;
 }
示例#9
0
 public function getLocations()
 {
     try {
         $environment = Scalr_UI_Request::getInstance()->getEnvironment();
     } catch (Exception $e) {
         return array();
     }
     if (!$environment || !$environment->isPlatformEnabled(SERVER_PLATFORMS::CLOUDSTACK)) {
         return array();
     }
     try {
         $cs = Scalr_Service_Cloud_Cloudstack::newCloudstack($environment->getPlatformConfigValue(self::API_URL), $environment->getPlatformConfigValue(self::API_KEY), $environment->getPlatformConfigValue(self::SECRET_KEY));
         foreach ($cs->listZones() as $zone) {
             $retval[$zone->name] = "Cloudstack / {$zone->name}";
         }
     } catch (Exception $e) {
         return array();
     }
     return $retval;
 }
示例#10
0
 public function getLocations()
 {
     try {
         $environment = Scalr_UI_Request::getInstance()->getEnvironment();
     } catch (Exception $e) {
         return array();
     }
     if (!$environment || !$environment->isPlatformEnabled($this->platform)) {
         return array();
     }
     try {
         $client = $environment->openstack($this->platform, "fakeRegion");
         foreach ($client->listZones() as $zone) {
             $retval[$zone->name] = ucfirst($this->platform) . " / {$zone->name}";
         }
     } catch (Exception $e) {
         return array();
     }
     return $retval;
 }
示例#11
0
文件: uCloud.php 项目: recipe/scalr
 public function getLocations()
 {
     try {
         $environment = Scalr_UI_Request::getInstance()->getEnvironment();
     } catch (Exception $e) {
         return array();
     }
     if (!$environment || !$environment->isPlatformEnabled($this->platform)) {
         return array();
     }
     try {
         $cs = Scalr_Service_Cloud_Cloudstack::newCloudstack($this->getConfigVariable(self::API_URL, $environment), $this->getConfigVariable(self::API_KEY, $environment), $this->getConfigVariable(self::SECRET_KEY, $environment), $this->platform);
         $products = $cs->listAvailableProductTypes();
         foreach ($products->producttypes as $product) {
             $retval[$product->zoneid] = "KT uCloud / {$product->zonedesc} ({$product->zoneid})";
         }
     } catch (Exception $e) {
         return array();
     }
     return $retval;
 }
示例#12
0
文件: GoogleCE.php 项目: recipe/scalr
 public function getLocations()
 {
     try {
         $environment = Scalr_UI_Request::getInstance()->getEnvironment();
     } catch (Exception $e) {
         return array();
     }
     if (!$environment || !$environment->isPlatformEnabled(SERVER_PLATFORMS::GCE)) {
         return array();
     }
     try {
         $client = $this->getClient($environment, "fakeRegion");
         $zones = $client->zones->listZones($environment->getPlatformConfigValue(self::PROJECT_ID));
         foreach ($zones->getItems() as $zone) {
             if ($zone->status == 'UP') {
                 $retval[$zone->getName()] = "GCE / {$zone->getName()}";
             }
         }
     } catch (Exception $e) {
         return array();
     }
     return $retval;
 }
示例#13
0
 public function save()
 {
     // bilyad'
     if (!$this->ID) {
         $this->ID = 0;
         $this->Hash = substr(md5(uniqid(rand(), true)), 0, 14);
         $this->ClientID = Scalr_UI_Request::getInstance()->getUser()->getAccountId();
         $this->EnvID = Scalr_UI_Request::getInstance()->getEnvironment()->id;
     }
     if ($this->DB->GetOne('SELECT id FROM farms WHERE name = ? AND env_id = ? AND id != ?', array($this->Name, $this->EnvID, $this->ID))) {
         throw new Exception('This name already used');
     }
     if (!$this->ID) {
         $this->DB->Execute("INSERT INTO farms SET\r\n\t\t\t\t\tstatus\t\t= ?, \r\n\t\t\t\t\tname\t\t= ?, \r\n\t\t\t\t\tclientid\t= ?,\r\n\t\t\t\t\tenv_id\t\t= ?, \r\n\t\t\t\t\thash\t\t= ?, \r\n\t\t\t\t\tdtadded\t\t= NOW(),\t\t\t\t\t\t\r\n\t\t\t\t\tfarm_roles_launch_order = ?,\r\n\t\t\t\t\tcomments = ?\r\n\t\t\t\t", array(FARM_STATUS::TERMINATED, $this->Name, $this->ClientID, $this->EnvID, $this->Hash, $this->RolesLaunchOrder, $this->Comments));
         $this->ID = $this->DB->Insert_ID();
     } else {
         $this->DB->Execute("UPDATE farms SET \r\n\t\t\t\t\tname\t\t= ?,\r\n\t\t\t\t\tstatus\t\t= ?,\r\n\t\t\t\t\tfarm_roles_launch_order = ?,\r\n\t\t\t\t\tterm_on_sync_fail = ?,\r\n\t\t\t\t\tcomments = ?\r\n\t\t\t\tWHERE id = ?\r\n\t\t\t\t", array($this->Name, $this->Status, $this->RolesLaunchOrder, $this->TermOnSyncFail, $this->Comments, $this->ID));
     }
 }
示例#14
0
 /**
  *
  * @return Scalr_UI_Controller
  * @throws Scalr_UI_Exception_NotFound
  * @throws Scalr_Exception_InsufficientPermissions
  */
 public static function loadController($controller, $prefix = 'Scalr_UI_Controller', $checkPermissions = false)
 {
     if (preg_match("/^[a-z0-9]+\$/i", $controller)) {
         $controller = ucwords(strtolower($controller));
         // support versioning
         if ($prefix == 'Scalr_UI_Controller' && $controller == 'Account') {
             $request = Scalr_UI_Request::getInstance();
             if ($request->getRequestType() == Scalr_UI_Request::REQUEST_TYPE_UI) {
                 $controller = 'Account2';
             } else {
                 if ($request->getRequestType() == Scalr_UI_Request::REQUEST_TYPE_API && $request->requestApiVersion == '2') {
                     $controller = 'Account2';
                 }
             }
         }
         $className = "{$prefix}_{$controller}";
         if (file_exists(SRCPATH . '/' . str_replace('_', '/', $prefix) . '/' . $controller . '.php') && class_exists($className)) {
             $o = new $className();
             $o->init();
             if (!$checkPermissions || $o->hasAccess()) {
                 return $o;
             } else {
                 throw new Scalr_Exception_InsufficientPermissions();
             }
         }
     }
     throw new Scalr_UI_Exception_NotFound(isset($className) ? $className : '');
 }
 /**
  * Recursively parse XML object
  * @access protected
  * @return void
  */
 protected function GetNodes(&$root)
 {
     foreach ($root->childNodes as $node) {
         switch ($node->nodeName) {
             case "node":
                 $class = $node->getAttribute('class') ? " class='{$node->getAttribute('class')}'" : "";
                 $this->HTMLMenu .= "<li{$class}>{$node->getAttribute('title')}<ul>";
                 $this->SMenu .= "<li>{$node->getAttribute('title')}<ul>";
                 // Add nodes from externals
                 $id = (string) $node->getAttribute('id');
                 if ($this->ExternalNodes[$id]) {
                     $this->GetExternalNodes($this->ExternalNodes[$id]);
                 }
                 $this->GetNodes($node);
                 $this->HTMLMenu .= "</ul></li>";
                 $this->SMenu .= "</ul></li>";
                 break;
             case "item":
                 $class = $node->getAttribute('class') ? " class='{$node->getAttribute('class')}'" : "";
                 $this->HTMLMenu .= "<li{$class}><a href='{$node->getAttribute('href')}'>{$node->nodeValue}</a></li>";
                 if ($this->SearchString !== false && $node->getAttribute('search')) {
                     $query = (string) $node->getAttribute('search');
                     $query = str_replace('{ENV_ID}', Scalr_UI_Request::getInstance()->getEnvironment()->id, $query);
                     $query = str_replace('{CLIENT_ID}', Scalr_UI_Request::getInstance()->getUser()->getAccountId(), $query);
                     $this->SearchString = str_replace('\'', '', $this->SearchString);
                     $res = $this->DB->GetOne(sprintf($query, "%{$this->SearchString}%", "%{$this->SearchString}%", "%{$this->SearchString}%", "%{$this->SearchString}%"));
                     $this->SMenu .= "<li><a href='{$node->getAttribute('href')}?search={$this->SearchString}'>{$node->nodeValue}</a> ({$res})</li>";
                 }
                 break;
             case "separator":
                 $this->HTMLMenu .= "<li class='MenuSep'></li>";
                 break;
         }
     }
 }
示例#16
0
 public function save()
 {
     if (!$this->ID) {
         $this->ID = 0;
         $this->Hash = substr(Scalr_Util_CryptoTool::hash(uniqid(rand(), true)), 0, 14);
         //FIXME This is F*CKINK BULLSHIT! REMOVE Scalr_UI_Request From here.
         if (!$this->ClientID) {
             $this->ClientID = Scalr_UI_Request::getInstance()->getUser()->getAccountId();
         }
         if (!$this->EnvID) {
             $this->EnvID = Scalr_UI_Request::getInstance()->getEnvironment()->id;
         }
     }
     if ($this->DB->GetOne('SELECT id FROM farms WHERE name = ? AND env_id = ? AND id != ? LIMIT 1', array($this->Name, $this->EnvID, $this->ID))) {
         throw new Exception('This name already used');
     }
     if (!$this->ID) {
         $this->DB->Execute("INSERT INTO farms SET\n                status\t\t= ?,\n                name\t\t= ?,\n                clientid\t= ?,\n                env_id\t\t= ?,\n                hash\t\t= ?,\n                created_by_id = ?,\n                created_by_email = ?,\n                changed_by_id = ?,\n                changed_time = ?,\n                dtadded\t\t= NOW(),\n                farm_roles_launch_order = ?,\n                comments = ?\n            ", array(FARM_STATUS::TERMINATED, $this->Name, $this->ClientID, $this->EnvID, $this->Hash, $this->createdByUserId, $this->createdByUserEmail, $this->changedByUserId, $this->changedTime, $this->RolesLaunchOrder, $this->Comments));
         $this->ID = $this->DB->Insert_ID();
     } else {
         $this->DB->Execute("UPDATE farms SET\n                name\t\t= ?,\n                status\t\t= ?,\n                farm_roles_launch_order = ?,\n                term_on_sync_fail = ?,\n                comments = ?,\n                changed_by_id = ?,\n                changed_time = ?\n            WHERE id = ?\n            ", array($this->Name, $this->Status, $this->RolesLaunchOrder, $this->TermOnSyncFail, $this->Comments, $this->changedByUserId, $this->changedTime, $this->ID));
     }
 }
示例#17
0
 public static function handleRequest($pathChunks, $params)
 {
     if ($pathChunks[0] == '') {
         $pathChunks = array('guest');
     }
     try {
         Scalr_UI_Request::getInstance()->setParams($params);
         $user = Scalr_UI_Request::getInstance()->getUser();
         $controller = self::loadController(array_shift($pathChunks), 'Scalr_UI_Controller', true);
         if (!$user && get_class($controller) != 'Scalr_UI_Controller_Guest') {
             throw new Scalr_Exception_InsufficientPermissions();
         } else {
             $controller->uiCacheKeyPattern = '';
             if ($user && $user->getAccountId() && $user->getAccount()->status != Scalr_Account::STATUS_ACTIVE && $user->getType() == Scalr_Account_User::TYPE_ACCOUNT_OWNER && get_class($controller) != 'Scalr_UI_Controller_Billing' && get_class($controller) != 'Scalr_UI_Controller_Core' && get_class($controller) != 'Scalr_UI_Controller_Guest' && get_class($controller) != 'Scalr_UI_Controller_Environments') {
                 // suspended account, user = owner, replace controller with billing or allow billing action/guest action
                 $controller = self::loadController('Billing', 'Scalr_UI_Controller', true);
                 $controller->addUiCacheKeyPatternChunk(strtolower(array_pop(explode('_', get_class($controller)))));
                 $controller->call();
             } else {
                 $controller->addUiCacheKeyPatternChunk(strtolower(array_pop(explode('_', get_class($controller)))));
                 $controller->call($pathChunks);
             }
         }
     } catch (Scalr_UI_Exception_AccessDenied $e) {
         Scalr_UI_Response::getInstance()->setHttpResponseCode(403);
     } catch (Scalr_Exception_InsufficientPermissions $e) {
         if (is_object($user)) {
             Scalr_UI_Response::getInstance()->failure($e->getMessage());
         } else {
             Scalr_UI_Response::getInstance()->setHttpResponseCode(403);
         }
     } catch (Scalr_UI_Exception_NotFound $e) {
         Scalr_UI_Response::getInstance()->setHttpResponseCode(404);
     } catch (Exception $e) {
         Scalr_UI_Response::getInstance()->failure($e->getMessage());
     }
     Scalr_UI_Response::getInstance()->sendResponse();
 }
示例#18
0
文件: Response.php 项目: mheydt/scalr
 public function getModuleName($name)
 {
     $v = Scalr_UI_Request::getInstance()->getHeaderVar('Interface');
     $vPath = !is_null($v) ? intval(trim($v, 'v')) : '2';
     $path = "ui{$vPath}/js/";
     $fl = APPPATH . "/www/{$path}{$name}";
     if (file_exists($fl)) {
         $tm = filemtime(APPPATH . "/www/{$path}{$name}");
     } else {
         throw new Scalr_UI_Exception_NotFound(sprintf('Js file not found'));
     }
     $nameTm = str_replace('.js', "-{$tm}.js", $name);
     $nameTm = str_replace('.css', "-{$tm}.css", $nameTm);
     return "/{$path}{$nameTm}";
 }