Project

General

Profile

Download (33.6 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['inqueue'] = $a_shaper[$id]['inqueue'];
72
	$pconfig['outqueue'] = $a_shaper[$id]['outqueue'];
73

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

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

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

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

    
99
if ($_POST) {
100

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

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

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

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

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

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

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

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

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

    
173
	/* input validation */
174
	$reqdfields = explode(" ", "inqueue outqueue proto src dst");
175
	$reqdfieldsn = explode(",", "Inbound Queue,Outbound Queue,Protocol,Source,Destination");
176

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

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

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

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

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

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

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

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

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

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

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

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

    
268
		$shaperent['inqueue'] = $_POST['inqueue'];
269
		$shaperent['outqueue'] = $_POST['outqueue'];
270

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

    
280
		write_config();
281
		touch($d_shaperconfdirty_path);
282

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

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

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

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

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

    
381
	ext_change();
382
}
383

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

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

    
733
<script language="JavaScript">
734
<!--
735
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
736
var customarray=new Array(<?php echo $aliases; ?>);
737
//-->
738
</script>
739
<script type="text/javascript" language="javascript" src="auto_complete_helper.js">
740
</script>
741
<?php include("fend.inc"); ?>
742
</body>
743
</html>
(39-39/117)