Project

General

Profile

Download (31.4 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
		$pbeginport = "any";
88
		$pendport = "any";
89
	}
90
}
91

    
92
function pconfig_to_address(&$adr, $padr, $pmask, $pnot, $pbeginport, $pendport) {
93

    
94
	$adr = array();
95

    
96
	if ($padr == "any")
97
		$adr['any'] = true;
98
	else if (is_specialnet($padr))
99
		$adr['network'] = $padr;
100
	else {
101
		$adr['address'] = $padr;
102
		if ($pmask != 32)
103
			$adr['address'] .= "/" . $pmask;
104
	}
105

    
106
	$adr['not'] = $pnot ? true : false;
107

    
108
	if (($pbeginport != 0) && ($pbeginport != "any")) {
109
		if ($pbeginport != $pendport)
110
			$adr['port'] = $pbeginport . "-" . $pendport;
111
		else
112
			$adr['port'] = $pbeginport;
113
	}
114
}
115

    
116
if (isset($id) && $a_filter[$id]) {
117
	$pconfig['interface'] = $a_filter[$id]['interface'];
118

    
119
	if (!isset($a_filter[$id]['type']))
120
		$pconfig['type'] = "pass";
121
	else
122
		$pconfig['type'] = $a_filter[$id]['type'];
123

    
124
	if (isset($a_filter[$id]['protocol']))
125
		$pconfig['proto'] = $a_filter[$id]['protocol'];
126
	else
127
		$pconfig['proto'] = "any";
128

    
129
	if ($a_filter[$id]['protocol'] == "icmp")
130
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
131

    
132
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
133
		$pconfig['srcmask'], $pconfig['srcnot'],
134
		$pconfig['srcbeginport'], $pconfig['srcendport']);
135

    
136
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
137
		$pconfig['dstmask'], $pconfig['dstnot'],
138
		$pconfig['dstbeginport'], $pconfig['dstendport']);
139

    
140
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
141
	$pconfig['log'] = isset($a_filter[$id]['log']);
142
	$pconfig['frags'] = isset($a_filter[$id]['frags']);
143
	$pconfig['descr'] = $a_filter[$id]['descr'];
144

    
145
} else {
146
	/* defaults */
147
	$pconfig['type'] = "pass";
148
	$pconfig['src'] = "any";
149
	$pconfig['dst'] = "any";
150
}
151

    
152
if (isset($_GET['dup']))
153
	unset($id);
154

    
155
if ($_POST) {
156

    
157
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
158
		$_POST['srcbeginport'] = 0;
159
		$_POST['srcendport'] = 0;
160
		$_POST['dstbeginport'] = 0;
161
		$_POST['dstendport'] = 0;
162
	} else {
163

    
164
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
165
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
166
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
167
			$_POST['srcendport'] = $_POST['srcendport_cust'];
168

    
169
		if ($_POST['srcbeginport'] == "any") {
170
			$_POST['srcbeginport'] = 0;
171
			$_POST['srcendport'] = 0;
172
		} else {
173
			if (!$_POST['srcendport'])
174
				$_POST['srcendport'] = $_POST['srcbeginport'];
175
		}
176
		if ($_POST['srcendport'] == "any")
177
			$_POST['srcendport'] = $_POST['srcbeginport'];
178

    
179
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
180
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
181
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
182
			$_POST['dstendport'] = $_POST['dstendport_cust'];
183

    
184
		if ($_POST['dstbeginport'] == "any") {
185
			$_POST['dstbeginport'] = 0;
186
			$_POST['dstendport'] = 0;
187
		} else {
188
			if (!$_POST['dstendport'])
189
				$_POST['dstendport'] = $_POST['dstbeginport'];
190
		}
191
		if ($_POST['dstendport'] == "any")
192
			$_POST['dstendport'] = $_POST['dstbeginport'];
193
	}
194

    
195
	if (is_specialnet($_POST['srctype'])) {
196
		$_POST['src'] = $_POST['srctype'];
197
		$_POST['srcmask'] = 0;
198
	} else if ($_POST['srctype'] == "single") {
199
		$_POST['srcmask'] = 32;
200
	}
201
	if (is_specialnet($_POST['dsttype'])) {
202
		$_POST['dst'] = $_POST['dsttype'];
203
		$_POST['dstmask'] = 0;
204
	}  else if ($_POST['dsttype'] == "single") {
205
		$_POST['dstmask'] = 32;
206
	}
207

    
208
	unset($input_errors);
209
	$pconfig = $_POST;
210

    
211
	/* input validation */
212
	$reqdfields = explode(" ", "type interface proto src dst");
