Project

General

Profile

Download (62.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules_edit.php
5
	part of pfSense (http://www.pfsense.com)
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("filter.inc");
46
require("shaper.inc");
47

    
48
$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn");
49
$ifdisp = get_configured_interface_with_descr();
50
foreach ($ifdisp as $kif => $kdescr) {
51
	$specialsrcdst[] = "{$kif}";
52
	$specialsrcdst[] = "{$kif}ip";
53
}
54

    
55
if (!is_array($config['filter']['rule'])) {
56
	$config['filter']['rule'] = array();
57
}
58
filter_rules_sort();
59
$a_filter = &$config['filter']['rule'];
60

    
61
$id = $_GET['id'];
62
if (is_numeric($_POST['id']))
63
	$id = $_POST['id'];
64

    
65
$after = $_GET['after'];
66

    
67
if (isset($_POST['after']))
68
	$after = $_POST['after'];
69

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

    
75
if (isset($id) && $a_filter[$id]) {
76
	$pconfig['interface'] = $a_filter[$id]['interface'];
77

    
78
	if (isset($a_filter[$id]['id']))
79
		$pconfig['ruleid'] = $a_filter[$id]['id'];
80

    
81
	if (!isset($a_filter[$id]['type']))
82
		$pconfig['type'] = "pass";
83
	else
84
		$pconfig['type'] = $a_filter[$id]['type'];
85

    
86
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
87
		$pconfig['floating'] = $a_filter[$id]['floating'];
88
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "") 
89
			$pconfig['interface'] = $a_filter[$id]['interface'];
90
	}
91
	
92
	if (isset($a_filter['floating'])) 
93
		$pconfig['floating'] = "yes";
94

    
95
	if (isset($a_filter[$id]['direction']))
96
                $pconfig['direction'] = $a_filter[$id]['direction'];
97

    
98
	if (isset($a_filter[$id]['protocol']))
99
		$pconfig['proto'] = $a_filter[$id]['protocol'];
100
	else
101
		$pconfig['proto'] = "any";
102

    
103
	if ($a_filter[$id]['protocol'] == "icmp")
104
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
105

    
106
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
107
		$pconfig['srcmask'], $pconfig['srcnot'],
108
		$pconfig['srcbeginport'], $pconfig['srcendport']);
109

    
110
	if($a_filter[$id]['os'] <> "")
111
		$pconfig['os'] = $a_filter[$id]['os'];
112

    
113
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
114
		$pconfig['dstmask'], $pconfig['dstnot'],
115
		$pconfig['dstbeginport'], $pconfig['dstendport']);
116

    
117
	if ($a_filter[$id]['dscp'] <> "")
118
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
119

    
120
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
121
	$pconfig['log'] = isset($a_filter[$id]['log']);
122
	$pconfig['descr'] = $a_filter[$id]['descr'];
123

    
124
	if (isset($a_filter[$id]['tcpflags_any']))
125
		$pconfig['tcpflags_any'] = true;
126
	else {
127
		if (isset($a_filter[$id]['tcpflags1']) && $a_filter[$id]['tcpflags1'] <> "") 
128
			$pconfig['tcpflags1'] = $a_filter[$id]['tcpflags1'];
129
		if (isset($a_filter[$id]['tcpflags2']) && $a_filter[$id]['tcpflags2'] <> "") 
130
			$pconfig['tcpflags2'] = $a_filter[$id]['tcpflags2'];
131
	}
132

    
133
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "") 
134
		$pconfig['tag'] = $a_filter[$id]['tag'];
135
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tagged'] <> "")
136
        	$pconfig['tagged'] = $a_filter[$id]['tagged'];
137
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
138
		$pconfig['quick'] = $a_filter[$id]['quick'];
139
	if (isset($a_filter[$id]['allowopts']))
140
		$pconfig['allowopts'] = true;
141
	if (isset($a_filter[$id]['disablereplyto']))
142
		$pconfig['disablereplyto'] = true;
143

    
144
	/* advanced */
145
	$pconfig['max'] = $a_filter[$id]['max'];
146
	$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
147
	$pconfig['max-src-conn'] = $a_filter[$id]['max-src-conn'];
148
	$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
149
	$pconfig['statetype'] = $a_filter[$id]['statetype'];
150
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
151

    
152
	/* advanced - nosync */
153
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
154

    
155
	/* advanced - new connection per second banning*/
156
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
157
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
158

    
159
	/* Multi-WAN next-hop support */
160
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
161
	
162
	/* Shaper support */
163
	$pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
164
	$pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
165
	$pconfig['dnpipe'] = $a_filter[$id]['dnpipe'];
166
	$pconfig['pdnpipe'] = $a_filter[$id]['pdnpipe'];
167
	$pconfig['l7container'] = $a_filter[$id]['l7container'];
168

    
169
	//schedule support
170
	$pconfig['sched'] = $a_filter[$id]['sched'];
171
	if (!isset($_GET['dup']))
172
		$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
173

    
174
} else {
175
	/* defaults */
176
	if ($_GET['if'])
177
		$pconfig['interface'] = $_GET['if'];
178
	$pconfig['type'] = "pass";
179
	$pconfig['src'] = "any";
180
	$pconfig['dst'] = "any";
181
}
182
/* Allow the FlotingRules to work */
183
$if = $pconfig['interface'];
184

    
185
if (isset($_GET['dup']))
186
	unset($id);
187

    
188
if ($_POST) {
189

    
190
	if( isset($a_filter[$id]['associated-rule-id']) ) {
191
		$_POST['proto'] = $pconfig['proto'];
192
		if ($pconfig['proto'] == "icmp")
193
			$_POST['icmptype'] = $pconfig['icmptype'];
194
	}
195

    
196
	if ($_POST['type'] == "reject" && $_POST['proto'] <> "tcp")
197
		$input_errors[] = gettext("Reject type rules only works when the protocol is set to TCP.");
198

    
199
	if ($_POST['type'] == "match" && $_POST['defaultqueue'] == "none")
200
		$input_errors[] = gettext("Queue type rules only work with queues.");
201

    
202
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
203
		$_POST['srcbeginport'] = 0;
204
		$_POST['srcendport'] = 0;
205
		$_POST['dstbeginport'] = 0;
206
		$_POST['dstendport'] = 0;
207
	} else {
208

    
209
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
210
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
211
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
212
			$_POST['srcendport'] = $_POST['srcendport_cust'];
213

    
214
		if ($_POST['srcbeginport'] == "any") {
215
			$_POST['srcbeginport'] = 0;
216
			$_POST['srcendport'] = 0;
217
		} else {
218
			if (!$_POST['srcendport'])
219
				$_POST['srcendport'] = $_POST['srcbeginport'];
220
		}
221
		if ($_POST['srcendport'] == "any")
222
			$_POST['srcendport'] = $_POST['srcbeginport'];
223

    
224
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
225
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
226
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
227
			$_POST['dstendport'] = $_POST['dstendport_cust'];
228

    
229
		if ($_POST['dstbeginport'] == "any") {
230
			$_POST['dstbeginport'] = 0;
231
			$_POST['dstendport'] = 0;
232
		} else {
233
			if (!$_POST['dstendport'])
234
				$_POST['dstendport'] = $_POST['dstbeginport'];
235
		}
236
		if ($_POST['dstendport'] == "any")
237
			$_POST['dstendport'] = $_POST['dstbeginport'];
238
	}
