Project

General

Profile

Download (38 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	firewall_rules_edit.php
6
	part of pfSense (http://www.pfsense.com)
7
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
8

    
9
	originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

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

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

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

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

    
35
require("guiconfig.inc");
36

    
37
$specialsrcdst = explode(" ", "any lan pptp pppoe");
38

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

    
45
$id = $_GET['id'];
46
if (is_numeric($_POST['id']))
47
	$id = $_POST['id'];
48

    
49
$after = $_GET['after'];
50

    
51
if (isset($_POST['after']))
52
	$after = $_POST['after'];
53

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

    
59
if (isset($id) && $a_filter[$id]) {
60
	$pconfig['interface'] = $a_filter[$id]['interface'];
61

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

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

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

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

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

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

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

    
100
	/* Multi-WAN next-hop support */
101
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
102

    
103
} else {
104
	/* defaults */
105
	if ($_GET['if'])
106
		$pconfig['interface'] = $_GET['if'];
107
	$pconfig['type'] = "pass";
108
	$pconfig['src'] = "any";
109
	$pconfig['dst'] = "any";
110
}
111

    
112
if (isset($_GET['dup']))
113
	unset($id);
114

    
115
if ($_POST) {
116

    
117
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
118
		$_POST['srcbeginport'] = 0;
119
		$_POST['srcendport'] = 0;
120
		$_POST['dstbeginport'] = 0;
121
		$_POST['dstendport'] = 0;
122
	} else {
123

    
124
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
125
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
126
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
127
			$_POST['srcendport'] = $_POST['srcendport_cust'];
128

    
129
		if ($_POST['srcbeginport'] == "any") {
130
			$_POST['srcbeginport'] = 0;
131
			$_POST['srcendport'] = 0;
132
		} else {
133
			if (!$_POST['srcendport'])
134
				$_POST['srcendport'] = $_POST['srcbeginport'];
135
		}
136
		if ($_POST['srcendport'] == "any")
137
			$_POST['srcendport'] = $_POST['srcbeginport'];
138

    
139
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
140
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
141
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
142
			$_POST['dstendport'] = $_POST['dstendport_cust'];
143

    
144
		if ($_POST['dstbeginport'] == "any") {
145
			$_POST['dstbeginport'] = 0;
146
			$_POST['dstendport'] = 0;
147
		} else {
148
			if (!$_POST['dstendport'])
149
				$_POST['dstendport'] = $_POST['dstbeginport'];
150
		}
151
		if ($_POST['dstendport'] == "any")
152
			$_POST['dstendport'] = $_POST['dstbeginport'];
153
	}
154

    
155
	if (is_specialnet($_POST['srctype'])) {
156
		$_POST['src'] = $_POST['srctype'];
157
		$_POST['srcmask'] = 0;
158
	} else if ($_POST['srctype'] == "single") {
159
		$_POST['srcmask'] = 32;
160
	}
161
	if (is_specialnet($_POST['dsttype'])) {
162
		$_POST['dst'] = $_POST['dsttype'];
163
		$_POST['dstmask'] = 0;
164
	}  else if ($_POST['dsttype'] == "single") {
165
		$_POST['dstmask'] = 32;
166
	}
167

    
168
	unset($input_errors);
169
	$pconfig = $_POST;
170

    
171
	/* input validation */
172
	$reqdfields = explode(" ", "type interface proto src dst");
173
	$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
174

    
175

    
176
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state")
177
		if( $_POST['proto'] != "tcp" )
178
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
179

    
180

    
181
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
182
		$reqdfields[] = "srcmask";
183
		$reqdfieldsn[] = "Source bit count";
184
	}
185
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
186
		$reqdfields[] = "dstmask";
187
		$reqdfieldsn[] = "Destination bit count";
188
	}
189

    
190
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
191

    
192
	if (!$_POST['srcbeginport']) {
193
		$_POST['srcbeginport'] = 0;
194
		$_POST['srcendport'] = 0;
195
	}
