Project

General

Profile

Download (30.1 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	firewall_rules_edit.php
6
	part of pfSense (http://www.pfsense.com)
7
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
8

    
9
	originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34

    
35
require("guiconfig.inc");
36

    
37
$specialsrcdst = explode(" ", "any lan pptp pppoe");
38

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

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

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

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

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

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

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

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

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

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

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

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

    
86
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
87
	$pconfig['log'] = isset($a_filter[$id]['log']);
88
	$pconfig['descr'] = $a_filter[$id]['descr'];
89
	
90
	/* advanced */
91
        $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
92
        $pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
93
        $pconfig['statetype'] = $a_filter[$id]['statetype'];
94
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
95
	
96
	/* advanced - new connection per second banning*/
97
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
98
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
99

    
100
	/* Multi-WAN next-hop support */
101
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
102

    
103
} else {
104
	/* defaults */
105
	if ($_GET['if'])
106
		$pconfig['interface'] = $_GET['if'];
107
	$pconfig['type'] = "pass";
108
	$pconfig['src'] = "any";
109
	$pconfig['dst'] = "any";
110
}
111

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

    
115
if ($_POST) {
116

    
117
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
118
		$_POST['srcbeginport'] = 0;
119
		$_POST['srcendport'] = 0;
120
		$_POST['dstbeginport'] = 0;
121
		$_POST['dstendport'] = 0;
122
	} else {
123

    
124
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
125
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
126
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
127
			$_POST['srcendport'] = $_POST['srcendport_cust'];
128

    
129
		if ($_POST['srcbeginport'] == "any") {
130
			$_POST['srcbeginport'] = 0;
131
			$_POST['srcendport'] = 0;
132
		} else {
133
			if (!$_POST['srcendport'])
134
				$_POST['srcendport'] = $_POST['srcbeginport'];
135
		}
136
		if ($_POST['srcendport'] == "any")
137
			$_POST['srcendport'] = $_POST['srcbeginport'];
138

    
139
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
140
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
141
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
142
			$_POST['dstendport'] = $_POST['dstendport_cust'];
143

    
144
		if ($_POST['dstbeginport'] == "any") {
145
			$_POST['dstbeginport'] = 0;
146
			$_POST['dstendport'] = 0;
147
		} else {
148
			if (!$_POST['dstendport'])
149
				$_POST['dstendport'] = $_POST['dstbeginport'];
150
		}
151
		if ($_POST['dstendport'] == "any")
152
			$_POST['dstendport'] = $_POST['dstbeginport'];
153
	}
154

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

    
168
	unset($input_errors);
169
	$pconfig = $_POST;
170

    
171
	/* input validation */
172
	$reqdfields = explode(" ", "type interface proto src dst");
173
	$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
174

    
175

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

    
183

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

    
193
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
194

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

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

    
217
	if (!is_specialnet($_POST['srctype'])) {
218
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
219
			$input_errors[] = "A valid source IP address or alias must be specified.";
220
		}
221
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
222
			$input_errors[] = "A valid source bit count must be specified.";
223
		}
224
	}
225
	if (!is_specialnet($_POST['dsttype'])) {
226
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
227
			$input_errors[] = "A valid destination IP address or alias must be specified.";
228
		}
229
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
230
			$input_errors[] = "A valid destination bit count must be specified.";
231
		}
232
	}
233

    
234
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
235
		/* swap */
236
		$tmp = $_POST['srcendport'];
237
		$_POST['srcendport'] = $_POST['srcbeginport'];
238
		$_POST['srcbeginport'] = $tmp;
239
	}
240
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
241
		/* swap */
242
		$tmp = $_POST['dstendport'];
243
		$_POST['dstendport'] = $_POST['dstbeginport'];
244
		$_POST['dstbeginport'] = $tmp;
245
	}
246
	if ($_POST['os'])
247
		if( $_POST['proto'] != "tcp" )
248
			$input_errors[] = "OS detection is only valid with protocol tcp.";
