Projet

Général

Profil

Télécharger (32,3 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_nat_out_edit.php @ 0fab7eb1

1
<?php
2
/* $Id$ */
3
/*
4
	firewall_nat_out_edit.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34
	pfSense_MODULE:	nat
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-firewall-nat-outbound-edit
39
##|*NAME=Firewall: NAT: Outbound: Edit page
40
##|*DESCR=Allow access to the 'Firewall: NAT: Outbound: Edit' page.
41
##|*MATCH=firewall_nat_out_edit.php*
42
##|-PRIV
43

    
44
require("guiconfig.inc");
45
require_once("filter.inc");
46
require("shaper.inc");
47

    
48
if (!is_array($config['nat']['outbound']))
49
	$config['nat']['outbound'] = array();
50

    
51
if (!is_array($config['nat']['outbound']['rule'])) {
52
	$config['nat']['outbound']['rule'] = array();
53
}
54

    
55
$a_out = &$config['nat']['outbound']['rule'];
56

    
57
if (!is_array($config['aliases']['alias']))
58
	$config['aliases']['alias'] = array();
59
$a_aliases = &$config['aliases']['alias'];
60

    
61
if (is_numericint($_GET['id']))
62
	$id = $_GET['id'];
63
if (isset($_POST['id']) && is_numericint($_POST['id']))
64
	$id = $_POST['id'];
65

    
66
if (is_numericint($_GET['after']) || $_GET['after'] == "-1")
67
	$after = $_GET['after'];
68
if (isset($_POST['after']) && (is_numericint($_POST['after']) || $_POST['after'] == "-1"))
69
	$after = $_POST['after'];
70

    
71
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) {
72
        $id = $_GET['dup'];
73
        $after = $_GET['dup'];
74
}
75

    
76
if (isset($id) && $a_out[$id]) {
77
	if ( isset($a_out[$id]['created']) && is_array($a_out[$id]['created']) )
78
		$pconfig['created'] = $a_out[$id]['created'];
79

    
80
	if ( isset($a_out[$id]['updated']) && is_array($a_out[$id]['updated']) )
81
		$pconfig['updated'] = $a_out[$id]['updated'];
82

    
83
	$pconfig['protocol'] = $a_out[$id]['protocol'];
84
	list($pconfig['source'],$pconfig['source_subnet']) = explode('/', $a_out[$id]['source']['network']);
85
	if (!is_numeric($pconfig['source_subnet']))
86
		$pconfig['source_subnet'] = 32;
87
	$pconfig['sourceport'] = $a_out[$id]['sourceport'];
88
	address_to_pconfig($a_out[$id]['destination'], $pconfig['destination'],
89
		$pconfig['destination_subnet'], $pconfig['destination_not'],
90
		$none, $none);
91
	$pconfig['dstport'] = $a_out[$id]['dstport'];
92
	$pconfig['natport'] = $a_out[$id]['natport'];
93
	$pconfig['target'] = $a_out[$id]['target'];
94
	$pconfig['targetip'] = $a_out[$id]['targetip'];
95
	$pconfig['targetip_subnet'] = $a_out[$id]['targetip_subnet'];
96
	$pconfig['poolopts'] = $a_out[$id]['poolopts'];
97
	$pconfig['interface'] = $a_out[$id]['interface'];
98
	if (!$pconfig['interface']) {
99
		$pconfig['interface'] = "wan";
100
	}
101
	$pconfig['descr'] = $a_out[$id]['descr'];
102
	$pconfig['nonat'] = $a_out[$id]['nonat'];
103
	$pconfig['disabled'] = isset($a_out[$id]['disabled']);
104
	$pconfig['staticnatport'] = isset($a_out[$id]['staticnatport']);
105
	$pconfig['nosync'] = isset($a_out[$id]['nosync']);
106
} else {
107
	$pconfig['source_subnet'] = 24;
108
	$pconfig['destination'] = "any";
109
	$pconfig['destination_subnet'] = 24;
110
	$pconfig['interface'] = "wan";
111
}
112

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

    
116
if ($_POST) {
117
	if ($_POST['destination_type'] == "any") {
118
		$_POST['destination'] = "any";
119
		$_POST['destination_subnet'] = 24;
120
	}
121
	if ($_POST['source_type'] == "any") {
122
		$_POST['source'] = "any";
123
		$_POST['source_subnet'] = 24;
124
	}
125

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

    
138
	/* input validation */
139
	$reqdfields = explode(" ", "interface protocol source source_subnet destination destination_subnet");
140
	$reqdfieldsn = array(gettext("Interface"),gettext("Protocol"),gettext("Source"),gettext("Source bit count"),gettext("Destination"),gettext("Destination bit count"));
141

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

    
144
	$protocol_uses_ports = in_array($_POST['protocol'], explode(" ", "any tcp udp tcp/udp"));
145

    
146
	if ($_POST['source'])
147
		$_POST['source'] = trim($_POST['source']);
148
	if ($_POST['destination'])
149
		$_POST['destination'] = trim($_POST['destination']);
150
	if ($_POST['targetip'])
151
		$_POST['targetip'] = trim($_POST['targetip']);
152
	if ($_POST['sourceport'])
153
		$_POST['sourceport'] = trim($_POST['sourceport']);
154
	if ($_POST['dstport'])
155
		$_POST['dstport'] = trim($_POST['dstport']);
156
	if ($_POST['natport'])
157
		$_POST['natport'] = trim($_POST['natport']);
158

    
159
	if($protocol_uses_ports && $_POST['sourceport'] <> "" && !is_portoralias($_POST['sourceport']))
160
		$input_errors[] = gettext("You must supply either a valid port or port alias for the source port entry.");
161

    
162
	if($protocol_uses_ports && $_POST['dstport'] <> "" && !is_portoralias($_POST['dstport']))
163
		$input_errors[] = gettext("You must supply either a valid port or port alias for the destination port entry.");
164

    
165
	if($protocol_uses_ports && $_POST['natport'] <> "" && !is_port($_POST['natport']) && !isset($_POST['nonat']))
166
		$input_errors[] = gettext("You must supply a valid port for the NAT port entry.");
167

    
168
	if ($_POST['source_type'] != "any") {
169
		if ($_POST['source'] && !is_ipaddroralias($_POST['source']) && $_POST['source'] <> "any") {
170
			$input_errors[] = gettext("A valid source must be specified.");
171
		}
172
	}
173
	if ($_POST['source_subnet'] && !is_numericint($_POST['source_subnet'])) {
174
		$input_errors[] = gettext("A valid source bit count must be specified.");
175
	}
176
	if ($_POST['destination_type'] != "any") {
177
		if ($_POST['destination'] && !is_ipaddroralias($_POST['destination'])) {
178
			$input_errors[] = gettext("A valid destination must be specified.");
179
		}
180
	}
181
	if ($_POST['destination_subnet'] && !is_numericint($_POST['destination_subnet'])) {
182
		$input_errors[] = gettext("A valid destination bit count must be specified.");
183
	}
184
	if ($_POST['destination_type'] == "any") {
185
		if ($_POST['destination_not']) {
186
			$input_errors[] = gettext("Negating destination address of \"any\" is invalid.");
187
		}
188
	}
189

    
190
	if ($_POST['target'] && !is_ipaddr($_POST['target']) && !is_subnet($_POST['target']) && !is_alias($_POST['target']) && !isset($_POST['nonat']) && !($_POST['target'] == "other-subnet")) {
191
		$input_errors[] = gettext("A valid target IP address must be specified.");
192
	}
193

    
194
	if ($_POST['target'] == "other-subnet") {
195
		if (!is_ipaddr($_POST['targetip'])) {
196
			$input_errors[] = gettext("A valid target IP must be specified when using the 'Other Subnet' type.");
197
		}
198
		if (!is_numericint($_POST['targetip_subnet'])) {
199
			$input_errors[] = gettext("A valid target bit count must be specified when using the 'Other Subnet' type.");
200
		}
201
	}
202

    
203
	/* Verify Pool Options */
204
	$poolopts = "";
205
	if ($_POST['poolopts']) {
206
		if (is_subnet($_POST['target']) || ($_POST['target'] == "other-subnet"))
207
			$poolopts = $_POST['poolopts'];
208
		elseif (is_alias($_POST['target'])) {
209
			if (substr($_POST['poolopts'], 0, 11) == "round-robin")
210
				$poolopts = $_POST['poolopts'];
211
			else
212
				$input_errors[] = gettext("Only Round Robin pool options may be chosen when selecting an alias.");
213
		}
214
	}
215

    
216
	/* if user has selected any as source, set it here */
217
	if($_POST['source_type'] == "any") {
218
		$osn = "any";
219
	} else if(is_alias($_POST['source'])) {
220
		$osn = $_POST['source'];
221
	} else {
222
		$osn = gen_subnet($_POST['source'], $_POST['source_subnet']) . "/" . $_POST['source_subnet'];
223
	}
224

    
225
	/* check for existing entries */
226
	if ($_POST['destination_type'] == "any") {
227
		$ext = "any";
228
	} else if(is_alias($_POST['destination'])) {
229
		$ext = $_POST['destination'];
230
	} else {
231
		$ext = gen_subnet($_POST['destination'], $_POST['destination_subnet']) . "/" . $_POST['destination_subnet'];
232
	}
233

    
234
	foreach ($a_out as $natent) {
235
		if (isset($id) && ($a_out[$id]) && ($a_out[$id] === $natent)) {
236
			continue;
237
		}
238

    
239
		if (!$natent['interface']) {
240
			$natent['interface'] == "wan";
241
		}
242
	}
243

    
244
	// Allow extending of the firewall edit page and include custom input validation 
245
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aon/input_validation");
246

    
247
	if (!$input_errors) {
248
	        $natent = array();
249
		$natent['source']['network'] = $osn;
250
		$natent['sourceport'] = ($protocol_uses_ports) ? $_POST['sourceport'] : "";
251
		$natent['descr'] = $_POST['descr'];
252
		$natent['target'] = (!isset($_POST['nonat'])) ? $_POST['target'] : "";
253
		$natent['targetip'] = (!isset($_POST['nonat'])) ? $_POST['targetip'] : "";
254
		$natent['targetip_subnet'] = (!isset($_POST['nonat'])) ? $_POST['targetip_subnet'] : "";
255
		$natent['interface'] = $_POST['interface'];
256
		$natent['poolopts'] = $poolopts;
257

    
258
		/* static-port */
259
		if(isset($_POST['staticnatport']) && $protocol_uses_ports && !isset($_POST['nonat'])) {
260
			$natent['staticnatport'] = true;
261
		} else {
262
			unset($natent['staticnatport']);
263
		}
264
		
265
		if(isset($_POST['disabled'])) {
266
			$natent['disabled'] = true;
267
		} else {
268
			unset($natent['disabled']);
269
		}
270

    
271
		/* if user has selected not nat, set it here */
272
		if(isset($_POST['nonat'])) {
273
			$natent['nonat'] = true;
274
		} else {
275
			unset($natent['nonat']);
276
		}
277

    
278
		if ($_POST['protocol'] && $_POST['protocol'] != "any")
279
			$natent['protocol'] = $_POST['protocol'];
280
		else
281
			unset($natent['protocol']);
282

    
283
	        if ($ext == "any") {
284
			$natent['destination']['any'] = true;
285
		} else {
286
			$natent['destination']['address'] = $ext;
287
		}
288
		if($_POST['natport'] != "" && $protocol_uses_ports && !isset($_POST['nonat'])) {
289
	        	$natent['natport'] = $_POST['natport'];
290
		} else {
291
			unset($natent['natport']);
292
		}
293
		if($_POST['dstport'] != "" && $protocol_uses_ports) {
294
			$natent['dstport'] = $_POST['dstport'];
295
		} else {
296
			unset($natent['dstport']);
297
		}
298

    
299
		if($_POST['nosync'] == "yes") {
300
			$natent['nosync'] = true;
301
		} else {
302
			unset($natent['nosync']);
303
		}
304

    
305
		if (isset($_POST['destination_not']) && $ext != "any") {
306
			$natent['destination']['not'] = true;
307
		}
308

    
309
		if ( isset($a_out[$id]['created']) && is_array($a_out[$id]['created']) )
310
			$natent['created'] = $a_out[$id]['created'];
311

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

    
314
		// Allow extending of the firewall edit page and include custom input validation 
315
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aon/pre_write_config");
316

    
317
		if (isset($id) && $a_out[$id]) {
318
			$a_out[$id] = $natent;
319
		} else {
320
			$natent['created'] = make_config_revision_entry();
321
			if (is_numeric($after)) {
322
				array_splice($a_out, $after+1, 0, array($natent));
323
			} else {
324
				$a_out[] = $natent;
325
			}
326
		}
327

    
328
		if (write_config())
329
			mark_subsystem_dirty('natconf');
330
		header("Location: firewall_nat_out.php");
331
		exit;
332
	}
333
}
334

    
335
$pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("Outbound"),gettext("Edit"));
336
$closehead = false;
337
include("head.inc");
338

    
339
?>
340

    
341
<script type="text/javascript" src="/javascript/suggestions.js"></script>
342
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
343
<script type="text/javascript">
344
//<![CDATA[
345
var portsenabled = 1;
346
function staticportchange() {
347
	if(document.iform.staticnatport.checked) {
348
		document.iform.natport.value = "";
349
		document.iform.natport.disabled = 1;
350
	} else {
351
		document.iform.natport.disabled = 0;
352
	}
353
}
354
function typesel_change() {
355
	switch (document.iform.destination_type.selectedIndex) {
356
	case 1: // network
357
		document.iform.destination.disabled = 0;
358
		document.iform.destination_subnet.disabled = 0;
359
		break;
360
	default:
361
		document.iform.destination.value = "";
362
		document.iform.destination.disabled = 1;
363
		document.iform.destination_subnet.value = "24";
364
		document.iform.destination_subnet.disabled = 1;
365
		break;
366
	}
367
}
368
function sourcesel_change() {
369
	switch (document.iform.source_type.selectedIndex) {
370
	case 1: // network
371
		document.iform.source.disabled = 0;
372
		document.iform.source_subnet.disabled = 0;
373
		break;
374
	default:
375
		document.iform.source.value = "";
376
		document.iform.source.disabled = 1;
377
		document.iform.source_subnet.value = "24";
378
		document.iform.source_subnet.disabled = 1;
379
		break;
380
	}
381
}
382
function nonat_change() {
383
	if (document.iform.nonat.checked) {
384
		document.getElementById("transtable").style.display = 'none';
385
	} else {
386
		document.getElementById("transtable").style.display = '';
387
	}
388
}
389
function proto_change() {
390
	if (document.iform.protocol.selectedIndex >= 0 && document.iform.protocol.selectedIndex <= 3) {
391
		portsenabled = 1;
392
	} else {
393
		portsenabled = 0;
394
	}
395

    
396
	if (portsenabled) {
397
		document.getElementById("sport_tr").style.display = '';
398
		document.getElementById("dport_tr").style.display = '';
399
		document.getElementById("tport_tr").style.display = '';
400
		document.getElementById("tporttext_tr").style.display = '';
401
		document.getElementById("tportstatic_tr").style.display = '';
402
	} else {
403
		document.getElementById("sport_tr").style.display = 'none';
404
		document.getElementById("dport_tr").style.display = 'none';
405
		document.getElementById("tport_tr").style.display = 'none';
406
		document.getElementById("tporttext_tr").style.display = 'none';
407
		document.getElementById("tportstatic_tr").style.display = 'none';
408
	}
409
}
410
function poolopts_change() {
411
	if (jQuery('#target option:selected').text().substring(0,4) == "Host") {
412
		jQuery('#poolopts_tr').css('display','');
413
		jQuery('#target_network').css('display','none');
414
	} else if (jQuery('#target option:selected').text().substring(0,6) == "Subnet") {
415
		jQuery('#poolopts_tr').css('display','');
416
		jQuery('#target_network').css('display','none');
417
	} else if (jQuery('#target option:selected').text().substring(0,5) == "Other") {
418
		jQuery('#poolopts_tr').css('display','');
419
		jQuery('#target_network').css('display','');
420
	} else {
421
		jQuery('#poolopts').prop('selectedIndex',0);
422
		jQuery('#poolopts_tr').css('display','none');
423
		jQuery('#target_network').css('display','none');
424
		jQuery('#targetip').val('');
425
		jQuery('#targetip_subnet').val('0');
426
	}
427
}
428
//]]>
429
</script>
430
</head>
431

    
432
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
433
<?php include("fbegin.inc"); ?>
434
<?php if ($input_errors) print_input_errors($input_errors); ?>
435
<form action="firewall_nat_out_edit.php" method="post" name="iform" id="iform">
436
	<table width="100%" border="0" cellpadding="6" cellspacing="1" summary="firewall nat outbound edit">
