Project

General

Profile

Download (49.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

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

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

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

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

    
157
	//schedule support
158
	$pconfig['sched'] = $a_filter[$id]['sched'];
159

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

    
171
if (isset($_GET['dup']))
172
	unset($id);
173

    
174
if ($_POST) {
175

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

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

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

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

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

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

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

    
230
	unset($input_errors);
231
	$pconfig = $_POST;
232

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

    
245
	/* input validation */
246
	$reqdfields = explode(" ", "type proto src dst");
247
	$reqdfieldsn = explode(",", "Type,Protocol,Source,Destination");
248

    
249
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
250
		if( $_POST['proto'] != "tcp" )
251
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
252
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
253
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
254
	}
255
        
256
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
257
		$reqdfields[] = "srcmask";
258
		$reqdfieldsn[] = "Source bit count";
259
	}
260
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
261
		$reqdfields[] = "dstmask";
262
		$reqdfieldsn[] = "Destination bit count";
263
	}
264

    
265
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
266

    
267
	if (!$_POST['srcbeginport']) {
268
		$_POST['srcbeginport'] = 0;
269
		$_POST['srcendport'] = 0;
270
	}
271
	if (!$_POST['dstbeginport']) {
272
		$_POST['dstbeginport'] = 0;
273
		$_POST['dstendport'] = 0;
274
	}
275

    
276
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
277
                $input_errors[] = "{$_POST['srcbeginport']} is not a valid start source port. It must be a port alias or integer between 1 and 65535.";
278
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
279
                $input_errors[] = "{$_POST['srcendport']} is not a valid end source port. It must be a port alias or integer between 1 and 65535.";
280
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
281
                $input_errors[] = "{$_POST['dstbeginport']} is not a valid start destination port. It must be a port alias or integer between 1 and 65535.";
282
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
283
                $input_errors[] = "{$_POST['dstendport']} is not a valid end destination port. It must be a port alias or integer between 1 and 65535.";
284

    
285
	/* if user enters an alias and selects "network" then disallow. */
286
	if($_POST['srctype'] == "network") {
287
		if(is_alias($_POST['src']))
288
			$input_errors[] = "You must specify single host or alias for alias entries.";
289
	}
290
	if($_POST['dsttype'] == "network") {
291
		if(is_alias($_POST['dst']))
292
			$input_errors[] = "You must specify single host or alias for alias entries.";
293
	}
294

    
295
	if (!is_specialnet($_POST['srctype'])) {
296
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
297
			$input_errors[] = "{$_POST['src']} is not a valid source IP address or alias.";
298
		}
299
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
300
			$input_errors[] = "A valid source bit count must be specified.";
301
		}
302
	}
303
	if (!is_specialnet($_POST['dsttype'])) {
304
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
305
			$input_errors[] = "{$_POST['dst']} is not a valid destination IP address or alias.";
306
		}
307
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
308
			$input_errors[] = "A valid destination bit count must be specified.";
309
		}
310
	}
311

    
312
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
313
		/* swap */
314
		$tmp = $_POST['srcendport'];
315
		$_POST['srcendport'] = $_POST['srcbeginport'];
316
		$_POST['srcbeginport'] = $tmp;
317
	}
318
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
319
		/* swap */
320
		$tmp = $_POST['dstendport'];
321
		$_POST['dstendport'] = $_POST['dstbeginport'];
322
		$_POST['dstbeginport'] = $tmp;
323
	}
324
	if ($_POST['os'])
325
		if( $_POST['proto'] != "tcp" )
326
			$input_errors[] = "OS detection is only valid with protocol tcp.";
327

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

    
353
	if (!$input_errors) {
354
		$filterent = array();
355
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
356
		$filterent['type'] = $_POST['type'];
357
		if (isset($_POST['interface'] ))
358
			$filterent['interface'] = $_POST['interface'];
359

    
360
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
361
			if (isset($_POST['tag']))
362
				$filterent['tag'] = $_POST['tag'];
363
			if (isset($_POST['tagged']))
364
				$filterent['tagged'] = $_POST['tagged'];
365
			$filterent['direction'] = $_POST['direction'];
366
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
367
				$filterent['quick'] = $_POST['quick'];
368
			$filterent['floating'] = "yes";
369
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
370
				$filterent['interface'] = implode(",", $_POST['interface']);
371
			}