249

    
250
	if (!$input_errors) {
251
		$filterent = array();
252
		$filterent['type'] = $_POST['type'];
253
		$filterent['interface'] = $_POST['interface'];
254

    
255
		/* Advanced options */
256
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
257
		$filterent['max-src-states'] = $_POST['max-src-states'];
258
		$filterent['statetimeout'] = $_POST['statetimeout'];
259
		$filterent['statetype'] = $_POST['statetype'];
260
		$filterent['os'] = $_POST['os'];
261
		$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
262
		$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
263

    
264
		if ($_POST['proto'] != "any")
265
			$filterent['protocol'] = $_POST['proto'];
266
		else
267
			unset($filterent['protocol']);
268

    
269
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
270
			$filterent['icmptype'] = $_POST['icmptype'];
271
		else
272
			unset($filterent['icmptype']);
273

    
274
		pconfig_to_address($filterent['source'], $_POST['src'],
275
			$_POST['srcmask'], $_POST['srcnot'],
276
			$_POST['srcbeginport'], $_POST['srcendport']);
277

    
278
		pconfig_to_address($filterent['destination'], $_POST['dst'],
279
			$_POST['dstmask'], $_POST['dstnot'],
280
			$_POST['dstbeginport'], $_POST['dstendport']);
281

    
282
                if ($_POST['disabled'])
283
                        $filterent['disabled'] = true;
284
                else
285
                        unset($filterent['disabled']);
286
                if ($_POST['log'])
287
                        $filterent['log'] = true;
288
                else
289
                        unset($filterent['log']);
290
		strncpy($filterent['descr'], $_POST['descr'], 52);
291

    
292
		if ($_POST['gateway'] != "") {
293
			$filterent['gateway'] = $_POST['gateway'];
294
		}
295

    
296
		if (isset($id) && $a_filter[$id])
297
			$a_filter[$id] = $filterent;
298
		else {
299
			if (is_numeric($after))
300
				array_splice($a_filter, $after+1, 0, array($filterent));
301
			else
302
				$a_filter[] = $filterent;
303
		}
304

    
305
		write_config();
306
		touch($d_filterconfdirty_path);
307

    
308
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
309
		exit;
310
	}
311
}
312

    
313
$pgtitle = "Firewall: Rules: Edit";
314
$closehead = false;
315

    
316
$page_filename = "firewall_rules_edit.php";
317
include("head.inc");
318

    
319
?>
320

    
321
</head>
322

    
323
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
324
<?php include("fbegin.inc"); ?>
325
<p class="pgtitle"><?=$pgtitle?></p>
326
<?php if ($input_errors) print_input_errors($input_errors); ?>
327

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

    
412
				foreach ($icmptypes as $icmptype => $descr): ?>
413
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
414
<?php 			endforeach; ?>
415
			</select>
416
			<br />
417
			<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span>
418
		</td>
419
		</tr>
420
		<tr>
421
			<td width="22%" valign="top" class="vncellreq">Source</td>
422
			<td width="78%" class="vtable">
423
				<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
424
				<strong>not</strong>
425
				<br />
426
				Use this option to invert the sense of the match.
427
				<br />
428
				<br />
429
				<table border="0" cellspacing="0" cellpadding="0">
430
					<tr>
431
						<td>Type:&nbsp;&nbsp;</td>
432
						<td>
433
							<select name="srctype" class="formfld" onChange="typesel_change()">
434
<?php
435
								$sel = is_specialnet($pconfig['src']); ?>
436
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
437
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
438
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
439
								<option value="lan"     <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
440
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
441
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>			    
442
<?php
443
								for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
444
									<option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>><?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
445
<?php 							endfor; ?>
446
							</select>
447
						</td>
448
					</tr>
449
					<tr>
450
						<td>Address:&nbsp;&nbsp;</td>
451
						<td>
452
							<input autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
453
							<select name="srcmask" class="formfld" id="srcmask">
454
<?php						for ($i = 31; $i > 0; $i--): ?>
455
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
456
<?php 						endfor; ?>
457
							</select>
458
						</td>
459
					</tr>
460
				</table>
461
			</td>
462
		</tr>
463
		<tr>
464
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
465
			<td width="78%" class="vtable">
466
				<table border="0" cellspacing="0" cellpadding="0">
467
					<tr>
468
						<td>from:&nbsp;&nbsp;</td>
469
						<td>
470
							<select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
471
								<option value="">(other)</option>
472
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
473
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
474
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
475
<?php 							endforeach; ?>
476
							</select> 
477
							<input autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
478
						</td>
479
					</tr>
480
					<tr>
481
						<td>to:</td>
482
						<td>
483
							<select name="srcendport" class="formfld" onchange="ext_change()">
484
								<option value="">(other)</option>
485
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
486
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
487
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
488
<?php							endforeach; ?>
489
							</select> 
490
							<input autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
491
						</td>