437
		<tr>
438
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Advanced Outbound NAT entry");?></td>
439
		</tr>
440
<?php
441
		// Allow extending of the firewall edit page and include custom input validation 
442
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphpearly");
443
?>
444
		<tr>
445
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled");?></td>
446
			<td width="78%" class="vtable">
447
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
448
				<strong><?=gettext("Disable this rule");?></strong><br />
449
				<span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list.");?></span>
450
			</td>
451
		</tr>
452
		<tr>
453
			<td width="22%" valign="top" class="vncell"><?=gettext("Do not NAT");?></td>
454
			<td width="78%" class="vtable">
455
				<input type="checkbox" name="nonat" id="nonat" onclick="nonat_change();" <?php if(isset($pconfig['nonat'])) echo " checked=\"checked\""; ?> />
456
				<span class="vexpl"><?=gettext("Enabling this option will disable NAT for traffic matching this rule and stop processing Outbound NAT rules.");?>
457
				<br /><?=gettext("Hint: in most cases, you won't use this option.");?></span>
458
			</td>
459
		</tr>
460
		<tr>
461
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
462
			<td width="78%" class="vtable">
463
				<select name="interface" class="formselect">
464
<?php
465
					$iflist = get_configured_interface_with_descr(false, true);
466
					foreach ($iflist as $if => $ifdesc)
