. 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. */ require("guiconfig.inc"); 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; config_lock(); $retval |= filter_configure(); config_unlock(); if(stristr($retval, "error") <> true) $savemsg = get_std_save_message($retval); else $savemsg = $retval; if ($retval == 0) { unlink_if_exists($d_natconfdirty_path); unlink_if_exists($d_filterconfdirty_path); } } 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']); if(count($config['nat']['advancedoutbound']['rule']) == 0) unset($config['nat']['advancedoutbound']['rule']); break; case "advancedoutboundnat": $was_enabled = isset($config['nat']['advancedoutbound']['enable']); $config['nat']['advancedoutbound']['enable'] = true; unset($config['nat']['ipsecpassthru']['enable']); if($was_enabled == false) { /* * user has enabled advanced outbound nat -- lets automatically create entries * for all of the interfaces to make life easier on the pip-o-chap */ $ifdescrs = array('lan'); for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) $ifdescrs[] = "opt" . $j; foreach($ifdescrs as $if) { if($if <> "lan" and $if <> "wan") { /* interface is an optional. is it enabled? */ if(!isset($config['interfaces'][$if]['enabled'])) { continue; } } $natent = array(); $osn = gen_subnet($config['interfaces'][$if]['ipaddr'], $config['interfaces'][$if]['subnet']); $natent['source']['network'] = $osn . "/" . $config['interfaces'][$if]['subnet']; $natent['sourceport'] = ""; $int_description = $config['interfaces'][$if]['descr']; if($if == "lan") $int_description = "LAN"; $natent['descr'] = "Auto created rule for {$int_description}"; $natent['target'] = ""; $natent['interface'] = "wan"; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; } $savemsg = "Default rules for each interface have been created."; } break; } write_config(); touch($d_natconfdirty_path); 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(); touch($d_natconfdirty_path); 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(); touch($d_natconfdirty_path); header("Location: firewall_nat_out.php"); exit; } } $pgtitle = "Firewall: NAT: Outbound"; include("head.inc"); ?>

Firewall: NAT: Outbound

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
"; ?>