Project

General

Profile

Download (139 KB) Statistics
| Branch: | Tag: | Revision:
1 061f78b1 Bill Marquette
<?php
2
/*
3 ac24dc24 Renato Botelho
 * shaper.inc
4 ba360ed7 Stephen Beaver
 *
5 ac24dc24 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 0b4c14a4 Steve Beaver
 * Copyright (c) 2004-2019 Rubicon Communications, LLC (Netgate)
7 ac24dc24 Renato Botelho
 * All rights reserved.
8 fd9ebcd5 Stephen Beaver
 *
9 ac24dc24 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
10 c5d81585 Renato Botelho
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11 ac24dc24 Renato Botelho
 * All rights reserved.
12 fd9ebcd5 Stephen Beaver
 *
13 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16 fd9ebcd5 Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 fd9ebcd5 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24 fd9ebcd5 Stephen Beaver
 */
25 061f78b1 Bill Marquette
26 f5881023 Ermal Lu?i
/* XXX: needs some reducing on include. */
27
/* include all configuration functions. */
28 77b86ada Ermal
require_once("globals.inc");
29 061f78b1 Bill Marquette
require_once("functions.inc");
30 8633930d Ermal
require_once("util.inc");
31
require_once("notices.inc");
32 0e2bed22 PiBa-NL
include_once("interfaces.inc");//required for convert_real_interface_to_friendly_interface_name() in get_queue_stats() to get altq interface name.
33
34 254581a5 Matt Underscore
/* Limiter patch */
35
// I need this crazy looking model/struct to specify various algos, ecn caps, and params.
36
// update as needed when dummynet changes
37
38
// List of schedulers ('type' command on scheduler/pipe) that dummynet/ipfw is supposed to support
39
function getSchedulers() {
40
	return array(
41 25d029d1 Luiz Souza
		"wf2q+" => array(
42
			"name" => "Worst-case Weighted fair Queueing (default)",
43
			"parameter_format" => "type wf2q+",
44
			"description" => "Worst-case Weighted fair Queueing (WF2Q+) schedules flows with an associated weight. ".
45
					 "WF2Q+ is the default algorithm used by previous versions.",
46
			"parameters" => array(),
47
			"ecn" => false
48
		),
49 254581a5 Matt Underscore
		"fifo" => array(
50
			"name" => "FIFO",
51
			"parameter_format" => "type fifo",
52 25d029d1 Luiz Souza
			"description" => "First-in-First-out is a fundamental queueing discipline which ensures packet sequence. ".
53
					 "Dynamic queues are not supported with the FIFO scheduler (all packets are stored in a single queue).",
54 254581a5 Matt Underscore
			"parameters" => array(),
55
			"ecn" => false
56
		),
57
		"qfq" => array(
58
			"name" => "Quick Fair Queueing",
59
			"parameter_format" => "type qfq",
60
			"description" => "QFQ is a fast, low-complexity Approximated Fair Queueing scheduler.",
61
			"parameters" => array(),
62
			"ecn" => false
63
		),
64
		"rr" => array(
65
			"name" => "Round Robin",
66
			"parameter_format" => "type rr",
67
			"description" => "Round Robin (RR) schedules packets in a round-robin fashion.",
68
			"parameters" => array(),
69
			"ecn" => false
70
		),
71
		"prio" => array(
72
			"name" => "PRIO",
73
			"parameter_format" => "type prio",
74
			"description" => "PRIO schedules packets by their corresponding priority.",
75
			"parameters" => array(),
76
			"ecn" => false
77
		),
78
		"fq_codel" => array(
79
			"name" => "FQ_CODEL",
80 1de72f61 Matt Underscore
			"parameter_format" => "type fq_codel target %sms interval %sms quantum %s limit %s flows %s",
81 254581a5 Matt Underscore
			"description" => "CoDel is a novel \"no knobs\", \"just works\", \"handles variable bandwidth and RTT\", and simple AQM algorithm."
82
							. " As a scheduler, FQ_CODEL implements several flows (defined below), each having their own CoDel AQM.",
83
			"parameters" => array(
84 d4f29a52 Steve Beaver
				"target" => array("name" => "Target Delay (ms)", "type" => "number", "default" => intval(get_single_sysctl("net.inet.ip.dummynet.fqcodel.target")) / 1000),
85
				"interval" => array("name" => "Interval (ms)", "type" => "number", "default" => intval(get_single_sysctl("net.inet.ip.dummynet.fqcodel.interval")) / 1000),
86 254581a5 Matt Underscore
				"quantum" => array("name" => "quantum", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqcodel.quantum")),
87
				"limit" => array("name" => "limit", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqcodel.limit")),
88
				"flows" => array("name" => "flows", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqcodel.flows"))
89
			),
90
			"ecn" => true
91
		),
92
		"fq_pie" => array(
93
			"name" => "FQ_PIE",
94
			"parameter_format" => "type fq_pie target %sms tupdate %sms alpha %s beta %s max_burst %s max_ecnth %s",
95
			"description" => "Fair Queue Proportional Integral controller Enhanced AQM (FQ_PIE) is similar to FQ_CODEL but uses a slightly different algorithm.",
96
			"parameters" => array(
97 d4f29a52 Steve Beaver
				"target" => array("name" => "Target Delay (ms)", "type" => "number", "default" => intval(get_single_sysctl("net.inet.ip.dummynet.fqpie.target")) / 1000),
98
				"tupdate" => array("name" => "Interval (ms)", "type" => "number", "default" => intval(get_single_sysctl("net.inet.ip.dummynet.fqpie.tupdate")) / 1000),
99 254581a5 Matt Underscore
				"alpha" => array("name" => "alpha", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqpie.alpha")),
100
				"beta" => array("name" => "beta", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqpie.beta")),
101
				"max_burst" => array("name" => "max_burst", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqpie.max_burst")),
102
				"max_ecnth" => array("name" => "max_ecnth", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqpie.max_ecnth"))
103
			),
104
			"ecn" => true
105
		)
106
	);
107
}
108
// list of AQMs that dummynet supports
109
function getAQMs() {
110
	return array(
111
		"droptail" => array(
112
			"name" => "Tail Drop",
113
			"description" => "Tail Drop is a fundamental queue management algorithm which drops inbound packets once the queue is full.",
114
			"parameter_format" => "droptail",
115
			"parameters" => array(),
116
			"ecn" => false
117
		),
118
		"codel" => array(
119
			"name" => "CoDel",
120
			"description" => "CoDel is a novel \"no knobs\", \"just works\", \"handles variable bandwidth and RTT\", and simple AQM algorithm.",
121
			"parameter_format" => "codel target %sms interval %sms",
122
			"parameters" => array(
123 d4f29a52 Steve Beaver
				"target" => array("name" => "Target Delay (ms)", "type" => "number", "default" => intval(get_single_sysctl("net.inet.ip.dummynet.codel.target")) / 1000),
124
				"interval" => array("name" => "Interval (ms)", "type" => "number", "default" => intval(get_single_sysctl("net.inet.ip.dummynet.codel.interval")) / 1000),
125 254581a5 Matt Underscore
			),
126
			"ecn" => true
127
		),
128
		"pie" => array(
129
			"name" => "PIE",
130
			"description" => "Proportional Integral controller Enhanced AQM (PIE) is similar to CoDel but uses a slightly different algorithm.",
131
			"parameter_format" => "pie target %sms tupdate %sms alpha %s beta %s max_burst %s max_ecnth %s",
132
			"parameters" => array(
133 d4f29a52 Steve Beaver
				"target" => array("name" => "Target Delay (ms)", "type" => "number", "default" => intval(get_single_sysctl("net.inet.ip.dummynet.fqpie.target")) / 1000),
134
				"tupdate" => array("name" => "Interval (ms)", "type" => "number", "default" => intval(get_single_sysctl("net.inet.ip.dummynet.fqpie.tupdate")) / 1000),
135 254581a5 Matt Underscore
				"alpha" => array("name" => "alpha", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqpie.alpha")),
136
				"beta" => array("name" => "beta", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqpie.beta")),
137
				"max_burst" => array("name" => "max_burst", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqpie.max_burst")),
138
				"max_ecnth" => array("name" => "max_ecnth", "type" => "number", "default" => get_single_sysctl("net.inet.ip.dummynet.fqpie.max_ecnth"))
139
			),
140
			"ecn" => true
141
		),
142
		"red" => array(
143
			"name" => "Random Early Detection (RED)",
144
			"description" => "Random Early Detection (RED) drops packets based on probability, which increases as the queue increases in size.",
145
			"parameter_format" => "red %s/%s/%s/%s",
146
			"parameters" => array(
147
				"w_q" => array("name" => "w_q", "type" => "number", "default" => 1),
148
				"min_th" => array("name" => "min_th", "type" => "number", "default" => 0),
149
				"max_th" => array("name" => "max_th", "type" => "number", "default" => 1),
150
				"max_p" => array("name" => "max_p", "type" => "number", "default" => 1)
151
			),
152
			"ecn" => true
153
		),
154
		"gred" => array(
155
			"name" => "Gentle Random Early Detection (GRED)",
156
			"description" => "Gentle Random Early Detection (GRED) drops packets based on probability, which increases as the queue increases in size.",
157
			"parameter_format" => "gred %s/%s/%s/%s",
158
			"parameters" => array(
159
				"w_q" => array("name" => "w_q", "type" => "number", "default" => 1),
160
				"min_th" => array("name" => "min_th", "type" => "number", "default" => 0),
161
				"max_th" => array("name" => "max_th", "type" => "number", "default" => 1),
162
				"max_p" => array("name" => "max_p", "type" => "number", "default" => 1)
163
			),
164
			"ecn" => true
165
		)
166
	);
167
}
168
// used to map above
169
function array_map_assoc(callable $f, array $a) {
170
	return array_column(array_map($f, array_keys($a), $a), 1, 0);
171
}
172
function build_queue_params($array, $selected, $params, $id) {
173 74b3e6ec Matt Underscore
	$form .= '<div id="params_' . $id . '">';
174 d4f29a52 Steve Beaver
175 254581a5 Matt Underscore
	$selectedAlgorithm = $array[$selected];
176 d4f29a52 Steve Beaver
177 254581a5 Matt Underscore
	if ($selectedAlgorithm) {
178
		$form .= '<span class="help-block">' . gettext($selectedAlgorithm['description']) . '</span><br/>';
179
	}
180 d4f29a52 Steve Beaver
181 254581a5 Matt Underscore
	$parameters = $selectedAlgorithm["parameters"];
182 d4f29a52 Steve Beaver
183 254581a5 Matt Underscore
	if (!$parameters || sizeof($parameters) <= 0) {
184
		if (!$selectedAlgorithm) {
185
			$form .= 'No parameters for selected algorithm.';
186
		} else {
187
			$form .= 'No parameters for ' . $selectedAlgorithm["name"] . '.';
188
		}
189
	} else {
190
		$form .= '<div class="table-responsive">';
191
		$form .= '<table id="maintable" class="table table-hover table-striped">';
192
		$form .= "<thead><tr>";
193
		$form .= "<th>Parameter</th>";
194
		$form .= "<th>Value</th>";
195
		$form .= "</tr></thead>";
196
		$form .= "<tbody>";
197 d4f29a52 Steve Beaver
198 254581a5 Matt Underscore
		foreach ($parameters as $key => $value) {
199
			$form .= '<tr>';
200 d4f29a52 Steve Beaver
201 254581a5 Matt Underscore
			// get current value, or default.
202
			$currentValue = $params[$key];
203
			if (!$currentValue || $currentValue == '') {
204
				$currentValue = $value["default"]; // default to default
205
			}
206 d4f29a52 Steve Beaver
207 5ee16aa6 no
			$form .= "<td class=\"col-xs-4\">" . htmlspecialchars($key) . "</td>";
208 d4f29a52 Steve Beaver
			$form .= "<td class=\"col-xs-8\"><input class=\"form-control\" type=" . gettext($value["type"])
209 5ee16aa6 no
					. " name=\"param_" . $selected . "_" . $key . "\" placeholder=\"" .
210
					htmlspecialchars($value["default"]) . "\" value=\"" . htmlspecialchars($currentValue) . "\"/></td>";
211 d4f29a52 Steve Beaver
212 254581a5 Matt Underscore
			$form .= '</tr>';
213
		}
214 d4f29a52 Steve Beaver
215 254581a5 Matt Underscore
		$form .= "</tbody></table></div><br />";
216
	}
217 d4f29a52 Steve Beaver
218 254581a5 Matt Underscore
	$form .= '</div>';
219
	$form .= '<script type="text/javascript">';
220 74b3e6ec Matt Underscore
	$form .= 'events.push(function() {$("#' . $id . '").change(function() {$("#params_' .
221 254581a5 Matt Underscore
		gettext($id) . '").html("Save this limiter to see algorithm parameters.");})});</script>';
222
223
	return($form);
224
}
225
function FormatParameters($format_string, $params) {
226
	return vsprintf($format_string, $params);
227
}
228
/* End limiter patch */
229
230 0e2bed22 PiBa-NL
function get_queue_stats() {
231 0f5bd6f8 Stephen Jones
	// due to sysutils\qstats not providing accurate stats with 'currently' valid numbers
232 0e2bed22 PiBa-NL
	// in its current implementation this php function does the job for now..
233
	$result = array();
234
	$result['timestamp'] = gettimeofday(true);
235
	$r = exec("/sbin/pfctl -s queue -v", $output, $ret);
236
	$interfacestats = array();
237
	foreach($output as $line) {
238
		$partial = explode('{', $line);
239
		$items = explode(" ", $partial[0]);
240
		if (isset($partial[1])) {
241
			$contains = explode(", ", substr($partial[1], 0, strlen($partial[1]) - 1));
242
		} else {
243
			unset($contains);
244
		}
245
		if ($items[0] == "queue") {
246
			$level = 1;
247
			while (empty($items[$level])) {
248
				$level++;
249
			}
250
			unset($newqueue);
251
			$newqueue = array();
252
			$currentqueuename = $items[$level];
253
			$currentqueueif = $items[$level+2];
254
			$newqueue['name'] = $currentqueuename;
255
			$newqueue['interface'] = $items[$level+2];
256 0f5bd6f8 Stephen Jones
257 0e2bed22 PiBa-NL
			if ($items[$level+3] == "bandwidth") {
258
				$level += 2;
259
			}
260
			if ($items[$level+3] == "priority") {
261
				$level += 2;
262
			}
263
			if ($items[$level+3] == "qlimit") {
264
				$level += 2;
265
			}
266
			$tmp = $items[$level+3];
267
			if (substr($tmp,strlen($tmp)-1) == "(") {
268
				$newqueue['shapertype'] = substr($tmp, 0, strlen($tmp)-1);
269
			}
270 0f5bd6f8 Stephen Jones
271 0e2bed22 PiBa-NL
			$interfacestats[$currentqueueif][$currentqueuename] = &$newqueue;
272
			if (is_array($contains)) {
273
				$newqueue['contains'] = $contains;
274
			}
275
		} elseif ($items[0] == "altq") {
276
			unset($newqueue);
277
			$newqueue = array();
278
			$currentqueuename = convert_real_interface_to_friendly_interface_name($items[2]);
279
			$currentqueueif = $items[2];
280
			$newqueue['name'] = $currentqueuename;
281
			$newqueue['interface'] = $items[2];
282
			$interfacestats[$currentqueueif][$currentqueuename] = &$newqueue;
283
		} else {
284
			if ($items[3] == "pkts:") {
285
				$newqueue["pkts"] = trim(substr($line, 10, 10));
286
				$newqueue["bytes"] = trim(substr($line, 29, 10));
287
				$newqueue["droppedpkts"] = trim(substr($line, 55, 6));
288
				$newqueue["droppedbytes"] = trim(substr($line, 69, 6));
289
			}
290
			if ($items[3] == "qlength:") {
291
				$subitems = explode("/", substr($line, 13, 8));
292
				$newqueue["qlengthitems"] = trim($subitems[0]);
293
				$newqueue["qlengthsize"] = trim($subitems[1]);
294
				if (substr($line, 22, 8) == "borrows:") {
295
					$newqueue["borrows"] = trim(substr($line, 31, 7));
296
				}
297
				if (substr($line, 39, 9) == "suspends:") {
298
					$newqueue["suspends"] = trim(substr($line, 49, 7));
299
				}
300
			}
301
		}
302
	}
303
	$result['interfacestats'] = $interfacestats;
304
	return $result;
305
}
306 061f78b1 Bill Marquette
307 197bfe96 Ermal Luçi
/*
308 61e047a5 Phil Davis
 * I admit :) this is derived from xmlparse.inc StartElement()
309 197bfe96 Ermal Luçi
 */
310 61e047a5 Phil Davis
function &get_reference_to_me_in_config(&$mypath) {
311 197bfe96 Ermal Luçi
	global $config;
312
313 c6c398c6 jim-p
	init_config_arr(array('shaper'));
314
	$ptr = &$config['shaper'];
315 197bfe96 Ermal Luçi
	foreach ($mypath as $indeks) {
316 be228fd8 Stephen Jones
		if (!is_array($ptr)) {
317
			$ptr = array();
318
		}
319 41160d19 Stephen Jones
		if (!is_array($ptr['queue'])) {
320
			$ptr['queue'] = array();
321
		}
322
		if (!is_array($ptr['queue'][$indeks])) {
323
			$ptr['queue'][$indeks] = array();
324
		}
325 c6c398c6 jim-p
		$ptr = &$ptr['queue'][$indeks];
326 f5881023 Ermal Lu?i
	}
327 061f78b1 Bill Marquette
328 197bfe96 Ermal Luçi
	return $ptr;
329 061f78b1 Bill Marquette
}
330 d62ba478 Ermal Luçi
331 61e047a5 Phil Davis
function unset_object_by_reference(&$mypath) {
332 197bfe96 Ermal Luçi
	global $config;
333 061f78b1 Bill Marquette
334 c6c398c6 jim-p
	init_config_arr(array('shaper'));
335
	$ptr = &$config['shaper'];
336 f5881023 Ermal Lu?i
	for ($i = 0; $i < count($mypath) - 1; $i++) {
337 c6c398c6 jim-p
		$ptr = &$ptr['queue'][$mypath[$i]];
338 f5881023 Ermal Lu?i
	}
339 197bfe96 Ermal Luçi
	unset($ptr['queue'][$mypath[$i]]);
340
}
341 d62ba478 Ermal Luçi
342 61e047a5 Phil Davis
function &get_dn_reference_to_me_in_config(&$mypath) {
343 c25a6b6a Ermal Luçi
	global $config;
344
345 c6c398c6 jim-p
	init_config_arr(array('dnshaper'));
346
	$ptr = &$config['dnshaper'];
347 c25a6b6a Ermal Luçi
	foreach ($mypath as $indeks) {
348 c6c398c6 jim-p
		$ptr = &$ptr['queue'][$indeks];
349 f5881023 Ermal Lu?i
	}
350 c25a6b6a Ermal Luçi
351
	return $ptr;
352
}
353 d62ba478 Ermal Luçi
354 61e047a5 Phil Davis
function unset_dn_object_by_reference(&$mypath) {
355 c25a6b6a Ermal Luçi
	global $config;
356
357 c6c398c6 jim-p
	init_config_arr(array('dnshaper'));
358
	$ptr = &$config['dnshaper'];
359 f5881023 Ermal Lu?i
	for ($i = 0; $i < count($mypath) - 1; $i++) {
360 c6c398c6 jim-p
		$ptr = &$ptr['queue'][$mypath[$i]];
361 f5881023 Ermal Lu?i
	}
362 c25a6b6a Ermal Luçi
	unset($ptr['queue'][$mypath[$i]]);
363
}
364
365 61e047a5 Phil Davis
function clean_child_queues($type, $mypath) {
366 197bfe96 Ermal Luçi
	$ref = &get_reference_to_me_in_config($mypath);
367
368
	switch ($type) {
369 61e047a5 Phil Davis
		case 'HFSC':
370
			if (isset($ref['borrow'])) {
371
				unset($ref['borrow']);
372
			}
373
			if (isset($ref['hogs'])) {
374
				unset($ref['hogs']);
375
			}
376
			if (isset($ref['buckets'])) {
377
				unset($ref['buckets']);
378
			}
379
			break;
380
		case 'PRIQ':
381
			if (isset($ref['borrow'])) {
382
				unset($ref['borrow']);
383
			}
384
			if (isset($ref['bandwidth'])) {
385
				unset($ref['bandwidth']);
386
			}
387
			if (isset($ref['bandwidthtype'])) {
388
				unset($ref['bandwidthtype']);
389
			}
390
			/* fall through */
391
		case 'FAIRQ':
392
			if (isset($ref['borrow'])) {
393
				unset($ref['borrow']);
394
			}
395
			/* fall through */
396
		case 'CBQ':
397
			if (isset($ref['realtime'])) {
398
				unset($ref['realtime']);
399
			}
400
			if (isset($ref['realtime1'])) {
401
				unset($ref['realtime1']);
402
			}
403
			if (isset($ref['realtime2'])) {
404
				unset($ref['realtime2']);
405
			}
406
			if (isset($ref['realtime3'])) {
407
				unset($ref['realtime3']);
408
			}
409
			if (isset($ref['upperlimit'])) {
410
				unset($ref['upperlimit']);
411
			}
412
			if (isset($ref['upperlimit1'])) {
413
				unset($ref['upperlimit1']);
414
			}
415
			if (isset($ref['upperlimit2'])) {
416
				unset($ref['upperlimit2']);
417
			}
418
			if (isset($ref['upperlimit3'])) {
419
				unset($ref['upperlimit3']);
420
			}
421
			if (isset($ref['linkshare'])) {
422
				unset($ref['linkshare']);
423
			}
424
			if (isset($ref['linkshare1'])) {
425
				unset($ref['linkshare1']);
426
			}
427
			if (isset($ref['linkshare2'])) {
428
				unset($ref['linkshare2']);
429
			}
430
			if (isset($ref['linkshare3'])) {
431
				unset($ref['linkshare3']);
432
			}
433
			if (isset($ref['hogs'])) {
434
				unset($ref['hogs']);
435
			}
436
			if (isset($ref['buckets'])) {
437
				unset($ref['buckets']);
438
			}
439
			break;
440 197bfe96 Ermal Luçi
	}
441
}
442 061f78b1 Bill Marquette
443 61e047a5 Phil Davis
function get_bandwidthtype_scale($type) {
444 420b4538 Renato Botelho
	switch ($type) {
445 61e047a5 Phil Davis
		case "Gb":
446
			$factor = 1024 * 1024 * 1024;
447
			break;
448
		case "Mb":
449
			$factor = 1024 * 1024;
450
			break;
451
		case "Kb":
452
			$factor = 1024;
453
			break;
454
		case "b":
455
		default:
456
			$factor = 1;
457
			break;
458 420b4538 Renato Botelho
	}
459
	return intval($factor);
460 40de74f5 Ermal Luçi
}
461
462 45eeb038 Luiz Otavio O Souza
function get_bandwidth($bw, $scale, $obj) {
463 7140cb27 Stephen Jones
	$bw = (int) $bw;
464 2638ddec Luiz Otavio O Souza
	$pattern= "/(b|Kb|Mb|Gb|%)/";
465
	if (!preg_match($pattern, $scale, $match))
466
		return 0;
467
468
	switch ($match[1]) {
469
		case '%':
470 45eeb038 Luiz Otavio O Souza
			$objbw = ($bw / 100) * get_queue_bandwidth($obj);
471 2638ddec Luiz Otavio O Souza
			break;
472
		default:
473
			$objbw = $bw * get_bandwidthtype_scale($scale);
474
			break;
475
	}
476
477
	return floatval($objbw);
478
}
479
480 45eeb038 Luiz Otavio O Souza
/*
481
 * XXX - unused
482
 *
483 61e047a5 Phil Davis
function get_hfsc_bandwidth($object, $bw) {
484 40de74f5 Ermal Luçi
	$pattern= "/[0-9]+/";
485 61e047a5 Phil Davis
	if (preg_match($pattern, $bw, $match)) {
486 420b4538 Renato Botelho
		$bw_1 = $match[1];
487 61e047a5 Phil Davis
	} else {
488 420b4538 Renato Botelho
		return 0;
489 61e047a5 Phil Davis
	}
490 420b4538 Renato Botelho
	$pattern= "/(b|Kb|Mb|Gb|%)/";
491
	if (preg_match($pattern, $bw, $match)) {
492
		switch ($match[1]) {
493 61e047a5 Phil Davis
			case '%':
494 45eeb038 Luiz Otavio O Souza
				$bw_1 = ($bw_1 / 100) * get_interface_bandwidth($object);
495 61e047a5 Phil Davis
				break;
496
			default:
497
				$bw_1 = $bw_1 * get_bandwidthtype_scale($match[0]);
498
				break;
499 420b4538 Renato Botelho
		}
500 3a54efed Ermal Luçi
		return floatval($bw_1);
501 61e047a5 Phil Davis
	} else {
502 420b4538 Renato Botelho
		return 0;
503 61e047a5 Phil Davis
	}
504 40de74f5 Ermal Luçi
}
505 45eeb038 Luiz Otavio O Souza
*/
506
507
function get_queue_bandwidth($obj) {
508
	$bw = $obj->GetBandwidth();
509
	$scale = $obj->GetBwscale();
510
511
	$pattern= "/(b|Kb|Mb|Gb|%)/";
512
	if (!preg_match($pattern, $scale, $match))
513
		return 0;
514
515
	switch ($match[1]) {
516
		case '%':
517
			$objbw = ($bw / 100) * get_queue_bandwidth($obj->GetParent());
518
			break;
519
		default:
520
			$objbw = $bw * get_bandwidthtype_scale($scale);
521
			break;
522
	}
523
524
	return floatval($objbw);
525
}
526 40de74f5 Ermal Luçi
527 61e047a5 Phil Davis
function get_interface_bandwidth($object) {
528 40de74f5 Ermal Luçi
	global $altq_list_queues;
529
530 420b4538 Renato Botelho
	$int = $object->GetInterface();
531 c6c398c6 jim-p
	if (isset($altq_list_queues[$int])) {
532
		$altq = &$altq_list_queues[$int];
533 420b4538 Renato Botelho
		$bw_3 = $altq->GetBandwidth();
534 4de8f7ba Phil Davis
		$bw_3 = $bw_3 * get_bandwidthtype_scale($altq->GetBwscale());
535 3a54efed Ermal Luçi
		return floatval($bw_3);
536 61e047a5 Phil Davis
	} else {
537 f5881023 Ermal Lu?i
		return 0;
538 61e047a5 Phil Davis
	}
539 40de74f5 Ermal Luçi
}
540
541
/*
542
 * This is duplicated here since we cannot include guiconfig.inc.
543
 * Including it makes all stuff break.
544
 */
545 61e047a5 Phil Davis
function shaper_do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
546 40de74f5 Ermal Luçi
547 420b4538 Renato Botelho
	/* check for bad control characters */
548
	foreach ($postdata as $pn => $pd) {
549
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
550
			$input_errors[] = sprintf(gettext("The field '%s' contains invalid characters."), $pn);
551
		}
552
	}
553
554
	for ($i = 0; $i < count($reqdfields); $i++) {
555
		if ($postdata[$reqdfields[$i]] == "") {
556
			$input_errors[] = sprintf(gettext("The field '%s' is required."), $reqdfieldsn[$i]);
557
		}
558
	}
559 40de74f5 Ermal Luçi
}
560
561 61e047a5 Phil Davis
function cleanup_queue_from_rules($queue) {
562 197bfe96 Ermal Luçi
	global $config;
563 061f78b1 Bill Marquette
564 197bfe96 Ermal Luçi
	foreach ($config['filter']['rule'] as $rule) {
565 61e047a5 Phil Davis
		if ($rule['defaultqueue'] == $queue) {
566 197bfe96 Ermal Luçi
			unset($rule['defaultqueue']);
567 61e047a5 Phil Davis
		}
568
		if ($rule['ackqueue'] == $queue) {
569 197bfe96 Ermal Luçi
			unset($rule['ackqueue']);
570 61e047a5 Phil Davis
		}
571 197bfe96 Ermal Luçi
	}
572 061f78b1 Bill Marquette
}
573
574 61e047a5 Phil Davis
function cleanup_dnqueue_from_rules($queue) {
575 c25a6b6a Ermal Luçi
	global $config;
576
577
	foreach ($config['filter']['rule'] as $rule) {
578 61e047a5 Phil Davis
		if ($rule['dnpipe'] == $queue) {
579 c25a6b6a Ermal Luçi
			unset($rule['dnpipe']);
580 61e047a5 Phil Davis
		}
581
		if ($rule['pdnpipe'] == $queue) {
582 c25a6b6a Ermal Luçi
			unset($rule['pdnpipe']);
583 61e047a5 Phil Davis
		}
584 c25a6b6a Ermal Luçi
	}
585
}
586
587 197bfe96 Ermal Luçi
class altq_root_queue {
588 f5881023 Ermal Lu?i
	var $interface;
589
	var $tbrconfig ;
590
	var $bandwidth;
591 bfc94df0 Phil Davis
	var $bandwidthtype; /* b, Kb, Mb, Gb, % */
592 f5881023 Ermal Lu?i
	var $scheduler;
593
	var $qlimit;
594
	var $queues = array();
595
	var $qenabled = false;
596
	var $link;
597
598 d6fa899d Phil Davis
	/* Accessor functions */
599 197bfe96 Ermal Luçi
	function GetDefaultQueuePresent() {
600 f61dc8e6 Ermal
		if (!empty($this->queues)) {
601
			foreach ($this->queues as $q) {
602 61e047a5 Phil Davis
				if ($q->GetDefault()) {
603 f61dc8e6 Ermal
					return true;
604 61e047a5 Phil Davis
				}
605 f61dc8e6 Ermal
			}
606
		}
607
608
		return false;
609 197bfe96 Ermal Luçi
	}
610
	function SetLink($link) {
611
		$this->link = $link;
612
	}
613
	function GetLink() {
614
		return $this->link;
615 420b4538 Renato Botelho
	}
616 197bfe96 Ermal Luçi
	function GetEnabled() {
617
		return $this->qenabled;
618
	}
619 92125c97 Ermal Luçi
	function SetEnabled($value) {
620 197bfe96 Ermal Luçi
		$this->qenabled = $value;
621
	}
622 70b139a3 Chris Buechler
	function CanHaveChildren() {
623 61e047a5 Phil Davis
		if ($this->GetScheduler() == "CODELQ") {
624 8edaa92c Ermal
			return false;
625 61e047a5 Phil Davis
		} else {
626 8edaa92c Ermal
			return true;
627 61e047a5 Phil Davis
		}
628 197bfe96 Ermal Luçi
	}
629
	function CanBeDeleted() {
630
		return false;
631
	}
632
	function GetQname() {
633
		return $this->interface;
634
	}
635
	function SetQname($name) {
636
		$this->interface = trim($name);
637
	}
638 92125c97 Ermal Luçi
	function GetInterface() {
639 f5881023 Ermal Lu?i
		return $this->interface;
640 92125c97 Ermal Luçi
	}
641
	function SetInterface($name) {
642 f5881023 Ermal Lu?i
		$this->interface = trim($name);
643 92125c97 Ermal Luçi
	}
644
	function GetTbrConfig() {
645 f5881023 Ermal Lu?i
		return $this->tbrconfig;
646 92125c97 Ermal Luçi
	}
647
	function SetTbrConfig($tbrconfig) {
648 f5881023 Ermal Lu?i
		$this->tbrconfig = $tbrconfig;
649 92125c97 Ermal Luçi
	}
650
	function GetBandwidth() {
651 f5881023 Ermal Lu?i
		return $this->bandwidth;
652 92125c97 Ermal Luçi
	}
653
	function SetBandwidth($bw) {
654 f5881023 Ermal Lu?i
		$this->bandwidth = $bw;
655 92125c97 Ermal Luçi
	}
656
	function GetBwscale() {
657 f5881023 Ermal Lu?i
		return $this->bandwidthtype;
658 92125c97 Ermal Luçi
	}
659
	function SetBwscale($bwscale) {
660 f5881023 Ermal Lu?i
		$this->bandwidthtype = $bwscale;
661 92125c97 Ermal Luçi
	}
662
	function GetScheduler() {
663 f5881023 Ermal Lu?i
		return $this->scheduler;
664 92125c97 Ermal Luçi
	}
665
	function SetScheduler($scheduler) {
666 f5881023 Ermal Lu?i
		$this->scheduler = trim($scheduler);
667 92125c97 Ermal Luçi
	}
668 197bfe96 Ermal Luçi
	function GetQlimit() {
669
		return $this->qlimit;
670
	}
671
	function SetQlimit($limit) {
672
		$this->qlimit = $limit;
673
	}
674 f5881023 Ermal Lu?i
675 bfc94df0 Phil Davis
	function GetBwscaleText() {
676
		switch ($this->bandwidthtype) {
677
			case "b":
678
				$bwscaletext = "Bit/s";
679
				break;
680
			case "Kb":
681
				$bwscaletext = "Kbit/s";
682
				break;
683
			case "Mb":
684
				$bwscaletext = "Mbit/s";
685
				break;
686
			case "Gb":
687
				$bwscaletext = "Gbit/s";
688
				break;
689
			default:
690
				/* For others that do not need translating like % */
691
				$bwscaletext = $this->bandwidthtype;
692
				break;
693
		}
694
		return $bwscaletext;
695
	}
696
697 45eeb038 Luiz Otavio O Souza
	function CheckBandwidth($bw, $bwtype) {
698
		$sum = $this->GetTotalBw();
699
		if ($sum > $bw * get_bandwidthtype_scale($bwtype))
700
			return 1;
701
		foreach ($this->queues as $q) {
702
			if ($q->CheckBandwidth(0, ''))
703
				return 1;
704
		}
705
706
		return 0;
707
	}
708
709
	function GetTotalBw($qignore = NULL) {
710 2638ddec Luiz Otavio O Souza
		$sum = 0;
711
		foreach ($this->queues as $q) {
712 45eeb038 Luiz Otavio O Souza
			if ($qignore != NULL && $qignore == $q)
713
				continue;
714
			$sum += get_bandwidth($q->GetBandwidth(), $q->GetBwscale(), $this);
715 2638ddec Luiz Otavio O Souza
		}
716
717
		return $sum;
718
	}
719
720 197bfe96 Ermal Luçi
	function validate_input($data, &$input_errors) {
721 ce0117f7 Colin Fleming
722 2c072899 jim-p
		$reqdfields[] = "bandwidth";
723 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidth");
724 2c072899 jim-p
		$reqdfields[] = "bandwidthtype";
725 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidthtype");
726 ce0117f7 Colin Fleming
727 40de74f5 Ermal Luçi
		shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
728 ce0117f7 Colin Fleming
729 2638ddec Luiz Otavio O Souza
		if (!isset($data['bandwidth']) || strlen($data['bandwidth']) == 0) {
730
			$input_errors[] = gettext("Bandwidth must be set.  This is usually the interface speed.");
731
		}
732 61e047a5 Phil Davis
		if ($data['bandwidth'] && (!is_numeric($data['bandwidth']))) {
733 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("Bandwidth must be an integer.");
734 61e047a5 Phil Davis
		}
735
		if ($data['bandwidth'] < 0) {
736 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("Bandwidth cannot be negative.");
737 61e047a5 Phil Davis
		}
738 45eeb038 Luiz Otavio O Souza
		if ($data['bandwidthtype'] == "%") {
739
			if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0) {
740
				$input_errors[] = gettext("Bandwidth in percentage should be between 1 and 100.");
741
			}
742
		}
743
		if ($this->CheckBandwidth($data['bandwidth'], $data['bandwidthtype']))
744
			$input_errors[] = "The sum of child bandwidth is higher than parent.";
745
746 61e047a5 Phil Davis
		if ($data['qlimit'] && (!is_numeric($data['qlimit']))) {
747 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("Qlimit must be an integer.");
748 61e047a5 Phil Davis
		}
749
		if ($data['qlimit'] < 0) {
750 794195d1 Phil Davis
			$input_errors[] = gettext("Qlimit must be positive.");
751 61e047a5 Phil Davis
		}
752
		if ($data['tbrconfig'] && (!is_numeric($data['tbrconfig']))) {
753 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("Tbrsize must be an integer.");
754 61e047a5 Phil Davis
		}
755
		if ($data['tbrconfig'] < 0) {
756 794195d1 Phil Davis
			$input_errors[] = gettext("Tbrsize must be positive.");
757 61e047a5 Phil Davis
		}
758 92125c97 Ermal Luçi
	}
759 197bfe96 Ermal Luçi
760
	/* Implement this to shorten some code on the frontend page */
761 f5881023 Ermal Lu?i
	function ReadConfig(&$conf) {
762 61e047a5 Phil Davis
		if (isset($conf['tbrconfig'])) {
763 f5881023 Ermal Lu?i
			$this->SetTbrConfig($conf['tbrconfig']);
764 61e047a5 Phil Davis
		} else {
765 06f3e447 Ermal
			$this->SetTbrConfig($conf['tbrconfig']);
766 61e047a5 Phil Davis
		}
767 1941345c Ermal
		$this->SetBandwidth($conf['bandwidth']);
768 61e047a5 Phil Davis
		if ($conf['bandwidthtype'] <> "") {
769 1941345c Ermal
			$this->SetBwscale($conf['bandwidthtype']);
770 61e047a5 Phil Davis
		}
771 197bfe96 Ermal Luçi
		if (isset($conf['scheduler'])) {
772 f5881023 Ermal Lu?i
			if ($this->GetScheduler() != $conf['scheduler']) {
773
				foreach ($this->queues as $q) {
774
					clean_child_queues($conf['scheduler'], $this->GetLink());
775
					$q->clean_queue($conf['scheduler']);
776 061f78b1 Bill Marquette
				}
777
			}
778 f5881023 Ermal Lu?i
			$this->SetScheduler($conf['scheduler']);
779
		}
780 61e047a5 Phil Davis
		if (isset($conf['qlimit']) && $conf['qlimit'] <> "") {
781 197bfe96 Ermal Luçi
			$this->SetQlimit($conf['qlimit']);
782 61e047a5 Phil Davis
		} else {
783 06f3e447 Ermal
			$this->SetQlimit("");
784 61e047a5 Phil Davis
		}
785
		if (isset($conf['name'])) {
786 420b4538 Renato Botelho
			$this->SetQname($conf['name']);
787 61e047a5 Phil Davis
		}
788
		if (!empty($conf['enabled'])) {
789 f5881023 Ermal Lu?i
			$this->SetEnabled($conf['enabled']);
790 61e047a5 Phil Davis
		} else {
791 ea25d26d Ermal Lu?i
			$this->SetEnabled("");
792 61e047a5 Phil Davis
		}
793 197bfe96 Ermal Luçi
	}
794 f5881023 Ermal Lu?i
795 a843b04f Ermal Luçi
	function copy_queue($interface, &$cflink) {
796 420b4538 Renato Botelho
		$cflink['interface'] = $interface;
797
		$cflink['name'] = $interface;
798
		$cflink['scheduler'] = $this->GetScheduler();
799
		$cflink['bandwidth'] = $this->GetBandwidth();
800
		$cflink['bandwidthtype'] = $this->GetBwscale();
801
		$cflink['qlimit'] = $this->GetQlimit();
802
		$cflink['tbrconfig'] = $this->GetTbrConfig();
803
		$cflink['enabled'] = $this->GetEnabled();
804 a843b04f Ermal Luçi
		if (is_array($this->queues)) {
805
			$cflink['queue'] = array();
806
			foreach ($this->queues as $q) {
807
				$cflink['queue'][$q->GetQname()] = array();
808 dbf2dde4 Renato Botelho
				$q->copy_queue($interface, $cflink['queue'][$q->GetQname()]);
809 a843b04f Ermal Luçi
			}
810 92125c97 Ermal Luçi
		}
811 061f78b1 Bill Marquette
	}
812
813 ea51e9f8 Renato Botelho
	function &get_queue_list(&$q = null) {
814 f5881023 Ermal Lu?i
		$qlist = array();
815 b7ff5e40 Scott Ullrich
816 8484586f Ermal
		//$qlist[$this->GetQname()] = & $this;
817 f5881023 Ermal Lu?i
		if (is_array($this->queues)) {
818 61e047a5 Phil Davis
			foreach ($this->queues as $queue) {
819 ea51e9f8 Renato Botelho
				$queue->get_queue_list($qlist);
820 61e047a5 Phil Davis
			}
821 fe93b17b Ermal Luçi
		}
822 f5881023 Ermal Lu?i
		return $qlist;
823
	}
824 fe93b17b Ermal Luçi
825 f5881023 Ermal Lu?i
	function &add_queue($interface, &$queue, &$path, &$input_errors) {
826 92125c97 Ermal Luçi
827 61e047a5 Phil Davis
		if (!is_array($this->queues)) {
828 f5881023 Ermal Lu?i
			$this->queues = array();
829 61e047a5 Phil Davis
		}
830 f5881023 Ermal Lu?i
831
		switch ($this->GetScheduler()) {
832 61e047a5 Phil Davis
			case "PRIQ":
833 5c4fcabc Renato Botelho
				$__tmp_q = new priq_queue(); $q =& $__tmp_q;
834 61e047a5 Phil Davis
				break;
835
			case "HFSC":
836 5c4fcabc Renato Botelho
				$__tmp_q = new hfsc_queue(); $q =& $__tmp_q;
837 61e047a5 Phil Davis
				break;
838
			case "CBQ":
839 5c4fcabc Renato Botelho
				$__tmp_q = new cbq_queue(); $q =& $__tmp_q;
840 61e047a5 Phil Davis
				break;
841
			case "FAIRQ":
842 5c4fcabc Renato Botelho
				$__tmp_q = new fairq_queue(); $q =& $__tmp_q;
843 61e047a5 Phil Davis
				break;
844
			default:
845
				/* XXX: but should not happen anyway */
846
				return;
847
				break;
848 f5881023 Ermal Lu?i
		}
849
		$q->SetLink($path);
850
		$q->SetInterface($this->GetInterface());
851
		$q->SetEnabled("on");
852 ea51e9f8 Renato Botelho
		$q->SetParent($this);
853 f5881023 Ermal Lu?i
		$q->ReadConfig($queue);
854
		$q->validate_input($queue, $input_errors);
855 197bfe96 Ermal Luçi
856 420b4538 Renato Botelho
		$this->queues[$q->GetQname()] = &$q;
857 f5881023 Ermal Lu?i
		ref_on_altq_queue_list($this->GetQname(), $q->GetQname());
858
		if (is_array($queue['queue'])) {
859
			foreach ($queue['queue'] as $key1 => $que) {
860
				array_push($path, $key1);
861 ea51e9f8 Renato Botelho
				$q->add_queue($q->GetInterface(), $que, $path, $input_errors);
862 f5881023 Ermal Lu?i
				array_pop($path);
863
			}
864
		}
865
866
		return $q;
867
	}
868
869
	/* interface here might be optional */
870
	function &find_queue($interface, $qname) {
871
		if ($qname == $this->GetQname()) {
872
			return $this;
873 420b4538 Renato Botelho
		}
874 f5881023 Ermal Lu?i
		foreach ($this->queues as $q) {
875
			$result =& $q->find_queue("", $qname);
876 61e047a5 Phil Davis
			if ($result) {
877 f5881023 Ermal Lu?i
				return $result;
878 61e047a5 Phil Davis
			}
879 f5881023 Ermal Lu?i
		}
880
	}
881 197bfe96 Ermal Luçi
882
	function &find_parentqueue($interface, $qname) {
883
		if ($qname == $interface) {
884 4de8f7ba Phil Davis
			$result = NULL;
885 420b4538 Renato Botelho
		} else if ($this->queues[$qname]) {
886 197bfe96 Ermal Luçi
			$result = $this;
887
		} else if ($this->GetScheduler() <> "PRIQ") {
888
			foreach ($this->queues as $q) {
889
				$result = $q->find_parentqueue("", $qname);
890 61e047a5 Phil Davis
				if ($result) {
891 197bfe96 Ermal Luçi
					return $result;
892 61e047a5 Phil Davis
				}
893 b7ff5e40 Scott Ullrich
			}
894 061f78b1 Bill Marquette
		}
895
	}
896
897 197bfe96 Ermal Luçi
	function build_tree() {
898 057399e4 Ermal Luçi
		global $shaperIFlist;
899
900 420b4538 Renato Botelho
		$tree = " <li><a href=\"firewall_shaper.php?interface=".$this->GetInterface()."&amp;queue=". $this->GetInterface()."&amp;action=show";
901 057399e4 Ermal Luçi
		$tree .= "\">" . $shaperIFlist[$this->GetInterface()] . "</a>";
902 197bfe96 Ermal Luçi
		if (is_array($this->queues)) {
903
			$tree .= "<ul>";
904 4de8f7ba Phil Davis
			foreach ($this->queues as $q) {
905 197bfe96 Ermal Luçi
				$tree .= $q->build_tree();
906
			}
907 61e047a5 Phil Davis
			$tree .= "</ul>";
908 197bfe96 Ermal Luçi
		}
909
		$tree .= "</li>";
910
		return $tree;
911
	}
912 ce0117f7 Colin Fleming
913 420b4538 Renato Botelho
	function delete_queue() {
914 45eeb038 Luiz Otavio O Souza
		foreach ($this->queues as $q)
915 420b4538 Renato Botelho
			$q->delete_queue();
916 197bfe96 Ermal Luçi
		unset_object_by_reference($this->GetLink());
917 420b4538 Renato Botelho
	}
918 92125c97 Ermal Luçi
919 b0262cb2 Ermal Luçi
	function delete_all() {
920 420b4538 Renato Botelho
		if (count($this->queues)) {
921
			foreach ($this->queues as $q) {
922
				$q->delete_all();
923
				unset_object_by_reference($q->GetLink());
924
				unset($q);
925
			}
926
			unset($this->queues);
927
		}
928
	}
929 b0262cb2 Ermal Luçi
930 92125c97 Ermal Luçi
	/*
931
	 * First it spits:
932
	 * altq on $interface ..............
933 6990ad35 Phil Davis
	 *	then it goes like
934
	 *	foreach ($queues as $qkey => $queue) {
935
	 *		this->queues[$qkey]->build_rule();
936
	 *	}
937 92125c97 Ermal Luçi
	 */
938 9d0b0635 Ermal
	function build_rules(&$default = false) {
939 34a3694b Ermal
		if (count($this->queues) > 0 && $this->GetEnabled() == "on") {
940 ef8fca71 Ermal
			$default = false;
941 4de8f7ba Phil Davis
			$rules = " altq on " . get_real_interface($this->GetInterface());
942 61e047a5 Phil Davis
			if ($this->GetScheduler()) {
943 f5881023 Ermal Lu?i
				$rules .= " ".strtolower($this->GetScheduler());
944 61e047a5 Phil Davis
			}
945
			if ($this->GetQlimit() > 0) {
946 a061ddb9 Chris Buechler
				$rules .= " qlimit " . $this->GetQlimit() . " ";
947 61e047a5 Phil Davis
			}
948 1941345c Ermal
			if ($this->GetBandwidth()) {
949 f5881023 Ermal Lu?i
				$rules .= " bandwidth ".trim($this->GetBandwidth());
950 61e047a5 Phil Davis
				if ($this->GetBwscale()) {
951 1941345c Ermal
					$rules .= $this->GetBwscale();
952 61e047a5 Phil Davis
				}
953 1941345c Ermal
			}
954 61e047a5 Phil Davis
			if ($this->GetTbrConfig()) {
955 f5881023 Ermal Lu?i
				$rules .= " tbrsize ".$this->GetTbrConfig();
956 61e047a5 Phil Davis
			}
957 92125c97 Ermal Luçi
			if (count($this->queues)) {
958 f5881023 Ermal Lu?i
				$i = count($this->queues);
959
				$rules .= " queue { ";
960
				foreach ($this->queues as $qkey => $qnone) {
961
					if ($i > 1) {
962
						$i--;
963
						$rules .= " {$qkey}, ";
964 61e047a5 Phil Davis
					} else {
965 f5881023 Ermal Lu?i
						$rules .= " {$qkey} ";
966 61e047a5 Phil Davis
					}
967 f5881023 Ermal Lu?i
				}
968
				$rules .= " } \n";
969
				foreach ($this->queues as $q) {
970 9d0b0635 Ermal
					$rules .= $q->build_rules($default);
971 f5881023 Ermal Lu?i
				}
972 92125c97 Ermal Luçi
			}
973 8edaa92c Ermal
974 ef8fca71 Ermal
			if ($default == false) {
975 e8c516a0 Phil Davis
				$error = sprintf(gettext("SHAPER: no default queue specified for interface %s."), $this->GetInterface()) . " " . gettext("The interface queue will be enforced as default.");
976 8633930d Ermal
				file_notice("Shaper", $error, "Error occurred", "");
977
				unset($error);
978 ef8fca71 Ermal
				return "\n";
979 420b4538 Renato Botelho
			}
980 ef8fca71 Ermal
			$frule .= $rules;
981 8edaa92c Ermal
		} else if ($this->GetEnabled() == "on" && $this->GetScheduler() == "CODELQ") {
982 4de8f7ba Phil Davis
			$rules = " altq on " . get_real_interface($this->GetInterface());
983 61e047a5 Phil Davis
			if ($this->GetScheduler()) {
984 8edaa92c Ermal
				$rules .= " ".strtolower($this->GetScheduler());
985 61e047a5 Phil Davis
			}
986
			if ($this->GetQlimit() > 0) {
987 8edaa92c Ermal
				$rules .= " ( qlimit " . $this->GetQlimit() . " ) ";
988 61e047a5 Phil Davis
			}
989 8edaa92c Ermal
			if ($this->GetBandwidth()) {
990
				$rules .= " bandwidth ".trim($this->GetBandwidth());
991 61e047a5 Phil Davis
				if ($this->GetBwscale()) {
992 8edaa92c Ermal
					$rules .= $this->GetBwscale();
993 61e047a5 Phil Davis
				}
994 8edaa92c Ermal
			}
995 61e047a5 Phil Davis
			if ($this->GetTbrConfig()) {
996 8edaa92c Ermal
				$rules .= " tbrsize ".$this->GetTbrConfig();
997 61e047a5 Phil Davis
			}
998 8edaa92c Ermal
999
			$rules .= " queue";
1000 197bfe96 Ermal Luçi
		}
1001 8edaa92c Ermal
1002 197bfe96 Ermal Luçi
		$rules .= " \n";
1003 92125c97 Ermal Luçi
		return $rules;
1004
	}
1005 197bfe96 Ermal Luçi
1006
	function build_javascript() {
1007 f5881023 Ermal Lu?i
		$javascript = "<script type=\"text/javascript\">";
1008 ee02550a Michele Di Maria
		$javascript .= "//<![CDATA[\n";
1009 f5881023 Ermal Lu?i
		$javascript .= "function mySuspend() {";
1010 01890f6a Ermal
		$javascript .= "if (document.layers && document.layers['shaperarea'] != null) ";
1011
		$javascript .= "document.layers['shaperarea'].visibility = 'hidden'; ";
1012 f5881023 Ermal Lu?i
		$javascript .= "else if (document.all)";
1013
		$javascript .= "document.all['shaperarea'].style.visibility = 'hidden';";
1014
		$javascript .= "}";
1015
1016
		$javascript .= "function myResume() {";
1017 01890f6a Ermal
		$javascript .= "if (document.layers && document.layers['shaperarea'] != null) ";
1018 f5881023 Ermal Lu?i
		$javascript .= "document.layers['shaperarea'].visibility = 'visible';";
1019 01890f6a Ermal
		$javascript .= "else if (document.all) ";
1020 f5881023 Ermal Lu?i
		$javascript .= "document.all['shaperarea'].style.visibility = 'visible';";
1021
		$javascript .= "}";
1022 0fa05f45 Colin Fleming
		$javascript .= "//]]>";
1023 f5881023 Ermal Lu?i
		$javascript .= "</script>";
1024
1025
		return $javascript;
1026 92125c97 Ermal Luçi
	}
1027 ce0117f7 Colin Fleming
1028 92125c97 Ermal Luçi
	function build_shortform() {
1029 f5881023 Ermal Lu?i
		global $g;
1030
1031
		$altq =& $this;
1032 d17c4ee9 Stephen Beaver
1033 61e047a5 Phil Davis
		if ($altq) {
1034 f5881023 Ermal Lu?i
			$scheduler = ": " . $altq->GetScheduler();
1035 61e047a5 Phil Davis
		}
1036 f5881023 Ermal Lu?i
1037 b28e1512 Stephen Beaver
		$form = '<dl class="dl-horizontal">';
1038
		$form .= '	<dt>';
1039
		$form .= '		<a href="firewall_shaper.php?interface=' . $this->GetInterface() . '&amp;queue=' . $this->GetQname() . '&amp;action=show">' . $shaperIFlist[$this->GetInterface()] . '</a>';
1040
		$form .= '	</dt>';
1041
		$form .= '	<dd>';
1042 d17c4ee9 Stephen Beaver
		$form .=		$scheduler;
1043 b28e1512 Stephen Beaver
		$form .= '	</dd>';
1044 d17c4ee9 Stephen Beaver
1045 b28e1512 Stephen Beaver
		$form .= '	<dt>';
1046 d17c4ee9 Stephen Beaver
		$form .=		'Bandwidth';
1047 b28e1512 Stephen Beaver
		$form .= '	</dt>';
1048
		$form .= '	<dd>';
1049 bfc94df0 Phil Davis
		$form .=		$this->GetBandwidth() . '&nbsp;' . $this->GetBwscaleText();
1050 b28e1512 Stephen Beaver
		$form .= '	</dd>';
1051 d17c4ee9 Stephen Beaver
1052
		$form .= '	<dt>';
1053 b28e1512 Stephen Beaver
		$form .= 'Disable';
1054
		$form .= '	<dt>';
1055
		$form .= '	<dd>';
1056
1057 27d6a45b jim-p
		$form .= '<a class="btn btn-danger btn-xs" href="firewall_shaper_queues.php?interface=';
1058 b28e1512 Stephen Beaver
		$form .= $this->GetInterface() . '&amp;queue=';
1059
		$form .= $this->GetQname() . '&amp;action=delete">';
1060 27d6a45b jim-p
		$form .= '<i class="fa fa-trash icon-embed-btn"></i>';
1061
		$form .= gettext("Remove shaper from this interface") . '</a>';
1062 b28e1512 Stephen Beaver
1063 d17c4ee9 Stephen Beaver
		$form .= '	</dd>';
1064
1065
		$form .= '</dl>';
1066
1067 f5881023 Ermal Lu?i
		return $form;
1068 92125c97 Ermal Luçi
1069
	}
1070 aef9d8fe Stephen Beaver
1071 f5881023 Ermal Lu?i
	/*
1072 ce0117f7 Colin Fleming
	 * For requesting the parameters of the root queues
1073 f5881023 Ermal Lu?i
	 * to the user like the traffic wizard does.
1074 806942d0 Stephen Beaver
	 */
1075 420b4538 Renato Botelho
	function build_form() {
1076 806942d0 Stephen Beaver
1077 27d6a45b jim-p
		$sform = new Form();
1078 806942d0 Stephen Beaver
1079 a51c7c7f Stephen Beaver
		$sform->setAction("firewall_shaper.php");
1080
1081 aef9d8fe Stephen Beaver
		$section = new Form_Section(null);
1082 806942d0 Stephen Beaver
1083 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Checkbox(
1084
			'enabled',
1085
			'Enable/Disable',
1086
			'Enable/disable discipline and its children',
1087
			($this->GetEnabled() == "on"),
1088
			'on'
1089
		));
1090 806942d0 Stephen Beaver
1091 aef9d8fe Stephen Beaver
		$section->addInput(new Form_StaticText(
1092 40dcb4b6 Phil Davis
			'*Name',
1093 aef9d8fe Stephen Beaver
			$this->GetQname()
1094
		));
1095 806942d0 Stephen Beaver
1096 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Select(
1097
			'scheduler',
1098
			'Scheduler Type',
1099
			$this->GetScheduler(),
1100 806942d0 Stephen Beaver
			array('HFSC' => 'HFSC',
1101 aef9d8fe Stephen Beaver
				  'CBQ' => 'CBQ',
1102
				  'FAIRQ' => 'FAIRQ',
1103
				  'CODELQ' => 'CODELQ',
1104
				  'PRIQ' => 'PRIQ')
1105 530e4707 NOYB
		))->setHelp('Changing this changes all child queues! Beware information can be lost.');
1106 806942d0 Stephen Beaver
1107 aef9d8fe Stephen Beaver
		$group = new Form_group('Bandwidth');
1108 806942d0 Stephen Beaver
1109 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
1110
			'bandwidth',
1111
			null,
1112
			'number',
1113
			$this->GetBandwidth()
1114
		));
1115 806942d0 Stephen Beaver
1116 aef9d8fe Stephen Beaver
		$group->add(new Form_Select(
1117
			'bandwidthtype',
1118
			null,
1119
			$this->GetBwscale(),
1120 bfc94df0 Phil Davis
			array('Kb' => 'Kbit/s',
1121
				  'Mb' => 'Mbit/s',
1122
				  'Gb' => 'Gbit/s',
1123
				  'b' => 'Bit/s',
1124 820519e5 Stephen Beaver
				  '%' => '%')
1125 aef9d8fe Stephen Beaver
		));
1126 806942d0 Stephen Beaver
1127 aef9d8fe Stephen Beaver
		$section->add($group);
1128 806942d0 Stephen Beaver
1129 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Input(
1130
			'qlimit',
1131
			'Queue Limit',
1132
			'number',
1133
			$this->GetQlimit()
1134
		));
1135 806942d0 Stephen Beaver
1136 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Input(
1137
			'tbrconfig',
1138 e643627c Ben Cook
			'TBR Size',
1139 aef9d8fe Stephen Beaver
			'number',
1140
			$this->GetTbrConfig()
1141
		))->setHelp('Adjusts the size, in bytes, of the token bucket regulator. If not specified, heuristics based on the interface ' .
1142 806942d0 Stephen Beaver
					'bandwidth are used to determine the size.');
1143
1144 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Input(
1145
			'interface',
1146
			null,
1147
			'hidden',
1148
			$this->GetInterface()
1149
		));
1150 806942d0 Stephen Beaver
1151 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Input(
1152
			'name',
1153
			null,
1154
			'hidden',
1155
			$this->GetQname()
1156
		));
1157 806942d0 Stephen Beaver
1158 aef9d8fe Stephen Beaver
		$sform->add($section);
1159 806942d0 Stephen Beaver
1160 aef9d8fe Stephen Beaver
		return($sform);
1161 197bfe96 Ermal Luçi
	}