467
						if(have_ruleint_access($if))
468
							$interfaces[$if] = $ifdesc;
469

    
470
					if ($config['l2tp']['mode'] == "server")
471
						if(have_ruleint_access("l2tp"))
472
							$interfaces['l2tp'] = "L2TP VPN";
473

    
474
					if ($config['pptpd']['mode'] == "server")
475
						if(have_ruleint_access("pptp"))
476
							$interfaces['pptp'] = "PPTP VPN";
477

    
478
					if (is_pppoe_server_enabled() && have_ruleint_access("pppoe"))
479
						$interfaces['pppoe'] = "PPPoE VPN";
480

    
481
					/* add ipsec interfaces */
482
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
483
						if(have_ruleint_access("enc0"))
484
							$interfaces["enc0"] = "IPsec";
485

    
486
					/* add openvpn/tun interfaces */
487
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
488
						$interfaces["openvpn"] = "OpenVPN";
489

    
490
					foreach ($interfaces as $iface => $ifacename):
491
?>
492
						<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
493
							<?=htmlspecialchars($ifacename);?>
494
						</option>
495
<?php
496
					endforeach;
497
?>
498
				</select><br />
499
				<span class="vexpl"><?=gettext("Choose which interface this rule applies to.");?><br />
500
					<?=gettext("Hint: in most cases, you'll want to use WAN here.");?>
