Example #1
0
 public function requestAction()
 {
     // start
     $str_ip = $this->_getParam('ip');
     $zend_validate_ip = new Zend_Validate_Ip();
     if (is_null($str_ip) || !$zend_validate_ip->isValid($str_ip)) {
         $arr_data = array('outcome' => 'failed', 'reason' => 'validation error');
         $this->_helper->json($arr_data);
         return;
     }
     // lets get our IP Address ip number
     $arr_ip_parts = explode('.', $str_ip);
     $int_ipnum = $arr_ip_parts[0] * 16777216 + $arr_ip_parts[1] * 65536 + $arr_ip_parts[2] * 256 + $arr_ip_parts[3];
     // lets get our info from the DB
     $dbtable_blocks = new Application_Model_DbTable_Blocks();
     $arr_results_block = $dbtable_blocks->fetchAll("`endIpNum` >= {$int_ipnum}", "endIpNum ASC", 1);
     if (count($arr_results_block) != 1) {
         $arr_data = array('outcome' => 'failed', 'reason' => 'not found');
         $this->_helper->json($arr_data);
         return;
     } else {
         $arr_results_block = $arr_results_block->toArray();
         $arr_results_block = $arr_results_block[0];
     }
     $dbtable_locations = new Application_Model_DbTable_Locations();
     $arr_results_location = $dbtable_locations->fetchRow("locId = {$arr_results_block['locId']}")->toArray();
     $dbtable_countries = new Application_Model_DbTable_Countries();
     $arr_results_countries = $dbtable_countries->fetchRow("`country_code` = '{$arr_results_location['country']}'")->toArray();
     $arr_data = array('outcome' => 'success', 'ip' => $str_ip, 'country_name' => $arr_results_countries['country_name'], 'country_code' => $arr_results_countries['country_code'], 'region' => $arr_results_location['region'], 'city' => $arr_results_location['city'], 'postalcode' => $arr_results_location['postalCode']);
     $this->_helper->json($arr_data);
     // end
 }
Example #2
0
 /**
  * Ensures that the validator follows expected behavior
  *
  * @return void
  */
 public function testBasic()
 {
     $valuesExpected = array(array(true, array('1.2.3.4', '10.0.0.1', '255.255.255.255')), array(false, array('0.0.0.256', '1.2.3.4.5', '0.0.0.0')));
     foreach ($valuesExpected as $element) {
         foreach ($element[1] as $input) {
             $this->assertEquals($element[0], $this->_validator->isValid($input));
         }
     }
 }
Example #3
0
 /**
  * Set the Hostname / IP to connect to.
  * @param	string			$host	Hostname / IP of the Database.
  * @return	Couchdb_Config	$this	This main class for method chaining.
  * @throws	Couchdb_Exception_Parameter
  */
 public function setHost($host)
 {
     $ip = new Zend_Validate_Ip();
     $name = new Zend_Validate_Hostname();
     if ($ip->isValid($host) xor $name->isValid($host)) {
         throw new Couchdb_Exception_Parameter("Wrong Parameters, host must either be a valid hostname or an IP");
     }
     $this->_host = $host;
     return $this;
 }
Example #4
0
 /**
  * sets new ip address
  *
  * @param string $ip
  * @throws Zend_Service_DeveloperGarden_Exception
  * @return Zend_Service_DeveloperGarden_IpLocation_IpAddress
  */
 public function setIp($ip)
 {
     $validator = new Zend_Validate_Ip();
     if (!$validator->isValid($ip)) {
         $message = $validator->getMessages();
         throw new Zend_Service_DeveloperGarden_Exception($message['notIpAddress']);
     }
     $this->_address = $ip;
     return $this;
 }
Example #5
0
 /**
  * sets new ip address
  *
  * @param string $ip
  * @throws Zend_Service_DeveloperGarden_Exception
  * @return Zend_Service_DeveloperGarden_IpLocation_IpAddress
  */
 public function setIp($ip)
 {
     $validator = new Zend_Validate_Ip();
     if (!$validator->isValid($ip)) {
         $message = $validator->getMessages();
         require_once PHP_LIBRARY_PATH . 'Zend/Service/DeveloperGarden/Exception.php';
         throw new Zend_Service_DeveloperGarden_Exception($message['notIpAddress']);
     }
     $this->_address = $ip;
     return $this;
 }
