summaryrefslogtreecommitdiffstats
path: root/frontends/php/include/validate.inc.php
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-09-17 09:35:13 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-09-17 09:35:13 +0000
commit2ae95f35e566afdee93ea06bbf02443257ce7716 (patch)
tree0eddf35ca439ddc34473ffe97fce4615705017ad /frontends/php/include/validate.inc.php
parentcb2c5743fee519c1490317552b98a09f48daf92a (diff)
downloadzabbix-2ae95f35e566afdee93ea06bbf02443257ce7716.tar.gz
zabbix-2ae95f35e566afdee93ea06bbf02443257ce7716.tar.xz
zabbix-2ae95f35e566afdee93ea06bbf02443257ce7716.zip
[DEV-23] improvements in configure.in IPv6 (Sasha)
[DEV-23] Autodiscovery for IPv6 (Sasha) [DEV-17] Add support of IPv6 to standard library (comms.c) (Sasha) [DEV-21] extended size of IP fields to accept IPv6 style IPs (Alexei) [DEV-21] added basic validation of IPv6 IP addresses in GUI (Alexei) [DEV-18] Modified structures of include/db.h to have larger length for IP addresses. [DEV-18] database schema enhanced for IPv6 addresses (Alexei) Minor fix for confgure.in. support of --enable-ipv6 for configure.in (Alexei) git-svn-id: svn://svn.zabbix.com/trunk@4752 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/validate.inc.php')
-rw-r--r--frontends/php/include/validate.inc.php89
1 files changed, 86 insertions, 3 deletions
diff --git a/frontends/php/include/validate.inc.php b/frontends/php/include/validate.inc.php
index 997e7f76..a628744f 100644
--- a/frontends/php/include/validate.inc.php
+++ b/frontends/php/include/validate.inc.php
@@ -70,15 +70,41 @@
{
return 'ereg(\'^([0-9a-zA-Z\_\.[.-.]\$ ]+)$\',{'.$var.'})&&';
}
-
- function validate_ip($str,&$arr)
+ function validate_ipv4($str,&$arr)
{
if( !ereg('^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$', $str, $arr) ) return false;
for($i=1; $i<=4; $i++) if( !is_numeric($arr[$i]) || $arr[$i] > 255 || $arr[$i] < 0 ) return false;
return true;
}
+ function validate_ipv6($str,&$arr)
+ {
+ $pattern1 = '([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}';
+ $pattern2 = ':(:[A-Fa-f0-9]{1,4}){1,7}';
+ $pattern3 = '[A-Fa-f0-9]{1,4}::([A-Fa-f0-9]{1,4}:){0,5}[A-Fa-f0-9]{1,4}';
+ $pattern4 = '([A-Fa-f0-9]{1,4}:){2}:([A-Fa-f0-9]{1,4}:){0,4}[A-Fa-f0-9]{1,4}';
+ $pattern5 = '([A-Fa-f0-9]{1,4}:){3}:([A-Fa-f0-9]{1,4}:){0,3}[A-Fa-f0-9]{1,4}';
+ $pattern6 = '([A-Fa-f0-9]{1,4}:){4}:([A-Fa-f0-9]{1,4}:){0,2}[A-Fa-f0-9]{1,4}';
+ $pattern7 = '([A-Fa-f0-9]{1,4}:){5}:([A-Fa-f0-9]{1,4}:){0,1}[A-Fa-f0-9]{1,4}';
+ $pattern8 = '([A-Fa-f0-9]{1,4}:){6}:[A-Fa-f0-9]{1,4}';
+
+ $full = "/^($pattern1)$|^($pattern2)$|^($pattern3)$|^($pattern4)$|^($pattern5)$|^($pattern6)$|^($pattern7)$|^($pattern8)$/";
+
+ if( !ereg($full, $str, $arr) ) return false;
+ return true;
+ }
- function validate_ip_range($str)
+ function validate_ip($str,&$arr)
+ {
+ if(validate_ipv4($str,&$arr))
+ return true;
+ if(defined('ZBX_HAVE_IPV6'))
+ {
+ return validate_ipv6($str,&$arr);
+ }
+ return false;
+ }
+
+/* function validate_ip_range($str)
{
foreach(explode(',',$str) as $ip_range)
{
@@ -100,7 +126,64 @@
}
return true;
}
+*/
+ function validate_ip_range($str)
+ {
+ foreach(explode(',',$str) as $ip_range)
+ {
+ $parts = explode('-', $ip_range);
+ $parts_count = count($parts);
+ if($parts_count > 2) return false;
+
+ if(validate_ipv4($parts[0], $arr))
+ {
+ $ip_parts = explode('.', $parts[0]);
+
+ if( $parts_count == 2 )
+ {
+ if( !ereg('^[0-9]{1,3}$', $parts[1]) ) return false;
+
+ sscanf($ip_parts[3], "%d", $from_value);
+ sscanf($parts[1], "%d", $to_value);
+ if($to_value > 255 || $from_value > $to_value) return false;
+ }
+ }
+ else if( defined('ZBX_HAVE_IPV6') && validate_ipv6($parts[0], $arr) )
+ {
+ $ip_parts = explode(':', $parts[0]);
+ $ip_parts_count = count($ip_parts);
+
+ if( $parts_count == 2 )
+ {
+ if( !ereg('^[A-Fa-f0-9]{1,4}$', $parts[1]) ) return false;
+
+ sscanf($ip_parts[$ip_parts_count - 1], "%x", $from_value);
+ sscanf($parts[1], "%x", $to_value);
+ if($from_value > $to_value) return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+ return true;
+ }
+/* function validate_ip_range($str)
+ {
+ if(defined('ZBX_HAVE_IPV6'))
+ {
+ return validate_ipv4_ipv6_range($str);
+ }
+ else
+ {
+ return validate_ipv4_range($str);
+ }
+ return false;
+ }
+*/
function validate_port_list($str)
{
foreach(explode(',',$str) as $port_range)