1162 061f78b1 Bill Marquette
1163 420b4538 Renato Botelho
	function update_altq_queue_data(&$data) {
1164 197bfe96 Ermal Luçi
		$this->ReadConfig($data);
1165 061f78b1 Bill Marquette
	}
1166 ce0117f7 Colin Fleming
1167 92125c97 Ermal Luçi
	/*
1168
	 * Should call on each of it queues and subqueues
1169
	 * the same function much like build_rules();
1170
	 */
1171 420b4538 Renato Botelho
	function wconfig() {
1172 92125c97 Ermal Luçi
		$cflink = &get_reference_to_me_in_config($this->GetLink());
1173 61e047a5 Phil Davis
		if (!is_array($cflink)) {
1174 92125c97 Ermal Luçi
			$cflink = array();
1175 61e047a5 Phil Davis
		}
1176 420b4538 Renato Botelho
		$cflink['interface'] = $this->GetInterface();
1177 92125c97 Ermal Luçi
		$cflink['name'] = $this->GetQname();
1178
		$cflink['scheduler'] = $this->GetScheduler();
1179
		$cflink['bandwidth'] = $this->GetBandwidth();
1180
		$cflink['bandwidthtype'] = $this->GetBwscale();
1181 f5881023 Ermal Lu?i
		$cflink['qlimit'] = trim($this->GetQlimit());
1182 61e047a5 Phil Davis
		if (empty($cflink['qlimit'])) {
1183 f5881023 Ermal Lu?i
			unset($cflink['qlimit']);
1184 61e047a5 Phil Davis
		}
1185 f5881023 Ermal Lu?i
		$cflink['tbrconfig'] = trim($this->GetTbrConfig());
1186 61e047a5 Phil Davis
		if (empty($cflink['tbrconfig'])) {
1187 f5881023 Ermal Lu?i
			unset($cflink['tbrconfig']);
1188 61e047a5 Phil Davis
		}
1189 92125c97 Ermal Luçi
		$cflink['enabled'] = $this->GetEnabled();
1190 61e047a5 Phil Davis
		if (empty($cflink['enabled'])) {
1191 f5881023 Ermal Lu?i
			unset($cflink['enabled']);
1192 61e047a5 Phil Davis
		}
1193 92125c97 Ermal Luçi
	}
1194 061f78b1 Bill Marquette
1195 197bfe96 Ermal Luçi
}
1196 061f78b1 Bill Marquette
1197 197bfe96 Ermal Luçi
class priq_queue {
1198 92125c97 Ermal Luçi
	var $qname;
1199 420b4538 Renato Botelho
	var $qinterface;
1200 92125c97 Ermal Luçi
	var $qlimit;
1201
	var $qpriority;
1202
	var $description;
1203
	var $isparent;
1204 197bfe96 Ermal Luçi
	var $qbandwidth;
1205
	var $qbandwidthtype;
1206 f5881023 Ermal Lu?i
	var $qdefault = "";
1207
	var $qrio = "";
1208
	var $qred = "";
1209 8edaa92c Ermal
	var $qcodel = "";
1210 f5881023 Ermal Lu?i
	var $qecn = "";
1211 197bfe96 Ermal Luçi
	var $qack;
1212 f5881023 Ermal Lu?i
	var $qenabled = "";
1213 197bfe96 Ermal Luçi
	var $qparent;
1214
	var $link;
1215 92125c97 Ermal Luçi
1216 70b139a3 Chris Buechler
	/* This is here to help with form building and building rules/lists */
1217 57c448d0 Ermal
	var $subqueues = array();
1218 92125c97 Ermal Luçi
1219 d6fa899d Phil Davis
	/* Accessor functions */
1220 92125c97 Ermal Luçi
	function SetLink($link) {
1221 f5881023 Ermal Lu?i
		$this->link = $link;
1222 92125c97 Ermal Luçi
	}
1223
	function GetLink() {
1224 f5881023 Ermal Lu?i
		return $this->link;
1225 92125c97 Ermal Luçi
	}
1226 197bfe96 Ermal Luçi
	function &GetParent() {
1227
		return $this->qparent;
1228
	}
1229
	function SetParent(&$parent) {
1230
		$this->qparent = &$parent;
1231
	}
1232 92125c97 Ermal Luçi
	function GetEnabled() {
1233 f5881023 Ermal Lu?i
		return $this->qenabled;
1234 92125c97 Ermal Luçi
	}
1235
	function SetEnabled($value) {
1236 f5881023 Ermal Lu?i
		$this->qenabled = $value;
1237 92125c97 Ermal Luçi
	}
1238 70b139a3 Chris Buechler
	function CanHaveChildren() {
1239 f5881023 Ermal Lu?i
		return false;
1240 92125c97 Ermal Luçi
	}
1241 197bfe96 Ermal Luçi
	function CanBeDeleted() {
1242 f5881023 Ermal Lu?i
		return true;
1243 92125c97 Ermal Luçi
	}
1244
	function GetQname() {
1245 f5881023 Ermal Lu?i
		return $this->qname;
1246 92125c97 Ermal Luçi
	}
1247
	function SetQname($name) {
1248 f5881023 Ermal Lu?i
		$this->qname = trim($name);
1249 92125c97 Ermal Luçi
	}
1250
	function GetBandwidth() {
1251 f5881023 Ermal Lu?i
		return $this->qbandwidth;
1252 92125c97 Ermal Luçi
	}
1253
	function SetBandwidth($bandwidth) {
1254 f5881023 Ermal Lu?i
		$this->qbandwidth = $bandwidth;
1255 92125c97 Ermal Luçi
	}
1256
	function GetInterface() {
1257 f5881023 Ermal Lu?i
		return $this->qinterface;
1258 92125c97 Ermal Luçi
	}
1259
	function SetInterface($name) {
1260 f5881023 Ermal Lu?i
		$this->qinterface = trim($name);
1261 92125c97 Ermal Luçi
	}
1262
	function GetQlimit() {
1263 f5881023 Ermal Lu?i
		return $this->qlimit;
1264 92125c97 Ermal Luçi
	}
1265
	function SetQlimit($limit) {
1266 f5881023 Ermal Lu?i
		$this->qlimit = $limit;
1267 92125c97 Ermal Luçi
	}
1268
	function GetQpriority() {
1269 f5881023 Ermal Lu?i
		return $this->qpriority;
1270 92125c97 Ermal Luçi
	}
1271
	function SetQpriority($priority) {
1272 f5881023 Ermal Lu?i
		$this->qpriority = $priority;
1273 92125c97 Ermal Luçi
	}
1274
	function GetDescription() {
1275 f5881023 Ermal Lu?i
		return $this->description;
1276 92125c97 Ermal Luçi
	}
1277
	function SetDescription($str) {
1278 f5881023 Ermal Lu?i
		$this->description = trim($str);
1279 92125c97 Ermal Luçi
	}
1280
	function GetFirstime() {
1281 f5881023 Ermal Lu?i
		return $this->firsttime;
1282 92125c97 Ermal Luçi
	}
1283
	function SetFirsttime($number) {
1284 f5881023 Ermal Lu?i
		$this->firsttime = $number;
1285 92125c97 Ermal Luçi
	}
1286 45eeb038 Luiz Otavio O Souza
	function CheckBandwidth($bw, $bwtype) {
1287
		$parent = $this->GetParent();
1288 fbbd7d2b Steve Beaver
1289
		// If the child queues have bandwidth specified in %, there is no point trying
1290
		// to compare the total to the parent's bandwidth, which is defined in Kb/S or Mb/S etc.
1291
		// ToDo: Add check for total % > 100
1292
		//		 If one child is in %, they must all be
1293
1294
		if ($bwtype != "%") {
1295
			$sum = $parent->GetTotalBw(($bw > 0) ? $this : NULL);
1296
1297
			if ($bw > 0) {
1298
				$sum += get_bandwidth($bw, $bwtype, $parent);
1299
			}
1300
1301
			if ($sum > get_queue_bandwidth($parent)) {
1302
				return 1;
1303
			}
1304
		}
1305 45eeb038 Luiz Otavio O Souza
1306
		foreach ($this->subqueues as $q) {
1307 fbbd7d2b Steve Beaver
			if ($q->CheckBandwidth(0, '')) {
1308 45eeb038 Luiz Otavio O Souza
				return 1;
1309 fbbd7d2b Steve Beaver
			}
1310 45eeb038 Luiz Otavio O Souza
		}
1311
1312
		return 0;
1313
	}
1314
	function GetTotalBw($qignore = NULL) {
1315 2638ddec Luiz Otavio O Souza
		$sum = 0;
1316
		foreach ($this->subqueues as $q) {
1317 45eeb038 Luiz Otavio O Souza
			if ($qignore != NULL && $qignore == $q)
1318
				continue;
1319
			$sum += get_bandwidth($q->GetBandwidth(), $q->GetBwscale(), $q->GetParent());
1320 2638ddec Luiz Otavio O Souza
		}
1321
1322
		return $sum;
1323
	}
1324 92125c97 Ermal Luçi
	function GetBwscale() {
1325 f5881023 Ermal Lu?i
		return $this->qbandwidthtype;
1326 92125c97 Ermal Luçi
	}
1327
	function SetBwscale($scale) {
1328 f5881023 Ermal Lu?i
		$this->qbandwidthtype = $scale;
1329 92125c97 Ermal Luçi
	}
1330 f61dc8e6 Ermal
	function GetDefaultQueuePresent() {
1331 61e047a5 Phil Davis
		if ($this->GetDefault()) {
1332 f61dc8e6 Ermal
			return true;
1333 61e047a5 Phil Davis
		}
1334 f61dc8e6 Ermal
		if (!empty($this->subqueues)) {
1335
			foreach ($this->subqueues as $q) {
1336 61e047a5 Phil Davis
				if ($q->GetDefault()) {
1337 f61dc8e6 Ermal
					return true;
1338 61e047a5 Phil Davis
				}
1339 f61dc8e6 Ermal
			}
1340
		}
1341
1342
		return false;
1343
	}
1344 197bfe96 Ermal Luçi
	function GetDefault() {
1345 f5881023 Ermal Lu?i
		return $this->qdefault;
1346 92125c97 Ermal Luçi
	}
1347
	function SetDefault($value = false) {
1348 f5881023 Ermal Lu?i
		$this->qdefault = $value;
1349 92125c97 Ermal Luçi
	}
1350 8edaa92c Ermal
	function GetCodel() {
1351
		return $this->codel;
1352
	}
1353
	function SetCodel($codel = false) {
1354
		$this->codel = $codel;
1355
	}
1356 197bfe96 Ermal Luçi
	function GetRed() {
1357 f5881023 Ermal Lu?i
		return $this->qred;
1358 92125c97 Ermal Luçi
	}
1359
	function SetRed($red = false) {
1360 f5881023 Ermal Lu?i
		$this->qred = $red;
1361 92125c97 Ermal Luçi
	}
1362 197bfe96 Ermal Luçi
	function GetRio() {
1363 f5881023 Ermal Lu?i
		return $this->qrio;
1364 92125c97 Ermal Luçi
	}
1365
	function SetRio($rio = false) {
1366 f5881023 Ermal Lu?i
		$this->qrio = $rio;
1367 92125c97 Ermal Luçi
	}
1368 f5881023 Ermal Lu?i
	function GetEcn() {
1369
		return $this->qecn;
1370 92125c97 Ermal Luçi
	}
1371
	function SetEcn($ecn = false) {
1372 f5881023 Ermal Lu?i
		$this->qecn = $ecn;
1373 92125c97 Ermal Luçi
	}
1374 197bfe96 Ermal Luçi
	function GetAck() {
1375 f5881023 Ermal Lu?i
		return $this->qack;
1376 92125c97 Ermal Luçi
	}
1377
	function SetAck($ack = false) {
1378 f5881023 Ermal Lu?i
		$this->qack = $ack;
1379 92125c97 Ermal Luçi
	}
1380 197bfe96 Ermal Luçi
1381 bfc94df0 Phil Davis
	function GetBwscaleText() {
1382
		switch ($this->qbandwidthtype) {
1383
			case "b":
1384
				$bwscaletext = "Bit/s";
1385
				break;
1386
			case "Kb":
1387
				$bwscaletext = "Kbit/s";
1388
				break;
1389
			case "Mb":
1390
				$bwscaletext = "Mbit/s";
1391
				break;
1392
			case "Gb":
1393
				$bwscaletext = "Gbit/s";
1394
				break;
1395
			default:
1396
				/* For others that do not need translating like % */
1397
				$bwscaletext = $this->qbandwidthtype;
1398
				break;
1399
		}
1400
		return $bwscaletext;
1401
	}
1402
1403 197bfe96 Ermal Luçi
	function build_javascript() {
1404
		$javascript = "<script type=\"text/javascript\">";
1405 ee02550a Michele Di Maria
		$javascript .= "//<![CDATA[\n";
1406 197bfe96 Ermal Luçi
		$javascript .= "function mySuspend() { \n";
1407 01890f6a Ermal
		$javascript .= "if (document.layers && document.layers['shaperarea'] != null)\n";
1408 92125c97 Ermal Luçi
		$javascript .= "document.layers['shaperarea'].visibility = 'hidden';\n";
1409
		$javascript .= "else if (document.all)\n";
1410
		$javascript .= "document.all['shaperarea'].style.visibility = 'hidden';\n";
1411
		$javascript .= "}\n";
1412
1413
		$javascript .= "function myResume() {\n";
1414
		$javascript .= "if (document.layers && document.layers['shaperarea'] != null)\n";
1415
		$javascript .= "document.layers['shaperarea'].visibility = 'visible';\n";
1416
		$javascript .= "else if (document.all)\n";
1417
		$javascript .= "document.all['shaperarea'].style.visibility = 'visible';\n";
1418
		$javascript .= "}\n";
1419 0fa05f45 Colin Fleming
		$javascript .= "//]]>";
1420 92125c97 Ermal Luçi
		$javascript .= "</script>";
1421 ce0117f7 Colin Fleming
1422 197bfe96 Ermal Luçi
		return $javascript;
1423
	}
1424 ce0117f7 Colin Fleming
1425 6f627d41 Ermal Luçi
	function &add_queue($interface, &$qname, &$path, &$input_errors) { return; }
1426
1427 420b4538 Renato Botelho
	/*
1428
	 * Currently this will not be called unless we decide to clone a whole
1429 197bfe96 Ermal Luçi
	 * queue tree on the 'By Queues' view or support drag&drop on the tree/list
1430
	 */
1431 420b4538 Renato Botelho
	function copy_queue($interface, &$cflink) {
1432
1433
		$cflink['name'] = $this->GetQname();
1434
		$cflink['interface'] = $interface;
1435
		$cflink['qlimit'] = $this->GetQlimit();
1436
		$cflink['priority'] = $this->GetQpriority();
1437
		$cflink['description'] = $this->GetDescription();
1438
		$cflink['enabled'] = $this->GetEnabled();
1439
		$cflink['default'] = $this->GetDefault();
1440
		$cflink['red'] = $this->GetRed();
1441
		$cflink['codel'] = $this->GetCodel();
1442
		$cflink['rio'] = $this->GetRio();
1443
		$cflink['ecn'] = $this->GetEcn();
1444
1445
		if (is_array($this->subqueues)) {
1446
			$cflinkp['queue'] = array();
1447
			foreach ($this->subqueues as $q) {
1448
				$cflink['queue'][$q->GetQname()] = array();
1449
				$q->copy_queue($interface, $cflink['queue'][$q->GetQname()]);
1450 a843b04f Ermal Luçi
			}
1451 420b4538 Renato Botelho
		}
1452
	}
1453 197bfe96 Ermal Luçi
1454
	function clean_queue($sched) {
1455 92125c97 Ermal Luçi
		clean_child_queues($sched, $this->GetLink());
1456
		if (is_array($this->subqueues)) {
1457 61e047a5 Phil Davis
			foreach ($this->subqueues as $q) {
1458 f5881023 Ermal Lu?i
				$q->clean_queue($sched);
1459 61e047a5 Phil Davis
			}
1460 92125c97 Ermal Luçi
		}
1461 f5881023 Ermal Lu?i
	}
1462 197bfe96 Ermal Luçi
1463 420b4538 Renato Botelho
	function &get_queue_list(&$qlist) {
1464 ce0117f7 Colin Fleming
1465 f5881023 Ermal Lu?i
		$qlist[$this->GetQname()] = & $this;
1466
		if (is_array($this->subqueues)) {
1467 61e047a5 Phil Davis
			foreach ($this->subqueues as $queue) {
1468 f5881023 Ermal Lu?i
				$queue->get_queue_list($qlist);
1469 61e047a5 Phil Davis
			}
1470 f5881023 Ermal Lu?i
		}
1471
	}
1472 fe93b17b Ermal Luçi
1473 197bfe96 Ermal Luçi
	function delete_queue() {
1474 92125c97 Ermal Luçi
		unref_on_altq_queue_list($this->GetQname());
1475
		cleanup_queue_from_rules($this->GetQname());
1476
		unset_object_by_reference($this->GetLink());
1477
	}
1478 ce0117f7 Colin Fleming
1479 b0262cb2 Ermal Luçi
	function delete_all() {
1480 420b4538 Renato Botelho
		if (count($this->subqueues)) {
1481
			foreach ($this->subqueues as $q) {
1482
				$q->delete_all();
1483
				unset_object_by_reference($q->GetLink());
1484
				unset($q);
1485
			}
1486
			unset($this->subqueues);
1487
		}
1488
	}
1489
1490
	function &find_queue($interface, $qname) {
1491 61e047a5 Phil Davis
		if ($qname == $this->GetQname()) {
1492 420b4538 Renato Botelho
			return $this;
1493 61e047a5 Phil Davis
		}
1494 197bfe96 Ermal Luçi
	}
1495 ce0117f7 Colin Fleming
1496 62150088 Ermal Lu?i
	function find_parentqueue($interface, $qname) { return; }
1497 ce0117f7 Colin Fleming
1498 92125c97 Ermal Luçi
	function validate_input($data, &$input_errors) {
1499 ce0117f7 Colin Fleming
1500 2c072899 jim-p
		$reqdfields[] = "name";
1501 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Name");
1502 40de74f5 Ermal Luçi
		shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
1503 197bfe96 Ermal Luçi
1504 61e047a5 Phil Davis
		if ($data['bandwidth'] && (!is_numeric($data['bandwidth']))) {
1505 e8c516a0 Phil Davis
			$input_errors[] = gettext("Bandwidth must be an integer.");
1506 61e047a5 Phil Davis
		}
1507
		if ($data['bandwidth'] < 0) {
1508 e8c516a0 Phil Davis
			$input_errors[] = gettext("Bandwidth cannot be negative.");
1509 61e047a5 Phil Davis
		}
1510 45eeb038 Luiz Otavio O Souza
		if ($data['bandwidthtype'] == "%") {
1511
			if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0) {
1512
				$input_errors[] = gettext("Bandwidth in percentage should be between 1 and 100.");
1513
			}
1514
		}
1515
		if ($this->CheckBandwidth($data['bandwidth'], $data['bandwidthtype']))
1516
			$input_errors[] = "The sum of child bandwidth is higher than parent.";
1517 fbbd7d2b Steve Beaver
1518 41799195 PiBa-NL
		if (isset($data['priority']) && (!is_numeric($data['priority']) ||
1519
		    ($data['priority'] < 0) || ($data['priority'] > 15))) {
1520 fccdc01a Luiz Souza
			$input_errors[] = gettext("The priority must be an integer between 0 and 15.");
1521 92125c97 Ermal Luçi
		}
1522 61e047a5 Phil Davis
		if ($data['qlimit'] && (!is_numeric($data['qlimit']))) {
1523 dbaf21d4 Renato Botelho
				$input_errors[] = gettext("Queue limit must be an integer");
1524 61e047a5 Phil Davis
		}
1525
		if ($data['qlimit'] < 0) {
1526 dbaf21d4 Renato Botelho
				$input_errors[] = gettext("Queue limit must be positive");
1527 61e047a5 Phil Davis
		}
1528
		if (!empty($data['newname']) && !preg_match("/^[a-zA-Z0-9_-]*$/", $data['newname'])) {
1529 420b4538 Renato Botelho
			$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
1530 61e047a5 Phil Davis
		}
1531
		if (!empty($data['name']) && !preg_match("/^[a-zA-Z0-9_-]*$/", $data['name'])) {
1532 420b4538 Renato Botelho
			$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
1533 61e047a5 Phil Davis
		}
1534 f8dca5a3 Renato Botelho
		$default = $this->GetDefault();
1535 61e047a5 Phil Davis
		if (!empty($data['default']) && altq_get_default_queue($data['interface']) && empty($default)) {
1536 f61dc8e6 Ermal
			$input_errors[] = gettext("Only one default queue per interface is allowed.");
1537 61e047a5 Phil Davis
		}
1538 061f78b1 Bill Marquette
	}
