Project

General

Profile

Download (33 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
} else {
105
	/* defaults */
106
	if ($_GET['if'])
107
		$pconfig['interface'] = $_GET['if'];
108
	$pconfig['type'] = "pass";
109
	$pconfig['src'] = "any";
110
	$pconfig['dst'] = "any";
111
}
112

    
113
if (isset($_GET['dup']))
114
	unset($id);
115

    
116
if ($_POST) {
117

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

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

    
128
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
129
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
130
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
131
			$_POST['srcendport'] = $_POST['srcendport_cust'];
132

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

    
143
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
144
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
145
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
146
			$_POST['dstendport'] = $_POST['dstendport_cust'];
147

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

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

    
172
	unset($input_errors);
173
	$pconfig = $_POST;
174

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

    
179

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

    
187

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

    
197
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
198

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

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

    
221
	/* if user enters an alias and selects "network" then disallow. */
222
	if($_POST['srctype'] == "network") {
223
		if(is_alias($_POST['src']))
224
			$input_errors[] = "You must specify single host or alias for alias entries.";
225
	}
226
	if($_POST['dsttype'] == "network") {
227
		if(is_alias($_POST['dst']))
228
			$input_errors[] = "You must specify single host or alias for alias entries.";
229
	}
230

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

    
248
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
249
		/* swap */
250
		$tmp = $_POST['srcendport'];
251
		$_POST['srcendport'] = $_POST['srcbeginport'];
252
		$_POST['srcbeginport'] = $tmp;
253
	}
254
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
255
		/* swap */
256
		$tmp = $_POST['dstendport'];
257
		$_POST['dstendport'] = $_POST['dstbeginport'];
258
		$_POST['dstbeginport'] = $tmp;
259
	}
260
	if ($_POST['os'])
261
		if( $_POST['proto'] != "tcp" )
262
			$input_errors[] = "OS detection is only valid with protocol tcp.";
263

    
264
	if (!$input_errors) {
265
		$filterent = array();
266
		$filterent['type'] = $_POST['type'];
267
		$filterent['interface'] = $_POST['interface'];
268

    
269
		/* Advanced options */
270
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
271
		$filterent['max-src-states'] = $_POST['max-src-states'];
272
		$filterent['statetimeout'] = $_POST['statetimeout'];
273
		$filterent['statetype'] = $_POST['statetype'];
274
		$filterent['os'] = $_POST['os'];
275

    
276
		/* Nosync directive - do not xmlrpc sync this item */
277
		if($_POST['nosync'] <> "")
278
			$filterent['nosync'] = true;
279
		else
280
			unset($filterent['nosync']);
281

    
282
		/* unless both values are provided, unset the values - ticket #650 */
283
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
284
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
285
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
286
		} else {
287
			unset($filterent['max-src-conn-rate']);
288
			unset($filterent['max-src-conn-rates']);
289
		}
290

    
291
		if ($_POST['proto'] != "any")
292
			$filterent['protocol'] = $_POST['proto'];
293
		else
294
			unset($filterent['protocol']);
295

    
296
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
297
			$filterent['icmptype'] = $_POST['icmptype'];
298
		else
299
			unset($filterent['icmptype']);
300

    
301
		pconfig_to_address($filterent['source'], $_POST['src'],
302
			$_POST['srcmask'], $_POST['srcnot'],
303
			$_POST['srcbeginport'], $_POST['srcendport']);
304

    
305
		pconfig_to_address($filterent['destination'], $_POST['dst'],
306
			$_POST['dstmask'], $_POST['dstnot'],
307
			$_POST['dstbeginport'], $_POST['dstendport']);
308

    
309
                if ($_POST['disabled'])
310
                        $filterent['disabled'] = true;
311
                else
312
                        unset($filterent['disabled']);
313
                if ($_POST['log'])
314
                        $filterent['log'] = true;
315
                else
316
                        unset($filterent['log']);
317
		strncpy($filterent['descr'], $_POST['descr'], 52);
318

    
319
		if ($_POST['gateway'] != "") {
320
			$filterent['gateway'] = $_POST['gateway'];
321
		}
322

    
323
		if (isset($id) && $a_filter[$id])
324
			$a_filter[$id] = $filterent;
325
		else {
326
			if (is_numeric($after))
327
				array_splice($a_filter, $after+1, 0, array($filterent));
328
			else
329
				$a_filter[] = $filterent;
330
		}
331

    
332
		write_config();
333
		touch($d_filterconfdirty_path);
334

    
335
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
336
		exit;
337
	}
338
}
339

    
340
$pgtitle = "Firewall: Rules: Edit";
341
$closehead = false;
342

    
343
$page_filename = "firewall_rules_edit.php";
344
include("head.inc");
345

    
346
?>
347

    
348
</head>
349

    
350
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
351
<?php include("fbegin.inc"); ?>
352
<p class="pgtitle"><?=$pgtitle?></p>
353
<?php if ($input_errors) print_input_errors($input_errors); ?>
354

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

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

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

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

    
679
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
680
				State Timeout in seconds
681
				<p />
