Project

General

Profile

Download (56.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules_edit.php
5
	part of pfSense (http://www.pfsense.com)
6
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34
	pfSense_MODULE:	filter
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-firewall-rules-edit
39
##|*NAME=Firewall: Rules: Edit page
40
##|*DESCR=Allow access to the 'Firewall: Rules: Edit' page.
41
##|*MATCH=firewall_rules_edit.php*
42
##|-PRIV
43

    
44
require("guiconfig.inc");
45
require("filter.inc");
46
require("shaper.inc");
47

    
48
$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn");
49
$ifdisp = get_configured_interface_with_descr();
50
foreach ($ifdisp as $kif => $kdescr) {
51
	$specialsrcdst[] = "{$kif}";
52
	$specialsrcdst[] = "{$kif}ip";
53
}
54

    
55
if (!is_array($config['filter']['rule'])) {
56
	$config['filter']['rule'] = array();
57
}
58
filter_rules_sort();
59
$a_filter = &$config['filter']['rule'];
60

    
61
$id = $_GET['id'];
62
if (is_numeric($_POST['id']))
63
	$id = $_POST['id'];
64

    
65
$after = $_GET['after'];
66

    
67
if (isset($_POST['after']))
68
	$after = $_POST['after'];
69

    
70
if (isset($_GET['dup'])) {
71
	$id = $_GET['dup'];
72
	$after = $_GET['dup'];
73
}
74

    
75
if (isset($id) && $a_filter[$id]) {
76
	$pconfig['interface'] = $a_filter[$id]['interface'];
77

    
78
	if (isset($a_filter[$id]['id']))
79
		$pconfig['ruleid'] = $a_filter[$id]['id'];
80

    
81
	if (!isset($a_filter[$id]['type']))
82
		$pconfig['type'] = "pass";
83
	else
84
		$pconfig['type'] = $a_filter[$id]['type'];
85

    
86
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
87
		$pconfig['floating'] = $a_filter[$id]['floating'];
88
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "") 
89
			$pconfig['interface'] = $a_filter[$id]['interface'];
90
	}
91
	
92
	if (isset($a_filter['floating'])) 
93
		$pconfig['floating'] = "yes";
94

    
95
	if (isset($a_filter[$id]['direction']))
96
                $pconfig['direction'] = $a_filter[$id]['direction'];
97

    
98
	if (isset($a_filter[$id]['protocol']))
99
		$pconfig['proto'] = $a_filter[$id]['protocol'];
100
	else
101
		$pconfig['proto'] = "any";
102

    
103
	if ($a_filter[$id]['protocol'] == "icmp")
104
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
105

    
106
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
107
		$pconfig['srcmask'], $pconfig['srcnot'],
108
		$pconfig['srcbeginport'], $pconfig['srcendport']);
109

    
110
	if($a_filter[$id]['os'] <> "")
111
		$pconfig['os'] = $a_filter[$id]['os'];
112

    
113
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
114
		$pconfig['dstmask'], $pconfig['dstnot'],
115
		$pconfig['dstbeginport'], $pconfig['dstendport']);
116

    
117
	if ($a_filter[$id]['dscp'] <> "")
118
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
119

    
120
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
121
	$pconfig['log'] = isset($a_filter[$id]['log']);
122
	$pconfig['descr'] = $a_filter[$id]['descr'];
123

    
124
	if (isset($a_filter[$id]['tcpflags_any']))
125
		$pconfig['tcpflags_any'] = true;
126
	else {
127
		if (isset($a_filter[$id]['tcpflags1']) && $a_filter[$id]['tcpflags1'] <> "") 
128
			$pconfig['tcpflags1'] = $a_filter[$id]['tcpflags1'];
129
		if (isset($a_filter[$id]['tcpflags2']) && $a_filter[$id]['tcpflags2'] <> "") 
130
			$pconfig['tcpflags2'] = $a_filter[$id]['tcpflags2'];
131
	}
132

    
133
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "") 
134
		$pconfig['tag'] = $a_filter[$id]['tag'];
135
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tagged'] <> "")
136
        	$pconfig['tagged'] = $a_filter[$id]['tagged'];
137
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
138
		$pconfig['quick'] = $a_filter[$id]['quick'];
139
	if (isset($a_filter[$id]['allowopts']))
140
		$pconfig['allowopts'] = true;
141
	if (isset($a_filter[$id]['disablereplyto']))
142
		$pconfig['disablereplyto'] = true;
143

    
144
	/* advanced */
145
	$pconfig['max'] = $a_filter[$id]['max'];
146
	$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
147
	$pconfig['max-src-conn'] = $a_filter[$id]['max-src-conn'];
148
	$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
149
	$pconfig['statetype'] = $a_filter[$id]['statetype'];
150
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
151

    
152
	/* advanced - nosync */
153
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
154

    
155
	/* advanced - new connection per second banning*/
156
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
157
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
158

    
159
	/* Multi-WAN next-hop support */
