Project

General

Profile

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

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

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

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

    
16
	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

    
20
	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
*/
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

    
46
$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

    
59
	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

    
67
	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

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

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

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

    
98
	$adr = array();
99

    
100
	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

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

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

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

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

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

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

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

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

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

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

    
151
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
152
	$pconfig['log'] = isset($a_filter[$id]['log']);
153
	$pconfig['frags'] = isset($a_filter[$id]['frags']);
154
	$pconfig['descr'] = $a_filter[$id]['descr'];
155
        $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
156
        $pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
157
        $pconfig['statetype'] = $a_filter[$id]['statetype'];
158
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
159

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

    
169
if (isset($_GET['dup']))
170
	unset($id);
171

    
172
if ($_POST) {
173

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

    
181
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
182
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
183
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
184
			$_POST['srcendport'] = $_POST['srcendport_cust'];
185

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

    
196
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
197
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
198
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
199
			$_POST['dstendport'] = $_POST['dstendport_cust'];
200

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

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

    
225
	unset($input_errors);
226
	$pconfig = $_POST;
227

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

    
232

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

    
237

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

    
247
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
248

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

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

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

    
288
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
289
		/* swap */
290
		$tmp = $_POST['srcendport'];
291
		$_POST['srcendport'] = $_POST['srcbeginport'];
292
		$_POST['srcbeginport'] = $tmp;
293
	}
294
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
295
		/* swap */
296
		$tmp = $_POST['dstendport'];
297
		$_POST['dstendport'] = $_POST['dstbeginport'];
298
		$_POST['dstbeginport'] = $tmp;
299
	}
300
	if ($_POST['os'])
301
		if( $_POST['proto'] != "tcp" )
302
			$input_errors[] = "OS detection is only valid with protocol tcp.";
303

    
304
	if (!$input_errors) {
305
		$filterent = array();
306
		$filterent['type'] = $_POST['type'];
307
		$filterent['interface'] = $_POST['interface'];
308

    
309
		/* Advanced options */
310
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
311
		$filterent['max-src-states'] = $_POST['max-src-states'];
312
		$filterent['statetimeout'] = $_POST['statetimeout'];
313
		$filterent['statetype'] = $_POST['statetype'];
314
		$filterent['os'] = $_POST['os'];
315

    
316
		if ($_POST['proto'] != "any")
317
			$filterent['protocol'] = $_POST['proto'];
318
		else
319
			unset($filterent['protocol']);
320

    
321
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
322
			$filterent['icmptype'] = $_POST['icmptype'];
323
		else
324
			unset($filterent['icmptype']);
325

    
326
		pconfig_to_address($filterent['source'], $_POST['src'],
327
			$_POST['srcmask'], $_POST['srcnot'],
328
			$_POST['srcbeginport'], $_POST['srcendport']);
329

    
330
		pconfig_to_address($filterent['destination'], $_POST['dst'],
331
			$_POST['dstmask'], $_POST['dstnot'],
332
			$_POST['dstbeginport'], $_POST['dstendport']);
333

    
334
		$filterent['disabled'] = $_POST['disabled'] ? true : false;
335
		$filterent['log'] = $_POST['log'] ? true : false;
336
		$filterent['frags'] = $_POST['frags'] ? true : false;
337
		$filterent['descr'] = $_POST['descr'];
338

    
339
		if (isset($id) && $a_filter[$id])
340
			$a_filter[$id] = $filterent;
341
		else {
342
			if (is_numeric($after))
343
				array_splice($a_filter, $after+1, 0, array($filterent));
344
			else
345
				$a_filter[] = $filterent;
346
		}
347

    
348
		write_config();
349
		touch($d_filterconfdirty_path);
350

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

    
366
function ext_change() {
367
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
368
		document.iform.srcbeginport_cust.disabled = 0;
369
	} else {
370
		document.iform.srcbeginport_cust.value = "";
371
		document.iform.srcbeginport_cust.disabled = 1;
372
	}
373
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
374
		document.iform.srcendport_cust.disabled = 0;
375
	} else {
376
		document.iform.srcendport_cust.value = "";
377
		document.iform.srcendport_cust.disabled = 1;
378
	}
379
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
380
		document.iform.dstbeginport_cust.disabled = 0;
381
	} else {
382
		document.iform.dstbeginport_cust.value = "";
383
		document.iform.dstbeginport_cust.disabled = 1;
384
	}
385
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
386
		document.iform.dstendport_cust.disabled = 0;
387
	} else {
388
		document.iform.dstendport_cust.value = "";
389
		document.iform.dstendport_cust.disabled = 1;
390
	}
391

    
392
	if (!portsenabled) {
393
		document.iform.srcbeginport.disabled = 1;
394
		document.iform.srcendport.disabled = 1;
395
		document.iform.dstbeginport.disabled = 1;
396
		document.iform.dstendport.disabled = 1;
397
	} else {
398
		document.iform.srcbeginport.disabled = 0;
399
		document.iform.srcendport.disabled = 0;
400
		document.iform.dstbeginport.disabled = 0;
401
		document.iform.dstendport.disabled = 0;
402
	}
