Project

General

Profile

Download (60.2 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 ($_POST['type'] == "reject" && $_POST['proto'] <> "tcp")
191
		$input_errors[] = gettext("Reject type rules only works when the protocol is set to TCP.");
192

    
193
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
194
		$_POST['srcbeginport'] = 0;
195
		$_POST['srcendport'] = 0;
196
		$_POST['dstbeginport'] = 0;
197
		$_POST['dstendport'] = 0;
198
	} else {
199

    
200
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
201
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
202
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
203
			$_POST['srcendport'] = $_POST['srcendport_cust'];
204

    
205
		if ($_POST['srcbeginport'] == "any") {
206
			$_POST['srcbeginport'] = 0;
207
			$_POST['srcendport'] = 0;
208
		} else {
209
			if (!$_POST['srcendport'])
210
				$_POST['srcendport'] = $_POST['srcbeginport'];
211
		}
212
		if ($_POST['srcendport'] == "any")
213
			$_POST['srcendport'] = $_POST['srcbeginport'];
214

    
215
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
216
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
217
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
218
			$_POST['dstendport'] = $_POST['dstendport_cust'];
219

    
220
		if ($_POST['dstbeginport'] == "any") {
221
			$_POST['dstbeginport'] = 0;
222
			$_POST['dstendport'] = 0;
223
		} else {
224
			if (!$_POST['dstendport'])
225
				$_POST['dstendport'] = $_POST['dstbeginport'];
226
		}
227
		if ($_POST['dstendport'] == "any")
228
			$_POST['dstendport'] = $_POST['dstbeginport'];
229
	}
230

    
231
	if (is_specialnet($_POST['srctype'])) {
232
		$_POST['src'] = $_POST['srctype'];
233
		$_POST['srcmask'] = 0;
234
	} else if ($_POST['srctype'] == "single") {
235
		$_POST['srcmask'] = 32;
236
	}
237
	if (is_specialnet($_POST['dsttype'])) {
238
		$_POST['dst'] = $_POST['dsttype'];
239
		$_POST['dstmask'] = 0;
240
	}  else if ($_POST['dsttype'] == "single") {
241
		$_POST['dstmask'] = 32;
242
	}
243

    
244
	unset($input_errors);
245
	$pconfig = $_POST;
246

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

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

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

    
290
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
291

    
292
	if (!$_POST['srcbeginport']) {
293
		$_POST['srcbeginport'] = 0;
294
		$_POST['srcendport'] = 0;
295
	}
296
	if (!$_POST['dstbeginport']) {
297
		$_POST['dstbeginport'] = 0;
298
		$_POST['dstendport'] = 0;
299
	}
300

    
301
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
302
                $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']);
303
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
304
                $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']);
305
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
306
                $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']);
307
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
308
                $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']);
309

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

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

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

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

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

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

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

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

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

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

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

    
462
		if ($_POST['proto'] != "any")
463
			$filterent['protocol'] = $_POST['proto'];
464
		else
465
			unset($filterent['protocol']);
466

    
467
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
468
			$filterent['icmptype'] = $_POST['icmptype'];
469
		else
470
			unset($filterent['icmptype']);
471

    
472
		pconfig_to_address($filterent['source'], $_POST['src'],
473
			$_POST['srcmask'], $_POST['srcnot'],
474
			$_POST['srcbeginport'], $_POST['srcendport']);
475

    
476
		pconfig_to_address($filterent['destination'], $_POST['dst'],
477
			$_POST['dstmask'], $_POST['dstnot'],
478
			$_POST['dstbeginport'], $_POST['dstendport']);
479

    
480
		if ($_POST['disabled'])
481
			$filterent['disabled'] = true;
482
		else
483
			unset($filterent['disabled']);
484

    
485
		if ($_POST['dscp'])
486
			$filterent['dscp'] = $_POST['dscp'];
487

    
488
		if ($_POST['log'])
489
			$filterent['log'] = true;
490
		else
491
			unset($filterent['log']);
492
		strncpy($filterent['descr'], $_POST['descr'], 52);
493

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

    
504
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
505
			$filterent['dnpipe'] = $_POST['dnpipe'];
506
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
507
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
508
		}
509

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

    
518
		// If we have an associated nat rule, make sure the source and destination doesn't change
