convertTz() public static method

Converts Time according to timezone settings of current user.
public static convertTz ( DateTime | string | integer $value, string $format = 'M j, Y H:i:s' ) : string
$value DateTime | string | integer DateTime object or Unix Timestamp or string that represents time.
$format string Format
return string Returns updated time in given format.
示例#1
0
 public function xGetListAction()
 {
     $this->request->defineParams(array('query', 'sort' => array('type' => 'json')));
     $hist = new WebhookHistory();
     $sql = "SELECT " . $hist->fields('h') . ", w.name AS webhookName, e.url\n                FROM " . $hist->table() . " h\n                INNER JOIN webhook_endpoints e ON h.endpoint_id = e.endpoint_id\n                INNER JOIN webhook_configs w ON h.webhook_id = w.webhook_id\n                WHERE e.env_id = ?\n                AND :FILTER:\n        ";
     $args = array($this->getEnvironmentId());
     if ($this->getParam('eventId')) {
         $sql .= ' AND h.event_id = ?';
         $args[] = $this->getParam('eventId');
     }
     $response = $this->buildResponseFromSql2($sql, array('created'), array('e.url', 'h.event_type'), $args);
     foreach ($response['data'] as $index => $row) {
         $hist = new WebhookHistory();
         $hist->load($row);
         $item = array();
         foreach (get_object_vars($hist) as $k => $v) {
             $item[$k] = $v;
         }
         $item['url'] = $row['url'];
         $item['webhookName'] = $row['webhookName'];
         $item['created'] = Scalr_Util_DateTime::convertTz($hist->created);
         unset($hist);
         $response['data'][$index] = $item;
     }
     $this->response->data($response);
 }
示例#2
0
 public function xListTasksAction()
 {
     $this->request->defineParams(array('bundleTaskId' => array('type' => 'int'), 'sort' => array('type' => 'json', 'default' => array('property' => 'id', 'direction' => 'DESC'))));
     $sql = "SELECT * FROM bundle_tasks WHERE env_id = ?";
     $args = array($this->getEnvironmentId());
     if ($this->getParam('id') > 0) {
         $sql .= " AND id = ?";
         $args[] = $this->getParam('bundleTaskId');
     }
     $response = $this->buildResponseFromSql2($sql, array('id', 'server_id', 'rolename', 'status', 'os_family', 'dtadded', 'dtstarted', 'created_by_email'), array(), $args);
     foreach ($response["data"] as &$row) {
         $row['server_exists'] = DBServer::IsExists($row['server_id']);
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row['dtadded']);
         if (!$row['bundle_type']) {
             $row['bundle_type'] = "*";
         }
         if ($row['dtfinished'] && $row['dtstarted']) {
             $row['duration'] = Scalr_Util_DateTime::getDateTimeDiff($row['dtfinished'], $row['dtstarted']);
         }
         if ($row['dtfinished']) {
             $row['dtfinished'] = Scalr_Util_DateTime::convertTz($row['dtfinished']);
         }
         if ($row['dtstarted']) {
             $row['dtstarted'] = Scalr_Util_DateTime::convertTz($row['dtstarted']);
         }
     }
     $this->response->data($response);
 }
示例#3
0
文件: Tasks.php 项目: mheydt/scalr
 public function xListTasksAction()
 {
     $this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
     $sql = "\n            SELECT\n                dt.id, dma.name AS application_name, servers.index AS server_index, farms.name AS farm_name, roles.name AS role_name,\n                dt.status AS status, dt.dtadded AS dtadded\n            FROM dm_deployment_tasks dt\n            LEFT JOIN dm_applications dma ON dt.dm_application_id = dma.id\n            LEFT JOIN servers ON servers.id = dt.server_id\n            LEFT JOIN farms ON servers.farm_id = farms.id\n            LEFT JOIN roles ON servers.farm_roleid = roles.id\n            WHERE dt.`status` != ? AND dt.env_id = ?\n        ";
     $args = array(Scalr_Dm_DeploymentTask::STATUS_ARCHIVED, $this->getEnvironmentId());
     list($sql, $args) = $this->request->prepareFarmSqlQuery($sql, $args, 'farms');
     $response = $this->buildResponseFromSql2($sql, array('id', 'application_name', 'farm_name', 'role_name', 'server_index', 'status', 'dtadded', 'dtdeployed'), array(), $args);
     foreach ($response["data"] as $k => $row) {
         $data = false;
         try {
             $deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
             $application = $deploymentTask->getApplication();
             try {
                 $dbServer = DBServer::LoadByID($deploymentTask->serverId);
                 $serverIndex = $dbServer->index;
             } catch (Exception $e) {
             }
             $data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
             try {
                 $dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
                 $data['farm_roleid'] = $dbFarmRole->ID;
                 $data['role_name'] = $dbFarmRole->GetRoleObject()->name;
                 $data['farm_id'] = $dbFarmRole->FarmID;
                 $data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
             } catch (Exception $e) {
             }
         } catch (Exception $e) {
         }
         $response["data"][$k] = $data;
     }
     $this->response->data($response);
 }
