1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_shaper_vinterface.php
|
5
|
Copyright (C) 2004, 2005 Scott Ullrich
|
6
|
Copyright (C) 2008 Ermal Luçi
|
7
|
All rights reserved.
|
8
|
|
9
|
Redistribution and use in source and binary forms, with or without
|
10
|
modification, are permitted provided that the following conditions are met:
|
11
|
|
12
|
1. Redistributions of source code must retain the above copyright notice,
|
13
|
this list of conditions and the following disclaimer.
|
14
|
|
15
|
2. Redistributions in binary form must reproduce the above copyright
|
16
|
notice, this list of conditions and the following disclaimer in the
|
17
|
documentation and/or other materials provided with the distribution.
|
18
|
|
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-limiter
|
38
|
##|*NAME=Firewall: Traffic Shaper: Limiter page
|
39
|
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper: Limiter' page.
|
40
|
##|*MATCH=firewall_shaper_vinterface.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
require("guiconfig.inc");
|
44
|
require_once("functions.inc");
|
45
|
require_once("filter.inc");
|
46
|
require_once("shaper.inc");
|
47
|
|
48
|
if($_GET['reset'] <> "") {
|
49
|
mwexec("/usr/bin/killall -9 pfctl");
|
50
|
exit;
|
51
|
}
|
52
|
|
53
|
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"), gettext("Limiter"));
|
54
|
$shortcut_section = "trafficshaper-limiters";
|
55
|
|
56
|
read_dummynet_config();
|
57
|
/*
|
58
|
* The whole logic in these code maybe can be specified.
|
59
|
* If you find a better way contact me :).
|
60
|
*/
|
61
|
|
62
|
if ($_GET) {
|
63
|
if ($_GET['queue'])
|
64
|
$qname = htmlspecialchars(trim($_GET['queue']));
|
65
|
if ($_GET['pipe'])
|
66
|
$pipe = htmlspecialchars(trim($_GET['pipe']));
|
67
|
if ($_GET['action'])
|
68
|
$action = htmlspecialchars($_GET['action']);
|
69
|
}
|
70
|
if ($_POST) {
|
71
|
if ($_POST['name'])
|
72
|
$qname = htmlspecialchars(trim($_POST['name']));
|
73
|
else if ($_POST['newname'])
|
74
|
$qname = htmlspecialchars(trim($_POST['newname']));
|
75
|
if ($_POST['pipe'])
|
76
|
$pipe = htmlspecialchars(trim($_POST['pipe']));
|
77
|
else
|
78
|
$pipe = htmlspecialchars(trim($qname));
|
79
|
if ($_POST['parentqueue'])
|
80
|
$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
|
81
|
}
|
82
|
|
83
|
if ($pipe) {
|
84
|
$dnpipe = $dummynet_pipe_list[$pipe];
|
85
|
if ($dnpipe) {
|
86
|
$queue =& $dnpipe->find_queue($pipe, $qname);
|
87
|
} else $addnewpipe = true;
|
88
|
}
|
89
|
|
90
|
$dontshow = false;
|
91
|
$newqueue = false;
|
92
|
$output_form = "";
|
93
|
|
94
|
if ($_GET) {
|
95
|
switch ($action) {
|
96
|
case "delete":
|
97
|
if ($queue) {
|
98
|
if (is_array($config['filter']['rule'])) {
|
99
|
foreach ($config['filter']['rule'] as $rule) {
|
100
|
if ($rule['dnpipe'] == $queue->GetQname() || $rule['pdnpipe'] == $queue->GetQname())
|
101
|
$input_errors[] = gettext("This pipe/queue is referenced in filter rules, please remove references from there before deleting.");
|
102
|
}
|
103
|
}
|
104
|
if (!$input_errors) {
|
105
|
$queue->delete_queue();
|
106
|
if (write_config())
|
107
|
mark_subsystem_dirty('shaper');
|
108
|
header("Location: firewall_shaper_vinterface.php");
|
109
|
exit;
|
110
|
}
|
111
|
$output_form .= $queue->build_form();
|
112
|
} else {
|
113
|
$input_errors[] = sprintf(gettext("No queue with name %s was found!"),$qname);
|
114
|
$output_form .= $dn_default_shaper_msg;
|
115
|
$dontshow = true;
|
116
|
}
|
117
|
break;
|
118
|
case "resetall":
|
119
|
foreach ($dummynet_pipe_list as $dn)
|
120
|
$dn->delete_queue();
|
121
|
unset($dummynet_pipe_list);
|
122
|
$dummynet_pipe_list = array();
|
123
|
unset($config['dnshaper']['queue']);
|
124
|
unset($queue);
|
125
|
unset($pipe);
|
126
|
$can_add = false;
|
127
|
$can_enable = false;
|
128
|
$dontshow = true;
|
129
|
foreach ($config['filter']['rule'] as $key => $rule) {
|
130
|
if (isset($rule['dnpipe']))
|
131
|
unset($config['filter']['rule'][$key]['dnpipe']);
|
132
|
if (isset($rule['pdnpipe']))
|
133
|
unset($config['filter']['rule'][$key]['pdnpipe']);
|
134
|
}
|
135
|
if (write_config()) {
|
136
|
$retval = 0;
|
137
|
$retval = filter_configure();
|
138
|
$savemsg = get_std_save_message($retval);
|
139
|
|
140
|
if (stristr($retval, "error") <> true)
|
141
|
$savemsg = get_std_save_message($retval);
|
142
|
else
|
143
|
$savemsg = $retval;
|
144
|
} else
|
145
|
$savemsg = gettext("Unable to write config.xml (Access Denied?)");
|
146
|
$output_form = $dn_default_shaper_message;
|
147
|
|
148
|
break;
|
149
|
case "add":
|
150
|
if ($dnpipe) {
|
151
|
$q = new dnqueue_class();
|
152
|
$q->SetPipe($pipe);
|
153
|
$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
|
154
|
$output_form .= " value=\"".$pipe."\" />";
|
155
|
} else if ($addnewpipe) {
|
156
|
$q = new dnpipe_class();
|
157
|
$q->SetQname($pipe);
|
158
|
} else
|
159
|
$input_errors[] = gettext("Could not create new queue/discipline!");
|
160
|
|
161
|
if ($q) {
|
162
|
$output_form .= $q->build_form();
|
163
|
$newjavascript = $q->build_javascript();
|
164
|
unset($q);
|
165
|
$newqueue = true;
|
166
|
}
|
167
|
break;
|
168
|
case "show":
|
169
|
if ($queue)
|
170
|
$output_form .= $queue->build_form();
|
171
|
else
|
172
|
$input_errors[] = gettext("Queue not found!");
|
173
|
break;
|
174
|
case "enable":
|
175
|
if ($queue) {
|
176
|
$queue->SetEnabled("on");
|
177
|
$output_form .= $queue->build_form();
|
178
|
$queue->wconfig();
|
179
|
if (write_config())
|
180
|
mark_subsystem_dirty('shaper');
|
181
|
} else
|
182
|
$input_errors[] = gettext("Queue not found!");
|
183
|
break;
|
184
|
case "disable":
|
185
|
if ($queue) {
|
186
|
$queue->SetEnabled("");
|
187
|
$output_form .= $queue->build_form();
|
188
|
$queue->wconfig();
|
189
|
if (write_config())
|
190
|
mark_subsystem_dirty('shaper');
|
191
|
} else
|
192
|
$input_errors[] = gettext("Queue not found!");
|
193
|
break;
|
194
|
default:
|
195
|
$output_form .= $dn_default_shaper_msg;
|
196
|
$dontshow = true;
|
197
|
break;
|
198
|
}
|
199
|
} else if ($_POST) {
|
200
|
unset($input_errors);
|
201
|
|
202
|
if ($addnewpipe) {
|
203
|
if (!empty($dummynet_pipe_list[$qname]))
|
204
|
$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
|
205
|
else {
|
206
|
$dnpipe =& new dnpipe_class();
|
207
|
|
208
|
$dnpipe->ReadConfig($_POST);
|
209
|
$dnpipe->validate_input($_POST, $input_errors);
|
210
|
if (!$input_errors) {
|
211
|
$number = dnpipe_find_nextnumber();
|
212
|
$dnpipe->SetNumber($number);
|
213
|
unset($tmppath);
|
214
|
$tmppath[] = $dnpipe->GetQname();
|
215
|
$dnpipe->SetLink($tmppath);
|
216
|
$dnpipe->wconfig();
|
217
|
if (write_config())
|
218
|
mark_subsystem_dirty('shaper');
|
219
|
$can_enable = true;
|
220
|
$can_add = true;
|
221
|
}
|
222
|
|
223
|
read_dummynet_config();
|
224
|
$output_form .= $dnpipe->build_form();
|
225
|
$newjavascript = $dnpipe->build_javascript();
|
226
|
}
|
227
|
} else if ($parentqueue) { /* Add a new queue */
|
228
|
if (!empty($dummynet_pipe_list[$qname]))
|
229
|
$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
|
230
|
else if ($dnpipe) {
|
231
|
$tmppath =& $dnpipe->GetLink();
|
232
|
array_push($tmppath, $qname);
|
233
|
$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, $input_errors);
|
234
|
if (!$input_errors) {
|
235
|
array_pop($tmppath);
|
236
|
$tmp->wconfig();
|
237
|
if (write_config()) {
|
238
|
$can_enable = true;
|
239
|
$can_add = false;
|
240
|
mark_subsystem_dirty('shaper');
|
241
|
}
|
242
|
}
|
243
|
read_dummynet_config();
|
244
|
$output_form .= $tmp->build_form();
|
245
|
} else
|
246
|
$input_errors[] = gettext("Could not add new queue.");
|
247
|
} else if ($_POST['apply']) {
|
248
|
write_config();
|
249
|
|
250
|
$retval = 0;
|
251
|
$retval = filter_configure();
|
252
|
$savemsg = get_std_save_message($retval);
|
253
|
|
254
|
if (stristr($retval, "error") <> true)
|
255
|
$savemsg = get_std_save_message($retval);
|
256
|
else
|
257
|
$savemsg = $retval;
|
258
|
|
259
|
/* XXX: TODO Make dummynet pretty graphs */
|
260
|
// enable_rrd_graphing();
|
261
|
|
262
|
clear_subsystem_dirty('shaper');
|
263
|
|
264
|
if ($queue) {
|
265
|
$output_form .= $queue->build_form();
|
266
|
$dontshow = false;
|
267
|
}
|
268
|
else {
|
269
|
$output_form .= $dn_default_shaper_message;
|
270
|
$dontshow = true;
|
271
|
}
|
272
|
|
273
|
} else if ($queue) {
|
274
|
$queue->validate_input($_POST, $input_errors);
|
275
|
if (!$input_errors) {
|
276
|
$queue->update_dn_data($_POST);
|
277
|
$queue->wconfig();
|
278
|
if (write_config())
|
279
|
mark_subsystem_dirty('shaper');
|
280
|
$dontshow = false;
|
281
|
}
|
282
|
read_dummynet_config();
|
283
|
$output_form .= $queue->build_form();
|
284
|
} else {
|
285
|
$output_form .= $dn_default_shaper_msg;
|
286
|
$dontshow = true;
|
287
|
}
|
288
|
} else {
|
289
|
$output_form .= $dn_default_shaper_msg;
|
290
|
$dontshow = true;
|
291
|
}
|
292
|
|
293
|
if ($queue) {
|
294
|
if ($queue->GetEnabled())
|
295
|
$can_enable = true;
|
296
|
else
|
297
|
$can_enable = false;
|
298
|
if ($queue->CanHaveChildren()) {
|
299
|
$can_add = true;
|
300
|
} else
|
301
|
$can_add = false;
|
302
|
}
|
303
|
|
304
|
$tree = "<ul class=\"tree\" >";
|
305
|
if (is_array($dummynet_pipe_list)) {
|
306
|
foreach ($dummynet_pipe_list as $tmpdn) {
|
307
|
$tree .= $tmpdn->build_tree();
|
308
|
}
|
309
|
}
|
310
|
$tree .= "</ul>";
|
311
|
|
312
|
if (!$dontshow || $newqueue) {
|
313
|
|
314
|
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
|
315
|
$output_form .= gettext("Queue Actions");
|
316
|
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
|
317
|
|
318
|
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
|
319
|
if ($can_add || $addnewaltq) {
|
320
|
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
|
321
|
$output_form .= $pipe;
|
322
|
if ($queue) {
|
323
|
$output_form .= "&queue=" . $queue->GetQname();
|
324
|
}
|
325
|
$output_form .= "&action=add\">";
|
326
|
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") ."\" />";
|
327
|
$output_form .= "</a>";
|
328
|
}
|
329
|
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
|
330
|
$output_form .= $pipe;
|
331
|
if ($queue) {
|
332
|
$output_form .= "&queue=" . $queue->GetQname();
|
333
|
}
|
334
|
$output_form .= "&action=delete\">";
|
335
|
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
|
336
|
if ($queue)
|
337
|
$output_form .= " value=\"" . gettext("Delete this queue") ."\" />";
|
338
|
else
|
339
|
$output_form .= " value=\"" . gettext("Delete Limiter") ."\" />";
|
340
|
$output_form .= "</a>";
|
341
|
$output_form .= "</td></tr>";
|
342
|
$output_form .= "</table>";
|
343
|
}
|
344
|
else
|
345
|
$output_form .= "</table>";
|
346
|
|
347
|
$output = "<table summary=\"output form\">";
|
348
|
$output .= $output_form;
|
349
|
$closehead = false;
|
350
|
include("head.inc");
|
351
|
?>
|
352
|
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
|
353
|
<script type="text/javascript" src="./tree/tree.js"></script>
|
354
|
<script type="text/javascript">
|
355
|
//<![CDATA[
|
356
|
function show_source_port_range() {
|
357
|
document.getElementById("sprtable").style.display = '';
|
358
|
document.getElementById("sprtable1").style.display = '';
|
359
|
document.getElementById("sprtable2").style.display = '';
|
360
|
document.getElementById("sprtable5").style.display = '';
|
361
|
document.getElementById("sprtable4").style.display = 'none';
|
362
|
document.getElementById("showadvancedboxspr").innerHTML='';
|
363
|
}
|
364
|
//]]>
|
365
|
</script>
|
366
|
</head>
|
367
|
|
368
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
369
|
|
370
|
<?php
|
371
|
if ($queue)
|
372
|
echo $queue->build_javascript();
|
373
|
else
|
374
|
echo $newjavascript;
|
375
|
|
376
|
include("fbegin.inc");
|
377
|
?>
|
378
|
<div id="inputerrors"></div>
|
379
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
380
|
|
381
|
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
|
382
|
|
383
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
384
|
<?php if (is_subsystem_dirty('shaper')): ?><p>
|
385
|
<?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>
|
386
|
<?php endif; ?>
|
387
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="traffic shaper limiter">
|
388
|
<tr><td>
|
389
|
<?php
|
390
|
$tab_array = array();
|
391
|
$tab_array[0] = array(gettext("By Interface"), false, "firewall_shaper.php");
|
392
|
$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
|
393
|
$tab_array[2] = array(gettext("Limiter"), true, "firewall_shaper_vinterface.php");
|
394
|
$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
|
395
|
$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
|
396
|
display_top_tabs($tab_array);
|
397
|
?>
|
398
|
</td></tr>
|
399
|
<tr>
|
400
|
<td>
|
401
|
<div id="mainarea">
|
402
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
|
403
|
<?php if (count($dummynet_pipe_list) > 0): ?>
|
404
|
<tr class="tabcont"><td width="25%" align="left">
|
405
|
</td><td width="75%"> </td></tr>
|
406
|
<?php endif; ?>
|
407
|
<tr>
|
408
|
<td width="25%" valign="top" align="left">
|
409
|
<?php
|
410
|
echo $tree;
|
411
|
?>
|
412
|
<br /><br />
|
413
|
<a href="firewall_shaper_vinterface.php?pipe=new&action=add">
|
414
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("Create new limiter");?>" width="17" height="17" border="0" alt="add" /> <?=gettext("Create new limiter");?>
|
415
|
</a><br />
|
416
|
</td>
|
417
|
<td width="75%" valign="top" align="center">
|
418
|
<div id="shaperarea" style="position:relative">
|
419
|
<?php
|
420
|
echo $output;
|
421
|
?>
|
422
|
</div>
|
423
|
|
424
|
</td></tr>
|
425
|
</table>
|
426
|
</div>
|
427
|
</td>
|
428
|
</tr>
|
429
|
</table>
|
430
|
</form>
|
431
|
<script type='text/javascript'>
|
432
|
//<![CDATA[
|
433
|
<?php
|
434
|
$totalrows = 0;
|
435
|
if (is_array($config['dnshaper']) && is_array($config['dnshaper']['queue']))
|
436
|
$totalrows = count($config['dnshaper']['queue']);
|
437
|
echo "totalrows = {$totalrows}";
|
438
|
?>
|
439
|
//]]>
|
440
|
</script>
|
441
|
<?php include("fend.inc"); ?>
|
442
|
</body>
|
443
|
</html>
|