Example #1
0
 /**
  * @param JsonData $sort
  * @param int $start
  * @param int $limit
  */
 public function xListAction(JsonData $sort, $start = 0, $limit = 20)
 {
     $result = ScriptShortcut::find(['farmId' => ['$in' => $this->getAllowedFarmId()]], null, Scalr\UI\Utils::convertOrder($sort, ['scriptId' => true], ['scriptId', 'farmId', 'farmRoleId']), $limit, $start, true);
     $data = [];
     foreach ($result as $shortcut) {
         /* @var $shortcut ScriptShortcut */
         $s = get_object_vars($shortcut);
         $s['farmName'] = DBFarm::LoadByIDOnlyName($shortcut->farmId);
         $s['scriptName'] = $shortcut->getScriptName();
         try {
             $farmRole = DBFarmRole::LoadByID($shortcut->farmRoleId);
             $s['farmRoleName'] = $farmRole->Alias ? $farmRole->Alias : $farmRole->GetRoleObject()->name;
         } catch (Exception $e) {
         }
         $data[] = $s;
     }
     $this->response->data(['total' => $result->totalNumber, 'data' => $data]);
 }
Example #2
0
 public function xListFarmRolesAction()
 {
     $this->request->defineParams(array('farmId' => array('type' => 'int'), 'farmRoleId' => array('type' => 'int'), 'roleId' => array('type' => 'int'), 'id' => array('type' => 'int'), 'sort' => array('type' => 'json')));
     $this->request->restrictFarmAccess(DBFarm::LoadByID($this->getParam('farmId')));
     $sql = "\n            SELECT farm_roles.*\n            FROM farm_roles\n            JOIN roles ON farm_roles.role_id = roles.id\n            WHERE farmid = ?\n            AND :FILTER:\n        ";
     $params = array($this->getParam('farmId'));
     if ($this->getParam('roleId')) {
         $sql .= ' AND role_id = ?';
         $params[] = $this->getParam('roleId');
     }
     if ($this->getParam('farmRoleId')) {
         $sql .= ' AND farm_roles.id = ?';
         $params[] = $this->getParam('farmRoleId');
     }
     $response = $this->buildResponseFromSql($sql, array('platform', 'name', 'alias'), array('name'), $params);
     foreach ($response['data'] as &$row) {
         $row["running_servers"] = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_roleid='{$row['id']}' AND status IN ('Pending', 'Initializing', 'Running', 'Temporary')");
         $row["suspended_servers"] = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_roleid='{$row['id']}' AND status IN ('Suspended', 'Pending suspend')");
         $row["non_running_servers"] = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_roleid='{$row['id']}' AND status NOT IN ('Pending', 'Initializing', 'Running', 'Temporary')");
         $row['farm_status'] = $this->db->GetOne("SELECT status FROM farms WHERE id=? LIMIT 1", array($row['farmid']));
         $row["domains"] = $this->db->GetOne("SELECT COUNT(*) FROM dns_zones WHERE farm_roleid=? AND status != ? AND farm_id=?", array($row["id"], DNS_ZONE_STATUS::PENDING_DELETE, $row['farmid']));
         $DBFarmRole = DBFarmRole::LoadByID($row['id']);
         $row['min_count'] = $DBFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MIN_INSTANCES);
         $row['max_count'] = $DBFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MAX_INSTANCES);
         $row['allow_launch_instance'] = !$DBFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MONGODB) && !$DBFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER);
         $vpcId = $this->environment->getPlatformConfigValue(Ec2PlatformModule::DEFAULT_VPC_ID . ".{$DBFarmRole->CloudLocation}");
         $row['is_vpc'] = $vpcId || $DBFarmRole->GetFarmObject()->GetSetting(DBFarm::SETTING_EC2_VPC_ID) ? true : false;
         $row['location'] = $DBFarmRole->CloudLocation;
         $DBRole = DBRole::loadById($row['role_id']);
         $row["name"] = $DBRole->name;
         $row['image_id'] = $DBRole->__getNewRoleObject()->getImage($DBFarmRole->Platform, $DBFarmRole->CloudLocation)->imageId;
         if ($DBFarmRole->GetFarmObject()->Status == FARM_STATUS::RUNNING) {
             $row['shortcuts'] = [];
             foreach (\Scalr\Model\Entity\ScriptShortcut::find(array(array('farmRoleId' => $row['id']))) as $shortcut) {
                 /* @var $shortcut \Scalr\Model\Entity\ScriptShortcut */
                 $row['shortcuts'][] = array('id' => $shortcut->id, 'name' => $shortcut->getScriptName());
             }
         }
         $scalingManager = new Scalr_Scaling_Manager($DBFarmRole);
         $scaling_algos = array();
         foreach ($scalingManager->getFarmRoleMetrics() as $farmRoleMetric) {
             $scaling_algos[] = $farmRoleMetric->getMetric()->name;
         }
         if (count($scaling_algos) == 0) {
             $row['scaling_algos'] = _("Scaling disabled");
         } else {
             $row['scaling_algos'] = implode(', ', $scaling_algos);
         }
     }
     $this->response->data($response);
 }
