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-2015 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
	if (($_POST['proto'] == "icmp") && ($_POST['icmptype'] <> "")){
302
		if($_POST['ipprotocol'] == "inet46")
303
			$input_errors[] =  gettext("You can not assign a ICMP type to a rule that applies to IPv4 and IPv6");
304
	}
305

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

    
326
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
327
			$_POST['dstbeginport'] = trim($_POST['dstbeginport_cust']);
328
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
329
			$_POST['dstendport'] = trim($_POST['dstendport_cust']);
330

    
331
		if ($_POST['dstbeginport'] == "any") {
332
			$_POST['dstbeginport'] = 0;
333
			$_POST['dstendport'] = 0;
334
		} else {
335
			if (!$_POST['dstendport'])
336
				$_POST['dstendport'] = $_POST['dstbeginport'];
337
		}
338
		if ($_POST['dstendport'] == "any")
339
			$_POST['dstendport'] = $_POST['dstbeginport'];
340
	}
341

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

    
361
	$pconfig = $_POST;
362

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

    
375
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
376
		if( $_POST['proto'] != "tcp" )
377
			$input_errors[] = sprintf(gettext("%s is only valid with protocol TCP."),$_POST['statetype']);
378
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
379
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
380
	}
381

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

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

    
395
	if (!$_POST['srcbeginport']) {
396
		$_POST['srcbeginport'] = 0;
397
		$_POST['srcendport'] = 0;
398
	}
399
	if (!$_POST['dstbeginport']) {
400
		$_POST['dstbeginport'] = 0;
401
		$_POST['dstendport'] = 0;
402
	}
403

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

    
433
	if ($_POST['src'])
434
		$_POST['src'] = trim($_POST['src']);
435
	if ($_POST['dst'])
436
		$_POST['dst'] = trim($_POST['dst']);
437

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

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

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

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

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

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

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

    
550
	if (($_POST['statetype'] == "none") && (empty($_POST['l7container']))) {
551
		if (!empty($_POST['max']))
552
			$input_errors[] = gettext("You cannot specify the maximum state entries (advanced option) if statetype is none and no L7 container is selected.");
553
		if (!empty($_POST['max-src-nodes']))
554
			$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.");
555
		if (!empty($_POST['max-src-conn']))
556
			$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.");
557
		if (!empty($_POST['max-src-states']))
558
			$input_errors[] = gettext("You cannot specify the maximum state entries per host (advanced option) if statetype is none and no L7 container is selected.");
559
		if (!empty($_POST['max-src-conn-rate']) || !empty($_POST['max-src-conn-rates']))
560
			$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.");
561
		if (!empty($_POST['statetimeout']))
562
			$input_errors[] = gettext("You cannot specify the state timeout (advanced option) if statetype is none and no L7 container is selected.");
563
	}
564

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

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

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

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

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

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

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

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

    
600
	// Allow extending of the firewall edit page and include custom input validation
