From ecd1f2d946abe16193e0ea62dbbdd6c87aa9b985 Mon Sep 17 00:00:00 2001 From: jim-p Date: Sun, 7 Mar 2010 16:37:02 -0500 Subject: Adding support for using IP ranges aliases. If you input an IP Range such as 192.168.0.1-192.168.0.254, it will instead turn that into a number of CIDR networks which will completely fill the range. --- usr/local/www/firewall_aliases_edit.php | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'usr/local/www') diff --git a/usr/local/www/firewall_aliases_edit.php b/usr/local/www/firewall_aliases_edit.php index d974bb43..acf898c 100755 --- a/usr/local/www/firewall_aliases_edit.php +++ b/usr/local/www/firewall_aliases_edit.php @@ -221,20 +221,25 @@ if ($_POST) { $wrongaliases = ""; for($x=0; $x<4999; $x++) { if($_POST["address{$x}"] <> "") { + $count = 0; if ($isfirst > 0) $address .= " "; - $address .= $_POST["address{$x}"]; - if(($_POST['type'] == "network" || is_ipaddr($_POST["address{$x}"])) && $_POST["address_subnet{$x}"] <> "") - $address .= "/" . $_POST["address_subnet{$x}"]; - - if($_POST["detail{$x}"] <> "") { - $final_address_details .= $_POST["detail{$x}"]; - } else { - $final_address_details .= "Entry added" . " "; - $final_address_details .= date('r'); - } - $final_address_details .= "||"; - $isfirst++; + if (is_iprange($_POST["address{$x}"])) { + list($startip, $endip) = explode('-', $_POST["address{$x}"]); + $rangesubnets = ip_range_to_subnet_array($startip, $endip); + $count = count($rangesubnets); + $address .= implode($rangesubnets, ' '); + } else { + $address .= $_POST["address{$x}"]; + if(($_POST['type'] == "network" || is_ipaddr($_POST["address{$x}"])) && $_POST["address_subnet{$x}"] <> "") + $address .= "/" . $_POST["address_subnet{$x}"]; + } + if($_POST["detail{$x}"] <> "") { + $final_address_details .= str_repeat($_POST["detail{$x}"] . "||", $count); + } else { + $final_address_details .= str_repeat("Entry added " . date('r') . "||", $count); + } + $isfirst += $count; if (is_alias($_POST["address{$x}"])) { if (!alias_same_type($_POST["address{$x}"], $_POST['type'])) @@ -243,7 +248,9 @@ if ($_POST) { if (!is_port($_POST["address{$x}"])) $input_errors[] = $_POST["address{$x}"] . " is not a valid port or alias."; } else if ($_POST['type'] == "host" || $_POST['type'] == "network") { - if (!is_ipaddr($_POST["address{$x}"]) && !is_hostname($_POST["address{$x}"])) + if (!is_ipaddr($_POST["address{$x}"]) + && !is_hostname($_POST["address{$x}"]) + && !is_iprange($_POST["address{$x}"])) $input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias."; } } -- cgit v1.1