示例#4
0
文件: Images.php 项目: rickb838/scalr
 /**
  * @param string $query
  * @param string $platform
  * @param string $cloudLocation
  * @param JsonData $sort
  * @param int $start
  * @param int $limit
  * @throws Exception
  */
 public function xListAction($query = null, $platform = null, $cloudLocation = null, JsonData $sort, $start = 0, $limit = 20)
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES);
     $criteria = [];
     $criteria[] = ['envId' => $this->getEnvironmentId()];
     if ($query) {
         $querySql = '%' . $query . '%';
         $criteria[] = ['$or' => [['id' => ['$like' => $querySql]]]];
     }
     if ($platform) {
         $criteria[] = ['platform' => $platform];
     }
     if ($cloudLocation) {
         $criteria[] = ['cloudLocation' => $cloudLocation];
     }
     $result = Image::find($criteria, \Scalr\UI\Utils::convertOrder($sort, ['id' => 'ASC'], ['id', 'platform', 'cloudLocation', 'os', 'dtAdded', 'architecture', 'source']), $limit, $start, true);
     $data = [];
     foreach ($result as $image) {
         /* @var Image $image */
         $s = get_object_vars($image);
         $s['dtAdded'] = Scalr_Util_DateTime::convertTz($image->dtAdded);
         $s['status'] = $image->isUsed() ? 'In use' : 'Not used';
         $data[] = $s;
     }
     $this->response->data(['total' => $result->totalNumber, 'data' => $data]);
 }
示例#5
0
 public function xListTasksAction()
 {
     $this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
     $sql = "SELECT id FROM dm_deployment_tasks WHERE status !='" . Scalr_Dm_DeploymentTask::STATUS_ARCHIVED . "' AND env_id = '{$this->getEnvironmentId()}'";
     $response = $this->buildResponseFromSql($sql, array("id"));
     foreach ($response["data"] as $k => $row) {
         $data = false;
         try {
             $deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
             $application = $deploymentTask->getApplication();
             try {
                 $dbServer = DBServer::LoadByID($deploymentTask->serverId);
                 $serverIndex = $dbServer->index;
             } catch (Exception $e) {
             }
             $data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
             try {
                 $dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
                 $data['farm_roleid'] = $dbFarmRole->ID;
                 $data['role_name'] = $dbFarmRole->GetRoleObject()->name;
                 $data['farm_id'] = $dbFarmRole->FarmID;
                 $data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
             } catch (Exception $e) {
             }
         } catch (Exception $e) {
         }
         $response["data"][$k] = $data;
     }
     $this->response->data($response);
 }
示例#6
0
 public function getAccountEnvironmentsList()
 {
     $environments = $this->user->getEnvironments();
     $result = array();
     foreach ($environments as &$row) {
         $env = Scalr_Environment::init()->loadById($row['id']);
         $row['platforms'] = $env->getEnabledPlatforms();
         $row['teams'] = array();
         if ($this->getContainer()->config->get('scalr.auth_mode') == 'ldap') {
             $row['teamIds'] = array();
         }
         foreach ($env->getTeams() as $teamId) {
             if ($this->getContainer()->config->get('scalr.auth_mode') == 'ldap') {
                 $team = new Scalr_Account_Team();
                 $team->loadById($teamId);
                 $row['teams'][] = $team->name;
                 $row['teamIds'][] = $teamId;
             } else {
                 $row['teams'][] = $teamId;
             }
         }
         $row['dtAdded'] = Scalr_Util_DateTime::convertTz($env->dtAdded);
         $row['status'] = $env->status;
         if ($this->getContainer()->analytics->enabled) {
             $row['ccId'] = $env->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID);
         }
         $result[] =& $row;
     }
     return $result;
 }
示例#7
0
文件: Backups.php 项目: recipe/scalr
 private function getBackupDetails($backupId)
 {
     $links = array();
     $backup = Scalr_Db_Backup::init()->loadById($backupId);
     $this->user->getPermissions()->validate($backup);
     $data = array('backup_id' => $backup->id, 'farm_id' => $backup->farmId, 'type' => ROLE_BEHAVIORS::GetName($backup->service) ? ROLE_BEHAVIORS::GetName($backup->service) : 'unknown', 'date' => Scalr_Util_DateTime::convertTz($backup->dtCreated), 'size' => $backup->size ? round($backup->size / 1024 / 1024, 2) : 0, 'provider' => $backup->provider, 'cloud_location' => $backup->cloudLocation, 'farmName' => DBFarm::LoadByIDOnlyName($backup->farmId));
     $downloadParts = $backup->getParts();
     foreach ($downloadParts as $part) {
         $part['size'] = $part['size'] ? round($part['size'] / 1024 / 1024, 2) : '';
         if ($part['size'] == 0) {
             $part['size'] = 0.01;
         }
         if ($data['provider'] == 's3') {
             $part['link'] = $this->getS3SignedUrl($part['path']);
         } else {
             if ($data['provider'] == 'cf') {
                 if ($backup->platform == SERVER_PLATFORMS::RACKSPACE) {
                     $part['link'] = $this->getCfSignedUrl($part['path'], $data['cloud_location'], $backup->platform);
                 } else {
                     $part['link'] = "swift://{$part['path']}";
                 }
             } else {
                 continue;
             }
         }
         $part['path'] = pathinfo($part['path']);
         $links[$part['number']] = $part;
     }
     $data['links'] = $links;
     return $data;
 }
