Project

General

Profile

Download (34.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
require("guiconfig.inc");
35

    
36
$specialsrcdst = explode(" ", "any wanip lanip lan pptp pppoe");
37

    
38
if (!is_array($config['filter']['rule'])) {
39
	$config['filter']['rule'] = array();
40
}
41
filter_rules_sort();
42
$a_filter = &$config['filter']['rule'];
43

    
44
$id = $_GET['id'];
45
if (is_numeric($_POST['id']))
46
	$id = $_POST['id'];
47

    
48
$after = $_GET['after'];
49

    
50
if (isset($_POST['after']))
51
	$after = $_POST['after'];
52

    
53
if (isset($_GET['dup'])) {
54
	$id = $_GET['dup'];
55
	$after = $_GET['dup'];
56
}
57

    
58
if (isset($id) && $a_filter[$id]) {
59
	$pconfig['interface'] = $a_filter[$id]['interface'];
60

    
61
	if (!isset($a_filter[$id]['type']))
62
		$pconfig['type'] = "pass";
63
	else
64
		$pconfig['type'] = $a_filter[$id]['type'];
65

    
66
	if (isset($a_filter[$id]['protocol']))
67
		$pconfig['proto'] = $a_filter[$id]['protocol'];
68
	else
69
		$pconfig['proto'] = "any";
70

    
71
	if ($a_filter[$id]['protocol'] == "icmp")
72
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
73

    
74
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
75
		$pconfig['srcmask'], $pconfig['srcnot'],
76
		$pconfig['srcbeginport'], $pconfig['srcendport']);
77

    
78
	if($a_filter[$id]['os'] <> "")
79
		$pconfig['os'] = $a_filter[$id]['os'];
80

    
81
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
82
		$pconfig['dstmask'], $pconfig['dstnot'],
83
		$pconfig['dstbeginport'], $pconfig['dstendport']);
84

    
85
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
86
	$pconfig['log'] = isset($a_filter[$id]['log']);
87
	$pconfig['descr'] = $a_filter[$id]['descr'];
88

    
89
	/* advanced */
90
        $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
91
        $pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
92
        $pconfig['statetype'] = $a_filter[$id]['statetype'];
93
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
94

    
95
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
96

    
97
	/* advanced - new connection per second banning*/
98
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
99
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
100

    
101
	/* Multi-WAN next-hop support */
102
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
103
	
104
	//schedule support
105
	$pconfig['sched'] = $a_filter[$id]['sched'];
106

    
107
} else {
108
	/* defaults */
109
	if ($_GET['if'])
110
		$pconfig['interface'] = $_GET['if'];
111
	$pconfig['type'] = "pass";
112
	$pconfig['src'] = "any";
113
	$pconfig['dst'] = "any";
114
}
115

    
116
if (isset($_GET['dup']))
117
	unset($id);
118

    
119
if ($_POST) {
120

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

    
124
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
125
		$_POST['srcbeginport'] = 0;
126
		$_POST['srcendport'] = 0;
127
		$_POST['dstbeginport'] = 0;
128
		$_POST['dstendport'] = 0;
129
	} else {
130

    
131
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
132
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
133
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
134
			$_POST['srcendport'] = $_POST['srcendport_cust'];
135

    
136
		if ($_POST['srcbeginport'] == "any") {
137
			$_POST['srcbeginport'] = 0;
138
			$_POST['srcendport'] = 0;
139
		} else {
140
			if (!$_POST['srcendport'])
141
				$_POST['srcendport'] = $_POST['srcbeginport'];
142
		}
143
		if ($_POST['srcendport'] == "any")
144
			$_POST['srcendport'] = $_POST['srcbeginport'];
145

    
146
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
147
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
148
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
149
			$_POST['dstendport'] = $_POST['dstendport_cust'];
150

    
151
		if ($_POST['dstbeginport'] == "any") {
152
			$_POST['dstbeginport'] = 0;
153
			$_POST['dstendport'] = 0;
154
		} else {
155
			if (!$_POST['dstendport'])
156
				$_POST['dstendport'] = $_POST['dstbeginport'];
157
		}
158
		if ($_POST['dstendport'] == "any")
159
			$_POST['dstendport'] = $_POST['dstbeginport'];
160
	}