372
		}
373

    
374
		/* Advanced options */
375
		if ($_POST['allowopts'] == "yes")
376
			$filterent['allowopts'] = true;
377
		else
378
			unset($filterent['allowopts']);
379
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
380
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
381
		$filterent['max-src-states'] = $_POST['max-src-states'];
382
		$filterent['statetimeout'] = $_POST['statetimeout'];
383
		$filterent['statetype'] = $_POST['statetype'];
384
		$filterent['os'] = $_POST['os'];
385

    
386
		/* Nosync directive - do not xmlrpc sync this item */
387
		if($_POST['nosync'] <> "")
388
			$filterent['nosync'] = true;
389
		else
390
			unset($filterent['nosync']);
391

    
392
		/* unless both values are provided, unset the values - ticket #650 */
393
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
394
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
395
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
396
		} else {
397
			unset($filterent['max-src-conn-rate']);
398
			unset($filterent['max-src-conn-rates']);
399
		}
400

    
401
		if ($_POST['proto'] != "any")
402
			$filterent['protocol'] = $_POST['proto'];
403
		else
404
			unset($filterent['protocol']);
405

    
406
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
407
			$filterent['icmptype'] = $_POST['icmptype'];
408
		else
409
			unset($filterent['icmptype']);
410

    
411
		pconfig_to_address($filterent['source'], $_POST['src'],
412
			$_POST['srcmask'], $_POST['srcnot'],
413
			$_POST['srcbeginport'], $_POST['srcendport']);
414

    
415
		pconfig_to_address($filterent['destination'], $_POST['dst'],
416
			$_POST['dstmask'], $_POST['dstnot'],
417
			$_POST['dstbeginport'], $_POST['dstendport']);
418

    
419
		if ($_POST['disabled'])
420
			$filterent['disabled'] = true;
421
		else
422
			unset($filterent['disabled']);
423

    
424
		if ($_POST['dscp'])
425
			$filterent['dscp'] = $_POST['dscp'];
426

    
427
		if ($_POST['log'])
428
			$filterent['log'] = true;
429
		else
430
			unset($filterent['log']);
431
		strncpy($filterent['descr'], $_POST['descr'], 52);
432

    
433
		if ($_POST['gateway'] != "") {
434
			$filterent['gateway'] = $_POST['gateway'];
435
		}
436
		
437
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
438
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
439
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
440
				$filterent['ackqueue'] = $_POST['ackqueue'];
441
		}
442

    
443
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
444
			$filterent['dnpipe'] = $_POST['dnpipe'];
445
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
446
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
447
		}
448

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

    
457
		if (isset($id) && $a_filter[$id])
458
			$a_filter[$id] = $filterent;
459
		else {
460
			if (is_numeric($after))
461
				array_splice($a_filter, $after+1, 0, array($filterent));
462
			else
463
				$a_filter[] = $filterent;
464
		}
465

    
466
		write_config();
467
		mark_subsystem_dirty('filter');
468

    
469
		if (isset($_POST['floating']))
470
			header("Location: firewall_rules.php?if=FloatingRules");
471
		else
472
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
473
		exit;
474
	}
475
}
476

    
477
read_altq_config(); /* XXX: */
478
$qlist =& get_unique_queue_list();
479
read_dummynet_config(); /* XXX: */
480
$dnqlist =& get_unique_dnqueue_list();
481
read_layer7_config();
482
$l7clist =& get_l7_unique_list();
483

    
484
$pgtitle = array("Firewall","Rules","Edit");
485
$closehead = false;
486

    
487
$page_filename = "firewall_rules_edit.php";
488
include("head.inc");
489

    
490
?>
491

    
492
</head>
493

    
494
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
495
<?php include("fbegin.inc"); ?>
496
<?php if ($input_errors) print_input_errors($input_errors); ?>
497

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

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

    
644
				foreach ($icmptypes as $icmptype => $descr): ?>
