Project

General

Profile

Download (37 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	firewall_rules_edit.php
6
	part of m0n0wall (http://m0n0.ch/wall)
7

    
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10

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

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

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

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

    
33
require("guiconfig.inc");
34

    
35
$specialsrcdst = explode(" ", "any lan pptp");
36

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

    
43
$id = $_GET['id'];
44
if (is_numeric($_POST['id']))
45
	$id = $_POST['id'];
46

    
47
$after = $_GET['after'];
48

    
49
if (isset($_POST['after']))
50
	$after = $_POST['after'];
51

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

    
57
function is_specialnet($net) {
58
	global $specialsrcdst;
59

    
60
	if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
61
		return true;
62
	else
63
		return false;
64
}
65

    
66
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
67

    
68
	if (isset($adr['any']))
69
		$padr = "any";
70
	else if ($adr['network'])
71
		$padr = $adr['network'];
72
	else if ($adr['address']) {
73
		list($padr, $pmask) = explode("/", $adr['address']);
74
		if (!$pmask)
75
			$pmask = 32;
76
	}
77

    
78
	if (isset($adr['not']))
79
		$pnot = 1;
80
	else
81
		$pnot = 0;
82

    
83
	if ($adr['port']) {
84
		list($pbeginport, $pendport) = explode("-", $adr['port']);
85
		if (!$pendport)
86
			$pendport = $pbeginport;
87
	} else {
88
		if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
89
			/* Item is a port alias */
90
		} else {
91
			$pbeginport = "any";
92
			$pendport = "any";
93
		}
94
	}
95
}
96

    
97
function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) {
98

    
99
	$adr = array();
100

    
101
	if ($padr == "any")
102
		$adr['any'] = true;
103
	else if (is_specialnet($padr))
104
		$adr['network'] = $padr;
105
	else {
106
		$adr['address'] = $padr;
107
		if ($pmask != 32)
108
			$adr['address'] .= "/" . $pmask;
109
	}
110

    
111
	$adr['not'] = $pnot ? true : false;
112

    
113
	if (($pbeginport != 0) && ($pbeginport != "any")) {
114
		if ($pbeginport != $pendport)
115
			$adr['port'] = $pbeginport . "-" . $pendport;
116
		else
117
			$adr['port'] = $pbeginport;
118
	}
119

    
120
	if(alias_expand($pbeginport)) {
121
		$adr['port'] = $pbeginport;
122
	}
123
}
124

    
125
if (isset($id) && $a_filter[$id]) {
126
	$pconfig['interface'] = $a_filter[$id]['interface'];
127

    
128
	if (!isset($a_filter[$id]['type']))
129
		$pconfig['type'] = "pass";
130
	else
131
		$pconfig['type'] = $a_filter[$id]['type'];
132

    
133
	if (isset($a_filter[$id]['protocol']))
134
		$pconfig['proto'] = $a_filter[$id]['protocol'];
135
	else
136
		$pconfig['proto'] = "any";
137

    
138
	if ($a_filter[$id]['protocol'] == "icmp")
139
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
140

    
141
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
142
		$pconfig['srcmask'], $pconfig['srcnot'],
143
		$pconfig['srcbeginport'], $pconfig['srcendport']);
144

    
145
	if($a_filter[$id]['os'] <> "")
146
		$pconfig['os'] = $a_filter[$id]['os'];
147

    
148
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
149
		$pconfig['dstmask'], $pconfig['dstnot'],
150
		$pconfig['dstbeginport'], $pconfig['dstendport']);
151

    
152
	$pconfig['returngateway'] = $a_filter[$id]['returngateway'];
153
	$pconfig['returninterface'] = $a_filter[$id]['returninterface'];
154

    
155
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
156
	$pconfig['log'] = isset($a_filter[$id]['log']);
157
	$pconfig['descr'] = $a_filter[$id]['descr'];
158
        $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
159
        $pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
160
        $pconfig['statetype'] = $a_filter[$id]['statetype'];
161
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
162

    
163
} else {
164
	/* defaults */
165
	if ($_GET['if'])
166
		$pconfig['interface'] = $_GET['if'];
167
	$pconfig['type'] = "pass";
168
	$pconfig['src'] = "any";
169
	$pconfig['dst'] = "any";
170
}
171

    
172
if (isset($_GET['dup']))
173
	unset($id);
