public static getTimezones ( boolean $returnOffset = false ) : array | ||
$returnOffset | boolean | optional If true return object [timezone] = GMT offset, otherwise return array of timezones |
Результат | array |
public function editAction() { $this->request->defineParams(array('schedulerTaskId' => array('type' => 'int'))); //$DBFarmRole->FarmID; $task = Scalr_SchedulerTask::init(); $task->loadById($this->getParam(self::CALL_PARAM_NAME)); $this->user->getPermissions()->validate($task); $taskValues = array('targetId' => $task->targetId, 'targetType' => $task->targetType, 'id' => $task->id, 'name' => $task->name, 'type' => $task->type, 'comments' => htmlspecialchars_decode($task->comments), 'config' => $task->config, 'startTime' => $task->startTime ? Scalr_Util_DateTime::convertTimeZone(new DateTime($task->startTime), $task->timezone)->format('Y-m-d H:i') : '', 'endTime' => $task->endTime ? Scalr_Util_DateTime::convertTimeZone(new DateTime($task->endTime), $task->timezone)->format('Y-m-d H:i') : '', 'restartEvery' => $task->restartEvery, 'timezone' => $task->timezone); $farmWidget = array(); switch ($task->targetType) { case Scalr_SchedulerTask::TARGET_FARM: $farmWidget = self::loadController('Farms')->getFarmWidget(array('farmId' => $task->targetId), 'addAll'); break; case Scalr_SchedulerTask::TARGET_ROLE: $farmWidget = self::loadController('Farms')->getFarmWidget(array('farmRoleId' => $task->targetId), 'addAll'); break; case Scalr_SchedulerTask::TARGET_INSTANCE: try { $DBServer = DBServer::LoadByFarmRoleIDAndIndex($task->targetId, $task->targetServerIndex); $farmWidget = self::loadController('Farms')->getFarmWidget(array('serverId' => $DBServer->serverId), 'addAll'); } catch (Exception $e) { $farmWidget = self::loadController('Farms')->getFarmWidget(array('farmRoleId' => $task->targetId), 'addAll'); } break; default: break; } $this->response->page('ui/schedulertasks/create.js', array('farmWidget' => $farmWidget, 'timezones' => Scalr_Util_DateTime::getTimezones(), 'scripts' => self::loadController('Scripts')->getList(), 'defaultTimezone' => $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE), 'task' => $taskValues)); }
public function viewAction() { $events = array_map(function ($item) { if ($item->envId) { $scope = 'environment'; } else { if ($item->accountId) { $scope = 'account'; } else { $scope = 'scalr'; } } return ['name' => $item->name, 'description' => $item->description, 'scope' => $scope]; }, EventDefinition::result(EventDefinition::RESULT_ENTITY_COLLECTION)->find([['$or' => [['accountId' => null], ['accountId' => $this->user->getAccountId()]]], ['$or' => [['envId' => null], ['envId' => $this->getEnvironmentId()]]]], null, ['name' => true])->getArrayCopy()); $this->response->page('ui/schedulertasks/view.js', ['farmWidget' => self::loadController('Farms')->getFarmWidget(array(), 'addAll'), 'timezones' => Scalr_Util_DateTime::getTimezones(true), 'scripts' => Script::getList($this->user->getAccountId(), $this->getEnvironmentId()), 'events' => $events, 'defaultTimezone' => $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE)]); }
public function buildAction() { $this->request->restrictAccess(Acl::RESOURCE_FARMS, Acl::PERM_FARMS_MANAGE); $this->request->defineParams(array('farmId' => array('type' => 'int'), 'roleId' => array('type' => 'int'))); $farmId = $this->getParam('farmId'); $roleId = $this->getParam('roleId'); $moduleParams = array('farmId' => $farmId, 'roleId' => $roleId, 'behaviors' => ROLE_BEHAVIORS::GetName(null, true)); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CASSANDRA]); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CUSTOM]); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::HAPROXY]); //platforms list $platforms = self::loadController('Platforms')->getEnabledPlatforms(); if (empty($platforms)) { throw new Exception('Before building new farm you need to configure environment and setup cloud credentials'); } //categories list $categories = $this->db->GetAll("SELECT c.id, c.name, COUNT(DISTINCT r.id) AS total\n FROM role_categories c\n LEFT JOIN roles r ON c.id = r.cat_id AND r.env_id IN(0, ?) AND r.id IN (\n SELECT role_id\n FROM role_images\n WHERE role_id = r.id\n AND platform IN ('" . implode("','", array_keys($platforms)) . "')\n )\n LEFT JOIN roles_queue q ON r.id = q.role_id\n WHERE c.env_id IN (0, ?)\n AND q.id IS NULL\n GROUP BY c.id\n ", array($this->environment->id, $this->environment->id)); $moduleParams['categories'] = array(); foreach ($categories as $g) { $moduleParams['categories'][$g['id']] = $g; } $moduleParams['farmVpcEc2Enabled'] = $this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2); if ($moduleParams['farmVpcEc2Enabled']) { $moduleParams['farmVpcEc2Locations'] = self::loadController('Platforms')->getCloudLocations(SERVER_PLATFORMS::EC2, false); } if ($farmId) { $c = self::loadController('Builder', 'Scalr_UI_Controller_Farms'); $moduleParams['farm'] = $c->getFarm2($farmId); } else { // TODO: remove hack, do better $vars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARM); $moduleParams['farmVariables'] = $vars->getValues(); } $moduleParams['tabs'] = array('vpcrouter', 'dbmsr', 'mongodb', 'mysql', 'scaling', 'network', 'gce', 'cloudfoundry', 'rabbitmq', 'haproxy', 'proxy', 'rds', 'scripting', 'nimbula', 'ec2', 'security', 'devel', 'storage', 'variables', 'advanced'); if ($this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_CHEF)) { $moduleParams['tabs'][] = 'chef'; } //deprecated tabs $moduleParams['tabs'][] = 'deployments'; $moduleParams['tabs'][] = 'ebs'; $moduleParams['tabs'][] = 'params'; $moduleParams['tabs'][] = 'servicesconfig'; $conf = $this->getContainer()->config->get('scalr.load_statistics.connections.plotter'); $moduleParams['tabParams'] = array('farmId' => $farmId, 'farmHash' => $moduleParams['farm'] ? $moduleParams['farm']['farm']['hash'] : '', 'accountId' => $this->environment->getPlatformConfigValue(Ec2PlatformModule::ACCOUNT_ID), 'remoteAddress' => $this->request->getRemoteAddr(), 'monitoringHostUrl' => "{$conf['scheme']}://{$conf['host']}:{$conf['port']}", 'nginx' => array('server_section' => @file_get_contents("../templates/services/nginx/server_section.tpl"), 'server_section_ssl' => @file_get_contents("../templates/services/nginx/server_section_ssl.tpl"))); // TODO: Features $moduleParams['tabParams']['featureRAID'] = $this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_RAID); $moduleParams['tabParams']['featureMFS'] = $this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_MFS); $moduleParams['tabParams']['scalr.dns.global.enabled'] = \Scalr::config('scalr.dns.global.enabled'); $moduleParams['tabParams']['scalr.instances_connection_policy'] = \Scalr::config('scalr.instances_connection_policy'); $moduleParams['tabParams']['scalr.scalarizr_update.repos'] = array_keys(\Scalr::config('scalr.scalarizr_update.repos')); $moduleParams['tabParams']['scalr.scalarizr_update.default_repo'] = \Scalr::config('scalr.scalarizr_update.default_repo'); $moduleParams['metrics'] = self::loadController('Metrics', 'Scalr_UI_Controller_Scaling')->getList(); $moduleParams['timezones_list'] = Scalr_Util_DateTime::getTimezones(); $moduleParams['timezone_default'] = $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE); if ($moduleParams['farm']['farm']['ownerEditable']) { $moduleParams['usersList'] = Scalr_Account_User::getList($this->user->getAccountId()); } $governance = new Scalr_Governance($this->getEnvironmentId()); $moduleParams['governance'] = $governance->getValues(true); $defaultFarmRoleSecurityGroups = array('default'); if (\Scalr::config('scalr.aws.security_group_name')) { $defaultFarmRoleSecurityGroups[] = \Scalr::config('scalr.aws.security_group_name'); } $moduleParams['roleDefaultSettings'] = array('base.keep_scripting_logs_time' => \Scalr::config('scalr.system.scripting.default_instance_log_rotation_period'), 'security_groups.list' => json_encode($defaultFarmRoleSecurityGroups)); //cost analytics if ($this->getContainer()->analytics->enabled && $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID)) { $costCenter = $this->getContainer()->analytics->ccs->get($this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID)); $projects = []; if ($costCenter instanceof CostCentreEntity) { $projectsIterator = new SharedProjectsFilterIterator($costCenter->getProjects(), $costCenter->ccId, $this->user, $this->getEnvironment()); foreach ($projectsIterator as $item) { /* @var $item ProjectEntity */ $projects[] = array('projectId' => $item->projectId, 'name' => $item->name); } $costCentreName = $costCenter->name; } else { $costCentreName = ''; } $moduleParams['analytics'] = array('costCenterName' => $costCentreName, 'projects' => $projects); if ($farmId) { $dbFarm = DBFarm::LoadByID($farmId); $moduleParams['farm']['farm']['projectId'] = $dbFarm->GetSetting(DBFarm::SETTING_PROJECT_ID); } } $this->response->page('ui/farms/builder.js', $moduleParams, array('ui/farms/builder/selroles.js', 'ui/farms/builder/roleedit.js', 'ui/farms/builder/roleslibrary.js', 'ui/farms/builder/tabs/dbmsr.js', 'ui/farms/builder/tabs/cloudfoundry.js', 'ui/farms/builder/tabs/rabbitmq.js', 'ui/farms/builder/tabs/mongodb.js', 'ui/farms/builder/tabs/haproxy.js', 'ui/farms/builder/tabs/proxy.js', 'ui/farms/builder/tabs/mysql.js', 'ui/farms/builder/tabs/nimbula.js', 'ui/farms/builder/tabs/rds.js', 'ui/farms/builder/tabs/gce.js', 'ui/farms/builder/tabs/scaling.js', 'ui/farms/builder/tabs/scripting.js', 'ui/farms/builder/tabs/advanced.js', 'ui/farms/builder/tabs/ec2.js', 'ui/farms/builder/tabs/security.js', 'ui/farms/builder/tabs/storage.js', 'ui/farms/builder/tabs/variables.js', 'ui/farms/builder/tabs/devel.js', 'ui/farms/builder/tabs/chef.js', 'ui/farms/builder/tabs/vpcrouter.js', 'ui/farms/builder/tabs/network.js', 'ui/farms/builder/tabs/deployments.js', 'ui/farms/builder/tabs/ebs.js', 'ui/farms/builder/tabs/params.js', 'ui/farms/builder/tabs/servicesconfig.js', 'ui/farms/builder/roleslibrary/ec2.js', 'ui/farms/builder/roleslibrary/vpc.js', 'ui/farms/builder/roleslibrary/euca.js', 'ui/farms/builder/roleslibrary/rackspace.js', 'ui/farms/builder/roleslibrary/openstack.js', 'ui/farms/builder/roleslibrary/cloudstack.js', 'ui/farms/builder/roleslibrary/gce.js', 'ui/farms/builder/roleslibrary/mongodb.js', 'ui/farms/builder/roleslibrary/dbmsr.js', 'ui/farms/builder/roleslibrary/proxy.js', 'ui/farms/builder/roleslibrary/haproxy.js', 'ui/farms/builder/roleslibrary/chef.js', 'codemirror/codemirror.js', 'ui/core/variablefield.js', 'ui/scripts/scriptfield.js', 'ux-boxselect.js', 'ui/monitoring/window.js', 'ui/services/chef/chefsettings.js', 'ui/security/groups/sgeditor.js'), array('ui/farms/builder/selroles.css', 'ui/farms/builder/roleedit.css', 'ui/farms/builder/roleslibrary.css', 'codemirror/codemirror.css', 'ui/core/variablefield.css', 'ui/scripts/scriptfield.css', 'ui/farms/builder/tabs/scaling.css')); }
public function settingsAction() { if ($this->user->isAdmin()) { throw new Scalr_Exception_InsufficientPermissions(); } $panel = $this->user->getDashboard($this->getEnvironmentId()); $params = array_merge($this->user->getSshConsoleSettings(), array('gravatar_email' => $this->user->getSetting(Scalr_Account_User::SETTING_GRAVATAR_EMAIL) ? $this->user->getSetting(Scalr_Account_User::SETTING_GRAVATAR_EMAIL) : '', 'gravatar_hash' => $this->user->getGravatarHash(), 'rss_login' => $this->user->getSetting(Scalr_Account_User::SETTING_RSS_LOGIN), 'rss_pass' => $this->user->getSetting(Scalr_Account_User::SETTING_RSS_PASSWORD), 'timezone' => $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE), 'timezones_list' => Scalr_Util_DateTime::getTimezones(), 'user_email' => $this->user->getEmail(), 'user_fullname' => $this->user->fullname, 'dashboard_columns' => count($panel['configuration']), 'scalr.id' => SCALR_ID)); $this->response->page('ui/core/settings.js', $params); }
public function editAction() { $this->request->defineParams(array('schedulerTaskId' => array('type' => 'int'))); //$DBFarmRole->FarmID; $task = Scalr_SchedulerTask::init(); $task->loadById($this->getParam(self::CALL_PARAM_NAME)); $this->user->getPermissions()->validate($task); $taskValues = array('targetId' => $task->targetId, 'targetType' => $task->targetType, 'id' => $task->id, 'name' => $task->name, 'type' => $task->type, 'config' => $task->config, 'startTime' => $task->startTime ? Scalr_Util_DateTime::convertDateTime(new DateTime($task->startTime), $task->timezone)->format('Y-m-d H:i') : '', 'endTime' => $task->endTime ? Scalr_Util_DateTime::convertDateTime(new DateTime($task->endTime), $task->timezone)->format('Y-m-d H:i') : '', 'restartEvery' => $task->restartEvery, 'timezone' => $task->timezone); $farmRoles = array('farms' => self::loadController('Farms')->getList(), 'farmRoles' => array(), 'servers' => array()); switch ($task->targetType) { case Scalr_SchedulerTask::TARGET_FARM: try { $farmRoles['farmId'] = $task->targetId; $this->request->setParams(array('farmId' => $task->targetId)); $farmRole = self::loadController('Roles', 'Scalr_UI_Controller_Farms')->getList(); if (count($farmRole)) { $farmRole[0] = array('id' => '0', 'name' => 'On all roles'); $farmRoles['farmRoleId'] = '0'; } $farmRoles['farmRoles'] = $farmRole; } catch (Exception $e) { } break; case Scalr_SchedulerTask::TARGET_ROLE: try { $DBFarmRole = DBFarmRole::LoadByID($task->targetId); $farmRoles['farmId'] = $DBFarmRole->FarmID; $farmRoles['farmRoleId'] = $task->targetId; $this->request->setParams(array('farmId' => $DBFarmRole->FarmID)); $farmRole = self::loadController('Roles', 'Scalr_UI_Controller_Farms')->getList(); if (count($farmRole)) { $farmRole[0] = array('id' => '0', 'name' => 'On all roles'); } $farmRoles['farmRoles'] = $farmRole; $servers = array(); foreach ($DBFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING)) as $key => $value) { $servers[$value->serverId] = $value->remoteIp; } $farmRoles['servers'] = $servers; if (count($servers)) { $farmRoles['servers'][0] = 'On all servers'; $farmRoles['serverId'] = '0'; } } catch (Exception $e) { } break; case Scalr_SchedulerTask::TARGET_INSTANCE: $serverArgs = explode(':', $task->targetId); try { $DBServer = DBServer::LoadByFarmRoleIDAndIndex($serverArgs[0], $serverArgs[1]); $farmRoles['serverId'] = $DBServer->serverId; $farmRoles['farmRoleId'] = $DBServer->farmRoleId; $farmRoles['farmId'] = $DBServer->farmId; $this->request->setParams(array('farmId' => $DBServer->farmId)); $farmRole = self::loadController('Roles', 'Scalr_UI_Controller_Farms')->getList(); if (count($farmRole)) { $farmRole[0] = array('id' => '0', 'name' => 'On all roles'); } $farmRoles['farmRoles'] = $farmRole; $servers = array(); $dbFarmRole = DBFarmRole::LoadByID($DBServer->farmRoleId); foreach ($dbFarmRole->GetServersByFilter(array('status' => SERVER_STATUS::RUNNING)) as $key => $value) { $servers[$value->serverId] = $value->remoteIp; } $farmRoles['servers'] = $servers; if (count($servers)) { $farmRoles['servers'][0] = 'On all servers'; } } catch (Exception $e) { } break; default: break; } $this->response->page('ui/schedulertasks/create.js', array('farmRoles' => $farmRoles, 'timezones' => Scalr_Util_DateTime::getTimezones(), 'scripts' => self::loadController('Scripts')->getList(), 'defaultTimezone' => $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_TIMEZONE), 'task' => $taskValues)); }
/** * @param int $farmId optional * @param int $roleId optional * @param string $scalrPageHash optional * @param string $scalrPageUiHash optional * @throws Scalr_Exception_InsufficientPermissions */ public function xGetFarmAction($farmId = null, $roleId = null, $scalrPageHash = null, $scalrPageUiHash = null) { if ($scalrPageHash && $scalrPageHash != $this->calcFarmDesignerHash()) { $this->response->data(['scalrPageHashMismatch' => true]); return; } if ($scalrPageUiHash && $scalrPageUiHash != $this->response->pageUiHash()) { $this->response->data(['scalrPageUiHashMismatch' => true]); return; } $moduleParams = array('farmId' => $farmId, 'roleId' => $roleId, 'behaviors' => ROLE_BEHAVIORS::GetName(null, true)); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CASSANDRA]); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CUSTOM]); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::HAPROXY]); //platforms list $platforms = self::loadController('Platforms')->getEnabledPlatforms(); if (empty($platforms)) { throw new Exception('Before building new farm you need to configure environment and setup cloud credentials'); } $moduleParams['categories'] = self::loadController('Roles')->listRoleCategories(true, true); $moduleParams['farmVpcEc2Enabled'] = $this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2); if ($moduleParams['farmVpcEc2Enabled']) { $moduleParams['farmVpcEc2Locations'] = self::loadController('Platforms')->getCloudLocations(SERVER_PLATFORMS::EC2, false); } if ($farmId) { $this->request->checkPermissions(DBFarm::LoadByID($farmId)->__getNewFarmObject(), Acl::PERM_FARMS_UPDATE); $c = self::loadController('Builder', 'Scalr_UI_Controller_Farms'); $moduleParams['farm'] = $c->getFarm2($farmId); } else { $this->request->restrictAccess(Acl::RESOURCE_OWN_FARMS, Acl::PERM_FARMS_CREATE); // TODO: remove hack, do better $vars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), ScopeInterface::SCOPE_FARM); $moduleParams['farmVariables'] = $vars->getValues(); } $moduleParams['tabs'] = array('vpcrouter', 'dbmsr', 'mongodb', 'mysql', 'scaling', 'network', 'cloudfoundry', 'rabbitmq', 'haproxy', 'proxy', 'scripting', 'ec2', 'openstack', 'gce', 'azure', 'security', 'devel', 'storage', 'variables', 'advanced', 'chef'); //deprecated tabs if (\Scalr::config('scalr.ui.show_deprecated_features')) { $moduleParams['tabs'][] = 'ebs'; } $conf = $this->getContainer()->config->get('scalr.load_statistics.connections.plotter'); $moduleParams['tabParams'] = array('farmId' => $farmId, 'farmHash' => $moduleParams['farm'] ? $moduleParams['farm']['farm']['hash'] : '', 'accountId' => $this->environment->keychain(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID], 'remoteAddress' => $this->request->getRemoteAddr(), 'monitoringHostUrl' => "{$conf['scheme']}://{$conf['host']}:{$conf['port']}", 'nginx' => array('server_section' => file_get_contents(APPPATH . '/templates/services/nginx/server_section.tpl'), 'server_section_ssl' => file_get_contents(APPPATH . '/templates/services/nginx/server_section_ssl.tpl'))); $moduleParams['tabParams']['scalr.instances_connection_policy'] = \Scalr::config('scalr.instances_connection_policy'); $moduleParams['tabParams']['scalr.scalarizr_update.default_repo'] = \Scalr::config('scalr.scalarizr_update.default_repo'); if (Scalr::isHostedScalr()) { $moduleParams['tabParams']['scalr.scalarizr_update.repos'] = ['latest' => Utils::getScalarizrUpdateRepoTitle('latest')]; if ($this->user->getAccount()->priority == 100) { $moduleParams['tabParams']['scalr.scalarizr_update.repos']['stable'] = Utils::getScalarizrUpdateRepoTitle('stable'); } } else { $repos = array_keys(\Scalr::config('scalr.scalarizr_update.repos')); $moduleParams['tabParams']['scalr.scalarizr_update.repos'] = array_combine($repos, $repos); } $moduleParams['tabParams']['scalr.scalarizr_update.devel_repos'] = is_array(\Scalr::config('scalr.scalarizr_update.devel_repos')) ? array_keys(\Scalr::config('scalr.scalarizr_update.devel_repos')) : []; $moduleParams['tabParams']['scalr.aws.ec2.limits.security_groups_per_instance'] = \Scalr::config('scalr.aws.ec2.limits.security_groups_per_instance'); $moduleParams['metrics'] = Entity\ScalingMetric::getList($this->getEnvironmentId()); $moduleParams['timezones_list'] = Scalr_Util_DateTime::getTimezones(); $moduleParams['timezone_default'] = $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE); if ($moduleParams['farm']['farm']['ownerEditable']) { $moduleParams['usersList'] = []; foreach (Entity\Account\User::findByAccountId($this->user->getAccountId()) as $user) { $moduleParams['usersList'][] = ['id' => $user->id, 'email' => $user->email]; } } $defaultFarmRoleSecurityGroups = array('default'); if (\Scalr::config('scalr.aws.security_group_name')) { $defaultFarmRoleSecurityGroups[] = \Scalr::config('scalr.aws.security_group_name'); } $moduleParams['roleDefaultSettings'] = array('base.keep_scripting_logs_time' => \Scalr::config('scalr.system.scripting.default_instance_log_rotation_period'), 'security_groups.list' => json_encode($defaultFarmRoleSecurityGroups), 'base.abort_init_on_script_fail' => \Scalr::config('scalr.system.scripting.default_abort_init_on_script_fail') ? 1 : 0, 'base.disable_firewall_management' => \Scalr::config('scalr.system.default_disable_firewall_management') ? 1 : 0); //cost analytics if ($this->getContainer()->analytics->enabled && $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID)) { $farmCostData = $this->getFarmCostData($farmId); $moduleParams['analytics'] = $farmCostData['analytics']; if ($farmId) { $moduleParams['farm']['farm']['projectId'] = $farmCostData['projectId']; $moduleParams['analytics']['farmCostMetering'] = $farmCostData['farmCostMetering']; } } $moduleParams['farmLaunchPermission'] = $farmId ? $moduleParams['farm']['farm']['launchPermission'] : $this->request->isAllowed([Acl::RESOURCE_FARMS, Acl::RESOURCE_TEAM_FARMS, Acl::RESOURCE_OWN_FARMS], Acl::PERM_FARMS_LAUNCH_TERMINATE); $this->response->data($moduleParams); }
/** * @param int $farmId optional * @param int $roleId optional * @param string $scalrPageHash optional * @param string $scalrPageUiHash optional * @throws Scalr_Exception_InsufficientPermissions */ public function xGetFarmAction($farmId = null, $roleId = null, $scalrPageHash = null, $scalrPageUiHash = null) { if ($scalrPageHash && $scalrPageHash != $this->calcFarmDesignerHash()) { $this->response->data(['scalrPageHashMismatch' => true]); return; } if ($scalrPageUiHash && $scalrPageUiHash != $this->response->pageUiHash()) { $this->response->data(['scalrPageUiHashMismatch' => true]); return; } $moduleParams = array('farmId' => $farmId, 'roleId' => $roleId, 'behaviors' => ROLE_BEHAVIORS::GetName(null, true)); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CASSANDRA]); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CUSTOM]); unset($moduleParams['behaviors'][ROLE_BEHAVIORS::HAPROXY]); //platforms list $platforms = self::loadController('Platforms')->getEnabledPlatforms(); if (empty($platforms)) { throw new Exception('Before building new farm you need to configure environment and setup cloud credentials'); } //categories list $categories = $this->db->GetAll("SELECT c.id, c.name, COUNT(DISTINCT r.id) AS total\n FROM role_categories c\n LEFT JOIN roles r ON c.id = r.cat_id AND (r.env_id IS NULL OR r.env_id = ?) AND r.id IN (\n SELECT role_id\n FROM role_images\n WHERE role_id = r.id\n AND platform IN ('" . implode("','", array_keys($platforms)) . "')\n )\n WHERE c.env_id IS NULL OR c.env_id = ?\n GROUP BY c.id\n ", array($this->environment->id, $this->environment->id)); $moduleParams['categories'] = array(); foreach ($categories as $g) { $moduleParams['categories'][$g['id']] = $g; } $moduleParams['farmVpcEc2Enabled'] = $this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2); if ($moduleParams['farmVpcEc2Enabled']) { $moduleParams['farmVpcEc2Locations'] = self::loadController('Platforms')->getCloudLocations(SERVER_PLATFORMS::EC2, false); } if ($farmId) { $this->request->restrictFarmAccess(DBFarm::LoadByID($farmId), Acl::PERM_FARMS_MANAGE); $c = self::loadController('Builder', 'Scalr_UI_Controller_Farms'); $moduleParams['farm'] = $c->getFarm2($farmId); } else { $this->request->restrictFarmAccess(null, Acl::PERM_FARMS_MANAGE); // TODO: remove hack, do better $vars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), ScopeInterface::SCOPE_FARM); $moduleParams['farmVariables'] = $vars->getValues(); } $moduleParams['tabs'] = array('vpcrouter', 'dbmsr', 'mongodb', 'mysql', 'scaling', 'network', 'cloudfoundry', 'rabbitmq', 'haproxy', 'proxy', 'scripting', 'ec2', 'openstack', 'gce', 'azure', 'security', 'devel', 'storage', 'variables', 'advanced', 'chef'); //deprecated tabs if (\Scalr::config('scalr.ui.show_deprecated_features')) { $moduleParams['tabs'][] = 'deployments'; $moduleParams['tabs'][] = 'ebs'; $moduleParams['tabs'][] = 'servicesconfig'; } $conf = $this->getContainer()->config->get('scalr.load_statistics.connections.plotter'); $moduleParams['tabParams'] = array('farmId' => $farmId, 'farmHash' => $moduleParams['farm'] ? $moduleParams['farm']['farm']['hash'] : '', 'accountId' => $this->environment->cloudCredentials(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID], 'remoteAddress' => $this->request->getRemoteAddr(), 'monitoringHostUrl' => "{$conf['scheme']}://{$conf['host']}:{$conf['port']}", 'nginx' => array('server_section' => file_get_contents(APPPATH . '/templates/services/nginx/server_section.tpl'), 'server_section_ssl' => file_get_contents(APPPATH . '/templates/services/nginx/server_section_ssl.tpl'))); $moduleParams['tabParams']['scalr.dns.global.enabled'] = \Scalr::config('scalr.dns.global.enabled'); $moduleParams['tabParams']['scalr.instances_connection_policy'] = \Scalr::config('scalr.instances_connection_policy'); $moduleParams['tabParams']['scalr.scalarizr_update.repos'] = array_keys(\Scalr::config('scalr.scalarizr_update.repos')); $moduleParams['tabParams']['scalr.scalarizr_update.devel_repos'] = is_array(\Scalr::config('scalr.scalarizr_update.devel_repos')) ? array_keys(\Scalr::config('scalr.scalarizr_update.devel_repos')) : []; $moduleParams['tabParams']['scalr.scalarizr_update.default_repo'] = \Scalr::config('scalr.scalarizr_update.default_repo'); $moduleParams['tabParams']['scalr.aws.ec2.limits.security_groups_per_instance'] = \Scalr::config('scalr.aws.ec2.limits.security_groups_per_instance'); $moduleParams['metrics'] = Entity\ScalingMetric::getList($this->getEnvironmentId()); $moduleParams['timezones_list'] = Scalr_Util_DateTime::getTimezones(); $moduleParams['timezone_default'] = $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE); if ($moduleParams['farm']['farm']['ownerEditable']) { $moduleParams['usersList'] = Scalr_Account_User::getList($this->user->getAccountId()); } $defaultFarmRoleSecurityGroups = array('default'); if (\Scalr::config('scalr.aws.security_group_name')) { $defaultFarmRoleSecurityGroups[] = \Scalr::config('scalr.aws.security_group_name'); } $moduleParams['roleDefaultSettings'] = array('base.keep_scripting_logs_time' => \Scalr::config('scalr.system.scripting.default_instance_log_rotation_period'), 'security_groups.list' => json_encode($defaultFarmRoleSecurityGroups), 'base.abort_init_on_script_fail' => \Scalr::config('scalr.system.scripting.default_abort_init_on_script_fail') ? 1 : 0, 'base.disable_firewall_management' => \Scalr::config('scalr.system.default_disable_firewall_management') ? 1 : 0); //cost analytics if ($this->getContainer()->analytics->enabled && $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID)) { $farmCostData = $this->getFarmCostData($farmId); $moduleParams['analytics'] = $farmCostData['analytics']; if ($farmId) { $moduleParams['farm']['farm']['projectId'] = $farmCostData['projectId']; $moduleParams['analytics']['farmCostMetering'] = $farmCostData['farmCostMetering']; } } $moduleParams['farmLaunchPermission'] = $farmId ? $moduleParams['farm']['farm']['launchPermission'] : $this->request->isFarmAllowed(null, Acl::PERM_FARMS_LAUNCH_TERMINATE); if ($moduleParams['farm']['farm']['teamOwnerEditable'] || !$farmId) { if ($this->user->canManageAcl()) { $teams = $this->db->getAll('SELECT id, name, description FROM account_teams WHERE account_id = ?', array($this->user->getAccountId())); } else { $teams = $this->user->getTeams(); $teamId = $moduleParams['farm']['farm']['teamOwner']; $flag = !!$teamId; foreach ($teams as $t) { if ($t['id'] == $teamId) { $flag = false; break; } } if ($flag) { // team is missed in list, add manually $team = $this->db->GetRow('SELECT name, description FROM account_teams WHERE id = ?', [$teamId]); array_unshift($teams, ['id' => $teamId, 'name' => $team ? $team['name'] : '', 'description' => $team ? $team['description'] : '']); } } array_unshift($teams, ['id' => 0, 'name' => '']); $moduleParams['teamsList'] = $teams; } $this->response->data($moduleParams); }
public function settingsAction() { if ($this->user->isAdmin()) { throw new Scalr_Exception_InsufficientPermissions(); } $panel = $this->user->getDashboard($this->getEnvironmentId(true)); $params = ['scalrId' => SCALR_ID, 'userEmail' => $this->user->getEmail(), 'userFullname' => $this->user->fullname, 'dashboardColumns' => count($panel['configuration']), 'timezonesList' => Scalr_Util_DateTime::getTimezones(), 'gravatarHash' => $this->user->getGravatarHash()]; $params = array_merge($params, $this->user->getSshConsoleSettings()); foreach ([Scalr_Account_User::SETTING_GRAVATAR_EMAIL, Scalr_Account_User::SETTING_UI_TIMEZONE] as $setting) { $v = $this->user->getSetting($setting); $params[$setting] = $v ? $v : ''; } $this->response->page('ui/core/settings.js', $params); }
public function settingsAction() { $panel = $this->user->getDashboard($this->getEnvironmentId()); $params = array('gravatar_email' => $this->user->getSetting(Scalr_Account_User::SETTING_GRAVATAR_EMAIL) ? $this->user->getSetting(Scalr_Account_User::SETTING_GRAVATAR_EMAIL) : '', 'gravatar_hash' => $this->user->getGravatarHash(), 'rss_login' => $this->user->getSetting(Scalr_Account_User::SETTING_RSS_LOGIN), 'rss_pass' => $this->user->getSetting(Scalr_Account_User::SETTING_RSS_PASSWORD), 'timezone' => $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE), 'timezones_list' => Scalr_Util_DateTime::getTimezones(), 'user_email' => $this->user->getEmail(), 'user_fullname' => $this->user->fullname, 'dashboard_columns' => count($panel['configuration'])); $this->response->page('ui/core/settings.js', $params); }