Project

General

Profile

Download (61.3 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['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
200
		$_POST['srcbeginport'] = 0;
201
		$_POST['srcendport'] = 0;
202
		$_POST['dstbeginport'] = 0;
203
		$_POST['dstendport'] = 0;
204
	} else {
205

    
206
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
207
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
208
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
209
			$_POST['srcendport'] = $_POST['srcendport_cust'];
210

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

    
221
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
222
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
223
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
224
			$_POST['dstendport'] = $_POST['dstendport_cust'];
225

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

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

    
250
	unset($input_errors);
251
	$pconfig = $_POST;
252

    
253
	/*  run through $_POST items encoding HTML entties so that the user
254
	 *  cannot think he is slick and perform a XSS attack on the unwilling 
255
	 */
256
	foreach ($_POST as $key => $value) {
257
		$temp = str_replace(">", "", $value);
258
			
259
		if (isset($_POST['floating']) && $key == "interface")
260
			continue;
261
		$newpost = htmlentities($temp);
262
		if($newpost <> $temp)   	 
263
			$input_errors[] = sprintf(gettext("Invalid characters detected (%s).  Please remove invalid characters and save again."),$temp);		
264
	}
265

    
266
	/* input validation */
267
	$reqdfields = explode(" ", "type proto");
268
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
269
		$reqdfields[] = "src";
270
		$reqdfields[] = "dst";
271
	}
272
	$reqdfieldsn = explode(",", "Type,Protocol");
273
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
274
		$reqdfieldsn[] = "Source";
275
		$reqdfieldsn[] = "Destination";
276
	}
277

    
278
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
279
		if( $_POST['proto'] != "tcp" )
280
			$input_errors[] = sprintf(gettext("%s is only valid with protocol tcp."),$_POST['statetype']);
281
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
282
			$input_errors[] = sprintf(gettext("%s is only valid if the gateway is set to 'default'."),$_POST['statetype']);
283
	}
284
        
285
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
286
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
287
		$reqdfields[] = "srcmask";
288
		$reqdfieldsn[] = "Source bit count";
289
	}
290
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
291
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
292
		$reqdfields[] = "dstmask";
293
		$reqdfieldsn[] = gettext("Destination bit count");
294
	}
295

    
296
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
297

    
298
	if (!$_POST['srcbeginport']) {
299
		$_POST['srcbeginport'] = 0;
300
		$_POST['srcendport'] = 0;
301
	}
302
	if (!$_POST['dstbeginport']) {
303
		$_POST['dstbeginport'] = 0;
304
		$_POST['dstendport'] = 0;
305
	}
306

    
307
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
308
                $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']);
309
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
310
                $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']);
311
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
312
                $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']);
313
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
314
                $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']);
315

    
316
	/* if user enters an alias and selects "network" then disallow. */
317
	if($_POST['srctype'] == "network") {
318
		if(is_alias($_POST['src']))
319
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
320
	}
321
	if($_POST['dsttype'] == "network") {
322
		if(is_alias($_POST['dst']))
323
			$input_errors[] = gettext("You must specify single host or alias for alias entries.");
324
	}
325

    
326
	if (!is_specialnet($_POST['srctype'])) {
327
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
328
			$input_errors[] = sprintf(gettext("%s is not a valid source IP address or alias."),$_POST['src']);
329
		}
330
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
331
			$input_errors[] = gettext("A valid source bit count must be specified.");
332
		}
333
	}
334
	if (!is_specialnet($_POST['dsttype'])) {
335
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
336
			$input_errors[] = sprintf(gettext("%s is not a valid destination IP address or alias."),$_POST['dst']);
337
		}
338
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
339
			$input_errors[] = gettext("A valid destination bit count must be specified.");
340
		}
341
	}
342

    
343
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
344
		/* swap */
345
		$tmp = $_POST['srcendport'];
346
		$_POST['srcendport'] = $_POST['srcbeginport'];
347
		$_POST['srcbeginport'] = $tmp;
348
	}
349
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
350
		/* swap */
351
		$tmp = $_POST['dstendport'];
352
		$_POST['dstendport'] = $_POST['dstbeginport'];
353
		$_POST['dstbeginport'] = $tmp;
354
	}
355
	if ($_POST['os'])
356
		if( $_POST['proto'] != "tcp" )
357
			$input_errors[] = gettext("OS detection is only valid with protocol tcp.");
