From 5a1eebc7efe36e28a3543f8d30d66c7fd98e985d Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Wed, 24 Jan 2007 04:34:52 +0000 Subject: Backport the alias rowhelper description feature --- usr/local/www/firewall_aliases_edit.php | 530 ++++++++++++++++++++++---------- usr/local/www/row_helper.js | 11 +- 2 files changed, 381 insertions(+), 160 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/firewall_aliases_edit.php b/usr/local/www/firewall_aliases_edit.php index 93ec131..4de4048 100755 --- a/usr/local/www/firewall_aliases_edit.php +++ b/usr/local/www/firewall_aliases_edit.php @@ -31,6 +31,8 @@ POSSIBILITY OF SUCH DAMAGE. */ +$pgtitle = "Firewall: Aliases: Edit"; + require("guiconfig.inc"); if (!is_array($config['aliases']['alias'])) @@ -59,8 +61,31 @@ if (isset($id) && $a_aliases[$id]) { $pconfig['type'] = "host"; else $pconfig['type'] = "port"; - - $pconfig['descr'] = $a_aliases[$id]['descr']; + + $pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']); + + /* Explode out details for entry details */ + $address_details = explode('||', $a_aliases[$id]['detail']); + if (is_array($address_details)) + $address_detail = $address_details[0]; + else + $address_detail = $address_details; + + if($a_aliases[$id]['aliasurl'] <> "") { + $pconfig['type'] = "url"; + if(is_array($a_aliases[$id]['aliasurl'])) { + $isfirst = 0; + $pconfig['address'] = ""; + foreach($a_aliases[$id]['aliasurl'] as $aa) { + if($isfirst == 1) + $pconfig['address'] .= " "; + $isfirst = 1; + $pconfig['address'] .= $aa; + } + } else { + $pconfig['address'] = $a_aliases[$id]['aliasurl']; + } + } } if ($_POST) { @@ -89,7 +114,7 @@ if ($_POST) { $input_errors[] = "Reserved word used for alias name."; } else { if (is_validaliasname($_POST['name']) == false) - $input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9."; + $input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, -, _."; } if ($_POST['type'] == "host") if (!is_ipaddr($_POST['address'])) { @@ -103,9 +128,15 @@ if ($_POST) { $input_errors[] = "A valid subnet bit count must be specified."; } } + + if ($_POST['type'] == "url") { + if(stristr($_POST['address'], "http") == false) + $input_errors[] = "You must provide a valid URL to the resource."; + } + if ($_POST['type'] == "port") - if (!is_port($_POST['address'])) - $input_errors[] = "The port must be an integer between 1 and 65535."; + if (! is_port($_POST['address']) && ! is_portrange($_POST['address'])) + $input_errors[] = "Please specify a valid port or portrange."; /* check for name conflicts */ foreach ($a_aliases as $alias) { @@ -117,14 +148,14 @@ if ($_POST) { break; } } - + /* check for name interface description conflicts */ foreach($config['interfaces'] as $interface) { if($interface['descr'] == $_POST['name']) { - $input_errors[] = gettext("An interface description with this name already exists."); - break; + $input_errors[] = "An interface description with this name already exists."; + break; } - } + } if (!$input_errors) { $alias = array(); @@ -136,185 +167,338 @@ if ($_POST) { $alias['address'] = $_POST['address']; $address = $alias['address']; + $final_address_detail = htmlentities($_POST['detail'], ENT_QUOTES, 'UTF-8'); + if($final_address_detail <> "") { + $final_address_details .= $final_address_detail; + } else { + $final_address_details .= "Entry added" . " "; + $final_address_details .= date('r'); + } + $final_address_details .= "||"; $isfirst = 0; - for($x=0; $x<99; $x++) { - $comd = "\$subnet = \$_POST['address" . $x . "'];"; - eval($comd); - $comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];"; - eval($comd); - if($subnet <> "") { - $address .= " "; - $address .= $subnet; - if($subnet_address <> "") $address .= "/" . $subnet_address; + + if($_POST['type'] == "url") { + $address = ""; + $isfirst = 0; + $address_count = 2; + + /* item is a url type */ + if($_POST['address']) + $_POST['address0'] = $_POST['address']; + for($x=0; $x<99; $x++) { + if($_POST['address' . $x]) { + /* fetch down and add in */ + $isfirst = 0; + $temp_filename = tempnam("/tmp/", "alias_import"); + unlink($temp_filename); + $fda = fopen("/tmp/tmpfetch","w"); + fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\""); + fclose($fda); + mwexec("mkdir -p {$temp_filename}"); + mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\""); + /* if the item is tar gzipped then extract */ + if(stristr($_POST['address' . $x], ".tgz")) + process_alias_tgz($temp_filename); + if(file_exists("{$temp_filename}/aliases")) { + $file_contents = file_get_contents("{$temp_filename}/aliases"); + $file_contents = str_replace("#", "\n#", $file_contents); + $file_contents_split = split("\n", $file_contents); + foreach($file_contents_split as $fc) { + $tmp = trim($fc); + if(stristr($fc, "#")) { + $tmp_split = split("#", $tmp); + $tmp = trim($tmp_split[0]); + } + if(trim($tmp) <> "") { + if($isfirst == 1) + $address .= " "; + $address .= $tmp; + $isfirst = 1; + } + } + if($isfirst == 0) { + /* nothing was found */ + $input_errors[] = "You must provide a valid URL. Could not fetch usable data."; + $dont_update = true; + break; + } + $alias['aliasurl'][] = $_POST['address' . $x]; + mwexec("/bin/rm -rf {$temp_filename}"); + } else { + $input_errors[] = "You must provide a valid URL."; + $dont_update = true; + break; + } + } + } + } else { + /* item is a normal alias type */ + for($x=0; $x<99; $x++) { + $comd = "\$subnet = \$_POST['address" . $x . "'];"; + eval($comd); + $comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];"; + eval($comd); + if($subnet <> "") { + $address .= " "; + $address .= $subnet; + if($subnet_address <> "") $address .= "/" . $subnet_address; + + /* Compress in details to a single key, data separated by pipes. + Pulling details here lets us only pull in details for valid + address entries, saving us from having to track which ones to + process later. */ + $comd = "\$final_address_detail = htmlentities( \$_POST['detail" . $x . "'], ENT_QUOTES, 'UTF-8' );"; + eval($comd); + if($final_address_detail <> "") { + $final_address_details .= $final_address_detail; + } else { + $final_address_details .= "Entry added" . " "; + $final_address_details .= date('r'); + } + $final_address_details .= "||"; + } } } - $alias['address'] = $address; - $alias['descr'] = $_POST['descr']; + if($dont_update <> true) { - if (isset($id) && $a_aliases[$id]) - $a_aliases[$id] = $alias; - else - $a_aliases[] = $alias; + $alias['address'] = $address; + $alias['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8'); + $alias['type'] = $_POST['type']; + $alias['detail'] = $final_address_details; - touch($d_aliasesdirty_path); + if (isset($id) && $a_aliases[$id]) + $a_aliases[$id] = $alias; + else + $a_aliases[] = $alias; - write_config(); + touch($d_aliasesdirty_path); - filter_configure(); + write_config(); + filter_configure(); - header("Location: firewall_aliases.php"); - exit; + header("Location: firewall_aliases.php"); + exit; + } } } $pgtitle = "System: Firewall: Aliases: Edit"; include("head.inc"); -?> +$jscriptstr = << - - - +EOD - +?> - - +"> + + + -

+ -
- +
+ + +
- - - + + - +

+ NOTE: This alias is in use so the name may not be modified! +

+ + - - - - + + + + - - - - - - - - - - - + + + + + + + + + + +
Name +
Name -

NOTE: This alias is in use so the name may not be modified!

Name -
The name of the alias may only consist - of the characters a-z, A-Z and 0-9.
Name + +
+ + The name of the alias may only consist of the characters a-z, A-Z and 0-9. + +
Description -
You may enter a description here - for your reference (not parsed).
Type - -
Host(s)
- - - - + + + + + + + + + + + - - - - - -
Description + +
+ + You may enter a description here for your reference (not parsed). + +
Type + +
Host(s)
+ + + + + + + + + + 0) $tracker = $counter + 1; ?> - - - - -
+
Item information
+
Network
CIDR
Description
- - 0) - echo ""; - ?> - -
- -
  - - - -