161

    
162
	if (is_specialnet($_POST['srctype'])) {
163
		$_POST['src'] = $_POST['srctype'];
164
		$_POST['srcmask'] = 0;
165
	} else if ($_POST['srctype'] == "single") {
166
		$_POST['srcmask'] = 32;
167
	}
168
	if (is_specialnet($_POST['dsttype'])) {
169
		$_POST['dst'] = $_POST['dsttype'];
170
		$_POST['dstmask'] = 0;
171
	}  else if ($_POST['dsttype'] == "single") {
172
		$_POST['dstmask'] = 32;
173
	}
174

    
175
	unset($input_errors);
176
	$pconfig = $_POST;
177

    
178
	/* input validation */
179
	$reqdfields = explode(" ", "type interface proto src dst");
180
	$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
181

    
182

    
183
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
184
		if( $_POST['proto'] != "tcp" )
185
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
186
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
187
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
188
	}
189

    
190

    
191
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
192
		$reqdfields[] = "srcmask";
193
		$reqdfieldsn[] = "Source bit count";
194
	}
195
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
196
		$reqdfields[] = "dstmask";
197
		$reqdfieldsn[] = "Destination bit count";
198
	}
199

    
200
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
201

    
202
	if (!$_POST['srcbeginport']) {
203
		$_POST['srcbeginport'] = 0;
204
		$_POST['srcendport'] = 0;
205
	}
206
	if (!$_POST['dstbeginport']) {
207
		$_POST['dstbeginport'] = 0;
208
		$_POST['dstendport'] = 0;
209
	}
210

    
211
	if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) {
212
		$input_errors[] = "The start source port must be an alias or integer between 1 and 65535.";
213
	}
214
	if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) {
215
		$input_errors[] = "The end source port must be an alias or integer between 1 and 65535.";
216
	}
217
	if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) {
218
		$input_errors[] = "The start destination port must be an alias or integer between 1 and 65535.";
219
	}
220
	if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) {
221
		$input_errors[] = "The end destination port must be an alias or integer between 1 and 65535.";
222
	}
223

    
224
	/* if user enters an alias and selects "network" then disallow. */
225
	if($_POST['srctype'] == "network") {
226
		if(is_alias($_POST['src']))
227
			$input_errors[] = "You must specify single host or alias for alias entries.";
228
	}
229
        if($_POST['sched'] && $_POST['gateway'])
230
                $input_errors[] = "You cannot specify a gateway with time based rules.";
231

    
232
	if($_POST['dsttype'] == "network") {
233
		if(is_alias($_POST['dst']))
234
			$input_errors[] = "You must specify single host or alias for alias entries.";
235
	}
236

    
237
	if (!is_specialnet($_POST['srctype'])) {
238
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
239
			$input_errors[] = "A valid source IP address or alias must be specified.";
240
		}
241
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
242
			$input_errors[] = "A valid source bit count must be specified.";
243
		}
244
	}
245
	if (!is_specialnet($_POST['dsttype'])) {
246
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
247
			$input_errors[] = "A valid destination IP address or alias must be specified.";
248
		}
249
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
250
			$input_errors[] = "A valid destination bit count must be specified.";
251
		}
252
	}
253

    
254
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
255
		/* swap */
256
		$tmp = $_POST['srcendport'];
257
		$_POST['srcendport'] = $_POST['srcbeginport'];
258
		$_POST['srcbeginport'] = $tmp;
259
	}
260
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
261
		/* swap */
262
		$tmp = $_POST['dstendport'];
263
		$_POST['dstendport'] = $_POST['dstbeginport'];
264
		$_POST['dstbeginport'] = $tmp;
265
	}
266
	if ($_POST['os'])
267
		if( $_POST['proto'] != "tcp" )
268
			$input_errors[] = "OS detection is only valid with protocol tcp.";
