예제 #1
0
 public function ApacheVhostCreate($DomainName, $FarmID, $FarmRoleID, $DocumentRootDir, $EnableSSL, $SSLPrivateKey = null, $SSLCertificate = null)
 {
     $validator = new Validator();
     if (!$validator->IsDomain($DomainName)) {
         $err[] = _("Domain name is incorrect");
     }
     $DBFarm = DBFarm::LoadByID($FarmID);
     if ($DBFarm->EnvID != $this->Environment->id) {
         throw new Exception(sprintf("Farm #%s not found", $FarmID));
     }
     $DBFarmRole = DBFarmRole::LoadByID($FarmRoleID);
     if ($DBFarm->ID != $DBFarmRole->FarmID) {
         throw new Exception(sprintf("FarmRole #%s not found on Farm #%s", $FarmRoleID, $FarmID));
     }
     if (!$DocumentRootDir) {
         throw new Exception(_("DocumentRootDir required"));
     }
     $options = serialize(array("document_root" => trim($DocumentRootDir), "logs_dir" => "/var/log", "server_admin" => $this->user->getEmail()));
     $httpConfigTemplateSSL = @file_get_contents(dirname(__FILE__) . "/../../templates/services/apache/ssl.vhost.tpl");
     $httpConfigTemplate = @file_get_contents(dirname(__FILE__) . "/../../templates/services/apache/nonssl.vhost.tpl");
     $vHost = Scalr_Service_Apache_Vhost::init();
     $vHost->envId = (int) $this->Environment->id;
     $vHost->clientId = $this->user->getAccountId();
     $vHost->domainName = $DomainName;
     $vHost->isSslEnabled = $EnableSSL ? true : false;
     $vHost->farmId = $FarmID;
     $vHost->farmRoleId = $FarmRoleID;
     $vHost->httpdConf = $httpConfigTemplate;
     $vHost->templateOptions = $options;
     //SSL stuff
     if ($vHost->isSslEnabled) {
         if ($SSLCertificate) {
             $vHost->sslCert = base64_decode($SSLCertificate);
         }
         if ($SSLPrivateKey) {
             $vHost->sslKey = base64_decode($SSLPrivateKey);
         }
         $vHost->httpdConfSsl = $httpConfigTemplateSSL;
     } else {
         $vHost->sslCert = "";
         $vHost->sslKey = "";
         $vHost->caCert = "";
         $vHost->httpdConfSsl = "";
     }
     $vHost->save();
     $servers = $DBFarm->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
     foreach ($servers as $dBServer) {
         if ($dBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::NGINX) || $dBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::APACHE)) {
             $dBServer->SendMessage(new Scalr_Messaging_Msg_VhostReconfigure());
         }
     }
     $response = $this->CreateInitialResponse();
     $response->Result = 1;
     return $response;
 }