213
	$reqdfieldsn = explode(",", "Type,Interface,Protocol,Source,Destination");
214

    
215
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
216
		$reqdfields[] = "srcmask";
217
		$reqdfieldsn[] = "Source bit count";
218
	}
219
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
220
		$reqdfields[] = "dstmask";
221
		$reqdfieldsn[] = "Destination bit count";
222
	}
223

    
224
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
225

    
226
	if (!$_POST['srcbeginport']) {
227
		$_POST['srcbeginport'] = 0;
228
		$_POST['srcendport'] = 0;
229
	}
230
	if (!$_POST['dstbeginport']) {
231
		$_POST['dstbeginport'] = 0;
232
		$_POST['dstendport'] = 0;
233
	}
234

    
235
	if (($_POST['srcbeginport'] && !is_port($_POST['srcbeginport']))) {
236
		$input_errors[] = "The start source port must be an integer between 1 and 65535.";
237
	}
238
	if (($_POST['srcendport'] && !is_port($_POST['srcendport']))) {
239
		$input_errors[] = "The end source port must be an integer between 1 and 65535.";
240
	}
241
	if (($_POST['dstbeginport'] && !is_port($_POST['dstbeginport']))) {
242
		$input_errors[] = "The start destination port must be an integer between 1 and 65535.";
243
	}
244
	if (($_POST['dstendport'] && !is_port($_POST['dstendport']))) {
245
		$input_errors[] = "The end destination port must be an integer between 1 and 65535.";
246
	}
247

    
248
	if (!is_specialnet($_POST['srctype'])) {
249
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
250
			$input_errors[] = "A valid source IP address or alias must be specified.";
251
		}
252
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
253
			$input_errors[] = "A valid source bit count must be specified.";
254
		}
255
	}
256
	if (!is_specialnet($_POST['dsttype'])) {
257
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
258
			$input_errors[] = "A valid destination IP address or alias must be specified.";
259
		}
260
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
261
			$input_errors[] = "A valid destination bit count must be specified.";
262
		}
263
	}
264

    
265
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
266
		/* swap */
267
		$tmp = $_POST['srcendport'];
268
		$_POST['srcendport'] = $_POST['srcbeginport'];
269
		$_POST['srcbeginport'] = $tmp;
270
	}
271
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
272
		/* swap */
273
		$tmp = $_POST['dstendport'];
274
		$_POST['dstendport'] = $_POST['dstbeginport'];
275
		$_POST['dstbeginport'] = $tmp;
276
	}
277

    
278
	if (!$input_errors) {
279
		$filterent = array();
280
		$filterent['type'] = $_POST['type'];
281
		$filterent['interface'] = $_POST['interface'];
282

    
283
		if ($_POST['proto'] != "any")
284
			$filterent['protocol'] = $_POST['proto'];
285
		else
286
			unset($filterent['protocol']);
287

    
288
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
289
			$filterent['icmptype'] = $_POST['icmptype'];
290
		else
291
			unset($filterent['icmptype']);
292

    
293
		pconfig_to_address($filterent['source'], $_POST['src'],
294
			$_POST['srcmask'], $_POST['srcnot'],
295
			$_POST['srcbeginport'], $_POST['srcendport']);
296

    
297
		pconfig_to_address($filterent['destination'], $_POST['dst'],
298
			$_POST['dstmask'], $_POST['dstnot'],
299
			$_POST['dstbeginport'], $_POST['dstendport']);
300

    
301
		$filterent['disabled'] = $_POST['disabled'] ? true : false;
302
		$filterent['log'] = $_POST['log'] ? true : false;
303
		$filterent['frags'] = $_POST['frags'] ? true : false;
304
		$filterent['descr'] = $_POST['descr'];
305

    
306
		if (isset($id) && $a_filter[$id])
307
			$a_filter[$id] = $filterent;
308
		else {
309
			if (is_numeric($after))
310
				array_splice($a_filter, $after+1, 0, array($filterent));
311
			else
312
				$a_filter[] = $filterent;
313
		}
314

    
315
		/* ALTQ */
316
		$filterent['direction'] = $_POST['direction'];
317
		$filterent['queue'] = $_POST['queue'];
318

    
319
		write_config();
320
		touch($d_filterconfdirty_path);
321

    
322
		header("Location: firewall_rules.php");
323
		exit;
324
	}
325
}
326
?>
327
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
328
<html>
329
<head>
330
<title><?=gentitle("Firewall: Rules: Edit");?></title>
331
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
332
<link href="gui.css" rel="stylesheet" type="text/css">
333
<script language="JavaScript">
334
<!--
335
var portsenabled = 1;
336

    
337
function ext_change() {
338
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
339
		document.iform.srcbeginport_cust.disabled = 0;
340
	} else {
341
		document.iform.srcbeginport_cust.value = "";
342
		document.iform.srcbeginport_cust.disabled = 1;
343
	}
