Project

General

Profile

Download (80.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules_edit.php
5
	part of pfSense (https://www.pfsense.org)
6
	Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
8

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

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

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

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

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

    
38
##|+PRIV
39
##|*IDENT=page-firewall-rules-edit
40
##|*NAME=Firewall: Rules: Edit page
41
##|*DESCR=Allow access to the 'Firewall: Rules: Edit' page.
42
##|*MATCH=firewall_rules_edit.php*
43
##|-PRIV
44

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

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

    
51
function is_posnumericint($arg) {
52
	// Note that to be safe we do not allow any leading zero - "01", "007"
53
	return (is_numericint($arg) && $arg[0] != '0' && $arg > 0);
54
}
55

    
56
function is_aoadv_used($rule_config) {
57
	// Note that the user could set "tag" or "tagged" to the string "0", which is valid but empty().
58
	// And if the user enters "0" in other fields, we want to present an error message, and keep the Advanced Options section open.
59
	if ((isset($rule_config['allowopts'])) ||
60
	    (isset($rule_config['disablereplyto'])) ||
61
	    ($rule_config['tag'] != "") ||
62
	    ($rule_config['tagged'] != "") ||
63
	    ($rule_config['max'] != "") ||
64
	    ($rule_config['max-src-nodes'] != "") ||
65
	    ($rule_config['max-src-conn'] != "") ||
66
	    ($rule_config['max-src-states'] != "") ||
67
	    ($rule_config['max-src-conn-rate'] != "") ||
68
	    ($rule_config['max-src-conn-rates'] != "") ||
69
	    ($rule_config['statetimeout'] != ""))
70
		return true;
71
	return false;
72
}
73

    
74
$ostypes = array();
75
exec('/sbin/pfctl -s osfp | /usr/bin/tr \'\t\' \' \'', $ostypes);
76

    
77
if (count($ostypes) > 2) {
78
	// Remove header rows from pfctl output
79
	array_shift($ostypes);
80
	array_shift($ostypes);
81
} else {
82
	// Fall back to a default list
83
	$ostypes = array(
84
		"AIX",
85
		"Linux",
86
		"FreeBSD",
87
		"NetBSD",
88
		"OpenBSD",
89
		"Solaris",
90
		"MacOS",
91
		"Windows",
92
		"Novell",
93
		"NMAP"
94
	);
95
}
96

    
97
$specialsrcdst = explode(" ", "any (self) pptp pppoe l2tp openvpn");
98
$ifdisp = get_configured_interface_with_descr();
99
foreach ($ifdisp as $kif => $kdescr) {
100
	$specialsrcdst[] = "{$kif}";
101
	$specialsrcdst[] = "{$kif}ip";
102
}
103

    
104
if (!is_array($config['filter']['rule'])) {
105
	$config['filter']['rule'] = array();
106
}
107
filter_rules_sort();
108
$a_filter = &$config['filter']['rule'];
109

    
110
if (is_numericint($_GET['id']))
111
	$id = $_GET['id'];
112
if (isset($_POST['id']) && is_numericint($_POST['id']))
113
	$id = $_POST['id'];
114

    
115
if (is_numericint($_GET['after']) || $_GET['after'] == "-1")
116
	$after = $_GET['after'];
117
if (isset($_POST['after']) && (is_numericint($_POST['after']) || $_POST['after'] == "-1"))
118
	$after = $_POST['after'];
119

    
120
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) {
121
        $id = $_GET['dup'];
122
        $after = $_GET['dup'];
123
}
124

    
125
if (isset($id) && $a_filter[$id]) {
126
	$pconfig['interface'] = $a_filter[$id]['interface'];
127

    
128
	if (isset($a_filter[$id]['id']))
129
		$pconfig['ruleid'] = $a_filter[$id]['id'];
130

    
131
	if ( isset($a_filter[$id]['created']) && is_array($a_filter[$id]['created']) )
132
		$pconfig['created'] = $a_filter[$id]['created'];
133

    
134
	if ( isset($a_filter[$id]['updated']) && is_array($a_filter[$id]['updated']) )
135
		$pconfig['updated'] = $a_filter[$id]['updated'];
136

    
137
	if (!isset($a_filter[$id]['type']))
138
		$pconfig['type'] = "pass";
139
	else
140
		$pconfig['type'] = $a_filter[$id]['type'];
141

    
142
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
143
		$pconfig['floating'] = $a_filter[$id]['floating'];
144
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "")
145
			$pconfig['interface'] = $a_filter[$id]['interface'];
146
	}
147

    
148
	if (isset($a_filter['floating']))
149
		$pconfig['floating'] = "yes";
150

    
151
	if (isset($a_filter[$id]['direction']))
152
		$pconfig['direction'] = $a_filter[$id]['direction'];
153

    
154
	if (isset($a_filter[$id]['ipprotocol']))
155
		$pconfig['ipprotocol'] = $a_filter[$id]['ipprotocol'];
156

    
157
	if (isset($a_filter[$id]['protocol']))
158
		$pconfig['proto'] = $a_filter[$id]['protocol'];
159
	else
160
		$pconfig['proto'] = "any";
161

    
162
	if ($a_filter[$id]['protocol'] == "icmp")
163
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
164

    
165
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
166
		$pconfig['srcmask'], $pconfig['srcnot'],
167
		$pconfig['srcbeginport'], $pconfig['srcendport']);
168

    
169
	if($a_filter[$id]['os'] <> "")
170
		$pconfig['os'] = $a_filter[$id]['os'];
171

    
172
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
173
		$pconfig['dstmask'], $pconfig['dstnot'],
174
		$pconfig['dstbeginport'], $pconfig['dstendport']);
175

    
176
	if ($a_filter[$id]['dscp'] <> "")
177
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
178

    
179
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
180
	$pconfig['log'] = isset($a_filter[$id]['log']);
181
	$pconfig['descr'] = $a_filter[$id]['descr'];
182

    
183
	if (isset($a_filter[$id]['tcpflags_any']))
184
		$pconfig['tcpflags_any'] = true;
185
	else {
186
		if (isset($a_filter[$id]['tcpflags1']) && $a_filter[$id]['tcpflags1'] <> "")
187
			$pconfig['tcpflags1'] = $a_filter[$id]['tcpflags1'];
188
		if (isset($a_filter[$id]['tcpflags2']) && $a_filter[$id]['tcpflags2'] <> "")
189
			$pconfig['tcpflags2'] = $a_filter[$id]['tcpflags2'];
190
	}
191

    
192
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "")
193
		$pconfig['tag'] = $a_filter[$id]['tag'];
194
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tagged'] <> "")
195
		$pconfig['tagged'] = $a_filter[$id]['tagged'];
196
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
197
		$pconfig['quick'] = $a_filter[$id]['quick'];
198
	if (isset($a_filter[$id]['allowopts']))
199
		$pconfig['allowopts'] = true;
200
	if (isset($a_filter[$id]['disablereplyto']))
201
		$pconfig['disablereplyto'] = true;
202

    
203
	/* advanced */
204
	$pconfig['max'] = $a_filter[$id]['max'];
205
	$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
206
	$pconfig['max-src-conn'] = $a_filter[$id]['max-src-conn'];
207
	$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
208
	$pconfig['statetype'] = $a_filter[$id]['statetype'];
209
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
210
	$pconfig['nopfsync'] = isset($a_filter[$id]['nopfsync']);
211

    
212
	/* advanced - nosync */
213
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
214

    
215
	/* advanced - new connection per second banning*/
216
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
217
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
218

    
219
	/* Multi-WAN next-hop support */
220
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
221

    
222
	/* Shaper support */
223
	$pconfig['defaultqueue'] = (($a_filter[$id]['ackqueue'] == "none") ? '' : $a_filter[$id]['defaultqueue']);
224
	$pconfig['ackqueue'] = (($a_filter[$id]['ackqueue'] == "none") ? '' : $a_filter[$id]['ackqueue']);
225
	$pconfig['dnpipe'] = (($a_filter[$id]['dnpipe'] == "none") ? '' : $a_filter[$id]['dnpipe']);
226
	$pconfig['pdnpipe'] = (($a_filter[$id]['pdnpipe'] == "none") ? '' : $a_filter[$id]['pdnpipe']);
227
	$pconfig['l7container'] = (($a_filter[$id]['l7container'] == "none") ? '' : $a_filter[$id]['l7container']);
228

    
229
	//schedule support
230
	$pconfig['sched'] = (($a_filter[$id]['sched'] == "none") ? '' : $a_filter[$id]['sched']);
231
	$pconfig['vlanprio'] = (($a_filter[$id]['vlanprio'] == "none") ? '' : $a_filter[$id]['vlanprio']);
232
	$pconfig['vlanprioset'] = (($a_filter[$id]['vlanprioset'] == "none") ? '' : $a_filter[$id]['vlanprioset']);
233
	if (!isset($_GET['dup']) || !is_numericint($_GET['dup']))
234
		$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
235

    
236
	$pconfig['tracker'] = $a_filter[$id]['tracker'];
237

    
238
} else {
239
	/* defaults */
240
	if ($_GET['if'])
241
		$pconfig['interface'] = $_GET['if'];
242
	$pconfig['type'] = "pass";
243
	$pconfig['src'] = "any";
244
	$pconfig['dst'] = "any";
245
}
246
/* Allow the FloatingRules to work */
247
$if = $pconfig['interface'];
248

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

    
252
read_altq_config(); /* XXX: */
253
$qlist =& get_unique_queue_list();
254
read_dummynet_config(); /* XXX: */
255
$dnqlist =& get_unique_dnqueue_list();
256
read_layer7_config();
257
$l7clist =& get_l7_unique_list();
258
$a_gatewaygroups = return_gateway_groups_array();
259

    
260
if ($_POST) {
261
	unset($input_errors);
262

    
263
	if( isset($a_filter[$id]['associated-rule-id']) ) {
264
		$_POST['proto'] = $pconfig['proto'];
265
		if ($pconfig['proto'] == "icmp")
266
			$_POST['icmptype'] = $pconfig['icmptype'];
267
	}
268

    
269
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "")) {
270
		if(is_array($config['gateways']['gateway_group'])) {
271
			foreach($config['gateways']['gateway_group'] as $gw_group) {
272
				if($gw_group['name'] == $_POST['gateway']) {
273
					$family = $a_gatewaygroups[$_POST['gateway']]['ipprotocol'];
274
					if($_POST['ipprotocol'] == $family) {
275
						continue;
276
					}
277
					if(($_POST['ipprotocol'] == "inet46") && ($_POST['ipprotocol'] != $family)) {
278
						$input_errors[] = gettext("You can not assign a gateway to a rule that applies to IPv4 and IPv6");
279
					}
280
					if(($_POST['ipprotocol'] == "inet6") && ($_POST['ipprotocol'] != $family)) {
281
						$input_errors[] = gettext("You can not assign an IPv4 gateway group on IPv6 Address Family rule");
282
					}
283
					if(($_POST['ipprotocol'] == "inet") && ($_POST['ipprotocol'] != $family)) {
284
						$input_errors[] = gettext("You can not assign an IPv6 gateway group on IPv4 Address Family rule");
285
					}
286
				}
287
			}
288
		}
289
	}