269

    
270
	if (!$input_errors) {
271
		$filterent = array();
272
		$filterent['type'] = $_POST['type'];
273
		$filterent['interface'] = $_POST['interface'];
274

    
275
		/* Advanced options */
276
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
277
		$filterent['max-src-states'] = $_POST['max-src-states'];
278
		$filterent['statetimeout'] = $_POST['statetimeout'];
279
		$filterent['statetype'] = $_POST['statetype'];
280
		$filterent['os'] = $_POST['os'];
281

    
282
		/* Nosync directive - do not xmlrpc sync this item */
283
		if($_POST['nosync'] <> "")
284
			$filterent['nosync'] = true;
285
		else
286
			unset($filterent['nosync']);
287

    
288
		/* unless both values are provided, unset the values - ticket #650 */
289
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
290
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
291
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
292
		} else {
293
			unset($filterent['max-src-conn-rate']);
294
			unset($filterent['max-src-conn-rates']);
295
		}
296

    
297
		if ($_POST['proto'] != "any")
298
			$filterent['protocol'] = $_POST['proto'];
299
		else
300
			unset($filterent['protocol']);
301

    
302
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
303
			$filterent['icmptype'] = $_POST['icmptype'];
304
		else
305
			unset($filterent['icmptype']);
306

    
307
		pconfig_to_address($filterent['source'], $_POST['src'],
308
			$_POST['srcmask'], $_POST['srcnot'],
309
			$_POST['srcbeginport'], $_POST['srcendport']);
310

    
311
		pconfig_to_address($filterent['destination'], $_POST['dst'],
312
			$_POST['dstmask'], $_POST['dstnot'],
313
			$_POST['dstbeginport'], $_POST['dstendport']);
314

    
315
                if ($_POST['disabled'])
316
                        $filterent['disabled'] = true;
317
                else
318
                        unset($filterent['disabled']);
319
                if ($_POST['log'])
320
                        $filterent['log'] = true;
321
                else
322
                        unset($filterent['log']);
323
		strncpy($filterent['descr'], $_POST['descr'], 52);
324

    
325
		if ($_POST['gateway'] != "") {
326
			$filterent['gateway'] = $_POST['gateway'];
327
		}
328

    
329
		if ($_POST['sched'] != "") {
330
			$filterent['sched'] = $_POST['sched'];
331
		}
332

    
333
		if (isset($id) && $a_filter[$id])
334
			$a_filter[$id] = $filterent;
335
		else {
336
			if (is_numeric($after))
337
				array_splice($a_filter, $after+1, 0, array($filterent));
338
			else
339
				$a_filter[] = $filterent;
340
		}
341

    
342
		write_config();
343
		touch($d_filterconfdirty_path);
344

    
345
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
346
		exit;
347
	}
348
}
349

    
350
$pgtitle = "Firewall: Rules: Edit";
351
$closehead = false;
352

    
353
$page_filename = "firewall_rules_edit.php";
354
include("head.inc");
355

    
356
?>
357

    
358
</head>
359

    
360
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
361
<?php include("fbegin.inc"); ?>
362
<p class="pgtitle"><?=$pgtitle?></p>
363
<?php if ($input_errors) print_input_errors($input_errors); ?>
364

    
365
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
366
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
367
    	<tr>
368
			<td width="22%" valign="top" class="vncellreq">Action</td>
369
			<td width="78%" class="vtable">
370
				<select name="type" class="formfld">
371
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
372
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
373
					<?=htmlspecialchars($type);?>
374
					</option>
375
					<?php endforeach; ?>
376
				</select>
377
				<br/>
378
				<span class="vexpl">
379
					Choose what to do with packets that match the criteria specified below. <br/>
380
					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.
381
				</span>
382
			</td>
383
		</tr>
384
		<tr>
385
			<td width="22%" valign="top" class="vncellreq">Disabled</td>
386
			<td width="78%" class="vtable">
387
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
388
				<strong>Disable this rule</strong><br />
389
				<span class="vexpl">Set this option to disable this rule without removing it from the list.</span>
390
			</td>
391
		</tr>
392
		<tr>
