firewall_nat_edit.php 45.2 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2
<?php
/*
3
	Copyright (C) 2014 Deciso B.V.
Ad Schellevis's avatar
Ad Schellevis committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
	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.
*/

29
require_once("guiconfig.inc");
Ad Schellevis's avatar
Ad Schellevis committed
30 31
require_once("itemid.inc");
require_once("filter.inc");
32
require_once("shaper.inc");
Ad Schellevis's avatar
Ad Schellevis committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_nat.php');

$specialsrcdst = explode(" ", "any (self) pptp pppoe l2tp openvpn");
$ifdisp = get_configured_interface_with_descr();
foreach ($ifdisp as $kif => $kdescr) {
	$specialsrcdst[] = "{$kif}";
	$specialsrcdst[] = "{$kif}ip";
}

if (!is_array($config['nat']['rule'])) {
	$config['nat']['rule'] = array();
}
$a_nat = &$config['nat']['rule'];

if (is_numericint($_GET['id']))
	$id = $_GET['id'];
if (isset($_POST['id']) && is_numericint($_POST['id']))
	$id = $_POST['id'];

if (is_numericint($_GET['after']) || $_GET['after'] == "-1")
	$after = $_GET['after'];
if (isset($_POST['after']) && (is_numericint($_POST['after']) || $_POST['after'] == "-1"))
	$after = $_POST['after'];

if (isset($_GET['dup']) && is_numericint($_GET['dup'])) {
        $id = $_GET['dup'];
        $after = $_GET['dup'];
}

if (isset($id) && $a_nat[$id]) {
	if ( isset($a_nat[$id]['created']) && is_array($a_nat[$id]['created']) )
		$pconfig['created'] = $a_nat[$id]['created'];

	if ( isset($a_nat[$id]['updated']) && is_array($a_nat[$id]['updated']) )
		$pconfig['updated'] = $a_nat[$id]['updated'];

	$pconfig['disabled'] = isset($a_nat[$id]['disabled']);
	$pconfig['nordr'] = isset($a_nat[$id]['nordr']);
	address_to_pconfig($a_nat[$id]['source'], $pconfig['src'],
		$pconfig['srcmask'], $pconfig['srcnot'],
		$pconfig['srcbeginport'], $pconfig['srcendport']);

	address_to_pconfig($a_nat[$id]['destination'], $pconfig['dst'],
		$pconfig['dstmask'], $pconfig['dstnot'],
		$pconfig['dstbeginport'], $pconfig['dstendport']);

	$pconfig['proto'] = $a_nat[$id]['protocol'];
	$pconfig['localip'] = $a_nat[$id]['target'];
	$pconfig['localbeginport'] = $a_nat[$id]['local-port'];
	$pconfig['descr'] = $a_nat[$id]['descr'];
	$pconfig['interface'] = $a_nat[$id]['interface'];
	$pconfig['associated-rule-id'] = $a_nat[$id]['associated-rule-id'];
	$pconfig['nosync'] = isset($a_nat[$id]['nosync']);
	$pconfig['natreflection'] = $a_nat[$id]['natreflection'];

	if (!$pconfig['interface'])
		$pconfig['interface'] = "wan";
} else {
	$pconfig['interface'] = "wan";
	$pconfig['src'] = "any";
	$pconfig['srcbeginport'] = "any";
	$pconfig['srcendport'] = "any";
}

if (isset($_GET['dup']) && is_numericint($_GET['dup']))
	unset($id);

/*  run through $_POST items encoding HTML entties so that the user
 *  cannot think he is slick and perform a XSS attack on the unwilling
 */
unset($input_errors);
foreach ($_POST as $key => $value) {
	$temp = $value;
	$newpost = htmlentities($temp);
	if($newpost <> $temp)
		$input_errors[] = sprintf(gettext("Invalid characters detected %s. Please remove invalid characters and save again."), $temp);
}

