From b6f3005c2b192b613cd4102aa31e43267dec60ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ermal=20Lu=C3=A7i?= Date: Sun, 10 Aug 2008 16:54:54 +0000 Subject: Bring to functionality the editing of aliases. * Cleanup uneccesary eval() use in php code * Invrease on javascript the limits to 299 to really allow 299 entries * Remove limitiation of not being able to delete the first entry * Make all the rows dynamic. Now a new alias will not show any rows unless the plus sign is clicked. * Fix bug where OpenVPN aliases where being selected in case of Port aliases * Cleanup and style(9) here and there --- usr/local/www/firewall_aliases_edit.php | 149 ++++++++------------------------ usr/local/www/row_helper.js | 16 ++-- 2 files changed, 44 insertions(+), 121 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/firewall_aliases_edit.php b/usr/local/www/firewall_aliases_edit.php index ec0dafb..6b12695 100755 --- a/usr/local/www/firewall_aliases_edit.php +++ b/usr/local/www/firewall_aliases_edit.php @@ -103,20 +103,6 @@ if ($_POST) { $pconfig = $_POST; /* input validation */ - $reqdfields = explode(" ", "name address"); - $reqdfieldsn = explode(",", "Name,Address"); - - if ($_POST['type'] == "network") { - $reqdfields[] = "address_subnet"; - $reqdfieldsn[] = "Subnet bit count"; - } - - do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - - if(strtolower($_POST['name']) == "lan") - $input_errors[] = "Aliases may not be named LAN."; - if(strtolower($_POST['name']) == "wan") - $input_errors[] = "Aliases may not be named WAN."; if(strtolower($_POST['name']) == "pptp") $input_errors[] = gettext("Aliases may not be named PPTP."); @@ -127,24 +113,6 @@ if ($_POST) { if (is_validaliasname($_POST['name']) == false) $input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _."; } - if ($_POST['type'] == "network") { - if (!is_ipaddr($_POST['address'])) { - $input_errors[] = "A valid address must be specified."; - } - if (!is_numeric($_POST['address_subnet'])) { - $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']) && ! is_portrange($_POST['address'])) - $input_errors[] = "Please specify a valid port or portrange."; - /* check for name conflicts */ foreach ($a_aliases as $alias) { if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias)) @@ -166,31 +134,12 @@ if ($_POST) { $alias = array(); $alias['name'] = $_POST['name']; - if ($_POST['type'] == "network") - $alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet']; - - else - $alias['address'] = $_POST['address']; - - $address = $alias['address']; - $final_address_detail = mb_convert_encoding($_POST['detail'],"HTML-ENTITIES","auto"); - 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; - 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; isset($_POST['address'. $x]); $x++) { if($_POST['address' . $x]) { /* fetch down and add in */ @@ -238,35 +187,31 @@ if ($_POST) { } } } else { + $address = ""; + $isfirst = 0; /* item is a normal alias type */ for($x=0; $x<299; $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 = mb_convert_encoding(\$_POST['detail" . $x . "'],'HTML-ENTITIES','auto');"; - 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 .= "||"; + if($_POST["address{$x}"] <> "") { + if ($isfirst > 0) + $address .= " "; + $address .= $_POST["address{$x}"]; + if($_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 (!$input_errors) { + echo "{$address} --- ggggggggg

"; $alias['address'] = $address; $alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto"); $alias['type'] = $_POST['type']; @@ -305,11 +250,8 @@ function typesel_change() { case 0: /* host */ var cmd; - document.iform.address_subnet.disabled = 1; - document.iform.address_subnet.value = ""; - document.iform.address_subnet.selected = 0; - newrows = totalrows+1; - for(i=2; i @@ -512,7 +437,7 @@ EOD; - + @@ -535,6 +460,7 @@ EOD; "") { $item = explode(" ", $address); $item3 = explode("||", $pconfig['detail']); foreach($item as $ww) { @@ -548,7 +474,7 @@ EOD; } } $item4 = $item3[$counter]; - if($counter > 0) $tracker = $counter + 1; + $tracker = $counter; ?> @@ -566,16 +492,13 @@ EOD; - 0) - echo ""; - ?> - + + @@ -591,7 +514,7 @@ EOD;   - + diff --git a/usr/local/www/row_helper.js b/usr/local/www/row_helper.js index 8b14732..094f45a 100755 --- a/usr/local/www/row_helper.js +++ b/usr/local/www/row_helper.js @@ -1,14 +1,14 @@ // Global Variables -var rowname = new Array(99); -var rowtype = new Array(99); -var newrow = new Array(99); -var rowsize = new Array(99); +var rowname = new Array(299); +var rowtype = new Array(299); +var newrow = new Array(299); +var rowsize = new Array(299); -for (i = 0; i < 99; i++) { +for (i = 0; i < 299; i++) { rowname[i] = ''; rowtype[i] = ''; newrow[i] = ''; - rowsize[i] = '25'; + rowsize[i] = '30'; } var field_counter_js = 0; @@ -22,13 +22,12 @@ var addRowTo = (function() { d = document; tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0); tr = d.createElement("tr"); - totalrows++; for (i = 0; i < field_counter_js; i++) { td = d.createElement("td"); if(rowtype[i] == 'textbox') { td.innerHTML=" "; } else if(rowtype[i] == 'select') { - td.innerHTML=" "; + td.innerHTML=" "; } else { td.innerHTML=" "; } @@ -40,6 +39,7 @@ var addRowTo = (function() { td.innerHTML = ''; tr.appendChild(td); tbody.appendChild(tr); + totalrows++; }); })(); -- cgit v1.1