Project

General

Profile

Download (33 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
if (isset($id) && $a_shaper[$id]) {
56
	$pconfig['interface'] = $a_shaper[$id]['interface'];
57

    
58
	if (isset($a_shaper[$id]['protocol']))
59
		$pconfig['proto'] = $a_shaper[$id]['protocol'];
60
	else
61
		$pconfig['proto'] = "any";
62

    
63
	address_to_pconfig($a_shaper[$id]['source'], $pconfig['src'],
64
		$pconfig['srcmask'], $pconfig['srcnot'],
65
		$pconfig['srcbeginport'], $pconfig['srcendport']);
66

    
67
	address_to_pconfig($a_shaper[$id]['destination'], $pconfig['dst'],
68
		$pconfig['dstmask'], $pconfig['dstnot'],
69
		$pconfig['dstbeginport'], $pconfig['dstendport']);
70

    
71
	$pconfig['targetqueue'] = $a_shaper[$id]['targetqueue'];
72

    
73
	$pconfig['direction'] = $a_shaper[$id]['direction'];
74
	$pconfig['iptos'] = $a_shaper[$id]['iptos'];
75
	$pconfig['iplen'] = $a_shaper[$id]['iplen'];
76
	$pconfig['tcpflags'] = $a_shaper[$id]['tcpflags'];
77
	$pconfig['descr'] = $a_shaper[$id]['descr'];
78
	$pconfig['disabled'] = isset($a_shaper[$id]['disabled']);
79

    
80
	if ($pconfig['srcbeginport'] == 0) {
81
		$pconfig['srcbeginport'] = "any";
82
		$pconfig['srcendport'] = "any";
83
	}
84
	if ($pconfig['dstbeginport'] == 0) {
85
		$pconfig['dstbeginport'] = "any";
86
		$pconfig['dstendport'] = "any";
87
	}
88

    
89
} else {
90
	/* defaults */
91
	$pconfig['src'] = "any";
92
	$pconfig['dst'] = "any";
93
}
94

    
95
if (isset($_GET['dup']))
96
	unset($id);
97

    
98
if ($_POST) {
99

    
100
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "any")) {
101
		$_POST['srcbeginport'] = 0;
102
		$_POST['srcendport'] = 0;
103
		$_POST['dstbeginport'] = 0;
104
		$_POST['dstendport'] = 0;
105
	} else {
106

    
107
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
108
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
109
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
110
			$_POST['srcendport'] = $_POST['srcendport_cust'];
111

    
112
		if ($_POST['srcbeginport'] == "any") {
113
			$_POST['srcbeginport'] = 0;
114
			$_POST['srcendport'] = 0;
115
		} else {
116
			if (!$_POST['srcendport'])
117
				$_POST['srcendport'] = $_POST['srcbeginport'];
118
		}
119
		if ($_POST['srcendport'] == "any")
120
			$_POST['srcendport'] = $_POST['srcbeginport'];
121

    
122
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
123
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
124
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
125
			$_POST['dstendport'] = $_POST['dstendport_cust'];
126

    
127
		if ($_POST['dstbeginport'] == "any") {
128
			$_POST['dstbeginport'] = 0;
129
			$_POST['dstendport'] = 0;
130
		} else {
131
			if (!$_POST['dstendport'])
132
				$_POST['dstendport'] = $_POST['dstbeginport'];
133
		}
134
		if ($_POST['dstendport'] == "any")
135
			$_POST['dstendport'] = $_POST['dstbeginport'];
136
	}
137

    
138
	if (is_specialnet($_POST['srctype'])) {
139
		$_POST['src'] = $_POST['srctype'];
140
		$_POST['srcmask'] = 0;
141
	} else if ($_POST['srctype'] == "single") {
142
		$_POST['srcmask'] = 32;
143
	}
144
	if (is_specialnet($_POST['dsttype'])) {
145
		$_POST['dst'] = $_POST['dsttype'];
146
		$_POST['dstmask'] = 0;
147
	}  else if ($_POST['dsttype'] == "single") {
148
		$_POST['dstmask'] = 32;
149
	}
150

    
151
	$intos = array();
152
	foreach ($iptos as $tos) {
153
		if ($_POST['iptos_' . $tos] == "on")
154
			$intos[] = $tos;
155
		else if ($_POST['iptos_' . $tos] == "off")
156
			$intos[] = "!" . $tos;
157
	}
158
	$_POST['iptos'] = join(",", $intos);
159

    
160
	$intcpflags = array();
161
	foreach ($tcpflags as $tcpflag) {
162
		if ($_POST['tcpflags_' . $tcpflag] == "on")
163
			$intcpflags[] = $tcpflag;
164
		else if ($_POST['tcpflags_' . $tcpflag] == "off")
165
			$intcpflags[] = "!" . $tcpflag;
166
	}
167
	$_POST['tcpflags'] = join(",", $intcpflags);
168

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

    
172
	/* input validation */
173
	$reqdfields = explode(" ", "target proto src dst");
174
	$reqdfieldsn = explode(",", "Target,Protocol,Source,Destination");
175

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

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

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

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

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

    
226
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
227
		/* swap */
228
		$tmp = $_POST['srcendport'];
229
		$_POST['srcendport'] = $_POST['srcbeginport'];
230
		$_POST['srcbeginport'] = $tmp;
231
	}
232
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
233
		/* swap */
234
		$tmp = $_POST['dstendport'];
235
		$_POST['dstendport'] = $_POST['dstbeginport'];
236
		$_POST['dstbeginport'] = $tmp;
237
	}
238

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

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

    
247
		if ($_POST['proto'] != "any")