if ($_POST) {

	if(strtoupper($_POST['proto']) == "TCP" || strtoupper($_POST['proto']) == "UDP" || strtoupper($_POST['proto']) == "TCP/UDP") {
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
			$_POST['srcbeginport'] = trim($_POST['srcbeginport_cust']);
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
			$_POST['srcendport'] = trim($_POST['srcendport_cust']);

		if ($_POST['srcbeginport'] == "any") {
			$_POST['srcbeginport'] = 0;
			$_POST['srcendport'] = 0;
		} else {
			if (!$_POST['srcendport'])
				$_POST['srcendport'] = $_POST['srcbeginport'];
		}
		if ($_POST['srcendport'] == "any")
			$_POST['srcendport'] = $_POST['srcbeginport'];

		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
			$_POST['dstbeginport'] = trim($_POST['dstbeginport_cust']);
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
			$_POST['dstendport'] = trim($_POST['dstendport_cust']);

		if ($_POST['dstbeginport'] == "any") {
			$_POST['dstbeginport'] = 0;
			$_POST['dstendport'] = 0;
		} else {
			if (!$_POST['dstendport'])
				$_POST['dstendport'] = $_POST['dstbeginport'];
		}
		if ($_POST['dstendport'] == "any")
			$_POST['dstendport'] = $_POST['dstbeginport'];

		if ($_POST['localbeginport_cust'] && !$_POST['localbeginport'])
			$_POST['localbeginport'] = trim($_POST['localbeginport_cust']);

		/* Make beginning port end port if not defined and endport is */
		if (!$_POST['srcbeginport'] && $_POST['srcendport'])
			$_POST['srcbeginport'] = $_POST['srcendport'];
		if (!$_POST['dstbeginport'] && $_POST['dstendport'])
			$_POST['dstbeginport'] = $_POST['dstendport'];
	} else {
		$_POST['srcbeginport'] = 0;
		$_POST['srcendport'] = 0;
		$_POST['dstbeginport'] = 0;
		$_POST['dstendport'] = 0;
	}

	if (is_specialnet($_POST['srctype'])) {
		$_POST['src'] = $_POST['srctype'];
		$_POST['srcmask'] = 0;
	} else if ($_POST['srctype'] == "single") {
		$_POST['srcmask'] = 32;
	}
	if (is_specialnet($_POST['dsttype'])) {
		$_POST['dst'] = $_POST['dsttype'];
		$_POST['dstmask'] = 0;
	} else if ($_POST['dsttype'] == "single") {
		$_POST['dstmask'] = 32;
	} else if (is_ipaddr($_POST['dsttype'])) {
		$_POST['dst'] = $_POST['dsttype'];
		$_POST['dstmask'] = 32;
		$_POST['dsttype'] = "single";
	}

	$pconfig = $_POST;

	/* input validation */
	if(strtoupper($_POST['proto']) == "TCP" or strtoupper($_POST['proto']) == "UDP" or strtoupper($_POST['proto']) == "TCP/UDP") {
		$reqdfields = explode(" ", "interface proto dstbeginport dstendport");
		$reqdfieldsn = array(gettext("Interface"),gettext("Protocol"),gettext("Destination port from"),gettext("Destination port to"));
	} else {
		$reqdfields = explode(" ", "interface proto");
		$reqdfieldsn = array(gettext("Interface"),gettext("Protocol"));
	}

	if ($_POST['srctype'] == "single" || $_POST['srctype'] == "network") {
		$reqdfields[] = "src";
		$reqdfieldsn[] = gettext("Source address");
	}
	if ($_POST['dsttype'] == "single" || $_POST['dsttype'] == "network") {
		$reqdfields[] = "dst";
		$reqdfieldsn[] = gettext("Destination address");
	}
	if (!isset($_POST['nordr'])) {
		$reqdfields[] = "localip";
		$reqdfieldsn[] = gettext("Redirect target IP");
	}

	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);

	if (!$_POST['srcbeginport']) {
		$_POST['srcbeginport'] = 0;
		$_POST['srcendport'] = 0;
	}
	if (!$_POST['dstbeginport']) {
		$_POST['dstbeginport'] = 0;
		$_POST['dstendport'] = 0;
	}

	if ($_POST['src'])
		$_POST['src'] = trim($_POST['src']);
	if ($_POST['dst'])
		$_POST['dst'] = trim($_POST['dst']);
	if ($_POST['localip'])
		$_POST['localip'] = trim($_POST['localip']);

	if (!isset($_POST['nordr']) && ($_POST['localip'] && !is_ipaddroralias($_POST['localip']))) {
		$input_errors[] = sprintf(gettext("\"%s\" is not a valid redirect target IP address or host alias."), $_POST['localip']);
	}

	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
		$input_errors[] = sprintf(gettext("%s is not a valid start source port. It must be a port alias or integer between 1 and 65535."), $_POST['srcbeginport']);
	if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
		$input_errors[] = sprintf(gettext("%s is not a valid end source port. It must be a port alias or integer between 1 and 65535."), $_POST['srcendport']);
	if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
		$input_errors[] = sprintf(gettext("%s is not a valid start destination port. It must be a port alias or integer between 1 and 65535."), $_POST['dstbeginport']);
	if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
		$input_errors[] = sprintf(gettext("%s is not a valid end destination port. It must be a port alias or integer between 1 and 65535."), $_POST['dstendport']);

	if ((strtoupper($_POST['proto']) == "TCP" || strtoupper($_POST['proto']) == "UDP" || strtoupper($_POST['proto']) == "TCP/UDP") && (!isset($_POST['nordr']) && !is_portoralias($_POST['localbeginport']))) {
		$input_errors[] = sprintf(gettext("A valid redirect target port must be specified. It must be a port alias or integer between 1 and 65535."), $_POST['localbeginport']);
	}

	/* if user enters an alias and selects "network" then disallow. */