Example #6
0
 public function getCurrentIp()
 {
     if (self::$_unitTestEnabled) {
         return '127.0.0.1';
     }
     if (!$this->current_ip) {
         $request = $this->getRequest();
         if ($request) {
             if ($request->getServer('HTTP_CLIENT_IP')) {
                 $ip = $request->getServer('HTTP_CLIENT_IP');
             } else {
                 if ($request->getServer('HTTP_X_FORWARDED_FOR')) {
                     $ip = trim(end(explode(',', $request->getServer('HTTP_X_FORWARDED_FOR'))));
                 } else {
                     $ip = $request->getServer('REMOTE_ADDR');
                 }
             }
         } else {
             if (isset($_SERVER['HTTP_CLIENT_IP'])) {
                 $ip = $_SERVER['HTTP_CLIENT_IP'];
             } else {
                 if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                     $ip = trim(end(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])));
                 } else {
                     $ip = $_SERVER['REMOTE_ADDR'];
                 }
             }
         }
         $config = Zend_Registry::get('config');
         if (isset($config['resources']['loadbalancer']['enabled']) && $config['resources']['loadbalancer']['enabled']) {
             if ($request && $request->getServer('HTTP_X_FORWARDED_FOR')) {
                 $ip = trim(end(explode(',', $request->getServer('HTTP_X_FORWARDED_FOR'))));
             } else {
                 if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                     $ip = trim(end(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])));
                 }
             }
         }
         $ip_validation = new Zend_Validate_Ip(array('allowipv6' => true, 'allowipv4' => true));
         if (!$ip_validation->isValid($ip)) {
             throw new Base_Exception('Niedozwolona wartość IP hosta zdalnego! Możliwa próba ataku typu Man In The Middle.');
         }
         $this->current_ip = $ip;
     }
     return $this->current_ip;
 }
Example #7
0
File: Ip.php Project: knatorski/SMS
 /**
  * 
  * @param string $value
  * @return boolean
  */
 public function _validateIPv4($value)
 {
     if (!parent::_validateIPv4($value)) {
         return false;
     }
     if (!$this->_cidr_match($value, $this->_range)) {
         return false;
     }
     return true;
 }