174

    
175
if ($_POST) {
176

    
177
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
178
		$_POST['srcbeginport'] = 0;
179
		$_POST['srcendport'] = 0;
180
		$_POST['dstbeginport'] = 0;
181
		$_POST['dstendport'] = 0;
182
	} else {
183

    
184
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
185
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
186
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
187
			$_POST['srcendport'] = $_POST['srcendport_cust'];
188

    
189
		if ($_POST['srcbeginport'] == "any") {
190
			$_POST['srcbeginport'] = 0;
191
			$_POST['srcendport'] = 0;
192
		} else {
193
			if (!$_POST['srcendport'])
194
				$_POST['srcendport'] = $_POST['srcbeginport'];
195
		}
196
		if ($_POST['srcendport'] == "any")
197
			$_POST['srcendport'] = $_POST['srcbeginport'];
198

    
199
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
200
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
201
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
202
			$_POST['dstendport'] = $_POST['dstendport_cust'];
203

    
204
		if ($_POST['dstbeginport'] == "any") {
205
			$_POST['dstbeginport'] = 0;
206
			$_POST['dstendport'] = 0;
207
		} else {
208
			if (!$_POST['dstendport'])
209
				$_POST['dstendport'] = $_POST['dstbeginport'];
210
		}
211
		if ($_POST['dstendport'] == "any")
212
			$_POST['dstendport'] = $_POST['dstbeginport'];
213
	}
214

    
215
	if (is_specialnet($_POST['srctype'])) {
216
		$_POST['src'] = $_POST['srctype'];
217
		$_POST['srcmask'] = 0;
218
	} else if ($_POST['srctype'] == "single") {
219
		$_POST['srcmask'] = 32;
220
	}
221
	if (is_specialnet($_POST['dsttype'])) {
222
		$_POST['dst'] = $_POST['dsttype'];
223
		$_POST['dstmask'] = 0;
224
	}  else if ($_POST['dsttype'] == "single") {
225
		$_POST['dstmask'] = 32;
226
	}
227

    
228
	unset($input_errors);
229
	$pconfig = $_POST;
230

    
231
	/* input validation */
232
	$reqdfields = explode(" ", "type interface proto src dst");
233
	$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
234

    
235

    
236
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state")
237
		if( $_POST['proto'] != "tcp" )
238
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
239

    
240

    
241
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
242
		$reqdfields[] = "srcmask";
243
		$reqdfieldsn[] = "Source bit count";
244
	}
245
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
246
		$reqdfields[] = "dstmask";
247
		$reqdfieldsn[] = "Destination bit count";
248
	}
249

    
250
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
251

    
252
	if (!$_POST['srcbeginport']) {
253
		$_POST['srcbeginport'] = 0;
254
		$_POST['srcendport'] = 0;
255
	}
256
	if (!$_POST['dstbeginport']) {
257
		$_POST['dstbeginport'] = 0;
258
		$_POST['dstendport'] = 0;
259
	}
260

    
261
	if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) {
262
		$input_errors[] = "The start source port must be an alias or integer between 1 and 65535.";
263
	}
264
	if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) {
265
		$input_errors[] = "The end source port must be an alias or integer between 1 and 65535.";
266
	}
267
	if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) {
268
		$input_errors[] = "The start destination port must be an alias or integer between 1 and 65535.";
269
	}
270
	if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) {
271
		$input_errors[] = "The end destination port must be an alias or integer between 1 and 65535.";
272
	}
273

    
274
	if (($_POST['returngateway'] && !is_ipaddroranyalias($_POST['returngateway'])))
275
		$input_errors[] = "A valid return gateway IP address or alias must be specified.";
276

    
277
	if (!is_specialnet($_POST['srctype'])) {
278
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
279
			$input_errors[] = "A valid source IP address or alias must be specified.";
280
		}
281
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
282
			$input_errors[] = "A valid source bit count must be specified.";
283
		}
284
	}
285
	if (!is_specialnet($_POST['dsttype'])) {
286
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
287
			$input_errors[] = "A valid destination IP address or alias must be specified.";
288
		}