645
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
646
<?php 			endforeach; ?>
647
			</select>
648
			<br />
649
			<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span>
650
		</td>
651
		</tr>
652
		<tr>
653
			<td width="22%" valign="top" class="vncellreq">Source</td>
654
			<td width="78%" class="vtable">
655
				<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
656
				<strong>not</strong>
657
				<br />
658
				Use this option to invert the sense of the match.
659
				<br />
660
				<br />
661
				<table border="0" cellspacing="0" cellpadding="0">
662
					<tr>
663
						<td>Type:&nbsp;&nbsp;</td>
664
						<td>
665
							<select name="srctype" class="formselect" onChange="typesel_change()">
666
<?php
667
								$sel = is_specialnet($pconfig['src']); ?>
668
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
669
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
670
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
671
								<?php if(have_ruleint_access("pptp")): ?>
672
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
673
								<?php endif; ?>
674
								<?php if(have_ruleint_access("pppoe")): ?>
675
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
676
								<?php endif; ?>								
677
								 <?php if(have_ruleint_access("l2tp")): ?>
678
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
679
                                                                <?php endif; ?>
680
<?php
681
								foreach ($ifdisp as $ifent => $ifdesc): ?>
682
								<?php if(have_ruleint_access($ifent)): ?>
683
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
684
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
685
										<?=$ifdesc?> address
686
									</option>
687
								<?php endif; ?>
688
<?php 							endforeach; ?>
689
							</select>
690
						</td>
691
					</tr>
692
					<tr>
693
						<td>Address:&nbsp;&nbsp;</td>
694
						<td>
695
							<input autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
696
							<select name="srcmask" class="formselect" id="srcmask">
697
<?php						for ($i = 31; $i > 0; $i--): ?>
698
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
699
<?php 						endfor; ?>
700
							</select>
701
						</td>
702
					</tr>
703
				</table>
704
				<div id="showadvancedboxspr">
705
					<p>
706
					<input type="button" onClick="show_source_port_range()" value="Advanced"></input> - Show source port range</a>
707
				</div>
708
			</td>
709
		</tr>
710
		<tr style="display:none" id="sprtable" name="sprtable">
711
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
712
			<td width="78%" class="vtable">
713
				<table border="0" cellspacing="0" cellpadding="0">
714
					<tr>
715
						<td>from:&nbsp;&nbsp;</td>
716
						<td>
717
							<select name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
718
								<option value="">(other)</option>
719
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
720
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
721
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
722
<?php 							endforeach; ?>
723
							</select>
724
							<input autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
725
						</td>
726
					</tr>
727
					<tr>
728
						<td>to:</td>
729
						<td>
730
							<select name="srcendport" class="formselect" onchange="ext_change()">
731
								<option value="">(other)</option>
732
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
733
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
734
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
735
<?php							endforeach; ?>
736
							</select>
737
							<input autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
738
						</td>
739
					</tr>
740
				</table>
741
				<br />
742
				<span class="vexpl">Specify the port or port range for the source of the packet for this rule. This is usually not equal to the destination port range (and is often &quot;any&quot;). <br /> Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port</span><br/>
743
				<span class="vexpl"><B>NOTE:</B> You will not need to enter anything here in 99.99999% of the circumstances.  If you're unsure, do not enter anything here!</span>
744
			</td>
745
		</tr>
746
		<tr>
747
			<td width="22%" valign="top" class="vncellreq">Destination</td>
748
			<td width="78%" class="vtable">
749
				<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
750
				<strong>not</strong>
751
					<br />
752
				Use this option to invert the sense of the match.
753
					<br />
754
					<br />
755
				<table border="0" cellspacing="0" cellpadding="0">