237
	if( ($_POST['srctype'] == "network" && is_alias($_POST['src']) )
Ad Schellevis's avatar
Ad Schellevis committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
	 || ($_POST['dsttype'] == "network" && is_alias($_POST['dst']) ) ) {
		$input_errors[] = gettext("You must specify single host or alias for alias entries.");
	}

	if (!is_specialnet($_POST['srctype'])) {
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."), $_POST['src']);
		}
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
			$input_errors[] = gettext("A valid source bit count must be specified.");
		}
	}
	if (!is_specialnet($_POST['dsttype'])) {
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."), $_POST['dst']);
		}
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
			$input_errors[] = gettext("A valid destination bit count must be specified.");
		}
	}

	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
		/* swap */
		$tmp = $_POST['srcendport'];
		$_POST['srcendport'] = $_POST['srcbeginport'];
		$_POST['srcbeginport'] = $tmp;
	}
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
		/* swap */
		$tmp = $_POST['dstendport'];
		$_POST['dstendport'] = $_POST['dstbeginport'];
		$_POST['dstbeginport'] = $tmp;
	}

	if (!$input_errors) {
		if (!isset($_POST['nordr']) && ($_POST['dstendport'] - $_POST['dstbeginport'] + $_POST['localbeginport']) > 65535)
			$input_errors[] = gettext("The target port range must be an integer between 1 and 65535.");
	}

	/* check for overlaps */
	foreach ($a_nat as $natent) {
		if (isset($id) && ($a_nat[$id]) && ($a_nat[$id] === $natent))
			continue;
		if ($natent['interface'] != $_POST['interface'])
			continue;
		if ($natent['destination']['address'] != $_POST['dst'])
			continue;
		if (($natent['proto'] != $_POST['proto']) && ($natent['proto'] != "tcp/udp") && ($_POST['proto'] != "tcp/udp"))
			continue;

		list($begp,$endp) = explode("-", $natent['destination']['port']);
		if (!$endp)
			$endp = $begp;

		if (!(   (($_POST['beginport'] < $begp) && ($_POST['endport'] < $begp))
		      || (($_POST['beginport'] > $endp) && ($_POST['endport'] > $endp)))) {

			$input_errors[] = gettext("The destination port range overlaps with an existing entry.");
			break;
		}
	}

	if (!$input_errors) {
		$natent = array();

		$natent['disabled'] = isset($_POST['disabled']) ? true:false;
		$natent['nordr'] = isset($_POST['nordr']) ? true:false;

		if ($natent['nordr']) {
			$_POST['associated-rule-id'] = '';
			$_POST['filter-rule-association'] = '';
		}

		pconfig_to_address($natent['source'], $_POST['src'],
			$_POST['srcmask'], $_POST['srcnot'],
			$_POST['srcbeginport'], $_POST['srcendport']);

		pconfig_to_address($natent['destination'], $_POST['dst'],
			$_POST['dstmask'], $_POST['dstnot'],
			$_POST['dstbeginport'], $_POST['dstendport']);

		$natent['protocol'] = $_POST['proto'];

		if (!$natent['nordr']) {
			$natent['target'] = $_POST['localip'];
			$natent['local-port'] = $_POST['localbeginport'];
		}
		$natent['interface'] = $_POST['interface'];
		$natent['descr'] = $_POST['descr'];
		$natent['associated-rule-id'] = $_POST['associated-rule-id'];

		if($_POST['filter-rule-association'] == "pass")
			$natent['associated-rule-id'] = "pass";

		if($_POST['nosync'] == "yes")
			$natent['nosync'] = true;
		else
			unset($natent['nosync']);

		if ($_POST['natreflection'] == "enable" || $_POST['natreflection'] == "purenat" || $_POST['natreflection'] == "disable")
			$natent['natreflection'] = $_POST['natreflection'];
		else
			unset($natent['natreflection']);

		// If we used to have an associated filter rule, but no-longer should have one
		if (!empty($a_nat[$id]) && ( empty($natent['associated-rule-id']) || $natent['associated-rule-id'] != $a_nat[$id]['associated-rule-id'] ) ) {
			// Delete the previous rule
			delete_id($a_nat[$id]['associated-rule-id'], $config['filter']['rule']);
			mark_subsystem_dirty('filter');
		}

		$need_filter_rule = false;
		// Updating a rule with a filter rule associated
		if (!empty($natent['associated-rule-id']))
			$need_filter_rule = true;
		// Create a rule or if we want to create a new one
		if( $natent['associated-rule-id']=='new' ) {
			$need_filter_rule = true;
			unset( $natent['associated-rule-id'] );
			$_POST['filter-rule-association']='add-associated';
		}
		// If creating a new rule, where we want to add the filter rule, associated or not
		else if( isset($_POST['filter-rule-association']) &&
			($_POST['filter-rule-association']=='add-associated' ||
			$_POST['filter-rule-association']=='add-unassociated') )
			$need_filter_rule = true;

		if ($need_filter_rule == true) {

			/* auto-generate a matching firewall rule */
			$filterent = array();
			unset($filterentid);
			// If a rule already exists, load it
			if (!empty($natent['associated-rule-id'])) {
				$filterentid = get_id($natent['associated-rule-id'], $config['filter']['rule']);
				if ($filterentid === false)
					$filterent['associated-rule-id'] = $natent['associated-rule-id'];
				else
					$filterent =& $config['filter']['rule'][$filterentid];
			}
			pconfig_to_address($filterent['source'], $_POST['src'],
				$_POST['srcmask'], $_POST['srcnot'],
				$_POST['srcbeginport'], $_POST['srcendport']);

			// Update interface, protocol and destination
			$filterent['interface'] = $_POST['interface'];
			$filterent['protocol'] = $_POST['proto'];
			$filterent['destination']['address'] = $_POST['localip'];

			$dstpfrom = $_POST['localbeginport'];
			$dstpto = $dstpfrom + $_POST['dstendport'] - $_POST['dstbeginport'];

			if ($dstpfrom == $dstpto)
				$filterent['destination']['port'] = $dstpfrom;
			else
				$filterent['destination']['port'] = $dstpfrom . "-" . $dstpto;

			/*
			 * Our firewall filter description may be no longer than
			 * 63 characters, so don't let it be.
			 */
			$filterent['descr'] = substr("NAT " . $_POST['descr'], 0, 62);

			// If this is a new rule, create an ID and add the rule
			if( $_POST['filter-rule-association']=='add-associated' ) {
				$filterent['associated-rule-id'] = $natent['associated-rule-id'] = get_unique_id();
				$filterent['created'] = make_config_revision_entry(null, gettext("NAT Port Forward"));
				$config['filter']['rule'][] = $filterent;
			}

			mark_subsystem_dirty('filter');
		}

		if ( isset($a_nat[$id]['created']) && is_array($a_nat[$id]['created']) )
			$natent['created'] = $a_nat[$id]['created'];

		$natent['updated'] = make_config_revision_entry();

		// Update the NAT entry now
		if (isset($id) && $a_nat[$id])
			$a_nat[$id] = $natent;
		else {
			$natent['created'] = make_config_revision_entry();
			if (is_numeric($after))
				array_splice($a_nat, $after+1, 0, array($natent));
			else
				$a_nat[] = $natent;
		}

		if (write_config())
			mark_subsystem_dirty('natconf');

		header("Location: firewall_nat.php");
		exit;
	}
}