Example #3
0
 public function xListFarmRolesAction()
 {
     $this->request->defineParams(array('farmId' => array('type' => 'int'), 'farmRoleId' => array('type' => 'int'), 'roleId' => array('type' => 'int'), 'id' => array('type' => 'int'), 'sort' => array('type' => 'json')));
     $sql = "\n            SELECT farm_roles.*\n            FROM farm_roles\n            JOIN roles ON farm_roles.role_id = roles.id\n            WHERE farmid = ?\n            AND :FILTER:\n        ";
     $params = array($this->getParam('farmId'));
     if ($this->getParam('roleId')) {
         $sql .= ' AND role_id = ?';
         $params[] = $this->getParam('roleId');
     }
     if ($this->getParam('farmRoleId')) {
         $sql .= ' AND farm_roles.id = ?';
         $params[] = $this->getParam('farmRoleId');
     }
     $response = $this->buildResponseFromSql($sql, array('platform', 'name', 'alias'), array('name'), $params);
     foreach ($response['data'] as &$row) {
         $servers = $this->db->GetRow("\n                SELECT SUM(IF(`status` IN (?,?,?,?,?),1,0)) AS running_servers,\n                    SUM(IF(`status` IN (?,?),1,0)) AS suspended_servers,\n                    SUM(IF(`status` IN (?,?),1,0)) AS non_running_servers\n                FROM `servers` WHERE `farm_roleid` = ?\n            ", [Entity\Server::STATUS_PENDING, Entity\Server::STATUS_INIT, Entity\Server::STATUS_RUNNING, Entity\Server::STATUS_TEMPORARY, Entity\Server::STATUS_RESUMING, Entity\Server::STATUS_SUSPENDED, Entity\Server::STATUS_PENDING_SUSPEND, Entity\Server::STATUS_TERMINATED, Entity\Server::STATUS_PENDING_TERMINATE, $row['id']]);
         if (is_null($servers['running_servers'])) {
             $servers = ['running_servers' => 0, 'suspended_servers' => 0, 'non_running_servers' => 0];
         }
         $row = array_merge($row, $servers);
         $row['farm_status'] = $this->db->GetOne("SELECT status FROM farms WHERE id=? LIMIT 1", array($row['farmid']));
         $row["domains"] = $this->db->GetOne("SELECT COUNT(*) FROM dns_zones WHERE farm_roleid=? AND status != ? AND farm_id=?", array($row["id"], DNS_ZONE_STATUS::PENDING_DELETE, $row['farmid']));
         $DBFarmRole = DBFarmRole::LoadByID($row['id']);
         $row['allow_launch_instance'] = !$DBFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MONGODB) && !$DBFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER);
         $vpcId = $this->environment->getPlatformConfigValue(Ec2PlatformModule::DEFAULT_VPC_ID . ".{$DBFarmRole->CloudLocation}");
         $row['is_vpc'] = $vpcId || $DBFarmRole->GetFarmObject()->GetSetting(Entity\FarmSetting::EC2_VPC_ID) ? true : false;
         $row['location'] = $DBFarmRole->CloudLocation;
         $DBRole = DBRole::loadById($row['role_id']);
         $row["name"] = $DBRole->name;
         $row['image_id'] = $DBRole->__getNewRoleObject()->getImage($DBFarmRole->Platform, $DBFarmRole->CloudLocation)->imageId;
         if ($DBFarmRole->GetFarmObject()->Status == FARM_STATUS::RUNNING) {
             $row['shortcuts'] = [];
             foreach (\Scalr\Model\Entity\ScriptShortcut::find([['farmRoleId' => $row['id']]]) as $shortcut) {
                 /* @var $shortcut \Scalr\Model\Entity\ScriptShortcut */
                 $row['shortcuts'][] = array('id' => $shortcut->id, 'name' => $shortcut->getScriptName());
             }
         }
         $row['scaling_enabled'] = $DBFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_ENABLED);
         if ($row['scaling_enabled'] == 1) {
             $row['min_count'] = $DBFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MIN_INSTANCES);
             $row['max_count'] = $DBFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MAX_INSTANCES);
             $scalingManager = new Scalr_Scaling_Manager($DBFarmRole);
             $scaling_algos = [];
             foreach ($scalingManager->getFarmRoleMetrics() as $farmRoleMetric) {
                 $scaling_algos[] = $farmRoleMetric->getMetric()->name;
             }
             $row['scaling_algos'] = implode(', ', $scaling_algos);
         }
         $row['farmOwnerIdPerm'] = $DBFarmRole->GetFarmObject()->createdByUserId == $this->user->getId();
         $row['farmTeamIdPerm'] = $DBFarmRole->GetFarmObject()->teamId ? $this->user->isInTeam($DBFarmRole->GetFarmObject()->teamId) : false;
     }
     $this->response->data($response);
 }