290
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "") && (is_ipaddr(lookup_gateway_ip_by_name($_POST['gateway'])))) {
291
		if(($_POST['ipprotocol'] == "inet46") && ($_POST['gateway'] <> "")) {
292
			$input_errors[] = gettext("You can not assign a gateway to a rule that applies to IPv4 and IPv6");
293
		}
294
		if(($_POST['ipprotocol'] == "inet6") && (!is_ipaddrv6(lookup_gateway_ip_by_name($_POST['gateway'])))) {
295
			$input_errors[] = gettext("You can not assign an IPv4 Gateway to an IPv6 Filter rule");
296
		}
297
		if(($_POST['ipprotocol'] == "inet") && (!is_ipaddrv4(lookup_gateway_ip_by_name($_POST['gateway'])))) {
298
			$input_errors[] = gettext("You can not assign an IPv6 Gateway to an IPv4 Filter rule");
299
		}
300
	}
301

    
302
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp") && ($_POST['proto'] != "icmp")) {
303
		if($_POST['ipprotocol'] == "inet46")
304
			$input_errors[] =  gettext("You can not assign a protocol other than ICMP, TCP, UDP or TCP/UDP to a rule that applies to IPv4 and IPv6");
305
	}
306
	if (($_POST['proto'] == "icmp") && ($_POST['icmptype'] <> "")){
307
		if($_POST['ipprotocol'] == "inet46")
308
			$input_errors[] =  gettext("You can not assign a ICMP type to a rule that applies to IPv4 and IPv6");
309
	}
310

    
311
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
312
		$_POST['srcbeginport'] = 0;
313
		$_POST['srcendport'] = 0;
314
		$_POST['dstbeginport'] = 0;
315
		$_POST['dstendport'] = 0;
316
	} else {
317
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
318
			$_POST['srcbeginport'] = trim($_POST['srcbeginport_cust']);
319
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
320
			$_POST['srcendport'] = trim($_POST['srcendport_cust']);
321
		if ($_POST['srcbeginport'] == "any") {
322
			$_POST['srcbeginport'] = 0;
323
			$_POST['srcendport'] = 0;
324
		} else {
325
			if (!$_POST['srcendport'])
326
				$_POST['srcendport'] = $_POST['srcbeginport'];
327
		}
328
		if ($_POST['srcendport'] == "any")
329
			$_POST['srcendport'] = $_POST['srcbeginport'];
330

    
331
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
332
			$_POST['dstbeginport'] = trim($_POST['dstbeginport_cust']);
333
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
334
			$_POST['dstendport'] = trim($_POST['dstendport_cust']);
335

    
336
		if ($_POST['dstbeginport'] == "any") {
337
			$_POST['dstbeginport'] = 0;
338
			$_POST['dstendport'] = 0;
339
		} else {
340
			if (!$_POST['dstendport'])
341
				$_POST['dstendport'] = $_POST['dstbeginport'];
342
		}
343
		if ($_POST['dstendport'] == "any")
344
			$_POST['dstendport'] = $_POST['dstbeginport'];
345
	}
346

    
347
	if (is_specialnet($_POST['srctype'])) {
348
		$_POST['src'] = $_POST['srctype'];
349
		$_POST['srcmask'] = 0;
350
	} else if ($_POST['srctype'] == "single") {
351
		if (is_ipaddrv6($_POST['src']))
352
			$_POST['srcmask'] = 128;
353
		else
354
			$_POST['srcmask'] = 32;
355
	}
356
	if (is_specialnet($_POST['dsttype'])) {
357
		$_POST['dst'] = $_POST['dsttype'];
358
		$_POST['dstmask'] = 0;
359
	}  else if ($_POST['dsttype'] == "single") {
360
		if (is_ipaddrv6($_POST['dst']))
361
			$_POST['dstmask'] = 128;
362
		else
363
			$_POST['dstmask'] = 32;
364
	}
365

    
366
	$pconfig = $_POST;
367

    
368
	/* input validation */
369
	$reqdfields = explode(" ", "type proto");
370
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
371
		$reqdfields[] = "src";
372
		$reqdfields[] = "dst";
373
	}
374
	$reqdfieldsn = explode(",", "Type,Protocol");
375
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
376
		$reqdfieldsn[] = "Source";
377
		$reqdfieldsn[] = "Destination";
378
	}
379

    
380
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
381
		if( $_POST['proto'] != "tcp" )
382
			$input_errors[] = sprintf(gettext("%s is only valid with protocol tcp."),$_POST['statetype']);
383
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
384
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
385
	}
386

    
387
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
388
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
389
		$reqdfields[] = "srcmask";
390
		$reqdfieldsn[] = "Source bit count";
391
	}
392
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
393
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
394
		$reqdfields[] = "dstmask";
395
		$reqdfieldsn[] = gettext("Destination bit count");
396
	}
397

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

    
400
	if (!$_POST['srcbeginport']) {
401
		$_POST['srcbeginport'] = 0;
402
		$_POST['srcendport'] = 0;
403
	}
404
	if (!$_POST['dstbeginport']) {
405
		$_POST['dstbeginport'] = 0;
406
		$_POST['dstendport'] = 0;
407
	}
408

    
409
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
410
		$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['srcbeginposrt']);
411
	if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
412
			$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']);
413
	if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
414
			$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']);
415
	if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
416
			$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']);
417
	if ( !$_POST['srcbeginport_cust'] && $_POST['srcendport_cust'])
418
		if (is_alias($_POST['srcendport_cust']))
419
			$input_errors[] = 'If you put port alias in Source port range to: field you must put the same port alias in from: field';
420
	if ( $_POST['srcbeginport_cust'] && $_POST['srcendport_cust']){
421
		if (is_alias($_POST['srcendport_cust']) && is_alias($_POST['srcendport_cust']) && $_POST['srcbeginport_cust'] != $_POST['srcendport_cust'])
422
			$input_errors[] = 'The same port alias must be used in Source port range from: and to: fields';
423
		if ((is_alias($_POST['srcbeginport_cust']) && (!is_alias($_POST['srcendport_cust']) && $_POST['srcendport_cust']!='')) ||
424
		    ((!is_alias($_POST['srcbeginport_cust']) && $_POST['srcbeginport_cust']!='') && is_alias($_POST['srcendport_cust'])))
425
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Source port range from: and to: field';
426
	}
427
	if ( !$_POST['dstbeginport_cust'] && $_POST['dstendport_cust'])
428
		if (is_alias($_POST['dstendport_cust']))
429
			$input_errors[] = 'If you put port alias in Destination port range to: field you must put the same port alias in from: field';
430
	if ( $_POST['dstbeginport_cust'] && $_POST['dstendport_cust']){
431
		if (is_alias($_POST['dstendport_cust']) && is_alias($_POST['dstendport_cust']) && $_POST['dstbeginport_cust'] != $_POST['dstendport_cust'])
432
			$input_errors[] = 'The same port alias must be used in Destination port range from: and to: fields';
433
		if ((is_alias($_POST['dstbeginport_cust']) && (!is_alias($_POST['dstendport_cust']) && $_POST['dstendport_cust']!='')) ||
434
		    ((!is_alias($_POST['dstbeginport_cust']) && $_POST['dstbeginport_cust']!='') && is_alias($_POST['dstendport_cust'])))
435
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Destination port range from: and to: field';
436
	}
437

    
438
	if ($_POST['src'])
439
		$_POST['src'] = trim($_POST['src']);
440
	if ($_POST['dst'])
441
		$_POST['dst'] = trim($_POST['dst']);
442

    
443
	/* if user enters an alias and selects "network" then disallow. */
444
	if($_POST['srctype'] == "network") {
445
		if(is_alias($_POST['src']))
446
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
447
	}
448
	if($_POST['dsttype'] == "network") {
449
		if(is_alias($_POST['dst']))
450
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
451
	}
452

    
453
	if (!is_specialnet($_POST['srctype'])) {
454
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
455
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."),$_POST['src']);
456
		}
457
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
458
			$input_errors[] = gettext("A valid source bit count must be specified.");
459
		}
460
	}
461
	if (!is_specialnet($_POST['dsttype'])) {
462
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
463
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."),$_POST['dst']);
464
		}
465
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
466
			$input_errors[] = gettext("A valid destination bit count must be specified.");
467
		}
468
	}
469
	if((is_ipaddr($_POST['src']) && is_ipaddr($_POST['dst']))) {
470
		if(!validate_address_family($_POST['src'], $_POST['dst']))
471
			$input_errors[] = sprintf(gettext("The Source IP address %s Address Family differs from the destination %s."), $_POST['src'], $_POST['dst']);
472
		if((is_ipaddrv6($_POST['src']) || is_ipaddrv6($_POST['dst'])) && ($_POST['ipprotocol'] == "inet"))
473
			$input_errors[] = gettext("You can not use IPv6 addresses in IPv4 rules.");
474
		if((is_ipaddrv4($_POST['src']) || is_ipaddrv4($_POST['dst'])) && ($_POST['ipprotocol'] == "inet6"))
475
			$input_errors[] = gettext("You can not use IPv4 addresses in IPv6 rules.");
476
	}
477

    
478
	if((is_ipaddr($_POST['src']) || is_ipaddr($_POST['dst'])) && ($_POST['ipprotocol'] == "inet46"))
479
		$input_errors[] = gettext("You can not use a IPv4 or IPv6 address in combined IPv4 + IPv6 rules.");
480

    
481
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
482
		/* swap */
483
		$tmp = $_POST['srcendport'];
484
		$_POST['srcendport'] = $_POST['srcbeginport'];
485
		$_POST['srcbeginport'] = $tmp;
486
	}
487
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
488
		/* swap */
