Project

General

Profile

Download (37.2 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
if (isset($id) && $a_filter[$id]) {
58
	$pconfig['interface'] = $a_filter[$id]['interface'];
59

    
60
	if (!isset($a_filter[$id]['type']))
61
		$pconfig['type'] = "pass";
62
	else
63
		$pconfig['type'] = $a_filter[$id]['type'];
64

    
65
	if (isset($a_filter[$id]['protocol']))
66
		$pconfig['proto'] = $a_filter[$id]['protocol'];
67
	else
68
		$pconfig['proto'] = "any";
69

    
70
	if ($a_filter[$id]['protocol'] == "icmp")
71
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
72

    
73
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
74
		$pconfig['srcmask'], $pconfig['srcnot'],
75
		$pconfig['srcbeginport'], $pconfig['srcendport']);
76

    
77
	if($a_filter[$id]['os'] <> "")
78
		$pconfig['os'] = $a_filter[$id]['os'];
79

    
80
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
81
		$pconfig['dstmask'], $pconfig['dstnot'],
82
		$pconfig['dstbeginport'], $pconfig['dstendport']);
83

    
84
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
85
	$pconfig['log'] = isset($a_filter[$id]['log']);
86
	$pconfig['descr'] = $a_filter[$id]['descr'];
87
	
88
	/* advanced */
89
        $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
90
        $pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
91
        $pconfig['statetype'] = $a_filter[$id]['statetype'];
92
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
93
	
94
	/* advanced - new connection per second banning*/
95
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
96
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
97

    
98
} else {
99
	/* defaults */
100
	if ($_GET['if'])
101
		$pconfig['interface'] = $_GET['if'];
102
	$pconfig['type'] = "pass";
103
	$pconfig['src'] = "any";
104
	$pconfig['dst'] = "any";
105
}
106

    
107
if (isset($_GET['dup']))
108
	unset($id);
109

    
110
if ($_POST) {
111

    
112
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
113
		$_POST['srcbeginport'] = 0;
114
		$_POST['srcendport'] = 0;
115
		$_POST['dstbeginport'] = 0;
116
		$_POST['dstendport'] = 0;
117
	} else {
118

    
119
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
120
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
121
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
122
			$_POST['srcendport'] = $_POST['srcendport_cust'];
123

    
124
		if ($_POST['srcbeginport'] == "any") {
125
			$_POST['srcbeginport'] = 0;
126
			$_POST['srcendport'] = 0;
127
		} else {
128
			if (!$_POST['srcendport'])
129
				$_POST['srcendport'] = $_POST['srcbeginport'];
130
		}
131
		if ($_POST['srcendport'] == "any")
132
			$_POST['srcendport'] = $_POST['srcbeginport'];
133

    
134
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
135
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
136
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
137
			$_POST['dstendport'] = $_POST['dstendport_cust'];
138

    
139
		if ($_POST['dstbeginport'] == "any") {
140
			$_POST['dstbeginport'] = 0;
141
			$_POST['dstendport'] = 0;
142
		} else {
143
			if (!$_POST['dstendport'])
144
				$_POST['dstendport'] = $_POST['dstbeginport'];
145
		}
146
		if ($_POST['dstendport'] == "any")
147
			$_POST['dstendport'] = $_POST['dstbeginport'];
148
	}
149

    
150
	if (is_specialnet($_POST['srctype'])) {
151
		$_POST['src'] = $_POST['srctype'];
152
		$_POST['srcmask'] = 0;
153
	} else if ($_POST['srctype'] == "single") {
154
		$_POST['srcmask'] = 32;
155
	}
156
	if (is_specialnet($_POST['dsttype'])) {
157
		$_POST['dst'] = $_POST['dsttype'];
158
		$_POST['dstmask'] = 0;
159
	}  else if ($_POST['dsttype'] == "single") {
160
		$_POST['dstmask'] = 32;
161
	}
162

    
163
	unset($input_errors);