344
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
345
		document.iform.srcendport_cust.disabled = 0;
346
	} else {
347
		document.iform.srcendport_cust.value = "";
348
		document.iform.srcendport_cust.disabled = 1;
349
	}
350
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
351
		document.iform.dstbeginport_cust.disabled = 0;
352
	} else {
353
		document.iform.dstbeginport_cust.value = "";
354
		document.iform.dstbeginport_cust.disabled = 1;
355
	}
356
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
357
		document.iform.dstendport_cust.disabled = 0;
358
	} else {
359
		document.iform.dstendport_cust.value = "";
360
		document.iform.dstendport_cust.disabled = 1;
361
	}
362

    
363
	if (!portsenabled) {
364
		document.iform.srcbeginport.disabled = 1;
365
		document.iform.srcendport.disabled = 1;
366
		document.iform.dstbeginport.disabled = 1;
367
		document.iform.dstendport.disabled = 1;
368
	} else {
369
		document.iform.srcbeginport.disabled = 0;
370
		document.iform.srcendport.disabled = 0;
371
		document.iform.dstbeginport.disabled = 0;
372
		document.iform.dstendport.disabled = 0;
373
	}
374
}
375

    
376
function typesel_change() {
377
	switch (document.iform.srctype.selectedIndex) {
378
		case 1:	/* single */
379
			document.iform.src.disabled = 0;
380
			document.iform.srcmask.value = "";
381
			document.iform.srcmask.disabled = 1;
382
			break;
383
		case 2:	/* network */
384
			document.iform.src.disabled = 0;
385
			document.iform.srcmask.disabled = 0;
386
			break;
387
		default:
388
			document.iform.src.value = "";
389
			document.iform.src.disabled = 1;
390
			document.iform.srcmask.value = "";
391
			document.iform.srcmask.disabled = 1;
392
			break;
393
	}
394
	switch (document.iform.dsttype.selectedIndex) {
395
		case 1:	/* single */
396
			document.iform.dst.disabled = 0;
397
			document.iform.dstmask.value = "";
398
			document.iform.dstmask.disabled = 1;
399
			break;
400
		case 2:	/* network */
401
			document.iform.dst.disabled = 0;
402
			document.iform.dstmask.disabled = 0;
403
			break;
404
		default:
405
			document.iform.dst.value = "";
406
			document.iform.dst.disabled = 1;
407
			document.iform.dstmask.value = "";
408
			document.iform.dstmask.disabled = 1;
409
			break;
410
	}
411
}
412

    
413
function proto_change() {
414
	if (document.iform.proto.selectedIndex < 3) {
415
		portsenabled = 1;
416
	} else {
417
		portsenabled = 0;
418
	}
419

    
420
	if (document.iform.proto.selectedIndex == 3) {
421
		document.iform.icmptype.disabled = 0;
422
	} else {
423
		document.iform.icmptype.disabled = 1;
424
	}
425

    
426
	ext_change();
427
}
428

    
429
function src_rep_change() {
430
	document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
431
}
432
function dst_rep_change() {
433
	document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
434
}
435
//-->
436
</script>
437
</head>
438

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

    
504
					  $icmptypes = array(
505
					  	"" => "any",
506
					  	"unreach" => "Destination unreachable",
507
						"echo" => "Echo",
508
						"echorep" => "Echo reply",
509
						"squench" => "Source quench",
510
						"redir" => "Redirect",
511
						"timex" => "Time exceeded",
512
						"paramprob" => "Parameter problem",
513
						"timest" => "Timestamp",
514
						"timestrep" => "Timestamp reply",
515
						"inforeq" => "Information request",
516
						"inforep" => "Information reply",
517
						"maskreq" => "Address mask request",
518
						"maskrep" => "Address mask reply"
519
					  );
520

    
521
					  foreach ($icmptypes as $icmptype => $descr): ?>
522
                      <option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>>
523
                      <?=htmlspecialchars($descr);?>
524
                      </option>
525
                      <?php endforeach; ?>
526
                    </select>
527
                    <br>
528
                    <span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span></td>
529
                </tr>
530
                <tr>
531
                  <td width="22%" valign="top" class="vncellreq">Source</td>
532
                  <td width="78%" class="vtable">
533
<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
534
                    <strong>not</strong><br>
535
                    Use this option to invert the sense of the match.<br>
536
                    <br>