Example #4
0
 public function xListFarmsAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS);
     $this->request->defineParams(array('clientId' => array('type' => 'int'), 'farmId' => array('type' => 'int'), 'sort' => array('type' => 'json'), 'expirePeriod' => array('type' => 'int')));
     $governance = new Scalr_Governance($this->getEnvironmentId());
     $leaseStatus = $governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE);
     $sql = 'SELECT f.clientid, f.id, f.name, f.status, f.dtadded, f.created_by_id, f.created_by_email FROM farms f WHERE env_id = ? AND :FILTER:';
     $args = array($this->getEnvironmentId());
     if ($leaseStatus && $this->getParam('expirePeriod')) {
         $dt = new DateTime();
         $dt->add(new DateInterval('P' . $this->getParam('expirePeriod') . 'D'));
         $sql = str_replace('FROM farms f', 'FROM farms f LEFT JOIN farm_settings fs ON f.id = fs.farmid', $sql);
         $sql = str_replace('WHERE', 'WHERE fs.name = ? AND fs.value < ? AND f.status = ? AND', $sql);
         array_unshift($args, DBFarm::SETTING_LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'), FARM_STATUS::RUNNING);
     }
     if ($this->getParam('farmId')) {
         $sql .= ' AND id = ?';
         $args[] = $this->getParam('farmId');
     }
     if ($this->getParam('clientId')) {
         $sql .= ' AND clientid = ?';
         $args[] = $this->getParam('clientId');
     }
     if ($this->getParam('status') != '') {
         $sql .= ' AND status = ?';
         $args[] = $this->getParam('status');
     }
     if ($this->getParam('showOnlyMy') || !$this->request->isAllowed(Acl::RESOURCE_FARMS, Acl::PERM_FARMS_NOT_OWNED_FARMS)) {
         $sql .= ' AND created_by_id = ?';
         $args[] = $this->user->getId();
     }
     $response = $this->buildResponseFromSql2($sql, array('id', 'name', 'dtadded', 'created_by_email', 'status'), array('name', 'id', 'comments'), $args);
     foreach ($response["data"] as &$row) {
         $row["running_servers"] = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_id='{$row['id']}' AND status IN ('Pending', 'Initializing', 'Running', 'Temporary','Resuming')");
         $row["suspended_servers"] = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_id='{$row['id']}' AND status IN ('Suspended', 'Pending suspend')");
         $row["non_running_servers"] = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_id='{$row['id']}' AND status NOT IN ('Suspended', 'Pending suspend', 'Resuming', 'Pending', 'Initializing', 'Running', 'Temporary', 'Pending launch')");
         $row["roles"] = $this->db->GetOne("SELECT COUNT(*) FROM farm_roles WHERE farmid='{$row['id']}'");
         $row["zones"] = $this->db->GetOne("SELECT COUNT(*) FROM dns_zones WHERE farm_id='{$row['id']}'");
         //TODO: Use Alerts class
         $row['alerts'] = $this->db->GetOne("SELECT COUNT(*) FROM server_alerts WHERE farm_id='{$row['id']}' AND status='failed'");
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row["dtadded"]);
         $dbFarm = DBFarm::LoadByID($row['id']);
         $row['lock'] = $dbFarm->GetSetting(DBFarm::SETTING_LOCK);
         if ($row['lock']) {
             $row['lock_comment'] = $dbFarm->isLocked(false);
         }
         if ($leaseStatus && $dbFarm->GetSetting(DBFarm::SETTING_LEASE_STATUS)) {
             $row['lease'] = $dbFarm->GetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND) ? 'Expire' : $dbFarm->GetSetting(DBFarm::SETTING_LEASE_STATUS);
             if ($row['lease'] == 'Expire') {
                 $dt = new DateTime();
                 $td = new DateTime($dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE));
                 $days = 0;
                 $hours = 1;
                 $interval = $dt->diff($td);
                 if ($interval) {
                     $days = $interval->days;
                     $hours = $interval->h ? $interval->h : 1;
                 }
                 $row['leaseMessage'] = sprintf('Your farm lease is about to expire in %d %s, after which this farm will be terminated', $days ? $days : $hours, $days ? $days > 1 ? 'days' : 'day' : ($hours > 1 ? 'hours' : 'hour'));
             }
         }
         $b = (array) $this->db->GetAll("SELECT DISTINCT(behavior) FROM farm_roles\n                INNER JOIN role_behaviors ON role_behaviors.role_id = farm_roles.role_id WHERE farmid = ?", array($row['id']));
         $behaviors = array();
         foreach ($b as $behavior) {
             $behaviors[] = $behavior['behavior'];
         }
         $row["havemysqlrole"] = in_array(ROLE_BEHAVIORS::MYSQL, $behaviors);
         $row["havemysql2role"] = in_array(ROLE_BEHAVIORS::MYSQL2, $behaviors);
         $row["havepgrole"] = in_array(ROLE_BEHAVIORS::POSTGRESQL, $behaviors);
         $row["haveredisrole"] = in_array(ROLE_BEHAVIORS::REDIS, $behaviors);
         $row["haverabbitmqrole"] = in_array(ROLE_BEHAVIORS::RABBITMQ, $behaviors);
         $row["havemongodbrole"] = in_array(ROLE_BEHAVIORS::MONGODB, $behaviors);
         $row["haveperconarole"] = in_array(ROLE_BEHAVIORS::PERCONA, $behaviors);
         $row["havemariadbrole"] = in_array(ROLE_BEHAVIORS::MARIADB, $behaviors);
         $row['status_txt'] = FARM_STATUS::GetStatusName($row['status']);
         if ($row['status'] == FARM_STATUS::RUNNING) {
             $row['shortcuts'] = [];
             foreach (\Scalr\Model\Entity\ScriptShortcut::find(array(array('farmId' => $row['id']), array('farmRoleId' => NULL))) as $shortcut) {
                 /* @var \Scalr\Model\Entity\ScriptShortcut $shortcut */
                 $row['shortcuts'][] = array('id' => $shortcut->id, 'name' => $shortcut->getScriptName());
             }
         }
     }
     $this->response->data($response);
 }
