From 59455106725e16ced4d5eb2f6f42a68a7b19bf0d Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Tue, 24 Jan 2017 12:17:25 -0200 Subject: Introduce is_intrange() to validate a range of integers delimited by ':' or '-' --- src/etc/inc/util.inc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/etc') diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index 62da39d..8d8a083 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -1114,6 +1114,35 @@ function invalidaliasnamemsg($name, $object = "alias") { return is_validaliasname($name, true, $object); } +/* + * returns true if $range is a valid integer range between $min and $max + * range delimiter can be ':' or '-' + */ +function is_intrange($range, $min, $max) { + $values = preg_split("/[:-]/", $range); + + if (!is_array($values) || count($values) != 2) { + return false; + } + + if (!ctype_digit($values[0]) || !ctype_digit($values[1])) { + return false; + } + + $values[0] = intval($values[0]); + $values[1] = intval($values[1]); + + if ($values[0] >= $values[1]) { + return false; + } + + if ($values[0] < $min || $values[1] > $max) { + return false; + } + + return true; +} + /* returns true if $port is a valid TCP/UDP port */ function is_port($port) { if (ctype_digit($port) && ((intval($port) >= 1) && (intval($port) <= 65535))) { -- cgit v1.1