Project

General

Profile

Download (34.1 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	firewall_shaper_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
if (!is_array($config['shaper']['rule'])) {
36
	$config['shaper']['rule'] = array();
37
}
38
$a_shaper = &$config['shaper']['rule'];
39

    
40
$specialsrcdst = explode(" ", "any lan pptp");
41

    
42
$id = $_GET['id'];
43
if (isset($_POST['id']))
44
	$id = $_POST['id'];
45

    
46
$after = $_GET['after'];
47
if (isset($_POST['after']))
48
	$after = $_POST['after'];
49

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

    
55
function is_specialnet($net) {
56
	global $specialsrcdst;
57

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

    
64
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
65

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

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

    
81
	if ($adr['port']) {
82
		list($pbeginport, $pendport) = explode("-", $adr['port']);
83
		if (!$pendport)
84
			$pendport = $pbeginport;
85
	} else {
86
		$pbeginport = "any";
87
		$pendport = "any";
88
	}
89
}
90

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

    
93
	$adr = array();
94

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

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

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

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

    
118
	if (isset($a_shaper[$id]['protocol']))
119
		$pconfig['proto'] = $a_shaper[$id]['protocol'];
120
	else
121
		$pconfig['proto'] = "any";
122

    
123
	address_to_pconfig($a_shaper[$id]['source'], $pconfig['src'],
124
		$pconfig['srcmask'], $pconfig['srcnot'],
125
		$pconfig['srcbeginport'], $pconfig['srcendport']);
126

    
127
	address_to_pconfig($a_shaper[$id]['destination'], $pconfig['dst'],
128
		$pconfig['dstmask'], $pconfig['dstnot'],
129
		$pconfig['dstbeginport'], $pconfig['dstendport']);
130

    
131
	$pconfig['targetqueue'] = $a_shaper[$id]['targetqueue'];
132

    
133
	$pconfig['direction'] = $a_shaper[$id]['direction'];
134
	$pconfig['iptos'] = $a_shaper[$id]['iptos'];
135
	$pconfig['iplen'] = $a_shaper[$id]['iplen'];
136
	$pconfig['tcpflags'] = $a_shaper[$id]['tcpflags'];
137
	$pconfig['descr'] = $a_shaper[$id]['descr'];
138
	$pconfig['disabled'] = isset($a_shaper[$id]['disabled']);
139

    
140
	if ($pconfig['srcbeginport'] == 0) {
141
		$pconfig['srcbeginport'] = "any";
142
		$pconfig['srcendport'] = "any";
143
	}
144
	if ($pconfig['dstbeginport'] == 0) {
145
		$pconfig['dstbeginport'] = "any";
146
		$pconfig['dstendport'] = "any";
147
	}
148

    
149
} else {
150
	/* defaults */
151
	$pconfig['src'] = "any";
152
	$pconfig['dst'] = "any";
153
}
154

    
155
if (isset($_GET['dup']))
156
	unset($id);
157

    
158
if ($_POST) {
159

    
160
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "any")) {
161
		$_POST['srcbeginport'] = 0;
162
		$_POST['srcendport'] = 0;
163
		$_POST['dstbeginport'] = 0;
164
		$_POST['dstendport'] = 0;
165
	} else {
166

    
167
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
168
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
169
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
170
			$_POST['srcendport'] = $_POST['srcendport_cust'];
171

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

    
182
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
183
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
184
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
185
			$_POST['dstendport'] = $_POST['dstendport_cust'];
186

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

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

    
211
	$intos = array();
212
	foreach ($iptos as $tos) {
213
		if ($_POST['iptos_' . $tos] == "on")
214
			$intos[] = $tos;
215
		else if ($_POST['iptos_' . $tos] == "off")
216
			$intos[] = "!" . $tos;
217
	}
218
	$_POST['iptos'] = join(",", $intos);
219

    
220
	$intcpflags = array();
221
	foreach ($tcpflags as $tcpflag) {
222
		if ($_POST['tcpflags_' . $tcpflag] == "on")
223
			$intcpflags[] = $tcpflag;
224
		else if ($_POST['tcpflags_' . $tcpflag] == "off")
225
			$intcpflags[] = "!" . $tcpflag;
226
	}
227
	$_POST['tcpflags'] = join(",", $intcpflags);
228

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

    
232
	/* input validation */
233
	$reqdfields = explode(" ", "target proto src dst");
234
	$reqdfieldsn = explode(",", "Target,Protocol,Source,Destination");
235

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

    
245
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
246

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

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

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

    
286
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
287
		/* swap */
288
		$tmp = $_POST['srcendport'];
289
		$_POST['srcendport'] = $_POST['srcbeginport'];
290
		$_POST['srcbeginport'] = $tmp;
291
	}