239

    
240
	if (is_specialnet($_POST['srctype'])) {
241
		$_POST['src'] = $_POST['srctype'];
242
		$_POST['srcmask'] = 0;
243
	} else if ($_POST['srctype'] == "single") {
244
		$_POST['srcmask'] = 32;
245
	}
246
	if (is_specialnet($_POST['dsttype'])) {
247
		$_POST['dst'] = $_POST['dsttype'];
248
		$_POST['dstmask'] = 0;
249
	}  else if ($_POST['dsttype'] == "single") {
250
		$_POST['dstmask'] = 32;
251
	}
252

    
253
	unset($input_errors);
254
	$pconfig = $_POST;
255

    
256
	/* input validation */
257
	$reqdfields = explode(" ", "type proto");
258
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
259
		$reqdfields[] = "src";
260
		$reqdfields[] = "dst";
261
	}
262
	$reqdfieldsn = explode(",", "Type,Protocol");
263
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
264
		$reqdfieldsn[] = "Source";
265
		$reqdfieldsn[] = "Destination";
266
	}
267

    
268
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
269
		if( $_POST['proto'] != "tcp" )
270
			$input_errors[] = sprintf(gettext("%s is only valid with protocol tcp."),$_POST['statetype']);
271
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
272
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
273
	}
274
        
275
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
276
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
277
		$reqdfields[] = "srcmask";
278
		$reqdfieldsn[] = "Source bit count";
279
	}
280
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
281
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
282
		$reqdfields[] = "dstmask";
283
		$reqdfieldsn[] = gettext("Destination bit count");
284
	}
285

    
286
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
287

    
288
	if (!$_POST['srcbeginport']) {
289
		$_POST['srcbeginport'] = 0;
290
		$_POST['srcendport'] = 0;
291
	}
292
	if (!$_POST['dstbeginport']) {
293
		$_POST['dstbeginport'] = 0;
294
		$_POST['dstendport'] = 0;
295
	}
296

    
297
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
298
                $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']);
299
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
300
                $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']);
301
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
302
                $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']);
303
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
304
                $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']);
305

    
306
	/* if user enters an alias and selects "network" then disallow. */
307
	if($_POST['srctype'] == "network") {
308
		if(is_alias($_POST['src']))
309
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
310
	}
311
	if($_POST['dsttype'] == "network") {
312
		if(is_alias($_POST['dst']))
313
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
314
	}
315

    
316
	if (!is_specialnet($_POST['srctype'])) {
317
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
318
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."),$_POST['src']);
319
		}
320
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
321
			$input_errors[] = gettext("A valid source bit count must be specified.");
322
		}
323
	}
324
	if (!is_specialnet($_POST['dsttype'])) {
325
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
326
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."),$_POST['dst']);
327
		}
328
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
329
			$input_errors[] = gettext("A valid destination bit count must be specified.");
330
		}
331
	}
332

    
333
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
334
		/* swap */
335
		$tmp = $_POST['srcendport'];
336
		$_POST['srcendport'] = $_POST['srcbeginport'];
337
		$_POST['srcbeginport'] = $tmp;
338
	}
339
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
340
		/* swap */
341
		$tmp = $_POST['dstendport'];
342
		$_POST['dstendport'] = $_POST['dstbeginport'];
343
		$_POST['dstbeginport'] = $tmp;
344
	}
345
	if ($_POST['os'])
346
		if( $_POST['proto'] != "tcp" )
347
			$input_errors[] = gettext("OS detection is only valid with protocol tcp.");
348

    
349
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
350
		if ($_POST['defaultqueue'] == "none" )
351
			$input_errors[] = gettext("You have to select a queue when you select an acknowledge queue too.");
352
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
353
			$input_errors[] = gettext("Acknowledge queue and Queue cannot be the same.");		
354
	}
355
	if (isset($_POST['floating']) && $_POST['pdnpipe'] != "none" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
356
		$input_errors[] = gettext("You can not use limiters in Floating rules without choosing a direction.");
357
	if (isset($_POST['floating']) && $_POST['gateway'] != "" && (empty($_POST['direction']) || $_POST['direction'] == "any"))
358
		$input_errors[] = gettext("You can not use gateways in Floating rules without choosing a direction.");
359
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
360
		if ($_POST['dnpipe'] == "none" )
361
			$input_errors[] = gettext("You must select a queue for the In direction before selecting one for Out too.");
362
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
363
			$input_errors[] = gettext("In and Out Queue cannot be the same.");
364
		else if ($pdnpipe[0] == "?" && $dnpipe[0] <> "?")
365
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
366
		else if ($dnpipe[0] == "?" && $pdnpipe[0] <> "?")			
367
			$input_errors[] = gettext("You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.");
368
	}
369
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
370
		$input_errors[] = gettext('ID must be an integer');
371
	if($_POST['l7container'] && $_POST['l7container'] != "none") {
372
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
373
			$input_errors[] = gettext("You can only select a layer7 container for TCP and/or UDP protocols");
374
		if ($_POST['type'] <> "pass")
375
			$input_errors[] = gettext("You can only select a layer7 container for Pass type rules.");
376
	}
377

    
378
	if (!$_POST['tcpflags_any']) {
379
		$settcpflags = array();
380
		$outoftcpflags = array();
381
		foreach ($tcpflags as $tcpflag) {
382
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
383
				$settcpflags[] = $tcpflag;
384
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
385
				$outoftcpflags[] = $tcpflag;
386
		}
387
		if (empty($outoftcpflags) && !empty($settcpflags))
388
			$input_errors[] = gettext("If you specify TCP flags that should be set you should specify out of which flags as well.");
389
	}
390

    
391
	// Allow extending of the firewall edit page and include custom input validation 
392
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/input_validation");
393

    
394
	if (!$input_errors) {
395
		$filterent = array();
396
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
397
		$filterent['type'] = $_POST['type'];
398
		if (isset($_POST['interface'] ))
399
			$filterent['interface'] = $_POST['interface'];
400

    
401
		if ($_POST['tcpflags_any']) {
402
			$filterent['tcpflags_any'] = true;
403
		} else {
404
			$settcpflags = array();
405
			$outoftcpflags = array();
406
			foreach ($tcpflags as $tcpflag) {
407
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
408
					$settcpflags[] = $tcpflag;
409
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
410
					$outoftcpflags[] = $tcpflag;
411
			}
412
			if (!empty($outoftcpflags)) {
413
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
414
				if (!empty($settcpflags))
415
					$filterent['tcpflags1'] = join(",", $settcpflags);
416
			}
417
		}
418

    
419
		if (isset($_POST['tag']))
420
			$filterent['tag'] = $_POST['tag'];
421
		if (isset($_POST['tagged']))
422
			$filterent['tagged'] = $_POST['tagged'];
423
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
424
			$filterent['direction'] = $_POST['direction'];
425
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
426
				$filterent['quick'] = $_POST['quick'];
427
			$filterent['floating'] = "yes";
428
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
429
				$filterent['interface'] = implode(",", $_POST['interface']);
430
			}
