protected function run2($stage) { $this->console->out("Populating new properties"); $platforms = $envs = []; foreach (array_keys(\SERVER_PLATFORMS::GetList()) as $platform) { $platforms[$platform] = PlatformFactory::NewPlatform($platform); } $result = $this->db->Execute("\n SELECT s.server_id, s.`platform`, s.`cloud_location`, s.env_id, s.`type`\n FROM servers AS s\n WHERE s.`status` NOT IN (?, ?) AND s.`type` IS NOT NULL\n ", [Server::STATUS_PENDING_TERMINATE, Server::STATUS_TERMINATED]); while ($row = $result->FetchRow()) { if (!empty($row["type"])) { if (!array_key_exists($row["env_id"], $envs)) { $envs[$row["env_id"]] = \Scalr_Environment::init()->loadById($row["env_id"]); } if ($this->isPlatformEnabled($envs[$row["env_id"]], $row["platform"])) { try { $instanceTypeEntity = $platforms[$row["platform"]]->getInstanceType($row["type"], $envs[$row["env_id"]], $row["cloud_location"]); /* @var $instanceTypeEntity CloudInstanceType */ if ($instanceTypeEntity && (int) $instanceTypeEntity->vcpus > 0) { $this->db->Execute("\n INSERT IGNORE INTO server_properties (`server_id`, `name`, `value`) VALUES (?, ?, ?)\n ", [$row["server_id"], Server::INFO_INSTANCE_VCPUS, $instanceTypeEntity->vcpus]); } } catch (\Exception $e) { $this->console->warning("Can't get access to %s, error: %s", $row["platform"], $e->getMessage()); } } } } }
/** * Data provider for testNewPlatform * * @return array */ public function providerNewPlatform() { $ret = []; foreach (\SERVER_PLATFORMS::GetList() as $platform => $name) { $ret[] = [$platform]; } return $ret; }
public function getEnabledPlatforms($addLocations = false) { $ePlatforms = $this->getEnvironment()->getEnabledPlatforms(); $lPlatforms = SERVER_PLATFORMS::GetList(); $platforms = array(); foreach ($ePlatforms as $platform) { $platforms[$platform] = $addLocations ? array('id' => $platform, 'name' => $lPlatforms[$platform], 'locations' => PlatformFactory::NewPlatform($platform)->getLocations()) : $lPlatforms[$platform]; } return $platforms; }
public function getEnabledPlatforms() { $enabled = array(); foreach (array_keys(SERVER_PLATFORMS::getList()) as $value) { if ($this->isPlatformEnabled($value)) { $enabled[] = $value; } } return $enabled; }
public function getEnabledPlatforms($addLocations = false, $includeGCELocations = true) { $ePlatforms = $this->user->isScalrAdmin() ? array_keys(SERVER_PLATFORMS::GetList()) : $this->getEnvironment()->getEnabledPlatforms(); $lPlatforms = SERVER_PLATFORMS::GetList(); $platforms = array(); foreach ($ePlatforms as $platform) { $platforms[$platform] = $addLocations ? array('id' => $platform, 'name' => $lPlatforms[$platform], 'locations' => $platform !== SERVER_PLATFORMS::GCE || $includeGCELocations ? PlatformFactory::NewPlatform($platform)->getLocations() : array()) : $lPlatforms[$platform]; } return $platforms; }
/** * @param jsonData $platforms * @throws Exception */ public function xGetLocationsAction(JsonData $platforms) { $allPlatforms = $this->user->isScalrAdmin() ? array_keys(SERVER_PLATFORMS::GetList()) : $this->getEnvironment()->getEnabledPlatforms(); $result = array(); foreach ($platforms as $platform) { if (in_array($platform, $allPlatforms)) { $result[$platform] = !in_array($platform, array(SERVER_PLATFORMS::GCE, SERVER_PLATFORMS::ECS)) ? PlatformFactory::NewPlatform($platform)->getLocations($this->environment) : array(); } } $this->response->data(array('locations' => $result)); }
/** * {@inheritdoc} * @see \Scalr\System\Zmq\Cron\TaskInterface::enqueue() */ public function enqueue() { $plt = []; $args = [date("Y-m-d H:00:00"), Server::STATUS_RUNNING]; foreach (array_keys(\SERVER_PLATFORMS::GetList()) as $platform) { $plt[] = "SELECT CONVERT(? USING latin1) AS `platform`"; $args[] = $platform; } $args[] = Server::INFO_INSTANCE_VCPUS; \Scalr::getDb()->Execute("\n INSERT IGNORE INTO platform_usage (`time`, `platform`, `value`)\n SELECT ? AS `time`, p.`platform`, SUM(IF(s.status = ?, IFNULL(sp.`value`, 0), 0))\n FROM (" . implode(" UNION ALL ", $plt) . ") AS p\n LEFT JOIN servers AS s ON p.platform = s.platform\n LEFT JOIN server_properties AS sp ON s.server_id = sp.server_id AND sp.`name` = ?\n GROUP BY p.`platform`\n ", $args); return new ArrayObject([]); }
/** * DataProvider method for the testPlatformAction */ public function providerPlatformAction() { $aPrefixed = array_fill_keys(array(SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::UCLOUD, SERVER_PLATFORMS::OPENSTACK, SERVER_PLATFORMS::RACKSPACENG_UK, SERVER_PLATFORMS::RACKSPACENG_US, SERVER_PLATFORMS::OCS, SERVER_PLATFORMS::ECS, SERVER_PLATFORMS::NEBULA), true); $pars = array(); foreach (\SERVER_PLATFORMS::GetList() as $platform => $opts) { if ($platform == \SERVER_PLATFORMS::RACKSPACE) { continue; } if ($platform == \SERVER_PLATFORMS::EUCALYPTUS) { continue; } $pars[] = array($platform, array_key_exists($platform, $aPrefixed) ? $platform . '.' : ''); } return $pars; }
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()); if (!$this->user->isScalrAdmin()) { $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'); $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('enabled' => $this->user->isScalrAdmin() ? false : !!$this->environment->isPlatformEnabled($platform), 'name' => $platformName); } } $data['flags']['authMode'] = $this->getContainer()->config->get('scalr.auth_mode'); $data['flags']['specialToken'] = Scalr_Session::getInstance()->getToken(); return $data; }
public function xListEnvironmentsAction() { $this->request->defineParams(array('sort' => array('type' => 'json'))); $selectStmt = "SELECT e.id, e.name, e.dt_added AS dtAdded, e.status"; if ($this->user->isAccountOwner()) { $sql = "\n {$selectStmt}\n FROM client_environments e\n WHERE e.client_id = ? AND :FILTER:\n GROUP BY e.id\n "; $params = array($this->user->getAccountId()); } else { $sql = "\n {$selectStmt}\n FROM client_environments e\n JOIN account_team_envs te ON e.id = te.env_id\n JOIN account_team_users tu ON te.team_id = tu.team_id\n WHERE e.client_id = ? AND tu.user_id = ? AND :FILTER:\n GROUP BY e.id\n "; $params = array($this->user->getAccountId(), $this->user->id); } $response = $this->buildResponseFromSql($sql, array('id', 'name', 'dtAdded', 'status'), array(), $params); foreach ($response['data'] as &$row) { $row['platforms'] = array(); foreach (Scalr_Environment::init()->loadById($row['id'])->getEnabledPlatforms() as $platform) { $row['platforms'][] = SERVER_PLATFORMS::GetName($platform); } $row['platforms'] = implode(', ', $row['platforms']); $row['dtAdded'] = Scalr_Util_DateTime::convertTz($row['dtAdded']); } $this->response->data($response); }
/** * Raises onCloudAdd notification event * * @param string $platform A platform name. * @param \Scalr_Environment $environment An environment object which cloud is created in. * @param \Scalr_Account_User $user An user who has created platform. */ public function onCloudAdd($platform, $environment, $user) { $container = \Scalr::getContainer(); $analytics = $container->analytics; //Nothing to do in case analytics is disabled if (!$analytics->enabled) { return; } if (!$environment instanceof \Scalr_Environment) { $environment = \Scalr_Environment::init()->loadById($environment); } $pm = PlatformFactory::NewPlatform($platform); //Check if there are some price for this platform and endpoint url if (($endpointUrl = $pm->hasCloudPrices($environment)) === true) { return; } //Disabled or badly configured environment if ($endpointUrl === false && !in_array($platform, [\SERVER_PLATFORMS::EC2, \SERVER_PLATFORMS::GCE])) { return; } //Send a message to financial admin if there are not any price for this cloud $baseUrl = rtrim($container->config('scalr.endpoint.scheme') . "://" . $container->config('scalr.endpoint.host'), '/'); //Disable notifications for hosted Scalr if (!\Scalr::isAllowedAnalyticsOnHostedScalrAccount($environment->clientId)) { return; } $emails = $this->getFinancialAdminEmails(); //There isn't any financial admin if (empty($emails)) { return; } $emails = array_map(function ($email) { return '<' . trim($email, '<>') . '>'; }, $emails); try { $res = $container->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/analytics_on_cloud_add.eml.php', ['isPublicCloud' => $platform == \SERVER_PLATFORMS::EC2, 'userEmail' => $user->getEmail(), 'cloudName' => \SERVER_PLATFORMS::GetName($platform), 'linkToPricing' => $baseUrl . '/#/analytics/pricing?platform=' . urlencode($platform) . '&url=' . urlencode($endpointUrl === false ? '' : $analytics->prices->normalizeUrl($endpointUrl))], join(',', $emails)); } catch (\Exception $e) { } }
public function defaultAction() { //Platforms should be in the same order everywhere $platforms = array_values(array_intersect(array_keys(SERVER_PLATFORMS::GetList()), array_merge([SERVER_PLATFORMS::EC2], PlatformFactory::getOpenstackBasedPlatforms(), PlatformFactory::getCloudstackBasedPlatforms()))); $this->response->page('ui/analytics/pricing/view.js', ['platforms' => $platforms, 'forbidAutomaticUpdate' => [SERVER_PLATFORMS::EC2 => !!SettingEntity::getValue(SettingEntity::ID_FORBID_AUTOMATIC_UPDATE_AWS_PRICES)]], [], ['ui/analytics/pricing/view.css']); }
/** * TODO: migrate to the new cloud credentials entities * Gets array of the linked variables * * @param string $linkid optional If provided it will return variables from given group id * @return array If linkid is null it will return array looks like array(variable => linkid). * If linkid is provided it will return list of the linked variables * from the specified group. array(variable1, variable2, ..., variableN) */ private static function getLinkedVariables($linkid = null) { static $ret = array(), $rev = array(); if (empty($ret)) { //Performs at once $ret = array(SERVER_PLATFORMS::EC2 => array(Ec2PlatformModule::ACCESS_KEY, Ec2PlatformModule::SECRET_KEY, Ec2PlatformModule::CERTIFICATE, Ec2PlatformModule::PRIVATE_KEY, Ec2PlatformModule::ACCOUNT_ID, Ec2PlatformModule::ACCOUNT_TYPE), SERVER_PLATFORMS::GCE => array(GoogleCEPlatformModule::ACCESS_TOKEN, GoogleCEPlatformModule::CLIENT_ID, GoogleCEPlatformModule::KEY, GoogleCEPlatformModule::PROJECT_ID, GoogleCEPlatformModule::RESOURCE_BASE_URL, GoogleCEPlatformModule::SERVICE_ACCOUNT_NAME, GoogleCEPlatformModule::JSON_KEY), 'enabledPlatforms' => array()); foreach (array_keys(SERVER_PLATFORMS::getList()) as $value) { $ret['enabledPlatforms'][] = "{$value}.is_enabled"; } foreach (array(SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::CLOUDSTACK) as $platform) { $ret[$platform] = array($platform . "." . CloudstackPlatformModule::ACCOUNT_NAME, $platform . "." . CloudstackPlatformModule::API_KEY, $platform . "." . CloudstackPlatformModule::API_URL, $platform . "." . CloudstackPlatformModule::DOMAIN_ID, $platform . "." . CloudstackPlatformModule::DOMAIN_NAME, $platform . "." . CloudstackPlatformModule::SECRET_KEY, $platform . "." . CloudstackPlatformModule::SHARED_IP, $platform . "." . CloudstackPlatformModule::SHARED_IP_ID, $platform . "." . CloudstackPlatformModule::SHARED_IP_INFO, $platform . "." . CloudstackPlatformModule::SZR_PORT_COUNTER); } foreach (array(SERVER_PLATFORMS::OPENSTACK, SERVER_PLATFORMS::OCS, SERVER_PLATFORMS::NEBULA, SERVER_PLATFORMS::MIRANTIS, SERVER_PLATFORMS::RACKSPACENG_UK, SERVER_PLATFORMS::RACKSPACENG_US) as $platform) { $ret[$platform] = array($platform . "." . OpenstackPlatformModule::API_KEY, $platform . "." . OpenstackPlatformModule::AUTH_TOKEN, $platform . "." . OpenstackPlatformModule::KEYSTONE_URL, $platform . "." . OpenstackPlatformModule::PASSWORD, $platform . "." . OpenstackPlatformModule::TENANT_NAME, $platform . "." . OpenstackPlatformModule::DOMAIN_NAME, $platform . "." . OpenstackPlatformModule::USERNAME); } $ret[SERVER_PLATFORMS::AZURE] = [AzurePlatformModule::SUBSCRIPTION_ID, AzurePlatformModule::ACCESS_TOKEN, AzurePlatformModule::ACCESS_TOKEN_EXPIRE, AzurePlatformModule::AUTH_CODE, AzurePlatformModule::AUTH_STEP, AzurePlatformModule::CLIENT_OBJECT_ID, AzurePlatformModule::CLIENT_TOKEN, AzurePlatformModule::CLIENT_TOKEN_EXPIRE, AzurePlatformModule::CONTRIBUTOR_ID, AzurePlatformModule::REFRESH_TOKEN, AzurePlatformModule::REFRESH_TOKEN_EXPIRE, AzurePlatformModule::STORAGE_ACCOUNT_NAME, AzurePlatformModule::TENANT_NAME, AzurePlatformModule::ROLE_ASSIGNMENT_ID]; //Computes fast access keys foreach ($ret as $platform => $linkedKeys) { foreach ($linkedKeys as $variable) { $rev[$variable] = $platform; } } } return $linkid !== null ? isset($ret[$linkid]) ? $ret[$linkid] : null : $rev; }
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; }
protected function run2($stage) { if ($this->getCountOfAccountTagValues(TagEntity::TAG_ID_PLATFORM) && $this->console->confirm('Would you like to remove old platforms from account_tag_values?')) { $this->console->out("Removing old platforms"); $this->db->Execute("DELETE FROM account_tag_values WHERE tag_id = ?", array(TagEntity::TAG_ID_PLATFORM)); } $this->console->out('Populating platforms to the dictionary'); $platforms = \SERVER_PLATFORMS::GetList(); $pars = array(); $values = ''; foreach ($platforms as $id => $name) { $values .= ",('0', '" . TagEntity::TAG_ID_PLATFORM . "', ?, ?)"; $pars[] = $id; $pars[] = $name; } $values = ltrim($values, ','); if ($values != '') { $this->db->Execute("\n INSERT IGNORE account_tag_values (`account_id`, `tag_id`, `value_id`, `value_name`)\n VALUES " . $values . "\n ", $pars); } }
/** * Get information about role * * @param int $roleId Identifier of role * @param bool $extended Get extended information about role * @param array $canAddImage Array of platform, cloudLocation to check if role has image in that location * @return array * @throws Exception * @throws Scalr_Exception_Core * @throws Scalr_Exception_InsufficientPermissions */ private function getInfo($roleId, $extended = false, $canAddImage = null) { /* @var $role Role */ $role = Role::findPk($roleId); if (!$role) { throw new Scalr_Exception_Core(sprintf(_("Role ID#%s not found in database"), $roleId)); } $this->request->checkPermissions($role); $usedBy = $role->getFarmsCount($this->user->getAccountId(), $this->getEnvironmentId(true)); $platforms = array_keys($role->fetchImagesArray()); $allPlatforms = array_flip(array_keys(SERVER_PLATFORMS::GetList())); usort($platforms, function ($a, $b) use($allPlatforms) { return $allPlatforms[$a] > $allPlatforms[$b] ? 1 : -1; }); $result = array('name' => $role->name, 'behaviors' => $role->getBehaviors(), 'id' => $role->id, 'accountId' => $role->accountId, 'envId' => $role->envId, 'catId' => $role->catId, 'status' => $usedBy > 0 ? 'In use' : 'Not used', 'scope' => $role->getScope(), 'os' => $role->getOs()->name, 'osId' => $role->osId, 'osFamily' => $role->getOs()->family, 'dtAdded' => $role->added ? Scalr_Util_DateTime::convertTz($role->added) : NULL, 'dtLastUsed' => $role->lastUsed ? Scalr_Util_DateTime::convertTz($role->lastUsed) : NULL, 'isQuickStart' => $role->isQuickStart, 'isDeprecated' => $role->isDeprecated, 'isScalarized' => $role->isScalarized, 'platforms' => $platforms, 'environments' => !empty($envs = $role->getAllowedEnvironments()) ? $this->db->GetCol("SELECT name FROM client_environments WHERE id IN(" . join(',', $envs) . ")") : []); if ($canAddImage) { try { $role->getImage($canAddImage['platform'], $canAddImage['cloudLocation']); $result['canAddImage'] = false; } catch (Exception $e) { $result['canAddImage'] = true; } } if ($extended) { $result['description'] = $role->description; $result['images'] = []; foreach (RoleImage::find([['roleId' => $role->id]]) as $image) { /* @var $image RoleImage */ $im = $image->getImage(); $ext = []; if ($im) { $ext = get_object_vars($im); $ext['software'] = $im->getSoftwareAsString(); } $result['images'][] = ['imageId' => $image->imageId, 'platform' => $image->platform, 'cloudLocation' => $image->cloudLocation, 'extended' => $ext]; } if ($result['status'] == 'In use' && $this->getEnvironmentId(true)) { $farms = []; $f = []; foreach (FarmRole::find([['roleId' => $role->id]]) as $farmRole) { /* @var $farmRole FarmRole */ $f[] = $farmRole->farmId; } $f = array_unique($f); if (count($f)) { foreach (Farm::find([['id' => ['$in' => $f]], ['envId' => $this->getEnvironmentId()]]) as $fm) { /* @var $fm Farm */ $farms[] = ['id' => $fm->id, 'name' => $fm->name]; } } $result['usedBy'] = ['farms' => $farms, 'cnt' => count($farms)]; } } return $result; }
<?php require_once __DIR__ . '/../src/prepend.inc.php'; use Scalr\Util\PhpTemplate; $opt = getopt('', ['csv::']); $format = array_key_exists('csv', $opt) && $opt['csv'] === false ? 'csv' : 'txt'; $quarterDays = [90, 91, 92, 92]; $data = []; $allPlatforms = \SERVER_PLATFORMS::getList(); $res = \Scalr::getDb()->Execute("\n SELECT `time`, `platform`, `value`, QUARTER(`time`) AS quarter, YEAR(`time`) AS year\n FROM platform_usage\n ORDER BY `time` ASC\n"); while ($row = $res->FetchRow()) { $quarter = "Q" . $row["quarter"] . " " . $row["year"]; if (!array_key_exists($quarter, $data)) { $data[$quarter] = ["quarter" => $row["quarter"] - 1, "year" => $row["year"], "days" => [], "dataByPlatform" => []]; } if (!array_key_exists($row["platform"], $data[$quarter]["dataByPlatform"])) { $data[$quarter]["dataByPlatform"][$row["platform"]] = []; } $data[$quarter]["dataByPlatform"][$row["platform"]][] = $row["value"]; $data[$quarter]["days"][substr($row["time"], 0, 10)] = true; } if ($format == 'csv') { $csvRowTemplate = ['year' => '', 'quarter' => '', 'partial' => '']; } foreach ($data as $quarter => &$set) { ksort($set["dataByPlatform"]); foreach ($set["dataByPlatform"] as $platform => &$report) { $report = \Scalr_Util_Arrays::percentile($report, 90, true); if ($format == 'csv' && !array_key_exists($platform, $csvRowTemplate)) { $csvRowTemplate[$platform] = 0; }
/** * Get list of roles for roles library */ public function xGetListAction() { $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES); $total = 0; $roles = array(); $filterRoleId = $this->getParam('roleId'); $filterCatId = $this->getParam('catId'); $filterOsFamily = $this->getParam('osFamily'); $filterKeyword = $this->getParam('keyword'); $filterPlatform = $this->getParam('platform'); $e_platforms = $this->getEnvironment()->getEnabledPlatforms(); $platforms = array(); $l_platforms = SERVER_PLATFORMS::GetList(); foreach ($e_platforms as $platform) { $platforms[$platform] = $l_platforms[$platform]; } if ($filterPlatform) { if (!$platforms[$filterPlatform]) { throw new Exception("Selected cloud not enabled in current environment"); } } if ($filterCatId === 'shared') { $roles_sql = "SELECT DISTINCT(roles.id), platform FROM roles INNER JOIN role_images ON role_images.role_id = roles.id WHERE is_deprecated='0' AND generation = '2' AND env_id=?"; $args[] = 0; if (!$filterPlatform) { $roles_sql .= " AND role_images.platform IN ('" . implode("','", array_keys($platforms)) . "')"; } else { $roles_sql .= " AND role_images.platform = ?"; $args[] = $filterPlatform; } if ($filterOsFamily) { $roles_sql .= ' AND os_family = ?'; $args[] = $filterOsFamily; } $dbRoles = $this->db->Execute($roles_sql, $args); $software = array(); $softwareOrdering = array('base' => 0, 'mysql' => 10, 'percona' => 20, 'mariadb' => 10, 'postgresql' => 30, 'mongodb' => 40, 'redis' => 50, 'apache' => 60, 'lamp' => 70, 'tomcat' => 80, 'haproxy' => 90, 'nginx' => 100, 'memcached' => 110, 'rabbitmq' => 120, 'vpcrouter' => 130); foreach ($dbRoles as $role) { $dbRole = DBRole::loadById($role['id']); // Get type if ($dbRole->hasBehavior(ROLE_BEHAVIORS::VPC_ROUTER)) { $type = 'vpcrouter'; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::APACHE) && ($dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL2) || $dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL) || $dbRole->hasBehavior(ROLE_BEHAVIORS::PERCONA) || $dbRole->hasBehavior(ROLE_BEHAVIORS::MARIADB))) { $type = 'lamp'; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL2)) { $type = 'mysql'; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::APACHE)) { $type = 'apache'; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::TOMCAT)) { $type = ROLE_BEHAVIORS::TOMCAT; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::NGINX)) { $type = 'nginx'; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::HAPROXY)) { $type = 'haproxy'; } elseif ($dbRole->getDbMsrBehavior()) { $type = $dbRole->getDbMsrBehavior(); } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::MONGODB)) { $type = ROLE_BEHAVIORS::MONGODB; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::RABBITMQ)) { $type = ROLE_BEHAVIORS::RABBITMQ; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::MEMCACHED)) { $type = ROLE_BEHAVIORS::MEMCACHED; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::BASE)) { $type = ROLE_BEHAVIORS::BASE; } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL)) { continue; } // Set hvm flag $hvm = stristr($dbRole->name, '-hvm-') ? 1 : 0; // Set arch flag $architecture = stristr($dbRole->name, '64-') ? 'x86_64' : 'i386'; $images = $dbRole->getImages(true); foreach ($images as $cloud => $locations) { if (!$platforms[$cloud]) { unset($images[$cloud]); } else { foreach ($locations as $location => $image) { if (!$image['architecture']) { $images[$cloud][$location]['architecture'] = $architecture; } } } } $item = array('role_id' => $dbRole->id, 'name' => $dbRole->name, 'behaviors' => $dbRole->getBehaviors(), 'origin' => $dbRole->origin, 'cat_name' => $dbRole->getCategoryName(), 'cat_id' => $dbRole->catId, 'os_name' => $dbRole->os, 'os_family' => $dbRole->osFamily, 'os_generation' => $dbRole->osGeneration, 'os_version' => $dbRole->osVersion, 'images' => $images, 'hvm' => $hvm, 'ebs' => 1, 'description' => $dbRole->description); $software[$type]['roles'][] = $item; $software[$type]['name'] = $type; $software[$type]['ordering'] = isset($softwareOrdering[$type]) ? $softwareOrdering[$type] : 1000; $total++; } $software = array_values($software); } else { $args[] = $this->getEnvironmentId(); $roles_sql = "\n SELECT DISTINCT(r.id), r.env_id\n FROM roles r\n LEFT JOIN roles_queue q ON r.id = q.role_id\n INNER JOIN role_images as i ON i.role_id = r.id\n WHERE generation = '2' AND env_id IN(0, ?)\n AND q.id IS NULL\n AND i.platform\n "; if (!$filterPlatform) { $roles_sql .= " IN ('" . implode("','", array_keys($platforms)) . "')"; } else { $roles_sql .= " = ?"; $args[] = $filterPlatform; } if ($filterCatId === 'search') { $roles_sql .= ' AND r.name LIKE ' . $this->db->qstr('%' . trim($filterKeyword) . '%'); if ($filterRoleId) { $roles_sql .= ' AND r.id = ?'; $args[] = $filterRoleId; } } elseif ($filterCatId === 'recent') { } elseif ($filterCatId) { $roles_sql .= ' AND r.cat_id = ?'; $args[] = $filterCatId; } if ($filterOsFamily) { $roles_sql .= ' AND r.os_family = ?'; $args[] = $filterOsFamily; } $roles_sql .= ' GROUP BY r.id'; if ($filterCatId === 'recent') { $roles_sql .= ' ORDER BY r.id DESC LIMIT 10'; } $dbRoles = $this->db->Execute($roles_sql, $args); $globalVars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE); foreach ($dbRoles as $role) { $dbRole = DBRole::loadById($role['id']); $architecture = stristr($dbRole->name, '64-') ? 'x86_64' : 'i386'; $images = $dbRole->getImages(true); foreach ($images as $cloud => $locations) { if (!$platforms[$cloud]) { unset($images[$cloud]); } else { if ($dbRole->envId == 0) { foreach ($locations as $location => $image) { if (!$image['architecture']) { $images[$cloud][$location]['architecture'] = $architecture; } } } } } $roles[] = array('role_id' => $dbRole->id, 'name' => $dbRole->name, 'behaviors' => $dbRole->getBehaviors(), 'origin' => $dbRole->origin, 'cat_name' => $dbRole->getCategoryName(), 'cat_id' => $dbRole->catId, 'os_name' => $dbRole->os, 'os_family' => $dbRole->osFamily, 'os_generation' => $dbRole->osGeneration, 'os_version' => $dbRole->osVersion, 'images' => $images, 'tags' => $dbRole->getTags(), 'variables' => $globalVars->getValues($dbRole->id, 0, 0), 'shared' => $role['env_id'] == 0, 'description' => $dbRole->description); } $total = count($roles); } $moduleParams = array('roles' => $roles, 'software' => $software, 'total' => $total); $this->response->data($moduleParams); }
/** * Get information about role */ public function infoAction() { $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES); $this->request->defineParams(array('roleId' => array('type' => 'int'))); $roleId = $this->getParam('roleId'); $dbRole = DBRole::loadById($roleId); if ($dbRole->envId != 0) { $this->user->getPermissions()->validate($dbRole); } $dbRole->groupName = $dbRole->getCategoryName(); $dbRole->behaviorsList = implode(", ", $dbRole->getBehaviors()); foreach ($dbRole->getSoftwareList() as $soft) { $dbRole->softwareList[] = "{$soft['name']} {$soft['version']}"; } if ($dbRole->softwareList) { $dbRole->softwareList = implode(", ", $dbRole->softwareList); } else { $dbRole->softwareList = ""; } $dbRole->tagsString = implode(", ", $dbRole->getTags()); $dbRole->platformsList = array(); foreach ($dbRole->getPlatforms() as $platform) { $dbRole->platformsList[] = array('name' => SERVER_PLATFORMS::GetName($platform), 'locations' => implode(", ", $dbRole->getCloudLocations($platform))); } $this->response->page('ui/roles/info.js', array('name' => $dbRole->name, 'info' => get_object_vars($dbRole))); }
public function editAction() { $env = $this->getEnvironmentInfo(); if (!($this->user->getType() == Scalr_Account_User::TYPE_ACCOUNT_OWNER || $this->user->isTeamUserInEnvironment($env['id'], Scalr_Account_Team::PERMISSIONS_OWNER))) { throw new Scalr_Exception_InsufficientPermissions(); } $platforms = SERVER_PLATFORMS::GetList(); unset($platforms[SERVER_PLATFORMS::RDS]); //TODO: if (!$this->getParam('beta')) { unset($platforms[SERVER_PLATFORMS::OPENSTACK]); } $timezones = array(); $timezoneAbbreviationsList = timezone_abbreviations_list(); foreach ($timezoneAbbreviationsList as $timezoneAbbreviations) { foreach ($timezoneAbbreviations as $value) { if (preg_match('/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific|Australia)\\//', $value['timezone_id'])) { $timezones[$value['timezone_id']] = $value['offset']; } } } @ksort($timezones); $timezones = array_keys($timezones); $this->response->page('ui/environments/edit.js', array('environment' => $env, 'platforms' => $platforms, 'timezones' => $timezones)); }
/** * @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; }
public function importAction() { $behaviors = array(array(ROLE_BEHAVIORS::BASE, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::BASE)), array(ROLE_BEHAVIORS::APACHE, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::APACHE)), array(ROLE_BEHAVIORS::MYSQL, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::MYSQL)), array(ROLE_BEHAVIORS::MYSQL2, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::MYSQL2)), array(ROLE_BEHAVIORS::NGINX, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::NGINX)), array(ROLE_BEHAVIORS::MEMCACHED, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::MEMCACHED)), array(ROLE_BEHAVIORS::POSTGRESQL, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::POSTGRESQL)), array(ROLE_BEHAVIORS::REDIS, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::REDIS)), array(ROLE_BEHAVIORS::RABBITMQ, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::RABBITMQ)), array(ROLE_BEHAVIORS::MONGODB, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::MONGODB))); if ($this->getParam('beta') == 1) { array_push($behaviors, array(ROLE_BEHAVIORS::HAPROXY, ROLE_BEHAVIORS::GetName(ROLE_BEHAVIORS::HAPROXY))); } $euca_locations = array(); $rs_locations = array(); $platforms = array(); $env = Scalr_Environment::init()->loadById($this->getEnvironmentId()); $enabledPlatforms = $env->getEnabledPlatforms(); foreach (SERVER_PLATFORMS::getList() as $k => $v) { if (in_array($k, $enabledPlatforms)) { if ($k == 'rds') { continue; } $platforms[] = array($k, $v); if ($k == SERVER_PLATFORMS::EUCALYPTUS) { foreach (PlatformFactory::NewPlatform($k)->getLocations() as $lk => $lv) { $euca_locations[$lk] = array('id' => $lk, 'name' => $lv); } } elseif ($k == SERVER_PLATFORMS::RACKSPACE) { foreach (PlatformFactory::NewPlatform($k)->getLocations() as $lk => $lv) { $rs_locations[$lk] = array('id' => $lk, 'name' => $lv); } } elseif ($k == SERVER_PLATFORMS::OPENSTACK) { foreach (PlatformFactory::NewPlatform($k)->getLocations() as $lk => $lv) { $os_locations[$lk] = array('id' => $lk, 'name' => $lv); } } } } unset($platforms['rds']); $this->response->page('ui/servers/import_step1.js', array('platforms' => $platforms, 'behaviors' => $behaviors, 'euca_locations' => $euca_locations, 'rs_locations' => $rs_locations, 'os_locations' => $os_locations)); }
/** * Gets array of the linked variables * * @param string $linkid optional If provided it will return variables from given group id * @return array If linkid is null it will return array looks like array(variable => linkid). * If linkid is provided it will return list of the linked variables * from the specified group. array(variable1, variable2, ..., variableN) */ private static function getLinkedVariables($linkid = null) { static $ret = array(), $rev = array(); if (empty($ret)) { //Performs at once $ret = array(SERVER_PLATFORMS::EC2 => array(Modules_Platforms_Ec2::ACCESS_KEY, Modules_Platforms_Ec2::SECRET_KEY, Modules_Platforms_Ec2::CERTIFICATE, Modules_Platforms_Ec2::PRIVATE_KEY, Modules_Platforms_Ec2::ACCOUNT_ID), SERVER_PLATFORMS::GCE => array(Modules_Platforms_GoogleCE::ACCESS_TOKEN, Modules_Platforms_GoogleCE::CLIENT_ID, Modules_Platforms_GoogleCE::KEY, Modules_Platforms_GoogleCE::PROJECT_ID, Modules_Platforms_GoogleCE::RESOURCE_BASE_URL, Modules_Platforms_GoogleCE::SERVICE_ACCOUNT_NAME), 'enabledPlatforms' => array()); foreach (array_keys(SERVER_PLATFORMS::getList()) as $value) { $ret['enabledPlatforms'][] = "{$value}.is_enabled"; } foreach (array(SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::UCLOUD, SERVER_PLATFORMS::CLOUDSTACK) as $platform) { $ret[$platform] = array($platform . "." . Modules_Platforms_Cloudstack::ACCOUNT_NAME, $platform . "." . Modules_Platforms_Cloudstack::API_KEY, $platform . "." . Modules_Platforms_Cloudstack::API_URL, $platform . "." . Modules_Platforms_Cloudstack::DOMAIN_ID, $platform . "." . Modules_Platforms_Cloudstack::DOMAIN_NAME, $platform . "." . Modules_Platforms_Cloudstack::SECRET_KEY, $platform . "." . Modules_Platforms_Cloudstack::SHARED_IP, $platform . "." . Modules_Platforms_Cloudstack::SHARED_IP_ID, $platform . "." . Modules_Platforms_Cloudstack::SHARED_IP_INFO, $platform . "." . Modules_Platforms_Cloudstack::SZR_PORT_COUNTER); } foreach (array(SERVER_PLATFORMS::OPENSTACK, SERVER_PLATFORMS::ECS, SERVER_PLATFORMS::OCS, SERVER_PLATFORMS::NEBULA, SERVER_PLATFORMS::RACKSPACENG_UK, SERVER_PLATFORMS::RACKSPACENG_US) as $platform) { $ret[$platform] = array($platform . "." . Modules_Platforms_Openstack::API_KEY, $platform . "." . Modules_Platforms_Openstack::AUTH_TOKEN, $platform . "." . Modules_Platforms_Openstack::KEYSTONE_URL, $platform . "." . Modules_Platforms_Openstack::PASSWORD, $platform . "." . Modules_Platforms_Openstack::TENANT_NAME, $platform . "." . Modules_Platforms_Openstack::USERNAME); } //Computes fast access keys foreach ($ret as $platform => $linkedKeys) { foreach ($linkedKeys as $variable) { $rev[$variable] = $platform; } } } return $linkid !== null ? isset($ret[$linkid]) ? $ret[$linkid] : null : $rev; }
/** * @param jsonData $platforms * @throws Exception */ public function xGetLocationsAction(JsonData $platforms) { $allPlatforms = $this->request->getScope() != ScopeInterface::SCOPE_ENVIRONMENT ? array_keys(SERVER_PLATFORMS::GetList()) : $this->getEnvironment()->getEnabledPlatforms(); $result = array(); foreach ($platforms as $platform) { if (in_array($platform, $allPlatforms)) { $result[$platform] = !in_array($platform, array(SERVER_PLATFORMS::GCE, SERVER_PLATFORMS::AZURE)) ? PlatformFactory::NewPlatform($platform)->getLocations($this->environment) : array(); } } $this->response->data(array('locations' => $result)); }
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; }