Example #8
0
 public function isValid($value, $context = array())
 {
     if (!isset($context['network'])) {
         $this->_error(self::NOT_IP_ADDRESS);
         return false;
     }
     $network = $context['network'];
     $maskPrefix = explode("/", $value);
     if (count($maskPrefix) == 2) {
         $value = $maskPrefix[1];
     }
     $network_bytearray = App_Util_Ip::dtr_pton($network);
     if (is_numeric($value)) {
         if ($value <= 128 && $value > 0) {
             if (!filter_var($network, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
                 $this->_error(self::INCOMPATIBLE_IP);
                 return false;
             }
             $mask_bytearray = App_Util_Ip::dtr_pton(App_Util_Ip::long2ipv6($value));
             if (($network_bytearray & $mask_bytearray) != $network_bytearray) {
                 $this->_error(self::INCOMPATIBLE_NETWORK);
                 return false;
             }
             return true;
         } else {
             $this->_error(self::INVALID_IPV6_PREFFIX);
             return false;
         }
     }
     if (parent::isValid($value)) {
         if (!filter_var($network, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
             $this->_error(self::INCOMPATIBLE_IP);
             return false;
         }
         $mask_bytearray = App_Util_Ip::dtr_pton($value);
         if (($network_bytearray & $mask_bytearray) != $network_bytearray) {
             $this->_error(self::INCOMPATIBLE_NETWORK);
             return false;
         }
         return true;
     }
     return false;
 }
Example #9
0
 /**
  * Unshare IP address for a server ($id)
  * 
  * @param  string $id
  * @param  string $ip
  * @return boolean 
  */
 public function unshareIpAddress($id, $ip)
 {
     if (empty($id)) {
         // require_once 'Zend/Service/Rackspace/Exception.php';
         throw new Zend_Service_Rackspace_Exception('You didn\'t specified the ID of the server');
     }
     if (empty($ip)) {
         // require_once 'Zend/Service/Rackspace/Exception.php';
         throw new Zend_Service_Rackspace_Exception('You didn\'t specified the IP address to share');
     }
     $validator = new Zend_Validate_Ip();
     if (!$validator->isValid($ip)) {
         // require_once 'Zend/Service/Rackspace/Exception.php';
         throw new Zend_Service_Rackspace_Exception("The parameter {$ip} specified is not a valid IP address");
     }
     $result = $this->httpCall($this->getManagementUrl() . '/servers/' . rawurlencode($id) . '/ips/public/' . rawurlencode($ip), 'DELETE');
     $status = $result->getStatus();
     switch ($status) {
         case '202':
             // break intentionally omitted
             return true;
         case '503':
             $this->errorMsg = self::ERROR_SERVICE_UNAVAILABLE;
             break;
         case '401':
             $this->errorMsg = self::ERROR_UNAUTHORIZED;
             break;
         case '404':
             $this->errorMsg = self::ERROR_ITEM_NOT_FOUND;
             break;
         case '413':
             $this->errorMsg = self::ERROR_OVERLIMIT;
             break;
         default:
             $this->errorMsg = $result->getBody();
             break;
     }
     $this->errorCode = $status;
     return false;
 }
Example #10
0
 /**
  * Ensures that getMessages() returns expected default value
  *
  * @return void
  */
 public function testGetMessages()
 {
     $this->assertEquals(array(), $this->_validator->getMessages());
 }
Example #11
0
 /**
  * @ZF-8640
  */
 public function testNonNewlineValidation()
 {
     $this->assertFalse($this->_validator->isValid("::C0A8:2\n"));
 }
Example #12
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  *
  * @param  mixed $value
  * @throws Zend_Validate_Exception if a fatal error occurs for validation process
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_messages = array();
     // Check input against IP address schema
     /**
      * @see Zend_Validate_Ip
      */
     require_once 'Zend/Validate/Ip.php';
     $ip = new Zend_Validate_Ip();
     if ($ip->isValid($value)) {
         if (!($this->_allow & self::ALLOW_IP)) {
             $this->_messages[] = "'{$value}' appears to be an IP address but IP addresses are not allowed";
             return false;
         } else {
             return true;
         }
     }
     // Check input against DNS hostname schema
     $domainParts = explode('.', $value);
     if (count($domainParts) > 1 && strlen($value) >= 4 && strlen($value) <= 254) {
         $status = false;
         do {
             // First check TLD
             if (preg_match('/([a-z]{2,10})$/i', end($domainParts), $matches)) {
                 reset($domainParts);
                 // Hostname characters are: *(label dot)(label dot label); max 254 chars
                 // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
                 // id-prefix: alpha / digit
                 // ldh: alpha / digit / dash
                 // Match TLD against known list
                 $valueTld = strtolower($matches[1]);
                 if (!in_array($valueTld, $this->_validTlds)) {
                     $this->_messages[] = "'{$value}' appears to be a DNS hostname but cannot match TLD against known list";
                     $status = false;
                     break;
                 }
                 /**
                  * @todo 0.9 ZF-881 Implement UTF-8 support for IDN characters allowed in some TLD hostnames, i.e. bürger.de
                  */
                 // Keep label regex short to avoid issues with long patterns when matching IDN hostnames
                 $labelChars = 'a-zA-Z0-9';
                 $regexLabel = '/^[' . $labelChars . '\\x2d]{1,63}$/';
                 // Check each hostname part
                 $valid = true;
                 foreach ($domainParts as $domainPart) {
                     // Check dash (-) does not start, end or appear in 3rd and 4th positions
                     if (strpos($domainPart, '-') === 0 || strlen($domainPart) > 2 && strpos($domainPart, '-', 2) == 2 && strpos($domainPart, '-', 3) == 3 || strrpos($domainPart, '-') === strlen($domainPart) - 1) {
                         $this->_messages[] = "'{$value}' appears to be a DNS hostname but contains a dash(-) " . "in an invalid position";
                         $status = false;
                         break 2;
                     }
                     // Check each domain part
                     $status = @preg_match($regexLabel, strtolower($domainPart));
                     if ($status === false) {
                         /**
                          * Regex error
                          * @see Zend_Validate_Exception
                          */
                         require_once 'Zend/Validate/Exception.php';
                         throw new Zend_Validate_Exception('Internal error: DNS validation failed');
                     } elseif ($status === 0) {
                         $valid = false;
                     }
                 }
                 // If all labels didn't match, the hostname is invalid
                 if (!$valid) {
                     $this->_messages[] = "'{$value}' appears to be a DNS hostname but cannot match against " . "hostname schema for TLD '{$valueTld}'";
                     $status = false;
                 }
             } else {
                 // Hostname not long enough
                 $this->_messages[] = "'{$value}' appears to be a DNS hostname but cannot extract TLD part";
                 $status = false;
             }
         } while (false);
         // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
         // passes validation
         if ($status && $this->_allow & self::ALLOW_DNS) {
             return true;
         }
     } else {
         $this->_messages[] = "'{$value}' does not match the expected structure for a DNS hostname";
     }
     // Check input against local network name schema; last chance to pass validation
     $status = @preg_match($this->_regex['local'], $value);
     if (false === $status) {
         /**
          * Regex error
          * @see Zend_Validate_Exception
          */
         require_once 'Zend/Validate/Exception.php';
         throw new Zend_Validate_Exception('Internal error: local network name validation failed');
     }
     // If the input passes as a local network name, and local network names are allowed, then the
     // hostname passes validation
     $allowLocal = $this->_allow & self::ALLOW_LOCAL;
     if ($status && $allowLocal) {
         return true;
     }
     // If the input does not pass as a local network name, add a message
     if (!$status) {
         $this->_messages[] = "'{$value}' does not appear to be a valid local network name";
     }
     // If local network names are not allowed, add a message
     if (!$allowLocal) {
         $this->_messages[] = "'{$value}' appears to be a local network name but but local network names are not allowed";
     }
     return false;
 }
Example #13
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  *
  * @param  string $value
  * @throws Zend_Validate_Exception if a fatal error occurs for validation process
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_messages = array();
     $valueString = (string) $value;
     /**
      * Check input against IP address schema
      * @see Zend_Validate_Ip
      */
     require_once 'Zend/Validate/Ip.php';
     $ip = new Zend_Validate_Ip();
     if ($ip->isValid($valueString)) {
         if (!($this->_allow & self::ALLOW_IP)) {
             $this->_messages[] = "'{$valueString}' appears to be an IP address, but IP addresses are not allowed";
             return false;
         } else {
             return true;
         }
     }
     // Check input against DNS hostname schema
     $domainParts = explode('.', $valueString);
     if (count($domainParts) > 1 && strlen($valueString) >= 4 && strlen($valueString) <= 254) {
         $status = false;
         do {
             // First check TLD
             if (preg_match('/([a-z]{2,10})$/i', end($domainParts), $matches)) {
                 reset($domainParts);
                 // Hostname characters are: *(label dot)(label dot label); max 254 chars
                 // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
                 // id-prefix: alpha / digit
                 // ldh: alpha / digit / dash
                 // Match TLD against known list
                 $valueTld = strtolower($matches[1]);
                 if ($this->_validateTld) {
                     if (!in_array($valueTld, $this->_validTlds)) {
                         $this->_messages[] = "'{$valueString}' appears to be a DNS hostname but cannot match TLD" . " against known list";
                         $status = false;
                         break;
                     }
                 }
                 /**
                  * Match against IDN hostnames
                  * @see Zend_Validate_Hostname_Interface
                  */
                 $labelChars = 'a-z0-9';
                 $utf8 = false;
                 $classFile = 'Zend/Validate/Hostname/' . ucfirst($valueTld) . '.php';
                 if ($this->_validateIdn) {
                     if (Zend_Loader::isReadable($classFile)) {
                         // Load additional characters
                         $className = 'Zend_Validate_Hostname_' . ucfirst($valueTld);
                         Zend_Loader::loadClass($className);
                         $labelChars .= call_user_func(array($className, 'getCharacters'));
                         $utf8 = true;
                     }
                 }
                 // Keep label regex short to avoid issues with long patterns when matching IDN hostnames
                 $regexLabel = '/^[' . $labelChars . '\\x2d]{1,63}$/i';
                 if ($utf8) {
                     $regexLabel .= 'u';
                 }
                 // Check each hostname part
                 $valid = true;
                 foreach ($domainParts as $domainPart) {
                     // Check dash (-) does not start, end or appear in 3rd and 4th positions
                     if (strpos($domainPart, '-') === 0 || strlen($domainPart) > 2 && strpos($domainPart, '-', 2) == 2 && strpos($domainPart, '-', 3) == 3 || strrpos($domainPart, '-') === strlen($domainPart) - 1) {
                         $this->_messages[] = "'{$valueString}' appears to be a DNS hostname but contains a dash (-)" . " in an invalid position";
                         $status = false;
                         break 2;
                     }
                     // Check each domain part
                     $status = @preg_match($regexLabel, $domainPart);
                     if ($status === false) {
                         /**
                          * Regex error
                          * @see Zend_Validate_Exception
                          */
                         require_once 'Zend/Validate/Exception.php';
                         throw new Zend_Validate_Exception('Internal error: DNS validation failed');
                     } elseif ($status === 0) {
                         $valid = false;
                     }
                 }
                 // If all labels didn't match, the hostname is invalid
                 if (!$valid) {
                     $this->_messages[] = "'{$valueString}' appears to be a DNS hostname but cannot match against" . " hostname schema for TLD '{$valueTld}'";
                     $status = false;
                 }
             } else {
                 // Hostname not long enough
                 $this->_messages[] = "'{$valueString}' appears to be a DNS hostname but cannot extract TLD part";
                 $status = false;
             }
         } while (false);
         // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
         // passes validation
         if ($status && $this->_allow & self::ALLOW_DNS) {
             return true;
         }
     } else {
         $this->_messages[] = "'{$valueString}' does not match the expected structure for a DNS hostname";
     }
     // Check input against local network name schema; last chance to pass validation
     $regexLocal = "/^(([a-zA-Z0-9-]{1,63}.)*[a-zA-Z0-9-]{1,63}){1,254}\$/";
     $status = @preg_match($regexLocal, $valueString);
     if (false === $status) {
         /**
          * Regex error
          * @see Zend_Validate_Exception
          */
         require_once 'Zend/Validate/Exception.php';
         throw new Zend_Validate_Exception('Internal error: local network name validation failed');
     }
     // If the input passes as a local network name, and local network names are allowed, then the
     // hostname passes validation
     $allowLocal = $this->_allow & self::ALLOW_LOCAL;
     if ($status && $allowLocal) {
         return true;
     }
     // If the input does not pass as a local network name, add a message
     if (!$status) {
         $this->_messages[] = "'{$valueString}' does not appear to be a valid local network name";
     }
     // If local network names are not allowed, add a message
     if (!$allowLocal) {
         $this->_messages[] = "'{$valueString}' appears to be a local network name but but local network names are" . " not allowed";
     }
     return false;
 }
