From 416f079781dffc6fb31a0d0c7274cbd80aa51752 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Tue, 19 Jan 2016 12:02:46 +0545 Subject: Standardize NAT NPt Give NAT NPt GUI the same sort of interface as NAT 1:1 1) Checkbox to select multiple mappings and then delete selected mappings 2) Tick/cross to enable/disable a mapping 3) Ability to "Add a new mapping based on this one" 4) Double-click to edit an entry 5) Ability to reorder mappings and save the new order - probably nobody cares about that but it is easy to provide it the same as on other forms, and so users can order the entries as they like. Note: It used to try to automagically sort the entries based on ipcmp() of the value of 'external' - that does not work in 2.2.* because 'external' is not a key at all for NPt. So I took that out - seemed more consistent to provide the user drag-drop entry ordering feature. Other bits of text in firewall NAT, 1:1 and Out standardized to make all of them match. --- src/usr/local/www/firewall_nat.php | 2 +- src/usr/local/www/firewall_nat_1to1.php | 10 +- src/usr/local/www/firewall_nat_npt.php | 158 +++++++++++++++++++++------- src/usr/local/www/firewall_nat_npt_edit.php | 38 +++---- src/usr/local/www/firewall_nat_out.php | 5 +- 5 files changed, 145 insertions(+), 68 deletions(-) (limited to 'src') diff --git a/src/usr/local/www/firewall_nat.php b/src/usr/local/www/firewall_nat.php index ec7a708..0d0d3a6 100644 --- a/src/usr/local/www/firewall_nat.php +++ b/src/usr/local/www/firewall_nat.php @@ -175,7 +175,7 @@ if ($savemsg) { if (is_subsystem_dirty('natconf')) { print_info_box_np(gettext('The NAT configuration has been changed.') . '
' . - gettext('You must apply the changes in order for them to take effect.') . '
'); + gettext('You must apply the changes in order for them to take effect.')); } $tab_array = array(); diff --git a/src/usr/local/www/firewall_nat_1to1.php b/src/usr/local/www/firewall_nat_1to1.php index f336433..1fc1593 100644 --- a/src/usr/local/www/firewall_nat_1to1.php +++ b/src/usr/local/www/firewall_nat_1to1.php @@ -161,7 +161,7 @@ if ($savemsg) { if (is_subsystem_dirty('natconf')) { print_info_box_np(gettext('The NAT configuration has been changed.') . '
' . - gettext('You must apply the changes in order for them to take effect.') . '
'); + gettext('You must apply the changes in order for them to take effect.')); } $tab_array = array(); @@ -249,9 +249,9 @@ display_top_tabs($tab_array); - " href="firewall_nat_1to1_edit.php?id="> - " href="firewall_nat_1to1_edit.php?dup="> - " href="firewall_nat_1to1.php?act=del&id=" > + " href="firewall_nat_1to1_edit.php?id="> + " href="firewall_nat_1to1_edit.php?dup="> + " href="firewall_nat_1to1.php?act=del&id="> @@ -273,7 +273,7 @@ display_top_tabs($tab_array); - diff --git a/src/usr/local/www/firewall_nat_npt.php b/src/usr/local/www/firewall_nat_npt.php index 9dc8fd5..034017f 100644 --- a/src/usr/local/www/firewall_nat_npt.php +++ b/src/usr/local/www/firewall_nat_npt.php @@ -75,6 +75,27 @@ if (!is_array($config['nat']['npt'])) { $a_npt = &$config['nat']['npt']; +/* update rule order, POST[rule] is an array of ordered IDs */ +if (array_key_exists('order-store', $_POST)) { + if (is_array($_POST['rule']) && !empty($_POST['rule'])) { + $a_npt_new = array(); + + // if a rule is not in POST[rule], it has been deleted by the user + foreach ($_POST['rule'] as $id) { + $a_npt_new[] = $a_npt[$id]; + } + + $a_npt = $a_npt_new; + + if (write_config()) { + mark_subsystem_dirty('natconf'); + } + + header("Location: firewall_nat_npt.php"); + exit; + } +} + if ($_POST) { $pconfig = $_POST; @@ -101,6 +122,36 @@ if ($_GET['act'] == "del") { } } +if (isset($_POST['del_x'])) { + /* delete selected rules */ + if (is_array($_POST['rule']) && count($_POST['rule'])) { + foreach ($_POST['rule'] as $rulei) { + unset($a_npt[$rulei]); + } + + if (write_config()) { + mark_subsystem_dirty('natconf'); + } + + header("Location: firewall_nat_npt.php"); + exit; + } + +} else if ($_GET['act'] == "toggle") { + if ($a_npt[$_GET['id']]) { + if (isset($a_npt[$_GET['id']]['disabled'])) { + unset($a_npt[$_GET['id']]['disabled']); + } else { + $a_npt[$_GET['id']]['disabled'] = true; + } + if (write_config(gettext("Firewall: NAT: NPt, enable/disable NAT rule"))) { + mark_subsystem_dirty('natconf'); + } + header("Location: firewall_nat_npt.php"); + exit; + } +} + $pgtitle = array(gettext("Firewall"), gettext("NAT"), gettext("NPt")); include("head.inc"); @@ -109,7 +160,8 @@ if ($savemsg) { } if (is_subsystem_dirty('natconf')) { - print_info_box_np(gettext("The NAT configuration has been changed") . ".
" . gettext("You must apply the changes in order for them to take effect.")); + print_info_box_np(gettext('The NAT configuration has been changed.') . '
' . + gettext('You must apply the changes in order for them to take effect.')); } $tab_array = array(); @@ -119,14 +171,15 @@ $tab_array[] = array(gettext("Outbound"), false, "firewall_nat_out.php"); $tab_array[] = array(gettext("NPt"), true, "firewall_nat_npt.php"); display_top_tabs($tab_array); ?> -
-

-
-
-
+ +
+

+
+ + @@ -137,38 +190,58 @@ display_top_tabs($tab_array); "; + $i = 0; + foreach ($a_npt as $natent): + if (isset($natent['disabled'])) { + $textss = ""; + $iconfn = "pass_d"; + $trclass = 'class="disabled"'; + } else { + $textss = ""; + $iconfn = "pass"; + $trclass = ''; + } ?> - > + onClick="fr_toggle()" ondblclick="document.location='firewall_nat_npt_edit.php?id=';"> + + + + - - - - + + diff --git a/src/usr/local/www/firewall_nat_npt_edit.php b/src/usr/local/www/firewall_nat_npt_edit.php index 6adbbcf..4025605 100644 --- a/src/usr/local/www/firewall_nat_npt_edit.php +++ b/src/usr/local/www/firewall_nat_npt_edit.php @@ -63,20 +63,6 @@ require_once("ipsec.inc"); -function natnptcmp($a, $b) { - return ipcmp($a['external'], $b['external']); -} - -function nat_npt_rules_sort() { - global $g, $config; - - if (!is_array($config['nat']['npt'])) { - return; - } - - usort($config['nat']['npt'], "natnptcmp"); -} - require("guiconfig.inc"); require_once("interfaces.inc"); require_once("filter.inc"); @@ -102,6 +88,11 @@ if (isset($_POST['id']) && is_numericint($_POST['id'])) { $id = $_POST['id']; } +if (isset($_GET['dup'])) { + $id = $_GET['dup']; + $after = $_GET['dup']; +} + if (isset($id) && $a_npt[$id]) { $pconfig['disabled'] = isset($a_npt[$id]['disabled']); @@ -118,12 +109,14 @@ if (isset($id) && $a_npt[$id]) { $pconfig['interface'] = "wan"; } - $pconfig['external'] = $a_npt[$id]['external']; $pconfig['descr'] = $a_npt[$id]['descr']; } else { $pconfig['interface'] = "wan"; } +if (isset($_GET['dup'])) { + unset($id); +} if ($_POST) { @@ -161,9 +154,12 @@ if ($_POST) { if (isset($id) && $a_npt[$id]) { $a_npt[$id] = $natent; } else { - $a_npt[] = $natent; + if (is_numeric($after)) { + array_splice($a_npt, $after+1, 0, array($natent)); + } else { + $a_npt[] = $natent; + } } - nat_npt_rules_sort(); if (write_config()) { mark_subsystem_dirty('natconf'); @@ -185,24 +181,24 @@ function build_if_list() { if ($config['l2tp']['mode'] == "server") { if (have_ruleint_access("l2tp")) { - $interfaces['l2tp'] = "L2TP VPN"; + $interfaces['l2tp'] = gettext("L2TP VPN"); } } if ($config['pppoe']['mode'] == "server") { if (have_ruleint_access("pppoe")) { - $interfaces['pppoe'] = "PPPoE Server"; + $interfaces['pppoe'] = gettext("PPPoE Server"); } } /* add ipsec interfaces */ if (ipsec_enabled() && have_ruleint_access("enc0")) { - $interfaces["enc0"] = "IPsec"; + $interfaces["enc0"] = gettext("IPsec"); } /* add openvpn/tun interfaces */ if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) { - $interfaces["openvpn"] = "OpenVPN"; + $interfaces["openvpn"] = gettext("OpenVPN"); } return($interfaces); diff --git a/src/usr/local/www/firewall_nat_out.php b/src/usr/local/www/firewall_nat_out.php index 20b7098..29dce5a 100644 --- a/src/usr/local/www/firewall_nat_out.php +++ b/src/usr/local/www/firewall_nat_out.php @@ -244,7 +244,8 @@ if ($savemsg) { } if (is_subsystem_dirty('natconf')) { - print_info_box_np(gettext("The NAT configuration has been changed.")."
".gettext("You must apply the changes in order for them to take effect.")); + print_info_box_np(gettext('The NAT configuration has been changed.') . '
' . + gettext('You must apply the changes in order for them to take effect.')); } $tab_array = array(); @@ -529,7 +530,7 @@ print($form); - -- cgit v1.1
+ + + + " title=""> + + - - - - - + - + - " href="firewall_nat_npt_edit.php?id="> - " href="firewall_nat_npt.php?act=del&id="> + " href="firewall_nat_npt_edit.php?id="> + " href="firewall_nat_npt_edit.php?dup="> + " href="firewall_nat_npt.php?act=del&id=">