1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
status_queues.php
|
5
|
Part of the pfSense project
|
6
|
Copyright (C) 2004, 2005 Scott Ullrich
|
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
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
POSSIBILITY OF SUCH DAMAGE.
|
29
|
*/
|
30
|
|
31
|
require("guiconfig.inc");
|
32
|
|
33
|
if($_GET['reset'] <> "") {
|
34
|
mwexec("killall -9 pfctl pfctl");
|
35
|
Header("Location: status_queues.php");
|
36
|
exit;
|
37
|
}
|
38
|
|
39
|
if (!is_array($config['shaper']['queue'])) {
|
40
|
$config['shaper']['queue'] = array();
|
41
|
}
|
42
|
|
43
|
$a_queues = array();
|
44
|
|
45
|
$pfctl_vsq = `/sbin/pfctl -vsq`;
|
46
|
$pfctl_vsq_array = split("\n", $pfctl_vsq);
|
47
|
foreach($pfctl_vsq_array as $pfctl) {
|
48
|
if (preg_match_all("/queue\s+(\w+)\s+/",$pfctl,$match_array))
|
49
|
if(stristr($match_array[1][0],"root_")==false)
|
50
|
$a_queues[] = $match_array[1][0];
|
51
|
}
|
52
|
|
53
|
$pgtitle = "Status: Traffic Shaper: Queues";
|
54
|
include("head.inc");
|
55
|
|
56
|
?>
|
57
|
|
58
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
59
|
<?php include("fbegin.inc"); ?>
|
60
|
<p class="pgtitle"><?=$pgtitle?></p>
|
61
|
<?php
|
62
|
if(!isset($config['shaper']['enable'])) {
|
63
|
echo "Traffic shaping is currently disabled.";
|
64
|
include("fend.inc");
|
65
|
exit;
|
66
|
}
|
67
|
?>
|
68
|
|
69
|
<form action="status_queues.php" method="post">
|
70
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
71
|
<tr>
|
72
|
<td class="listhdr" colspan="1">Queue</td>
|
73
|
<td class="listhdr" colspan="6">Statistics</td>
|
74
|
</tr>
|
75
|
<?php $i = 0; foreach ($a_queues as $queue): ?>
|
76
|
<tr><td bgcolor="#DDDDDD" colspan="7"> </td></tr>
|
77
|
<tr valign="top">
|
78
|
<td bgcolor="#DDDDDD">
|
79
|
<font color="#000000"> <?echo "<a href=\"firewall_shaper_queues_edit.php?id={$queue}\">" . htmlspecialchars($queue) . "</a>";?> </td>
|
80
|
<td bgcolor="#DDDDDD">
|
81
|
<nobr>
|
82
|
<?php
|
83
|
$cpuUsage = 0;
|
84
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='15' width='4' border='0' align='absmiddle'>";
|
85
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='15' name='queue{$i}widtha' id='queue{$i}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
|
86
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='15' name='queue{$i}widthb' id='queue{$i}widthb' width='" . (400 - $cpuUsage) . "' border='0' align='absmiddle'>";
|
87
|
echo "<nobr><img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='15' width='5' border='0' align='absmiddle'> ";
|
88
|
echo "</nobr></td></tr>";
|
89
|
echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
|
90
|
echo " ";
|
91
|
echo "<nobr>";
|
92
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}pps' id='queue{$i}pps' value=' (Loading)' align='right'>";
|
93
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}bps' id='queue{$i}bps' value='' align='right'>";
|
94
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}borrows' id='queue{$i}borrows' value='' align='right'>";
|
95
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}suspends' id='queue{$i}suspends' value='' align='right'>";
|
96
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='15' name='queue{$i}drops' id='queue{$i}drops' value='' align='right'>";
|
97
|
echo "</nobr>";
|
98
|
?>
|
99
|
|
100
|
</td>
|
101
|
</tr>
|
102
|
<tr><td class="vncell" bgcolor="#DDDDDD" colspan="7"> </td></tr>
|
103
|
<?php $i++; endforeach; $total_queues = $i; ?>
|
104
|
</table>
|
105
|
<p>
|
106
|
<strong><span class="red">Note:</span></strong><strong><br></strong>
|
107
|
Queue graphs take 5 seconds to sample data.<br>
|
108
|
You can configure the Traffic Shaper <a href="firewall_shaper.php?reset=true">here</a>.
|
109
|
</p>
|
110
|
</form>
|
111
|
<br><a href="status_queues.php?reset=true">Reset</a> queues if they do not load.
|
112
|
|
113
|
<meta http-equiv="refresh" content="60;url=<?php print $_SERVER['PHP_SELF']; ?>">
|
114
|
|
115
|
<?php include("fend.inc"); ?>
|
116
|
</body>
|
117
|
</html>
|
118
|
|
119
|
<?php
|
120
|
|
121
|
sleep(3);
|
122
|
|
123
|
$counter = 0;
|
124
|
While(!Connection_Aborted()) {
|
125
|
|
126
|
$stats_array = gather_altq_queue_stats(true);
|
127
|
|
128
|
/* calculate total packets being moved through all queues. */
|
129
|
$total_packets_s = 0;
|
130
|
foreach($stats_array as $stats_line) {
|
131
|
$stat_line_split = split("\|", $stats_line);
|
132
|
$total_packets_s = $total_packets_s + intval($stat_line_split[2]);
|
133
|
}
|
134
|
|
135
|
$i = 0;
|
136
|
foreach($stats_array as $stats_line) {
|
137
|
if($stat_line_split[2] == "" and $counter > 1) {
|
138
|
mwexec("/usr/bin/killall pfctl php");
|
139
|
exit;
|
140
|
}
|
141
|
|
142
|
$stat_line_split = split("\|", $stats_line);
|
143
|
$packet_sampled = intval($stat_line_split[2]);
|
144
|
$speed = $stat_line_split[1];
|
145
|
$borrows = intval($stat_line_split[3]);
|
146
|
$suspends = intval($stat_line_split[4]);
|
147
|
$drops = intval($stat_line_split[5]);
|
148
|
|
149
|
echo "<script language='javascript'>\n";
|
150
|
|
151
|
/* Since pps can be 0, let's not divide by zero */
|
152
|
if ($total_packets_s == 0) {
|
153
|
$packet_s = round(400 * (1 - $packet_sampled / $total_packets_s), 0);
|
154
|
} else {
|
155
|
$packet_s = 0;
|
156
|
}
|
157
|
|
158
|
echo "document.queue{$i}widthb.style.width='{$packet_s}px';\n";
|
159
|
echo "document.queue{$i}widtha.style.width='" . (400 - $packet_s) . "px';\n";
|
160
|
$borrows_txt = "{$borrows} borrows";
|
161
|
$suspends_txt = "{$suspends} suspends";
|
162
|
$drops_txt = "${drops} drops";
|
163
|
echo "document.forms[0].queue{$i}pps.value = '{$packet_sampled}/pps';\n";
|
164
|
echo "document.forms[0].queue{$i}bps.value = '{$speed}';\n";
|
165
|
echo "document.forms[0].queue{$i}borrows.value = '{$borrows_txt}';\n";
|
166
|
echo "document.forms[0].queue{$i}suspends.value = '{$suspends_txt}';\n";
|
167
|
echo "document.forms[0].queue{$i}drops.value = '{$drops_txt}';\n";
|
168
|
echo "</script>\n";
|
169
|
$i++;
|
170
|
}
|
171
|
|
172
|
/*
|
173
|
* prevent user from running out of ram.
|
174
|
* firefox and ie can be a bear on ram usage!
|
175
|
*/
|
176
|
$counter++;
|
177
|
if($counter > 40) {
|
178
|
echo "Redirecting to <a href=\"status_queues.php\">Queue Status</a>.<p>";
|
179
|
echo "<meta http-equiv=\"refresh\" content=\"1;url={$_SERVER['PHP_SELF']}\">";
|
180
|
mwexec("/usr/bin/killall pfctl");
|
181
|
exit;
|
182
|
}
|
183
|
}
|
184
|
|
185
|
mwexec("/usr/bin/killall pfctl");
|
186
|
|
187
|
?>
|