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

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

    
755
<?php include("fend.inc"); ?>
756
</body>
757
</html>
(56-56/186)