Project

General

Profile

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