403
}
404

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

    
442
function proto_change() {
443
	if (document.iform.proto.selectedIndex < 3) {
444
		portsenabled = 1;
445
	} else {
446
		portsenabled = 0;
447
	}
448

    
449
	/* Disable OS knob if the proto is not TCP. */
450
	if (document.iform.proto.selectedIndex < 1) {
451
		document.forms[0].os.disabled = 0;
452
	} else {
453
		document.forms[0].os.disabled = 1;
454
	}
455

    
456
	if (document.iform.proto.selectedIndex == 3) {
457
		document.iform.icmptype.disabled = 0;
458
	} else {
459
		document.iform.icmptype.disabled = 1;
460
	}
461

    
462
	ext_change();
463
}
464

    
465
function src_rep_change() {
466
	document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
467
}
468
function dst_rep_change() {
469
	document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
470
}
471
//-->
472
</script>
473
</head>
474

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

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

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

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

    
670
                                          foreach ($ostypes as $ostype => $descr): ?>
671
                      <option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>>
672
                      <?=htmlspecialchars($descr);?>
673
                      </option>
674
                      <?php endforeach; ?>
675
                    </select><br>
676
                    Note: this only works for TCP rules</td>
677
		</tr>
678
                <tr>
679
                  <td width="22%" valign="top" class="vncellreq">Destination</td>
680
                  <td width="78%" class="vtable">
681
                    <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
682
                    <strong>not</strong><br>
683
                    Use this option to invert the sense of the match.<br>
684
                    <br>
685
                    <table border="0" cellspacing="0" cellpadding="0">
686
                      <tr>
687
                        <td>Type:&nbsp;&nbsp;</td>
688
                        <td><select name="dsttype" class="formfld" onChange="typesel_change()">
689
                            <?php $sel = is_specialnet($pconfig['dst']); ?>
690
                            <option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
691
                            any</option>
692
                            <option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
693
                            Single host or alias</option>
694
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
695
                            Network</option>
696
                            <option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
697
                            LAN subnet</option>
698
                            <option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
699
                            PPTP clients</option>
700
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
701
                            <option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
702
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
703
							<?php endfor; ?>
704
                          </select></td>
705
                      </tr>
706
                      <tr>
707
                        <td>Address:&nbsp;&nbsp;</td>
708
                        <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']);?>">
709
                          /
710
                          <select name="dstmask" class="formfld" id="dstmask">
711
						<?php for ($i = 31; $i > 0; $i--): ?>
712
						<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
713
						<?php endfor; ?>
714
						</select></td>
715
                      </tr>
716
                    </table></td>
717
                </tr>
718
                <tr>
719
                  <td width="22%" valign="top" class="vncellreq">Destination port
720
                    range </td>
721
                  <td width="78%" class="vtable">
722
                    <table border="0" cellspacing="0" cellpadding="0">
723
                      <tr>
724
                        <td>from:&nbsp;&nbsp;</td>
725
                        <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
726
                            <option value="">(other)</option>
727
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
728
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
729
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
730
																echo "selected";
731
																$bfound = 1;
732
															}?>>
733
                            <?=htmlspecialchars($wkportdesc);?>
734
                            </option>
735
                            <?php endforeach; ?>
736
                          </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>
737
                      </tr>
738
                      <tr>
739
                        <td>to:</td>
740
                        <td><select name="dstendport" class="formfld" onchange="ext_change()">
741
                            <option value="">(other)</option>
742
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
743
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
744
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
745
																echo "selected";
746
																$bfound = 1;
747
															}?>>
748
                            <?=htmlspecialchars($wkportdesc);?>
749
                            </option>
750
                            <?php endforeach; ?>
751
                          </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>
752
                      </tr>
753
                    </table>
754
                    <br> <span class="vexpl">Specify the port or port range for
755
                    the destination of the packet for this rule.<br>
756
                    Hint: you can leave the <em>'to'</em> field empty if you only
757
                    want to filter a single port</span></td>
758

    
759
                <tr>
760
                  <td width="22%" valign="top" class="vncellreq">Fragments</td>
761
                  <td width="78%" class="vtable">
762
                    <input name="frags" type="checkbox" id="frags" value="yes" <?php if ($pconfig['frags']) echo "checked"; ?>>
763
                    <strong>Allow fragmented packets</strong><br>
764
                    <span class="vexpl">Hint: this option puts additional load
765
                    on the firewall and may make it vulnerable to DoS attacks.
766
                    In most cases, it is not needed. Try enabling it if you have
767
                    troubles connecting to certain sites.</span></td>
768
                </tr>
769
                <tr>
770
                  <td width="22%" valign="top" class="vncellreq">Log</td>
771
                  <td width="78%" class="vtable">
772
                    <input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
773
                    <strong>Log packets that are handled by this rule</strong><br>
774
                    <span class="vexpl">Hint: the firewall has limited local log
775
                    space. Don't turn on logging for everything. If you want to
776
                    do a lot of logging, consider using a remote syslog server
777
                    (see the <a href="diag_logs_settings.php">Diagnostics: System
778
                    logs: Settings</a> page).</span></td>
779
                </tr>
780
                <tr>
781
                  <td width="22%" valign="top" class="vncell">Description</td>
782
                  <td width="78%" class="vtable">
783
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
784
                    <br> <span class="vexpl">You may enter a description here
785
                    for your reference (not parsed).</span></td>
786
                </tr>
787

    
788

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

    
795
			<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
796
		    </td>
797
                </tr>
798

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

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

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

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

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

    
867
//-->
868
</script>
869
<script type="text/javascript" language="javascript" src="auto_complete_helper.js">
870
</script>
871
<?php include("fend.inc"); ?>
872
</body>
873
</html>
(31-31/101)