Project

General

Profile

Download (34.8 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 5ba18897 Scott Ullrich
<?php
3 5b237745 Scott Ullrich
/*
4 bdb7d6e7 Scott Ullrich
	firewall_rules_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 5ba18897 Scott Ullrich
7 bdb7d6e7 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 5ba18897 Scott Ullrich
10 bdb7d6e7 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 5ba18897 Scott Ullrich
13 bdb7d6e7 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 5ba18897 Scott Ullrich
16 bdb7d6e7 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19 5ba18897 Scott Ullrich
20 bdb7d6e7 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30 5b237745 Scott Ullrich
*/
31
32
require("guiconfig.inc");
33
34
$specialsrcdst = explode(" ", "any lan pptp");
35
36
if (!is_array($config['filter']['rule'])) {
37
	$config['filter']['rule'] = array();
38
}
39
filter_rules_sort();
40
$a_filter = &$config['filter']['rule'];
41
42
$id = $_GET['id'];
43
if (is_numeric($_POST['id']))
44
	$id = $_POST['id'];
45 5ba18897 Scott Ullrich
46 5b237745 Scott Ullrich
$after = $_GET['after'];
47
48
if (isset($_POST['after']))
49
	$after = $_POST['after'];
50
51
if (isset($_GET['dup'])) {
52
	$id = $_GET['dup'];
53
	$after = $_GET['dup'];
54
}
55
56
function is_specialnet($net) {
57
	global $specialsrcdst;
58 5ba18897 Scott Ullrich
59 5b237745 Scott Ullrich
	if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
60
		return true;
61
	else
62
		return false;
63
}
64
65
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
66 5ba18897 Scott Ullrich
67 5b237745 Scott Ullrich
	if (isset($adr['any']))
68
		$padr = "any";
69
	else if ($adr['network'])
70
		$padr = $adr['network'];
71
	else if ($adr['address']) {
72
		list($padr, $pmask) = explode("/", $adr['address']);
73
		if (!$pmask)
74
			$pmask = 32;
75
	}
76 5ba18897 Scott Ullrich
77 5b237745 Scott Ullrich
	if (isset($adr['not']))
78
		$pnot = 1;
79
	else
80
		$pnot = 0;
81 5ba18897 Scott Ullrich
82 5b237745 Scott Ullrich
	if ($adr['port']) {
83
		list($pbeginport, $pendport) = explode("-", $adr['port']);
84
		if (!$pendport)
85
			$pendport = $pbeginport;
86
	} else {
87 19757279 Scott Ullrich
		if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
88
			/* Item is a port alias */
89
		} else {
90
			$pbeginport = "any";
91
			$pendport = "any";
92
		}
93 5b237745 Scott Ullrich
	}
94
}
95
96
function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) {
97 5ba18897 Scott Ullrich
98 5b237745 Scott Ullrich
	$adr = array();
99 5ba18897 Scott Ullrich
100 5b237745 Scott Ullrich
	if ($padr == "any")
101
		$adr['any'] = true;
102
	else if (is_specialnet($padr))
103
		$adr['network'] = $padr;
104
	else {
105
		$adr['address'] = $padr;
106
		if ($pmask != 32)
107
			$adr['address'] .= "/" . $pmask;
108
	}
109 5ba18897 Scott Ullrich
110 5b237745 Scott Ullrich
	$adr['not'] = $pnot ? true : false;
111 5ba18897 Scott Ullrich
112 5b237745 Scott Ullrich
	if (($pbeginport != 0) && ($pbeginport != "any")) {
113
		if ($pbeginport != $pendport)
114
			$adr['port'] = $pbeginport . "-" . $pendport;
115
		else
116
			$adr['port'] = $pbeginport;
117
	}
118 19757279 Scott Ullrich
119
	if(alias_expand($pbeginport)) {
120
		$adr['port'] = $pbeginport;
121
	}
122 5b237745 Scott Ullrich
}
123
124
if (isset($id) && $a_filter[$id]) {
125
	$pconfig['interface'] = $a_filter[$id]['interface'];
126 5ba18897 Scott Ullrich
127 5b237745 Scott Ullrich
	if (!isset($a_filter[$id]['type']))
128
		$pconfig['type'] = "pass";
129
	else
130
		$pconfig['type'] = $a_filter[$id]['type'];
131 5ba18897 Scott Ullrich
132 5b237745 Scott Ullrich
	if (isset($a_filter[$id]['protocol']))
133
		$pconfig['proto'] = $a_filter[$id]['protocol'];
134
	else
135
		$pconfig['proto'] = "any";
136 5ba18897 Scott Ullrich
137 5b237745 Scott Ullrich
	if ($a_filter[$id]['protocol'] == "icmp")
138
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
139 5ba18897 Scott Ullrich
140 5b237745 Scott Ullrich
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
141
		$pconfig['srcmask'], $pconfig['srcnot'],
142
		$pconfig['srcbeginport'], $pconfig['srcendport']);