537
                    <table border="0" cellspacing="0" cellpadding="0">
538
                      <tr>
539
                        <td>Type:&nbsp;&nbsp;</td>
540
                        <td><select name="srctype" class="formfld" onChange="typesel_change()">
541
							<?php $sel = is_specialnet($pconfig['src']); ?>
542
                            <option value="any" <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>
543
                            any</option>
544
                            <option value="single" <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
545
                            Single host or alias</option>
546
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
547
                            Network</option>
548
                            <option value="lan" <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>
549
                            LAN subnet</option>
550
                            <option value="pptp" <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>
551
                            PPTP clients</option>
552
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
553
                            <option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>>
554
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
555
							<?php endfor; ?>
556
                          </select></td>
557
                      </tr>
558
                      <tr>
559
                        <td>Address:&nbsp;&nbsp;</td>
560
                        <td><input name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>">
561
                        /
562
						<select name="srcmask" class="formfld" id="srcmask">
563
						<?php for ($i = 31; $i > 0; $i--): ?>
564
						<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
565
						<?php endfor; ?>
566
						</select>
567
						</td>
568
					  </tr>
569
                    </table></td>
570
                </tr>
571
                <tr>
572
                  <td width="22%" valign="top" class="vncellreq">Source port range
573
                  </td>
574
                  <td width="78%" class="vtable">
575
                    <table border="0" cellspacing="0" cellpadding="0">
576
                      <tr>
577
                        <td>from:&nbsp;&nbsp;</td>
578
                        <td><select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
579
                            <option value="">(other)</option>
580
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
581
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
582
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) {
583
																echo "selected";
584
																$bfound = 1;
585
															}?>>
586
                            <?=htmlspecialchars($wkportdesc);?>
587
                            </option>
588
                            <?php endforeach; ?>
589
                          </select> <input name="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>"></td>
590
                      </tr>
591
                      <tr>
592
                        <td>to:</td>
593
                        <td><select name="srcendport" class="formfld" onchange="ext_change()">
594
                            <option value="">(other)</option>
595
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
596
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
597
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) {
598
																echo "selected";
599
																$bfound = 1;
600
															}?>>
601
                            <?=htmlspecialchars($wkportdesc);?>
602
                            </option>
603
                            <?php endforeach; ?>
604
                          </select> <input name="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>"></td>
605
                      </tr>
606
                    </table>
607
                    <br> <span class="vexpl">Specify the port or port range for
608
                    the source of the packet for this rule.<br>
609
                    Hint: you can leave the <em>'to'</em> field empty if you only
610
                    want to filter a single port</span></td>
611
                <tr>
612
                  <td width="22%" valign="top" class="vncellreq">Destination</td>
613
                  <td width="78%" class="vtable">
614
                    <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
615
                    <strong>not</strong><br>
616
                    Use this option to invert the sense of the match.<br>
617
                    <br>
618
                    <table border="0" cellspacing="0" cellpadding="0">
619
                      <tr>
620
                        <td>Type:&nbsp;&nbsp;</td>
621
                        <td><select name="dsttype" class="formfld" onChange="typesel_change()">
622
                            <?php $sel = is_specialnet($pconfig['dst']); ?>
623
                            <option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
624
                            any</option>
625
                            <option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
626
                            Single host or alias</option>
627
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
628
                            Network</option>
629
                            <option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
630
                            LAN subnet</option>
631
                            <option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
632
                            PPTP clients</option>
633
							<?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
634
                            <option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
635
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?> subnet</option>
636
							<?php endfor; ?>
637
                          </select></td>
638
                      </tr>
639
                      <tr>
640
                        <td>Address:&nbsp;&nbsp;</td>
641
                        <td><input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
642
                          /
643
                          <select name="dstmask" class="formfld" id="dstmask">
644
						<?php for ($i = 31; $i > 0; $i--): ?>
645
						<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
646
						<?php endfor; ?>
647
						</select></td>
648
                      </tr>
649
                    </table></td>
650
                </tr>
651
                <tr>
652
                  <td width="22%" valign="top" class="vncellreq">Destination port
653
                    range </td>
654
                  <td width="78%" class="vtable">
655
                    <table border="0" cellspacing="0" cellpadding="0">
656
                      <tr>
657
                        <td>from:&nbsp;&nbsp;</td>
658
                        <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
659
                            <option value="">(other)</option>
660
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
661
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
662
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
663
																echo "selected";
664
																$bfound = 1;
665
															}?>>
666
                            <?=htmlspecialchars($wkportdesc);?>
667
                            </option>
668
                            <?php endforeach; ?>
669
                          </select> <input name="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>"></td>
