summaryrefslogtreecommitdiffstats
path: root/src/etc
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:28 -0200
commit59455106725e16ced4d5eb2f6f42a68a7b19bf0d (patch)
treed1f9d210d156c6377c5e0dff20ca997328a569a8 /src/etc
parentc6e02f8b6e4a09e1e7439d6ec7a1cf8606c64de5 (diff)
downloadpfsense-59455106725e16ced4d5eb2f6f42a68a7b19bf0d.zip
pfsense-59455106725e16ced4d5eb2f6f42a68a7b19bf0d.tar.gz
Introduce is_intrange() to validate a range of integers delimited by ':' or '-'
Diffstat (limited to 'src/etc')
-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 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))) {
OpenPOWER on IntegriCloud