292
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
293
		/* swap */
294
		$tmp = $_POST['dstendport'];
295
		$_POST['dstendport'] = $_POST['dstbeginport'];
296
		$_POST['dstbeginport'] = $tmp;
297
	}
298

    
299
	if (($_POST['iplen'] && !preg_match("/^(\d+)(-(\d+))?$/", $_POST['iplen']))) {
300
		$input_errors[] = "The IP packet length must be an integer or a range (from-to).";
301
	}
302

    
303
	if (!$input_errors) {
304
		$shaperent = array();
305
		$shaperent['interface'] = $_POST['interface'];
306

    
307
		if ($_POST['proto'] != "any")
308
			$shaperent['protocol'] = $_POST['proto'];
309
		else
310
			unset($shaperent['protocol']);
311

    
312
		pconfig_to_address($shaperent['source'], $_POST['src'],
313
			$_POST['srcmask'], $_POST['srcnot'],
314
			$_POST['srcbeginport'], $_POST['srcendport']);
315

    
316
		pconfig_to_address($shaperent['destination'], $_POST['dst'],
317
			$_POST['dstmask'], $_POST['dstnot'],
318
			$_POST['dstbeginport'], $_POST['dstendport']);
319

    
320
		$shaperent['direction'] = $_POST['direction'];
321
		$shaperent['iplen'] = $_POST['iplen'];
322
		$shaperent['iptos'] = $_POST['iptos'];
323
		$shaperent['tcpflags'] = $_POST['tcpflags'];
324
		$shaperent['descr'] = $_POST['descr'];
325
		$shaperent['disabled'] = $_POST['disabled'] ? true : false;
326

    
327
		$shaperent['targetqueue'] = $_POST['target'];
328

    
329
		if (isset($id) && $a_shaper[$id])
330
			$a_shaper[$id] = $shaperent;
331
		else {
332
			if (is_numeric($after))
333
				array_splice($a_shaper, $after+1, 0, array($shaperent));
334
			else
335
				$a_shaper[] = $shaperent;
336
		}
337

    
338
		write_config();
339
		touch($d_shaperconfdirty_path);
340

    
341
		header("Location: firewall_shaper.php");
342
		exit;
343
	}
344
}
345
?>
346
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
347
<html>
348
<head>
349
<title><?=gentitle("Firewall: Traffic shaper: Edit rule");?></title>
350
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
351
<link href="gui.css" rel="stylesheet" type="text/css">
352
<script language="JavaScript">
353
<!--
354
var portsenabled = 1;
355

    
356
function ext_change() {
357
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
358
		document.iform.srcbeginport_cust.disabled = 0;
359
	} else {
360
		document.iform.srcbeginport_cust.value = "";
361
		document.iform.srcbeginport_cust.disabled = 1;
362
	}
363
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
364
		document.iform.srcendport_cust.disabled = 0;
365
	} else {
366
		document.iform.srcendport_cust.value = "";
367
		document.iform.srcendport_cust.disabled = 1;
368
	}
369
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
370
		document.iform.dstbeginport_cust.disabled = 0;
371
	} else {
372
		document.iform.dstbeginport_cust.value = "";
373
		document.iform.dstbeginport_cust.disabled = 1;
374
	}
375
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
376
		document.iform.dstendport_cust.disabled = 0;
377
	} else {
378
		document.iform.dstendport_cust.value = "";
379
		document.iform.dstendport_cust.disabled = 1;
380
	}
