diff --git a/src/www/firewall_nat_edit.php b/src/www/firewall_nat_edit.php index 5cccabf99..d2fd228d4 100644 --- a/src/www/firewall_nat_edit.php +++ b/src/www/firewall_nat_edit.php @@ -55,7 +55,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['dstbeginport'] = 80 ; $pconfig['dstendport'] = 80 ; $pconfig['local-port'] = 80; - $pconfig['filter-rule-association'] = "add-associated"; + $pconfig['associated-rule-id'] = "add-associated"; if (isset($configId)) { // copy 1-on-1 foreach (array('protocol','target','local-port','descr','interface','associated-rule-id','nosync','log', @@ -223,9 +223,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!empty($natent['nordr'])) { $natent['associated-rule-id'] = ''; - } elseif (!empty($pconfig['filter-rule-association']) && $pconfig['filter-rule-association'] == "pass") { + } elseif (!empty($pconfig['associated-rule-id']) && $pconfig['associated-rule-id'] == "pass") { $natent['associated-rule-id'] = "pass"; - } elseif (!empty($pconfig['associated-rule-id'])) { + } elseif (!empty($pconfig['associated-rule-id']) && !in_array($pconfig['associated-rule-id'], ['add-associated', 'add-unassociated'])) { $natent['associated-rule-id'] = $pconfig['associated-rule-id']; } else { $natent['associated-rule-id'] = null; @@ -266,24 +266,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } // Updating a rule with a filter rule associated - if (!empty($natent['associated-rule-id']) || !empty($pconfig['filter-rule-association'])) { + if (!empty($natent['associated-rule-id']) || in_array($pconfig['associated-rule-id'], ['add-associated', 'add-unassociated'])) { /* auto-generate a matching firewall rule */ - $filterent = array(); - // If a rule already exists, load it - if (!empty($natent['associated-rule-id'])) { - // search rule by associated-rule-id - $filterentid = false; - foreach ($config['filter']['rule'] as $key => $item){ + $filterent = []; + if (in_array($pconfig['associated-rule-id'], ['add-associated', 'add-unassociated'])) { + $filterent['associated-rule-id'] = $natent['associated-rule-id']; + } else { + $filterent['associated-rule-id'] = $natent['associated-rule-id']; + foreach ($config['filter']['rule'] as $key => &$item){ if (isset($item['associated-rule-id']) && $item['associated-rule-id']==$natent['associated-rule-id']) { - $filterentid = $key; - break; + $filterent = &config_read_array('filter', 'rule', $key); + break; } } - if ($filterentid === false) { - $filterent['associated-rule-id'] = $natent['associated-rule-id']; - } else { - $filterent = &config_read_array('filter', 'rule', $filterentid); - } } pconfig_to_address($filterent['source'], $pconfig['src'], $pconfig['srcmask'], !empty($pconfig['srcnot']), @@ -339,8 +334,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $filterent['category'] = $natent['category']; // If this is a new rule, create an ID and add the rule - if (!empty($pconfig['filter-rule-association']) && $pconfig['filter-rule-association'] != 'pass') { - if ($pconfig['filter-rule-association'] == 'add-associated') { + if ( + !empty($pconfig['associated-rule-id']) && + in_array($pconfig['associated-rule-id'], ['add-associated', 'add-unassociated']) + ) { + if ($pconfig['associated-rule-id'] == 'add-associated') { $filterent['associated-rule-id'] = $natent['associated-rule-id'] = uniqid("nat_", true); } $filterent['created'] = make_config_revision_entry(); @@ -1051,52 +1049,43 @@ $( document ).ready(function() { - -