682

    
683
				<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
684
			  </div>
685
			</td>
686
		</tr>
687
		<tr>
688
			<td width="22%" valign="top" class="vncell">State Type</td>
689
			<td width="78%" class="vtable">
690
				<div id="showadvstatebox">
691
					<input type="button" onClick="show_advanced_state()" value="Advanced"></input> - Show state</a>
692
				</div>
693
				<div id="showstateadv" style="display:none">
694
					<select name="statetype">
695
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
696
						<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
697
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
698
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
699
					</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
700
					<p>
701
					<table width="90%">
702
						<tr><td width="25%"><ul><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</ul></td></tr>
703
						<tr><td width="25%"><ul><li>modulate state</li></td><td>works only with TCP. pfSense will generate strong Initial Sequence Numbers (ISNs) for packets matching this rule.</li></ul></td></tr>
704
						<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>
705
						<tr><td width="25%"><ul><li>none</li></td><td>do not use state mechanisms to keep track.  this is only useful if your doing advanced queueing in certain situations.  please check the faq.</ul></td></tr>
706
					</table>
707
					</p>
708
			  </div>
709
			</td>
710
		</tr>
711
		<tr>
712
			<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
713
			<td width="78%" class="vtable">
714
				<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
715
				HINT: This prevents the rule from automatically syncing to other carp members.
716
			</td>
717
		</tr>
718
<?php
719
			/* build a list of gateways */
720
			$gateways = array();
721
                        $gateways[] = "default"; // default to don't use this feature :)
722
			foreach($config['interfaces'] as $int) {
723
				if($int['gateway'] <> "")
724
					$gateways[]=$int['gateway'];
725
			}
726
?>
727
		<tr>
728
			<td width="22%" valign="top" class="vncell">Gateway</td>
729
			<td width="78%" class="vtable">
730
				<select name='gateway'>
731
<?php
732
				foreach($gateways as $gw) {
733
					if($gw == $pconfig['gateway']) {
734
						$selected = " SELECTED";
735
					} else {
736
						$selected = "";
737
					}
738
					if ($gw == "default") {
739
						echo "<option value=\"\" {$selected}>{$gw}</option>\n";
740
					} else {
741
						echo "<option value=\"{$gw}\" {$selected}>{$gw}</option>\n";
742
					}
743
				}
744
				if(is_array($config['load_balancer']['lbpool'])) {
745
					foreach($config['load_balancer']['lbpool'] as $lb) {
746
						if($pconfig['gateway'] == $lb['name']) {
747
							echo "<option value=\"{$lb['name']}\" SELECTED>{$lb['name']}</option>\n";
748
						} else {
749
							echo "<option value=\"{$lb['name']}\">{$lb['name']}</option>\n";
750
						}
751
					}
752
				}
753
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
754
					if($config['interfaces']['opt' . $i]['ipaddr'] == "dhcp") {
755
						$descr = $config['interfaces']['opt' . $i]['descr'];
756
						if ($pconfig['gateway'] == "opt{$i}") {
757
							$selected = " SELECTED";
758
						} else {
759
							$selected = "";
760
						}
761
						echo "<option value=\"opt{$i}\" {$selected}>OPT{$i} - {$descr}</option>\n";
762
					}
763
				}
764
?>
765
				</select>
766
				<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
767
			</td>
768
		</tr>
769
		<tr>
770
			<td width="22%" valign="top" class="vncell">Description</td>
771
			<td width="78%" class="vtable">
772
				<input name="descr" type="text" class="formfld" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
773
				<br />
774
				<span class="vexpl">You may enter a description here for your reference (not parsed).</span>
775
			</td>
776
		</tr>
777
		<tr>
778
			<td width="22%" valign="top">&nbsp;</td>
779
			<td width="78%">
780
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
781
<?php			if (isset($id) && $a_filter[$id]): ?>
782
					<input name="id" type="hidden" value="<?=$id;?>">
783
<?php 			endif; ?>
784
				<input name="after" type="hidden" value="<?=$after;?>">
785
			</td>
786
		</tr>
787
	</table>
788
</form>
789
<script language="JavaScript">
790
<!--
791
	ext_change();
792
	typesel_change();
793
	proto_change();
794

    
795
<?php
796
	$isfirst = 0;
797
	$aliases = "";
798
	$addrisfirst = 0;
799
	$aliasesaddr = "";
800
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
801
		foreach($config['aliases']['alias'] as $alias_name) {
802
			if(!stristr($alias_name['address'], ".")) {
803
				if($isfirst == 1) $aliases .= ",";
804
				$aliases .= "'" . $alias_name['name'] . "'";
805
				$isfirst = 1;
806
			} else {
807
				if($addrisfirst == 1) $aliasesaddr .= ",";
808
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
809
				$addrisfirst = 1;
810
			}
811
		}
812
?>
813

    
814
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
815
	var customarray=new Array(<?php echo $aliases; ?>);
816

    
817
//-->
818
</script>
819

    
820

    
821
<?php include("fend.inc"); ?>
822
</body>
823
</html>
824

    
(49-49/167)