$closehead = false;
$pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("Port Forward"),gettext("Edit"));
include("head.inc");

?>
<link type="text/css" rel="stylesheet" href="/javascript/chosen/chosen.css" />
</head>

Ad Schellevis's avatar
Ad Schellevis committed
443 444
<body>
<?php include("fbegin.inc"); ?>
445

Ad Schellevis's avatar
Ad Schellevis committed
446
	<script src="/javascript/chosen/chosen.jquery.js" type="text/javascript"></script>
447

Ad Schellevis's avatar
Ad Schellevis committed
448 449 450
	<section class="page-content-main">

		<div class="container-fluid">
451 452 453

			<div class="row">

Ad Schellevis's avatar
Ad Schellevis committed
454
				<?php if ($input_errors) print_input_errors($input_errors); ?>
455

Ad Schellevis's avatar
Ad Schellevis committed
456
			    <section class="col-xs-12">
457 458 459 460 461 462

				<div class="content-box">

                        <form action="firewall_nat_edit.php" method="post" name="iform" id="iform">

					<table class="table table-striped table-sort">
Ad Schellevis's avatar
Ad Schellevis committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487



									<tr>
										<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Redirect entry"); ?></td>
									</tr>
							<tr>
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
								<td width="78%" class="vtable">
									<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
									<strong><?=gettext("Disable this rule"); ?></strong><br />
									<span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list."); ?></span>
								</td>
							</tr>
					                <tr>
					                  <td width="22%" valign="top" class="vncell"><?=gettext("No RDR (NOT)"); ?></td>
					                  <td width="78%" class="vtable">
					                    <input type="checkbox" name="nordr" id="nordr" onclick="nordr_change();" <?php if($pconfig['nordr']) echo "checked=\"checked\""; ?> />
					                    <span class="vexpl"><?=gettext("Enabling this option will disable redirection for traffic matching this rule."); ?>
					                    <br /><?=gettext("Hint: this option is rarely needed, don't use this unless you know what you're doing."); ?></span>
					                  </td>
					                </tr>
							<tr>
					                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
					                  <td width="78%" class="vtable">
488
										<select name="interface" class="selectpicker" data-live-search="true" onchange="dst_change(this.value,iface_old,document.iform.dsttype.value);iface_old = document.iform.interface.value;typesel_change();">
Ad Schellevis's avatar
Ad Schellevis committed
489
											<?php
490

Ad Schellevis's avatar
Ad Schellevis committed
491 492 493 494
											$iflist = get_configured_interface_with_descr(false, true);
											foreach ($iflist as $if => $ifdesc)
												if(have_ruleint_access($if))
													$interfaces[$if] = $ifdesc;
495

Ad Schellevis's avatar
Ad Schellevis committed
496 497 498
											if ($config['l2tp']['mode'] == "server")
												if(have_ruleint_access("l2tp"))
													$interfaces['l2tp'] = "L2TP VPN";
499

Ad Schellevis's avatar
Ad Schellevis committed
500 501 502
											if ($config['pptpd']['mode'] == "server")
												if(have_ruleint_access("pptp"))
													$interfaces['pptp'] = "PPTP VPN";
503

Ad Schellevis's avatar
Ad Schellevis committed
504 505
											if (is_pppoe_server_enabled() && have_ruleint_access("pppoe"))
												$interfaces['pppoe'] = "PPPoE VPN";
506

Ad Schellevis's avatar
Ad Schellevis committed
507 508 509 510
											/* add ipsec interfaces */
											if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
												if(have_ruleint_access("enc0"))
													$interfaces["enc0"] = "IPsec";
511

Ad Schellevis's avatar
Ad Schellevis committed
512 513 514
											/* add openvpn/tun interfaces */
											if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
												$interfaces["openvpn"] = "OpenVPN";
