Project

General

Profile

Download (33.6 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
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
/* redirect to wizard if shaper isn't already configured */
40
if(isset($config['shaper']['enable'])) {
41
	$pconfig['enable'] = TRUE;
42
} else {
43
	if(!is_array($config['shaper']['queue']))
44
		Header("Location: wizard.php?xml=traffic_shaper_wizard.xml");
45
}
46

    
47
$specialsrcdst = explode(" ", "any wanip lanip lan pptp");
48

    
49
$id = $_GET['id'];
50
if (isset($_POST['id']))
51
	$id = $_POST['id'];
52

    
53
$after = $_GET['after'];
54
if (isset($_POST['after']))
55
	$after = $_POST['after'];
56

    
57
if (isset($_GET['dup'])) {
58
	$id = $_GET['dup'];
59
	$after = $_GET['dup'];
60
}
61

    
62
if (isset($id) && $a_shaper[$id]) {
63
	$pconfig['in-interface'] = $a_shaper[$id]['in-interface'];
64
	$pconfig['out-interface'] = $a_shaper[$id]['out-interface'];
65

    
66
	if (isset($a_shaper[$id]['protocol']))
67
		$pconfig['proto'] = $a_shaper[$id]['protocol'];
68
	else
69
		$pconfig['proto'] = "any";
70

    
71
	address_to_pconfig($a_shaper[$id]['source'], $pconfig['src'],
72
		$pconfig['srcmask'], $pconfig['srcnot'],
73
		$pconfig['srcbeginport'], $pconfig['srcendport']);
74

    
75
	address_to_pconfig($a_shaper[$id]['destination'], $pconfig['dst'],
76
		$pconfig['dstmask'], $pconfig['dstnot'],
77
		$pconfig['dstbeginport'], $pconfig['dstendport']);
78

    
79
	$pconfig['inqueue'] = $a_shaper[$id]['inqueue'];
80
	$pconfig['outqueue'] = $a_shaper[$id]['outqueue'];
81

    
82
	$pconfig['direction'] = $a_shaper[$id]['direction'];
83
	$pconfig['iptos'] = $a_shaper[$id]['iptos'];
84
	$pconfig['tcpflags'] = $a_shaper[$id]['tcpflags'];
85
	$pconfig['descr'] = $a_shaper[$id]['descr'];
86
	$pconfig['disabled'] = isset($a_shaper[$id]['disabled']);
87

    
88
	if ($pconfig['srcbeginport'] == 0) {
89
		$pconfig['srcbeginport'] = "any";
90
		$pconfig['srcendport'] = "any";
91
	}
92
	if ($pconfig['dstbeginport'] == 0) {
93
		$pconfig['dstbeginport'] = "any";
94
		$pconfig['dstendport'] = "any";
95
	}
96

    
97
} else {
98
	/* defaults */
99
	$pconfig['src'] = "any";
100
	$pconfig['dst'] = "any";
101
}
102

    
103
if (isset($_GET['dup']))
104
	unset($id);
105

    
106
if ($_POST) {
107

    
108
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "any")) {
109
		$_POST['srcbeginport'] = 0;
110
		$_POST['srcendport'] = 0;
111
		$_POST['dstbeginport'] = 0;
112
		$_POST['dstendport'] = 0;
113
	} else {
114

    
115
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
116
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
117
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
118
			$_POST['srcendport'] = $_POST['srcendport_cust'];
119

    
120
		if ($_POST['srcbeginport'] == "any") {
121
			$_POST['srcbeginport'] = 0;
122
			$_POST['srcendport'] = 0;
123
		} else {
124
			if (!$_POST['srcendport'])
125
				$_POST['srcendport'] = $_POST['srcbeginport'];
126
		}
127
		if ($_POST['srcendport'] == "any")
128
			$_POST['srcendport'] = $_POST['srcbeginport'];
129

    
130
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
131
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
132
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
133
			$_POST['dstendport'] = $_POST['dstendport_cust'];
134

    
135
		if ($_POST['dstbeginport'] == "any") {
136
			$_POST['dstbeginport'] = 0;
137
			$_POST['dstendport'] = 0;
138
		} else {
139
			if (!$_POST['dstendport'])
140
				$_POST['dstendport'] = $_POST['dstbeginport'];
141
		}
142
		if ($_POST['dstendport'] == "any")
143
			$_POST['dstendport'] = $_POST['dstbeginport'];
144
	}
145

    
146
	if (is_specialnet($_POST['srctype'])) {
147
		$_POST['src'] = $_POST['srctype'];
148
		$_POST['srcmask'] = 0;
149
	} else if ($_POST['srctype'] == "single") {
150
		$_POST['srcmask'] = 32;
151
	}
152
	if (is_specialnet($_POST['dsttype'])) {
153
		$_POST['dst'] = $_POST['dsttype'];
154
		$_POST['dstmask'] = 0;
155
	}  else if ($_POST['dsttype'] == "single") {
156
		$_POST['dstmask'] = 32;
157
	}
158

    
159
	$intos = array();
160
	foreach ($iptos as $tos) {
161
		if ($_POST['iptos_' . $tos] == "on")
162
			$intos[] = $tos;
163
		else if ($_POST['iptos_' . $tos] == "off")
164
			$intos[] = "!" . $tos;
165
	}