示例#8
0
 public function xListTasksAction()
 {
     $this->request->defineParams(array('bundleTaskId' => array('type' => 'int'), 'sort' => array('type' => 'string', 'default' => 'id'), 'dir' => array('type' => 'string', 'default' => 'DESC')));
     $sql = "SELECT * FROM bundle_tasks WHERE env_id = '" . $this->getEnvironmentId() . "'";
     if ($this->getParam('id') > 0) {
         $sql .= " AND id = " . $this->db->qstr($this->getParam('bundleTaskId'));
     }
     $response = $this->buildResponseFromSql($sql, array("server_id", "rolename", "failure_reason", "snapshot_id", "id"));
     foreach ($response["data"] as &$row) {
         $row['server_exists'] = DBServer::IsExists($row['server_id']);
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row['dtadded']);
         if (!$row['bundle_type']) {
             $row['bundle_type'] = "*";
         }
         if ($row['dtfinished'] && $row['dtstarted']) {
             $row['duration'] = Scalr_Util_DateTime::getDateTimeDiff($row['dtfinished'], $row['dtstarted']);
         }
         if ($row['dtfinished']) {
             $row['dtfinished'] = Scalr_Util_DateTime::convertTz($row['dtfinished']);
         }
         if ($row['dtstarted']) {
             $row['dtstarted'] = Scalr_Util_DateTime::convertTz($row['dtstarted']);
         }
     }
     $this->response->data($response);
 }
示例#9
0
文件: Events.php 项目: recipe/scalr
 public function xListEventsAction()
 {
     $this->request->defineParams(array('farmId' => array('type' => 'int'), 'eventServerId', 'eventId', 'query' => array('type' => 'string'), 'sort' => array('type' => 'string', 'default' => 'id'), 'dir' => array('type' => 'string', 'default' => 'DESC')));
     $sql = "SELECT farmid, message, type, dtadded, event_server_id, event_id FROM events WHERE farmid='{$this->dbFarm->ID}'";
     if ($this->getParam('eventServerId')) {
         $sql .= " AND event_server_id = " . $this->db->qstr($this->getParam('eventServerId'));
     }
     if ($this->getParam('eventId')) {
         $sql .= " AND event_id = " . $this->db->qstr($this->getParam('eventId'));
     }
     $response = $this->buildResponseFromSql($sql, array("message", "type", "dtadded", "event_server_id", "event_id"));
     $cache = array();
     foreach ($response['data'] as &$row) {
         $row['message'] = nl2br($row['message']);
         $row["dtadded"] = Scalr_Util_DateTime::convertTz($row["dtadded"]);
         $row['scripts'] = $this->db->GetOne("SELECT COUNT(*) FROM scripting_log WHERE event_id = ?", array($row['event_id']));
         if ($row['event_server_id']) {
             $esInfo = $this->db->GetRow("SELECT role_id, farm_roleid, `index`, farm_id FROM servers WHERE server_id = ? LIMIT 1", array($row['event_server_id']));
             if ($esInfo) {
                 if (!$cache['farm_names'][$esInfo['farm_id']]) {
                     $cache['farm_names'][$esInfo['farm_id']] = $this->db->GetOne("SELECT name FROM farms WHERE id=?", array($esInfo['farm_id']));
                 }
                 $row['event_farm_name'] = $cache['farm_names'][$esInfo['farm_id']];
                 $row['event_farm_id'] = $esInfo['farm_id'];
                 $row['event_farm_roleid'] = $esInfo['farm_roleid'];
                 if (!$cache['role_names'][$esInfo['role_id']]) {
                     $cache['role_names'][$esInfo['role_id']] = $this->db->GetOne("SELECT name FROM roles WHERE id=?", array($esInfo['role_id']));
                 }
                 $row['event_role_name'] = $cache['role_names'][$esInfo['role_id']];
                 $row['event_server_index'] = $esInfo['index'];
             }
         }
     }
     $this->response->data($response);
 }
示例#10
0
文件: Script.php 项目: recipe/scalr
 /**
  * @return array
  */
 public function getRevisions()
 {
     $revisions = $this->db->GetAll("SELECT id, revision, script, dtcreated as dtCreated, variables FROM script_revisions WHERE scriptid=? ORDER BY revision DESC", array($this->id));
     foreach ($revisions as $index => $rev) {
         $revisions[$index]['dtCreated'] = Scalr_Util_DateTime::convertTz($rev['dtCreated']);
         $revisions[$index]['variables'] = unserialize($revisions[$index]['variables']);
     }
     return $revisions;
 }
示例#11
0
文件: Accounts.php 项目: mheydt/scalr
 public function xListAccountsAction()
 {
     $this->request->defineParams(array('sort' => array('type' => 'json'), 'accountId' => array('type' => 'int')));
     $sql = "SELECT id, name, dtadded, status FROM clients WHERE :FILTER:";
     $args = array();
     if ($this->getParam('serverId')) {
         $sql .= " AND `id` IN (SELECT `client_id` FROM `servers_history` WHERE `server_id` = ?)";
         $args[] = $this->getParam('serverId');
     }
     if ($this->getParam('farmId')) {
         $sql .= ' AND id IN (SELECT clientid FROM farms WHERE id = ?)';
         $args[] = $this->getParam('farmId');
     }
     if ($this->getParam('owner')) {
         $sql .= ' AND id IN (SELECT account_id FROM account_users WHERE `type` = ? AND email LIKE ?)';
         $args[] = Scalr_Account_User::TYPE_ACCOUNT_OWNER;
         $args[] = '%' . $this->getParam('owner') . '%';
     }
     if ($this->getParam('user')) {
         $sql .= ' AND id IN (SELECT account_id FROM account_users WHERE email LIKE ?)';
         $args[] = '%' . $this->getParam('user') . '%';
     }
     if ($this->getParam('envId')) {
         $sql .= ' AND id IN (SELECT client_id FROM client_environments WHERE id = ?)';
         $args[] = $this->getParam('envId');
     }
     $response = $this->buildResponseFromSql2($sql, array('id', 'name', 'dtadded', 'status'), array('id', 'name'), $args);
     foreach ($response['data'] as &$row) {
         $account = Scalr_Account::init()->loadById($row['id']);
         try {
             $owner = $account->getOwner();
             $row['ownerEmail'] = $owner->getEmail();
             $row['ownerLocked'] = $owner->status == User::STATUS_INACTIVE;
         } catch (Exception $e) {
             $row['ownerEmail'] = '*No owner*';
         }
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row['dtadded']);
         $row['isTrial'] = (int) $account->getSetting(Scalr_Account::SETTING_IS_TRIAL);
         $limit = Scalr_Limits::init()->Load(Scalr_Limits::ACCOUNT_ENVIRONMENTS, $row['id']);
         $row['envs'] = $limit->getCurrentUsage();
         $row['limitEnvs'] = $limit->getLimitValue() > -1 ? $limit->getLimitValue() : '-';
         $limit = Scalr_Limits::init()->Load(Scalr_Limits::ACCOUNT_FARMS, $row['id']);
         $row['farms'] = $limit->getCurrentUsage();
         $row['limitFarms'] = $limit->getLimitValue() > -1 ? $limit->getLimitValue() : '-';
         $limit = Scalr_Limits::init()->Load(Scalr_Limits::ACCOUNT_USERS, $row['id']);
         $row['users'] = $limit->getCurrentUsage();
         $row['limitUsers'] = $limit->getLimitValue() > -1 ? $limit->getLimitValue() : '-';
         $limit = Scalr_Limits::init()->Load(Scalr_Limits::ACCOUNT_SERVERS, $row['id']);
         $row['servers'] = $limit->getCurrentUsage();
         $row['limitServers'] = $limit->getLimitValue() > -1 ? $limit->getLimitValue() : '-';
         $row['dnsZones'] = $this->db->GetOne("SELECT COUNT(*) FROM dns_zones WHERE client_id = ?", array($row['id']));
     }
     $this->response->data($response);
 }