431
		}
432

    
433
		/* Advanced options */
434
		if ($_POST['allowopts'] == "yes")
435
			$filterent['allowopts'] = true;
436
		else
437
			unset($filterent['allowopts']);
438
		if ($_POST['disablereplyto'] == "yes")
439
			$filterent['disablereplyto'] = true;
440
		else
441
			unset($filterent['disablereplyto']);
442
		$filterent['max'] = $_POST['max'];
443
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
444
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
445
		$filterent['max-src-states'] = $_POST['max-src-states'];
446
		$filterent['statetimeout'] = $_POST['statetimeout'];
447
		$filterent['statetype'] = $_POST['statetype'];
448
		$filterent['os'] = $_POST['os'];
449

    
450
		/* Nosync directive - do not xmlrpc sync this item */
451
		if($_POST['nosync'] <> "")
452
			$filterent['nosync'] = true;
453
		else
454
			unset($filterent['nosync']);
455

    
456
		/* unless both values are provided, unset the values - ticket #650 */
457
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
458
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
459
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
460
		} else {
461
			unset($filterent['max-src-conn-rate']);
462
			unset($filterent['max-src-conn-rates']);
463
		}
464

    
465
		if ($_POST['proto'] != "any")
466
			$filterent['protocol'] = $_POST['proto'];
467
		else
468
			unset($filterent['protocol']);
469

    
470
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
471
			$filterent['icmptype'] = $_POST['icmptype'];
472
		else
473
			unset($filterent['icmptype']);
474

    
475
		pconfig_to_address($filterent['source'], $_POST['src'],
476
			$_POST['srcmask'], $_POST['srcnot'],
477
			$_POST['srcbeginport'], $_POST['srcendport']);
478

    
479
		pconfig_to_address($filterent['destination'], $_POST['dst'],
480
			$_POST['dstmask'], $_POST['dstnot'],
481
			$_POST['dstbeginport'], $_POST['dstendport']);
482

    
483
		if ($_POST['disabled'])
484
			$filterent['disabled'] = true;
485
		else
486
			unset($filterent['disabled']);
487

    
488
		if ($_POST['dscp'])
489
			$filterent['dscp'] = $_POST['dscp'];
490

    
491
		if ($_POST['log'])
492
			$filterent['log'] = true;
493
		else
494
			unset($filterent['log']);
495
		strncpy($filterent['descr'], $_POST['descr'], 52);
496

    
497
		if ($_POST['gateway'] != "") {
498
			$filterent['gateway'] = $_POST['gateway'];
499
		}
500
		
501
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
502
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
503
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
504
				$filterent['ackqueue'] = $_POST['ackqueue'];
505
		}
506

    
507
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
508
			$filterent['dnpipe'] = $_POST['dnpipe'];
509
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
510
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
511
		}
512

    
513
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
514
			$filterent['l7container'] = $_POST['l7container'];
515
		}
516
		
517
		if ($_POST['sched'] != "") {
518
			$filterent['sched'] = $_POST['sched'];
519
		}
520

    
521
		// If we have an associated nat rule, make sure the source and destination doesn't change
522
		if( isset($a_filter[$id]['associated-rule-id']) ) {
523
			$filterent['interface'] = $a_filter[$id]['interface'];
524
			if (isset($a_filter[$id]['protocol']))
525
				$filterent['protocol'] = $a_filter[$id]['protocol'];
526
			else if (isset($filterent['protocol']))
527
				unset($filterent['protocol']);
528
			if ($a_filter[$id]['protocol'] == "icmp" && $a_filter[$id]['icmptype'])
529
				$filterent['icmptype'] = $a_filter[$id]['icmptype'];
530
			else if (isset($filterent['icmptype']))
531
				unset($filterent['icmptype']);
532
			$filterent['source'] = $a_filter[$id]['source'];
533
			$filterent['destination'] = $a_filter[$id]['destination'];
534
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
535
		}
536

    
537
		// Allow extending of the firewall edit page and include custom input validation 
538
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_write_config");
539

    
540
		if (isset($id) && $a_filter[$id])
541
			$a_filter[$id] = $filterent;
542
		else {
543
			if (is_numeric($after))
544
				array_splice($a_filter, $after+1, 0, array($filterent));
545
			else
546
				$a_filter[] = $filterent;
547
		}
548

    
549
		filter_rules_sort();
550

    
551
		write_config();
552
		mark_subsystem_dirty('filter');
553

    
554
		if (isset($_POST['floating']))
555
			header("Location: firewall_rules.php?if=FloatingRules");
556
		else
557
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
558
		exit;
559
	}
560
}
561

    
562
read_altq_config(); /* XXX: */
563
$qlist =& get_unique_queue_list();
564
read_dummynet_config(); /* XXX: */
565
$dnqlist =& get_unique_dnqueue_list();
566
read_layer7_config();
567
$l7clist =& get_l7_unique_list();
568

    
569
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
570
$statusurl = "status_filter_reload.php";
571
$logurl = "diag_logs_filter.php";
572

    
573
$closehead = false;
574

    
575
$page_filename = "firewall_rules_edit.php";
576
include("head.inc");
577

    
578
?>
579

    
580
</head>
581

    
582
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
583
<?php include("fbegin.inc"); ?>
584
<?php if ($input_errors) print_input_errors($input_errors); ?>
585

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

    
589
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
590
		<tr>
591
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit Firewall rule");?></td>
592
		</tr>	
593
<?php
594
		// Allow extending of the firewall edit page and include custom input validation 
595
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphpearly");
596
?>
597
    	<tr>
598
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Action");?></td>
599
			<td width="78%" class="vtable">
600
				<select name="type" class="formselect">
601
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
602
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
603
					<?=htmlspecialchars($type);?>
604
					</option>
605
					<?php endforeach; ?>
606
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
607
					<option value="match" <?php if ("match" == strtolower($pconfig['type'])) echo "selected"; ?>>Queue</option>
608
<?php endif; ?>
609
				</select>
610
				<br/>
611
				<span class="vexpl">
612
					<?=gettext("Choose what to do with packets that match the criteria specified below.");?> <br/>
613
					<?=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.");?> 
614
				</span>
615
			</td>
616
		</tr>
617
		<tr>
618
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled");?></td>
619
			<td width="78%" class="vtable">
620
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
621
				<strong><?=gettext("Disable this rule");?></strong><br />
622
				<span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list.");?></span>
623
			</td>
624
		</tr>
625
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
626
		<tr>