143 5ba18897 Scott Ullrich
144 5b237745 Scott Ullrich
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
145
		$pconfig['dstmask'], $pconfig['dstnot'],
146
		$pconfig['dstbeginport'], $pconfig['dstendport']);
147
148
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
149
	$pconfig['log'] = isset($a_filter[$id]['log']);
150
	$pconfig['frags'] = isset($a_filter[$id]['frags']);
151
	$pconfig['descr'] = $a_filter[$id]['descr'];
152 5ba18897 Scott Ullrich
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
153
154 5b237745 Scott Ullrich
} else {
155
	/* defaults */
156 a23d7248 Scott Ullrich
	if ($_GET['if'])
157
		$pconfig['interface'] = $_GET['if'];
158 5b237745 Scott Ullrich
	$pconfig['type'] = "pass";
159
	$pconfig['src'] = "any";
160
	$pconfig['dst'] = "any";
161
}
162
163
if (isset($_GET['dup']))
164
	unset($id);
165
166
if ($_POST) {
167
168
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
169
		$_POST['srcbeginport'] = 0;
170
		$_POST['srcendport'] = 0;
171
		$_POST['dstbeginport'] = 0;
172
		$_POST['dstendport'] = 0;
173
	} else {
174 5ba18897 Scott Ullrich
175 5b237745 Scott Ullrich
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
176
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
177
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
178
			$_POST['srcendport'] = $_POST['srcendport_cust'];
179 5ba18897 Scott Ullrich
180 5b237745 Scott Ullrich
		if ($_POST['srcbeginport'] == "any") {
181
			$_POST['srcbeginport'] = 0;
182
			$_POST['srcendport'] = 0;
183 5ba18897 Scott Ullrich
		} else {
184 5b237745 Scott Ullrich
			if (!$_POST['srcendport'])
185
				$_POST['srcendport'] = $_POST['srcbeginport'];
186
		}
187
		if ($_POST['srcendport'] == "any")
188
			$_POST['srcendport'] = $_POST['srcbeginport'];
189 5ba18897 Scott Ullrich
190 5b237745 Scott Ullrich
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
191
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
192
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
193
			$_POST['dstendport'] = $_POST['dstendport_cust'];
194 5ba18897 Scott Ullrich
195 5b237745 Scott Ullrich
		if ($_POST['dstbeginport'] == "any") {
196
			$_POST['dstbeginport'] = 0;
197
			$_POST['dstendport'] = 0;
198 5ba18897 Scott Ullrich
		} else {
199 5b237745 Scott Ullrich
			if (!$_POST['dstendport'])
200
				$_POST['dstendport'] = $_POST['dstbeginport'];
201
		}
202
		if ($_POST['dstendport'] == "any")
203 5ba18897 Scott Ullrich
			$_POST['dstendport'] = $_POST['dstbeginport'];
204 5b237745 Scott Ullrich
	}
205 5ba18897 Scott Ullrich
206 5b237745 Scott Ullrich
	if (is_specialnet($_POST['srctype'])) {
207
		$_POST['src'] = $_POST['srctype'];
208
		$_POST['srcmask'] = 0;
209
	} else if ($_POST['srctype'] == "single") {
210
		$_POST['srcmask'] = 32;
211
	}
212
	if (is_specialnet($_POST['dsttype'])) {
213
		$_POST['dst'] = $_POST['dsttype'];
214
		$_POST['dstmask'] = 0;
215
	}  else if ($_POST['dsttype'] == "single") {
216
		$_POST['dstmask'] = 32;
217
	}
218 5ba18897 Scott Ullrich
219 5b237745 Scott Ullrich
	unset($input_errors);
220
	$pconfig = $_POST;
221
222
	/* input validation */
223
	$reqdfields = explode(" ", "type interface proto src dst");
224
	$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
225
226 bdb7d6e7 Scott Ullrich
227
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state")
228
		if( $_POST['proto'] == "udp" or $_POST['proto'] == "tcp/udp" or $_POST['proto'] == "icmp")
229
			$input_errors[] = "You cannot select udp or icmp when using modulate state or synproxy state.";
230
231 5ba18897 Scott Ullrich
232 5b237745 Scott Ullrich
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
233
		$reqdfields[] = "srcmask";