489
		$tmp = $_POST['dstendport'];
490
		$_POST['dstendport'] = $_POST['dstbeginport'];
491
		$_POST['dstbeginport'] = $tmp;
492
	}
493
	if ($_POST['os']) {
494
		if( $_POST['proto'] != "tcp" )
495
			$input_errors[] = gettext("OS detection is only valid with protocol tcp.");
496
		if (!in_array($_POST['os'], $ostypes))
497
			$input_errors[] = gettext("Invalid OS detection selection. Please select a valid OS.");
498
	}
499

    
500
	if ($_POST['ackqueue'] != "") {
501
		if ($_POST['defaultqueue'] == "" )
502
			$input_errors[] = gettext("You have to select a queue when you select an acknowledge queue too.");
503
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
504
			$input_errors[] = gettext("Acknowledge queue and Queue cannot be the same.");
505
	}
506
	if (isset($_POST['floating']) && $_POST['pdnpipe'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
507
		$input_errors[] = gettext("You can not use limiters in Floating rules without choosing a direction.");
508
	if (isset($_POST['floating']) && $_POST['gateway'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
509
		$input_errors[] = gettext("You can not use gateways in Floating rules without choosing a direction.");
510
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "") {
511
		if ($_POST['dnpipe'] == "" )
512
			$input_errors[] = gettext("You must select a queue for the In direction before selecting one for Out too.");
513
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
514
			$input_errors[] = gettext("In and Out Queue cannot be the same.");
515
		else if ($dnqlist[$_POST['pdnpipe']][0] == "?" && $dnqlist[$_POST['dnpipe']][0] <> "?")
516
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. Both must be from the same type.");
517
		else if ($dnqlist[$_POST['dnpipe']][0] == "?" && $dnqlist[$_POST['pdnpipe']][0] <> "?")
518
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. Both must be from the same type.");
519
		if ($_POST['direction'] == "out" && empty($_POST['gateway']))
520
			$input_errors[] = gettext("Please select a gateway, normally the interface selected gateway, so the limiters work correctly");
521
	}
522
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
523
		$input_errors[] = gettext('ID must be an integer');
524
	if($_POST['l7container'] && $_POST['l7container'] != "") {
525
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
526
			$input_errors[] = gettext("You can only select a layer7 container for TCP and/or UDP protocols");
527
		if ($_POST['type'] <> "pass")
528
			$input_errors[] = gettext("You can only select a layer7 container for Pass type rules.");
529
	}
530

    
531
	if (!in_array($_POST['proto'], array("tcp","tcp/udp"))) {
532
		if (!empty($_POST['max-src-conn']))
533
			$input_errors[] = gettext("You can only specify the maximum number of established connections per host (advanced option) for TCP protocol.");
534
		if (!empty($_POST['max-src-conn-rate']) || !empty($_POST['max-src-conn-rates']))
535
			$input_errors[] = gettext("You can only specify the maximum new connections per host / per second(s) (advanced option) for TCP protocol.");
536
		if (!empty($_POST['statetimeout']))
537
			$input_errors[] = gettext("You can only specify the state timeout (advanced option) for TCP protocol.");
538
	}
539

    
540
	if ($_POST['type'] <> "pass") {
541
		if (!empty($_POST['max']))
542
			$input_errors[] = gettext("You can only specify the maximum state entries (advanced option) for Pass type rules.");
543
		if (!empty($_POST['max-src-nodes']))
544
			$input_errors[] = gettext("You can only specify the maximum number of unique source hosts (advanced option) for Pass type rules.");
545
		if (!empty($_POST['max-src-conn']))
546
			$input_errors[] = gettext("You can only specify the maximum number of established connections per host (advanced option) for Pass type rules.");
547
		if (!empty($_POST['max-src-states']))
548
			$input_errors[] = gettext("You can only specify the maximum state entries per host (advanced option) for Pass type rules.");
549
		if (!empty($_POST['max-src-conn-rate']) || !empty($_POST['max-src-conn-rates']))
550
			$input_errors[] = gettext("You can only specify the maximum new connections per host / per second(s) (advanced option) for Pass type rules.");
551
		if (!empty($_POST['statetimeout']))
552
			$input_errors[] = gettext("You can only specify the state timeout (advanced option) for Pass type rules.");
553
	}
554

    
555
	if (($_POST['statetype'] == "none") && (empty($_POST['l7container']))) {
556
		if (!empty($_POST['max']))
557
			$input_errors[] = gettext("You cannot specify the maximum state entries (advanced option) if statetype is none and no L7 container is selected.");
558
		if (!empty($_POST['max-src-nodes']))
559
			$input_errors[] = gettext("You cannot specify the maximum number of unique source hosts (advanced option) if statetype is none and no L7 container is selected.");
560
		if (!empty($_POST['max-src-conn']))
561
			$input_errors[] = gettext("You cannot specify the maximum number of established connections per host (advanced option) if statetype is none and no L7 container is selected.");
562
		if (!empty($_POST['max-src-states']))
563
			$input_errors[] = gettext("You cannot specify the maximum state entries per host (advanced option) if statetype is none and no L7 container is selected.");
564
		if (!empty($_POST['max-src-conn-rate']) || !empty($_POST['max-src-conn-rates']))
565
			$input_errors[] = gettext("You cannot specify the maximum new connections per host / per second(s) (advanced option) if statetype is none and no L7 container is selected.");
566
		if (!empty($_POST['statetimeout']))
567
			$input_errors[] = gettext("You cannot specify the state timeout (advanced option) if statetype is none and no L7 container is selected.");
568
	}
569

    
570
	if (($_POST['max'] != "") && !is_posnumericint($_POST['max']))
571
		$input_errors[] = gettext("Maximum state entries (advanced option) must be a positive integer");
572

    
573
	if (($_POST['max-src-nodes'] != "") && !is_posnumericint($_POST['max-src-nodes']))
574
		$input_errors[] = gettext("Maximum number of unique source hosts (advanced option) must be a positive integer");
575

    
576
	if (($_POST['max-src-conn'] != "") && !is_posnumericint($_POST['max-src-conn']))
577
		$input_errors[] = gettext("Maximum number of established connections per host (advanced option) must be a positive integer");
578

    
579
	if (($_POST['max-src-states'] != "") && !is_posnumericint($_POST['max-src-states']))
580
		$input_errors[] = gettext("Maximum state entries per host (advanced option) must be a positive integer");
581

    
582
	if (($_POST['max-src-conn-rate'] != "") && !is_posnumericint($_POST['max-src-conn-rate']))
583
		$input_errors[] = gettext("Maximum new connections per host / per second(s) (advanced option) must be a positive integer");
584

    
585
	if (($_POST['statetimeout'] != "") && !is_posnumericint($_POST['statetimeout']))
586
		$input_errors[] = gettext("State timeout (advanced option) must be a positive integer");
587

    
588
	if ((($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] == "")) || 
589
	    (($_POST['max-src-conn-rate'] == "" and $_POST['max-src-conn-rates'] <> "")))
590
		$input_errors[] = gettext("Both maximum new connections per host and the interval (per second(s)) must be specified");
591

    
592
	if (!$_POST['tcpflags_any']) {
593
		$settcpflags = array();
594
		$outoftcpflags = array();
595
		foreach ($tcpflags as $tcpflag) {
596
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
597
				$settcpflags[] = $tcpflag;
598
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
599
				$outoftcpflags[] = $tcpflag;
600
		}
601
		if (empty($outoftcpflags) && !empty($settcpflags))
602
			$input_errors[] = gettext("If you specify TCP flags that should be set you should specify out of which flags as well.");
603
	}
604

    
605
	// Allow extending of the firewall edit page and include custom input validation
606
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
607

    
608
	if (!$input_errors) {
609
		$filterent = array();
610
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
611

    
612
		$filterent['tracker'] = empty($_POST['tracker']) ? (int)microtime(true) : $_POST['tracker'];
613

    
614
		$filterent['type'] = $_POST['type'];
615
		if (isset($_POST['interface'] ))
616
			$filterent['interface'] = $_POST['interface'];
617

    
618
		if (isset($_POST['ipprotocol'] ))
619
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
620

    
621
		if ($_POST['tcpflags_any']) {
622
			$filterent['tcpflags_any'] = true;
623
		} else {
624
			$settcpflags = array();
625
			$outoftcpflags = array();
626
			foreach ($tcpflags as $tcpflag) {
627
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
628
					$settcpflags[] = $tcpflag;
629
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
630
					$outoftcpflags[] = $tcpflag;
631
			}
632
			if (!empty($outoftcpflags)) {
633
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
634
				if (!empty($settcpflags))
635
					$filterent['tcpflags1'] = join(",", $settcpflags);
636
			}
637
		}
638

    
639
		if (isset($_POST['tag']))
640
			$filterent['tag'] = $_POST['tag'];
641
		if (isset($_POST['tagged']))
642
			$filterent['tagged'] = $_POST['tagged'];
643
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
644
			$filterent['direction'] = $_POST['direction'];
645
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
646
				$filterent['quick'] = $_POST['quick'];
647
			$filterent['floating'] = "yes";
648
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
649
				$filterent['interface'] = implode(",", $_POST['interface']);
650
			}
651
		}
652

    
653
		/* Advanced options */
654
		if ($_POST['allowopts'] == "yes")
655
			$filterent['allowopts'] = true;
656
		else
657
			unset($filterent['allowopts']);
658
		if ($_POST['disablereplyto'] == "yes")
659
			$filterent['disablereplyto'] = true;
660
		else
661
			unset($filterent['disablereplyto']);
662
		$filterent['max'] = $_POST['max'];
663
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
664
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
665
		$filterent['max-src-states'] = $_POST['max-src-states'];
666
		$filterent['statetimeout'] = $_POST['statetimeout'];
667
		$filterent['statetype'] = $_POST['statetype'];
668
		$filterent['os'] = $_POST['os'];
669
		if($_POST['nopfsync'] <> "")
670
			$filterent['nopfsync'] = true;
671
		else
672
			unset($filterent['nopfsync']);
673

    
674
		/* Nosync directive - do not xmlrpc sync this item */
675
		if($_POST['nosync'] <> "")
676
			$filterent['nosync'] = true;
677
		else
678
			unset($filterent['nosync']);
679

    
680
		/* unless both values are provided, unset the values - ticket #650 */
681
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
682
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
683
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
684
		} else {
685
			unset($filterent['max-src-conn-rate']);
686
			unset($filterent['max-src-conn-rates']);
687
		}
