Commit 4a12e38c authored by Ad Schellevis's avatar Ad Schellevis

(legacy) refactor firewall_nat_out_edit.php

parent 577ecaf7
<?php <?php
/* /*
Copyright (C) 2014-2015 Deciso B.V. Copyright (C) 2014-2015 Deciso B.V.
Copyright (C) 2004 Scott Ullrich Copyright (C) 2004 Scott Ullrich
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>. Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution. documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once("pfsense-utils.inc"); require_once("pfsense-utils.inc");
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_nat_out.php');
if (!is_array($config['nat']['outbound'])) /**
$config['nat']['outbound'] = array(); * build array with interface options for this form
*/
function formInterfaces() {
global $config;
$interfaces = array();
foreach ( get_configured_interface_with_descr(false, true) as $if => $ifdesc)
$interfaces[$if] = $ifdesc;
if (!is_array($config['nat']['outbound']['rule'])) { if (isset($config['l2tp']['mode']) && $config['l2tp']['mode'] == "server")
$config['nat']['outbound']['rule'] = array(); $interfaces['l2tp'] = "L2TP VPN";
}
$a_out = &$config['nat']['outbound']['rule']; if (isset($config['pptpd']['mode']) && $config['pptpd']['mode'] == "server")
$interfaces['pptp'] = "PPTP VPN";
if (!is_array($config['aliases'])) { if (is_pppoe_server_enabled())
$config['aliases'] = array(); $interfaces['pppoe'] = "PPPoE VPN";
}
if (!is_array($config['aliases']['alias'])) {
$config['aliases']['alias'] = array();
}
$a_aliases = &$config['aliases']['alias'];
if (is_numericint($_GET['id'])) /* add ipsec interfaces */
$id = $_GET['id']; if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
if (isset($_POST['id']) && is_numericint($_POST['id'])) $interfaces["enc0"] = "IPsec";
$id = $_POST['id'];
if (is_numericint($_GET['after']) || $_GET['after'] == "-1") /* add openvpn/tun interfaces */
$after = $_GET['after']; if (isset($config['openvpn']['openvpn-server']) || isset($config['openvpn']['openvpn-client'])) {
if (isset($_POST['after']) && (is_numericint($_POST['after']) || $_POST['after'] == "-1")) $interfaces['openvpn'] = 'OpenVPN';
$after = $_POST['after']; }
return $interfaces;
}
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { /**
$id = $_GET['dup']; * return option array for valid translation networks
$after = $_GET['dup']; */
function formTranslateAddresses() {
global $config;
$retval = array();
// add this hosts ips
foreach ($config['interfaces'] as $intf => $intfdata) {
if (isset($intfdata['ipaddr']) && $intfdata['ipaddr'] != 'dhcp') {
$retval[$intfdata['ipaddr']] = (!empty($intfdata['descr']) ? $intfdata['descr'] : $intf ) . " " . gettext("address");
}
}
// add VIPs's
if (isset($config['virtualip']['vip'])) {
foreach ($config['virtualip']['vip'] as $sn) {
if (!isset($sn['noexpand'])) {
if ($sn['mode'] == "proxyarp" && $sn['type'] == "network") {
$start = ip2long32(gen_subnet($sn['subnet'], $sn['subnet_bits']));
$end = ip2long32(gen_subnet_max($sn['subnet'], $sn['subnet_bits']));
$len = $end - $start;
$retval[$sn['subnet'].'/'.$sn['subnet_bits']] = htmlspecialchars("Subnet: {$sn['subnet']}/{$sn['subnet_bits']} ({$sn['descr']})");
for ($i = 0; $i <= $len; $i++) {
$snip = long2ip32($start+$i);
$retval[$snip] = htmlspecialchars("{$snip} ({$sn['descr']})");
}
} else {
$retval[$sn['subnet']] = htmlspecialchars("{$sn['subnet']} ({$sn['descr']})");
}
}
}
}
// add Aliases
foreach (legacy_list_aliasses("network") as $alias) {
if ($alias['type'] == "host") {
$retval[$alias['name']] = $alias['name'];;
}
}
return $retval;
} }
if (isset($id) && $a_out[$id]) { if (!isset($config['nat']['outbound']['rule'])) {
if ( isset($a_out[$id]['created']) && is_array($a_out[$id]['created']) ) if (!isset($config['nat']['outbound'])) {
$pconfig['created'] = $a_out[$id]['created']; $config['nat']['outbound'] = array();
}
if ( isset($a_out[$id]['updated']) && is_array($a_out[$id]['updated']) ) $config['nat']['outbound']['rule'] = array();
$pconfig['updated'] = $a_out[$id]['updated'];
$pconfig['protocol'] = $a_out[$id]['protocol'];
list($pconfig['source'],$pconfig['source_subnet']) = explode('/', $a_out[$id]['source']['network']);
if (!is_numeric($pconfig['source_subnet']))
$pconfig['source_subnet'] = 32;
$pconfig['sourceport'] = $a_out[$id]['sourceport'];
address_to_pconfig($a_out[$id]['destination'], $pconfig['destination'],
$pconfig['destination_subnet'], $pconfig['destination_not'],
$none, $none);
$pconfig['dstport'] = $a_out[$id]['dstport'];
$pconfig['natport'] = $a_out[$id]['natport'];
$pconfig['target'] = $a_out[$id]['target'];
$pconfig['targetip'] = $a_out[$id]['targetip'];
$pconfig['targetip_subnet'] = $a_out[$id]['targetip_subnet'];
$pconfig['poolopts'] = $a_out[$id]['poolopts'];
$pconfig['interface'] = $a_out[$id]['interface'];
if (!$pconfig['interface']) {
$pconfig['interface'] = "wan";
}
$pconfig['descr'] = $a_out[$id]['descr'];
$pconfig['nonat'] = $a_out[$id]['nonat'];
$pconfig['disabled'] = isset($a_out[$id]['disabled']);
$pconfig['staticnatport'] = isset($a_out[$id]['staticnatport']);
$pconfig['nosync'] = isset($a_out[$id]['nosync']);
} else {
$pconfig['source_subnet'] = 24;
$pconfig['destination'] = "any";
$pconfig['destination_subnet'] = 24;
$pconfig['interface'] = "wan";
} }
$a_out = &$config['nat']['outbound']['rule'];
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) if ($_SERVER['REQUEST_METHOD'] === 'GET') {
unset($id); // input record id, if valid
if (isset($_GET['dup']) && isset($a_out[$_GET['dup']])) {
if ($_POST) { $configId = $_GET['dup'];
if ($_POST['destination_type'] == "any") { $after = $configId;
$_POST['destination'] = "any"; } elseif (isset($_GET['id']) && isset($a_out[$_GET['id']])) {
$_POST['destination_subnet'] = 24; $id = $_GET['id'];
} $configId = $id;
if ($_POST['source_type'] == "any") { }
$_POST['source'] = "any";
$_POST['source_subnet'] = 24; // init form data
} elseif ($_POST['source_type'] == "(self)") { $pconfig = array();
$_POST['source'] = "(self)"; // set defaults
$_POST['source_subnet'] = 24; $pconfig['source'] = 'any';
} $pconfig['source_subnet'] = 24;
$pconfig['destination'] = "any";
unset($input_errors); $pconfig['destination_subnet'] = 24;
$pconfig = $_POST; $pconfig['interface'] = "wan";
/* run through $_POST items encoding HTML entties so that the user
* cannot think he is slick and perform a XSS attack on the unwilling if (isset($configId)) {
*/ // load data from config
foreach ($_POST as $key => $value) { foreach (array('protocol','sourceport','dstport','natport','target','targetip'
$temp = str_replace(">", "", $value); ,'targetip_subnet','poolopts','interface','descr','nonat'
$newpost = htmlentities($temp); ,'disabled','staticnatport','nosync') as $fieldname) {
if($newpost <> $temp) if (isset($a_out[$configId][$fieldname])) {
$input_errors[] = sprintf(gettext("Invalid characters detected (%s). Please remove invalid characters and save again."),$temp); $pconfig[$fieldname] = $a_out[$configId][$fieldname];
} }
}
/* input validation */
$reqdfields = explode(" ", "interface protocol source source_subnet destination destination_subnet"); if (strpos($a_out[$configId]['source']['network'], "/") !== false) {
$reqdfieldsn = array(gettext("Interface"),gettext("Protocol"),gettext("Source"),gettext("Source bit count"),gettext("Destination"),gettext("Destination bit count")); list($pconfig['source'],$pconfig['source_subnet']) = explode('/', $a_out[$configId]['source']['network']);
} else {
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); $pconfig['source_subnet'] = $a_out[$configId]['source']['network'];
}
$protocol_uses_ports = in_array($_POST['protocol'], explode(" ", "any tcp udp tcp/udp"));
if (!is_numeric($pconfig['source_subnet']))
if ($_POST['source']) $pconfig['source_subnet'] = 32;
$_POST['source'] = trim($_POST['source']); address_to_pconfig($a_out[$configId]['destination'], $pconfig['destination'],
if ($_POST['destination']) $pconfig['destination_subnet'], $pconfig['destination_not'],
$_POST['destination'] = trim($_POST['destination']); $none, $none);
if ($_POST['targetip']) }
$_POST['targetip'] = trim($_POST['targetip']);
if ($_POST['sourceport']) // initialize unused elements
$_POST['sourceport'] = trim($_POST['sourceport']); foreach (array('protocol','sourceport','dstport','natport','target','targetip'
if ($_POST['dstport']) ,'targetip_subnet','poolopts','interface','descr','nonat'
$_POST['dstport'] = trim($_POST['dstport']); ,'disabled','staticnatport','nosync','source','source_subnet') as $fieldname) {
if ($_POST['natport']) if (!isset($pconfig[$fieldname])) {
$_POST['natport'] = trim($_POST['natport']); $pconfig[$fieldname] = null;
}
if($protocol_uses_ports && $_POST['sourceport'] <> "" && !is_portoralias($_POST['sourceport'])) }
$input_errors[] = gettext("You must supply either a valid port or port alias for the source port entry.");
if($protocol_uses_ports && $_POST['dstport'] <> "" && !is_portoralias($_POST['dstport'])) } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input_errors[] = gettext("You must supply either a valid port or port alias for the destination port entry."); $input_errors = array();
$pconfig = $_POST;
if($protocol_uses_ports && $_POST['natport'] <> "" && !is_port($_POST['natport']) && !isset($_POST['nonat'])) // input record id, if valid
$input_errors[] = gettext("You must supply a valid port for the NAT port entry."); if (isset($pconfig['id']) && isset($a_out[$pconfig['id']])) {
$id = $pconfig['id'];
if (($_POST['source_type'] != "any") && ($_POST['source_type'] != "(self)")) { }
if ($_POST['source'] && !is_ipaddroralias($_POST['source']) && $_POST['source'] <> "any") { if (isset($pconfig['after']) && isset($a_out[$pconfig['after']])) {
$input_errors[] = gettext("A valid source must be specified."); $after = $pconfig['after'];
} }
}
if ($_POST['source_subnet'] && !is_numericint($_POST['source_subnet'])) { /* input validation */
$input_errors[] = gettext("A valid source bit count must be specified."); foreach ($pconfig as $key => $value) {
} if(htmlentities($value) <> $value) {
if ($_POST['destination_type'] != "any") { $input_errors[] = sprintf(gettext("Invalid characters detected %s. Please remove invalid characters and save again."), htmlentities($value));
if ($_POST['destination'] && !is_ipaddroralias($_POST['destination'])) { }
$input_errors[] = gettext("A valid destination must be specified."); }
} $reqdfields = explode(" ", "interface protocol source source_subnet destination destination_subnet");
} $reqdfieldsn = array(gettext("Interface"),gettext("Protocol"),gettext("Source"),gettext("Source bit count"),gettext("Destination"),gettext("Destination bit count"));
if ($_POST['destination_subnet'] && !is_numericint($_POST['destination_subnet'])) {
$input_errors[] = gettext("A valid destination bit count must be specified."); do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors);
}
if ($_POST['destination_type'] == "any") { if (in_array($pconfig['protocol'], explode(" ", "any tcp udp tcp/udp"))) {
if ($_POST['destination_not']) { if(!empty($pconfig['sourceport']) && !is_portoralias($pconfig['sourceport']))
$input_errors[] = gettext("Negating destination address of \"any\" is invalid."); $input_errors[] = gettext("You must supply either a valid port or port alias for the source port entry.");
}
} if(!empty($pconfig['dstport']) && !is_portoralias($pconfig['dstport']))
$input_errors[] = gettext("You must supply either a valid port or port alias for the destination port entry.");
if ($_POST['target'] && !is_ipaddr($_POST['target']) && !is_subnet($_POST['target']) && !is_alias($_POST['target']) && !isset($_POST['nonat']) && !($_POST['target'] == "other-subnet")) {
$input_errors[] = gettext("A valid target IP address must be specified."); if(!empty($pconfig['natport']) && !is_port($pconfig['natport']) && empty($pconfig['nonat']))
} $input_errors[] = gettext("You must supply a valid port for the NAT port entry.");
}
if ($_POST['target'] == "other-subnet") {
if (!is_ipaddr($_POST['targetip'])) { if (!(in_array($pconfig['source'], array("any","self")) || is_ipaddroralias($pconfig['source']))) {
$input_errors[] = gettext("A valid target IP must be specified when using the 'Other Subnet' type."); $input_errors[] = gettext("A valid source must be specified.");
} }
if (!is_numericint($_POST['targetip_subnet'])) { if (!empty($pconfig['source_subnet']) && !is_numericint($pconfig['source_subnet'])) {
$input_errors[] = gettext("A valid target bit count must be specified when using the 'Other Subnet' type."); $input_errors[] = gettext("A valid source bit count must be specified.");
} }
} if (!(in_array($pconfig['destination'], array("any","self")) || is_ipaddroralias($pconfig['destination']))) {
$input_errors[] = gettext("A valid destination must be specified.");
/* Verify Pool Options */ }
$poolopts = ""; if (!empty($pconfig['destination_subnet']) && !is_numericint($pconfig['destination_subnet'])) {
if ($_POST['poolopts']) { $input_errors[] = gettext("A valid destination bit count must be specified.");
if (is_subnet($_POST['target']) || ($_POST['target'] == "other-subnet")) }
$poolopts = $_POST['poolopts']; if ($pconfig['destination'] == "any" && !empty($pconfig['destination_not'])) {
elseif (is_alias($_POST['target'])) { $input_errors[] = gettext("Negating destination address of \"any\" is invalid.");
if (substr($_POST['poolopts'], 0, 11) == "round-robin") }
$poolopts = $_POST['poolopts'];
else if (!is_ipaddr($pconfig['targetip']) && !is_subnet($pconfig['targetip']) && !is_alias($pconfig['targetip']) && empty($pconfig['nonat'])) {
$input_errors[] = gettext("Only Round Robin pool options may be chosen when selecting an alias."); $input_errors[] = gettext("A valid target IP address must be specified.");
} }
} /* Verify Pool Options */
if (!is_alias($pconfig['targetip']) && substr($pconfig['poolopts'], 0, 11) == "round-robin") {
/* if user has selected any as source, set it here */ $input_errors[] = gettext("Only Round Robin pool options may be chosen when selecting an alias.");
if($_POST['source_type'] == "any") { }
$osn = "any";
} else if($_POST['source_type'] == "(self)") { if (count($input_errors) == 0) {
$osn = "(self)"; $natent = array();
} else if(is_alias($_POST['source'])) { $natent['source'] = array();
$osn = $_POST['source']; $natent['destination'] = array();
} else { $natent['descr'] = $pconfig['descr'];
$osn = gen_subnet($_POST['source'], $_POST['source_subnet']) . "/" . $_POST['source_subnet']; $natent['interface'] = $pconfig['interface'];
} $natent['poolopts'] = $pconfig['poolopts'];
/* check for existing entries */ if ( isset($a_out[$id]['created']) && is_array($a_out[$id]['created']) ){
if ($_POST['destination_type'] == "any") { $natent['created'] = $a_out[$id]['created'];
$ext = "any"; }
} else if(is_alias($_POST['destination'])) {
$ext = $_POST['destination']; // target ip/net
} else { if (!array_key_exists($pconfig['targetip'], formTranslateAddresses())) {
$ext = gen_subnet($_POST['destination'], $_POST['destination_subnet']) . "/" . $_POST['destination_subnet']; // a bit vague behaviour in "target" and "targetip", if a custom net is given
} // the backend code wants target to be filled with "other-subnet".
// if any other known net is given, target is used to provide the actual address....
foreach ($a_out as $natent) { // -- can't remove this behaviour now without breaking old confid, so let's reimplement
if (isset($id) && ($a_out[$id]) && ($a_out[$id] === $natent)) { $natent['target'] = 'other-subnet';
continue; $natent['targetip'] = trim($pconfig['targetip']) ;
} $natent['targetip_subnet'] = $pconfig['targetip_subnet'] ;
} else {
if (!$natent['interface']) { $natent['target'] = $pconfig['targetip'] ;
$natent['interface'] == "wan"; }
}
}
// handle fields containing portnumbers
if (!$input_errors) { if (in_array($pconfig['protocol'], explode(" ", "any tcp udp tcp/udp"))) {
$natent = array(); if (isset($pconfig['staticnatport']) && !empty($pconfig['nonat'])) {
$natent['source']['network'] = $osn; $natent['staticnatport'] = true;
$natent['sourceport'] = ($protocol_uses_ports) ? $_POST['sourceport'] : ""; }
$natent['descr'] = $_POST['descr']; $natent['sourceport'] = trim($pconfig['sourceport']);
$natent['target'] = (!isset($_POST['nonat'])) ? $_POST['target'] : ""; if (!empty($pconfig['natport']) && empty($pconfig['nonat'])) {
$natent['targetip'] = (!isset($_POST['nonat'])) ? $_POST['targetip'] : ""; $natent['natport'] = trim($pconfig['natport']);
$natent['targetip_subnet'] = (!isset($_POST['nonat'])) ? $_POST['targetip_subnet'] : ""; }
$natent['interface'] = $_POST['interface']; if (!empty($pconfig['dstport'])) {
$natent['poolopts'] = $poolopts; $natent['dstport'] = trim($pconfig['dstport']);
}
/* static-port */ } else {
if(isset($_POST['staticnatport']) && $protocol_uses_ports && !isset($_POST['nonat'])) { $natent['sourceport'] = "";
$natent['staticnatport'] = true; }
} else {
unset($natent['staticnatport']); if (!empty($pconfig['protocol']) && $pconfig['protocol'] != "any") {
} $natent['protocol'] = $pconfig['protocol'];
}
if(isset($_POST['disabled'])) {
$natent['disabled'] = true; /* parse source entry */
} else { if($pconfig['source'] == "any") {
unset($natent['disabled']); $natent['source']['network'] = "any";
} } else if($pconfig['source'] == "(self)") {
$natent['source']['network'] = "(self)";
/* if user has selected not nat, set it here */ } else if(is_alias($pconfig['source'])) {
if(isset($_POST['nonat'])) { $natent['source']['network'] = trim($pconfig['source']);
$natent['nonat'] = true; } else {
} else { $natent['source']['network'] = gen_subnet(trim($pconfig['source']), $pconfig['source_subnet']) . "/" . $pconfig['source_subnet'];
unset($natent['nonat']); }
}
// destination address
if ($_POST['protocol'] && $_POST['protocol'] != "any") if ($pconfig['destination'] == "any") {
$natent['protocol'] = $_POST['protocol']; $natent['destination']['any'] = true;
else } elseif (is_alias($pconfig['destination'])){
unset($natent['protocol']); $natent['destination']['address'] = trim($pconfig['destination']) ;
} else {
if ($ext == "any") { $natent['destination']['address'] = gen_subnet(trim($pconfig['destination']), $pconfig['destination_subnet']) . "/" . $pconfig['destination_subnet'];;
$natent['destination']['any'] = true; }
} else {
$natent['destination']['address'] = $ext; // boolean fields
} if(!empty($pconfig['disabled'])) {
if($_POST['natport'] != "" && $protocol_uses_ports && !isset($_POST['nonat'])) { $natent['disabled'] = true;
$natent['natport'] = $_POST['natport']; }
} else { if(!empty($pconfig['nonat'])) {
unset($natent['natport']); $natent['nonat'] = true;
} }
if($_POST['dstport'] != "" && $protocol_uses_ports) {
$natent['dstport'] = $_POST['dstport']; if(isset($pconfig['nosync'] ) && $pconfig['nosync'] == "yes") {
} else { $natent['nosync'] = true;
unset($natent['dstport']); }
} if (isset($pconfig['destination_not']) && $pconfig['destination'] != "any") {
$natent['destination']['not'] = true;
if($_POST['nosync'] == "yes") { }
$natent['nosync'] = true;
} else { $natent['updated'] = make_config_revision_entry();
unset($natent['nosync']); if (isset($id)) {
} $a_out[$id] = $natent;
} else {
if (isset($_POST['destination_not']) && $ext != "any") { $natent['created'] = make_config_revision_entry();
$natent['destination']['not'] = true; if (isset($after)) {
} array_splice($a_out, $after+1, 0, array($natent));
} else {
if ( isset($a_out[$id]['created']) && is_array($a_out[$id]['created']) ) $a_out[] = $natent;
$natent['created'] = $a_out[$id]['created']; }
}
$natent['updated'] = make_config_revision_entry(); if (write_config()) {
mark_subsystem_dirty('natconf');
if (isset($id) && $a_out[$id]) { }
$a_out[$id] = $natent; header("Location: firewall_nat_out.php");
} else { exit;
$natent['created'] = make_config_revision_entry(); }
if (is_numeric($after)) {
array_splice($a_out, $after+1, 0, array($natent));
} else {
$a_out[] = $natent;
}
}
if (write_config())
mark_subsystem_dirty('natconf');
header("Location: firewall_nat_out.php");
exit;
}
} }
legacy_html_escape_form_data($pconfig);
$pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("Outbound"),gettext("Edit")); $pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("Outbound"),gettext("Edit"));
$closehead = false; $closehead = false;
include("head.inc"); include("head.inc");
?> ?>
<script type="text/javascript" src="/javascript/suggestions.js"></script>
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
<script type="text/javascript">
//<![CDATA[
var portsenabled = 1;
function staticportchange() {
if(document.iform.staticnatport.checked) {
document.iform.natport.value = "";
document.iform.natport.disabled = 1;
} else {
document.iform.natport.disabled = 0;
}
}
function typesel_change() {
switch (document.iform.destination_type.selectedIndex) {
case 1: // network
document.iform.destination.disabled = 0;
document.iform.destination_subnet.disabled = 0;
jQuery('.selectpicker').selectpicker('refresh');
break;
default:
document.iform.destination.value = "";
document.iform.destination.disabled = 1;
document.iform.destination_subnet.value = "24";
document.iform.destination_subnet.disabled = 1;
jQuery('.selectpicker').selectpicker('refresh');
break;
}
}
function sourcesel_change() {
switch (document.iform.source_type.selectedIndex) {
case 2: // network
document.iform.source.disabled = 0;
document.iform.source_subnet.disabled = 0;
jQuery('.selectpicker').selectpicker('refresh');
break;
default:
document.iform.source.value = "";
document.iform.source.disabled = 1;
document.iform.source_subnet.value = "24";
document.iform.source_subnet.disabled = 1;
jQuery('.selectpicker').selectpicker('refresh');
break;
}
}
function nonat_change() {
if (document.iform.nonat.checked) {
document.getElementById("transtable").style.display = 'none';
} else {
document.getElementById("transtable").style.display = '';
}
}
function proto_change() {
if (document.iform.protocol.selectedIndex >= 0 && document.iform.protocol.selectedIndex <= 3) {
portsenabled = 1;
} else {
portsenabled = 0;
}
if (portsenabled) {
document.getElementById("sport_tr").style.display = '';
document.getElementById("dport_tr").style.display = '';
document.getElementById("tport_tr").style.display = '';
document.getElementById("tporttext_tr").style.display = '';
document.getElementById("tportstatic_tr").style.display = '';
} else {
document.getElementById("sport_tr").style.display = 'none';
document.getElementById("dport_tr").style.display = 'none';
document.getElementById("tport_tr").style.display = 'none';
document.getElementById("tporttext_tr").style.display = 'none';
document.getElementById("tportstatic_tr").style.display = 'none';
}
}
function poolopts_change() {
if (jQuery('#target option:selected').text().trim().substring(0,4) == "Host") {
jQuery('#poolopts_tr').css('display','');
jQuery('#target_network').css('display','none');
} else if (jQuery('#target option:selected').text().trim().substring(0,6) == "Subnet") {
jQuery('#poolopts_tr').css('display','');
jQuery('#target_network').css('display','none');
} else if (jQuery('#target option:selected').text().trim().substring(0,5) == "Other") {
jQuery('#poolopts_tr').css('display','');
jQuery('#target_network').css('display','');
} else {
jQuery('#poolopts').prop('selectedIndex',0);
jQuery('#poolopts_tr').css('display','none');
jQuery('#target_network').css('display','none');
jQuery('#targetip').val('');
jQuery('#targetip_subnet').val('0');
}
}
//]]>
</script>
</head> </head>
<body> <body>
<?php include("fbegin.inc"); ?> <script type="text/javascript">
$( document ).ready(function() {
// select / input combination, link behaviour
// when the data attribute "data-other" is selected, display related input item(s)
// push changes from input back to selected option value
$('[for!=""][for]').each(function(){
var refObj = $("#"+$(this).attr("for"));
if (refObj.is("select")) {
// connect on change event to select box (show/hide)
refObj.change(function(){
if ($(this).find(":selected").attr("data-other") == "true") {
// show related controls
$('*[for="'+$(this).attr("id")+'"]').each(function(){
if ($(this).hasClass("selectpicker")) {
$(this).selectpicker('show');
} else {
$(this).removeClass("hidden");
}
});
} else {
// hide related controls
$('*[for="'+$(this).attr("id")+'"]').each(function(){
if ($(this).hasClass("selectpicker")) {
$(this).selectpicker('hide');
} else {
$(this).addClass("hidden");
}
});
}
});
// update initial
refObj.change();
// connect on change to input to save data to selector
if ($(this).attr("name") == undefined) {
$(this).change(function(){
var otherOpt = $('#'+$(this).attr('for')+' > option[data-other="true"]') ;
otherOpt.attr("value",$(this).val());
});
}
}
});
});
</script>
<section class="page-content-main"> <?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row">
<div class="row"> <?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?> <section class="col-xs-12">
<div class="content-box">
<section class="col-xs-12"> <form action="firewall_nat_out_edit.php" method="post" name="iform" id="iform">
<table class="table table-striped">
<div class="content-box"> <tr>
<td colspan="2">
<form action="firewall_nat_out_edit.php" method="post" name="iform" id="iform"> <table>
<tr>
<table class="table table-striped table-sort"> <td><?=gettext("Edit Advanced Outbound NAT entry");?></td>
<td colspan="2" align="right">
<tr> <small><?=gettext("full help"); ?> </small>
<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Advanced Outbound NAT entry");?></td> <i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_opnvpn_server" type="button"></i></a>
</tr> </td>
<tr> </tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled");?></td> </table>
<td width="78%" class="vtable"> </td>
<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> /> </tr>
<strong><?=gettext("Disable this rule");?></strong><br /> <tr>
<span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list.");?></span> <td><a id="help_for_disabled" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Disabled"); ?></td>
</td> <td>
</tr> <input name="disabled" type="checkbox" id="disabled" value="yes" <?= !empty($pconfig['disabled']) ? "checked=\"checked\"" : ""; ?> />
<tr> <div class="hidden" for="help_for_disabled">
<td width="22%" valign="top" class="vncell"><?=gettext("Do not NAT");?></td> <strong><?=gettext("Disable this rule"); ?></strong><br />
<td width="78%" class="vtable"> <?=gettext("Set this option to disable this rule without removing it from the list."); ?>
<input type="checkbox" name="nonat" id="nonat" onclick="nonat_change();" <?php if(isset($pconfig['nonat'])) echo " checked=\"checked\""; ?> /> </div>
<span class="vexpl"><?=gettext("Enabling this option will disable NAT for traffic matching this rule and stop processing Outbound NAT rules.");?> </td>
<br /><?=gettext("Hint: in most cases, you won't use this option.");?></span> </tr>
</td> <tr>
</tr> <td><a id="help_for_do_not_nat" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Do not NAT");?></td>
<tr> <td width="78%" class="vtable">
<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td> <input type="checkbox" name="nonat" <?=!empty($pconfig['nonat']) ? " checked=\"checked\"" : ""; ?> />
<td width="78%" class="vtable"> <div class="hidden" for="help_for_do_not_nat">
<select name="interface" class="selectpicker"> <?=gettext("Enabling this option will disable NAT for traffic matching this rule and stop processing Outbound NAT rules.");?><br />
<?php <?=gettext("Hint: in most cases, you won't use this option.");?>
$iflist = get_configured_interface_with_descr(false, true); </div>
foreach ($iflist as $if => $ifdesc) </td>
if(have_ruleint_access($if)) </tr>
$interfaces[$if] = $ifdesc; <tr>
<td><a id="help_for_interface" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Interface"); ?></td>
if ($config['l2tp']['mode'] == "server") <td>
if(have_ruleint_access("l2tp")) <div class="input-group">
$interfaces['l2tp'] = "L2TP VPN"; <select name="interface" class="selectpicker" data-width="auto" data-live-search="true" onchange="dst_change(this.value,iface_old,document.iform.dsttype.value);iface_old = document.iform.interface.value;typesel_change();">
<?php
if ($config['pptpd']['mode'] == "server") foreach (formInterfaces() as $iface => $ifacename): ?>
if(have_ruleint_access("pptp")) <option value="<?=$iface;?>" <?= $iface == $pconfig['interface'] ? "selected=\"selected\"" : ""; ?>>
$interfaces['pptp'] = "PPTP VPN"; <?=htmlspecialchars($ifacename);?>
</option>
if (is_pppoe_server_enabled() && have_ruleint_access("pppoe")) <?php endforeach; ?>
$interfaces['pppoe'] = "PPPoE VPN"; </select>
</div>
/* add ipsec interfaces */ <div class="hidden" for="help_for_interface">
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) <?=gettext("Choose which interface this rule applies to"); ?>.<br />
if(have_ruleint_access("enc0")) <?=gettext("Hint: in most cases, you'll want to use WAN here"); ?>
$interfaces["enc0"] = "IPsec"; </div>
</td>
/* add openvpn/tun interfaces */ </tr>
if (isset($config['openvpn']['openvpn-server']) || isset($config['openvpn']['openvpn-client'])) { <tr>
$interfaces['openvpn'] = 'OpenVPN'; <td><a id="help_for_proto" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Protocol"); ?></td>
} <td>
<div class="input-group">
foreach ($interfaces as $iface => $ifacename): <select id="proto" name="protocol" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
?> <?php foreach (explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IPV6 IGMP PIM OSPF") as $proto):
<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>> ?>
<?=htmlspecialchars($ifacename);?> <option value="<?=strtolower($proto);?>" <?= strtolower($proto) == $pconfig['protocol'] ? "selected=\"selected\"" : ""; ?>>
</option> <?=$proto;?>
<?php </option>
endforeach; <?php endforeach; ?>
?> </select>
</select><br /> </div>
<span class="vexpl"><?=gettext("Choose which interface this rule applies to.");?><br /> <div class="hidden" for="help_for_proto">
<?=gettext("Hint: in most cases, you'll want to use WAN here.");?> <?=gettext("Choose which IP protocol " ."this rule should match."); ?><br/>
</span> <?=gettext("Hint: in most cases, you should specify"); ?> <em><?=gettext("TCP"); ?></em> &nbsp;<?=gettext("here."); ?>
</td> </div>
</tr> </td>
<tr> </tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td> <tr>
<td width="78%" class="vtable"> <td><a id="help_for_source" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Source"); ?></td>
<select name="protocol" class="selectpicker" onchange="proto_change();"> <td>
<?php <table class="table table-condensed">
$protocols = explode(" ", "any TCP UDP TCP/UDP ICMP ESP AH GRE IPV6 IGMP carp pfsync"); <tr>
foreach ($protocols as $proto): <td>
?> <select name="source" id="source" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['protocol']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($proto);?></option> <option data-other=true value="<?=$pconfig['source'];?>" <?=!is_alias($pconfig['source']) && !in_array($pconfig['source'],array('(self)','any')) ? "selected=\"selected\"" : "";?>><?=gettext("Single host or Network"); ?></option>
<?php <option value="any" <?=$pconfig['source'] == "any" ? "selected=\"selected\"" : ""; ?>><?=gettext("any");?></option>
endforeach; <option value="(self)" <?=$pconfig['source'] == "(self)" ? "selected=\"selected\"" : ""; ?>><?=gettext("This Firewall (self)");?></option>
?> <optgroup label="<?=gettext("aliasses");?>">
</select><br /> <?php foreach (legacy_list_aliasses("network") as $alias):
<span class="vexpl"><?=gettext("Choose which protocol this rule should match.");?><br /> ?>
<?php <option value="<?=$alias['name'];?>" <?=$alias['name'] == $pconfig['source'] ? "selected=\"selected\"" : "";?>><?=htmlspecialchars($alias['name']);?></option>
printf(gettext("Hint: in most cases, you should specify %s any %s here."),"<em>","</em>&nbsp;"); <?php endforeach; ?>
?> </optgroup>
</span> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td> <td>
<td width="78%" class="vtable"> <div class="input-group">
<table border="0" cellspacing="1" cellpadding="1" summary="source"> <!-- updates to "other" option in source -->
<tr> <input type="text" for="source" value="<?=$pconfig['source'];?>" aria-label="<?=gettext("Source address");?>"/>
<td><?=gettext("Type:");?>&nbsp;&nbsp;</td> <select name="source_subnet" class="selectpicker" data-size="5" id="srcmask" data-width="auto" for="source" >
<td> <?php for ($i = 32; $i > 0; $i--): ?>
<select name="source_type" class="selectpicker" onchange="sourcesel_change()"> <option value="<?=$i;?>" <?= $i == $pconfig['source_subnet'] ? "selected=\"selected\"" : ""; ?>><?=$i;?></option>
<option value="any" <?php if ($pconfig['source'] == "any") echo "selected=\"selected\""; ?>><?=gettext("any");?></option> <?php endfor; ?>
<option value="(self)" <?PHP if ($pconfig['source'] == "(self)") echo "selected=\"selected\""; ?>><?=gettext("This Firewall (self)");?></option> </select>
<option value="network" <?php if (($pconfig['source'] != "any") && ($pconfig['source'] != "(self)")) echo "selected=\"selected\""; ?>><?=gettext("Network");?></option> </div>
</select> </td>
</td> </tr>
</tr> </table>
<tr> <div class="hidden" for="help_for_source">
<td><?=gettext("Address:");?>&nbsp;&nbsp;</td> <?=gettext("Enter the source network for the outbound NAT mapping.");?>
<td> </div>
<table> </td>
<tr> </tr>
<td width="348px"> <tr>
<input name="source" type="text" autocomplete="off" class="formfldalias" id="source" size="20" value="<?=htmlspecialchars($pconfig['source']);?>" /> <td><a id="help_for_src_port" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Source port:");?></td>
</td> <td>
<td> <input name="sourceport" type="text" value="<?=$pconfig['sourceport'];?>" />
<select name="source_subnet" class="selectpicker" id="source_subnet" data-width="auto"> <div class="hidden" for="help_for_src_port">
<?php <?=gettext("(leave blank for any)");?>
for ($i = 32; $i >= 0; $i--): </div>
?> </td>
<option value="<?=$i;?>"<?php if ($i == $pconfig['source_subnet']) echo " selected=\"selected\""; ?>><?=$i;?></option> </tr>
<?php <tr>
endfor; <td> <a id="help_for_dst_invert" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Destination") . " / ".gettext("Invert");?> </td>
?> <td>
</select> <input name="destination_not" type="checkbox" value="yes" <?= !empty($pconfig['destination_not']) ? "checked=\"checked\"" : "";?> />
</td> <div class="hidden" for="help_for_dst_invert">
</tr> <?=gettext("Use this option to invert the sense of the match."); ?>
</table> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>&nbsp;</td> <td><a id="help_for_destination" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Destination"); ?></td>
<td> <td>
<span class="vexpl"><?=gettext("Enter the source network for the outbound NAT mapping.");?></span> <table class="table table-condensed">
</td> <tr>
</tr> <td>
<tr name="sport_tr" id="sport_tr"> <select name="destination" id="destination" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
<td><?=gettext("Source port:");?>&nbsp;&nbsp;</td> <option data-other=true value="<?=$pconfig['destination'];?>" <?=!is_alias($pconfig['destination']) && $pconfig['destination'] != 'any' ? "selected=\"selected\"" : "";?>><?=gettext("Single host or Network"); ?></option>
<td> <option value="any" <?=$pconfig['destination'] == "any" ? "selected=\"selected\"" : ""; ?>><?=gettext("any");?></option>
<input name="sourceport" type="text" autocomplete="off" class="formfldalias" id="sourceport" size="5" value="<?=htmlspecialchars($pconfig['sourceport']);?>" /> <optgroup label="<?=gettext("aliasses");?>">
<?=gettext("(leave blank for any)");?> <?php foreach (legacy_list_aliasses("network") as $alias):
</td> ?>
</tr> <option value="<?=$alias['name'];?>" <?=$alias['name'] == $pconfig['destination'] ? "selected=\"selected\"" : "";?>><?=htmlspecialchars($alias['name']);?></option>
</table> <?php endforeach; ?>
</td> </optgroup>
</tr> </select>
<tr> </td>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td> </tr>
<td width="78%" class="vtable"> <tr>
<input name="destination_not" type="checkbox" id="destination_not" value="yes" <?php if ($pconfig['destination_not']) echo "checked=\"checked\""; ?> /> <td>
<strong><?=gettext("not");?></strong><br /> <div class="input-group">
<?=gettext("Use this option to invert the sense of the match.");?><br /> <!-- updates to "other" option in source -->
<br /> <input type="text" for="destination" value="<?=$pconfig['destination'];?>" aria-label="<?=gettext("Destination address");?>"/>
<table border="0" cellspacing="1" cellpadding="1" summary="destination"> <select name="destination_subnet" class="selectpicker" data-size="5" data-width="auto" for="destination" >
<tr> <?php for ($i = 32; $i > 0; $i--): ?>
<td><?=gettext("Type:");?>&nbsp;&nbsp;</td> <option value="<?=$i;?>" <?= $i == $pconfig['destination_subnet'] ? "selected=\"selected\"" : ""; ?>><?=$i;?></option>
<td> <?php endfor; ?>
<select name="destination_type" class="selectpicker" onchange="typesel_change()"> </select>
<option value="any"<?php if ($pconfig['destination'] == "any") echo " selected=\"selected\""; ?>> </div>
<?=gettext("any");?> </td>
</option> </tr>
<option value="network"<?php if ($pconfig['destination'] != "any") echo " selected=\"selected\""; ?>> </table>
<?=gettext("Network");?> <div class="hidden" for="help_for_destination">
</option> <?=gettext("Enter the source network for the outbound NAT mapping.");?>
</select> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><?=gettext("Address:");?>&nbsp;&nbsp;</td> <td><a id="help_for_dstport" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Destination port:");?></td>
<td> <td>
<table> <input name="dstport" type="text" value="<?=$pconfig['dstport'];?>" />
<tr> <div class="hidden" for="help_for_dstport">
<td width="348px"> <?=gettext("(leave blank for any)");?>
<input name="destination" type="text" autocomplete="off" class="formfldalias" id="destination" size="20" value="<?=htmlspecialchars($pconfig['destination']);?>" /> </div>
</td> </td>
<td> </tr>
<select name="destination_subnet" class="selectpicker" id="destination_subnet" data-width="auto"> <tr>
<?php <td><a id="help_for_target" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Translation"); ?></td>
for ($i = 32; $i >= 0; $i--): <td>
?> <table class="table table-condensed">
<option value="<?=$i;?>"<?php if ($i == $pconfig['destination_subnet']) echo " selected=\"selected\""; ?>><?=$i;?></option> <tr>
<?php <td>
endfor; <select name="targetip" id="targetip" class="selectpicker" data-live-search="true" data-size="5" data-width="auto">
?> <option data-other=true value="<?=$pconfig['targetip'];?>" <?= !empty($pconfig['target']) && !array_key_exists($pconfig['targetip'], formTranslateAddresses() ) ? "selected=\"selected\"" : "";?>><?=gettext("Single host or Network"); ?></option>
</select> <? foreach (formTranslateAddresses() as $optKey => $optValue):
</td> ?>
</tr> <option value="<?=$optKey;?>" <?= $pconfig['target'] == $optKey ? "selected=\"selected\"" : ""; ?>>
</table> <?=$optValue;?>
</td> </option>
</tr> <? endforeach;
<tr> ?>
<td>&nbsp;</td> </select>
<td> </td>
<span class="vexpl"><?=gettext("Enter the destination network for the outbound NAT mapping.");?></span> </tr>
</td> <tr>
</tr> <td>
<tr name="dport_tr" id="dport_tr"> <div class="input-group">
<td><?=gettext("Destination port:");?>&nbsp;&nbsp;</td> <!-- updates to "other" option in source -->
<td> <input type="text" for="targetip" value="<?=$pconfig['targetip'];?>" aria-label="<?=gettext("Translation address");?>"/>
<input name="dstport" type="text" autocomplete="off" class="formfldalias" id="dstport" size="5" value="<?=htmlspecialchars($pconfig['dstport']);?>" /> <select name="targetip_subnet" class="selectpicker" data-size="5" data-width="auto" for="destination" >
<?=gettext("(leave blank for any)");?> <?php for ($i = 32; $i > 0; $i--): ?>
</td> <option value="<?=$i;?>" <?= $i == $pconfig['targetip_subnet'] ? "selected=\"selected\"" : ""; ?>><?=$i;?></option>
</tr> <?php endfor; ?>
</table> </select>
</td> </div>
</tr> </td>
<tr name="transtable" id="transtable"> </tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Translation");?></td> </table>
<td width="78%" class="vtable"> <div class="hidden" for="help_for_target">
<table border="0" cellspacing="1" cellpadding="1" summary="translation"> <?=gettext("Packets matching this rule will be mapped to the IP address given here.");?><br />
<tr> <?=gettext("If you want this rule to apply to another IP address rather than the IP address of the interface chosen above, ".
<td><?=gettext("Address:");?>&nbsp;&nbsp;</td> "select it here (you will need to define ");?>
<td> <a href="firewall_virtual_ip.php"><?=gettext("Virtual IP");?></a>
<select name="target" class="selectpicker" id="target" onchange="poolopts_change();"> <?=gettext("addresses on the interface first).");?>
<option value=""<?php if (!$pconfig['target']) echo " selected=\"selected\""; ?>> </div>
<?=gettext("Interface address");?> </td>
</option> </tr>
<?php <tr>
if (is_array($config['virtualip']['vip'])): <td><a id="help_for_poolopts" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Pool Options:");?></td>
foreach ($config['virtualip']['vip'] as $sn): <td>
if (isset($sn['noexpand'])) <select name="poolopts" class="selectpicker">
continue; <option value="" <?=empty($pconfig['poolopts']) ? "selected=\"selected\"" : ""; ?>>
if ($sn['mode'] == "proxyarp" && $sn['type'] == "network"): <?=gettext("Default");?>
$start = ip2long32(gen_subnet($sn['subnet'], $sn['subnet_bits'])); </option>
$end = ip2long32(gen_subnet_max($sn['subnet'], $sn['subnet_bits'])); <option value="round-robin" <?=$pconfig['poolopts'] == "round-robin" ? "selected=\"selected\"" : ""; ?>>
$len = $end - $start; <?=gettext("Round Robin");?>
?> </option>
<option value="<?=$sn['subnet'].'/'.$sn['subnet_bits'];?>" <?php if ($sn['subnet'].'/'.$sn['subnet_bits'] == $pconfig['target']) echo "selected=\"selected\""; ?>> <option value="round-robin sticky-address" <?=$pconfig['poolopts'] == "round-robin sticky-address" ? "selected=\"selected\"" : ""; ?>>
<?=htmlspecialchars("Subnet: {$sn['subnet']}/{$sn['subnet_bits']} ({$sn['descr']})");?> <?=gettext("Round Robin with Sticky Address");?>
</option> </option>
<?php <option value="random" <?=$pconfig['poolopts'] == "random" ? "selected=\"selected\"" : ""; ?>>
for ($i = 0; $i <= $len; $i++): <?=gettext("Random");?>
$snip = long2ip32($start+$i); </option>
?> <option value="random sticky-address" <?=$pconfig['poolopts'] == "random sticky-address" ? "selected=\"selected\"" : ""; ?>>
<option value="<?=$snip;?>" <?php if ($snip == $pconfig['target']) echo "selected"; ?>> <?=gettext("Random with Sticky Address");?>
<?=htmlspecialchars("{$snip} ({$sn['descr']})");?> </option>
</option> <option value="source-hash" <?=$pconfig['poolopts'] == "source-hash" ? "selected=\"selected\"" : ""; ?>>
<?php <?=gettext("Source Hash");?>
endfor; </option>
?> <option value="bitmask" <?=$pconfig['poolopts'] == "bitmask" ? "selected=\"selected\"" : ""; ?>>
<?php <?=gettext("Bitmask");?>
else: </option>
?> </select>
<option value="<?=$sn['subnet'];?>" <?php if ($sn['subnet'] == $pconfig['target']) echo "selected=\"selected\""; ?>> <div class="hidden" for="help_for_poolopts">
<?=htmlspecialchars("{$sn['subnet']} ({$sn['descr']})");?> <?=gettext("Only Round Robin types work with Host Aliases. Any type can be used with a Subnet.");?><br />
</option> * <?=gettext("Round Robin: Loops through the translation addresses.");?><br />
<?php * <?=gettext("Random: Selects an address from the translation address pool at random.");?><br />
endif; * <?=gettext("Source Hash: Uses a hash of the source address to determine the translation address, ensuring that the redirection address is always the same for a given source.");?><br />
endforeach; * <?=gettext("Bitmask: Applies the subnet mask and keeps the last portion identical; 10.0.1.50 -&gt; x.x.x.50.");?><br />
endif; * <?=gettext("Sticky Address: The Sticky Address option can be used with the Random and Round Robin pool types to ensure that a particular source address is always mapped to the same translation address.");?><br />
foreach ($a_aliases as $alias): </div>
if ($alias['type'] != "host") </td>
continue; </tr>
?> <tr>
<option value="<?=$alias['name'];?>" <?php if ($alias['name'] == $pconfig['target']) echo "selected=\"selected\""; ?>> <td><a id="help_for_natport" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Translation") . " / " .gettext("port:");?></td>
<?=htmlspecialchars("Host Alias: {$alias['name']} ({$alias['descr']})");?> <td>
</option> <input name="natport" type="text" value="<?=$pconfig['natport'];?>" />
<?php <div class="hidden" for="help_for_natport">
endforeach; <?=gettext("Enter the source port for the outbound NAT mapping.");?>
?> </div>
<option value="other-subnet"<?php if($pconfig['target'] == "other-subnet") echo " selected=\"selected\""; ?>> </td>
<?=gettext("Other Subnet (Enter Below)");?> </tr>
</option> <tr>
</select> <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Static-port:");?></td>
</td> <td>
</tr> <input name="staticnatport" type="checkbox" <?=!empty($pconfig['staticnatport']) ? " checked=\"checked\"" : "";?> >
</td>
<tr id="target_network"> </tr>
<td><?=gettext("Other Subnet:");?>&nbsp;&nbsp;</td> <tr>
<td> <td><a id="help_for_nosync" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("No XMLRPC Sync"); ?></td>
<input name="targetip" type="text" class="formfld unknown" id="targetip" size="20" value="<?=htmlspecialchars($pconfig['targetip']);?>" />/ <td>
<select name="targetip_subnet" class="selectpicker" id="targetip_subnet"> <input type="checkbox" value="yes" name="nosync" <?=!empty($pconfig['nosync']) ? "checked=\"checked\"" :"";?> />
<?php <div class="hidden" for="help_for_nosync">
for ($i = 32; $i >= 0; $i--): <?=gettext("Hint: This prevents the rule on Master from automatically syncing to other CARP members. This does NOT prevent the rule from being overwritten on Slave.");?>
?> </div>
<option value="<?=$i;?>"<?php if ($i == $pconfig['targetip_subnet']) echo " selected=\"selected\""; ?>><?=$i;?></option> </td>
<?php </tr>
endfor; <tr>
?> <td><a id="help_for_descr" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("Description"); ?></td>
</select> <td>
</td> <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
</tr> <div class="hidden" for="help_for_descr">
<?=gettext("You may enter a description here " ."for your reference (not parsed)."); ?>
<tr> </div>
<td>&nbsp;</td> </tr>
<td> <?php
<span class="vexpl"><?=gettext("Packets matching this rule will be mapped to the IP address given here.");?><br /> $has_created_time = (isset($a_out[$id]['created']) && is_array($a_out[$id]['created']));
<?=gettext("If you want this rule to apply to another IP address rather than the IP address of the interface chosen above, ". $has_updated_time = (isset($a_out[$id]['updated']) && is_array($a_out[$id]['updated']));
"select it here (you will need to define ");?> if ($has_created_time || $has_updated_time):
<a href="firewall_virtual_ip.php"><?=gettext("Virtual IP");?></a> ?>
<?=gettext("addresses on the interface first).");?> <tr>
</span><br /> <td colspan="2">&nbsp;</td>
</td> </tr>
</tr> <tr>
<tr id="poolopts_tr"> <td colspan="2"><?=gettext("Rule Information");?></td>
<td valign="top">Pool Options</td> </tr>
<td> <?php
<select name="poolopts" id="poolopts" class="selectpicker"> if ($has_created_time):
<option value="" <?php if ($pconfig['poolopts'] == "") echo "selected=\"selected\""; ?>> ?>
<?=htmlspecialchars("Default");?> <tr>
</option> <td><?=gettext("Created");?></td>
<option value="round-robin" <?php if ($pconfig['poolopts'] == "round-robin") echo "selected=\"selected\""; ?>> <td>
<?=htmlspecialchars("Round Robin");?> <?= date(gettext("n/j/y H:i:s"), $a_out[$id]['created']['time']) ?> <?= gettext("by") ?> <strong><?= $a_out[$id]['created']['username'] ?></strong>
</option> </td>
<option value="round-robin sticky-address" <?php if ($pconfig['poolopts'] == "round-robin sticky-address") echo "selected=\"selected\""; ?>> </tr>
<?=htmlspecialchars("Round Robin with Sticky Address");?> <?php
</option> endif;
<option value="random" <?php if ($pconfig['poolopts'] == "random") echo "selected=\"selected\""; ?>> if ($has_updated_time):
<?=htmlspecialchars("Random");?> ?>
</option> <tr>
<option value="random sticky-address" <?php if ($pconfig['poolopts'] == "random sticky-address") echo "selected=\"selected\""; ?>> <td><?=gettext("Updated");?></td>
<?=htmlspecialchars("Random with Sticky Address");?> <td>
</option> <?= date(gettext("n/j/y H:i:s"), $a_out[$id]['updated']['time']) ?> <?= gettext("by") ?> <strong><?= $a_out[$id]['updated']['username'] ?></strong>
<option value="source-hash" <?php if ($pconfig['poolopts'] == "source-hash") echo "selected=\"selected\""; ?>> </td>
<?=htmlspecialchars("Source Hash");?> </tr>
</option> <?php
<option value="bitmask" <?php if ($pconfig['poolopts'] == "bitmask") echo "selected=\"selected\""; ?>> endif;
<?=htmlspecialchars("Bitmask");?> endif;
</option> ?>
</select> <tr>
<br /> <td>&nbsp;</td>
<span class="vexpl"> <td>
<?=gettext("Only Round Robin types work with Host Aliases. Any type can be used with a Subnet.");?><br /> <input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
* <?=gettext("Round Robin: Loops through the translation addresses.");?><br /> <input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_nat_out.php');?>'" />
* <?=gettext("Random: Selects an address from the translation address pool at random.");?><br /> <?php
* <?=gettext("Source Hash: Uses a hash of the source address to determine the translation address, ensuring that the redirection address is always the same for a given source.");?><br /> if (isset($id) && $a_out[$id]):
* <?=gettext("Bitmask: Applies the subnet mask and keeps the last portion identical; 10.0.1.50 -&gt; x.x.x.50.");?><br /> ?>
* <?=gettext("Sticky Address: The Sticky Address option can be used with the Random and Round Robin pool types to ensure that a particular source address is always mapped to the same translation address.");?><br /> <input name="id" type="hidden" value="<?=$id;?>" />
</span><br /> <?php
</td> endif;
</tr> ?>
<tr name="tport_tr" id="tport_tr"> <input name="after" type="hidden" value="<?=isset($after) ? $after : "";?>" />
<td><?=gettext("Port:");?>&nbsp;&nbsp;</td> </td>
<td> </tr>
<input name="natport" type="text" class="formfld unknown" id="natport" size="5" value="<?=htmlspecialchars($pconfig['natport']);?>" /> </table>
</td> </form>
</tr> </div>
<tr name="tporttext_tr" id="tporttext_tr"> </section>
<td>&nbsp;</td> </div>
<td> </div>
<span class="vexpl"><?=gettext("Enter the source port for the outbound NAT mapping.");?></span> </section>
</td>
</tr>
<tr name="tportstatic_tr" id="tportstatic_tr">
<td><?=gettext("Static-port:");?>&nbsp;&nbsp;</td>
<td><input onchange="staticportchange();" name="staticnatport" type="checkbox" class="formfld" id="staticnatport" size="5"<?php if($pconfig['staticnatport']) echo " checked=\"checked\"";?> /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("No XMLRPC Sync");?></td>
<td width="78%" class="vtable">
<input value="yes" name="nosync" type="checkbox" class="formfld" id="nosync"<?php if($pconfig['nosync']) echo " checked=\"checked\""; ?> /><br />
<?=gettext("Hint: This prevents the rule on Master from automatically syncing to other CARP members. This does NOT prevent the rule from being overwritten on Slave.");?>
</td>
</tr>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
<td width="78%" class="vtable">
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
<br />
<span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed).");?></span>
</td>
</tr>
<?php
$has_created_time = (isset($a_out[$id]['created']) && is_array($a_out[$id]['created']));
$has_updated_time = (isset($a_out[$id]['updated']) && is_array($a_out[$id]['updated']));
if ($has_created_time || $has_updated_time):
?>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" valign="top" class="listtopic"><?=gettext("Rule Information");?></td>
</tr>
<?php
if ($has_created_time):
?>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Created");?></td>
<td width="78%" class="vtable">
<?= date(gettext("n/j/y H:i:s"), $a_out[$id]['created']['time']) ?> <?= gettext("by") ?> <strong><?= $a_out[$id]['created']['username'] ?></strong>
</td>
</tr>
<?php
endif;
if ($has_updated_time):
?>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Updated");?></td>
<td width="78%" class="vtable">
<?= date(gettext("n/j/y H:i:s"), $a_out[$id]['updated']['time']) ?> <?= gettext("by") ?> <strong><?= $a_out[$id]['updated']['username'] ?></strong>
</td>
</tr>
<?php
endif;
endif;
?>
<tr>
<td width="22%" valign="top">&nbsp;</td>
<td width="78%">
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
<?php
if (isset($id) && $a_out[$id]):
?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
<?php
endif;
?>
<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>" />
</td>
</tr>
</table>
</form>
</div>
</section>
</div>
</div>
</section>
<script type="text/javascript">
//<![CDATA[
sourcesel_change();
typesel_change();
staticportchange();
nonat_change();
proto_change();
poolopts_change();
var addressarray = <?= json_encode(get_alias_list(array("host", "network", "openvpn", "urltable"))) ?>;
var customarray = <?= json_encode(get_alias_list(array("port", "url_ports", "urltable_ports"))) ?>;
var oTextbox1 = new AutoSuggestControl(document.getElementById("source"), new StateSuggestions(addressarray));
var oTextbox2 = new AutoSuggestControl(document.getElementById("sourceport"), new StateSuggestions(customarray));
var oTextbox3 = new AutoSuggestControl(document.getElementById("destination"), new StateSuggestions(addressarray));
var oTextbox4 = new AutoSuggestControl(document.getElementById("dstport"), new StateSuggestions(customarray));
//]]>
</script>
<?php include("foot.inc"); ?> <?php include("foot.inc"); ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment