Project

General

Profile

Download (30.7 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 wanip 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
		
262
		/* unless both values are provided, unset the values - ticket #650 */
263
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
264
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
265
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
266
		} else {
267
			unset($filterent['max-src-conn-rate']);
268
			unset($filterent['max-src-conn-rates']);
269
		}
270

    
271
		if ($_POST['proto'] != "any")
272
			$filterent['protocol'] = $_POST['proto'];
273
		else
274
			unset($filterent['protocol']);
275

    
276
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
277
			$filterent['icmptype'] = $_POST['icmptype'];
278
		else
279
			unset($filterent['icmptype']);
280

    
281
		pconfig_to_address($filterent['source'], $_POST['src'],
282
			$_POST['srcmask'], $_POST['srcnot'],
283
			$_POST['srcbeginport'], $_POST['srcendport']);
284

    
285
		pconfig_to_address($filterent['destination'], $_POST['dst'],
286
			$_POST['dstmask'], $_POST['dstnot'],
287
			$_POST['dstbeginport'], $_POST['dstendport']);
288

    
289
                if ($_POST['disabled'])
290
                        $filterent['disabled'] = true;
291
                else
292
                        unset($filterent['disabled']);
293
                if ($_POST['log'])
294
                        $filterent['log'] = true;
295
                else
296
                        unset($filterent['log']);
297
		strncpy($filterent['descr'], $_POST['descr'], 52);
298

    
299
		if ($_POST['gateway'] != "") {
300
			$filterent['gateway'] = $_POST['gateway'];
301
		}
302

    
303
		if (isset($id) && $a_filter[$id])
304
			$a_filter[$id] = $filterent;
305
		else {
306
			if (is_numeric($after))
307
				array_splice($a_filter, $after+1, 0, array($filterent));
308
			else
309
				$a_filter[] = $filterent;
310
		}
311

    
312
		write_config();
313
		touch($d_filterconfdirty_path);
314

    
315
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
316
		exit;
317
	}
318
}
319

    
320
$pgtitle = "Firewall: Rules: Edit";
321
$closehead = false;
322

    
323
$page_filename = "firewall_rules_edit.php";
324
include("head.inc");
325

    
326
?>
327

    
328
</head>
329

    
330
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
331
<?php include("fbegin.inc"); ?>
332
<p class="pgtitle"><?=$pgtitle?></p>
333
<?php if ($input_errors) print_input_errors($input_errors); ?>
334

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

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

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

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

    
746
<?php
747
	$isfirst = 0;
748
	$aliases = "";
749
	$addrisfirst = 0;
750
	$aliasesaddr = "";
751
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
752
		foreach($config['aliases']['alias'] as $alias_name) {
753
			if(!stristr($alias_name['address'], ".")) {
754
				if($isfirst == 1) $aliases .= ",";
755
				$aliases .= "'" . $alias_name['name'] . "'";
756
				$isfirst = 1;
757
			} else {
758
				if($addrisfirst == 1) $aliasesaddr .= ",";
759
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
760
				$addrisfirst = 1;
761
			}
762
		}
763
?>
764

    
765
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
766
	var customarray=new Array(<?php echo $aliases; ?>);
767

    
768
//-->
769
</script>
770

    
771

    
772
<?php include("fend.inc"); ?>
773
</body>
774
</html>
775

    
(44-44/153)