601
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
602

    
603
	if (!$input_errors) {
604
		$filterent = array();
605
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
606

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

    
609
		$filterent['type'] = $_POST['type'];
610
		if (isset($_POST['interface'] ))
611
			$filterent['interface'] = $_POST['interface'];
612

    
613
		if (isset($_POST['ipprotocol'] ))
614
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
615

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

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

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

    
669
		/* Nosync directive - do not xmlrpc sync this item */
670
		if($_POST['nosync'] <> "")
671
			$filterent['nosync'] = true;
672
		else
673
			unset($filterent['nosync']);
674

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

    
684
		if ($_POST['proto'] != "any")
685
			$filterent['protocol'] = $_POST['proto'];
686
		else
687
			unset($filterent['protocol']);
688

    
689
		if ($_POST['proto'] == "icmp") {
690
			if ($filterent['ipprotocol'] == 'inet6' && $_POST['icmp6type'])
691
				$filterent['icmptype'] = $_POST['icmp6type'];
692
			else if ($filterent['ipprotocol'] != 'inet6' && $_POST['icmptype'])
693
				$filterent['icmptype'] = $_POST['icmptype'];
694
			else
695
				unset($filterent['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
				<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
944
					<span class="vexpl"><?=gettext("Choose the interface(s) for this rule.");?></span>
945
				<?php else: ?>
946
					<span class="vexpl"><?=gettext("Choose which interface packets must be sourced on to match this rule.");?></span>
947
				<?php endif; ?>
948
			</td>
949
		</tr>
950
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
951
		<tr>
952
			<td width="22%" valign="top" class="vncellreq">
953
				<?=gettext("Direction");?>
954
			</td>
955
			<td width="78%" class="vtable">
956
				<select name="direction" class="formselect">
957
					<?php      $directions = array('any','in','out');
958
				foreach ($directions as $direction): ?>
959
				<option value="<?=$direction;?>"
960
					<?php if ($direction == $pconfig['direction']): ?>
961
						selected="selected"
962
					<?php endif; ?>
963
					><?=$direction;?></option>
964
				<?php endforeach; ?>
965
				</select>
966
				<input type="hidden" id="floating" name="floating" value="floating" />
967
			</td>
968
		<tr>
969
<?php endif; ?>
970
		<tr>
971
			<td width="22%" valign="top" class="vncellreq"><?=gettext("TCP/IP Version");?></td>
972
			<td width="78%" class="vtable">
973
				<select name="ipprotocol" class="formselect" onchange="proto_change()">
974
					<?php      $ipproto = array('inet' => 'IPv4','inet6' => 'IPv6', 'inet46' => 'IPv4+IPv6' );
975
				foreach ($ipproto as $proto => $name): ?>
976
				<option value="<?=$proto;?>"
977
					<?php if ($proto == $pconfig['ipprotocol']): ?>
978
						selected="selected"
979
					<?php endif; ?>
980
					><?=$name;?></option>
981
				<?php endforeach; ?>
982
				</select>
983
				<strong><?=gettext("Select the Internet Protocol version this rule applies to");?></strong><br />
984
			</td>
985
		</tr>
986
		<tr>
987
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
988
			<td width="78%" class="vtable">
989
				<select <?=$edit_disabled;?> name="proto" class="formselect" onchange="proto_change()">
990
<?php
991
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IPV6 IGMP PIM OSPF SCTP any carp pfsync");
992
				foreach ($protocols as $proto): ?>
993
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($proto);?></option>
994
<?php 			endforeach; ?>
995
				</select>
996
				<br />
997
				<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>
998
			</td>
999
		</tr>
1000
		<tr id="icmpbox">
1001
			<td valign="top" class="vncell"><?=gettext("ICMP type");?></td>
1002
			<td class="vtable">
1003
				<select <?=$edit_disabled;?> name="icmptype" class="formselect">
1004
<?php
1005
				foreach ($icmptypes as $icmptype => $descr):
1006
?>
1007
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($descr);?></option>
1008
<?php
1009
				endforeach;
1010
?>
1011
				</select>
1012
				<br />
1013
				<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
1014
			</td>
1015
		</tr>
1016
		<tr id="icmp6box">
1017
			<td valign="top" class="vncell"><?=gettext("ICMPv6 type");?></td>
1018
			<td class="vtable">
1019
				<select <?=$edit_disabled;?> name="icmp6type" class="formselect">
1020
<?php
1021
				foreach ($icmp6types as $icmptype => $descr):
1022
?>
1023
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($descr);?></option>
1024
<?php
1025
				endforeach;
1026
?>
1027
				</select>
1028
				<br />
1029
				<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
1030
			</td>
1031
		</tr>
1032
		<tr>
1033
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
1034
			<td width="78%" class="vtable">
1035
				<input <?=$edit_disabled;?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked=\"checked\""; ?> />
1036
				<strong><?=gettext("not");?></strong>
1037
				<br />
1038
				<?=gettext("Use this option to invert the sense of the match.");?>
1039
				<br />
1040
				<br />
1041
				<table border="0" cellspacing="0" cellpadding="0">
1042
					<tr>
1043
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
1044
						<td>
1045
							<select <?=$edit_disabled;?> name="srctype" class="formselect" onchange="typesel_change()">
1046
<?php
1047
								$sel = is_specialnet($pconfig['src']); ?>
1048
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected=\"selected\""; } ?>><?=gettext("any");?></option>
1049
								<option value="single"
1050
						<?php  if (!$sel &&
1051
							    ((is_ipaddrv6($pconfig['src']) && $pconfig['srcmask'] == 128) ||
1052
							    (is_ipaddrv4($pconfig['src']) && $pconfig['srcmask'] == 32) || is_alias($pconfig['src'])))
1053
								{ echo "selected=\"selected\""; $sel = 1; }
1054
						?>
1055
								> <?=gettext("Single host or alias");?></option>
1056
								<option value="network" <?php if (!$sel) echo "selected=\"selected\""; ?>><?=gettext("Network");?></option>
1057
								<?PHP	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules"): ?>
1058
								<option value="(self)" <?PHP if ($pconfig['src'] == "(self)") echo "selected=\"selected\""; ?>><?=gettext("This Firewall (self)");?></option>
1059
								<?PHP endif;?>
1060
								<?php if(have_ruleint_access("pptp")): ?>
1061
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected=\"selected\""; } ?>><?=gettext("PPTP clients");?></option>
1062
								<?php endif; ?>
1063
								<?php if(have_ruleint_access("pppoe")): ?>
1064
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected=\"selected\""; } ?>><?=gettext("PPPoE clients");?></option>
1065
								<?php endif; ?>
1066
								<?php if(have_ruleint_access("l2tp")): ?>
1067
								<option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected=\"selected\""; } ?>><?=gettext("L2TP clients");?></option>
1068
								<?php endif; ?>