234
		$reqdfieldsn[] = "Source bit count";
235
	}
236
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
237
		$reqdfields[] = "dstmask";
238
		$reqdfieldsn[] = "Destination bit count";
239
	}
240 5ba18897 Scott Ullrich
241 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
242 5ba18897 Scott Ullrich
243 5b237745 Scott Ullrich
	if (!$_POST['srcbeginport']) {
244
		$_POST['srcbeginport'] = 0;
245
		$_POST['srcendport'] = 0;
246
	}
247
	if (!$_POST['dstbeginport']) {
248
		$_POST['dstbeginport'] = 0;
249
		$_POST['dstendport'] = 0;
250
	}
251 5ba18897 Scott Ullrich
252 19757279 Scott Ullrich
	if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) {
253 5b237745 Scott Ullrich
		$input_errors[] = "The start source port must be an integer between 1 and 65535.";
254 bdb7d6e7 Scott Ullrich
	}
255 19757279 Scott Ullrich
	if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) {
256 5b237745 Scott Ullrich
		$input_errors[] = "The end source port must be an integer between 1 and 65535.";
257 bdb7d6e7 Scott Ullrich
	}
258 19757279 Scott Ullrich
	if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) {
259 5b237745 Scott Ullrich
		$input_errors[] = "The start destination port must be an integer between 1 and 65535.";
260 bdb7d6e7 Scott Ullrich
	}
261 19757279 Scott Ullrich
	if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) {
262 5b237745 Scott Ullrich
		$input_errors[] = "The end destination port must be an integer between 1 and 65535.";
263 bdb7d6e7 Scott Ullrich
	}
264 5ba18897 Scott Ullrich
265 5b237745 Scott Ullrich
	if (!is_specialnet($_POST['srctype'])) {
266
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
267
			$input_errors[] = "A valid source IP address or alias must be specified.";
268
		}
269
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
270
			$input_errors[] = "A valid source bit count must be specified.";
271
		}
272
	}
273
	if (!is_specialnet($_POST['dsttype'])) {
274
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
275
			$input_errors[] = "A valid destination IP address or alias must be specified.";
276
		}
277
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
278
			$input_errors[] = "A valid destination bit count must be specified.";
279
		}
280
	}
281 5ba18897 Scott Ullrich
282 5b237745 Scott Ullrich
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
283
		/* swap */
284
		$tmp = $_POST['srcendport'];
285
		$_POST['srcendport'] = $_POST['srcbeginport'];
286
		$_POST['srcbeginport'] = $tmp;
287
	}
288
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
289
		/* swap */
290
		$tmp = $_POST['dstendport'];
291
		$_POST['dstendport'] = $_POST['dstbeginport'];
292
		$_POST['dstbeginport'] = $tmp;
293
	}
294
295
	if (!$input_errors) {
296
		$filterent = array();
297
		$filterent['type'] = $_POST['type'];
298
		$filterent['interface'] = $_POST['interface'];
299 d59874c1 Scott Ullrich
300 bdb7d6e7 Scott Ullrich
		/* Advanced options */
301
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
302
		$filterent['max-src-states'] = $_POST['max-src-states'];
303 5ba18897 Scott Ullrich
		$filterent['statetimeout'] = $_POST['statetimeout'];
304
305 5b237745 Scott Ullrich
		if ($_POST['proto'] != "any")
306
			$filterent['protocol'] = $_POST['proto'];
307
		else
308
			unset($filterent['protocol']);
309 5ba18897 Scott Ullrich
310 5b237745 Scott Ullrich
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
311
			$filterent['icmptype'] = $_POST['icmptype'];
312
		else
313
			unset($filterent['icmptype']);
314 5ba18897 Scott Ullrich
315 5b237745 Scott Ullrich
		pconfig_to_address($filterent['source'], $_POST['src'],
316
			$_POST['srcmask'], $_POST['srcnot'],
317
			$_POST['srcbeginport'], $_POST['srcendport']);
318 5ba18897 Scott Ullrich
319 5b237745 Scott Ullrich
		pconfig_to_address($filterent['destination'], $_POST['dst'],
320
			$_POST['dstmask'], $_POST['dstnot'],
321
			$_POST['dstbeginport'], $_POST['dstendport']);
322 5ba18897 Scott Ullrich
323 5b237745 Scott Ullrich
		$filterent['disabled'] = $_POST['disabled'] ? true : false;
324
		$filterent['log'] = $_POST['log'] ? true : false;
325
		$filterent['frags'] = $_POST['frags'] ? true : false;
326
		$filterent['descr'] = $_POST['descr'];
327 5ba18897 Scott Ullrich
328 5b237745 Scott Ullrich
		if (isset($id) && $a_filter[$id])
329
			$a_filter[$id] = $filterent;
330
		else {
331
			if (is_numeric($after))
332
				array_splice($a_filter, $after+1, 0, array($filterent));
333
			else
334
				$a_filter[] = $filterent;
335
		}
336 5ba18897 Scott Ullrich
337 5b237745 Scott Ullrich
		write_config();
338
		touch($d_filterconfdirty_path);
339 5ba18897 Scott Ullrich
340 a23d7248 Scott Ullrich
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
341 5b237745 Scott Ullrich
		exit;
342
	}