381

    
382
	if (!portsenabled) {
383
		document.iform.srcbeginport.disabled = 1;
384
		document.iform.srcendport.disabled = 1;
385
		document.iform.dstbeginport.disabled = 1;
386
		document.iform.dstendport.disabled = 1;
387
	} else {
388
		document.iform.srcbeginport.disabled = 0;
389
		document.iform.srcendport.disabled = 0;
390
		document.iform.dstbeginport.disabled = 0;
391
		document.iform.dstendport.disabled = 0;
392
	}
393
}
394

    
395
function typesel_change() {
396
	switch (document.iform.srctype.selectedIndex) {
397
		case 1:	/* single */
398
			document.iform.src.disabled = 0;
399
			document.iform.srcmask.value = "";
400
			document.iform.srcmask.disabled = 1;
401
			break;
402
		case 2:	/* network */
403
			document.iform.src.disabled = 0;
404
			document.iform.srcmask.disabled = 0;
405
			break;
406
		default:
407
			document.iform.src.value = "";
408
			document.iform.src.disabled = 1;
409
			document.iform.srcmask.value = "";
410
			document.iform.srcmask.disabled = 1;
411
			break;
412
	}
413
	switch (document.iform.dsttype.selectedIndex) {
414
		case 1:	/* single */
415
			document.iform.dst.disabled = 0;
416
			document.iform.dstmask.value = "";
417
			document.iform.dstmask.disabled = 1;
418
			break;
419
		case 2:	/* network */
420
			document.iform.dst.disabled = 0;
421
			document.iform.dstmask.disabled = 0;
422
			break;
423
		default:
424
			document.iform.dst.value = "";
425
			document.iform.dst.disabled = 1;
426
			document.iform.dstmask.value = "";
427
			document.iform.dstmask.disabled = 1;
428
			break;
429
	}
430
}
431

    
432
function proto_change() {
433
	if (document.iform.proto.selectedIndex < 2 || document.iform.proto.selectedIndex == 8) {
434
		portsenabled = 1;
435
	} else {
436
		portsenabled = 0;
437
	}
438

    
439
	ext_change();
440
}
441

    
442
function src_rep_change() {
443
	document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
444
}
445
function dst_rep_change() {
446
	document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
447
}
448
//-->
449
</script>
450
</head>
451

    
452
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
453
<?php include("fbegin.inc"); ?>
454
<p class="pgtitle">Firewall: Traffic shaper: Edit rule</p>
455
<?php if ($input_errors) print_input_errors($input_errors); ?>
456
<?php if (is_array($config['shaper']['queue']) && (count($config['shaper']['queue']) > 0)): ?>
457
            <form action="firewall_shaper_edit.php" method="post" name="iform" id="iform">
458
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
459
                <tr>
460
                  <td valign="top" class="vncellreq">Target</td>
461
                  <td class="vtable"> <select name="target" class="formfld">
462
                      <?php
463
					  foreach ($config['shaper']['queue'] as $queuei => $queue): ?>
464
                      <option value="<?=$queue['name'];?>" <?php if ($queue['name'] == $pconfig['targetqueue']) echo "selected"; ?>>
465
                        <?php
466
					  	echo htmlspecialchars("Queue " . ($queuei + 1));
467
						if ($queue['name'])
468
							echo htmlspecialchars(" (" . $queue['name'] . ")");
469
			?>
470
                      </option>
471
                      <?php endforeach; ?>
472
                    </select> <br>
473
                    <span class="vexpl">Choose a queue where packets that
474
                    match this rule should be sent.</span></td>
475
                </tr>
476
                <tr>
477
                  <td valign="top" class="vncellreq">Disabled</td>
478
                  <td class="vtable">
479
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
480
                    <strong>Disable this rule</strong><br>
481
                    <span class="vexpl">Set this option to disable this rule without removing it from the list.</span></td>
482
                </tr>
483
                <tr>
484
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
485
                  <td width="78%" class="vtable"> <select name="interface" class="formfld">
486
                      <?php $interfaces = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
487
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
488
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
489
					  }
490
					  foreach ($interfaces as $iface => $ifacename): ?>