1539
1540 92125c97 Ermal Luçi
	function ReadConfig(&$q) {
1541 30ef6f8d Ermal
		if (!empty($q['name']) && !empty($q['newname']) && $q['name'] != $q['newname']) {
1542
			$this->SetQname($q['newname']);
1543
		} else if (!empty($q['newname'])) {
1544
			$this->SetQname($q['newname']);
1545 61e047a5 Phil Davis
		} else if (isset($q['name'])) {
1546 30ef6f8d Ermal
			$this->SetQname($q['name']);
1547 61e047a5 Phil Davis
		}
1548
		if (isset($q['interface'])) {
1549 f61dc8e6 Ermal
			$this->SetInterface($q['interface']);
1550 61e047a5 Phil Davis
		}
1551 0b13e3f9 Ermal
		$this->SetBandwidth($q['bandwidth']);
1552 61e047a5 Phil Davis
		if ($q['bandwidthtype'] <> "") {
1553 0b13e3f9 Ermal
			$this->SetBwscale($q['bandwidthtype']);
1554 61e047a5 Phil Davis
		}
1555
		if (!empty($q['qlimit'])) {
1556 f5881023 Ermal Lu?i
			$this->SetQlimit($q['qlimit']);
1557 61e047a5 Phil Davis
		} else {
1558 ea25d26d Ermal Lu?i
			$this->SetQlimit(""); // Default
1559 61e047a5 Phil Davis
		}
1560 41799195 PiBa-NL
		if (is_numeric($q['priority'])) {
1561 f5881023 Ermal Lu?i
			$this->SetQPriority($q['priority']);
1562 61e047a5 Phil Davis
		} else {
1563 ea25d26d Ermal Lu?i
			$this->SetQpriority("");
1564 61e047a5 Phil Davis
		}
1565
		if (!empty($q['description'])) {
1566 f5881023 Ermal Lu?i
			$this->SetDescription($q['description']);
1567 61e047a5 Phil Davis
		} else {
1568 da0ce7ee Chris Buechler
			$this->SetDescription("");
1569 61e047a5 Phil Davis
		}
1570
		if (!empty($q['red'])) {
1571 f5881023 Ermal Lu?i
			$this->SetRed($q['red']);
1572 61e047a5 Phil Davis
		} else {
1573 ea25d26d Ermal Lu?i
			$this->SetRed();
1574 61e047a5 Phil Davis
		}
1575
		if (!empty($q['codel'])) {
1576 8edaa92c Ermal
			$this->SetCodel($q['codel']);
1577 61e047a5 Phil Davis
		} else {
1578 8edaa92c Ermal
			$this->SetCodel();
1579 61e047a5 Phil Davis
		}
1580
		if (!empty($q['rio'])) {
1581 f5881023 Ermal Lu?i
			$this->SetRio($q['rio']);
1582 61e047a5 Phil Davis
		} else {
1583 ea25d26d Ermal Lu?i
			$this->SetRio();
1584 61e047a5 Phil Davis
		}
1585
		if (!empty($q['ecn'])) {
1586 f5881023 Ermal Lu?i
			$this->SetEcn($q['ecn']);
1587 61e047a5 Phil Davis
		} else {
1588 ea25d26d Ermal Lu?i
			$this->SetEcn();
1589 61e047a5 Phil Davis
		}
1590
		if (!empty($q['default'])) {
1591 f5881023 Ermal Lu?i
			$this->SetDefault($q['default']);
1592 61e047a5 Phil Davis
		} else {
1593 ea25d26d Ermal Lu?i
			$this->SetDefault();
1594 61e047a5 Phil Davis
		}
1595
		if (!empty($q['enabled'])) {
1596 f5881023 Ermal Lu?i
			$this->SetEnabled($q['enabled']);
1597 61e047a5 Phil Davis
		} else {
1598 ea25d26d Ermal Lu?i
			$this->SetEnabled("");
1599 61e047a5 Phil Davis
		}
1600 f5881023 Ermal Lu?i
	}
1601 197bfe96 Ermal Luçi
1602
	function build_tree() {
1603 1072b933 jim-p
		$tree = " <li><a href=\"firewall_shaper.php?interface=". $this->GetInterface()."&amp;queue=". htmlspecialchars($this->GetQname())."&amp;action=show";
1604 f5881023 Ermal Lu?i
		$tree .= "\" ";
1605
		$tmpvalue = $this->GetDefault();
1606 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
1607 f5881023 Ermal Lu?i
			$tree .= " class=\"navlnk\"";
1608 61e047a5 Phil Davis
		}
1609 1072b933 jim-p
		$tree .= " >" . htmlspecialchars($this->GetQname()) . "</a>";
1610 420b4538 Renato Botelho
		/*
1611 f5881023 Ermal Lu?i
		 * Not needed here!
1612
		 * if (is_array($queues) {
1613
		 *	  $tree .= "<ul>";
1614 420b4538 Renato Botelho
		 *	  foreach ($q as $queues)
1615 f5881023 Ermal Lu?i
		 *		  $tree .= $queues['$q->GetName()']->build_tree();
1616 420b4538 Renato Botelho
		 *	  endforeach
1617 f5881023 Ermal Lu?i
		 *	  $tree .= "</ul>";
1618
		 * }
1619 92125c97 Ermal Luçi
		 */
1620 f5881023 Ermal Lu?i
1621 420b4538 Renato Botelho
		$tree .= "</li>";
1622 f5881023 Ermal Lu?i
1623
		return $tree;
1624
	}
1625 ce0117f7 Colin Fleming
1626 f5881023 Ermal Lu?i
	/* Should return something like:
1627
	 * queue $qname on $qinterface bandwidth ....
1628
	 */
1629 9d0b0635 Ermal
	function build_rules(&$default = false) {
1630 f5881023 Ermal Lu?i
		$pfq_rule = " queue ". $this->qname;
1631 61e047a5 Phil Davis
		if ($this->GetInterface()) {
1632 f5881023 Ermal Lu?i
			$pfq_rule .= " on ".get_real_interface($this->GetInterface());
1633 61e047a5 Phil Davis
		}
1634 f5881023 Ermal Lu?i
		$tmpvalue = $this->GetQpriority();
1635 41799195 PiBa-NL
		if (is_numeric($tmpvalue)) {
1636 f5881023 Ermal Lu?i
			$pfq_rule .= " priority ".$this->GetQpriority();
1637 61e047a5 Phil Davis
		}
1638 f5881023 Ermal Lu?i
		$tmpvalue = $this->GetQlimit();
1639 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
1640 f5881023 Ermal Lu?i
			$pfq_rule .= " qlimit " . $this->GetQlimit();
1641 61e047a5 Phil Davis
		}
1642 8edaa92c Ermal
		if ($this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetDefault() || $this->GetCodel()) {
1643 f5881023 Ermal Lu?i
			$pfq_rule .= " priq ( ";
1644
			$tmpvalue = $this->GetRed();
1645
			if (!empty($tmpvalue)) {
1646
				$comma = 1;
1647
				$pfq_rule .= " red ";
1648
			}
1649
			$tmpvalue = $this->GetRio();
1650
			if (!empty($tmpvalue)) {
1651 61e047a5 Phil Davis
				if ($comma) {
1652 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
1653 61e047a5 Phil Davis
				}
1654 f5881023 Ermal Lu?i
				$comma = 1;
1655
				$pfq_rule .= " rio ";
1656
			}
1657
			$tmpvalue = $this->GetEcn();
1658
			if (!empty($tmpvalue)) {
1659 61e047a5 Phil Davis
				if ($comma) {
1660 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
1661 61e047a5 Phil Davis
				}
1662 f5881023 Ermal Lu?i
				$comma = 1;
1663
				$pfq_rule .= " ecn ";
1664
			}
1665 8edaa92c Ermal
			$tmpvalue = $this->GetCodel();
1666
			if (!empty($tmpvalue)) {
1667 61e047a5 Phil Davis
				if ($comma) {
1668 8edaa92c Ermal
					$pfq_rule .= " ,";
1669 61e047a5 Phil Davis
				}
1670 8edaa92c Ermal
				$comma = 1;
1671
				$pfq_rule .= " codel ";
1672
			}
1673 f5881023 Ermal Lu?i
			$tmpvalue = $this->GetDefault();
1674
			if (!empty($tmpvalue)) {
1675 61e047a5 Phil Davis
				if ($comma) {
1676 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
1677 61e047a5 Phil Davis
				}
1678 f5881023 Ermal Lu?i
				$pfq_rule .= " default ";
1679 ef8fca71 Ermal
				$default = true;
1680 f5881023 Ermal Lu?i
			}
1681
			$pfq_rule .= " ) ";
1682 92125c97 Ermal Luçi
		}
1683
1684 f5881023 Ermal Lu?i
		$pfq_rule .= " \n";
1685
1686
		return $pfq_rule;
1687
	}
1688
1689
	/*
1690
	 * To return the html form to show to user
1691
	 * for getting the parameters.
1692
	 * Should do even for first time when the
1693
	 * object is created and later when we may
1694 aef9d8fe Stephen Beaver
	 * need to update it. (2)
1695 f5881023 Ermal Lu?i
	 */
1696 806942d0 Stephen Beaver
1697 f5881023 Ermal Lu?i
	function build_form() {
1698 806942d0 Stephen Beaver
1699 27d6a45b jim-p
		$sform = new Form();
1700 5605a0c4 Stephen Beaver
1701
		$sform->setAction("firewall_shaper.php");
1702 806942d0 Stephen Beaver
1703 3feefc07 Stephen Beaver
		$section = new Form_Section("");
1704 806942d0 Stephen Beaver
1705 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Checkbox(
1706
			'enabled',
1707
			'Enable/Disable',
1708
			'Enable/disable discipline and its children',
1709
			($this->GetEnabled() == "on"),
1710
			'on'
1711
		));
1712 806942d0 Stephen Beaver
1713 3feefc07 Stephen Beaver
		$section->addInput(new Form_Input(
1714 5605a0c4 Stephen Beaver
			'newname',
1715 40dcb4b6 Phil Davis
			'*Name',
1716 3feefc07 Stephen Beaver
			'text',
1717 aef9d8fe Stephen Beaver
			$this->GetQname()
1718
		))->setHelp('Enter the name of the queue here. Do not use spaces and limit the size to 15 characters.');
1719 806942d0 Stephen Beaver
1720 5605a0c4 Stephen Beaver
		$section->addInput(new Form_Input(
1721
			'name',
1722
			null,
1723
			'hidden',
1724
			$this->GetQname()
1725
		));
1726
1727 41799195 PiBa-NL
		if (!is_a($this, "hfsc_queue")) {
1728
			$section->addInput(new Form_Input(
1729
				'priority',
1730
				'Priority',
1731
				'number',
1732
				$this->GetQpriority(),
1733
				['min' => '0', 'max'=> '']
1734
			))->setHelp('For cbq and fairq the range is 0 to 7. The default is 1. For priq the range is 0 to 15, queues with a higher priority are preferred in the case of overload.');
1735
		}
1736 aef9d8fe Stephen Beaver
1737
		$section->addInput(new Form_Input(
1738
			'qlimit',
1739
			'Queue Limit',
1740
			'number',
1741
			$this->GetQlimit()
1742
		))->setHelp('Queue limit in packets.');
1743 806942d0 Stephen Beaver
1744 aef9d8fe Stephen Beaver
		$group = new Form_Group('Scheduler options');
1745 806942d0 Stephen Beaver
1746 bc788561 Ermal
		if (empty($this->subqueues)) {
1747 aef9d8fe Stephen Beaver
			$group->add(new Form_Checkbox(
1748
				'default',
1749
				null,
1750
				null,
1751 5605a0c4 Stephen Beaver
				$this->GetDefault(),
1752
				'default'
1753 806942d0 Stephen Beaver
			))->setHelp('Default Queue');
1754 aef9d8fe Stephen Beaver
		}
1755 806942d0 Stephen Beaver
1756 aef9d8fe Stephen Beaver
		$group->add(new Form_Checkbox(
1757
			'red',
1758
			null,
1759
			null,
1760
			!empty($this->GetRed())
1761 08dbe1c5 Phil Davis
		))->setHelp('%1$sRandom Early Detection%2$s', '<a target="_new" href="https://web.archive.org/web/20160404153707/http://www.openbsd.org/faq/pf/queueing.html#red">', '</a>');
1762 806942d0 Stephen Beaver
1763 aef9d8fe Stephen Beaver
		$group->add(new Form_Checkbox(
1764
			'rio',
1765
			null,
1766
			null,
1767
			!empty($this->GetRio())
1768 08dbe1c5 Phil Davis
		))->setHelp('%1$sRandom Early Detection In and Out%2$s', '<a target="_new" href="https://web.archive.org/web/20160404153707/http://www.openbsd.org/faq/pf/queueing.html#rio">', '</a>');
1769 806942d0 Stephen Beaver
1770 aef9d8fe Stephen Beaver
		$group->add(new Form_Checkbox(
1771
			'ecn',
1772
			null,
1773
			null,
1774
			!empty($this->GetEcn())
1775 08dbe1c5 Phil Davis
		))->setHelp('%1$sExplicit Congestion Notification%2$s', '<a target="_new" href="https://web.archive.org/web/20160404153707/http://www.openbsd.org/faq/pf/queueing.html#ecn">', '</a>');
1776 806942d0 Stephen Beaver
1777 aef9d8fe Stephen Beaver
		$group->add(new Form_Checkbox(
1778
			'codel',
1779
			null,
1780
			null,
1781
			!empty($this->GetCodel())
1782 08dbe1c5 Phil Davis
		))->setHelp('%1$sCodel Active Queue%2$s', '<a target="_new" href="https://web.archive.org/web/20160404153707/http://www.openbsd.org/faq/pf/queueing.html#ecn">', '</a>');
1783 aef9d8fe Stephen Beaver
1784
		$group->setHelp('Select options for this queue');
1785 806942d0 Stephen Beaver
1786
		$section->add($group);
1787
1788 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Input(
1789
			'description',
1790
			'Description',
1791
			'text',
1792
			$this->GetDescription()
1793
		));
1794 806942d0 Stephen Beaver
1795 5605a0c4 Stephen Beaver
		$sform->add($section);
1796
1797
		$sform->addGlobal(new Form_Input(
1798 aef9d8fe Stephen Beaver
			'interface',
1799
			null,
1800
			'hidden',
1801
			$this->GetInterface()
1802 806942d0 Stephen Beaver
		));
1803
1804 5605a0c4 Stephen Beaver
		$sform->addGlobal(new Form_Input(
1805
			'name',
1806
			null,
1807
			'hidden',
1808
			$this->GetQname()
1809
		));
1810 806942d0 Stephen Beaver
1811 aef9d8fe Stephen Beaver
		return($sform);
1812 806942d0 Stephen Beaver
	}
1813 197bfe96 Ermal Luçi
1814
	function build_shortform() {
1815 61e047a5 Phil Davis
		/* XXX: Hacks in sight. Mostly layer violations!  */
1816 197bfe96 Ermal Luçi
		global $g, $altq_list_queues;
1817 d34ade52 Michele Di Maria
		global $shaperIFlist;
1818 ce0117f7 Colin Fleming
1819 197bfe96 Ermal Luçi
		$altq =& $altq_list_queues[$this->GetInterface()];
1820 d17c4ee9 Stephen Beaver
1821 61e047a5 Phil Davis
		if ($altq) {
1822 b28e1512 Stephen Beaver
			$scheduler = $altq->GetScheduler();
1823
		}
1824 d17c4ee9 Stephen Beaver
1825 b28e1512 Stephen Beaver
		$form = '<dl class="dl-horizontal">';
1826
		$form .= '	<dt>';
1827
		$form .= '		<a href="firewall_shaper.php?interface=' . $this->GetInterface() . '&amp;queue=' . $this->GetQname() . '&amp;action=show">' . $shaperIFlist[$this->GetInterface()] . '</a>';
1828
		$form .= '	</dt>';
1829
		$form .= '	<dd>';
1830 d17c4ee9 Stephen Beaver
		$form .=		$scheduler;
1831 b28e1512 Stephen Beaver
		$form .= '	</dd>';
1832 d17c4ee9 Stephen Beaver
1833 b28e1512 Stephen Beaver
		$form .= '	<dt>';
1834 d17c4ee9 Stephen Beaver
		$form .=		'Bandwidth';
1835 b28e1512 Stephen Beaver
		$form .= '	</dt>';
1836
		$form .= '	<dd>';
1837 bfc94df0 Phil Davis
		$form .=		$this->GetBandwidth() . '&nbsp;' . $this->GetBwscaleText();
1838 b28e1512 Stephen Beaver
		$form .= '	</dd>';
1839 d17c4ee9 Stephen Beaver
1840 f5881023 Ermal Lu?i
		$tmpvalue = $this->GetQpriority();
1841 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
1842 d17c4ee9 Stephen Beaver
			$form .= '	<dt>';
1843
			$form .=		'Priority';
1844 b28e1512 Stephen Beaver
			$form .= '	<dt>';
1845
			$form .= '	<dd>';
1846 d17c4ee9 Stephen Beaver
			$form .=		'On';
1847 b28e1512 Stephen Beaver
			$form .= '	</dd>';
1848
		}
1849 d17c4ee9 Stephen Beaver
1850 f5881023 Ermal Lu?i
		$tmpvalue = $this->GetDefault();
1851 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
1852 d17c4ee9 Stephen Beaver
			$form .= '	<dt>';
1853
			$form .=		'Default';
1854 b28e1512 Stephen Beaver
			$form .= '	<dt>';
1855
			$form .= '	<dd>';
1856 d17c4ee9 Stephen Beaver
			$form .=		'On';
1857 b28e1512 Stephen Beaver
			$form .= '	</dd>';
1858
		}
1859 d17c4ee9 Stephen Beaver
1860
			$form .= '	<dt>';
1861 b28e1512 Stephen Beaver
			$form .= 'Delete';
1862
			$form .= '	<dt>';
1863
			$form .= '	<dd>';
1864
1865
			$form .= '<a class="btn btn-danger btn-xs" href="firewall_shaper_queues.php?interface=';
1866
			$form .= $this->GetInterface() . '&amp;queue=';
1867
			$form .= $this->GetQname() . '&amp;action=delete">';
1868 27d6a45b jim-p
			$form .= '<i class="fa fa-trash icon-embed-btn"></i>';
1869
			$form .= gettext("Delete Queue from this Interface") . '</a>';
1870 b28e1512 Stephen Beaver
1871 d17c4ee9 Stephen Beaver
			$form .= '	</dd>';
1872
1873
			$form .= '</dl>';
1874 ce0117f7 Colin Fleming
1875 197bfe96 Ermal Luçi
		return $form;
1876 061f78b1 Bill Marquette
1877 197bfe96 Ermal Luçi
	}
1878 061f78b1 Bill Marquette
1879 61e047a5 Phil Davis
	function update_altq_queue_data(&$q) {
1880 197bfe96 Ermal Luçi
		$this->ReadConfig($q);
1881
	}
1882 061f78b1 Bill Marquette
1883 f5881023 Ermal Lu?i
	function wconfig() {
1884
		$cflink =& get_reference_to_me_in_config($this->GetLink());
1885 61e047a5 Phil Davis
		if (!is_array($cflink)) {
1886 197bfe96 Ermal Luçi
			$cflink = array();
1887 61e047a5 Phil Davis
		}
1888 197bfe96 Ermal Luçi
		$cflink['name'] = $this->GetQname();
1889 f5881023 Ermal Lu?i
		$cflink['interface'] = $this->GetInterface();
1890
		$cflink['qlimit'] = trim($this->GetQlimit());
1891 61e047a5 Phil Davis
		if (empty($cflink['qlimit'])) {
1892 f5881023 Ermal Lu?i
			unset($cflink['qlimit']);
1893 61e047a5 Phil Davis
		}
1894 f5881023 Ermal Lu?i
		$cflink['priority'] = trim($this->GetQpriority());
1895 41799195 PiBa-NL
		if (!is_numeric($cflink['priority'])) {
1896 f5881023 Ermal Lu?i
			unset($cflink['priority']);
1897 61e047a5 Phil Davis
		}
1898 f5881023 Ermal Lu?i
		$cflink['description'] = trim($this->GetDescription());
1899 61e047a5 Phil Davis
		if (empty($cflink['description'])) {
1900 f5881023 Ermal Lu?i
			unset($cflink['description']);
1901 61e047a5 Phil Davis
		}
1902 f5881023 Ermal Lu?i
		$cflink['enabled'] = trim($this->GetEnabled());
1903 61e047a5 Phil Davis
		if (empty($cflink['enabled'])) {
1904 f5881023 Ermal Lu?i
			unset($cflink['enabled']);
1905 61e047a5 Phil Davis
		}
1906 f5881023 Ermal Lu?i
		$cflink['default'] = trim($this->GetDefault());
1907 61e047a5 Phil Davis
		if (empty($cflink['default'])) {
1908 f5881023 Ermal Lu?i
			unset($cflink['default']);
1909 61e047a5 Phil Davis
		}
1910 f5881023 Ermal Lu?i
		$cflink['red'] = trim($this->GetRed());
1911 61e047a5 Phil Davis
		if (empty($cflink['red'])) {
1912 f5881023 Ermal Lu?i
			unset($cflink['red']);
1913 61e047a5 Phil Davis
		}
1914 8edaa92c Ermal
		$cflink['codel'] = trim($this->GetCodel());
1915 61e047a5 Phil Davis
		if (empty($cflink['codel'])) {
1916 8edaa92c Ermal
			unset($cflink['codel']);
1917 61e047a5 Phil Davis
		}
1918 f5881023 Ermal Lu?i
		$cflink['rio'] = trim($this->GetRio());
1919 61e047a5 Phil Davis
		if (empty($cflink['rio'])) {
1920 f5881023 Ermal Lu?i
			unset($cflink['rio']);
1921 61e047a5 Phil Davis
		}
1922 f5881023 Ermal Lu?i
		$cflink['ecn'] = trim($this->GetEcn());
1923 61e047a5 Phil Davis
		if (empty($cflink['ecn'])) {
1924 f5881023 Ermal Lu?i
			unset($cflink['ecn']);
1925 61e047a5 Phil Davis
		}
1926 061f78b1 Bill Marquette
	}