756
					<tr>
757
						<td>Type:&nbsp;&nbsp;</td>
758
						<td>
759
							<select name="dsttype" class="formselect" onChange="typesel_change()">
760
<?php
761
								$sel = is_specialnet($pconfig['dst']); ?>
762
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
763
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
764
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
765
								<?php if(have_ruleint_access("pptp")): ?>
766
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
767
								<?php endif; ?>
768
								<?php if(have_ruleint_access("pppoe")): ?>
769
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
770
								<?php endif; ?>								
771
								<?php if(have_ruleint_access("l2tp")): ?>
772
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
773
                                                                <?php endif; ?>
774

    
775
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
776
								<?php if(have_ruleint_access($if)): ?>
777
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
778
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
779
										<?=$ifdesc;?> address
780
									</option>
781
								<?php endif; ?>
782
<?php 							endforeach; ?>
783
							</select>
784
						</td>
785
					</tr>
786
					<tr>
787
						<td>Address:&nbsp;&nbsp;</td>
788
						<td>
789
							<input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
790
							/
791
							<select name="dstmask" class="formselect" id="dstmask">
792
<?php
793
							for ($i = 31; $i > 0; $i--): ?>
794
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
795
<?php						endfor; ?>
796
							</select>
797
						</td>
798
					</tr>
799
				</table>
800
			</td>
801
		</tr>
802
		<tr id="dprtr" name="dprtr">
803
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
804
			<td width="78%" class="vtable">
805
				<table border="0" cellspacing="0" cellpadding="0">
806
					<tr>
807
						<td>from:&nbsp;&nbsp;</td>
808
						<td>
809
							<select name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
810
								<option value="">(other)</option>
811
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
812
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
813
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
814
<?php 							endforeach; ?>
815
							</select>
816
							<input autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>">
817
						</td>
818
					</tr>
819
					<tr>
820
						<td>to:</td>
821
						<td>
822
							<select name="dstendport" class="formselect" onchange="ext_change()">
823
								<option value="">(other)</option>
824
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
825
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
826
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
827
<?php 							endforeach; ?>
828
							</select>
829
							<input autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>">
830
						</td>
831
					</tr>
832
				</table>
833
				<br />
834
				<span class="vexpl">
835
					Specify the port or port range for the destination of the packet for this rule.
836
					<br />
837
					Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port
838
				</span>
839
			</td>
840
		</tr>
841
		<tr>
842
			<td width="22%" valign="top" class="vncellreq">Log</td>
843
			<td width="78%" class="vtable">
844
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
845
				<strong>Log packets that are handled by this rule</strong>
846
				<br />
847
				<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>
848
			</td>
849
		</tr>
850
		<tr>
851
			<td width="22%" valign="top" class="vncell">Description</td>
852
			<td width="78%" class="vtable">
853
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
854
				<br />
855
				<span class="vexpl">You may enter a description here for your reference.</span>
856
			</td>
857
		</tr>
858
		<tr>
859
			<td width="22%" valign="top">&nbsp;</td>
860
			<td width="78%">
861
				&nbsp;<br>&nbsp;
862
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
863
<?php			if (isset($id) && $a_filter[$id]): ?>
864
					<input name="id" type="hidden" value="<?=$id;?>">
865
<?php 			endif; ?>
866
				<input name="after" type="hidden" value="<?=$after;?>">
867
			</td>
868
		</tr>
869
		<tr>
870
			<td>&nbsp;</td>
871
		</tr>
872
		<tr>
873
			<td colspan="2" valign="top" class="listtopic">Advanced features</td>
874
		</tr>	
875
		<tr>
876
			<td width="22%" valign="top" class="vncell">Source OS</td>
877
			<td width="78%" class="vtable">
878
				<div id="showadvsourceosbox">
879
					<input type="button" onClick="show_advanced_sourceos()" value="Advanced"></input> - Show advanced option</a>
880
				</div>
881
				<div id="showsourceosadv" style="display:none">