393
			<td width="22%" valign="top" class="vncellreq">Interface</td>
394
			<td width="78%" class="vtable">
395
				<select name="interface" class="formfld">
396
<?php
397
					$interfaces = array('wan' => 'WAN', 'lan' => 'LAN', 'pptp' => 'PPTP', 'pppoe' => 'PPPOE', 'enc0' => 'IPSEC');
398
					for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
399
						$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
400
					}
401
					foreach ($interfaces as $iface => $ifacename): ?>
402
						<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>><?=htmlspecialchars($ifacename);?></option>
403
<?php 				endforeach; ?>
404
				</select>
405
				<br />
406
				<span class="vexpl">Choose on which interface packets must come in to match this rule.</span>
407
			</td>
408
		</tr>
409
		<tr>
410
			<td width="22%" valign="top" class="vncellreq">Protocol</td>
411
			<td width="78%" class="vtable">
412
				<select name="proto" class="formfld" onchange="proto_change()">
413
<?php
414
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IGMP any carp pfsync");
415
				foreach ($protocols as $proto): ?>
416
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
417
<?php 			endforeach; ?>
418
				</select>
419
				<br />
420
				<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>
421
			</td>
422
		</tr>
423
		<tr id="icmpbox" name="icmpbox">
424
			<td valign="top" class="vncell">ICMP type</td>
425
			<td class="vtable">
426
				<select name="icmptype" class="formfld">
427
<?php
428
				$icmptypes = array(
429
				"" => "any",
430
				"echorep" => "Echo reply",
431
				"unreach" => "Destination unreachable",
432
				"squench" => "Source quench",
433
				"redir" => "Redirect",
434
				"althost" => "Alternate Host",
435
				"echoreq" => "Echo",
436
				"routeradv" => "Router advertisement",
437
				"routersol" => "Router solicitation",
438
				"timex" => "Time exceeded",
439
				"paramprob" => "Invalid IP header",
440
				"timereq" => "Timestamp",
441
				"timerep" => "Timestamp reply",
442
				"inforeq" => "Information request",
443
				"inforep" => "Information reply",
444
				"maskreq" => "Address mask request",
445
				"maskrep" => "Address mask reply"
446
				);
447

    
448
				foreach ($icmptypes as $icmptype => $descr): ?>
449
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
450
<?php 			endforeach; ?>
451
			</select>
452
			<br />
453
			<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span>
454
		</td>
455
		</tr>
456
		<tr>
457
			<td width="22%" valign="top" class="vncellreq">Source</td>
458
			<td width="78%" class="vtable">
459
				<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
460
				<strong>not</strong>
461
				<br />
462
				Use this option to invert the sense of the match.
463
				<br />
464
				<br />
465
				<table border="0" cellspacing="0" cellpadding="0">
466
					<tr>
467
						<td>Type:&nbsp;&nbsp;</td>
468
						<td>
469
							<select name="srctype" class="formfld" onChange="typesel_change()">
470
<?php
471
								$sel = is_specialnet($pconfig['src']); ?>
472
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
473
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
474
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
475
								<option value="wanip" 	<?php if ($pconfig['src'] == "wanip") { echo "selected"; } ?>>WAN address</option>
476
								<option value="lanip" 	<?php if ($pconfig['src'] == "lanip") { echo "selected"; } ?>>LAN address</option>
477
								<option value="lan"     <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
478
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
479
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
480
<?php
481
								for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
482
									<option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>><?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
483
									<option value="opt<?=$i;?>ip"<?php if ($pconfig['src'] == "opt" . $i . "ip") { echo "selected"; } ?>>
484
										<?=$config['interfaces']['opt' . $i]['descr']?> address
485
									</option>
486
<?php 							endfor; ?>
487
							</select>
488
						</td>
489
					</tr>
490
					<tr>
491
						<td>Address:&nbsp;&nbsp;</td>
492
						<td>
493
							<input autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
494
							<select name="srcmask" class="formfld" id="srcmask">
495
<?php						for ($i = 31; $i > 0; $i--): ?>
496
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
497
<?php 						endfor; ?>
498
							</select>