343
}
344
?>
345
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
346
<html>
347
<head>
348
<title><?=gentitle("Firewall: Rules: Edit");?></title>
349
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
350
<link href="gui.css" rel="stylesheet" type="text/css">
351
<script language="JavaScript">
352
<!--
353
var portsenabled = 1;
354 bdb7d6e7 Scott Ullrich
355 5b237745 Scott Ullrich
function ext_change() {
356
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
357
		document.iform.srcbeginport_cust.disabled = 0;
358
	} else {
359
		document.iform.srcbeginport_cust.value = "";
360
		document.iform.srcbeginport_cust.disabled = 1;
361
	}
362
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
363
		document.iform.srcendport_cust.disabled = 0;
364
	} else {
365
		document.iform.srcendport_cust.value = "";
366
		document.iform.srcendport_cust.disabled = 1;
367
	}
368
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
369
		document.iform.dstbeginport_cust.disabled = 0;
370
	} else {
371
		document.iform.dstbeginport_cust.value = "";
372
		document.iform.dstbeginport_cust.disabled = 1;
373
	}
374
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
375
		document.iform.dstendport_cust.disabled = 0;
376
	} else {
377
		document.iform.dstendport_cust.value = "";
378
		document.iform.dstendport_cust.disabled = 1;
379
	}
380 5ba18897 Scott Ullrich
381 5b237745 Scott Ullrich
	if (!portsenabled) {
382
		document.iform.srcbeginport.disabled = 1;
383
		document.iform.srcendport.disabled = 1;
384
		document.iform.dstbeginport.disabled = 1;
385
		document.iform.dstendport.disabled = 1;
386
	} else {
387
		document.iform.srcbeginport.disabled = 0;
388
		document.iform.srcendport.disabled = 0;
389
		document.iform.dstbeginport.disabled = 0;
390
		document.iform.dstendport.disabled = 0;
391
	}
392
}
393
394 bdb7d6e7 Scott Ullrich
function typesel_change() {
395 5b237745 Scott Ullrich
	switch (document.iform.srctype.selectedIndex) {
396
		case 1:	/* single */
397
			document.iform.src.disabled = 0;
398
			document.iform.srcmask.value = "";
399
			document.iform.srcmask.disabled = 1;
400
			break;
401
		case 2:	/* network */
402
			document.iform.src.disabled = 0;
403
			document.iform.srcmask.disabled = 0;
404
			break;
405
		default:
406
			document.iform.src.value = "";
407
			document.iform.src.disabled = 1;
408
			document.iform.srcmask.value = "";
409
			document.iform.srcmask.disabled = 1;
410
			break;
411
	}
412
	switch (document.iform.dsttype.selectedIndex) {
413
		case 1:	/* single */
414
			document.iform.dst.disabled = 0;
415
			document.iform.dstmask.value = "";
416
			document.iform.dstmask.disabled = 1;
417
			break;
418
		case 2:	/* network */
419
			document.iform.dst.disabled = 0;
420
			document.iform.dstmask.disabled = 0;
421
			break;
422
		default:
423
			document.iform.dst.value = "";
424
			document.iform.dst.disabled = 1;
425
			document.iform.dstmask.value = "";
426
			document.iform.dstmask.disabled = 1;
427
			break;
428
	}
429
}
430
431
function proto_change() {
432
	if (document.iform.proto.selectedIndex < 3) {
433
		portsenabled = 1;
434
	} else {
435
		portsenabled = 0;
436
	}
437 5ba18897 Scott Ullrich
438 5b237745 Scott Ullrich
	if (document.iform.proto.selectedIndex == 3) {
439
		document.iform.icmptype.disabled = 0;
440
	} else {
441
		document.iform.icmptype.disabled = 1;
442
	}
443 5ba18897 Scott Ullrich
444 5b237745 Scott Ullrich
	ext_change();
445
}
446
447
function src_rep_change() {
448
	document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
449
}
450
function dst_rep_change() {
451
	document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
452
}
453
//-->
454
</script>
455
</head>
456
457
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
458
<?php include("fbegin.inc"); ?>
459
<p class="pgtitle">Firewall: Rules: Edit</p>
460
<?php if ($input_errors) print_input_errors($input_errors); ?>
461
            <form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