501
				</span>
502
			</td>
503
		</tr>
504
		<tr>
505
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
506
			<td width="78%" class="vtable">
507
				<select name="protocol" class="formselect" onchange="proto_change();">
508
<?php
509
				$protocols = explode(" ", "any TCP UDP TCP/UDP ICMP ESP AH GRE IPV6 IGMP carp pfsync");
510
				foreach ($protocols as $proto):
511
?>
512
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['protocol']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($proto);?></option>
513
<?php
514
				endforeach;
515
?>
516
				</select><br />
517
				<span class="vexpl"><?=gettext("Choose which protocol this rule should match.");?><br />
518
<?php
519
					printf(gettext("Hint: in most cases, you should specify %s any %s here."),"<em>","</em>&nbsp;");
520
?>
521
				</span>
522
			</td>
523
		</tr>
524
		<tr>
525
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
526
			<td width="78%" class="vtable">
527
				<table border="0" cellspacing="1" cellpadding="1" summary="source">
528
					<tr>
529
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
530
						<td>
531
							<select name="source_type" class="formselect" onchange="sourcesel_change()">
532
								<option value="any" <?php if ($pconfig['source'] == "any") echo "selected=\"selected\""; ?>><?=gettext("any");?></option>
533
								<option value="network" <?php if ($pconfig['source'] != "any") echo "selected=\"selected\""; ?>><?=gettext("Network");?></option>
