summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorErmal Luçi <eri@pfsense.org>2009-12-03 13:54:11 +0000
committerErmal Luçi <eri@pfsense.org>2009-12-03 13:54:43 +0000
commit1e578a7f10843f470d2bf5274bbef695a14bb9d0 (patch)
tree9cb418145d2f8ab621e320f0961e971da6783715 /etc
parentb96cad97eafee7dc4b2cdb143af07f92ff35c68e (diff)
downloadpfsense-1e578a7f10843f470d2bf5274bbef695a14bb9d0.zip
pfsense-1e578a7f10843f470d2bf5274bbef695a14bb9d0.tar.gz
Resolves #146 Add propper validation on alias usage. Allow port type aliases only on port side and other aliases in ip specifications and similar. Introduce a new function is_portoralias to ressemble the is_ipaddroralias to check for the cases.
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/util.inc52
1 files changed, 28 insertions, 24 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index b585aa8..603ad8a 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -201,34 +201,21 @@ function is_ipaddr($ipaddr) {
/* returns true if $ipaddr is a valid dotted IPv4 address or an alias thereof */
function is_ipaddroralias($ipaddr) {
+ global $config;
- global $aliastable, $config;
-
- if(is_array($config['aliases']['alias'])) {
- foreach($config['aliases']['alias'] as $alias) {
- if($alias['name'] == $ipaddr)
- return true;
- }
- }
-
- if (isset($aliastable[$ipaddr]) && is_ipaddr($aliastable[$ipaddr]))
- return true;
- else
+ if (is_alias($ipaddr)) {
+ if (is_array($config['aliases']['alias'])) {
+ foreach ($config['aliases']['alias'] as $alias) {
+ if ($alias['name'] == $ipaddr && $alias['type'] != "port")
+ return true;
+ }
+ }
+ return false;
+ } else
return is_ipaddr($ipaddr);
}
-/* returns true if $ipaddr is a valid dotted IPv4 address or any alias */
-function is_ipaddroranyalias($ipaddr) {
-
- global $aliastable;
-
- if (isset($aliastable[$ipaddr]))
- return true;
- else
- return is_ipaddr($ipaddr);
-}
-
/* returns true if $subnet is a valid subnet in CIDR format */
function is_subnet($subnet) {
if (!is_string($subnet))
@@ -332,6 +319,23 @@ function is_portrange($portrange) {
return false;
}
+/* returns true if $port is a valid port number or an alias thereof */
+function is_portoralias($port) {
+ global $config;
+
+ if (is_alias($port)) {
+ if (is_array($config['aliases']['alias'])) {
+ foreach ($config['aliases']['alias'] as $alias) {
+ if ($alias['name'] == $port && $alias['type'] == "port")
+ return true;
+ }
+ }
+ return false;
+ } else
+ return is_port($ipaddr);
+
+}
+
/* returns true if $val is a valid shaper bandwidth value */
function is_valid_shaperbw($val) {
return (preg_match("/^(\d+(?:\.\d+)?)([MKG]?b|%)$/", $val));
@@ -1115,4 +1119,4 @@ function is_URL($url) {
return false;
}
-?> \ No newline at end of file
+?>
OpenPOWER on IntegriCloud