462
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
463 5ba18897 Scott Ullrich
                <tr>
464 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Action</td>
465
                  <td width="78%" class="vtable">
466 bdb7d6e7 Scott Ullrich
<select name="type" class="formfld">
467 5b237745 Scott Ullrich
                      <?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
468
                      <option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
469
                      <?=htmlspecialchars($type);?>
470
                      </option>
471
                      <?php endforeach; ?>
472
                    </select> <br>
473 bdb7d6e7 Scott Ullrich
                    <span class="vexpl">Choose what to do with packets that match
474
					the criteria specified below.<br>
475
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.</span></td>
476 5b237745 Scott Ullrich
                </tr>
477 5ba18897 Scott Ullrich
                <tr>
478 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Disabled</td>
479 5ba18897 Scott Ullrich
                  <td width="78%" class="vtable">
480 5b237745 Scott Ullrich
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
481
                    <strong>Disable this rule</strong><br>
482
                    <span class="vexpl">Set this option to disable this rule without
483
					removing it from the list.</span></td>
484
                </tr>
485 5ba18897 Scott Ullrich
                <tr>
486 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
487
                  <td width="78%" class="vtable">
488 bdb7d6e7 Scott Ullrich
<select name="interface" class="formfld">
489 5b237745 Scott Ullrich
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN', 'pptp' => 'PPTP');
490
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
491
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
492
					  }
493
					  foreach ($interfaces as $iface => $ifacename): ?>
494
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
495
                      <?=htmlspecialchars($ifacename);?>
496
                      </option>
497
                      <?php endforeach; ?>
498
                    </select> <br>
499 5ba18897 Scott Ullrich
                    <span class="vexpl">Choose on which interface packets must
500 5b237745 Scott Ullrich
                    come in to match this rule.</span></td>
501
                </tr>
502 5ba18897 Scott Ullrich
                <tr>
503 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
504
                  <td width="78%" class="vtable">
505 bdb7d6e7 Scott Ullrich
<select name="proto" class="formfld" onchange="proto_change()">
506 5b237745 Scott Ullrich
                      <?php $protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IPv6 IGMP any"); foreach ($protocols as $proto): ?>
507
                      <option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>>
508
                      <?=htmlspecialchars($proto);?>
509
                      </option>
510
                      <?php endforeach; ?>
511
                    </select> <br>
512 5ba18897 Scott Ullrich
                    <span class="vexpl">Choose which IP protocol this rule should
513 5b237745 Scott Ullrich
                    match.<br>
514
                    Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span></td>
515
                </tr>
516
                <tr>
517
                  <td valign="top" class="vncell">ICMP type</td>
518
                  <td class="vtable">
519
                    <select name="icmptype" class="formfld">
520
                      <?php
521 5ba18897 Scott Ullrich
522 5b237745 Scott Ullrich
					  $icmptypes = array(
523
					  	"" => "any",
524
					  	"unreach" => "Destination unreachable",
525
						"echo" => "Echo",
526
						"echorep" => "Echo reply",
527
						"squench" => "Source quench",
528
						"redir" => "Redirect",
529
						"timex" => "Time exceeded",
530
						"paramprob" => "Parameter problem",
531
						"timest" => "Timestamp",
532
						"timestrep" => "Timestamp reply",
533
						"inforeq" => "Information request",
534
						"inforep" => "Information reply",
535
						"maskreq" => "Address mask request",
536
						"maskrep" => "Address mask reply"
537
					  );
538 5ba18897 Scott Ullrich
539 5b237745 Scott Ullrich
					  foreach ($icmptypes as $icmptype => $descr): ?>
540
                      <option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>>
541
                      <?=htmlspecialchars($descr);?>
542
                      </option>
543
                      <?php endforeach; ?>
544
                    </select>
545
                    <br>
546
                    <span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span></td>
547
                </tr>
548 5ba18897 Scott Ullrich
                <tr>
549 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Source</td>
550
                  <td width="78%" class="vtable">
551 bdb7d6e7 Scott Ullrich
<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
552 5b237745 Scott Ullrich
                    <strong>not</strong><br>
553
                    Use this option to invert the sense of the match.<br>
