Exemplo n.º 1
0
 protected function run1($stage)
 {
     $stmt = '';
     if (!$this->hasTableColumn('os', 'created')) {
         $bCreated = true;
         $this->console->out("Adding scalr.os.created column...");
         $stmt .= ", ADD COLUMN `created` DATETIME NOT NULL COMMENT 'Created at timestamp' AFTER `is_system`";
     }
     if (!$this->hasTableIndex('os', 'idx_created')) {
         $this->console->out("Adding idx_created index for scalr.os.created column...");
         $stmt .= ", ADD INDEX `idx_created` (`created` ASC)";
     }
     if (!empty($stmt)) {
         $this->db->Execute("ALTER TABLE `os` " . ltrim($stmt, ','));
     }
     if (!empty($bCreated)) {
         $date = new \DateTime();
         $date->modify('-1 hour');
         $list = Os::find([['$or' => [['created' => null], ['created' => new \DateTime('0000-00-00 00:00:00')]]]]);
         foreach ($list as $os) {
             /* @var $os Os */
             $os->created = $date;
             $os->save();
             $date->modify('+1 second');
         }
     }
 }
Exemplo n.º 2
0
 public function xCheckCommunicationAction()
 {
     $dbServer = DBServer::LoadByID($this->getParam('serverId'));
     $this->user->getPermissions()->validate($dbServer);
     if ($dbServer->status != SERVER_STATUS::IMPORTING) {
         throw new Exception('Server is not in importing state');
     }
     $inboundConnection = false;
     $outboundConnection = false;
     $row = $this->db->GetRow("SELECT * FROM messages WHERE server_id = ? AND type = ? LIMIT 1", array($dbServer->serverId, "in"));
     if ($row) {
         $inboundConnection = true;
         $outboundConnection = (bool) $dbServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_OUT_CONNECTION);
         if ($outboundConnection) {
             $behaviors = $dbServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR);
         } else {
             $connectionError = $dbServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_OUT_CONNECTION_ERROR);
         }
         $bundleTaskId = $this->db->GetOne("SELECT id FROM bundle_tasks WHERE server_id = ? ORDER BY dtadded DESC LIMIT 1", array($dbServer->serverId));
         if ($bundleTaskId) {
             $bundleTask = BundleTask::LoadById($bundleTaskId);
             $osDetails = $bundleTask->getOsDetails();
             $criteria = [['family' => $osDetails->family], ['generation' => $osDetails->generation], ['status' => Os::STATUS_ACTIVE]];
             $os = Os::find($criteria);
         }
     }
     $this->response->data(array('inbound' => $inboundConnection, 'outbound' => $outboundConnection, 'connectionError' => $connectionError, 'bundleTaskId' => $bundleTaskId, 'behaviors' => $behaviors ? explode(',', $behaviors) : null, 'os' => isset($os) ? $os->getArrayCopy() : [], 'serverOs' => $osDetails ? $osDetails->name : ''));
 }
Exemplo n.º 3
0
Arquivo: Os.php Projeto: scalr/scalr
 private function getList()
 {
     $list = [];
     foreach (Os::find() as $entity) {
         $data = get_object_vars($entity);
         $data['used'] = $entity->getUsed();
         $list[] = $data;
     }
     return $list;
 }