515

Ad Schellevis's avatar
Ad Schellevis committed
516 517 518 519 520 521 522 523 524 525 526 527
											foreach ($interfaces as $iface => $ifacename): ?>
											<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
											<?=htmlspecialchars($ifacename);?>
											</option>
											<?php endforeach; ?>
										</select><br />
					                     <span class="vexpl"><?=gettext("Choose which interface this rule applies to."); ?><br />
					                     <?=gettext("Hint: in most cases, you'll want to use WAN here."); ?></span></td>
					                </tr>
					                <tr>
					                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol"); ?></td>
					                  <td width="78%" class="vtable">
528
					                    <select name="proto" class="selectpicker" onchange="proto_change(); check_for_aliases();">
Ad Schellevis's avatar
Ad Schellevis committed
529 530 531 532 533 534 535 536 537 538
					                      <?php $protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IPV6 IGMP PIM OSPF"); foreach ($protocols as $proto): ?>
					                      <option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($proto);?></option>
					                      <?php endforeach; ?>
					                    </select> <br /> <span class="vexpl"><?=gettext("Choose which IP protocol " .
					                    "this rule should match."); ?><br />
					                    <?=gettext("Hint: in most cases, you should specify"); ?> <em><?=gettext("TCP"); ?></em> &nbsp;<?=gettext("here."); ?></span></td>
					                </tr>
							<tr id="showadvancedboxsrc" name="showadvancedboxsrc">
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Source"); ?></td>
								<td width="78%" class="vtable">
Ad Schellevis's avatar
Ad Schellevis committed
539
									<input type="button" onclick="show_source()" class="btn btn-default" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show source address and port range"); ?>
Ad Schellevis's avatar
Ad Schellevis committed
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
								</td>
							</tr>
							<tr style="display: none;" id="srctable" name="srctable">
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Source"); ?></td>
								<td width="78%" class="vtable">
									<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked=\"checked\""; ?> />
									<strong><?=gettext("not"); ?></strong>
									<br />
									<?=gettext("Use this option to invert the sense of the match."); ?>
									<br />
									<br />
									<table border="0" cellspacing="0" cellpadding="0" summary="type">
										<tr>
											<td><?=gettext("Type:"); ?>&nbsp;&nbsp;</td>
											<td>
555
												<select name="srctype" class="selectpicker" onchange="typesel_change()">
Ad Schellevis's avatar
Ad Schellevis committed
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
					<?php
													$sel = is_specialnet($pconfig['src']); ?>
													<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected=\"selected\""; } ?>><?=gettext("any"); ?></option>
													<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected=\"selected\""; $sel = 1; } ?>><?=gettext("Single host or alias"); ?></option>
													<option value="network" <?php if (!$sel) echo "selected=\"selected\""; ?>><?=gettext("Network"); ?></option>
													<?php if(have_ruleint_access("pptp")): ?>
													<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected=\"selected\""; } ?>><?=gettext("PPTP clients"); ?></option>
													<?php endif; ?>
													<?php if(have_ruleint_access("pppoe")): ?>
													<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected=\"selected\""; } ?>><?=gettext("PPPoE clients"); ?></option>
													<?php endif; ?>
													 <?php if(have_ruleint_access("l2tp")): ?>
					                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected=\"selected\""; } ?>><?=gettext("L2TP clients"); ?></option>
					                                 <?php endif; ?>
					<?php
													foreach ($ifdisp as $ifent => $ifdesc): ?>
													<?php if(have_ruleint_access($ifent)): ?>
														<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected=\"selected\""; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("net"); ?></option>
														<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected=\"selected\""; } ?>>
															<?=$ifdesc?> <?=gettext("address");?>
														</option>
													<?php endif; ?>
578
					<?php							endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
579 580 581 582 583 584
												</select>
											</td>
										</tr>
										<tr>
											<td><?=gettext("Address:"); ?>&nbsp;&nbsp;</td>
											<td>
585 586 587 588 589 590 591 592 593 594 595 596 597 598
												<table>
													<tr>
														<td width="348px">
															<input autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>" />
														</td>
														<td>
															<select name="srcmask" class="selectpicker" id="srcmask" data-width="auto" data-size="auto">
															<?php for ($i = 31; $i > 0; $i--): ?>
																<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected=\"selected\""; ?>><?=$i;?></option>
															<?php endfor; ?>
															</select>
														</td>
													</tr>
												</table>
Ad Schellevis's avatar
Ad Schellevis committed
599 600 601 602 603 604 605 606 607 608 609 610
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr style="display:none" id="sprtable" name="sprtable">
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range"); ?></td>
								<td width="78%" class="vtable">
									<table border="0" cellspacing="0" cellpadding="0" summary="source port range">
										<tr>
											<td><?=gettext("from:"); ?>&nbsp;&nbsp;</td>
											<td>
611 612

												<select name="srcbeginport" class="selectpicker" onchange="src_rep_change();ext_change()">
Ad Schellevis's avatar
Ad Schellevis committed
613 614
													<option value="">(<?=gettext("other"); ?>)</option>
													<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any"); ?></option>
615
					<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
Ad Schellevis's avatar
Ad Schellevis committed
616
														<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