554
                    <br>
555
                    <table border="0" cellspacing="0" cellpadding="0">
556 5ba18897 Scott Ullrich
                      <tr>
557 5b237745 Scott Ullrich
                        <td>Type:&nbsp;&nbsp;</td>
558 bdb7d6e7 Scott Ullrich
                        <td><select name="srctype" class="formfld" onChange="typesel_change()">
559 5b237745 Scott Ullrich
							<?php $sel = is_specialnet($pconfig['src']); ?>
560
                            <option value="any" <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>
561
                            any</option>
562
                            <option value="single" <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
563
                            Single host or alias</option>
564
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
565
                            Network</option>
566
                            <option value="lan" <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>
567
                            LAN subnet</option>
568
                            <option value="pptp" <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>
569
                            PPTP clients</option>
570
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
571
                            <option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>>
572
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
573
							<?php endfor; ?>
574
                          </select></td>
575
                      </tr>
576 5ba18897 Scott Ullrich
                      <tr>
577 5b237745 Scott Ullrich
                        <td>Address:&nbsp;&nbsp;</td>
578 19757279 Scott Ullrich
                        <td><input autocomplete='off' onblur='actb_removedisp()'  onkeydown='actb_checkkey(event);' onkeyup='actb_tocomplete(this,event,addressarray)' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>">
579 5b237745 Scott Ullrich
                        /
580 bdb7d6e7 Scott Ullrich
						<select name="srcmask" class="formfld" id="srcmask">
581
						<?php for ($i = 31; $i > 0; $i--): ?>
582
						<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
583
						<?php endfor; ?>
584
						</select>
585
						</td>
586
					  </tr>
587 5b237745 Scott Ullrich
                    </table></td>
588
                </tr>
589 5ba18897 Scott Ullrich
                <tr>
590
                  <td width="22%" valign="top" class="vncellreq">Source port range
591 5b237745 Scott Ullrich
                  </td>
592 5ba18897 Scott Ullrich
                  <td width="78%" class="vtable">
593 5b237745 Scott Ullrich
                    <table border="0" cellspacing="0" cellpadding="0">
594 5ba18897 Scott Ullrich
                      <tr>
595 5b237745 Scott Ullrich
                        <td>from:&nbsp;&nbsp;</td>
596
                        <td><select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
597
                            <option value="">(other)</option>
598 bdb7d6e7 Scott Ullrich
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
599 5b237745 Scott Ullrich
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
600
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) {
601
																echo "selected";
602
																$bfound = 1;
603
															}?>>
604
                            <?=htmlspecialchars($wkportdesc);?>
605
                            </option>
606
                            <?php endforeach; ?>
607 19757279 Scott Ullrich
                          </select> <input autocomplete='off' onblur='actb_removedisp()'  onkeydown='actb_checkkey(event);' onkeyup='actb_tocomplete(this,event,customarray)' class="formfldalias" name="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>"></td>
608 5b237745 Scott Ullrich
                      </tr>
609 5ba18897 Scott Ullrich
                      <tr>
610 5b237745 Scott Ullrich
                        <td>to:</td>
611
                        <td><select name="srcendport" class="formfld" onchange="ext_change()">
612
                            <option value="">(other)</option>
613 bdb7d6e7 Scott Ullrich
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
614 5b237745 Scott Ullrich
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
615
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) {
616
																echo "selected";
617
																$bfound = 1;
618
															}?>>
619
                            <?=htmlspecialchars($wkportdesc);?>
620
                            </option>
621
                            <?php endforeach; ?>
622 19757279 Scott Ullrich
                          </select> <input autocomplete='off' onblur='actb_removedisp()'  onkeydown='actb_checkkey(event);' onkeyup='actb_tocomplete(this,event,customarray)' class="formfldalias" name="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>"></td>
623 5b237745 Scott Ullrich
                      </tr>
624
                    </table>
625 5ba18897 Scott Ullrich
                    <br>
626
                    <span class="vexpl">Specify the port or port range for
627 bdb7d6e7 Scott Ullrich
                    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>
628 5ba18897 Scott Ullrich
                    Hint: you can leave the <em>'to'</em> field empty if you only
629 5b237745 Scott Ullrich
                    want to filter a single port</span></td>
630 5ba18897 Scott Ullrich
                <tr>
631 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Destination</td>
632 5ba18897 Scott Ullrich
                  <td width="78%" class="vtable">
633
                    <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
634 5b237745 Scott Ullrich
                    <strong>not</strong><br>
635
                    Use this option to invert the sense of the match.<br>
636
                    <br>