688

    
689
		if ($_POST['proto'] != "any")
690
			$filterent['protocol'] = $_POST['proto'];
691
		else
692
			unset($filterent['protocol']);
693

    
694
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
695
			$filterent['icmptype'] = $_POST['icmptype'];
696
		else
697
			unset($filterent['icmptype']);
698

    
699
		pconfig_to_address($filterent['source'], $_POST['src'],
700
			$_POST['srcmask'], $_POST['srcnot'],
701
			$_POST['srcbeginport'], $_POST['srcendport']);
702

    
703
		pconfig_to_address($filterent['destination'], $_POST['dst'],
704
			$_POST['dstmask'], $_POST['dstnot'],
705
			$_POST['dstbeginport'], $_POST['dstendport']);
706

    
707
		if ($_POST['disabled'])
708
			$filterent['disabled'] = true;
709
		else
710
			unset($filterent['disabled']);
711

    
712
		if ($_POST['dscp'])
713
			$filterent['dscp'] = $_POST['dscp'];
714

    
715
		if ($_POST['log'])
716
			$filterent['log'] = true;
717
		else
718
			unset($filterent['log']);
719
		strncpy($filterent['descr'], $_POST['descr'], 52);
720

    
721
		if ($_POST['gateway'] != "") {
722
			$filterent['gateway'] = $_POST['gateway'];
723
		}
724

    
725
		if ($_POST['defaultqueue'] != "") {
726
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
727
			if ($_POST['ackqueue'] != "")
728
				$filterent['ackqueue'] = $_POST['ackqueue'];
729
		}
730

    
731
		if ($_POST['dnpipe'] != "") {
732
			$filterent['dnpipe'] = $_POST['dnpipe'];
733
			if ($_POST['pdnpipe'] != "")
734
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
735
		}
736

    
737
		if ($_POST['l7container'] != "") {
738
			$filterent['l7container'] = $_POST['l7container'];
739
		}
740

    
741
		if ($_POST['sched'] != "") {
742
			$filterent['sched'] = $_POST['sched'];
743
		}
744

    
745
		if ($_POST['vlanprio'] != "") {
746
			$filterent['vlanprio'] = $_POST['vlanprio'];
747
		}
748
		if ($_POST['vlanprioset'] != "") {
749
			$filterent['vlanprioset'] = $_POST['vlanprioset'];
750
		}
751

    
752
		// If we have an associated nat rule, make sure the source and destination doesn't change
753
		if( isset($a_filter[$id]['associated-rule-id']) ) {
754
			$filterent['interface'] = $a_filter[$id]['interface'];
755
			if (isset($a_filter[$id]['protocol']))
756
				$filterent['protocol'] = $a_filter[$id]['protocol'];
757
			else if (isset($filterent['protocol']))
758
				unset($filterent['protocol']);
759
			if ($a_filter[$id]['protocol'] == "icmp" && $a_filter[$id]['icmptype'])
760
				$filterent['icmptype'] = $a_filter[$id]['icmptype'];
761
			else if (isset($filterent['icmptype']))
762
				unset($filterent['icmptype']);
763

    
764
			$filterent['source'] = $a_filter[$id]['source'];
765
			$filterent['destination'] = $a_filter[$id]['destination'];
766
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
767
		}
768

    
769
		if ( isset($a_filter[$id]['created']) && is_array($a_filter[$id]['created']) )
770
			$filterent['created'] = $a_filter[$id]['created'];
771

    
772
		$filterent['updated'] = make_config_revision_entry();
773

    
774
		// Allow extending of the firewall edit page and include custom input validation
775
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
776

    
777
		if (isset($id) && $a_filter[$id])
778
			$a_filter[$id] = $filterent;
779
		else {
780
			$filterent['created'] = make_config_revision_entry();
781
			if (is_numeric($after))
782
				array_splice($a_filter, $after+1, 0, array($filterent));
783
			else
784
				$a_filter[] = $filterent;
785
		}
786

    
787
		filter_rules_sort();
788

    
789
		if (write_config())
790
			mark_subsystem_dirty('filter');
791

    
792
		if (isset($_POST['floating']))
793
			header("Location: firewall_rules.php?if=FloatingRules");
794
		else
795
			header("Location: firewall_rules.php?if=" . htmlspecialchars($_POST['interface']));
796
		exit;
797
	}
798
}
799

    
800
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
801
$shortcut_section = "firewall";
802

    
803
$closehead = false;
804

    
805
$page_filename = "firewall_rules_edit.php";
806
include("head.inc");
807

    
808
?>
809
<link rel="stylesheet" href="/javascript/chosen/chosen.css" />
810
</head>
811

    
812
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
813
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
814
<script src="/javascript/chosen/chosen.jquery.js" type="text/javascript"></script>
815
<?php include("fbegin.inc"); ?>
816
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
817
<?php if ($input_errors) print_input_errors($input_errors); ?>
818

    
819
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
820
<input type='hidden' name="ruleid" value="<?=(isset($pconfig['ruleid'])&&$pconfig['ruleid']>0)?htmlspecialchars($pconfig['ruleid']):''?>" />
821

    
822
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall rules edit">
823
		<tr>
824
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Firewall rule");?></td>
825
		</tr>
826
<?php
827
		// Allow extending of the firewall edit page and include custom input validation
828
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphpearly");
829
?>
830
		<tr>
831
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Action");?></td>
832
			<td width="78%" class="vtable">
833
				<select name="type" class="formselect">
834
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
835
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected=\"selected\""; ?>>
836
					<?=htmlspecialchars($type);?>
837
					</option>
838
					<?php endforeach; ?>
839
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
840
					<option value="match" <?php if ("match" == strtolower($pconfig['type'])) echo "selected=\"selected\""; ?>>Match</option>
841
<?php endif; ?>
842
				</select>
843
				<br />
844
				<span class="vexpl">
845
					<?=gettext("Choose what to do with packets that match the criteria specified below.");?> <br />
846
					<?=gettext("Hint: the difference between block and reject is that with reject, a packet (TCP RST or ICMP port unreachable for UDP) is returned to the sender, whereas with block the packet is dropped silently. In either case, the original packet is discarded.");?>
847
				</span>
848
			</td>
849
		</tr>
850
		<tr>
851
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled");?></td>
852
			<td width="78%" class="vtable">
853
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
854
				<strong><?=gettext("Disable this rule");?></strong><br />
855
				<span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list.");?></span>
856
			</td>
857
		</tr>
858
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
859
		<tr>
860
			<td width="22%" valign="top" class="vncellreq">
861
				<?=gettext("Quick");?>
862
			</td>
863
			<td width="78%" class="vtable">
864
				<input name="quick" type="checkbox" id="quick" value="yes" <?php if ($pconfig['quick']) echo "checked=\"checked\""; ?> />
865
				<strong><?=gettext("Apply the action immediately on match.");?></strong><br />
866
				<span class="vexpl"><?=gettext("Set this option if you need to apply this action to traffic that matches this rule immediately.");?></span>
867
			</td>
868
		</tr>
869
<?php endif; ?>
870
<?php $edit_disabled = ""; ?>
871
<?php if( isset($pconfig['associated-rule-id']) ): ?>
872
		<tr>
873
			<td width="22%" valign="top" class="vncell"><?=gettext("Associated filter rule");?></td>
874
			<td width="78%" class="vtable">
875
				<span class="red"><strong><?=gettext("Note: ");?></strong></span><?=gettext("This is associated to a NAT rule.");?><br />
876
				<?=gettext("You cannot edit the interface, protocol, source, or destination of associated filter rules.");?><br />
877
				<br />
878
				<?php
879
					$edit_disabled = "disabled";
880
					if (is_array($config['nat']['rule'])) {
881
						foreach( $config['nat']['rule'] as $index => $nat_rule ) {
882
							if( isset($nat_rule['associated-rule-id']) && $nat_rule['associated-rule-id']==$pconfig['associated-rule-id'] ) {
883
								echo "<a href=\"firewall_nat_edit.php?id={$index}\">" . gettext("View the NAT rule") . "</a><br />";
884
								break;
885
							}
886
						}
887
					}
888
					echo "<input name='associated-rule-id' id='associated-rule-id' type='hidden' value='{$pconfig['associated-rule-id']}' />";
889
					if (!empty($pconfig['interface']))
890
						echo "<input name='interface' id='interface' type='hidden' value='{$pconfig['interface']}' />";
891
				?>
892
				<script type="text/javascript">
893
				//<![CDATA[
894
				editenabled = 0;
895
				//]]>
896
				</script>
897
			</td>
898
		</tr>
899
<?php endif; ?>
900
		<tr>
901
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
902
			<td width="78%" class="vtable">
903
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
904
				<select name="interface[]" title="Select interfaces..." multiple="multiple" style="width:350px;" class="chzn-select" tabindex="2" <?=$edit_disabled;?>>
905
<?php else: ?>
906
				<select name="interface" class="formselect" <?=$edit_disabled;?>>
907
<?php endif;
908
				/* add group interfaces */
909
				if (is_array($config['ifgroups']['ifgroupentry']))
910
					foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
911
						if (have_ruleint_access($ifgen['ifname']))
912
							$interfaces[$ifgen['ifname']] = $ifgen['ifname'];
913
				$ifdescs = get_configured_interface_with_descr();
914
				// Allow extending of the firewall edit page and include custom input validation
915
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_interfaces_edit");
916
				foreach ($ifdescs as $ifent => $ifdesc)
917
					if(have_ruleint_access($ifent))
918
							$interfaces[$ifent] = $ifdesc;
919
					if ($config['l2tp']['mode'] == "server")
920
						if(have_ruleint_access("l2tp"))
921
							$interfaces['l2tp'] = "L2TP VPN";
922
					if ($config['pptpd']['mode'] == "server")
923
						if(have_ruleint_access("pptp"))
924
							$interfaces['pptp'] = "PPTP VPN";
925

    
926
					if (is_pppoe_server_enabled() && have_ruleint_access("pppoe"))
927
						$interfaces['pppoe'] = "PPPoE Server";
928
					/* add ipsec interfaces */
929
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
930
						if(have_ruleint_access("enc0"))
931
							$interfaces["enc0"] = "IPsec";
932
					/* add openvpn/tun interfaces */
933
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
934
						$interfaces["openvpn"] = "OpenVPN";
935
					if (is_array($pconfig['interface']))