534
							</select>
535
						</td>
536
					</tr>
537
					<tr>
538
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
539
						<td>
540
							<input name="source" type="text" autocomplete="off" class="formfldalias" id="source" size="20" value="<?=htmlspecialchars($pconfig['source']);?>" />/
541
							<select name="source_subnet" class="formfld" id="source_subnet">
542
<?php
543
							for ($i = 32; $i >= 0; $i--):
544
?>
545
								<option value="<?=$i;?>"<?php if ($i == $pconfig['source_subnet']) echo " selected=\"selected\""; ?>><?=$i;?></option>
546
<?php
547
							endfor;
548
?>
549
							</select>
550
						</td>
551
					</tr>
552
					<tr>
553
						<td>&nbsp;</td>
554
						<td>
555
							<span class="vexpl"><?=gettext("Enter the source network for the outbound NAT mapping.");?></span>
556
						</td>
557
					</tr>
558
					<tr name="sport_tr" id="sport_tr">
559
						<td><?=gettext("Source port:");?>&nbsp;&nbsp;</td>
560
						<td>
561
							<input name="sourceport" type="text" autocomplete="off" class="formfldalias" id="sourceport" size="5" value="<?=htmlspecialchars($pconfig['sourceport']);?>" />
562
							<?=gettext("(leave blank for any)");?>
563
						</td>
564
					</tr>
565
				</table>
566
			</td>
567
		</tr>
568
		<tr>
569
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
570
			<td width="78%" class="vtable">