Example #5
0
 /**
  * @param int $farmId
  * @param int $farmRoleId optional
  * @param string $serverId optional
  * @param int $scriptId optional
  * @param string $scriptPath optional
  * @param int $scriptIsSync
  * @param int $scriptTimeout
  * @param int $scriptVersion
  * @param array $scriptParams optional
  * @param int $shortcutId optional
  * @param int $editShortcut optional
  * @throws Exception
  */
 public function xExecuteAction($farmId, $farmRoleId = 0, $serverId = '', $scriptId = 0, $scriptPath = '', $scriptIsSync, $scriptTimeout, $scriptVersion, array $scriptParams = [], $shortcutId = null, $editShortcut = null)
 {
     $this->request->restrictAccess(Acl::RESOURCE_SCRIPTS_ENVIRONMENT, Acl::PERM_SCRIPTS_ENVIRONMENT_EXECUTE);
     if ($serverId) {
         $dbServer = DBServer::LoadByID($serverId);
         $this->user->getPermissions()->validate($dbServer);
         $target = Script::TARGET_INSTANCE;
         $serverId = $dbServer->serverId;
         $farmRoleId = $dbServer->farmRoleId;
         $farmId = $dbServer->farmId;
     } else {
         if ($farmRoleId) {
             $dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
             $this->user->getPermissions()->validate($dbFarmRole);
             $target = Script::TARGET_ROLE;
             $farmRoleId = $dbFarmRole->ID;
             $farmId = $dbFarmRole->FarmID;
         } else {
             if (!$farmId) {
                 $target = Script::TARGET_ALL;
             } else {
                 $dbFarm = DBFarm::LoadByID($farmId);
                 $this->user->getPermissions()->validate($dbFarm);
                 $target = Script::TARGET_FARM;
                 $farmId = $dbFarm->ID;
             }
         }
     }
     if ($farmId) {
         $this->request->checkPermissions(Entity\Farm::findPk($farmId), Acl::PERM_FARMS_SERVERS);
     }
     if ($scriptId) {
         $script = Script::findPk($scriptId);
         /* @var $script Script */
         if (!$script) {
             throw new Scalr_UI_Exception_NotFound();
         }
         $script->checkPermission($this->user, $this->getEnvironmentId());
     } elseif (!$scriptPath) {
         throw new Scalr_Exception_Core('scriptId or scriptPath should be set');
     }
     if (!$scriptTimeout) {
         $scriptTimeout = $scriptIsSync == 1 ? Scalr::config('scalr.script.timeout.sync') : Scalr::config('scalr.script.timeout.async');
     }
     $executeScript = true;
     if ($shortcutId && ($target != Script::TARGET_INSTANCE || $target != Script::TARGET_ALL)) {
         if ($shortcutId == -1) {
             $shortcut = new ScriptShortcut();
             $shortcut->farmId = $farmId;
         } else {
             $shortcut = ScriptShortcut::findPk($shortcutId);
             /* @var $shortcut ScriptShortcut */
             if (!$shortcut) {
                 throw new Scalr_UI_Exception_NotFound();
             }
             if ($editShortcut == 1) {
                 $executeScript = false;
             }
         }
         $shortcut->farmRoleId = $farmRoleId == 0 ? NULL : $farmRoleId;
         if ($scriptId) {
             $shortcut->scriptId = $scriptId;
             $shortcut->scriptPath = '';
         } else {
             $shortcut->scriptPath = $scriptPath;
             $shortcut->scriptId = NULL;
         }
         $shortcut->isSync = $scriptIsSync;
         $shortcut->version = $scriptVersion;
         $shortcut->timeout = $scriptTimeout;
         $shortcut->params = $scriptParams;
         $shortcut->save();
     }
     if ($executeScript) {
         switch ($target) {
             case Script::TARGET_FARM:
                 $servers = $this->db->GetAll("\n                        SELECT server_id\n                        FROM servers\n                        WHERE is_scalarized = 1 AND status IN (?,?) AND farm_id=?", [SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, $farmId]);
                 break;
             case Script::TARGET_ROLE:
                 $servers = $this->db->GetAll("\n                        SELECT server_id\n                        FROM servers\n                        WHERE is_scalarized = 1 AND status IN (?,?) AND farm_roleid=?", [SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, $farmRoleId]);
                 break;
             case Script::TARGET_INSTANCE:
                 $servers = $this->db->GetAll("\n                        SELECT server_id\n                        FROM servers\n                        WHERE is_scalarized = 1 AND status IN (?,?) AND server_id=?", [SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, $serverId]);
                 break;
             case Script::TARGET_ALL:
                 $sql = "\n                        SELECT s.server_id\n                        FROM servers s\n                        JOIN farms f ON f.id = s.farm_id\n                        WHERE s.is_scalarized = 1\n                        AND s.status IN (?,?)\n                        AND s.env_id = ?\n                        AND " . $this->request->getFarmSqlQuery(Acl::PERM_FARMS_SERVERS);
                 $args = [SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, $this->getEnvironmentId()];
                 $servers = $this->db->GetAll($sql, $args);
                 break;
         }
         $scriptSettings = array('version' => $scriptVersion, 'timeout' => $scriptTimeout, 'issync' => $scriptIsSync, 'params' => serialize($scriptParams));
         if ($scriptId) {
             $scriptSettings['scriptid'] = $scriptId;
             $scriptSettings['type'] = Scalr_Scripting_Manager::ORCHESTRATION_SCRIPT_TYPE_SCALR;
         } else {
             $scriptSettings['script_path'] = $scriptPath;
             $scriptSettings['type'] = Scalr_Scripting_Manager::ORCHESTRATION_SCRIPT_TYPE_LOCAL;
         }
         $serializer = Scalr_Messaging_JsonSerializer::getInstance();
         $cryptoTool = \Scalr::getContainer()->srzcrypto;
         // send message to start executing task (starts script)
         if (count($servers) > 0) {
             foreach ($servers as $server) {
                 $DBServer = DBServer::LoadByID($server['server_id']);
                 $msg = new Scalr_Messaging_Msg_ExecScript("Manual");
                 $msg->setServerMetaData($DBServer);
                 $script = Scalr_Scripting_Manager::prepareScript($scriptSettings, $DBServer);
                 if ($script) {
                     $DBServer->executeScript($script, $msg);
                     $this->auditLog("script.execute", $script, $DBServer);
                     $manualLog = new OrchestrationLogManualScript($script['execution_id'], $msg->serverId);
                     $manualLog->userId = $this->getUser()->getId();
                     $manualLog->userEmail = $this->getUser()->getEmail();
                     $manualLog->added = new DateTime('now', new DateTimeZone('UTC'));
                     $manualLog->save();
                 }
             }
         }
         $this->response->success('Script execution has been queued and will occur on the selected instance(s) within a couple of minutes.');
     } else {
         $this->response->success('Script shortcut successfully saved');
     }
 }