160
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
161
	
162
	/* Shaper support */
163
	$pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
164
	$pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
165
	$pconfig['dnpipe'] = $a_filter[$id]['dnpipe'];
166
	$pconfig['pdnpipe'] = $a_filter[$id]['pdnpipe'];
167
	$pconfig['l7container'] = $a_filter[$id]['l7container'];
168

    
169
	//schedule support
170
	$pconfig['sched'] = $a_filter[$id]['sched'];
171
	$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 = $value;
251
		if (isset($_POST['floating']) && $key == "interface")
252
			continue;
253
		$newpost = htmlentities($temp);
254
		if($newpost <> $temp)   	 
255
			$input_errors[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";		
256
	}
257

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

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

    
283
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
284

    
285
	if (!$_POST['srcbeginport']) {
286
		$_POST['srcbeginport'] = 0;
287
		$_POST['srcendport'] = 0;
288
	}
289
	if (!$_POST['dstbeginport']) {
290
		$_POST['dstbeginport'] = 0;
291
		$_POST['dstendport'] = 0;
292
	}
293

    
294
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
295
                $input_errors[] = "{$_POST['srcbeginport']} is not a valid start source port. It must be a port alias or integer between 1 and 65535.";
296
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
297
                $input_errors[] = "{$_POST['srcendport']} is not a valid end source port. It must be a port alias or integer between 1 and 65535.";
298
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
299
                $input_errors[] = "{$_POST['dstbeginport']} is not a valid start destination port. It must be a port alias or integer between 1 and 65535.";
300
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
301
                $input_errors[] = "{$_POST['dstendport']} is not a valid end destination port. It must be a port alias or integer between 1 and 65535.";
302

    
303
	/* if user enters an alias and selects "network" then disallow. */
304
	if($_POST['srctype'] == "network") {
305
		if(is_alias($_POST['src']))
306
			$input_errors[] = "You must specify single host or alias for alias entries.";
307
	}
308
	if($_POST['dsttype'] == "network") {
309
		if(is_alias($_POST['dst']))
310
			$input_errors[] = "You must specify single host or alias for alias entries.";
311
	}
312

    
313
	if (!is_specialnet($_POST['srctype'])) {
314
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
315
			$input_errors[] = "{$_POST['src']} is not a valid source IP address or alias.";
316
		}
317
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
318
			$input_errors[] = "A valid source bit count must be specified.";
319
		}
320
	}
321
	if (!is_specialnet($_POST['dsttype'])) {
322
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
323
			$input_errors[] = "{$_POST['dst']} is not a valid destination IP address or alias.";
324
		}
325
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
326
			$input_errors[] = "A valid destination bit count must be specified.";
327
		}
328
	}
329

    
330
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
331
		/* swap */
332
		$tmp = $_POST['srcendport'];
333
		$_POST['srcendport'] = $_POST['srcbeginport'];
334
		$_POST['srcbeginport'] = $tmp;
335
	}
336
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
337
		/* swap */
338
		$tmp = $_POST['dstendport'];
339
		$_POST['dstendport'] = $_POST['dstbeginport'];
340
		$_POST['dstbeginport'] = $tmp;
341
	}
342
	if ($_POST['os'])
343
		if( $_POST['proto'] != "tcp" )
344
			$input_errors[] = "OS detection is only valid with protocol tcp.";
345

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

    
371
	if (!$_POST['tcpflags_any']) {
372
		$settcpflags = array();
373
		$outoftcpflags = array();
374
		foreach ($tcpflags as $tcpflag) {
375
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
376
				$settcpflags[] = $tcpflag;
377
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
378
				$outoftcpflags[] = $tcpflag;
379
		}
380
		if (empty($outoftcpflags) && !empty($settcpflags))
381
			$input_errors[] = "If you specify TCP flags that should be set you should specify out of which flags as well.";
382
	}
383

    
384
	if (!$input_errors) {
385
		$filterent = array();
386
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
387
		$filterent['type'] = $_POST['type'];
388
		if (isset($_POST['interface'] ))
389
			$filterent['interface'] = $_POST['interface'];
390

    
391
		if ($_POST['tcpflags_any']) {
392
			$filterent['tcpflags_any'] = true;
393
		} else {
394
			$settcpflags = array();
395
			$outoftcpflags = array();
396
			foreach ($tcpflags as $tcpflag) {
397
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
398
					$settcpflags[] = $tcpflag;
399
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
400
					$outoftcpflags[] = $tcpflag;
401
			}
402
			if (!empty($outoftcpflags)) {
403
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
404
				if (!empty($settcpflags))
405
					$filterent['tcpflags1'] = join(",", $settcpflags);
406
			}
407
		}
408

    
409
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
410
			if (isset($_POST['tag']))
411
				$filterent['tag'] = $_POST['tag'];
412
			if (isset($_POST['tagged']))
413
				$filterent['tagged'] = $_POST['tagged'];
414
			$filterent['direction'] = $_POST['direction'];
415
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
416
				$filterent['quick'] = $_POST['quick'];
417
			$filterent['floating'] = "yes";
418
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
419
				$filterent['interface'] = implode(",", $_POST['interface']);
420
			}
