1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_shaper.php
|
5
|
Copyright (C) 2004, 2005 Scott Ullrich
|
6
|
Copyright (C) 2008 Ermal Luçi
|
7
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
/*
|
32
|
pfSense_BUILDER_BINARIES: /usr/bin/killall
|
33
|
pfSense_MODULE: shaper
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-firewall-trafficshaper
|
38
|
##|*NAME=Firewall: Traffic Shaper page
|
39
|
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper' page.
|
40
|
##|*MATCH=firewall_shaper.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
require('classes/Form.class.php');
|
44
|
|
45
|
require("guiconfig.inc");
|
46
|
require_once("functions.inc");
|
47
|
require_once("filter.inc");
|
48
|
require_once("shaper.inc");
|
49
|
require_once("rrd.inc");
|
50
|
|
51
|
if($_GET['reset'] != "") {
|
52
|
/* XXX: Huh, why are we killing php? */
|
53
|
mwexec("killall -9 pfctl php");
|
54
|
exit;
|
55
|
}
|
56
|
|
57
|
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"));
|
58
|
$shortcut_section = "trafficshaper";
|
59
|
|
60
|
$shaperIFlist = get_configured_interface_with_descr();
|
61
|
read_altq_config();
|
62
|
/*
|
63
|
* The whole logic in these code maybe can be specified.
|
64
|
* If you find a better way contact me :).
|
65
|
*/
|
66
|
|
67
|
if ($_GET) {
|
68
|
if ($_GET['queue'])
|
69
|
$qname = htmlspecialchars(trim($_GET['queue']));
|
70
|
|
71
|
if ($_GET['interface'])
|
72
|
$interface = htmlspecialchars(trim($_GET['interface']));
|
73
|
|
74
|
if ($_GET['action'])
|
75
|
$action = htmlspecialchars($_GET['action']);
|
76
|
}
|
77
|
|
78
|
if ($_POST) {
|
79
|
if ($_POST['name'])
|
80
|
$qname = htmlspecialchars(trim($_POST['name']));
|
81
|
|
82
|
if ($_POST['interface'])
|
83
|
$interface = htmlspecialchars(trim($_POST['interface']));
|
84
|
|
85
|
if ($_POST['parentqueue'])
|
86
|
$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
|
87
|
}
|
88
|
|
89
|
if ($interface) {
|
90
|
$altq = $altq_list_queues[$interface];
|
91
|
|
92
|
if ($altq) {
|
93
|
$queue =& $altq->find_queue($interface, $qname);
|
94
|
} else
|
95
|
$addnewaltq = true;
|
96
|
}
|
97
|
|
98
|
$dontshow = false;
|
99
|
$newqueue = false;
|
100
|
$output_form = "";
|
101
|
$dfltmsg = false;
|
102
|
|
103
|
if ($_GET) {
|
104
|
switch ($action) {
|
105
|
case "delete":
|
106
|
if ($queue) {
|
107
|
$queue->delete_queue();
|
108
|
if (write_config())
|
109
|
mark_subsystem_dirty('shaper');
|
110
|
}
|
111
|
header("Location: firewall_shaper.php");
|
112
|
exit;
|
113
|
break;
|
114
|
case "resetall":
|
115
|
foreach ($altq_list_queues as $altq)
|
116
|
$altq->delete_all();
|
117
|
unset($altq_list_queues);
|
118
|
$altq_list_queues = array();
|
119
|
$tree = "<ul class=\"tree\" >";
|
120
|
$tree .= get_interface_list_to_show();
|
121
|
$tree .= "</ul>";
|
122
|
unset($config['shaper']['queue']);
|
123
|
unset($queue);
|
124
|
unset($altq);
|
125
|
$can_add = false;
|
126
|
$can_enable = false;
|
127
|
$dontshow = true;
|
128
|
foreach ($config['filter']['rule'] as $key => $rule) {
|
129
|
if (isset($rule['wizard']) && $rule['wizard'] == "yes")
|
130
|
unset($config['filter']['rule'][$key]);
|
131
|
}
|
132
|
|
133
|
if (write_config()) {
|
134
|
$retval = 0;
|
135
|
$retval |= filter_configure();
|
136
|
$savemsg = get_std_save_message($retval);
|
137
|
|
138
|
if (stristr($retval, "error") != true)
|
139
|
$savemsg = get_std_save_message($retval);
|
140
|
else
|
141
|
$savemsg = $retval;
|
142
|
|
143
|
} else {
|
144
|
$savemsg = gettext("Unable to write config.xml (Access Denied?)");
|
145
|
}
|
146
|
|
147
|
$dfltmsg = true;
|
148
|
|
149
|
|
150
|
break;
|
151
|
case "add":
|
152
|
/* XXX: Find better way because we shouldn't know about this */
|
153
|
if ($altq) {
|
154
|
switch ($altq->GetScheduler()) {
|
155
|
case "PRIQ":
|
156
|
$q = new priq_queue();
|
157
|
break;
|
158
|
case "FAIRQ":
|
159
|
$q = new fairq_queue();
|
160
|
break;
|
161
|
case "HFSC":
|
162
|
$q = new hfsc_queue();
|
163
|
break;
|
164
|
case "CBQ":
|
165
|
$q = new cbq_queue();
|
166
|
break;
|
167
|
default:
|
168
|
/* XXX: Happens when sched==NONE?! */
|
169
|
$q = new altq_root_queue();
|
170
|
break;
|
171
|
}
|
172
|
} else if ($addnewaltq) {
|
173
|
$q = new altq_root_queue();
|
174
|
} else
|
175
|
$input_errors[] = gettext("Could not create new queue/discipline!");
|
176
|
|
177
|
if ($q) {
|
178
|
$q->SetInterface($interface);
|
179
|
$output_form .= $q->build_form();
|
180
|
$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
|
181
|
$output_form .= " value=\"".htmlspecialchars($qname)."\" />";
|
182
|
$newjavascript = $q->build_javascript();
|
183
|
unset($q);
|
184
|
$newqueue = true;
|
185
|
}
|
186
|
break;
|
187
|
case "show":
|
188
|
if ($queue) {
|
189
|
$sform = $queue->build_form();
|
190
|
//$output_form .= $queue->build_form();
|
191
|
}
|
192
|
else
|
193
|
$input_errors[] = gettext("Queue not found!");
|
194
|
break;
|
195
|
case "enable":
|
196
|
if ($queue) {
|
197
|
$queue->SetEnabled("on");
|
198
|
$output_form .= $queue->build_form();
|
199
|
if (write_config())
|
200
|
mark_subsystem_dirty('shaper');
|
201
|
} else
|
202
|
$input_errors[] = gettext("Queue not found!");
|
203
|
break;
|
204
|
case "disable":
|
205
|
if ($queue) {
|
206
|
$queue->SetEnabled("");
|
207
|
$output_form .= $queue->build_form();
|
208
|
if (write_config())
|
209
|
mark_subsystem_dirty('shaper');
|
210
|
} else
|
211
|
$input_errors[] = gettext("Queue not found!");
|
212
|
break;
|
213
|
default:
|
214
|
$dfltmsg = true;
|
215
|
$dontshow = true;
|
216
|
break;
|
217
|
}
|
218
|
}
|
219
|
|
220
|
if ($_POST) {
|
221
|
unset($input_errors);
|
222
|
|
223
|
if ($addnewaltq) {
|
224
|
$altq =& new altq_root_queue();
|
225
|
$altq->SetInterface($interface);
|
226
|
|
227
|
switch ($altq->GetBwscale()) {
|
228
|
case "Mb":
|
229
|
$factor = 1000 * 1000;
|
230
|
break;
|
231
|
case "Kb":
|
232
|
$factor = 1000;
|
233
|
break;
|
234
|
case "b":
|
235
|
$factor = 1;
|
236
|
break;
|
237
|
case "Gb":
|
238
|
$factor = 1000 * 1000 * 1000;
|
239
|
break;
|
240
|
case "%": /* We don't use it for root_XXX queues. */
|
241
|
default: /* XXX assume Kb by default. */
|
242
|
$factor = 1000;
|
243
|
break;
|
244
|
}
|
245
|
|
246
|
$altq->SetAvailableBandwidth($altq->GetBandwidth() * $factor);
|
247
|
$altq->ReadConfig($_POST);
|
248
|
$altq->validate_input($_POST, $input_errors);
|
249
|
if (!$input_errors) {
|
250
|
unset($tmppath);
|
251
|
$tmppath[] = $altq->GetInterface();
|
252
|
$altq->SetLink($tmppath);
|
253
|
$altq->wconfig();
|
254
|
if (write_config())
|
255
|
mark_subsystem_dirty('shaper');
|
256
|
$can_enable = true;
|
257
|
$can_add = true;
|
258
|
}
|
259
|
|
260
|
read_altq_config();
|
261
|
$output_form .= $altq->build_form();
|
262
|
|
263
|
} else if ($parentqueue) { /* Add a new queue */
|
264
|
$qtmp =& $altq->find_queue($interface, $parentqueue);
|
265
|
if ($qtmp) {
|
266
|
$tmppath =& $qtmp->GetLink();
|
267
|
array_push($tmppath, $qname);
|
268
|
$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, $input_errors);
|
269
|
if (!$input_errors) {
|
270
|
array_pop($tmppath);
|
271
|
$tmp->wconfig();
|
272
|
$can_enable = true;
|
273
|
if ($tmp->CanHaveChildren() && $can_enable) {
|
274
|
if ($tmp->GetDefault() != "")
|
275
|
$can_add = false;
|
276
|
else
|
277
|
$can_add = true;
|
278
|
} else
|
279
|
$can_add = false;
|
280
|
if (write_config())
|
281
|
mark_subsystem_dirty('shaper');
|
282
|
$can_enable = true;
|
283
|
if ($altq->GetScheduler() != "PRIQ") /* XXX */
|
284
|
if ($tmp->GetDefault() != "")
|
285
|
$can_add = false;
|
286
|
else
|
287
|
$can_add = true;
|
288
|
}
|
289
|
read_altq_config();
|
290
|
$output_form .= $tmp->build_form();
|
291
|
} else
|
292
|
$input_errors[] = gettext("Could not add new queue.");
|
293
|
} else if ($_POST['apply']) {
|
294
|
write_config();
|
295
|
|
296
|
$retval = 0;
|
297
|
$retval = filter_configure();
|
298
|
$savemsg = get_std_save_message($retval);
|
299
|
|
300
|
if (stristr($retval, "error") != true)
|
301
|
$savemsg = get_std_save_message($retval);
|
302
|
else
|
303
|
$savemsg = $retval;
|
304
|
|
305
|
/* reset rrd queues */
|
306
|
system("rm -f /var/db/rrd/*queuedrops.rrd");
|
307
|
system("rm -f /var/db/rrd/*queues.rrd");
|
308
|
enable_rrd_graphing();
|
309
|
|
310
|
clear_subsystem_dirty('shaper');
|
311
|
|
312
|
if ($queue) {
|
313
|
$output_form .= $queue->build_form();
|
314
|
$dontshow = false;
|
315
|
}
|
316
|
else {
|
317
|
$dfltmsg = true;
|
318
|
$dontshow = true;
|
319
|
}
|
320
|
|
321
|
} else if ($queue) {
|
322
|
$queue->validate_input($_POST, $input_errors);
|
323
|
if (!$input_errors) {
|
324
|
$queue->update_altq_queue_data($_POST);
|
325
|
$queue->wconfig();
|
326
|
if (write_config())
|
327
|
mark_subsystem_dirty('shaper');
|
328
|
$dontshow = false;
|
329
|
}
|
330
|
read_altq_config();
|
331
|
$output_form .= $queue->build_form();
|
332
|
} else {
|
333
|
$dfltmsg = true;
|
334
|
$dontshow = true;
|
335
|
}
|
336
|
mwexec("killall qstats");
|
337
|
}
|
338
|
|
339
|
if(!$_POST && !$_GET){
|
340
|
$dfltmsg = true;
|
341
|
$dontshow = true;
|
342
|
}
|
343
|
|
344
|
if ($queue) {
|
345
|
if ($queue->GetEnabled())
|
346
|
$can_enable = true;
|
347
|
else
|
348
|
$can_enable = false;
|
349
|
|
350
|
if ($queue->CanHaveChildren() && $can_enable) {
|
351
|
if ($altq->GetQname() != $queue->GetQname() && $queue->GetDefault() != "")
|
352
|
$can_add = false;
|
353
|
else
|
354
|
$can_add = true;
|
355
|
} else
|
356
|
$can_add = false;
|
357
|
}
|
358
|
|
359
|
//$pgtitle = "Firewall: Shaper: By Interface View";
|
360
|
$closehead = false;
|
361
|
include("head.inc");
|
362
|
|
363
|
$tree = '<ul class="tree" >';
|
364
|
if (is_array($altq_list_queues)) {
|
365
|
foreach ($altq_list_queues as $tmpaltq) {
|
366
|
$tree .= $tmpaltq->build_tree();
|
367
|
}
|
368
|
$tree .= get_interface_list_to_show();
|
369
|
}
|
370
|
|
371
|
$tree .= "</ul>";
|
372
|
|
373
|
if ($queue)
|
374
|
print($queue->build_javascript());
|
375
|
|
376
|
print($newjavascript);
|
377
|
|
378
|
if ($input_errors)
|
379
|
print_input_errors($input_errors);
|
380
|
|
381
|
if ($savemsg)
|
382
|
print_info_box($savemsg, 'success');
|
383
|
|
384
|
if (is_subsystem_dirty('shaper'))
|
385
|
print_info_box_np(gettext("The traffic shaper configuration has been changed. You must apply the changes in order for them to take effect."));
|
386
|
|
387
|
$tab_array = array();
|
388
|
$tab_array[] = array(gettext("By Interface"), true, "firewall_shaper.php");
|
389
|
$tab_array[] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
|
390
|
$tab_array[] = array(gettext("Limiter"), false, "firewall_shaper_vinterface.php");
|
391
|
$tab_array[] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
|
392
|
$tab_array[] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
|
393
|
display_top_tabs($tab_array);
|
394
|
|
395
|
?>
|
396
|
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
|
397
|
<script type="text/javascript" src="./tree/tree.js"></script>
|
398
|
|
399
|
<div class="table-responsive">
|
400
|
<table class="table">
|
401
|
<tbody>
|
402
|
<tr class="tabcont">
|
403
|
<td class="col-md-1">
|
404
|
<?php
|
405
|
// Display the shaper tree
|
406
|
print($tree);
|
407
|
|
408
|
if (count($altq_list_queues) > 0) {
|
409
|
?>
|
410
|
<a href="firewall_shaper.php?action=resetall" class="btn btn-sm btn-danger"/>
|
411
|
<?=gettext('Remove Shaper')?>
|
412
|
</a>
|
413
|
<?php
|
414
|
}
|
415
|
?>
|
416
|
</td>
|
417
|
<td>
|
418
|
<?php
|
419
|
|
420
|
if($dfltmsg)
|
421
|
print_info_box($default_shaper_msg);
|
422
|
else{
|
423
|
// Add global buttons
|
424
|
if (!$dontshow || $newqueue) {
|
425
|
if ($can_add || $addnewaltq) {
|
426
|
if($queue)
|
427
|
$url = 'firewall_shaper.php?interface='. $interface . '&queue=' . $queue->GetQname() . '&action=add';
|
428
|
else
|
429
|
$url = 'firewall_shaper.php?interface='. $interface . '&action=add';
|
430
|
|
431
|
$sform->addGlobal(new Form_Button(
|
432
|
'add',
|
433
|
'Add new Queue',
|
434
|
$url
|
435
|
))->addClass('btn-success');
|
436
|
}
|
437
|
|
438
|
if($queue)
|
439
|
$url = 'firewall_shaper.php?interface='. $interface . '&queue=' . $queue->GetQname() . '&action=delete';
|
440
|
else
|
441
|
$url = 'firewall_shaper.php?interface='. $interface . '&action=delete';
|
442
|
|
443
|
$sform->addGlobal(new Form_Button(
|
444
|
'delete',
|
445
|
$queue ? 'Delete this queue':'Disable shaper on interface',
|
446
|
$url
|
447
|
))->addClass('btn-danger');
|
448
|
}
|
449
|
|
450
|
// Print hte form
|
451
|
print($sform);
|
452
|
}
|
453
|
?>
|
454
|
</td>
|
455
|
</tr>
|
456
|
</tbody>
|
457
|
</table>
|
458
|
</div>
|
459
|
|
460
|
<?php
|
461
|
include("foot.inc");
|