Project

General

Profile

Download (52.7 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]['tag']) && $a_filter[$id]['tag'] <> "") 
125
		$pconfig['tag'] = $a_filter[$id]['tag'];
126
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tagged'] <> "")
127
        	$pconfig['tagged'] = $a_filter[$id]['tagged'];
128
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
129
		$pconfig['quick'] = $a_filter[$id]['quick'];
130
	if (isset($a_filter[$id]['allowopts']))
131
		$pconfig['allowopts'] = true;
132
	if (isset($a_filter[$id]['disablereplyto']))
133
		$pconfig['disablereplyto'] = true;
134

    
135
	/* advanced */
136
	$pconfig['max'] = $a_filter[$id]['max'];
137
	$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
138
	$pconfig['max-src-conn'] = $a_filter[$id]['max-src-conn'];
139
	$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
140
	$pconfig['statetype'] = $a_filter[$id]['statetype'];
141
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
142

    
143
	/* advanced - nosync */
144
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
145

    
146
	/* advanced - new connection per second banning*/
147
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
148
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
149

    
150
	/* Multi-WAN next-hop support */
151
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
152
	
153
	/* Shaper support */
154
	$pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
155
	$pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
156
	$pconfig['dnpipe'] = $a_filter[$id]['dnpipe'];
157
	$pconfig['pdnpipe'] = $a_filter[$id]['pdnpipe'];
158
	$pconfig['l7container'] = $a_filter[$id]['l7container'];
159

    
160
	//schedule support
161
	$pconfig['sched'] = $a_filter[$id]['sched'];
162
	$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
163

    
164
} else {
165
	/* defaults */
166
	if ($_GET['if'])
167
		$pconfig['interface'] = $_GET['if'];
168
	$pconfig['type'] = "pass";
169
	$pconfig['src'] = "any";
170
	$pconfig['dst'] = "any";
171
}
172
/* Allow the FlotingRules to work */
173
$if = $pconfig['interface'];
174

    
175
if (isset($_GET['dup']))
176
	unset($id);
177

    
178
if ($_POST) {
179

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

    
183
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
184
		$_POST['srcbeginport'] = 0;
185
		$_POST['srcendport'] = 0;
186
		$_POST['dstbeginport'] = 0;
187
		$_POST['dstendport'] = 0;
188
	} else {
189

    
190
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
191
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
192
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
193
			$_POST['srcendport'] = $_POST['srcendport_cust'];
194

    
195
		if ($_POST['srcbeginport'] == "any") {
196
			$_POST['srcbeginport'] = 0;
197
			$_POST['srcendport'] = 0;
198
		} else {
199
			if (!$_POST['srcendport'])
200
				$_POST['srcendport'] = $_POST['srcbeginport'];
201
		}
202
		if ($_POST['srcendport'] == "any")
203
			$_POST['srcendport'] = $_POST['srcbeginport'];
204

    
205
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
206
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
207
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
208
			$_POST['dstendport'] = $_POST['dstendport_cust'];
209

    
210
		if ($_POST['dstbeginport'] == "any") {
211
			$_POST['dstbeginport'] = 0;
212
			$_POST['dstendport'] = 0;
213
		} else {
214
			if (!$_POST['dstendport'])
215
				$_POST['dstendport'] = $_POST['dstbeginport'];
216
		}
217
		if ($_POST['dstendport'] == "any")
218
			$_POST['dstendport'] = $_POST['dstbeginport'];
219
	}
220

    
221
	if (is_specialnet($_POST['srctype'])) {
222
		$_POST['src'] = $_POST['srctype'];
223
		$_POST['srcmask'] = 0;
224
	} else if ($_POST['srctype'] == "single") {
225
		$_POST['srcmask'] = 32;
226
	}