196
	if (!$_POST['dstbeginport']) {
197
		$_POST['dstbeginport'] = 0;
198
		$_POST['dstendport'] = 0;
199
	}
200

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

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

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

    
247
	if (!$input_errors) {
248
		$filterent = array();
249
		$filterent['type'] = $_POST['type'];
250
		$filterent['interface'] = $_POST['interface'];
251

    
252
		/* Advanced options */
253
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
254
		$filterent['max-src-states'] = $_POST['max-src-states'];
255
		$filterent['statetimeout'] = $_POST['statetimeout'];
256
		$filterent['statetype'] = $_POST['statetype'];
257
		$filterent['os'] = $_POST['os'];
258
		$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
259
		$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
260

    
261
		if ($_POST['proto'] != "any")
262
			$filterent['protocol'] = $_POST['proto'];
263
		else
264
			unset($filterent['protocol']);
265

    
266
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
267
			$filterent['icmptype'] = $_POST['icmptype'];
268
		else
269
			unset($filterent['icmptype']);
270

    
271
		pconfig_to_address($filterent['source'], $_POST['src'],
272
			$_POST['srcmask'], $_POST['srcnot'],
273
			$_POST['srcbeginport'], $_POST['srcendport']);
274

    
275
		pconfig_to_address($filterent['destination'], $_POST['dst'],
276
			$_POST['dstmask'], $_POST['dstnot'],
277
			$_POST['dstbeginport'], $_POST['dstendport']);
278

    
279
                if ($_POST['disabled'])
280
                        $filterent['disabled'] = true;
281
                else
282
                        unset($filterent['disabled']);
283
                if ($_POST['log'])
284
                        $filterent['log'] = true;
285
                else
286
                        unset($filterent['log']);
287
		strncpy($filterent['descr'], $_POST['descr'], 52);
288

    
289
		if ($_POST['gateway'] != "") {
290
			$filterent['gateway'] = $_POST['gateway'];
291
		}
292

    
293
		if (isset($id) && $a_filter[$id])
294
			$a_filter[$id] = $filterent;
295
		else {
296
			if (is_numeric($after))
297
				array_splice($a_filter, $after+1, 0, array($filterent));
298
			else
299
				$a_filter[] = $filterent;
300
		}
301

    
302
		write_config();
303
		touch($d_filterconfdirty_path);
304

    
305
		header("Location: firewall_rules.php?if=" . $_POST['interface']);
306
		exit;
307
	}
308
}
309

    
310
$pgtitle = "Firewall: Rules: Edit";
311
$closehead = false;
312
include("head.inc");
313

    
314
?>
315

    
316
<script language="JavaScript">
317
<!--
318
var portsenabled = 1;
319

    
320
function ext_change() {
321
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
322
		document.iform.srcbeginport_cust.disabled = 0;
323
	} else {
324
		document.iform.srcbeginport_cust.value = "";
325
		document.iform.srcbeginport_cust.disabled = 1;
326
	}
327
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
328
		document.iform.srcendport_cust.disabled = 0;
329
	} else {
330
		document.iform.srcendport_cust.value = "";
331
		document.iform.srcendport_cust.disabled = 1;
332
	}
333
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
334
		document.iform.dstbeginport_cust.disabled = 0;
335
	} else {
336
		document.iform.dstbeginport_cust.value = "";
337
		document.iform.dstbeginport_cust.disabled = 1;
338
	}
339
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
340
		document.iform.dstendport_cust.disabled = 0;
341
	} else {
342
		document.iform.dstendport_cust.value = "";
343
		document.iform.dstendport_cust.disabled = 1;
344
	}