164
	$pconfig = $_POST;
165

    
166
	/* input validation */
167
	$reqdfields = explode(" ", "type interface proto src dst");
168
	$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
169

    
170

    
171
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state")
172
		if( $_POST['proto'] != "tcp" )
173
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
174

    
175

    
176
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
177
		$reqdfields[] = "srcmask";
178
		$reqdfieldsn[] = "Source bit count";
179
	}
180
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
181
		$reqdfields[] = "dstmask";
182
		$reqdfieldsn[] = "Destination bit count";
183
	}
184

    
185
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
186

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

    
196
	if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) {
197
		$input_errors[] = "The start source port must be an alias or integer between 1 and 65535.";
198
	}
199
	if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) {
200
		$input_errors[] = "The end source port must be an alias or integer between 1 and 65535.";
201
	}
202
	if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) {
203
		$input_errors[] = "The start destination port must be an alias or integer between 1 and 65535.";
204
	}
205
	if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) {
206
		$input_errors[] = "The end destination port must be an alias or integer between 1 and 65535.";
207
	}
208

    
209
	if (!is_specialnet($_POST['srctype'])) {
210
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
211
			$input_errors[] = "A valid source IP address or alias must be specified.";
212
		}
213
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
214
			$input_errors[] = "A valid source bit count must be specified.";
215
		}
216
	}
217
	if (!is_specialnet($_POST['dsttype'])) {
218
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
219
			$input_errors[] = "A valid destination IP address or alias must be specified.";
220
		}
221
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
222
			$input_errors[] = "A valid destination bit count must be specified.";
223
		}
224
	}
225

    
226
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
227
		/* swap */
228
		$tmp = $_POST['srcendport'];
229
		$_POST['srcendport'] = $_POST['srcbeginport'];
230
		$_POST['srcbeginport'] = $tmp;
231
	}
232
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
233
		/* swap */
234
		$tmp = $_POST['dstendport'];
235
		$_POST['dstendport'] = $_POST['dstbeginport'];
236
		$_POST['dstbeginport'] = $tmp;
237
	}
238
	if ($_POST['os'])
239
		if( $_POST['proto'] != "tcp" )
240
			$input_errors[] = "OS detection is only valid with protocol tcp.";
241

    
242
	if (!$input_errors) {
243
		$filterent = array();
244
		$filterent['type'] = $_POST['type'];
245
		$filterent['interface'] = $_POST['interface'];
246

    
247
		/* Advanced options */
248
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
249
		$filterent['max-src-states'] = $_POST['max-src-states'];
250
		$filterent['statetimeout'] = $_POST['statetimeout'];
251
		$filterent['statetype'] = $_POST['statetype'];
252
		$filterent['os'] = $_POST['os'];
253
		$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
254
		$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
255

    
256
		if ($_POST['proto'] != "any")
257
			$filterent['protocol'] = $_POST['proto'];
258
		else
259
			unset($filterent['protocol']);
260

    
261
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
262
			$filterent['icmptype'] = $_POST['icmptype'];
263
		else
264
			unset($filterent['icmptype']);
265

    
266
		pconfig_to_address($filterent['source'], $_POST['src'],
267
			$_POST['srcmask'], $_POST['srcnot'],
268
			$_POST['srcbeginport'], $_POST['srcendport']);
269

    
270
		pconfig_to_address($filterent['destination'], $_POST['dst'],
271
			$_POST['dstmask'], $_POST['dstnot'],
272
			$_POST['dstbeginport'], $_POST['dstendport']);
273

    
274
                if ($_POST['disabled'])
275
                        $filterent['disabled'] = true;
276
                else
277
                        unset($filterent['disabled']);
278
                if ($_POST['log'])
279
                        $filterent['log'] = true;
280
                else
281
                        unset($filterent['log']);
282
		$filterent['descr'] = $_POST['descr'];
283

    
284
		if (isset($id) && $a_filter[$id])
285
			$a_filter[$id] = $filterent;
286
		else {
287
			if (is_numeric($after))
288
				array_splice($a_filter, $after+1, 0, array($filterent));
289
			else
290
				$a_filter[] = $filterent;
291
		}
292

    
293
		write_config();
294
		touch($d_filterconfdirty_path);
295

    
296
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
297
		exit;
298
	}