227
	if (is_specialnet($_POST['dsttype'])) {
228
		$_POST['dst'] = $_POST['dsttype'];
229
		$_POST['dstmask'] = 0;
230
	}  else if ($_POST['dsttype'] == "single") {
231
		$_POST['dstmask'] = 32;
232
	}
233

    
234
	unset($input_errors);
235
	$pconfig = $_POST;
236

    
237
	/*  run through $_POST items encoding HTML entties so that the user
238
	 *  cannot think he is slick and perform a XSS attack on the unwilling 
239
	 */
240
	foreach ($_POST as $key => $value) {
241
		$temp = $value;
242
		if (isset($_POST['floating']) && $key == "interface")
243
			continue;
244
		$newpost = htmlentities($temp);
245
		if($newpost <> $temp)   	 
246
			$input_errors[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";		
247
	}
248

    
249
	/* input validation */
250
	$reqdfields = explode(" ", "type proto src");
251
	if ( isset($a_filter[$id]['associated-rule-id'])===false )
252
		$redqfields[] = "dst";
253
	$reqdfieldsn = explode(",", "Type,Protocol,Source");
254
	if ( isset($a_filter[$id]['associated-rule-id'])===false )
255
		$reqdfieldsn[] = "Destination";
256

    
257
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
258
		if( $_POST['proto'] != "tcp" )
259
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
260
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
261
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
262
	}
263
        
264
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
265
		$reqdfields[] = "srcmask";
266
		$reqdfieldsn[] = "Source bit count";
267
	}
268
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
269
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
270
		$reqdfields[] = "dstmask";
271
		$reqdfieldsn[] = "Destination bit count";
272
	}
273

    
274
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
275

    
276
	if (!$_POST['srcbeginport']) {
277
		$_POST['srcbeginport'] = 0;
278
		$_POST['srcendport'] = 0;
279
	}
280
	if (!$_POST['dstbeginport']) {
281
		$_POST['dstbeginport'] = 0;
282
		$_POST['dstendport'] = 0;
283
	}
284

    
285
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
286
                $input_errors[] = "{$_POST['srcbeginport']} is not a valid start source port. It must be a port alias or integer between 1 and 65535.";
287
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
288
                $input_errors[] = "{$_POST['srcendport']} is not a valid end source port. It must be a port alias or integer between 1 and 65535.";
289
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
290
                $input_errors[] = "{$_POST['dstbeginport']} is not a valid start destination port. It must be a port alias or integer between 1 and 65535.";
291
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
292
                $input_errors[] = "{$_POST['dstendport']} is not a valid end destination port. It must be a port alias or integer between 1 and 65535.";
293

    
294
	/* if user enters an alias and selects "network" then disallow. */
295
	if($_POST['srctype'] == "network") {
296
		if(is_alias($_POST['src']))
297
			$input_errors[] = "You must specify single host or alias for alias entries.";
298
	}
299
	if($_POST['dsttype'] == "network") {
300
		if(is_alias($_POST['dst']))
301
			$input_errors[] = "You must specify single host or alias for alias entries.";
302
	}
303

    
304
	if (!is_specialnet($_POST['srctype'])) {
305
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
306
			$input_errors[] = "{$_POST['src']} is not a valid source IP address or alias.";
307
		}
308
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
309
			$input_errors[] = "A valid source bit count must be specified.";
310
		}
311
	}
312
	if (!is_specialnet($_POST['dsttype'])) {
313
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
314
			$input_errors[] = "{$_POST['dst']} is not a valid destination IP address or alias.";
315
		}
316
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
317
			$input_errors[] = "A valid destination bit count must be specified.";
318
		}
319
	}
320

    
321
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
322
		/* swap */
323
		$tmp = $_POST['srcendport'];
324
		$_POST['srcendport'] = $_POST['srcbeginport'];
325
		$_POST['srcbeginport'] = $tmp;
326
	}
327
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
328
		/* swap */
329
		$tmp = $_POST['dstendport'];
330
		$_POST['dstendport'] = $_POST['dstbeginport'];