491
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
492
                      <?=htmlspecialchars($ifacename);?>
493
                      </option>
494
                      <?php endforeach; ?>
495
                    </select> <br>
496
                    <span class="vexpl">Choose which interface packets must pass
497
                    through to match this rule.</span></td>
498
                </tr>
499
                <tr>
500
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
501
                  <td width="78%" class="vtable"> <select name="proto" class="formfld" onchange="proto_change()">
502
                      <?php $protocols = explode(" ", "TCP UDP ICMP ESP AH GRE IPv6 IGMP any"); foreach ($protocols as $proto): ?>
503
                      <option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>>
504
                      <?=htmlspecialchars($proto);?>
505
                      </option>
506
                      <?php endforeach; ?>
507
                    </select> <br> <span class="vexpl">Choose which IP protocol
508
                    this rule should match.<br>
509
                    Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span></td>
510
                </tr>
511
                <tr>
512
                  <td width="22%" valign="top" class="vncellreq">Source</td>
513
                  <td width="78%" class="vtable"> <input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
514
                    <strong>not</strong><br>
515
                    Use this option to invert the sense of the match.<br> <br>
516
                    <table border="0" cellspacing="0" cellpadding="0">
517
                      <tr>
518
                        <td>Type:&nbsp;&nbsp;</td>
519
                        <td><select name="srctype" class="formfld" onChange="typesel_change()">
520
                            <?php $sel = is_specialnet($pconfig['src']); ?>
521
                            <option value="any" <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>
522
                            any</option>
523
                            <option value="single" <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
524
                            Single host or alias</option>
525
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
526
                            Network</option>
527
                            <option value="lan" <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>
528
                            LAN subnet</option>
529
                            <option value="pptp" <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>
530
                            PPTP clients</option>
531
                            <?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
532
                            <option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>>
533
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?>
534
                            subnet</option>
535
                            <?php endfor; ?>
536
                          </select></td>
537
                      </tr>
538
                      <tr>
539
                        <td>Address:&nbsp;&nbsp;</td>
540
                        <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']);?>">
541
                          /
542
                          <select name="srcmask" class="formfld" id="srcmask">
543
                            <?php for ($i = 31; $i > 0; $i--): ?>
544
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>>
545
                            <?=$i;?>
546
                            </option>
547
                            <?php endfor; ?>
548
                          </select></td>
549
                      </tr>
550
                    </table></td>
551
                </tr>
552
                <tr>
553
                  <td width="22%" valign="top" class="vncellreq">Source port range
554
                  </td>
555
                  <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0">
556
                      <tr>
557
                        <td>from:&nbsp;&nbsp;</td>
558
                        <td><select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
559
                            <option value="">(other)</option>
560
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
561
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
562
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) {
563
																echo "selected";
564
																$bfound = 1;
565
															}?>>
566
                            <?=htmlspecialchars($wkportdesc);?>
567
                            </option>
568
                            <?php endforeach; ?>
569
                          </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>
570
                      </tr>
571
                      <tr>
572
                        <td>to:</td>
573
                        <td><select name="srcendport" class="formfld" onchange="ext_change()">
574
                            <option value="">(other)</option>
575
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
576
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
577
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) {
578
																echo "selected";
579
																$bfound = 1;
580
															}?>>
581
                            <?=htmlspecialchars($wkportdesc);?>
582
                            </option>
583
                            <?php endforeach; ?>
584
                          </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>
585
                      </tr>
586
                    </table>
587
                    <br> <span class="vexpl">Specify the port or port range for
588
                    the source of the packet for this rule.<br>
589
                    Hint: you can leave the <em>'to'</em> field empty if you only
590
                    want to filter a single port</span></td>
591
                <tr>
592
                  <td width="22%" valign="top" class="vncellreq">Destination</td>
593
                  <td width="78%" class="vtable"> <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
594
                    <strong>not</strong><br>
595
                    Use this option to invert the sense of the match.<br> <br>
596
                    <table border="0" cellspacing="0" cellpadding="0">
597
                      <tr>
598
                        <td>Type:&nbsp;&nbsp;</td>
