Project

General

Profile

Download (52.1 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

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

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

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

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

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

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

    
173
if (isset($_GET['dup']))
174
	unset($id);
175

    
176
if ($_POST) {
177

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

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

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

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

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

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

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

    
232
	unset($input_errors);
233
	$pconfig = $_POST;
234

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

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

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

    
272
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
273

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

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

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

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

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

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

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

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

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

    
394
		/* Nosync directive - do not xmlrpc sync this item */
395
		if($_POST['nosync'] <> "")
396
			$filterent['nosync'] = true;
397
		else
398
			unset($filterent['nosync']);
399

    
400
		/* unless both values are provided, unset the values - ticket #650 */
401
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
402
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
403
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
404
		} else {
405
			unset($filterent['max-src-conn-rate']);
406
			unset($filterent['max-src-conn-rates']);
407
		}
408

    
409
		if ($_POST['proto'] != "any")
410
			$filterent['protocol'] = $_POST['proto'];
411
		else
412
			unset($filterent['protocol']);
413

    
414
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
415
			$filterent['icmptype'] = $_POST['icmptype'];
416
		else
417
			unset($filterent['icmptype']);
418

    
419
		pconfig_to_address($filterent['source'], $_POST['src'],
420
			$_POST['srcmask'], $_POST['srcnot'],
421
			$_POST['srcbeginport'], $_POST['srcendport']);
422

    
423
		pconfig_to_address($filterent['destination'], $_POST['dst'],
424
			$_POST['dstmask'], $_POST['dstnot'],
425
			$_POST['dstbeginport'], $_POST['dstendport']);
426

    
427
		if ($_POST['disabled'])
428
			$filterent['disabled'] = true;
429
		else
430
			unset($filterent['disabled']);
431

    
432
		if ($_POST['dscp'])
433
			$filterent['dscp'] = $_POST['dscp'];
434

    
435
		if ($_POST['log'])
436
			$filterent['log'] = true;
437
		else
438
			unset($filterent['log']);
439
		strncpy($filterent['descr'], $_POST['descr'], 52);
440

    
441
		if ($_POST['gateway'] != "") {
442
			$filterent['gateway'] = $_POST['gateway'];
443
		}
444
		
445
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
446
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
447
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
448
				$filterent['ackqueue'] = $_POST['ackqueue'];
449
		}
450

    
451
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
452
			$filterent['dnpipe'] = $_POST['dnpipe'];
453
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
454
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
455
		}
456

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

    
465
		// If we have an associated nat rule, make sure the destination doesn't change
466
		if( isset($a_filter[$id]['associated-rule-id']) ) {
467
			$filterent['destination'] = $a_filter[$id]['destination'];
468
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
469
		}
470

    
471
		if (isset($id) && $a_filter[$id])
472
			$a_filter[$id] = $filterent;
473
		else {
474
			if (is_numeric($after))
475
				array_splice($a_filter, $after+1, 0, array($filterent));
476
			else
477
				$a_filter[] = $filterent;
478
		}
479

    
480
		write_config();
481
		mark_subsystem_dirty('filter');
482

    
483
		if (isset($_POST['floating']))
484
			header("Location: firewall_rules.php?if=FloatingRules");
485
		else
486
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
487
		exit;
488
	}
489
}
490

    
491
read_altq_config(); /* XXX: */
492
$qlist =& get_unique_queue_list();
493
read_dummynet_config(); /* XXX: */
494
$dnqlist =& get_unique_dnqueue_list();
495
read_layer7_config();
496
$l7clist =& get_l7_unique_list();
497

    
498
$pgtitle = array("Firewall","Rules","Edit");
499
$closehead = false;
500

    
501
$page_filename = "firewall_rules_edit.php";
502
include("head.inc");
503

    
504
?>
505

    
506
</head>
507

    
508
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
509
<?php include("fbegin.inc"); ?>
510
<?php if ($input_errors) print_input_errors($input_errors); ?>
511

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

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

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

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

    
989
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
990
				State Timeout in seconds
991
				<p />
992

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

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

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

    
1319
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1320
	var customarray=new Array(<?php echo $portaliases; ?>);
1321

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