936
						$pconfig['interface'] = implode(",", $pconfig['interface']);
937
					$selected_interfaces = explode(",", $pconfig['interface']);
938
					foreach ($interfaces as $iface => $ifacename): ?>
939
						<option value="<?=$iface;?>" <?php if ($pconfig['interface'] <> "" && ( strcasecmp($pconfig['interface'], $iface) == 0 || in_array($iface, $selected_interfaces) )) echo "selected=\"selected\""; ?>><?=$ifacename?></option>
940
<?php 				endforeach; ?>
941
				</select>
942
				<br />
943
				<span class="vexpl"><?=gettext("Choose on which interface packets must come in to match this rule.");?></span>
944
			</td>
945
		</tr>
946
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
947
		<tr>
948
			<td width="22%" valign="top" class="vncellreq">
949
				<?=gettext("Direction");?>
950
			</td>
951
			<td width="78%" class="vtable">
952
				<select name="direction" class="formselect">
953
					<?php      $directions = array('any','in','out');
954
				foreach ($directions as $direction): ?>
955
				<option value="<?=$direction;?>"
956
					<?php if ($direction == $pconfig['direction']): ?>
957
						selected="selected"
958
					<?php endif; ?>
959
					><?=$direction;?></option>
960
				<?php endforeach; ?>
961
				</select>
962
				<input type="hidden" id="floating" name="floating" value="floating" />
963
			</td>
964
		<tr>
965
<?php endif; ?>
966
		<tr>
967
			<td width="22%" valign="top" class="vncellreq"><?=gettext("TCP/IP Version");?></td>
968
			<td width="78%" class="vtable">
969
				<select name="ipprotocol" class="formselect">
970
					<?php      $ipproto = array('inet' => 'IPv4','inet6' => 'IPv6', 'inet46' => 'IPv4+IPv6' );
971
				foreach ($ipproto as $proto => $name): ?>
972
				<option value="<?=$proto;?>"
973
					<?php if ($proto == $pconfig['ipprotocol']): ?>
974
						selected="selected"
975
					<?php endif; ?>
976
					><?=$name;?></option>
977
				<?php endforeach; ?>
978
				</select>
979
				<strong><?=gettext("Select the Internet Protocol version this rule applies to");?></strong><br />
980
			</td>
981
		</tr>
982
		<tr>
983
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
984
			<td width="78%" class="vtable">
985
				<select <?=$edit_disabled;?> name="proto" class="formselect" onchange="proto_change()">
986
<?php
987
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IPV6 IGMP PIM OSPF any carp pfsync");
988
				foreach ($protocols as $proto): ?>
989
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($proto);?></option>
990
<?php 			endforeach; ?>
991
				</select>
992
				<br />
993
				<span class="vexpl"><?=gettext("Choose which IP protocol this rule should match.");?> <br /> <?=gettext("Hint: in most cases, you should specify ");?><em>TCP</em> &nbsp;<?=gettext("here.");?></span>
994
			</td>
995
		</tr>
996
		<tr id="icmpbox">
997
			<td valign="top" class="vncell"><?=gettext("ICMP type");?></td>
998
			<td class="vtable">
999
				<select <?=$edit_disabled;?> name="icmptype" class="formselect">
1000
<?php
1001
				$icmptypes = array(
1002
				"" => gettext("any"),
1003
				"echoreq" => gettext("Echo request"),
1004
				"echorep" => gettext("Echo reply"),
1005
				"unreach" => gettext("Destination unreachable"),
1006
				"squench" => gettext("Source quench"),
1007
				"redir" => gettext("Redirect"),
1008
				"althost" => gettext("Alternate Host"),
1009
				"routeradv" => gettext("Router advertisement"),
1010
				"routersol" => gettext("Router solicitation"),
1011
				"timex" => gettext("Time exceeded"),
1012
				"paramprob" => gettext("Invalid IP header"),
1013
				"timereq" => gettext("Timestamp"),
1014
				"timerep" => gettext("Timestamp reply"),
1015
				"inforeq" => gettext("Information request"),
1016
				"inforep" => gettext("Information reply"),
1017
				"maskreq" => gettext("Address mask request"),
1018
				"maskrep" => gettext("Address mask reply")
1019
				);
1020

    
1021
				foreach ($icmptypes as $icmptype => $descr): ?>
1022
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($descr);?></option>
1023
<?php 			endforeach; ?>
1024
			</select>
1025
			<br />
1026
			<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
1027
		</td>
1028
		</tr>
1029
		<tr>
1030
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
1031
			<td width="78%" class="vtable">
1032
				<input <?=$edit_disabled;?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked=\"checked\""; ?> />
1033
				<strong><?=gettext("not");?></strong>
1034
				<br />
1035
				<?=gettext("Use this option to invert the sense of the match.");?>
1036
				<br />
1037
				<br />
1038
				<table border="0" cellspacing="0" cellpadding="0">
1039
					<tr>
1040
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
1041
						<td>
1042
							<select <?=$edit_disabled;?> name="srctype" class="formselect" onchange="typesel_change()">
1043
<?php
1044
								$sel = is_specialnet($pconfig['src']); ?>
1045
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected=\"selected\""; } ?>><?=gettext("any");?></option>
1046
								<option value="single"
1047
						<?php  if (!$sel &&
1048
							    ((is_ipaddrv6($pconfig['src']) && $pconfig['srcmask'] == 128) ||
1049
							    (is_ipaddrv4($pconfig['src']) && $pconfig['srcmask'] == 32) || is_alias($pconfig['src'])))
1050
								{ echo "selected=\"selected\""; $sel = 1; }
1051
						?>
1052
								> <?=gettext("Single host or alias");?></option>
1053
								<option value="network" <?php if (!$sel) echo "selected=\"selected\""; ?>><?=gettext("Network");?></option>
1054
								<?PHP	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules"): ?>
1055
								<option value="(self)" <?PHP if ($pconfig['src'] == "(self)") echo "selected=\"selected\""; ?>><?=gettext("This Firewall (self)");?></option>
1056
								<?PHP endif;?>
1057
								<?php if(have_ruleint_access("pptp")): ?>
1058
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected=\"selected\""; } ?>><?=gettext("PPTP clients");?></option>
1059
								<?php endif; ?>
1060
								<?php if(have_ruleint_access("pppoe")): ?>
1061
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected=\"selected\""; } ?>><?=gettext("PPPoE clients");?></option>
1062
								<?php endif; ?>
1063
								<?php if(have_ruleint_access("l2tp")): ?>
1064
								<option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected=\"selected\""; } ?>><?=gettext("L2TP clients");?></option>
1065
								<?php endif; ?>
1066
<?php
1067
								foreach ($ifdisp as $ifent => $ifdesc): ?>
1068
								<?php if(have_ruleint_access($ifent)): ?>
1069
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected=\"selected\""; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("net");?></option>
1070
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected=\"selected\""; } ?>>
1071
										<?=$ifdesc?> <?=gettext("address");?>
1072
									</option>
1073
								<?php endif; ?>
1074
<?php 							endforeach; ?>
1075
							</select>
1076
						</td>
1077
					</tr>
1078
					<tr>
1079
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
1080
						<td>
1081
							<input <?=$edit_disabled;?> autocomplete='off' name="src" type="text" class="formfldalias ipv4v6" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>" /> /
1082
							<select <?=$edit_disabled;?> name="srcmask" class="formselect ipv4v6" id="srcmask">
1083
<?php						for ($i = 127; $i > 0; $i--): ?>
1084
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected=\"selected\""; ?>><?=$i;?></option>
1085
<?php 						endfor; ?>
1086
							</select>
1087
						</td>
1088
					</tr>
1089
				</table>
1090
				<div id="showadvancedboxspr">
1091
					<p>
1092
					<input <?=$edit_disabled;?> type="button" onclick="show_source_port_range()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show source port range");?>
1093
					</p>
1094
				</div>
1095
			</td>
1096
		</tr>
1097
		<tr style="display:none" id="sprtable">
1098
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range");?></td>
1099
			<td width="78%" class="vtable">
1100
				<table border="0" cellspacing="0" cellpadding="0">
1101
					<tr>
1102
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
1103
						<td>
1104
							<select <?=$edit_disabled;?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
1105
								<option value="">(<?=gettext("other"); ?>)</option>
1106
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any");?></option>
1107
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
1108
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars("{$wkportdesc} ({$wkport})");?></option>
1109
<?php 							endforeach; ?>
1110
							</select>
1111
							<input <?=$edit_disabled;?> autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo htmlspecialchars($pconfig['srcbeginport']); ?>" />
1112
						</td>
1113
					</tr>
1114
					<tr>
1115
						<td><?=gettext("to:");?></td>
1116
						<td>
1117
							<select <?=$edit_disabled;?> name="srcendport" class="formselect" onchange="ext_change()">
1118
								<option value="">(<?=gettext("other"); ?>)</option>
1119
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any");?></option>
1120
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
1121
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars("{$wkportdesc} ({$wkport})");?></option>
1122
<?php							endforeach; ?>
1123
							</select>
1124
							<input <?=$edit_disabled;?> autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo htmlspecialchars($pconfig['srcendport']); ?>" />
1125
						</td>
1126
					</tr>
1127
				</table>
1128
				<br />
1129
				<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"); ?> &quot;<?=gettext("any"); ?>&quot;).</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 />
1130
			</td>
1131
		</tr>
1132
		<tr>
1133
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
1134
			<td width="78%" class="vtable">
1135
				<input <?=$edit_disabled;?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked=\"checked\""; ?> />
1136
				<strong><?=gettext("not");?></strong>
1137
					<br />
1138
				<?=gettext("Use this option to invert the sense of the match.");?>
1139
					<br />
1140
					<br />
1141
				<table border="0" cellspacing="0" cellpadding="0">
1142
					<tr>
1143
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
1144
						<td>
1145
							<select <?=$edit_disabled;?> name="dsttype" class="formselect" onchange="typesel_change()">
1146
<?php
1147
								$sel = is_specialnet($pconfig['dst']); ?>
1148
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected=\"selected\""; } ?>><?=gettext("any");?></option>
1149
								<option value="single"
1150
								<?php  if (!$sel &&
1151
									    ((is_ipaddrv6($pconfig['dst']) && $pconfig['dstmask'] == 128) ||
1152
									    (is_ipaddrv4($pconfig['dst']) && $pconfig['dstmask'] == 32) || is_alias($pconfig['dst'])))