예제 #2
0
			if ($registry_config->idn)
	    	{
	    		$allowed_utf8_chars = $registry_config->idn->xpath("//allowed-utf8-chars");
			    $disallowed_utf8_chars = $registry_config->idn->xpath("//disallowed-utf8-chars");
			    
			    if ($allowed_utf8_chars[0] || $disallowed_utf8_chars[0])
			    {
				    $Validator = new Validator();
				    if (!$Validator->IsDomain("{$attr["name"]}.{$TLD}", null, null, (string)$allowed_utf8_chars[0], (string)$disallowed_utf8_chars[0]))
				    	throw new Exception(_("Domain name contains non-supported characters"));
			    }
	    	}
	    	else
	    	{
			    $Validator = new Validator();
			    if (!$Validator->IsDomain("{$attr["name"]}.{$TLD}"))
			    	throw new Exception(_("Domain name contains non-supported characters"));
	    	}
			
			if ($attr["isTransfer"] == "false")
			{
				if ($Registry->DomainCanBeRegistered($Domain)->Result && !DBDomain::GetInstance()->ActiveDomainExists($Domain))
					$res = "AVAIL";
				else
					$res = "NOT_AVAIL";
			}
			else
			{
				if ($Registry->DomainCanBeTransferred($Domain) && !DBDomain::GetInstance()->ActiveDomainExists($Domain))
					$res = "AVAIL";
				else
예제 #3
0
 public function xSaveAction()
 {
     $validator = new Validator();
     try {
         if (!$validator->IsDomain($this->getParam('domainName'))) {
             $err['domainName'] = _("Domain name is incorrect");
         }
         if (!$this->getParam('farmId')) {
             $err['farmId'] = _("Farm required");
         } else {
             $dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
             $this->user->getPermissions()->validate($dbFarm);
         }
         if (!$this->getParam('farmRoleId')) {
             $err['farmRoleId'] = _("Role required");
         } else {
             $dbFarmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
             if ($dbFarmRole->FarmID != $dbFarm->ID) {
                 $err['farmRoleId'] = _("Role not found");
             }
         }
         if (!$validator->IsEmail($this->getParam('serverAdmin'))) {
             $err['serverAdmin'] = _("Server admin's email is incorrect or empty ");
         }
         if (!$this->getParam('documentRoot')) {
             $err['documentRoot'] = _("Document root required");
         }
         if (!$this->getParam('logsDir')) {
             $err['logsDir'] = _("Logs directory required");
         }
         if ($this->db->GetOne("SELECT id FROM apache_vhosts WHERE env_id=? AND `name` = ? AND id != ?", array($this->getEnvironmentId(), $this->getParam('domainName'), $this->getParam('vhostId')))) {
             $err['domainName'] = "'{$this->getParam('domainName')}' virtualhost already exists";
         }
     } catch (Exception $e) {
         $err[] = $e->getMessage();
     }
     if (count($err) == 0) {
         $vHost = Scalr_Service_Apache_Vhost::init();
         if ($this->getParam('vhostId')) {
             $vHost->loadById($this->getParam('vhostId'));
             $this->user->getPermissions()->validate($vHost);
         } else {
             $vHost->envId = $this->getEnvironmentId();
             $vHost->clientId = $this->user->getAccountId();
         }
         $vHost->domainName = $this->getParam('domainName');
         $vHost->isSslEnabled = $this->getParam('isSslEnabled') == 'on' ? true : false;
         $vHost->farmId = $this->getParam('farmId');
         $vHost->farmRoleId = $this->getParam('farmRoleId');
         $vHost->httpdConf = $this->getParam("nonSslTemplate");
         $vHost->templateOptions = serialize(array("document_root" => trim($this->getParam('documentRoot')), "logs_dir" => trim($this->getParam('logsDir')), "server_admin" => trim($this->getParam('serverAdmin')), "server_alias" => trim($this->getParam('serverAlias'))));
         //SSL stuff
         if ($vHost->isSslEnabled) {
             if ($_FILES['certificate']['tmp_name']) {
                 $vHost->sslCert = file_get_contents($_FILES['certificate']['tmp_name']);
             }
             if ($_FILES['privateKey']['tmp_name']) {
                 $vHost->sslKey = file_get_contents($_FILES['privateKey']['tmp_name']);
             }
             if ($_FILES['certificateChain']['tmp_name']) {
                 $vHost->caCert = file_get_contents($_FILES['certificateChain']['tmp_name']);
             }
             $vHost->httpdConfSsl = $this->getParam("sslTemplate");
         } else {
             $vHost->sslCert = "";
             $vHost->sslKey = "";
             $vHost->caCert = "";
             $vHost->httpdConfSsl = "";
         }
         $vHost->save();
         $servers = $dbFarm->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
         foreach ($servers as $dBServer) {
             if ($dBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::NGINX) || $dBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::APACHE) && $dBServer->farmRoleId == $vHost->farmRoleId) {
                 $dBServer->SendMessage(new Scalr_Messaging_Msg_VhostReconfigure());
             }
         }
         $this->response->success(_('Virtualhost successfully saved'));
     } else {
         $this->response->failure();
         $this->response->data(array('errors' => $err));
     }
 }
