Project

General

Profile

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

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

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

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

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

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

    
33
require("guiconfig.inc");
34

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

    
40
/* redirect to wizard if shaper isn't already configured */
41
if(isset($config['shaper']['enable'])) {
42
        $pconfig['enable'] = TRUE;
43
} else {
44
        Header("Location: wizard.php?xml=traffic_shaper_wizard.xml");
45
}
46

    
47
$specialsrcdst = explode(" ", "any 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['interface'] = $a_shaper[$id]['interface'];
64

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

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

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

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

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

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

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

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

    
105
if ($_POST) {
106

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
246
	if (!$input_errors) {
247
		$shaperent = array();
248
		$shaperent['interface'] = $_POST['interface'];
249

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

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

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

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

    
269
		$shaperent['inqueue'] = $_POST['inqueue'];
270
		$shaperent['outqueue'] = $_POST['outqueue'];
271

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

    
281
		write_config();
282
		touch($d_shaperconfdirty_path);
283

    
284
		header("Location: firewall_shaper.php");
285
		exit;
286
	}
287
}
288

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

    
294
<script language="JavaScript">
295
<!--
296
var portsenabled = 1;
297

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

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

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

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

    
381
	ext_change();
382
}
383

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

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

    
726
<script language="JavaScript">
727
<!--
728
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
729
	var customarray=new Array(<?php echo $aliases; ?>);
730
//-->
731
</script>
732

    
733
<?php include("fend.inc"); ?>
734
</body>
735
</html>
(46-46/153)