Project

General

Profile

Download (34.1 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	firewall_shaper_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

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

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

    
32
require("guiconfig.inc");
33

    
34
if (!is_array($config['shaper']['rule'])) {
35
	$config['shaper']['rule'] = array();
36
}
37
$a_shaper = &$config['shaper']['rule'];
38

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

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

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

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

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

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

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

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

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

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

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

    
92
	$adr = array();
93

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

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

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

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

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

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

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

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

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

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

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

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

    
157
if ($_POST) {
158

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
438
	ext_change();
439
}
440

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

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

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