599
                        <td><select name="dsttype" class="formfld" onChange="typesel_change()">
600
                            <?php $sel = is_specialnet($pconfig['dst']); ?>
601
                            <option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
602
                            any</option>
603
                            <option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
604
                            Single host or alias</option>
605
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
606
                            Network</option>
607
                            <option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
608
                            LAN subnet</option>
609
                            <option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
610
                            PPTP clients</option>
611
                            <?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
612
                            <option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
613
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?>
614
                            subnet</option>
615
                            <?php endfor; ?>
616
                          </select> </td>
617
                      </tr>
618
                      <tr>
619
                        <td>Address:&nbsp;&nbsp;</td>
620
                        <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']);?>">
621
                          /
622
                          <select name="dstmask" class="formfld" id="dstmask">
623
                            <?php for ($i = 31; $i > 0; $i--): ?>
624
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>>
625
                            <?=$i;?>
626
                            </option>
627
                            <?php endfor; ?>
628
                          </select></td>
629
                      </tr>
630
                    </table></td>
631
                </tr>
632
                <tr>
633
                  <td width="22%" valign="top" class="vncellreq">Destination port
634
                    range </td>
635
                  <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0">
636
                      <tr>
637
                        <td>from:&nbsp;&nbsp;</td>
638
                        <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
639
                            <option value="">(other)</option>
640
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
641
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
642
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
643
																echo "selected";
644
																$bfound = 1;
645
															}?>>
646
                            <?=htmlspecialchars($wkportdesc);?>
647
                            </option>
648
                            <?php endforeach; ?>
649
                          </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>
650
                      </tr>
651
                      <tr>
652
                        <td>to:</td>
653
                        <td><select name="dstendport" class="formfld" onchange="ext_change()">
654
                            <option value="">(other)</option>
655
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
656
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
657
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
658
																echo "selected";
659
																$bfound = 1;
660
															}?>>
661
                            <?=htmlspecialchars($wkportdesc);?>
662
                            </option>
663
                            <?php endforeach; ?>
664
                          </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>
665
                      </tr>
666
                    </table>
667
                    <br> <span class="vexpl">Specify the port or port range for
668
                    the destination of the packet for this rule.<br>
669
                    Hint: you can leave the <em>'to'</em> field empty if you only
670
                    want to filter a single port</span></td>
671
                <tr>
672
                  <td valign="top" class="vncell">Direction</td>
673
                  <td class="vtable"> <select name="direction" class="formfld">
674
                      <option value="" <?php if (!$pconfig['direction']) echo "selected"; ?>>any</option>
675
                      <option value="in" <?php if ($pconfig['direction'] == "in") echo "selected"; ?>>in</option>
676
                      <option value="out" <?php if ($pconfig['direction'] == "out") echo "selected"; ?>>out</option>
677
                    </select> <br>
678
                    Use this to match only packets travelling in a given direction
679
                    on the interface specified above (as seen from the firewall's
680
                    perspective). </td>
681
                </tr>
682
				<tr>
683
                  <td width="22%" valign="top" class="vncell">IP Type of Service (TOS)</td>
684
                  <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0">
685
                      <?php
686
				  $iniptos = explode(",", $pconfig['iptos']);
687
				  foreach ($iptos as $tos): $dontcare = true; ?>
688
                      <tr>
689
                        <td width="80" nowrap><strong>
690
			  <?echo $tos;?>
691
                          </strong></td>
692
                        <td nowrap> <input type="radio" name="iptos_<?=$tos;?>" value="on" <?php if (array_search($tos, $iniptos) !== false) { echo "checked"; $dontcare = false; }?>>
693
                          yes&nbsp;&nbsp;&nbsp;</td>
694
                        <td nowrap> <input type="radio" name="iptos_<?=$tos;?>" value="off" <?php if (array_search("!" . $tos, $iniptos) !== false) { echo "checked"; $dontcare = false; }?>>
695
                          no&nbsp;&nbsp;&nbsp;</td>
696
                        <td nowrap> <input type="radio" name="iptos_<?=$tos;?>" value="" <?php if ($dontcare) echo "checked";?>>
697
                          don't care</td>