627
			<td width="22%" valign="top" class="vncellreq">
628
				<?=gettext("Quick");?>
629
			</td>
630
			<td width="78%" class="vtable">
631
				<input name="quick" type="checkbox" id="quick" value="yes" <?php if ($pconfig['quick']) echo "checked=\"checked\""; ?> />
632
				<strong><?=gettext("Apply the action immediately on match.");?></strong><br />
633
				<span class="vexpl"><?=gettext("Set this option if you need to apply this action to traffic that matches this rule immediately.");?></span>
634
			</td>
635
		</tr>
636
<?php endif; ?>
637
<?php $edit_disabled = ""; ?>
638
<?php if( isset($pconfig['associated-rule-id']) ): ?>
639
		<tr>
640
			<td width="22%" valign="top" class="vncell"><?=gettext("Associated filter rule");?></td>
641
			<td width="78%" class="vtable">
642
				<span class="red"><strong><?=gettext("NOTE: ");?></strong></span><?=gettext("This is associated to a NAT rule.");?><br />
643
				<?=gettext("You cannot edit the interface, protocol, source, or destination of associated filter rules.");?><br />
644
				<br />
645
				<?php
646
					$edit_disabled = "disabled";
647
					if (is_array($config['nat']['rule'])) {
648
						foreach( $config['nat']['rule'] as $index => $nat_rule ) {
649
							if( isset($nat_rule['associated-rule-id']) && $nat_rule['associated-rule-id']==$pconfig['associated-rule-id'] ) {
650
								echo "<a href=\"firewall_nat_edit.php?id={$index}\">" . gettext("View the NAT rule") . "</a><br>";
651
								break;
652
							}
653
						}
654
					}
655
					echo "<input name='associated-rule-id' id='associated-rule-id' type='hidden' value='{$pconfig['associated-rule-id']}' >";
656
					if (!empty($pconfig['interface']))
657
						echo "<input name='interface' id='interface' type='hidden' value='{$pconfig['interface']}' >";
658
				?>
659
				<script type="text/javascript">
660
				editenabled = 0;
661
				</script>
662
			</td>
663
		</tr>
664
<?php endif; ?>
665
		<tr>
666
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
667
			<td width="78%" class="vtable">
668
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
669
				<select name="interface[]" multiple="true" class="formselect" size="3" <?=$edit_disabled;?>>
670
<?php else: ?>
671
				<select name="interface" class="formselect" <?=$edit_disabled;?>>
672
<?php
673
   endif;
674
				/* add group interfaces */
675
				if (is_array($config['ifgroups']['ifgroupentry']))
676
					foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
677
						if (have_ruleint_access($ifgen['ifname']))
678
							$interfaces[$ifgen['ifname']] = $ifgen['ifname'];
679
				$ifdescs = get_configured_interface_with_descr();
680
				foreach ($ifdescs as $ifent => $ifdesc)
681
        				if(have_ruleint_access($ifent))
682
							$interfaces[$ifent] = $ifdesc;
683
					if ($config['l2tp']['mode'] == "server")
684
						if(have_ruleint_access("l2tp"))
685
							$interfaces['l2tp'] = "L2TP VPN";
686
					if ($config['pptpd']['mode'] == "server")
687
						if(have_ruleint_access("pptp")) 
688
							$interfaces['pptp'] = "PPTP VPN";
689
					
690
					if (is_pppoe_server_enabled() && have_ruleint_access("pppoe"))
691
						$interfaces['pppoe'] = "PPPoE VPN";
692
					/* add ipsec interfaces */
693
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
694
						if(have_ruleint_access("enc0")) 
695
							$interfaces["enc0"] = "IPsec";
696
					/* add openvpn/tun interfaces */
697
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
698
						$interfaces["openvpn"] = "OpenVPN";
699
					$selected_interfaces = explode(",", $pconfig['interface']);
700
					foreach ($interfaces as $iface => $ifacename): ?>
701
						<option value="<?=$iface;?>" <?php if ($pconfig['interface'] <> "" && ( strcasecmp($pconfig['interface'], $iface) == 0 || in_array($iface, $selected_interfaces) )) echo "selected"; ?>><?=$ifacename?></option>
702
<?php 				endforeach; ?>
703
				</select>
704
				<br />
705
				<span class="vexpl"><?=gettext("Choose on which interface packets must come in to match this rule.");?></span>
706
			</td>
707
		</tr>
708
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
709
		<tr>
710
			<td width="22%" valign="top" class="vncellreq">
711
				<?=gettext("Direction");?>
712
			</td>
713
			<td width="78%" class="vtable">
714
				<select name="direction" class="formselect">
715
					<?php      $directions = array('any','in','out');
716
				foreach ($directions as $direction): ?>
717
				<option value="<?=$direction;?>"
718
					<?php if ($direction == $pconfig['direction']): ?>
719
						selected="selected" 
720
					<?php endif; ?>
721
					><?=$direction;?></option>
722
				<?php endforeach; ?>      
723
				</select>
724
				<input type="hidden" id="floating" name="floating" value="floating">
725
			</td>
726
		<tr>
727
<?php endif; ?>
728
		<tr>
729
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Protocol");?></td>
730
			<td width="78%" class="vtable">
731
				<select <?=$edit_disabled;?> name="proto" class="formselect" onchange="proto_change()">
732
<?php
733
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IGMP OSPF any carp pfsync");
734
				foreach ($protocols as $proto): ?>
735
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
736
<?php 			endforeach; ?>
737
				</select>
738
				<br />
739
				<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>
740
			</td>
741
		</tr>
742
		<tr id="icmpbox" name="icmpbox">
743
			<td valign="top" class="vncell"><?=gettext("ICMP type");?></td>
744
			<td class="vtable">
745
				<select <?=$edit_disabled;?> name="icmptype" class="formselect">
746
<?php
747
				$icmptypes = array(
748
				"" => gettext("any"),
749
				"echoreq" => gettext("Echo request"),
750
				"echorep" => gettext("Echo reply"),
751
				"unreach" => gettext("Destination unreachable"),
752
				"squench" => gettext("Source quench"),
753
				"redir" => gettext("Redirect"),
754
				"althost" => gettext("Alternate Host"),
755
				"routeradv" => gettext("Router advertisement"),
756
				"routersol" => gettext("Router solicitation"),
757
				"timex" => gettext("Time exceeded"),
758
				"paramprob" => gettext("Invalid IP header"),
759
				"timereq" => gettext("Timestamp"),
760
				"timerep" => gettext("Timestamp reply"),
761
				"inforeq" => gettext("Information request"),
762
				"inforep" => gettext("Information reply"),
763
				"maskreq" => gettext("Address mask request"),
764
				"maskrep" => gettext("Address mask reply")
765
				);
766

    
767
				foreach ($icmptypes as $icmptype => $descr): ?>
768
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
769
<?php 			endforeach; ?>
770
			</select>
771
			<br />
772
			<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
773
		</td>
774
		</tr>
775
		<tr>