421
		}
422

    
423
		/* Advanced options */
424
		if ($_POST['allowopts'] == "yes")
425
			$filterent['allowopts'] = true;
426
		else
427
			unset($filterent['allowopts']);
428
		if ($_POST['disablereplyto'] == "yes")
429
			$filterent['disablereplyto'] = true;
430
		else
431
			unset($filterent['disablereplyto']);
432
		$filterent['max'] = $_POST['max'];
433
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
434
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
435
		$filterent['max-src-states'] = $_POST['max-src-states'];
436
		$filterent['statetimeout'] = $_POST['statetimeout'];
437
		$filterent['statetype'] = $_POST['statetype'];
438
		$filterent['os'] = $_POST['os'];
439

    
440
		/* Nosync directive - do not xmlrpc sync this item */
441
		if($_POST['nosync'] <> "")
442
			$filterent['nosync'] = true;
443
		else
444
			unset($filterent['nosync']);
445

    
446
		/* unless both values are provided, unset the values - ticket #650 */
447
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
448
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
449
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
450
		} else {
451
			unset($filterent['max-src-conn-rate']);
452
			unset($filterent['max-src-conn-rates']);
453
		}
454

    
455
		if ($_POST['proto'] != "any")
456
			$filterent['protocol'] = $_POST['proto'];
457
		else
458
			unset($filterent['protocol']);
459

    
460
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
461
			$filterent['icmptype'] = $_POST['icmptype'];
462
		else
463
			unset($filterent['icmptype']);
464

    
465
		pconfig_to_address($filterent['source'], $_POST['src'],
466
			$_POST['srcmask'], $_POST['srcnot'],
467
			$_POST['srcbeginport'], $_POST['srcendport']);
468

    
469
		pconfig_to_address($filterent['destination'], $_POST['dst'],
470
			$_POST['dstmask'], $_POST['dstnot'],
471
			$_POST['dstbeginport'], $_POST['dstendport']);
472

    
473
		if ($_POST['disabled'])
474
			$filterent['disabled'] = true;
475
		else
476
			unset($filterent['disabled']);
477

    
478
		if ($_POST['dscp'])
479
			$filterent['dscp'] = $_POST['dscp'];
480

    
481
		if ($_POST['log'])
482
			$filterent['log'] = true;
483
		else
484
			unset($filterent['log']);
485
		strncpy($filterent['descr'], $_POST['descr'], 52);
486

    
487
		if ($_POST['gateway'] != "") {
488
			$filterent['gateway'] = $_POST['gateway'];
489
		}
490
		
491
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
492
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
493
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
494
				$filterent['ackqueue'] = $_POST['ackqueue'];
495
		}
496

    
497
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
498
			$filterent['dnpipe'] = $_POST['dnpipe'];
499
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
500
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
501
		}
502

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

    
511
		// If we have an associated nat rule, make sure the destination doesn't change
512
		if( isset($a_filter[$id]['associated-rule-id']) ) {
513
			$filterent['destination'] = $a_filter[$id]['destination'];
514
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
515
		}
516

    
517
		if (isset($id) && $a_filter[$id])
518
			$a_filter[$id] = $filterent;
519
		else {
520
			if (is_numeric($after))
521
				array_splice($a_filter, $after+1, 0, array($filterent));
522
			else
523
				$a_filter[] = $filterent;
524
		}
525

    
526
		write_config();
527
		mark_subsystem_dirty('filter');
528

    
529
		if (isset($_POST['floating']))
530
			header("Location: firewall_rules.php?if=FloatingRules");
531
		else
532
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
533
		exit;
534
	}
535
}
536

    
537
read_altq_config(); /* XXX: */
538
$qlist =& get_unique_queue_list();
539
read_dummynet_config(); /* XXX: */
540
$dnqlist =& get_unique_dnqueue_list();
541
read_layer7_config();
542
$l7clist =& get_l7_unique_list();
543

    
544
$pgtitle = array("Firewall","Rules","Edit");
545
$closehead = false;
546

    
547
$page_filename = "firewall_rules_edit.php";
548
include("head.inc");
549

    
550
?>
551

    
552
</head>
553

    
554
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
555
<?php include("fbegin.inc"); ?>
556
<?php if ($input_errors) print_input_errors($input_errors); ?>
557

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

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

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

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

    
1039
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
1040
				State Timeout in seconds
1041
				<p />
1042

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

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

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

    
1378
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1379
	var customarray=new Array(<?php echo $portaliases; ?>);
1380

    
1381
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1382
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1383
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1384
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1385
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1386
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1387
//-->
1388
</script>
1389
<?php include("fend.inc"); ?>
1390
</body>
1391
</html>
(56-56/217)