1153
										{ echo "selected=\"selected\""; $sel = 1; }
1154
								?>
1155
								><?=gettext("Single host or alias");?></option>
1156
								<option value="network" <?php if (!$sel) echo "selected=\"selected\""; ?>><?=gettext("Network");?></option>
1157
								<option value="(self)" <?PHP if ($pconfig['dst'] == "(self)") echo "selected=\"selected\""; ?>><?=gettext("This Firewall (self)");?></option>
1158
								<?php if(have_ruleint_access("pptp")): ?>
1159
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected=\"selected\""; } ?>><?=gettext("PPTP clients");?></option>
1160
								<?php endif; ?>
1161
								<?php if(have_ruleint_access("pppoe")): ?>
1162
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected=\"selected\""; } ?>><?=gettext("PPPoE clients");?></option>
1163
								<?php endif; ?>
1164
								<?php if(have_ruleint_access("l2tp")): ?>
1165
								<option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected=\"selected\""; } ?>><?=gettext("L2TP clients");?></option>
1166
								<?php endif; ?>
1167

    
1168
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
1169
								<?php if(have_ruleint_access($if)): ?>
1170
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected=\"selected\""; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("net");?></option>
1171
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected=\"selected\""; } ?>>
1172
										<?=$ifdesc;?> <?=gettext("address");?>
1173
									</option>
1174
								<?php endif; ?>
1175
<?php 							endforeach; ?>
1176
							</select>
1177
						</td>
1178
					</tr>
1179
					<tr>
1180
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
1181
						<td>
1182
							<input <?=$edit_disabled;?> autocomplete='off' name="dst" type="text" class="formfldalias ipv4v6" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>" />
1183
							/
1184
							<select <?=$edit_disabled;?> name="dstmask" class="formselect ipv4v6" id="dstmask">
1185
<?php
1186
							for ($i = 127; $i > 0;
1187
$i--): ?>
1188
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected=\"selected\""; ?>><?=$i;?></option>
1189
<?php						endfor; ?>
1190
							</select>
1191
						</td>
1192
					</tr>
1193
				</table>
1194
			</td>
1195
		</tr>
1196
		<tr id="dprtr">
1197
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination port range ");?></td>
1198
			<td width="78%" class="vtable">
1199
				<table border="0" cellspacing="0" cellpadding="0">
1200
					<tr>
1201
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
1202
						<td>
1203
							<select <?=$edit_disabled;?> name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
1204
								<option value="">(<?=gettext("other"); ?>)</option>
1205
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any");?></option>
1206
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
1207
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected=\"selected\""; $bfound = 1; }?>><?=htmlspecialchars("{$wkportdesc} ({$wkport})");?></option>
1208
<?php 							endforeach; ?>
1209
							</select>
1210
							<input <?=$edit_disabled;?> autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo htmlspecialchars($pconfig['dstbeginport']); ?>" />
1211
						</td>
1212
					</tr>
1213
					<tr>
1214
						<td><?=gettext("to:");?></td>
1215
						<td>
1216
							<select <?=$edit_disabled;?> name="dstendport" class="formselect" onchange="ext_change()">
1217
								<option value="">(<?=gettext("other"); ?>)</option>
1218
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any");?></option>
1219
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
1220
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars("{$wkportdesc} ({$wkport})");?></option>
1221
<?php 							endforeach; ?>
1222
							</select>
1223
								<input <?=$edit_disabled;?> autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo htmlspecialchars($pconfig['dstendport']); ?>" />
1224
						</td>
1225
					</tr>
1226
				</table>
1227
				<br />
1228
				<span class="vexpl">
1229
					<?=gettext("Specify the port or port range for the destination of the packet for this rule.");?>
1230
					<br />
1231
					<?=gettext("Hint: you can leave the"); ?> <em><?=gettext("'to'"); ?></em> <?=gettext("field empty if you only want to filter a single port");?>
1232
				</span>
1233
			</td>
1234
		</tr>
1235
		<tr>
1236
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Log");?></td>
1237
			<td width="78%" class="vtable">
1238
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked=\"checked\""; ?> />
1239
				<strong><?=gettext("Log packets that are handled by this rule");?></strong>
1240
				<br />
1241
				<span class="vexpl"><?=gettext("Hint: the firewall has limited local log space. Don't turn on logging for everything. If you want to do a lot of logging, consider using a remote syslog server"); ?> (<?=gettext("see the"); ?> <a href="diag_logs_settings.php"><?=gettext("Diagnostics: System logs: Settings"); ?></a> <?=gettext("page"); ?>).</span>
1242
			</td>
1243
		</tr>
1244
		<tr>
1245
			<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
1246
			<td width="78%" class="vtable">
1247
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>" />
1248
				<br />
1249
				<span class="vexpl"><?=gettext("You may enter a description here for your reference.");?></span>
1250
			</td>
1251
		</tr>
1252
<?php		if (!isset($id) || !($a_filter[$id] && firewall_check_for_advanced_options($a_filter[$id]) <> "")): ?>
1253
		<tr>
1254
			<td width="22%" valign="top">&nbsp;</td>
1255
			<td width="78%">
1256
				&nbsp;<br />&nbsp;
1257
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
1258
				<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
1259
<?php			if (isset($id) && $a_filter[$id]): ?>
1260
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
1261
<?php 			endif; ?>
1262
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>" />
1263
			</td>
1264
		</tr>
1265
<?php		endif; ?>
1266
		<tr>
1267
			<td>&nbsp;</td>
1268
		</tr>
1269
		<tr>
1270
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced features");?></td>
1271
		</tr>
1272
		<tr>
1273
			<td width="22%" valign="top" class="vncell"><?=gettext("Source OS");?></td>
1274
			<td width="78%" class="vtable">
1275
				<div id="showadvsourceosbox" <?php if ($pconfig['os']) echo "style='display:none'"; ?>>
1276
					<input type="button" onclick="show_advanced_sourceos()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1277
				</div>
1278
				<div id="showsourceosadv" <?php if (empty($pconfig['os'])) echo "style='display:none'"; ?>>
1279
					<?=gettext("OS Type:");?>&nbsp;
1280
					<select name="os" id="os" class="formselect">
1281
						<option value="" <?php if (empty($pconfig['os'])) echo "selected=\"selected\""; ?>>Any</option>
1282
<?php
1283
						foreach ($ostypes as $ostype): ?>
1284
							<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($ostype);?></option>
1285
<?php
1286
					endforeach;
1287
?>
1288
					</select>
1289
					<br />
1290
					<?=gettext("Note: this only works for TCP rules. General OS choice matches all subtypes.");?>
1291
				</div>
1292
			</td>
1293
		</tr>
1294
		<tr>
1295
			<td width="22%" valign="top" class="vncell"><?=gettext("Diffserv Code Point");?></td>
1296
			<td width="78%" class="vtable">
1297
				<div id="dsadv" <?php if ($pconfig['dscp']) echo "style='display:none'"; ?>>
1298
					<input type="button" onclick="show_dsdiv();" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1299
				</div>
1300
				<div id="dsdivmain" <?php if (empty($pconfig['dscp'])) echo "style='display:none'"; ?>>
1301
					<select name="dscp" id="dscp">
1302
						<option value=""></option>
1303
						<?php foreach($firewall_rules_dscp_types as $frdt): ?>
1304
							<option value="<?=$frdt?>"<?php if($pconfig['dscp'] == $frdt) echo " selected=\"selected\""; ?>><?=$frdt?></option>
1305
						<?php endforeach; ?>
1306
					</select>
1307
				</div>
1308
			</td>
1309
		</tr>
1310
		<tr>
1311
			<td width="22%" valign="top" class="vncell"><?=gettext("Advanced Options");?></td>
1312
			<td width="78%" class="vtable">
1313
			<div id="aoadv" <?php if (is_aoadv_used($pconfig)) echo "style='display:none'"; ?>>
1314
				<input type="button" onclick="show_aodiv();" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1315
			</div>
1316
			<div id="aodivmain" <?php if (!is_aoadv_used($pconfig)) echo "style='display:none'"; ?>>
1317
				<input type="checkbox" id="allowopts" value="yes" name="allowopts"<?php if($pconfig['allowopts'] == true) echo " checked=\"checked\""; ?> />
1318
				<br /><span class="vexpl"><?=gettext("This allows packets with IP options to pass. Otherwise they are blocked by default. This is usually only seen with multicast traffic.");?>
1319
				</span><p>
1320
				<input type="checkbox" id="disablereplyto" value="yes" name="disablereplyto"<?php if($pconfig['disablereplyto'] == true) echo " checked=\"checked\""; ?> />
1321
				<br /><span class="vexpl"><?=gettext("This will disable auto generated reply-to for this rule.");?>
1322
				</span></p><p>
1323
				<input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>" />
1324
				<br /><span class="vexpl"><?=gettext("You can mark a packet matching this rule and use this mark to match on other NAT/filter rules. It is called"); ?> <b><?=gettext("Policy filtering"); ?></b>
1325
				</span></p><p>
1326
				<input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>" />
1327
				<br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before on another rule.")?>
1328
				</span></p><p>
1329
				<input name="max" id="max" value="<?php echo htmlspecialchars($pconfig['max']) ?>" /><br /><?=gettext(" Maximum state entries this rule can create");?></p><p>
1330
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo htmlspecialchars($pconfig['max-src-nodes']) ?>" /><br /><?=gettext(" Maximum number of unique source hosts");?></p><p>
1331
				<input name="max-src-conn" id="max-src-conn" value="<?php echo htmlspecialchars($pconfig['max-src-conn']) ?>" /><br /><?=gettext(" Maximum number of established connections per host (TCP only)");?></p><p>
1332
				<input name="max-src-states" id="max-src-states" value="<?php echo htmlspecialchars($pconfig['max-src-states']) ?>" /><br /><?=gettext(" Maximum state entries per host");?></p><p>
1333
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo htmlspecialchars($pconfig['max-src-conn-rate']) ?>" /> /
1334
				<select name="max-src-conn-rates" id="max-src-conn-rates">
1335
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected=\"selected\""; ?>></option>
1336
<?php				for($x=1; $x<255; $x++) {
1337
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected=\"selected\""; else $selected = "";
1338
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
1339
					} ?>
1340
				</select><br />
1341
				<?=gettext("Maximum new connections per host / per second(s) (TCP only)");?>
1342
				</p><p>