492
					</tr>
493
				</table>
494
				<br />
495
				<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>
496
			</td>
497
		</tr>		
498
		<tr>
499
			<td width="22%" valign="top" class="vncellreq">Source OS</td>
500
			<td width="78%" class="vtable">OS Type:&nbsp;
501
				<select name="os" id="os" class="formfld">
502
<?php
503
		           $ostypes = array(
504
						 "" => "any",
505
		                 "AIX" => "AIX",
506
		                 "Linux" => "Linux",
507
		                 "FreeBSD" => "FreeBSD",
508
		                 "NetBSD" => "NetBSD",
509
		                 "OpenBSD" => "OpenBSD",
510
		                 "Solaris" => "Solaris",
511
		                 "MacOS" => "MacOS",
512
		                 "Windows" => "Windows",
513
		                 "Novell" => "Novell"
514
		           );
515

    
516
					foreach ($ostypes as $ostype => $descr): ?>
517
						<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
518
<?php				endforeach; ?>
519
				</select>
520
				<br />
521
				Note: this only works for TCP rules
522
			</td>
523
		</tr>
524
		<tr>
525
			<td width="22%" valign="top" class="vncellreq">Destination</td>
526
			<td width="78%" class="vtable">
527
				<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
528
				<strong>not</strong>
529
					<br />
530
				Use this option to invert the sense of the match.
531
					<br />
532
					<br />
533
				<table border="0" cellspacing="0" cellpadding="0">
534
					<tr>
535
						<td>Type:&nbsp;&nbsp;</td>
536
						<td>
537
							<select name="dsttype" class="formfld" onChange="typesel_change()">
538
<?php
539
								$sel = is_specialnet($pconfig['dst']); ?>
540
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
541
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
542
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
543
								<option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
544
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
545
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
546
<?php 							for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
547
									<option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>><?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
548
<?php 							endfor; ?>
549
							</select>
550
						</td>
551
					</tr>
552
					<tr>
553
						<td>Address:&nbsp;&nbsp;</td>
554
						<td>
555
							<input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
556
							/
557
							<select name="dstmask" class="formfld" id="dstmask">
558
<?php
559
							for ($i = 31; $i > 0; $i--): ?>
560
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
561
<?php						endfor; ?>
562
							</select>
563
						</td>
564
					</tr>
565
				</table>
566

    
567
			</td>
568
		</tr>
569
		<tr>
570
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
571
			<td width="78%" class="vtable">
572
				<table border="0" cellspacing="0" cellpadding="0">
573
					<tr>
574
						<td>from:&nbsp;&nbsp;</td>
575
						<td>
576
							<select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
577
								<option value="">(other)</option>
578
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
579
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
580
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
581
<?php 							endforeach; ?>
582
							</select>
583
							<input autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>">
584
						</td>
585
					</tr>
586
					<tr>
587
						<td>to:</td>
588
						<td>
589
							<select name="dstendport" class="formfld" onchange="ext_change()">
590
								<option value="">(other)</option>
591
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
592
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
593
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
594
<?php 							endforeach; ?>
595
							</select> 
596
							<input autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>">
597
						</td>
598
					</tr>
599
				</table>
600
				<br />
601
				<span class="vexpl">
602
					Specify the port or port range for the destination of the packet for this rule.
603
						<br />
604
					Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port
605
				</span>
606
			</td>
607
		</tr>
608
		<tr>
609
			<td width="22%" valign="top" class="vncellreq">Log</td>
610
			<td width="78%" class="vtable">
611
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
612
				<strong>Log packets that are handled by this rule</strong>
613
					<br />
614
				<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>
615
			</td>
616
		</tr>
617
		<tr>
618
			<td width="22%" valign="top" class="vncell">Description</td>
619
			<td width="78%" class="vtable">
620
				<input name="descr" type="text" class="formfld" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
621
				<br />
622
				<span class="vexpl">You may enter a description here for your reference (not parsed).</span>
623
			</td>
624
		</tr>
625
		<tr>
626
			<td width="22%" valign="top" class="vncell">Advanced Options</td>
627
			<td width="78%" class="vtable">
628
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
629
				<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
630
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
631
				<select name="max-src-conn-rates" id="max-src-conn-rates">
632
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
633
<?php				for($x=1; $x<255; $x++) {
634
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
635
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
636
					} ?>
637
				</select>
638
				<br />
639
				Maximum new connections / per second
640
				<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
641
			</td>