示例#12
0
 public function xListEventsAction()
 {
     $this->request->defineParams(array('farmId' => array('type' => 'int'), 'query' => array('type' => 'string'), 'sort' => array('type' => 'string', 'default' => 'id'), 'dir' => array('type' => 'string', 'default' => 'DESC')));
     $sql = "SELECT farmid, message, type, dtadded FROM events WHERE farmid='{$this->dbFarm->ID}'";
     $response = $this->buildResponseFromSql($sql, array("message", "type", "dtadded"));
     foreach ($response['data'] as &$row) {
         $row['message'] = nl2br($row['message']);
         $row["dtadded"] = Scalr_Util_DateTime::convertTz($row["dtadded"]);
     }
     $this->response->data($response);
 }
示例#13
0
 public function xGetClusterLogAction()
 {
     $dbFarmRole = $this->getFarmRole();
     $sql = "SELECT id, severity, dtadded, message FROM services_mongodb_cluster_log WHERE farm_roleid=" . $this->db->qstr($dbFarmRole->ID);
     $response = $this->buildResponseFromSql($sql, array("message", "severity"), " ORDER BY id DESC");
     foreach ($response["data"] as &$row) {
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row['dtadded']);
         $row['message'] = nl2br(htmlspecialchars($row['message']));
     }
     $this->response->data($response);
 }
示例#14
0
文件: Mongodb.php 项目: mheydt/scalr
 public function xGetClusterLogAction()
 {
     $dbFarmRole = $this->getFarmRole();
     $sql = "SELECT id, severity, dtadded, message FROM services_mongodb_cluster_log WHERE farm_roleid = ? AND :FILTER:";
     $args = [$dbFarmRole->ID];
     $response = $this->buildResponseFromSql2($sql, ['id', 'severity', 'message', 'dtadded'], ['message', 'severity'], $args);
     foreach ($response["data"] as &$row) {
         $row['dtadded'] = Scalr_Util_DateTime::convertTz($row['dtadded']);
         $row['message'] = nl2br(htmlspecialchars($row['message']));
     }
     $this->response->data($response);
 }
示例#15
0
 public function xGetSnapshotsAction()
 {
     $aws = $this->getEnvironment()->aws($this->getParam('cloudLocation'));
     $response = $aws->ec2->snapshot->describe(null, null, array(array('name' => SnapshotFilterNameType::ownerId(), 'value' => $this->getEnvironment()->getPlatformConfigValue(Ec2PlatformModule::ACCOUNT_ID)), array('name' => SnapshotFilterNameType::status(), 'value' => SnapshotData::STATUS_COMPLETED)));
     $data = array();
     /* @var $pv \Scalr\Service\Aws\Ec2\DataType\SnapshotData */
     foreach ($response as $pv) {
         if ($pv->status == SnapshotData::STATUS_COMPLETED) {
             $data[] = array('snapid' => $pv->snapshotId, 'createdat' => Scalr_Util_DateTime::convertTz($pv->startTime), 'size' => $pv->volumeSize, 'snapshotId' => $pv->snapshotId, 'createdDate' => Scalr_Util_DateTime::convertTz($pv->startTime), 'size' => $pv->volumeSize, 'volumeId' => $pv->volumeId, 'description' => (string) $pv->description, 'encrypted' => $pv->encrypted);
         }
     }
     $this->response->data(array('data' => $data));
 }
示例#16
0
 public function xListLimitsAction()
 {
     $cloudLocation = $this->getParam('cloudLocation');
     $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($this->environment->getPlatformConfigValue(Modules_Platforms_Rackspace::USERNAME, true, $cloudLocation), $this->environment->getPlatformConfigValue(Modules_Platforms_Rackspace::API_KEY, true, $cloudLocation), $cloudLocation);
     $limits = $cs->limits();
     $l = array();
     foreach ($limits->limits->rate as $limit) {
         $limit->resetTime = Scalr_Util_DateTime::convertTz(date("c", $limit->resetTime));
         $l[] = (array) $limit;
     }
     $response = $this->buildResponseFromData($l, array());
     $this->response->data($response);
 }