1927
}
1928
1929 197bfe96 Ermal Luçi
class hfsc_queue extends priq_queue {
1930 f5881023 Ermal Lu?i
	/* realtime */
1931 197bfe96 Ermal Luçi
	var $realtime;
1932 f5881023 Ermal Lu?i
	var $r_m1;
1933
	var $r_d;
1934
	var $r_m2;
1935
	/* linkshare */
1936 197bfe96 Ermal Luçi
	var $linkshare;
1937 f5881023 Ermal Lu?i
	var $l_m1;
1938
	var $l_d;
1939
	var $l_m2;
1940
	/* upperlimit */
1941 197bfe96 Ermal Luçi
	var $upperlimit;
1942 f5881023 Ermal Lu?i
	var $u_m1;
1943
	var $u_d;
1944
	var $u_m2;
1945 197bfe96 Ermal Luçi
1946 f5881023 Ermal Lu?i
	/*
1947
	 * HFSC can have nested queues.
1948
	 */
1949 70b139a3 Chris Buechler
	function CanHaveChildren() {
1950 f5881023 Ermal Lu?i
		return true;
1951
	}
1952 197bfe96 Ermal Luçi
	function GetRealtime() {
1953 420b4538 Renato Botelho
		return $this->realtime;
1954 f5881023 Ermal Lu?i
	}
1955
	function GetR_m1() {
1956
		return $this->r_m1;
1957
	}
1958
	function GetR_d() {
1959
		return $this->r_d;
1960
	}
1961
	function GetR_m2() {
1962
		return $this->r_m2;
1963
	}
1964
	function SetRealtime() {
1965
		$this->realtime = "on";
1966
	}
1967
	function DisableRealtime() {
1968
		$this->realtime = "";
1969
	}
1970
	function SetR_m1($value) {
1971
		$this->r_m1 = $value;
1972
	}
1973
	function SetR_d($value) {
1974
		$this->r_d = $value;
1975
	}
1976
	function SetR_m2($value) {
1977
		$this->r_m2 = $value;
1978
	}
1979
	function GetLinkshare() {
1980
		return $this->linkshare;
1981
	}
1982
	function DisableLinkshare() {
1983
		$this->linkshare = "";
1984
	}
1985
	function GetL_m1() {
1986
		return $this->l_m1;
1987
	}
1988
	function GetL_d() {
1989
		return $this->l_d;
1990
	}
1991
	function GetL_m2() {
1992
		return $this->l_m2;
1993
	}
1994
	function SetLinkshare() {
1995
		$this->linkshare = "on";
1996
	}
1997
	function SetL_m1($value) {
1998
		$this->l_m1 = $value;
1999
	}
2000
	function SetL_d($value) {
2001
		$this->l_d = $value;
2002
	}
2003
	function SetL_m2($value) {
2004
		$this->l_m2 = $value;
2005
	}
2006
	function GetUpperlimit() {
2007
		return $this->upperlimit;
2008
	}
2009
	function GetU_m1() {
2010
		return $this->u_m1;
2011
	}
2012
	function GetU_d() {
2013
		return $this->u_d;
2014
	}
2015
	function GetU_m2() {
2016
		return $this->u_m2;
2017
	}
2018
	function SetUpperlimit() {
2019
		$this->upperlimit = "on";
2020
	}
2021
	function DisableUpperlimit() {
2022
		$this->upperlimit = "";
2023
	}
2024
	function SetU_m1($value) {
2025
		$this->u_m1 = $value;
2026
	}
2027
	function SetU_d($value) {
2028
		$this->u_d = $value;
2029
	}
2030
	function SetU_m2($value) {
2031
		$this->u_m2 = $value;
2032
	}
2033
2034
	function &add_queue($interface, &$qname, &$path, &$input_errors) {
2035
2036 61e047a5 Phil Davis
		if (!is_array($this->subqueues)) {
2037 f5881023 Ermal Lu?i
			$this->subqueues = array();
2038 61e047a5 Phil Davis
		}
2039 5c4fcabc Renato Botelho
		$__tmp_q = new hfsc_queue(); $q =& $__tmp_q;
2040 f5881023 Ermal Lu?i
		$q->SetInterface($this->GetInterface());
2041 ea51e9f8 Renato Botelho
		$q->SetParent($this);
2042 f5881023 Ermal Lu?i
		$q->ReadConfig($qname);
2043
		$q->validate_input($qname, $input_errors);
2044 197bfe96 Ermal Luçi
2045 f5881023 Ermal Lu?i
		$q->SetEnabled("on");
2046
		$q->SetLink($path);
2047
2048
		$this->subqueues[$q->GetQname()] =& $q; //new hfsc_queue()
2049
		ref_on_altq_queue_list($this->GetQname(), $q->GetQname());
2050
		if (is_array($qname['queue'])) {
2051
			foreach ($qname['queue'] as $key1 => $que) {
2052
				array_push($path, $key1);
2053 ea51e9f8 Renato Botelho
				$q->add_queue($q->GetInterface(), $que, $path, $input_errors);
2054 f5881023 Ermal Lu?i
				array_pop($path);
2055
			}
2056
		}
2057 ce0117f7 Colin Fleming
2058 f5881023 Ermal Lu?i
		return $q;
2059
	}
2060 a843b04f Ermal Luçi
2061 420b4538 Renato Botelho
	function copy_queue($interface, &$cflink) {
2062 a843b04f Ermal Luçi
2063 f5881023 Ermal Lu?i
		$cflink['name'] = $this->GetQname();
2064
		$cflink['interface'] = $interface;
2065
		$cflink['qlimit'] = trim($this->GetQlimit());
2066 61e047a5 Phil Davis
		if (empty($cflink['qlimit'])) {
2067 f5881023 Ermal Lu?i
			unset($cflink['qlimit']);
2068 61e047a5 Phil Davis
		}
2069 f5881023 Ermal Lu?i
		$cflink['priority'] = trim($this->GetQpriority());
2070 61e047a5 Phil Davis
		if (empty($cflink['priority'])) {
2071 f5881023 Ermal Lu?i
			unset($cflink['priority']);
2072 61e047a5 Phil Davis
		}
2073 f5881023 Ermal Lu?i
		$cflink['description'] = trim($this->GetDescription());
2074 61e047a5 Phil Davis
		if (empty($cflink['description'])) {
2075 f5881023 Ermal Lu?i
			unset($cflink['description']);
2076 61e047a5 Phil Davis
		}
2077 f5881023 Ermal Lu?i
		$cflink['bandwidth'] = $this->GetBandwidth();
2078
		$cflink['bandwidthtype'] = $this->GetBwscale();
2079
		$cflink['enabled'] = trim($this->GetEnabled());
2080 61e047a5 Phil Davis
		if (empty($cflink['enabled'])) {
2081 f5881023 Ermal Lu?i
			unset($cflink['enabled']);
2082 61e047a5 Phil Davis
		}
2083 f5881023 Ermal Lu?i
		$cflink['default'] = trim($this->GetDefault());
2084 61e047a5 Phil Davis
		if (empty($cflink['default'])) {
2085 f5881023 Ermal Lu?i
			unset($cflink['default']);
2086 61e047a5 Phil Davis
		}
2087 f5881023 Ermal Lu?i
		$cflink['red'] = trim($this->GetRed());
2088 61e047a5 Phil Davis
		if (empty($cflink['red'])) {
2089 f5881023 Ermal Lu?i
			unset($cflink['red']);
2090 61e047a5 Phil Davis
		}
2091 f5881023 Ermal Lu?i
		$cflink['rio'] = trim($this->GetRio());
2092 61e047a5 Phil Davis
		if (empty($cflink['rio'])) {
2093 f5881023 Ermal Lu?i
			unset($cflink['rio']);
2094 61e047a5 Phil Davis
		}
2095 f5881023 Ermal Lu?i
		$cflink['ecn'] = trim($this->GetEcn());
2096 61e047a5 Phil Davis
		if (empty($cflink['ecn'])) {
2097 f5881023 Ermal Lu?i
			unset($cflink['ecn']);
2098 61e047a5 Phil Davis
		}
2099 f5881023 Ermal Lu?i
		if ($this->GetLinkshare() <> "") {
2100
			if ($this->GetL_m1() <> "") {
2101
				$cflink['linkshare1'] = $this->GetL_m1();
2102
				$cflink['linkshare2'] = $this->GetL_d();
2103
				$cflink['linkshare'] = "on";
2104
			} else {
2105
				unset($cflink['linkshare1']);
2106
				unset($cflink['linkshare2']);
2107
				unset($cflink['linkshare']);
2108 fce82460 Ermal Luçi
			}
2109 f5881023 Ermal Lu?i
			if ($this->GetL_m2() <> "") {
2110
				$cflink['linkshare3'] = $this->GetL_m2();
2111
				$cflink['linkshare'] = "on";
2112
			} else {
2113
				unset($cflink['linkshare3']);
2114
				unset($cflink['linkshare']);
2115 92125c97 Ermal Luçi
			}
2116 f5881023 Ermal Lu?i
		}
2117
		if ($this->GetRealtime() <> "") {
2118
			if ($this->GetR_m1() <> "") {
2119
				$cflink['realtime1'] = $this->GetR_m1();
2120
				$cflink['realtime2'] = $this->GetR_d();
2121
				$cflink['realtime'] = "on";
2122
			} else {
2123
				unset($cflink['realtime1']);
2124 420b4538 Renato Botelho
				unset($cflink['realtime2']);
2125
				unset($cflink['realtime']);
2126 f5881023 Ermal Lu?i
			}
2127
			if ($this->GetR_m2() <> "") {
2128
				$cflink['realtime3'] = $this->GetR_m2();
2129
				$cflink['realtime'] = "on";
2130
			} else {
2131
				unset($cflink['realtime3']);
2132
				unset($cflink['realtime']);
2133 92125c97 Ermal Luçi
			}
2134 b7ff5e40 Scott Ullrich
		}
2135 f5881023 Ermal Lu?i
		if ($this->GetUpperlimit() <> "") {
2136
			if ($this->GetU_m1() <> "") {
2137
				$cflink['upperlimit1'] = $this->GetU_m1();
2138
				$cflink['upperlimit2'] = $this->GetU_d();
2139
				$cflink['upperlimit'] = "on";
2140
			} else {
2141
				unset($cflink['upperlimit']);
2142
				unset($cflink['upperlimit1']);
2143
				unset($cflink['upperlimit2']);
2144
			}
2145
			if ($this->GetU_m2() <> "") {
2146
				$cflink['upperlimit3'] = $this->GetU_m2();
2147
				$cflink['upperlimit'] = "on";
2148
			} else {
2149
				unset($cflink['upperlimit3']);
2150
				unset($cflink['upperlimit']);
2151
			}
2152 92125c97 Ermal Luçi
		}
2153 40de74f5 Ermal Luçi
2154 f5881023 Ermal Lu?i
		if (is_array($this->subqueues)) {
2155
			$cflinkp['queue'] = array();
2156
			foreach ($this->subqueues as $q) {
2157
				$cflink['queue'][$q->GetQname()] = array();
2158 ea51e9f8 Renato Botelho
				$q->copy_queue($interface, $cflink['queue'][$q->GetQname()]);
2159 f5881023 Ermal Lu?i
			}
2160
		}
2161
	}
2162
2163 420b4538 Renato Botelho
	function delete_queue() {
2164 f5881023 Ermal Lu?i
		unref_on_altq_queue_list($this->GetQname());
2165
		cleanup_queue_from_rules($this->GetQname());
2166
		$parent =& $this->GetParent();
2167 45eeb038 Luiz Otavio O Souza
		foreach ($this->subqueues as $q)
2168
			$q->delete_queue();
2169 f5881023 Ermal Lu?i
		unset_object_by_reference($this->GetLink());
2170
	}
2171
2172
	/*
2173
	 * Should search even its children
2174
	 */
2175
	function &find_queue($interface, $qname) {
2176 61e047a5 Phil Davis
		if ($qname == $this->GetQname()) {
2177 f5881023 Ermal Lu?i
			return $this;
2178 61e047a5 Phil Davis
		}
2179 f5881023 Ermal Lu?i
2180
		foreach ($this->subqueues as $q) {
2181
			$result =& $q->find_queue("", $qname);
2182 61e047a5 Phil Davis
			if ($result) {
2183 f5881023 Ermal Lu?i
				return $result;
2184 61e047a5 Phil Davis
			}
2185 f5881023 Ermal Lu?i
		}
2186
	}
2187
2188
	function &find_parentqueue($interface, $qname) {
2189 61e047a5 Phil Davis
		if ($this->subqueues[$qname]) {
2190 f5881023 Ermal Lu?i
			return $this;
2191 61e047a5 Phil Davis
		}
2192 f5881023 Ermal Lu?i
		foreach ($this->subqueues as $q) {
2193
			$result = $q->find_parentqueue("", $qname);
2194 61e047a5 Phil Davis
			if ($result) {
2195 f5881023 Ermal Lu?i
				return $result;
2196 61e047a5 Phil Davis
			}
2197 f5881023 Ermal Lu?i
		}
2198
	}
2199 ce0117f7 Colin Fleming
2200 f5881023 Ermal Lu?i
	function validate_input($data, &$input_errors) {
2201
		parent::validate_input($data, $input_errors);
2202 ce0117f7 Colin Fleming
2203 f5881023 Ermal Lu?i
		$reqdfields[] = "bandwidth";
2204 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidth");
2205 f5881023 Ermal Lu?i
		$reqdfields[] = "bandwidthtype";
2206 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidthtype");
2207 f5881023 Ermal Lu?i
2208
		shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
2209 ce0117f7 Colin Fleming
2210 f5881023 Ermal Lu?i
		if (isset($data['linkshare3']) && $data['linkshare3'] <> "") {
2211 61e047a5 Phil Davis
			if ($data['bandwidth'] && (!is_numeric($data['bandwidth']))) {
2212 dbaf21d4 Renato Botelho
				$input_errors[] = gettext("Bandwidth must be an integer.");
2213 61e047a5 Phil Davis
			}
2214 f5881023 Ermal Lu?i
2215 61e047a5 Phil Davis
			if ($data['bandwidth'] < 0) {
2216 dbaf21d4 Renato Botelho
				$input_errors[] = gettext("Bandwidth cannot be negative.");
2217 61e047a5 Phil Davis
			}
2218 f5881023 Ermal Lu?i
2219
			if ($data['bandwidthtype'] == "%") {
2220 61e047a5 Phil Davis
				if ($data['bandwidth'] > 100 || $data['bandwidth'] < 0) {
2221 45eeb038 Luiz Otavio O Souza
					$input_errors[] = gettext("Bandwidth in percentage should be between 1 and 100.");
2222 61e047a5 Phil Davis
				}
2223 f5881023 Ermal Lu?i
			}
2224 92125c97 Ermal Luçi
		}
2225
2226 4de8f7ba Phil Davis
		if ($data['upperlimit1'] <> "" && $data['upperlimit2'] == "") {
2227 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("upperlimit service curve defined but missing (d) value");
2228 61e047a5 Phil Davis
		}
2229 4de8f7ba Phil Davis
		if ($data['upperlimit2'] <> "" && $data['upperlimit1'] == "") {
2230 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("upperlimit service curve defined but missing initial bandwidth (m1) value");
2231 61e047a5 Phil Davis
		}
2232
		if ($data['upperlimit1'] <> "" && !is_valid_shaperbw($data['upperlimit1'])) {
2233 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("upperlimit m1 value needs to be Kb, Mb, Gb, or %");
2234 61e047a5 Phil Davis
		}
2235
		if ($data['upperlimit2'] <> "" && !is_numeric($data['upperlimit2'])) {
2236 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("upperlimit d value needs to be numeric");
2237 61e047a5 Phil Davis
		}
2238
		if ($data['upperlimit3'] <> "" && !is_valid_shaperbw($data['upperlimit3'])) {
2239 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("upperlimit m2 value needs to be Kb, Mb, Gb, or %");
2240 61e047a5 Phil Davis
		}
2241 a843b04f Ermal Luçi
2242 f5881023 Ermal Lu?i
		/*
2243 40de74f5 Ermal Luçi
		if (isset($data['upperlimit']) && $data['upperlimit3'] <> "" && $data['upperlimit1'] <> "") {
2244 f5881023 Ermal Lu?i
			$bw_1 = get_hfsc_bandwidth($this, $data['upperlimit1']);
2245
			$bw_2 = get_hfsc_bandwidth($this, $data['upperlimit3']);
2246 61e047a5 Phil Davis
			if (floatval($bw_1) < floatval($bw_2)) {
2247 f5881023 Ermal Lu?i
				$input_errors[] = ("upperlimit m1 cannot be smaller than m2");
2248 61e047a5 Phil Davis
			}
2249 40de74f5 Ermal Luçi
2250 61e047a5 Phil Davis
			if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2)))) {
2251 794195d1 Phil Davis
				$input_errors[] = ("upperlimit specification exceeds 80% of allowable allocation.");
2252 61e047a5 Phil Davis
			}
2253 40de74f5 Ermal Luçi
		}
2254 f5881023 Ermal Lu?i
		*/
2255 4de8f7ba Phil Davis
		if ($data['linkshare1'] <> "" && $data['linkshare2'] == "") {
2256 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("linkshare service curve defined but missing (d) value");
2257 61e047a5 Phil Davis
		}
2258 4de8f7ba Phil Davis
		if ($data['linkshare2'] <> "" && $data['linkshare1'] == "") {
2259 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("linkshare service curve defined but missing initial bandwidth (m1) value");
2260 61e047a5 Phil Davis
		}
2261
		if ($data['linkshare1'] <> "" && !is_valid_shaperbw($data['linkshare1'])) {
2262 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("linkshare m1 value needs to be Kb, Mb, Gb, or %");
2263 61e047a5 Phil Davis
		}
2264
		if ($data['linkshare2'] <> "" && !is_numeric($data['linkshare2'])) {
2265 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("linkshare d value needs to be numeric");
2266 61e047a5 Phil Davis
		}
2267
		if ($data['linkshare3'] <> "" && !is_valid_shaperbw($data['linkshare3'])) {
2268 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("linkshare m2 value needs to be Kb, Mb, Gb, or %");
2269 61e047a5 Phil Davis
		}
2270 4de8f7ba Phil Davis
		if ($data['realtime1'] <> "" && $data['realtime2'] == "") {
2271 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("realtime service curve defined but missing (d) value");
2272 61e047a5 Phil Davis
		}
2273 4de8f7ba Phil Davis
		if ($data['realtime2'] <> "" && $data['realtime1'] == "") {
2274 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("realtime service curve defined but missing initial bandwidth (m1) value");
2275 61e047a5 Phil Davis
		}
2276 40de74f5 Ermal Luçi
2277 f5881023 Ermal Lu?i
		/*
2278 a843b04f Ermal Luçi
		if (isset($data['linkshare']) && $data['linkshare3'] <> "" && $data['linkshare1'] <> "" && 0) {
2279 f5881023 Ermal Lu?i
			$bw_1 = get_hfsc_bandwidth($this, $data['linkshare1']);
2280 420b4538 Renato Botelho
			$bw_2 = get_hfsc_bandwidth($this, $data['linkshare3']);
2281 61e047a5 Phil Davis
			if (floatval($bw_1) < floatval($bw_2)) {
2282 420b4538 Renato Botelho
				$input_errors[] = ("linkshare m1 cannot be smaller than m2");
2283 61e047a5 Phil Davis
			}
2284 40de74f5 Ermal Luçi
2285 61e047a5 Phil Davis
			if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2)))) {
2286 420b4538 Renato Botelho
				$input_errors[] = ("linkshare specification exceeds 80% of allowable allocation.");
2287 61e047a5 Phil Davis
			}
2288 40de74f5 Ermal Luçi
		}
2289 f5881023 Ermal Lu?i
		*/
2290 a2f70da3 Ermal Luçi
2291 61e047a5 Phil Davis
		if ($data['realtime1'] <> "" && !is_valid_shaperbw($data['realtime1'])) {
2292 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("realtime m1 value needs to be Kb, Mb, Gb, or %");
2293 61e047a5 Phil Davis
		}
2294
		if ($data['realtime2'] <> "" && !is_numeric($data['realtime2'])) {
2295 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("realtime d value needs to be numeric");
2296 61e047a5 Phil Davis
		}
2297
		if ($data['realtime3'] <> "" && !is_valid_shaperbw($data['realtime3'])) {
2298 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("realtime m2 value needs to be Kb, Mb, Gb, or %");
2299 61e047a5 Phil Davis
		}
2300 40de74f5 Ermal Luçi
2301 f5881023 Ermal Lu?i
		/*
2302 a843b04f Ermal Luçi
		if (isset($data['realtime']) && $data['realtime3'] <> "" && $data['realtime1'] <> "" && 0) {
2303 f5881023 Ermal Lu?i
			$bw_1 = get_hfsc_bandwidth($this, $data['realtime1']);
2304 420b4538 Renato Botelho
			$bw_2 = get_hfsc_bandwidth($this, $data['realtime3']);
2305 61e047a5 Phil Davis
			if (floatval($bw_1) < floatval($bw_2)) {
2306 420b4538 Renato Botelho
				$input_errors[] = ("realtime m1 cannot be smaller than m2");
2307 61e047a5 Phil Davis
			}
2308 40de74f5 Ermal Luçi
2309 61e047a5 Phil Davis
			if (get_interface_bandwidth($this) < (0.8 * (floatval($bw_1) + floatval($bw_2)))) {
2310 794195d1 Phil Davis
				$input_errors[] = ("realtime specification exceeds 80% of allowable allocation.");
2311 61e047a5 Phil Davis
			}
2312 40de74f5 Ermal Luçi
		}
2313 f5881023 Ermal Lu?i
		*/
2314 061f78b1 Bill Marquette
	}
2315
2316 f5881023 Ermal Lu?i
	function ReadConfig(&$cflink) {
2317
		if (!empty($cflink['linkshare'])) {
2318
			if (!empty($cflink['linkshare1'])) {
2319 92125c97 Ermal Luçi
				$this->SetL_m1($cflink['linkshare1']);
2320 420b4538 Renato Botelho
				$this->SetL_d($cflink['linkshare2']);
2321 92125c97 Ermal Luçi
				$this->SetLinkshare();
2322 7ed9c6ac Ermal
			} else {
2323
				$this->SetL_m1("");
2324 420b4538 Renato Botelho
				$this->SetL_d("");
2325 7ed9c6ac Ermal
				$this->DisableLinkshare();
2326 92125c97 Ermal Luçi
			}
2327 f5881023 Ermal Lu?i
			if (!empty($cflink['linkshare3'])) {
2328 420b4538 Renato Botelho
				$this->SetL_m2($cflink['linkshare3']);
2329 92125c97 Ermal Luçi
				$this->SetLinkshare();
2330
			}
2331 61e047a5 Phil Davis
		} else {
2332 f5881023 Ermal Lu?i
			$this->DisableLinkshare();
2333 61e047a5 Phil Davis
		}
2334 f5881023 Ermal Lu?i
		if (!empty($cflink['realtime'])) {
2335 420b4538 Renato Botelho
			if (!empty($cflink['realtime1'])) {
2336
				$this->SetR_m1($cflink['realtime1']);
2337
				$this->SetR_d($cflink['realtime2']);
2338 92125c97 Ermal Luçi
				$this->SetRealtime();
2339 7ed9c6ac Ermal
			} else {
2340 420b4538 Renato Botelho
				$this->SetR_m1("");
2341
				$this->SetR_d("");
2342 7ed9c6ac Ermal
				$this->DisableRealtime();
2343 92125c97 Ermal Luçi
			}
2344 420b4538 Renato Botelho
			if (!empty($cflink['realtime3'])) {
2345
				$this->SetR_m2($cflink['realtime3']);
2346 92125c97 Ermal Luçi
				$this->SetRealtime();
2347
			}
2348 61e047a5 Phil Davis
		} else {
2349 420b4538 Renato Botelho
			$this->DisableRealtime();
2350 61e047a5 Phil Davis
		}
2351 f5881023 Ermal Lu?i
		if (!empty($cflink['upperlimit'])) {
2352 420b4538 Renato Botelho
			if (!empty($cflink['upperlimit1'])) {
2353
				$this->SetU_m1($cflink['upperlimit1']);
2354
				$this->SetU_d($cflink['upperlimit2']);
2355 92125c97 Ermal Luçi
				$this->SetUpperlimit();
2356 7ed9c6ac Ermal
			} else {
2357 420b4538 Renato Botelho
				$this->SetU_m1("");
2358
				$this->SetU_d("");
2359 7ed9c6ac Ermal
				$this->DisableUpperlimit();
2360 92125c97 Ermal Luçi
			}
2361 420b4538 Renato Botelho
			if (!empty($cflink['upperlimit3'])) {
2362
				$this->SetU_m2($cflink['upperlimit3']);
2363 92125c97 Ermal Luçi
				$this->SetUpperlimit();
2364
			}
2365 61e047a5 Phil Davis
		} else {
2366 f5881023 Ermal Lu?i
			$this->DisableUpperlimit();
2367 61e047a5 Phil Davis
		}
2368 92125c97 Ermal Luçi
		parent::ReadConfig($cflink);
2369 f5881023 Ermal Lu?i
	}
2370 197bfe96 Ermal Luçi
2371
	function build_tree() {
2372 1072b933 jim-p
		$tree = " <li><a href=\"firewall_shaper.php?interface=" . $this->GetInterface() ."&amp;queue=" . htmlspecialchars($this->GetQname())."&amp;action=show";
2373 197bfe96 Ermal Luçi
		$tree .= "\" ";
2374 f5881023 Ermal Lu?i
		$tmpvalue = $this->GetDefault();
2375 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
2376 f5881023 Ermal Lu?i
			$tree .= " class=\"navlnk\"";
2377 61e047a5 Phil Davis
		}
2378 1072b933 jim-p
		$tree .= " >" . htmlspecialchars($this->GetQname()) . "</a>";
2379 197bfe96 Ermal Luçi
		if (is_array($this->subqueues)) {
2380
			$tree .= "<ul>";
2381 4de8f7ba Phil Davis
			foreach ($this->subqueues as $q) {
2382 197bfe96 Ermal Luçi
				$tree .= $q->build_tree();
2383 420b4538 Renato Botelho
			}
2384 197bfe96 Ermal Luçi
			$tree .= "</ul>";
2385
		}
2386
		$tree .= "</li>";
2387
		return $tree;
2388 061f78b1 Bill Marquette
	}
2389
2390 f5881023 Ermal Lu?i
	/* Even this should take children into consideration */
2391 9d0b0635 Ermal
	function build_rules(&$default = false) {
2392 197bfe96 Ermal Luçi
2393 f5881023 Ermal Lu?i
		$pfq_rule = " queue ". $this->qname;
2394 61e047a5 Phil Davis
		if ($this->GetInterface()) {
2395 f5881023 Ermal Lu?i
			$pfq_rule .= " on ".get_real_interface($this->GetInterface());
2396 61e047a5 Phil Davis
		}
2397
		if ($this->GetBandwidth() && $this->GetBwscale()) {
2398 f5881023 Ermal Lu?i
			$pfq_rule .= " bandwidth ".trim($this->GetBandwidth()).$this->GetBwscale();
2399 61e047a5 Phil Davis
		}
2400 ce0117f7 Colin Fleming
2401 f5881023 Ermal Lu?i
		$tmpvalue = $this->GetQlimit();
2402 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
2403 f5881023 Ermal Lu?i
			$pfq_rule .= " qlimit " . $this->GetQlimit();
2404 61e047a5 Phil Davis
		}
2405 8edaa92c Ermal
		if ($this->GetDefault() || $this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetCodel() || $this->GetRealtime() <> "" || $this->GetLinkshare() <> "" || $this->GetUpperlimit() <> "") {
2406 f5881023 Ermal Lu?i
			$pfq_rule .= " hfsc ( ";
2407
			$tmpvalue = $this->GetRed();
2408
			if (!empty($tmpvalue)) {
2409
				$comma = 1;
2410
				$pfq_rule .= " red ";
2411
			}
2412 ce0117f7 Colin Fleming
2413 f5881023 Ermal Lu?i
			$tmpvalue = $this->GetRio();
2414
			if (!empty($tmpvalue)) {
2415 61e047a5 Phil Davis
				if ($comma) {
2416 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
2417 61e047a5 Phil Davis
				}
2418 f5881023 Ermal Lu?i
				$comma = 1;
2419
				$pfq_rule .= " rio ";
2420
			}
2421
			$tmpvalue = $this->GetEcn();
2422
			if (!empty($tmpvalue)) {
2423 61e047a5 Phil Davis
				if ($comma) {
2424 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
2425 61e047a5 Phil Davis
				}
2426 f5881023 Ermal Lu?i
				$comma = 1;
2427
				$pfq_rule .= " ecn ";
2428
			}
2429 8edaa92c Ermal
			$tmpvalue = $this->GetCodel();
2430
			if (!empty($tmpvalue)) {
2431 61e047a5 Phil Davis
				if ($comma) {
2432 8edaa92c Ermal
					$pfq_rule .= " ,";
2433 61e047a5 Phil Davis
				}
2434 8edaa92c Ermal
				$comma = 1;
2435
				$pfq_rule .= " codel ";
2436
			}
2437 f5881023 Ermal Lu?i
			$tmpvalue = $this->GetDefault();
2438
			if (!empty($tmpvalue)) {
2439 61e047a5 Phil Davis
				if ($comma) {
2440 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
2441 61e047a5 Phil Davis
				}
2442 f5881023 Ermal Lu?i
				$comma = 1;
2443
				$pfq_rule .= " default ";
2444 ef8fca71 Ermal
				$default = true;
2445 f5881023 Ermal Lu?i
			}
2446
2447 4de8f7ba Phil Davis
			if ($this->GetRealtime() <> "") {
2448 61e047a5 Phil Davis
				if ($comma) {
2449 f5881023 Ermal Lu?i
					$pfq_rule .= " , ";
2450 61e047a5 Phil Davis
				}
2451 4de8f7ba Phil Davis
				if ($this->GetR_m1() <> "" && $this->GetR_d() <> "" && $this->GetR_m2() <> "") {
2452 f5881023 Ermal Lu?i
					$pfq_rule .= " realtime (".$this->GetR_m1() . ", " . $this->GetR_d().", ". $this->GetR_m2() .") ";
2453 4de8f7ba Phil Davis
				} else if ($this->GetR_m2() <> "") {
2454 92125c97 Ermal Luçi
					$pfq_rule .= " realtime " . $this->GetR_m2();
2455 61e047a5 Phil Davis
				}
2456 197bfe96 Ermal Luçi
				$comma = 1;
2457
			}
2458 f5881023 Ermal Lu?i
			if ($this->GetLinkshare() <> "") {
2459 61e047a5 Phil Davis
				if ($comma) {
2460 197bfe96 Ermal Luçi
					$pfq_rule .= " ,";
2461 61e047a5 Phil Davis
				}
2462
				if ($this->GetL_m1() <> "" && $this->GetL_d() <> "" && $this->GetL_m2() <> "") {
2463 f5881023 Ermal Lu?i
					$pfq_rule .= " linkshare (".$this->GetL_m1(). ", ". $this->GetL_d(). ", ". $this->GetL_m2(). ") ";
2464 61e047a5 Phil Davis
				} else if ($this->GetL_m2() <> "") {
2465 92125c97 Ermal Luçi
					$pfq_rule .= " linkshare " . $this->GetL_m2() . " ";
2466 61e047a5 Phil Davis
				}
2467 197bfe96 Ermal Luçi
				$comma = 1;
2468
			}
2469 f5881023 Ermal Lu?i
			if ($this->GetUpperlimit() <> "") {
2470 61e047a5 Phil Davis
				if ($comma) {
2471 197bfe96 Ermal Luçi
					$pfq_rule .= " ,";
2472 61e047a5 Phil Davis
				}
2473
				if ($this->GetU_m1() <> "" && $this->GetU_d() <> "" && $this->GetU_m2() <> "") {
2474 92125c97 Ermal Luçi
							$pfq_rule .= " upperlimit (".$this->GetU_m1().", ". $this->GetU_d().", ". $this->GetU_m2(). ") ";
2475 61e047a5 Phil Davis
				} else if ($this->GetU_m2() <> "") {
2476 92125c97 Ermal Luçi
					$pfq_rule .= " upperlimit " . $this->GetU_m2() . " ";
2477 61e047a5 Phil Davis
				}
2478 197bfe96 Ermal Luçi
			}
2479 f5881023 Ermal Lu?i
			$pfq_rule .= " ) ";
2480
		}
2481
		if (count($this->subqueues)) {
2482
			$i = count($this->subqueues);
2483
			$pfq_rule .= " { ";
2484
			foreach ($this->subqueues as $qkey => $qnone) {
2485
				if ($i > 1) {
2486
					$i--;
2487
					$pfq_rule .= " {$qkey}, ";
2488 61e047a5 Phil Davis
				} else {
2489 f5881023 Ermal Lu?i
					$pfq_rule .= " {$qkey} ";
2490 61e047a5 Phil Davis
				}
2491 f5881023 Ermal Lu?i
			}
2492
			$pfq_rule .= " } \n";
2493 61e047a5 Phil Davis
			foreach ($this->subqueues as $q) {
2494 ea51e9f8 Renato Botelho
				$pfq_rule .= $q->build_rules($default);
2495 61e047a5 Phil Davis
			}
2496 92125c97 Ermal Luçi
		}
2497 197bfe96 Ermal Luçi
2498 420b4538 Renato Botelho
		$pfq_rule .= " \n";
2499 ce0117f7 Colin Fleming
2500 f5881023 Ermal Lu?i
		return $pfq_rule;
2501
	}
2502
2503 197bfe96 Ermal Luçi
	function build_javascript() {
2504 806942d0 Stephen Beaver
2505 9ddd492c Stephen Beaver
		$javascript = <<<EOJS
2506
<script type="text/javascript">
2507 806942d0 Stephen Beaver
//<![CDATA[
2508 9ddd492c Stephen Beaver
	events.push(function(){
2509 806942d0 Stephen Beaver
2510
		// Disables the specified input element
2511
		function disableInput(id, disable) {
2512
			$('#' + id).prop("disabled", disable);
2513
		}
2514
2515
		// Upperlimit
2516
		function enable_upperlimit() {
2517
			disableInput('upperlimit1', !$('#upperlimit').prop('checked'));
2518
			disableInput('upperlimit2', !$('#upperlimit').prop('checked'));
2519
			disableInput('upperlimit3', !$('#upperlimit').prop('checked'));
2520
		}
2521
2522
		$('#upperlimit').click(function () {
2523
			enable_upperlimit();
2524
		});
2525
2526
		enable_upperlimit();
2527
2528
		// realtime
2529
		function enable_realtime() {
2530
			disableInput('realtime1', !$('#realtime').prop('checked'));
2531
			disableInput('realtime2', !$('#realtime').prop('checked'));
2532
			disableInput('realtime3', !$('#realtime').prop('checked'));
2533
		}
2534
2535
		$('#realtime').click(function () {
2536
			enable_realtime();
2537
		});
2538
2539
		enable_realtime();
2540
2541
		// linkshare
2542
		function enable_linkshare() {
2543
			disableInput('linkshare1', !$('#linkshare').prop('checked'));
2544
			disableInput('linkshare2', !$('#linkshare').prop('checked'));
2545
			disableInput('linkshare3', !$('#linkshare').prop('checked'));
2546
		}
2547
2548
		$('#linkshare').click(function () {
2549
			enable_linkshare();
2550
		});
2551
2552
		enable_linkshare();
2553 9ddd492c Stephen Beaver
	});
2554 806942d0 Stephen Beaver
//]]>
2555
</script>
2556 9ddd492c Stephen Beaver
EOJS;
2557 92125c97 Ermal Luçi
2558 197bfe96 Ermal Luçi
		return $javascript;
2559
	}
2560 061f78b1 Bill Marquette
2561 f5881023 Ermal Lu?i
	function build_form() {
2562 806942d0 Stephen Beaver
2563 aef9d8fe Stephen Beaver
		$sform = parent::build_form();
2564 806942d0 Stephen Beaver
2565 aef9d8fe Stephen Beaver
		$section = new Form_Section('Service Curve (sc)');
2566
2567
		$group = new Form_Group('Bandwidth');
2568 806942d0 Stephen Beaver
2569 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2570
			'bandwidth',
2571
			null,
2572
			'number',
2573 54a217f0 Steve Beaver
			$this->GetBandwidth(),
2574
			['step' => 'any', 'min' => '0.000']
2575 aef9d8fe Stephen Beaver
		));
2576 806942d0 Stephen Beaver
2577 aef9d8fe Stephen Beaver
		$group->add(new Form_Select(
2578
			'bandwidthtype',
2579
			null,
2580
			$this->GetBwscale(),
2581 bfc94df0 Phil Davis
			array('Kb' => 'Kbit/s',
2582
				  'Mb' => 'Mbit/s',
2583
				  'Gb' => 'Gbit/s',
2584
				  'b' => 'Bit/s',
2585 820519e5 Stephen Beaver
				  '%' => '%')
2586 aef9d8fe Stephen Beaver
		));
2587 806942d0 Stephen Beaver
2588 aef9d8fe Stephen Beaver
		$group->setHelp('Choose the amount of bandwidth for this queue');
2589 806942d0 Stephen Beaver
2590 aef9d8fe Stephen Beaver
		$section->add($group);
2591 806942d0 Stephen Beaver
2592 aef9d8fe Stephen Beaver
		$group = new Form_Group('Max bandwidth for queue.');
2593 806942d0 Stephen Beaver
2594 aef9d8fe Stephen Beaver
		$group->add(new Form_Checkbox(
2595
			'upperlimit',
2596
			null,
2597
			'Upper Limit',
2598
			($this->GetUpperlimit()<> "")
2599 806942d0 Stephen Beaver
		));
2600
2601 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2602
			'upperlimit1',
2603
			null,
2604
			'text',
2605
			$this->GetU_m1()
2606 f7b9f8ee Stephen Beaver
		))->setHelp('m1');
2607 806942d0 Stephen Beaver
2608 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2609
			'upperlimit2',
2610
			null,
2611
			'text',
2612
			$this->GetU_d()
2613 f7b9f8ee Stephen Beaver
		))->setHelp('d');
2614 b37b4034 Phil Davis
2615 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2616
			'upperlimit3',
2617
			null,
2618
			'text',
2619
			$this->GetU_m2()
2620 f7b9f8ee Stephen Beaver
		))->setHelp('m2');
2621 806942d0 Stephen Beaver
2622
2623
		$section->add($group);
2624
2625 aef9d8fe Stephen Beaver
		$group = new Form_Group('Min bandwidth for queue.');
2626 806942d0 Stephen Beaver
2627 aef9d8fe Stephen Beaver
		$group->add(new Form_Checkbox(
2628
			'realtime',
2629
			null,
2630 9ddd492c Stephen Beaver
			'Real Time',
2631 aef9d8fe Stephen Beaver
			($this->GetRealtime()<> "")
2632 806942d0 Stephen Beaver
		));
2633
2634 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2635
			'realtime1',
2636
			null,
2637
			'text',
2638
			$this->GetR_m1()
2639 f7b9f8ee Stephen Beaver
		))->setHelp('m1');
2640 806942d0 Stephen Beaver
2641 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2642
			'realtime2',
2643
			null,
2644
			'text',
2645
			$this->GetR_d()
2646 f7b9f8ee Stephen Beaver
		))->setHelp('d');
2647 b37b4034 Phil Davis
2648 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2649
			'realtime3',
2650
			null,
2651
			'text',
2652
			$this->GetR_m2()
2653 f7b9f8ee Stephen Beaver
		))->setHelp('m2');
2654 806942d0 Stephen Beaver
2655 aef9d8fe Stephen Beaver
		$section->add($group);
2656 806942d0 Stephen Beaver
2657 aef9d8fe Stephen Beaver
		$group = new Form_Group('B/W share of a backlogged queue.');
2658 806942d0 Stephen Beaver
2659 aef9d8fe Stephen Beaver
		$group->add(new Form_Checkbox(
2660
			'linkshare',
2661
			null,
2662
			'Link Share',
2663
			($this->GetLinkshare()<> "")
2664 806942d0 Stephen Beaver
		));
2665
2666 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2667
			'linkshare1',
2668
			null,
2669
			'text',
2670
			$this->GetL_m1()
2671 f7b9f8ee Stephen Beaver
		))->setHelp('m1');
2672 806942d0 Stephen Beaver
2673 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2674
			'linkshare2',
2675
			null,
2676
			'text',
2677
			$this->GetL_d()
2678 f7b9f8ee Stephen Beaver
		))->setHelp('d');
2679 b37b4034 Phil Davis
2680 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
2681
			'linkshare3',
2682
			null,
2683
			'text',
2684
			$this->GetL_m2()
2685 f7b9f8ee Stephen Beaver
		))->setHelp('m2');
2686 806942d0 Stephen Beaver
2687 08dbe1c5 Phil Davis
		$group->sethelp('Bandwidth share overrides priority.%s' .
2688 aef9d8fe Stephen Beaver
						'The format for service curve specifications is (m1, d, m2). m2 controls the bandwidth assigned to the queue. ' .
2689
						'm1 and d are optional and can be used to control the initial bandwidth assignment. ' .
2690 08dbe1c5 Phil Davis
						'For the first d milliseconds the queue gets the bandwidth given as m1, afterwards the value given in m2.',
2691
						'<br />');
2692 806942d0 Stephen Beaver
2693 aef9d8fe Stephen Beaver
		$section->add($group);
2694 806942d0 Stephen Beaver
2695 aef9d8fe Stephen Beaver
		$sform->add($section);
2696 806942d0 Stephen Beaver
2697
		return($sform);
2698 f5881023 Ermal Lu?i
	}
2699 197bfe96 Ermal Luçi
2700 420b4538 Renato Botelho
	function update_altq_queue_data(&$data) {
2701 197bfe96 Ermal Luçi
		$this->ReadConfig($data);
2702 061f78b1 Bill Marquette
	}
