Project

General

Profile

Download (79.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

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

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

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

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

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

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

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

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

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

    
71
$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn");
72
$ifdisp = get_configured_interface_with_descr();
73
foreach ($ifdisp as $kif => $kdescr) {
74
	$specialsrcdst[] = "{$kif}";
75
	$specialsrcdst[] = "{$kif}ip";
76
}
77

    
78
if (!is_array($config['filter']['rule'])) {
79
	$config['filter']['rule'] = array();
80
}
81
filter_rules_sort();
82
$a_filter = &$config['filter']['rule'];
83

    
84
if (is_numericint($_GET['id']))
85
	$id = $_GET['id'];
86
if (isset($_POST['id']) && is_numericint($_POST['id']))
87
	$id = $_POST['id'];
88

    
89
if (is_numericint($_GET['after']))
90
	$after = $_GET['after'];
91
if (isset($_POST['after']) && is_numericint($_GET['after']))
92
	$after = $_POST['after'];
93

    
94
if (isset($_GET['dup']) && is_numericint($_GET['dup'])) {
95
        $id = $_GET['dup'];
96
        $after = $_GET['dup'];
97
}
98

    
99
if (isset($id) && $a_filter[$id]) {
100
	$pconfig['interface'] = $a_filter[$id]['interface'];
101

    
102
	if (isset($a_filter[$id]['id']))
103
		$pconfig['ruleid'] = $a_filter[$id]['id'];
104

    
105
	if ( isset($a_filter[$id]['created']) && is_array($a_filter[$id]['created']) )
106
		$pconfig['created'] = $a_filter[$id]['created'];
107

    
108
	if ( isset($a_filter[$id]['updated']) && is_array($a_filter[$id]['updated']) )
109
		$pconfig['updated'] = $a_filter[$id]['updated'];
110

    
111
	if (!isset($a_filter[$id]['type']))
112
		$pconfig['type'] = "pass";
113
	else
114
		$pconfig['type'] = $a_filter[$id]['type'];
115

    
116
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
117
		$pconfig['floating'] = $a_filter[$id]['floating'];
118
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "")
119
			$pconfig['interface'] = $a_filter[$id]['interface'];
120
	}
121

    
122
	if (isset($a_filter['floating']))
123
		$pconfig['floating'] = "yes";
124

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

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

    
131
	if (isset($a_filter[$id]['protocol']))
132
		$pconfig['proto'] = $a_filter[$id]['protocol'];
133
	else
134
		$pconfig['proto'] = "any";
135

    
136
	if ($a_filter[$id]['protocol'] == "icmp")
137
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
138

    
139
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
140
		$pconfig['srcmask'], $pconfig['srcnot'],
141
		$pconfig['srcbeginport'], $pconfig['srcendport']);
142

    
143
	if($a_filter[$id]['os'] <> "")
144
		$pconfig['os'] = $a_filter[$id]['os'];
145

    
146
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
147
		$pconfig['dstmask'], $pconfig['dstnot'],
148
		$pconfig['dstbeginport'], $pconfig['dstendport']);
149

    
150
	if ($a_filter[$id]['dscp'] <> "")
151
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
152

    
153
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
154
	$pconfig['log'] = isset($a_filter[$id]['log']);
155
	$pconfig['descr'] = $a_filter[$id]['descr'];
156

    
157
	if (isset($a_filter[$id]['tcpflags_any']))
158
		$pconfig['tcpflags_any'] = true;
159
	else {
160
		if (isset($a_filter[$id]['tcpflags1']) && $a_filter[$id]['tcpflags1'] <> "")
161
			$pconfig['tcpflags1'] = $a_filter[$id]['tcpflags1'];
162
		if (isset($a_filter[$id]['tcpflags2']) && $a_filter[$id]['tcpflags2'] <> "")
163
			$pconfig['tcpflags2'] = $a_filter[$id]['tcpflags2'];
164
	}
165

    
166
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "")
167
		$pconfig['tag'] = $a_filter[$id]['tag'];
168
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tagged'] <> "")
169
		$pconfig['tagged'] = $a_filter[$id]['tagged'];
170
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
171
		$pconfig['quick'] = $a_filter[$id]['quick'];
172
	if (isset($a_filter[$id]['allowopts']))
173
		$pconfig['allowopts'] = true;
174
	if (isset($a_filter[$id]['disablereplyto']))
175
		$pconfig['disablereplyto'] = true;
176

    
177
	/* advanced */
178
	$pconfig['max'] = $a_filter[$id]['max'];
179
	$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
180
	$pconfig['max-src-conn'] = $a_filter[$id]['max-src-conn'];
181
	$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
182
	$pconfig['statetype'] = $a_filter[$id]['statetype'];
183
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
184
	$pconfig['nopfsync'] = isset($a_filter[$id]['nopfsync']);
185

    
186
	/* advanced - nosync */
187
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
188

    
189
	/* advanced - new connection per second banning*/
190
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
191
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
192

    
193
	/* Multi-WAN next-hop support */
194
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
195

    
196
	/* Shaper support */
197
	$pconfig['defaultqueue'] = (($a_filter[$id]['ackqueue'] == "none") ? '' : $a_filter[$id]['defaultqueue']);
198
	$pconfig['ackqueue'] = (($a_filter[$id]['ackqueue'] == "none") ? '' : $a_filter[$id]['ackqueue']);
199
	$pconfig['dnpipe'] = (($a_filter[$id]['dnpipe'] == "none") ? '' : $a_filter[$id]['dnpipe']);
200
	$pconfig['pdnpipe'] = (($a_filter[$id]['pdnpipe'] == "none") ? '' : $a_filter[$id]['pdnpipe']);
201
	$pconfig['l7container'] = (($a_filter[$id]['l7container'] == "none") ? '' : $a_filter[$id]['l7container']);
202

    
203
	//schedule support
204
	$pconfig['sched'] = (($a_filter[$id]['sched'] == "none") ? '' : $a_filter[$id]['sched']);
