Project

General

Profile

Download (32.9 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
	if (isset($a_shaper[$id]['targetpipe'])) {
131
		$pconfig['target'] = "targetpipe:" . $a_shaper[$id]['targetpipe'];
132
	} else if (isset($a_shaper[$id]['targetqueue'])) {
133
		$pconfig['target'] = "targetqueue:" . $a_shaper[$id]['targetqueue'];
134
	}
135
	
136
	$pconfig['direction'] = $a_shaper[$id]['direction'];
137
	$pconfig['iptos'] = $a_shaper[$id]['iptos'];
138
	$pconfig['iplen'] = $a_shaper[$id]['iplen'];
139
	$pconfig['tcpflags'] = $a_shaper[$id]['tcpflags'];
140
	$pconfig['descr'] = $a_shaper[$id]['descr'];
141
	$pconfig['disabled'] = isset($a_shaper[$id]['disabled']);
142
	
143
	if ($pconfig['srcbeginport'] == 0) {
144
		$pconfig['srcbeginport'] = "any";
145
		$pconfig['srcendport'] = "any";
146
	}
147
	if ($pconfig['dstbeginport'] == 0) {
148
		$pconfig['dstbeginport'] = "any";
149
		$pconfig['dstendport'] = "any";
150
	}
151
	
152
} else {
153
	/* defaults */
154
	$pconfig['src'] = "any";
155
	$pconfig['dst'] = "any";
156
}
157

    
158
if (isset($_GET['dup']))
159
	unset($id);
160

    
161
if ($_POST) {
162

    
163
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "any")) {
164
		$_POST['srcbeginport'] = 0;
165
		$_POST['srcendport'] = 0;
166
		$_POST['dstbeginport'] = 0;
167
		$_POST['dstendport'] = 0;
168
	} else {
169
	
170
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
171
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
172
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
173
			$_POST['srcendport'] = $_POST['srcendport_cust'];
174
	
175
		if ($_POST['srcbeginport'] == "any") {
176
			$_POST['srcbeginport'] = 0;
177
			$_POST['srcendport'] = 0;
178
		} else {			
179
			if (!$_POST['srcendport'])
180
				$_POST['srcendport'] = $_POST['srcbeginport'];
181
		}
182
		if ($_POST['srcendport'] == "any")
183
			$_POST['srcendport'] = $_POST['srcbeginport'];
184
		
185
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
186
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
187
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
188
			$_POST['dstendport'] = $_POST['dstendport_cust'];
189
		
190
		if ($_POST['dstbeginport'] == "any") {
191
			$_POST['dstbeginport'] = 0;
192
			$_POST['dstendport'] = 0;
193
		} else {			
194
			if (!$_POST['dstendport'])
195
				$_POST['dstendport'] = $_POST['dstbeginport'];
196
		}
197
		if ($_POST['dstendport'] == "any")
198
			$_POST['dstendport'] = $_POST['dstbeginport'];		
199
	}
200
		
201
	if (is_specialnet($_POST['srctype'])) {
202
		$_POST['src'] = $_POST['srctype'];
203
		$_POST['srcmask'] = 0;
204
	} else if ($_POST['srctype'] == "single") {
205
		$_POST['srcmask'] = 32;
206
	}
207
	if (is_specialnet($_POST['dsttype'])) {
208
		$_POST['dst'] = $_POST['dsttype'];
209
		$_POST['dstmask'] = 0;
210
	}  else if ($_POST['dsttype'] == "single") {
211
		$_POST['dstmask'] = 32;
212
	}
213
	
214
	$intos = array();
215
	foreach ($iptos as $tos) {
216
		if ($_POST['iptos_' . $tos] == "on")
217
			$intos[] = $tos;
218
		else if ($_POST['iptos_' . $tos] == "off")
219
			$intos[] = "!" . $tos;
220
	}
221
	$_POST['iptos'] = join(",", $intos);
222
	
223
	$intcpflags = array();
224
	foreach ($tcpflags as $tcpflag) {
225
		if ($_POST['tcpflags_' . $tcpflag] == "on")
226
			$intcpflags[] = $tcpflag;
227
		else if ($_POST['tcpflags_' . $tcpflag] == "off")
228
			$intcpflags[] = "!" . $tcpflag;
229
	}
230
	$_POST['tcpflags'] = join(",", $intcpflags);
231
	
232
	unset($input_errors);
233
	$pconfig = $_POST;
234

    
235
	/* input validation */
236
	$reqdfields = explode(" ", "target proto src dst");
237
	$reqdfieldsn = explode(",", "Target,Protocol,Source,Destination");
238
	
239
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
240
		$reqdfields[] = "srcmask";
241
		$reqdfieldsn[] = "Source bit count";
242
	}
243
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
244
		$reqdfields[] = "dstmask";
245
		$reqdfieldsn[] = "Destination bit count";
246
	}
247
	
248
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
249
	
250
	if (!$_POST['srcbeginport']) {
251
		$_POST['srcbeginport'] = 0;
252
		$_POST['srcendport'] = 0;
253
	}
254
	if (!$_POST['dstbeginport']) {
255
		$_POST['dstbeginport'] = 0;
256
		$_POST['dstendport'] = 0;
257
	}
258
	
259
	if (($_POST['srcbeginport'] && !is_port($_POST['srcbeginport']))) {
260
		$input_errors[] = "The start source port must be an integer between 1 and 65535.";
261
	}
262
	if (($_POST['srcendport'] && !is_port($_POST['srcendport']))) {
263
		$input_errors[] = "The end source port must be an integer between 1 and 65535.";
264
	}
