/** * @param array $tags * @param int $accountId * @param string $resource * @param int $resourceId */ public static function setTags($tags, $accountId, $resource, $resourceId) { $tags = array_unique($tags); $tagId = []; foreach ($tags as $tag) { $tag = trim($tag); if ($tag) { $t = self::findOne([['name' => $tag], ['accountId' => $accountId]]); if (!$t) { $t = new Tag(); $t->name = $tag; $t->accountId = $accountId; $t->save(); } $tagId[] = $t->id; } } foreach (TagLink::find([['resource' => $resource], ['resourceId' => $resourceId]]) as $l) { /* @var $l TagLink */ if (!in_array($l->tagId, $tagId)) { $l->delete(); } else { unset($tagId[array_search($l->tagId, $tagId)]); } } foreach ($tagId as $id) { $l = new TagLink(); $l->tagId = $id; $l->resource = $resource; $l->resourceId = $resourceId; $l->save(); } self::clearTags(); }
/** * Deletes this script * * @throws Scalr_Exception_Core * @throws Exception * @throws ModelException */ public function delete() { // Check script usage $usage = []; $farmRolesCount = $this->db()->GetOne("SELECT COUNT(DISTINCT farm_roleid) FROM farm_role_scripts WHERE scriptid=?", array($this->id)); if ($farmRolesCount > 0) { $message = []; foreach ($this->db()->GetCol("SELECT DISTINCT farm_roleid FROM farm_role_scripts WHERE scriptid = ? LIMIT 3", array($this->id)) as $id) { $dbFarmRole = \DBFarmRole::LoadByID($id); $message[] = $dbFarmRole->GetFarmObject()->Name . ' (' . $dbFarmRole->Alias . ')'; } $usage[] = sprintf("%d farm roles: %s%s", $farmRolesCount, join(', ', $message), $farmRolesCount > 3 ? ' and others' : ''); } $rolesCount = $this->db()->GetOne("SELECT COUNT(DISTINCT role_id) FROM role_scripts WHERE script_id=?", array($this->id)); if ($rolesCount > 0) { $message = []; foreach ($this->db()->GetCol("SELECT DISTINCT role_id FROM role_scripts WHERE script_id = ? LIMIT 3", array($this->id)) as $id) { $dbRole = \DBRole::LoadByID($id); $message[] = $dbRole->name; } $usage[] = sprintf("%d roles: %s%s", $rolesCount, join(', ', $message), $rolesCount > 3 ? ' and others' : ''); } $accountCount = $this->db()->GetOne("SELECT COUNT(*) FROM account_scripts WHERE script_id=?", array($this->id)); if ($accountCount > 0) { $usage[] = sprintf("%d orchestration rule(s) on account level", $accountCount); } $taskCount = $this->db()->GetOne("SELECT COUNT(*) FROM scheduler WHERE script_id = ?", array($this->id)); if ($taskCount > 0) { $usage[] = sprintf("%d scheduler task(s)", $taskCount); } if (count($usage)) { throw new Scalr_Exception_Core(sprintf('Script "%s" being used by %s, and can\'t be deleted', $this->name, join(', ', $usage))); } Tag::deleteTags(Tag::RESOURCE_SCRIPT, $this->id); parent::delete(); }
/** * @param int $id * @param string $name * @param string $description * @param int $isSync * @param bool $allowScriptParameters * @param int $envId optional * @param int $timeout optional * @param int $version * @param RawData $content * @param string $tags * @param string $uploadType optional * @param string $uploadUrl optional * @param FileUploadData $uploadFile optional * @param bool $checkScriptParameters optional * @throws Scalr_UI_Exception_NotFound * @throws Scalr_Exception_InsufficientPermissions * @throws Exception */ public function xSaveAction($id, $name, $description, $isSync = 0, $allowScriptParameters = false, $envId = NULL, $timeout = NULL, $version, RawData $content, $tags, $uploadType = NULL, $uploadUrl = NULL, FileUploadData $uploadFile = NULL, $checkScriptParameters = false) { $this->request->restrictAccess('SCRIPTS', 'MANAGE'); $validator = new Validator(); $validator->validate($name, 'name', Validator::NOEMPTY); if ($uploadType && $uploadType == 'URL') { $validator->validate($uploadUrl, 'uploadUrl', Validator::URL); if (!$validator->isValid($this->response)) { return; } } if ($uploadType) { $content = false; if ($uploadType == 'URL') { $content = @file_get_contents($uploadUrl); $validator->validate($content, 'uploadUrl', Validator::NOEMPTY, [], 'Invalid source'); } else { if ($uploadType == 'File') { $content = $uploadFile; $validator->validate($content, 'uploadFile', Validator::NOEMPTY, [], 'Invalid source'); } else { $validator->addError('uploadType', 'Invalid source for script'); } } } $envId = $this->getEnvironmentId(true); $content = str_replace("\r\n", "\n", $content); $tagsResult = []; foreach (explode(',', $tags) as $t) { $t = trim($t); if ($t) { if (!preg_match('/^[a-zA-Z0-9-]{3,10}$/', $t)) { $validator->addError('tags', sprintf('Invalid name for tag: %s', $t)); } $tagsResult[] = $t; } } $tags = $tagsResult; $criteria = []; $criteria[] = ['name' => $name]; if ($id) { $criteria[] = ['id' => ['$ne' => $id]]; } switch ($this->request->getScope()) { case Script::SCOPE_ENVIRONMENT: $criteria[] = ['envId' => $envId]; $criteria[] = ['accountId' => $this->user->getAccountId()]; break; case Script::SCOPE_ACCOUNT: $criteria[] = ['envId' => null]; $criteria[] = ['accountId' => $this->user->getAccountId()]; break; case Script::SCOPE_SCALR: $criteria[] = ['envId' => null]; $criteria[] = ['accountId' => null]; break; } if (Script::findOne($criteria)) { $validator->addError('name', 'Script name must be unique within current scope'); } if (!$validator->isValid($this->response)) { return; } /* @var $script Script */ if ($id) { $script = Script::findPk($id); if (!$script) { throw new Scalr_UI_Exception_NotFound(); } $script->checkPermission($this->user, $envId); if (!$script->accountId && $this->user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) { throw new Scalr_Exception_InsufficientPermissions(); } if (!$script->envId && $this->request->getScope() == ScopeInterface::SCOPE_ENVIRONMENT) { throw new Scalr_Exception_InsufficientPermissions(); } } else { $script = new Script(); $script->accountId = $this->user->getAccountId() ?: NULL; $script->createdById = $this->user->getId(); $script->createdByEmail = $this->user->getEmail(); $script->envId = $envId; $version = 1; } //check variables in script content if (!$id && $checkScriptParameters && !$allowScriptParameters) { $scriptHasParameters = Script::hasVariables($content); if (!$scriptHasParameters) { /* @var $scriptVersion ScriptVersion */ foreach ($script->getVersions() as $scriptVersion) { if ($scriptVersion->version != $version) { $scriptHasParameters = Script::hasVariables($scriptVersion->content); if ($scriptHasParameters) { break; } } } } if ($scriptHasParameters) { $this->response->data(['showScriptParametersConfirmation' => true]); $this->response->failure(); return; } } $script->name = $name; $script->description = $description; $script->timeout = $timeout ? $timeout : NULL; $script->isSync = $isSync == 1 ? 1 : 0; $script->allowScriptParameters = $allowScriptParameters ? 1 : 0; $script->os = !strncmp($content, '#!cmd', strlen('#!cmd')) || !strncmp($content, '#!powershell', strlen('#!powershell')) ? Script::OS_WINDOWS : Script::OS_LINUX; $script->save(); $scriptVersion = NULL; if ($version) { $scriptVersion = $script->getVersion($version); } if (!$scriptVersion && $script->getLatestVersion()->content !== $content) { $scriptVersion = new ScriptVersion(); $scriptVersion->scriptId = $script->id; $scriptVersion->version = $script->getLatestVersion()->version + 1; } if ($scriptVersion) { $scriptVersion->changedById = $this->user->getId(); $scriptVersion->changedByEmail = $this->user->getEmail(); $scriptVersion->content = $content; $scriptVersion->save(); } if ($this->user->getAccountId()) { Tag::setTags($tags, $this->user->getAccountId(), Tag::RESOURCE_SCRIPT, $script->id); } $this->response->success('Script successfully saved'); $this->response->data(['script' => array_merge($this->getScript($script), $this->getScriptInfo($script))]); }
public function getContext() { $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()); $envVars = json_decode($data['user']['envVars'], true); $betaMode = $envVars && $envVars['beta'] == 1; if (!$this->user->isAdmin()) { $data['farms'] = $this->db->getAll('SELECT id, name FROM farms WHERE env_id = ? ORDER BY name', array($this->getEnvironmentId())); if ($this->user->getAccountId() != 0) { $data['flags'] = $this->user->getAccount()->getFeaturesList(); $data['user']['userIsTrial'] = $this->user->getAccount()->getSetting(Scalr_Account::SETTING_IS_TRIAL) == '1' ? true : false; } else { $data['flags'] = array(); } $data['flags']['billingExists'] = \Scalr::config('scalr.billing.enabled'); $data['flags']['featureUsersPermissions'] = $this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_USERS_PERMISSIONS); $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()) { if (!$this->user->getAccount()->getSetting(Scalr_Account::SETTING_DATE_ENV_CONFIGURED)) { if (count($this->environment->getEnabledPlatforms()) == 0) { $data['flags']['needEnvConfig'] = Scalr_Environment::init()->loadDefault($this->user->getAccountId())->id; } } } $data['environments'] = $this->user->getEnvironments(); if ($this->getEnvironment() && $this->user->isTeamOwner()) { $data['user']['isTeamOwner'] = true; } } $data['platforms'] = array(); $allowedClouds = (array) \Scalr::config('scalr.allowed_clouds'); foreach (SERVER_PLATFORMS::getList() as $platform => $platformName) { if (!in_array($platform, $allowedClouds) || $platform == SERVER_PLATFORMS::UCLOUD && !$this->request->getHeaderVar('Interface-Beta')) { continue; } $data['platforms'][$platform] = array('public' => PlatformFactory::isPublic($platform), 'enabled' => $this->user->isAdmin() ? true : !!$this->environment->isPlatformEnabled($platform), 'name' => $platformName); if (!$this->user->isAdmin()) { 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); } if ($this->user) { $data['tags'] = Tag::getAll($this->user->getAccountId()); } $data['flags']['authMode'] = $this->getContainer()->config->get('scalr.auth_mode'); $data['flags']['specialToken'] = Scalr_Session::getInstance()->getToken(); $data['flags']['hostedScalr'] = (bool) Scalr::isHostedScalr(); $data['flags']['analyticsEnabled'] = $this->getContainer()->analytics->enabled; return $data; }
public function getName() { $tag = Tag::findPk($this->tagId); /* @var $tag Tag */ return $tag ? $tag->name : '*Unknown tag*'; }
/** * @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; }
/** * @param int $scriptId * @throws Scalr_UI_Exception_NotFound * @throws Scalr_Exception_InsufficientPermissions */ public function editAction($scriptId) { $this->request->restrictAccess(Acl::RESOURCE_ADMINISTRATION_SCRIPTS, Acl::PERM_ADMINISTRATION_SCRIPTS_MANAGE); $vars = Scalr_Scripting_Manager::getScriptingBuiltinVariables(); /* @var Script $script */ $script = Script::findPk($scriptId); if (!$script) { throw new Scalr_UI_Exception_NotFound(); } $script->checkPermission($this->user, $this->getEnvironmentId(true)); if (!$script->accountId && $this->user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) { throw new Scalr_Exception_InsufficientPermissions(); } $version = $script->getLatestVersion(); $versionIds = array_map(function ($v) { return $v->version; }, $script->getVersions()->getArrayCopy()); $environments = $this->user->getEnvironments(); array_unshift($environments, array('id' => 0, 'name' => 'All environments')); $this->response->page('ui/scripts/create.js', array('script' => array('id' => $script->id, 'name' => $script->name, 'description' => $script->description, 'envId' => $script->envId ? $script->envId : 0, 'isSync' => !is_null($script->isSync) ? $script->isSync : 0, 'timeout' => $script->timeout, 'content' => $version->content, 'version' => $version->version, 'tags' => join(',', Tag::getTags(Tag::RESOURCE_SCRIPT, $script->id))), 'versions' => $versionIds, 'timeouts' => $this->getContainer()->config->get('scalr.script.timeout'), 'environments' => $environments, 'variables' => "%" . implode("%, %", array_keys($vars)) . "%"), array('codemirror/codemirror.js', 'ux-boxselect.js'), array('codemirror/codemirror.css')); }
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; }