Project

General

Profile

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

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

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

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

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

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

    
34
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['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
119
		$_POST['srcbeginport'] = 0;
120
		$_POST['srcendport'] = 0;
121
		$_POST['dstbeginport'] = 0;
122
		$_POST['dstendport'] = 0;
123
	} else {
124

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

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

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

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

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

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

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

    
176

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

    
184

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

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

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

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

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

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

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

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

    
263
		/* Nosync directive - do not xmlrpc sync this item */
264
		if($_POST['nosync'] <> "")
265
			$filterent['nosync'] = true;
266
		else
267
			unset($filterent['nosync']);
268

    
269
		/* unless both values are provided, unset the values - ticket #650 */
270
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
271
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
272
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
273
		} else {
274
			unset($filterent['max-src-conn-rate']);
275
			unset($filterent['max-src-conn-rates']);
276
		}
277

    
278
		if ($_POST['proto'] != "any")
279
			$filterent['protocol'] = $_POST['proto'];
280
		else
281
			unset($filterent['protocol']);
282

    
283
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
284
			$filterent['icmptype'] = $_POST['icmptype'];
285
		else
286
			unset($filterent['icmptype']);
287

    
288
		pconfig_to_address($filterent['source'], $_POST['src'],
289
			$_POST['srcmask'], $_POST['srcnot'],
290
			$_POST['srcbeginport'], $_POST['srcendport']);
291

    
292
		pconfig_to_address($filterent['destination'], $_POST['dst'],
293
			$_POST['dstmask'], $_POST['dstnot'],
294
			$_POST['dstbeginport'], $_POST['dstendport']);
295

    
296
                if ($_POST['disabled'])
297
                        $filterent['disabled'] = true;
298
                else
299
                        unset($filterent['disabled']);
300
                if ($_POST['log'])
301
                        $filterent['log'] = true;
302
                else
303
                        unset($filterent['log']);
304
		strncpy($filterent['descr'], $_POST['descr'], 52);
305

    
306
		if ($_POST['gateway'] != "") {
307
			$filterent['gateway'] = $_POST['gateway'];
308
		}
309

    
310
		if (isset($id) && $a_filter[$id])
311
			$a_filter[$id] = $filterent;
312
		else {
313
			if (is_numeric($after))
314
				array_splice($a_filter, $after+1, 0, array($filterent));
315
			else
316
				$a_filter[] = $filterent;
317
		}
318

    
319
		write_config();
320
		touch($d_filterconfdirty_path);
321

    
322
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
323
		exit;
324
	}
325
}
326

    
327
$pgtitle = "Firewall: Rules: Edit";
328
$closehead = false;
329

    
330
$page_filename = "firewall_rules_edit.php";
331
include("head.inc");
332

    
333
?>
334

    
335
</head>
336

    
337
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
338
<?php include("fbegin.inc"); ?>
339
<p class="pgtitle"><?=$pgtitle?></p>
340
<?php if ($input_errors) print_input_errors($input_errors); ?>
341

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

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

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

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

    
765
<?php
766
	$isfirst = 0;
767
	$aliases = "";
768
	$addrisfirst = 0;
769
	$aliasesaddr = "";
770
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
771
		foreach($config['aliases']['alias'] as $alias_name) {
772
			if(!stristr($alias_name['address'], ".")) {
773
				if($isfirst == 1) $aliases .= ",";
774
				$aliases .= "'" . $alias_name['name'] . "'";
775
				$isfirst = 1;
776
			} else {
777
				if($addrisfirst == 1) $aliasesaddr .= ",";
778
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
779
				$addrisfirst = 1;
780
			}
781
		}
782
?>
783

    
784
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
785
	var customarray=new Array(<?php echo $aliases; ?>);
786

    
787
//-->
788
</script>
789

    
790

    
791
<?php include("fend.inc"); ?>
792
</body>
793
</html>
794

    
(47-47/164)