diff options
author | Phil Davis <phil.davis@inf.org> | 2016-01-19 12:02:46 +0545 |
---|---|---|
committer | Phil Davis <phil.davis@inf.org> | 2016-01-19 12:02:46 +0545 |
commit | 416f079781dffc6fb31a0d0c7274cbd80aa51752 (patch) | |
tree | c2cbb1fe7361c1589dc4913dda2789530527b2d0 /src/usr | |
parent | bf2103299d521659459f335d18954e451debecaf (diff) | |
download | pfsense-416f079781dffc6fb31a0d0c7274cbd80aa51752.zip pfsense-416f079781dffc6fb31a0d0c7274cbd80aa51752.tar.gz |
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.
Diffstat (limited to 'src/usr')
-rw-r--r-- | src/usr/local/www/firewall_nat.php | 2 | ||||
-rw-r--r-- | src/usr/local/www/firewall_nat_1to1.php | 10 | ||||
-rw-r--r-- | src/usr/local/www/firewall_nat_npt.php | 158 | ||||
-rw-r--r-- | src/usr/local/www/firewall_nat_npt_edit.php | 38 | ||||
-rw-r--r-- | src/usr/local/www/firewall_nat_out.php | 5 |
5 files changed, 145 insertions, 68 deletions
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.') . '<br />' . - gettext('You must apply the changes in order for them to take effect.') . '<br />'); + 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.') . '<br />' . - gettext('You must apply the changes in order for them to take effect.') . '<br />'); + 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); </td> <td> - <a class="fa fa-pencil" title="<?=gettext("Edit rule")?>" href="firewall_nat_1to1_edit.php?id=<?=$i?>"></a> - <a class="fa fa-clone" title="<?=gettext("Add a new rule based on this one")?>" href="firewall_nat_1to1_edit.php?dup=<?=$i?>"></a> - <a class="fa fa-trash" title="<?=gettext("Delete rule")?>" href="firewall_nat_1to1.php?act=del&id=<?=$i?>" ></a> + <a class="fa fa-pencil" title="<?=gettext("Edit mapping")?>" href="firewall_nat_1to1_edit.php?id=<?=$i?>"></a> + <a class="fa fa-clone" title="<?=gettext("Add a new mapping based on this one")?>" href="firewall_nat_1to1_edit.php?dup=<?=$i?>"></a> + <a class="fa fa-trash" title="<?=gettext("Delete mapping")?>" href="firewall_nat_1to1.php?act=del&id=<?=$i?>"></a> </td> </tr> @@ -273,7 +273,7 @@ display_top_tabs($tab_array); <i class="fa fa-trash icon-embed-btn"></i> <?=gettext("Delete"); ?> </button> - <button type="submit" id="order-store" name="order-store" class="btn btn-primary btn-sm" disabled title="<?=gettext('Save rule order')?>"> + <button type="submit" id="order-store" name="order-store" class="btn btn-primary btn-sm" disabled title="<?=gettext('Save mapping order')?>"> <i class="fa fa-save icon-embed-btn"></i> <?=gettext("Save")?> </button> 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") . ".<br />" . gettext("You must apply the changes in order for them to take effect.")); + print_info_box_np(gettext('The NAT configuration has been changed.') . '<br />' . + 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); ?> -<div class="panel panel-default"> - <div class="panel-heading"><h2 class="panel-title"><?=gettext('NPt Mappings')?></h2></div> - <div class="panel-body"> - <div class="table responsive"> - <form method="post"> +<form action="firewall_nat_npt.php" method="post"> + <div class="panel panel-default"> + <div class="panel-heading"><h2 class="panel-title"><?=gettext('NPt Mappings')?></h2></div> + <div id="mainarea" class="table-responsive panel-body"> <table class="table table-striped table-hover table-condensed"> <thead> <tr> + <th><!-- checkbox --></th> + <th><!-- icon --></th> <th><?=gettext("Interface")?></th> <th><?=gettext("External Prefix")?></th> <th><?=gettext("Internal prefix")?></th> @@ -137,38 +190,58 @@ display_top_tabs($tab_array); <tbody class="user-entries"> <?php -$i = 0; -foreach ($a_npt as $natent): + $textse = "</span>"; + $i = 0; + foreach ($a_npt as $natent): + if (isset($natent['disabled'])) { + $textss = "<span class=\"gray\">"; + $iconfn = "pass_d"; + $trclass = 'class="disabled"'; + } else { + $textss = "<span>"; + $iconfn = "pass"; + $trclass = ''; + } ?> - <tr<?=isset($natent['disabled'])? ' class="disabled"' : ''?>> + <tr id="fr<?=$i;?>" <?=$trclass?> onClick="fr_toggle(<?=$i;?>)" ondblclick="document.location='firewall_nat_npt_edit.php?id=<?=$i;?>';"> + <td > + <input type="checkbox" id="frc<?=$i;?>" onClick="fr_toggle(<?=$i;?>)" name="rule[]" value="<?=$i;?>"/> + </td> + <td> + <a href="?act=toggle&id=<?=$i?>"> + <i class="fa <?= ($iconfn == "pass") ? "fa-check":"fa-times"?>" title="<?=gettext("click to toggle enabled/disabled status")?>"></i> + </a> + </td> <td> - <input type="hidden" name="rule[]" value="<?=$i?>" /> <?php - if (!$natent['interface']) { - print(htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan"))); - } else { - print(htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface']))); - } + echo $textss; + if (!$natent['interface']) { + echo htmlspecialchars(convert_friendly_interface_to_friendly_descr("wan")); + } else { + echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface'])); + } + echo $textse; ?> - </td> + </td> + <td> <?php - $source_net = pprint_address($natent['source']); - $source_cidr = strstr($source_net, '/'); - $destination_net = pprint_address($natent['destination']); - $destination_cidr = strstr($destination_net, '/'); + echo $textss . pprint_address($natent['destination']) . $textse; ?> - <td> - <?=$destination_net?> </td> <td> - <?=$source_net?> +<?php + echo $textss . pprint_address($natent['source']) . $textse; +?> </td> <td> - <?=htmlspecialchars($natent['descr'])?> +<?php + echo $textss . htmlspecialchars($natent['descr']) . ' ' . $textse; +?> </td> <td> - <a class="fa fa-pencil" title="<?=gettext("Edit"); ?>" href="firewall_nat_npt_edit.php?id=<?=$i?>"></a> - <a class="fa fa-trash" title="<?=gettext("Delete")?>" href="firewall_nat_npt.php?act=del&id=<?=$i?>"></a> + <a class="fa fa-pencil" title="<?=gettext("Edit mapping")?>" href="firewall_nat_npt_edit.php?id=<?=$i?>"></a> + <a class="fa fa-clone" title="<?=gettext("Add a new mapping based on this one")?>" href="firewall_nat_npt_edit.php?dup=<?=$i?>"></a> + <a class="fa fa-trash" title="<?=gettext("Delete mapping")?>" href="firewall_nat_npt.php?act=del&id=<?=$i?>"></a> </td> </tr> <?php @@ -179,19 +252,21 @@ endforeach; </table> </div> </div> -</div> - - -<nav class="action-buttons"> - <a href="firewall_nat_npt_edit.php" class="btn btn-sm btn-success"> - <i class="fa fa-plus icon-embed-btn"></i> - <?=gettext("Add")?> - </a> - <button type="submit" id="order-store" class="btn btn-primary btn-sm" value="store changes" disabled> - <i class="fa fa-save icon-embed-btn"></i> - <?=gettext("Save")?> - </button> -</nav> + + <nav class="action-buttons"> + <a href="firewall_nat_npt_edit.php" class="btn btn-sm btn-success" title="<?=gettext('Add new mapping')?>"> + <i class="fa fa-plus icon-embed-btn"></i> + <?=gettext('Add')?> + </a> + <button name="del_x" type="submit" class="btn btn-danger btn-sm" title="<?=gettext('Delete selected mappings')?>"> + <i class="fa fa-trash icon-embed-btn"></i> + <?=gettext("Delete"); ?> + </button> + <button type="submit" id="order-store" name="order-store" class="btn btn-primary btn-sm" disabled title="<?=gettext('Save mapping order')?>"> + <i class="fa fa-save icon-embed-btn"></i> + <?=gettext("Save")?> + </button> + </nav> </form> <script type="text/javascript"> @@ -204,6 +279,11 @@ events.push(function() { $('#order-store').removeAttr('disabled'); } }); + + // Check all of the rule checkboxes so that their values are posted + $('#order-store').click(function () { + $('[id^=frc]').prop('checked', true); + }); }); //]]> </script> 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.")."<br />".gettext("You must apply the changes in order for them to take effect.")); + print_info_box_np(gettext('The NAT configuration has been changed.') . '<br />' . + gettext('You must apply the changes in order for them to take effect.')); } $tab_array = array(); @@ -529,7 +530,7 @@ print($form); <i class="fa fa-trash icon-embed-btn"></i> <?=gettext("Delete"); ?> </button> - <button type="submit" id="order-store" class="btn btn-primary btn-sm" value="Save changes" disabled name="order-store" title="<?=gettext('Save map order')?>"> + <button type="submit" id="order-store" class="btn btn-primary btn-sm" value="Save changes" disabled name="order-store" title="<?=gettext('Save mapping order')?>"> <i class="fa fa-save icon-embed-btn"></i> <?=gettext("Save")?> </button> |