331
		$_POST['dstbeginport'] = $tmp;
332
	}
333
	if ($_POST['os'])
334
		if( $_POST['proto'] != "tcp" )
335
			$input_errors[] = "OS detection is only valid with protocol tcp.";
336

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

    
362
	if (!$input_errors) {
363
		$filterent = array();
364
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
365
		$filterent['type'] = $_POST['type'];
366
		if (isset($_POST['interface'] ))
367
			$filterent['interface'] = $_POST['interface'];
368

    
369
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
370
			if (isset($_POST['tag']))
371
				$filterent['tag'] = $_POST['tag'];
372
			if (isset($_POST['tagged']))
373
				$filterent['tagged'] = $_POST['tagged'];
374
			$filterent['direction'] = $_POST['direction'];
375
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
376
				$filterent['quick'] = $_POST['quick'];
377
			$filterent['floating'] = "yes";
378
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
379
				$filterent['interface'] = implode(",", $_POST['interface']);
380
			}
381
		}
382

    
383
		/* Advanced options */
384
		if ($_POST['allowopts'] == "yes")
385
			$filterent['allowopts'] = true;
386
		else
387
			unset($filterent['allowopts']);
388
		if ($_POST['disablereplyto'] == "yes")
389
			$filterent['disablereplyto'] = true;
390
		else
391
			unset($filterent['disablereplyto']);
392
		$filterent['max'] = $_POST['max'];
393
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
394
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
395
		$filterent['max-src-states'] = $_POST['max-src-states'];
396
		$filterent['statetimeout'] = $_POST['statetimeout'];
397
		$filterent['statetype'] = $_POST['statetype'];
398
		$filterent['os'] = $_POST['os'];
399

    
400
		/* Nosync directive - do not xmlrpc sync this item */
401
		if($_POST['nosync'] <> "")
402
			$filterent['nosync'] = true;
403
		else
404
			unset($filterent['nosync']);
405

    
406
		/* unless both values are provided, unset the values - ticket #650 */
407
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
408
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
409
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
410
		} else {
411
			unset($filterent['max-src-conn-rate']);
412
			unset($filterent['max-src-conn-rates']);
413
		}
414

    
415
		if ($_POST['proto'] != "any")
416
			$filterent['protocol'] = $_POST['proto'];
417
		else
418
			unset($filterent['protocol']);
419

    
420
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
421
			$filterent['icmptype'] = $_POST['icmptype'];
422
		else
423
			unset($filterent['icmptype']);
424

    
425
		pconfig_to_address($filterent['source'], $_POST['src'],
426
			$_POST['srcmask'], $_POST['srcnot'],
427
			$_POST['srcbeginport'], $_POST['srcendport']);
428

    
429
		pconfig_to_address($filterent['destination'], $_POST['dst'],
430
			$_POST['dstmask'], $_POST['dstnot'],
431
			$_POST['dstbeginport'], $_POST['dstendport']);
432

    
433
		if ($_POST['disabled'])
434
			$filterent['disabled'] = true;
435
		else
436
			unset($filterent['disabled']);
437

    
438
		if ($_POST['dscp'])
439
			$filterent['dscp'] = $_POST['dscp'];
440

    
441
		if ($_POST['log'])
442
			$filterent['log'] = true;
443
		else
444
			unset($filterent['log']);
445
		strncpy($filterent['descr'], $_POST['descr'], 52);
446

    
447
		if ($_POST['gateway'] != "") {
448
			$filterent['gateway'] = $_POST['gateway'];
449
		}
450
		
451
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
452
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
453
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
454
				$filterent['ackqueue'] = $_POST['ackqueue'];
455
		}
456

    
457
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
458
			$filterent['dnpipe'] = $_POST['dnpipe'];
459
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
460
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
461
		}
462

    
463
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
464
			$filterent['l7container'] = $_POST['l7container'];
465
		}
466
		