248
			$shaperent['protocol'] = $_POST['proto'];
249
		else
250
			unset($shaperent['protocol']);
251

    
252
		pconfig_to_address($shaperent['source'], $_POST['src'],
253
			$_POST['srcmask'], $_POST['srcnot'],
254
			$_POST['srcbeginport'], $_POST['srcendport']);
255

    
256
		pconfig_to_address($shaperent['destination'], $_POST['dst'],
257
			$_POST['dstmask'], $_POST['dstnot'],
258
			$_POST['dstbeginport'], $_POST['dstendport']);
259

    
260
		$shaperent['direction'] = $_POST['direction'];
261
		$shaperent['iplen'] = $_POST['iplen'];
262
		$shaperent['iptos'] = $_POST['iptos'];
263
		$shaperent['tcpflags'] = $_POST['tcpflags'];
264
		$shaperent['descr'] = $_POST['descr'];
265
		$shaperent['disabled'] = $_POST['disabled'] ? true : false;
266

    
267
		$shaperent['targetqueue'] = $_POST['target'];
268

    
269
		if (isset($id) && $a_shaper[$id])
270
			$a_shaper[$id] = $shaperent;
271
		else {
272
			if (is_numeric($after))
273
				array_splice($a_shaper, $after+1, 0, array($shaperent));
274
			else
275
				$a_shaper[] = $shaperent;
276
		}
277

    
278
		write_config();
279
		touch($d_shaperconfdirty_path);
280

    
281
		header("Location: firewall_shaper.php");
282
		exit;
283
	}
284
}
285
?>
286
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
287
<html>
288
<head>
289
<title><?=gentitle("Firewall: Traffic shaper: Edit rule");?></title>
290
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
291
<link href="gui.css" rel="stylesheet" type="text/css">
292
<script language="JavaScript">
293
<!--
294
var portsenabled = 1;
295

    
296
function ext_change() {
297
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
298
		document.iform.srcbeginport_cust.disabled = 0;
299
	} else {
300
		document.iform.srcbeginport_cust.value = "";
301
		document.iform.srcbeginport_cust.disabled = 1;
302
	}
303
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
304
		document.iform.srcendport_cust.disabled = 0;
305
	} else {
306
		document.iform.srcendport_cust.value = "";
307
		document.iform.srcendport_cust.disabled = 1;
308
	}
309
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
310
		document.iform.dstbeginport_cust.disabled = 0;
311
	} else {
312
		document.iform.dstbeginport_cust.value = "";
313
		document.iform.dstbeginport_cust.disabled = 1;
314
	}
315
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
316
		document.iform.dstendport_cust.disabled = 0;
317
	} else {
318
		document.iform.dstendport_cust.value = "";
319
		document.iform.dstendport_cust.disabled = 1;
320
	}
321

    
322
	if (!portsenabled) {
323
		document.iform.srcbeginport.disabled = 1;
324
		document.iform.srcendport.disabled = 1;
325
		document.iform.dstbeginport.disabled = 1;
326
		document.iform.dstendport.disabled = 1;
327
	} else {
328
		document.iform.srcbeginport.disabled = 0;
329
		document.iform.srcendport.disabled = 0;
330
		document.iform.dstbeginport.disabled = 0;
331
		document.iform.dstendport.disabled = 0;
332
	}
333
}
334

    
335
function typesel_change() {
336
	switch (document.iform.srctype.selectedIndex) {
337
		case 1:	/* single */
338
			document.iform.src.disabled = 0;
339
			document.iform.srcmask.value = "";
340
			document.iform.srcmask.disabled = 1;
341
			break;
342
		case 2:	/* network */
343
			document.iform.src.disabled = 0;
344
			document.iform.srcmask.disabled = 0;
345
			break;
346
		default:
347
			document.iform.src.value = "";
348
			document.iform.src.disabled = 1;
349
			document.iform.srcmask.value = "";
350
			document.iform.srcmask.disabled = 1;
351
			break;
352
	}
353
	switch (document.iform.dsttype.selectedIndex) {
354
		case 1:	/* single */
355
			document.iform.dst.disabled = 0;
356
			document.iform.dstmask.value = "";
357
			document.iform.dstmask.disabled = 1;
358
			break;
359
		case 2:	/* network */
360
			document.iform.dst.disabled = 0;
361
			document.iform.dstmask.disabled = 0;
362
			break;
363
		default:
364
			document.iform.dst.value = "";
365
			document.iform.dst.disabled = 1;
366
			document.iform.dstmask.value = "";
367
			document.iform.dstmask.disabled = 1;
368
			break;
369
	}
370
}
371

    
372
function proto_change() {
373
	if (document.iform.proto.selectedIndex < 2 || document.iform.proto.selectedIndex == 8) {
374
		portsenabled = 1;
375
	} else {
376
		portsenabled = 0;
377
	}
378

    
379
	ext_change();
380
}
381

    
382
function src_rep_change() {
383
	document.iform.srcendport.selectedIndex = document.iform.srcbeginport.selectedIndex;
384
}
385
function dst_rep_change() {
386
	document.iform.dstendport.selectedIndex = document.iform.dstbeginport.selectedIndex;
387
}
388
//-->
389
</script>
390
</head>
391

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

    
721
<script language="JavaScript">
722
<!--
723
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
724
var customarray=new Array(<?php echo $aliases; ?>);
725
//-->
726
</script>
727
<script type="text/javascript" language="javascript" src="auto_complete_helper.js">
728
</script>
729
<?php include("fend.inc"); ?>
730
</body>
731
</html>
(38-38/115)