. 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"); if (!is_array($config['nat']['advancedoutbound'])) $config['nat']['advancedoutbound'] = array(); if (!is_array($config['nat']['advancedoutbound']['rule'])) $config['nat']['advancedoutbound']['rule'] = array(); $a_out = &$config['nat']['advancedoutbound']['rule']; 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 */ switch ($_POST['advancedoripsec']) { case "ipsecpassthru": $config['nat']['ipsecpassthru']['enable'] = true; unset($config['nat']['advancedoutbound']['enable']); break; case "advancedoutboundnat": if (!isset($config['nat']['advancedoutbound']['enable'])) { $config['nat']['advancedoutbound']['enable'] = true; // if there are already AON rules configured, don't generate default ones if(!empty($a_out)) continue; /* * 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 */ $ifdescrs = get_configured_interface_with_descr(); foreach($ifdescrs as $if => $ifdesc) { if (interface_has_gateway($if)) continue; $osipaddr = get_interface_ip($if); $ossubnet = get_interface_subnet($if); if (!is_ipaddr($osipaddr) || empty($ossubnet)) continue; $osn = gen_subnet($osipaddr, $ossubnet); foreach ($ifdescrs as $if2 => $ifdesc2) { if (!interface_has_gateway($if2)) continue; $natent = array(); $natent['source']['network'] = "{$osn}/{$ossubnet}"; $natent['dstport'] = "500"; $natent['descr'] = "Auto created rule for ISAKMP - {$ifdesc} to {$ifdesc2}"; $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['staticnatport'] = true; $a_out[] = $natent; $natent = array(); $natent['source']['network'] = "{$osn}/{$ossubnet}"; $natent['dstport'] = "5060"; $natent['descr'] = "Auto created rule for SIP - {$ifdesc} to {$ifdesc2}"; $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['staticnatport'] = true; $a_out[] = $natent; $natent = array(); $natent['source']['network'] = "{$osn}/{$ossubnet}"; $natent['sourceport'] = ""; $natent['descr'] = "Auto created rule for {$ifdesc} to {$ifdesc2}"; $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; } } $savemsg = "Default rules for each interface have been created."; } break; } 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]); } write_config(); 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; else unset($config['nat']['advancedoutbound']); write_config(); mark_subsystem_dirty('natconf'); header("Location: firewall_nat_out.php"); exit; } } $pgtitle = array("Firewall","NAT","Outbound"); include("head.inc"); ?>

You must apply the changes in order for them to take effect.");?>

>

>

Note:
If advanced outbound NAT is enabled, no outbound NAT rules will be automatically generated any longer. Instead, only the mappings you specify below will be used. With advanced outbound NAT disabled, a mapping is automatically created for each interface's subnet (except WAN). If you use target addresses other than the WAN interface's IP address, then depending on the way your WAN connection is setup, you may also need a Virtual IP.


You may enter your own mappings below.

    Interface Source Source Port Destination Destination Port NAT Address NAT Port Static Port Description
  YES"; else echo "
NO
"; ?>