2703
2704 92125c97 Ermal Luçi
	function wconfig() {
2705 197bfe96 Ermal Luçi
		$cflink =& get_reference_to_me_in_config($this->GetLink());
2706 61e047a5 Phil Davis
		if (!is_array($cflink)) {
2707 92125c97 Ermal Luçi
			$cflink = array();
2708 61e047a5 Phil Davis
		}
2709 f5881023 Ermal Lu?i
		$cflink['name'] = $this->GetQname();
2710
		$cflink['interface'] = $this->GetInterface();
2711
		$cflink['qlimit'] = trim($this->GetQlimit());
2712 61e047a5 Phil Davis
		if (empty($cflink['qlimit'])) {
2713 f5881023 Ermal Lu?i
			unset($cflink['qlimit']);
2714 61e047a5 Phil Davis
		}
2715 f5881023 Ermal Lu?i
		$cflink['priority'] = $this->GetQpriority();
2716 41799195 PiBa-NL
		if (!is_numericint($cflink['priority'])) {
2717 f5881023 Ermal Lu?i
			unset($cflink['priority']);
2718 61e047a5 Phil Davis
		}
2719 f5881023 Ermal Lu?i
		$cflink['description'] = $this->GetDescription();
2720 61e047a5 Phil Davis
		if (empty($cflink['description'])) {
2721 f5881023 Ermal Lu?i
			unset($cflink['description']);
2722 61e047a5 Phil Davis
		}
2723 f5881023 Ermal Lu?i
		$cflink['bandwidth'] = $this->GetBandwidth();
2724
		$cflink['bandwidthtype'] = $this->GetBwscale();
2725
		$cflink['enabled'] = $this->GetEnabled();
2726 61e047a5 Phil Davis
		if (empty($cflink['enabled'])) {
2727 f5881023 Ermal Lu?i
			unset($cflink['enabled']);
2728 61e047a5 Phil Davis
		}
2729 f5881023 Ermal Lu?i
		$cflink['default'] = $this->GetDefault();
2730 61e047a5 Phil Davis
		if (empty($cflink['default'])) {
2731 f5881023 Ermal Lu?i
			unset($cflink['default']);
2732 61e047a5 Phil Davis
		}
2733 f5881023 Ermal Lu?i
		$cflink['red'] = trim($this->GetRed());
2734 61e047a5 Phil Davis
		if (empty($cflink['red'])) {
2735 f5881023 Ermal Lu?i
			unset($cflink['red']);
2736 61e047a5 Phil Davis
		}
2737 f5881023 Ermal Lu?i
		$cflink['rio'] = $this->GetRio();
2738 61e047a5 Phil Davis
		if (empty($cflink['rio'])) {
2739 f5881023 Ermal Lu?i
			unset($cflink['rio']);
2740 61e047a5 Phil Davis
		}
2741 f5881023 Ermal Lu?i
		$cflink['ecn'] = trim($this->GetEcn());
2742 61e047a5 Phil Davis
		if (empty($cflink['ecn'])) {
2743 f5881023 Ermal Lu?i
			unset($cflink['ecn']);
2744 61e047a5 Phil Davis
		}
2745 9f6919e6 Richard Connon
		$cflink['codel'] = trim($this->GetCodel());
2746 61e047a5 Phil Davis
		if (empty($cflink['codel'])) {
2747 9f6919e6 Richard Connon
			unset($cflink['codel']);
2748 61e047a5 Phil Davis
		}
2749 f5881023 Ermal Lu?i
		if ($this->GetLinkshare() <> "") {
2750
			if ($this->GetL_m1() <> "") {
2751
				$cflink['linkshare1'] = $this->GetL_m1();
2752
				$cflink['linkshare2'] = $this->GetL_d();
2753
				$cflink['linkshare'] = "on";
2754
			} else {
2755
				unset($cflink['linkshare']);
2756
				unset($cflink['linkshare1']);
2757
				unset($cflink['linkshare2']);
2758
			}
2759
			if ($this->GetL_m2() <> "") {
2760
				$cflink['linkshare3'] = $this->GetL_m2();
2761
				$cflink['linkshare'] = "on";
2762
			} else {
2763
				unset($cflink['linkshare']);
2764
				unset($cflink['linkshare3']);
2765
			}
2766
		} else {
2767
			unset($cflink['linkshare']);
2768
			unset($cflink['linkshare1']);
2769
			unset($cflink['linkshare2']);
2770
			unset($cflink['linkshare3']);
2771
		}
2772
		if ($this->GetRealtime() <> "") {
2773
			if ($this->GetR_m1() <> "") {
2774
				$cflink['realtime1'] = $this->GetR_m1();
2775
				$cflink['realtime2'] = $this->GetR_d();
2776
				$cflink['realtime'] = "on";
2777
			} else {
2778
				unset($cflink['realtime']);
2779
				unset($cflink['realtime1']);
2780
				unset($cflink['realtime2']);
2781
			}
2782
			if ($this->GetR_m2() <> "") {
2783
				$cflink['realtime3'] = $this->GetR_m2();
2784
				$cflink['realtime'] = "on";
2785
			} else {
2786
				unset($cflink['realtime']);
2787
				unset($cflink['realtime3']);
2788
			}
2789
		} else {
2790
			unset($cflink['realtime']);
2791
			unset($cflink['realtime1']);
2792
			unset($cflink['realtime2']);
2793
			unset($cflink['realtime3']);
2794
		}
2795
		if ($this->GetUpperlimit() <> "") {
2796
			if ($this->GetU_m1() <> "") {
2797
				$cflink['upperlimit1'] = $this->GetU_m1();
2798
				$cflink['upperlimit2'] = $this->GetU_d();
2799
				$cflink['upperlimit'] = "on";
2800
			} else {
2801
				unset($cflink['upperlimit']);
2802
				unset($cflink['upperlimit1']);
2803
				unset($cflink['upperlimit2']);
2804
			}
2805
			if ($this->GetU_m2() <> "") {
2806
				$cflink['upperlimit3'] = $this->GetU_m2();
2807
				$cflink['upperlimit'] = "on";
2808
			} else {
2809
				unset($cflink['upperlimit']);
2810
				unset($cflink['upperlimit3']);
2811
			}
2812
		} else {
2813
			unset($cflink['upperlimit']);
2814
			unset($cflink['upperlimit1']);
2815
			unset($cflink['upperlimit2']);
2816
			unset($cflink['upperlimit3']);
2817 197bfe96 Ermal Luçi
		}
2818
	}
2819 f5881023 Ermal Lu?i
}
2820 061f78b1 Bill Marquette
2821 197bfe96 Ermal Luçi
class cbq_queue extends priq_queue {
2822 f5881023 Ermal Lu?i
	var $qborrow = "";
2823 061f78b1 Bill Marquette
2824 197bfe96 Ermal Luçi
	function GetBorrow() {
2825
		return $this->qborrow;
2826 061f78b1 Bill Marquette
	}
2827 197bfe96 Ermal Luçi
	function SetBorrow($borrow) {
2828
		$this->qborrow = $borrow;
2829
	}
2830 70b139a3 Chris Buechler
	function CanHaveChildren() {
2831 f5881023 Ermal Lu?i
		return true;
2832 92125c97 Ermal Luçi
	}
2833 197bfe96 Ermal Luçi
2834 92125c97 Ermal Luçi
	function &add_queue($interface, &$qname, &$path, &$input_errors) {
2835 197bfe96 Ermal Luçi
2836 61e047a5 Phil Davis
		if (!is_array($this->subqueues)) {
2837 f5881023 Ermal Lu?i
			$this->subqueues = array();
2838 61e047a5 Phil Davis
		}
2839 5c4fcabc Renato Botelho
		$__tmp_q = new cbq_queue(); $q =& $__tmp_q;
2840 197bfe96 Ermal Luçi
		$q->SetInterface($this->GetInterface());
2841 ea51e9f8 Renato Botelho
		$q->SetParent($this);
2842 92125c97 Ermal Luçi
		$q->ReadConfig($qname);
2843 420b4538 Renato Botelho
		$q->validate_input($qname, $input_errors);
2844 40de74f5 Ermal Luçi
2845 197bfe96 Ermal Luçi
		$q->SetEnabled("on");
2846 92125c97 Ermal Luçi
		$q->SetLink($path);
2847
		$this->subqueues[$q->GetQName()] = &$q;
2848 197bfe96 Ermal Luçi
		ref_on_altq_queue_list($this->GetQname(), $q->GetQname());
2849
		if (is_array($qname['queue'])) {
2850 f5881023 Ermal Lu?i
			foreach ($qname['queue'] as $key1 => $que) {
2851
				array_push($path, $key1);
2852 ea51e9f8 Renato Botelho
				$q->add_queue($q->GetInterface(), $que, $path, $input_errors);
2853 f5881023 Ermal Lu?i
				array_pop($path);
2854
			}
2855 92125c97 Ermal Luçi
		}
2856 197bfe96 Ermal Luçi
2857
		return $q;
2858 f5881023 Ermal Lu?i
	}
2859 a843b04f Ermal Luçi
2860 f5881023 Ermal Lu?i
	function copy_queue($interface, &$cflink) {
2861 a843b04f Ermal Luçi
2862 f5881023 Ermal Lu?i
		$cflink['interface'] = $interface;
2863
		$cflink['qlimit'] = trim($this->GetQlimit());
2864 61e047a5 Phil Davis
		if (empty($clink['qlimit'])) {
2865 f5881023 Ermal Lu?i
			unset($cflink['qlimit']);
2866 61e047a5 Phil Davis
		}
2867 f5881023 Ermal Lu?i
		$cflink['priority'] = trim($this->GetQpriority());
2868 41799195 PiBa-NL
		if (!is_numeric($cflink['priority'])) {
2869 f5881023 Ermal Lu?i
			unset($cflink['priority']);
2870 61e047a5 Phil Davis
		}
2871 f5881023 Ermal Lu?i
		$cflink['name'] = $this->GetQname();
2872
		$cflink['description'] = trim($this->GetDescription());
2873 61e047a5 Phil Davis
		if (empty($cflink['description'])) {
2874 f5881023 Ermal Lu?i
			unset($cflink['description']);
2875 61e047a5 Phil Davis
		}
2876 f5881023 Ermal Lu?i
		$cflink['bandwidth'] = $this->GetBandwidth();
2877
		$cflink['bandwidthtype'] = $this->GetBwscale();
2878
		$cflink['enabled'] = trim($this->GetEnabled());
2879 61e047a5 Phil Davis
		if (empty($cflink['enabled'])) {
2880 f5881023 Ermal Lu?i
			unset($cflink['enabled']);
2881 61e047a5 Phil Davis
		}
2882 f5881023 Ermal Lu?i
		$cflink['default'] = trim($this->GetDefault());
2883 61e047a5 Phil Davis
		if (empty($cflink['default'])) {
2884 f5881023 Ermal Lu?i
			unset($cflink['default']);
2885 61e047a5 Phil Davis
		}
2886 f5881023 Ermal Lu?i
		$cflink['red'] = trim($this->GetRed());
2887 61e047a5 Phil Davis
		if (empty($cflink['red'])) {
2888 f5881023 Ermal Lu?i
			unset($cflink['red']);
2889 61e047a5 Phil Davis
		}
2890 f5881023 Ermal Lu?i
		$cflink['rio'] = trim($this->GetRio());
2891 61e047a5 Phil Davis
		if (empty($cflink['rio'])) {
2892 f5881023 Ermal Lu?i
			unset($cflink['rio']);
2893 61e047a5 Phil Davis
		}
2894 f5881023 Ermal Lu?i
		$cflink['ecn'] = trim($this->GetEcn());
2895 61e047a5 Phil Davis
		if (empty($cflink['ecn'])) {
2896 f5881023 Ermal Lu?i
			unset($cflink['ecn']);
2897 61e047a5 Phil Davis
		}
2898 f5881023 Ermal Lu?i
		$cflink['borrow'] = trim($this->GetBorrow());
2899 61e047a5 Phil Davis
		if (empty($cflink['borrow'])) {
2900 f5881023 Ermal Lu?i
			unset($cflink['borrow']);
2901 61e047a5 Phil Davis
		}
2902 f5881023 Ermal Lu?i
		if (is_array($this->queues)) {
2903
			$cflinkp['queue'] = array();
2904
			foreach ($this->subqueues as $q) {
2905
				$cflink['queue'][$q->GetQname()] = array();
2906 ea51e9f8 Renato Botelho
				$q->copy_queue($interface, $cflink['queue'][$q->GetQname()]);
2907 f5881023 Ermal Lu?i
			}
2908 a843b04f Ermal Luçi
		}
2909 f5881023 Ermal Lu?i
	}
2910 ce0117f7 Colin Fleming
2911 f5881023 Ermal Lu?i
	/*
2912
	 * Should search even its children
2913
	 */
2914
	function &find_queue($interface, $qname) {
2915 61e047a5 Phil Davis
		if ($qname == $this->GetQname()) {
2916 f5881023 Ermal Lu?i
			return $this;
2917 61e047a5 Phil Davis
		}
2918 f5881023 Ermal Lu?i
		foreach ($this->subqueues as $q) {
2919
			$result =& $q->find_queue("", $qname);
2920 61e047a5 Phil Davis
			if ($result) {
2921 f5881023 Ermal Lu?i
				return $result;
2922 61e047a5 Phil Davis
			}
2923 92125c97 Ermal Luçi
		}
2924 f5881023 Ermal Lu?i
	}
2925 197bfe96 Ermal Luçi
2926
	function &find_parentqueue($interface, $qname) {
2927 61e047a5 Phil Davis
		if ($this->subqueues[$qname]) {
2928 f5881023 Ermal Lu?i
			return $this;
2929 61e047a5 Phil Davis
		}
2930 f5881023 Ermal Lu?i
		foreach ($this->subqueues as $q) {
2931
			$result = $q->find_parentqueue("", $qname);
2932 61e047a5 Phil Davis
			if ($result) {
2933 197bfe96 Ermal Luçi
				return $result;
2934 61e047a5 Phil Davis
			}
2935 197bfe96 Ermal Luçi
		}
2936 f5881023 Ermal Lu?i
	}
2937 197bfe96 Ermal Luçi
2938 f5881023 Ermal Lu?i
	function delete_queue() {
2939
		unref_on_altq_queue_list($this->GetQname());
2940
		cleanup_queue_from_rules($this->GetQname());
2941 45eeb038 Luiz Otavio O Souza
		foreach ($this->subqueues as $q)
2942
			$q->delete_queue();
2943 f5881023 Ermal Lu?i
		unset_object_by_reference($this->GetLink());
2944
	}
2945 ce0117f7 Colin Fleming
2946 197bfe96 Ermal Luçi
	function validate_input($data, &$input_errors) {
2947
		parent::validate_input($data, $input_errors);
2948 ce0117f7 Colin Fleming
2949 61e047a5 Phil Davis
		if ($data['priority'] > 7) {
2950 41799195 PiBa-NL
				$input_errors[] = gettext("Priority must be an integer between 0 and 7.");
2951 61e047a5 Phil Davis
		}
2952 2c072899 jim-p
		$reqdfields[] = "bandwidth";
2953 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidth");
2954 2c072899 jim-p
		$reqdfields[] = "bandwidthtype";
2955 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidthtype");
2956 061f78b1 Bill Marquette
2957 40de74f5 Ermal Luçi
		shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
2958 92125c97 Ermal Luçi
	}
2959 f5881023 Ermal Lu?i
2960
	function ReadConfig(&$q) {
2961
		parent::ReadConfig($q);
2962 61e047a5 Phil Davis
		if (!empty($q['borrow'])) {
2963 197bfe96 Ermal Luçi
			$this->SetBorrow("on");
2964 61e047a5 Phil Davis
		} else {
2965 7ed9c6ac Ermal
			$this->SetBorrow("");
2966 61e047a5 Phil Davis
		}
2967 f5881023 Ermal Lu?i
	}
2968 ce0117f7 Colin Fleming
2969 197bfe96 Ermal Luçi
	function build_javascript() {
2970
		return parent::build_javascript();
2971
	}
2972 061f78b1 Bill Marquette
2973 197bfe96 Ermal Luçi
	function build_tree() {
2974 1072b933 jim-p
		$tree = " <li><a href=\"firewall_shaper.php?interface=" . $this->GetInterface()."&amp;queue=" . htmlspecialchars($this->GetQname())."&amp;action=show";
2975 f5881023 Ermal Lu?i
		$tree .= "\" ";
2976
		$tmpvalue = trim($this->GetDefault());
2977 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
2978 f5881023 Ermal Lu?i
			$tree .= " class=\"navlnk\"";
2979 61e047a5 Phil Davis
		}
2980 1072b933 jim-p
		$tree .= " >" . htmlspecialchars($this->GetQname()) . "</a>";
2981 f5881023 Ermal Lu?i
		if (is_array($this->subqueues)) {
2982
			$tree .= "<ul>";
2983 4de8f7ba Phil Davis
			foreach ($this->subqueues as $q) {
2984 f5881023 Ermal Lu?i
				$tree .= $q->build_tree();
2985 420b4538 Renato Botelho
			}
2986 f5881023 Ermal Lu?i
			$tree .= "</ul>";
2987
		}
2988
		$tree .= "</li>";
2989
		return $tree;
2990 197bfe96 Ermal Luçi
	}
2991 ce0117f7 Colin Fleming
2992 70b139a3 Chris Buechler
	/* Even this should take children into consideration */
2993 9d0b0635 Ermal
	function build_rules(&$default = false) {
2994 f5881023 Ermal Lu?i
		$pfq_rule = "queue ". $this->qname;
2995 61e047a5 Phil Davis
		if ($this->GetInterface()) {
2996 f5881023 Ermal Lu?i
			$pfq_rule .= " on ".get_real_interface($this->GetInterface());
2997 61e047a5 Phil Davis
		}
2998
		if ($this->GetBandwidth() && $this->GetBwscale()) {
2999 f5881023 Ermal Lu?i
			$pfq_rule .= " bandwidth ".trim($this->GetBandwidth()).$this->GetBwscale();
3000 61e047a5 Phil Davis
		}
3001 f5881023 Ermal Lu?i
		$tmpvalue = $this->GetQpriority();
3002 41799195 PiBa-NL
		if (is_numeric($tmpvalue)) {
3003 f5881023 Ermal Lu?i
			$pfq_rule .= " priority " . $this->GetQpriority();
3004 61e047a5 Phil Davis
		}
3005 f5881023 Ermal Lu?i
		$tmpvalue = trim($this->GetQlimit());
3006 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
3007 f5881023 Ermal Lu?i
			$pfq_rule .= " qlimit " . $this->GetQlimit();
3008 61e047a5 Phil Davis
		}
3009 8edaa92c Ermal
		if ($this->GetDefault() || $this->GetRed() || $this->GetRio() || $this->GetEcn() || $this->GetBorrow() || $this->GetCodel()) {
3010 f5881023 Ermal Lu?i
			$pfq_rule .= " cbq ( ";
3011
			$tmpvalue = trim($this->GetRed());
3012
			if (!empty($tmpvalue)) {
3013
				$comma = 1;
3014
				$pfq_rule .= " red ";
3015
			}
3016 8edaa92c Ermal
			$tmpvalue = trim($this->GetCodel());
3017
			if (!empty($tmpvalue)) {
3018
				$comma = 1;
3019
				$pfq_rule .= " codel ";
3020
			}
3021 f5881023 Ermal Lu?i
			$tmpvalue = trim($this->GetRio());
3022
			if (!empty($tmpvalue)) {
3023 61e047a5 Phil Davis
				if ($comma) {
3024 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
3025 61e047a5 Phil Davis
				}
3026 f5881023 Ermal Lu?i
				$comma = 1;
3027
				$pfq_rule .= " rio ";
3028
			}
3029
			$tmpvalue = trim($this->GetEcn());
3030
			if (!empty($tmpvalue)) {
3031 61e047a5 Phil Davis
				if ($comma) {
3032 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
3033 61e047a5 Phil Davis
				}
3034 f5881023 Ermal Lu?i
				$comma = 1;
3035
				$pfq_rule .= " ecn ";
3036
			}
3037
			$tmpvalue = trim($this->GetDefault());
3038
			if (!empty($tmpvalue)) {
3039 61e047a5 Phil Davis
				if ($comma) {
3040 f5881023 Ermal Lu?i
					$pfq_rule .= " ,";
3041 61e047a5 Phil Davis
				}
3042 f5881023 Ermal Lu?i
				$comma = 1;
3043
				$pfq_rule .= " default ";
3044 ef8fca71 Ermal
				$default = true;
3045 f5881023 Ermal Lu?i
			}
3046
			$tmpvalue = trim($this->GetBorrow());
3047
			if (!empty($tmpvalue)) {
3048 61e047a5 Phil Davis
				if ($comma) {
3049 f5881023 Ermal Lu?i
					$pfq_rule .= ", ";
3050 61e047a5 Phil Davis
				}
3051 f5881023 Ermal Lu?i
				$pfq_rule .= " borrow ";
3052 92125c97 Ermal Luçi
			}
3053 f5881023 Ermal Lu?i
			$pfq_rule .= " ) ";
3054 420b4538 Renato Botelho
		}
3055 f5881023 Ermal Lu?i
		if (count($this->subqueues)) {
3056
			$i = count($this->subqueues);
3057
			$pfq_rule .= " { ";
3058
			foreach ($this->subqueues as $qkey => $qnone) {
3059
				if ($i > 1) {
3060
					$i--;
3061
					$pfq_rule .= " {$qkey}, ";
3062 61e047a5 Phil Davis
				} else {
3063 f5881023 Ermal Lu?i
					$pfq_rule .= " {$qkey} ";
3064 61e047a5 Phil Davis
				}
3065 f5881023 Ermal Lu?i
			}
3066
			$pfq_rule .= " } \n";
3067 61e047a5 Phil Davis
			foreach ($this->subqueues as $q) {
3068 9d0b0635 Ermal
				$pfq_rule .= $q->build_rules($default);
3069 61e047a5 Phil Davis
			}
3070 f5881023 Ermal Lu?i
		}
3071 92125c97 Ermal Luçi
3072 f5881023 Ermal Lu?i
		$pfq_rule .= " \n";
3073
		return $pfq_rule;
3074 92125c97 Ermal Luçi
	}
3075
3076
	function build_form() {
3077 aef9d8fe Stephen Beaver
		$sform = parent::build_form();
3078 806942d0 Stephen Beaver
3079 9ce54773 Stephen Beaver
		$section = new Form_Section('NOTITLE');
3080 aef9d8fe Stephen Beaver
3081
		$group = new Form_Group('Bandwidth');
3082 806942d0 Stephen Beaver
3083 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
3084
			'bandwidth',
3085
			null,
3086
			'number',
3087
			$this->GetBandwidth()
3088
		));
3089 806942d0 Stephen Beaver
3090 aef9d8fe Stephen Beaver
		$group->add(new Form_Select(
3091
			'bandwidthtype',
3092
			null,
3093
			$this->GetBwscale(),
3094 bfc94df0 Phil Davis
			array('Kb' => 'Kbit/s',
3095
				  'Mb' => 'Mbit/s',
3096
				  'Gb' => 'Gbit/s',
3097
				  'b' => 'Bit/s',
3098 820519e5 Stephen Beaver
				  '%' => '%')
3099 aef9d8fe Stephen Beaver
		));
3100 806942d0 Stephen Beaver
3101 aef9d8fe Stephen Beaver
		$group->setHelp('Choose the amount of bandwidth for this queue');
3102
3103
		$section->add($group);
3104 806942d0 Stephen Beaver
3105 aef9d8fe Stephen Beaver
		$section->addInput(new Form_Checkbox(
3106
			'borrow',
3107 9ddd492c Stephen Beaver
			'Scheduler option',
3108 aef9d8fe Stephen Beaver
			'Borrow from other queues when available',
3109
			($this->GetBorrow() == "on")
3110 806942d0 Stephen Beaver
		));
3111
3112 7bba13e8 Stephen Beaver
		$sform->add($section);
3113
3114 aef9d8fe Stephen Beaver
		return $sform;
3115 92125c97 Ermal Luçi
	}
3116 197bfe96 Ermal Luçi
3117 420b4538 Renato Botelho
	function update_altq_queue_data(&$data) {
3118 197bfe96 Ermal Luçi
		$this->ReadConfig($data);
3119
	}
3120 061f78b1 Bill Marquette
3121 92125c97 Ermal Luçi
	function wconfig() {
3122 197bfe96 Ermal Luçi
		$cflink =& get_reference_to_me_in_config($this->GetLink());
3123 61e047a5 Phil Davis
		if (!is_array($cflink)) {
3124 f5881023 Ermal Lu?i
			$cflink = array();
3125 61e047a5 Phil Davis
		}
3126 f5881023 Ermal Lu?i
		$cflink['interface'] = $this->GetInterface();
3127
		$cflink['qlimit'] = trim($this->GetQlimit());
3128 61e047a5 Phil Davis
		if (empty($cflink['qlimit'])) {
3129 f5881023 Ermal Lu?i
			unset($cflink['qlimit']);
3130 61e047a5 Phil Davis
		}
3131 f5881023 Ermal Lu?i
		$cflink['priority'] = $this->GetQpriority();
3132 41799195 PiBa-NL
		if (!is_numeric($cflink['priority'])) {
3133 f5881023 Ermal Lu?i
			unset($cflink['priority']);
3134 61e047a5 Phil Davis
		}
3135 f5881023 Ermal Lu?i
		$cflink['name'] = $this->GetQname();
3136
		$cflink['description'] = $this->GetDescription();
3137 61e047a5 Phil Davis
		if (empty($cflink['description'])) {
3138 f5881023 Ermal Lu?i
			unset($cflink['description']);
3139 61e047a5 Phil Davis
		}
3140 f5881023 Ermal Lu?i
		$cflink['bandwidth'] = $this->GetBandwidth();
3141
		$cflink['bandwidthtype'] = $this->GetBwscale();
3142
		$cflink['enabled'] = trim($this->GetEnabled());
3143 61e047a5 Phil Davis
		if (empty($cflink['enabled'])) {
3144 f5881023 Ermal Lu?i
			unset($cflink['enabled']);
3145 61e047a5 Phil Davis
		}
3146 f5881023 Ermal Lu?i
		$cflink['default'] = trim($this->GetDefault());
3147 61e047a5 Phil Davis
		if (empty($cflink['default'])) {
3148 f5881023 Ermal Lu?i
			unset($cflink['default']);
3149 61e047a5 Phil Davis
		}
3150 f5881023 Ermal Lu?i
		$cflink['red'] = trim($this->GetRed());
3151 61e047a5 Phil Davis
		if (empty($cflink['red'])) {
3152 f5881023 Ermal Lu?i
			unset($cflink['red']);
3153 61e047a5 Phil Davis
		}
3154 f5881023 Ermal Lu?i
		$cflink['rio'] = trim($this->GetRio());
3155 61e047a5 Phil Davis
		if (empty($cflink['rio'])) {
3156 f5881023 Ermal Lu?i
			unset($cflink['rio']);
3157 61e047a5 Phil Davis
		}
3158 f5881023 Ermal Lu?i
		$cflink['ecn'] = trim($this->GetEcn());
3159 61e047a5 Phil Davis
		if (empty($cflink['ecn'])) {
3160 f5881023 Ermal Lu?i
			unset($cflink['ecn']);
3161 61e047a5 Phil Davis
		}
3162 9f6919e6 Richard Connon
		$cflink['codel'] = trim($this->GetCodel());
3163 61e047a5 Phil Davis
		if (empty($cflink['codel'])) {
3164 9f6919e6 Richard Connon
			unset($cflink['codel']);
3165 61e047a5 Phil Davis
		}
3166 f5881023 Ermal Lu?i
		$cflink['borrow'] = trim($this->GetBorrow());
3167 61e047a5 Phil Davis
		if (empty($cflink['borrow'])) {
3168 f5881023 Ermal Lu?i
			unset($cflink['borrow']);
3169 61e047a5 Phil Davis
		}
3170 f5881023 Ermal Lu?i
	}
3171 197bfe96 Ermal Luçi
}
3172 061f78b1 Bill Marquette
3173 2b5caa0e Ermal Luçi
class fairq_queue extends priq_queue {
3174 f5881023 Ermal Lu?i
	var $hogs;
3175
	var $buckets;
3176 2b5caa0e Ermal Luçi
3177
	function GetBuckets() {
3178
		return $this->buckets;
3179
	}
3180
	function SetBuckets($buckets) {
3181 ae3d3adb Ermal Luçi
		$this->buckets = $buckets;
3182 2b5caa0e Ermal Luçi
	}
3183
	function GetHogs() {
3184
		return $this->hogs;
3185
	}
3186
	function SetHogs($hogs) {
3187 ae3d3adb Ermal Luçi
		$this->hogs = $hogs;
3188 2b5caa0e Ermal Luçi
	}
3189 70b139a3 Chris Buechler
	function CanHaveChildren() {
3190 2b5caa0e Ermal Luçi
		return false;
3191
	}
3192
3193
3194
	function copy_queue($interface, &$cflink) {
3195 420b4538 Renato Botelho
		$cflink['interface'] = $interface;
3196
		$cflink['qlimit'] = $this->GetQlimit();
3197
		$cflink['priority'] = $this->GetQpriority();
3198
		$cflink['name'] = $this->GetQname();
3199
		$cflink['description'] = $this->GetDescription();
3200
		$cflink['bandwidth'] = $this->GetBandwidth();
3201
		$cflink['bandwidthtype'] = $this->GetBwscale();
3202
		$cflink['enabled'] = $this->GetEnabled();
3203
		$cflink['default'] = $this->GetDefault();
3204
		$cflink['red'] = $this->GetRed();
3205
		$cflink['rio'] = $this->GetRio();
3206
		$cflink['ecn'] = $this->GetEcn();
3207
		$cflink['buckets'] = $this->GetBuckets();
3208 8774ca6e Ermal Luçi
		$cflink['hogs'] = $this->GetHogs();
3209 2b5caa0e Ermal Luçi
	}
3210 ce0117f7 Colin Fleming
3211 2b5caa0e Ermal Luçi
	/*
3212 70b139a3 Chris Buechler
	 * Should search even its children
3213 2b5caa0e Ermal Luçi
	 */
3214
	function &find_queue($interface, $qname) {
3215 61e047a5 Phil Davis
		if ($qname == $this->GetQname()) {
3216 2b5caa0e Ermal Luçi
			return $this;
3217 61e047a5 Phil Davis
		}
3218 2b5caa0e Ermal Luçi
	}
3219
3220 62150088 Ermal Lu?i
	function find_parentqueue($interface, $qname) { return; }
3221 2b5caa0e Ermal Luçi
3222
	function delete_queue() {
3223
		unref_on_altq_queue_list($this->GetQname());
3224
		cleanup_queue_from_rules($this->GetQname());
3225
		unset_object_by_reference($this->GetLink());
3226
	}
3227 ce0117f7 Colin Fleming
3228 2b5caa0e Ermal Luçi
	function validate_input($data, &$input_errors) {
3229
		parent::validate_input($data, $input_errors);
3230 ce0117f7 Colin Fleming
3231 41799195 PiBa-NL
		if ($data['priority'] > 7) {
3232
				$input_errors[] = gettext("Priority must be an integer between 0 and 7.");
3233 61e047a5 Phil Davis
		}
3234 2c072899 jim-p
		$reqdfields[] = "bandwidth";
3235 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidth");
3236 2c072899 jim-p
		$reqdfields[] = "bandwidthtype";
3237 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidthtype");
3238 2b5caa0e Ermal Luçi
3239
		shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
3240
	}
3241 ce0117f7 Colin Fleming
3242 2b5caa0e Ermal Luçi
	function ReadConfig(&$q) {
3243
		parent::ReadConfig($q);
3244 61e047a5 Phil Davis
		if (!empty($q['buckets'])) {
3245 2b5caa0e Ermal Luçi
			$this->SetBuckets($q['buckets']);
3246 61e047a5 Phil Davis
		} else {
3247 7ed9c6ac Ermal
			$this->SetBuckets("");
3248 61e047a5 Phil Davis
		}
3249
		if (!empty($q['hogs']) && is_valid_shaperbw($q['hogs'])) {
3250 2b5caa0e Ermal Luçi
			$this->SetHogs($q['hogs']);
3251 61e047a5 Phil Davis
		} else {
3252 7ed9c6ac Ermal
			$this->SetHogs("");
3253 61e047a5 Phil Davis
		}
3254 2b5caa0e Ermal Luçi
	}
3255 ce0117f7 Colin Fleming
3256 2b5caa0e Ermal Luçi
	function build_javascript() {
3257
		return parent::build_javascript();
3258
	}
3259
3260
	function build_tree() {
3261 420b4538 Renato Botelho
		$tree = " <li><a href=\"firewall_shaper.php?interface=" .
3262 1072b933 jim-p
		$this->GetInterface()."&amp;queue=" . htmlspecialchars($this->GetQname())."&amp;action=show";
3263 f5881023 Ermal Lu?i
		$tree .= "\" ";
3264
		$tmpvalue = trim($this->GetDefault());
3265 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
3266 f5881023 Ermal Lu?i
			$tree .= " class=\"navlnk\"";
3267 61e047a5 Phil Davis
		}
3268 1072b933 jim-p
		$tree .= " >" . htmlspecialchars($this->GetQname()) . "</a>";
3269 f5881023 Ermal Lu?i
		$tree .= "</li>";
3270
		return $tree;
3271 2b5caa0e Ermal Luçi
	}
3272 ce0117f7 Colin Fleming
3273 70b139a3 Chris Buechler
	/* Even this should take children into consideration */
3274 9d0b0635 Ermal
	function build_rules(&$default = false) {
3275 2b5caa0e Ermal Luçi
		$pfq_rule = "queue ". $this->qname;
3276 61e047a5 Phil Davis
		if ($this->GetInterface()) {
3277 85a5da13 Ermal Luçi
			$pfq_rule .= " on ".get_real_interface($this->GetInterface());
3278 61e047a5 Phil Davis
		}
3279
		if ($this->GetBandwidth() && $this->GetBwscale()) {
3280 2b5caa0e Ermal Luçi
			$pfq_rule .= " bandwidth ".trim($this->GetBandwidth()).$this->GetBwscale();
3281 61e047a5 Phil Davis
		}
3282 f5881023 Ermal Lu?i
		$tmpvalue = trim($this->GetQpriority());
3283 41799195 PiBa-NL
		if (is_numeric($tmpvalue)) {
3284 2b5caa0e Ermal Luçi
			$pfq_rule .= " priority " . $this->GetQpriority();
3285 61e047a5 Phil Davis
		}
3286 f5881023 Ermal Lu?i
		$tmpvalue = trim($this->GetQlimit());
3287 61e047a5 Phil Davis
		if (!empty($tmpvalue)) {
3288 2b5caa0e Ermal Luçi
			$pfq_rule .= " qlimit " . $this->GetQlimit();
3289 61e047a5 Phil Davis
		}
3290
		if ($this->GetDefault() || $this->GetRed() || $this->GetRio() ||
3291 4de8f7ba Phil Davis
		    $this->GetEcn() || $this->GetBuckets() || $this->GetHogs() || $this->GetCodel()) {
3292 ae3d3adb Ermal Luçi
			$pfq_rule .= " fairq ( ";
3293 f5881023 Ermal Lu?i
			$tmpvalue = trim($this->GetRed());
3294
			if (!empty($tmpvalue)) {
3295 2b5caa0e Ermal Luçi
				$comma = 1;
3296
				$pfq_rule .= " red ";
3297
			}
3298 8edaa92c Ermal
			$tmpvalue = trim($this->GetCodel());
3299
			if (!empty($tmpvalue)) {
3300
				$comma = 1;
3301
				$pfq_rule .= " codel ";
3302
			}
3303 f5881023 Ermal Lu?i
			$tmpvalue = trim($this->GetRio());
3304
			if (!empty($tmpvalue)) {
3305 61e047a5 Phil Davis
				if ($comma) {
3306 2b5caa0e Ermal Luçi
					$pfq_rule .= " ,";
3307 61e047a5 Phil Davis
				}
3308 2b5caa0e Ermal Luçi
				$comma = 1;
3309
				$pfq_rule .= " rio ";
3310
			}
3311 f5881023 Ermal Lu?i
			$tmpvalue = trim($this->GetEcn());
3312
			if (!empty($tmpvalue)) {
3313 61e047a5 Phil Davis
				if ($comma) {
3314 2b5caa0e Ermal Luçi
					$pfq_rule .= " ,";
3315 61e047a5 Phil Davis
				}
3316 2b5caa0e Ermal Luçi
				$comma = 1;
3317
				$pfq_rule .= " ecn ";
3318
			}
3319 f5881023 Ermal Lu?i
			$tmpvalue = trim($this->GetDefault());
3320
			if (!empty($tmpvalue)) {
3321 61e047a5 Phil Davis
				if ($comma) {
3322 2b5caa0e Ermal Luçi
					$pfq_rule .= " ,";
3323 61e047a5 Phil Davis
				}
3324 2b5caa0e Ermal Luçi
				$comma = 1;
3325
				$pfq_rule .= " default ";
3326 ef8fca71 Ermal
				$default = true;
3327 2b5caa0e Ermal Luçi
			}
3328 f5881023 Ermal Lu?i
			$tmpvalue = trim($this->GetBuckets());
3329
			if (!empty($tmpvalue)) {
3330 61e047a5 Phil Davis
				if ($comma) {
3331 2b5caa0e Ermal Luçi
					$pfq_rule .= ", ";
3332 61e047a5 Phil Davis
				}
3333 2b5caa0e Ermal Luçi
				$pfq_rule .= " buckets " . $this->GetBuckets() . " ";
3334
			}
3335 f5881023 Ermal Lu?i
			$tmpvalue = trim($this->GetHogs());
3336
			if (!empty($tmpvalue)) {
3337 61e047a5 Phil Davis
				if ($comma) {
3338 2b5caa0e Ermal Luçi
					$pfq_rule .= ", ";
3339 61e047a5 Phil Davis
				}
3340 2b5caa0e Ermal Luçi
				$pfq_rule .= " hogs " . $this->GetHogs() . " ";
3341
			}
3342 61e047a5 Phil Davis
			$pfq_rule .= " ) ";
3343 420b4538 Renato Botelho
		}
3344 2b5caa0e Ermal Luçi
3345
		$pfq_rule .= " \n";
3346
		return $pfq_rule;
3347
	}
