Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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

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

    
495
		if ($_POST['dscp'])
496
			$filterent['dscp'] = $_POST['dscp'];
497

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

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

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

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

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

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

    
553
		filter_rules_sort();
554
		write_config();
555
		mark_subsystem_dirty('filter');
556

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

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

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

    
576
$closehead = false;
577

    
578
$page_filename = "firewall_rules_edit.php";
579
include("head.inc");
580

    
581
?>
582

    
583
</head>
584

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

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

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

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

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

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

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

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

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

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

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