Exemplo n.º 4
0
 /**
  * @param string $query
  * @param string $platform
  * @param string $cloudLocation
  * @param string $scope
  * @param string $osFamily
  * @param string $osId
  * @param string $id
  * @param string $hash
  * @param JsonData $sort
  * @param int $start
  * @param int $limit
  * @param JsonData $hideLocation
  * @param bool $hideNotActive
  * @throws Exception
  */
 public function xListAction($query = null, $platform = null, $cloudLocation = null, $scope = null, $osFamily = null, $osId = null, $id = null, $hash = null, JsonData $sort, $start = 0, $limit = 20, JsonData $hideLocation, $hideNotActive = false)
 {
     $this->restrictAccess('IMAGES');
     $osIds = $criteria = [];
     $accountId = $this->user->getAccountId() ?: NULL;
     $envId = $this->getEnvironmentId(true);
     if ($this->request->getScope() == ScopeInterface::SCOPE_SCALR) {
         $criteria[] = ['accountId' => NULL];
     } else {
         if ($this->request->getScope() == ScopeInterface::SCOPE_ACCOUNT) {
             $criteria[] = ['$or' => [['accountId' => $accountId], ['accountId' => NULL]]];
             $criteria[] = ['envId' => NULL];
         } else {
             $enabledPlatforms = $this->getEnvironment()->getEnabledPlatforms();
             $criteria[] = ['$or' => [['$and' => [['accountId' => NULL], ['platform' => empty($enabledPlatforms) ? NULL : ['$in' => $enabledPlatforms]]]], ['$and' => [['accountId' => $accountId], ['envId' => NULL]]], ['envId' => $envId]]];
         }
     }
     if ($hash) {
         $criteria[] = ['hash' => $hash];
     } else {
         if ($query) {
             $querySql = '%' . $query . '%';
             $criteria[] = ['name' => ['$like' => $querySql]];
         }
         if ($platform) {
             $criteria[] = ['platform' => $platform];
         }
         if ($cloudLocation) {
             $criteria[] = ['cloudLocation' => $cloudLocation];
         }
         if ($scope == ScopeInterface::SCOPE_SCALR) {
             $criteria[] = ['accountId' => NULL];
         } else {
             if ($scope == ScopeInterface::SCOPE_ACCOUNT) {
                 $criteria[] = ['accountId' => $accountId];
                 $criteria[] = ['envId' => NULL];
             } else {
                 if ($scope == ScopeInterface::SCOPE_ENVIRONMENT) {
                     $criteria[] = ['envId' => $envId];
                 }
             }
         }
         if ($osFamily) {
             $osIds = Os::findIdsBy($osFamily);
         }
         if ($osId) {
             $os = Os::find([['id' => $osId]]);
             $osIds = [];
             foreach ($os as $i) {
                 /* @var $i Os */
                 array_push($osIds, $i->id);
             }
         }
         if (!empty($osIds)) {
             $criteria[] = ['osId' => ['$in' => $osIds]];
         }
         if ($id) {
             $criteria[] = ['id' => ['$like' => $id . '%']];
         }
         if ($hideLocation) {
             foreach ($hideLocation as $platform => $locations) {
                 foreach ($locations as $loc) {
                     if ($loc) {
                         $criteria[] = ['$or' => [['platform' => ['$ne' => $platform]], ['cloudLocation' => ['$ne' => $loc]]]];
                     } else {
                         $criteria[] = ['platform' => ['$ne' => $platform]];
                     }
                 }
             }
         }
         if ($hideNotActive) {
             $criteria[] = ['status' => Image::STATUS_ACTIVE];
         }
     }
     $image = new Image();
     $os = new Os();
     $order = \Scalr\UI\Utils::convertOrder($sort, ['dtAdded' => false], ['id', 'platform', 'cloudLocation', 'name', 'osId', 'dtAdded', 'architecture', 'createdByEmail', 'source', 'type']);
     if (!empty($order)) {
         $sOrder = '';
         foreach ($order as $k => $v) {
             if ($k == 'osId') {
                 $sOrder .= ', IF(os.family IS NOT NULL, os.family, images.os_id)' . ($v ? '' : ' DESC') . ", CAST(os.version AS DECIMAL(10,2))" . ($v ? '' : ' DESC');
             } else {
                 $field = $image->getIterator()->getField($k);
                 if (!$field) {
                     throw new InvalidArgumentException(sprintf("Property %s does not exist in %s", $k, get_class($image)));
                 }
                 $sOrder .= ', ' . $field->getColumnName() . ($v ? '' : ' DESC');
             }
         }
         $sOrder = $sOrder != '' ? 'ORDER BY ' . substr($sOrder, 2) : '';
     }
     $result = $this->db->Execute("\n            SELECT " . (isset($limit) ? 'SQL_CALC_FOUND_ROWS ' : '') . $image->fields('images') . "\n            FROM " . $image->table('images') . "\n            LEFT JOIN " . $os->table('os') . " ON {$os->columnId} = {$image->columnOsId}\n            WHERE " . $image->_buildQuery($criteria, 'AND', 'images')['where'] . "\n            " . (!empty($sOrder) ? $sOrder : "") . "\n            " . (isset($limit) ? "LIMIT " . ($start ? intval($start) . ',' : '') . intval($limit) : "") . "\n        ");
     if (isset($limit)) {
         $totalNumber = $this->db->getOne('SELECT FOUND_ROWS()');
     } else {
         $totalNumber = $result->RowCount();
     }
     $data = [];
     while ($rec = $result->FetchRow()) {
         $image = new Image();
         $image->load($rec);
         $s = get_object_vars($image);
         $dtAdded = $image->getDtAdded();
         $s['dtAdded'] = $dtAdded ? Scalr_Util_DateTime::convertTz($dtAdded) : '';
         $s['dtLastUsed'] = $image->dtLastUsed ? Scalr_Util_DateTime::convertTz($image->dtLastUsed) : '';
         $s['used'] = $image->getUsed($accountId, $envId);
         $s['software'] = $image->getSoftwareAsString();
         $s['osFamily'] = $image->getOs()->family;
         $s['osGeneration'] = $image->getOs()->generation;
         $s['osVersion'] = $image->getOs()->version;
         $s['os'] = $image->getOs()->name;
         $s['scope'] = $image->getScope();
         $data[] = $s;
     }
     $this->response->data(['total' => $totalNumber, 'data' => $data]);
 }
