Project

General

Profile

Download (56.6 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[] = "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[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";		
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[] = "{$_POST['statetype']} is only valid with protocol tcp.";
274
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
275
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
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[] = "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[] = "{$_POST['srcbeginport']} is not a valid start source port. It must be a port alias or integer between 1 and 65535.";
302
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
303
                $input_errors[] = "{$_POST['srcendport']} is not a valid end source port. It must be a port alias or integer between 1 and 65535.";
304
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
305
                $input_errors[] = "{$_POST['dstbeginport']} is not a valid start destination port. It must be a port alias or integer between 1 and 65535.";
306
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
307
                $input_errors[] = "{$_POST['dstendport']} is not a valid end destination port. It must be a port alias or integer between 1 and 65535.";
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[] = "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[] = "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[] = "{$_POST['src']} is not a valid source IP address or alias.";
322
		}
323
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
324
			$input_errors[] = "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[] = "{$_POST['dst']} is not a valid destination IP address or alias.";
330
		}
331
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
332
			$input_errors[] = "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[] = "OS detection is only valid with protocol tcp.";
351

    
352
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
353
		if ($_POST['defaultqueue'] == "none" )
354
			$input_errors[] = "You have to select a queue when you select an acknowledge queue too.";
355
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
356
			$input_errors[] = "Acknowledge queue and Queue cannot be the same.";		
357
	}
358
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
359
		if ($_POST['dnpipe'] == "none" )
360
			$input_errors[] = "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[] = "In and Out Queue cannot be the same.";
363
		else if ($pdnpipe[0] == "?" && $dnpipe[0] <> "?")
364
			$input_errors[] = "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[] = "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[] = '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[] = "You can only select a layer7 container for TCP and/or UDP protocols";
373
		if ($_POST['type'] <> "pass")
374
			$input_errors[] = "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[] = "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("Firewall","Rules","Edit");
552
$closehead = false;
553

    
554
$page_filename = "firewall_rules_edit.php";
555
include("head.inc");
556

    
557
?>
558

    
559
</head>
560

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

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

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

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

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

    
1046
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
1047
				State Timeout in seconds
1048
				<p />
1049

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

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

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

    
1385
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1386
	var customarray=new Array(<?php echo $portaliases; ?>);
1387

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