205
	$pconfig['vlanprio'] = (($a_filter[$id]['vlanprio'] == "none") ? '' : $a_filter[$id]['vlanprio']);
206
	$pconfig['vlanprioset'] = (($a_filter[$id]['vlanprioset'] == "none") ? '' : $a_filter[$id]['vlanprioset']);
207
	if (!isset($_GET['dup']) || !is_numericint($_GET['dup']))
208
		$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
209

    
210
	$pconfig['tracker'] = $a_filter[$id]['tracker'];
211

    
212
} else {
213
	/* defaults */
214
	if ($_GET['if'])
215
		$pconfig['interface'] = $_GET['if'];
216
	$pconfig['type'] = "pass";
217
	$pconfig['src'] = "any";
218
	$pconfig['dst'] = "any";
219
}
220
/* Allow the FloatingRules to work */
221
$if = $pconfig['interface'];
222

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

    
226
read_altq_config(); /* XXX: */
227
$qlist =& get_unique_queue_list();
228
read_dummynet_config(); /* XXX: */
229
$dnqlist =& get_unique_dnqueue_list();
230
read_layer7_config();
231
$l7clist =& get_l7_unique_list();
232
$a_gatewaygroups = return_gateway_groups_array();
233

    
234
if ($_POST) {
235
	unset($input_errors);
236

    
237
	if( isset($a_filter[$id]['associated-rule-id']) ) {
238
		$_POST['proto'] = $pconfig['proto'];
239
		if ($pconfig['proto'] == "icmp")
240
			$_POST['icmptype'] = $pconfig['icmptype'];
241
	}
242

    
243
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "")) {
244
		if(is_array($config['gateways']['gateway_group'])) {
245
			foreach($config['gateways']['gateway_group'] as $gw_group) {
246
				if($gw_group['name'] == $_POST['gateway']) {
247
					$family = $a_gatewaygroups[$_POST['gateway']]['ipprotocol'];
248
					if($_POST['ipprotocol'] == $family) {
249
						continue;
250
					}
251
					if(($_POST['ipprotocol'] == "inet46") && ($_POST['ipprotocol'] != $family)) {
252
						$input_errors[] = gettext("You can not assign a gateway to a rule that applies to IPv4 and IPv6");
253
					}
254
					if(($_POST['ipprotocol'] == "inet6") && ($_POST['ipprotocol'] != $family)) {
255
						$input_errors[] = gettext("You can not assign a IPv4 gateway group on IPv6 Address Family rule");
256
					}
257
					if(($_POST['ipprotocol'] == "inet") && ($_POST['ipprotocol'] != $family)) {
258
						$input_errors[] = gettext("You can not assign a IPv6 gateway group on IPv4 Address Family rule");
259
					}
260
				}
261
			}
262
		}
263
	}
264
	if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "") && (is_ipaddr(lookup_gateway_ip_by_name($_POST['gateway'])))) {
265
		if(($_POST['ipprotocol'] == "inet46") && ($_POST['gateway'] <> "")) {
266
			$input_errors[] = gettext("You can not assign a gateway to a rule that applies to IPv4 and IPv6");
267
		}
268
		if(($_POST['ipprotocol'] == "inet6") && (!is_ipaddrv6(lookup_gateway_ip_by_name($_POST['gateway'])))) {
269
			$input_errors[] = gettext("You can not assign the IPv4 Gateway to a IPv6 Filter rule");
270
		}
271
		if(($_POST['ipprotocol'] == "inet") && (!is_ipaddrv4(lookup_gateway_ip_by_name($_POST['gateway'])))) {
272
			$input_errors[] = gettext("You can not assign the IPv6 Gateway to a IPv4 Filter rule");
273
		}
274
	}
275

    
276
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp") && ($_POST['proto'] != "icmp")) {
277
		if($_POST['ipprotocol'] == "inet46")
278
			$input_errors[] =  gettext("You can not assign a protocol other then ICMP, TCP, UDP or TCP/UDP to a rule that applies to IPv4 and IPv6");
279
	}
280
	if (($_POST['proto'] == "icmp") && ($_POST['icmptype'] <> "")){
281
		if($_POST['ipprotocol'] == "inet46")
282
			$input_errors[] =  gettext("You can not assign a ICMP type to a rule that applies to IPv4 and IPv6");
283
	}
284

    
285
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
286
		$_POST['srcbeginport'] = 0;
287
		$_POST['srcendport'] = 0;
288
		$_POST['dstbeginport'] = 0;
289
		$_POST['dstendport'] = 0;
290
	} else {
291
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
292
			$_POST['srcbeginport'] = trim($_POST['srcbeginport_cust']);
293
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
294
			$_POST['srcendport'] = trim($_POST['srcendport_cust']);
295
		if ($_POST['srcbeginport'] == "any") {
296
			$_POST['srcbeginport'] = 0;
297
			$_POST['srcendport'] = 0;
298
		} else {
299
			if (!$_POST['srcendport'])
300
				$_POST['srcendport'] = $_POST['srcbeginport'];
301
		}
302
		if ($_POST['srcendport'] == "any")
303
			$_POST['srcendport'] = $_POST['srcbeginport'];
304

    
305
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
306
			$_POST['dstbeginport'] = trim($_POST['dstbeginport_cust']);
307
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
308
			$_POST['dstendport'] = trim($_POST['dstendport_cust']);
309

    
310
		if ($_POST['dstbeginport'] == "any") {
311
			$_POST['dstbeginport'] = 0;
312
			$_POST['dstendport'] = 0;
313
		} else {
314
			if (!$_POST['dstendport'])
315
				$_POST['dstendport'] = $_POST['dstbeginport'];
316
		}
317
		if ($_POST['dstendport'] == "any")
318
			$_POST['dstendport'] = $_POST['dstbeginport'];
319
	}
320

    
321
	if (is_specialnet($_POST['srctype'])) {
322
		$_POST['src'] = $_POST['srctype'];
323
		$_POST['srcmask'] = 0;
324
	} else if ($_POST['srctype'] == "single") {
325
		if (is_ipaddrv6($_POST['src']))
326
			$_POST['srcmask'] = 128;
327
		else
328
			$_POST['srcmask'] = 32;
329
	}
