summaryrefslogtreecommitdiffstats
path: root/usr/local/www/firewall_nat_edit.php
diff options
context:
space:
mode:
authorpierrepomes <pierre.pomes@interface-tech.com>2009-12-12 15:57:19 -0500
committerpierrepomes <pierre.pomes@interface-tech.com>2009-12-12 15:57:19 -0500
commit473d0ff02fb2dddca7e98435614a0a47ba5e7115 (patch)
treec416bdc464af6baac8c698a412513f76b05238c7 /usr/local/www/firewall_nat_edit.php
parent1b6650903ac0770344012baee77c145b48d7b488 (diff)
downloadpfsense-473d0ff02fb2dddca7e98435614a0a47ba5e7115.zip
pfsense-473d0ff02fb2dddca7e98435614a0a47ba5e7115.tar.gz
Add patch from lietu (Janne Enberg). Ticket #136
1) Multiple NAT rules can be assigned the same filter rule -> Fixed, added assigned-nat-rule-id to filter rules to keep track of the assignment 2) when removing the link (i.e. switching to "pass" or "none", the linked rule isn't deleted (should it be? probably yes) -> Fixed, when a NAT rule's association is removed, the filter rule is deleted. Added a "create new associated filter rule" option to the dropdown if there is none selected. 3) The destination IP and port of linked rules can be edited in firewall_rules_edit.php and shouldn't be. Source should be editable but not destination, since that should strictly be tied to the NAT rule. -> Fixed, you cannot edit the destination for the filter rules that are linked to NAT rules, this has been disabled both by JavaScript and PHP. 4) If you edit the source in a linked firewall rule, it gets overwritten when you edit the NAT rule. The NAT rule should never touch the firewall rule source after the rule exists. -> Fixed, previously the old rule was deleted and a new one created, now it only updates the old rule and doesn't touch the source. Also added crosslinking from the NAT rule to the filter rule and back, so you can jump to edit the filter rule from the NAT rule and vice-versa.
Diffstat (limited to 'usr/local/www/firewall_nat_edit.php')
-rwxr-xr-xusr/local/www/firewall_nat_edit.php73
1 files changed, 58 insertions, 15 deletions
diff --git a/usr/local/www/firewall_nat_edit.php b/usr/local/www/firewall_nat_edit.php
index a1e0c9c..4f5045c 100755
--- a/usr/local/www/firewall_nat_edit.php
+++ b/usr/local/www/firewall_nat_edit.php
@@ -199,27 +199,57 @@ if ($_POST) {
else
unset($natent['nosync']);
+ // If we used to have an associated filter rule, but no-longer should have one
+ if( $a_nat[$id]>0 && ($natent['associated-filter-rule-id']>0)===false ) {
+ // Delete the previous rule
+ delete_id($a_nat[$id]['associated-filter-rule-id'], $config['filter']['rule']);
+ mark_subsystem_dirty('filter');
+ }
+
$need_filter_rule = false;
// Updating a rule with a filter rule associated
if( $natent['associated-filter-rule-id']>0 )
$need_filter_rule = true;
+ // Create a rule or if we want to create a new one
+ if( $natent['associated-filter-rule-id']=='new' ) {
+ $need_filter_rule = true;
+ unset( $natent['associated-filter-rule-id'] );
+ $_POST['filter-rule-association']='add-associated';
+ }
// If creating a new rule, where we want to add the filter rule, associated or not
- else if( isset($_POST['filter-rule-association']) &&
- ($_POST['filter-rule-association']=='add-associated' ||
+ else if( isset($_POST['filter-rule-association']) &&
+ ($_POST['filter-rule-association']=='add-associated' ||
$_POST['filter-rule-association']=='add-unassociated') )
$need_filter_rule = true;
- if ($need_filter_rule) {
+ // Determine NAT entry ID now, we need it for the firewall rule
+ if (isset($id) && $a_nat[$id])
+ $a_nat[$id] = $natent;
+ else {
+ if (is_numeric($after))
+ $id = $after + 1;
+ else
+ $id = count($a_nat);
+ }
- // If we had a previous rule associated with this NAT rule, delete that
- if( $natent['associated-filter-rule-id'] > 0 )
- delete_id($natent['associated-filter-rule-id'], $config['filter']['rule']);
+ if ($need_filter_rule) {
/* auto-generate a matching firewall rule */
$filterent = array();
+
+ // If a rule already exists, load it
+ if( $natent['associated-filter-rule-id'] > 0 )
+ $filterent = &get_id($natent['associated-filter-rule-id'], $config['filter']['rule']);
+ else
+ // Create the default source entry for new filter entries
+ $filterent['source']['any'] = "";
+
+ // Update associated nat rule ID
+ $filterent['associated-nat-rule-id'] = $id;
+
+ // Update interface, protocol and destination
$filterent['interface'] = $_POST['interface'];
$filterent['protocol'] = $_POST['proto'];
- $filterent['source']['any'] = "";
$filterent['destination']['address'] = $_POST['localip'];
$dstpfrom = $_POST['localbeginport'];
@@ -237,19 +267,17 @@ if ($_POST) {
*/
$filterent['descr'] = substr("NAT " . $_POST['descr'], 0, 59);
- // If we had a previous rule association, update this rule with that ID so we don't lose association
- if ($natent['associated-filter-rule-id'] > 0)
- $filterent['id'] = $natent['associated-filter-rule-id'];
- // If we wanted this rule to be associated, make sure the NAT entry is updated with the same ID
- else if($_POST['filter-rule-association']=='add-associated')
+ // If this is a new rule, create an ID and add the rule
+ if( $_POST['filter-rule-association']=='add-associated' ) {
$natent['associated-filter-rule-id'] = $filterent['id'] = get_next_id($config['filter']['rule']);
- $config['filter']['rule'][] = $filterent;
+ $config['filter']['rule'][] = $filterent;
+ }
mark_subsystem_dirty('filter');
}
- // Update NAT entry after creating/updating the firewall rule, so we have it's rule ID if one was created
+ // Update the NAT entry now
if (isset($id) && $a_nat[$id])
$a_nat[$id] = $natent;
else {
@@ -433,13 +461,28 @@ include("fbegin.inc"); ?>
<option value="">None</option>
<option value="pass" <?php if($pconfig['associated-filter-rule-id'] == "pass") echo " SELECTED"; ?>>Pass</option>
<?php foreach ($config['filter']['rule'] as $filter_rule): ?>
- <?php if (isset($filter_rule['id']) && $filter_rule['id']>0): ?>
+ <?php if (isset($filter_rule['id']) && $filter_rule['id']>0 && ( isset($filter_rule['associated-nat-rule-id'])===false || $filter_rule['id']==$pconfig['associated-filter-rule-id'])): ?>
<option value="<?php echo $filter_rule['id']; ?>"<?php if($filter_rule['id']==$pconfig['associated-filter-rule-id']) echo " SELECTED"; ?>>
<?php echo htmlspecialchars('Rule ' . $filter_rule['id'] . ' - ' . $filter_rule['descr']); ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
+ <?php if ( ($pconfig['associated-filter-rule-id']>0)===false ): ?>
+ <option value="new">Create new associated filter rule</option>
+ <?php endif; ?>
</select>
+ <?php if($pconfig['associated-filter-rule-id']>0): ?>
+ <?php
+ foreach( $config['filter']['rule'] as $index => $filter_rule ) {
+ if( $filter_rule['id']==$pconfig['associated-filter-rule-id'] ) {
+ ?>
+ <a href="firewall_rules_edit.php?id=<?=$index;?>">View the filter rule</a>
+ <?php
+ break;
+ }
+ }
+ ?>
+ <?php endif; ?>
</td>
</tr>
<?php endif; ?>
OpenPOWER on IntegriCloud