1343
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>" /><br />
1344
				<?=gettext("State Timeout in seconds (TCP only)");?>
1345
				</p>
1346
				<p><strong><?=gettext("Note: Leave fields blank to disable that feature.");?></strong></p>
1347
			</div>
1348
			</td>
1349
		</tr>
1350
		<tr id="tcpflags">
1351
			<td width="22%" valign="top" class="vncell"><?=gettext("TCP flags");?></td>
1352
			<td width="78%" class="vtable">
1353
			<div id="showtcpflagsbox" <?php if ($pconfig['tcpflags_any'] || $pconfig['tcpflags1'] || $pconfig['tcpflags2']) echo "style='display:none'"; ?>>
1354
				<input type="button" onclick="show_advanced_tcpflags()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1355
			</div>
1356
			<div id="showtcpflagsadv" <?php if (empty($pconfig['tcpflags_any']) && empty($pconfig['tcpflags1']) && empty($pconfig['tcpflags2'])) echo "style='display:none'"; ?>>
1357
			<div id="tcpheader" align="center">
1358
			<table border="0" cellspacing="0" cellpadding="0">
1359
			<?php
1360
				$setflags = explode(",", $pconfig['tcpflags1']);
1361
				$outofflags = explode(",", $pconfig['tcpflags2']);
1362
				$header = "<td width='40' class='nowrap'></td>";
1363
				$tcpflags1 = "<td width='40' class='nowrap'>set</td>";
1364
				$tcpflags2 = "<td width='40' class='nowrap'>out of</td>";
1365
				foreach ($tcpflags as $tcpflag) {
1366
					$header .= "<td  width='40' class='nowrap'><strong>" . strtoupper($tcpflag) . "</strong></td>\n";
1367
					$tcpflags1 .= "<td  width='40' class='nowrap'> <input type='checkbox' name='tcpflags1_{$tcpflag}' value='on' ";
1368
					if (array_search($tcpflag, $setflags) !== false)
1369
						$tcpflags1 .= "checked=\"checked\"";
1370
					$tcpflags1 .= " /></td>\n";
1371
					$tcpflags2 .= "<td  width='40' class='nowrap'> <input type='checkbox' name='tcpflags2_{$tcpflag}' value='on' ";
1372
					if (array_search($tcpflag, $outofflags) !== false)
1373
						$tcpflags2 .= "checked=\"checked\"";
1374
					$tcpflags2 .= " /></td>\n";
1375
				}
1376
				echo "<tr id='tcpheader'>{$header}</tr>\n";
1377
				echo "<tr id='tcpflags1'>{$tcpflags1}</tr>\n";
1378
				echo "<tr id='tcpflags2'>{$tcpflags2}</tr>\n";
1379
			?>
1380
			</table>
1381
			</div>
1382
			<br /><center>
1383
			<input onclick='tcpflags_anyclick(this);' type='checkbox' name='tcpflags_any' value='on' <?php if ($pconfig['tcpflags_any']) echo "checked=\"checked\""; ?> /><strong><?=gettext("Any flags.");?></strong><br /></center>
1384
			<br />
1385
			<span class="vexpl"><?=gettext("Use this to choose TCP flags that must ".
1386
			"be set or cleared for this rule to match.");?></span>
1387
			</div>
1388
			</td>
1389
		</tr>
1390
		<tr>
1391
			<td width="22%" valign="top" class="vncell"><?=gettext("State Type");?></td>
1392
			<td width="78%" class="vtable">
1393
				<div id="showadvstatebox" <?php if (!empty($pconfig['nopfsync']) || (!empty($pconfig['statetype']) && $pconfig['statetype'] != "keep state")) echo "style='display:none'"; ?>>
1394
					<input type="button" onclick="show_advanced_state()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1395
				</div>
1396
				<div id="showstateadv" <?php if (empty($pconfig['nopfsync']) && (empty($pconfig['statetype']) || $pconfig['statetype'] == "keep state")) echo "style='display:none'"; ?>>
1397
					<input name="nopfsync" type="checkbox" id="nopfsync" value="yes" <?php if ($pconfig['nopfsync']) echo "checked=\"checked\""; ?> />
1398
					<span class="vexpl">
1399
						NO pfsync<br />
1400
						<?=gettext("Hint: This prevents states created by this rule to be sync'ed over pfsync.");?><br />
1401
					</span><br />
1402
					<select name="statetype">
1403
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected=\"selected\""; ?>><?=gettext("keep state");?></option>
1404
						<option value="sloppy state" <?php if($pconfig['statetype'] == "sloppy state") echo "selected=\"selected\""; ?>><?=gettext("sloppy state");?></option>
1405
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected=\"selected\""; ?>><?=gettext("synproxy state");?></option>
1406
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected=\"selected\""; ?>><?=gettext("none");?></option>
1407
					</select><br />
1408
					<span class="vexpl">
1409
						<?=gettext("Hint: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.");?>
1410
					</span>
1411
					<table width="90%">