289
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
290
			$input_errors[] = "A valid destination bit count must be specified.";
291
		}
292
	}
293

    
294
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
295
		/* swap */
296
		$tmp = $_POST['srcendport'];
297
		$_POST['srcendport'] = $_POST['srcbeginport'];
298
		$_POST['srcbeginport'] = $tmp;
299
	}
300
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
301
		/* swap */
302
		$tmp = $_POST['dstendport'];
303
		$_POST['dstendport'] = $_POST['dstbeginport'];
304
		$_POST['dstbeginport'] = $tmp;
305
	}
306
	if ($_POST['os'])
307
		if( $_POST['proto'] != "tcp" )
308
			$input_errors[] = "OS detection is only valid with protocol tcp.";
309

    
310
	if (!$input_errors) {
311
		$filterent = array();
312
		$filterent['type'] = $_POST['type'];
313
		$filterent['interface'] = $_POST['interface'];
314

    
315
		/* Advanced options */
316
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
317
		$filterent['max-src-states'] = $_POST['max-src-states'];
318
		$filterent['statetimeout'] = $_POST['statetimeout'];
319
		$filterent['statetype'] = $_POST['statetype'];
320
		$filterent['os'] = $_POST['os'];
321

    
322
		if ($_POST['proto'] != "any")
323
			$filterent['protocol'] = $_POST['proto'];
324
		else
325
			unset($filterent['protocol']);
326

    
327
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
328
			$filterent['icmptype'] = $_POST['icmptype'];
329
		else
330
			unset($filterent['icmptype']);
331

    
332
		pconfig_to_address($filterent['source'], $_POST['src'],
333
			$_POST['srcmask'], $_POST['srcnot'],
334
			$_POST['srcbeginport'], $_POST['srcendport']);
335

    
336
		pconfig_to_address($filterent['destination'], $_POST['dst'],
337
			$_POST['dstmask'], $_POST['dstnot'],
338
			$_POST['dstbeginport'], $_POST['dstendport']);
339

    
340
		$filterent['disabled'] = $_POST['disabled'] ? true : false;
341
		$filterent['log'] = $_POST['log'] ? true : false;
342
		$filterent['descr'] = $_POST['descr'];
343
		$filterent['returngateway'] = $_POST['returngateway'];
344
		$filterent['returninterface'] = $_POST['returninterface'];
345

    
346
		if (isset($id) && $a_filter[$id])
347
			$a_filter[$id] = $filterent;
348
		else {
349
			if (is_numeric($after))
350
				array_splice($a_filter, $after+1, 0, array($filterent));
351
			else
352
				$a_filter[] = $filterent;
353
		}
354

    
355
		write_config();
356
		touch($d_filterconfdirty_path);
357

    
358
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
359
		exit;
360
	}
361
}
362
?>
363
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
364
<html>
365
<head>
366
<title><?=gentitle("Firewall: Rules: Edit");?></title>
367
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
368
<link href="gui.css" rel="stylesheet" type="text/css">
369
<script language="JavaScript">
370
<!--
371
var portsenabled = 1;
372

    
373
function ext_change() {
374
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
375
		document.iform.srcbeginport_cust.disabled = 0;
376
	} else {
377
		document.iform.srcbeginport_cust.value = "";
378
		document.iform.srcbeginport_cust.disabled = 1;
379
	}
380
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
381
		document.iform.srcendport_cust.disabled = 0;
382
	} else {
383
		document.iform.srcendport_cust.value = "";
384
		document.iform.srcendport_cust.disabled = 1;
385
	}
386
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
387
		document.iform.dstbeginport_cust.disabled = 0;
388
	} else {
389
		document.iform.dstbeginport_cust.value = "";
390
		document.iform.dstbeginport_cust.disabled = 1;
391
	}
392
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
393
		document.iform.dstendport_cust.disabled = 0;
394
	} else {
395
		document.iform.dstendport_cust.value = "";
396
		document.iform.dstendport_cust.disabled = 1;
397
	}