299
}
300
?>
301
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
302
<html>
303
<head>
304
<title><?=gentitle("Firewall: Rules: Edit");?></title>
305
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
306
<link href="gui.css" rel="stylesheet" type="text/css">
307
<script language="JavaScript">
308
<!--
309
var portsenabled = 1;
310

    
311
function ext_change() {
312
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
313
		document.iform.srcbeginport_cust.disabled = 0;
314
	} else {
315
		document.iform.srcbeginport_cust.value = "";
316
		document.iform.srcbeginport_cust.disabled = 1;
317
	}
318
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
319
		document.iform.srcendport_cust.disabled = 0;
320
	} else {
321
		document.iform.srcendport_cust.value = "";
322
		document.iform.srcendport_cust.disabled = 1;
323
	}
324
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
325
		document.iform.dstbeginport_cust.disabled = 0;
326
	} else {
327
		document.iform.dstbeginport_cust.value = "";
328
		document.iform.dstbeginport_cust.disabled = 1;
329
	}
330
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
331
		document.iform.dstendport_cust.disabled = 0;
332
	} else {
333
		document.iform.dstendport_cust.value = "";
334
		document.iform.dstendport_cust.disabled = 1;
335
	}
336

    
337
	if (!portsenabled) {
338
		document.iform.srcbeginport.disabled = 1;
339
		document.iform.srcendport.disabled = 1;
340
		document.iform.dstbeginport.disabled = 1;
341
		document.iform.dstendport.disabled = 1;
342
	} else {
343
		document.iform.srcbeginport.disabled = 0;
344
		document.iform.srcendport.disabled = 0;
345
		document.iform.dstbeginport.disabled = 0;
346
		document.iform.dstendport.disabled = 0;
347
	}
348
}
349

    
350
function typesel_change() {
351
	switch (document.iform.srctype.selectedIndex) {
352
		case 1:	/* single */
353
			document.iform.src.disabled = 0;
354
			document.iform.srcmask.value = "";
355
			document.iform.srcmask.disabled = 1;
356
			break;
357
		case 2:	/* network */
358
			document.iform.src.disabled = 0;
359
			document.iform.srcmask.disabled = 0;
360
			break;
361
		default:
362
			document.iform.src.value = "";
363
			document.iform.src.disabled = 1;
364
			document.iform.srcmask.value = "";
365
			document.iform.srcmask.disabled = 1;
366
			break;
367
	}
368
	switch (document.iform.dsttype.selectedIndex) {
369
		case 1:	/* single */
370
			document.iform.dst.disabled = 0;
371
			document.iform.dstmask.value = "";
372
			document.iform.dstmask.disabled = 1;
373
			break;
374
		case 2:	/* network */
375
			document.iform.dst.disabled = 0;
376
			document.iform.dstmask.disabled = 0;
377
			break;
378
		default:
379
			document.iform.dst.value = "";
380
			document.iform.dst.disabled = 1;
381
			document.iform.dstmask.value = "";
382
			document.iform.dstmask.disabled = 1;
383
			break;
384
	}
385
}
386

    
387
function proto_change() {
388
	if (document.iform.proto.selectedIndex < 3) {
389
		portsenabled = 1;
390
	} else {
391
		portsenabled = 0;
392
	}
393

    
394
	/* Disable OS knob if the proto is not TCP. */
395
	if (document.iform.proto.selectedIndex < 1) {
396
		document.forms[0].os.disabled = 0;
397
	} else {
398
		document.forms[0].os.disabled = 1;
399
	}
400

    
401
	if (document.iform.proto.selectedIndex == 3) {
402
		document.iform.icmptype.disabled = 0;
403
	} else {
404
		document.iform.icmptype.disabled = 1;
405
	}
406

    
407
	ext_change();
408
}
409

    
410
function src_rep_change() {
411
	document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
412
}
413
function dst_rep_change() {
414
	document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
415
}
416
//-->
417
</script>
418
</head>
419

    
420
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
421
<?php include("fbegin.inc"); ?>
422
<p class="pgtitle">Firewall: Rules: Edit</p>
423
<?php if ($input_errors) print_input_errors($input_errors); ?>
424
            <form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