Exemplo n.º 5
0
 /**
  * @param  int $uiStorageTime optional
  * @return array
  */
 public function getContext($uiStorageTime = 0)
 {
     $data = array();
     if ($this->user) {
         $data['user'] = array('userId' => $this->user->getId(), 'clientId' => $this->user->getAccountId(), 'userName' => $this->user->getEmail(), 'gravatarHash' => $this->user->getGravatarHash(), 'envId' => $this->getEnvironment() ? $this->getEnvironmentId() : 0, 'envName' => $this->getEnvironment() ? $this->getEnvironment()->name : '', 'envVars' => '', 'type' => $this->user->getType(), 'settings' => [Scalr_Account_User::SETTING_UI_TIMEZONE => $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE), UserSetting::NAME_UI_ANNOUNCEMENT_TIME => $this->getUser()->getSetting(UserSetting::NAME_UI_ANNOUNCEMENT_TIME)]);
         if ($this->getEnvironment()) {
             $data['user']['envVars'] = $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_UI_VARS);
         } else {
             if ($this->user->getAccountId()) {
                 $data['user']['envVars'] = $this->user->getAccount()->getSetting(Scalr_Account::SETTING_UI_VARS);
             }
         }
         if ($uiStorageTime > 0 && $uiStorageTime < $this->user->getSetting(Scalr_Account_User::SETTING_UI_STORAGE_TIME) && !Scalr_Session::getInstance()->isVirtual()) {
             $data['user']['uiStorage'] = $this->user->getVar(Scalr_Account_User::VAR_UI_STORAGE);
         }
         $envVars = json_decode($data['user']['envVars'], true);
         $betaMode = $envVars && $envVars['beta'] == 1;
         if (!$this->user->isAdmin()) {
             $data['flags'] = [];
             if ($this->user->getAccountId() != 0) {
                 $data['user']['userIsTrial'] = $this->user->getAccount()->getSetting(Scalr_Account::SETTING_IS_TRIAL) == '1' ? true : false;
             }
             $data['flags']['billingExists'] = \Scalr::config('scalr.billing.enabled');
             $data['flags']['showDeprecatedFeatures'] = \Scalr::config('scalr.ui.show_deprecated_features');
             $data['acl'] = $this->request->getAclRoles()->getAllowedArray(true);
             if (!$this->user->isAccountOwner()) {
                 $data['user']['accountOwnerName'] = $this->user->getAccount()->getOwner()->getEmail();
             }
             $data['environments'] = $this->user->getEnvironments();
             if ($this->user->isAccountOwner()) {
                 if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
                     $data['flags']['needEnvConfig'] = true;
                 }
             }
             if ($this->request->getScope() == 'environment') {
                 $sql = "SELECT id, name FROM farms f WHERE env_id = ? AND " . $this->request->getFarmSqlQuery();
                 $args = [$this->getEnvironmentId()];
                 $sql .= " ORDER BY name";
                 $data['farms'] = $this->db->getAll($sql, $args);
                 if ($this->getEnvironment() && $this->user->isTeamOwner()) {
                     $data['user']['isTeamOwner'] = true;
                 }
             }
         }
         $data['flags']['wikiUrl'] = \Scalr::config('scalr.ui.wiki_url');
         $data['flags']['supportUrl'] = \Scalr::config('scalr.ui.support_url');
         if ($data['flags']['supportUrl'] == '/core/support') {
             if ($this->user->isAdmin()) {
                 unset($data['flags']['supportUrl']);
             } else {
                 $data['flags']['supportUrl'] .= '?X-Requested-Token=' . Scalr_Session::getInstance()->getToken();
             }
         }
         //OS
         $data['os'] = [];
         foreach (Os::find() as $os) {
             /* @var $os Os */
             $data['os'][] = ['id' => $os->id, 'family' => $os->family, 'name' => $os->name, 'generation' => $os->generation, 'version' => $os->version, 'status' => $os->status];
         }
         $data['defaults'] = (new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(true), ScopeInterface::SCOPE_ENVIRONMENT))->getUiDefaults();
         $data['platforms'] = [];
         $allowedClouds = (array) \Scalr::config('scalr.allowed_clouds');
         if ($this->user->getAccountId() == 263) {
             array_push($allowedClouds, SERVER_PLATFORMS::VERIZON);
         }
         $platforms = SERVER_PLATFORMS::getList();
         if (!($this->request->getHeaderVar('Interface-Beta') || $betaMode)) {
             $platforms = array_intersect_key($platforms, array_flip($allowedClouds));
         }
         $environment = $this->getEnvironment();
         if (!empty($environment)) {
             $cloudsCredentials = $environment->cloudCredentialsList(array_keys($platforms));
         }
         foreach ($platforms as $platform => $platformName) {
             if (!in_array($platform, $allowedClouds) && !$this->request->getHeaderVar('Interface-Beta') && !$betaMode) {
                 continue;
             }
             $data['platforms'][$platform] = array('public' => PlatformFactory::isPublic($platform), 'enabled' => $this->user->isAdmin() || $this->request->getScope() != 'environment' ? true : isset($cloudsCredentials[$platform]) && $cloudsCredentials[$platform]->isEnabled(), 'name' => $platformName);
             if (!($this->user->isAdmin() || $this->request->getScope() != 'environment')) {
                 if ($platform == SERVER_PLATFORMS::EC2 && $this->environment->status == Scalr_Environment::STATUS_INACTIVE && $this->environment->getPlatformConfigValue('system.auto-disable-reason')) {
                     $data['platforms'][$platform]['config'] = array('autoDisabled' => true);
                 }
                 if (PlatformFactory::isOpenstack($platform) && $data['platforms'][$platform]['enabled']) {
                     $ccProps = $cloudsCredentials[$platform]->properties;
                     $data['platforms'][$platform]['config'] = [CloudCredentialsProperty::OPENSTACK_EXT_SECURITYGROUPS_ENABLED => $ccProps[CloudCredentialsProperty::OPENSTACK_EXT_SECURITYGROUPS_ENABLED], CloudCredentialsProperty::OPENSTACK_EXT_LBAAS_ENABLED => $ccProps[CloudCredentialsProperty::OPENSTACK_EXT_LBAAS_ENABLED], CloudCredentialsProperty::OPENSTACK_EXT_FLOATING_IPS_ENABLED => $ccProps[CloudCredentialsProperty::OPENSTACK_EXT_FLOATING_IPS_ENABLED], CloudCredentialsProperty::OPENSTACK_EXT_CINDER_ENABLED => $ccProps[CloudCredentialsProperty::OPENSTACK_EXT_CINDER_ENABLED], CloudCredentialsProperty::OPENSTACK_EXT_SWIFT_ENABLED => $ccProps[CloudCredentialsProperty::OPENSTACK_EXT_SWIFT_ENABLED]];
                 }
             }
         }
         $data['flags']['uiStorageTime'] = $this->user->getSetting(Scalr_Account_User::SETTING_UI_STORAGE_TIME);
         $data['flags']['uiStorage'] = $this->user->getVar(Scalr_Account_User::VAR_UI_STORAGE);
         $data['flags']['allowManageAnalytics'] = $this->user->getAccountId() && Scalr::isAllowedAnalyticsOnHostedScalrAccount($this->user->getAccountId());
         $data['flags']['hostedScalr'] = (bool) Scalr::isHostedScalr();
         $data['flags']['analyticsEnabled'] = $this->getContainer()->analytics->enabled;
         $data['flags']['apiEnabled'] = (bool) \Scalr::config('scalr.system.api.enabled');
         $data['flags']['dnsGlobalEnabled'] = (bool) \Scalr::config('scalr.dns.global.enabled');
         $data['flags']['allowBetaEbsTypes'] = SCALR_ID == 'gdp-aws-east';
         $data['scope'] = $this->request->getScope();
         if ($this->request->getScope() == 'environment') {
             $governance = new Scalr_Governance($this->getEnvironmentId());
             $data['governance'] = $governance->getValues(true);
         }
     }
     if ($this->user) {
         $data['tags'] = Tag::getAll($this->user->getAccountId());
     }
     $data['flags']['authMode'] = $this->getContainer()->config->get('scalr.auth_mode');
     $data['flags']['recaptchaPublicKey'] = $this->getContainer()->config->get('scalr.ui.recaptcha.public_key');
     $data['flags']['specialToken'] = Scalr_Session::getInstance()->getToken();
     $data['flags']['loginWarning'] = $this->getContainer()->config->get('scalr.ui.login_warning');
     return $data;
 }