499
						</td>
500
					</tr>
501
				</table>
502
				<div id="showadvancedboxspr">
503
					<p>
504
					<input type="button" onClick="show_source_port_range()" value="Advanced"></input> - Show source port range</a>
505
				</div>
506
			</td>
507
		</tr>
508
		<tr style="display:none" id="sprtable" name="sprtable">
509
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
510
			<td width="78%" class="vtable">
511
				<table border="0" cellspacing="0" cellpadding="0">
512
					<tr>
513
						<td>from:&nbsp;&nbsp;</td>
514
						<td>
515
							<select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
516
								<option value="">(other)</option>
517
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
518
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
519
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
520
<?php 							endforeach; ?>
521
							</select>
522
							<input autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
523
						</td>
524
					</tr>
525
					<tr>
526
						<td>to:</td>
527
						<td>
528
							<select name="srcendport" class="formfld" onchange="ext_change()">
529
								<option value="">(other)</option>
530
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
531
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
532
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
533
<?php							endforeach; ?>
534
							</select>
535
							<input autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
536
						</td>
537
					</tr>
538
				</table>
539
				<br />
540
				<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/>
541
				<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>
542
			</td>
543
		</tr>
544
		<tr>
545
			<td width="22%" valign="top" class="vncell">Source OS</td>
546
			<td width="78%" class="vtable">OS Type:&nbsp;
547
				<select name="os" id="os" class="formfld">
548
<?php
549
		           $ostypes = array(
550
						 "" => "any",
551
		                 "AIX" => "AIX",
552
		                 "Linux" => "Linux",
553
		                 "FreeBSD" => "FreeBSD",
554
		                 "NetBSD" => "NetBSD",
555
		                 "OpenBSD" => "OpenBSD",
556
		                 "Solaris" => "Solaris",
557
		                 "MacOS" => "MacOS",
558
		                 "Windows" => "Windows",
559
		                 "Novell" => "Novell",
560
		                 "NMAP" => "NMAP"
561
		           );
562

    
563
					foreach ($ostypes as $ostype => $descr): ?>
564
						<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
565
<?php				endforeach; ?>
566
				</select>
567
				<br />
568
				Note: this only works for TCP rules
569
			</td>
570
		</tr>
571
		<tr>
572
			<td width="22%" valign="top" class="vncellreq">Destination</td>
573
			<td width="78%" class="vtable">
574
				<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
575
				<strong>not</strong>
576
					<br />
577
				Use this option to invert the sense of the match.
578
					<br />
579
					<br />
580
				<table border="0" cellspacing="0" cellpadding="0">
581
					<tr>
582
						<td>Type:&nbsp;&nbsp;</td>
583
						<td>
584
							<select name="dsttype" class="formfld" onChange="typesel_change()">
585
<?php
586
								$sel = is_specialnet($pconfig['dst']); ?>
587
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
588
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
589
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
590
								<option value="wanip" <?php if ($pconfig['dst'] == "wanip") { echo "selected"; } ?>>WAN address</option>
591
								<option value="lanip" <?php if ($pconfig['dst'] == "lanip") { echo "selected"; } ?>>LAN address</option>
592
								<option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
593
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
594
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
595
<?php 							for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
596
									<option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>><?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
597
									<option value="opt<?=$i;?>ip"<?php if ($pconfig['dst'] == "opt" . $i . "ip") { echo "selected"; } ?>>
598
										<?=$config['interfaces']['opt' . $i]['descr']?> address
599
									</option>
600
<?php 							endfor; ?>
601
							</select>
602
						</td>
603
					</tr>
604
					<tr>
605
						<td>Address:&nbsp;&nbsp;</td>
606
						<td>
607
							<input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
608
							/
609
							<select name="dstmask" class="formfld" id="dstmask">
610
<?php
611
							for ($i = 31; $i > 0; $i--): ?>
612
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
613
<?php						endfor; ?>
614
							</select>
615
						</td>
616
					</tr>
617
				</table>
618

    
619
			</td>
620
		</tr>
