Project

General

Profile

Download (30.9 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
    firewall_shaper_edit.php
5
    Copyright (C) 2004, 2005 Scott Ullrich
6
    All rights reserved.
7

    
8
    Originally part of m0n0wall (http://m0n0.ch/wall)
9
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
    All rights reserved.
11

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

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

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

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

    
34
require("guiconfig.inc");
35

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

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

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

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

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

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

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

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

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

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

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

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

    
94
	$adr = array();
95

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

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

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

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

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

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

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

    
132
		$pconfig['target'] =  $a_shaper[$id]['targetqueue'];
133

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

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

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

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

    
159
if ($_POST) {
160

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
328
		list($targettype,$target) = explode(":", $_POST['target']);
329
		$shaperent[$targettype] = $target;
330

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

    
340
		write_config();
341
		touch($d_shaperconfdirty_path);
342

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

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

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

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

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

    
441
	ext_change();
442
}
443

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

    
454
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
455
<?php include("fbegin.inc"); ?>
456
<p class="pgtitle">Firewall: Traffic shaper: Edit rule</p>
457
<?php if ($input_errors) print_input_errors($input_errors); ?>
458
<?php if (is_array($config['shaper']['queue']) > 0): ?>
459

    
460
            <form action="firewall_shaper_edit.php" method="post" name="iform" id="iform">
461
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
462
                <tr>
463
                  <td valign="top" class="vncellreq">Target</td>
464
                  <td class="vtable"> <select name="target" class="formfld">
465
                      <?php
466
					  foreach ($config['shaper']['queue'] as $queuei => $queue): ?>
467
                      <option value="<?="$queuei";?>" <?php if ("$queuei" == $pconfig['target']) echo "selected"; ?>>
468
                      <?php
469
					  	echo htmlspecialchars("Queue " . ($queuei + 1));
470
						if ($queue['name'])
471
							echo htmlspecialchars(" (" . $queue['name'] . ")");
472
					  ?>
473
                      </option>
474
                      <?php endforeach; ?>
475
                    </select> <br>
476
                    <span class="vexpl">Choose a pipe or queue where packets that
477
                    match this rule should be sent.</span></td>
478
                </tr>
479
                <tr>
480
                  <td valign="top" class="vncellreq">Disabled</td>
481
                  <td class="vtable">
482
                    <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
483
                    <strong>Disable this rule</strong><br>
484
                    <span class="vexpl">Set this option to disable this rule without removing it from the list.</span></td>
485
                </tr>
486
                <tr>
487
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
488
                  <td width="78%" class="vtable"> <select name="interface" class="formfld">
489
                      <?php $interfaces = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
490
					  for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
491
					  	$interfaces['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
492
					  }
493
					  foreach ($interfaces as $iface => $ifacename): ?>
494
                      <option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
495
                      <?=htmlspecialchars($ifacename);?>
496
                      </option>
497
                      <?php endforeach; ?>
498
                    </select> <br>
499
                    <span class="vexpl">Choose which interface packets must pass
500
                    through to match this rule.</span></td>
501
                </tr>
502
                <tr>
503
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
504
                  <td width="78%" class="vtable"> <select name="proto" class="formfld" onchange="proto_change()">
505
                      <?php $protocols = explode(" ", "TCP UDP ICMP ESP AH GRE IPv6 IGMP any"); foreach ($protocols as $proto): ?>
506
                      <option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>>
507
                      <?=htmlspecialchars($proto);?>
508
                      </option>
509
                      <?php endforeach; ?>
510
                    </select> <br> <span class="vexpl">Choose which IP protocol
511
                    this rule should match.<br>
512
                    Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span></td>
513
                </tr>
514
                <tr>
515
                  <td width="22%" valign="top" class="vncellreq">Source</td>
516
                  <td width="78%" class="vtable"> <input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
517
                    <strong>not</strong><br>
518
                    Use this option to invert the sense of the match.<br> <br>
519
                    <table border="0" cellspacing="0" cellpadding="0">
520
                      <tr>
521
                        <td>Type:&nbsp;&nbsp;</td>
522
                        <td><select name="srctype" class="formfld" onChange="typesel_change()">
523
                            <?php $sel = is_specialnet($pconfig['src']); ?>
524
                            <option value="any" <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>
525
                            any</option>
526
                            <option value="single" <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
527
                            Single host or alias</option>
528
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
529
                            Network</option>
530
                            <option value="lan" <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>
531
                            LAN subnet</option>
532
                            <option value="pptp" <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>
533
                            PPTP clients</option>
534
                            <?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
535
                            <option value="opt<?=$i;?>" <?php if ($pconfig['src'] == "opt" . $i) { echo "selected"; } ?>>
536
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?>
537
                            subnet</option>
538
                            <?php endfor; ?>
539
                          </select></td>
540
                      </tr>
541
                      <tr>
542
                        <td>Address:&nbsp;&nbsp;</td>
543
                        <td><input name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>">
544
                          /
545
                          <select name="srcmask" class="formfld" id="srcmask">
546
                            <?php for ($i = 31; $i > 0; $i--): ?>
547
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>>
548
                            <?=$i;?>
549
                            </option>
550
                            <?php endfor; ?>
551
                          </select></td>
552
                      </tr>
553
                    </table></td>
554
                </tr>
555
                <tr>
556
                  <td width="22%" valign="top" class="vncellreq">Source port range
557
                  </td>
558
                  <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0">
559
                      <tr>
560
                        <td>from:&nbsp;&nbsp;</td>
561
                        <td><select name="srcbeginport" class="formfld" onchange="src_rep_change();ext_change()">
562
                            <option value="">(other)</option>
563
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
564
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
565
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) {
566
																echo "selected";
567
																$bfound = 1;
568
															}?>>
569
                            <?=htmlspecialchars($wkportdesc);?>
570
                            </option>
571
                            <?php endforeach; ?>
572
                          </select> <input name="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>"></td>
573
                      </tr>
574
                      <tr>
575
                        <td>to:</td>
576
                        <td><select name="srcendport" class="formfld" onchange="ext_change()">
577
                            <option value="">(other)</option>
578
                            <option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
579
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
580
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) {
581
																echo "selected";
582
																$bfound = 1;
583
															}?>>