예제 #4
0
파일: tests.php 프로젝트: jasherai/libwebta
 function testValidation()
 {
     $Validator = new Validator();
     // IsEmpty
     $empty_var = 'sdfsdfsdfs';
     $empty_var2 = 'sdfsdfs';
     $result = $Validator->IsNotEmpty($empty_var) && $Validator->IsNotEmpty($empty_var2);
     $this->assertTrue($result, "Validator->IsEmpty returned true on non empty var");
     $empty_var = '';
     $empty_var2 = 0;
     $result = $Validator->IsNotEmpty($empty_var) && $Validator->IsNotEmpty($empty_var2);
     $this->assertFalse($result, "Validator->IsEmpty returned false on empty var");
     // IsNumeric
     $number1 = 0;
     $number2 = -1;
     $number3 = 1.2;
     $result = $Validator->IsNumeric($number1) && $Validator->IsNumeric($number2) && $Validator->IsNumeric($number3);
     $this->assertTrue($result, "Validator->IsNumeric returned true on number var");
     $number1 = "1,2";
     $number2 = "abc";
     $result = $Validator->IsNumeric($number1) && $Validator->IsNumeric($number2);
     $this->assertFalse($result, "Validator->IsNumeric returned false on non-number var");
     // IsAlpha
     $alpha = "Alpha";
     $result = $Validator->IsAlpha($alpha);
     $this->assertTrue($result, "Validator->IsAlpha returned true");
     $alpha = "22323";
     $result = $Validator->IsAlpha($alpha);
     $this->assertFalse($result, "Validator->IsAlpha returned false");
     // IsAlphaNumeric
     $alpha = "Alpha12";
     $result = $Validator->IsAlphaNumeric($alpha);
     $this->assertTrue($result, "Validator->IsAlphaNumeric returned true");
     $alpha = "22323 sdfsd  fsdf s";
     $result = $Validator->IsAlphaNumeric($alpha);
     $this->assertFalse($result, "Validator->IsAlphaNumeric returned false");
     // IsEmail
     $email = "*****@*****.**";
     $result = $Validator->IsEmail($email);
     $this->assertTrue($result, "Validator->IsEmail returned true");
     $email = "asdasdsdfs";
     $result = $Validator->IsEmail($email);
     $this->assertFalse($result, "Validator->IsEmail returned false");
     // IsURL
     $url = "http://webta.net";
     $url2 = "webta.net";
     $url3 = "www.webta.net";
     $url4 = "http://www.webta.net";
     $result = $Validator->IsURL($url) && $Validator->IsURL($url2) && $Validator->IsURL($url3) && $Validator->IsURL($url4);
     $this->assertTrue($result, "Validator->IsURL returned true");
     $url = "asdasdsdfs";
     $url2 = "asdasdsdfs-222.1-";
     $url3 = "-webta.com";
     $result = $Validator->IsURL($url) && $Validator->IsURL($url2) && $Validator->IsURL($url3);
     $this->assertFalse($result, "Validator->IsURL returned false");
     // IsIPAddress
     $ip = "10.100.10.10";
     $result = $Validator->IsIPAddress($ip);
     $this->assertTrue($result, "Validator->IsIPAddress returned true");
     $ip = "288.1221.11.11";
     $result = $Validator->IsIPAddress($ip);
     $this->assertFalse($result, "Validator->IsIPAddress returned false");
     // IsExternalIPAddress
     $result = $Validator->IsExternalIPAddress("111.120.11.1");
     $this->assertTrue($result, "Validator->IsExternalIPAddress returned true for '111.120.11.1'");
     $result = $Validator->IsExternalIPAddress("192.168.1.1");
     $this->assertFalse($result, "Validator->IsExternalIPAddress returned false for '192.168.1.1'");
     $result = $Validator->IsExternalIPAddress("172.16.10.100");
     $this->assertFalse($result, "Validator->IsExternalIPAddress returned false for '172.16.10.100'");
     $result = $Validator->IsExternalIPAddress("172.32.10.100");
     $this->assertTrue($result, "Validator->IsExternalIPAddress returned true for '172.32.10.100'");
     // IsDomain
     $result = $Validator->IsDomain("webta.net");
     $this->assertTrue($result, "Validator->IsDomain returned true for webta.net");
     $result = $Validator->IsDomain("c1.webta.net");
     $this->assertTrue($result, "Validator->IsDomain returned true for c1.webta.net");
     $result = $Validator->IsDomain("webta@net") || $Validator->IsDomain("webtanet");
     $this->assertFalse($result, "Validator->IsDomain returned false for weird zones");
     // MatchesPattern
     $string = "abs_111";
     $pattern = "/^[A-Za-z]{3}_[0-9]{3}\$/";
     $result = $Validator->MatchesPattern($string, $pattern);
     $this->assertTrue($result, "Validator->MatchesPattern returned true");
     $pattern = "/^[A-Za-z]_[0-9]\$/";
     $result = $Validator->MatchesPattern($string, $pattern);
     $this->assertFalse($result, "Validator->MatchesPattern returned false");
     // AreEqual
     $s1 = "abc123";
     $s2 = "abc123";
     $result = $Validator->AreEqual($s1, $s2);
     $this->assertTrue($result, "Validator->AreEqual returned true");
     $s2 = "sdfsdfasd";
     $result = $Validator->AreEqual($s1, $s2);
     $this->assertFalse($result, "Validator->AreEqual returned false");
 }