Example #14
0
 public function check_field_values($ins_fields, $categorized_fields = '', $trackerId = '', $itemId = '')
 {
     global $prefs;
     $mandatory_fields = array();
     $erroneous_values = array();
     if (isset($ins_fields) && isset($ins_fields['data'])) {
         foreach ($ins_fields['data'] as $f) {
             if ($f['type'] == 'f' && isset($f['error']) && $f['isMandatory'] != 'y') {
                 $erroneous_values[] = $f;
             }
             if ($f['type'] != 'q' and isset($f['isMandatory']) && $f['isMandatory'] == 'y') {
                 if (($f['type'] == 'e' || in_array($f['fieldId'], $categorized_fields)) && empty($f['value'])) {
                     // category: value is now categ id's
                     $mandatory_fields[] = $f;
                 } elseif (in_array($f['type'], array('a', 't')) && $this->is_multilingual($f['fieldId']) == 'y') {
                     if (!isset($multi_languages)) {
                         $multi_languages = $prefs['available_languages'];
                     }
                     //Check recipient
                     if (isset($f['lingualvalue'])) {
                         foreach ($f['lingualvalue'] as $val) {
                             foreach ($multi_languages as $num => $tmplang) {
                                 //Check if trad is empty
                                 if (!isset($val['lang']) || !isset($val['value']) || $val['lang'] == $tmplang && strlen($val['value']) == 0) {
                                     $mandatory_fields[] = $f;
                                 }
                             }
                         }
                     } else {
                         $mandatory_fields[] = $f;
                     }
                 } elseif (in_array($f['type'], array('u', 'g')) && $f['options_array'][0] == 1) {
                 } elseif ($f['type'] == 'c' && (empty($f['value']) || $f['value'] == 'n')) {
                     $mandatory_fields[] = $f;
                 } elseif ($f['type'] == 'A' && !empty($itemId) && empty($f['value'])) {
                     $val = $this->get_item_value($trackerId, $itemId, $f['fieldId']);
                     if (empty($val)) {
                         $mandatory_fields[] = $f;
                     }
                 } elseif (!isset($f['value']) or strlen($f['value']) == 0) {
                     $mandatory_fields[] = $f;
                 }
             }
             if (!empty($f['value'])) {
                 switch ($f['type']) {
                     // IP address (only for IPv4)
                     case 'I':
                         $validator = new Zend_Validate_Ip();
                         if (!$validator->isValid($f['value'])) {
                             $erroneous_values[] = $f;
                         }
                         break;
                         // numeric
                     // numeric
                     case 'n':
                         if (!is_numeric($f['value'])) {
                             $f['error'] = tra('Field is not numeric');
                             $erroneous_values[] = $f;
                         }
                         break;
                         // email
                     // email
                     case 'm':
                         if (!validate_email($f['value'], $prefs['validateEmail'])) {
                             $erroneous_values[] = $f;
                         }
                         break;
                         // password
                     // password
                     case 'p':
                         if ($f['options_array'][0] == 'password') {
                             $userlib = TikiLib::lib('user');
                             if (($e = $userlib->check_password_policy($f['value'])) != '') {
                                 $erroneous_values[] = $f;
                             }
                         } elseif ($f['options_array'][0] == 'email') {
                             if (!validate_email($f['value'])) {
                                 $erroneous_values[] = $f;
                             }
                         }
                         break;
                     case 'a':
                         if (isset($f['options_array'][5]) && $f['options_array'][5] > 0) {
                             if (count(preg_split('/\\s+/', trim($f['value']))) > $f['options_array'][5]) {
                                 $erroneous_values[] = $f;
                             }
                         }
                         if (isset($f['options_array'][6]) && $f['options_array'][6] == 'y') {
                             if (in_array($f['value'], $this->list_tracker_field_values($trackerId, $f['fieldId'], 'opc', 'y', '', $itemId))) {
                                 $erroneous_values[] = $f;
                             }
                         }
                         break;
                 }
                 $handler = $this->get_field_handler($f);
                 if (method_exists($handler, 'isValid') && !$handler->isValid()) {
                     $f['errorMsg'] = $f['validationMessage'] ?: tr('Unknown error');
                     $erroneous_values[] = $f;
                 }
             }
         }
     }
     $res = array();
     $res['err_mandatory'] = $mandatory_fields;
     $res['err_value'] = $erroneous_values;
     return $res;
 }