584
                            <?=htmlspecialchars($wkportdesc);?>
585
                            </option>
586
                            <?php endforeach; ?>
587
                          </select> <input name="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>"></td>
588
                      </tr>
589
                    </table>
590
                    <br> <span class="vexpl">Specify the port or port range for
591
                    the source of the packet for this rule.<br>
592
                    Hint: you can leave the <em>'to'</em> field empty if you only
593
                    want to filter a single port</span></td>
594
                <tr>
595
                  <td width="22%" valign="top" class="vncellreq">Destination</td>
596
                  <td width="78%" class="vtable"> <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
597
                    <strong>not</strong><br>
598
                    Use this option to invert the sense of the match.<br> <br>
599
                    <table border="0" cellspacing="0" cellpadding="0">
600
                      <tr>
601
                        <td>Type:&nbsp;&nbsp;</td>
602
                        <td><select name="dsttype" class="formfld" onChange="typesel_change()">
603
                            <?php $sel = is_specialnet($pconfig['dst']); ?>
604
                            <option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>
605
                            any</option>
606
                            <option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>
607
                            Single host or alias</option>
608
                            <option value="network" <?php if (!$sel) echo "selected"; ?>>
609
                            Network</option>
610
                            <option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>
611
                            LAN subnet</option>
612
                            <option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>
613
                            PPTP clients</option>
614
                            <?php for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++): ?>
615
                            <option value="opt<?=$i;?>" <?php if ($pconfig['dst'] == "opt" . $i) { echo "selected"; } ?>>
616
                            <?=htmlspecialchars($config['interfaces']['opt' . $i]['descr']);?>
617
                            subnet</option>
618
                            <?php endfor; ?>
619
                          </select> </td>
620
                      </tr>
621
                      <tr>
622
                        <td>Address:&nbsp;&nbsp;</td>
623
                        <td><input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
624
                          /
625
                          <select name="dstmask" class="formfld" id="dstmask">
626
                            <?php for ($i = 31; $i > 0; $i--): ?>
627
                            <option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>>
628
                            <?=$i;?>
629
                            </option>
630
                            <?php endfor; ?>
631
                          </select></td>
632
                      </tr>
633
                    </table></td>
634
                </tr>
635
                <tr>
636
                  <td width="22%" valign="top" class="vncellreq">Destination port
637
                    range </td>
638
                  <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0">
639
                      <tr>
640
                        <td>from:&nbsp;&nbsp;</td>
641
                        <td><select name="dstbeginport" class="formfld" onchange="dst_rep_change();ext_change()">
642
                            <option value="">(other)</option>
643
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
644
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
645
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) {
646
																echo "selected";
647
																$bfound = 1;
648
															}?>>
649
                            <?=htmlspecialchars($wkportdesc);?>
650
                            </option>
651
                            <?php endforeach; ?>
652
                          </select> <input name="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>"></td>
