1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
firewall_shaper_queues.php
|
5
|
Copyright (C) 2004, 2005 Scott Ullrich
|
6
|
All rights reserved.
|
7
|
|
8
|
Originally part of m0n0wall (http://m0n0.ch/wall)
|
9
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10
|
All rights reserved.
|
11
|
|
12
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, are permitted provided that the following conditions are met:
|
14
|
|
15
|
1. Redistributions of source code must retain the above copyright notice,
|
16
|
this list of conditions and the following disclaimer.
|
17
|
|
18
|
2. Redistributions in binary form must reproduce the above copyright
|
19
|
notice, this list of conditions and the following disclaimer in the
|
20
|
documentation and/or other materials provided with the distribution.
|
21
|
|
22
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
POSSIBILITY OF SUCH DAMAGE.
|
32
|
*/
|
33
|
|
34
|
require("guiconfig.inc");
|
35
|
|
36
|
if($_GET['reset'] <> "") {
|
37
|
mwexec("killall -9 pfctl php");
|
38
|
exit;
|
39
|
}
|
40
|
|
41
|
if (!is_array($config['shaper']['queue'])) {
|
42
|
$config['shaper']['queue'] = array();
|
43
|
}
|
44
|
$a_queues = &$config['shaper']['queue'];
|
45
|
|
46
|
$iflist = array("lan" => "LAN", "wan" => "WAN");
|
47
|
|
48
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
49
|
$iflist['opt' . $i] = $config['interfaces']['opt' . $i]['descr'];
|
50
|
}
|
51
|
|
52
|
if ($_POST['apply'] || $_POST['submit']) {
|
53
|
$config['shaper']['enable'] = true;
|
54
|
write_config();
|
55
|
|
56
|
$retval = 0;
|
57
|
$savemsg = get_std_save_message($retval);
|
58
|
/* Setup pf rules since the user may have changed the optimization value */
|
59
|
//config_lock();
|
60
|
$retval = filter_configure();
|
61
|
//config_unlock();
|
62
|
if(stristr($retval, "error") <> true)
|
63
|
$savemsg = get_std_save_message($retval);
|
64
|
else
|
65
|
$savemsg = $retval;
|
66
|
|
67
|
if(file_exists($d_shaperconfdirty_path))
|
68
|
unlink($d_shaperconfdirty_path);
|
69
|
}
|
70
|
|
71
|
if ($_GET['act'] == "del") {
|
72
|
if ($a_queues[$_GET['id']]) {
|
73
|
/* check that no rule references this queue */
|
74
|
if (is_array($config['shaper']['rule'])) {
|
75
|
foreach ($config['shaper']['rule'] as $rule) {
|
76
|
if (isset($rule['targetqueue']) && ($rule['targetqueue'] == $_GET['id'])) {
|
77
|
$input_errors[] = "This queue cannot be deleted because it is still referenced by a rule.";
|
78
|
break;
|
79
|
}
|
80
|
}
|
81
|
}
|
82
|
|
83
|
if (!$input_errors) {
|
84
|
unset($a_queues[$_GET['id']]);
|
85
|
|
86
|
/* renumber all rules */
|
87
|
if (is_array($config['shaper']['rule'])) {
|
88
|
for ($i = 0; isset($config['shaper']['rule'][$i]); $i++) {
|
89
|
$currule = &$config['shaper']['rule'][$i];
|
90
|
if (isset($currule['targetqueue']) && ($currule['targetqueue'] > $_GET['id']))
|
91
|
$currule['targetqueue']--;
|
92
|
}
|
93
|
}
|
94
|
|
95
|
write_config();
|
96
|
touch($d_shaperconfdirty_path);
|
97
|
header("Location: firewall_shaper_queues.php");
|
98
|
exit;
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
?>
|
103
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
104
|
<html>
|
105
|
<head>
|
106
|
<title><?=gentitle("Firewall: Traffic shaper: Queues");?></title>
|
107
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
108
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
109
|
</head>
|
110
|
|
111
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
112
|
<?php include("fbegin.inc"); ?>
|
113
|
<p class="pgtitle">Firewall: Traffic shaper: Queues</p>
|
114
|
<form action="firewall_shaper_queues.php" method="post">
|
115
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
116
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
117
|
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
|
118
|
<?php print_info_box_np("The traffic shaper configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
|
119
|
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
|
120
|
<?php endif; ?>
|
121
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
122
|
<tr><td>
|
123
|
<ul id="tabnav">
|
124
|
<li class="tabinact"><a href="firewall_shaper.php">Rules</a></li>
|
125
|
<li class="tabact">Queues</a></li>
|
126
|
<li class="tabinact"><a href="firewall_shaper_magic.php">Magic shaper wizard</a></li>
|
127
|
</ul>
|
128
|
</td></tr>
|
129
|
<tr>
|
130
|
<td class="tabcont">
|
131
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
132
|
<tr>
|
133
|
<td width="5%" class="listhdrr">No.</td>
|
134
|
<td width="5%" class="listhdrr">Flags</td>
|
135
|
<td width="5%" class="listhdrr">Priority</td>
|
136
|
<td width="5%" class="listhdr">Default</td>
|
137
|
<td width="70%" class="listhdr">Name</td>
|
138
|
<td width="10%" class="list"></td>
|
139
|
</tr>
|
140
|
<?php $i = 0; foreach ($a_queues as $queue): ?>
|
141
|
<tr valign="top">
|
142
|
<td class="listlr">
|
143
|
<?=($i+1);?>
|
144
|
</td>
|
145
|
<td class="listlr">
|
146
|
<?php
|
147
|
if($queue['red'] <> "") echo " RED";
|
148
|
if($queue['ecn'] <> "") echo " ECN";
|
149
|
if($queue['borrow'] <> "") echo " Borrow";
|
150
|
?>
|
151
|
|
152
|
</td>
|
153
|
<td class="listr">
|
154
|
<?=$queue['priority'];?>
|
155
|
</td>
|
156
|
<td class="listr">
|
157
|
<?php
|
158
|
if($queue['defaultqueue'] <> "") {
|
159
|
echo "Yes";
|
160
|
} else {
|
161
|
echo "No";
|
162
|
}
|
163
|
?>
|
164
|
</td>
|
165
|
<td class="listbg">
|
166
|
<font color="#FFFFFF"><?=htmlspecialchars($queue['name']);?>
|
167
|
<br>
|
168
|
<?php
|
169
|
$cpuUsage = 0;
|
170
|
echo "<img src='bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
|
171
|
echo "<img src='bar_blue.gif' height='15' name='queue{$i}widtha' id='queue{$i}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
|
172
|
echo "<img src='bar_gray.gif' height='15' name='queue{$i}widthb' id='queue{$i}widthb' width='" . (100 - $cpuUsage) . "' border='0' align='absmiddle'>";
|
173
|
echo "<nobr><img src='bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
|
174
|
echo "<input style='border: 0px solid white; background-color:#990000; color:#FFFFFF;' size='25' name='queue{$i}meter' id='queue{$i}meter' value='( Loading )'></nobr>";
|
175
|
?>
|
176
|
|
177
|
</td>
|
178
|
<td valign="middle" nowrap class="list"> <a href="firewall_shaper_queues_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
|
179
|
<a href="firewall_shaper_queues.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this queue?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
|
180
|
</tr>
|
181
|
<?php $i++; endforeach; $total_queues = $i; ?>
|
182
|
<tr>
|
183
|
<td class="list" colspan="5"></td>
|
184
|
<td class="list"> <a href="firewall_shaper_queues_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
|
185
|
</tr>
|
186
|
</table>
|
187
|
<p>
|
188
|
<strong><span class="red">Note:</span></strong><strong><br></strong>
|
189
|
1) A queue can only be deleted if it is not referenced by any rules.<br>
|
190
|
2) Queue graphs take 5 seconds to sample data.
|
191
|
</td>
|
192
|
</p>
|
193
|
</tr>
|
194
|
</table>
|
195
|
</form>
|
196
|
<br><a href="firewall_shaper_queues.php?reset=true">Reset</a> queues if they do not load.
|
197
|
<?php include("fend.inc"); ?>
|
198
|
</body>
|
199
|
</html>
|
200
|
|
201
|
<?php
|
202
|
|
203
|
sleep(3);
|
204
|
|
205
|
$counter = 0;
|
206
|
While(!Connection_Aborted()) {
|
207
|
|
208
|
$stats_array = gather_altq_queue_stats(true);
|
209
|
|
210
|
/* calculate total packets being moved through all queues. */
|
211
|
$total_packets_s = 0;
|
212
|
foreach($stats_array as $stats_line) {
|
213
|
$stat_line_split = split("\|", $stats_line);
|
214
|
$total_packets_s = $total_packets_s + intval($stat_line_split[2]);
|
215
|
}
|
216
|
|
217
|
$i = 0;
|
218
|
foreach($stats_array as $stats_line) {
|
219
|
if($stat_line_split[2] == "" and $counter > 1) {
|
220
|
mwexec("/usr/bin/killall -9 pfctl php");
|
221
|
exit;
|
222
|
}
|
223
|
|
224
|
$stat_line_split = split("\|", $stats_line);
|
225
|
$packet_sampled = intval($stat_line_split[2]);
|
226
|
$speed = $stat_line_split[1];
|
227
|
$borrows = intval($stat_line_split[3]);
|
228
|
|
229
|
echo "<script language='javascript'>\n";
|
230
|
|
231
|
$packet_s = round(100 * (1 - $packet_sampled / $total_packets_s), 0);
|
232
|
|
233
|
echo "document.queue{$i}widthb.style.width='{$packet_s}';\n";
|
234
|
echo "document.queue{$i}widtha.style.width='" . (100 - $packet_s) . "';\n";
|
235
|
$borrows_txt = "";
|
236
|
if(intval($borrows > 0))
|
237
|
$borrows_txt = " - {$borrows} borrows";
|
238
|
echo "document.forms[0].queue{$i}meter.value = '" . $packet_sampled . "/pps - " . $speed . "{$borrows_txt}';\n";
|
239
|
echo "</script>\n";
|
240
|
$i++;
|
241
|
}
|
242
|
|
243
|
/*
|
244
|
* prevent user from running out of ram.
|
245
|
* firefox and ie can be a bear on ram usage!
|
246
|
*/
|
247
|
$counter++;
|
248
|
if($counter > 40) {
|
249
|
echo "Redirecting to <a href=\"firewall_shaper_queues.php\">Firewall Shaper Queues</a>.<p>";
|
250
|
echo "<meta http-equiv=\"refresh\" content=\"1;url=firewall_shaper_queues.php\">";
|
251
|
mwexec("/usr/bin/killall -9 pfctl");
|
252
|
exit;
|
253
|
}
|
254
|
}
|
255
|
|
256
|
mwexec("/usr/bin/killall -9 pfctl php");
|
257
|
|
258
|
?>
|