571
				<input name="destination_not" type="checkbox" id="destination_not" value="yes" <?php if ($pconfig['destination_not']) echo "checked=\"checked\""; ?> />
572
				<strong><?=gettext("not");?></strong><br />
573
				<?=gettext("Use this option to invert the sense of the match.");?><br />
574
				<br />
575
				<table border="0" cellspacing="1" cellpadding="1" summary="destination">
576
					<tr>
577
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
578
						<td>
579
							<select name="destination_type" class="formselect" onchange="typesel_change()">
580
								<option value="any"<?php if ($pconfig['destination'] == "any") echo " selected=\"selected\""; ?>>
581
									<?=gettext("any");?>
582
								</option>
583
								<option value="network"<?php if ($pconfig['destination'] != "any") echo " selected=\"selected\""; ?>>
584
									<?=gettext("Network");?>
585
								</option>
586
							</select>
587
						</td>
588
					</tr>
589
					<tr>
590
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
591
						<td>
592
							<input name="destination" type="text" autocomplete="off" class="formfldalias" id="destination" size="20" value="<?=htmlspecialchars($pconfig['destination']);?>" />/
593
							<select name="destination_subnet" class="formselect" id="destination_subnet">
594
<?php
595
							for ($i = 32; $i >= 0; $i--):
596
?>
597
								<option value="<?=$i;?>"<?php if ($i == $pconfig['destination_subnet']) echo " selected=\"selected\""; ?>><?=$i;?></option>
598
<?php
599
							endfor;
600
?>
601
							</select>
602
						</td>
603
					</tr>
604
					<tr>
605
						<td>&nbsp;</td>
606
						<td>
607
							<span class="vexpl"><?=gettext("Enter the destination network for the outbound NAT mapping.");?></span>
608
						</td>
609
					</tr>
610
					<tr name="dport_tr" id="dport_tr">
611
						<td><?=gettext("Destination port:");?>&nbsp;&nbsp;</td>
612
						<td>
613
							<input name="dstport" type="text" autocomplete="off" class="formfldalias" id="dstport" size="5" value="<?=htmlspecialchars($pconfig['dstport']);?>" />
614
							<?=gettext("(leave blank for any)");?>
615
						</td>
616
					</tr>
617
				</table>
618
			</td>
619
		</tr>
620
		<tr name="transtable" id="transtable">
621
			<td width="22%" valign="top" class="vncell"><?=gettext("Translation");?></td>
622
			<td width="78%" class="vtable">
623
				<table border="0" cellspacing="1" cellpadding="1" summary="translation">
624
					<tr>
625
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
626
						<td>
627
							<select name="target" class="formselect" id="target" onchange="poolopts_change();">
628
								<option value=""<?php if (!$pconfig['target']) echo " selected=\"selected\""; ?>>
629
									<?=gettext("Interface address");?>
630
								</option>
631
<?php
632
								if (is_array($config['virtualip']['vip'])):
633
									foreach ($config['virtualip']['vip'] as $sn):
634
										if (isset($sn['noexpand']))
635
											continue;
636
										if ($sn['mode'] == "proxyarp" && $sn['type'] == "network"):
637
											$start = ip2long32(gen_subnet($sn['subnet'], $sn['subnet_bits']));
638
											$end = ip2long32(gen_subnet_max($sn['subnet'], $sn['subnet_bits']));
639
											$len = $end - $start;
640
?>
641
								<option value="<?=$sn['subnet'].'/'.$sn['subnet_bits'];?>" <?php if ($sn['subnet'].'/'.$sn['subnet_bits'] == $pconfig['target']) echo "selected=\"selected\""; ?>>
642
									<?=htmlspecialchars("Subnet: {$sn['subnet']}/{$sn['subnet_bits']} ({$sn['descr']})");?>
643
								</option>
644
<?php
645
											for ($i = 0; $i <= $len; $i++):
646
												$snip = long2ip32($start+$i);
647
?>
648
								<option value="<?=$snip;?>" <?php if ($snip == $pconfig['target']) echo "selected"; ?>>
649
									<?=htmlspecialchars("{$snip} ({$sn['descr']})");?>
650
								</option>
651
<?php
652
											endfor;
653
?>
654
<?php
655
										else:
656
?>
657
								<option value="<?=$sn['subnet'];?>" <?php if ($sn['subnet'] == $pconfig['target']) echo "selected=\"selected\""; ?>>
658
									<?=htmlspecialchars("{$sn['subnet']} ({$sn['descr']})");?>
659
								</option>
660
<?php
661
										endif;