467
		if ($_POST['sched'] != "") {
468
			$filterent['sched'] = $_POST['sched'];
469
		}
470

    
471
		// If we have an associated nat rule, make sure the destination doesn't change
472
		if( isset($a_filter[$id]['associated-rule-id']) ) {
473
			$filterent['destination'] = $a_filter[$id]['destination'];
474
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
475
		}
476

    
477
		if (isset($id) && $a_filter[$id])
478
			$a_filter[$id] = $filterent;
479
		else {
480
			if (is_numeric($after))
481
				array_splice($a_filter, $after+1, 0, array($filterent));
482
			else
483
				$a_filter[] = $filterent;
484
		}
485

    
486
		write_config();
487
		mark_subsystem_dirty('filter');
488

    
489
		if (isset($_POST['floating']))
490
			header("Location: firewall_rules.php?if=FloatingRules");
491
		else
492
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
493
		exit;
494
	}
495
}
496

    
497
read_altq_config(); /* XXX: */
498
$qlist =& get_unique_queue_list();
499
read_dummynet_config(); /* XXX: */
500
$dnqlist =& get_unique_dnqueue_list();
501
read_layer7_config();
502
$l7clist =& get_l7_unique_list();
503

    
504
$pgtitle = array("Firewall","Rules","Edit");
505
$closehead = false;
506

    
507
$page_filename = "firewall_rules_edit.php";
508
include("head.inc");
509

    
510
?>
511

    
512
</head>
513

    
514
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
515
<?php include("fbegin.inc"); ?>
516
<?php if ($input_errors) print_input_errors($input_errors); ?>
517

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

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

    
664
				foreach ($icmptypes as $icmptype => $descr): ?>
665
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
666
<?php 			endforeach; ?>
667
			</select>
668
			<br />
669
			<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span>
670
		</td>
671
		</tr>
672
		<tr>
673
			<td width="22%" valign="top" class="vncellreq">Source</td>
674
			<td width="78%" class="vtable">
675
				<?php $edit_disabled=false; ?>
676
				<?php if( isset($pconfig['associated-rule-id']) ): ?>
677
					<span class="red"><strong>NOTE: </strong></span> This is associated to a NAT rule.<br />
678
					You cannot edit the source and destination of associated filter rules.<br />
679
					<br />
680
                                        <?php
681
						$edit_disabled=true;
682
						if (is_array($config['nat']['rule'])) {
683
                                                       	foreach( $config['nat']['rule'] as $index => $nat_rule ) {
684
                                                               	if( $nat_rule['associated-rule-id']==$pconfig['associated-rule-id']) {
685
                                                                       	echo "<a href=\"firewall_nat_edit.php?id={$nat_rule[$index]}\">View the NAT rule</a><br>";
686
                                                                       	break;
687
								}
688
                                                       	}
689
						}
690
					?>
691
					<br />
692
					<script type="text/javascript">
693
					editenabled = 0;
694
					</script>
695
				<?php endif; ?>
696
				<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
697
				<strong>not</strong>
698
				<br />
699
				Use this option to invert the sense of the match.
700
				<br />
701
				<br />
702
				<table border="0" cellspacing="0" cellpadding="0">
703
					<tr>
704
						<td>Type:&nbsp;&nbsp;</td>
705
						<td>
706
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srctype" class="formselect" onChange="typesel_change()">
707
<?php
708
								$sel = is_specialnet($pconfig['src']); ?>
709
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
710
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
711
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
712
								<?php if(have_ruleint_access("pptp")): ?>
713
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
714
								<?php endif; ?>
715
								<?php if(have_ruleint_access("pppoe")): ?>
716
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
717
								<?php endif; ?>								
718
								 <?php if(have_ruleint_access("l2tp")): ?>
719
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
720
                                                                <?php endif; ?>
721
<?php
722
								foreach ($ifdisp as $ifent => $ifdesc): ?>