Exemplo n.º 6
0
Arquivo: Os.php Projeto: mheydt/scalr
 /**
  * Fetches identifiers of the OSes which satisfy specified criteria
  *
  * @param   string $family      The family
  * @param   string $generation  optional The generation
  * @param   string $version     optional The version
  * @return  array  Returns array of the identifiers of the OSes which satisfy specified criteria
  */
 public static function findIdsBy($family, $generation = null, $version = null)
 {
     $criteria = [['family' => $family]];
     if ($generation) {
         $criteria[] = ['generation' => $generation];
     }
     if ($version) {
         $criteria[] = ['version' => $version];
     }
     $os = Os::find($criteria);
     $osIds = [];
     foreach ($os as $i) {
         /* @var $i Os */
         array_push($osIds, $i->id);
     }
     return $osIds;
 }
Exemplo n.º 7
0
 public function getContext($uiStorageTime = 0)
 {
     $data = array();
     if ($this->user) {
         $data['user'] = array('userId' => $this->user->getId(), 'clientId' => $this->user->getAccountId(), 'userName' => $this->user->getEmail(), 'gravatarHash' => $this->user->getGravatarHash(), 'envId' => $this->getEnvironment() ? $this->getEnvironmentId() : 0, 'envName' => $this->getEnvironment() ? $this->getEnvironment()->name : '', 'envVars' => $this->getEnvironment() ? $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_UI_VARS) : '', 'type' => $this->user->getType(), 'settings' => [Scalr_Account_User::VAR_SSH_CONSOLE_LAUNCHER => $this->user->getVar(Scalr_Account_User::VAR_SSH_CONSOLE_LAUNCHER)]);
         if ($uiStorageTime > 0 && $uiStorageTime < $this->user->getSetting(Scalr_Account_User::SETTING_UI_STORAGE_TIME) && !Scalr_Session::getInstance()->isVirtual()) {
             $data['user']['uiStorage'] = $this->user->getVar(Scalr_Account_User::VAR_UI_STORAGE);
         }
         $envVars = json_decode($data['user']['envVars'], true);
         $betaMode = $envVars && $envVars['beta'] == 1;
         if (!$this->user->isAdmin()) {
             $data['flags'] = [];
             if ($this->user->getAccountId() != 0) {
                 $data['user']['userIsTrial'] = $this->user->getAccount()->getSetting(Scalr_Account::SETTING_IS_TRIAL) == '1' ? true : false;
             }
             $data['flags']['billingExists'] = \Scalr::config('scalr.billing.enabled');
             $data['flags']['showDeprecatedFeatures'] = \Scalr::config('scalr.ui.show_deprecated_features');
             $data['flags']['wikiUrl'] = \Scalr::config('scalr.ui.wiki_url');
             $data['flags']['supportUrl'] = \Scalr::config('scalr.ui.support_url');
             if ($data['flags']['supportUrl'] == '/core/support') {
                 $data['flags']['supportUrl'] .= '?X-Requested-Token=' . Scalr_Session::getInstance()->getToken();
             }
             $data['acl'] = $this->request->getAclRoles()->getAllowedArray(true);
             if (!$this->user->isAccountOwner()) {
                 $data['user']['accountOwnerName'] = $this->user->getAccount()->getOwner()->getEmail();
             }
             $data['environments'] = $this->user->getEnvironments();
             if ($this->user->isAccountOwner()) {
                 if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) {
                     $data['flags']['needEnvConfig'] = true;
                 }
             }
             if ($this->request->getScope() == 'environment') {
                 $sql = 'SELECT id, name FROM farms WHERE env_id = ?';
                 $args = [$this->getEnvironmentId()];
                 list($sql, $args) = $this->request->prepareFarmSqlQuery($sql, $args);
                 $sql .= ' ORDER BY name';
                 $data['farms'] = $this->db->getAll($sql, $args);
                 if ($this->getEnvironment() && $this->user->isTeamOwner()) {
                     $data['user']['isTeamOwner'] = true;
                 }
             }
         }
         //OS
         $data['os'] = [];
         foreach (Os::find([['status' => Os::STATUS_ACTIVE]]) as $os) {
             /* @var $os Os */
             $data['os'][] = ['id' => $os->id, 'family' => $os->family, 'name' => $os->name, 'generation' => $os->generation, 'version' => $os->version];
         }
         $data['platforms'] = [];
         $allowedClouds = (array) \Scalr::config('scalr.allowed_clouds');
         foreach (SERVER_PLATFORMS::getList() as $platform => $platformName) {
             if ($this->user->getAccountId() == 263) {
                 array_push($allowedClouds, SERVER_PLATFORMS::VERIZON);
             }
             if (!in_array($platform, $allowedClouds) && !$this->request->getHeaderVar('Interface-Beta')) {
                 continue;
             }
             $data['platforms'][$platform] = array('public' => PlatformFactory::isPublic($platform), 'enabled' => $this->user->isAdmin() || $this->request->getScope() != 'environment' ? true : !!$this->environment->isPlatformEnabled($platform), 'name' => $platformName);
             if (!($this->user->isAdmin() || $this->request->getScope() != 'environment')) {
                 if ($platform == SERVER_PLATFORMS::EC2 && $this->environment->status == Scalr_Environment::STATUS_INACTIVE && $this->environment->getPlatformConfigValue('system.auto-disable-reason')) {
                     $data['platforms'][$platform]['config'] = array('autoDisabled' => true);
                 }
                 if (PlatformFactory::isOpenstack($platform) && $data['platforms'][$platform]['enabled']) {
                     $data['platforms'][$platform]['config'] = array(OpenstackPlatformModule::EXT_SECURITYGROUPS_ENABLED => PlatformFactory::NewPlatform($platform)->getConfigVariable(OpenstackPlatformModule::EXT_SECURITYGROUPS_ENABLED, $this->getEnvironment(), false), OpenstackPlatformModule::EXT_LBAAS_ENABLED => PlatformFactory::NewPlatform($platform)->getConfigVariable(OpenstackPlatformModule::EXT_LBAAS_ENABLED, $this->getEnvironment(), false), OpenstackPlatformModule::EXT_FLOATING_IPS_ENABLED => PlatformFactory::NewPlatform($platform)->getConfigVariable(OpenstackPlatformModule::EXT_FLOATING_IPS_ENABLED, $this->getEnvironment(), false), OpenstackPlatformModule::EXT_CINDER_ENABLED => PlatformFactory::NewPlatform($platform)->getConfigVariable(OpenstackPlatformModule::EXT_CINDER_ENABLED, $this->getEnvironment(), false), OpenstackPlatformModule::EXT_SWIFT_ENABLED => PlatformFactory::NewPlatform($platform)->getConfigVariable(OpenstackPlatformModule::EXT_SWIFT_ENABLED, $this->getEnvironment(), false));
                 }
             }
         }
         $data['flags']['uiStorageTime'] = $this->user->getSetting(Scalr_Account_User::SETTING_UI_STORAGE_TIME);
         $data['flags']['uiStorage'] = $this->user->getVar(Scalr_Account_User::VAR_UI_STORAGE);
         $data['flags']['allowManageAnalytics'] = (bool) Scalr::isAllowedAnalyticsOnHostedScalrAccount($this->environment->clientId);
         $data['scope'] = $this->request->getScope();
         if ($this->request->getScope() == 'environment') {
             $governance = new Scalr_Governance($this->getEnvironmentId());
             $data['governance'] = $governance->getValues(true);
         }
     }
     if ($this->user) {
         $data['tags'] = Tag::getAll($this->user->getAccountId());
     }
     $data['flags']['authMode'] = $this->getContainer()->config->get('scalr.auth_mode');
     $data['flags']['recaptchaPublicKey'] = $this->getContainer()->config->get('scalr.ui.recaptcha.public_key');
     $data['flags']['specialToken'] = Scalr_Session::getInstance()->getToken();
     $data['flags']['hostedScalr'] = (bool) Scalr::isHostedScalr();
     $data['flags']['analyticsEnabled'] = $this->getContainer()->analytics->enabled;
     $data['flags']['apiEnabled'] = (bool) \Scalr::config('scalr.system.api.enabled');
     return $data;
 }
