Project

General

Profile

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

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

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

    
299
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
300

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

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

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

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

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

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

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

    
404
	if (!$input_errors) {
405
		$filterent = array();
406
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
407
		$filterent['type'] = $_POST['type'];
408
		if (isset($_POST['interface'] ))
409
			$filterent['interface'] = $_POST['interface'];
410

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

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

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

    
460
		/* Nosync directive - do not xmlrpc sync this item */
461
		if($_POST['nosync'] <> "")
462
			$filterent['nosync'] = true;
463
		else
464
			unset($filterent['nosync']);
465

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

    
475
		if ($_POST['proto'] != "any")
476
			$filterent['protocol'] = $_POST['proto'];
477
		else
478
			unset($filterent['protocol']);
479

    
480
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
481
			$filterent['icmptype'] = $_POST['icmptype'];
482
		else
483
			unset($filterent['icmptype']);
484

    
485
		pconfig_to_address($filterent['source'], $_POST['src'],
486
			$_POST['srcmask'], $_POST['srcnot'],
487
			$_POST['srcbeginport'], $_POST['srcendport']);
488

    
489
		pconfig_to_address($filterent['destination'], $_POST['dst'],
490
			$_POST['dstmask'], $_POST['dstnot'],
491
			$_POST['dstbeginport'], $_POST['dstendport']);
492

    
493
		if ($_POST['disabled'])
494
			$filterent['disabled'] = true;
495
		else
496
			unset($filterent['disabled']);
497

    
498
		if ($_POST['dscp'])
499
			$filterent['dscp'] = $_POST['dscp'];
500

    
501
		if ($_POST['log'])
502
			$filterent['log'] = true;
503
		else
504
			unset($filterent['log']);
505
		strncpy($filterent['descr'], $_POST['descr'], 52);
506

    
507
		if ($_POST['gateway'] != "") {
508
			$filterent['gateway'] = $_POST['gateway'];
509
		}
510
		
511
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
512
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
513
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
514
				$filterent['ackqueue'] = $_POST['ackqueue'];
515
		}
516

    
517
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
518
			$filterent['dnpipe'] = $_POST['dnpipe'];
519
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
520
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
521
		}
522

    
523
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
524
			$filterent['l7container'] = $_POST['l7container'];
525
		}
526
		
527
		if ($_POST['sched'] != "") {
528
			$filterent['sched'] = $_POST['sched'];
529
		}
530

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

    
547
		if (isset($id) && $a_filter[$id])
548
			$a_filter[$id] = $filterent;
549
		else {
550
			if (is_numeric($after))
551
				array_splice($a_filter, $after+1, 0, array($filterent));
552
			else
553
				$a_filter[] = $filterent;
554
		}
555

    
556
		filter_rules_sort();
557
		write_config();
558
		mark_subsystem_dirty('filter');
559

    
560
		if (isset($_POST['floating']))
561
			header("Location: firewall_rules.php?if=FloatingRules");
562
		else
563
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
564
		exit;
565
	}
566
}
567

    
568
read_altq_config(); /* XXX: */
569
$qlist =& get_unique_queue_list();
570
read_dummynet_config(); /* XXX: */
571
$dnqlist =& get_unique_dnqueue_list();
572
read_layer7_config();
573
$l7clist =& get_l7_unique_list();
574

    
575
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
576
$statusurl = "status_filter_reload.php";
577
$logurl = "diag_logs_filter.php";
578

    
579
$closehead = false;
580

    
581
$page_filename = "firewall_rules_edit.php";
582
include("head.inc");
583

    
584
?>
585

    
586
</head>
587

    
588
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
589
<?php include("fbegin.inc"); ?>
590
<?php if ($input_errors) print_input_errors($input_errors); ?>
591

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

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

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

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

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

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

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

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

    
1427
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1428
	var customarray=new Array(<?php echo $portaliases; ?>);
1429

    
1430
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1431
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1432
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1433
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1434
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1435
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1436
//-->
1437
</script>
1438
<?php include("fend.inc"); ?>
1439
</body>
1440
</html>
(60-60/224)