diff --git a/src/www/firewall_nat_1to1.php b/src/www/firewall_nat_1to1.php index 69d71598a..3d7478dd8 100644 --- a/src/www/firewall_nat_1to1.php +++ b/src/www/firewall_nat_1to1.php @@ -8,11 +8,11 @@ modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY @@ -30,15 +30,19 @@ require_once("guiconfig.inc"); require_once("interfaces.inc"); require_once("filter.inc"); -if (!is_array($config['nat']['onetoone'])) - $config['nat']['onetoone'] = array(); - +if (!isset($config['nat']['onetoone'])) { + $config['nat']['onetoone'] = array(); +} $a_1to1 = &$config['nat']['onetoone']; -if ($_POST) { +if ($_SERVER['REQUEST_METHOD'] === 'POST') { $pconfig = $_POST; + if (isset($pconfig['id']) && isset($a_1to1[$pconfig['id']])) { + // id found and valid + $id = $pconfig['id']; + } - if ($_POST['apply']) { + if (isset($pconfig['apply'])) { $retval = 0; $retval |= filter_configure(); $savemsg = get_std_save_message(); @@ -47,88 +51,83 @@ if ($_POST) { clear_subsystem_dirty('natconf'); clear_subsystem_dirty('filter'); } + } elseif (isset($pconfig['action']) && $pconfig['action'] == 'del' && isset($id)) { + // delete single entry + unset($a_1to1[$id]); + if (write_config()) { + mark_subsystem_dirty('natconf'); + } + header("Location: firewall_nat_1to1.php"); + exit; + } elseif (isset($pconfig['action']) && $pconfig['action'] == 'del_x' && isset($pconfig['rule']) && count($pconfig['rule']) > 0) { + // delete selected + foreach ($pconfig['rule'] as $rulei) { + unset($a_1to1[$rulei]); + } + if (write_config()) { + mark_subsystem_dirty('natconf'); + } + header("Location: firewall_nat_1to1.php"); + exit; + } elseif (isset($pconfig['action']) && $pconfig['action'] == 'move') { + // move selected + if (isset($pconfig['rule']) && count($pconfig['rule']) > 0) { + // if rule not set/found, move to end + if (!isset($id)) { + $id = count($a_1to1); + } + $a_1to1_new = array(); + + /* copy all rules < $id and not selected */ + for ($i = 0; $i < $id; $i++) { + if (!in_array($i, $pconfig['rule'])) { + $a_1to1_new[] = $a_1to1[$i]; + } + } + + /* copy all selected rules */ + for ($i = 0; $i < count($a_1to1); $i++) { + if ($i == $id) + continue; + if (in_array($i, $pconfig['rule'])) { + $a_1to1_new[] = $a_1to1[$i]; + } + } + + /* copy $id rule */ + if ($id < count($a_1to1)) { + $a_1to1_new[] = $a_1to1[$id]; + } + + /* copy all rules > $id and not selected */ + for ($i = $id+1; $i < count($a_1to1); $i++) { + if (!in_array($i, $pconfig['rule'])) { + $a_1to1_new[] = $a_1to1[$i]; + } + } + $a_1to1 = $a_1to1_new; + } + if (write_config()) { + mark_subsystem_dirty('natconf'); + } + header("Location: firewall_nat_1to1.php"); + exit; + } elseif (isset($pconfig['action']) && $pconfig['action'] == 'toggle' && isset($id)) { + // toggle item + if(isset($a_1to1[$id]['disabled'])) { + unset($a_1to1[$id]['disabled']); + } else { + $a_1to1[$id]['disabled'] = true; + } + if (write_config("Firewall: NAT: Outbound, enable/disable NAT rule")) { + mark_subsystem_dirty('natconf'); + } + header("Location: firewall_nat_1to1.php"); + exit; } } -if ($_GET['act'] == "del") { - if ($a_1to1[$_GET['id']]) { - unset($a_1to1[$_GET['id']]); - if (write_config()) - mark_subsystem_dirty('natconf'); - header("Location: firewall_nat_1to1.php"); - exit; - } -} - -if (isset($_POST['del_x'])) { - /* delete selected rules */ - if (is_array($_POST['rule']) && count($_POST['rule'])) { - foreach ($_POST['rule'] as $rulei) { - unset($a_1to1[$rulei]); - } - if (write_config()) - mark_subsystem_dirty('natconf'); - header("Location: firewall_nat_1to1.php"); - exit; - } - -} else if ($_GET['act'] == "toggle") { - if ($a_1to1[$_GET['id']]) { - if(isset($a_1to1[$_GET['id']]['disabled'])) - unset($a_1to1[$_GET['id']]['disabled']); - else - $a_1to1[$_GET['id']]['disabled'] = true; - if (write_config("Firewall: NAT: Outbound, enable/disable NAT rule")) - mark_subsystem_dirty('natconf'); - header("Location: firewall_nat_1to1.php"); - exit; - } -} else { - /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */ - unset($movebtn); - foreach ($_POST as $pn => $pd) { - if (preg_match("/move_(\d+)_x/", $pn, $matches)) { - $movebtn = $matches[1]; - break; - } - } - /* move selected rules before this rule */ - if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) { - $a_1to1_new = array(); - - /* copy all rules < $movebtn and not selected */ - for ($i = 0; $i < $movebtn; $i++) { - if (!in_array($i, $_POST['rule'])) - $a_1to1_new[] = $a_1to1[$i]; - } - - /* copy all selected rules */ - for ($i = 0; $i < count($a_1to1); $i++) { - if ($i == $movebtn) - continue; - if (in_array($i, $_POST['rule'])) - $a_1to1_new[] = $a_1to1[$i]; - } - - /* copy $movebtn rule */ - if ($movebtn < count($a_1to1)) - $a_1to1_new[] = $a_1to1[$movebtn]; - - /* copy all rules > $movebtn and not selected */ - for ($i = $movebtn+1; $i < count($a_1to1); $i++) { - if (!in_array($i, $_POST['rule'])) - $a_1to1_new[] = $a_1to1[$i]; - } - if (count($a_1to1_new) > 0) - $a_1to1 = $a_1to1_new; - - if (write_config()) - mark_subsystem_dirty('natconf'); - header("Location: firewall_nat_1to1.php"); - exit; - } -} - +legacy_html_escape_form_data($a_1to1); $pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("1:1")); include("head.inc"); @@ -136,172 +135,211 @@ $main_buttons = array( array('label'=>gettext("add rule"), 'href'=>'firewall_nat_1to1_edit.php'), ); - ?>
+ + + - - -