519
		if( isset($a_filter[$id]['associated-rule-id']) ) {
520
			$filterent['interface'] = $a_filter[$id]['interface'];
521
			$filterent['source'] = $a_filter[$id]['source'];
522
			$filterent['destination'] = $a_filter[$id]['destination'];
523
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
524
		}
525

    
526
		if (isset($id) && $a_filter[$id])
527
			$a_filter[$id] = $filterent;
528
		else {
529
			if (is_numeric($after))
530
				array_splice($a_filter, $after+1, 0, array($filterent));
531
			else
532
				$a_filter[] = $filterent;
533
		}
534

    
535
		write_config();
536
		mark_subsystem_dirty('filter');
537

    
538
		if (isset($_POST['floating']))
539
			header("Location: firewall_rules.php?if=FloatingRules");
540
		else
541
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
542
		exit;
543
	}
544
}
545

    
546
read_altq_config(); /* XXX: */
547
$qlist =& get_unique_queue_list();
548
read_dummynet_config(); /* XXX: */
549
$dnqlist =& get_unique_dnqueue_list();
550
read_layer7_config();
551
$l7clist =& get_l7_unique_list();
552

    
553
$pgtitle = array(gettext("Firewall"),gettext("Rules"),gettext("Edit"));
554
$statusurl = "status_filter_reload.php";
555
$logurl = "diag_logs_filter.php";
556

    
557
$closehead = false;
558

    
559
$page_filename = "firewall_rules_edit.php";
560
include("head.inc");
561

    
562
?>
563

    
564
</head>
565

    
566
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
567
<?php include("fbegin.inc"); ?>
568
<?php if ($input_errors) print_input_errors($input_errors); ?>
569

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

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

    
723
				foreach ($icmptypes as $icmptype => $descr): ?>
724
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
725
<?php 			endforeach; ?>
726
			</select>
727
			<br />
728
			<span class="vexpl"><?=gettext("If you selected ICMP for the protocol above, you may specify an ICMP type here.");?></span>
729
		</td>
730
		</tr>
731
		<tr>
732
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source");?></td>
733
			<td width="78%" class="vtable">
734
				<?php $edit_disabled=false; ?>
735
				<?php if( isset($pconfig['associated-rule-id']) ): ?>
736
					<span class="red"><strong><?=gettext("NOTE: ");?></strong></span><?=gettext("This is associated to a NAT rule.");?><br />
737
					<?=gettext("You cannot edit the source and destination of associated filter rules.");?><br />
738
					<br />
739
					<?php
740
						$edit_disabled=true;
741
						if (is_array($config['nat']['rule'])) {
742
							foreach( $config['nat']['rule'] as $index => $nat_rule ) {
743
								if( isset($nat_rule['associated-rule-id']) && $nat_rule['associated-rule-id']==$pconfig['associated-rule-id'] ) {
744
									printf("<a href=\"firewall_nat_edit.php?id=%s\">%s</a><br>", $index, gettext("View the NAT rule"));
745
									break;
746
								}
747
							}
748
						}
749
					?>
750
					<br />
751
					<script type="text/javascript">
752
					editenabled = 0;
753
					</script>
754
				<?php endif; ?>
755
				<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
756
				<strong><?=gettext("not");?></strong>
757
				<br />
758
				<?=gettext("Use this option to invert the sense of the match.");?>
759
				<br />
760
				<br />
761
				<table border="0" cellspacing="0" cellpadding="0">
762
					<tr>
763
						<td><?=gettext("Type");?>:&nbsp;&nbsp;</td>
764
						<td>
765
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srctype" class="formselect" onChange="typesel_change()">
766
<?php
767
								$sel = is_specialnet($pconfig['src']); ?>
768
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
769
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>><?=gettext("Single host or alias");?></option>
770
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
771
								<?php if(have_ruleint_access("pptp")): ?>
772
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
773
								<?php endif; ?>
774
								<?php if(have_ruleint_access("pppoe")): ?>
775
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
776
								<?php endif; ?>								
777
								 <?php if(have_ruleint_access("l2tp")): ?>
778
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
779
                                                                <?php endif; ?>
780
<?php
781
								foreach ($ifdisp as $ifent => $ifdesc): ?>
782
								<?php if(have_ruleint_access($ifent)): ?>
783
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?><?=gettext(" subnet");?></option>
784
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
785
										<?=$ifdesc?> <?=gettext("address");?>
786
									</option>
787
								<?php endif; ?>
