#!/usr/local/bin/php . 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) { $pconfig = $_POST; if ($_POST['apply']) { write_config(); $retval = 0; if (!file_exists($d_sysrebootreqd_path)) { config_lock(); $retval |= filter_configure(); config_unlock(); } if(stristr($retval, "error") <> true) $savemsg = get_std_save_message($retval); else $savemsg = $retval; if ($retval == 0) { if (file_exists($d_natconfdirty_path)) unlink($d_natconfdirty_path); if (file_exists($d_filterconfdirty_path)) unlink($d_filterconfdirty_path); } } } if (isset($_POST['save'])) { /* mutually exclusive settings - if user wants advanced NAT, we don't help with IPSec */ if ($_POST['ipsecpassthru'] == true) { $config['nat']['ipsecpassthru']['enable'] = true; $config['nat']['advancedoutbound']['enable'] = false; } if ($_POST['advancedoutbound'] == true) { $config['nat']['advancedoutbound']['enable'] = true; $config['nat']['ipsecpassthru']['enable'] = false; } if ($_POST['ipsecpassthru'] == false) $config['nat']['ipsecpassthru']['enable'] = false; if ($_POST['advancedoutbound'] == false) $config['nat']['advancedoutbound']['enable'] = false; if($config['nat']['advancedoutbound']['enable'] and $_POST['advancedoutbound'] <> "") { /* * user has enabled advanced outbound nat -- lets automatically create entries * for all of the interfaces to make life easier on the pip-o-chap */ $a_out = &$config['nat']['advancedoutbound']['rule']; $ifdescrs = array('lan'); for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++) $ifdescrs[] = "opt" . $j; foreach($ifdescrs as $if) { $natent = array(); $osn = convert_ip_to_network_format($config['interfaces'][$if]['ipaddr'], $config['interfaces'][$if]['subnet']); $natent['source']['network'] = $osn; $natent['sourceport'] = ""; $natent['descr'] = "Auto created rule for {$if}"; $natent['target'] = ""; $natent['interface'] = "wan"; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; } $savemsg = "Default rules for each interface have been created."; } 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]; } $a_out = $a_out_new; 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.");?>

> Enable IPSec passthru

> Enable advanced outbound NAT

Note:
If advanced outbound NAT is enabled, no outbound NAT rules will be automatically generated anymore. 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 NAT Port Target Description