617
					<?php							endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
618 619 620 621 622 623 624
												</select>
												<input autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo htmlspecialchars($pconfig['srcbeginport']); ?>" />
											</td>
										</tr>
										<tr>
											<td><?=gettext("to:"); ?></td>
											<td>
625
												<select name="srcendport" class="selectpicker" onchange="ext_change()">
Ad Schellevis's avatar
Ad Schellevis committed
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
													<option value="">(<?=gettext("other"); ?>)</option>
													<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any"); ?></option>
					<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
														<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
					<?php							endforeach; ?>
												</select>
												<input autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo htmlspecialchars($pconfig['srcendport']); ?>" />
											</td>
										</tr>
									</table>
									<br />
									<span class="vexpl"><?=gettext("Specify the source port or port range for this rule"); ?>. <b><?=gettext("This is usually"); ?> <em><?=gettext("random"); ?></em> <?=gettext("and almost never equal to the destination port range (and should usually be 'any')"); ?>.</b> <br /> <?=gettext("Hint: you can leave the"); ?> <em>'<?=gettext("to"); ?>'</em> <?=gettext("field empty if you only want to filter a single port."); ?></span><br />
								</td>
							</tr>
							<tr>
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination"); ?></td>
								<td width="78%" class="vtable">
									<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked=\"checked\""; ?> />
									<strong><?=gettext("not"); ?></strong>
										<br />
									<?=gettext("Use this option to invert the sense of the match."); ?>
										<br />
										<br />
									<table border="0" cellspacing="0" cellpadding="0" summary="type">
										<tr>
											<td><?=gettext("Type:"); ?>&nbsp;&nbsp;</td>
											<td>
653
												<select name="dsttype" class="selectpicker" onchange="typesel_change()">
Ad Schellevis's avatar
Ad Schellevis committed
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
					<?php
													$sel = is_specialnet($pconfig['dst']); ?>
													<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected=\"selected\""; } ?>><?=gettext("any"); ?></option>
													<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected=\"selected\""; $sel = 1; } ?>><?=gettext("Single host or alias"); ?></option>
													<option value="network" <?php if (!$sel) echo "selected=\"selected\""; ?>><?=gettext("Network"); ?></option>
													<option value="(self)" <?PHP if ($pconfig['dst'] == "(self)") echo "selected=\"selected\""; ?>><?=gettext("This Firewall (self)");?></option>
													<?php if(have_ruleint_access("pptp")): ?>
													<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected=\"selected\""; } ?>><?=gettext("PPTP clients"); ?></option>
													<?php endif; ?>
													<?php if(have_ruleint_access("pppoe")): ?>
													<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected=\"selected\""; } ?>><?=gettext("PPPoE clients"); ?></option>
													<?php endif; ?>
													<?php if(have_ruleint_access("l2tp")): ?>
					                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected=\"selected\""; } ?>><?=gettext("L2TP clients"); ?></option>
					                                                                <?php endif; ?>
669 670

					<?php							foreach ($ifdisp as $if => $ifdesc): ?>
Ad Schellevis's avatar
Ad Schellevis committed
671 672 673 674 675 676
													<?php if(have_ruleint_access($if)): ?>
														<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected=\"selected\""; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("net"); ?></option>
														<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected=\"selected\""; } ?>>
															<?=$ifdesc;?> <?=gettext("address");?>
														</option>
													<?php endif; ?>
677 678
					<?php							endforeach; ?>

Ad Schellevis's avatar
Ad Schellevis committed
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
					<?php							if (is_array($config['virtualip']['vip'])):
														foreach ($config['virtualip']['vip'] as $sn):
															if (isset($sn['noexpand']))
																continue;
															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;
																for ($i = 0; $i <= $len; $i++):
																	$snip = long2ip32($start+$i);
					?>
																	<option value="<?=$snip;?>" <?php if ($snip == $pconfig['dst']) echo "selected=\"selected\""; ?>><?=htmlspecialchars("{$snip} ({$sn['descr']})");?></option>
					<?php										endfor;
															else:
					?>
																<option value="<?=$sn['subnet'];?>" <?php if ($sn['subnet'] == $pconfig['dst']) echo "selected=\"selected\""; ?>><?=htmlspecialchars("{$sn['subnet']} ({$sn['descr']})");?></option>
					<?php									endif;
														endforeach;
													endif;
					?>
												</select>
											</td>
										</tr>
										<tr>
											<td><?=gettext("Address:"); ?>&nbsp;&nbsp;</td>
											<td>
705 706
												<table>
													<tr>
707
														<td width="348px">
708 709 710 711 712 713 714 715 716 717 718 719
															<input autocomplete='off' name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>" />
														</td>
														<td>
															<select name="dstmask" class="selectpicker" data-width="auto" id="dstmask">
																<?php
																	for ($i = 31; $i > 0; $i--): ?>
																		<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected=\"selected\""; ?>><?=$i;?></option>
																<?php endfor; ?>
															</select>
														</td>
													</tr>
												</table>