166
	$_POST['iptos'] = join(",", $intos);
167

    
168
	$intcpflags = array();
169
	foreach ($tcpflags as $tcpflag) {
170
		if ($_POST['tcpflags_' . $tcpflag] == "on")
171
			$intcpflags[] = $tcpflag;
172
		else if ($_POST['tcpflags_' . $tcpflag] == "off")
173
			$intcpflags[] = "!" . $tcpflag;
174
	}
175
	$_POST['tcpflags'] = join(",", $intcpflags);
176

    
177
	unset($input_errors);
178
	$pconfig = $_POST;
179

    
180
	/* input validation */
181
	$reqdfields = explode(" ", "inqueue outqueue proto src dst");
182
	$reqdfieldsn = explode(",", "Inbound Queue,Outbound Queue,Protocol,Source,Destination");
183

    
184
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
185
		$reqdfields[] = "srcmask";
186
		$reqdfieldsn[] = "Source bit count";
187
	}
188
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
189
		$reqdfields[] = "dstmask";
190
		$reqdfieldsn[] = "Destination bit count";
191
	}
192

    
193
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
194

    
195
	if (!$_POST['srcbeginport']) {
196
		$_POST['srcbeginport'] = 0;
197
		$_POST['srcendport'] = 0;
198
	}
199
	if (!$_POST['dstbeginport']) {
200
		$_POST['dstbeginport'] = 0;
201
		$_POST['dstendport'] = 0;
202
	}
203

    
204
	if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) {
205
		$input_errors[] = "The start source port must be an alias or integer between 1 and 65535.";
206
	}
207
	if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) {
208
		$input_errors[] = "The end source port must be an alias or integer between 1 and 65535.";
209
	}
210
	if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) {
211
		$input_errors[] = "The start destination port must be an alias or integer between 1 and 65535.";
212
	}
213
	if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) {
214
		$input_errors[] = "The end destination port must be an alias or integer between 1 and 65535.";
215
	}
216

    
217
	if (!is_specialnet($_POST['srctype'])) {
218
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
219
			$input_errors[] = "A valid source IP address or alias must be specified.";
220
		}
221
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
222
			$input_errors[] = "A valid source bit count must be specified.";
223
		}
224
	}
225
	if (!is_specialnet($_POST['dsttype'])) {
226
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
227
			$input_errors[] = "A valid destination IP address or alias must be specified.";
228
		}
229
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
230
			$input_errors[] = "A valid destination bit count must be specified.";
231
		}
232
	}
233

    
234
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
235
		/* swap */
236
		$tmp = $_POST['srcendport'];
237
		$_POST['srcendport'] = $_POST['srcbeginport'];
238
		$_POST['srcbeginport'] = $tmp;
239
	}
240
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
241
		/* swap */
242
		$tmp = $_POST['dstendport'];
243
		$_POST['dstendport'] = $_POST['dstbeginport'];
244
		$_POST['dstbeginport'] = $tmp;
245
	}
246

    
247
	if (!$input_errors) {
248
		$shaperent = array();
249
		$shaperent['in-interface'] = $_POST['in-interface'];
250
		$shaperent['out-interface'] = $_POST['out-interface'];
251

    
252
		if ($_POST['proto'] != "any")
253
			$shaperent['protocol'] = $_POST['proto'];
254
		else
255
			unset($shaperent['protocol']);
256

    
257
		pconfig_to_address($shaperent['source'], $_POST['src'],
258
			$_POST['srcmask'], $_POST['srcnot'],
259
			$_POST['srcbeginport'], $_POST['srcendport']);
260

    
261
		pconfig_to_address($shaperent['destination'], $_POST['dst'],
262
			$_POST['dstmask'], $_POST['dstnot'],
263
			$_POST['dstbeginport'], $_POST['dstendport']);
264

    
265
		$shaperent['direction'] = $_POST['direction'];
266
		$shaperent['iptos'] = $_POST['iptos'];
267
		$shaperent['tcpflags'] = $_POST['tcpflags'];
268
		$shaperent['descr'] = $_POST['descr'];
269
		$shaperent['disabled'] = $_POST['disabled'] ? true : false;
270

    
271
		$shaperent['inqueue'] = $_POST['inqueue'];
272
		$shaperent['outqueue'] = $_POST['outqueue'];
273

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

    
283
		write_config();
284
		touch($d_shaperconfdirty_path);
285

    
286
		header("Location: firewall_shaper.php");
287
		exit;
288
	}
289
}
290

    
291
$pgtitle = "Firewall: Shaper: Rules: Edit";
292
$closehead = false;
293
include("head.inc");
294
?>
295

    
296
<script language="JavaScript">
297
<!--
298
var portsenabled = 1;
299

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

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

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

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

    
383
	ext_change();
384
}
385

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

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

    
749
<script language="JavaScript">
750
<!--
751
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
752
	var customarray=new Array(<?php echo $aliases; ?>);
753
//-->
754
</script>
755

    
756
<?php include("fend.inc"); ?>
757
</body>
758
</html>
(55-55/173)