コード例 #1
0
ファイル: DateTime.php プロジェクト: sacredwebsite/scalr
 /**
  * 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
ファイル: Rackspace.php プロジェクト: recipe/scalr
 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
ファイル: 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");
 }
コード例 #4
0
ファイル: DeploymentTask.php プロジェクト: mheydt/scalr
 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
ファイル: Openstack.php プロジェクト: rakesh-mohanta/scalr
 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;
 }
コード例 #6
0
ファイル: Permissions.php プロジェクト: mheydt/scalr
 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
ファイル: DateTime.php プロジェクト: rakesh-mohanta/scalr
 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
ファイル: Cloudstack.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);
         foreach ($cs->listZones() as $zone) {
             $retval[$zone->name] = ucfirst($this->platform) . " / {$zone->name}";
         }
     } catch (Exception $e) {
         return array();
     }
     return $retval;
 }
コード例 #9
0
ファイル: Cloudstack.php プロジェクト: rakesh-mohanta/scalr
 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
ファイル: Openstack.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 {
         $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
ファイル: Request.php プロジェクト: rakesh-mohanta/scalr
 public static function initializeInstance($type, $userId, $envId)
 {
     $instance = new Scalr_UI_Request($type);
     if ($userId) {
         try {
             $user = Scalr_Account_User::init();
             $user->loadById($userId);
         } catch (Exception $e) {
             throw new Exception('User account is no longer available.');
         }
         if ($user->status != Scalr_Account_User::STATUS_ACTIVE) {
             throw new Exception('User account has been deactivated. Please contact your account owner.');
         }
         if ($user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) {
             $environment = $user->getDefaultEnvironment($envId);
             $user->getPermissions()->setEnvironmentId($environment->id);
         }
         if ($user->getAccountId()) {
             if ($user->getAccount()->status == Scalr_Account::STATUS_INACIVE) {
                 if ($user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
                     throw new Exception('Scalr account has been deactivated. Please contact scalr team.');
                 }
             } else {
                 if ($user->getAccount()->status == Scalr_Account::STATUS_SUSPENDED) {
                     if ($user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
                         throw new Exception('Account was suspended. Please contact your account owner to solve this situation.');
                     }
                 }
             }
         }
         $instance->user = $user;
         $instance->environment = $environment;
     }
     self::$_instance = $instance;
     return $instance;
 }
コード例 #14
0
ファイル: Controller.php プロジェクト: recipe/scalr
 /**
  *
  * @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 : '');
 }
コード例 #15
0
ファイル: ui.php プロジェクト: rakesh-mohanta/scalr
    if ($error && ($error['type'] == E_ERROR || $error['type'] == E_PARSE || $error['type'] == E_COMPILE_ERROR)) {
        if (!headers_sent()) {
            header("HTTP/1.0 500");
        }
    }
});
$path = trim(str_replace("?{$_SERVER['QUERY_STRING']}", "", $_SERVER['REQUEST_URI']), '/');
define('SCALR_NOT_CHECK_SESSION', 1);
try {
    $t = microtime(true);
    require "src/prepend.inc.php";
    $pTime = microtime(true) - $t;
    @header("X-Scalr-PTime: {$pTime}");
    $session = Scalr_Session::getInstance();
    try {
        $request = Scalr_UI_Request::initializeInstance(Scalr_UI_Request::REQUEST_TYPE_UI, $session->getUserId(), $session->getEnvironmentId());
    } catch (Exception $e) {
        if ($path == 'guest/logout') {
            // hack
            Scalr_Session::destroy();
            Scalr_UI_Response::getInstance()->setRedirect('/');
            Scalr_UI_Response::getInstance()->sendResponse();
            exit;
        }
        $message = $e->getMessage() . ' <a href="/guest/logout">Click here to login as another user</a>';
        throw new Exception($message);
    }
    if ($session->isAuthenticated()) {
        $session->setEnvironmentId($request->getEnvironment()->id);
    }
    //@session_write_close();
コード例 #16
0
ファイル: Request.php プロジェクト: scalr/scalr
 /**
  * @param $type
  * @param $headers
  * @param $server
  * @param $params
  * @param $files
  * @param $userId
  * @param $envId int optional Could be null, when we check headers (for UI)
  * @return Scalr_UI_Request
  * @throws Scalr_Exception_Core
  * @throws Exception
  */
 public static function initializeInstance($type, $headers, $server, $params, $files, $userId, $envId = null)
 {
     if (self::$_instance) {
         self::$_instance = null;
     }
     $class = get_called_class();
     /* @var $instance Scalr_UI_Request */
     $instance = new $class($type, $headers, $server, $params, $files);
     $container = Scalr::getContainer();
     if ($userId) {
         try {
             $user = Scalr_Account_User::init();
             $user->loadById($userId);
         } catch (Exception $e) {
             throw new Exception('User account is no longer available.');
         }
         if ($user->status != Scalr_Account_User::STATUS_ACTIVE) {
             throw new Exception('User account has been deactivated. Please contact your account owner.');
         }
         $scope = $instance->getHeaderVar('Scope');
         // ajax file upload, download files
         if (empty($scope)) {
             $scope = $instance->getParam('X-Scalr-Scope');
         }
         if (empty($envId)) {
             $envId = $instance->getParam('X-Scalr-Envid');
         }
         if ($user->isAdmin()) {
             if ($scope != 'scalr') {
                 $scope = 'scalr';
             }
         } else {
             if (!in_array($scope, ['account', 'environment'])) {
                 $scope = 'environment';
             }
         }
         if (!$user->isAdmin()) {
             if ($envId || $scope == 'environment') {
                 if (!$envId) {
                     $envId = $instance->getHeaderVar('Envid');
                 }
                 $environment = $user->getDefaultEnvironment($envId);
                 $user->getPermissions()->setEnvironmentId($environment->id);
                 $scope = 'environment';
             }
         }
         if ($user->getAccountId()) {
             if ($user->getAccount()->status == Scalr_Account::STATUS_INACIVE) {
                 if ($user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
                     throw new Exception('Scalr account has been deactivated. Please contact scalr team.');
                 }
             } else {
                 if ($user->getAccount()->status == Scalr_Account::STATUS_SUSPENDED) {
                     if ($user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
                         throw new Exception('Account was suspended. Please contact your account owner to solve this situation.');
                     }
                 }
             }
         }
         $ipWhitelist = $user->getVar(Scalr_Account_User::VAR_SECURITY_IP_WHITELIST);
         if ($ipWhitelist) {
             $ipWhitelist = unserialize($ipWhitelist);
             if (!Scalr_Util_Network::isIpInSubnets($instance->getRemoteAddr(), $ipWhitelist)) {
                 throw new Exception('The IP address isn\'t authorized.');
             }
         }
         // check header's variables
         $headerUserId = !is_null($instance->getHeaderVar('Userid')) ? intval($instance->getHeaderVar('Userid')) : null;
         if (!empty($headerUserId) && $headerUserId != $user->getId()) {
             throw new Scalr_Exception_Core('Session expired. Please refresh page.', 1);
         }
         $instance->user = $user;
         $instance->environment = isset($environment) ? $environment : null;
         $instance->scope = $scope;
     }
     $container->request = $instance;
     $container->environment = isset($instance->environment) ? $instance->environment : null;
     self::$_instance = $instance;
     $container->set('auditlogger.request', function () {
         return self::$_instance;
     });
     return $instance;
 }