882
					OS Type:&nbsp;
883
					<select name="os" id="os" class="formselect">
884
<?php
885
						$ostypes = array(
886
							 "" => "any",
887
							"AIX" => "AIX",
888
							"Linux" => "Linux",
889
							"FreeBSD" => "FreeBSD",
890
							"NetBSD" => "NetBSD",
891
							"OpenBSD" => "OpenBSD",
892
							"Solaris" => "Solaris",
893
							"MacOS" => "MacOS",
894
							"Windows" => "Windows",
895
							"Novell" => "Novell",
896
							"NMAP" => "NMAP"
897
			           );
898
						foreach ($ostypes as $ostype => $descr): ?>
899
							<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
900
<?php
901
					endforeach; 
902
?>
903
					</select>
904
					<br />
905
					Note: this only works for TCP rules
906
				</div>
907
			</td>
908
		</tr>
909
		<tr>
910
			<td width="22%" valign="top" class="vncell">Diffserv Code Point</td>
911
			<td width="78%" class="vtable">
912
				<div id="dsadv" name="dsadv">
913
					<input type="button" onClick="show_dsdiv();" value="Advanced"> - Show advanced option
914
				</div>
915
				<div id="dsdivmain" name="dsdivmain" style="display:none">
916
					<select name="dscp" id="dscp">
917
						<option value=""></option>
918
						<?php foreach($firewall_rules_dscp_types as $frdt): ?>
919
							<option value="<?=$frdt?>"<?php if($pconfig['dscp'] == $frdt) echo " SELECTED"; ?>><?=$frdt?></option>
920
						<?php endforeach; ?>
921
					</select>
922
				</div>
923
			</td>
924
		</tr>
925
		<tr>
926
			<td width="22%" valign="top" class="vncell">Advanced Options</td>
927
			<td width="78%" class="vtable">
928
			<div id="aoadv" name="aoadv">
929
				<input type="button" onClick="show_aodiv();" value="Advanced"> - Show advanced option
930
			</div>
931
			<div id="aodivmain" name="aodivmain" style="display:none">
932
				<input type="checkbox" id="allowopts" value="yes" name="allowopts"<?php if($pconfig['allowopts'] == true) echo " checked"; ?>>
933
				<br/><span class="vexpl"><?=gettext("This allows packets with ip options to pass otherwise they are blocked by default i.e. with multicast routing/proxing.");?>
934
				</span><p>
935
				<input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
936
				<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>");?>
937
				</span><p>
938
				<input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>">
939
				<br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before on another rule.")?>
940
				</span> <p>
941
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
942
				<input name="max-src-conn" id="max-src-conn" value="<?php echo $pconfig['max-src-conn'] ?>"><br> Maximum established TCP connections per host<p>	 
943
				<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
944
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
945
				<select name="max-src-conn-rates" id="max-src-conn-rates">
946
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
947
<?php				for($x=1; $x<255; $x++) {
948
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
949
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
950
					} ?>
951
				</select><br />
952
				Maximum new connections / per second
953
				<p>
954

    
955
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
956
				State Timeout in seconds
957
				<p />
958

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

    
1153
		<tr>
1154
			<td width="22%" valign="top" class="vncell">Ackqueue/Queue</td>
1155
			<td width="78%" class="vtable">
1156
			<div id="showadvackqueuebox">
1157
				<input type="button" onClick="show_advanced_ackqueue()" value="Advanced"></input> - Show advanced option</a>
1158
			</div>
1159
			<div id="showackqueueadv" style="display:none">
1160
				<select name="ackqueue">
1161
<?php
1162
			if (!is_array($qlist))
1163
				$qlist = array();
1164
			echo "<option value=\"none\"";
1165
			if (!$qselected) echo " SELECTED";
1166
			echo " >none</option>";
1167
			foreach ($qlist as $q => $qkey) {
1168
				if($q == "")
1169
					continue;
1170
				echo "<option value=\"$q\"";
1171
				if ($q == $pconfig['ackqueue']) {
1172
					$qselected = 1;
1173
					echo " SELECTED";
1174
				}
1175
				echo ">{$q}</option>"; 
1176
			}