642
		</tr>
643
		<tr>
644
			<td width="22%" valign="top" class="vncell">State Type</td>
645
			<td width="78%" class="vtable">
646
				<select name="statetype">
647
					<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
648
					<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
649
					<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
650
					<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
651
				</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
652
				<p><strong>
653
				<table>
654
					<tr><td width="25%"><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</td></tr>
655
					<tr><td width="25%"><li>modulate state</li></td><td>works only with TCP. pfSense will generate strong Initial Sequence Numbers (ISNs) for packets matching this rule.</li></td></tr>
656
					<tr><td width="25%"><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.</td></tr>
657
					<tr><td width="25%"><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.</td></tr>
658
				</table>
659
				</strong></p>
660
			</td>
661
		</tr>
662
		<tr>
663
			<td width="22%" valign="top" class="vncell">State Timeout</td>
664
			<td width="78%" class="vtable">
665
				<input name="statetimeout" value="<?php echo $pconfig['frags'] ?>">
666
				<p><strong>Leave blank for default.  Amount is in seconds.</strong></p>
667
			</td>
668
		</tr>
669
<?php
670
			/* build a list of gateways */
671
			$gateways = array();
672
                        $gateways[] = "default"; // default to don't use this feature :)
673
			foreach($config['interfaces'] as $int) {
674
				if($int['gateway'] <> "")
675
					$gateways[]=$int['gateway'];
676
			}
677
?>
678
		<tr>
679
			<td width="22%" valign="top" class="vncell">Gateway</td>
680
			<td width="78%" class="vtable">
681
				<select name='gateway'>
682
<?php
683
				foreach($gateways as $gw) {
684
					if($gw == $pconfig['gateway']) {
685
						$selected = " SELECTED";
686
					} else {
687
						$selected = "";
688
					}
689
					if ($gw == "default") {
690
						echo "<option value=\"\" {$selected}>{$gw}</option>\n";	
691
					} else {
692
						echo "<option value=\"{$gw}\" {$selected}>{$gw}</option>\n";
693
					}
694
				}
695
				foreach($config['load_balancer']['lbpool'] as $lb) {
696
					if($pconfig['gateway'] == $lb['name']) {
697
						echo "<option value=\"{$lb['name']}\" SELECTED>{$lb['name']}</option>\n";
698
					} else {
699
						echo "<option value=\"{$lb['name']}\">{$lb['name']}</option>\n";
700
					}		
701
				}
702
				for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
703
					if($config['interfaces']['opt' . $i]['ipaddr'] == "dhcp") {
704
						$descr = $config['interfaces']['opt' . $i]['descr'];
705
						if ($pconfig['gateway'] == "opt{$i}") {
706
							$selected = " SELECTED";
707
						} else {
708
							$selected = "";
709
						}
710
						echo "<option value=\"opt{$i}\" {$selected}>OPT{$i} - {$descr}</option>\n";
711
					}
712
				}
713
?>
714
				</select>
715
				<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
716
			</td>
717
		</tr>
718
		<tr>
719
			<td width="22%" valign="top">&nbsp;</td>
720
			<td width="78%">
721
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
722
<?php			if (isset($id) && $a_filter[$id]): ?>
723
					<input name="id" type="hidden" value="<?=$id;?>">
724
<?php 			endif; ?>
725
				<input name="after" type="hidden" value="<?=$after;?>">
726
			</td>
727
		</tr>
728
	</table>
729
</form>
730
<script language="JavaScript">
731
<!--
732
	ext_change();
733
	typesel_change();
734
	proto_change();
735

    
736
<?php
737
	$isfirst = 0;
738
	$aliases = "";
739
	$addrisfirst = 0;
740
	$aliasesaddr = "";
741
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
742
		foreach($config['aliases']['alias'] as $alias_name) {
743
			if(!stristr($alias_name['address'], ".")) {
744
				if($isfirst == 1) $aliases .= ",";
745
				$aliases .= "'" . $alias_name['name'] . "'";
746
				$isfirst = 1;
747
			} else {
748
				if($addrisfirst == 1) $aliasesaddr .= ",";
749
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
750
				$addrisfirst = 1;
751
			}
752
		}
753
?>
754

    
755
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
756
	var customarray=new Array(<?php echo $aliases; ?>);
757

    
758
//-->
759
</script>
760

    
761

    
762
<?php include("fend.inc"); ?>
763
</body>
764
</html>
765

    
(44-44/146)