637
                    <table border="0" cellspacing="0" cellpadding="0">
638 5ba18897 Scott Ullrich
                      <tr>
639 5b237745 Scott Ullrich
                        <td>Type:&nbsp;&nbsp;</td>
640 bdb7d6e7 Scott Ullrich
                        <td><select name="dsttype" class="formfld" onChange="typesel_change()">
641 5b237745 Scott Ullrich
                            <?php $sel = is_specialnet($pconfig['dst']); ?>
642
                            <option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
643
                            any</option>
644
                            <option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
645
                            Single host or alias</option>
646
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
647
                            Network</option>
648
                            <option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
649
                            LAN subnet</option>
650
                            <option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
651
                            PPTP clients</option>
652
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
653
                            <option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
654
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
655
							<?php endfor; ?>
656
                          </select></td>
657
                      </tr>
658 5ba18897 Scott Ullrich
                      <tr>
659 5b237745 Scott Ullrich
                        <td>Address:&nbsp;&nbsp;</td>
660 19757279 Scott Ullrich
                        <td><input name="dst" autocomplete='off' onblur='actb_removedisp()'  onkeydown='actb_checkkey(event);' onkeyup='actb_tocomplete(this,event,addressarray)' type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
661 5ba18897 Scott Ullrich
                          /
662 bdb7d6e7 Scott Ullrich
                          <select name="dstmask" class="formfld" id="dstmask">
663
						<?php for ($i = 31; $i > 0; $i--): ?>
664
						<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
665
						<?php endfor; ?>
666
						</select></td>
667 5b237745 Scott Ullrich
                      </tr>
668
                    </table></td>
669
                </tr>
670 5ba18897 Scott Ullrich
                <tr>
671
                  <td width="22%" valign="top" class="vncellreq">Destination port
672 5b237745 Scott Ullrich
                    range </td>
673 5ba18897 Scott Ullrich
                  <td width="78%" class="vtable">
674 5b237745 Scott Ullrich
                    <table border="0" cellspacing="0" cellpadding="0">
675 5ba18897 Scott Ullrich
                      <tr>
676 5b237745 Scott Ullrich
                        <td>from:&nbsp;&nbsp;</td>
677
                        <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
678
                            <option value="">(other)</option>
679
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
680
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
681
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
682
																echo "selected";
683
																$bfound = 1;
684
															}?>>
685
                            <?=htmlspecialchars($wkportdesc);?>
686
                            </option>
687
                            <?php endforeach; ?>
688 19757279 Scott Ullrich
                          </select> <input autocomplete='off' onblur='actb_removedisp()' onkeydown='actb_checkkey(event);' onkeyup='actb_tocomplete(this,event,customarray)' class="formfldalias" name="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>"></td>
689 5b237745 Scott Ullrich
                      </tr>
690 5ba18897 Scott Ullrich
                      <tr>
691 5b237745 Scott Ullrich
                        <td>to:</td>
692
                        <td><select name="dstendport" class="formfld" onchange="ext_change()">
693
                            <option value="">(other)</option>
694
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
695
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
696
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
697
																echo "selected";
698
																$bfound = 1;
699
															}?>>
700
                            <?=htmlspecialchars($wkportdesc);?>
701
                            </option>
702
                            <?php endforeach; ?>
703 19757279 Scott Ullrich
                          </select> <input autocomplete='off' onblur='actb_removedisp()' onkeydown='actb_checkkey(event);' onkeyup='actb_tocomplete(this,event,customarray)' class="formfldalias" name="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>"></td>
704 5b237745 Scott Ullrich
                      </tr>
705
                    </table>
706 5ba18897 Scott Ullrich
                    <br> <span class="vexpl">Specify the port or port range for
707 5b237745 Scott Ullrich
                    the destination of the packet for this rule.<br>
708 5ba18897 Scott Ullrich
                    Hint: you can leave the <em>'to'</em> field empty if you only
709 5b237745 Scott Ullrich
                    want to filter a single port</span></td>
710 5ba18897 Scott Ullrich
711
                <tr>
712 bdb7d6e7 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Fragments</td>
713 5ba18897 Scott Ullrich
                  <td width="78%" class="vtable">
714 bdb7d6e7 Scott Ullrich
                    <input name="frags" type="checkbox" id="frags" value="yes" <?php if ($pconfig['frags']) echo "checked"; ?>>
715
                    <strong>Allow fragmented packets</strong><br>
716 5ba18897 Scott Ullrich
                    <span class="vexpl">Hint: this option puts additional load
717
                    on the firewall and may make it vulnerable to DoS attacks.