+
+ + + + + + + 0) + echo ""; + ?> +
+ + + + + + +   + + + + + + + + +
- + + + diff --git a/usr/local/www/row_helper.js b/usr/local/www/row_helper.js index 7794ea8..8b14732 100755 --- a/usr/local/www/row_helper.js +++ b/usr/local/www/row_helper.js @@ -2,11 +2,13 @@ var rowname = new Array(99); var rowtype = new Array(99); var newrow = new Array(99); +var rowsize = new Array(99); for (i = 0; i < 99; i++) { rowname[i] = ''; rowtype[i] = ''; - newrow[i] = ''; + newrow[i] = ''; + rowsize[i] = '25'; } var field_counter_js = 0; @@ -24,11 +26,11 @@ var addRowTo = (function() { for (i = 0; i < field_counter_js; i++) { td = d.createElement("td"); if(rowtype[i] == 'textbox') { - td.innerHTML=" "; + td.innerHTML=" "; } else if(rowtype[i] == 'select') { - td.innerHTML=" "; + td.innerHTML=" "; } else { - td.innerHTML=" "; + td.innerHTML=" "; } tr.appendChild(td); } @@ -50,7 +52,6 @@ function removeRow(el) { cel = el.getElementsByTagName("td").item(0); el.parentNode.removeChild(el); } - totalrows--; } function find_unique_field_name(field_name) { -- cgit v1.1