345

    
346
	if (!portsenabled) {
347
		document.iform.srcbeginport.disabled = 1;
348
		document.iform.srcendport.disabled = 1;
349
		document.iform.dstbeginport.disabled = 1;
350
		document.iform.dstendport.disabled = 1;
351
	} else {
352
		document.iform.srcbeginport.disabled = 0;
353
		document.iform.srcendport.disabled = 0;
354
		document.iform.dstbeginport.disabled = 0;
355
		document.iform.dstendport.disabled = 0;
356
	}
357
}
358

    
359
function typesel_change() {
360
	switch (document.iform.srctype.selectedIndex) {
361
		case 1:	/* single */
362
			document.iform.src.disabled = 0;
363
			document.iform.srcmask.value = "";
364
			document.iform.srcmask.disabled = 1;
365
			break;
366
		case 2:	/* network */
367
			document.iform.src.disabled = 0;
368
			document.iform.srcmask.disabled = 0;
369
			break;
370
		default:
371
			document.iform.src.value = "";
372
			document.iform.src.disabled = 1;
373
			document.iform.srcmask.value = "";
374
			document.iform.srcmask.disabled = 1;
375
			break;
376
	}
377
	switch (document.iform.dsttype.selectedIndex) {
378
		case 1:	/* single */
379
			document.iform.dst.disabled = 0;
380
			document.iform.dstmask.value = "";
381
			document.iform.dstmask.disabled = 1;
382
			break;
383
		case 2:	/* network */
384
			document.iform.dst.disabled = 0;
385
			document.iform.dstmask.disabled = 0;
386
			break;
387
		default:
388
			document.iform.dst.value = "";
389
			document.iform.dst.disabled = 1;
390
			document.iform.dstmask.value = "";
391
			document.iform.dstmask.disabled = 1;
392
			break;
393
	}
394
}
395

    
396
function proto_change() {
397
	if (document.iform.proto.selectedIndex < 3) {
398
		portsenabled = 1;
399
	} else {
400
		portsenabled = 0;
401
	}
402

    
403
	/* Disable OS knob if the proto is not TCP. */
404
	if (document.iform.proto.selectedIndex < 1) {
405
		document.forms[0].os.disabled = 0;
406
	} else {
407
		document.forms[0].os.disabled = 1;
408
	}
409

    
410
	if (document.iform.proto.selectedIndex == 3) {
411
		document.iform.icmptype.disabled = 0;
412
	} else {
413
		document.iform.icmptype.disabled = 1;
414
	}
415

    
416
	ext_change();
417
}
418

    
419
function src_rep_change() {
420
	document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
421
}
422
function dst_rep_change() {
423
	document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
424
}
425
//-->
426
</script>
427
</head>
428

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

    
495
					  $icmptypes = array(
496
					  	"" => "any",
497
						"echorep" => "Echo reply",
498
					  	"unreach" => "Destination unreachable",
499
						"squench" => "Source quench",
500
						"redir" => "Redirect",
501
						"althost" => "Alternate Host",
502
						"echoreq" => "Echo",
503
						"routeradv" => "Router advertisement",
504
						"routersol" => "Router solicitation",
505
						"timex" => "Time exceeded",
506
						"paramprob" => "Invalid IP header",
507
						"timereq" => "Timestamp",
508
						"timerep" => "Timestamp reply",
509
						"inforeq" => "Information request",
510
						"inforep" => "Information reply",
511
						"maskreq" => "Address mask request",
512
						"maskrep" => "Address mask reply"
513
					  );
514

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

    
609
                <tr>
610
                  <td width="22%" valign="top" class="vncellreq">Source OS</td>
611
                  <td width="78%" class="vtable">OS Type:&nbsp;
612
                    <select name="os" id="os" class="formfld">
613
                      <?php
614
                                          $ostypes = array(
615
						"" => "any",
616
                                                "AIX" => "AIX",
617
                                                "Linux" => "Linux",
618
                                                "FreeBSD" => "FreeBSD",
619
                                                "NetBSD" => "NetBSD",
620
                                                "OpenBSD" => "OpenBSD",
621
                                                "Solaris" => "Solaris",
622
                                                "MacOS" => "MacOS",
623
                                                "Windows" => "Windows",
624
                                                "Novell" => "Novell"
625
                                          );