示例#17
0
文件: Users.php 项目: recipe/scalr
 public function xListUsersAction()
 {
     $this->request->defineParams(array('sort' => array('type' => 'json')));
     $sql = 'SELECT id, status, email, fullname, dtcreated, dtlastlogin, comments FROM account_users WHERE type = ? AND :FILTER:';
     $response = $this->buildResponseFromSql2($sql, array('id', 'status', 'email', 'fullname', 'dtcreated', 'dtlastlogin'), array('email', 'fullname'), array(Scalr_Account_User::TYPE_SCALR_ADMIN));
     foreach ($response["data"] as &$row) {
         $user = Scalr_Account_User::init();
         $user->loadById($row['id']);
         $row['dtcreated'] = Scalr_Util_DateTime::convertTz($row["dtcreated"]);
         $row['dtlastlogin'] = $row['dtlastlogin'] ? Scalr_Util_DateTime::convertTz($row["dtlastlogin"]) : 'Never';
     }
     $this->response->data($response);
 }
示例#18
0
 public function xListLimitsAction()
 {
     //TODO: check correct platform name
     $ccProps = $this->environment->cloudCredentials($this->getParam('cloudLocation') . SERVER_PLATFORMS::RACKSPACE)->properties;
     $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($ccProps[Entity\CloudCredentialsProperty::RACKSPACE_USERNAME], $ccProps[Entity\CloudCredentialsProperty::RACKSPACE_API_KEY], $this->getParam('cloudLocation'));
     $limits = $cs->limits();
     $l = array();
     foreach ($limits->limits->rate as $limit) {
         $limit->resetTime = Scalr_Util_DateTime::convertTz(date("c", $limit->resetTime));
         $l[] = (array) $limit;
     }
     $response = $this->buildResponseFromData($l, array());
     $this->response->data($response);
 }
示例#19
0
    public function xListUsersAction()
    {
        $this->request->defineParams(array('sort' => array('type' => 'json')));
        // account owner, team owner
        if ($this->user->getType() == Scalr_Account_User::TYPE_ACCOUNT_OWNER || $this->user->isTeamOwner()) {
            $sql = "SELECT account_users.id, status, email, fullname, dtcreated, dtlastlogin, type, comments FROM account_users\n\t\t\t\tLEFT JOIN account_team_users ON account_users.id = account_team_users.user_id\n\t\t\t\tLEFT JOIN account_user_groups ON account_users.id = account_user_groups.user_id\n\t\t\t\tWHERE account_id='" . $this->user->getAccountId() . "'";
        } else {
            // team user
            $teams = $this->user->getTeams();
            if (!count($teams)) {
                throw new Exception('You are not belongs to any team');
            }
            $sql = 'SELECT account_users.id, status, email, fullname, dtcreated, dtlastlogin, type, comments FROM account_users
				JOIN account_team_users ON account_users.id = account_team_users.user_id
				LEFT JOIN account_user_groups ON account_users.id = account_user_groups.user_id
				WHERE account_id="' . $this->user->getAccountId() . '"';
            foreach ($this->user->getTeams() as $team) {
                $r[] = 'account_team_users.team_id = "' . $team['id'] . '"';
            }
            $sql .= ' AND (' . implode(' OR ', $r) . ')';
        }
        if ($this->getParam('teamId')) {
            $sql .= ' AND account_team_users.team_id = ' . $this->db->qstr($this->getParam('teamId'));
        }
        if ($this->getParam('userId')) {
            $sql .= ' AND account_users.id = ' . $this->db->qstr($this->getParam('userId'));
        }
        if ($this->getParam('groupPermissionId')) {
            $sql .= ' AND account_user_groups.group_id = ' . $this->db->qstr($this->getParam('groupPermissionId'));
        }
        $response = $this->buildResponseFromSql($sql, array('email', 'fullname'));
        foreach ($response["data"] as &$row) {
            $user = Scalr_Account_User::init();
            $user->loadById($row['id']);
            $row['dtcreated'] = Scalr_Util_DateTime::convertTz($row["dtcreated"]);
            $row['dtlastlogin'] = $row['dtlastlogin'] ? Scalr_Util_DateTime::convertTz($row["dtlastlogin"]) : 'Never';
            $row['teams'] = $user->getTeams();
            $row['is2FaEnabled'] = $user->getSetting(Scalr_Account_User::SETTING_SECURITY_2FA_GGL) == '1' ? true : false;
            switch ($row['type']) {
                case Scalr_Account_User::TYPE_ACCOUNT_OWNER:
                    $row['type'] = 'Account Owner';
                    break;
                default:
                    $row['type'] = $user->isTeamOwner() ? 'Team Owner' : 'Team User';
                    break;
            }
        }
        $this->response->data($response);
    }
示例#20
0
 public function xHistoryRequestsAction()
 {
     $this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'id', 'direction' => 'DESC'))));
     $sql = 'SELECT fl.*, f.name as farm_name, u1.email AS request_user_email, u2.email AS answer_user_email FROM farm_lease_requests fl
         LEFT JOIN farms f ON f.id = fl.farm_id
         LEFT JOIN account_users u1 ON fl.request_user_id = u1.id
         LEFT JOIN account_users u2 ON fl.answer_user_id = u2.id
         WHERE f.env_id = ?
     ';
     $response = $this->buildResponseFromSql2($sql, array('farm_id', 'request_time', 'request_days', 'status'), array(), array($this->getEnvironmentId()));
     foreach ($response["data"] as &$row) {
         $row['request_time'] = $row['request_time'] ? Scalr_Util_DateTime::convertTz($row['request_time']) : '';
     }
     $this->response->data($response);
 }