698
                      </tr>
699
                      <?php endforeach; ?>
700
                    </table>
701
                    <span class="vexpl">Use this to match packets according to their IP TOS values.
702
                    </span></td>
703
                </tr>
704
                <tr>
705
                  <td width="22%" valign="top" class="vncell">IP packet length</td>
706
                  <td width="78%" class="vtable"><input name="iplen" type="text" id="iplen" size="10" value="<?=htmlspecialchars($pconfig['iplen']);?>">
707
                    <br>
708
                    Setting this makes the rule match packets of a given length
709
                    (either a single value or a range in the syntax <em>from-to</em>,
710
                    e.g. 0-80). </td>
711
                </tr>
712
                <tr>
713
                  <td width="22%" valign="top" class="vncell">TCP flags</td>
714
                  <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0">
715
                      <?php
716
				  $inflags = explode(",", $pconfig['tcpflags']);
717
				  foreach ($tcpflags as $tcpflag): $dontcare = true; ?>
718
                      <tr>
719
                        <td width="40" nowrap><strong>
720
                          <?=strtoupper($tcpflag);?>
721
                          </strong></td>
722
                        <td nowrap> <input type="radio" name="tcpflags_<?=$tcpflag;?>" value="on" <?php if (array_search($tcpflag, $inflags) !== false) { echo "checked"; $dontcare = false; }?>>
723
                          set&nbsp;&nbsp;&nbsp;</td>
724
                        <td nowrap> <input type="radio" name="tcpflags_<?=$tcpflag;?>" value="off" <?php if (array_search("!" . $tcpflag, $inflags) !== false) { echo "checked"; $dontcare = false; }?>>
725
                          cleared&nbsp;&nbsp;&nbsp;</td>
726
                        <td nowrap> <input type="radio" name="tcpflags_<?=$tcpflag;?>" value="" <?php if ($dontcare) echo "checked";?>>
727
                          don't care</td>
728
                      </tr>
729
                      <?php endforeach; ?>
730
                    </table>
731
                    <span class="vexpl">Use this to choose TCP flags that must
732
                    be set or cleared for this rule to match.</span></td>
733
                </tr>
734
                <tr>
735
                  <td width="22%" valign="top" class="vncell">Description</td>
736
                  <td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
737
                    <br> <span class="vexpl">You may enter a description here
738
                    for your reference (not parsed).</span></td>
739
                </tr>
740
                <tr>
741
                  <td width="22%" valign="top">&nbsp;</td>
742
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
743
                    <?php if (isset($id) && $a_shaper[$id]): ?>
744
                    <input name="id" type="hidden" value="<?=$id;?>">
745
                    <?php endif; ?>
746
					<input name="after" type="hidden" value="<?=$after;?>">
747
                  </td>
748
                </tr>
749
              </table>
750
</form>
751
<script language="JavaScript">
752
<!--
753
ext_change();
754
typesel_change();
755
proto_change();
756
-->
757
</script>
758
<?php else: ?>
759
<p><strong>You need to create a queue before you can add a new rule.</strong></p>
760
<?php endif; ?>
761
<?php
762
$isfirst = 0;
763
$aliases = "";
764
$addrisfirst = 0;
765
$aliasesaddr = "";
766
if(is_array($config['aliases']['alias'])) {
767
	foreach($config['aliases']['alias'] as $alias_name) {
768
		if(!stristr($alias_name['address'], ".")) {
769
			if($isfirst == 1) $aliases .= ",";
770
			$aliases .= "'" . $alias_name['name'] . "'";
771
			$isfirst = 1;
772
		} else {
773
			if($addrisfirst == 1) $aliasesaddr .= ",";
774
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
775
			$addrisfirst = 1;
776
		}
777
	}
778
}
779
?>
780

    
781
<script language="JavaScript">
782
<!--
783
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
784
var customarray=new Array(<?php echo $aliases; ?>);
785
//-->
786
</script>
787
<script type="text/javascript" language="javascript" src="auto_complete_helper.js">
788
</script>
789
<?php include("fend.inc"); ?>
790
</body>
791
</html>
(36-36/111)