예제 #5
0
	    	if ($registry_config->idn)
	    	{
	    		$allowed_utf8_chars = $registry_config->idn->xpath("//allowed-utf8-chars");
			    $disallowed_utf8_chars = $registry_config->idn->xpath("//disallowed-utf8-chars");
			    
			    if ($allowed_utf8_chars[0] || $disallowed_utf8_chars[0])
			    {
				    $Validator = new Validator();
				    if (!$Validator->IsDomain("{$post_domain}.{$post_TLD}", null, null, (string)$allowed_utf8_chars[0], (string)$disallowed_utf8_chars[0]))
				    	throw new Exception(_("Domain name contains non-supported characters"));
			    }
	    	}
	    	else
	    	{
			    $Validator = new Validator();
			    if (!$Validator->IsDomain("{$post_domain}.{$post_TLD}"))
			    	throw new Exception(_("Domain name contains non-supported characters"));
	    	}	
		    
		    // Create domain object
		    $Domain = $Registry->NewDomainInstance();
		    $Domain->Name = $post_domain;
		    
			try
			{ 
				// Be sure that it's free 
				$domain_avaiable = $Registry->DomainCanBeRegistered($Domain);
			}
			catch (Exception $e)
			{
				throw new Exception(_("Cannot check domain name availability. Make sure that you spelled domain name correctly"));
예제 #6
0
 public function xSaveAction()
 {
     $this->request->defineParams(array('domainId' => array('type' => 'int'), 'domainName', 'domainType', 'domainFarm' => array('type' => 'int'), 'domainFarmRole' => array('type' => 'int'), 'soaRefresh' => array('type' => 'int'), 'soaExpire' => array('type' => 'int'), 'soaRetry' => array('type' => 'int'), 'records' => array('type' => 'json')));
     $errors = array();
     // validate farmId, farmRoleId
     $farmId = 0;
     $farmRoleId = 0;
     if ($this->getParam('domainFarm')) {
         $DBFarm = DBFarm::LoadByID($this->getParam('domainFarm'));
         if (!$this->user->getPermissions()->check($DBFarm)) {
             $errors['domainFarm'] = _('Farm not found');
         } else {
             $farmId = $DBFarm->ID;
             if ($this->getParam('domainFarmRole')) {
                 $DBFarmRole = DBFarmRole::LoadByID($this->getParam('domainFarmRole'));
                 if ($DBFarmRole->FarmID != $DBFarm->ID) {
                     $errors['domainFarmRole'] = _('Role not found');
                 } else {
                     $farmRoleId = $DBFarmRole->ID;
                 }
             }
         }
     }
     // validate domain name
     $domainName = '';
     if (!$this->getParam('domainId')) {
         if ($this->getParam('domainType') == 'own') {
             $Validator = new Validator();
             if (!$Validator->IsDomain($this->getParam('domainName'))) {
                 $errors['domainName'] = _("Invalid domain name");
             } else {
                 $domainChunks = explode(".", $this->getParam('domainName'));
                 $chkDmn = '';
                 while (count($domainChunks) > 0) {
                     $chkDmn = trim(array_pop($domainChunks) . ".{$chkDmn}", ".");
                     $chkDomainId = $this->db->GetOne("SELECT id FROM dns_zones WHERE zone_name=? AND client_id != ?", array($chkDmn, $this->user->getAccountId()));
                     if ($chkDomainId) {
                         if ($chkDmn == $this->getParam('domainName')) {
                             $errors['domainName'] = sprintf(_("%s already exists on scalr nameservers"), $this->getParam('domainName'));
                         } else {
                             $chkDnsZone = DBDNSZone::loadById($chkDomainId);
                             $access = false;
                             foreach (explode(";", $chkDnsZone->allowedAccounts) as $email) {
                                 if ($email == $this->user->getEmail()) {
                                     $access = true;
                                 }
                             }
                             if (!$access) {
                                 $errors['domainName'] = sprintf(_("You cannot use %s domain name because top level domain %s does not belong to you"), $this->getParam('domainName'), $chkDmn);
                             }
                         }
                     }
                 }
                 //if (! $errors['domainName'])
                 $domainName = $this->getParam('domainName');
             }
         } else {
             $domainName = Scalr::GenerateUID() . '.' . CONFIG::$DNS_TEST_DOMAIN_NAME;
         }
         // check in DB
         $rez = $this->db->GetOne("SELECT id FROM dns_zones WHERE zone_name = ?", array($domainName));
         if ($rez) {
             $errors['domainName'] = 'Domain name already exist in database';
         }
     }
     $records = array();
     foreach ($this->getParam('records') as $key => $r) {
         if (($r['name'] || $r['value']) && $r['issystem'] == 0) {
             $r['name'] = str_replace("%hostname%", "{$domainName}", $r['name']);
             $r['value'] = str_replace("%hostname%", "{$domainName}", $r['value']);
             $records[$key] = $r;
         }
     }
     $recordsValidation = Scalr_Net_Dns_Zone::validateRecords($records);
     if ($recordsValidation !== true) {
         $errors = array_merge($errors, $recordsValidation);
     }
     if (count($errors) == 0) {
         if ($this->getParam('domainId')) {
             $DBDNSZone = DBDNSZone::loadById($this->getParam('domainId'));
             $this->user->getPermissions()->validate($DBDNSZone);
             $DBDNSZone->soaRefresh = $this->getParam('soaRefresh');
             $DBDNSZone->soaExpire = $this->getParam('soaExpire');
             $DBDNSZone->soaRetry = $this->getParam('soaRetry');
             $this->response->success("DNS zone successfully updated. It could take up to 5 minutes to update it on NS servers.");
         } else {
             $DBDNSZone = DBDNSZone::create($domainName, $this->getParam('soaRefresh'), $this->getParam('soaExpire'), str_replace('@', '.', $this->user->getEmail()), $this->getParam('soaRetry'));
             $DBDNSZone->clientId = $this->user->getAccountId();
             $DBDNSZone->envId = $this->getEnvironmentId();
             $this->response->success("DNS zone successfully added to database. It could take up to 5 minutes to setup it on NS servers.");
         }
         if ($DBDNSZone->farmRoleId != $farmRoleId || $DBDNSZone->farmId != $farmId) {
             $DBDNSZone->farmId = 0;
             $DBDNSZone->updateSystemRecords();
         }
         $DBDNSZone->farmRoleId = $farmRoleId;
         $DBDNSZone->farmId = $farmId;
         $DBDNSZone->setRecords($records);
         $DBDNSZone->save(true);
     } else {
         $this->response->failure();
         $this->response->data(array('errors' => $errors));
     }
 }
예제 #7
0
@set_time_limit(999999);
if (Client::Load($_SESSION['userid'])->GetSettingValue('domain_preorder') != 1) {
    CoreUtils::Redirect("index.php");
}
if ($_POST) {
    $Validator = new Validator();
    $lines = explode("\n", $post_domains);
    $post_domainname = FQDN::Sanitize($post_domainname);
    list($domain_name, $extension) = FQDN::Parse($post_domainname);
    $expiredate = trim($post_dt);
    // Validate date. Sucks.
    if (!preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}\$/", $expiredate) || !strtotime($expiredate)) {
        throw new ApplicationException(sprintf(_("Incorrect expiration date.")));
    }
    // Validate domain name
    if (!$Validator->IsDomain($post_domainname)) {
        throw new Exception(sprintf(_("Incorrect domain name: %s"), $post_domainname));
    }
    if (!$Registries[$extension]) {
        try {
            $Registry = RegistryModuleFactory::GetInstance()->GetRegistryByExtension($extension);
        } catch (Exception $e) {
            throw new ApplicationException($e->getMessage());
        }
        $Manifest = $Registry->GetManifest();
        if ($Manifest->GetRegistryOptions()->ability->preregistration != 1) {
            throw new ApplicationException(sprintf(_("Module %s does not support domain pre-registration."), $Registry->GetModuleName()));
        }
    }
    $Domain = $Registry->NewDomainInstance();
    $Domain->Name = $domain_name;
예제 #8
0
 public function xImportStartAction()
 {
     $validator = new Validator();
     if ($validator->IsDomain($this->getParam('remoteIp'))) {
         $remoteIp = @gethostbyname($this->getParam('remoteIp'));
     } else {
         $remoteIp = $this->getParam('remoteIp');
     }
     if (!$validator->IsIPAddress($remoteIp, _("Server IP address"))) {
         $err['remoteIp'] = 'Server IP address is incorrect';
     }
     if (!$validator->IsNotEmpty($this->getParam('roleName'))) {
         $err['roleName'] = 'Role name cannot be empty';
     }
     if (strlen($this->getParam('roleName')) < 3) {
         $err['roleName'] = _("Role name should be greater than 3 chars");
     }
     if (!preg_match("/^[A-Za-z0-9-]+\$/si", $this->getParam('roleName'))) {
         $err['roleName'] = _("Role name is incorrect");
     }
     if ($this->db->GetOne("SELECT id FROM roles WHERE name=? AND (env_id = '0' OR env_id = ?)", array($this->getParam('roleName'), $this->getEnvironmentId()))) {
         $err['roleName'] = 'Selected role name is already used. Please select another one.';
     }
     if ($this->getParam('add2farm')) {
     }
     // Find server in the database
     $existingServer = $this->db->GetRow("SELECT * FROM servers WHERE remote_ip = ?", array($remoteIp));
     if ($existingServer["client_id"] == $this->user->getAccountId()) {
         $err['remoteIp'] = sprintf(_("Server %s is already in Scalr with a server_id: %s"), $remoteIp, $existingServer["server_id"]);
     } else {
         if ($existingServer) {
             $err['remoteIp'] = sprintf(_("Server with selected IP address cannot be imported"));
         }
     }
     if (count($err) == 0) {
         $cryptoKey = Scalr::GenerateRandomKey(40);
         $creInfo = new ServerCreateInfo($this->getParam('platform'), null, 0, 0);
         $creInfo->clientId = $this->user->getAccountId();
         $creInfo->envId = $this->getEnvironmentId();
         $creInfo->farmId = (int) $this->getParam('farmId');
         $creInfo->remoteIp = $remoteIp;
         $creInfo->SetProperties(array(SERVER_PROPERTIES::SZR_IMPORTING_ROLE_NAME => $this->getParam('roleName'), SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR => $this->getParam('behavior'), SERVER_PROPERTIES::SZR_KEY => $cryptoKey, SERVER_PROPERTIES::SZR_KEY_TYPE => SZR_KEY_TYPE::PERMANENT, SERVER_PROPERTIES::SZR_VESION => "0.7-1", SERVER_PROPERTIES::SZR_IMPORTING_OS_FAMILY => $this->getParam('os')));
         if ($this->getParam('platform') == SERVER_PLATFORMS::EUCALYPTUS) {
             $creInfo->SetProperties(array(EUCA_SERVER_PROPERTIES::REGION => $this->getParam('cloudLocation')));
         }
         if ($this->getParam('platform') == SERVER_PLATFORMS::RACKSPACE) {
             $creInfo->SetProperties(array(RACKSPACE_SERVER_PROPERTIES::DATACENTER => $this->getParam('cloudLocation')));
         }
         if ($this->getParam('platform') == SERVER_PLATFORMS::OPENSTACK) {
             $creInfo->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $this->getParam('cloudLocation')));
         }
         if ($this->getParam('platform') == SERVER_PLATFORMS::NIMBULA) {
             $creInfo->SetProperties(array(NIMBULA_SERVER_PROPERTIES::CLOUD_LOCATION => 'nimbula-default'));
         }
         $dbServer = DBServer::Create($creInfo, true);
         $this->response->data(array('serverId' => $dbServer->serverId));
     } else {
         $this->response->failure();
         $this->response->data(array('errors' => $err));
     }
 }
