From 93801929e298a4971e8b9f3517e37e38bae564bd Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 21 Dec 2009 14:03:09 +0000 Subject: [PATCH] Added additional checks git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14920 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/utils/class_tests.inc | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/gosa-core/include/utils/class_tests.inc b/gosa-core/include/utils/class_tests.inc index 4c6c60f65..cfd7f255b 100644 --- a/gosa-core/include/utils/class_tests.inc +++ b/gosa-core/include/utils/class_tests.inc @@ -31,7 +31,7 @@ class tests { public static function is_dns_name($str) { - return(preg_match("/^[a-z0-9\.\-]*$/i",$str)); + return(preg_match("/^[a-z0-9\.\-_]*$/i",$str)); } @@ -73,7 +73,24 @@ class tests { public static function is_ip($ip) { - return preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/", $ip); + if(function_exists('filter_var')) { + return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); + } else { + return preg_match("/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/", $ip); + } + } + + + public static function is_ipv6($ip) + { + if(function_exists('filter_var')) { + return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); + } else { + $ipv4 = '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; + $g = '([0-9a-f]{1,4})'; //IPv6 group + return preg_match("/^$g:$g:$g:$g:$g:$g:$g:$g$/", $ip) || + preg_match("/^$g:$g:$g:$g:$g:$g:$ipv4$/", $ip); + } } -- 2.30.2