Project

General

Profile

Download (31.2 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 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="lan"     <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
454
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
455
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>			    
456
<?php
457
								for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
458
									<option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>><?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
459
<?php 							endfor; ?>
460
							</select>
461
						</td>
462
					</tr>
463
					<tr>
464
						<td>Address:&nbsp;&nbsp;</td>
465
						<td>
466
							<input autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
467
							<select name="srcmask" class="formfld" id="srcmask">
468
<?php						for ($i = 31; $i > 0; $i--): ?>
469
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
470
<?php 						endfor; ?>
471
							</select>
472
						</td>
473
					</tr>
474
				</table>
475
			</td>
476
		</tr>
477
		<tr>
478
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
479
			<td width="78%" class="vtable">
480
				<table border="0" cellspacing="0" cellpadding="0">
481
					<tr>
482
						<td>from:&nbsp;&nbsp;</td>
483
						<td>
484
							<select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
485
								<option value="">(other)</option>
486
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
487
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
488
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
489
<?php 							endforeach; ?>
490
							</select> 
491
							<input autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
492
						</td>
493
					</tr>
494
					<tr>
495
						<td>to:</td>
496
						<td>
497
							<select name="srcendport" class="formfld" onchange="ext_change()">
498
								<option value="">(other)</option>
499
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
500
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
501
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
502
<?php							endforeach; ?>
503
							</select> 
504
							<input autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
505
						</td>
506
					</tr>
507
				</table>
508
				<br />
509
				<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/>
510
				<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>
511
			</td>
512
		</tr>		
513
		<tr>
514
			<td width="22%" valign="top" class="vncellreq">Source OS</td>
515
			<td width="78%" class="vtable">OS Type:&nbsp;
516
				<select name="os" id="os" class="formfld">
517
<?php
518
		           $ostypes = array(
519
						 "" => "any",
520
		                 "AIX" => "AIX",
521
		                 "Linux" => "Linux",
522
		                 "FreeBSD" => "FreeBSD",
523
		                 "NetBSD" => "NetBSD",
524
		                 "OpenBSD" => "OpenBSD",
525
		                 "Solaris" => "Solaris",
526
		                 "MacOS" => "MacOS",
527
		                 "Windows" => "Windows",
528
		                 "Novell" => "Novell"
529
		           );
530

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

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

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

    
778
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
779
	var customarray=new Array(<?php echo $aliases; ?>);
780

    
781
//-->
782
</script>
783

    
784

    
785
<?php include("fend.inc"); ?>
786
</body>
787
</html>
788

    
(46-46/159)