425
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
426
                <tr>
427
                  <td width="22%" valign="top" class="vncellreq">Action</td>
428
                  <td width="78%" class="vtable">
429
<select name="type" class="formfld">
430
                      <?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
431
                      <option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
432
                      <?=htmlspecialchars($type);?>
433
                      </option>
434
                      <?php endforeach; ?>
435
                    </select> <br>
436
                    <span class="vexpl">Choose what to do with packets that match
437
					the criteria specified below.<br>
438
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>
439
                </tr>
440
                <tr>
441
                  <td width="22%" valign="top" class="vncellreq">Disabled</td>
442
                  <td width="78%" class="vtable">
443
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
444
                    <strong>Disable this rule</strong><br>
445
                    <span class="vexpl">Set this option to disable this rule without
446
					removing it from the list.</span></td>
447
                </tr>
448
                <tr>
449
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
450
                  <td width="78%" class="vtable">
451
<select name="interface" class="formfld">
452
                      <?php $interfaces = array('wan' => 'WAN', 'lan' => 'LAN', 'pptp' => 'PPTP');
453
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
454
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
455
					  }
456
					  foreach ($interfaces as $iface => $ifacename): ?>
457
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
458
                      <?=htmlspecialchars($ifacename);?>
459
                      </option>
460
                      <?php endforeach; ?>
461
                    </select> <br>
462
                    <span class="vexpl">Choose on which interface packets must
463
                    come in to match this rule.</span></td>
464
                </tr>
465
                <tr>
466
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
467
                  <td width="78%" class="vtable">
468
<select name="proto" class="formfld" onchange="proto_change()">
469
                      <?php $protocols = explode(" ", "TCP UDP TCP/UDP ICMP ICMP6 ESP AH GRE IPv6 IGMP any carp pfsync"); foreach ($protocols as $proto): ?>
470
                      <option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>>
471
                      <?=htmlspecialchars($proto);?>
472
                      </option>
473
                      <?php endforeach; ?>
474
                    </select> <br>
475
                    <span class="vexpl">Choose which IP protocol this rule should
476
                    match.<br>
477
                    Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span></td>
478
                </tr>
479
                <tr>
480
                  <td valign="top" class="vncell">ICMP type</td>
481
                  <td class="vtable">
482
                    <select name="icmptype" class="formfld">
483
                      <?php
484

    
485
					  $icmptypes = array(
486
					  	"" => "any",
487
						"echorep" => "Echo reply",
488
					  	"unreach" => "Destination unreachable",
489
						"squench" => "Source quench",
490
						"redir" => "Redirect",
491
						"althost" => "Alternate Host",
492
						"echoreq" => "Echo",
493
						"routeradv" => "Router advertisement",
494
						"routersol" => "Router solicitation",
495
						"timex" => "Time exceeded",
496
						"paramprob" => "Invalid IP header",
497
						"timereq" => "Timestamp",
498
						"timerep" => "Timestamp reply",
499
						"inforeq" => "Information request",
500
						"inforep" => "Information reply",
501
						"maskreq" => "Address mask request",
502
						"maskrep" => "Address mask reply"
503
					  );
504

    
505
					  foreach ($icmptypes as $icmptype => $descr): ?>
506
                      <option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>>
507
                      <?=htmlspecialchars($descr);?>
508
                      </option>
