Beispiel #1
0
 public function xCreateAction()
 {
     $this->request->defineParams(array('listeners' => array('type' => 'json'), 'healthcheck' => array('type' => 'json'), 'zones' => array('type' => 'array'), 'subnets' => array('type' => 'array'), 'scheme' => array('type' => 'string')));
     $healthCheck = $this->getParam('healthcheck');
     $elb = $this->environment->aws($this->getParam('cloudLocation'))->elb;
     //prepare listeners
     $listenersList = new ListenerList();
     $li = 0;
     foreach ($this->getParam('listeners') as $listener) {
         $listener_chunks = explode("#", $listener);
         $listenersList->append(new ListenerData(trim($listener_chunks[1]), trim($listener_chunks[2]), trim($listener_chunks[0]), null, trim($listener_chunks[3])));
     }
     $availZones = $this->getParam('zones');
     $subnets = $this->getParam('subnets');
     $scheme = $this->getParam('scheme');
     $elb_name = sprintf("scalr-%s-%s", Scalr_Util_CryptoTool::sault(10), rand(100, 999));
     $healthCheckType = new HealthCheckData();
     $healthCheckType->target = $healthCheck['target'];
     $healthCheckType->healthyThreshold = $healthCheck['healthyThreshold'];
     $healthCheckType->interval = $healthCheck['interval'];
     $healthCheckType->timeout = $healthCheck['timeout'];
     $healthCheckType->unhealthyThreshold = $healthCheck['unhealthyThreshold'];
     //Creates a new ELB
     $dnsName = $elb->loadBalancer->create($elb_name, $listenersList, !empty($availZones) ? $availZones : null, !empty($subnets) ? $subnets : null, null, !empty($scheme) ? $scheme : null);
     try {
         $elb->loadBalancer->configureHealthCheck($elb_name, $healthCheckType);
     } catch (Exception $e) {
         $elb->loadBalancer->delete($elb_name);
         throw $e;
     }
     // return all as in xListElb
     $this->response->data(array('elb' => array('name' => $elb_name, 'dnsName' => $dnsName)));
 }
Beispiel #2
0
 public static function create($userId)
 {
     @session_start();
     $_SESSION[__CLASS__][self::SESSION_USER_ID] = $userId;
     $sault = Scalr_Util_CryptoTool::sault();
     $_SESSION[__CLASS__][self::SESSION_SAULT] = $sault;
     $_SESSION[__CLASS__][self::SESSION_HASH] = self::createHash($userId, $sault);
     @session_write_close();
     self::restore(false);
 }