예제 #9
0
 public function DNSZoneCreate($DomainName, $FarmID = null, $FarmRoleID = null)
 {
     $DomainName = trim($DomainName);
     $Validator = new Validator();
     if (!$Validator->IsDomain($DomainName)) {
         throw new Exception(_("Invalid domain name"));
     }
     $domain_chunks = explode(".", $DomainName);
     $chk_dmn = '';
     while (count($domain_chunks) > 0) {
         $chk_dmn = trim(array_pop($domain_chunks) . ".{$chk_dmn}", ".");
         if ($this->DB->GetOne("SELECT id FROM dns_zones WHERE zone_name=? AND client_id != ?", array($chk_dmn, $this->user->getAccountId()))) {
             if ($chk_dmn == $DomainName) {
                 throw new Exception(sprintf(_("%s already exists on scalr nameservers"), $DomainName));
             } else {
                 throw new Exception(sprintf(_("You cannot use %s domain name because top level domain %s does not belong to you"), $DomainName, $chk_dmn));
             }
         }
     }
     if ($FarmID) {
         $DBFarm = DBFarm::LoadByID($FarmID);
         if ($DBFarm->EnvID != $this->Environment->id) {
             throw new Exception(sprintf("Farm #%s not found", $FarmID));
         }
     }
     if ($FarmRoleID) {
         $DBFarmRole = DBFarmRole::LoadByID($FarmRoleID);
         if ($DBFarm->ID != $DBFarmRole->FarmID) {
             throw new Exception(sprintf("FarmRole #%s not found on Farm #%s", $FarmRoleID, $FarmID));
         }
     }
     $response = $this->CreateInitialResponse();
     $DBDNSZone = DBDNSZone::create($DomainName, 14400, 86400, str_replace('@', '.', $this->user->getEmail()));
     $DBDNSZone->farmRoleId = (int) $FarmRoleID;
     $DBDNSZone->farmId = (int) $FarmID;
     $DBDNSZone->clientId = $this->user->getAccountId();
     $DBDNSZone->envId = $this->Environment->id;
     $def_records = $this->DB->GetAll("SELECT * FROM default_records WHERE clientid=?", array($this->user->getAccountId()));
     foreach ($def_records as $record) {
         $record["name"] = str_replace("%hostname%", "{$DomainName}.", $record["name"]);
         $record["value"] = str_replace("%hostname%", "{$DomainName}.", $record["value"]);
         $records[] = $record;
     }
     $nss = $this->DB->GetAll("SELECT * FROM nameservers WHERE isbackup='0'");
     foreach ($nss as $ns) {
         $records[] = array("id" => "c" . rand(10000, 999999), "type" => "NS", "ttl" => 14400, "value" => "{$ns["host"]}.", "name" => "{$DomainName}.", "issystem" => 0);
     }
     $DBDNSZone->setRecords($records);
     $DBDNSZone->save(true);
     $response->Result = 1;
     return $response;
 }
