Project

General

Profile

Download (10.5 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3 c5d81585 Renato Botelho
 * firewall_shaper.php
4 fd9ebcd5 Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 0284d79e jim-p
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 fd9ebcd5 Stephen Beaver
 *
11 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14 fd9ebcd5 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
16 fd9ebcd5 Stephen Beaver
 *
17 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22 fd9ebcd5 Stephen Beaver
 */
23 5b237745 Scott Ullrich
24 6b07c15a Matthew Grooms
##|+PRIV
25
##|*IDENT=page-firewall-trafficshaper
26 5230f468 jim-p
##|*NAME=Firewall: Traffic Shaper
27 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper' page.
28
##|*MATCH=firewall_shaper.php*
29
##|-PRIV
30
31 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
32 7a927e67 Scott Ullrich
require_once("functions.inc");
33
require_once("filter.inc");
34
require_once("shaper.inc");
35 a5f07f09 Ermal Lu?i
require_once("rrd.inc");
36 5b237745 Scott Ullrich
37 e6f34d22 Phil Davis
if ($_GET['reset'] != "") {
38 7ac5a4cb Scott Ullrich
	/* XXX: Huh, why are we killing php? */
39
	mwexec("killall -9 pfctl php");
40 8f8a97c8 Ermal Luçi
	exit;
41 1b2c6c29 Ermal Luçi
}
42
43 02fb3a41 k-paulius
$pgtitle = array(gettext("Firewall"), gettext("Traffic Shaper"), gettext("By Interface"));
44 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
45 b32dd0a6 jim-p
$shortcut_section = "trafficshaper";
46 09eafb8b Scott Ullrich
47 725aee3f PiBa-NL
$shaperIFlist = get_configured_interface_with_descr(true);
48 197bfe96 Ermal Luçi
read_altq_config();
49 806942d0 Stephen Beaver
/*
50 197bfe96 Ermal Luçi
 * The whole logic in these code maybe can be specified.
51
 * If you find a better way contact me :).
52
 */
53 57b89461 Scott Ullrich
54 197bfe96 Ermal Luçi
if ($_GET) {
55 6aaec445 Phil Davis
	if ($_GET['queue']) {
56 e52c3c88 jim-p
		$qname = htmlspecialchars(trim($_GET['queue']));
57 6aaec445 Phil Davis
	}
58
	if ($_GET['interface']) {
59
		$interface = htmlspecialchars(trim($_GET['interface']));
60
	}
61
	if ($_GET['action']) {
62
		$action = htmlspecialchars($_GET['action']);
63
	}
64 197bfe96 Ermal Luçi
}
65 aef9d8fe Stephen Beaver
66 197bfe96 Ermal Luçi
if ($_POST) {
67 6aaec445 Phil Davis
	if ($_POST['name']) {
68
		$qname = htmlspecialchars(trim($_POST['name']));
69
	}
70
	if ($_POST['interface']) {
71
		$interface = htmlspecialchars(trim($_POST['interface']));
72
	}
73
	if ($_POST['parentqueue']) {
74 daab67a1 Scott Ullrich
		$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
75 6aaec445 Phil Davis
	}
76 57b89461 Scott Ullrich
}
77
78 197bfe96 Ermal Luçi
if ($interface) {
79
	$altq = $altq_list_queues[$interface];
80 806942d0 Stephen Beaver
81 197bfe96 Ermal Luçi
	if ($altq) {
82
		$queue =& $altq->find_queue($interface, $qname);
83 6aaec445 Phil Davis
	} else {
84 aef9d8fe Stephen Beaver
		$addnewaltq = true;
85 6aaec445 Phil Davis
	}
86 57b89461 Scott Ullrich
}
87
88 197bfe96 Ermal Luçi
$dontshow = false;
89
$newqueue = false;
90 aef9d8fe Stephen Beaver
$dfltmsg = false;
91 5b237745 Scott Ullrich
92 197bfe96 Ermal Luçi
if ($_GET) {
93
	switch ($action) {
94 6aaec445 Phil Davis
		case "delete":
95 197bfe96 Ermal Luçi
			if ($queue) {
96
				$queue->delete_queue();
97 6aaec445 Phil Davis
				if (write_config()) {
98 3a343d73 jim-p
					mark_subsystem_dirty('shaper');
99 6aaec445 Phil Davis
				}
100 197bfe96 Ermal Luçi
			}
101 3b6dedf3 Stephen Beaver
102 197bfe96 Ermal Luçi
			header("Location: firewall_shaper.php");
103
			exit;
104 6aaec445 Phil Davis
			break;
105
		case "resetall":
106
			foreach ($altq_list_queues as $altq) {
107 26dfbf80 Ermal Luçi
				$altq->delete_all();
108 6aaec445 Phil Davis
			}
109 26dfbf80 Ermal Luçi
			unset($altq_list_queues);
110
			$altq_list_queues = array();
111
			$tree = "<ul class=\"tree\" >";
112
			$tree .= get_interface_list_to_show();
113
			$tree .= "</ul>";
114
			unset($config['shaper']['queue']);
115
			unset($queue);
116
			unset($altq);
117
			$can_add = false;
118
			$can_enable = false;
119
			$dontshow = true;
120
			foreach ($config['filter']['rule'] as $key => $rule) {
121 6aaec445 Phil Davis
				if (isset($rule['wizard']) && $rule['wizard'] == "yes") {
122 26dfbf80 Ermal Luçi
					unset($config['filter']['rule'][$key]);
123 6aaec445 Phil Davis
				}
124 26dfbf80 Ermal Luçi
			}
125 806942d0 Stephen Beaver
126 3a343d73 jim-p
			if (write_config()) {
127 44c42356 Phil Davis
				$changes_applied = true;
128 3a343d73 jim-p
				$retval = 0;
129
				$retval |= filter_configure();
130
			} else {
131 44c42356 Phil Davis
				$no_write_config_msg = gettext("Unable to write config.xml (Access Denied?).");
132 3a343d73 jim-p
			}
133 806942d0 Stephen Beaver
134 aef9d8fe Stephen Beaver
			$dfltmsg = true;
135
136 26dfbf80 Ermal Luçi
137
		break;
138 3b6dedf3 Stephen Beaver
139 197bfe96 Ermal Luçi
	case "add":
140
			/* XXX: Find better way because we shouldn't know about this */
141
		if ($altq) {
142 3b6dedf3 Stephen Beaver
143 7903dd5e Stephen Beaver
			switch ($altq->GetScheduler()) {
144
				case "PRIQ":
145
					$q = new priq_queue();
146 c563b7a8 Ermal Luçi
				break;
147 7903dd5e Stephen Beaver
				case "FAIRQ":
148
					$q = new fairq_queue();
149
				break;
150
				case "HFSC":
151
					$q = new hfsc_queue();
152
				break;
153
				case "CBQ":
154
						$q = new cbq_queue();
155
				break;
156
				default:
157
					/* XXX: Happens when sched==NONE?! */
158
					$q = new altq_root_queue();
159
				break;
160
			}
161 197bfe96 Ermal Luçi
		} else if ($addnewaltq) {
162
			$q = new altq_root_queue();
163 a4af095c Renato Botelho
		} else {
164 dbed2db5 NOYB
			$input_errors[] = gettext("Could not create new queue/discipline! Any recent changes may need to be applied first.");
165 5605a0c4 Stephen Beaver
		}
166 197bfe96 Ermal Luçi
167 5605a0c4 Stephen Beaver
		if ($q) {
168
			$q->SetInterface($interface);
169
			$sform = $q->build_form();
170
			$sform->addGlobal(new Form_Input(
171
				'parentqueue',
172
				null,
173
				'hidden',
174
				$qname
175
			));
176
177
			$newjavascript = $q->build_javascript();
178
			unset($q);
179
			$newqueue = true;
180
		}
181
		break;
182 197bfe96 Ermal Luçi
		case "show":
183 aef9d8fe Stephen Beaver
			if ($queue) {
184 806942d0 Stephen Beaver
				$sform = $queue->build_form();
185 7841a35c Colin Fleming
			} else {
186 aef9d8fe Stephen Beaver
				$input_errors[] = gettext("Queue not found!");
187 7841a35c Colin Fleming
			}
188 197bfe96 Ermal Luçi
		break;
189
		case "enable":
190
			if ($queue) {
191 7841a35c Colin Fleming
				$queue->SetEnabled("on");
192
				$sform = $queue->build_form();
193
				if (write_config()) {
194
					mark_subsystem_dirty('shaper');
195
				}
196 6aaec445 Phil Davis
			} else {
197 7841a35c Colin Fleming
				$input_errors[] = gettext("Queue not found!");
198 6aaec445 Phil Davis
			}
199
			break;
200 197bfe96 Ermal Luçi
		case "disable":
201
			if ($queue) {
202 6aaec445 Phil Davis
				$queue->SetEnabled("");
203 a51c7c7f Stephen Beaver
				$sform = $queue->build_form();
204 6aaec445 Phil Davis
				if (write_config()) {
205
					mark_subsystem_dirty('shaper');
206
				}
207
			} else {
208 7841a35c Colin Fleming
				$input_errors[] = gettext("Queue not found!");
209 6aaec445 Phil Davis
			}
210
			break;
211 197bfe96 Ermal Luçi
		default:
212 aef9d8fe Stephen Beaver
			$dfltmsg = true;
213 197bfe96 Ermal Luçi
			$dontshow = true;
214
			break;
215 5b237745 Scott Ullrich
	}
216 aef9d8fe Stephen Beaver
}
217
218
if ($_POST) {
219 197bfe96 Ermal Luçi
	unset($input_errors);
220 5b237745 Scott Ullrich
221 197bfe96 Ermal Luçi
	if ($addnewaltq) {
222 5c4fcabc Renato Botelho
		$__tmp_altq = new altq_root_queue(); $altq =& $__tmp_altq;
223 197bfe96 Ermal Luçi
		$altq->SetInterface($interface);
224
		$altq->ReadConfig($_POST);
225 ea51e9f8 Renato Botelho
		$altq->validate_input($_POST, $input_errors);
226 92125c97 Ermal Luçi
		if (!$input_errors) {
227
			unset($tmppath);
228
			$tmppath[] = $altq->GetInterface();
229 806942d0 Stephen Beaver
			$altq->SetLink($tmppath);
230 92125c97 Ermal Luçi
			$altq->wconfig();
231 6aaec445 Phil Davis
			if (write_config()) {
232 3a343d73 jim-p
				mark_subsystem_dirty('shaper');
233 6aaec445 Phil Davis
			}
234 92125c97 Ermal Luçi
			$can_enable = true;
235 aef9d8fe Stephen Beaver
			$can_add = true;
236 92125c97 Ermal Luçi
		}
237 aef9d8fe Stephen Beaver
238 48d418e8 Ermal Luçi
		read_altq_config();
239 a51c7c7f Stephen Beaver
		$sform = $altq->build_form();
240 197bfe96 Ermal Luçi
	} else if ($parentqueue) { /* Add a new queue */
241
		$qtmp =& $altq->find_queue($interface, $parentqueue);
242
		if ($qtmp) {
243
			$tmppath =& $qtmp->GetLink();
244
			array_push($tmppath, $qname);
245 ea51e9f8 Renato Botelho
			$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, $input_errors);
246 92125c97 Ermal Luçi
			if (!$input_errors) {
247
				array_pop($tmppath);
248
				$tmp->wconfig();
249
				$can_enable = true;
250 70b139a3 Chris Buechler
				if ($tmp->CanHaveChildren() && $can_enable) {
251 6aaec445 Phil Davis
					if ($tmp->GetDefault() <> "") {
252 3b6dedf3 Stephen Beaver
						$can_add = false;
253 6aaec445 Phil Davis
					} else {
254 3b6dedf3 Stephen Beaver
						$can_add = true;
255 6aaec445 Phil Davis
					}
256
				} else {
257 92125c97 Ermal Luçi
					$can_add = false;
258 6aaec445 Phil Davis
				}
259
				if (write_config()) {
260 3a343d73 jim-p
					mark_subsystem_dirty('shaper');
261 6aaec445 Phil Davis
				}
262 92125c97 Ermal Luçi
				$can_enable = true;
263 6aaec445 Phil Davis
				if ($altq->GetScheduler() != "PRIQ") { /* XXX */
264
					if ($tmp->GetDefault() <> "") {
265 3b6dedf3 Stephen Beaver
						$can_add = false;
266 6aaec445 Phil Davis
					} else {
267 3b6dedf3 Stephen Beaver
						$can_add = true;
268 6aaec445 Phil Davis
					}
269
				}
270 92125c97 Ermal Luçi
			}
271 48d418e8 Ermal Luçi
			read_altq_config();
272 a51c7c7f Stephen Beaver
			$sform = $tmp->build_form();
273 6aaec445 Phil Davis
		} else {
274 2f8fe6af Carlos Eduardo Ramos
			$input_errors[] = gettext("Could not add new queue.");
275 6aaec445 Phil Davis
		}
276 197bfe96 Ermal Luçi
	} else if ($_POST['apply']) {
277 6aaec445 Phil Davis
		write_config();
278 44c42356 Phil Davis
		$changes_applied = true;
279 6aaec445 Phil Davis
		$retval = 0;
280 44c42356 Phil Davis
		$retval |= filter_configure();
281 5b237745 Scott Ullrich
282 806942d0 Stephen Beaver
		/* reset rrd queues */
283 7ac5a4cb Scott Ullrich
		system("rm -f /var/db/rrd/*queuedrops.rrd");
284
		system("rm -f /var/db/rrd/*queues.rrd");
285
		enable_rrd_graphing();
286 1f276138 Scott Ullrich
287 a368a026 Ermal Lu?i
		clear_subsystem_dirty('shaper');
288 806942d0 Stephen Beaver
289 6aaec445 Phil Davis
		if ($queue) {
290 a51c7c7f Stephen Beaver
			$sform = $queue->build_form();
291 6aaec445 Phil Davis
			$dontshow = false;
292
		} else {
293 a51c7c7f Stephen Beaver
			$sform = $default_shaper_message;
294 6aaec445 Phil Davis
			$dontshow = true;
295
		}
296 197bfe96 Ermal Luçi
	} else if ($queue) {
297 6aaec445 Phil Davis
		$queue->validate_input($_POST, $input_errors);
298
		if (!$input_errors) {
299
			$queue->update_altq_queue_data($_POST);
300
			$queue->wconfig();
301
			if (write_config()) {
302
				mark_subsystem_dirty('shaper');
303
			}
304
			$dontshow = false;
305
		}
306 48d418e8 Ermal Luçi
		read_altq_config();
307 a51c7c7f Stephen Beaver
		$sform = $queue->build_form();
308 806942d0 Stephen Beaver
	} else	{
309 aef9d8fe Stephen Beaver
		$dfltmsg = true;
310 92125c97 Ermal Luçi
		$dontshow = true;
311
	}
312 5f471c95 Ermal
	mwexec("killall qstats");
313 aef9d8fe Stephen Beaver
}
314
315 e6f34d22 Phil Davis
if (!$_POST && !$_GET) {
316 aef9d8fe Stephen Beaver
	$dfltmsg = true;
317 197bfe96 Ermal Luçi
	$dontshow = true;
318
}
319 0ceb8927 Bill Marquette
320 fce82460 Ermal Luçi
if ($queue) {
321 6aaec445 Phil Davis
	if ($queue->GetEnabled()) {
322 aef9d8fe Stephen Beaver
		$can_enable = true;
323 6aaec445 Phil Davis
	} else {
324 aef9d8fe Stephen Beaver
		$can_enable = false;
325 6aaec445 Phil Davis
	}
326 806942d0 Stephen Beaver
	if ($queue->CanHaveChildren() && $can_enable) {
327 6aaec445 Phil Davis
		if ($altq->GetQname() <> $queue->GetQname() && $queue->GetDefault() <> "") {
328 aef9d8fe Stephen Beaver
			$can_add = false;
329 6aaec445 Phil Davis
		} else {
330 aef9d8fe Stephen Beaver
			$can_add = true;
331 6aaec445 Phil Davis
		}
332
	} else {
333 aef9d8fe Stephen Beaver
		$can_add = false;
334 6aaec445 Phil Davis
	}
335 fce82460 Ermal Luçi
}
336
337 aef9d8fe Stephen Beaver
include("head.inc");
338
339
$tree = '<ul class="tree" >';
340 fce82460 Ermal Luçi
if (is_array($altq_list_queues)) {
341 3b6dedf3 Stephen Beaver
	foreach ($altq_list_queues as $tmpaltq) {
342 6aaec445 Phil Davis
		$tree .= $tmpaltq->build_tree();
343 3b6dedf3 Stephen Beaver
	}
344 6aaec445 Phil Davis
	$tree .= get_interface_list_to_show();
345 fce82460 Ermal Luçi
}
346 0ceb8927 Bill Marquette
347 aef9d8fe Stephen Beaver
$tree .= "</ul>";
348 197bfe96 Ermal Luçi
349 7841a35c Colin Fleming
if ($queue) {
350 aef9d8fe Stephen Beaver
	print($queue->build_javascript());
351 7841a35c Colin Fleming
}
352 806942d0 Stephen Beaver
353 aef9d8fe Stephen Beaver
print($newjavascript);
354
355 7841a35c Colin Fleming
if ($input_errors) {
356 806942d0 Stephen Beaver
	print_input_errors($input_errors);
357 7841a35c Colin Fleming
}
358 aef9d8fe Stephen Beaver
359 44c42356 Phil Davis
if ($no_write_config_msg) {
360
	print_info_box($no_write_config_msg, 'danger');
361
}
362
363
if ($changes_applied) {
364
	print_apply_result_box($retval);
365 7841a35c Colin Fleming
}
366 806942d0 Stephen Beaver
367 7841a35c Colin Fleming
if (is_subsystem_dirty('shaper')) {
368 dbed2db5 NOYB
	print_apply_box(gettext("The traffic shaper configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
369 7841a35c Colin Fleming
}
370 aef9d8fe Stephen Beaver
371
$tab_array = array();
372
$tab_array[] = array(gettext("By Interface"), true, "firewall_shaper.php");
373
$tab_array[] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
374 544af3fe k-paulius
$tab_array[] = array(gettext("Limiters"), false, "firewall_shaper_vinterface.php");
375 aef9d8fe Stephen Beaver
$tab_array[] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
376
display_top_tabs($tab_array);
377 806942d0 Stephen Beaver
378 5b237745 Scott Ullrich
?>
379 8ed6b8e3 Stephen Beaver
<script type="text/javascript" src="./vendor/tree/tree.js"></script>
380 df5c0bc0 Colin Fleming
381 aef9d8fe Stephen Beaver
<div class="table-responsive">
382
	<table class="table">
383
		<tbody>
384
			<tr class="tabcont">
385 806942d0 Stephen Beaver
				<td class="col-md-1">
386
<?php
387
// Display the shaper tree
388 aef9d8fe Stephen Beaver
print($tree);
389 5b237745 Scott Ullrich
390 806942d0 Stephen Beaver
if (count($altq_list_queues) > 0) {
391 92125c97 Ermal Luçi
?>
392 6cb05fa7 Colin Fleming
					<a href="firewall_shaper.php?action=resetall" class="btn btn-sm btn-danger">
393 37676f4e jim-p
						<i class="fa fa-trash icon-embed-btn"></i>
394 aef9d8fe Stephen Beaver
						<?=gettext('Remove Shaper')?>
395
					</a>
396 806942d0 Stephen Beaver
<?php
397 aef9d8fe Stephen Beaver
}
398 197bfe96 Ermal Luçi
?>
399 aef9d8fe Stephen Beaver
				</td>
400
				<td>
401
<?php
402
403 f7d2d5aa Stephen Beaver
if (!$dfltmsg && $sform)  {
404 aef9d8fe Stephen Beaver
	// Add global buttons
405
	if (!$dontshow || $newqueue) {
406
		if ($can_add || $addnewaltq) {
407 7841a35c Colin Fleming
			if ($queue) {
408 aef9d8fe Stephen Beaver
				$url = 'firewall_shaper.php?interface='. $interface . '&queue=' . $queue->GetQname() . '&action=add';
409 7841a35c Colin Fleming
			} else {
410 aef9d8fe Stephen Beaver
				$url = 'firewall_shaper.php?interface='. $interface . '&action=add';
411 7841a35c Colin Fleming
			}
412 806942d0 Stephen Beaver
413 aef9d8fe Stephen Beaver
			$sform->addGlobal(new Form_Button(
414
				'add',
415 faab522f Renato Botelho
				'Add new Queue',
416 37676f4e jim-p
				$url,
417
				'fa-plus'
418 27d6a45b jim-p
			))->addClass('btn-success');
419 a51c7c7f Stephen Beaver
420 aef9d8fe Stephen Beaver
		}
421 806942d0 Stephen Beaver
422 7841a35c Colin Fleming
		if ($queue) {
423 aef9d8fe Stephen Beaver
			$url = 'firewall_shaper.php?interface='. $interface . '&queue=' . $queue->GetQname() . '&action=delete';
424 7841a35c Colin Fleming
		} else {
425 aef9d8fe Stephen Beaver
			$url = 'firewall_shaper.php?interface='. $interface . '&action=delete';
426 7841a35c Colin Fleming
		}
427 806942d0 Stephen Beaver
428 aef9d8fe Stephen Beaver
		$sform->addGlobal(new Form_Button(
429
			'delete',
430 faab522f Renato Botelho
			$queue ? 'Delete this queue':'Disable shaper on interface',
431 37676f4e jim-p
			$url,
432
			'fa-trash'
433 27d6a45b jim-p
		))->addClass('btn-danger');
434 a51c7c7f Stephen Beaver
435 aef9d8fe Stephen Beaver
	}
436 806942d0 Stephen Beaver
437 aef9d8fe Stephen Beaver
	print($sform);
438
}
439 806942d0 Stephen Beaver
?>
440 aef9d8fe Stephen Beaver
				</td>
441
			</tr>
442
		</tbody>
443
	</table>
444 806942d0 Stephen Beaver
</div>
445
446 fc47d47a jim-p
<?php if (empty(get_interface_list_to_show()) && (!is_array($altq_list_queues) || (count($altq_list_queues) == 0))): ?>
447 aa64bb65 jim-p
<div>
448
	<div class="infoblock blockopen">
449
		<?php print_info_box(gettext("This firewall does not have any interfaces assigned that are capable of using ALTQ traffic shaping."), 'danger', false); ?>
450
	</div>
451
</div>
452
<?php endif; ?>
453
454 806942d0 Stephen Beaver
<?php
455 a51c7c7f Stephen Beaver
if ($dfltmsg) {
456
?>
457
<div>
458 35681930 Stephen Beaver
	<div class="infoblock">
459 f6aebbcc NewEraCracker
		<?php print_info_box($default_shaper_msg, 'info', false); ?>
460 a51c7c7f Stephen Beaver
	</div>
461
</div>
462
<?php
463
}
464 c10cb196 Stephen Beaver
include("foot.inc");