Project

General

Profile

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