723
								<?php if(have_ruleint_access($ifent)): ?>
724
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
725
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
726
										<?=$ifdesc?> address
727
									</option>
728
								<?php endif; ?>
729
<?php 							endforeach; ?>
730
							</select>
731
						</td>
732
					</tr>
733
					<tr>
734
						<td>Address:&nbsp;&nbsp;</td>
735
						<td>
736
							<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']);?>"> /
737
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcmask" class="formselect" id="srcmask">
738
<?php						for ($i = 31; $i > 0; $i--): ?>
739
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
740
<?php 						endfor; ?>
741
							</select>
742
						</td>
743
					</tr>
744
				</table>
745
				<div id="showadvancedboxspr">
746
					<p>
747
					<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> type="button" onClick="show_source_port_range()" value="Advanced"></input> - Show source port range</a>
748
				</div>
749
			</td>
750
		</tr>
751
		<tr style="display:none" id="sprtable" name="sprtable">
752
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
753
			<td width="78%" class="vtable">
754
				<table border="0" cellspacing="0" cellpadding="0">
755
					<tr>
756
						<td>from:&nbsp;&nbsp;</td>
757
						<td>
758
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
759
								<option value="">(other)</option>
760
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
761
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
762
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
763
<?php 							endforeach; ?>
764
							</select>
765
							<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']; ?>">
766
						</td>
767
					</tr>
768
					<tr>
769
						<td>to:</td>
770
						<td>
771
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcendport" class="formselect" onchange="ext_change()">
772
								<option value="">(other)</option>
773
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
774
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
775
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
776
<?php							endforeach; ?>
777
							</select>
778
							<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']; ?>">
779
						</td>
780
					</tr>
781
				</table>
782
				<br />