662
									endforeach;
663
								endif;
664
								foreach ($a_aliases as $alias):
665
									if ($alias['type'] != "host")
666
										continue;
667
?>
668
								<option value="<?=$alias['name'];?>" <?php if ($alias['name'] == $pconfig['target']) echo "selected=\"selected\""; ?>>
669
									<?=htmlspecialchars("Host Alias: {$alias['name']} ({$alias['descr']})");?>
670
								</option>
671
<?php
672
								endforeach;
673
?>
674
								<option value="other-subnet"<?php if($pconfig['target'] == "other-subnet") echo " selected=\"selected\""; ?>>
675
									<?=gettext("Other Subnet (Enter Below)");?>
676
								</option>
677
							</select>
678
						</td>
679
					</tr>
680

    
681
					<tr id="target_network">
682
						<td><?=gettext("Other Subnet:");?>&nbsp;&nbsp;</td>
683
						<td>
684
							<input name="targetip" type="text" class="formfld unknown" id="targetip" size="20" value="<?=htmlspecialchars($pconfig['targetip']);?>" />/
685
							<select name="targetip_subnet" class="formfld" id="targetip_subnet">
686
<?php
687
							for ($i = 32; $i >= 0; $i--):
688
?>
689
								<option value="<?=$i;?>"<?php if ($i == $pconfig['targetip_subnet']) echo " selected=\"selected\""; ?>><?=$i;?></option>
690
<?php
691
							endfor;
692
?>
693
							</select>
694
						</td>
695
					</tr>
696

    
697
					<tr>
698
						<td>&nbsp;</td>
699
						<td>
700
							<span class="vexpl"><?=gettext("Packets matching this rule will be mapped to the IP address given here.");?><br />
701
								<?=gettext("If you want this rule to apply to another IP address rather than the IP address of the interface chosen above, ".
702
								"select it here (you will need to define ");?>
703
								<a href="firewall_virtual_ip.php"><?=gettext("Virtual IP");?></a>
704
								<?=gettext("addresses on the interface first).");?>
705
							</span><br />
706
						</td>
707
					</tr>
708
					<tr id="poolopts_tr">
709
						<td valign="top">Pool Options</td>
710
						<td>
711
							<select name="poolopts" id="poolopts">
712
								<option value="" <?php if ($pconfig['poolopts'] == "") echo "selected=\"selected\""; ?>>
713
									<?=htmlspecialchars("Default");?>
714
								</option>
715
								<option value="round-robin" <?php if ($pconfig['poolopts'] == "round-robin") echo "selected=\"selected\""; ?>>
716
									<?=htmlspecialchars("Round Robin");?>
717
								</option>
718
								<option value="round-robin sticky-address" <?php if ($pconfig['poolopts'] == "round-robin sticky-address") echo "selected=\"selected\""; ?>>
719
									<?=htmlspecialchars("Round Robin with Sticky Address");?>
720
								</option>
721
								<option value="random" <?php if ($pconfig['poolopts'] == "random") echo "selected=\"selected\""; ?>>
722
									<?=htmlspecialchars("Random");?>
723
								</option>
724
								<option value="random sticky-address" <?php if ($pconfig['poolopts'] == "random sticky-address") echo "selected=\"selected\""; ?>>
725
									<?=htmlspecialchars("Random with Sticky Address");?>
726
								</option>
727
								<option value="source-hash" <?php if ($pconfig['poolopts'] == "source-hash") echo "selected=\"selected\""; ?>>
728
									<?=htmlspecialchars("Source Hash");?>
729
								</option>
730
								<option value="bitmask" <?php if ($pconfig['poolopts'] == "bitmask") echo "selected=\"selected\""; ?>>
731
									<?=htmlspecialchars("Bitmask");?>
732
								</option>
733
							</select>
734
							<br />
735
							<span class="vexpl">
736
								<?=gettext("Only Round Robin types work with Host Aliases. Any type can be used with a Subnet.");?><br />
737
								* <?=gettext("Round Robin: Loops through the translation addresses.");?><br />
738
								* <?=gettext("Random: Selects an address from the translation address pool at random.");?><br />
739
								* <?=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 />
740
								* <?=gettext("Bitmask: Applies the subnet mask and keeps the last portion identical; 10.0.1.50 -&gt; x.x.x.50.");?><br />
741
								* <?=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 />
742
							</span><br />
743
						</td>
744
					</tr>
745
					<tr name="tport_tr" id="tport_tr">
746
						<td><?=gettext("Port:");?>&nbsp;&nbsp;</td>
747
						<td>