示例#21
0
 public function xListSnapshotsAction()
 {
     $this->request->defineParams(array('cloudLocation', 'dbinstance', 'sort' => array('type' => 'json', 'default' => array('property' => 'id', 'direction' => 'ASC'))));
     $amazonRDSClient = Scalr_Service_Cloud_Aws::newRds($this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY), $this->getParam('cloudLocation'));
     $awsResponse = $amazonRDSClient->DescribeDBSnapshots($this->getParam('dbinstance'));
     $rows = $awsResponse->DescribeDBSnapshotsResult->DBSnapshots->DBSnapshot;
     $rowz = array();
     if ($rows instanceof stdClass) {
         $rows = array($rows);
     }
     foreach ($rows as $pv) {
         $rowz[] = array("dtcreated" => Scalr_Util_DateTime::convertTz($pv->SnapshotCreateTime), "port" => (string) $pv->Port, "status" => (string) $pv->Status, "engine" => (string) $pv->Engine, "avail_zone" => (string) $pv->AvailabilityZone, "idtcreated" => Scalr_Util_DateTime::convertTz($pv->InstanceCreateTime), "storage" => (string) $pv->AllocatedStorage, "name" => (string) $pv->DBSnapshotIdentifier, "id" => (string) $pv->DBSnapshotIdentifier);
     }
     $response = $this->buildResponseFromData($rowz);
     $this->response->data($response);
 }
示例#22
0
 public function xListSnapshotsAction()
 {
     $this->request->defineParams(['cloudLocation', 'dbinstance', 'sort' => ['type' => 'json', 'default' => ['property' => 'id', 'direction' => 'ASC']]]);
     $aws = $this->getEnvironment()->aws($this->getParam('cloudLocation'));
     $rows = $aws->rds->dbSnapshot->describe($this->getParam('dbinstance'));
     $rowz = [];
     foreach ($rows as $pv) {
         /* @var $pv \Scalr\Service\Aws\Rds\DataType\DBSnapshotData */
         $rowz[] = ["dtcreated" => $pv->snapshotCreateTime, "port" => $pv->port, "status" => $pv->status, "engine" => $pv->engine, "avail_zone" => $pv->availabilityZone, "idtcreated" => $pv->instanceCreateTime, "storage" => $pv->allocatedStorage, "name" => $pv->dBSnapshotIdentifier, "id" => $pv->dBSnapshotIdentifier, "type" => $pv->snapshotType];
     }
     $response = $this->buildResponseFromData($rowz);
     foreach ($response['data'] as &$row) {
         $row['dtcreated'] = $row['dtcreated'] ? Scalr_Util_DateTime::convertTz($row['dtcreated']) : '';
         $row['idtcreated'] = $row['idtcreated'] ? Scalr_Util_DateTime::convertTz($row['idtcreated']) : '';
     }
     $this->response->data($response);
 }
示例#23
0
文件: Alerts.php 项目: mheydt/scalr
 public function xListAction($serverId = null, $farmId = null, $farmRoleId = null, $status = null)
 {
     $sql = "SELECT sa.* FROM server_alerts sa LEFT JOIN farms f ON f.id = sa.farm_id WHERE sa.env_id = ?";
     $args = [$this->getEnvironmentId()];
     if ($serverId) {
         $sql .= ' AND sa.server_id = ?';
         $args[] = $serverId;
     }
     if ($farmId) {
         $sql .= ' AND sa.farm_id = ?';
         $args[] = $farmId;
         if ($farmRoleId) {
             $sql .= ' AND sa.farm_roleid = ?';
             $args[] = $farmRoleId;
         }
     }
     if ($status) {
         $sql .= ' AND sa.status = ?';
         $args[] = $status;
     }
     list($sql, $args) = $this->request->prepareFarmSqlQuery($sql, $args, 'f');
     $response = $this->buildResponseFromSql2($sql, ['metric', 'status', 'dtoccured', 'dtlastcheck', 'dtsolved', 'details'], ['server_id', 'details'], $args);
     foreach ($response['data'] as $i => $row) {
         $row['dtoccured'] = Scalr_Util_DateTime::convertTz($row['dtoccured']);
         if ($row['dtlastcheck']) {
             $row['dtlastcheck'] = Scalr_Util_DateTime::convertTz($row['dtlastcheck']);
         } else {
             $row['dtlastcheck'] = false;
         }
         if ($row['status'] == Alerts::STATUS_RESOLVED) {
             $row['dtsolved'] = Scalr_Util_DateTime::convertTz($row['dtsolved']);
         } else {
             $row['dtsolved'] = false;
         }
         $row['metric'] = Alerts::getMetricName($row['metric']);
         $row['farm_name'] = DBFarm::LoadByID($row['farm_id'])->Name;
         try {
             $row['role_name'] = DBFarmRole::LoadByID($row['farm_roleid'])->GetRoleObject()->name;
             $dbServer = DBServer::LoadByID($row['server_id']);
             $row['server_exists'] = $dbServer->status == SERVER_STATUS::RUNNING ? true : false;
         } catch (Exception $e) {
         }
         $response['data'][$i] = $row;
     }
     $this->response->data($response);
 }