1412
						<tr><td width="25%"><ul><li><?=gettext("keep state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1413
						<tr><td width="25%"><ul><li><?=gettext("sloppy state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1414
						<tr><td width="25%"><ul><li><?=gettext("synproxy state");?></li></ul></td><td><?=gettext("Proxies incoming TCP connections to help protect servers from spoofed TCP SYN floods. This option includes the functionality of keep state and modulate state combined.");?></td></tr>
1415
						<tr><td width="25%"><ul><li><?=gettext("none");?></li></ul></td><td><?=gettext("Do not use state mechanisms to keep track.  This is only useful if you're doing advanced queueing in certain situations.  Please check the documentation.");?></td></tr>
1416
					</table>
1417
				</div>
1418
			</td>
1419
		</tr>
1420
		<tr>
1421
			<td width="22%" valign="top" class="vncell"><?=gettext("No XMLRPC Sync");?></td>
1422
			<td width="78%" class="vtable">
1423
				<div id="showadvnoxmlrpcsyncbox" <?php if ($pconfig['nosync']) echo "style='display:none'"; ?>>
1424
					<input type="button" onclick="show_advanced_noxmlrpc()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1425
				</div>
1426
				<div id="shownoxmlrpcadv" <?php if (empty($pconfig['nosync'])) echo "style='display:none'"; ?>>
1427
					<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " checked=\"checked\""; ?> /><br />
1428
					<?=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.");?>
1429
				</div>
1430
			</td>
1431
		</tr>
1432
		<tr>
1433
			<td width="22%" valign="top" class="vncell"><?=gettext("802.1p");?></td>
1434
			<td width="78%" class="vtable">
1435
				<div id="showadvvlanpriobox" <?php if (!empty($pconfig['vlanprio'])) echo "style='display:none'"; ?>>
1436
					<input type="button" onclick="show_advanced_vlanprio()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1437
				</div>
1438
				<div id="showvlanprioadv" <?php if (empty($pconfig['vlanprio'])) echo "style='display:none'"; ?>>
1439
					<?php $vlanprio = array("none", "be", "bk", "ee", "ca", "vi", "vo", "ic", "nc"); ?>
1440
<?php
1441
					$opts = "";
1442
					foreach($vlanprio as $vprio) {
1443
						if ($vprio == $pconfig['vlanprio'])
1444
							$selected = " selected=\"selected\"";
1445
						else
1446
							$selected = "";
1447
						if ($vprio == "none")
1448
							$opts .= "<option value=\"\">{$vprio}</option>\n";
1449
						else
1450
							$opts .= "<option value=\"{$vprio}\" {$selected}>" . strtoupper($vprio) . "</option>\n";
1451
					}
1452

    
1453
					$optsset = "";
1454
					foreach($vlanprio as $vprioset) {
1455
						if ($vprioset == $pconfig['vlanprioset'])
1456
							$selected = " selected=\"selected\"";
1457
						else
1458
							$selected = "";
1459
						if ($vprioset == "none")
1460
							$optsset .= "<option value=\"\">{$vprioset}</option>\n";
1461
						else
1462
							$optsset .= "<option value=\"{$vprioset}\" {$selected}>" . strtoupper($vprioset) . "</option>\n";
1463
					}
1464
?>
1465
					<select name='vlanprio'>
1466
					<?php echo $opts; ?>
1467
					</select>
1468
					<p><?=gettext("Choose 802.1p priority to match on");?></p>
1469
					<select name='vlanprioset'>
1470
					<?php echo $optsset; ?>
1471
					</select>
1472
					<p><?=gettext("Choose 802.1p priority to apply");?></p>
1473
				</div>
1474
			</td>
1475
		</tr>
1476
		<?php
1477
			//build list of schedules
1478
			$schedules = array();
1479
			$schedules[] = "none";//leave none to leave rule enabled all the time
1480
			if(is_array($config['schedules']['schedule'])) {
1481
				foreach ($config['schedules']['schedule'] as $schedule) {
1482
					if ($schedule['name'] <> "")
1483
						$schedules[] = $schedule['name'];
1484
				}
1485
			}
1486
		?>
1487
		<tr>
1488
			<td width="22%" valign="top" class="vncell"><?=gettext("Schedule");?></td>
1489
			<td width="78%" class="vtable">
1490
				<div id="showadvschedulebox" <?php if (!empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1491
					<input type="button" onclick="show_advanced_schedule()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1492
				</div>
1493
				<div id="showscheduleadv" <?php if (empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1494
					<select name='sched'>
1495
<?php
1496
					foreach($schedules as $schedule) {
1497
						if($schedule == $pconfig['sched']) {
1498
							$selected = " selected=\"selected\"";
1499
						} else {
1500
							$selected = "";
1501
						}
1502
						if ($schedule == "none") {
1503
							echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
1504
						} else {
1505
							echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
1506
						}
1507
					}
1508
?>
1509
					</select>
1510
					<p><?=gettext("Leave as 'none' to leave the rule enabled all the time.");?></p>
1511
				</div>
1512
			</td>
1513
		</tr>
1514
		<tr>
1515
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
1516
			<td width="78%" class="vtable">
1517
				<div id="showadvgatewaybox" <?php if (!empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1518
					<input type="button" onclick="show_advanced_gateway()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1519
				</div>
1520
				<div id="showgatewayadv" <?php if (empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1521
					<select name='gateway'>
1522
					<option value="" ><?=gettext("default");?></option>
1523
<?php
1524
					/* build a list of gateways */
1525
					$gateways = return_gateways_array();
1526
					// add statically configured gateways to list
1527
					foreach($gateways as $gwname => $gw) {
1528
						if(($pconfig['ipprotocol'] == "inet46"))
1529
							continue;
1530
						if(($pconfig['ipprotocol'] == "inet6") && !(($gw['ipprotocol'] == "inet6") || (is_ipaddrv6($gw['gateway']))))
1531
							continue;
1532
						if(($pconfig['ipprotocol'] == "inet") && !(($gw['ipprotocol'] == "inet") || (is_ipaddrv4($gw['gateway']))))
1533
							continue;
1534
						if($gw == "")
1535
							continue;
1536
						if($gwname == $pconfig['gateway']) {
1537
							$selected = " selected=\"selected\"";
1538
						} else {
1539
							$selected = "";
1540
						}
1541
						$gateway_addr_str = empty($gw['gateway']) ? "" : " - " . $gw[gateway];
1542
						echo "<option value=\"{$gwname}\" {$selected}>{$gw['name']}{$gateway_addr_str}</option>\n";
1543
					}
1544
					/* add gateway groups to the list */
1545
					if (is_array($a_gatewaygroups)) {
1546
						foreach($a_gatewaygroups as $gwg_name => $gwg_data) {
1547
							if((empty($pconfig['ipprotocol'])) || ($pconfig['ipprotocol'] == $gwg_data['ipprotocol'])) {
1548
								if($pconfig['gateway'] == $gwg_name) {
1549
									$selected = " selected=\"selected\"";
1550
								} else {
1551
									$selected = "";
1552
								}
1553
								echo "<option value=\"{$gwg_name}\" $selected>{$gwg_name}</option>\n";
1554
							}
1555
						}
1556
					}
1557
?>
1558
					</select>
1559
					<p><?=gettext("Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.");?></p>
1560
				</div>
1561
			</td>
1562
		</tr>
1563
		<tr>
1564
			<td width="22%" valign="top" class="vncell"><?=gettext("In/Out");?></td>
1565
			<td width="78%" class="vtable">
1566
				<div id="showadvinoutbox" <?php if (!empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1567
					<input type="button" onclick="show_advanced_inout()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1568
				</div>
1569
				<div id="showinoutadv" <?php if (empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1570
					<select name="dnpipe">
1571
<?php
1572
		if (!is_array($dnqlist))
1573
			$dnqlist = array();
1574
		echo "<option value=\"\"";
1575
		if (!$dnqselected) echo " selected=\"selected\"";
1576
		echo " >none</option>";
1577
		foreach ($dnqlist as $dnq => $dnqkey) {
1578
			if($dnq == "")
1579
				continue;
1580
			echo "<option value=\"$dnq\"";
1581
			if ($dnq == $pconfig['dnpipe']) {
1582
				$dnqselected = 1;
1583
				echo " selected=\"selected\"";
1584
			}
1585
			echo ">{$dnq}</option>";
1586
		}
1587
?>
1588
			</select> /
1589
			<select name="pdnpipe">
1590
<?php
1591
		$dnqselected = 0;
1592
		echo "<option value=\"\"";
1593
		if (!$dnqselected) echo " selected=\"selected\"";
1594
		echo " >none</option>";
1595
		foreach ($dnqlist as $dnq => $dnqkey) {
1596
			if($dnq == "")
1597
				continue;
1598
			echo "<option value=\"$dnq\"";
1599
			if ($dnq == $pconfig['pdnpipe']) {
1600
				$dnqselected = 1;
1601
				echo " selected=\"selected\"";
1602
			}
1603
			echo ">{$dnq}</option>";
1604
		}
1605
?>
1606
				</select>
1607
				<br />
1608
				<span class="vexpl"><?=gettext("Choose the Out queue/Virtual interface only if you have also selected In.")."<br />".gettext("The Out selection is applied to traffic leaving the interface where the rule is created, In is applied to traffic coming into the chosen interface.")."<br />".gettext("If you are creating a floating rule, if the direction is In then the same rules apply, if the direction is out the selections are reverted Out is for incoming and In is for outgoing.");?></span>
1609
				</div>
1610
			</td>
1611
		</tr>
1612

    
1613
		<tr>
1614
			<td width="22%" valign="top" class="vncell"><?=gettext("Ackqueue/Queue");?></td>
1615
			<td width="78%" class="vtable">
1616
			<div id="showadvackqueuebox" <?php if (!empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1617
				<input type="button" onclick="show_advanced_ackqueue()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1618
			</div>
1619
			<div id="showackqueueadv" <?php if (empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1620
				<select name="ackqueue">
1621
<?php
1622
			if (!is_array($qlist))
1623
				$qlist = array();
1624
			echo "<option value=\"\"";
1625
			if (!$qselected) echo " selected=\"selected\"";
1626
			echo " >none</option>";
1627
			foreach ($qlist as $q => $qkey) {
1628
				if($q == "")
1629
					continue;
1630
				echo "<option value=\"$q\"";
1631
				if ($q == $pconfig['ackqueue']) {
1632
					$qselected = 1;
1633
					echo " selected=\"selected\"";
1634
				}
1635
				if (isset($ifdisp[$q]))
1636
					echo ">{$ifdisp[$q]}</option>";
1637
				else
1638
					echo ">{$q}</option>";
1639
			}
1640
?>
1641
				</select> /
1642
				<select name="defaultqueue">
1643
<?php
1644
			$qselected = 0;
1645
			echo "<option value=\"\"";
1646
			if (!$qselected) echo " selected=\"selected\"";
1647
			echo " >none</option>";
1648
			foreach ($qlist as $q => $qkey) {
1649
				if($q == "")
1650
					continue;
1651
				echo "<option value=\"$q\"";
1652
				if ($q == $pconfig['defaultqueue']) {
1653
					$qselected = 1;
1654
					echo " selected=\"selected\"";
1655
				}
1656
				if (isset($ifdisp[$q]))
1657
					echo ">{$ifdisp[$q]}</option>";
1658
				else
1659
					echo ">{$q}</option>";
1660
			}
1661
?>
1662
				</select>
1663
					<br />
1664
					<span class="vexpl"><?=gettext("Choose the Acknowledge Queue only if you have selected Queue.");?></span>
1665
					</div>
1666
				</td>
1667
			</tr>
1668
			<tr>
1669
				<td width="22%" valign="top" class="vncell"><?=gettext("Layer7");?></td>
1670
				<td width="78%" class="vtable">
1671
					<div id="showadvlayer7box" <?php if (!empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1672
						<input type="button" onclick="show_advanced_layer7()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show advanced option");?>
1673
					</div>
1674
					<div id="showlayer7adv" <?php if (empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1675
						<select name="l7container">
1676
<?php
1677
						if (!is_array($l7clist))
1678
							$l7clist = array();
1679
						echo "<option value=\"\"";
1680
						echo " >none</option>";
1681
						foreach ($l7clist as $l7ckey) {
1682
							echo "<option value=\"{$l7ckey}\"";
1683
							if ($l7ckey == $pconfig['l7container']) {
1684
								echo " selected=\"selected\"";
1685
							}
1686
							echo ">{$l7ckey}</option>";
1687
						}
1688
?>
1689
						</select>
1690
						<br />
1691
						<span class="vexpl">
1692
							<?=gettext("Choose a Layer7 container to apply application protocol inspection rules. " .
1693
							"These are valid for TCP and UDP protocols only.");?>
1694
						</span>
1695
					</div>
1696
				</td>
1697
			</tr>
1698
<?php
1699
		// Allow extending of the firewall edit page and include custom input validation
1700
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphplate");
1701
?>
1702
<?php
1703
$has_created_time = (isset($a_filter[$id]['created']) && is_array($a_filter[$id]['created']));
1704
$has_updated_time = (isset($a_filter[$id]['updated']) && is_array($a_filter[$id]['updated']));
1705
?>
1706
		<?php if ($has_created_time || $has_updated_time): ?>
1707
		<tr>
1708
			<td>&nbsp;</td>
1709
		</tr>
1710
		<tr>
1711
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Rule Information");?></td>
1712
		</tr>
1713
		<?php if ($has_created_time): ?>
1714
		<tr>
1715
			<td width="22%" valign="top" class="vncell"><?=gettext("Created");?></td>
1716
			<td width="78%" class="vtable">
1717
				<?= date(gettext("n/j/y H:i:s"), $a_filter[$id]['created']['time']) ?> <?= gettext("by") ?> <strong><?= $a_filter[$id]['created']['username'] ?></strong>
1718
			</td>
1719
		</tr>
1720
		<?php endif; ?>
1721
		<?php if ($has_updated_time): ?>
1722
		<tr>
1723
			<td width="22%" valign="top" class="vncell"><?=gettext("Updated");?></td>
1724
			<td width="78%" class="vtable">
1725
				<?= date(gettext("n/j/y H:i:s"), $a_filter[$id]['updated']['time']) ?> <?= gettext("by") ?> <strong><?= $a_filter[$id]['updated']['username'] ?></strong>
1726
			</td>
1727
		</tr>
1728
		<?php endif; ?>
1729
		<?php endif; ?>
1730
		<tr>
1731
			<td width="22%" valign="top">&nbsp;</td>
1732
			<td width="78%">
1733
				&nbsp;<br />&nbsp;
1734
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
1735
				<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
1736
<?php			if (isset($id) && $a_filter[$id]): ?>
1737
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
1738
					<input name="tracker" type="hidden" value="<?=htmlspecialchars($pconfig['tracker']);?>">
1739
<?php 			endif; ?>
1740
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>" />
1741
			</td>
1742
		</tr>
1743
	</table>
1744
</form>
1745
<script type="text/javascript">
1746
//<![CDATA[
1747
	ext_change();
1748
	typesel_change();
1749
	proto_change();
1750
	<?php if ( (!empty($pconfig['srcbeginport']) && $pconfig['srcbeginport'] != "any") || (!empty($pconfig['srcendport']) && $pconfig['srcendport'] != "any") ): ?>
1751
	show_source_port_range();
1752
	<?php endif; ?>
1753

    
1754
	var addressarray = <?= json_encode(get_alias_list(array("host", "network", "openvpn", "urltable"))) ?>;
1755
	var customarray  = <?= json_encode(get_alias_list(array("port", "url_ports", "urltable_ports"))) ?>;
1756

    
1757
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1758
	var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1759
	var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1760
	var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1761
	var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1762
	var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1763
//]]>
1764
</script>
1765
<?php include("fend.inc"); ?>
1766
</body>
1767
</html>
(72-72/256)