718
                    In most cases, it is not needed. Try enabling it if you have
719 bdb7d6e7 Scott Ullrich
                    troubles connecting to certain sites.</span></td>
720
                </tr>
721 5ba18897 Scott Ullrich
                <tr>
722 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Log</td>
723 5ba18897 Scott Ullrich
                  <td width="78%" class="vtable">
724 5b237745 Scott Ullrich
                    <input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
725
                    <strong>Log packets that are handled by this rule</strong><br>
726 5ba18897 Scott Ullrich
                    <span class="vexpl">Hint: the firewall has limited local log
727
                    space. Don't turn on logging for everything. If you want to
728
                    do a lot of logging, consider using a remote syslog server
729
                    (see the <a href="diag_logs_settings.php">Diagnostics: System
730 5b237745 Scott Ullrich
                    logs: Settings</a> page).</span></td>
731
                </tr>
732 5ba18897 Scott Ullrich
                <tr>
733 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Description</td>
734 5ba18897 Scott Ullrich
                  <td width="78%" class="vtable">
735
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
736
                    <br> <span class="vexpl">You may enter a description here
737 5b237745 Scott Ullrich
                    for your reference (not parsed).</span></td>
738
                </tr>
739
740 bdb7d6e7 Scott Ullrich
741 a44455c4 Scott Ullrich
               <tr>
742
                  <td width="22%" valign="top" class="vncell">Advanced Options</td>
743
                  <td width="78%" class="vtable">
744
			<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
745
			<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<br>
746 4cc0d94c Scott Ullrich
			<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
747 a44455c4 Scott Ullrich
		    </td>
748
                </tr>
749
750 3849b323 Scott Ullrich
               <tr>
751
                  <td width="22%" valign="top" class="vncell">State Type</td>
752
                  <td width="78%" class="vtable">
753 d59874c1 Scott Ullrich
			<select name="statetype">
754 3849b323 Scott Ullrich
			<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
755
			<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
756
			<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
757
			<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
758
			</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
759
			<p><strong>
760
			<table>
761 5ba18897 Scott Ullrich
			<tr><td width="25%"><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</td></tr>
762
			<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>
763
			<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>
764
			<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>
765
			</table>
766 3849b323 Scott Ullrich
			</strong>
767
		    </td>
768
                </tr>
769 a44455c4 Scott Ullrich
770 5ba18897 Scott Ullrich
		<tr>
771
                  <td width="22%" valign="top" class="vncell">State Timeout</td>
772
                  <td width="78%" class="vtable">
773
			<input name="statetimeout" value="<?php echo $pconfig['frags'] ?>">
774
			<p><strong>Leave blank for default.  Amount is in seconds.
775
			</strong>
776
		    </td>
777
		</tr>
778
779
                <tr>
780 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
781 5ba18897 Scott Ullrich
                  <td width="78%">
782
                    <input name="Submit" type="submit" class="formbtn" value="Save">
783 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_filter[$id]): ?>
784 5ba18897 Scott Ullrich
                    <input name="id" type="hidden" value="<?=$id;?>">
785 5b237745 Scott Ullrich
                    <?php endif; ?>
786 5ba18897 Scott Ullrich
                    <input name="after" type="hidden" value="<?=$after;?>">
787 5b237745 Scott Ullrich
                  </td>
788
                </tr>
789
              </table>
790
</form>
791
<script language="JavaScript">
792
<!--
793
ext_change();
794
typesel_change();
795
proto_change();
796 19757279 Scott Ullrich
797
<?php
798
$isfirst = 0;
799
$aliases = "";
800
$addrisfirst = 0;
801
$aliasesaddr = "";
802
foreach($config['aliases']['alias'] as $alias_name) {
803
	if(!stristr($alias_name['address'], ".")) {
804
		if($isfirst == 1) $aliases .= ",";
805
		$aliases .= "'" . $alias_name['name'] . "'";
806
		$isfirst = 1;
807 a6308b24 Scott Ullrich
	} else {
808 19757279 Scott Ullrich
		if($addrisfirst == 1) $aliasesaddr .= ",";
809
		$aliasesaddr .= "'" . $alias_name['name'] . "'";
810
		$addrisfirst = 1;
811
	}
812
}
813
?>
814
815
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
816
var customarray=new Array(<?php echo $aliases; ?>);
817
818 5b237745 Scott Ullrich
//-->
819
</script>
820 ef8b343d Scott Ullrich
<script type="text/javascript" language="javascript" src="auto_complete_helper.js">
821
</script>
822 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
823
</body>
824
</html>