示例#24
0
文件: Disks.php 项目: mheydt/scalr
 /**
  * @param   string  $cloudLocation
  * @param   string  $diskId optional
  */
 public function xListAction($cloudLocation, $diskId = '')
 {
     $platform = PlatformFactory::NewPlatform(SERVER_PLATFORMS::GCE);
     $client = $platform->getClient($this->environment, $cloudLocation);
     /* @var $client Google_Service_Compute */
     $retval = array();
     $disks = $client->disks->listDisks($this->environment->cloudCredentials(SERVER_PLATFORMS::GCE)->properties[Entity\CloudCredentialsProperty::GCE_PROJECT_ID], $cloudLocation, $diskId ? ['filter' => "name eq {$diskId}"] : []);
     foreach ($disks as $disk) {
         /* @var $disk Google_Service_Compute_Disk */
         $item = array('id' => $disk->name, 'description' => $disk->description, 'createdAt' => strtotime($disk->creationTimestamp), 'size' => (int) $disk->sizeGb, 'status' => $disk->status, 'snapshotId' => $disk->sourceSnapshotId);
         $retval[] = $item;
     }
     $response = $this->buildResponseFromData($retval, array('id', 'name', 'description', 'snapshotId', 'createdAt', 'size'));
     foreach ($response['data'] as &$row) {
         $row['createdAt'] = Scalr_Util_DateTime::convertTz($row['createdAt']);
     }
     $this->response->data($response);
 }
示例#25
0
 public function xGetSnapshotsAction()
 {
     $amazonEC2Client = Scalr_Service_Cloud_Aws::newEc2($this->getParam('cloudLocation'), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
     $response = $amazonEC2Client->DescribeSnapshots();
     if ($response->snapshotSet->item instanceof stdClass) {
         $response->snapshotSet->item = array($response->snapshotSet->item);
     }
     $data = array();
     foreach ($response->snapshotSet->item as $pk => $pv) {
         if ($pv->ownerId != $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCOUNT_ID)) {
             continue;
         }
         if ($pv->status == 'completed') {
             $data[] = array('snapid' => (string) $pv->snapshotId, 'createdat' => Scalr_Util_DateTime::convertTz($pv->startTime), 'size' => (string) $pv->volumeSize);
         }
     }
     $this->response->data(array('data' => $data));
 }
示例#26
0
 public function xListSnapshotsAction()
 {
     $this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'id', 'direction' => 'ASC')), 'snapshotId'));
     $platform = PlatformFactory::NewPlatform(SERVER_PLATFORMS::GCE);
     $client = $platform->getClient($this->environment);
     /* @var $client Google_Service_Compute */
     $retval = array();
     $snaps = $client->snapshots->listSnapshots($this->environment->getPlatformConfigValue(GoogleCEPlatformModule::PROJECT_ID));
     foreach ($snaps as $snap) {
         /* @var $snap Google_Service_Compute_Snapshot */
         if ($this->getParam('snapshotId') && $this->getParam('snapshotId') != $snap->name) {
             continue;
         }
         $item = array('id' => $snap->name, 'description' => $snap->description, 'createdAt' => Scalr_Util_DateTime::convertTz(strtotime($snap->creationTimestamp)), 'size' => $snap->diskSizeGb, 'status' => $snap->status);
         $retval[] = $item;
     }
     $response = $this->buildResponseFromData($retval, array('id', 'description'));
     $this->response->data($response);
 }
示例#27
0
文件: Rds.php 项目: mheydt/scalr
 /**
  *
  * @param string $cloudLocation
  * @param string $name          optional
  * @param string $type          optional
  */
 public function xListLogsAction($cloudLocation, $name = null, $type = null)
 {
     $request = new DescribeEventRequestData();
     $request->sourceIdentifier = $name ?: null;
     $request->sourceType = $type ?: null;
     $events = $this->environment->aws($cloudLocation)->rds->event->describe($request);
     $logs = array();
     /* @var $event \Scalr\Service\Aws\Rds\DataType\EventData */
     foreach ($events as $event) {
         if ($event->message) {
             $logs[] = array('Message' => $event->message, 'Date' => $event->date, 'SourceIdentifier' => $event->sourceIdentifier, 'SourceType' => $event->sourceType);
         }
     }
     $response = $this->buildResponseFromData($logs, ['Date', 'Message']);
     foreach ($response['data'] as &$row) {
         $row['Date'] = Scalr_Util_DateTime::convertTz($row['Date']);
     }
     $this->response->data($response);
 }
示例#28
0
 public function xListLogsAction()
 {
     $amazonRDSClient = Scalr_Service_Cloud_Aws::newRds($this->environment->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $this->environment->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY), $this->getParam('cloudLocation'));
     $aws_response = $amazonRDSClient->DescribeEvents($this->getParam('name'), $this->getParam('type'));
     $events = (array) $aws_response->DescribeEventsResult->Events;
     if (!is_array($events['Event'])) {
         $events['Event'] = array($events['Event']);
     }
     foreach ($events['Event'] as $event) {
         if ($event->Message) {
             $logs[] = array('Message' => (string) $event->Message, 'Date' => (string) $event->Date, 'SourceIdentifier' => (string) $event->SourceIdentifier, 'SourceType' => (string) $event->SourceType);
         }
     }
     $response = $this->buildResponseFromData($logs, array('Date', 'Message'));
     foreach ($response['data'] as &$row) {
         $row['Date'] = Scalr_Util_DateTime::convertTz($row['Date']);
     }
     $this->response->data($response);
 }
