. 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'] = sprintf(gettext('Auto created rule for ISAKMP - %1$s to %2$s'),$ifdesc,$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'] = sprintf(gettext('Auto created rule for %1$s to %2$s'),$ifdesc,$ifdesc2); $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; $natent = array(); $natent['source']['network'] = "127.0.0.0/8"; $natent['dstport'] = ""; $natent['descr'] = sprintf(gettext('Auto created rule for localhost to %1$s'),$ifdesc2); $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['staticnatport'] = false; $natent['natport'] = "1024:65535"; $a_out[] = $natent; /* PPTP subnet */ if (($config['pptpd']['mode'] == "server") && is_private_ip($config['pptpd']['remoteip'])) { $pptp_size = empty($config['pptpd']['n_pptp_units']) ? 16 : $config['pptpd']['n_pptp_units']; $pptptopip = $pptp_size - 1; $pptp_subnets = ip_range_to_subnet_array($config['pptpd']['remoteip'], long2ip32(ip2long($config['pptpd']['remoteip'])+$pptptopip)); foreach ($pptp_subnets as $pptpsn) { $natent = array(); $natent['source']['network'] = $pptpsn; $natent['sourceport'] = ""; $natent['descr'] = gettext("Auto created rule for PPTP server"); $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; } } /* PPPoE subnet */ if (is_pppoe_server_enabled() && have_ruleint_access("pppoe")) { foreach ($config['pppoes']['pppoe'] as $pppoes) { if (($pppoes['mode'] == "server") && is_ipaddr($pppoes['localip'])) { if($pppoes['pppoe_subnet'] <> "") $ossubnet = $pppoes['pppoe_subnet']; else $ossubnet = "32"; $osn = gen_subnet($pppoes['localip'], $ossubnet); $natent = array(); $natent['source']['network'] = "{$osn}/{$ossubnet}"; $natent['sourceport'] = ""; $natent['descr'] = gettext("Auto created rule for PPPoE server"); $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; } } } /* L2TP subnet */ if($config['l2tp']['mode'] == "server") { if (is_ipaddr($config['l2tp']['localip'])) { if($config['l2tp']['l2tp_subnet'] <> "") $ossubnet = $config['l2tp']['l2tp_subnet']; else $ossubnet = "32"; $osn = gen_subnet($config['l2tp']['localip'], $ossubnet); $natent = array(); $natent['source']['network'] = "{$osn}/{$ossubnet}"; $natent['sourceport'] = ""; $natent['descr'] = gettext("Auto created rule for L2TP server"); $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; } } /* add openvpn interfaces */ if($config['openvpn']['openvpn-server']) { foreach ($config['openvpn']['openvpn-server'] as $ovpnsrv) { $natent = array(); $natent['source']['network'] = $ovpnsrv['tunnel_network']; $natent['sourceport'] = ""; $natent['descr'] = gettext("Auto created rule for OpenVPN server"); $natent['target'] = ""; $natent['interface'] = $if2; $natent['destination']['any'] = true; $natent['natport'] = ""; $a_out[] = $natent; } } } } $savemsg = gettext("Default rules for each interface have been created."); } break; } 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 { /* 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']); 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."));?>
  >
          
  >           " . gettext("(AON - Advanced Outbound NAT)");?> ">  
 
 
 
 
 
   
">
  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']; ?> " . gettext("YES") . ""; else echo "
" . gettext("NO") . "
"; ?>
 
" height="17" type="image" width="17" border="0"> ">
')">"> " width="17" height="17" border="0">
" border="0">" border="0"> ">
" border="0">" onclick="return confirm('')">



" . "If manual outbound NAT is enabled, outbound NAT rules will not be " . "automatically generated and only the mappings you specify on this page " . "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 "); ?>