330
	if (is_specialnet($_POST['dsttype'])) {
331
		$_POST['dst'] = $_POST['dsttype'];
332
		$_POST['dstmask'] = 0;
333
	}  else if ($_POST['dsttype'] == "single") {
334
		if (is_ipaddrv6($_POST['dst']))
335
			$_POST['dstmask'] = 128;
336
		else
337
			$_POST['dstmask'] = 32;
338
	}
339

    
340
	$pconfig = $_POST;
341

    
342
	/* input validation */
343
	$reqdfields = explode(" ", "type proto");
344
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
345
		$reqdfields[] = "src";
346
		$reqdfields[] = "dst";
347
	}
348
	$reqdfieldsn = explode(",", "Type,Protocol");
349
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
350
		$reqdfieldsn[] = "Source";
351
		$reqdfieldsn[] = "Destination";
352
	}
353

    
354
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
355
		if( $_POST['proto'] != "tcp" )
356
			$input_errors[] = sprintf(gettext("%s is only valid with protocol tcp."),$_POST['statetype']);
357
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
358
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
359
	}
360

    
361
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
362
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
363
		$reqdfields[] = "srcmask";
364
		$reqdfieldsn[] = "Source bit count";
365
	}
366
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
367
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
368
		$reqdfields[] = "dstmask";
369
		$reqdfieldsn[] = gettext("Destination bit count");
370
	}
371

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

    
374
	if (!$_POST['srcbeginport']) {
375
		$_POST['srcbeginport'] = 0;
376
		$_POST['srcendport'] = 0;
377
	}
378
	if (!$_POST['dstbeginport']) {
379
		$_POST['dstbeginport'] = 0;
380
		$_POST['dstendport'] = 0;
381
	}
382

    
383
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
384
		$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']);
385
	if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
386
			$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']);
387
	if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
388
			$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']);
389
	if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
390
			$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']);
391
	if ( !$_POST['srcbeginport_cust'] && $_POST['srcendport_cust'])
392
		if (is_alias($_POST['srcendport_cust']))
393
			$input_errors[] = 'If you put port alias in Source port range to: field you must put the same port alias in from: field';
394
	if ( $_POST['srcbeginport_cust'] && $_POST['srcendport_cust']){
395
		if (is_alias($_POST['srcendport_cust']) && is_alias($_POST['srcendport_cust']) && $_POST['srcbeginport_cust'] != $_POST['srcendport_cust'])
396
			$input_errors[] = 'The same port alias must be used in Source port range from: and to: fields';
397
		if ((is_alias($_POST['srcbeginport_cust']) && (!is_alias($_POST['srcendport_cust']) && $_POST['srcendport_cust']!='')) ||
398
		    ((!is_alias($_POST['srcbeginport_cust']) && $_POST['srcbeginport_cust']!='') && is_alias($_POST['srcendport_cust'])))
399
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Source port range from: and to: field';
400
	}
401
	if ( !$_POST['dstbeginport_cust'] && $_POST['dstendport_cust'])
402
		if (is_alias($_POST['dstendport_cust']))
403
			$input_errors[] = 'If you put port alias in Destination port range to: field you must put the same port alias in from: field';
404
	if ( $_POST['dstbeginport_cust'] && $_POST['dstendport_cust']){
405
		if (is_alias($_POST['dstendport_cust']) && is_alias($_POST['dstendport_cust']) && $_POST['dstbeginport_cust'] != $_POST['dstendport_cust'])
406
			$input_errors[] = 'The same port alias must be used in Destination port range from: and to: fields';
407
		if ((is_alias($_POST['dstbeginport_cust']) && (!is_alias($_POST['dstendport_cust']) && $_POST['dstendport_cust']!='')) ||
408
		    ((!is_alias($_POST['dstbeginport_cust']) && $_POST['dstbeginport_cust']!='') && is_alias($_POST['dstendport_cust'])))
409
			$input_errors[] = 'You cannot specify numbers and port aliases at the same time in Destination port range from: and to: field';
410
	}
411

    
412
	if ($_POST['src'])
413
		$_POST['src'] = trim($_POST['src']);
414
	if ($_POST['dst'])
415
		$_POST['dst'] = trim($_POST['dst']);
416

    
417
	/* if user enters an alias and selects "network" then disallow. */
418
	if($_POST['srctype'] == "network") {
419
		if(is_alias($_POST['src']))
420
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
421
	}
422
	if($_POST['dsttype'] == "network") {
423
		if(is_alias($_POST['dst']))
424
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
425
	}
426

    
427
	if (!is_specialnet($_POST['srctype'])) {
428
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
429
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."),$_POST['src']);
430
		}
431
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
432
			$input_errors[] = gettext("A valid source bit count must be specified.");
433
		}
434
	}
435
	if (!is_specialnet($_POST['dsttype'])) {
436
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
437
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."),$_POST['dst']);
438
		}
439
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
440
			$input_errors[] = gettext("A valid destination bit count must be specified.");
441
		}
442
	}
443
	if((is_ipaddr($_POST['src']) && is_ipaddr($_POST['dst']))) {
444
		if(!validate_address_family($_POST['src'], $_POST['dst']))
445
			$input_errors[] = sprintf(gettext("The Source IP address %s Address Family differs from the destination %s."), $_POST['src'], $_POST['dst']);
446
		if((is_ipaddrv6($_POST['src']) || is_ipaddrv6($_POST['dst'])) && ($_POST['ipprotocol'] == "inet"))
447
			$input_errors[] = gettext("You can not use IPv6 addresses in IPv4 rules.");
448
		if((is_ipaddrv4($_POST['src']) || is_ipaddrv4($_POST['dst'])) && ($_POST['ipprotocol'] == "inet6"))
449
			$input_errors[] = gettext("You can not use IPv4 addresses in IPv6 rules.");
450
	}
451

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

    
455
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
456
		/* swap */