Ad Schellevis's avatar
Ad Schellevis committed
720 721 722 723 724 725 726 727 728 729 730 731
											</td>
										</tr>
									</table>
								</td>
							</tr>
							<tr id="dprtr" name="dprtr">
								<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination port range"); ?> </td>
								<td width="78%" class="vtable">
									<table border="0" cellspacing="0" cellpadding="0" summary="destination port range">
										<tr>
											<td><?=gettext("from:"); ?>&nbsp;&nbsp;</td>
											<td>
732
												<select name="dstbeginport" id="dstbeginport" class="selectpicker" onchange="dst_rep_change();ext_change()">
Ad Schellevis's avatar
Ad Schellevis committed
733
													<option value="">(<?=gettext("other"); ?>)</option>
734
					<?php							$bfound = 0;
Ad Schellevis's avatar
Ad Schellevis committed
735 736
													foreach ($wkports as $wkport => $wkportdesc): ?>
														<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected=\"selected\""; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
737
					<?php							endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
738 739 740 741 742 743 744
												</select>
												<input autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo htmlspecialchars($pconfig['dstbeginport']); ?>" />
											</td>
										</tr>
										<tr>
											<td><?=gettext("to:"); ?></td>
											<td>
745
												<select name="dstendport" id="dstendport" class="selectpicker" onchange="ext_change()">
Ad Schellevis's avatar
Ad Schellevis committed
746 747 748 749
													<option value="">(<?=gettext("other"); ?>)</option>
					<?php							$bfound = 0;
													foreach ($wkports as $wkport => $wkportdesc): ?>
														<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
750
					<?php							endforeach; ?>
Ad Schellevis's avatar
Ad Schellevis committed
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
												</select>
												<input autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo htmlspecialchars($pconfig['dstendport']); ?>" />
											</td>
										</tr>
									</table>
									<br />
									<span class="vexpl">
										<?=gettext("Specify the port or port range for the destination of the packet for this mapping."); ?>
										<br />
										<?=gettext("Hint: you can leave the"); ?> <em>'<?=gettext("to"); ?>'</em> <?=gettext("field empty if you only want to map a single port"); ?>
									</span>
								</td>
							</tr>
					                <tr name="localiptable" id="localiptable">
					                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Redirect target IP"); ?></td>
					                  <td width="78%" class="vtable">
					                    <input autocomplete='off' name="localip" type="text" class="formfldalias" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>" />
					                    <br /> <span class="vexpl"><?=gettext("Enter the internal IP address of " .
					                    "the server on which you want to map the ports."); ?><br />
					                    <?=gettext("e.g."); ?> <em>192.168.1.12</em></span></td>
					                </tr>
					                <tr name="lprtr" id="lprtr">
					                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Redirect target port"); ?></td>
					                  <td width="78%" class="vtable">
775
					                    <select name="localbeginport" id="localbeginport" class="selectpicker" onchange="ext_change();check_for_aliases();">
Ad Schellevis's avatar
Ad Schellevis committed
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
					                      <option value="">(<?=gettext("other"); ?>)</option>
					                      <?php $bfound = 0; foreach ($wkports as $wkport => $wkportdesc): ?>
					                      <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['localbeginport']) {
												echo "selected=\"selected\"";
												$bfound = 1;
											}?>>
										  <?=htmlspecialchars($wkportdesc);?>
										  </option>
					                      <?php endforeach; ?>
					                    </select> <input onchange="check_for_aliases();" autocomplete='off' class="formfldalias" name="localbeginport_cust" id="localbeginport_cust" type="text" size="5" value="<?php if (!$bfound) echo htmlspecialchars($pconfig['localbeginport']); ?>" />
					                    <br />
					                    <span class="vexpl"><?=gettext("Specify the port on the machine with the " .
					                    "IP address entered above. In case of a port range, specify " .
					                    "the beginning port of the range (the end port will be calculated " .
					                    "automatically)."); ?><br />
					                    <?=gettext("Hint: this is usually identical to the 'from' port above"); ?></span></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>
									<tr>
										<td width="22%" valign="top" class="vncell"><?=gettext("No XMLRPC Sync"); ?></td>
										<td width="78%" class="vtable">
											<input type="checkbox" value="yes" name="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("NAT reflection"); ?></td>
										<td width="78%" class="vtable">
810
											<select name="natreflection" class="selectpicker">
Ad Schellevis's avatar
Ad Schellevis committed
811 812 813 814 815 816 817 818 819 820 821
											<option value="default" <?php if ($pconfig['natreflection'] != "enable" && $pconfig['natreflection'] != "purenat" && $pconfig['natreflection'] != "disable") echo "selected=\"selected\""; ?>><?=gettext("Use system default"); ?></option>
											<option value="enable" <?php if ($pconfig['natreflection'] == "enable") echo "selected=\"selected\""; ?>><?=gettext("Enable (NAT + Proxy)"); ?></option>
											<option value="purenat" <?php if ($pconfig['natreflection'] == "purenat") echo "selected=\"selected\""; ?>><?=gettext("Enable (Pure NAT)"); ?></option>
											<option value="disable" <?php if ($pconfig['natreflection'] == "disable") echo "selected=\"selected\""; ?>><?=gettext("Disable"); ?></option>
											</select>
										</td>
									</tr>
									<?php if (isset($id) && $a_nat[$id] && (!isset($_GET['dup']) || !is_numericint($_GET['dup']))): ?>
									<tr name="assoctable" id="assoctable">
										<td width="22%" valign="top" class="vncell"><?=gettext("Filter rule association"); ?></td>
										<td width="78%" class="vtable">