748
							<input name="natport" type="text" class="formfld unknown" id="natport" size="5" value="<?=htmlspecialchars($pconfig['natport']);?>" />
749
						</td>
750
					</tr>
751
					<tr name="tporttext_tr" id="tporttext_tr">
752
						<td>&nbsp;</td>
753
						<td>
754
							<span class="vexpl"><?=gettext("Enter the source port for the outbound NAT mapping.");?></span>
755
						</td>
756
					</tr>
757
					<tr name="tportstatic_tr" id="tportstatic_tr">
758
						<td><?=gettext("Static-port:");?>&nbsp;&nbsp;</td>
759
						<td><input onchange="staticportchange();" name="staticnatport" type="checkbox" class="formfld" id="staticnatport" size="5"<?php if($pconfig['staticnatport']) echo " checked=\"checked\"";?> /></td>
760
					</tr>
761
				</table>
762
			</td>
763
		</tr>
764
		<tr>
765
			<td width="22%" valign="top" class="vncell"><?=gettext("No XMLRPC Sync");?></td>
766
			<td width="78%" class="vtable">
767
				<input value="yes" name="nosync" type="checkbox" class="formfld" id="nosync"<?php if($pconfig['nosync']) echo " checked=\"checked\""; ?> /><br />
768
				<?=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.");?>
769
			</td>
770
		</tr>
771
		<tr>
772
			<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
773
			<td width="78%" class="vtable">
774
				<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
775
				<br />
776
				<span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed).");?></span>
777
			</td>
778
		</tr>
779
<?php
780
	$has_created_time = (isset($a_out[$id]['created']) && is_array($a_out[$id]['created']));
781
	$has_updated_time = (isset($a_out[$id]['updated']) && is_array($a_out[$id]['updated']));
782
	if ($has_created_time || $has_updated_time):
783
?>
784
		<tr>
785
			<td>&nbsp;</td>
786
		</tr>
787
		<tr>
788
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Rule Information");?></td>
789
		</tr>
790
<?php
791
		if ($has_created_time):
792
?>
793
		<tr>
794
			<td width="22%" valign="top" class="vncell"><?=gettext("Created");?></td>
795
			<td width="78%" class="vtable">
796
				<?= date(gettext("n/j/y H:i:s"), $a_out[$id]['created']['time']) ?> <?= gettext("by") ?> <strong><?= $a_out[$id]['created']['username'] ?></strong>
797
			</td>
798
		</tr>
799
<?php
800
		endif;
801

    
802
		if ($has_updated_time):
803
?>
804
		<tr>
805
			<td width="22%" valign="top" class="vncell"><?=gettext("Updated");?></td>
806
			<td width="78%" class="vtable">
807
				<?= date(gettext("n/j/y H:i:s"), $a_out[$id]['updated']['time']) ?> <?= gettext("by") ?> <strong><?= $a_out[$id]['updated']['username'] ?></strong>
808
			</td>
809
		</tr>
810
<?php
811
		endif;
812
	endif;
813
	// Allow extending of the firewall edit page and include custom input validation 
814
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aon/htmlphplate");
815
?>
816
		<tr>
817
			<td width="22%" valign="top">&nbsp;</td>
818
			<td width="78%">
819
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /> <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="history.back()" />
820
<?php
821
			if (isset($id) && $a_out[$id]):
822
?>
823
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
824
<?php
825
			endif;
826
?>
827
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>" />
828
			</td>
829
		</tr>
830
	</table>
831
</form>
832
<script type="text/javascript">
833
//<![CDATA[
834
	sourcesel_change();
835
	typesel_change();
836
	staticportchange();
837
	nonat_change();
838
	proto_change();
839
	poolopts_change();
840

    
841
	var addressarray = <?= json_encode(get_alias_list(array("host", "network", "openvpn", "urltable"))) ?>;
842
	var customarray  = <?= json_encode(get_alias_list(array("port", "url_ports", "urltable_ports"))) ?>;
843

    
844
	var oTextbox1 = new AutoSuggestControl(document.getElementById("source"), new StateSuggestions(addressarray));
845
	var oTextbox2 = new AutoSuggestControl(document.getElementById("sourceport"), new StateSuggestions(customarray));
846
	var oTextbox3 = new AutoSuggestControl(document.getElementById("destination"), new StateSuggestions(addressarray));
847
	var oTextbox4 = new AutoSuggestControl(document.getElementById("dstport"), new StateSuggestions(customarray));
848
//]]>
849
</script>
850
<?php include("fend.inc"); ?>
851
</body>
852
</html>
(68-68/254)