. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* pfSense_MODULE: nat */ ##|+PRIV ##|*IDENT=page-firewall-nat-outbound ##|*NAME=Firewall: NAT: Outbound page ##|*DESCR=Allow access to the 'Firewall: NAT: Outbound' page. ##|*MATCH=firewall_nat_out.php* ##|-PRIV require("guiconfig.inc"); require_once("functions.inc"); require_once("filter.inc"); require_once("shaper.inc"); global $FilterIflist; global $GatewaysList; if (!is_array($config['nat']['outbound'])) $config['nat']['outbound'] = array(); if (!is_array($config['nat']['outbound']['rule'])) $config['nat']['outbound']['rule'] = array(); $a_out = &$config['nat']['outbound']['rule']; if (!isset($config['nat']['outbound']['mode'])) $config['nat']['outbound']['mode'] = "automatic"; $mode = $config['nat']['outbound']['mode']; if ($_POST['apply']) { write_config(); $retval = 0; $retval |= filter_configure(); if(stristr($retval, "error") <> true) $savemsg = get_std_save_message($retval); else $savemsg = $retval; if ($retval == 0) { clear_subsystem_dirty('natconf'); clear_subsystem_dirty('filter'); } } if (isset($_POST['save']) && $_POST['save'] == "Save") { /* mutually exclusive settings - if user wants advanced NAT, we don't generate automatic rules */ if ($_POST['mode'] == "advanced" && ($mode == "automatic" || $mode == "hybrid")) { /* * user has enabled advanced outbound NAT and doesn't have rules * lets automatically create entries * for all of the interfaces to make life easier on the pip-o-chap */ if(empty($FilterIflist)) filter_generate_optcfg_array(); if(empty($GatewaysList)) filter_generate_gateways(); $tonathosts = filter_nat_rules_automatic_tonathosts(true); $automatic_rules = filter_nat_rules_outbound_automatic(""); foreach ($tonathosts as $tonathost) { foreach ($automatic_rules as $natent) { $natent['source']['network'] = $tonathost['subnet']; $natent['descr'] .= sprintf(gettext(' - %1$s to %2$s'), $tonathost['descr'], convert_real_interface_to_friendly_descr($natent['interface'])); $natent['created'] = make_config_revision_entry(null, gettext("Manual Outbound NAT Switch")); /* Try to detect already auto created rules and avoid duplicate them */ $found = false; foreach ($a_out as $rule) { if ($rule['interface'] == $natent['interface'] && $rule['source']['network'] == $natent['source']['network'] && $rule['dstport'] == $natent['dstport'] && $rule['target'] == $natent['target'] && $rule['descr'] == $natent['descr']) { $found = true; break; } } if ($found === false) $a_out[] = $natent; } } $savemsg = gettext("Default rules for each interface have been created."); unset($FilterIflist, $GatewaysList); } $config['nat']['outbound']['mode'] = $_POST['mode']; if (write_config()) mark_subsystem_dirty('natconf'); header("Location: firewall_nat_out.php"); exit; } if ($_GET['act'] == "del") { if ($a_out[$_GET['id']]) { unset($a_out[$_GET['id']]); if (write_config()) mark_subsystem_dirty('natconf'); header("Location: firewall_nat_out.php"); exit; } } if (isset($_POST['del_x'])) { /* delete selected rules */ if (is_array($_POST['rule']) && count($_POST['rule'])) { foreach ($_POST['rule'] as $rulei) { unset($a_out[$rulei]); } if (write_config()) mark_subsystem_dirty('natconf'); header("Location: firewall_nat_out.php"); exit; } } else if ($_GET['act'] == "toggle") { if ($a_out[$_GET['id']]) { if(isset($a_out[$_GET['id']]['disabled'])) unset($a_out[$_GET['id']]['disabled']); else $a_out[$_GET['id']]['disabled'] = true; if (write_config("Firewall: NAT: Outbound, enable/disable NAT rule")) mark_subsystem_dirty('natconf'); header("Location: firewall_nat_out.php"); exit; } } else { /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */ unset($movebtn); foreach ($_POST as $pn => $pd) { if (preg_match("/move_(\d+)_x/", $pn, $matches)) { $movebtn = $matches[1]; break; } } /* move selected rules before this rule */ if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) { $a_out_new = array(); /* copy all rules < $movebtn and not selected */ for ($i = 0; $i < $movebtn; $i++) { if (!in_array($i, $_POST['rule'])) $a_out_new[] = $a_out[$i]; } /* copy all selected rules */ for ($i = 0; $i < count($a_out); $i++) { if ($i == $movebtn) continue; if (in_array($i, $_POST['rule'])) $a_out_new[] = $a_out[$i]; } /* copy $movebtn rule */ if ($movebtn < count($a_out)) $a_out_new[] = $a_out[$movebtn]; /* copy all rules > $movebtn and not selected */ for ($i = $movebtn+1; $i < count($a_out); $i++) { if (!in_array($i, $_POST['rule'])) $a_out_new[] = $a_out[$i]; } if (count($a_out_new) > 0) $a_out = $a_out_new; if (write_config()) mark_subsystem_dirty('natconf'); header("Location: firewall_nat_out.php"); exit; } } $pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("Outbound")); include("head.inc"); ?>
".gettext("You must apply the changes in order for them to take effect.")); ?>
/>
/>
" />
 
/>
/>
 
"; $textse = ""; $iconfn .= "_d"; } //build Alias popup box $alias_src_span_begin = ""; $alias_src_port_span_begin = ""; $alias_dst_span_begin = ""; $alias_dst_port_span_begin = ""; $alias_popup = rule_popup($natent['source']['network'],pprint_port($natent['sourceport']),$natent['destination']['address'],pprint_port($natent['dstport'])); $alias_src_span_begin = $alias_popup["src"]; $alias_src_port_span_begin = $alias_popup["srcport"]; $alias_dst_span_begin = $alias_popup["dst"]; $alias_dst_port_span_begin = $alias_popup["dstport"]; $alias_src_span_end = $alias_popup["src_end"]; $alias_src_port_span_end = $alias_popup["srcport_end"]; $alias_dst_span_end = $alias_popup["dst_end"]; $alias_dst_port_span_end = $alias_popup["dstport_end"]; ?>
 
 
   
" alt="add" />
" alt="icon" /> " alt="icon" />   NO NAT'; elseif (!$natent['target']) echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface'])) . " address"; elseif ($natent['target'] == "other-subnet") echo $natent['targetip'] . '/' . $natent['targetip_subnet']; else echo $natent['target']; echo $textse; ?>  
" type="image" style="height:17;width:17;border:0" /> " alt="edit" />
')"> " alt="delete" /> " width="17" height="17" border="0" alt="duplicate" />
" border="0" alt="move" /> " /> " alt="add" />
" border="0" alt="delete" /> " onclick="return confirm('')" />
 
 
     
  " alt="icon" />   NO NAT'; elseif (!$natent['target']) echo htmlspecialchars(convert_friendly_interface_to_friendly_descr($natent['interface'])) . " address"; elseif ($natent['target'] == "other-subnet") echo $natent['targetip'] . '/' . $natent['targetip_subnet']; else echo $natent['target']; ?>    



" . "If manual outbound NAT is selected, outbound NAT rules will not be " . "automatically generated and only the mappings you specify on this page " . "will be used.

" . "If hybrid outbound NAT is selected, mappings you specify on this page will " . "be used, followed by the automatically generated ones.

" . "If disable outbound NAT is selected, no rules will be used.

" . "If a target address other than a WAN-type interface's IP address is used, " . "then depending on the way the WAN connection is setup, a "); ?>