457
		$tmp = $_POST['srcendport'];
458
		$_POST['srcendport'] = $_POST['srcbeginport'];
459
		$_POST['srcbeginport'] = $tmp;
460
	}
461
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
462
		/* swap */
463
		$tmp = $_POST['dstendport'];
464
		$_POST['dstendport'] = $_POST['dstbeginport'];
465
		$_POST['dstbeginport'] = $tmp;
466
	}
467
	if ($_POST['os'])
468
		if( $_POST['proto'] != "tcp" )
469
			$input_errors[] = gettext("OS detection is only valid with protocol tcp.");
470

    
471
	if ($_POST['ackqueue'] != "") {
472
		if ($_POST['defaultqueue'] == "" )
473
			$input_errors[] = gettext("You have to select a queue when you select an acknowledge queue too.");
474
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
475
			$input_errors[] = gettext("Acknowledge queue and Queue cannot be the same.");
476
	}
477
	if (isset($_POST['floating']) && $_POST['pdnpipe'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
478
		$input_errors[] = gettext("You can not use limiters in Floating rules without choosing a direction.");
479
	if (isset($_POST['floating']) && $_POST['gateway'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
480
		$input_errors[] = gettext("You can not use gateways in Floating rules without choosing a direction.");
481
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "") {
482
		if ($_POST['dnpipe'] == "" )
483
			$input_errors[] = gettext("You must select a queue for the In direction before selecting one for Out too.");
484
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
485
			$input_errors[] = gettext("In and Out Queue cannot be the same.");
486
		else if ($dnqlist[$_POST['pdnpipe']][0] == "?" && $dnqlist[$_POST['dnpipe']][0] <> "?")
487
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
488
		else if ($dnqlist[$_POST['dnpipe']][0] == "?" && $dnqlist[$_POST['pdnpipe']][0] <> "?")
489
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
490
		if ($_POST['direction'] == "out" && empty($_POST['gateway']))
491
			$input_errors[] = gettext("Please select a gateway, normaly the interface selected gateway, so the limiters work correctly");
492
	}
493
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
494
		$input_errors[] = gettext('ID must be an integer');
495
	if($_POST['l7container'] && $_POST['l7container'] != "") {
496
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
497
			$input_errors[] = gettext("You can only select a layer7 container for TCP and/or UDP protocols");
498
		if ($_POST['type'] <> "pass")
499
			$input_errors[] = gettext("You can only select a layer7 container for Pass type rules.");
500
	}
501

    
502
	if (!in_array($_POST['proto'], array("tcp","tcp/udp"))) {
503
		if (!empty($_POST['max-src-conn']))
504
			$input_errors[] = gettext("You can only specify the maximum number of established connections per host (advanced option) for TCP protocol.");
505
		if (!empty($_POST['max-src-conn-rate']) || !empty($_POST['max-src-conn-rates']))
506
			$input_errors[] = gettext("You can only specify the maximum new connections per host / per second(s) (advanced option) for TCP protocol.");
507
		if (!empty($_POST['statetimeout']))
508
			$input_errors[] = gettext("You can only specify the state timeout (advanced option) for TCP protocol.");
509
	}
510

    
511
	if ($_POST['type'] <> "pass") {
512
		if (!empty($_POST['max']))
513
			$input_errors[] = gettext("You can only specify the maximum state entries (advanced option) for Pass type rules.");
514
		if (!empty($_POST['max-src-nodes']))
515
			$input_errors[] = gettext("You can only specify the maximum number of unique source hosts (advanced option) for Pass type rules.");
516
		if (!empty($_POST['max-src-conn']))
517
			$input_errors[] = gettext("You can only specify the maximum number of established connections per host (advanced option) for Pass type rules.");
518
		if (!empty($_POST['max-src-states']))
519
			$input_errors[] = gettext("You can only specify the maximum state entries per host (advanced option) for Pass type rules.");
520
		if (!empty($_POST['max-src-conn-rate']) || !empty($_POST['max-src-conn-rates']))
521
			$input_errors[] = gettext("You can only specify the maximum new connections per host / per second(s) (advanced option) for Pass type rules.");
522
		if (!empty($_POST['statetimeout']))
523
			$input_errors[] = gettext("You can only specify the state timeout (advanced option) for Pass type rules.");
524
	}
525

    
526
	if (($_POST['statetype'] == "none") && (empty($_POST['l7container']))) {
527
		if (!empty($_POST['max']))
528
			$input_errors[] = gettext("You cannot specify the maximum state entries (advanced option) if statetype is none and no L7 container is selected.");
529
		if (!empty($_POST['max-src-nodes']))
530
			$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.");
531
		if (!empty($_POST['max-src-conn']))
532
			$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.");
533
		if (!empty($_POST['max-src-states']))
534
			$input_errors[] = gettext("You cannot specify the maximum state entries per host (advanced option) if statetype is none and no L7 container is selected.");
535
		if (!empty($_POST['max-src-conn-rate']) || !empty($_POST['max-src-conn-rates']))
536
			$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.");
537
		if (!empty($_POST['statetimeout']))
538
			$input_errors[] = gettext("You cannot specify the state timeout (advanced option) if statetype is none and no L7 container is selected.");
539
	}
540

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

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

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

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

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

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

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

    
563
	if (!$_POST['tcpflags_any']) {
564
		$settcpflags = array();
565
		$outoftcpflags = array();
566
		foreach ($tcpflags as $tcpflag) {
567
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
568
				$settcpflags[] = $tcpflag;
569
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
570
				$outoftcpflags[] = $tcpflag;
571
		}
572
		if (empty($outoftcpflags) && !empty($settcpflags))
573
			$input_errors[] = gettext("If you specify TCP flags that should be set you should specify out of which flags as well.");
574
	}
575

    
576
	// Allow extending of the firewall edit page and include custom input validation
577
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
578

    
579
	if (!$input_errors) {
580
		$filterent = array();
581
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
582

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

    
585
		$filterent['type'] = $_POST['type'];
586
		if (isset($_POST['interface'] ))
587
			$filterent['interface'] = $_POST['interface'];
588

    
589
		if (isset($_POST['ipprotocol'] ))
590
			$filterent['ipprotocol'] = $_POST['ipprotocol'];
591

    
592
		if ($_POST['tcpflags_any']) {
593
			$filterent['tcpflags_any'] = true;
594
		} else {
595
			$settcpflags = array();
596
			$outoftcpflags = array();
597
			foreach ($tcpflags as $tcpflag) {
598
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
599
					$settcpflags[] = $tcpflag;
600
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
601
					$outoftcpflags[] = $tcpflag;
602
			}
603
			if (!empty($outoftcpflags)) {
604
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
605
				if (!empty($settcpflags))
606
					$filterent['tcpflags1'] = join(",", $settcpflags);
607
			}
608
		}
609

    
610
		if (isset($_POST['tag']))
611
			$filterent['tag'] = $_POST['tag'];
612
		if (isset($_POST['tagged']))
613
			$filterent['tagged'] = $_POST['tagged'];
614
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
615
			$filterent['direction'] = $_POST['direction'];
616
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
617
				$filterent['quick'] = $_POST['quick'];
618
			$filterent['floating'] = "yes";
619
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
620
				$filterent['interface'] = implode(",", $_POST['interface']);
621
			}
622
		}
623

    
624
		/* Advanced options */
625
		if ($_POST['allowopts'] == "yes")
626
			$filterent['allowopts'] = true;
627
		else
628
			unset($filterent['allowopts']);
629
		if ($_POST['disablereplyto'] == "yes")
630
			$filterent['disablereplyto'] = true;
631
		else
632
			unset($filterent['disablereplyto']);
633
		$filterent['max'] = $_POST['max'];
634
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
635
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
636
		$filterent['max-src-states'] = $_POST['max-src-states'];
637
		$filterent['statetimeout'] = $_POST['statetimeout'];
638
		$filterent['statetype'] = $_POST['statetype'];
639
		$filterent['os'] = $_POST['os'];
640
		if($_POST['nopfsync'] <> "")
641
			$filterent['nopfsync'] = true;
642
		else
643
			unset($filterent['nopfsync']);
644

    
645
		/* Nosync directive - do not xmlrpc sync this item */
646
		if($_POST['nosync'] <> "")
647
			$filterent['nosync'] = true;
648
		else
649
			unset($filterent['nosync']);
650

    
651
		/* unless both values are provided, unset the values - ticket #650 */
652
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
653
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
654
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
655
		} else {
656
			unset($filterent['max-src-conn-rate']);
657
			unset($filterent['max-src-conn-rates']);
658
		}
659

    
660
		if ($_POST['proto'] != "any")
661
			$filterent['protocol'] = $_POST['proto'];
662
		else
663
			unset($filterent['protocol']);
664

    
665
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
666
			$filterent['icmptype'] = $_POST['icmptype'];
667
		else
668
			unset($filterent['icmptype']);
669

    
670
		pconfig_to_address($filterent['source'], $_POST['src'],
671
			$_POST['srcmask'], $_POST['srcnot'],
672
			$_POST['srcbeginport'], $_POST['srcendport']);
673

    
674
		pconfig_to_address($filterent['destination'], $_POST['dst'],
675
			$_POST['dstmask'], $_POST['dstnot'],
676
			$_POST['dstbeginport'], $_POST['dstendport']);
677

    
678
		if ($_POST['disabled'])
679
			$filterent['disabled'] = true;
680
		else
681
			unset($filterent['disabled']);
682

    
683
		if ($_POST['dscp'])
684
			$filterent['dscp'] = $_POST['dscp'];
685

    
686
		if ($_POST['log'])
687
			$filterent['log'] = true;
688
		else
689
			unset($filterent['log']);
690
		strncpy($filterent['descr'], $_POST['descr'], 52);
691

    
692
		if ($_POST['gateway'] != "") {
693
			$filterent['gateway'] = $_POST['gateway'];
694
		}
695

    
696
		if ($_POST['defaultqueue'] != "") {
697
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
698
			if ($_POST['ackqueue'] != "")
699
				$filterent['ackqueue'] = $_POST['ackqueue'];
700
		}
701

    
702
		if ($_POST['dnpipe'] != "") {
703
			$filterent['dnpipe'] = $_POST['dnpipe'];
704
			if ($_POST['pdnpipe'] != "")
705
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
706
		}
707

    
708
		if ($_POST['l7container'] != "") {
709
			$filterent['l7container'] = $_POST['l7container'];
710
		}
711

    
712
		if ($_POST['sched'] != "") {
713
			$filterent['sched'] = $_POST['sched'];
714
		}
715

    
716
		if ($_POST['vlanprio'] != "") {
717
			$filterent['vlanprio'] = $_POST['vlanprio'];
718
		}
719
		if ($_POST['vlanprioset'] != "") {
720
			$filterent['vlanprioset'] = $_POST['vlanprioset'];
721
		}
722

    
723
		// If we have an associated nat rule, make sure the source and destination doesn't change
724
		if( isset($a_filter[$id]['associated-rule-id']) ) {
725
			$filterent['interface'] = $a_filter[$id]['interface'];
726
			if (isset($a_filter[$id]['protocol']))
727
				$filterent['protocol'] = $a_filter[$id]['protocol'];
728
			else if (isset($filterent['protocol']))
729
				unset($filterent['protocol']);
730
			if ($a_filter[$id]['protocol'] == "icmp" && $a_filter[$id]['icmptype'])
731
				$filterent['icmptype'] = $a_filter[$id]['icmptype'];
732
			else if (isset($filterent['icmptype']))
733
				unset($filterent['icmptype']);
734

    
735
			$filterent['source'] = $a_filter[$id]['source'];
736
			$filterent['destination'] = $a_filter[$id]['destination'];
737
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
738
		}
739

    
740
		if ( isset($a_filter[$id]['created']) && is_array($a_filter[$id]['created']) )
741
			$filterent['created'] = $a_filter[$id]['created'];
742

    
743
		$filterent['updated'] = make_config_revision_entry();
744

    
745
		// Allow extending of the firewall edit page and include custom input validation
746
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
747

    
748
		if (isset($id) && $a_filter[$id])
749
			$a_filter[$id] = $filterent;
750
		else {
751
			$filterent['created'] = make_config_revision_entry();
752
			if (is_numeric($after))
753
				array_splice($a_filter, $after+1, 0, array($filterent));
754
			else
755
				$a_filter[] = $filterent;
756
		}
757

    
758
		filter_rules_sort();
759

    
760
		if (write_config())
761
			mark_subsystem_dirty('filter');
762

    
763
		if (isset($_POST['floating']))
764
			header("Location: firewall_rules.php?if=FloatingRules");
765
		else
766
			header("Location: firewall_rules.php?if=" . htmlspecialchars($_POST['interface']));
767
		exit;
768
	}