653
                      </tr>
654
                      <tr>
655
                        <td>to:</td>
656
                        <td><select name="dstendport" class="formfld" onchange="ext_change()">
657
                            <option value="">(other)</option>
658
                            <option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
659
                            <?php foreach ($wkports as $wkport => $wkportdesc): ?>
660
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) {
661
																echo "selected";
662
																$bfound = 1;
663
															}?>>
664
                            <?=htmlspecialchars($wkportdesc);?>
665
                            </option>
666
                            <?php endforeach; ?>
667
                          </select> <input name="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>"></td>
668
                      </tr>
669
                    </table>
670
                    <br> <span class="vexpl">Specify the port or port range for
671
                    the destination of the packet for this rule.<br>
672
                    Hint: you can leave the <em>'to'</em> field empty if you only
673
                    want to filter a single port</span></td>
674
                <tr>
675
                  <td valign="top" class="vncell">Direction</td>
676
                  <td class="vtable"> <select name="direction" class="formfld">
677
                      <option value="" <?php if (!$pconfig['direction']) echo "selected"; ?>>any</option>
678
                      <option value="in" <?php if ($pconfig['direction'] == "in") echo "selected"; ?>>in</option>
679
                      <option value="out" <?php if ($pconfig['direction'] == "out") echo "selected"; ?>>out</option>
680
                    </select> <br>
681
                    Use this to match only packets travelling in a given direction
682
                    on the interface specified above (as seen from the firewall's
683
                    perspective). </td>
684
                </tr>
685

    
686

    
687
                <tr>
688
                  <td width="22%" valign="top" class="vncell">IP packet length</td>
689
                  <td width="78%" class="vtable"><input name="iplen" type="text" id="iplen" size="10" value="<?=htmlspecialchars($pconfig['iplen']);?>">
690
                    <br>
691
                    Setting this makes the rule match packets of a given length
692
                    (either a single value or a range in the syntax <em>from-to</em>,
693
                    e.g. 0-80). </td>
694
                </tr>
695
                <tr>
696
                  <td width="22%" valign="top" class="vncell">TCP flags</td>
697
                  <td width="78%" class="vtable"> <table border="0" cellspacing="0" cellpadding="0">
698
                      <?php
699
				  $inflags = explode(",", $pconfig['tcpflags']);
700
				  foreach ($tcpflags as $tcpflag): $dontcare = true; ?>
701
                      <tr>
702
                        <td width="40" nowrap><strong>
703
                          <?=strtoupper($tcpflag);?>
704
                          </strong></td>
705
                        <td nowrap> <input type="radio" name="tcpflags_<?=$tcpflag;?>" value="on" <?php if (array_search($tcpflag, $inflags) !== false) { echo "checked"; $dontcare = false; }?>>
706
                          set&nbsp;&nbsp;&nbsp;</td>
707
                        <td nowrap> <input type="radio" name="tcpflags_<?=$tcpflag;?>" value="off" <?php if (array_search("!" . $tcpflag, $inflags) !== false) { echo "checked"; $dontcare = false; }?>>
708
                          cleared&nbsp;&nbsp;&nbsp;</td>
709
                        <td nowrap> <input type="radio" name="tcpflags_<?=$tcpflag;?>" value="" <?php if ($dontcare) echo "checked";?>>
710
                          don't care</td>
711
                      </tr>
712
                      <?php endforeach; ?>
713
                    </table>
714
                    <span class="vexpl">Use this to choose TCP flags that must
715
                    be set or cleared for this rule to match.</span></td>
716
                </tr>
717
                <tr>
718
                  <td width="22%" valign="top" class="vncell">Description</td>
719
                  <td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
720
                    <br> <span class="vexpl">You may enter a description here
721
                    for your reference (not parsed).</span></td>
722
                </tr>
723
                <tr>
724
                  <td width="22%" valign="top">&nbsp;</td>
725
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
726
                    <?php if (isset($id) && $a_shaper[$id]): ?>
727
                    <input name="id" type="hidden" value="<?=$id;?>">
728
                    <?php endif; ?>
729
					<input name="after" type="hidden" value="<?=$after;?>">
730
                  </td>
731
                </tr>
732
              </table>
733
</form>
734
<script language="JavaScript">
735
<!--
736
ext_change();
737
typesel_change();
738
proto_change();
739
//-->
740
</script>
741
<?php else: ?>
742
<p><strong>You need to create a queue before you can add a new rule.</strong></p>
743
<?php endif; ?>
744
<?php include("fend.inc"); ?>
745
</body>
746
</html>
(32-32/99)