3348
3349
	function build_form() {
3350 f5e511d3 Ermal
		$form = parent::build_form();
3351 806942d0 Stephen Beaver
3352 aef9d8fe Stephen Beaver
		$section = new Form_Section('');
3353
3354
		$group = new Form_Group('Bandwidth');
3355 806942d0 Stephen Beaver
3356 aef9d8fe Stephen Beaver
		$group->add(new Form_Input(
3357
			'bandwidth',
3358
			null,
3359
			'number',
3360
			$this->GetBandwidth()
3361
		));
3362 806942d0 Stephen Beaver
3363 aef9d8fe Stephen Beaver
		$group->add(new Form_Select(
3364
			'bandwidthtype',
3365
			null,
3366
			$this->GetBwscale(),
3367 bfc94df0 Phil Davis
			array('Kb' => 'Kbit/s',
3368
				  'Mb' => 'Mbit/s',
3369
				  'Gb' => 'Gbit/s',
3370
				  'b' => 'Bit/s',
3371 820519e5 Stephen Beaver
				  '%' => '%')
3372 aef9d8fe Stephen Beaver
		));
3373 806942d0 Stephen Beaver
3374 aef9d8fe Stephen Beaver
		$group->setHelp('Choose the amount of bandwidth for this queue');
3375
3376
		$section->add($group);
3377 806942d0 Stephen Beaver
3378 43568d7d Stephen Beaver
		$section->addInput(new Form_Input(
3379
			'buckets',
3380
			'Scheduler specific options',
3381
			'text',
3382
			$this->GetBuckets()
3383
		))->setHelp('Number of buckets available');
3384 aef9d8fe Stephen Beaver
3385 4700a731 Stephen Beaver
		$section->addInput(new Form_Input(
3386 43568d7d Stephen Beaver
			'hogs',
3387
			'',
3388
			'text',
3389
			$this->GetHogs()
3390
			))->setHelp('Bandwidth limit for hosts to not saturate link');
3391
3392
		$form->add($section);
3393 2b5caa0e Ermal Luçi
		return $form;
3394
	}
3395
3396 420b4538 Renato Botelho
	function update_altq_queue_data(&$data) {
3397 2b5caa0e Ermal Luçi
		$this->ReadConfig($data);
3398
	}
3399
3400
	function wconfig() {
3401
		$cflink =& get_reference_to_me_in_config($this->GetLink());
3402 61e047a5 Phil Davis
		if (!is_array($cflink)) {
3403 2b5caa0e Ermal Luçi
			$cflink = array();
3404 61e047a5 Phil Davis
		}
3405 2b5caa0e Ermal Luçi
		$cflink['interface'] = $this->GetInterface();
3406 f5881023 Ermal Lu?i
		$cflink['qlimit'] = trim($this->GetQlimit());
3407 61e047a5 Phil Davis
		if (empty($cflink['qlimit'])) {
3408 f5881023 Ermal Lu?i
			unset($cflink['qlimit']);
3409 61e047a5 Phil Davis
		}
3410 f5881023 Ermal Lu?i
		$cflink['priority'] = trim($this->GetQpriority());
3411 41799195 PiBa-NL
		if (!is_numeric($cflink['priority'])) {
3412 f5881023 Ermal Lu?i
			unset($cflink['priority']);
3413 61e047a5 Phil Davis
		}
3414 2b5caa0e Ermal Luçi
		$cflink['name'] = $this->GetQname();
3415 f5881023 Ermal Lu?i
		$cflink['description'] = trim($this->GetDescription());
3416 61e047a5 Phil Davis
		if (empty($cflink['description'])) {
3417 f5881023 Ermal Lu?i
			unset($cflink['description']);
3418 61e047a5 Phil Davis
		}
3419 2b5caa0e Ermal Luçi
		$cflink['bandwidth'] = $this->GetBandwidth();
3420
		$cflink['bandwidthtype'] = $this->GetBwscale();
3421
		$cflink['enabled'] = $this->GetEnabled();
3422 61e047a5 Phil Davis
		if (empty($cflink['enabled'])) {
3423 f5881023 Ermal Lu?i
			unset($cflink['enabled']);
3424 61e047a5 Phil Davis
		}
3425 f5881023 Ermal Lu?i
		$cflink['default'] = trim($this->GetDefault());
3426 61e047a5 Phil Davis
		if (empty($cflink['default'])) {
3427 f5881023 Ermal Lu?i
			unset($cflink['default']);
3428 61e047a5 Phil Davis
		}
3429 f5881023 Ermal Lu?i
		$cflink['red'] = trim($this->GetRed());
3430 61e047a5 Phil Davis
		if (empty($cflink['red'])) {
3431 f5881023 Ermal Lu?i
			unset($cflink['red']);
3432 61e047a5 Phil Davis
		}
3433 f5881023 Ermal Lu?i
		$cflink['rio'] = trim($this->GetRio());
3434 61e047a5 Phil Davis
		if (empty($cflink['rio'])) {
3435 f5881023 Ermal Lu?i
			unset($cflink['rio']);
3436 61e047a5 Phil Davis
		}
3437 f5881023 Ermal Lu?i
		$cflink['ecn'] = trim($this->GetEcn());
3438 61e047a5 Phil Davis
		if (empty($cflink['ecn'])) {
3439 f5881023 Ermal Lu?i
			unset($cflink['ecn']);
3440 61e047a5 Phil Davis
		}
3441 9f6919e6 Richard Connon
		$cflink['codel'] = trim($this->GetCodel());
3442 61e047a5 Phil Davis
		if (empty($cflink['codel'])) {
3443 9f6919e6 Richard Connon
			unset($cflink['codel']);
3444 61e047a5 Phil Davis
		}
3445 f5881023 Ermal Lu?i
		$cflink['buckets'] = trim($this->GetBuckets());
3446 61e047a5 Phil Davis
		if (empty($cflink['buckets'])) {
3447 f5881023 Ermal Lu?i
			unset($cflink['buckets']);
3448 61e047a5 Phil Davis
		}
3449 f5881023 Ermal Lu?i
		$cflink['hogs'] = trim($this->GetHogs());
3450 61e047a5 Phil Davis
		if (empty($cflink['hogs'])) {
3451 f5881023 Ermal Lu?i
			unset($cflink['hogs']);
3452 61e047a5 Phil Davis
		}
3453 2b5caa0e Ermal Luçi
	}
3454
}
3455 061f78b1 Bill Marquette
3456
3457 c25a6b6a Ermal Luçi
/*
3458 0dc7b4aa Ermal
 * dummynet(4) wrappers.
3459 c25a6b6a Ermal Luçi
 */
3460
3461
3462
/*
3463
 * List of respective objects!
3464
 */