509
                      <?php endforeach; ?>
510
                    </select>
511
                    <br>
512
                    <span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span></td>
513
                </tr>
514
                <tr>
515
                  <td width="22%" valign="top" class="vncellreq">Source</td>
516
                  <td width="78%" class="vtable">
517
<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
518
                    <strong>not</strong><br>
519
                    Use this option to invert the sense of the match.<br>
520
                    <br>
521
                    <table border="0" cellspacing="0" cellpadding="0">
522
                      <tr>
523
                        <td>Type:&nbsp;&nbsp;</td>
524
                        <td><select name="srctype" class="formfld" onChange="typesel_change()">
525
							<?php $sel = is_specialnet($pconfig['src']); ?>
526
                            <option value="any" <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>
527
                            any</option>
528
                            <option value="single" <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
529
                            Single host or alias</option>
530
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
531
                            Network</option>
532
                            <option value="lan" <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>
533
                            LAN subnet</option>
534
                            <option value="pptp" <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>
535
                            PPTP clients</option>
536
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
537
                            <option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>>
538
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
539
							<?php endfor; ?>
540
                          </select></td>
541
                      </tr>
542
                      <tr>
543
                        <td>Address:&nbsp;&nbsp;</td>
544
                        <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']);?>">
545
                        /
546
						<select name="srcmask" class="formfld" id="srcmask">
547
						<?php for ($i = 31; $i > 0; $i--): ?>
548
						<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
549
						<?php endfor; ?>
550
						</select>
551
						</td>
552
					  </tr>
553
                    </table></td>
554
                </tr>
555
                <tr>
556
                  <td width="22%" valign="top" class="vncellreq">Source port range
557
                  </td>
558
                  <td width="78%" class="vtable">
559
                    <table border="0" cellspacing="0" cellpadding="0">
560
                      <tr>
561
                        <td>from:&nbsp;&nbsp;</td>
562
                        <td><select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
563
                            <option value="">(other)</option>
564
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
565
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
566
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) {
567
																echo "selected";
568
																$bfound = 1;
569
															}?>>
570
                            <?=htmlspecialchars($wkportdesc);?>
571
                            </option>
572
                            <?php endforeach; ?>
573
                          </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>
574
                      </tr>
575
                      <tr>
576
                        <td>to:</td>
577
                        <td><select name="srcendport" class="formfld" onchange="ext_change()">
578
                            <option value="">(other)</option>
579
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
580
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
581
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) {
582
																echo "selected";
583
																$bfound = 1;
584
															}?>>
585
                            <?=htmlspecialchars($wkportdesc);?>
586
                            </option>
587
                            <?php endforeach; ?>
588
                          </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>
589
                      </tr>
590
                    </table>
591
                    <br>
592
                    <span class="vexpl">Specify the port or port range for
593
                    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>
594
                    Hint: you can leave the <em>'to'</em> field empty if you only
595
                    want to filter a single port</span></td>
596

    
597
                <tr>
598
                  <td width="22%" valign="top" class="vncellreq">Source OS</td>
599
                  <td width="78%" class="vtable">OS Type:&nbsp;
600
                    <select name="os" id="os" class="formfld">
601
                      <?php
602
                                          $ostypes = array(
603
						"" => "any",
604
                                                "AIX" => "AIX",
605
                                                "Linux" => "Linux",
606
                                                "FreeBSD" => "FreeBSD",
607
                                                "NetBSD" => "NetBSD",
608
                                                "OpenBSD" => "OpenBSD",
609
                                                "Solaris" => "Solaris",
610
                                                "MacOS" => "MacOS",
611
                                                "Windows" => "Windows",
612
                                                "Novell" => "Novell"
613
                                          );
614

    
615
                                          foreach ($ostypes as $ostype => $descr): ?>
616
                      <option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>>
617
                      <?=htmlspecialchars($descr);?>
618
                      </option>
619
                      <?php endforeach; ?>
620
                    </select><br>