398

    
399
	if (!portsenabled) {
400
		document.iform.srcbeginport.disabled = 1;
401
		document.iform.srcendport.disabled = 1;
402
		document.iform.dstbeginport.disabled = 1;
403
		document.iform.dstendport.disabled = 1;
404
	} else {
405
		document.iform.srcbeginport.disabled = 0;
406
		document.iform.srcendport.disabled = 0;
407
		document.iform.dstbeginport.disabled = 0;
408
		document.iform.dstendport.disabled = 0;
409
	}
410
}
411

    
412
function typesel_change() {
413
	switch (document.iform.srctype.selectedIndex) {
414
		case 1:	/* single */
415
			document.iform.src.disabled = 0;
416
			document.iform.srcmask.value = "";
417
			document.iform.srcmask.disabled = 1;
418
			break;
419
		case 2:	/* network */
420
			document.iform.src.disabled = 0;
421
			document.iform.srcmask.disabled = 0;
422
			break;
423
		default:
424
			document.iform.src.value = "";
425
			document.iform.src.disabled = 1;
426
			document.iform.srcmask.value = "";
427
			document.iform.srcmask.disabled = 1;
428
			break;
429
	}
430
	switch (document.iform.dsttype.selectedIndex) {
431
		case 1:	/* single */
432
			document.iform.dst.disabled = 0;
433
			document.iform.dstmask.value = "";
434
			document.iform.dstmask.disabled = 1;
435
			break;
436
		case 2:	/* network */
437
			document.iform.dst.disabled = 0;
438
			document.iform.dstmask.disabled = 0;
439
			break;
440
		default:
441
			document.iform.dst.value = "";
442
			document.iform.dst.disabled = 1;
443
			document.iform.dstmask.value = "";
444
			document.iform.dstmask.disabled = 1;
445
			break;
446
	}
447
}
448

    
449
function proto_change() {
450
	if (document.iform.proto.selectedIndex < 3) {
451
		portsenabled = 1;
452
	} else {
453
		portsenabled = 0;
454
	}
455

    
456
	/* Disable OS knob if the proto is not TCP. */
457
	if (document.iform.proto.selectedIndex < 1) {
458
		document.forms[0].os.disabled = 0;
459
	} else {
460
		document.forms[0].os.disabled = 1;
461
	}
462

    
463
	if (document.iform.proto.selectedIndex == 3) {
464
		document.iform.icmptype.disabled = 0;
465
	} else {
466
		document.iform.icmptype.disabled = 1;
467
	}
468

    
469
	ext_change();
470
}
471

    
472
function src_rep_change() {
473
	document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
474
}
475
function dst_rep_change() {
476
	document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
477
}
478
//-->
479
</script>
480
</head>
481

    
482
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
483
<?php include("fbegin.inc"); ?>
484
<p class="pgtitle">Firewall: Rules: Edit</p>
485
<?php if ($input_errors) print_input_errors($input_errors); ?>
486
            <form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
487
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
488
                <tr>
489
                  <td width="22%" valign="top" class="vncellreq">Action</td>
490
                  <td width="78%" class="vtable">
491
<select name="type" class="formfld">
492
                      <?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
493
                      <option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
494
                      <?=htmlspecialchars($type);?>
495
                      </option>
496
                      <?php endforeach; ?>
497
                    </select> <br>
498
                    <span class="vexpl">Choose what to do with packets that match
499
					the criteria specified below.<br>
500
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>
501
                </tr>
502
                <tr>
503
                  <td width="22%" valign="top" class="vncellreq">Disabled</td>
504
                  <td width="78%" class="vtable">
505
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
506
                    <strong>Disable this rule</strong><br>
507
                    <span class="vexpl">Set this option to disable this rule without
508
					removing it from the list.</span></td>
509
                </tr>
510
                <tr>
511
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
512
                  <td width="78%" class="vtable">
513
<select name="interface" class="formfld">
514
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN', 'pptp' => 'PPTP');
515
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
516
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
517
					  }
518
					  foreach ($interfaces as $iface => $ifacename): ?>
519
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
520
                      <?=htmlspecialchars($ifacename);?>
521
                      </option>
522
                      <?php endforeach; ?>
523
                    </select> <br>
524
                    <span class="vexpl">Choose on which interface packets must
525
                    come in to match this rule.</span></td>
526
                </tr>