358

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

    
386
	if (!$_POST['tcpflags_any']) {
387
		$settcpflags = array();
388
		$outoftcpflags = array();
389
		foreach ($tcpflags as $tcpflag) {
390
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
391
				$settcpflags[] = $tcpflag;
392
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
393
				$outoftcpflags[] = $tcpflag;
394
		}
395
		if (empty($outoftcpflags) && !empty($settcpflags))
396
			$input_errors[] = gettext("If you specify TCP flags that should be set you should specify out of which flags as well.");
397
	}
398

    
399
	if (!$input_errors) {
400
		$filterent = array();
401
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
402
		$filterent['type'] = $_POST['type'];
403
		if (isset($_POST['interface'] ))
404
			$filterent['interface'] = $_POST['interface'];
405

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

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

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

    
455
		/* Nosync directive - do not xmlrpc sync this item */
456
		if($_POST['nosync'] <> "")
457
			$filterent['nosync'] = true;
458
		else
459
			unset($filterent['nosync']);
460

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

    
470
		if ($_POST['proto'] != "any")
471
			$filterent['protocol'] = $_POST['proto'];
472
		else
473
			unset($filterent['protocol']);
474

    
475
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
476
			$filterent['icmptype'] = $_POST['icmptype'];
477
		else
478
			unset($filterent['icmptype']);
479

    
480
		pconfig_to_address($filterent['source'], $_POST['src'],
481
			$_POST['srcmask'], $_POST['srcnot'],
482
			$_POST['srcbeginport'], $_POST['srcendport']);
483

    
484
		pconfig_to_address($filterent['destination'], $_POST['dst'],
485
			$_POST['dstmask'], $_POST['dstnot'],
486
			$_POST['dstbeginport'], $_POST['dstendport']);
487

    
488
		if ($_POST['disabled'])
489
			$filterent['disabled'] = true;
490
		else
491
			unset($filterent['disabled']);
492

    
493
		if ($_POST['dscp'])
494
			$filterent['dscp'] = $_POST['dscp'];
495

    
496
		if ($_POST['log'])
497
			$filterent['log'] = true;
498
		else
499
			unset($filterent['log']);
500
		strncpy($filterent['descr'], $_POST['descr'], 52);
501

    
502
		if ($_POST['gateway'] != "") {
503
			$filterent['gateway'] = $_POST['gateway'];
504
		}
505
		
506
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
507
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
508
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
509
				$filterent['ackqueue'] = $_POST['ackqueue'];
510
		}
511

    
512
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
513
			$filterent['dnpipe'] = $_POST['dnpipe'];
514
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
515
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
516
		}
517

    
518
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
519
			$filterent['l7container'] = $_POST['l7container'];
520
		}
521
		
522
		if ($_POST['sched'] != "") {
523
			$filterent['sched'] = $_POST['sched'];
524
		}
525

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

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

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

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

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

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

    
574
$closehead = false;
575

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

    
579
?>
580

    
581
</head>
582

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

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

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

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

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

    
1078
				<input name="statetimeout" value="<?php echo htmlspecialchars($pconfig['statetimeout']) ?>"><br>
1079
				<?=gettext("State Timeout in seconds");?>
1080
				</p>
1081

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

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

    
1393
<?php
1394
	$isfirst = 0;
1395
	$aliases = "";
1396
	$addrisfirst = 0;
1397
	$aliasesaddr = "";
1398
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1399
		foreach($config['aliases']['alias'] as $alias_name) {
1400
			switch ($alias_name['type']) {
1401
			case "port":
1402
				if($isfirst == 1) $portaliases .= ",";
1403
				$portaliases .= "'" . $alias_name['name'] . "'";
1404
				$isfirst = 1;
1405
				break;
1406
			case "host":
1407
			case "network":
1408
			case "openvpn":
1409
			case "urltable":
1410
				if($addrisfirst == 1) $aliasesaddr .= ",";
1411
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1412
				$addrisfirst = 1;
1413
				break;
1414
			default:
1415
				break;
1416
			}
1417
		}
1418
?>
1419

    
1420
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1421
	var customarray=new Array(<?php echo $portaliases; ?>);
1422

    
1423
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1424
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1425
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1426
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1427
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1428
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1429
//-->
1430
</script>
1431
<?php include("fend.inc"); ?>
1432
</body>
1433
</html>
(59-59/222)