621
                    Note: this only works for TCP rules</td>
622
		</tr>
623
                <tr>
624
                  <td width="22%" valign="top" class="vncellreq">Destination</td>
625
                  <td width="78%" class="vtable">
626
                    <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
627
                    <strong>not</strong><br>
628
                    Use this option to invert the sense of the match.<br>
629
                    <br>
630
                    <table border="0" cellspacing="0" cellpadding="0">
631
                      <tr>
632
                        <td>Type:&nbsp;&nbsp;</td>
633
                        <td><select name="dsttype" class="formfld" onChange="typesel_change()">
634
                            <?php $sel = is_specialnet($pconfig['dst']); ?>
635
                            <option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
636
                            any</option>
637
                            <option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
638
                            Single host or alias</option>
639
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
640
                            Network</option>
641
                            <option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
642
                            LAN subnet</option>
643
                            <option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
644
                            PPTP clients</option>
645
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
646
                            <option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
647
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
648
							<?php endfor; ?>
649
                          </select></td>
650
                      </tr>
651
                      <tr>
652
                        <td>Address:&nbsp;&nbsp;</td>
653
                        <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']);?>">
654
                          /
655
                          <select name="dstmask" class="formfld" id="dstmask">
656
						<?php for ($i = 31; $i > 0; $i--): ?>
657
						<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
658
						<?php endfor; ?>
659
						</select></td>
660
                      </tr>
661
                    </table></td>
662
                </tr>
663
                <tr>
664
                  <td width="22%" valign="top" class="vncellreq">Destination port
665
                    range </td>
666
                  <td width="78%" class="vtable">
667
                    <table border="0" cellspacing="0" cellpadding="0">
668
                      <tr>
669
                        <td>from:&nbsp;&nbsp;</td>
670
                        <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
671
                            <option value="">(other)</option>
672
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
673
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
674
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
675
																echo "selected";
676
																$bfound = 1;
677
															}?>>
678
                            <?=htmlspecialchars($wkportdesc);?>
679
                            </option>
680
                            <?php endforeach; ?>
681
                          </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>
682
                      </tr>
683
                      <tr>
684
                        <td>to:</td>
685
                        <td><select name="dstendport" class="formfld" onchange="ext_change()">
686
                            <option value="">(other)</option>
687
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
688
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
689
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
690
																echo "selected";
691
																$bfound = 1;
692
															}?>>
693
                            <?=htmlspecialchars($wkportdesc);?>
694
                            </option>
695
                            <?php endforeach; ?>
696
                          </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>
697
                      </tr>
698
                    </table>
699
                    <br> <span class="vexpl">Specify the port or port range for
700
                    the destination of the packet for this rule.<br>
701
                    Hint: you can leave the <em>'to'</em> field empty if you only
702
                    want to filter a single port</span></td>
703
                </tr>
704
                <tr>
705
                  <td width="22%" valign="top" class="vncellreq">Log</td>
706
                  <td width="78%" class="vtable">
707
                    <input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
708
                    <strong>Log packets that are handled by this rule</strong><br>
709
                    <span class="vexpl">Hint: the firewall has limited local log
710
                    space. Don't turn on logging for everything. If you want to
711
                    do a lot of logging, consider using a remote syslog server
712
                    (see the <a href="diag_logs_settings.php">Diagnostics: System
713
                    logs: Settings</a> page).</span></td>
714
                </tr>
715
                <tr>
716
                  <td width="22%" valign="top" class="vncell">Description</td>
717
                  <td width="78%" class="vtable">
718
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
719
                    <br> <span class="vexpl">You may enter a description here
720
                    for your reference (not parsed).</span></td>
721
                </tr>
722
               <tr>
723
                  <td width="22%" valign="top" class="vncell">Advanced Options</td>
724
                  <td width="78%" class="vtable">
725
			<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
726
			<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
727
			<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
728
			<select name="max-src-conn-rates" id="max-src-conn-rates">