626

    
627
                                          foreach ($ostypes as $ostype => $descr): ?>
628
                      <option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>>
629
                      <?=htmlspecialchars($descr);?>
630
                      </option>
631
                      <?php endforeach; ?>
632
                    </select><br>
633
                    Note: this only works for TCP rules</td>
634
		</tr>
635
                <tr>
636
                  <td width="22%" valign="top" class="vncellreq">Destination</td>
637
                  <td width="78%" class="vtable">
638
                    <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
639
                    <strong>not</strong><br>
640
                    Use this option to invert the sense of the match.<br>
641
                    <br>
642
                    <table border="0" cellspacing="0" cellpadding="0">
643
                      <tr>
644
                        <td>Type:&nbsp;&nbsp;</td>
645
                        <td><select name="dsttype" class="formfld" onChange="typesel_change()">
646
                            <?php $sel = is_specialnet($pconfig['dst']); ?>
647
                            <option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
648
                            any</option>
649
                            <option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
650
                            Single host or alias</option>
651
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
652
                            Network</option>
653
                            <option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
654
                            LAN subnet</option>
655
                            <option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
656
                            PPTP clients</option>
657
                            <option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>
658
                            PPPoE clients</option>
659

    
660
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
661
                            <option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
662
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
663
							<?php endfor; ?>
664
                          </select></td>
665
                      </tr>
666
                      <tr>
667
                        <td>Address:&nbsp;&nbsp;</td>
668
                        <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']);?>">
669
                          /
670
                          <select name="dstmask" class="formfld" id="dstmask">
671
						<?php for ($i = 31; $i > 0; $i--): ?>
672
						<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
673
						<?php endfor; ?>
674
						</select></td>
675
                      </tr>
676
                    </table></td>
677
                </tr>
678
                <tr>
679
                  <td width="22%" valign="top" class="vncellreq">Destination port
680
                    range </td>
681
                  <td width="78%" class="vtable">
682
                    <table border="0" cellspacing="0" cellpadding="0">
683
                      <tr>
684
                        <td>from:&nbsp;&nbsp;</td>
685
                        <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
686
                            <option value="">(other)</option>
687
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
688
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
689
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
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="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>"></td>
697
                      </tr>
698
                      <tr>
699
                        <td>to:</td>
700
                        <td><select name="dstendport" class="formfld" onchange="ext_change()">
701
                            <option value="">(other)</option>
702
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
703
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
704
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
705
																echo "selected";
706
																$bfound = 1;
707
															}?>>
708
                            <?=htmlspecialchars($wkportdesc);?>
709
                            </option>
710
                            <?php endforeach; ?>
711
                          </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>
712
                      </tr>
713
                    </table>
714
                    <br> <span class="vexpl">Specify the port or port range for
715
                    the destination of the packet for this rule.<br>
716
                    Hint: you can leave the <em>'to'</em> field empty if you only
717
                    want to filter a single port</span></td>
718
                </tr>
719
                <tr>
720
                  <td width="22%" valign="top" class="vncellreq">Log</td>
721
                  <td width="78%" class="vtable">
722
                    <input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
723
                    <strong>Log packets that are handled by this rule</strong><br>
724
                    <span class="vexpl">Hint: the firewall has limited local log
725
                    space. Don't turn on logging for everything. If you want to
726
                    do a lot of logging, consider using a remote syslog server
727
                    (see the <a href="diag_logs_settings.php">Diagnostics: System
728
                    logs: Settings</a> page).</span></td>
729
                </tr>
730
                <tr>
731
                  <td width="22%" valign="top" class="vncell">Description</td>
732
                  <td width="78%" class="vtable">
733
                    <input name="descr" type="text" class="formfld" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