527
                <tr>
528
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
529
                  <td width="78%" class="vtable">
530
<select name="proto" class="formfld" onchange="proto_change()">
531
                      <?php $protocols = explode(" ", "TCP UDP TCP/UDP ICMP ICMP6 ESP AH GRE IPv6 IGMP any carp pfsync"); foreach ($protocols as $proto): ?>
532
                      <option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>>
533
                      <?=htmlspecialchars($proto);?>
534
                      </option>
535
                      <?php endforeach; ?>
536
                    </select> <br>
537
                    <span class="vexpl">Choose which IP protocol this rule should
538
                    match.<br>
539
                    Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span></td>
540
                </tr>
541
                <tr>
542
                  <td valign="top" class="vncell">ICMP type</td>
543
                  <td class="vtable">
544
                    <select name="icmptype" class="formfld">
545
                      <?php
546

    
547
					  $icmptypes = array(
548
					  	"" => "any",
549
						"echorep" => "Echo reply",
550
					  	"unreach" => "Destination unreachable",
551
						"squench" => "Source quench",
552
						"redir" => "Redirect",
553
						"althost" => "Alternate Host",
554
						"echoreq" => "Echo",
555
						"routeradv" => "Router advertisement",
556
						"routersol" => "Router solicitation",
557
						"timex" => "Time exceeded",
558
						"paramprob" => "Invalid IP header",
559
						"timereq" => "Timestamp",
560
						"timerep" => "Timestamp reply",
561
						"inforeq" => "Information request",
562
						"inforep" => "Information reply",
563
						"maskreq" => "Address mask request",
564
						"maskrep" => "Address mask reply"
565
					  );
566

    
567
					  foreach ($icmptypes as $icmptype => $descr): ?>
568
                      <option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>>
569
                      <?=htmlspecialchars($descr);?>
570
                      </option>
571
                      <?php endforeach; ?>
572
                    </select>
573
                    <br>
574
                    <span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span></td>
575
                </tr>
576
                <tr>
577
                  <td width="22%" valign="top" class="vncellreq">Source</td>
578
                  <td width="78%" class="vtable">
579
<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
580
                    <strong>not</strong><br>
581
                    Use this option to invert the sense of the match.<br>
582
                    <br>
583
                    <table border="0" cellspacing="0" cellpadding="0">
584
                      <tr>
585
                        <td>Type:&nbsp;&nbsp;</td>
586
                        <td><select name="srctype" class="formfld" onChange="typesel_change()">
587
							<?php $sel = is_specialnet($pconfig['src']); ?>
588
                            <option value="any" <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>
589
                            any</option>
590
                            <option value="single" <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
591
                            Single host or alias</option>
592
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
593
                            Network</option>
594
                            <option value="lan" <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>
595
                            LAN subnet</option>
596
                            <option value="pptp" <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>
597
                            PPTP clients</option>
598
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
599
                            <option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>>
600
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
601
							<?php endfor; ?>
602
                          </select></td>
603
                      </tr>
604
                      <tr>
605
                        <td>Address:&nbsp;&nbsp;</td>
606
                        <td><input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this)' 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']);?>">
607
                        /
608
						<select name="srcmask" class="formfld" id="srcmask">
609
						<?php for ($i = 31; $i > 0; $i--): ?>
610
						<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
611
						<?php endfor; ?>
612
						</select>
613
						</td>
614
					  </tr>
615
                    </table></td>
616
                </tr>
617
                <tr>
618
                  <td width="22%" valign="top" class="vncellreq">Source port range
619
                  </td>
620
                  <td width="78%" class="vtable">
621
                    <table border="0" cellspacing="0" cellpadding="0">
622
                      <tr>
623
                        <td>from:&nbsp;&nbsp;</td>
624
                        <td><select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
625
                            <option value="">(other)</option>
626
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
627
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
628
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) {
629
																echo "selected";
630
																$bfound = 1;
631
															}?>>
632
                            <?=htmlspecialchars($wkportdesc);?>
633
                            </option>
634
                            <?php endforeach; ?>
635
                          </select> <input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);'  onkeydown='actb_checkkey(event, this);' 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>
636
                      </tr>
637
                      <tr>