Example #6
0
 /**
  * @param   int         $farmId
  * @param   int         $expirePeriod
  * @param   bool        $manageable
  * @param   string      $owner
  * @param   int         $chefServerId
  * @param   string      $projectId
  * @param   int         $status
  * @throws  Exception
  * @throws  Scalr_Exception_Core
  * @throws  Scalr_Exception_InsufficientPermissions
  */
 public function xListFarmsAction($farmId = null, $expirePeriod = null, $manageable = false, $owner = null, $chefServerId = null, $projectId = null, $status = null)
 {
     $this->request->restrictAccess([Acl::RESOURCE_FARMS, Acl::RESOURCE_TEAM_FARMS, Acl::RESOURCE_OWN_FARMS]);
     $governance = new Scalr_Governance($this->getEnvironmentId());
     $leaseStatus = $governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE);
     $f = new Entity\Farm();
     $sql = "\n            SELECT {$f->fields('f')}, au.email AS ownerEmail,\n                (SELECT " . Entity\Farm::getUserTeamOwnershipSql($this->getUser()->id) . ") AS farmTeamIdPerm,\n                GROUP_CONCAT(DISTINCT at.name SEPARATOR ', ') AS farmTeams,\n                GROUP_CONCAT(DISTINCT behavior) AS behaviors,\n                (SELECT COUNT(*) FROM farm_roles WHERE farmid = f.id) AS rolesCnt,\n                (SELECT COUNT(*) FROM dns_zones WHERE farm_id = f.id) AS zonesCnt,\n                (SELECT COUNT(*) FROM server_alerts WHERE farm_id= f.id AND status = ?) AS alertsCnt,\n                (SELECT COUNT(*) FROM servers WHERE farm_id = f.id AND status IN (?,?,?,?,?)) AS runningServers,\n                (SELECT COUNT(*) FROM servers WHERE farm_id = f.id AND status IN (?,?)) AS suspendedServers,\n                (SELECT COUNT(*) FROM servers WHERE farm_id = f.id AND status IN (?,?)) AS nonRunningServers\n            FROM {$f->table('f')}\n            LEFT JOIN account_users au ON au.id = f.created_by_id\n            LEFT JOIN farm_teams ft ON ft.farm_id = {$f->columnId('f')}\n            LEFT JOIN account_teams at ON at.id = ft.team_id\n            LEFT JOIN farm_roles fr ON fr.farmid = {$f->columnId('f')}\n            LEFT JOIN role_behaviors rb ON rb.role_id = fr.role_id\n            WHERE {$f->columnEnvId('f')} = ?\n            AND :FILTER:\n            AND " . $this->request->getFarmSqlQuery($manageable ? Acl::PERM_FARMS_UPDATE : null);
     $args = [Entity\Server\Alert::STATUS_FAILED, Entity\Server::STATUS_PENDING, Entity\Server::STATUS_INIT, Entity\Server::STATUS_RUNNING, Entity\Server::STATUS_TEMPORARY, Entity\Server::STATUS_RESUMING, Entity\Server::STATUS_SUSPENDED, Entity\Server::STATUS_PENDING_SUSPEND, Entity\Server::STATUS_TERMINATED, Entity\Server::STATUS_PENDING_TERMINATE, $this->getEnvironmentId()];
     if ($leaseStatus && $expirePeriod) {
         $dt = new DateTime();
         $dt->add(new DateInterval('P' . $expirePeriod . 'D'));
         $sql .= " AND EXISTS (\n                        SELECT 1 FROM farm_settings\n                        WHERE farm_settings.farmid = f.id\n                        AND farm_settings.name = ?\n                        AND farm_settings.value != ''\n                        AND farm_settings.value < ?\n                    ) AND f.status = ?";
         $args[] = Entity\FarmSetting::LEASE_TERMINATE_DATE;
         $args[] = $dt->format('Y-m-d H:i:s');
         $args[] = Entity\Farm::STATUS_RUNNING;
     }
     if ($farmId) {
         $sql .= ' AND f.id = ?';
         $args[] = $farmId;
     }
     if ($owner) {
         if ($owner == 'me') {
             $sql .= " AND {$f->columnOwnerId('f')} = ?";
             $args[] = $this->getUser()->id;
         } else {
             if ($owner == 'team') {
                 $sql .= " AND " . Entity\Farm::getUserTeamOwnershipSql($this->getUser()->id);
             }
         }
     }
     if ($chefServerId) {
         $sql .= " AND f.id IN (\n                SELECT fr.farmid\n                FROM farm_roles fr\n                INNER JOIN farm_role_settings frs1 ON fr.id = frs1.farm_roleid AND frs1.name = ? AND frs1.value = ?\n                INNER JOIN farm_role_settings frs2 ON fr.id = frs2.farm_roleid AND frs2.name = ? AND frs2.value = ?\n            )";
         $args[] = \Scalr_Role_Behavior_Chef::ROLE_CHEF_SERVER_ID;
         $args[] = $chefServerId;
         $args[] = \Scalr_Role_Behavior_Chef::ROLE_CHEF_BOOTSTRAP;
         $args[] = 1;
     }
     if ($this->getContainer()->analytics->enabled && $projectId) {
         $sql .= " AND EXISTS (\n                SELECT 1 FROM farm_settings\n                WHERE farm_settings.farmid = f.id\n                AND farm_settings.name = " . $this->db->qstr(Entity\FarmSetting::PROJECT_ID) . "\n                AND farm_settings.value = ?) ";
         $args[] = $projectId;
     }
     $sql .= " GROUP BY {$f->columnId('f')}";
     $response = $this->buildResponseFromSql2($sql, array('id', 'name', 'dtadded', 'ownerEmail', 'status'), array('f.name', 'f.id', 'f.comments'), $args);
     foreach ($response["data"] as &$r) {
         $farm = new Entity\Farm();
         $farm->load($r);
         $row = get_object_vars($farm);
         $row['ownerEmail'] = $r['ownerEmail'];
         $row['farmTeams'] = $r['farmTeams'];
         $row['behaviors'] = $r['behaviors'];
         $row['rolesCnt'] = $r['rolesCnt'];
         $row['zonesCnt'] = $r['zonesCnt'];
         $row['alertsCnt'] = $r['alertsCnt'];
         $row['runningServers'] = $r['runningServers'];
         $row['suspendedServers'] = $r['suspendedServers'];
         $row['nonRunningServers'] = $r['nonRunningServers'];
         $row['added'] = Scalr_Util_DateTime::convertTz($farm->added);
         $row['lock'] = $farm->settings[Entity\FarmSetting::LOCK];
         if ($row['lock']) {
             try {
                 $farm->checkLocked();
             } catch (\Scalr\Exception\LockedException $e) {
                 $row['lockComment'] = $e->getMessage();
             }
         }
         if ($leaseStatus && $farm->settings[Entity\FarmSetting::LEASE_STATUS]) {
             $row['lease'] = $farm->settings[Entity\FarmSetting::LEASE_NOTIFICATION_SEND] ? 'Expire' : $farm->settings[Entity\FarmSetting::LEASE_STATUS];
             if ($row['lease'] == 'Expire') {
                 $dt = new DateTime();
                 $td = new DateTime($farm->settings[Entity\FarmSetting::LEASE_TERMINATE_DATE]);
                 $days = 0;
                 $hours = 1;
                 $interval = $dt->diff($td);
                 if ($interval) {
                     $days = $interval->days;
                     $hours = $interval->h ? $interval->h : 1;
                 }
                 $row['leaseMessage'] = sprintf('Your farm lease is about to expire in %d %s, after which this farm will be terminated', $days ? $days : $hours, $days ? $days > 1 ? 'days' : 'day' : ($hours > 1 ? 'hours' : 'hour'));
             }
         }
         $behaviors = explode(',', $row['behaviors']);
         $row["havemysqlrole"] = in_array(ROLE_BEHAVIORS::MYSQL, $behaviors);
         $row["havemysql2role"] = in_array(ROLE_BEHAVIORS::MYSQL2, $behaviors);
         $row["havepgrole"] = in_array(ROLE_BEHAVIORS::POSTGRESQL, $behaviors);
         $row["haveredisrole"] = in_array(ROLE_BEHAVIORS::REDIS, $behaviors);
         $row["haverabbitmqrole"] = in_array(ROLE_BEHAVIORS::RABBITMQ, $behaviors);
         $row["havemongodbrole"] = in_array(ROLE_BEHAVIORS::MONGODB, $behaviors);
         $row["haveperconarole"] = in_array(ROLE_BEHAVIORS::PERCONA, $behaviors);
         $row["havemariadbrole"] = in_array(ROLE_BEHAVIORS::MARIADB, $behaviors);
         $row['statusTxt'] = Entity\Farm::getStatusName($farm->status);
         if ($row['status'] == Entity\Farm::STATUS_RUNNING) {
             $row['shortcuts'] = [];
             foreach (\Scalr\Model\Entity\ScriptShortcut::find([['farmId' => $farm->id], ['farmRoleId' => null]]) as $shortcut) {
                 /* @var $shortcut \Scalr\Model\Entity\ScriptShortcut */
                 $row['shortcuts'][] = array('id' => $shortcut->id, 'name' => $shortcut->getScriptName());
             }
         }
         $row['farmOwnerIdPerm'] = $farm->ownerId && $this->getUser()->id == $farm->ownerId;
         $row['farmTeamIdPerm'] = !!$r['farmTeamIdPerm'];
         $r = $row;
     }
     $this->response->data($response);
 }