776
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
777
			<td width="78%" class="vtable">
778
				<input <?=$edit_disabled;?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
779
				<strong><?=gettext("not");?></strong>
780
				<br />
781
				<?=gettext("Use this option to invert the sense of the match.");?>
782
				<br />
783
				<br />
784
				<table border="0" cellspacing="0" cellpadding="0">
785
					<tr>
786
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
787
						<td>
788
							<select <?=$edit_disabled;?> name="srctype" class="formselect" onChange="typesel_change()">
789
<?php
790
								$sel = is_specialnet($pconfig['src']); ?>
791
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
792
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>><?=gettext("Single host or alias");?></option>
793
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
794
								<?php if(have_ruleint_access("pptp")): ?>
795
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
796
								<?php endif; ?>
797
								<?php if(have_ruleint_access("pppoe")): ?>
798
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
799
								<?php endif; ?>								
800
								 <?php if(have_ruleint_access("l2tp")): ?>
801
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
802
                                                                <?php endif; ?>
803
<?php
804
								foreach ($ifdisp as $ifent => $ifdesc): ?>
805
								<?php if(have_ruleint_access($ifent)): ?>
806
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?><?=gettext(" subnet");?></option>
807
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
808
										<?=$ifdesc?> <?=gettext("address");?>
809
									</option>
810
								<?php endif; ?>
811
<?php 							endforeach; ?>
812
							</select>
813
						</td>
814
					</tr>
815
					<tr>
816
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
817
						<td>
818
							<input <?=$edit_disabled;?> autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
819
							<select <?=$edit_disabled;?> name="srcmask" class="formselect" id="srcmask">
820
<?php						for ($i = 31; $i > 0; $i--): ?>
821
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
822
<?php 						endfor; ?>
823
							</select>
824
						</td>
825
					</tr>
826
				</table>
827
				<div id="showadvancedboxspr">
828
					<p>
829
					<input <?=$edit_disabled;?> type="button" onClick="show_source_port_range()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show source port range");?></a>
830
				</div>
831
			</td>
832
		</tr>
833
		<tr style="display:none" id="sprtable" name="sprtable">
834
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range");?></td>
835
			<td width="78%" class="vtable">
836
				<table border="0" cellspacing="0" cellpadding="0">
837
					<tr>
838
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
839
						<td>
840
							<select <?=$edit_disabled;?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
841
								<option value="">(<?=gettext("other"); ?>)</option>
842
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
843
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
844
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
845
<?php 							endforeach; ?>
846
							</select>
847
							<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']); ?>">
848
						</td>
849
					</tr>
850
					<tr>
851
						<td><?=gettext("to:");?></td>
852
						<td>
853
							<select <?=$edit_disabled;?> name="srcendport" class="formselect" onchange="ext_change()">
854
								<option value="">(<?=gettext("other"); ?>)</option>
855
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
856
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
857
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
858
<?php							endforeach; ?>
859
							</select>
860
							<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']); ?>">
861
						</td>
862
					</tr>
863
				</table>
864
				<br />
865
				<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/>
866
			</td>
867
		</tr>
868
		<tr>
869
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
870
			<td width="78%" class="vtable">
871
				<input <?=$edit_disabled;?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
872
				<strong><?=gettext("not");?></strong>
873
					<br />
874
				<?=gettext("Use this option to invert the sense of the match.");?>
875
					<br />
876
					<br />
877
				<table border="0" cellspacing="0" cellpadding="0">
878
					<tr>
879
						<td><?=gettext("Type:");?>&nbsp;&nbsp;</td>
880
						<td>
881
							<select <?=$edit_disabled;?> name="dsttype" class="formselect" onChange="typesel_change()">
882
<?php
883
								$sel = is_specialnet($pconfig['dst']); ?>
884
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
885
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>><?=gettext("Single host or alias");?></option>
886
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
887
								<?php if(have_ruleint_access("pptp")): ?>
888
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
889
								<?php endif; ?>
890
								<?php if(have_ruleint_access("pppoe")): ?>
891
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
892
								<?php endif; ?>								
893
								<?php if(have_ruleint_access("l2tp")): ?>
894
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
895
                                                                <?php endif; ?>
896

    
897
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
898
								<?php if(have_ruleint_access($if)): ?>
899
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> <?=gettext("subnet");?></option>
900
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
901
										<?=$ifdesc;?> <?=gettext("address");?>
902
									</option>
903
								<?php endif; ?>
904
<?php 							endforeach; ?>
905
							</select>
906
						</td>
907
					</tr>
908
					<tr>
909
						<td><?=gettext("Address:");?>&nbsp;&nbsp;</td>
910
						<td>
911
							<input <?=$edit_disabled;?> autocomplete='off' name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
912
							/
913
							<select <?=$edit_disabled;?> name="dstmask" class="formselect" id="dstmask">
914
<?php
915
							for ($i = 31; $i > 0; $i--): ?>
916
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
917
<?php						endfor; ?>
918
							</select>
919
						</td>
920
					</tr>
921
				</table>
922
			</td>
923
		</tr>
924
		<tr id="dprtr" name="dprtr">
925
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination port range ");?></td>
926
			<td width="78%" class="vtable">
927
				<table border="0" cellspacing="0" cellpadding="0">
928
					<tr>
929
						<td><?=gettext("from:");?>&nbsp;&nbsp;</td>
930
						<td>
931
							<select <?=$edit_disabled;?> name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
932
								<option value="">(<?=gettext("other"); ?>)</option>
933
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
934
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
935
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
936
<?php 							endforeach; ?>
937
							</select>
938
							<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']); ?>">
939
						</td>
940
					</tr>
941
					<tr>
942
						<td><?=gettext("to:");?></td>
943
						<td>
944
							<select <?=$edit_disabled;?> name="dstendport" class="formselect" onchange="ext_change()">
945
								<option value="">(<?=gettext("other"); ?>)</option>
946
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
947
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
948
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
949
<?php 							endforeach; ?>
950
							</select>
951
								<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']); ?>">
952
						</td>
953
					</tr>
954
				</table>
955
				<br />
956
				<span class="vexpl">
957
					<?=gettext("Specify the port or port range for the destination of the packet for this rule.");?>
958
					<br />
959
					<?=gettext("Hint: you can leave the"); ?> <em><?=gettext("'to'"); ?></em> <?=gettext("field empty if you only want to filter a single port");?>
960
				</span>
961
			</td>
962
		</tr>
963
		<tr>
964
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Log");?></td>
965
			<td width="78%" class="vtable">
966
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
967
				<strong><?=gettext("Log packets that are handled by this rule");?></strong>
968
				<br />
969
				<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>
970
			</td>
971
		</tr>
972
		<tr>
973
			<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
974
			<td width="78%" class="vtable">
975
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
976
				<br />
977
				<span class="vexpl"><?=gettext("You may enter a description here for your reference.");?></span>
978
			</td>
979
		</tr>