1069
<?php
1070
								foreach ($ifdisp as $ifent => $ifdesc): ?>
1071
								<?php if(have_ruleint_access($ifent)): ?>
1072
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected=\"selected\""; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("net");?></option>
1073
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected=\"selected\""; } ?>>
1074
										<?=$ifdesc?> <?=gettext("address");?>
1075
									</option>
1076
								<?php endif; ?>
1077
<?php 							endforeach; ?>
1078
							</select>
1079
						</td>
1080
					</tr>
1081
					<tr>
1082
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
1083
						<td>
1084
							<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']);?>" /> /
1085
							<select <?=$edit_disabled;?> name="srcmask" class="formselect ipv4v6" id="srcmask">
1086
<?php						for ($i = 127; $i > 0; $i--): ?>
1087
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected=\"selected\""; ?>><?=$i;?></option>
1088
<?php 						endfor; ?>
1089
							</select>
1090
						</td>
1091
					</tr>
1092
				</table>
1093
				<div id="showadvancedboxspr">
1094
					<p>
1095
					<input <?=$edit_disabled;?> type="button" onclick="show_source_port_range()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show source port range");?>
1096
					</p>
1097
				</div>
1098
			</td>
1099
		</tr>
1100
		<tr style="display:none" id="sprtable">
1101
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range");?></td>
1102
			<td width="78%" class="vtable">
1103
				<table border="0" cellspacing="0" cellpadding="0">
1104
					<tr>
1105
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
1106
						<td>
1107
							<select <?=$edit_disabled;?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
1108
								<option value="">(<?=gettext("other"); ?>)</option>
1109
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any");?></option>
1110
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
1111
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars("{$wkportdesc} ({$wkport})");?></option>
1112
<?php 							endforeach; ?>
1113
							</select>
1114
							<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']); ?>" />
1115
						</td>
1116
					</tr>
1117
					<tr>
1118
						<td><?=gettext("to:");?></td>
1119
						<td>
1120
							<select <?=$edit_disabled;?> name="srcendport" class="formselect" onchange="ext_change()">
1121
								<option value="">(<?=gettext("other"); ?>)</option>
1122
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any");?></option>
1123
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
1124
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars("{$wkportdesc} ({$wkport})");?></option>
1125
<?php							endforeach; ?>
1126
							</select>
1127
							<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']); ?>" />
1128
						</td>
1129
					</tr>
1130
				</table>
1131
				<br />
1132
				<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 />
1133
			</td>
1134
		</tr>
1135
		<tr>
1136
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
1137
			<td width="78%" class="vtable">
1138
				<input <?=$edit_disabled;?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked=\"checked\""; ?> />
1139
				<strong><?=gettext("not");?></strong>
1140
					<br />
1141
				<?=gettext("Use this option to invert the sense of the match.");?>
1142
					<br />
1143
					<br />
1144
				<table border="0" cellspacing="0" cellpadding="0">
1145
					<tr>
1146
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
1147
						<td>
1148
							<select <?=$edit_disabled;?> name="dsttype" class="formselect" onchange="typesel_change()">
1149
<?php
1150
								$sel = is_specialnet($pconfig['dst']); ?>
1151
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected=\"selected\""; } ?>><?=gettext("any");?></option>
1152
								<option value="single"
1153
								<?php  if (!$sel &&
1154
									    ((is_ipaddrv6($pconfig['dst']) && $pconfig['dstmask'] == 128) ||
1155
									    (is_ipaddrv4($pconfig['dst']) && $pconfig['dstmask'] == 32) || is_alias($pconfig['dst'])))
1156
										{ echo "selected=\"selected\""; $sel = 1; }
1157
								?>
1158
								><?=gettext("Single host or alias");?></option>
1159
								<option value="network" <?php if (!$sel) echo "selected=\"selected\""; ?>><?=gettext("Network");?></option>
1160
								<option value="(self)" <?PHP if ($pconfig['dst'] == "(self)") echo "selected=\"selected\""; ?>><?=gettext("This Firewall (self)");?></option>
1161
								<?php if(have_ruleint_access("pptp")): ?>
1162
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected=\"selected\""; } ?>><?=gettext("PPTP clients");?></option>
1163
								<?php endif; ?>
1164
								<?php if(have_ruleint_access("pppoe")): ?>
1165
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected=\"selected\""; } ?>><?=gettext("PPPoE clients");?></option>
1166
								<?php endif; ?>
1167
								<?php if(have_ruleint_access("l2tp")): ?>
1168
								<option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected=\"selected\""; } ?>><?=gettext("L2TP clients");?></option>
1169
								<?php endif; ?>
1170

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

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

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

    
1757
	var addressarray = <?= json_encode(get_alias_list(array("host", "network", "openvpn", "urltable"))) ?>;
1758
	var customarray  = <?= json_encode(get_alias_list(array("port", "url_ports", "urltable_ports"))) ?>;
1759

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