3465 d62ba478 Ermal Luçi
$dummynet_pipe_list = array();
3466 c25a6b6a Ermal Luçi
3467
class dummynet_class {
3468 420b4538 Renato Botelho
	var $qname;
3469 f5881023 Ermal Lu?i
	var $qnumber; /* dummynet(4) uses numbers instead of names; maybe integrate with pf the same as altq does?! */
3470 420b4538 Renato Botelho
	var $qlimit;
3471
	var $description;
3472 f5881023 Ermal Lu?i
	var $qenabled;
3473
	var $link;
3474
	var $qparent; /* link to upper class so we do things easily on WF2Q+ rule creation */
3475 420b4538 Renato Botelho
	var $plr;
3476
3477
	var $buckets;
3478
	/* mask parameters */
3479
	var $mask;
3480
	var $noerror;
3481
3482
	/* Accessor functions */
3483
	function SetLink($link) {
3484
		$this->link = $link;
3485
	}
3486
	function GetLink() {
3487
		return $this->link;
3488
	}
3489 0b4e7542 Jean Cyr
	function GetMask() {
3490 61e047a5 Phil Davis
		if (!isset($this->mask["type"])) {
3491 8c50a9d8 Jean Cyr
			$this->mask["type"] = "none";
3492 61e047a5 Phil Davis
		}
3493 f5881023 Ermal Lu?i
		return $this->mask;
3494
	}
3495
	function SetMask($mask) {
3496
		$this->mask = $mask;
3497
	}
3498
	function &GetParent() {
3499
		return $this->qparent;
3500
	}
3501
	function SetParent(&$parent) {
3502
		$this->qparent = &$parent;
3503
	}
3504 420b4538 Renato Botelho
	function GetEnabled() {
3505
		return $this->qenabled;
3506
	}
3507
	function SetEnabled($value) {
3508
		$this->qenabled = $value;
3509
	}
3510 f5881023 Ermal Lu?i
	function CanHaveChildren() {
3511
		return false;
3512 420b4538 Renato Botelho
	}
3513 f5881023 Ermal Lu?i
	function CanBeDeleted() {
3514 420b4538 Renato Botelho
		return true;
3515
	}
3516
	function GetQname() {
3517
		return $this->qname;
3518
	}
3519
	function SetQname($name) {
3520
		$this->qname = trim($name);
3521
	}
3522
	function GetQlimit() {
3523
		return $this->qlimit;
3524
	}
3525
	function SetQlimit($limit) {
3526
		$this->qlimit = $limit;
3527
	}
3528
	function GetDescription() {
3529
		return $this->description;
3530
	}
3531
	function SetDescription($str) {
3532
		$this->description = trim($str);
3533
	}
3534
	function GetFirstime() {
3535
		return $this->firsttime;
3536
	}
3537
	function SetFirsttime($number) {
3538
		$this->firsttime = $number;
3539
	}
3540
	function GetBuckets() {
3541
		return $this->buckets;
3542
	}
3543
	function SetBuckets($buckets) {
3544
		$this->buckets = $buckets;
3545
	}
3546 f5881023 Ermal Lu?i
	function SetNumber($number) {
3547
		$this->qnumber = $number;
3548
	}
3549
	function GetNumber() {
3550
		return $this->qnumber;
3551
	}
3552 420b4538 Renato Botelho
	function GetPlr() {
3553
		return $this->plr;
3554
	}
3555
	function SetPlr($plr) {
3556
		$this->plr = $plr;
3557
	}
3558 c25a6b6a Ermal Luçi
3559 8c50a9d8 Jean Cyr
	function build_javascript() {
3560 2d46e1e4 Jean Cyr
		$javascript .= "<script type=\"text/javascript\">\n";
3561 8c50a9d8 Jean Cyr
		$javascript .= "//<![CDATA[\n";
3562 2d46e1e4 Jean Cyr
		$javascript .= "function enable_maskbits(enable_over) {\n";
3563
		$javascript .= "var e = document.getElementById(\"mask\");\n";
3564
		$javascript .= "if ((e.options[e.selectedIndex].text == \"none\") || enable_over) {\n";
3565 8c50a9d8 Jean Cyr
		$javascript .= "document.iform.maskbits.disabled = 1;\n";
3566
		$javascript .= "document.iform.maskbits.value = \"\";\n";
3567 853030ac Jean Cyr
		$javascript .= "document.iform.maskbitsv6.disabled = 1;\n";
3568
		$javascript .= "document.iform.maskbitsv6.value = \"\";\n";
3569 2d46e1e4 Jean Cyr
		$javascript .= "} else {\n";
3570 8c50a9d8 Jean Cyr
		$javascript .= "document.iform.maskbits.disabled = 0;\n";
3571 420b4538 Renato Botelho
		$javascript .= "document.iform.maskbitsv6.disabled = 0;\n";
3572 2d46e1e4 Jean Cyr
		$javascript .= "}}\n";
3573 8c50a9d8 Jean Cyr
		$javascript .= "//]]>\n";
3574 2d46e1e4 Jean Cyr
		$javascript .= "</script>\n";
3575 8c50a9d8 Jean Cyr
		return $javascript;
3576
	}
3577 d62ba478 Ermal Luçi
3578 f5881023 Ermal Lu?i
	function validate_input($data, &$input_errors) {
3579
		$reqdfields[] = "bandwidth";
3580 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidth");
3581 5274102e Chris Buechler
		/*$reqdfields[] = "burst";
3582
		$reqdfieldsn[] = gettext("Burst"); */
3583 f5881023 Ermal Lu?i
		$reqdfields[] = "bandwidthtype";
3584 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Bandwidthtype");
3585 6be14e38 Ermal
		$reqdfields[] = "newname";
3586 dbaf21d4 Renato Botelho
		$reqdfieldsn[] = gettext("Name");
3587 ce0117f7 Colin Fleming
3588 f5881023 Ermal Lu?i
		shaper_do_input_validation($data, $reqdfields, $reqdfieldsn, $input_errors);
3589
3590 0f0f7b2c Renato Botelho
		if ($data['plr'] && (!is_numeric($data['plr']) ||
3591 4de8f7ba Phil Davis
		    ($data['plr'] < 0) || ($data['plr'] > 1))) {
3592 cabb34e4 Chris Buechler
			$input_errors[] = gettext("Packet Loss Rate must be a value between 0 and 1.");
3593 61e047a5 Phil Davis
		}
3594 0f0f7b2c Renato Botelho
		if ($data['buckets'] && (!is_numeric($data['buckets']) ||
3595 4de8f7ba Phil Davis
		    ($data['buckets'] < 16) || ($data['buckets'] > 65535))) {
3596
			$input_errors[] = gettext("Buckets must be an integer between 16 and 65535.");
3597 61e047a5 Phil Davis
		}
3598
		if ($data['qlimit'] && (!is_numeric($data['qlimit']))) {
3599 420b4538 Renato Botelho
			$input_errors[] = gettext("Queue limit must be an integer");
3600 61e047a5 Phil Davis
		}
3601
		if (!empty($data['newname']) && !preg_match("/^[a-zA-Z0-9_-]+$/", $data['newname'])) {
3602 152ab4d0 Vinicius Coque
			$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
3603 61e047a5 Phil Davis
		}
3604
		if (!empty($data['name']) && !preg_match("/^[a-zA-Z0-9_-]+$/", $data['name'])) {
3605 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("Queue names must be alphanumeric and _ or - only.");
3606 61e047a5 Phil Davis
		}
3607
		if (isset($data['maskbits']) && ($data['maskbits'] <> "")) {
3608
			if ((!is_numeric($data['maskbits'])) || ($data['maskbits'] <= 0) || ($data['maskbits'] > 32)) {
3609 cabb34e4 Chris Buechler
				$input_errors[] = gettext("IPv4 bit mask must be blank or numeric value between 1 and 32.");
3610 61e047a5 Phil Davis
			}
3611
		}
3612
		if (isset($data['maskbitsv6']) && ($data['maskbitsv6'] <> "")) {
3613
			if ((!is_numeric($data['maskbitsv6'])) || ($data['maskbitsv6'] <= 0) || ($data['maskbitsv6'] > 128)) {
3614 cabb34e4 Chris Buechler
				$input_errors[] = gettext("IPv6 bit mask must be blank or numeric value between 1 and 128.");
3615 61e047a5 Phil Davis
			}
3616
		}
3617 2d46e1e4 Jean Cyr
	}
3618 420b4538 Renato Botelho
3619 2d46e1e4 Jean Cyr
	function build_mask_rules(&$pfq_rule) {
3620
		$mask = $this->GetMask();
3621
		if (!empty($mask['type'])) {
3622 61e047a5 Phil Davis
			if ($mask['type'] <> 'none') {
3623 2d46e1e4 Jean Cyr
				$pfq_rule .= " mask";
3624 61e047a5 Phil Davis
			}
3625 2d46e1e4 Jean Cyr
			switch ($mask['type']) {
3626 61e047a5 Phil Davis
				case 'srcaddress':
3627
					if (!empty($mask['bitsv6']) && ($mask['bitsv6'] <> "")) {
3628
						$pfq_rule .= " src-ip6 /" . $mask['bitsv6'];
3629
					} else {
3630
						$pfq_rule .= " src-ip6 /128";
3631
					}
3632
					if (!empty($mask['bits']) && ($mask['bits'] <> "")) {
3633
						$pfq_rule .= sprintf(" src-ip 0x%x", gen_subnet_mask_long($mask['bits']));
3634
					} else {
3635
						$pfq_rule .= " src-ip 0xffffffff";
3636
					}
3637
					break;
3638
				case 'dstaddress':
3639
					if (!empty($mask['bitsv6']) && ($mask['bitsv6'] <> "")) {
3640
						$pfq_rule .= " dst-ip6 /" . $mask['bitsv6'];
3641
					} else {
3642
						$pfq_rule .= " dst-ip6 /128";
3643
					}
3644
					if (!empty($mask['bits']) && ($mask['bits'] <> "")) {
3645
						$pfq_rule .= sprintf(" dst-ip 0x%x", gen_subnet_mask_long($mask['bits']));
3646
					} else {
3647
						$pfq_rule .= " dst-ip 0xffffffff";
3648
					}
3649
					break;
3650
				default:
3651
					break;
3652 2d46e1e4 Jean Cyr
			}
3653 420b4538 Renato Botelho
		}
3654 f5881023 Ermal Lu?i
	}
3655 420b4538 Renato Botelho
3656 c25a6b6a Ermal Luçi
}
3657
3658
class dnpipe_class extends dummynet_class {
3659 420b4538 Renato Botelho
	var $delay;
3660 c9ba2f8a Ermal
	var $qbandwidth = array();
3661 d62ba478 Ermal Luçi
	var $qbandwidthtype;
3662 d4f29a52 Steve Beaver
3663 254581a5 Matt Underscore
	/* Limiter queue patch */
3664
    var $ecn; // ecn 'on' or 'off'
3665
    var $aqm; // key to aqm_map
3666
    var $aqm_params = array(); // AQM params
3667
    var $scheduler;	// key to scheduler_map
3668
    var $scheduler_params = array(); // AQM params
3669
	function GetAQM() {
3670
			return $this->aqm;
3671
	}
3672
	function SetAQM($aqm) {
3673
			$this->aqm = $aqm;
3674
	}
3675
	function GetAQMParameters() {
3676
			return $this->aqm_params;
3677
	}
3678 50d4c4f2 Matt Underscore
	function GetAQMParameter($parameter) {
3679
			return $this->aqm_params[$parameter];
3680
	}
3681
	function SetAQMParameter($key, $value) {
3682
			return $this->aqm_params[$key] = $value;
3683
	}
3684 254581a5 Matt Underscore
	function SetAQMParameters($params) {
3685
			$this->aqm_params = $params;
3686
	}
3687
	function GetECN() {
3688
			return $this->ecn;
3689
	}
3690
	function SetECN($ecn) {
3691
			$this->ecn = $ecn;
3692
	}
3693
	function GetScheduler() {
3694
			return $this->scheduler;
3695
	}
3696
	function SetScheduler($scheduler) {
3697
			$this->scheduler = $scheduler;
3698
	}
3699
	function GetSchedulerParameters() {
3700
			return $this->scheduler_params;
3701
	}
3702
	function SetSchedulerParameters($params) {
3703
			$this->scheduler_params = $params;
3704
	}
3705 50d4c4f2 Matt Underscore
	function SetSchedulerParameter($key, $value) {
3706
			$this->scheduler_params[$key] = $value;
3707
	}
3708
	function GetSchedulerParameter($key) {
3709
			return $this->scheduler_params[$key];
3710
	}
3711 254581a5 Matt Underscore
	/* End limiter queue patch */
3712 c25a6b6a Ermal Luçi
3713
		/* This is here to help on form building and building rules/lists */
3714 420b4538 Renato Botelho
	var $subqueues = array();
3715 c25a6b6a Ermal Luçi
3716 70b139a3 Chris Buechler
	function CanHaveChildren() {
3717 420b4538 Renato Botelho
		return true;
3718
	}
3719 d62ba478 Ermal Luçi
	function SetDelay($delay) {
3720
		$this->delay = $delay;
3721
	}
3722
	function GetDelay() {
3723
		return $this->delay;
3724
	}
3725
	function delete_queue() {
3726
		cleanup_dnqueue_from_rules($this->GetQname());
3727 61e047a5 Phil Davis
		foreach ($this->subqueues as $q) {
3728 d62ba478 Ermal Luçi
			$q->delete_queue();
3729 61e047a5 Phil Davis
		}
3730 d62ba478 Ermal Luçi
		unset_dn_object_by_reference($this->GetLink());
3731 517b893e Renato Botelho
		@pfSense_ipfw_pipe("pipe delete " . $this->GetNumber());
3732 bcb08ced Matt Underscore
		@pfSense_ipfw_pipe("sched delete " . $this->GetNumber());
3733 420b4538 Renato Botelho
	}
3734
	function GetBandwidth() {
3735
		return $this->qbandwidth;
3736
	}
3737
	function SetBandwidth($bandwidth) {
3738
		$this->qbandwidth = $bandwidth;
3739
	}
3740 61e047a5 Phil Davis
	function GetBurst() {
3741
		return $this->qburst;
3742
	}
3743
	function SetBurst($burst) {
3744
		$this->qburst = $burst;
3745
	}
3746 c25a6b6a Ermal Luçi
3747 d62ba478 Ermal Luçi
	function &add_queue($interface, &$queue, &$path, &$input_errors) {
3748 c25a6b6a Ermal Luçi
3749 61e047a5 Phil Davis
		if (!is_array($this->subqueues)) {
3750 d62ba478 Ermal Luçi
			$this->subqueues = array();
3751 61e047a5 Phil Davis
		}
3752 ce0117f7 Colin Fleming
3753 5c4fcabc Renato Botelho
		$__tmp_q = new dnqueue_class(); $q =& $__tmp_q;
3754 d62ba478 Ermal Luçi
		$q->SetLink($path);
3755
		$q->SetEnabled("on");
3756
		$q->SetPipe($this->GetQname());
3757 ea51e9f8 Renato Botelho
		$q->SetParent($this);
3758 d62ba478 Ermal Luçi
		$q->ReadConfig($queue);
3759
		$q->validate_input($queue, $input_errors);
3760 b2383d46 Steve Beaver
3761
		if (!is_array($input_errors)) {
3762
			$input_errors = array();
3763
		}
3764
3765 00ca3fb1 Ermal
		if (count($input_errors)) {
3766 c3ebf347 NOYB
			log_error(sprintf(gettext('SHAPER: Could not create queue %1$s on interface %2$s because: %3$s'), $q->GetQname(), $interface, print_r($input_errors, true)));
3767 d62ba478 Ermal Luçi
			return $q;
3768 00ca3fb1 Ermal
		}
3769 85a236e9 Ermal
		$number = dnqueue_find_nextnumber();
3770
		$q->SetNumber($number);
3771 d62ba478 Ermal Luçi
		$this->subqueues[$q->GetQname()] = &$q;
3772 420b4538 Renato Botelho
3773 d62ba478 Ermal Luçi
		return $q;
3774
	}
3775 c25a6b6a Ermal Luçi
3776 ea51e9f8 Renato Botelho
	function &get_queue_list(&$q = null) {
3777 d62ba478 Ermal Luçi
		$qlist = array();
3778 c25a6b6a Ermal Luçi
3779 64c7753b Ermal Luçi
		$qlist[$this->GetQname()] = $this->GetNumber();
3780 d62ba478 Ermal Luçi
		if (is_array($this->subqueues)) {
3781 61e047a5 Phil Davis
			foreach ($this->subqueues as $queue) {
3782 ea51e9f8 Renato Botelho
				$queue->get_queue_list($qlist);
3783 61e047a5 Phil Davis
			}
3784 c25a6b6a Ermal Luçi
		}
3785 d62ba478 Ermal Luçi
		return $qlist;
3786
	}
3787 ce0117f7 Colin Fleming
3788 420b4538 Renato Botelho
	/*
3789
	 * Should search even its children
3790
	 */
3791
	function &find_queue($pipe, $qname) {
3792 61e047a5 Phil Davis
		if ($qname == $this->GetQname()) {
3793 420b4538 Renato Botelho
			return $this;
3794 61e047a5 Phil Davis
		}
3795 420b4538 Renato Botelho
		foreach ($this->subqueues as $q) {
3796
			$result =& $q->find_queue("", $qname);
3797 61e047a5 Phil Davis
			if ($result) {
3798 420b4538 Renato Botelho
				return $result;
3799 61e047a5 Phil Davis
			}
3800 420b4538 Renato Botelho
		}
3801
	}
3802 c25a6b6a Ermal Luçi
3803 d62ba478 Ermal Luçi
	function &find_parentqueue($pipe, $qname) {
3804
		return NULL;
3805 420b4538 Renato Botelho
	}
3806 c25a6b6a Ermal Luçi
3807 d62ba478 Ermal Luçi
	function validate_input($data, &$input_errors) {
3808
		parent::validate_input($data, $input_errors);
3809 c25a6b6a Ermal Luçi
3810 c9ba2f8a Ermal
		$schedule = 0;
3811
		$schedulenone = 0;
3812
		$entries = 0;
3813 e02ea742 Ermal
		/* XXX: Really no better way? */
3814
		for ($i = 0; $i < 2900; $i++) {
3815 c9ba2f8a Ermal
			if (!empty($data["bwsched{$i}"])) {
3816 61e047a5 Phil Davis
				if ($data["bwsched{$i}"] != "none") {
3817 c9ba2f8a Ermal
					$schedule++;
3818 61e047a5 Phil Davis
				} else {
3819 c9ba2f8a Ermal
					$schedulenone++;
3820 61e047a5 Phil Davis
				}
3821 c9ba2f8a Ermal
			}
3822
			if (!empty($data["bandwidth{$i}"])) {
3823 61e047a5 Phil Davis
				if (!is_numeric($data["bandwidth{$i}"])) {
3824 c9ba2f8a Ermal
					$input_errors[] = sprintf(gettext("Bandwidth for schedule %s must be an integer."), $data["bwsched{$i}"]);
3825 61e047a5 Phil Davis
				} else if (($data["burst{$i}"] != "") && (!is_numeric($data["burst{$i}"]))) {
3826 794195d1 Phil Davis
					$input_errors[] = sprintf(gettext("Burst for schedule %s must be an integer."), $data["bwsched{$i}"]);
3827 61e047a5 Phil Davis
				} else {
3828 c9ba2f8a Ermal
					$entries++;
3829 61e047a5 Phil Davis
				}
3830 c9ba2f8a Ermal
			}
3831
		}
3832 61e047a5 Phil Davis
		if ($schedule == 0 && $entries > 1) {
3833 c3ebf347 NOYB
			$input_errors[] = gettext("A schedule needs to be specified for every additional entry.");
3834 61e047a5 Phil Davis
		}
3835
		if ($schedulenone > 0 && $entries > 1) {
3836 c3ebf347 NOYB
			$input_errors[] = gettext("If more than one bandwidth configured all schedules need to be selected.");
3837 61e047a5 Phil Davis
		}
3838
		if ($entries == 0) {
3839 c3ebf347 NOYB
			$input_errors[] = gettext("At least one bw specification is necessary.");
3840 61e047a5 Phil Davis
		}
3841
		if ($data['delay'] && (!is_numeric($data['delay']))) {
3842 dbaf21d4 Renato Botelho
			$input_errors[] = gettext("Delay must be an integer.");
3843 61e047a5 Phil Davis
		}
3844 d4f29a52 Steve Beaver
3845 254581a5 Matt Underscore
		/* Limiter patch */
3846
		$selectedScheduler = getSchedulers()[$data['sched']];
3847 202411c3 no
		if (!$selectedScheduler) {
3848
			$input_errors[] = gettext("Selected scheduler not recognized.");
3849
		}
3850 254581a5 Matt Underscore
		$selectedAqm = getAQMs()[$data['aqm']];
3851 cd3cde52 jim-p
		if (!empty($data['aqm']) && !$selectedAqm) {
3852 202411c3 no
			$input_errors[] = gettext("Selected AQM not recognized.");
3853
		}
3854 254581a5 Matt Underscore
		if ($data['ecn'] && $data['ecn'] == 'on' && !$selectedScheduler["ecn"] && !$selectedAqm["ecn"]) {
3855
			$input_errors[] = gettext("Explicit Congestion Notification is selected, but neither " . $selectedAqm["name"] . " nor " . $selectedScheduler["name"] . " support it.");
3856
		}
3857
		/* End limiter patch */
3858 dbaf21d4 Renato Botelho
	}
3859 c25a6b6a Ermal Luçi
3860 d62ba478 Ermal Luçi
	function ReadConfig(&$q) {
3861 1cbe86f0 Ermal
		if (!empty($q['name']) && !empty($q['newname']) && $q['name'] != $q['newname']) {
3862
			$this->SetQname($q['newname']);
3863
		} else if (!empty($q['newname'])) {
3864
			$this->SetQname($q['newname']);
3865
		} else {
3866
			$this->SetQname($q['name']);
3867
		}
3868 d62ba478 Ermal Luçi
		$this->SetNumber($q['number']);
3869 c9ba2f8a Ermal
3870
		if (!empty($_POST)) {
3871
			$bandwidth = array();
3872 e02ea742 Ermal
			/* XXX: Really no better way? */
3873
			for ($i = 0; $i < 2900; $i++) {
3874 420b4538 Renato Botelho
				if (isset($q["bandwidth{$i}"]) && $q["bandwidth{$i}"] <> "") {
3875 c9ba2f8a Ermal
					$bw = array();
3876
					$bw['bw'] = $q["bandwidth{$i}"];
3877 4981f881 Ermal
					$bw['burst'] = $q["burst{$i}"];
3878 61e047a5 Phil Davis
					if (isset($q["bwtype{$i}"]) && $q["bwtype{$i}"]) {
3879 c9ba2f8a Ermal
						$bw['bwscale'] = $q["bwtype{$i}"];
3880 61e047a5 Phil Davis
					}
3881
					if (isset($q["bwsched{$i}"]) && $q["bwsched{$i}"]) {
3882 c9ba2f8a Ermal
						$bw['bwsched'] = $q["bwsched{$i}"];
3883 61e047a5 Phil Davis
					}
3884 c9ba2f8a Ermal
					$bandwidth[] = $bw;
3885
				}
3886
			}
3887
			$this->SetBandwidth($bandwidth);
3888 d62ba478 Ermal Luçi
		}
3889 420b4538 Renato Botelho
3890 4981f881 Ermal
		if (is_array($q['bandwidth']) && is_array($q['bandwidth']['item'])) {
3891 c9ba2f8a Ermal
			$this->SetBandwidth($q['bandwidth']['item']);
3892 4981f881 Ermal
			$this->SetBurst($q['burst']['item']);
3893
		}
3894 420b4538 Renato Botelho
3895 61e047a5 Phil Davis
		if (isset($q['qlimit']) && $q['qlimit'] <> "") {
3896 420b4538 Renato Botelho
			$this->SetQlimit($q['qlimit']);
3897 61e047a5 Phil Davis
		} else {
3898 420b4538 Renato Botelho
			$this->SetQlimit("");
3899 61e047a5 Phil Davis
		}
3900
		if (isset($q['mask']) && $q['mask'] <> "") {
3901 0b4e7542 Jean Cyr
			$masktype = $q['mask'];
3902 61e047a5 Phil Davis
		} else {
3903 0b4e7542 Jean Cyr
			$masktype = "";
3904 61e047a5 Phil Davis
		}
3905
		if (isset($q['maskbits']) && $q['maskbits'] <> "") {
3906 0b4e7542 Jean Cyr
			$maskbits = $q['maskbits'];
3907 61e047a5 Phil Davis
		} else {
3908 0b4e7542 Jean Cyr
			$maskbits = "";
3909 61e047a5 Phil Davis
		}
3910
		if (isset($q['maskbitsv6']) && $q['maskbitsv6'] <> "") {
3911 2d46e1e4 Jean Cyr
			$maskbitsv6 = $q['maskbitsv6'];
3912 61e047a5 Phil Davis
		} else {
3913 2d46e1e4 Jean Cyr
			$maskbitsv6 = "";
3914 61e047a5 Phil Davis
		}
3915 2d46e1e4 Jean Cyr
		$this->SetMask(array("type" => $masktype, "bits" => $maskbits, "bitsv6" => $maskbitsv6));
3916 61e047a5 Phil Davis
		if (isset($q['buckets']) && $q['buckets'] <> "") {
3917 420b4538 Renato Botelho
			$this->SetBuckets($q['buckets']);
3918 61e047a5 Phil Davis
		} else {
3919 420b4538 Renato Botelho
			$this->SetBuckets("");
3920 61e047a5 Phil Davis
		}
3921
		if (isset($q['plr']) && $q['plr'] <> "") {
3922 420b4538 Renato Botelho
			$this->SetPlr($q['plr']);
3923 61e047a5 Phil Davis
		} else {
3924 420b4538 Renato Botelho
			$this->SetPlr("");
3925 61e047a5 Phil Davis
		}
3926
		if (isset($q['delay']) && $q['delay'] <> "") {
3927 420b4538 Renato Botelho
			$this->SetDelay($q['delay']);
3928 61e047a5 Phil Davis
		} else {
3929 c2461a56 Ermal
			$this->SetDelay(0);
3930 61e047a5 Phil Davis
		}
3931
		if (isset($q['description']) && $q['description'] <> "") {
3932 d62ba478 Ermal Luçi
			$this->SetDescription($q['description']);
3933 61e047a5 Phil Davis
		} else {
3934 c2461a56 Ermal
			$this->SetDescription("");
3935 61e047a5 Phil Davis
		}
3936 d62ba478 Ermal Luçi
		$this->SetEnabled($q['enabled']);
3937 d4f29a52 Steve Beaver
3938 254581a5 Matt Underscore
		/* Limiter patch */
3939
		if (isset($q['aqm']) && $q['aqm'] <> "") {
3940
				$this->SetAQM($q['aqm']);
3941
		} else {
3942
				$this->SetAQM('droptail');
3943
		}
3944
		// parse AQM arguments
3945
		$aqm_map = getAQMs();
3946
		$selectedParameters = $aqm_map[$this->getAQM()]["parameters"];
3947 5ee16aa6 no
		if (is_array($selectedParameters)) {
3948
			foreach ($selectedParameters as $key => $value) {
3949
				$config_key = 'param_' . $this->GetAQM() . '_' . $key;
3950
				if (isset($q[$config_key]) && $q[$config_key] <> "") {
3951
					$this->SetAQMParameter($key, $q[$config_key]);
3952
				} else {
3953
					$this->SetAQMParameter($key, $value["default"]);
3954
				}
3955 254581a5 Matt Underscore
			}
3956
		}
3957 d4f29a52 Steve Beaver
3958 254581a5 Matt Underscore
		if (isset($q['sched']) && $q['sched'] <> "") {
3959
				$this->SetScheduler($q['sched']);
3960
		} else {
3961 5ee16aa6 no
				$this->SetScheduler('fifo');
3962 254581a5 Matt Underscore
		}
3963
		$scheduler_map = getSchedulers();
3964
		$selectedParameters = $scheduler_map[$this->getScheduler()]["parameters"];
3965 5ee16aa6 no
		if (is_array($selectedParameters)) {
3966
			foreach ($selectedParameters as $key => $value) {
3967
				$config_key = 'param_' . $this->GetScheduler() . '_' . $key;
3968
				if (isset($q[$config_key]) && $q[$config_key] <> "") {
3969
					$this->SetSchedulerParameter($key, $q[$config_key]);
3970
				} else {
3971
					$this->SetSchedulerParameter($key, $value["default"]);
3972
				}
3973 254581a5 Matt Underscore
			}
3974
		}
3975 d4f29a52 Steve Beaver
3976 254581a5 Matt Underscore
		// ecn flag
3977
		$this->SetECN($q['ecn']);
3978
		/* End limiter patch */
3979 420b4538 Renato Botelho
	}
3980 c25a6b6a Ermal Luçi
3981 d62ba478 Ermal Luçi
	function build_tree() {
3982 1072b933 jim-p
		$tree = " <li><a href=\"firewall_shaper_vinterface.php?pipe=" . htmlspecialchars($this->GetQname()) ."&amp;queue=".htmlspecialchars($this->GetQname()) ."&amp;action=show\">";
3983
		$tree .= htmlspecialchars($this->GetQname()) . "</a>";
3984 d62ba478 Ermal Luçi
		if (is_array($this->subqueues)) {
3985
			$tree .= "<ul>";
3986 4de8f7ba Phil Davis
			foreach ($this->subqueues as $q) {
3987 d62ba478 Ermal Luçi
				$tree .= $q->build_tree();
3988 420b4538 Renato Botelho
			}
3989 d62ba478 Ermal Luçi
			$tree .= "</ul>";
3990 c25a6b6a Ermal Luçi
		}
3991 d62ba478 Ermal Luçi
		$tree .= "</li>";
3992 ce0117f7 Colin Fleming
3993 d62ba478 Ermal Luçi
		return $tree;
3994
	}
3995 c25a6b6a Ermal Luçi
3996 420b4538 Renato Botelho
	function build_rules() {
3997 c9ba2f8a Ermal
		global $config, $time_based_rules;
3998
3999 61e047a5 Phil Davis
		if ($this->GetEnabled() == "") {
4000 8cb1c6e3 Ermal Luçi
			return;
4001 61e047a5 Phil Davis
		}
4002 8cb1c6e3 Ermal Luçi
4003 e7ccf2a5 Ermal
		$pfq_rule = "\npipe ". $this->GetNumber() . " config ";
4004 fa29a6f0 Ermal
		$found = false;
4005 c9ba2f8a Ermal
		$bandwidth = $this->GetBandwidth();
4006
		if (is_array($bandwidth)) {
4007
			foreach ($bandwidth as $bw) {
4008 fbfed5ba Ermal
				if ($bw['bwsched'] != "none") {
4009 c9ba2f8a Ermal
					$time_based_rules = true;
4010 2ed21904 Ermal
					if (is_array($config['schedules']) && is_array($config['schedules']['schedule'])) {
4011 d96b96b9 Ermal
						foreach ($config['schedules']['schedule'] as $schedule) {
4012
							if ($bw['bwsched'] == $schedule['name']) {
4013
								if (filter_get_time_based_rule_status($schedule)) {
4014 7c4e07c6 jim-p
									/* pipe throughputs must always be an integer, enforce that restriction again here. */
4015
									$pfq_rule .= " bw ".round(trim($bw['bw']),0).$bw['bwscale'];
4016 61e047a5 Phil Davis
									if (is_numeric($bw['burst']) && ($bw['burst'] > 0)) {
4017 c90d37f3 jim-p
										$pfq_rule .= " burst ".trim($bw['burst']);
4018 61e047a5 Phil Davis
									}
4019 fa29a6f0 Ermal
									$found = true;
4020 d96b96b9 Ermal
									break;
4021
								}
4022 c9ba2f8a Ermal
							}
4023
						}
4024 0b3a76ca Ermal
					} else {
4025 fa29a6f0 Ermal
						$pfq_rule .= " bw 0";
4026 02593e37 Ermal Luçi
						$found = true;
4027 0b3a76ca Ermal
						break;
4028
					}
4029 ec091c89 Ermal
				} else {
4030 7c4e07c6 jim-p
					/* pipe throughputs must always be an integer, enforce that restriction again here. */
4031
					$pfq_rule .= " bw ".round(trim($bw['bw']), 0).$bw['bwscale'];
4032 61e047a5 Phil Davis
					if (is_numeric($bw['burst']) && ($bw['burst'] > 0)) {
4033 c90d37f3 jim-p
						$pfq_rule .= " burst ".trim($bw['burst']);
4034 61e047a5 Phil Davis
					}
4035 02593e37 Ermal Luçi
					$found = true;
4036 ec091c89 Ermal
					break;
4037
				}
4038 c9ba2f8a Ermal
			}
4039 61e047a5 Phil Davis
			if ($found == false) {
4040 fa29a6f0 Ermal
				$pfq_rule .= " bw 0";
4041 61e047a5 Phil Davis
			}
4042
		} else {
4043 ec091c89 Ermal
			$pfq_rule .= " bw 0";
4044 61e047a5 Phil Davis
		}
4045 c9ba2f8a Ermal
4046 61e047a5 Phil Davis
		if ($this->GetQlimit()) {
4047 4981f881 Ermal
			$pfq_rule .= " queue " . $this->GetQlimit();
4048 61e047a5 Phil Davis
		}
4049
		if ($this->GetPlr()) {
4050 d62ba478 Ermal Luçi
			$pfq_rule .= " plr " . $this->GetPlr();
4051 61e047a5 Phil Davis
		}
4052
		if ($this->GetBuckets()) {
4053 d62ba478 Ermal Luçi
			$pfq_rule .= " buckets " . $this->GetBuckets();
4054 61e047a5 Phil Davis
		}
4055
		if ($this->GetDelay()) {
4056 d62ba478 Ermal Luçi
			$pfq_rule .= " delay " . $this->GetDelay();
4057 61e047a5 Phil Davis
		}
4058 2d46e1e4 Jean Cyr
		$this->build_mask_rules($pfq_rule);
4059 d62ba478 Ermal Luçi
4060 254581a5 Matt Underscore
		/* Limiter patch */
4061
		$selectedAQM = getAQMs()[$this->getAQM()];
4062
		if ($selectedAQM) {
4063 50d4c4f2 Matt Underscore
			$pfq_rule .= " " . FormatParameters($selectedAQM["parameter_format"], $this->GetAQMParameters());
4064 254581a5 Matt Underscore
			if ($selectedAQM["ecn"]) {
4065
				if ($this->getECN() == 'on') {
4066
					$pfq_rule .= ' ecn';
4067
				} else {
4068
					$pfq_rule .= ' noecn';
4069
				}
4070
			}
4071
		}
4072
		$selectedScheduler = getSchedulers()[$this->getScheduler()];
4073
		if ($selectedScheduler) {
4074 50d4c4f2 Matt Underscore
			$pfq_rule .= "\nsched ". $this->GetNumber() . " config pipe " . $this->GetNumber() . " " . FormatParameters($selectedScheduler["parameter_format"], $this->GetSchedulerParameters());
4075 254581a5 Matt Underscore
			if ($selectedScheduler["ecn"]) {
4076
				if ($this->getECN() == 'on') {
4077
					$pfq_rule .= ' ecn';
4078
				} else {
4079
					$pfq_rule .= ' noecn';
4080
				}
4081
			}
4082
		}
4083 f7f33eb3 Ermal
		$pfq_rule .= "\n";
4084 254581a5 Matt Underscore
		/* End patch */
4085 d4f29a52 Steve Beaver
4086 f5130e64 Ermal
		if (!empty($this->subqueues) && count($this->subqueues) > 0) {
4087 61e047a5 Phil Davis
			foreach ($this->subqueues as $q) {
4088
				$pfq_rule .= $q->build_rules();
4089
			}
4090 f5130e64 Ermal
		}
4091 d4f29a52 Steve Beaver
4092 d62ba478 Ermal Luçi
		$pfq_rule .= " \n";
4093 c25a6b6a Ermal Luçi
4094 d62ba478 Ermal Luçi
		return $pfq_rule;
4095 420b4538 Renato Botelho
	}
4096 c25a6b6a Ermal Luçi
4097 420b4538 Renato Botelho
	function update_dn_data(&$data) {
4098 d62ba478 Ermal Luçi
		$this->ReadConfig($data);
4099
	}
4100 c25a6b6a Ermal Luçi
4101 c9ba2f8a Ermal
	function build_javascript() {
4102
		global $g, $config;
4103
4104 8c50a9d8 Jean Cyr
		$javasr = parent::build_javascript();
4105 420b4538 Renato Botelho
4106 c9ba2f8a Ermal
		//build list of schedules
4107
		$schedules = "<option value='none'>none</option>";
4108
		if (is_array($config['schedules']) && is_array($config['schedules']['schedule'])) {
4109
			foreach ($config['schedules']['schedule'] as $schedule) {
4110 61e047a5 Phil Davis
				if ($schedule['name'] <> "") {
4111 c9ba2f8a Ermal
					$schedules .= "<option value='{$schedule['name']}'>{$schedule['name']}</option>";
4112 61e047a5 Phil Davis
				}
4113 c9ba2f8a Ermal
			}
4114
		}
4115
		$bwopt = "";
4116 61e047a5 Phil Davis
		foreach (array("Kb" => "Kbit/s", "Mb" => "Mbit/s", "Gb" => "Gbit/s", "b" => "Bit/s") as $bwidx => $bw) {
4117 c9ba2f8a Ermal
			$bwopt .= "<option value='{$bwidx}'>{$bw}</option>";
4118 61e047a5 Phil Davis
		}
4119 c9ba2f8a Ermal
4120 8c50a9d8 Jean Cyr
		$javasr .= <<<EOD
4121 7da5315d Colin Fleming
<script type='text/javascript'>
4122 0fa05f45 Colin Fleming
//<![CDATA[
4123 c9ba2f8a Ermal
var addBwRowTo = (function() {
4124 3b6dedf3 Stephen Beaver
4125 c9ba2f8a Ermal
	return (function (tableId) {
4126 3b6dedf3 Stephen Beaver
4127 d2466d40 Stephen Beaver
	var table = document.getElementById(tableId);
4128
	var totalrows = table.rows.length -1;
4129 3b6dedf3 Stephen Beaver
4130 d2466d40 Stephen Beaver
	var row = table.insertRow(totalrows + 1);
4131
	var cell1 = row.insertCell(0);
4132
	var cell2 = row.insertCell(1);
4133
	var cell3 = row.insertCell(2);
4134
	var cell4 = row.insertCell(3);
4135
4136
	cell1.innerHTML = "<input type='hidden' value='" + totalrows +"' name='bandwidth_row-" + totalrows + "' /><input type='text' class='form-control' name='bandwidth" + totalrows + "' id='bandwidth" + totalrows + "' />";
4137
	cell2.innerHTML = "<input type='hidden' value='" + totalrows +"' name='bwtype_row-" + totalrows + "' /><select class='form-control' name='bwtype" + totalrows + "'>{$bwopt}</select>";
4138
	cell3.innerHTML = "<input type='hidden' value='" + totalrows +"' name='bwsched_row-" + totalrows + "' /><select class='form-control' name='bwsched" + totalrows + "'>{$schedules}</select>";
4139 27d6a45b jim-p
	cell4.innerHTML = '<a class="btn btn-warning" onclick="removeBwRow(this); return false;" href="#"><i class="fa fa-trash icon-embed-btn"></i>Delete</a>';
4140 d2466d40 Stephen Beaver
4141 c9ba2f8a Ermal
	});
4142
})();
4143
4144
function removeBwRow(el) {
4145 d2466d40 Stephen Beaver
	var d = el.parentNode.parentNode.rowIndex;
4146 3b6dedf3 Stephen Beaver
	document.getElementById('maintable').deleteRow(d);
4147 c9ba2f8a Ermal
}
4148 0f5bd6f8 Stephen Jones
4149
function ceil_func(el){
4150
	el.value = Math.ceil(el.value);
4151
4152
}
4153 0fa05f45 Colin Fleming
//]]>
4154 c9ba2f8a Ermal
</script>
4155
4156
EOD;
4157
4158 420b4538 Renato Botelho
		return $javasr;
4159 c9ba2f8a Ermal
	}
4160
4161 d2466d40 Stephen Beaver
	// Compose a table of bandwidths that can then be inserted into the form using a Form_StaticText
4162 df67ba6a Stephen Beaver
	// The table has been "Bootstrapped" to match the web design while maintaining compatibility with
4163 d2466d40 Stephen Beaver
	// with the javascript in this class
4164
	function build_bwtable() {
4165
		global $config;
4166 3b6dedf3 Stephen Beaver
4167 d2466d40 Stephen Beaver
		$bandwidth = $this->GetBandwidth();
4168
				//build list of schedules
4169
		$schedules = array();
4170
		$schedules[] = "none";//leave none to leave rule enabled all the time
4171
		if (is_array($config['schedules']) && is_array($config['schedules']['schedule'])) {
4172
			foreach ($config['schedules']['schedule'] as $schedule) {
4173 df67ba6a Stephen Beaver
				if ($schedule['name'] != "") {
4174 d2466d40 Stephen Beaver
					$schedules[] = $schedule['name'];
4175
				}
4176
			}
4177
		}
4178 3b6dedf3 Stephen Beaver
4179 df67ba6a Stephen Beaver
		$form = '<div class="table-responsive">';
4180
		$form .= '<table id="maintable" class="table table-hover table-striped">';
4181 d2466d40 Stephen Beaver
		$form .= "<thead><tr>";
4182 df67ba6a Stephen Beaver
		$form .= "<th>Bandwidth</th>";
4183 d2466d40 Stephen Beaver
		//$form .= "<td width='35%'><div id='fifthcolumn'>Burst</div></td>";
4184 df67ba6a Stephen Beaver
		$form .= "<th>Bw type</th>";
4185
		$form .= "<th>Schedule</th>";
4186
		$form .= "<th></th>";
4187 d2466d40 Stephen Beaver
		$form .= "</tr></thead>";
4188
		$form .= "<tbody>";
4189 3b6dedf3 Stephen Beaver
4190 df67ba6a Stephen Beaver
		// If there are no bandwidths defined, make a blank one for convenience
4191 4e322e2c Phil Davis
		if (empty($bandwidth)) {
4192 df67ba6a Stephen Beaver
			$bandwidth = array(0 => array('bw' => '', 'bwscale' => 'Kb', 'bwsched' => 'none'));
4193 4e322e2c Phil Davis
		}
4194 b37b4034 Phil Davis
4195 d2466d40 Stephen Beaver
		if (is_array($bandwidth)) {
4196
			foreach ($bandwidth as $bwidx => $bw) {
4197 df67ba6a Stephen Beaver
				$form .= '<tr>';
4198
				$form .= '<td class="col-xs-4">';
4199 0f5bd6f8 Stephen Jones
				$form .= "<input class='form-control' onchange=\"ceil_func(this)\" type=\"number\" id=\"bandwidth{$bwidx}\" name=\"bandwidth{$bwidx}\" value=\"" . ceil($bw['bw']) ."\" min=\"0\" step=\"1\"/>";
4200 d2466d40 Stephen Beaver
				//$form .= "</td><td width='20%'>";
4201
				//$form .= "<input class='formfld unknown' size='10' type=\"text\" id=\"burst{$bwidx}\" name=\"burst{$bwidx}\" value=\"{$bw['burst']}\" />";
4202 df67ba6a Stephen Beaver
				$form .= "</td>";
4203
				$form .= '<td class="col-xs-4">';
4204 d2466d40 Stephen Beaver
				$form .= "<select id=\"bwtype{$bwidx}\" name=\"bwtype{$bwidx}\" class=\"form-control\">";
4205 b37b4034 Phil Davis
4206 f95cdbea Chris Buechler
				foreach (array("Kb" => "Kbit/s", "Mb" => "Mbit/s", "b" => "Bit/s") as $bwsidx => $bwscale) {
4207 d2466d40 Stephen Beaver
					$form .= "<option value=\"{$bwsidx}\"";
4208 b37b4034 Phil Davis
4209 d2466d40 Stephen Beaver
					if ($bw['bwscale'] == $bwsidx) {
4210 c4b60a9a Colin Fleming
						$form .= " selected";
4211 d2466d40 Stephen Beaver
					}
4212 b37b4034 Phil Davis
4213 d2466d40 Stephen Beaver
					$form .= ">{$bwscale}</option>";
4214
				}
4215 b37b4034 Phil Davis
4216 d2466d40 Stephen Beaver
				$form .= "</select>";
4217 df67ba6a Stephen Beaver
				$form .= "</td>";
4218
				$form .= '<td class="col-xs-4">';
4219 d2466d40 Stephen Beaver
				$form .= "<select id=\"bwsched{$bwidx}\" name=\"bwsched{$bwidx}\" class=\"form-control\">";
4220 b37b4034 Phil Davis
4221 d2466d40 Stephen Beaver
				foreach ($schedules as $schd) {
4222
					$selected = "";
4223
					if ($bw['bwsched'] == $schd) {
4224 c4b60a9a Colin Fleming
						$selected = "selected";
4225 d2466d40 Stephen Beaver
					}
4226 b37b4034 Phil Davis
4227 d2466d40 Stephen Beaver
					$form .= "<option value='{$schd}' {$selected}>{$schd}</option>";
4228
				}
4229 b37b4034 Phil Davis
4230 d2466d40 Stephen Beaver
				$form .= "</select>";
4231 df67ba6a Stephen Beaver
				$form .= "</td>";
4232
				$form .= '<td>';
4233 27d6a45b jim-p
				$form .= '<a class="btn btn-warning" onclick="removeBwRow(this); return false;"><i class="fa fa-trash icon-embed-btn"></i>' . gettext('Delete') . '</a>';
4234 d2466d40 Stephen Beaver
				$form .= "</td></tr>";
4235
			}
4236
		}
4237 df67ba6a Stephen Beaver
		$form .= "</tbody></table></div><br />";
4238 3b6dedf3 Stephen Beaver
4239 b9bc38c1 NOYB
		$form .= '<a class="btn btn-sm btn-success" onclick="javascript:addBwRowTo(\'maintable\'); return false;" >';
4240 27d6a45b jim-p
		$form .= '<i class="fa fa-plus icon-embed-btn"></i>';
4241
		$form .= gettext("Add Schedule") . "</a>";
4242 3b6dedf3 Stephen Beaver
4243 d2466d40 Stephen Beaver
		return($form);
4244
	}
4245 3b6dedf3 Stephen Beaver
4246 7903dd5e Stephen Beaver
	function build_form() {
4247
		global $g, $config, $pipe, $action, $qname;
4248 c9ba2f8a Ermal
4249
		//build list of schedules
4250
		$schedules = array();
4251
		$schedules[] = "none";//leave none to leave rule enabled all the time
4252
		if (is_array($config['schedules']) && is_array($config['schedules']['schedule'])) {
4253
			foreach ($config['schedules']['schedule'] as $schedule) {
4254 61e047a5 Phil Davis
				if ($schedule['name'] <> "") {
4255 c9ba2f8a Ermal
					$schedules[] = $schedule['name'];
4256 61e047a5 Phil Davis
				}
4257 c9ba2f8a Ermal
			}
4258
		}
4259
4260 7903dd5e Stephen Beaver
4261
		$sform = new Form();
4262 5605a0c4 Stephen Beaver
		$sform->setAction("firewall_shaper.php");
4263 7903dd5e Stephen Beaver
4264
		$section = new Form_Section('Limiters');
4265
4266
		$section->addInput(new Form_Checkbox(
4267
			'enabled',
4268
			'Enable',
4269
			'Enable limiter and its children',
4270
			($this->GetEnabled() == "on"),
4271
			'on'
4272
		));
4273
4274
		$section->addInput(new Form_Input(
4275
			'newname',
4276 40dcb4b6 Phil Davis
			'*Name',
4277 7903dd5e Stephen Beaver
			'text',
4278
			$this->GetQname()
4279
		));
4280 d2466d40 Stephen Beaver
4281 7903dd5e Stephen Beaver
		$section->addInput(new Form_Input(
4282
			'name',
4283
			null,
4284
			'hidden',
4285
			$this->GetQname()
4286
		));
4287 d2466d40 Stephen Beaver
4288 85a236e9 Ermal
		if ($this->GetNumber() > 0) {
4289 7903dd5e Stephen Beaver
			$section->addInput(new Form_Input(
4290
				'number',
4291
				null,
4292
				'hidden',
4293
				$this->GetNumber()
4294
			));
4295
		}
4296 d2466d40 Stephen Beaver
4297
		$bandwidth = $this->GetBandwidth();
4298 7903dd5e Stephen Beaver
4299 c9ba2f8a Ermal
		if (is_array($bandwidth)) {
4300 df67ba6a Stephen Beaver
				$section->addInput(new Form_StaticText(
4301 7903dd5e Stephen Beaver
				'Bandwidth',
4302 d2466d40 Stephen Beaver
				$this->build_bwtable()
4303 3b6dedf3 Stephen Beaver
			));
4304 7903dd5e Stephen Beaver
		}
4305
4306 0b4e7542 Jean Cyr
		$mask = $this->GetMask();
4307 d2466d40 Stephen Beaver
4308 7903dd5e Stephen Beaver
		$section->addInput(new Form_Select(
4309 23f4c08f Stephen Beaver
			'mask',
4310 7903dd5e Stephen Beaver
			'Mask',
4311
			$mask['type'],
4312 b50d30c3 Stephen Beaver
			array('none' => gettext('None'), 'srcaddress' => gettext('Source addresses'), 'dstaddress' => gettext('Destination addresses'))
4313 7903dd5e Stephen Beaver
		))->setHelp('If "source" or "destination" slots is chosen a dynamic pipe with the bandwidth, delay, packet loss ' .
4314
					'and queue size given above will be created for each source/destination IP address encountered, respectively. ' .
4315
					'This makes it possible to easily specify bandwidth limits per host.');
4316 d2466d40 Stephen Beaver
4317 7903dd5e Stephen Beaver
		$group = new Form_Group(null);
4318 d2466d40 Stephen Beaver
4319 7903dd5e Stephen Beaver
		$group->add(new Form_Select(
4320
			'maskbits',
4321
			null,
4322
			$mask['bits'],
4323
			array_combine(range(32, 1, -1), range(32, 1, -1))
4324 08dbe1c5 Phil Davis
		))->setHelp('IPv4 mask bits%1$s%2$s', '<br />', '255.255.255.255/?');
4325 d2466d40 Stephen Beaver
4326 7903dd5e Stephen Beaver
		$group->add(new Form_Select(
4327
			'maskbitsv6',
4328
			null,
4329
			$mask['bitsv6'],
4330
			array_combine(range(128, 1, -1), range(128, 1, -1))
4331 08dbe1c5 Phil Davis
		))->setHelp('IPv6 mask bits%1$s%2$s', '<br />', '<span style="font-family:consolas">ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/?</span>');
4332 d2466d40 Stephen Beaver
4333 7903dd5e Stephen Beaver
		$section->add($group);
4334 c25a6b6a Ermal Luçi
4335 7903dd5e Stephen Beaver
		$section->addInput(new Form_Input(
4336
			'description',
4337
			'Description',
4338
			'text',
4339
			$this->GetDescription()
4340 530e4707 NOYB
		))->setHelp('A description may be entered here for administrative reference (not parsed).');
4341 d2466d40 Stephen Beaver
4342 7903dd5e Stephen Beaver
		$sform->add($section);
4343 d2466d40 Stephen Beaver
4344 254581a5 Matt Underscore
		/* Begin limiter patch */
4345
		$aqm_map = getAQMs();
4346
		$scheduler_map = getSchedulers();
4347 d4f29a52 Steve Beaver
4348 254581a5 Matt Underscore
		$section = new Form_Section('Queue');
4349
		$section->addInput(new Form_Select(
4350
				'aqm',
4351
				'Queue Management Algorithm',
4352
				$this->GetAQM(),
4353
				array_map_assoc(function ($k, $v) {
4354
					return [$k, $v["name"]];
4355
				}, $aqm_map)
4356
		))->setHelp('Active queue management (AQM) is the intelligent drop of network packets inside the limiter, ' .
4357
						'when it becomes full or gets close to becoming full, with the goal of reducing ' .
4358
						'network congestion.');
4359 d4f29a52 Steve Beaver
4360 254581a5 Matt Underscore
		$section->addInput(new Form_StaticText(
4361
			'',
4362 50d4c4f2 Matt Underscore
			build_queue_params($aqm_map, $this->GetAQM(), $this->GetAQMParameters(), "aqm")
4363 254581a5 Matt Underscore
		))->setHelp('Specifies the queue management algorithm parameters.');
4364 d4f29a52 Steve Beaver
4365 254581a5 Matt Underscore
		$section->addInput(new Form_Select(
4366
				'sched',
4367
				'Scheduler',
4368
				$this->GetScheduler(),
4369
				array_map_assoc(function ($k, $v) {
4370
					return [$k, $v["name"]];
4371
				}, $scheduler_map)
4372
		))->setHelp('The scheduler manages the sequence of network packets in the limiter\'s queue.');
4373
4374
		$section->addInput(new Form_StaticText(
4375
			'',
4376 50d4c4f2 Matt Underscore
			build_queue_params($scheduler_map, $this->GetScheduler(), $this->GetSchedulerParameters(), "sched")
4377 254581a5 Matt Underscore
		))->setHelp('Specifies the scheduler parameters.');
4378 d4f29a52 Steve Beaver
4379 254581a5 Matt Underscore
		$section->addInput(new Form_Input(
4380
				'qlimit',
4381
				'Queue length',
4382
				'number',
4383
				$this->GetQlimit()
4384
		))->setHelp('Specifies the length of the limiter\'s queue, which the scheduler and AQM are responsible for. ' .
4385
			'This field may be left empty.');
4386 d4f29a52 Steve Beaver
4387 254581a5 Matt Underscore
		$section->addInput(new Form_Checkbox(
4388
			'ecn',
4389
			'ECN',
4390
			'Enable Explicit Congestion Notification (ECN)',
4391
			($this->GetECN() == "on"),
4392
			'on'
4393
		))->setHelp('ECN sets a reserved TCP flag when the queue is nearing or exceeding capacity. Not all AQMs or schedulers support this.');
4394
4395
		$sform->add($section);
4396
		/* End limiter patch */
4397 d4f29a52 Steve Beaver
4398 5f88f964 k-paulius
		$section = new Form_Section('Advanced Options');
4399 d2466d40 Stephen Beaver
4400 7903dd5e Stephen Beaver
		$section->addInput(new Form_Input(
4401
			'delay',
4402 df67ba6a Stephen Beaver
			'Delay (ms)',
4403
			'text',
4404
			$this->GetDelay() > 0 ? $this->GetDelay():null
4405 c3ebf347 NOYB
		))->setHelp('In most cases, zero (0) should specified here (or leave the field empty).');
4406 d2466d40 Stephen Beaver
4407 7903dd5e Stephen Beaver
		$section->addInput(new Form_Input(
4408
			'plr',
4409
			'Packet Loss Rate',
4410
			'number',
4411
			$this->GetPlr(),
4412
			['step' => '0.001', 'min' => '0.000']
4413 530e4707 NOYB
		))->setHelp('In most cases, zero (0) should be specified here (or leave the field empty). ' .
4414 c3ebf347 NOYB
					'A value of 0.001 means one packet in 1000 gets dropped.');
4415 d2466d40 Stephen Beaver
4416 7903dd5e Stephen Beaver
		$section->addInput(new Form_Input(
4417
			'buckets',
4418
			'Bucket size (slots)',
4419
			'number',
4420
			$this->GetBuckets()
4421 c3ebf347 NOYB
		))->setHelp('In most cases, this field should be left empty. It increases the hash size set.');
4422 ce0117f7 Colin Fleming
4423 7903dd5e Stephen Beaver
		$sform->add($section);
4424 d2466d40 Stephen Beaver
4425 7903dd5e Stephen Beaver
		return($sform);
4426 c25a6b6a Ermal Luçi
		}
4427
4428 d62ba478 Ermal Luçi
	function wconfig() {
4429
		$cflink =& get_dn_reference_to_me_in_config($this->GetLink());
4430 61e047a5 Phil Davis
		if (!is_array($cflink)) {
4431 420b4538 Renato Botelho
			$cflink = array();
4432 61e047a5 Phil Davis
		}
4433 d62ba478 Ermal Luçi
		$cflink['name'] = $this->GetQname();
4434
		$cflink['number'] = $this->GetNumber();
4435 420b4538 Renato Botelho
		$cflink['qlimit'] = $this->GetQlimit();
4436
		$cflink['plr'] = $this->GetPlr();
4437
		$cflink['description'] = $this->GetDescription();
4438
4439 c9ba2f8a Ermal
		$bandwidth = $this->GetBandwidth();
4440
		if (is_array($bandwidth)) {
4441
			$cflink['bandwidth'] = array();
4442
			$cflink['bandwidth']['item'] = array();
4443 61e047a5 Phil Davis
			foreach ($bandwidth as $bwidx => $bw) {
4444 c9ba2f8a Ermal
				$cflink['bandwidth']['item'][] = $bw;
4445 61e047a5 Phil Davis
			}
4446 c9ba2f8a Ermal
		}
4447
4448 d62ba478 Ermal Luçi
		$cflink['enabled'] = $this->GetEnabled();
4449
		$cflink['buckets'] = $this->GetBuckets();
4450 0b4e7542 Jean Cyr
		$mask = $this->GetMask();
4451
		$cflink['mask'] = $mask['type'];
4452
		$cflink['maskbits'] = $mask['bits'];
4453 420b4538 Renato Botelho
		$cflink['maskbitsv6'] = $mask['bitsv6'];
4454 d62ba478 Ermal Luçi
		$cflink['delay'] = $this->GetDelay();
4455 d4f29a52 Steve Beaver
4456 254581a5 Matt Underscore
		/* Limiter queue patch */
4457
		$cflink['sched'] = $this->GetScheduler();
4458
		$scheduler_map = getSchedulers();
4459
		$selectedParameters = $scheduler_map[$this->getScheduler()]["parameters"];
4460
		foreach ($selectedParameters as $key => $value) {
4461
			$config_key = 'param_' . $this->GetScheduler() . '_' . $key;
4462 50d4c4f2 Matt Underscore
			$cflink[$config_key] = $this->GetSchedulerParameter($key);
4463 254581a5 Matt Underscore
		}
4464
		$cflink['aqm'] = $this->GetAQM();
4465
		$aqm_map = GetAQMs();
4466
		$selectedParameters = $aqm_map[$this->getAQM()]["parameters"];
4467
		foreach ($selectedParameters as $key => $value) {
4468
			$config_key = 'param_' . $this->GetAQM() . '_' . $key;
4469 50d4c4f2 Matt Underscore
			$cflink[$config_key] = $this->GetAQMParameter($key);
4470 254581a5 Matt Underscore
		}
4471
		$cflink['ecn'] = $this->GetECN();
4472
		/* End limiter queue patch */
4473 d62ba478 Ermal Luçi
	}
4474 c25a6b6a Ermal Luçi
4475
}
4476
4477
class dnqueue_class extends dummynet_class {
4478 420b4538 Renato Botelho
	var $pipeparent;
4479
	var $weight;
4480 254581a5 Matt Underscore
	/* Limiter queue patch */
4481
    var $ecn; // ecn 'on' or 'off'
4482
    var $aqm; // key to aqm_map
4483
    var $aqm_params = array(); // AQM params
4484
	function GetAQM() {
4485
			return $this->aqm;
4486
	}
4487
	function SetAQM($aqm) {
4488
			$this->aqm = $aqm;
4489
	}
4490
	function GetAQMParameters() {
4491
			return $this->aqm_params;
4492
	}
4493 50d4c4f2 Matt Underscore
	function GetAQMParameter($parameter) {
4494
			return $this->aqm_params[$parameter];
4495
	}
4496
	function SetAQMParameter($key, $value) {
4497
			return $this->aqm_params[$key] = $value;
4498
	}
4499 254581a5 Matt Underscore
	function SetAQMParameters($params) {
4500
			$this->aqm_params = $params;
4501
	}
4502
	function GetECN() {
4503
			return $this->ecn;
4504
	}
4505
	function SetECN($ecn) {
4506
			$this->ecn = $ecn;
4507
	}
4508
	/* End limiter queue patch */
4509 420b4538 Renato Botelho
4510
	function GetWeight() {
4511
		return $this->weight;
4512
	}
4513
	function SetWeight($weight) {
4514
		$this->weight = $weight;
4515
	}
4516 d62ba478 Ermal Luçi
	function GetPipe() {
4517
		return $this->pipeparent;
4518
	}
4519
	function SetPipe($pipe) {
4520
		$this->pipeparent = $pipe;
4521
	}
4522 c25a6b6a Ermal Luçi
4523 d62ba478 Ermal Luçi
	/* Just a stub in case we ever try to call this from the frontend. */
4524 61e047a5 Phil Davis
	function &add_queue($interface, &$queue, &$path, &$input_errors) {
4525
		return;
4526
	}
4527 c25a6b6a Ermal Luçi
4528 d62ba478 Ermal Luçi
	function delete_queue() {
4529
		cleanup_dnqueue_from_rules($this->GetQname());
4530
		unset_dn_object_by_reference($this->GetLink());
4531 517b893e Renato Botelho
		@pfSense_ipfw_pipe("queue delete " . $this->GetNumber());
4532 420b4538 Renato Botelho
	}
4533 c25a6b6a Ermal Luçi
4534 d62ba478 Ermal Luçi
	function validate_input($data, &$input_errors) {
4535
		parent::validate_input($data, $input_errors);
4536 d4f29a52 Steve Beaver
4537
4538 254581a5 Matt Underscore
		/* Limiter patch */
4539
		$selectedAqm = getAQMs()[$data['aqm']];
4540 cd3cde52 jim-p
		if (!empty($data['aqm']) && !$selectedAqm) {
4541 202411c3 no
			$input_errors[] = gettext("Selected AQM not recognized.");
4542
		}
4543 254581a5 Matt Underscore
		if ($data['ecn'] && $data['ecn'] == 'on' && !$selectedAqm["ecn"]) {
4544
			$input_errors[] = gettext("Explicit Congestion Notification is selected, but " . $selectedAqm["name"] . " does not support it.");
4545
		}
4546
		/* End limiter patch */
4547 c25a6b6a Ermal Luçi
4548 d62ba478 Ermal Luçi
		if ($data['weight'] && ((!is_numeric($data['weight'])) ||
4549 4de8f7ba Phil Davis
		    ($data['weight'] < 1 && $data['weight'] > 100))) {
4550 420b4538 Renato Botelho
			$input_errors[] = gettext("Weight must be an integer between 1 and 100.");
4551 61e047a5 Phil Davis
		}
4552 d62ba478 Ermal Luçi
	}
4553 c25a6b6a Ermal Luçi
4554 420b4538 Renato Botelho
	/*
4555
	 * Should search even its children
4556
	 */
4557
	function &find_queue($pipe, $qname) {
4558 61e047a5 Phil Davis
		if ($qname == $this->GetQname()) {
4559 420b4538 Renato Botelho
			return $this;
4560 61e047a5 Phil Davis
		} else {
4561 d62ba478 Ermal Luçi
			return NULL;
4562 61e047a5 Phil Davis
		}
4563 420b4538 Renato Botelho
	}
4564 c25a6b6a Ermal Luçi
4565 d62ba478 Ermal Luçi
	function &find_parentqueue($pipe, $qname) {
4566
		return $this->qparent;
4567 420b4538 Renato Botelho
	}
4568 c25a6b6a Ermal Luçi
4569 420b4538 Renato Botelho
	function &get_queue_list(&$qlist) {
4570 61e047a5 Phil Davis
		if ($this->GetEnabled() == "") {
4571 146f0fad Ermal
			return;
4572 61e047a5 Phil Davis
		}
4573 420b4538 Renato Botelho
		$qlist[$this->GetQname()] = "?" .$this->GetNumber();
4574
	}
4575 c25a6b6a Ermal Luçi
4576 d62ba478 Ermal Luçi
	function ReadConfig(&$q) {
4577 1cbe86f0 Ermal
		if (!empty($q['name']) && !empty($q['newname']) && $q['name'] != $q['newname']) {
4578
			$this->SetQname($q['newname']);
4579
		} else if (!empty($q['newname'])) {
4580
			$this->SetQname($q['newname']);
4581
		} else {
4582
			$this->SetQname($q['name']);
4583
		}
4584 d62ba478 Ermal Luçi
		$this->SetNumber($q['number']);
4585 61e047a5 Phil Davis
		if (isset($q['qlimit']) && $q['qlimit'] <> "") {
4586 420b4538 Renato Botelho
			$this->SetQlimit($q['qlimit']);
4587 61e047a5 Phil Davis
		} else {
4588 420b4538 Renato Botelho
			$this->SetQlimit("");
4589 61e047a5 Phil Davis
		}
4590
		if (isset($q['mask']) && $q['mask'] <> "") {
4591 0b4e7542 Jean Cyr
			$masktype = $q['mask'];
4592 61e047a5 Phil Davis
		} else {
4593 0b4e7542 Jean Cyr
			$masktype = "";
4594 61e047a5 Phil Davis
		}
4595
		if (isset($q['maskbits']) && $q['maskbits'] <> "") {
4596 0b4e7542 Jean Cyr
			$maskbits = $q['maskbits'];
4597 61e047a5 Phil Davis
		} else {
4598 0b4e7542 Jean Cyr
			$maskbits = "";
4599 61e047a5 Phil Davis
		}
4600
		if (isset($q['maskbitsv6']) && $q['maskbitsv6'] <> "") {
4601 2d46e1e4 Jean Cyr
			$maskbitsv6 = $q['maskbitsv6'];
4602 61e047a5 Phil Davis
		} else {
4603 2d46e1e4 Jean Cyr
			$maskbitsv6 = "";
4604 61e047a5 Phil Davis
		}
4605 2d46e1e4 Jean Cyr
		$this->SetMask(array("type" => $masktype, "bits" => $maskbits, "bitsv6" => $maskbitsv6));
4606 61e047a5 Phil Davis
		if (isset($q['buckets']) && $q['buckets'] <> "") {
4607 dda9c67f Renato Botelho
			$this->SetBuckets($q['buckets']);
4608 61e047a5 Phil Davis
		} else {
4609 dda9c67f Renato Botelho
			$this->SetBuckets("");
4610 61e047a5 Phil Davis
		}
4611
		if (isset($q['plr']) && $q['plr'] <> "") {
4612 dda9c67f Renato Botelho
			$this->SetPlr($q['plr']);
4613 61e047a5 Phil Davis
		} else {
4614 dda9c67f Renato Botelho
			$this->SetPlr("");
4615 61e047a5 Phil Davis
		}
4616
		if (isset($q['weight']) && $q['weight'] <> "") {
4617 420b4538 Renato Botelho
			$this->SetWeight($q['weight']);
4618 61e047a5 Phil Davis
		} else {
4619 420b4538 Renato Botelho
			$this->SetWeight("");
4620 61e047a5 Phil Davis
		}
4621
		if (isset($q['description']) && $q['description'] <> "") {
4622 d62ba478 Ermal Luçi
			$this->SetDescription($q['description']);
4623 61e047a5 Phil Davis
		} else {
4624 daacb818 Ermal
			$this->SetDescription("");
4625 61e047a5 Phil Davis
		}
4626 d62ba478 Ermal Luçi
		$this->SetEnabled($q['enabled']);
4627 d4f29a52 Steve Beaver
4628 254581a5 Matt Underscore
		/* Limiter patch */
4629
		if (isset($q['aqm']) && $q['aqm'] <> "") {
4630
				$this->SetAQM($q['aqm']);
4631
		} else {
4632
				$this->SetAQM('droptail');
4633
		}
4634
		// parse AQM arguments
4635
		$aqm_map = getAQMs();
4636
		$selectedParameters = $aqm_map[$this->getAQM()]["parameters"];
4637
		foreach ($selectedParameters as $key => $value) {
4638
			$config_key = 'param_' . $this->GetAQM() . '_' . $key;
4639
			if (isset($q[$config_key]) && $q[$config_key] <> "") {
4640 50d4c4f2 Matt Underscore
				$this->SetAQMParameter($key, $q[$config_key]);
4641 254581a5 Matt Underscore
			} else {
4642 50d4c4f2 Matt Underscore
				$this->SetAQMParameter($key, $value["default"]);
4643 254581a5 Matt Underscore
			}
4644
		}
4645 d4f29a52 Steve Beaver
4646 254581a5 Matt Underscore
		// ecn flag
4647
		$this->SetECN($q['ecn']);
4648
		/* End limiter patch */
4649 420b4538 Renato Botelho
	}
4650 c25a6b6a Ermal Luçi
4651 d62ba478 Ermal Luçi
	function build_tree() {
4652
		$parent =& $this->GetParent();
4653 1072b933 jim-p
		$tree = " <li><a href=\"firewall_shaper_vinterface.php?pipe=" . htmlspecialchars($parent->GetQname()) ."&amp;queue=" . htmlspecialchars($this->GetQname()) ."&amp;action=show\">";
4654
		$tree .= htmlspecialchars($this->GetQname()) . "</a>";
4655 d62ba478 Ermal Luçi
		$tree .= "</li>";
4656 ce0117f7 Colin Fleming
4657 d62ba478 Ermal Luçi
		return $tree;
4658
	}
4659 c25a6b6a Ermal Luçi
4660 420b4538 Renato Botelho
	function build_rules() {
4661 61e047a5 Phil Davis
		if ($this->GetEnabled() == "") {
4662 420b4538 Renato Botelho
			return;
4663 61e047a5 Phil Davis
		}
4664 8cb1c6e3 Ermal Luçi
4665 d62ba478 Ermal Luçi
		$parent =& $this->GetParent();
4666 420b4538 Renato Botelho
		$pfq_rule = "queue ". $this->GetNumber() . " config pipe " . $parent->GetNumber();
4667 61e047a5 Phil Davis
		if ($this->GetQlimit()) {
4668 420b4538 Renato Botelho
			$pfq_rule .= " queue " . $this->GetQlimit();
4669 61e047a5 Phil Davis
		}
4670
		if ($this->GetWeight()) {
4671 d62ba478 Ermal Luçi
			$pfq_rule .= " weight " . $this->GetWeight();
4672 61e047a5 Phil Davis
		}
4673
		if ($this->GetBuckets()) {
4674 d62ba478 Ermal Luçi
			$pfq_rule .= " buckets " . $this->GetBuckets();
4675 61e047a5 Phil Davis
		}
4676 2d46e1e4 Jean Cyr
		$this->build_mask_rules($pfq_rule);
4677 d4f29a52 Steve Beaver
4678 254581a5 Matt Underscore
		/* Limiter patch */
4679
		$selectedAQM = getAQMs()[$this->getAQM()];
4680
		if ($selectedAQM) {
4681 50d4c4f2 Matt Underscore
			$pfq_rule .= " " . FormatParameters($selectedAQM["parameter_format"], $this->GetAQMParameters());
4682 254581a5 Matt Underscore
			if ($selectedAQM["ecn"]) {
4683
				if ($this->getECN() == 'on') {
4684
					$pfq_rule .= ' ecn';
4685
				} else {
4686
					$pfq_rule .= ' noecn';
4687
				}
4688
			}
4689
		}
4690
		/* End patch */
4691 d4f29a52 Steve Beaver
4692 9b10a6ec Ermal
		$pfq_rule .= "\n";
4693 c25a6b6a Ermal Luçi
4694 d62ba478 Ermal Luçi
		return $pfq_rule;
4695
	}
4696
4697 420b4538 Renato Botelho
	function build_javascript() {
4698 8c50a9d8 Jean Cyr
		return parent::build_javascript();
4699
	}
4700
4701 d2466d40 Stephen Beaver
	function build_form() {
4702
		global $g, $config, $pipe, $action, $qname;
4703
4704
		//build list of schedules
4705
		$schedules = array();
4706
		$schedules[] = "none";//leave none to leave rule enabled all the time
4707
		if (is_array($config['schedules']) && is_array($config['schedules']['schedule'])) {
4708
			foreach ($config['schedules']['schedule'] as $schedule) {
4709
				if ($schedule['name'] <> "") {
4710
					$schedules[] = $schedule['name'];
4711
				}
4712
			}
4713
		}
4714
4715
4716
		$sform = new Form();
4717 5605a0c4 Stephen Beaver
		$sform->setAction("firewall_shaper.php");
4718 d2466d40 Stephen Beaver
		$section = new Form_Section('Limiters');
4719
4720
		$section->addInput(new Form_Checkbox(
4721
			'enabled',
4722
			'Enable',
4723
			'Enable this queue',
4724
			($this->GetEnabled() == "on"),
4725
			'on'
4726
		));
4727
4728
		$section->addInput(new Form_Input(
4729
			'newname',
4730 40dcb4b6 Phil Davis
			'*Name',
4731 d2466d40 Stephen Beaver
			'text',
4732
			$this->GetQname()
4733
		));
4734
4735
		$section->addInput(new Form_Input(
4736
			'name',
4737
			null,
4738
			'hidden',
4739
			$this->GetQname()
4740
		));
4741
4742 85a236e9 Ermal
		if ($this->GetNumber() > 0) {
4743 d2466d40 Stephen Beaver
			$section->addInput(new Form_Input(
4744
				'number',
4745
				null,
4746
				'hidden',
4747
				$this->GetNumber()
4748
			));
4749
		}
4750
4751 0b4e7542 Jean Cyr
		$mask = $this->GetMask();
4752 c25a6b6a Ermal Luçi
4753 d2466d40 Stephen Beaver
		$section->addInput(new Form_Select(
4754 49882789 Stephen Beaver
			'mask',
4755 d2466d40 Stephen Beaver
			'Mask',
4756
			$mask['type'],
4757 b50d30c3 Stephen Beaver
			array('none' => gettext('None'), 'srcaddress' => gettext('Source addresses'), 'dstaddress' => gettext('Destination addresses'))
4758 d2466d40 Stephen Beaver
		))->setHelp('If "source" or "destination" slots is chosen a dynamic pipe with the bandwidth, delay, packet loss ' .
4759
					'and queue size given above will be created for each source/destination IP address encountered, respectively. ' .
4760
					'This makes it possible to easily specify bandwidth limits per host.');
4761
4762
		$group = new Form_Group(null);
4763
4764
		$group->add(new Form_Select(
4765
			'maskbits',
4766
			null,
4767
			$mask['bits'],
4768
			array_combine(range(32, 1, -1), range(32, 1, -1))
4769 08dbe1c5 Phil Davis
		))->setHelp('IPv4 mask bits%1$s%2$s', '<br />', '255.255.255.255/?');
4770 d2466d40 Stephen Beaver
4771
		$group->add(new Form_Select(
4772
			'maskbitsv6',
4773
			null,
4774
			$mask['bitsv6'],
4775
			array_combine(range(128, 1, -1), range(128, 1, -1))
4776 08dbe1c5 Phil Davis
		))->setHelp('IPv6 mask bits%1$s%2$s', '<br />', '<span style="font-family:consolas">ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/?</span>');
4777 d2466d40 Stephen Beaver
4778
		$section->add($group);
4779
4780
		$section->addInput(new Form_Input(
4781
			'description',
4782
			'Description',
4783
			'text',
4784
			$this->GetDescription()
4785 530e4707 NOYB
		))->setHelp('A description may be entered here for administrative reference (not parsed).');
4786 d2466d40 Stephen Beaver
4787
		$sform->add($section);
4788 d4f29a52 Steve Beaver
4789 254581a5 Matt Underscore
		/* Begin limiter patch */
4790
		$aqm_map = getAQMs();
4791 d4f29a52 Steve Beaver
4792 254581a5 Matt Underscore
		$section = new Form_Section('Queue');
4793
		$section->addInput(new Form_Select(
4794
				'aqm',
4795
				'Queue Management Algorithm',
4796
				$this->GetAQM(),
4797
				array_map_assoc(function ($k, $v) {
4798
					return [$k, $v["name"]];
4799
				}, $aqm_map)
4800
		))->setHelp('Active queue management (AQM) is the intelligent drop of network packets inside this limiter\'s queue, ' .
4801
						'when it becomes full or gets close to becoming full, with the goal of reducing ' .
4802
						'network congestion.');
4803 d4f29a52 Steve Beaver
4804 254581a5 Matt Underscore
		$section->addInput(new Form_StaticText(
4805
			'',
4806 50d4c4f2 Matt Underscore
			build_queue_params($aqm_map, $this->GetAQM(), $this->GetAQMParameters(), "aqm")
4807 254581a5 Matt Underscore
		))->setHelp('Specifies the queue management algorithm parameters.');
4808 d4f29a52 Steve Beaver
4809 254581a5 Matt Underscore
		$section->addInput(new Form_Input(
4810
				'qlimit',
4811
				'Queue length',
4812
				'number',
4813
				$this->GetQlimit()
4814
		))->setHelp('Specifies the length of this queue, which the AQM is responsible for.  This field may be left empty.');
4815 d4f29a52 Steve Beaver
4816 254581a5 Matt Underscore
		$section->addInput(new Form_Checkbox(
4817
			'ecn',
4818
			'ECN',
4819
			'Enable Explicit Congestion Notification (ECN)',
4820
			($this->GetECN() == "on"),
4821
			'on'
4822
		))->setHelp('ECN sets a reserved TCP flag when the queue is nearing or exceeding capacity. Not all AQMs or schedulers support this.');
4823
4824
		$sform->add($section);
4825
		/* End limiter patch */
4826 d2466d40 Stephen Beaver
4827 5f88f964 k-paulius
		$section = new Form_Section('Advanced Options');
4828 d2466d40 Stephen Beaver
4829
		$section->addInput(new Form_Input(
4830
			'weight',
4831
			'Weight',
4832
			'number',
4833
			$this->GetWeight(),
4834
			['min' => '1', 'max' => '100']
4835 3b6dedf3 Stephen Beaver
		))->setHelp('For queues under the same parent this specifies the share that a queue gets(values range from 1 to 100),' .
4836 530e4707 NOYB
					' it can be left blank otherwise.');
4837 ce0117f7 Colin Fleming
4838 d2466d40 Stephen Beaver
		$section->addInput(new Form_Input(
4839
			'plr',
4840
			'Packet Loss Rate',
4841
			'number',
4842
			$this->GetPlr(),
4843
			['step' => '0.001', 'min' => '0.000']
4844 530e4707 NOYB
		))->setHelp('In most cases, zero (0) should be specified here (or leave the field empty). ' .
4845 d2466d40 Stephen Beaver
					'A value of 0.001 means one packet in 1000 gets dropped');
4846 d4f29a52 Steve Beaver
4847 d2466d40 Stephen Beaver
		$section->addInput(new Form_Input(
4848
			'buckets',
4849
			'Bucket size (slots)',
4850
			'number',
4851
			$this->GetBuckets()
4852 530e4707 NOYB
		))->setHelp('In most cases, this field should be left empty. It increases the hash size set');
4853 d2466d40 Stephen Beaver
4854 3b6dedf3 Stephen Beaver
		$section->addInput(new Form_Input(
4855
			'pipe',
4856
			null,
4857
			'hidden',
4858
			$this->GetPipe()
4859
		));
4860
4861 d2466d40 Stephen Beaver
		$sform->add($section);
4862
4863
		return($sform);
4864 d62ba478 Ermal Luçi
	}
4865 c25a6b6a Ermal Luçi
4866 420b4538 Renato Botelho
	function update_dn_data(&$data) {
4867 d62ba478 Ermal Luçi
		$this->ReadConfig($data);
4868
	}
4869 c25a6b6a Ermal Luçi
4870 d62ba478 Ermal Luçi
	function wconfig() {
4871
		$cflink =& get_dn_reference_to_me_in_config($this->GetLink());
4872 61e047a5 Phil Davis
		if (!is_array($cflink)) {
4873 420b4538 Renato Botelho
			$cflink = array();
4874 61e047a5 Phil Davis
		}
4875 d62ba478 Ermal Luçi
		$cflink['name'] = $this->GetQname();
4876
		$cflink['number'] = $this->GetNumber();
4877 420b4538 Renato Botelho
		$cflink['qlimit'] = $this->GetQlimit();
4878
		$cflink['description'] = $this->GetDescription();
4879 d62ba478 Ermal Luçi
		$cflink['weight'] = $this->GetWeight();
4880
		$cflink['enabled'] = $this->GetEnabled();
4881
		$cflink['buckets'] = $this->GetBuckets();
4882 0b4e7542 Jean Cyr
		$mask = $this->GetMask();
4883
		$cflink['mask'] = $mask['type'];
4884
		$cflink['maskbits'] = $mask['bits'];
4885 420b4538 Renato Botelho
		$cflink['maskbitsv6'] = $mask['bitsv6'];
4886 d4f29a52 Steve Beaver
4887 254581a5 Matt Underscore
		/* Limiter queue patch */
4888
		$cflink['aqm'] = $this->GetAQM();
4889
		$aqm_map = GetAQMs();
4890
		$selectedParameters = $aqm_map[$this->getAQM()]["parameters"];
4891
		foreach ($selectedParameters as $key => $value) {
4892
			$config_key = 'param_' . $this->GetAQM() . '_' . $key;
4893 50d4c4f2 Matt Underscore
			$cflink[$config_key] = $this->GetAQMParameter($key);
4894 254581a5 Matt Underscore
		}
4895
		$cflink['ecn'] = $this->GetECN();
4896
		/* End limiter queue patch */
4897 d62ba478 Ermal Luçi
	}
4898 c25a6b6a Ermal Luçi
}
4899
4900 daee46a5 Helder Pereira
function get_dummynet_name_list() {
4901 ce0117f7 Colin Fleming
4902 daee46a5 Helder Pereira
	$dn_name_list =& get_unique_dnqueue_list();
4903
	$dn_name = array();
4904 61e047a5 Phil Davis
	if (is_array($dn_name_list)) {
4905
		foreach ($dn_name_list as $key => $value) {
4906 daee46a5 Helder Pereira
			$dn_name[] = $key;
4907 61e047a5 Phil Davis
		}
4908
	}
4909 ce0117f7 Colin Fleming
4910 daee46a5 Helder Pereira
	return $dn_name;
4911 ce0117f7 Colin Fleming
4912 daee46a5 Helder Pereira
}
4913
4914
function get_altq_name_list() {
4915
	$altq_name_list =& get_unique_queue_list();
4916
	$altq_name = array();
4917 61e047a5 Phil Davis
	if (is_array($altq_name_list)) {
4918
		foreach ($altq_name_list as $key => $aqobj) {
4919 daee46a5 Helder Pereira
			$altq_name[] = $key;
4920 61e047a5 Phil Davis
		}
4921
	}
4922 ce0117f7 Colin Fleming
4923 daee46a5 Helder Pereira
	return $altq_name;
4924 f63d5b66 Helder Pereira
}
4925 c25a6b6a Ermal Luçi
4926 197bfe96 Ermal Luçi
/*
4927 61e047a5 Phil Davis
 * XXX: TODO Make a class shaper to hide all these functions
4928 197bfe96 Ermal Luçi
 * from the global namespace.
4929
 */