769
}
770

    
771
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
772
$shortcut_section = "firewall";
773

    
774
$closehead = false;
775

    
776
$page_filename = "firewall_rules_edit.php";
777
include("head.inc");
778

    
779
?>
780
<link rel="stylesheet" href="/javascript/chosen/chosen.css" />
781
</head>
782

    
783
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
784
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
785
<script src="/javascript/chosen/chosen.jquery.js" type="text/javascript"></script>
786
<?php include("fbegin.inc"); ?>
787
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_input_errors"); ?>
788
<?php if ($input_errors) print_input_errors($input_errors); ?>
789

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

    
793
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall rules edit">
794
		<tr>
795
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Firewall rule");?></td>
796
		</tr>
797
<?php
798
		// Allow extending of the firewall edit page and include custom input validation
799
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphpearly");
800
?>
801
		<tr>
802
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Action");?></td>
803
			<td width="78%" class="vtable">
804
				<select name="type" class="formselect">
805
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
806
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected=\"selected\""; ?>>
807
					<?=htmlspecialchars($type);?>
808
					</option>
809
					<?php endforeach; ?>
810
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
811
					<option value="match" <?php if ("match" == strtolower($pconfig['type'])) echo "selected=\"selected\""; ?>>Match</option>
812
<?php endif; ?>
813
				</select>