980
<?php		if (!isset($id) || !($a_filter[$id] && firewall_check_for_advanced_options($a_filter[$id]) <> "")): ?>
981
		<tr>
982
			<td width="22%" valign="top">&nbsp;</td>
983
			<td width="78%">
984
				&nbsp;<br>&nbsp;
985
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
986
<?php			if (isset($id) && $a_filter[$id]): ?>
987
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
988
<?php 			endif; ?>
989
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>">
990
			</td>
991
		</tr>
992
<?php		endif; ?>
993
		<tr>
994
			<td>&nbsp;</td>
995
		</tr>
996
		<tr>
997
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Advanced features");?></td>
998
		</tr>	
999
		<tr>
1000
			<td width="22%" valign="top" class="vncell"><?=gettext("Source OS");?></td>
1001
			<td width="78%" class="vtable">
1002
				<div id="showadvsourceosbox" <?php if ($pconfig['os']) echo "style='display:none'"; ?>>
1003
					<input type="button" onClick="show_advanced_sourceos()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1004
				</div>
1005
				<div id="showsourceosadv" <?php if (empty($pconfig['os'])) echo "style='display:none'"; ?>>
1006
					<?=gettext("OS Type:");?>&nbsp;
1007
					<select name="os" id="os" class="formselect">
1008
<?php
1009
						$ostypes = array(
1010
							 "" => gettext("any"),
1011
							"AIX" => "AIX",
1012
							"Linux" => "Linux",
1013
							"FreeBSD" => "FreeBSD",
1014
							"NetBSD" => "NetBSD",
1015
							"OpenBSD" => "OpenBSD",
1016
							"Solaris" => "Solaris",
1017
							"MacOS" => "MacOS",
1018
							"Windows" => "Windows",
1019
							"Novell" => "Novell",
1020
							"NMAP" => "NMAP"
1021
			           );
1022
						foreach ($ostypes as $ostype => $descr): ?>
1023
							<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
1024
<?php
1025
					endforeach; 
1026
?>
1027
					</select>
1028
					<br />
1029
					<?=gettext("Note: this only works for TCP rules");?>
1030
				</div>
1031
			</td>
1032
		</tr>
1033
		<tr>
1034
			<td width="22%" valign="top" class="vncell"><?=gettext("Diffserv Code Point");?></td>
1035
			<td width="78%" class="vtable">
1036
				<div id="dsadv" name="dsadv" <?php if ($pconfig['dscp']) echo "style='display:none'"; ?>>
1037
					<input type="button" onClick="show_dsdiv();" value="<?=gettext("Advanced"); ?>"> - <?=gettext("Show advanced option");?>
1038
				</div>
1039
				<div id="dsdivmain" name="dsdivmain" <?php if (empty($pconfig['dscp'])) echo "style='display:none'"; ?>>
1040
					<select name="dscp" id="dscp">
1041
						<option value=""></option>
1042
						<?php foreach($firewall_rules_dscp_types as $frdt): ?>
1043
							<option value="<?=$frdt?>"<?php if($pconfig['dscp'] == $frdt) echo " SELECTED"; ?>><?=$frdt?></option>
1044
						<?php endforeach; ?>
1045
					</select>
1046
				</div>
1047
			</td>
1048
		</tr>
1049
		<tr>
1050
			<td width="22%" valign="top" class="vncell"><?=gettext("Advanced Options");?></td>
1051
			<td width="78%" class="vtable">
1052
			<div id="aoadv" name="aoadv">
1053
				<input type="button" onClick="show_aodiv();" value="<?=gettext("Advanced"); ?>"> - <?=gettext("Show advanced option");?>
1054
			</div>
1055
			<div id="aodivmain" name="aodivmain" style="display:none">
1056
				<input type="checkbox" id="allowopts" value="yes" name="allowopts"<?php if($pconfig['allowopts'] == true) echo " checked"; ?>>
1057
				<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.");?>
1058
				</span><p>
1059
				<input type="checkbox" id="disablereplyto" value="yes" name="disablereplyto"<?php if($pconfig['disablereplyto'] == true) echo " checked"; ?>>
1060
				<br/><span class="vexpl"><?=gettext("This will disable auto generated reply-to for this rule.");?>
1061
				</span><p>
1062
				<input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
1063
				<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>
1064
				</span><p>
1065
				<input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>">
1066
				<br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before on another rule.")?>
1067
				</span> <p>
1068
				<input name="max" id="max" value="<?php echo htmlspecialchars($pconfig['max']) ?>"><br><?=gettext(" Maximum state entries this rule can create");?></p><p>
1069
				<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>
1070
				<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");?></p><p>
1071
				<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>
1072
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo htmlspecialchars($pconfig['max-src-conn-rate']) ?>"> /
1073
				<select name="max-src-conn-rates" id="max-src-conn-rates">
1074
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
1075
<?php				for($x=1; $x<255; $x++) {
1076
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
1077
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
1078
					} ?>
1079
				</select><br />
1080
				<?=gettext("Maximum new connections / per second(s)");?>
1081
				</p><p>
1082

    
1083
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1084
				<?=gettext("State Timeout in seconds");?>
1085
				</p>
1086

    
1087
				<p><strong><?=gettext("NOTE: Leave fields blank to disable that feature.");?></strong></p>
1088
			  </div>
1089
			</td>
1090
		</tr>
1091
		<tr id="tcpflags" name="tcpflags"> 
1092
			<td width="22%" valign="top" class="vncell"><?=gettext("TCP flags");?></td>
1093
			<td width="78%" class="vtable">
1094
			<div id="showtcpflagsbox" <?php if ($pconfig['tcpflags_any'] || $pconfig['tcpflags1'] || $pconfig['tcpflags2']) echo "style='display:none'"; ?>>
1095
                        	<input type="button" onClick="show_advanced_tcpflags()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1096
                        </div>
1097
                        <div id="showtcpflagsadv" <?php if (empty($pconfig['tcpflags_any']) && empty($pconfig['tcpflags1']) && empty($pconfig['tcpflags2'])) echo "style='display:none'"; ?>>
1098
			<div id="tcpheader" name="tcpheader">
1099
			<center>
1100
			<table border="0" cellspacing="0" cellpadding="0">
1101
			<?php 
1102
				$setflags = explode(",", $pconfig['tcpflags1']);
1103
				$outofflags = explode(",", $pconfig['tcpflags2']);
1104
				$header = "<td width='40' nowrap></td>";
1105
				$tcpflags1 = "<td width='40' nowrap>set</td>";
1106
				$tcpflags2 = "<td width='40' nowrap>out of</td>";
1107
				foreach ($tcpflags as $tcpflag) {
1108
					$header .= "<td  width='40' nowrap><strong>" . strtoupper($tcpflag) . "</strong></td>\n";
1109
					$tcpflags1 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags1_{$tcpflag}' value='on' ";
1110
					if (array_search($tcpflag, $setflags) !== false)
1111
						$tcpflags1 .= "checked";
1112
					$tcpflags1 .= "></td>\n";
1113
					$tcpflags2 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags2_{$tcpflag}' value='on' ";
1114
					if (array_search($tcpflag, $outofflags) !== false)
1115
						$tcpflags2 .= "checked";
1116
					$tcpflags2 .= "></td>\n";
1117
				}