Example #7
0
 public function xListFarmsAction()
 {
     $this->request->restrictFarmAccess();
     $this->request->defineParams(array('clientId' => array('type' => 'int'), 'farmId' => array('type' => 'int'), 'sort' => array('type' => 'json'), 'expirePeriod' => array('type' => 'int')));
     $governance = new Scalr_Governance($this->getEnvironmentId());
     $leaseStatus = $governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE);
     $sql = 'SELECT f.clientid, f.id, f.name, f.status, f.dtadded, f.created_by_id, f.created_by_email, ats.name AS team_name, ats.description AS team_description, ats.id as team_id FROM farms f LEFT JOIN account_teams ats ON ats.id = f.team_id WHERE env_id = ? AND :FILTER:';
     $args = array($this->getEnvironmentId());
     if ($leaseStatus && $this->getParam('expirePeriod')) {
         $dt = new DateTime();
         $dt->add(new DateInterval('P' . $this->getParam('expirePeriod') . 'D'));
         $sql = str_replace('FROM farms f', 'FROM farms f LEFT JOIN farm_settings fs ON f.id = fs.farmid', $sql);
         $sql = str_replace('WHERE', 'WHERE fs.name = ? AND fs.value < ? AND fs.value != "" AND f.status = ? AND', $sql);
         array_unshift($args, Entity\FarmSetting::LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'), FARM_STATUS::RUNNING);
     }
     if ($this->getParam('farmId')) {
         $sql .= ' AND f.id = ?';
         $args[] = $this->getParam('farmId');
     }
     if ($this->getParam('clientId')) {
         $sql .= ' AND clientid = ?';
         $args[] = $this->getParam('clientId');
     }
     if ($this->getParam('status') != '') {
         $sql .= ' AND status = ?';
         $args[] = $this->getParam('status');
     }
     $owner = $this->getParam('owner');
     $permission = $this->getParam('manageable') ? Acl::PERM_FARMS_MANAGE : null;
     $allowedResourceFarms = $this->request->isAllowed(Acl::RESOURCE_FARMS, $permission);
     if (!$allowedResourceFarms || $owner) {
         $q = [];
         if (($this->request->isAllowed(Acl::RESOURCE_TEAM_FARMS, $permission) || $allowedResourceFarms) && ($owner == '' || $owner == 'team')) {
             $t = array_map(function ($t) {
                 return $t['id'];
             }, $this->user->getTeams());
             if (count($t)) {
                 $q[] = 'team_id IN(' . join(',', $t) . ')';
             }
         }
         if (($this->request->isAllowed(Acl::RESOURCE_OWN_FARMS, $permission) || $allowedResourceFarms) && ($owner == '' || $owner == 'me')) {
             $q[] = 'created_by_id = ?';
             $args[] = $this->request->getUser()->getId();
         }
         if (count($q)) {
             $sql .= ' AND (' . join(' OR ', $q) . ')';
         } else {
             $sql .= ' AND false';
             // no permissions
         }
     }
     if ($this->getParam('chefServerId')) {
         $sql .= ' AND f.id IN (
             SELECT fr.farmid
             FROM farm_roles fr
             INNER JOIN farm_role_settings frs1 ON fr.id = frs1.farm_roleid AND frs1.name = ? AND frs1.value = ?
             INNER JOIN farm_role_settings frs2 ON fr.id = frs2.farm_roleid AND frs2.name = ? AND frs2.value = ?
         )';
         $args[] = \Scalr_Role_Behavior_Chef::ROLE_CHEF_SERVER_ID;
         $args[] = (int) $this->getParam('chefServerId');
         $args[] = \Scalr_Role_Behavior_Chef::ROLE_CHEF_BOOTSTRAP;
         $args[] = 1;
     }
     if ($this->getContainer()->analytics->enabled) {
         if ($this->getParam('projectId')) {
             $sql .= " AND EXISTS (\n                    SELECT 1 FROM farm_settings\n                    WHERE farm_settings.farmid = f.id\n                    AND farm_settings.name = " . $this->db->qstr(Entity\FarmSetting::PROJECT_ID) . "\n                    AND farm_settings.value = ?) ";
             $args[] = $this->getParam('projectId');
         }
     }
     $response = $this->buildResponseFromSql2($sql, array('id', 'name', 'dtadded', 'created_by_email', 'status', 'team_name'), array('f.name', 'f.id', 'f.comments'), $args);
     foreach ($response["data"] as &$row) {
         $servers = $this->db->GetRow("\n                SELECT SUM(IF(`status` IN (?,?,?,?,?),1,0)) AS running_servers,\n                    SUM(IF(`status` IN (?,?),1,0)) AS suspended_servers,\n                    SUM(IF(`status` IN (?,?),1,0)) AS non_running_servers\n                FROM `servers` WHERE `farm_id` = ?\n            ", [Entity\Server::STATUS_PENDING, Entity\Server::STATUS_INIT, Entity\Server::STATUS_RUNNING, Entity\Server::STATUS_TEMPORARY, Entity\Server::STATUS_RESUMING, Entity\Server::STATUS_SUSPENDED, Entity\Server::STATUS_PENDING_SUSPEND, Entity\Server::STATUS_TERMINATED, Entity\Server::STATUS_PENDING_TERMINATE, $row['id']]);
         if (is_null($servers['running_servers'])) {
             $servers = ['running_servers' => 0, 'suspended_servers' => 0, 'non_running_servers' => 0];
         }
         $row = array_merge($row, $servers);
         $row["roles"] = $this->db->GetOne("SELECT COUNT(*) FROM farm_roles WHERE farmid='{$row['id']}'");
         $row["zones"] = $this->db->GetOne("SELECT COUNT(*) FROM dns_zones WHERE farm_id='{$row['id']}'");
         //TODO: Use Alerts class
         $row['alerts'] = $this->db->GetOne("SELECT COUNT(*) FROM server_alerts WHERE farm_id='{$row['id']}' AND status='failed'");
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row["dtadded"], 'M j, Y H:i');
         $dbFarm = DBFarm::LoadByID($row['id']);
         $row['lock'] = $dbFarm->GetSetting(Entity\FarmSetting::LOCK);
         if ($row['lock']) {
             $row['lock_comment'] = $dbFarm->isLocked(false);
         }
         if ($leaseStatus && $dbFarm->GetSetting(Entity\FarmSetting::LEASE_STATUS)) {
             $row['lease'] = $dbFarm->GetSetting(Entity\FarmSetting::LEASE_NOTIFICATION_SEND) ? 'Expire' : $dbFarm->GetSetting(Entity\FarmSetting::LEASE_STATUS);
             if ($row['lease'] == 'Expire') {
                 $dt = new DateTime();
                 $td = new DateTime($dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE));
                 $days = 0;
                 $hours = 1;
                 $interval = $dt->diff($td);
                 if ($interval) {
                     $days = $interval->days;
                     $hours = $interval->h ? $interval->h : 1;
                 }
                 $row['leaseMessage'] = sprintf('Your farm lease is about to expire in %d %s, after which this farm will be terminated', $days ? $days : $hours, $days ? $days > 1 ? 'days' : 'day' : ($hours > 1 ? 'hours' : 'hour'));
             }
         }
         $b = (array) $this->db->GetAll("SELECT DISTINCT(behavior) FROM farm_roles\n                INNER JOIN role_behaviors ON role_behaviors.role_id = farm_roles.role_id WHERE farmid = ?", array($row['id']));
         $behaviors = array();
         foreach ($b as $behavior) {
             $behaviors[] = $behavior['behavior'];
         }
         $row["havemysqlrole"] = in_array(ROLE_BEHAVIORS::MYSQL, $behaviors);
         $row["havemysql2role"] = in_array(ROLE_BEHAVIORS::MYSQL2, $behaviors);
         $row["havepgrole"] = in_array(ROLE_BEHAVIORS::POSTGRESQL, $behaviors);
         $row["haveredisrole"] = in_array(ROLE_BEHAVIORS::REDIS, $behaviors);
         $row["haverabbitmqrole"] = in_array(ROLE_BEHAVIORS::RABBITMQ, $behaviors);
         $row["havemongodbrole"] = in_array(ROLE_BEHAVIORS::MONGODB, $behaviors);
         $row["haveperconarole"] = in_array(ROLE_BEHAVIORS::PERCONA, $behaviors);
         $row["havemariadbrole"] = in_array(ROLE_BEHAVIORS::MARIADB, $behaviors);
         $row['status_txt'] = FARM_STATUS::GetStatusName($row['status']);
         if ($row['status'] == FARM_STATUS::RUNNING) {
             $row['shortcuts'] = [];
             foreach (\Scalr\Model\Entity\ScriptShortcut::find([['farmId' => $row['id']], ['farmRoleId' => null]]) as $shortcut) {
                 /* @var $shortcut \Scalr\Model\Entity\ScriptShortcut */
                 $row['shortcuts'][] = array('id' => $shortcut->id, 'name' => $shortcut->getScriptName());
             }
         }
         $row['farmTeamIdPerm'] = $row['team_id'] && $this->user->isInTeam($row['team_id']);
         $row['farmOwnerIdPerm'] = $row['created_by_id'] && $this->user->getId() == $row['created_by_id'];
     }
     $this->response->data($response);
 }
