summaryrefslogtreecommitdiffstats
path: root/src/etc/inc/util.inc
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2017-01-24 12:17:25 -0200
committerRenato Botelho <renato@netgate.com>2017-01-24 12:17:25 -0200
commitee956d19a8936016be899dfcadac048a69b1ed75 (patch)
treebf3698159b80d0c0ff2763135b12f0cea3acb0ea /src/etc/inc/util.inc
parent61d1d1899ea280df5516b42b16c0e2ff5e4c1cf6 (diff)
downloadpfsense-ee956d19a8936016be899dfcadac048a69b1ed75.zip
pfsense-ee956d19a8936016be899dfcadac048a69b1ed75.tar.gz
Introduce is_intrange() to validate a range of integers delimited by ':' or '-'
Diffstat (limited to 'src/etc/inc/util.inc')
-rw-r--r--src/etc/inc/util.inc29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc
index 2876df9..fb116c1 100644
--- a/src/etc/inc/util.inc
+++ b/src/etc/inc/util.inc
@@ -1077,6 +1077,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))) {
OpenPOWER on IntegriCloud