729
			 <option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
730
			 <?php
731
			   for($x=1; $x<255; $x++) {
732
				if($x == $pconfig['max-src-conn-rates'])
733
					$selected = " selected";
734
				else 
735
					$selected = "";
736
				echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
737
			   }
738
			 ?>
739
			 </select>
740
			<br>
741
			Maximum new connections / per second
742
			<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
743
		    </td>
744
                </tr>
745
               <tr>
746
                  <td width="22%" valign="top" class="vncell">State Type</td>
747
                  <td width="78%" class="vtable">
748
			<select name="statetype">
749
			<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
750
			<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
751
			<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
752
			<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
753
			</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
754
			<p><strong>
755
			<table>
756
			<tr><td width="25%"><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</td></tr>
757
			<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>
758
			<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>
759
			<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>
760
			</table>
761
			</strong>
762
		    </td>
763
                </tr>
764

    
765
		<tr>
766
                  <td width="22%" valign="top" class="vncell">State Timeout</td>
767
                  <td width="78%" class="vtable">
768
			<input name="statetimeout" value="<?php echo $pconfig['frags'] ?>">
769
			<p><strong>Leave blank for default.  Amount is in seconds.
770
			</strong>
771
		    </td>
772
		</tr>
773

    
774
		<?php
775
			/* build a list of gateways */
776
			$gateways = array();
777
			exec("/sbin/route -n get default |/usr/bin/grep gateway", $defroute);
778
			preg_match("/(\d+\.\d+\.\d+\.\d+)/", $defroute[0], $matches);
779
                        $gateways[] = $matches[1];
780
			foreach($config['interfaces'] as $int) {
781
				if($int['gateway'] <> "")
782
					$gateways[]=$int['gateway'];
783
			}
784
		?>
785
		<tr>
786
                  <td width="22%" valign="top" class="vncell">Gateway</td>
787
                  <td width="78%" class="vtable">
788
			<select name='gateway'>
789
			<?php
790
				foreach($gateways as $gw) {
791
					if($gw == $pconfig['gateway'])
792
						$selected = " SELECTED";
793
					else
794
						$selected = "";
795
					if($gw <> "")
796
						echo "<option value=\"{$gw}\" {$selected}>{$gw}</option>\n";
797
				}
798
			?>
799
			</select>
800
			<p><strong>Leave blank for default.
801
			</strong>
802
		    </td>
803
		</tr>
804
                <tr>
805
                  <td width="22%" valign="top">&nbsp;</td>
806
                  <td width="78%">
807
                    <input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
808
                    <?php if (isset($id) && $a_filter[$id]): ?>
809
                    <input name="id" type="hidden" value="<?=$id;?>">
810
                    <?php endif; ?>
811
                    <input name="after" type="hidden" value="<?=$after;?>">
812
                  </td>
813
                </tr>
814
              </table>
815
</form>
816
<script language="JavaScript">
817
<!--
818
ext_change();
819
typesel_change();
820
proto_change();
821

    
822
<?php
823
$isfirst = 0;
824
$aliases = "";
825
$addrisfirst = 0;
826
$aliasesaddr = "";
827
if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
828
	foreach($config['aliases']['alias'] as $alias_name) {
829
		if(!stristr($alias_name['address'], ".")) {
830
			if($isfirst == 1) $aliases .= ",";
831
			$aliases .= "'" . $alias_name['name'] . "'";
832
			$isfirst = 1;
833
		} else {
834
			if($addrisfirst == 1) $aliasesaddr .= ",";
835
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
836
			$addrisfirst = 1;
837
		}
838
	}
839
?>
840

    
841
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
842
var customarray=new Array(<?php echo $aliases; ?>);
843

    
844
//-->
845
</script>
846
<script type="text/javascript" language="javascript" src="auto_complete_helper.js">
847
</script>
848
<?php include("fend.inc"); ?>
849
</body>
850
</html>
(37-37/117)