621
		<tr id="dprtr" name="dprtr">
622
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
623
			<td width="78%" class="vtable">
624
				<table border="0" cellspacing="0" cellpadding="0">
625
					<tr>
626
						<td>from:&nbsp;&nbsp;</td>
627
						<td>
628
							<select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
629
								<option value="">(other)</option>
630
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
631
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
632
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
633
<?php 							endforeach; ?>
634
							</select>
635
							<input autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>">
636
						</td>
637
					</tr>
638
					<tr>
639
						<td>to:</td>
640
						<td>
641
							<select name="dstendport" class="formfld" onchange="ext_change()">
642
								<option value="">(other)</option>
643
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
644
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
645
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
646
<?php 							endforeach; ?>
647
							</select>
648
							<input autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>">
649
						</td>
650
					</tr>
651
				</table>
652
				<br />
653
				<span class="vexpl">
654
					Specify the port or port range for the destination of the packet for this rule.
655
						<br />
656
					Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port
657
				</span>
658
			</td>
659
		</tr>
660
		<tr>
661
			<td width="22%" valign="top" class="vncellreq">Log</td>
662
			<td width="78%" class="vtable">
663
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
664
				<strong>Log packets that are handled by this rule</strong>
665
					<br />
666
				<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>
667
			</td>
668
		</tr>
669
		<tr>
670
			<td width="22%" valign="top" class="vncell">Advanced Options</td>
671
			<td width="78%" class="vtable">
672
			<div id="aoadv" name="aoadv">
673
				<input type="button" onClick="show_aodiv();" value="Advanced"> - Show advanced options
674
			</div>
675
			<div id="aodivmain" name="aodivmain" style="display:none">
676
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
677
				<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
678
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
679
				<select name="max-src-conn-rates" id="max-src-conn-rates">
680
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
681
<?php				for($x=1; $x<255; $x++) {
682
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
683
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
684
					} ?>
685
				</select><br />
686
				Maximum new connections / per second
687
				<p>
688

    
689
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
690
				State Timeout in seconds
691
				<p />
692

    
693
				<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
694
			  </div>
695
			</td>
696
		</tr>
697
		<tr>
698
			<td width="22%" valign="top" class="vncell">State Type</td>
699
			<td width="78%" class="vtable">
700
				<div id="showadvstatebox">
701
					<input type="button" onClick="show_advanced_state()" value="Advanced"></input> - Show state</a>
702
				</div>
703
				<div id="showstateadv" style="display:none">
704
					<select name="statetype">
705
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
706
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
707
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
708
					</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
709
					<p>
710
					<table width="90%">
711
						<tr><td width="25%"><ul><li>keep state</li></td><td>Works with all IP protocols.</ul></td></tr>
712
						<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>
713
						<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>
714
					</table>
715
					</p>
716
			  </div>
717
			</td>
718
		</tr>
719
		<tr>
720
			<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
721
			<td width="78%" class="vtable">
722
				<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
723
				HINT: This prevents the rule from automatically syncing to other CARP members.
724
			</td>
725
		</tr>
726
		<?php
727
			//build list of schedules
728
			$schedules = array();
729
			$schedules[] = "none";//leave none to leave rule enabled all the time
730
			if(is_array($config['schedules']['schedule'])) {
731
				foreach ($config['schedules']['schedule'] as $schedule) {
732
					if ($schedule['name'] <> "")
733
						$schedules[] = $schedule['name'];
734
				}
735
			}
736
		?>
737
		<tr>
738
			<td width="22%" valign="top" class="vncell">Schedule</td>
739
			<td width="78%" class="vtable">
740
				<select name='sched'>
741
<?php
742
				foreach($schedules as $schedule) {
743
					if($schedule == $pconfig['sched']) {
744
						$selected = " SELECTED";
745
					} else {
746
						$selected = "";
747
					}
748
					if ($schedule == "none") {
749
						echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
750
					} else {
751
						echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
752
					}
753
				}?>
754
				</select>
755
				<p>Leave as 'none' to leave the rule enabled all the time.</p>