670
                      </tr>
671
                      <tr>
672
                        <td>to:</td>
673
                        <td><select name="dstendport" class="formfld" onchange="ext_change()">
674
                            <option value="">(other)</option>
675
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
676
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
677
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
678
																echo "selected";
679
																$bfound = 1;
680
															}?>>
681
                            <?=htmlspecialchars($wkportdesc);?>
682
                            </option>
683
                            <?php endforeach; ?>
684
                          </select> <input name="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>"></td>
685
                      </tr>
686
                    </table>
687
                    <br> <span class="vexpl">Specify the port or port range for
688
                    the destination of the packet for this rule.<br>
689
                    Hint: you can leave the <em>'to'</em> field empty if you only
690
                    want to filter a single port</span></td>
691

    
692
                <tr>
693
                  <td width="22%" valign="top" class="vncellreq">Fragments</td>
694
                  <td width="78%" class="vtable">
695
                    <input name="frags" type="checkbox" id="frags" value="yes" <?php if ($pconfig['frags']) echo "checked"; ?>>
696
                    <strong>Allow fragmented packets</strong><br>
697
                    <span class="vexpl">Hint: this option puts additional load
698
                    on the firewall and may make it vulnerable to DoS attacks.
699
                    In most cases, it is not needed. Try enabling it if you have
700
                    troubles connecting to certain sites.</span></td>
701
                </tr>
702
                <tr>
703
                  <td width="22%" valign="top" class="vncellreq">Log</td>
704
                  <td width="78%" class="vtable">
705
                    <input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
706
                    <strong>Log packets that are handled by this rule</strong><br>
707
                    <span class="vexpl">Hint: the firewall has limited local log
708
                    space. Don't turn on logging for everything. If you want to
709
                    do a lot of logging, consider using a remote syslog server
710
                    (see the <a href="diag_logs_settings.php">Diagnostics: System
711
                    logs: Settings</a> page).</span></td>
712
                </tr>
713
                <tr>
714
                  <td width="22%" valign="top" class="vncell">Description</td>
715
                  <td width="78%" class="vtable">
716
                    <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
717
                    <br> <span class="vexpl">You may enter a description here
718
                    for your reference (not parsed).</span></td>
719
                </tr>
720

    
721

    
722
                <tr>
723
                  <td width="22%" valign="top" class="vncell">Traffic Queuing / Shaping</td>
724
                  <td width="78%" class="vtable">
725
		    Direction: <select name="direction">
726
		    <?php if($pconfig['direction'] <> "")
727
			echo "<option value=\"" . htmlspecialchars($pconfig['direction']) . "\">" . htmlspecialchars($pconfig['direction']) . "</option>";
728
		    ?>
729
		    <option value="">DONT CARE</option>
730
		    <option value="in">IN</option>
731
		    <option value="out">OUT</option>
732
		    </select>
733
                    <br> <span class="vexpl">If you need fine grained control on direction, select an option here.
734
		    <p> Queue: <select name="queue">
735
		    <?php
736
			if($pconfig['queue'] <> "") echo "<option value=\"" . $pconfig['queue'] . "\">" . $pconfig['queue'] . "</option>";
737
			echo "<option value=\"\"></option>";
738
			if (is_array($config['pfqueueing']['queue'])) {
739
				foreach ($config['pfqueueing']['queue'] as $queue) {
740
					if(is_subqueue($queue['name']) == 0) {
741
						echo "<option value=\"" . $queue['name'] . "\">" . $queue['name'] . "</option>";
742
					}
743
				}
744
			}
745
		    ?>
746
		    </select><br><span class="vexpl">To enable traffic shaping on this rule, select a queue above.</span>
747
		    <br><span class="vexpl"><input type="checkbox" name="autocreatequeue"> Automatically create a new queue for this rule.</span>
748
		    </td>
749
                </tr>
750

    
751
                <tr>
752
                  <td width="22%" valign="top">&nbsp;</td>
753
                  <td width="78%">
754
                    <input name="Submit" type="submit" class="formbtn" value="Save">
755
                    <?php if (isset($id) && $a_filter[$id]): ?>
756
                    <input name="id" type="hidden" value="<?=$id;?>">
757
                    <?php endif; ?>
758
                    <input name="after" type="hidden" value="<?=$after;?>">
759
                  </td>
760
                </tr>
761

    
762
              </table>
763
</form>
764
<script language="JavaScript">
765
<!--
766
ext_change();
767
typesel_change();
768
proto_change();
769
//-->
770
</script>
771
<?php include("fend.inc"); ?>
772
</body>
773
</html>
(29-29/86)