814
				<br/>
815
				<span class="vexpl">
816
					<?=gettext("Choose what to do with packets that match the criteria specified below.");?> <br/>
817
					<?=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.");?>
818
				</span>
819
			</td>
820
		</tr>
821
		<tr>
822
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled");?></td>
823
			<td width="78%" class="vtable">
824
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
825
				<strong><?=gettext("Disable this rule");?></strong><br />
826
				<span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list.");?></span>
827
			</td>
828
		</tr>
829
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
830
		<tr>
831
			<td width="22%" valign="top" class="vncellreq">
832
				<?=gettext("Quick");?>
833
			</td>
834
			<td width="78%" class="vtable">
835
				<input name="quick" type="checkbox" id="quick" value="yes" <?php if ($pconfig['quick']) echo "checked=\"checked\""; ?> />
836
				<strong><?=gettext("Apply the action immediately on match.");?></strong><br />
837
				<span class="vexpl"><?=gettext("Set this option if you need to apply this action to traffic that matches this rule immediately.");?></span>
838
			</td>
839
		</tr>
840
<?php endif; ?>
841
<?php $edit_disabled = ""; ?>
842
<?php if( isset($pconfig['associated-rule-id']) ): ?>
843
		<tr>
844
			<td width="22%" valign="top" class="vncell"><?=gettext("Associated filter rule");?></td>
845
			<td width="78%" class="vtable">
846
				<span class="red"><strong><?=gettext("Note: ");?></strong></span><?=gettext("This is associated to a NAT rule.");?><br />
847
				<?=gettext("You cannot edit the interface, protocol, source, or destination of associated filter rules.");?><br />
848
				<br />
849
				<?php
850
					$edit_disabled = "disabled";
851
					if (is_array($config['nat']['rule'])) {
852
						foreach( $config['nat']['rule'] as $index => $nat_rule ) {
853
							if( isset($nat_rule['associated-rule-id']) && $nat_rule['associated-rule-id']==$pconfig['associated-rule-id'] ) {
854
								echo "<a href=\"firewall_nat_edit.php?id={$index}\">" . gettext("View the NAT rule") . "</a><br/>";
855
								break;
856
							}
857
						}
858
					}
859
					echo "<input name='associated-rule-id' id='associated-rule-id' type='hidden' value='{$pconfig['associated-rule-id']}' />";
860
					if (!empty($pconfig['interface']))
861
						echo "<input name='interface' id='interface' type='hidden' value='{$pconfig['interface']}' />";
862
				?>
863
				<script type="text/javascript">
864
				editenabled = 0;
865
				</script>
866
			</td>
867
		</tr>
868
<?php endif; ?>
869
		<tr>
870
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
871
			<td width="78%" class="vtable">
872
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
873
				<select name="interface[]" title="Select interfaces..." multiple="multiple" style="width:350px;" class="chzn-select" tabindex="2" <?=$edit_disabled;?>>
874
<?php else: ?>
875
				<select name="interface" class="formselect" <?=$edit_disabled;?>>
876
<?php endif;
877
				/* add group interfaces */
878
				if (is_array($config['ifgroups']['ifgroupentry']))
879
					foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
880
						if (have_ruleint_access($ifgen['ifname']))
881
							$interfaces[$ifgen['ifname']] = $ifgen['ifname'];
882
				$ifdescs = get_configured_interface_with_descr();
883
				// Allow extending of the firewall edit page and include custom input validation
884
				pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_interfaces_edit");
885
				foreach ($ifdescs as $ifent => $ifdesc)
886
					if(have_ruleint_access($ifent))
887
							$interfaces[$ifent] = $ifdesc;
888
					if ($config['l2tp']['mode'] == "server")
889
						if(have_ruleint_access("l2tp"))
890
							$interfaces['l2tp'] = "L2TP VPN";