756
				<strong>NOTE:  schedule logic can be a bit different.  Click <a target="_new" href='firewall_rules_schedule_logic.php'>here</a> for more information.</strong>
757
			</td>
758
		</tr>
759
		
760
<?php
761
			/* build a list of gateways */
762
			$gateways = array();
763
			$gateways[] = "default"; // default to don't use this feature :)
764
			foreach($config['interfaces'] as $int) {
765
				if($int['gateway'] <> "")
766
					$gateways[]=$int['gateway'];
767
			}
768
?>
769
		<tr>
770
			<td width="22%" valign="top" class="vncell">Gateway</td>
771
			<td width="78%" class="vtable">
772
				<select name='gateway'>
773
<?php
774
				foreach($gateways as $gw) {
775
					if($gw == "") 
776
						continue;
777
					if($gw == $pconfig['gateway']) {
778
						$selected = " SELECTED";
779
					} else {
780
						$selected = "";
781
					}
782
					if ($gw == "default") {
783
						echo "<option value=\"\" {$selected}>{$gw}</option>\n";
784
					} else {
785
						echo "<option value=\"{$gw}\" {$selected}>{$gw}</option>\n";
786
					}
787
				}
788
				if(is_array($config['load_balancer']['lbpool'])) {
789
					foreach($config['load_balancer']['lbpool'] as $lb) {
790
						if($lb['name'] == "") 
791
							continue;
792
						if($pconfig['gateway'] == $lb['name']) {
793
							echo "<option value=\"{$lb['name']}\" SELECTED>{$lb['name']}</option>\n";
794
						} else {
795
							echo "<option value=\"{$lb['name']}\">{$lb['name']}</option>\n";
796
						}
797
					}
798
				}
799
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
800
					if($config['interfaces']['opt' . $i]['ipaddr'] == "dhcp") {
801
						$descr = $config['interfaces']['opt' . $i]['descr'];
802
						if ($pconfig['gateway'] == "opt{$i}") {
803
							$selected = " SELECTED";
804
						} else {
805
							$selected = "";
806
						}
807
						if($descr <> "") 
808
							echo "<option value=\"opt{$i}\" {$selected}>OPT{$i} - {$descr}</option>\n";
809
					}
810
				}
811
?>
812
				</select>
813
				<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
814
			</td>
815
		</tr>
816
		<tr>
817
			<td width="22%" valign="top" class="vncell">Description</td>
818
			<td width="78%" class="vtable">
819
				<input name="descr" type="text" class="formfld" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
820
				<br />
821
				<span class="vexpl">You may enter a description here for your reference (not parsed).</span>
822
			</td>
823
		</tr>
824
		<tr>
825
			<td width="22%" valign="top">&nbsp;</td>
826
			<td width="78%">
827
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
828
<?php			if (isset($id) && $a_filter[$id]): ?>
829
					<input name="id" type="hidden" value="<?=$id;?>">
830
<?php 			endif; ?>
831
				<input name="after" type="hidden" value="<?=$after;?>">
832
			</td>
833
		</tr>
834
	</table>
835
</form>
836
<script language="JavaScript">
837
<!--
838
	ext_change();
839
	typesel_change();
840
	proto_change();
841

    
842
<?php
843
	$isfirst = 0;
844
	$aliases = "";
845
	$addrisfirst = 0;
846
	$aliasesaddr = "";
847
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
848
		foreach($config['aliases']['alias'] as $alias_name) {
849
			if(!stristr($alias_name['address'], ".")) {
850
				if($isfirst == 1) $aliases .= ",";
851
				$aliases .= "'" . $alias_name['name'] . "'";
852
				$isfirst = 1;
853
			} else {
854
				if($addrisfirst == 1) $aliasesaddr .= ",";
855
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
856
				$addrisfirst = 1;
857
			}
858
		}
859
?>
860

    
861
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
862
	var customarray=new Array(<?php echo $aliases; ?>);
863

    
864
//-->
865
</script>
866

    
867

    
868
<?php include("fend.inc"); ?>
869
</body>
870
</html>
871

    
(50-50/173)