1118
				echo "<tr id='tcpheader' name='tcpheader'>{$header}</tr>\n";
1119
				echo "<tr id='tcpflags1' name='tcpflags1'>{$tcpflags1}</tr>\n";
1120
				echo "<tr id='tcpflags2' name='tcpflags2'>{$tcpflags2}</tr>\n";
1121
			?>
1122
			</table>
1123
			<center>
1124
			</div>
1125
			<br/><center>
1126
			<input onClick='tcpflags_anyclick(this);' type='checkbox' name='tcpflags_any' value='on' <?php if ($pconfig['tcpflags_any']) echo "checked"; ?>><strong><?=gettext("Any flags.");?></strong><br/></center>
1127
			<br/>
1128
			<span class="vexpl"><?=gettext("Use this to choose TCP flags that must ". 
1129
			"be set or cleared for this rule to match.");?></span>
1130
			</div>
1131
			</td>
1132
		</tr>
1133
		<tr>
1134
			<td width="22%" valign="top" class="vncell"><?=gettext("State Type");?></td>
1135
			<td width="78%" class="vtable">
1136
				<div id="showadvstatebox" <?php if (!empty($pconfig['statetype']) && $pconfig['statetype'] != "keep state") echo "style='display:none'"; ?>>
1137
					<input type="button" onClick="show_advanced_state()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1138
				</div>
1139
				<div id="showstateadv" <?php if (empty($pconfig['statetype']) || $pconfig['statetype'] == "keep state") echo "style='display:none'"; ?>>
1140
					<select name="statetype">
1141
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>><?=gettext("keep state");?></option>
1142
						<option value="sloppy state" <?php if($pconfig['statetype'] == "sloppy state") echo "selected"; ?>><?=gettext("sloppy state");?></option>
1143
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>><?=gettext("synproxy state");?></option>
1144
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>><?=gettext("none");?></option>
1145
					</select><br><?=gettext("HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.");?>
1146
					<p>
1147
					<table width="90%">
