Ejemplo n.º 1
0
 /**
  * IPAddress Constructor
  *
  * @param string $ip IP address string, q.x.y.z notation.
  * @uses Validaror
  */
 function __construct($ip)
 {
     $this->Validator = Core::GetInstance("Validator");
     $this->IP = $ip;
                
     if (!$this->Validator->IsIPAddress($ip))
         $this->IP = false;
 }
Ejemplo n.º 2
0
 /**
  * Convert Subnet mask 2 net bits
  *
  * @param string $mask
  * @return int
  */
 public final function SubnetMask2Bits($mask)
 {
     if (!$this->Validator->IsIPAddress($mask)) {
         return false;
     }
     $binary = $this->IP2bin($mask);
     return substr_count($binary, "1");
 }
Ejemplo n.º 3
0
 public function xSaveSettingsAction()
 {
     $this->request->defineParams(array('dnsZoneId' => array('type' => 'int'), 'axfrAllowedHosts' => array('type' => 'string'), 'allowedAccounts' => array('type' => 'string'), 'allowManageSystemRecords' => array('type' => 'int')));
     $DBDNSZone = DBDNSZone::loadById($this->getParam('dnsZoneId'));
     $this->user->getPermissions()->validate($DBDNSZone);
     $Validator = new Validator();
     if ($this->getParam('axfrAllowedHosts') != '') {
         $hosts = explode(";", $this->getParam('axfrAllowedHosts'));
         foreach ($hosts as $host) {
             $host = trim($host);
             if (!$Validator->IsIPAddress($host)) {
                 $errors['axfrAllowedHosts'] = sprintf(_("'%s' is not valid IP address"), $host);
             }
         }
     }
     if ($this->getParam('allowedAccounts')) {
         $accounts = explode(";", $this->getParam('allowedAccounts'));
         foreach ($accounts as $account) {
             if (!$Validator->IsEmail($account)) {
                 $errors['allowedAccounts'] = sprintf(_("'%s' is not valid Email address"), $account);
             }
         }
     }
     if (count($errors) == 0) {
         if ($this->getParam('axfrAllowedHosts') != $DBDNSZone->axfrAllowedHosts) {
             $DBDNSZone->axfrAllowedHosts = $this->getParam('axfrAllowedHosts');
             $DBDNSZone->isZoneConfigModified = 1;
         }
         $DBDNSZone->allowManageSystemRecords = $this->getParam('allowManageSystemRecords');
         $DBDNSZone->allowedAccounts = $this->getParam('allowedAccounts');
         $DBDNSZone->save();
         $this->response->success('Changes have been saved. They will become active in few minutes.');
     } else {
         $this->response->failure();
         $this->response->data(array('errors' => $errors));
     }
 }
Ejemplo n.º 4
0
 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");
 }
Ejemplo n.º 5
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));
     }
 }
Ejemplo n.º 6
0
	<br>After you add a nameserver, make sure to add appropriate NS record in <a target='_blank' href='dnsdef_manage.php'>Settings&nbsp;&raquo;&nbsp;Managed DNS&nbsp;&raquo;&nbsp;Set default zone records</a>.";
	
	if ($_POST) 
	{
		$Validator = new Validator();
		
		// 
		if (!$Validator->IsAlpha($post_username))
			$err[] = _("Username must consist of letters and numbers only");
		
		//
		if (!$Validator->IsNumeric($post_port))
			$err[] = _("Server port must be a number");
		
		// Check hostname
		if (!$Validator->IsIPAddress($post_host))
			$err[] = sprintf(_("'%s' is not valid IP address"), $post_host);
	
	    if (count($err) == 0)
	    {
    		if (!$post_id)
    		{
    			$db->Execute("INSERT INTO nameservers (host, port, username, password, rndc_path, named_path, namedconf_path, isnew) values (?,?,?,?,?,?,?, 1)",
                    			array(   $post_host, 
                    			         $post_port, 
                    			         $post_username, 
                    			         $Crypto->Encrypt($post_password, LICENSE_FLAGS::REGISTERED_TO), 
                    			         $post_rndc_path, 
                    			         $post_named_path, 
                    			         $post_namedconf_path
                    			     )
Ejemplo n.º 7
0
		
		
		// if add new host
		if ($post_add)
		{
			// Check host in database
			$chk = $db->GetRow("
				SELECT * 
				FROM nhosts 
				WHERE hostname=? AND domainid=?", 
				array($_POST["ns_add"], $_SESSION["selected_domain"])
			);
			
			if (!$chk)
			{
				if (!$Validator->IsIPAddress($post_ip_add))
					$err[] = _("IP address incorrect");
				else 
				{
					$nshost = new NameserverHost("{$post_ns_add}.{$Domain->GetHostName()}", $post_ip_add);
					
					try
					{
						$add = (bool)$Registry->CreateNameserverHost($nshost);
					}
					catch (ObjectExistsException $e)
					{
						// do nothing
						$add = true;
					}
					catch (Exception $e)