コード例 #17
0
 /**
  * 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;
         }
     }
 }
コード例 #18
0
ファイル: api.php プロジェクト: rakesh-mohanta/scalr
    $envId = (int) $_SERVER['HTTP_X_SCALR_ENV_ID'];
    $pathChunks = explode('/', $path);
    $version = array_shift($pathChunks);
    $path = '/' . $path;
    //if (! $envId)
    //throw new Exception('Environment not defined');
    // TODO: how to check if needed ?
    $user = Scalr_Account_User::init();
    $user->loadByApiAccessKey($keyId);
    if (!$user->getSetting(Scalr_Account_User::SETTING_API_ENABLED)) {
        throw new Exception("API disabled for this account");
    }
    //Check IP whitelist
    $postData = isset($_POST['rawPostData']) ? $_POST['rawPostData'] : '';
    $secretKey = $user->getSetting(Scalr_Account_User::SETTING_API_SECRET_KEY);
    $stringToSign = "{$path}:{$keyId}:{$envId}:{$postData}:{$secretKey}";
    $validToken = Scalr_Util_CryptoTool::hash($stringToSign);
    if ($validToken != $token) {
        throw new Exception("Invalid authentification token");
    }
    Scalr_UI_Request::initializeInstance(Scalr_UI_Request::REQUEST_TYPE_API, $user->id, $envId);
    // prepate input data
    $postDataConvert = array();
    foreach (json_decode($postData, true) as $key => $value) {
        $postDataConvert[str_replace('.', '_', $key)] = $value;
    }
    Scalr_Api_Controller::handleRequest($pathChunks, $postDataConvert);
} catch (Exception $e) {
    Scalr_UI_Response::getInstance()->failure($e->getMessage());
    Scalr_UI_Response::getInstance()->sendResponse();
}
コード例 #19
0
ファイル: Controller.php プロジェクト: rakesh-mohanta/scalr
 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();
 }
コード例 #20
0
ファイル: class.DBFarm.php プロジェクト: rakesh-mohanta/scalr
 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));
     }
 }
コード例 #21
0
ファイル: api.php プロジェクト: recipe/scalr
    $version = array_shift($pathChunks);
    $path = '/' . $path;
    //if (! $envId)
    //throw new Exception('Environment not defined');
    // TODO: how to check if needed ?
    $user = Scalr_Account_User::init();
    $user->loadByApiAccessKey($keyId);
    if (!$user->getSetting(Scalr_Account_User::SETTING_API_ENABLED)) {
        throw new Exception("API disabled for this account");
    }
    //Check IP whitelist
    $postData = isset($_POST['rawPostData']) ? $_POST['rawPostData'] : '';
    $secretKey = $user->getSetting(Scalr_Account_User::SETTING_API_SECRET_KEY);
    $stringToSign = "{$path}:{$keyId}:{$envId}:{$postData}:{$secretKey}";
    $validToken = Scalr_Util_CryptoTool::hash($stringToSign);
    if ($validToken != $token) {
        throw new Exception("Invalid authentification token");
    }
    // prepate input data
    $postDataConvert = array();
    foreach (json_decode($postData, true) as $key => $value) {
        $postDataConvert[str_replace('.', '_', $key)] = $value;
    }
    $request = Scalr_UI_Request::initializeInstance(Scalr_UI_Request::REQUEST_TYPE_API, apache_request_headers(), $_SERVER, $postDataConvert, $_FILES, $user->id, $envId);
    $request->requestApiVersion = intval(trim($version, 'v'));
    Scalr_Api_Controller::handleRequest($pathChunks);
    Scalr_UI_Response::getInstance()->sendResponse();
} catch (Exception $e) {
    Scalr_UI_Response::getInstance()->failure($e->getMessage());
    Scalr_UI_Response::getInstance()->sendResponse();
}
コード例 #22
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}";
 }
コード例 #23
0
ファイル: class.DBFarm.php プロジェクト: recipe/scalr
 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));
     }
 }
コード例 #24
0
ファイル: ui.php プロジェクト: sacredwebsite/scalr
    \Scalr::logException($e);
    Scalr_UI_Response::getInstance()->data(array('errorDB' => true));
    Scalr_UI_Response::getInstance()->debugException($e);
    Scalr_UI_Response::getInstance()->failure($e instanceof \Scalr\Exception\MysqlConnectionException ? 'Database connection issue' : 'Database error');
    Scalr_UI_Response::getInstance()->sendResponse();
};
try {
    $startTime = microtime(true);
    require __DIR__ . '/src/prepend.inc.php';
    $prependTime = microtime(true);
    // public controller for link like /public/*; don't check CSRF
    $publicController = !strncmp('public', $path, strlen('public'));
    $session = Scalr_Session::getInstance();
    $time1 = microtime(true);
    try {
        $request = Scalr_UI_Request::initializeInstance(Scalr_UI_Request::REQUEST_TYPE_UI, getallheaders(), $_SERVER, $_REQUEST, $_FILES, $session->getUserId(), null);
    } catch (Exception $e) {
        if ($path == 'guest/logout') {
            // hack
            Scalr_Session::destroy();
            Scalr_UI_Response::getInstance()->setRedirect('/');
            Scalr_UI_Response::getInstance()->sendResponse();
            exit;
        }
        $message = $e->getMessage();
        if ($e->getCode() != 1) {
            $message = htmlspecialchars($message) . ' <a href="/guest/logout">Click here to login as another user</a>';
            Scalr_UI_Response::getInstance()->debugException($e);
            Scalr_UI_Response::getInstance()->failure($message, true);
            throw new Exception();
        } else {
コード例 #25
0
ファイル: ui.php プロジェクト: rickb838/scalr
    if ($error && ($error['type'] == E_ERROR || $error['type'] == E_PARSE || $error['type'] == E_COMPILE_ERROR)) {
        if (!headers_sent()) {
            header("HTTP/1.0 500");
        }
    }
});
$path = trim(str_replace("?{$_SERVER['QUERY_STRING']}", "", $_SERVER['REQUEST_URI']), '/');
try {
    $startTime = microtime(true);
    require __DIR__ . '/src/prepend.inc.php';
    $prependTime = microtime(true);
    // public controller for link like /public/*; don't check CSRF
    $publicController = !strncmp('public', $path, strlen('public'));
    $session = Scalr_Session::getInstance();
    try {
        $request = Scalr_UI_Request::initializeInstance(Scalr_UI_Request::REQUEST_TYPE_UI, apache_request_headers(), $_SERVER, $_REQUEST, $_FILES, $session->getUserId(), $session->getEnvironmentId());
    } catch (Exception $e) {
        if ($path == 'guest/logout') {
            // hack
            Scalr_Session::destroy();
            Scalr_UI_Response::getInstance()->setRedirect('/');
            Scalr_UI_Response::getInstance()->sendResponse();
            exit;
        }
        $message = $e->getMessage();
        if ($e->getCode() != 1) {
            $message = htmlspecialchars($message) . ' <a href="/guest/logout">Click here to login as another user</a>';
            Scalr_UI_Response::getInstance()->failure($message, true);
            throw new Exception();
        } else {
            throw new Exception($message);