783
				<span class="vexpl">Specify the source port or port range for this rule. <b>This is almost never equal to the destination port range (and is usually &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/>
784
			</td>
785
		</tr>
786
		<tr>
787
			<td width="22%" valign="top" class="vncellreq">Destination</td>
788
			<td width="78%" class="vtable">
789
				<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
790
				<strong>not</strong>
791
					<br />
792
				Use this option to invert the sense of the match.
793
					<br />
794
					<br />
795
				<table border="0" cellspacing="0" cellpadding="0">
796
					<tr>
797
						<td>Type:&nbsp;&nbsp;</td>
798
						<td>
799
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dsttype" class="formselect" onChange="typesel_change()">
800
<?php
801
								$sel = is_specialnet($pconfig['dst']); ?>
802
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
803
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
804
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
805
								<?php if(have_ruleint_access("pptp")): ?>
806
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
807
								<?php endif; ?>
808
								<?php if(have_ruleint_access("pppoe")): ?>
809
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
810
								<?php endif; ?>								
811
								<?php if(have_ruleint_access("l2tp")): ?>
812
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
813
                                                                <?php endif; ?>
814

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

    
999
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
1000
				State Timeout in seconds
1001
				<p />
1002

    
1003
				<p><strong>NOTE: Leave fields blank to disable that feature.</strong>
1004
			  </div>
1005
			</td>
1006
		</tr>
1007
		<tr>
1008
			<td width="22%" valign="top" class="vncell">State Type</td>
1009
			<td width="78%" class="vtable">
1010
				<div id="showadvstatebox">
1011
					<input type="button" onClick="show_advanced_state()" value="Advanced"></input> - Show advanced option</a>
1012
				</div>
1013
				<div id="showstateadv" style="display:none">
1014
					<select name="statetype">
1015
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
1016
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
1017
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
1018
					</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
1019
					<p>
1020
					<table width="90%">
1021
						<tr><td width="25%"><ul><li>keep state</li></td><td>Works with all IP protocols.</ul></td></tr>
1022
						<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>
1023
						<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>
1024
					</table>
1025
					</p>
1026
			  </div>
1027
			</td>
1028
		</tr>
1029
		<tr>
1030
			<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
1031
			<td width="78%" class="vtable">
1032
				<div id="showadvnoxmlrpcsyncbox">
1033
					<input type="button" onClick="show_advanced_noxmlrpc()" value="Advanced"></input> - Show advanced option</a>
1034
				</div>
1035
				<div id="shownoxmlrpcadv" style="display:none">
1036
					<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
1037
					HINT: This prevents the rule from automatically syncing to other CARP members.
1038
				</div>
1039
			</td>
1040
		</tr>
1041
		<?php
1042
			//build list of schedules
1043
			$schedules = array();
1044
			$schedules[] = "none";//leave none to leave rule enabled all the time
1045
			if(is_array($config['schedules']['schedule'])) {
1046
				foreach ($config['schedules']['schedule'] as $schedule) {
1047
					if ($schedule['name'] <> "")
1048
						$schedules[] = $schedule['name'];
1049
				}
1050
			}
1051
		?>
1052
		<tr>
1053
			<td width="22%" valign="top" class="vncell">Schedule</td>
1054
			<td width="78%" class="vtable">
1055
				<div id="showadvschedulebox">
1056
					<input type="button" onClick="show_advanced_schedule()" value="Advanced"></input> - Show advanced option</a>
1057
				</div>
1058
				<div id="showscheduleadv" style="display:none">
1059
					<select name='sched'>
1060
<?php
1061
					foreach($schedules as $schedule) {
1062
						if($schedule == $pconfig['sched']) {
1063
							$selected = " SELECTED";
1064
						} else {
1065
							$selected = "";
1066
						}
1067
						if ($schedule == "none") {
1068
							echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
1069
						} else {
1070
							echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
1071
						}
1072
					}
1073
?>
1074
					</select>
1075
					<p>Leave as 'none' to leave the rule enabled all the time.</p>
1076
				</div>
1077
			</td>
1078
		</tr>
1079
		
1080
<?php
1081
			/* build a list of gateways */
1082
			$gateways = array();
1083
			$gateways[] = "default"; // default to don't use this feature :)
1084
			if (is_array($config['gateways']['gateway_item'])) {
1085
				foreach($config['gateways']['gateway_item'] as $gw_item) {
1086
				if($gw_item['gateway'] <> "")
1087
					$gateways[] = $gw_item['name'];
1088
				}
1089
			}
1090
			
1091
?>
1092
		<tr>
1093
			<td width="22%" valign="top" class="vncell">Gateway</td>
1094
			<td width="78%" class="vtable">
1095
				<div id="showadvgatewaybox">
1096
					<input type="button" onClick="show_advanced_gateway()" value="Advanced"></input> - Show advanced option</a>
1097
				</div>
1098
				<div id="showgatewayadv" style="display:none">
1099
					<select name='gateway'>
1100
<?php
1101
					// add statically configured gateways to list
1102
					foreach($gateways as $gw) {
1103
						if($gw == "") 
1104
							continue;
1105
						if($gw == $pconfig['gateway']) {
1106
							$selected = " SELECTED";
1107
						} else {
1108
							$selected = "";
1109
						}
1110
						if ($gw == "default") {
1111
							echo "<option value=\"\" {$selected}>{$gw}</option>\n";
1112
						} else {
1113
							$gwip = lookup_gateway_ip_by_name($gw);
1114
							echo "<option value=\"{$gw}\" {$selected}>{$gw} - {$gwip}</option>\n";
1115
						}
1116
					}
1117
					// add dynamic gateways to list
1118
					$iflist = get_configured_interface_with_descr();
1119
					foreach ($iflist as $ifent => $ifdesc) {
1120
						if (in_array($config['interfaces'][$ifent]['ipaddr'], array("dhcp", "pppoe", "pptp", "ppp"))) {
1121
							if ($pconfig['gateway'] == $ifent) {
1122
								$selected = " SELECTED";
1123
							} else {
1124
								$selected = "";
1125
							}
1126
							if($ifdesc <> "") 
1127
								echo "<option value=\"{$ifent}\" {$selected}>".strtoupper($ifent)." - {$ifdesc}</option>\n";
1128
						}
1129
					}
1130
					/* add gateway groups to the list */
1131
					if (is_array($config['gateways']['gateway_group'])) {
1132
						foreach($config['gateways']['gateway_group'] as $gw_group) {
1133
							if($gw_group['name'] == "")
1134
								continue;
1135
							if($pconfig['gateway'] == $gw_group['name']) {
1136
								echo "<option value=\"{$gw_group['name']}\" SELECTED>{$gw_group['name']}</option>\n";
1137
							} else {
1138
								echo "<option value=\"{$gw_group['name']}\">{$gw_group['name']}</option>\n";
1139
							}
1140
						}
1141
					}
1142
?>
1143
					</select>
1144
					<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
1145
				</div>
1146
			</td>
1147
		</tr>
1148
		<tr>
1149
			<td width="22%" valign="top" class="vncell">In/Out</td>
1150
			<td width="78%" class="vtable">
1151
				<div id="showadvinoutbox">
1152
					<input type="button" onClick="show_advanced_inout()" value="Advanced"></input> - Show advanced option</a>
1153
				</div>
1154
				<div id="showinoutadv" style="display:none">
1155
					<select name="dnpipe">
1156
<?php
1157
		if (!is_array($dnqlist))
1158
			$dnqlist = array();
1159
		echo "<option value=\"none\"";
1160
		if (!$dnqselected) echo " SELECTED";
1161
		echo " >none</option>";
1162
		foreach ($dnqlist as $dnq => $dnqkey) {
1163
			if($dnq == "")
1164
				continue;
1165
			echo "<option value=\"$dnqkey\"";
1166
			if ($dnqkey == $pconfig['dnpipe']) {
1167
				$dnqselected = 1;
1168
				echo " SELECTED";
1169
			}
1170
			echo ">{$dnq}</option>"; 
1171
		}
1172
?>
1173
			</select> / 			
1174
			<select name="pdnpipe">
1175
<?php
1176
		$dnqselected = 0;
1177
		echo "<option value=\"none\"";
1178
		if (!$dnqselected) echo " SELECTED";
1179
		echo " >none</option>";
1180
		foreach ($dnqlist as $dnq => $dnqkey) {
1181
			if($dnq == "")
1182
				continue;
1183
			echo "<option value=\"$dnqkey\"";
1184
			if ($dnqkey == $pconfig['pdnpipe']) {
1185
				$dnqselected = 1;
1186
				echo " SELECTED";
1187
			}
1188
			echo ">{$dnq}</option>"; 
1189
		}
1190
?>
1191
				</select>
1192
				<br />
1193
				<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>
1194
				</div>
1195
			</td>
1196
		</tr>
1197

    
1198
		<tr>
1199
			<td width="22%" valign="top" class="vncell">Ackqueue/Queue</td>
1200
			<td width="78%" class="vtable">
1201
			<div id="showadvackqueuebox">
1202
				<input type="button" onClick="show_advanced_ackqueue()" value="Advanced"></input> - Show advanced option</a>
1203
			</div>
1204
			<div id="showackqueueadv" style="display:none">
1205
				<select name="ackqueue">
1206
<?php
1207
			if (!is_array($qlist))
1208
				$qlist = array();
1209
			echo "<option value=\"none\"";
1210
			if (!$qselected) echo " SELECTED";
1211
			echo " >none</option>";
1212
			foreach ($qlist as $q => $qkey) {
1213
				if($q == "")
1214
					continue;
1215
				echo "<option value=\"$q\"";
1216
				if ($q == $pconfig['ackqueue']) {
1217
					$qselected = 1;
1218
					echo " SELECTED";
1219
				}
1220
				echo ">{$q}</option>"; 
1221
			}
1222
?>
1223
				</select> / 			
1224
				<select name="defaultqueue">
1225
<?php
1226
			$qselected = 0;
1227
			echo "<option value=\"none\"";
1228
			if (!$qselected) echo " SELECTED";
1229
			echo " >none</option>";
1230
			foreach ($qlist as $q => $qkey) {
1231
				if($q == "")
1232
					continue;
1233
				echo "<option value=\"$q\"";
1234
				if ($q == $pconfig['defaultqueue']) {
1235
					$qselected = 1;
1236
					echo " SELECTED";
1237
				}
1238
				echo ">{$q}</option>"; 
1239
			}
1240
?>
1241
				</select>
1242
					<br />
1243
					<span class="vexpl">Choose the Acknowledge Queue only if you have selected Queue.</span>
1244
				</td>
1245
			</tr>
1246
			<tr>
1247
				<td width="22%" valign="top" class="vncell">Layer7</td>
1248
				<td width="78%" class="vtable">
1249
					<div id="showadvlayer7box">
1250
						<input type="button" onClick="show_advanced_layer7()" value="Advanced"></input> - Show advanced option</a>
1251
					</div>
1252
					<div id="showlayer7adv" style="display:none">
1253
				<select name="l7container">
1254
<?php
1255
					if (!is_array($l7clist))
1256
						$l7clist = array();
1257
					echo "<option value=\"none\"";
1258
					echo " >none</option>";
1259
					foreach ($l7clist as $l7ckey) {
1260
						echo "<option value=\"{$l7ckey}\"";
1261
						if ($l7ckey == $pconfig['l7container']) {
1262
							echo " SELECTED";
1263
						}
1264
						echo ">{$l7ckey}</option>"; 
1265
					}
1266
?>
1267
				</select>			
1268
				<br/>
1269
				<span class="vexpl">
1270
					Choose a Layer7 container to apply application protocol inspection rules.
1271
					These are valid for TCP and UDP protocols only.
1272
				</span>
1273
			  </div>
1274
			</td>
1275
		</tr>
1276
		<tr>
1277
			<td width="22%" valign="top">&nbsp;</td>
1278
			<td width="78%">
1279
				&nbsp;<br>&nbsp;
1280
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
1281
<?php			if (isset($id) && $a_filter[$id]): ?>
1282
					<input name="id" type="hidden" value="<?=$id;?>">
1283
<?php 			endif; ?>
1284
				<input name="after" type="hidden" value="<?=$after;?>">
1285
			</td>
1286
		</tr>
1287
	</table>
1288
</form>
1289
<script language="JavaScript">
1290
<!--
1291
	ext_change();
1292
	typesel_change();
1293
	proto_change();
1294

    
1295
<?php
1296
	$isfirst = 0;
1297
	$aliases = "";
1298
	$addrisfirst = 0;
1299
	$aliasesaddr = "";
1300
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1301
		foreach($config['aliases']['alias'] as $alias_name) {
1302
			switch ($alias_name['type']) {
1303
			case "port":
1304
				if($isfirst == 1) $portaliases .= ",";
1305
				$portaliases .= "'" . $alias_name['name'] . "'";
1306
				$isfirst = 1;
1307
				break;
1308
			case "host":
1309
			case "network":
1310
			case "openvpn":
1311
			case "urltable":
1312
				if($addrisfirst == 1) $aliasesaddr .= ",";
1313
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1314
				$addrisfirst = 1;
1315
				break;
1316
			default:
1317
				break;
1318
			}
1319
		}
1320
?>
1321

    
1322
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1323
	var customarray=new Array(<?php echo $portaliases; ?>);
1324

    
1325
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1326
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1327
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1328
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1329
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1330
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1331
//-->
1332
</script>
1333
<?php include("fend.inc"); ?>
1334
</body>
1335
</html>
(56-56/216)