diff --git a/lib/functions/validate/function.validateUrl.php b/lib/functions/validate/function.validateUrl.php index 67b335eb..0c4be8bf 100644 --- a/lib/functions/validate/function.validateUrl.php +++ b/lib/functions/validate/function.validateUrl.php @@ -23,56 +23,49 @@ * @param string URL to be tested * @return bool * @author Christian Hoffmann + * @author Froxlor team (2010-) * */ +function validateUrl($url) { -function validateUrl($url) -{ global $idna_convert, $theme; - if(strtolower(substr($url, 0, 7)) != "http://" - && strtolower(substr($url, 0, 8)) != "https://") - { + if (strtolower(substr($url, 0, 7)) != "http://" + && strtolower(substr($url, 0, 8)) != "https://" + ) { $url = 'http://' . $url; } - + // needs converting $url = $idna_convert->encode($url); $pattern = "/^https?:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(\:[0-9]+)?\/?(.+)?$/i"; - if(preg_match($pattern, $url)) - { + if (preg_match($pattern, $url)) { return true; } // not an fqdn - if(strtolower(substr($url, 0, 7)) == "http://" - || strtolower(substr($url, 0, 8)) == "https://") - { - if(strtolower(substr($url, 0, 7)) == "http://") - { + if (strtolower(substr($url, 0, 7)) == "http://" + || strtolower(substr($url, 0, 8)) == "https://" + ) { + if (strtolower(substr($url, 0, 7)) == "http://") { $ip = strtolower(substr($url, 7)); } - if(strtolower(substr($url, 0, 8)) == "https://") - { + if (strtolower(substr($url, 0, 8)) == "https://") { $ip = strtolower(substr($url, 8)); } $ip = substr($ip, 0, strpos($ip, '/')); + // possible : in IP (when a port is given), #1173 + $ip = substr($ip, 0, strpos($ip, ':')); - if(validate_ip($ip, true) !== false) - { + if (validate_ip($ip, true) !== false) { return true; - } - else - { + } else { return false; } - } - else - { + } else { return false; } } - diff --git a/lib/functions/validate/function.validate_ip.php b/lib/functions/validate/function.validate_ip.php index 8381f101..54b57e6b 100644 --- a/lib/functions/validate/function.validate_ip.php +++ b/lib/functions/validate/function.validate_ip.php @@ -22,25 +22,19 @@ * * @return mixed ip address on success, standard_error on failure */ +function validate_ip($ip, $return_bool = false, $lng = 'invalidip') { -function validate_ip($ip, $return_bool = false, $lng = 'invalidip') -{ - if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === FALSE - && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE - && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) === FALSE) - { - if($return_bool) - { + if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false + && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false + && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) === false + ) { + if ($return_bool) { return false; - } - else - { + } else { standard_error($lng, $ip); exit; } - } - else - { + } else { return $ip; } }