1148
						<tr><td width="25%"><ul><li><?=gettext("keep state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1149
						<tr><td width="25%"><ul><li><?=gettext("sloppy state");?></li></ul></td><td><?=gettext("Works with all IP protocols.");?></td></tr>
1150
						<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>
1151
						<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>
1152
					</table>
1153
					</p>
1154
			  </div>
1155
			</td>
1156
		</tr>
1157
		<tr>
1158
			<td width="22%" valign="top" class="vncell"><?=gettext("No XMLRPC Sync");?></td>
1159
			<td width="78%" class="vtable">
1160
				<div id="showadvnoxmlrpcsyncbox" <?php if ($pconfig['nosync']) echo "style='display:none'"; ?>>
1161
					<input type="button" onClick="show_advanced_noxmlrpc()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1162
				</div>
1163
				<div id="shownoxmlrpcadv" <?php if (empty($pconfig['nosync'])) echo "style='display:none'"; ?>>
1164
					<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
1165
					<?=gettext("HINT: This prevents the rule from automatically syncing to other CARP members.");?>
1166
				</div>
1167
			</td>
1168
		</tr>
1169
		<?php
1170
			//build list of schedules
1171
			$schedules = array();
1172
			$schedules[] = "none";//leave none to leave rule enabled all the time
1173
			if(is_array($config['schedules']['schedule'])) {
1174
				foreach ($config['schedules']['schedule'] as $schedule) {
1175
					if ($schedule['name'] <> "")
1176
						$schedules[] = $schedule['name'];
1177
				}
1178
			}
1179
		?>
1180
		<tr>
1181
			<td width="22%" valign="top" class="vncell"><?=gettext("Schedule");?></td>
1182
			<td width="78%" class="vtable">
1183
				<div id="showadvschedulebox" <?php if (!empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1184
					<input type="button" onClick="show_advanced_schedule()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1185
				</div>
1186
				<div id="showscheduleadv" <?php if (empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1187
					<select name='sched'>
1188
<?php
1189
					foreach($schedules as $schedule) {
1190
						if($schedule == $pconfig['sched']) {
1191
							$selected = " SELECTED";
1192
						} else {
1193
							$selected = "";
1194
						}
1195
						if ($schedule == "none") {
1196
							echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
1197
						} else {
1198
							echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
1199
						}
1200
					}
1201
?>
1202
					</select>
1203
					<p><?=gettext("Leave as 'none' to leave the rule enabled all the time.");?></p>
1204
				</div>
1205
			</td>
1206
		</tr>
1207
		<tr>
1208
			<td width="22%" valign="top" class="vncell"><?=gettext("Gateway");?></td>
1209
			<td width="78%" class="vtable">
1210
				<div id="showadvgatewaybox" <?php if (!empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1211
					<input type="button" onClick="show_advanced_gateway()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1212
				</div>
1213
				<div id="showgatewayadv" <?php if (empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1214
					<select name='gateway'>
1215
					<option value="" ><?=gettext("default");?></option>
1216
<?php
1217
					/* build a list of gateways */
1218
					$gateways = return_gateways_array();
1219
					// add statically configured gateways to list
1220
					foreach($gateways as $gwname => $gw) {
1221
						if($gw == "") 
1222
							continue;
1223
						if($gwname == $pconfig['gateway']) {
1224
							$selected = " SELECTED";
1225
						} else {
1226
							$selected = "";
1227
						}
1228
						echo "<option value=\"{$gwname}\" {$selected}>{$gw['name']} - {$gw['gateway']}</option>\n";
1229
					}
1230
					/* add gateway groups to the list */
1231
					if (is_array($config['gateways']['gateway_group'])) {
1232
						foreach($config['gateways']['gateway_group'] as $gw_group) {
1233
							if($gw_group['name'] == "")
1234
								continue;
1235
							if($pconfig['gateway'] == $gw_group['name']) {
1236
								echo "<option value=\"{$gw_group['name']}\" SELECTED>{$gw_group['name']}</option>\n";
1237
							} else {
1238
								echo "<option value=\"{$gw_group['name']}\">{$gw_group['name']}</option>\n";
1239
							}
1240
						}
1241
					}
1242
?>
1243
					</select>
1244
					<p><?=gettext("Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.");?></p>
1245
				</div>
1246
			</td>
1247
		</tr>
1248
		<tr>
1249
			<td width="22%" valign="top" class="vncell"><?=gettext("In/Out");?></td>
1250
			<td width="78%" class="vtable">
1251
				<div id="showadvinoutbox" <?php if (!empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1252
					<input type="button" onClick="show_advanced_inout()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1253
				</div>
1254
				<div id="showinoutadv" <?php if (empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1255
					<select name="dnpipe">
1256
<?php
1257
		if (!is_array($dnqlist))
1258
			$dnqlist = array();
1259
		echo "<option value=\"none\"";
1260
		if (!$dnqselected) echo " SELECTED";
1261
		echo " >none</option>";
1262
		foreach ($dnqlist as $dnq => $dnqkey) {
1263
			if($dnq == "")
1264
				continue;
1265
			echo "<option value=\"$dnqkey\"";
1266
			if ($dnqkey == $pconfig['dnpipe']) {
1267
				$dnqselected = 1;
1268
				echo " SELECTED";
1269
			}
1270
			echo ">{$dnq}</option>"; 
1271
		}
1272
?>
1273
			</select> / 			
1274
			<select name="pdnpipe">
1275
<?php
1276
		$dnqselected = 0;
1277
		echo "<option value=\"none\"";
1278
		if (!$dnqselected) echo " SELECTED";
1279
		echo " >none</option>";
1280
		foreach ($dnqlist as $dnq => $dnqkey) {
1281
			if($dnq == "")
1282
				continue;
1283
			echo "<option value=\"$dnqkey\"";
1284
			if ($dnqkey == $pconfig['pdnpipe']) {
1285
				$dnqselected = 1;
1286
				echo " SELECTED";
1287
			}
1288
			echo ">{$dnq}</option>"; 
1289
		}
1290
?>
1291
				</select>
1292
				<br />
1293
				<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>
1294
				</div>
1295
			</td>
1296
		</tr>
1297

    
1298
		<tr>
1299
			<td width="22%" valign="top" class="vncell"><?=gettext("Ackqueue/Queue");?></td>
1300
			<td width="78%" class="vtable">
1301
			<div id="showadvackqueuebox" <?php if (!empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1302
				<input type="button" onClick="show_advanced_ackqueue()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1303
			</div>
1304
			<div id="showackqueueadv" <?php if (empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1305
				<select name="ackqueue">
1306
<?php
1307
			if (!is_array($qlist))
1308
				$qlist = array();
1309
			echo "<option value=\"none\"";
1310
			if (!$qselected) echo " SELECTED";
1311
			echo " >none</option>";
1312
			foreach ($qlist as $q => $qkey) {
1313
				if($q == "")
1314
					continue;
1315
				echo "<option value=\"$q\"";
1316
				if ($q == $pconfig['ackqueue']) {
1317
					$qselected = 1;
1318
					echo " SELECTED";
1319
				}
1320
				if (isset($ifdisp[$q]))
1321
					echo ">{$ifdisp[$q]}</option>";
1322
				else
1323
					echo ">{$q}</option>"; 
1324
			}
1325
?>
1326
				</select> / 			
1327
				<select name="defaultqueue">
1328
<?php
1329
			$qselected = 0;
1330
			echo "<option value=\"none\"";
1331
			if (!$qselected) echo " SELECTED";
1332
			echo " >none</option>";
1333
			foreach ($qlist as $q => $qkey) {
1334
				if($q == "")
1335
					continue;
1336
				echo "<option value=\"$q\"";
1337
				if ($q == $pconfig['defaultqueue']) {
1338
					$qselected = 1;
1339
					echo " SELECTED";
1340
				}
1341
				if (isset($ifdisp[$q]))
1342
					echo ">{$ifdisp[$q]}</option>";
1343
				else
1344
					echo ">{$q}</option>"; 
1345
			}
1346
?>
1347
				</select>
1348
					<br />
1349
					<span class="vexpl"><?=gettext("Choose the Acknowledge Queue only if you have selected Queue.");?></span>
1350
				</td>
1351
			</tr>
1352
			<tr>
1353
				<td width="22%" valign="top" class="vncell"><?=gettext("Layer7");?></td>
1354
				<td width="78%" class="vtable">
1355
					<div id="showadvlayer7box" <?php if (!empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1356
						<input type="button" onClick="show_advanced_layer7()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show advanced option");?></a>
1357
					</div>
1358
					<div id="showlayer7adv" <?php if (empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1359
				<select name="l7container">
1360
<?php
1361
					if (!is_array($l7clist))
1362
						$l7clist = array();
1363
					echo "<option value=\"none\"";
1364
					echo " >none</option>";
1365
					foreach ($l7clist as $l7ckey) {
1366
						echo "<option value=\"{$l7ckey}\"";
1367
						if ($l7ckey == $pconfig['l7container']) {
1368
							echo " SELECTED";
1369
						}
1370
						echo ">{$l7ckey}</option>"; 
1371
					}
1372
?>
1373
				</select>			
1374
				<br/>
1375
				<span class="vexpl">
1376
					<?=gettext("Choose a Layer7 container to apply application protocol inspection rules. " .
1377
					"These are valid for TCP and UDP protocols only.");?>
1378
				</span>
1379
			  </div>
1380
			</td>
1381
		</tr>
1382
<?php
1383
		// Allow extending of the firewall edit page and include custom input validation 
1384
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/htmlphplate");
1385
?>
1386
		<tr>
1387
			<td width="22%" valign="top">&nbsp;</td>
1388
			<td width="78%">
1389
				&nbsp;<br>&nbsp;
1390
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>">  <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()">
1391
<?php			if (isset($id) && $a_filter[$id]): ?>
1392
					<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
1393
<?php 			endif; ?>
1394
				<input name="after" type="hidden" value="<?=htmlspecialchars($after);?>">
1395
			</td>
1396
		</tr>
1397
	</table>
1398
</form>
1399
<script language="JavaScript">
1400
<!--
1401
	ext_change();
1402
	typesel_change();
1403
	proto_change();
1404
	<?php if ( (!empty($pconfig['srcbeginport']) && $pconfig['srcbeginport'] != "any") || (!empty($pconfig['srcendport']) && $pconfig['srcendport'] != "any") ): ?>
1405
	show_source_port_range();
1406
	<?php endif; ?>
1407

    
1408
<?php
1409
	$isfirst = 0;
1410
	$aliases = "";
1411
	$addrisfirst = 0;
1412
	$aliasesaddr = "";
1413
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1414
		foreach($config['aliases']['alias'] as $alias_name) {
1415
			switch ($alias_name['type']) {
1416
			case "port":
1417
				if($isfirst == 1) $portaliases .= ",";
1418
				$portaliases .= "'" . $alias_name['name'] . "'";
1419
				$isfirst = 1;
1420
				break;
1421
			case "host":
1422
			case "network":
1423
			case "openvpn":
1424
			case "urltable":
1425
				if($addrisfirst == 1) $aliasesaddr .= ",";
1426
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1427
				$addrisfirst = 1;
1428
				break;
1429
			default:
1430
				break;
1431
			}
1432
		}
1433
?>
1434

    
1435
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1436
	var customarray=new Array(<?php echo $portaliases; ?>);
1437

    
1438
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1439
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1440
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1441
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1442
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1443
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1444
//-->
1445
</script>
1446
<?php include("fend.inc"); ?>
1447
</body>
1448
</html>
(61-61/226)