Project

General

Profile

Download (59.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
	$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
172

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

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

    
187
if ($_POST) {
188

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
533
		write_config();
534
		mark_subsystem_dirty('filter');
535

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

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

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

    
555
$closehead = false;
556

    
557
$page_filename = "firewall_rules_edit.php";
558
include("head.inc");
559

    
560
?>
561

    
562
</head>
563

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

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

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

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

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

    
1049
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
1050
				<?=gettext("State Timeout in seconds");?>
1051
				<p />
1052

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

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

    
1361
<?php
1362
	$isfirst = 0;
1363
	$aliases = "";
1364
	$addrisfirst = 0;
1365
	$aliasesaddr = "";
1366
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1367
		foreach($config['aliases']['alias'] as $alias_name) {
1368
			switch ($alias_name['type']) {
1369
			case "port":
1370
				if($isfirst == 1) $portaliases .= ",";
1371
				$portaliases .= "'" . $alias_name['name'] . "'";
1372
				$isfirst = 1;
1373
				break;
1374
			case "host":
1375
			case "network":
1376
			case "openvpn":
1377
			case "urltable":
1378
				if($addrisfirst == 1) $aliasesaddr .= ",";
1379
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1380
				$addrisfirst = 1;
1381
				break;
1382
			default:
1383
				break;
1384
			}
1385
		}
1386
?>
1387

    
1388
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1389
	var customarray=new Array(<?php echo $portaliases; ?>);
1390

    
1391
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1392
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1393
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1394
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1395
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1396
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1397
//-->
1398
</script>
1399
<?php include("fend.inc"); ?>
1400
</body>
1401
</html>
(57-57/221)