1177
?>
1178
				</select> / 			
1179
				<select name="defaultqueue">
1180
<?php
1181
			$qselected = 0;
1182
			echo "<option value=\"none\"";
1183
			if (!$qselected) echo " SELECTED";
1184
			echo " >none</option>";
1185
			foreach ($qlist as $q => $qkey) {
1186
				if($q == "")
1187
					continue;
1188
				echo "<option value=\"$q\"";
1189
				if ($q == $pconfig['defaultqueue']) {
1190
					$qselected = 1;
1191
					echo " SELECTED";
1192
				}
1193
				echo ">{$q}</option>"; 
1194
			}
1195
?>
1196
				</select>
1197
					<br />
1198
					<span class="vexpl">Choose the Acknowledge Queue only if you have selected Queue.</span>
1199
				</td>
1200
			</tr>
1201
			<tr>
1202
				<td width="22%" valign="top" class="vncell">Layer7</td>
1203
				<td width="78%" class="vtable">
1204
					<div id="showadvlayer7box">
1205
						<input type="button" onClick="show_advanced_layer7()" value="Advanced"></input> - Show advanced option</a>
1206
					</div>
1207
					<div id="showlayer7adv" style="display:none">
1208
				<select name="l7container">
1209
<?php
1210
					if (!is_array($l7clist))
1211
						$dnqlist = array();
1212
					echo "<option value=\"none\"";
1213
					echo " >none</option>";
1214
					foreach ($l7clist as $l7ckey) {
1215
						echo "<option value=\"{$l7ckey}\"";
1216
						if ($l7ckey == $pconfig['l7container']) {
1217
							echo " SELECTED";
1218
						}
1219
						echo ">{$l7ckey}</option>"; 
1220
					}
1221
?>
1222
				</select>			
1223
				<br/>
1224
				<span class="vexpl">
1225
					Choose a Layer7 container to apply application protocol inspection rules.
1226
					This rule are valid for tcp and udp protocols for now.
1227
				</span>
1228
			  </div>
1229
			</td>
1230
		</tr>
1231
		<tr>
1232
			<td width="22%" valign="top">&nbsp;</td>
1233
			<td width="78%">
1234
				&nbsp;<br>&nbsp;
1235
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
1236
<?php			if (isset($id) && $a_filter[$id]): ?>
1237
					<input name="id" type="hidden" value="<?=$id;?>">
1238
<?php 			endif; ?>
1239
				<input name="after" type="hidden" value="<?=$after;?>">
1240
			</td>
1241
		</tr>
1242
	</table>
1243
</form>
1244
<script language="JavaScript">
1245
<!--
1246
	ext_change();
1247
	typesel_change();
1248
	proto_change();
1249

    
1250
<?php
1251
	$isfirst = 0;
1252
	$aliases = "";
1253
	$addrisfirst = 0;
1254
	$aliasesaddr = "";
1255
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1256
		foreach($config['aliases']['alias'] as $alias_name) {
1257
			switch ($alias_name['type']) {
1258
			case "port":
1259
				if($isfirst == 1) $portaliases .= ",";
1260
				$portaliases .= "'" . $alias_name['name'] . "'";
1261
				$isfirst = 1;
1262
				break;
1263
			case "host":
1264
			case "network":
1265
			case "openvpn":
1266
				if($addrisfirst == 1) $aliasesaddr .= ",";
1267
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1268
				$addrisfirst = 1;
1269
				break;
1270
			default:
1271
				break;
1272
			}
1273
		}
1274
?>
1275

    
1276
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1277
	var customarray=new Array(<?php echo $portaliases; ?>);
1278

    
1279
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1280
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1281
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1282
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1283
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1284
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1285
//-->
1286
</script>
1287
<?php include("fend.inc"); ?>
1288
</body>
1289
</html>
(56-56/214)