788
<?php 							endforeach; ?>
789
							</select>
790
						</td>
791
					</tr>
792
					<tr>
793
						<td><?=gettext("Address");?>:&nbsp;&nbsp;</td>
794
						<td>
795
							<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
796
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcmask" class="formselect" id="srcmask">
797
<?php						for ($i = 31; $i > 0; $i--): ?>
798
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
799
<?php 						endfor; ?>
800
							</select>
801
						</td>
802
					</tr>
803
				</table>
804
				<div id="showadvancedboxspr">
805
					<p>
806
					<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> type="button" onClick="show_source_port_range()" value="<?=gettext("Advanced"); ?>"></input> - <?=gettext("Show source port range");?></a>
807
				</div>
808
			</td>
809
		</tr>
810
		<tr style="display:none" id="sprtable" name="sprtable">
811
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Source port range");?></td>
812
			<td width="78%" class="vtable">
813
				<table border="0" cellspacing="0" cellpadding="0">
814
					<tr>
815
						<td><?=gettext("from");?>:&nbsp;&nbsp;</td>
816
						<td>
817
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
818
								<option value="">(<?=gettext("other"); ?>)</option>
819
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
820
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
821
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
822
<?php 							endforeach; ?>
823
							</select>
824
							<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
825
						</td>
826
					</tr>
827
					<tr>
828
						<td><?=gettext("to");?>:</td>
829
						<td>
830
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcendport" class="formselect" onchange="ext_change()">
831
								<option value="">(<?=gettext("other"); ?>)</option>
832
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>><?=gettext("any");?></option>
833
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
834
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
835
<?php							endforeach; ?>
836
							</select>
837
							<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
838
						</td>
839
					</tr>
840
				</table>
841
				<br />
842
				<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/>
843
			</td>
844
		</tr>
845
		<tr>
846
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Destination");?></td>
847
			<td width="78%" class="vtable">
848
				<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
849
				<strong><?=gettext("not");?></strong>
850
					<br />
851
				<?=gettext("Use this option to invert the sense of the match.");?>
852
					<br />
853
					<br />
854
				<table border="0" cellspacing="0" cellpadding="0">
855
					<tr>
856
						<td><?=gettext("Type");?>:&nbsp;&nbsp;</td>
857
						<td>
858
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dsttype" class="formselect" onChange="typesel_change()">
859
<?php
860
								$sel = is_specialnet($pconfig['dst']); ?>
861
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>><?=gettext("any");?></option>
862
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>><?=gettext("Single host or alias");?></option>
863
								<option value="network" <?php if (!$sel) echo "selected"; ?>><?=gettext("Network");?></option>
864
								<?php if(have_ruleint_access("pptp")): ?>
865
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>><?=gettext("PPTP clients");?></option>
866
								<?php endif; ?>
867
								<?php if(have_ruleint_access("pppoe")): ?>
868
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>><?=gettext("PPPoE clients");?></option>
869
								<?php endif; ?>								
870
								<?php if(have_ruleint_access("l2tp")): ?>
871
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>><?=gettext("L2TP clients");?></option>
872
                                                                <?php endif; ?>
873

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

    
1058
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
1059
				<?=gettext("State Timeout in seconds");?>
1060
				<p />
1061

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

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

    
1370
<?php
1371
	$isfirst = 0;
1372
	$aliases = "";
1373
	$addrisfirst = 0;
1374
	$aliasesaddr = "";
1375
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1376
		foreach($config['aliases']['alias'] as $alias_name) {
1377
			switch ($alias_name['type']) {
1378
			case "port":
1379
				if($isfirst == 1) $portaliases .= ",";
1380
				$portaliases .= "'" . $alias_name['name'] . "'";
1381
				$isfirst = 1;
1382
				break;
1383
			case "host":
1384
			case "network":
1385
			case "openvpn":
1386
			case "urltable":
1387
				if($addrisfirst == 1) $aliasesaddr .= ",";
1388
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1389
				$addrisfirst = 1;
1390
				break;
1391
			default:
1392
				break;
1393
			}
1394
		}
1395
?>
1396

    
1397
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1398
	var customarray=new Array(<?php echo $portaliases; ?>);
1399

    
1400
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1401
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1402
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1403
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1404
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1405
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1406
//-->
1407
</script>
1408
<?php include("fend.inc"); ?>
1409
</body>
1410
</html>
(58-58/222)