Example #15
0
 /**
  * Defined by Zend_Validate_Interface
  *
  * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  *
  * @param  mixed $value
  * @throws Zend_Validate_Exception if a fatal error occurs for validation process
  * @return boolean
  */
 public function isValid($value)
 {
     $this->_messages = array();
     do {
         // Check input against IP address schema
         require_once 'Zend/Validate/Ip.php';
         $ip = new Zend_Validate_Ip();
         if ($ip->isValid($value)) {
             if (!($this->_allow & self::ALLOW_IP)) {
                 $this->_messages[] = "'{$value}' appears to be an IP address but IP addresses are not allowed";
                 return false;
             } else {
                 break;
             }
         }
         // Check input against domain name schema
         $status = @preg_match('/^(?:[^\\W_]((?:[^\\W_]|-){0,61}[^\\W_])?\\.)+[a-zA-Z]{2,6}\\.?$/', $value);
         if (false === $status) {
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Internal error: DNS validation failed');
         }
         // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
         // passes validation
         if ($status && $this->_allow & self::ALLOW_DNS) {
             break;
         }
         // Check input against local network name schema; last chance to pass validation
         $status = @preg_match('/^(?:[^\\W_](?:[^\\W_]|-){0,61}[^\\W_]\\.)*(?:[^\\W_](?:[^\\W_]|-){0,61}[^\\W_])\\.?$/', $value);
         if (false === $status) {
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Internal error: local network name validation failed');
         }
         // If the input passes as a local network name, and local network names are allowed, then the
         // hostname passes validation
         $allowLocal = $this->_allow & self::ALLOW_LOCAL;
         if ($status && $allowLocal) {
             break;
         }
         // If the input does not pass as a local network name, add a message
         if (!$status) {
             $this->_messages[] = "'{$value}' does not appear to be a valid local network name";
         }
         // If local network names are not allowed, add a message
         if (!$allowLocal) {
             $this->_messages[] = "Local network names are not allowed";
         }
         return false;
     } while (false);
     return true;
 }
Example #16
0
 /**
  * @param string $srcIp
  * @return bool
  */
 public function validateIpOrAny($srcIp)
 {
     static $ipValidator;
     if (strtolower($srcIp) === 'any') {
         return true;
     }
     if ($ipValidator === null) {
         $ipValidator = new Zend_Validate_Ip();
     }
     return $ipValidator->isValid($srcIp);
 }
Example #17
0
 /**
  * Returns TRUE if value is a valid IP format, FALSE otherwise.
  *
  * @deprecated since 0.8.0
  * @param      mixed $value
  * @return     boolean
  */
 public static function isIp($value)
 {
     require_once 'Zend/Validate/Ip.php';
     $validator = new Zend_Validate_Ip();
     return $validator->isValid($value);
 }