638
                        <td>to:</td>
639
                        <td><select name="srcendport" class="formfld" onchange="ext_change()">
640
                            <option value="">(other)</option>
641
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
642
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
643
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) {
644
																echo "selected";
645
																$bfound = 1;
646
															}?>>
647
                            <?=htmlspecialchars($wkportdesc);?>
648
                            </option>
649
                            <?php endforeach; ?>
650
                          </select> <input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);'  onkeydown='actb_checkkey(event, this);' 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>
651
                      </tr>
652
                    </table>
653
                    <br>
654
                    <span class="vexpl">Specify the port or port range for
655
                    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>
656
                    Hint: you can leave the <em>'to'</em> field empty if you only
657
                    want to filter a single port</span></td>
658

    
659
                <tr>
660
                  <td width="22%" valign="top" class="vncellreq">Source OS</td>
661
                  <td width="78%" class="vtable">OS Type:&nbsp;
662
                    <select name="os" id="os" class="formfld">
663
                      <?php
664
                                          $ostypes = array(
665
						"" => "any",
666
                                                "AIX" => "AIX",
667
                                                "Linux" => "Linux",
668
                                                "FreeBSD" => "FreeBSD",
669
                                                "NetBSD" => "NetBSD",
670
                                                "OpenBSD" => "OpenBSD",
671
                                                "Solaris" => "Solaris",
672
                                                "MacOS" => "MacOS",
673
                                                "Windows" => "Windows",
674
                                                "Novell" => "Novell"
675
                                          );
676

    
677
                                          foreach ($ostypes as $ostype => $descr): ?>
678
                      <option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>>
679
                      <?=htmlspecialchars($descr);?>
680
                      </option>
681
                      <?php endforeach; ?>
682
                    </select><br>
683
                    Note: this only works for TCP rules</td>
684
		</tr>
685
                <tr>
686
                  <td width="22%" valign="top" class="vncellreq">Destination</td>
687
                  <td width="78%" class="vtable">
688
                    <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
689
                    <strong>not</strong><br>
690
                    Use this option to invert the sense of the match.<br>
691
                    <br>
692
                    <table border="0" cellspacing="0" cellpadding="0">
693
                      <tr>
694
                        <td>Type:&nbsp;&nbsp;</td>
695
                        <td><select name="dsttype" class="formfld" onChange="typesel_change()">
696
                            <?php $sel = is_specialnet($pconfig['dst']); ?>
697
                            <option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
698
                            any</option>
699
                            <option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
700
                            Single host or alias</option>
701
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
702
                            Network</option>
703
                            <option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
704
                            LAN subnet</option>
705
                            <option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
706
                            PPTP clients</option>
707
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
708
                            <option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
709
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
710
							<?php endfor; ?>
711
                          </select></td>
712
                      </tr>
713
                      <tr>
714
                        <td>Address:&nbsp;&nbsp;</td>
715
                        <td><input name="dst" autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);'  onkeydown='actb_checkkey(event, this);' 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']);?>">
716
                          /
717
                          <select name="dstmask" class="formfld" id="dstmask">
718
						<?php for ($i = 31; $i > 0; $i--): ?>
719
						<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
720
						<?php endfor; ?>
721
						</select></td>
722
                      </tr>
723
                    </table></td>
724
                </tr>
725
                <tr>
726
                  <td width="22%" valign="top" class="vncellreq">Destination port
727
                    range </td>
728
                  <td width="78%" class="vtable">
729
                    <table border="0" cellspacing="0" cellpadding="0">
730
                      <tr>
731
                        <td>from:&nbsp;&nbsp;</td>
732
                        <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
733
                            <option value="">(other)</option>
734
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
735
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
736
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
737
																echo "selected";
738
																$bfound = 1;
739
															}?>>
740
                            <?=htmlspecialchars($wkportdesc);?>
741
                            </option>
742
                            <?php endforeach; ?>
743
                          </select> <input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this);' 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>
744
                      </tr>
745
                      <tr>
746
                        <td>to:</td>
747
                        <td><select name="dstendport" class="formfld" onchange="ext_change()">
748
                            <option value="">(other)</option>
749
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
750
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
751
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
752
																echo "selected";
