summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/firewall_nat_npt.php
diff options
context:
space:
mode:
authorPhil Davis <phil.davis@inf.org>2016-01-19 12:02:46 +0545
committerPhil Davis <phil.davis@inf.org>2016-01-19 12:02:46 +0545
commit416f079781dffc6fb31a0d0c7274cbd80aa51752 (patch)
treec2cbb1fe7361c1589dc4913dda2789530527b2d0 /src/usr/local/www/firewall_nat_npt.php
parentbf2103299d521659459f335d18954e451debecaf (diff)
downloadpfsense-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/local/www/firewall_nat_npt.php')
-rw-r--r--src/usr/local/www/firewall_nat_npt.php158
1 files changed, 119 insertions, 39 deletions
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&amp;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']) . '&nbsp;' . $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&amp;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&amp;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>
OpenPOWER on IntegriCloud