891
					if ($config['pptpd']['mode'] == "server")
892
						if(have_ruleint_access("pptp"))
893
							$interfaces['pptp'] = "PPTP VPN";
894

    
895
					if (is_pppoe_server_enabled() && have_ruleint_access("pppoe"))
896
						$interfaces['pppoe'] = "PPPoE VPN";
897
					/* add ipsec interfaces */
898
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
899
						if(have_ruleint_access("enc0"))
900
							$interfaces["enc0"] = "IPsec";
901
					/* add openvpn/tun interfaces */
902
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
903
						$interfaces["openvpn"] = "OpenVPN";
904
					if (is_array($pconfig['interface']))
905
						$pconfig['interface'] = implode(",", $pconfig['interface']);
906
					$selected_interfaces = explode(",", $pconfig['interface']);
907
					foreach ($interfaces as $iface => $ifacename): ?>
908
						<option value="<?=$iface;?>" <?php if ($pconfig['interface'] <> "" && ( strcasecmp($pconfig['interface'], $iface) == 0 || in_array($iface, $selected_interfaces) )) echo "selected=\"selected\""; ?>><?=$ifacename?></option>
909
<?php 				endforeach; ?>
910
				</select>
911
				<br />
912
				<span class="vexpl"><?=gettext("Choose on which interface packets must come in to match this rule.");?></span>
913
			</td>
914
		</tr>
915
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
916
		<tr>
917
			<td width="22%" valign="top" class="vncellreq">
918
				<?=gettext("Direction");?>
919
			</td>
920
			<td width="78%" class="vtable">
921
				<select name="direction" class="formselect">
922
					<?php      $directions = array('any','in','out');
923
				foreach ($directions as $direction): ?>
924
				<option value="<?=$direction;?>"
925
					<?php if ($direction == $pconfig['direction']): ?>
926
						selected="selected"
927
					<?php endif; ?>
928
					><?=$direction;?></option>
929
				<?php endforeach; ?>
930
				</select>
931
				<input type="hidden" id="floating" name="floating" value="floating" />
932
			</td>
933
		<tr>
934
<?php endif; ?>
935
		<tr>
936
			<td width="22%" valign="top" class="vncellreq"><?=gettext("TCP/IP Version");?></td>
937
			<td width="78%" class="vtable">
938
				<select name="ipprotocol" class="formselect">
939
					<?php      $ipproto = array('inet' => 'IPv4','inet6' => 'IPv6', 'inet46' => 'IPv4+IPv6' );
940
				foreach ($ipproto as $proto => $name): ?>
941
				<option value="<?=$proto;?>"
942
					<?php if ($proto == $pconfig['ipprotocol']): ?>
943
						selected="selected"
944
					<?php endif; ?>
945
					><?=$name;?></option>
946
				<?php endforeach; ?>
947
				</select>
948
				<strong><?=gettext("Select the Internet Protocol version this rule applies to");?></strong><br />
949
			</td>
950
		</tr>
951
		<tr>
952
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
953
			<td width="78%" class="vtable">
954
				<select <?=$edit_disabled;?> name="proto" class="formselect" onchange="proto_change()">
955
<?php
956
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IPV6 IGMP PIM OSPF any carp pfsync");
957
				foreach ($protocols as $proto): ?>
958
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($proto);?></option>
959
<?php 			endforeach; ?>
960
				</select>
961
				<br />
962
				<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>
963
			</td>
964
		</tr>
965
		<tr id="icmpbox">
966
			<td valign="top" class="vncell"><?=gettext("ICMP type");?></td>
967
			<td class="vtable">
968
				<select <?=$edit_disabled;?> name="icmptype" class="formselect">
969
<?php
970
				$icmptypes = array(
971
				"" => gettext("any"),
972
				"echoreq" => gettext("Echo request"),
973
				"echorep" => gettext("Echo reply"),
974
				"unreach" => gettext("Destination unreachable"),
975
				"squench" => gettext("Source quench"),
976
				"redir" => gettext("Redirect"),
977
				"althost" => gettext("Alternate Host"),
978
				"routeradv" => gettext("Router advertisement"),
979
				"routersol" => gettext("Router solicitation"),
980
				"timex" => gettext("Time exceeded"),
981
				"paramprob" => gettext("Invalid IP header"),
982
				"timereq" => gettext("Timestamp"),
983
				"timerep" => gettext("Timestamp reply"),
984
				"inforeq" => gettext("Information request"),
985
				"inforep" => gettext("Information reply"),
986
				"maskreq" => gettext("Address mask request"),
987
				"maskrep" => gettext("Address mask reply")
988
				);
989

    
990
				foreach ($icmptypes as $icmptype => $descr): ?>
991
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected=\"selected\""; ?>><?=htmlspecialchars($descr);?></option>
992
<?php 			endforeach; ?>
993
			</select>
994
			<br />
995
			<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
996
		</td>
997
		</tr>
998
		<tr>
999
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
1000
			<td width="78%" class="vtable">
1001
				<input <?=$edit_disabled;?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked=\"checked\""; ?> />
1002
				<strong><?=gettext("not");?></strong>
1003
				<br />
1004
				<?=gettext("Use this option to invert the sense of the match.");?>
1005
				<br />
1006
				<br />
1007
				<table border="0" cellspacing="0" cellpadding="0">
1008
					<tr>
1009
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
1010
						<td>
1011
							<select <?=$edit_disabled;?> name="srctype" class="formselect" onchange="typesel_change()">
1012
<?php
1013
								$sel = is_specialnet($pconfig['src']); ?>
1014
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected=\"selected\""; } ?>><?=gettext("any");?></option>
1015
								<option value="single"
1016
						<?php  if (!$sel &&
1017
							    ((is_ipaddrv6($pconfig['src']) && $pconfig['srcmask'] == 128) ||
1018
							    (is_ipaddrv4($pconfig['src']) && $pconfig['srcmask'] == 32) || is_alias($pconfig['src'])))
1019
								{ echo "selected=\"selected\""; $sel = 1; }