Beispiel #3
0
require_once __DIR__ . "/../src/prepend.inc.php";
use Scalr\Service\OpenStack\OpenStack;
use Scalr\Service\OpenStack\OpenStackConfig;
use Scalr\Service\OpenStack\Services\Network\Type\CreateSubnet;
use Scalr\Service\OpenStack\Services\Network\Type\CreateRouter;
use Scalr\Modules\Platforms\Openstack\OpenstackPlatformModule;
use Scalr\Service\OpenStack\Services\Servers\Type\ServersExtension;
$validator = new Scalr_Validator();
$crypto = new Scalr_Util_CryptoTool(MCRYPT_TRIPLEDES, MCRYPT_MODE_CFB, 24, 8);
if (!$_REQUEST['update'] && !$_REQUEST['delete']) {
    if (!$_REQUEST['name']) {
        $err['name'] = _("Account name required");
    }
    $name = $_REQUEST['name'];
    $password = $crypto->sault(10);
}
if ($validator->validateEmail($_REQUEST['email'], null, true) !== true) {
    $err['email'] = _("Invalid E-mail address");
}
$email = $_REQUEST['email'];
function getOpenStackOption($name)
{
    return SERVER_PLATFORMS::ECS . "." . constant('Scalr\\Modules\\Platforms\\Openstack\\OpenstackPlatformModule::' . $name);
}
if (count($err) == 0) {
    if ($_REQUEST['delete']) {
        $user = Scalr_Account_User::init()->loadByEmail($email);
        if (!$user) {
            throw new Exception("User Not Found");
        }
Beispiel #4
0
 protected static function getAccountHash($userId)
 {
     $db = \Scalr::getDb();
     $hash = $db->GetOne("\n            SELECT `value`\n            FROM client_settings\n            JOIN account_users ON account_users.account_id = client_settings.clientid\n            WHERE `key` = ? AND account_users.id = ?\n            LIMIT 1\n        ", array(Scalr_Account::SETTING_AUTH_HASH, $userId));
     if (!$hash) {
         $accountId = $db->GetOne('SELECT account_id FROM account_users WHERE id = ? LIMIT 1', array($userId));
         if ($accountId) {
             $hash = Scalr_Util_CryptoTool::sault();
             $acc = new Scalr_Account();
             $acc->loadById($accountId);
             $acc->setSetting(Scalr_Account::SETTING_AUTH_HASH, $hash);
         }
     }
     return $hash;
 }
Beispiel #5
0
 /**
  * @param $qr
  * @param $code
  * @throws Exception
  */
 public function xSettingsEnable2FaGglAction($qr, $code)
 {
     if ($this->user->getSetting(Scalr_Account_User::SETTING_SECURITY_2FA_GGL) == 1) {
         throw new Exception('Two-factor authentication has been already enabled for this user');
     }
     if ($qr && $code) {
         if (Scalr_Util_Google2FA::verifyKey($qr, $code)) {
             $resetCode = Scalr_Util_CryptoTool::sault(12);
             $this->user->setSetting(Scalr_Account_User::SETTING_SECURITY_2FA_GGL, 1);
             $this->user->setSetting(Scalr_Account_User::SETTING_SECURITY_2FA_GGL_KEY, $this->getCrypto()->encrypt($qr));
             $this->user->setSetting(Scalr_Account_User::SETTING_SECURITY_2FA_GGL_RESET_CODE, Scalr_Util_CryptoTool::hash($resetCode));
             $this->response->data(['resetCode' => $resetCode]);
         } else {
             $this->response->data(array('errors' => array('code' => 'Invalid code')));
             $this->response->failure();
         }
     } else {
         $this->response->failure('Invalid data');
     }
 }
Beispiel #6
0
 public function cloneRole($newRoleName, $accountId, $envId)
 {
     $this->db->BeginTrans();
     try {
         $this->db->Execute("INSERT INTO roles SET\n                name            = ?,\n                origin          = ?,\n                client_id       = ?,\n                env_id          = ?,\n                cat_id          = ?,\n                description     = ?,\n                behaviors       = ?,\n                history         = ?,\n                generation      = ?,\n                os              = ?,\n                os_family       = ?,\n                os_version      = ?,\n                os_generation   = ?\n            ", array($newRoleName, ROLE_TYPE::CUSTOM, $accountId, $envId, $this->catId, $this->description, $this->behaviorsRaw, "*cloned from {$this->name} ({$this->id})*", 2, $this->os, $this->osFamily, $this->osVersion, $this->osGeneration));
         $newRoleId = $this->db->Insert_Id();
         //Set behaviors
         foreach ($this->getBehaviors() as $behavior) {
             $this->db->Execute("INSERT INTO role_behaviors SET role_id = ?, behavior = ?", array($newRoleId, $behavior));
         }
         // Set images
         $rsr7 = $this->db->Execute("SELECT * FROM role_images WHERE role_id = ?", array($this->id));
         while ($r7 = $rsr7->FetchRow()) {
             $this->db->Execute("INSERT INTO role_images SET\n                    `role_id` = ?,\n                    `cloud_location` = ?,\n                    `image_id` = ?,\n                    `platform` = ?,\n                    `architecture` = ?,\n                    `agent_version` = ?\n                ", array($newRoleId, $r7['cloud_location'], $r7['image_id'], $r7['platform'], $r7['architecture'], $r7['agent_version']));
         }
         //Set tags
         $rsr1 = $this->db->Execute("SELECT * FROM role_tags WHERE role_id = ?", array($this->id));
         $tags = array();
         while ($r1 = $rsr1->FetchRow()) {
             $this->db->Execute("INSERT INTO role_tags SET\n                    `role_id` = ?,\n                    `tag` = ?\n                ", array($newRoleId, $r1['tag']));
         }
         //Set software
         $rsr2 = $this->db->Execute("SELECT * FROM role_software WHERE role_id = ?", array($this->id));
         while ($r2 = $rsr2->FetchRow()) {
             $this->db->Execute("INSERT INTO role_software SET\n                    `role_id` = ?,\n                    `software_name` = ?,\n                    `software_version` = ?,\n                    `software_key` = ?\n                ", array($newRoleId, $r2['software_name'], $r2['software_version'], $r2['software_key']));
         }
         //Set global variables
         $variables = new Scalr_Scripting_GlobalVariables($this->envId, Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
         $variables->setValues($variables->getValues($this->id), $newRoleId);
         //Set scripts
         $rsr8 = $this->db->Execute("SELECT * FROM role_scripts WHERE role_id = ?", array($this->id));
         while ($r8 = $rsr8->FetchRow()) {
             $this->db->Execute("INSERT INTO role_scripts SET\n                    role_id = ?,\n                    event_name = ?,\n                    target = ?,\n                    script_id = ?,\n                    version = ?,\n                    timeout = ?,\n                    issync = ?,\n                    params = ?,\n                    order_index = ?,\n                    hash = ?\n                ", array($newRoleId, $r8['event_name'], $r8['target'], $r8['script_id'], $r8['version'], $r8['timeout'], $r8['issync'], $r8['params'], $r8['order_index'], Scalr_Util_CryptoTool::sault(12)));
         }
     } catch (Exception $e) {
         $this->db->RollbackTrans();
         throw $e;
     }
     $this->db->CommitTrans();
     return $newRoleId;
 }
Beispiel #7
0
 public function xSaveAction()
 {
     $user = Scalr_Account_User::init();
     $validator = new Scalr_Validator();
     if (!$this->getParam('email')) {
         throw new Scalr_Exception_Core('Email must be provided.');
     }
     if ($validator->validateEmail($this->getParam('email'), null, true) !== true) {
         throw new Scalr_Exception_Core('Email should be correct');
     }
     if ($this->user->canManageAcl() || $this->user->isTeamOwner()) {
         $newUser = false;
         if ($this->getParam('id')) {
             $user->loadById((int) $this->getParam('id'));
             if (!$this->user->canEditUser($user)) {
                 throw new Scalr_Exception_InsufficientPermissions();
             }
             $user->updateEmail($this->getParam('email'));
         } else {
             $this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_USERS, 1);
             $user->create($this->getParam('email'), $this->user->getAccountId());
             $user->type = Scalr_Account_User::TYPE_TEAM_USER;
             $newUser = true;
         }
         $sendResetLink = false;
         if (!$this->getParam('password')) {
             $password = Scalr_Util_CryptoTool::sault(10);
             $sendResetLink = true;
         } else {
             $password = $this->getParam('password');
         }
         if ($password != '******') {
             $user->updatePassword($password);
         }
         if (in_array($this->getParam('status'), array(Scalr_Account_User::STATUS_ACTIVE, Scalr_Account_User::STATUS_INACTIVE)) && !$user->isAccountOwner()) {
             $user->status = $this->getParam('status');
         }
         $user->fullname = $this->getParam('fullname');
         $user->comments = $this->getParam('comments');
         $user->save();
         if ($this->getParam('enableApi')) {
             $keys = Scalr::GenerateAPIKeys();
             $user->setSetting(Scalr_Account_User::SETTING_API_ENABLED, true);
             $user->setSetting(Scalr_Account_User::SETTING_API_ACCESS_KEY, $keys['id']);
             $user->setSetting(Scalr_Account_User::SETTING_API_SECRET_KEY, $keys['key']);
         }
         if ($newUser) {
             if ($sendResetLink) {
                 try {
                     $hash = $this->getCrypto()->sault(10);
                     $user->setSetting(Scalr_Account::SETTING_OWNER_PWD_RESET_HASH, $hash);
                     $clientinfo = array('email' => $user->getEmail(), 'fullname' => $user->fullname);
                     // Send reset password E-mail
                     $res = $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/user_account_confirm.eml', array("{{fullname}}" => $clientinfo['fullname'], "{{pwd_link}}" => "https://{$_SERVER['HTTP_HOST']}/#/guest/updatePassword/?hash={$hash}"), $clientinfo['email'], $clientinfo['fullname']);
                 } catch (Exception $e) {
                 }
             }
         }
         $this->response->data(array('user' => array('id' => $user->getId(), 'email' => $user->getEmail(), 'fullname' => $user->fullname)));
         $this->response->success('User successfully saved');
     } else {
         throw new Scalr_Exception_InsufficientPermissions();
     }
 }