753
																$bfound = 1;
754
															}?>>
755
                            <?=htmlspecialchars($wkportdesc);?>
756
                            </option>
757
                            <?php endforeach; ?>
758
                          </select> <input autocomplete='off' onblur='actb_removedisp()' onkeypress='return (event.keyCode!=13);' onkeydown='actb_checkkey(event, this);' 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>
759
                      </tr>
760
                    </table>
761
                    <br> <span class="vexpl">Specify the port or port range for
762
                    the destination of the packet for this rule.<br>
763
                    Hint: you can leave the <em>'to'</em> field empty if you only
764
                    want to filter a single port</span></td>
765
                </tr>
766
                <tr>
767
                  <td width="22%" valign="top" class="vncellreq">Log</td>
768
                  <td width="78%" class="vtable">
769
                    <input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
770
                    <strong>Log packets that are handled by this rule</strong><br>
771
                    <span class="vexpl">Hint: the firewall has limited local log
772
                    space. Don't turn on logging for everything. If you want to
773
                    do a lot of logging, consider using a remote syslog server
774
                    (see the <a href="diag_logs_settings.php">Diagnostics: System
775
                    logs: Settings</a> page).</span></td>
776
                </tr>
777
                <tr>
778
                  <td width="22%" valign="top" class="vncell">Description</td>
779
                  <td width="78%" class="vtable">
780
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
781
                    <br> <span class="vexpl">You may enter a description here
782
                    for your reference (not parsed).</span></td>
783
                </tr>
784

    
785

    
786
               <tr>
787
                  <td width="22%" valign="top" class="vncell">Advanced Options</td>
788
                  <td width="78%" class="vtable">
789
			<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
790
			<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
791

    
792
			<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
793
		    </td>
794
                </tr>
795

    
796
               <tr>
797
                  <td width="22%" valign="top" class="vncell">State Type</td>
798
                  <td width="78%" class="vtable">
799
			<select name="statetype">
800
			<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
801
			<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
802
			<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
803
			<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
804
			</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
805
			<p><strong>
806
			<table>
807
			<tr><td width="25%"><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</td></tr>
808
			<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>
809
			<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>
810
			<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>
811
			</table>
812
			</strong>
813
		    </td>
814
                </tr>
815

    
816
		<tr>
817
                  <td width="22%" valign="top" class="vncell">State Timeout</td>
818
                  <td width="78%" class="vtable">
819
			<input name="statetimeout" value="<?php echo $pconfig['frags'] ?>">
820
			<p><strong>Leave blank for default.  Amount is in seconds.
821
			</strong>
822
		    </td>
823
		</tr>
824

    
825
                <tr>
826
                  <td width="22%" valign="top">&nbsp;</td>
827
                  <td width="78%">
828
                    <input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" value="Cancel" onclick="history.back()">
829
                    <?php if (isset($id) && $a_filter[$id]): ?>
830
                    <input name="id" type="hidden" value="<?=$id;?>">
831
                    <?php endif; ?>
832
                    <input name="after" type="hidden" value="<?=$after;?>">
833
                  </td>
834
                </tr>
835
              </table>
836
</form>
837
<script language="JavaScript">
838
<!--
839
ext_change();
840
typesel_change();
841
proto_change();
842

    
843
<?php
844
$isfirst = 0;
845
$aliases = "";
846
$addrisfirst = 0;
847
$aliasesaddr = "";
848
if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
849
	foreach($config['aliases']['alias'] as $alias_name) {
850
		if(!stristr($alias_name['address'], ".")) {
851
			if($isfirst == 1) $aliases .= ",";
852
			$aliases .= "'" . $alias_name['name'] . "'";
853
			$isfirst = 1;
854
		} else {
855
			if($addrisfirst == 1) $aliasesaddr .= ",";
856
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
857
			$addrisfirst = 1;
858
		}
859
	}
860
?>
861

    
862
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
863
var customarray=new Array(<?php echo $aliases; ?>);
864

    
865
//-->
866
</script>
867
<script type="text/javascript" language="javascript" src="auto_complete_helper.js">
868
</script>
869
<?php include("fend.inc"); ?>
870
</body>
871
</html>
(34-34/112)