4930
4931 420b4538 Renato Botelho
/*
4932
 * This is a layer violation but for now there is no way
4933 61e047a5 Phil Davis
 * I can find to properly do this with PHP.
4934 197bfe96 Ermal Luçi
 */
4935
function altq_get_default_queue($interface) {
4936
	global $altq_list_queues;
4937 061f78b1 Bill Marquette
4938 197bfe96 Ermal Luçi
	$altq_tmp = $altq_list_queues[$interface];
4939 61e047a5 Phil Davis
	if ($altq_tmp) {
4940 420b4538 Renato Botelho
		return $altq_tmp->GetDefaultQueuePresent();
4941 61e047a5 Phil Davis
	} else {
4942 acebc1ec Ermal
		return false;
4943 61e047a5 Phil Davis
	}
4944 197bfe96 Ermal Luçi
}
4945 061f78b1 Bill Marquette
4946 21a0464c Ermal Luçi
function altq_check_default_queues() {
4947
	global $altq_list_queues;
4948
4949
	$count = 0;
4950
	if (is_array($altq_list_queues)) {
4951 61e047a5 Phil Davis
		foreach ($altq_list_queues as $altq) {
4952
			if ($altq->GetDefaultQueuePresent()) {
4953 21a0464c Ermal Luçi
				$count++;
4954 61e047a5 Phil Davis
			}
4955 21a0464c Ermal Luçi
		}
4956
	}
4957 61e047a5 Phil Davis
	else {
4958
		$count++;
4959
	}
4960 ce0117f7 Colin Fleming
4961 21a0464c Ermal Luçi
	return 0;
4962
}
4963
4964
function &get_unique_queue_list() {
4965
	global $altq_list_queues;
4966 ce0117f7 Colin Fleming
4967 21a0464c Ermal Luçi
	$qlist = array();
4968
	if (is_array($altq_list_queues)) {
4969
		foreach ($altq_list_queues as $altq) {
4970 61e047a5 Phil Davis
			if ($altq->GetEnabled() == "") {
4971 146f0fad Ermal
				continue;
4972 61e047a5 Phil Davis
			}
4973 21a0464c Ermal Luçi
			$tmplist =& $altq->get_queue_list();
4974 146f0fad Ermal
			foreach ($tmplist as $qname => $link) {
4975 61e047a5 Phil Davis
				if ($link->GetEnabled() <> "") {
4976 420b4538 Renato Botelho
					$qlist[$qname] = $link;
4977 61e047a5 Phil Davis
				}
4978 146f0fad Ermal
			}
4979 21a0464c Ermal Luçi
		}
4980
	}
4981
	return $qlist;
4982
}
4983
4984 309ffde9 Ermal Luçi
function &get_unique_dnqueue_list() {
4985 c25a6b6a Ermal Luçi
	global $dummynet_pipe_list;
4986 ce0117f7 Colin Fleming
4987 c25a6b6a Ermal Luçi
	$qlist = array();
4988
	if (is_array($dummynet_pipe_list)) {
4989
		foreach ($dummynet_pipe_list as $dn) {
4990 61e047a5 Phil Davis
			if ($dn->GetEnabled() == "") {
4991 146f0fad Ermal
				continue;
4992 61e047a5 Phil Davis
			}
4993 c25a6b6a Ermal Luçi
			$tmplist =& $dn->get_queue_list();
4994 146f0fad Ermal
			foreach ($tmplist as $qname => $link) {
4995 420b4538 Renato Botelho
				$qlist[$qname] = $link;
4996 146f0fad Ermal
			}
4997 c25a6b6a Ermal Luçi
		}
4998
	}
4999
	return $qlist;
5000
}
5001
5002 197bfe96 Ermal Luçi
function ref_on_altq_queue_list($parent, $qname) {
5003 61e047a5 Phil Davis
	if (isset($GLOBALS['queue_list'][$qname])) {
5004 197bfe96 Ermal Luçi
		$GLOBALS['queue_list'][$qname]++;
5005 61e047a5 Phil Davis
	} else {
5006 197bfe96 Ermal Luçi
		$GLOBALS['queue_list'][$qname] = 1;
5007 61e047a5 Phil Davis
	}
5008 061f78b1 Bill Marquette
5009 197bfe96 Ermal Luçi
	unref_on_altq_queue_list($parent);
5010
}
5011 061f78b1 Bill Marquette
5012 197bfe96 Ermal Luçi
function unref_on_altq_queue_list($qname) {
5013
	$GLOBALS['queue_list'][$qname]--;
5014 61e047a5 Phil Davis
	if ($GLOBALS['queue_list'][$qname] <= 1) {
5015 420b4538 Renato Botelho
		unset($GLOBALS['queue_list'][$qname]);
5016 61e047a5 Phil Davis
	}
5017 197bfe96 Ermal Luçi
}
5018 061f78b1 Bill Marquette
5019 197bfe96 Ermal Luçi
function read_altq_config() {
5020
	global $altq_list_queues, $config;
5021
	$path = array();
5022 ce0117f7 Colin Fleming
5023 c6c398c6 jim-p
	init_config_arr(array('shaper', 'queue'));
5024 197bfe96 Ermal Luçi
	$a_int = &$config['shaper']['queue'];
5025
5026
	$altq_list_queues = array();
5027 ce0117f7 Colin Fleming
5028 61e047a5 Phil Davis
	if (!is_array($config['shaper']['queue'])) {
5029 197bfe96 Ermal Luçi
		return;
5030 61e047a5 Phil Davis
	}
5031 197bfe96 Ermal Luçi
5032
	foreach ($a_int as $key => $conf) {
5033 520ad1a4 Ermal
		$int = $conf['interface'];
5034 5ffeceb6 Stephen Jones
		$root = new altq_root_queue();
5035 520ad1a4 Ermal
		$root->SetInterface($int);
5036 5ffeceb6 Stephen Jones
		$altq_list_queues[$root->GetInterface()] = $root;
5037 520ad1a4 Ermal
		$root->ReadConfig($conf);
5038 197bfe96 Ermal Luçi
		array_push($path, $key);
5039
		$root->SetLink($path);
5040
		if (is_array($conf['queue'])) {
5041
			foreach ($conf['queue'] as $key1 => $q) {
5042
				array_push($path, $key1);
5043 420b4538 Renato Botelho
				/*
5044
				 * XXX: we completely ignore errors here but anyway we must have
5045 92125c97 Ermal Luçi
				 *	checked them before so no harm should be come from this.
5046
				 */
5047 ea51e9f8 Renato Botelho
				$root->add_queue($root->GetInterface(), $q, $path, $input_errors);
5048 197bfe96 Ermal Luçi
				array_pop($path);
5049 420b4538 Renato Botelho
			}
5050 520ad1a4 Ermal
		}
5051 197bfe96 Ermal Luçi
		array_pop($path);
5052
	}
5053
}
5054 0a33f73e Scott Ullrich
5055 c25a6b6a Ermal Luçi
function read_dummynet_config() {
5056
	global $dummynet_pipe_list, $config;
5057
	$path = array();
5058 d62ba478 Ermal Luçi
5059 c6c398c6 jim-p
	init_config_arr(array('dnshaper', 'queue'));
5060 c25a6b6a Ermal Luçi
	$a_int = &$config['dnshaper']['queue'];
5061 2f038c0b Scott Ullrich
5062 c25a6b6a Ermal Luçi
	$dummynet_pipe_list = array();
5063 ce0117f7 Colin Fleming
5064 c6c398c6 jim-p
	if (!count($config['dnshaper']['queue'])) {
5065 c25a6b6a Ermal Luçi
		return;
5066 61e047a5 Phil Davis
	}
5067 c25a6b6a Ermal Luçi
5068
	foreach ($a_int as $key => $conf) {
5069 61e047a5 Phil Davis
		if (empty($conf['name'])) {
5070 420b4538 Renato Botelho
			continue; /* XXX: grrrrrr at php */
5071 61e047a5 Phil Davis
		}
5072 8f2cc9bd Stephen Jones
		$root = new dnpipe_class();
5073 d62ba478 Ermal Luçi
		$root->ReadConfig($conf);
5074 8f2cc9bd Stephen Jones
		$dummynet_pipe_list[$root->GetQname()] = $root;
5075 d62ba478 Ermal Luçi
		array_push($path, $key);
5076
		$root->SetLink($path);
5077
		if (is_array($conf['queue'])) {
5078
			foreach ($conf['queue'] as $key1 => $q) {
5079
				array_push($path, $key1);
5080 420b4538 Renato Botelho
				/*
5081
				 * XXX: we completely ignore errors here but anyway we must have
5082 d62ba478 Ermal Luçi
				 *	checked them before so no harm should be come from this.
5083 420b4538 Renato Botelho
				 */
5084 ea51e9f8 Renato Botelho
				$root->add_queue($root->GetQname(), $q, $path, $input_errors);
5085 c25a6b6a Ermal Luçi
				array_pop($path);
5086 420b4538 Renato Botelho
			}
5087 d62ba478 Ermal Luçi
		}
5088
		array_pop($path);
5089 c25a6b6a Ermal Luçi
	}
5090
}
5091 0a33f73e Scott Ullrich
5092 197bfe96 Ermal Luçi
function get_interface_list_to_show() {
5093
	global $altq_list_queues, $config;
5094 057399e4 Ermal Luçi
	global $shaperIFlist;
5095
5096 197bfe96 Ermal Luçi
	$tree = "";
5097 057399e4 Ermal Luçi
	foreach ($shaperIFlist as $shif => $shDescr) {
5098
		if ($altq_list_queues[$shif]) {
5099 197bfe96 Ermal Luçi
			continue;
5100 4de8f7ba Phil Davis
		} else {
5101 61e047a5 Phil Davis
			if (!is_altq_capable(get_real_interface($shif))) {
5102 0b033d22 Ermal Luçi
				continue;
5103 61e047a5 Phil Davis
			}
5104 7da5315d Colin Fleming
			$tree .= " <li><a href=\"firewall_shaper.php?interface=".$shif."&amp;action=add\">".$shDescr."</a></li>";
5105 197bfe96 Ermal Luçi
		}
5106
	}
5107 ce0117f7 Colin Fleming
5108 197bfe96 Ermal Luçi
	return $tree;
5109
}
5110 061f78b1 Bill Marquette
5111 197bfe96 Ermal Luçi
function filter_generate_altq_queues() {
5112
	global $altq_list_queues;
5113 ce0117f7 Colin Fleming
5114 197bfe96 Ermal Luçi
	read_altq_config();
5115 061f78b1 Bill Marquette
5116 197bfe96 Ermal Luçi
	$altq_rules = "";
5117 61e047a5 Phil Davis
	foreach ($altq_list_queues as $altq) {
5118 197bfe96 Ermal Luçi
		$altq_rules .= $altq->build_rules();
5119 61e047a5 Phil Davis
	}
5120 0f0c6a9e Scott Ullrich
5121 197bfe96 Ermal Luçi
	return $altq_rules;
5122
}
5123 0f0c6a9e Scott Ullrich
5124 85a236e9 Ermal
function dnqueue_find_nextnumber() {
5125
	global $dummynet_pipe_list;
5126
5127
	$dnused = array();
5128
	if (is_array($dummynet_pipe_list)) {
5129
		foreach ($dummynet_pipe_list as $dn) {
5130
			$tmplist =& $dn->get_queue_list();
5131
			foreach ($tmplist as $qname => $link) {
5132 61e047a5 Phil Davis
				if ($link[0] == "?") {
5133 85a236e9 Ermal
					$dnused[$qname] = substr($link, 1);
5134 61e047a5 Phil Davis
				}
5135 85a236e9 Ermal
			}
5136
		}
5137
	}
5138
5139
	sort($dnused, SORT_NUMERIC);
5140
	$dnnumber = 0;
5141
	$found = false;
5142
	foreach ($dnused as $dnnum) {
5143
		if (($dnnum - $dnnumber) > 1) {
5144 89cf3dc0 Renato Botelho
			$dnnumber = $dnnum - 1;
5145 85a236e9 Ermal
			$found = true;
5146
			break;
5147 61e047a5 Phil Davis
		} else {
5148 85a236e9 Ermal
			$dnnumber = $dnnum;
5149 61e047a5 Phil Davis
		}
5150 85a236e9 Ermal
	}
5151
5152 61e047a5 Phil Davis
	if ($found == false) {
5153 85a236e9 Ermal
		$dnnumber++;
5154 61e047a5 Phil Davis
	}
5155 85a236e9 Ermal
5156
	unset($dnused, $dnnum, $found);
5157
	return $dnnumber;
5158
}
5159
5160
function dnpipe_find_nextnumber() {
5161
	global $dummynet_pipe_list;
5162
5163
	$dnused = array();
5164 61e047a5 Phil Davis
	foreach ($dummynet_pipe_list as $dn) {
5165 85a236e9 Ermal
		$dnused[] = $dn->GetNumber();
5166 61e047a5 Phil Davis
	}
5167 85a236e9 Ermal
5168
	sort($dnused, SORT_NUMERIC);
5169
	$dnnumber = 0;
5170
	$found = false;
5171
	foreach ($dnused as $dnnum) {
5172
		if (($dnnum - $dnnumber) > 1) {
5173 89cf3dc0 Renato Botelho
			$dnnumber = $dnnum - 1;
5174 85a236e9 Ermal
			$found = true;
5175
			break;
5176 61e047a5 Phil Davis
		} else {
5177 85a236e9 Ermal
			$dnnumber = $dnnum;
5178 61e047a5 Phil Davis
		}
5179 85a236e9 Ermal
	}
5180
5181 61e047a5 Phil Davis
	if ($found == false) {
5182 85a236e9 Ermal
		$dnnumber++;
5183 61e047a5 Phil Davis
	}
5184 85a236e9 Ermal
5185
	unset($dnused, $dnnum, $found);
5186
	return $dnnumber;
5187
}
5188
5189 d62ba478 Ermal Luçi
function filter_generate_dummynet_rules() {
5190 d41e63b6 Ermal
	global $g, $dummynet_pipe_list;
5191 ce0117f7 Colin Fleming
5192 c25a6b6a Ermal Luçi
	read_dummynet_config();
5193 ce0117f7 Colin Fleming
5194 c25a6b6a Ermal Luçi
	$dn_rules = "";
5195 ef7c3a63 Chris Buechler
	$max_qlimit = "100"; // OS default
5196 61e047a5 Phil Davis
	foreach ($dummynet_pipe_list as $dn) {
5197 c25a6b6a Ermal Luçi
		$dn_rules .= $dn->build_rules();
5198 ef7c3a63 Chris Buechler
		$this_qlimit = $dn->GetQlimit();
5199
		if ($this_qlimit > $max_qlimit) {
5200
			$max_qlimit = $this_qlimit;
5201
		}
5202
	}
5203
	if (!is_numericint($max_qlimit)) {
5204
		$max_qlimit = "100";
5205 61e047a5 Phil Davis
	}
5206 e3e5160c Ermal
	if (!empty($dn_rules)) {
5207 1c73248c Ermal
		if (!is_module_loaded("dummynet.ko")) {
5208
			mwexec("/sbin/kldload dummynet");
5209
		}
5210 ef7c3a63 Chris Buechler
		set_sysctl(array(
5211
				"net.inet.ip.dummynet.io_fast" => "1",
5212
				"net.inet.ip.dummynet.hash_size" => "256",
5213
				"net.inet.ip.dummynet.pipe_slot_limit" => $max_qlimit
5214
		));
5215 d41e63b6 Ermal
		file_put_contents("{$g['tmp_path']}/rules.limiter", $dn_rules);
5216
		mwexec("/sbin/ipfw {$g['tmp_path']}/rules.limiter");
5217
	}
5218 c25a6b6a Ermal Luçi
}
5219 0a33f73e Scott Ullrich
5220 197bfe96 Ermal Luçi
function build_iface_without_this_queue($iface, $qname) {
5221
	global $g, $altq_list_queues;
5222 d34ade52 Michele Di Maria
	global $shaperIFlist;
5223 0a33f73e Scott Ullrich
5224 197bfe96 Ermal Luçi
	$altq =& $altq_list_queues[$iface];
5225 d17c4ee9 Stephen Beaver
5226 61e047a5 Phil Davis
	if ($altq) {
5227 b28e1512 Stephen Beaver
		$scheduler = $altq->GetScheduler();
5228
	}
5229 d17c4ee9 Stephen Beaver
5230 b28e1512 Stephen Beaver
	$form = '<dl class="dl-horizontal">';
5231 d17c4ee9 Stephen Beaver
5232 b28e1512 Stephen Beaver
	$form .= '	<dt>';
5233
	$form .= '		<a href="firewall_shaper.php?interface=' . $iface . '&amp;queue=' . $iface . '&amp;action=show">' . $shaperIFlist[$iface] . '</a>';
5234
	$form .= '	</dt>';
5235
	$form .= '	<dd>';
5236 d17c4ee9 Stephen Beaver
	$form .=		$scheduler;
5237 b28e1512 Stephen Beaver
	$form .= '	</dd>';
5238 d17c4ee9 Stephen Beaver
5239
	$form .= '	<dt>';
5240 b28e1512 Stephen Beaver
	$form .= 'Clone';
5241
	$form .= '	</dt>';
5242
	$form .= '	<dd>';
5243
	$form .= '<a class="btn btn-info btn-xs" href="firewall_shaper_queues.php?interface=';
5244
	$form .= $iface . '&amp;queue=';
5245
	$form .= $qname . '&amp;action=add">';
5246 27d6a45b jim-p
	$form .= '<i class="fa fa-clone icon-embed-btn"></i>';
5247
	$form .= gettext("Clone Shaper to this Interface") . '</a>';
5248 d17c4ee9 Stephen Beaver
	$form .= '	</dd>';
5249 b28e1512 Stephen Beaver
5250
	$form .= '</dl>';
5251 d17c4ee9 Stephen Beaver
5252 dbaf21d4 Renato Botelho
	return $form;
5253 0a33f73e Scott Ullrich
5254 197bfe96 Ermal Luçi
}
5255 0a33f73e Scott Ullrich
5256 6cb05fa7 Colin Fleming
$default_shaper_msg = sprintf(gettext("Welcome to the %s Traffic Shaper."), $g['product_name']) . "<br />";
5257 806942d0 Stephen Beaver
$dn_default_shaper_msg = $default_shaper_msg;
5258 d62ba478 Ermal Luçi
5259 aadc1358 Phil Davis
$shaper_msg = gettext("The tree on the left navigates through the %s.");
5260
$default_shaper_msg .= sprintf($shaper_msg, gettext("queues")) . "<br />";
5261
$dn_default_shaper_msg .= sprintf($shaper_msg, gettext("limiters")) . "<br />";
5262
5263
$shaper_msg = gettext("Buttons at the bottom represent %s actions and are activated accordingly.");
5264
$default_shaper_msg .= sprintf($shaper_msg, gettext("queue"));
5265
$dn_default_shaper_msg .= sprintf($shaper_msg, gettext("limiter"));
5266
5267 85ea9d46 Steve Beaver
// Check to see if the specified interface has a queue configured
5268
function interface_has_queue($if) {
5269
	global $config;
5270
5271
	if ($config['shaper']) {
5272
		foreach ($config['shaper']['queue'] as $queue) {
5273
			if ($queue['interface'] === $if) {
5274
				return true;
5275
			}
5276
		}
5277
	}
5278
5279
	return false;
5280
}
5281 7140cb27 Stephen Jones
?>