示例#29
0
文件: Servers.php 项目: scalr/scalr
 /**
  * List orphaned servers
  *
  * @param   string  $platform                   Cloud platform
  * @param   string  $cloudLocation  optional    Cloud location
  * @param   string  $query          optional    Filter parameter
  * @param   string  $imageId        optional    Filter parameter
  * @param   string  $vpcId          optional    Filter parameter
  * @param   string  $subnetId       optional    Filter paramerer
  */
 public function xListAction($platform, $cloudLocation = null, $query = null, $imageId = null, $vpcId = null, $subnetId = null)
 {
     $lookup = [];
     $p = PlatformFactory::NewPlatform($platform);
     if (!$this->environment->isPlatformEnabled($platform)) {
         $this->response->failure(sprintf("Platform '%s' is not enabled", $platform));
         return;
     }
     $filterFields = [];
     if ($query) {
         $filterFields[join(',', ['cloudServerId', 'privateIp', 'publicIp'])] = $query;
     }
     if ($imageId) {
         $filterFields['imageId'] = $imageId;
     }
     if ($vpcId) {
         $filterFields['vpcId'] = $vpcId;
     }
     if ($subnetId) {
         $filterFields['subnetId'] = $subnetId;
     }
     $orphans = $this->buildResponseFromData($p->getOrphanedServers($this->getEnvironmentEntity(), $cloudLocation), $filterFields);
     foreach ($orphans["data"] as $i => &$orphan) {
         $orphan["launchTime"] = \Scalr_Util_DateTime::convertTz($orphan["launchTime"]);
         $orphan["imageHash"] = null;
         $orphan["imageName"] = null;
         if (!is_array($lookup[$orphan["imageId"]])) {
             $lookup[$orphan["imageId"]] = [];
         }
         $lookup[$orphan["imageId"]][] = $orphan;
     }
     if (!empty($lookup)) {
         /* @var $image Scalr\Model\Entity\Image */
         foreach (Image::find([["status" => Image::STATUS_ACTIVE], ["id" => ['$in' => array_keys($lookup)]], ['$or' => [['accountId' => null], ['$and' => [['accountId' => $this->getUser()->accountId], ['$or' => [['envId' => null], ['envId' => $this->getEnvironment()->id]]]]]]]]) as $image) {
             foreach ($lookup[$image->id] as &$orphan) {
                 $orphan['imageHash'] = $image->hash;
                 $orphan['imageName'] = $image->name;
             }
         }
     }
     $this->response->data($orphans);
 }
示例#30
0
 /**
  * List snapshots
  *
  * @param string $cloudLocation                 Cloud location
  * @param string $type                          optional Snapshot type (manual, automated)
  * @param string $dbInstanceId                  optional Instance identifier
  * @param string $dbClusterId                   optional Cluster identifier
  */
 public function xListSnapshotsAction($cloudLocation, $type = null, $dbInstanceId = null, $dbClusterId = null)
 {
     $aws = $this->getAwsClient($cloudLocation);
     $rows = [];
     if (!isset($dbClusterId)) {
         $marker = null;
         do {
             if (isset($snapshots)) {
                 $marker = $snapshots->getMarker();
             }
             $snapshots = $aws->rds->dbSnapshot->describe($dbInstanceId, null, $type, $marker);
             foreach ($snapshots as $pv) {
                 /* @var $pv DBSnapshotData */
                 $rows[] = ["dtcreated" => isset($pv->snapshotCreateTime) ? $pv->snapshotCreateTime->getTimestamp() : 0, "port" => $pv->port, "status" => $pv->status, "engine" => $pv->engine, "avail_zone" => $pv->availabilityZone, "idtcreated" => isset($pv->instanceCreateTime) ? $pv->instanceCreateTime->getTimestamp() : 0, "storage" => $pv->allocatedStorage, "name" => $pv->dBSnapshotIdentifier, "id" => $pv->dBSnapshotIdentifier, "type" => $pv->snapshotType];
             }
         } while ($snapshots->getMarker() !== null);
     }
     if (!isset($dbInstanceId)) {
         $marker = null;
         do {
             if (isset($clusterSnapshots)) {
                 $marker = $clusterSnapshots->getMarker();
             }
             $clusterSnapshots = $aws->rds->dbClusterSnapshot->describe($dbClusterId, null, $type, $marker);
             foreach ($clusterSnapshots as $clusterSnapshot) {
                 /* @var $clusterSnapshot DBClusterSnapshotData */
                 $zones = [];
                 foreach ($clusterSnapshot->availabilityZones as $zone) {
                     /* @var $zone AvailabilityZoneData */
                     $zones[] = $zone->name;
                 }
                 $rows[] = ["dtcreated" => isset($clusterSnapshot->snapshotCreateTime) ? $clusterSnapshot->snapshotCreateTime->getTimestamp() : 0, "port" => $clusterSnapshot->port ? $clusterSnapshot->port : null, "status" => $clusterSnapshot->status, "engine" => $clusterSnapshot->engine, "avail_zone" => $zones, "idtcreated" => isset($clusterSnapshot->clusterCreateTime) ? $clusterSnapshot->clusterCreateTime->getTimestamp() : 0, "storage" => $clusterSnapshot->allocatedStorage, "name" => $clusterSnapshot->dBClusterSnapshotIdentifier, "id" => $clusterSnapshot->dBClusterSnapshotIdentifier, "type" => $clusterSnapshot->snapshotType];
             }
         } while ($clusterSnapshots->getMarker() !== null);
     }
     $response = $this->buildResponseFromData($rows, ['name']);
     foreach ($response['data'] as &$row) {
         $row['dtcreated'] = $row['dtcreated'] ? Scalr_Util_DateTime::convertTz($row['dtcreated']) : '';
         $row['idtcreated'] = $row['idtcreated'] ? Scalr_Util_DateTime::convertTz($row['idtcreated']) : '';
     }
     $this->response->data($response);
 }