734
                    <br> <span class="vexpl">You may enter a description here
735
                    for your reference (not parsed).</span></td>
736
                </tr>
737
               <tr>
738
                  <td width="22%" valign="top" class="vncell">Advanced Options</td>
739
                  <td width="78%" class="vtable">
740
			<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
741
			<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
742
			<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
743
			<select name="max-src-conn-rates" id="max-src-conn-rates">
744
			 <option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
745
			 <?php
746
			   for($x=1; $x<255; $x++) {
747
				if($x == $pconfig['max-src-conn-rates'])
748
					$selected = " selected";
749
				else 
750
					$selected = "";
751
				echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
752
			   }
753
			 ?>
754
			 </select>
755
			<br>
756
			Maximum new connections / per second
757
			<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
758
		    </td>
759
                </tr>
760
               <tr>
761
                  <td width="22%" valign="top" class="vncell">State Type</td>
762
                  <td width="78%" class="vtable">
763
			<select name="statetype">
764
			<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
765
			<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
766
			<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
767
			<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
768
			</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
769
			<p><strong>
770
			<table>
771
			<tr><td width="25%"><li>keep state</li></td><td>works with TCP, UDP, and ICMP.</td></tr>
772
			<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>
773
			<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>
774
			<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>
775
			</table>
776
			</strong>
777
		    </td>
778
                </tr>
779

    
780
		<tr>
781
                  <td width="22%" valign="top" class="vncell">State Timeout</td>
782
                  <td width="78%" class="vtable">
783
			<input name="statetimeout" value="<?php echo $pconfig['frags'] ?>">
784
			<p><strong>Leave blank for default.  Amount is in seconds.
785
			</strong>
786
		    </td>
787
		</tr>
788

    
789
		<?php
790
			/* build a list of gateways */
791
			$gateways = array();
792
                        $gateways[] = "default"; // default to don't use this feature :)
793
			foreach($config['interfaces'] as $int) {
794
				if($int['gateway'] <> "")
795
					$gateways[]=$int['gateway'];
796
			}
797
		?>
798
		<tr>
799
                  <td width="22%" valign="top" class="vncell">Gateway</td>
800
                  <td width="78%" class="vtable">
801
			<select name='gateway'>
802
			<?php
803
				foreach($gateways as $gw) {
804
					if($gw == $pconfig['gateway']) {
805
						$selected = " SELECTED";
806
					} else {
807
						$selected = "";
808
					}
809
					if ($gw == "default") {
810
						echo "<option value=\"\" {$selected}>{$gw}</option>\n";	
811
					} else {
812
						echo "<option value=\"{$gw}\" {$selected}>{$gw}</option>\n";
813
					}
814
				}
815
				foreach($config['load_balancer']['lbpool'] as $lb) {
816
					if($pconfig['gateway'] == $lb['name']) {
817
						echo "<option value=\"{$lb['name']}\" SELECTED>{$lb['name']}</option>\n";
818
					} else {
819
						echo "<option value=\"{$lb['name']}\">{$lb['name']}</option>\n";
820
					}		
821
				}
822
			?>
823
			</select>
824
			<p><strong>Leave blank for default.
825
			</strong>
826
		    </td>
827
		</tr>
828
                <tr>
829
                  <td width="22%" valign="top">&nbsp;</td>
830
                  <td width="78%">
831
                    <input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
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
if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
852
	foreach($config['aliases']['alias'] as $alias_name) {
853
		if(!stristr($alias_name['address'], ".")) {
854
			if($isfirst == 1) $aliases .= ",";
855
			$aliases .= "'" . $alias_name['name'] . "'";
856
			$isfirst = 1;
857
		} else {
858
			if($addrisfirst == 1) $aliasesaddr .= ",";
859
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
860
			$addrisfirst = 1;
861
		}
862
	}
863
?>
864

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

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

    
(42-42/143)