Projet

Général

Profil

Télécharger (80,2 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_rules_edit.php @ 62424bdb

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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_rules.php');
49

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
365
	$pconfig = $_POST;
366

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
786
		filter_rules_sort();
787

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

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

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

    
802
$closehead = false;
803

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

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

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

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

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

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

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

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

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

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

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

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