Example #8
0
 /**
  * @param int $farmId
  * @param int $farmRoleId optional
  * @param string $serverId optional
  * @param int $scriptId optional
  * @param string $scriptPath optional
  * @param int $scriptIsSync
  * @param int $scriptTimeout
  * @param int $scriptVersion
  * @param array $scriptParams optional
  * @param int $shortcutId optional
  * @param int $editShortcut optional
  * @throws Exception
  */
 public function xExecuteAction($farmId, $farmRoleId = 0, $serverId = '', $scriptId = 0, $scriptPath = '', $scriptIsSync, $scriptTimeout, $scriptVersion, array $scriptParams = [], $shortcutId = null, $editShortcut = null)
 {
     $this->request->restrictAccess(Acl::RESOURCE_ADMINISTRATION_SCRIPTS, Acl::PERM_ADMINISTRATION_SCRIPTS_EXECUTE);
     if ($serverId) {
         $dbServer = DBServer::LoadByID($serverId);
         $this->user->getPermissions()->validate($dbServer);
         $target = Script::TARGET_INSTANCE;
         $serverId = $dbServer->serverId;
         $farmRoleId = $dbServer->farmRoleId;
         $farmId = $dbServer->farmId;
     } else {
         if ($farmRoleId) {
             $dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
             $this->user->getPermissions()->validate($dbFarmRole);
             $target = Script::TARGET_ROLE;
             $farmRoleId = $dbFarmRole->ID;
             $farmId = $dbFarmRole->FarmID;
         } else {
             if (!$farmId) {
                 $target = Script::TARGET_ALL;
             } else {
                 $dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
                 $this->user->getPermissions()->validate($dbFarm);
                 $target = Script::TARGET_FARM;
                 $farmId = $dbFarm->ID;
             }
         }
     }
     if ($scriptId) {
         $script = Script::findPk($scriptId);
         /* @var Script $script */
         if (!$script) {
             throw new Scalr_UI_Exception_NotFound();
         }
         $script->checkPermission($this->user, $this->getEnvironmentId());
     } elseif (!$scriptPath) {
         throw new Scalr_Exception_Core('scriptId or scriptPath should be set');
     }
     if (!$scriptTimeout) {
         $scriptTimeout = $scriptIsSync == 1 ? Scalr::config('scalr.script.timeout.sync') : Scalr::config('scalr.script.timeout.async');
     }
     $executeScript = true;
     if ($shortcutId && ($target != Script::TARGET_INSTANCE || $target != Script::TARGET_ALL)) {
         if ($shortcutId == -1) {
             $shortcut = new ScriptShortcut();
             $shortcut->farmId = $farmId;
         } else {
             $shortcut = ScriptShortcut::findPk($shortcutId);
             /* @var ScriptShortcut $shortcut */
             if (!$shortcut) {
                 throw new Scalr_UI_Exception_NotFound();
             }
             if ($editShortcut == 1) {
                 $executeScript = false;
             }
         }
         $shortcut->farmRoleId = $farmRoleId == 0 ? NULL : $farmRoleId;
         if ($scriptId) {
             $shortcut->scriptId = $scriptId;
             $shortcut->scriptPath = '';
         } else {
             $shortcut->scriptPath = $scriptPath;
             $shortcut->scriptId = NULL;
         }
         $shortcut->isSync = $scriptIsSync;
         $shortcut->version = $scriptVersion;
         $shortcut->timeout = $scriptTimeout;
         $shortcut->params = $scriptParams;
         $shortcut->save();
     }
     if ($executeScript) {
         switch ($target) {
             case Script::TARGET_FARM:
                 $servers = $this->db->GetAll("SELECT server_id FROM servers WHERE status IN (?,?) AND farm_id=?", array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, $farmId));
                 break;
             case Script::TARGET_ROLE:
                 $servers = $this->db->GetAll("SELECT server_id FROM servers WHERE status IN (?,?) AND farm_roleid=?", array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, $farmRoleId));
                 break;
             case Script::TARGET_INSTANCE:
                 $servers = $this->db->GetAll("SELECT server_id FROM servers WHERE status IN (?,?) AND server_id=?", array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, $serverId));
                 break;
             case Script::TARGET_ALL:
                 $servers = $this->db->GetAll("SELECT server_id FROM servers WHERE status IN (?,?) AND env_id = ?", array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING, $this->getEnvironmentId()));
                 break;
         }
         $scriptSettings = array('version' => $scriptVersion, 'timeout' => $scriptTimeout, 'issync' => $scriptIsSync, 'params' => serialize($scriptParams));
         if ($scriptId) {
             $scriptSettings['scriptid'] = $scriptId;
             $scriptSettings['type'] = Scalr_Scripting_Manager::ORCHESTRATION_SCRIPT_TYPE_SCALR;
         } else {
             $scriptSettings['script_path'] = $scriptPath;
             $scriptSettings['type'] = Scalr_Scripting_Manager::ORCHESTRATION_SCRIPT_TYPE_LOCAL;
         }
         $serializer = Scalr_Messaging_JsonSerializer::getInstance();
         $cryptoTool = Scalr_Messaging_CryptoTool::getInstance();
         // send message to start executing task (starts script)
         if (count($servers) > 0) {
             foreach ($servers as $server) {
                 $DBServer = DBServer::LoadByID($server['server_id']);
                 $msg = new Scalr_Messaging_Msg_ExecScript("Manual");
                 $msg->setServerMetaData($DBServer);
                 $script = Scalr_Scripting_Manager::prepareScript($scriptSettings, $DBServer);
                 $itm = new stdClass();
                 // Script
                 $itm->asynchronous = $script['issync'] == 1 ? '0' : '1';
                 $itm->timeout = $script['timeout'];
                 if ($script['body']) {
                     $itm->name = $script['name'];
                     $itm->body = $script['body'];
                 } else {
                     $itm->path = $script['path'];
                     $itm->name = "local-" . crc32($script['path']) . mt_rand(100, 999);
                 }
                 $itm->executionId = $script['execution_id'];
                 $msg->scripts = array($itm);
                 $msg->setGlobalVariables($DBServer, true);
                 /*
                                     if ($DBServer->IsSupported('2.5.12')) {
                 $DBServer->scalarizr->system->executeScripts(
                     $msg->scripts,
                     $msg->globalVariables,
                     $msg->eventName,
                     $msg->roleName
                 );
                                     } else
                 */
                 $DBServer->SendMessage($msg, false, true);
             }
         }
         $this->response->success('Script execution has been queued and will occur on the selected instance(s) within a couple of minutes.');
     } else {
         $this->response->success('Script shortcut successfully saved');
     }
 }