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("guiconfig.inc");
|
44
|
require_once("functions.inc");
|
45
|
require_once("filter.inc");
|
46
|
require_once("shaper.inc");
|
47
|
require_once("rrd.inc");
|
48
|
|
49
|
if($_GET['reset'] <> "") {
|
50
|
/* XXX: Huh, why are we killing php? */
|
51
|
mwexec("killall -9 pfctl php");
|
52
|
exit;
|
53
|
}
|
54
|
|
55
|
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"));
|
56
|
$shortcut_section = "trafficshaper";
|
57
|
|
58
|
$shaperIFlist = get_configured_interface_with_descr();
|
59
|
read_altq_config();
|
60
|
/*
|
61
|
* The whole logic in these code maybe can be specified.
|
62
|
* If you find a better way contact me :).
|
63
|
*/
|
64
|
|
65
|
if ($_GET) {
|
66
|
if ($_GET['queue'])
|
67
|
$qname = htmlspecialchars(trim($_GET['queue']));
|
68
|
if ($_GET['interface'])
|
69
|
$interface = htmlspecialchars(trim($_GET['interface']));
|
70
|
if ($_GET['action'])
|
71
|
$action = htmlspecialchars($_GET['action']);
|
72
|
}
|
73
|
if ($_POST) {
|
74
|
if ($_POST['name'])
|
75
|
$qname = htmlspecialchars(trim($_POST['name']));
|
76
|
if ($_POST['interface'])
|
77
|
$interface = htmlspecialchars(trim($_POST['interface']));
|
78
|
if ($_POST['parentqueue'])
|
79
|
$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
|
80
|
}
|
81
|
|
82
|
if ($interface) {
|
83
|
$altq = $altq_list_queues[$interface];
|
84
|
if ($altq) {
|
85
|
$queue =& $altq->find_queue($interface, $qname);
|
86
|
} else $addnewaltq = true;
|
87
|
}
|
88
|
|
89
|
$dontshow = false;
|
90
|
$newqueue = false;
|
91
|
$output_form = "";
|
92
|
|
93
|
if ($_GET) {
|
94
|
switch ($action) {
|
95
|
case "delete":
|
96
|
if ($queue) {
|
97
|
$queue->delete_queue();
|
98
|
if (write_config())
|
99
|
mark_subsystem_dirty('shaper');
|
100
|
}
|
101
|
header("Location: firewall_shaper.php");
|
102
|
exit;
|
103
|
break;
|
104
|
case "resetall":
|
105
|
foreach ($altq_list_queues as $altq)
|
106
|
$altq->delete_all();
|
107
|
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
|
if (isset($rule['wizard']) && $rule['wizard'] == "yes")
|
120
|
unset($config['filter']['rule'][$key]);
|
121
|
}
|
122
|
if (write_config()) {
|
123
|
$retval = 0;
|
124
|
$retval |= filter_configure();
|
125
|
$savemsg = get_std_save_message($retval);
|
126
|
|
127
|
if (stristr($retval, "error") <> true)
|
128
|
$savemsg = get_std_save_message($retval);
|
129
|
else
|
130
|
$savemsg = $retval;
|
131
|
} else {
|
132
|
$savemsg = gettext("Unable to write config.xml (Access Denied?)");
|
133
|
}
|
134
|
$output_form = $default_shaper_message;
|
135
|
|
136
|
break;
|
137
|
case "add":
|
138
|
/* XXX: Find better way because we shouldn't know about this */
|
139
|
if ($altq) {
|
140
|
switch ($altq->GetScheduler()) {
|
141
|
case "PRIQ":
|
142
|
$q = new priq_queue();
|
143
|
break;
|
144
|
case "FAIRQ":
|
145
|
$q = new fairq_queue();
|
146
|
break;
|
147
|
case "HFSC":
|
148
|
$q = new hfsc_queue();
|
149
|
break;
|
150
|
case "CBQ":
|
151
|
$q = new cbq_queue();
|
152
|
break;
|
153
|
default:
|
154
|
/* XXX: Happens when sched==NONE?! */
|
155
|
$q = new altq_root_queue();
|
156
|
break;
|
157
|
}
|
158
|
} else if ($addnewaltq) {
|
159
|
$q = new altq_root_queue();
|
160
|
} else
|
161
|
$input_errors[] = gettext("Could not create new queue/discipline!");
|
162
|
|
163
|
if ($q) {
|
164
|
$q->SetInterface($interface);
|
165
|
$output_form .= $q->build_form();
|
166
|
$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
|
167
|
$output_form .= " value=\"".htmlspecialchars($qname)."\" />";
|
168
|
$newjavascript = $q->build_javascript();
|
169
|
unset($q);
|
170
|
$newqueue = true;
|
171
|
}
|
172
|
break;
|
173
|
case "show":
|
174
|
if ($queue)
|
175
|
$output_form .= $queue->build_form();
|
176
|
else
|
177
|
$input_errors[] = gettext("Queue not found!");
|
178
|
break;
|
179
|
case "enable":
|
180
|
if ($queue) {
|
181
|
$queue->SetEnabled("on");
|
182
|
$output_form .= $queue->build_form();
|
183
|
if (write_config())
|
184
|
mark_subsystem_dirty('shaper');
|
185
|
} else
|
186
|
$input_errors[] = gettext("Queue not found!");
|
187
|
break;
|
188
|
case "disable":
|
189
|
if ($queue) {
|
190
|
$queue->SetEnabled("");
|
191
|
$output_form .= $queue->build_form();
|
192
|
if (write_config())
|
193
|
mark_subsystem_dirty('shaper');
|
194
|
} else
|
195
|
$input_errors[] = gettext("Queue not found!");
|
196
|
break;
|
197
|
default:
|
198
|
$output_form .= $default_shaper_msg;
|
199
|
$dontshow = true;
|
200
|
break;
|
201
|
}
|
202
|
} else if ($_POST) {
|
203
|
unset($input_errors);
|
204
|
|
205
|
if ($addnewaltq) {
|
206
|
$altq =& new altq_root_queue();
|
207
|
$altq->SetInterface($interface);
|
208
|
|
209
|
switch ($altq->GetBwscale()) {
|
210
|
case "Mb":
|
211
|
$factor = 1000 * 1000;
|
212
|
brak;
|
213
|
case "Kb":
|
214
|
$factor = 1000;
|
215
|
break;
|
216
|
case "b":
|
217
|
$factor = 1;
|
218
|
break;
|
219
|
case "Gb":
|
220
|
$factor = 1000 * 1000 * 1000;
|
221
|
break;
|
222
|
case "%": /* We don't use it for root_XXX queues. */
|
223
|
default: /* XXX assume Kb by default. */
|
224
|
$factor = 1000;
|
225
|
break;
|
226
|
}
|
227
|
$altq->SetAvailableBandwidth($altq->GetBandwidth() * $factor);
|
228
|
$altq->ReadConfig($_POST);
|
229
|
$altq->validate_input($_POST, $input_errors);
|
230
|
if (!$input_errors) {
|
231
|
unset($tmppath);
|
232
|
$tmppath[] = $altq->GetInterface();
|
233
|
$altq->SetLink($tmppath);
|
234
|
$altq->wconfig();
|
235
|
if (write_config())
|
236
|
mark_subsystem_dirty('shaper');
|
237
|
$can_enable = true;
|
238
|
$can_add = true;
|
239
|
}
|
240
|
read_altq_config();
|
241
|
$output_form .= $altq->build_form();
|
242
|
|
243
|
} else if ($parentqueue) { /* Add a new queue */
|
244
|
$qtmp =& $altq->find_queue($interface, $parentqueue);
|
245
|
if ($qtmp) {
|
246
|
$tmppath =& $qtmp->GetLink();
|
247
|
array_push($tmppath, $qname);
|
248
|
$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, $input_errors);
|
249
|
if (!$input_errors) {
|
250
|
array_pop($tmppath);
|
251
|
$tmp->wconfig();
|
252
|
$can_enable = true;
|
253
|
if ($tmp->CanHaveChildren() && $can_enable) {
|
254
|
if ($tmp->GetDefault() <> "")
|
255
|
$can_add = false;
|
256
|
else
|
257
|
$can_add = true;
|
258
|
} else
|
259
|
$can_add = false;
|
260
|
if (write_config())
|
261
|
mark_subsystem_dirty('shaper');
|
262
|
$can_enable = true;
|
263
|
if ($altq->GetScheduler() != "PRIQ") /* XXX */
|
264
|
if ($tmp->GetDefault() <> "")
|
265
|
$can_add = false;
|
266
|
else
|
267
|
$can_add = true;
|
268
|
}
|
269
|
read_altq_config();
|
270
|
$output_form .= $tmp->build_form();
|
271
|
} else
|
272
|
$input_errors[] = gettext("Could not add new queue.");
|
273
|
} else if ($_POST['apply']) {
|
274
|
write_config();
|
275
|
|
276
|
$retval = 0;
|
277
|
$retval = filter_configure();
|
278
|
$savemsg = get_std_save_message($retval);
|
279
|
|
280
|
if (stristr($retval, "error") <> true)
|
281
|
$savemsg = get_std_save_message($retval);
|
282
|
else
|
283
|
$savemsg = $retval;
|
284
|
|
285
|
/* reset rrd queues */
|
286
|
system("rm -f /var/db/rrd/*queuedrops.rrd");
|
287
|
system("rm -f /var/db/rrd/*queues.rrd");
|
288
|
enable_rrd_graphing();
|
289
|
|
290
|
clear_subsystem_dirty('shaper');
|
291
|
|
292
|
if ($queue) {
|
293
|
$output_form .= $queue->build_form();
|
294
|
$dontshow = false;
|
295
|
}
|
296
|
else {
|
297
|
$output_form .= $default_shaper_message;
|
298
|
$dontshow = true;
|
299
|
}
|
300
|
|
301
|
} else if ($queue) {
|
302
|
$queue->validate_input($_POST, $input_errors);
|
303
|
if (!$input_errors) {
|
304
|
$queue->update_altq_queue_data($_POST);
|
305
|
$queue->wconfig();
|
306
|
if (write_config())
|
307
|
mark_subsystem_dirty('shaper');
|
308
|
$dontshow = false;
|
309
|
}
|
310
|
read_altq_config();
|
311
|
$output_form .= $queue->build_form();
|
312
|
} else {
|
313
|
$output_form .= $default_shaper_msg;
|
314
|
$dontshow = true;
|
315
|
}
|
316
|
mwexec("killall qstats");
|
317
|
} else {
|
318
|
$output_form .= $default_shaper_msg;
|
319
|
$dontshow = true;
|
320
|
}
|
321
|
|
322
|
if ($queue) {
|
323
|
if ($queue->GetEnabled())
|
324
|
$can_enable = true;
|
325
|
else
|
326
|
$can_enable = false;
|
327
|
if ($queue->CanHaveChildren() && $can_enable) {
|
328
|
if ($altq->GetQname() <> $queue->GetQname() && $queue->GetDefault() <> "")
|
329
|
$can_add = false;
|
330
|
else
|
331
|
$can_add = true;
|
332
|
} else
|
333
|
$can_add = false;
|
334
|
}
|
335
|
|
336
|
$tree = "<ul class=\"tree\" >";
|
337
|
if (is_array($altq_list_queues)) {
|
338
|
foreach ($altq_list_queues as $tmpaltq) {
|
339
|
$tree .= $tmpaltq->build_tree();
|
340
|
}
|
341
|
$tree .= get_interface_list_to_show();
|
342
|
}
|
343
|
$tree .= "</ul>";
|
344
|
|
345
|
if (!$dontshow || $newqueue) {
|
346
|
|
347
|
$output_form .= "<tr><td width=\"22%\" valign=\"middle\" class=\"vncellreq\">";
|
348
|
$output_form .= "<br />" . gettext("Queue Actions") . "<br />";
|
349
|
$output_form .= "</td><td valign=\"middle\" class=\"vncellreq\" width=\"78%\"><br />";
|
350
|
|
351
|
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
|
352
|
if ($can_add || $addnewaltq) {
|
353
|
$output_form .= "<a href=\"firewall_shaper.php?interface=";
|
354
|
$output_form .= $interface;
|
355
|
if ($queue) {
|
356
|
$output_form .= "&queue=" . $queue->GetQname();
|
357
|
}
|
358
|
$output_form .= "&action=add\">";
|
359
|
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") . "\" />";
|
360
|
$output_form .= "</a>";
|
361
|
}
|
362
|
$output_form .= "<a href=\"firewall_shaper.php?interface=";
|
363
|
$output_form .= $interface . "&queue=";
|
364
|
if ($queue) {
|
365
|
$output_form .= "&queue=" . $queue->GetQname();
|
366
|
}
|
367
|
$output_form .= "&action=delete\">";
|
368
|
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
|
369
|
if ($queue)
|
370
|
$output_form .= " value=\"" . gettext("Delete this queue") . "\" />";
|
371
|
else
|
372
|
$output_form .= " value=\"" . gettext("Disable shaper on interface") . "\" />";
|
373
|
$output_form .= "</a>";
|
374
|
$output_form .= "<br /></td></tr>";
|
375
|
$output_form .= "</table>";
|
376
|
}
|
377
|
else
|
378
|
$output_form .= "</table>";
|
379
|
|
380
|
$output = "<table summary=\"output form\">";
|
381
|
$output .= $output_form;
|
382
|
|
383
|
//$pgtitle = "Firewall: Shaper: By Interface View";
|
384
|
$closehead = false;
|
385
|
include("head.inc");
|
386
|
?>
|
387
|
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
|
388
|
<script type="text/javascript" src="./tree/tree.js"></script>
|
389
|
</head>
|
390
|
|
391
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
|
392
|
<?php
|
393
|
if ($queue)
|
394
|
echo $queue->build_javascript();
|
395
|
echo $newjavascript;
|
396
|
|
397
|
include("fbegin.inc");
|
398
|
?>
|
399
|
<div id="inputerrors"></div>
|
400
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
401
|
|
402
|
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
|
403
|
|
404
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
405
|
<?php if (is_subsystem_dirty('shaper')): ?><p>
|
406
|
<?php print_info_box_np(gettext("The traffic shaper configuration has been changed.")."<br />".gettext("You must apply the changes in order for them to take effect."));?><br /></p>
|
407
|
<?php endif; ?>
|
408
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="traffic shaper">
|
409
|
<tr><td>
|
410
|
<?php
|
411
|
$tab_array = array();
|
412
|
$tab_array[0] = array(gettext("By Interface"), true, "firewall_shaper.php");
|
413
|
$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
|
414
|
$tab_array[2] = array(gettext("Limiter"), false, "firewall_shaper_vinterface.php");
|
415
|
$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
|
416
|
$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
|
417
|
display_top_tabs($tab_array);
|
418
|
?>
|
419
|
</td></tr>
|
420
|
<tr>
|
421
|
<td>
|
422
|
<div id="mainarea">
|
423
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
|
424
|
<?php if (count($altq_list_queues) > 0): ?>
|
425
|
<tr class="tabcont"><td width="25%" align="left">
|
426
|
<a href="firewall_shaper.php?action=resetall" >
|
427
|
<input type="button" value="<?=gettext("Remove Shaper")?>" class="formbtn" />
|
428
|
</a>
|
429
|
</td><td width="75%"> </td></tr>
|
430
|
<?php endif; ?>
|
431
|
<tr>
|
432
|
<td width="25%" valign="top" align="left">
|
433
|
<?php
|
434
|
echo $tree;
|
435
|
?>
|
436
|
</td>
|
437
|
<td width="75%" valign="top" align="center">
|
438
|
<div id="shaperarea" style="position:relative">
|
439
|
<?php
|
440
|
echo $output;
|
441
|
?>
|
442
|
</div>
|
443
|
|
444
|
</td></tr>
|
445
|
</table>
|
446
|
</div>
|
447
|
</td>
|
448
|
</tr>
|
449
|
</table>
|
450
|
</form>
|
451
|
<?php include("fend.inc"); ?>
|
452
|
</body>
|
453
|
</html>
|