예제 #10
0
 if (empty($hostnames)) {
     $errmsg = sprintf(_("No nameservers were entered"));
 } else {
     if (!$_SESSION['BU_TLD']) {
         $errmsg = sprintf(_("No domain extension was selected"));
     } else {
         if (!$_SESSION['BU_DOMAINS']) {
             $errmsg = sprintf(_("No domains were selected"));
         } else {
             // Create bulk update task abd put in into tasks queue
             $Queue = TaskQueue::GetInstance();
             try {
                 $nslist = array();
                 $Validator = new Validator();
                 foreach ($hostnames as $hostname) {
                     if ($Validator->IsDomain($hostname)) {
                         $nslist[] = new Nameserver($hostname);
                     } else {
                         throw new Exception(sprintf(_("%s is not a valid host"), $hostname));
                     }
                 }
                 // Construct task
                 $Task = new Task($_SESSION['userid'], new BulkUpdateNSJob($_SESSION['BU_TLD'], $nslist), $_SESSION['BU_DOMAINS']);
                 $Queue->Put($Task);
                 CoreUtils::Redirect("bulk_update_complete.php");
             } catch (Exception $e) {
                 $errmsg = $e->getMessage();
                 $display['hostnames'] = join("\n", $hostnames);
             }
         }
     }
 private function Init()
 {
     if (!$this->prepared) {
         $ErrList = new ErrorList();
         if (!$this->Registry) {
             $Factory = RegistryModuleFactory::GetInstance();
             try {
                 $this->Registry = $Factory->GetRegistryByExtension($this->tld);
             } catch (Exception $e) {
                 throw new RegisterDomainAction_Exception(sprintf(_("Cannot init registry module. Reason: %s"), $e->getMessage()));
             }
         }
         $registry_config = $this->Registry->GetManifest()->GetSectionConfig();
         $Validator = new Validator();
         /**
          * Validate period
          */
         if ($this->period) {
             self::ValidatePeriod($this->period, $this->Registry);
         }
         /*
          * Validate additional domain information
          */
         $extra_fields = null;
         if (count($registry_config->domain->registration->extra_fields->field) > 0) {
             $extra_fields = UI::GetRegExtraFieldsForSmarty($registry_config);
             foreach ($extra_fields as $field) {
                 if ($field["isrequired"] == 1 && $field["type"] != "checkbox") {
                     if (!strlen($this->extra_data[$field['name']])) {
                         $ErrList->AddMessage(sprintf(_("%s required"), ucfirst($field["name"])));
                     }
                 }
             }
         }
         // Break on errors
         $this->ExceptionOnErrors($ErrList);
         /**
          * Validate DNS
          */
         if (!$this->managed_dns_enabled) {
             if (!$this->nameserver_list) {
                 foreach ($this->ns_list as $ns) {
                     $this->nameserver_list[] = new Nameserver($ns);
                 }
             }
             $nameserver_list = $this->nameserver_list;
             if (count(array_unique($nameserver_list)) < count($nameserver_list)) {
                 $ErrList->AddMessage(_("Cannot use the same nameserver twice."));
             } else {
                 foreach ($nameserver_list as $Nameserver) {
                     if (!$Validator->IsDomain($Nameserver->HostName)) {
                         $ErrList->AddMessage(sprintf(_("'%s' is not a valid host"), $Nameserver->HostName));
                     }
                 }
             }
         } else {
             $this->nameserver_list = array(new Nameserver(CONFIG::$NS1), new Nameserver(CONFIG::$NS2));
         }
         $this->ExceptionOnErrors($ErrList);
         /*
          * Validate contacts 
          */
         if (!$this->contact_list) {
             $DbContact = DBContact::GetInstance();
             $this->contact_list = array();
             foreach ($this->clid_list as $ctype => $clid) {
                 if (!$clid) {
                     continue;
                 }
                 try {
                     $Contact = $DbContact->LoadByCLID($clid);
                     $this->contact_list[$ctype] = $Contact;
                 } catch (Exception $e) {
                     $ErrList->AddMessage(sprintf(_("Cannot load %s contact. %s"), $ctype, $clid, $e->getMessage()));
                 }
             }
             // Break on errors
             $this->ExceptionOnErrors($ErrList);
         }
         $this->ExceptionOnErrors(self::ValidateContactList($this->contact_list, $this->Registry));
         $this->prepared = true;
     }
 }
예제 #12
0
}
if ($_POST) {
    $Validator = new Validator();
    $lines = explode("\n", $post_domains);
    $err = array();
    foreach ($lines as $k => $line) {
        try {
            $ErrorList = new ErrorList();
            $chunks = explode(",", $line);
            $domainname = trim($chunks[0]);
            $expiredate = trim($chunks[1]);
            if (!preg_match("/^[0-9]{4}-[0-9]{2}-[0-9]{2}\$/", $expiredate) || !strtotime($expiredate)) {
                $ErrorList->AddMessage(sprintf(_("Incorrect expiration date (%s) for domain %s."), $expiredate, $domainname));
                throw $ErrorList;
            }
            if (!$Validator->IsDomain($domainname)) {
                $ErrorList->AddMessage(sprintf(_("Incorrect domain name %s"), $domainname));
                throw $ErrorList;
            }
            $dmn_chunks = explode(".", $domainname);
            $domain_name = array_shift($dmn_chunks);
            $extension = implode(".", $dmn_chunks);
            if (!$Registries[$extension]) {
                try {
                    $Registries[$extension] = RegistryModuleFactory::GetInstance()->GetRegistryByExtension($extension);
                } catch (Exception $e) {
                    $ErrorList->AddMessage(sprintf(_("Error while processing domain %s: %s"), $domainname, $e->getMessage()));
                    throw $ErrorList;
                }
                // F**k! Add a singleton here, you dick!
                $Manifest = $Registries[$extension]->GetManifest();
예제 #13
0
 // Transfer not available
 // domain=>reason
 $res_fail = array();
 $Order = new Order($_SESSION['userid']);
 // For each entered domain name check tranfer posibility
 if (!$errmsg && $Registry) {
     foreach ($domainnames as $domain_name) {
         Log::Log("Process {$domain_name}", E_USER_NOTICE);
         if ($Registry->GetManifest()->GetSectionConfig()->idn) {
             $allowed_utf8_chars = $Registry->GetManifest()->GetSectionConfig()->idn->xpath("//allowed-utf8-chars");
             $disallowed_utf8_chars = $Registry->GetManifest()->GetSectionConfig()->idn->xpath("//disallowed-utf8-chars");
             $allowed_chars = (string) $allowed_utf8_chars[0];
             $disallowed_chars = (string) $disallowed_utf8_chars[0];
         }
         $Validator = new Validator();
         if (!$Validator->IsDomain("{$domain_name}.{$_SESSION["BT_TLD"]}", null, null, $allowed_chars, $disallowed_chars)) {
             $res_fail[$domain_name] = _("Domain name contains non-supported characters");
         } else {
             $DbDomain = DBDomain::GetInstance();
             // Inst domain object
             $Domain = $Registry->NewDomainInstance();
             $Domain->Name = $domain_name;
             // Check that domain can be transferred
             if ($DbDomain->ActiveDomainExists($Domain)) {
                 $res_fail[$domain_name] = _("Sorry, this domain can not be transferred");
             }
             // If no errors - start transfer process
             if ($res_fail[$domain_name] === null) {
                 Log::Log("Update domain status to awaitingPayment", E_USER_NOTICE);
                 // Configure and save domain in Db
                 $Domain->UserID = $Order->UserID;