265
	if (($_POST['dstbeginport'] && !is_port($_POST['dstbeginport']))) {
266
		$input_errors[] = "The start destination port must be an integer between 1 and 65535.";
267
	}
268
	if (($_POST['dstendport'] && !is_port($_POST['dstendport']))) {
269
		$input_errors[] = "The end destination port must be an integer between 1 and 65535.";
270
	}
271
	
272
	if (!is_specialnet($_POST['srctype'])) {
273
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
274
			$input_errors[] = "A valid source IP address or alias must be specified.";
275
		}
276
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
277
			$input_errors[] = "A valid source bit count must be specified.";
278
		}
279
	}
280
	if (!is_specialnet($_POST['dsttype'])) {
281
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
282
			$input_errors[] = "A valid destination IP address or alias must be specified.";
283
		}
284
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
285
			$input_errors[] = "A valid destination bit count must be specified.";
286
		}
287
	}
288
	
289
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
290
		/* swap */
291
		$tmp = $_POST['srcendport'];
292
		$_POST['srcendport'] = $_POST['srcbeginport'];
293
		$_POST['srcbeginport'] = $tmp;
294
	}
295
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
296
		/* swap */
297
		$tmp = $_POST['dstendport'];
298
		$_POST['dstendport'] = $_POST['dstbeginport'];
299
		$_POST['dstbeginport'] = $tmp;
300
	}
301
	
302
	if (($_POST['iplen'] && !preg_match("/^(\d+)(-(\d+))?$/", $_POST['iplen']))) {
303
		$input_errors[] = "The IP packet length must be an integer or a range (from-to).";
304
	}
305

    
306
	if (!$input_errors) {
307
		$shaperent = array();
308
		$shaperent['interface'] = $_POST['interface'];
309
		
310
		if ($_POST['proto'] != "any")
311
			$shaperent['protocol'] = $_POST['proto'];
312
		else
313
			unset($shaperent['protocol']);
314
		
315
		pconfig_to_address($shaperent['source'], $_POST['src'],
316
			$_POST['srcmask'], $_POST['srcnot'],
317
			$_POST['srcbeginport'], $_POST['srcendport']);
318
			
319
		pconfig_to_address($shaperent['destination'], $_POST['dst'],
320
			$_POST['dstmask'], $_POST['dstnot'],
321
			$_POST['dstbeginport'], $_POST['dstendport']);
322
		
323
		$shaperent['direction'] = $_POST['direction'];
324
		$shaperent['iplen'] = $_POST['iplen'];
325
		$shaperent['iptos'] = $_POST['iptos'];
326
		$shaperent['tcpflags'] = $_POST['tcpflags'];
327
		$shaperent['descr'] = $_POST['descr'];
328
		$shaperent['disabled'] = $_POST['disabled'] ? true : false;
329
		
330
		list($targettype,$target) = explode(":", $_POST['target']);
331
		$shaperent[$targettype] = $target;
332
		
333
		if (isset($id) && $a_shaper[$id])
334
			$a_shaper[$id] = $shaperent;
335
		else {
336
			if (is_numeric($after))
337
				array_splice($a_shaper, $after+1, 0, array($shaperent));
338
			else
339
				$a_shaper[] = $shaperent;
340
		}
341
		
342
		write_config();
343
		touch($d_shaperconfdirty_path);
344
		
345
		header("Location: firewall_shaper.php");
346
		exit;
347
	}
348
}
349
?>
350
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
351
<html>
352
<head>
353
<title><?=gentitle("Firewall: Traffic shaper: Edit rule");?></title>
354
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
355
<link href="gui.css" rel="stylesheet" type="text/css">
356
<script language="JavaScript">
357
<!--
358
var portsenabled = 1;
359

    
360
function ext_change() {
361
	if ((document.iform.srcbeginport.selectedIndex == 0) && portsenabled) {
362
		document.iform.srcbeginport_cust.disabled = 0;
363
	} else {
364
		document.iform.srcbeginport_cust.value = "";
365
		document.iform.srcbeginport_cust.disabled = 1;
366
	}
367
	if ((document.iform.srcendport.selectedIndex == 0) && portsenabled) {
368
		document.iform.srcendport_cust.disabled = 0;
369
	} else {
370
		document.iform.srcendport_cust.value = "";
371
		document.iform.srcendport_cust.disabled = 1;
372
	}
373
	if ((document.iform.dstbeginport.selectedIndex == 0) && portsenabled) {
374
		document.iform.dstbeginport_cust.disabled = 0;
375
	} else {
376
		document.iform.dstbeginport_cust.value = "";
377
		document.iform.dstbeginport_cust.disabled = 1;
378
	}
379
	if ((document.iform.dstendport.selectedIndex == 0) && portsenabled) {
380
		document.iform.dstendport_cust.disabled = 0;
381
	} else {
382
		document.iform.dstendport_cust.value = "";
383
		document.iform.dstendport_cust.disabled = 1;
384
	}
385
	
386
	if (!portsenabled) {
387
		document.iform.srcbeginport.disabled = 1;
388
		document.iform.srcendport.disabled = 1;
389
		document.iform.dstbeginport.disabled = 1;
390
		document.iform.dstendport.disabled = 1;
391
	} else {
392
		document.iform.srcbeginport.disabled = 0;
393
		document.iform.srcendport.disabled = 0;
394
		document.iform.dstbeginport.disabled = 0;
395
		document.iform.dstendport.disabled = 0;
396
	}
397
}
398

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

    
436
function proto_change() {
437
	if (document.iform.proto.selectedIndex < 2 || document.iform.proto.selectedIndex == 8) {
438
		portsenabled = 1;
439
	} else {
440
		portsenabled = 0;
441
	}
442
	
443
	ext_change();
444
}
445

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

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