1020
						?>
1021
								> <?=gettext("Single host or alias");?></option>
1022
								<option value="network" <?php if (!$sel) echo "selected=\"selected\""; ?>><?=gettext("Network");?></option>
1023
								<?php if(have_ruleint_access("pptp")): ?>
1024
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected=\"selected\""; } ?>><?=gettext("PPTP clients");?></option>
1025
								<?php endif; ?>
1026
								<?php if(have_ruleint_access("pppoe")): ?>
1027
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected=\"selected\""; } ?>><?=gettext("PPPoE clients");?></option>
1028
								<?php endif; ?>
1029
								<?php if(have_ruleint_access("l2tp")): ?>
1030
								<option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected=\"selected\""; } ?>><?=gettext("L2TP clients");?></option>
1031
								<?php endif; ?>
1032
<?php
1033
								foreach ($ifdisp as $ifent => $ifdesc): ?>
1034
								<?php if(have_ruleint_access($ifent)): ?>
1035
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected=\"selected\""; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("net");?></option>
1036
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected=\"selected\""; } ?>>
1037
										<?=$ifdesc?> <?=gettext("address");?>
1038
									</option>
1039
								<?php endif; ?>
1040
<?php 							endforeach; ?>
1041
							</select>
1042
						</td>
1043
					</tr>
1044
					<tr>
1045
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
1046
						<td>
1047
							<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']);?>" /> /
1048
							<select <?=$edit_disabled;?> name="srcmask" class="formselect ipv4v6" id="srcmask">
1049
<?php						for ($i = 127; $i > 0; $i--): ?>
1050
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected=\"selected\""; ?>><?=$i;?></option>
1051
<?php 						endfor; ?>
1052
							</select>
1053
						</td>
1054
					</tr>
1055
				</table>
1056
				<div id="showadvancedboxspr">
1057
					<p>
1058
					<input <?=$edit_disabled;?> type="button" onclick="show_source_port_range()" value="<?=gettext("Advanced"); ?>" /> - <?=gettext("Show source port range");?>
1059
					</p>
1060
				</div>
1061
			</td>
1062
		</tr>
1063
		<tr style="display:none" id="sprtable">
1064
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range");?></td>
1065
			<td width="78%" class="vtable">
1066
				<table border="0" cellspacing="0" cellpadding="0">
1067
					<tr>
1068
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
1069
						<td>
1070
							<select <?=$edit_disabled;?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
1071
								<option value="">(<?=gettext("other"); ?>)</option>
1072
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any");?></option>
1073
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
1074
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars("{$wkportdesc} ({$wkport})");?></option>
1075
<?php 							endforeach; ?>
1076
							</select>
1077
							<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']); ?>" />
1078
						</td>
1079
					</tr>
1080
					<tr>
1081
						<td><?=gettext("to:");?></td>
1082
						<td>
1083
							<select <?=$edit_disabled;?> name="srcendport" class="formselect" onchange="ext_change()">
1084
								<option value="">(<?=gettext("other"); ?>)</option>
1085
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected=\"selected\""; $bfound = 1; } ?>><?=gettext("any");?></option>
1086
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
1087
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected=\"selected\""; $bfound = 1; } ?>><?=htmlspecialchars("{$wkportdesc} ({$wkport})");?></option>
1088
<?php							endforeach; ?>
1089
							</select>
1090
							<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']); ?>" />
1091
						</td>
1092
					</tr>
1093
				</table>
1094
				<br />
1095
				<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/>
1096
			</td>
1097
		</tr>
1098
		<tr>
1099
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
1100
			<td width="78%" class="vtable">
1101
				<input <?=$edit_disabled;?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked=\"checked\""; ?> />
1102
				<strong><?=gettext("not");?></strong>
1103
					<br />
1104
				<?=gettext("Use this option to invert the sense of the match.");?>
1105
					<br />
1106
					<br />
1107
				<table border="0" cellspacing="0" cellpadding="0">
1108
					<tr>
1109
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
1110
						<td>
1111
							<select <?=$edit_disabled;?> name="dsttype" class="formselect" onchange="typesel_change()">
1112
<?php
1113
								$sel = is_specialnet($pconfig['dst']); ?>
1114
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected=\"selected\""; } ?>><?=gettext("any");?></option>
1115
								<option value="single"
1116
								<?php  if (!$sel &&
1117
									    ((is_ipaddrv6($pconfig['dst']) && $pconfig['dstmask'] == 128) ||
1118
									    (is_ipaddrv4($pconfig['dst']) && $pconfig['dstmask'] == 32) || is_alias($pconfig['dst'])))
1119
										{ echo "selected=\"selected\""; $sel = 1; }
1120
								?>
1121
								><?=gettext("Single host or alias");?></option>
1122
								<option value="network" <?php if (!$sel) echo "selected=\"selected\""; ?>><?=gettext("Network");?></option>
1123
								<?php if(have_ruleint_access("pptp")): ?>
1124
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected=\"selected\""; } ?>><?=gettext("PPTP clients");?></option>
1125
								<?php endif; ?>
1126
								<?php if(have_ruleint_access("pppoe")): ?>
1127
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected=\"selected\""; } ?>><?=gettext("PPPoE clients");?></option>
1128
								<?php endif; ?>
1129
								<?php if(have_ruleint_access("l2tp")): ?>
1130
								<option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected=\"selected\""; } ?>><?=gettext("L2TP clients");?></option>
1131
								<?php endif; ?>
1132

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

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

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

    
1729
	var addressarray = <?= json_encode(get_alias_list(array("host", "network", "openvpn", "urltable"))) ?>;
1730
	var customarray  = <?= json_encode(get_alias_list(array("port", "url_ports", "urltable_ports"))) ?>;
1731

    
1732
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1733
	var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1734
	var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1735
	var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1736
	var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1737
	var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1738
//]]>
1739
</script>
1740
<?php include("fend.inc"); ?>
1741
</body>
1742
</html>
(70-70/251)