822
											<select name="associated-rule-id" class="selectpicker" >
Ad Schellevis's avatar
Ad Schellevis committed
823 824 825 826 827 828 829 830 831 832 833 834 835 836
												<option value=""><?=gettext("None"); ?></option>
												<option value="pass" <?php if($pconfig['associated-rule-id'] == "pass") echo " selected=\"selected\""; ?>><?=gettext("Pass"); ?></option>
												<?php
												$linkedrule = "";
												if (is_array($config['filter']['rule'])) {
												      filter_rules_sort();
												      foreach ($config['filter']['rule'] as $filter_id => $filter_rule) {
													if (isset($filter_rule['associated-rule-id'])) {
														echo "<option value=\"{$filter_rule['associated-rule-id']}\"";
														if ($filter_rule['associated-rule-id']==$pconfig['associated-rule-id']) {
															echo " selected=\"selected\"";
															$linkedrule = "<br /><a href=\"firewall_rules_edit.php?id={$filter_id}\">" . gettext("View the filter rule") . "</a><br />";
														}
														echo ">". htmlspecialchars('Rule ' . $filter_rule['descr']) . "</option>\n";
837

Ad Schellevis's avatar
Ad Schellevis committed
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
													}
												      }
												}
												if (isset($pconfig['associated-rule-id']))
													echo "<option value=\"new\">" . gettext("Create new associated filter rule") . "</option>\n";
											echo "</select>\n";
											echo $linkedrule;
											?>
										</td>
									</tr>
									<?php endif; ?>
					                <?php if ((!(isset($id) && $a_nat[$id])) || (isset($_GET['dup']) && is_numericint($_GET['dup']))): ?>
					                <tr name="assoctable" id="assoctable">
					                  <td width="22%" valign="top" class="vncell"><?=gettext("Filter rule association"); ?></td>
					                  <td width="78%" class="vtable">
853
					                    <select name="filter-rule-association" id="filter-rule-association" class="selectpicker" >
Ad Schellevis's avatar
Ad Schellevis committed
854 855 856 857 858 859 860 861 862 863 864 865 866 867
											<option value=""><?=gettext("None"); ?></option>
											<option value="add-associated" selected="selected"><?=gettext("Add associated filter rule"); ?></option>
											<option value="add-unassociated"><?=gettext("Add unassociated filter rule"); ?></option>
											<option value="pass"><?=gettext("Pass"); ?></option>
										</select>
										<br /><br /><?=gettext("NOTE: The \"pass\" selection does not work properly with Multi-WAN. It will only work on an interface containing the default gateway.")?>
									  </td>
					                </tr><?php endif; ?>
					<?php
					$has_created_time = (isset($a_nat[$id]['created']) && is_array($a_nat[$id]['created']));
					$has_updated_time = (isset($a_nat[$id]['updated']) && is_array($a_nat[$id]['updated']));
					?>
							<?php if ($has_created_time || $has_updated_time): ?>
							<tr>
868
								<td colspan="2">&nbsp;</td>
Ad Schellevis's avatar
Ad Schellevis committed
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
							</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_nat[$id]['created']['time']) ?> <?= gettext("by") ?> <strong><?= $a_nat[$id]['created']['username'] ?></strong>
								</td>
							</tr>
							<?php endif; ?>
							<?php 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_nat[$id]['updated']['time']) ?> <?= gettext("by") ?> <strong><?= $a_nat[$id]['updated']['username'] ?></strong>
								</td>
							</tr>
							<?php endif; ?>
							<?php endif; ?>
									<tr>
					                  <td width="22%" valign="top">&nbsp;</td>
					                  <td width="78%">&nbsp;</td>
									</tr>
					                <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_nat[$id]): ?>
					                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
					                    <?php endif; ?>
					                    <input name="after" type="hidden" value="<?=htmlspecialchars($after);?>" />
					                  </td>
					                </tr>
					              </table>
					              </form>
					             </div>
					             </div>
					             </section>
					             </div>
					             </div>
					             </section>

Ad Schellevis's avatar
Ad Schellevis committed
914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
<script type="text/javascript">
//<![CDATA[
	ext_change();
	dst_change(document.iform.interface.value,'<?=htmlspecialchars($pconfig['interface'])?>','<?=htmlspecialchars($pconfig['dst'])?>');
	var iface_old = document.iform.interface.value;
	typesel_change();
	proto_change();
	<?php if ($pconfig['srcnot'] || $pconfig['src'] != "any" || $pconfig['srcbeginport'] != "any" || $pconfig['srcendport'] != "any"): ?>
	show_source();
	<?php endif; ?>
	nordr_change();
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
	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("localip"), new StateSuggestions(addressarray));
	var oTextbox2 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
	var oTextbox3 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
	var oTextbox4 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
	var oTextbox5 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
	var oTextbox6 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
	var oTextbox7 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
	var oTextbox8 = new AutoSuggestControl(document.getElementById("localbeginport_cust"), new StateSuggestions(customarray));
//]]>
</script>
942
<?php include("foot.inc"); ?>