Exemplo n.º 8
0
 /**
  * @param string $query
  * @param string $platform
  * @param string $cloudLocation
  * @param string $scope
  * @param string $osFamily
  * @param string $osId
  * @param string $id
  * @param string $hash
  * @param JsonData $sort
  * @param int $start
  * @param int $limit
  * @param JsonData $os
  * @param JsonData $hideLocation
  * @param bool $hideNotActive
  * @throws Exception
  */
 public function xListAction($query = null, $platform = null, $cloudLocation = null, $scope = null, $osFamily = null, $osId = null, $id = null, $hash = null, JsonData $sort, $start = 0, $limit = 20, JsonData $hideLocation, $hideNotActive = false)
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_IMAGES);
     $criteria = [];
     if ($hash) {
         $criteria[] = ['hash' => $hash];
         if ($this->getEnvironment()) {
             $enabledPlatforms = $this->getEnvironment()->getEnabledPlatforms();
             $criteria[] = ['$or' => [['envId' => $this->getEnvironmentId(true)], ['$and' => [['envId' => NULL], ['platform' => empty($enabledPlatforms) ? NULL : ['$in' => $enabledPlatforms]]]]]];
         } else {
             $criteria[] = ['envId' => NULL];
         }
     } else {
         if ($query) {
             $querySql = '%' . $query . '%';
             $criteria[] = ['name' => ['$like' => $querySql]];
         }
         if ($platform) {
             $criteria[] = ['platform' => $platform];
         }
         if ($cloudLocation) {
             $criteria[] = ['cloudLocation' => $cloudLocation];
         }
         if ($this->getEnvironment()) {
             $enabledPlatforms = $this->getEnvironment()->getEnabledPlatforms();
             if ($scope) {
                 if ($scope == 'env') {
                     $criteria[] = ['envId' => $this->getEnvironmentId(true)];
                 } else {
                     // hide shared images, which platforms are not configured
                     if (empty($enabledPlatforms)) {
                         $criteria[] = ['platform' => NULL];
                     } else {
                         $criteria[] = ['envId' => NULL];
                         $criteria[] = ['platform' => ['$in' => $enabledPlatforms]];
                     }
                 }
             } else {
                 $criteria[] = ['$or' => [['envId' => $this->getEnvironmentId(true)], ['$and' => [['envId' => NULL], ['platform' => empty($enabledPlatforms) ? NULL : ['$in' => $enabledPlatforms]]]]]];
             }
         } else {
             $criteria[] = ['envId' => NULL];
         }
         if ($osFamily) {
             $osIds = Os::findIdsBy($osFamily);
         }
         if ($osId) {
             $os = Os::find([['id' => $osId]]);
             $osIds = [];
             foreach ($os as $i) {
                 /* @var $i Os */
                 array_push($osIds, $i->id);
             }
         }
         if (count($osIds) > 0) {
             $criteria[] = ['osId' => ['$in' => $osIds]];
         }
         if ($id) {
             $criteria[] = ['id' => ['$like' => $id . '%']];
         }
         if ($hideLocation) {
             foreach ($hideLocation as $platform => $locations) {
                 foreach ($locations as $loc) {
                     if ($loc) {
                         $criteria[] = ['$or' => [['platform' => ['$ne' => $platform]], ['cloudLocation' => ['$ne' => $loc]]]];
                     } else {
                         $criteria[] = ['platform' => ['$ne' => $platform]];
                     }
                 }
             }
         }
         if ($hideNotActive) {
             $criteria[] = ['status' => Image::STATUS_ACTIVE];
         }
     }
     $result = Image::find($criteria, \Scalr\UI\Utils::convertOrder($sort, ['id' => 'ASC'], ['id', 'platform', 'cloudLocation', 'name', 'osId', 'dtAdded', 'architecture', 'createdByEmail', 'source']), $limit, $start, true);
     $data = [];
     foreach ($result as $image) {
         /* @var $image Image */
         $s = get_object_vars($image);
         $dtAdded = $image->getDtAdded();
         $s['dtAdded'] = $dtAdded ? Scalr_Util_DateTime::convertTz($dtAdded) : '';
         $s['dtLastUsed'] = $image->dtLastUsed ? Scalr_Util_DateTime::convertTz($image->dtLastUsed) : '';
         $s['used'] = $image->getUsed($this->getEnvironmentId(true));
         $s['software'] = $image->getSoftwareAsString();
         $s['osFamily'] = $image->getOs()->family;
         $s['osGeneration'] = $image->getOs()->generation;
         $s['osVersion'] = $image->getOs()->version;
         $s['os'] = $image->getOs()->name;
         $data[] = $s;
     }
     $this->response->data(['total' => $result->totalNumber, 'data' => $data, 'debug' => $criteria]);
 }