1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
status_queues.php
|
6
|
Part of the pfSense project
|
7
|
Copyright (C) 2004, 2005 Scott Ullrich
|
8
|
Copyright (C) 2009 Ermal Lu?i
|
9
|
All rights reserved.
|
10
|
|
11
|
Redistribution and use in source and binary forms, with or without
|
12
|
modification, are permitted provided that the following conditions are met:
|
13
|
|
14
|
1. Redistributions of source code must retain the above copyright notice,
|
15
|
this list of conditions and the following disclaimer.
|
16
|
|
17
|
2. Redistributions in binary form must reproduce the above copyright
|
18
|
notice, this list of conditions and the following disclaimer in the
|
19
|
documentation and/or other materials provided with the distribution.
|
20
|
|
21
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
POSSIBILITY OF SUCH DAMAGE.
|
31
|
*/
|
32
|
/*
|
33
|
pfSense_BUILDER_BINARIES: /sbin/pfctl
|
34
|
pfSense_MODULE: shaper
|
35
|
*/
|
36
|
|
37
|
##|+PRIV
|
38
|
##|*IDENT=page-status-trafficshaper-queues
|
39
|
##|*NAME=Status: Traffic shaper: Queues page
|
40
|
##|*DESCR=Allow access to the 'Status: Traffic shaper: Queues' page.
|
41
|
##|*MATCH=status_queues.php*
|
42
|
##|-PRIV
|
43
|
|
44
|
require("guiconfig.inc");
|
45
|
|
46
|
if ($_REQUEST['getactivity']) {
|
47
|
$stats_array = gather_altq_queue_stats(true);
|
48
|
|
49
|
/* calculate total packets being moved through all queues. */
|
50
|
$total_packets_s = 0;
|
51
|
foreach($stats_array as $stats_line) {
|
52
|
$stat_line_split = split("\|", $stats_line);
|
53
|
$total_packets_s = $total_packets_s + intval($stat_line_split[2]);
|
54
|
}
|
55
|
|
56
|
$i = 0;
|
57
|
$finscript = "";
|
58
|
foreach($stats_array as $stats_line) {
|
59
|
if($stat_line_split[2] == "" and $counter > 1) {
|
60
|
continue;
|
61
|
}
|
62
|
|
63
|
$stat_line_split = split("\|", $stats_line);
|
64
|
$packet_sampled = intval($stat_line_split[2]);
|
65
|
$speed = $stat_line_split[1];
|
66
|
$borrows = intval($stat_line_split[3]);
|
67
|
$suspends = intval($stat_line_split[4]);
|
68
|
$drops = intval($stat_line_split[5]);
|
69
|
|
70
|
|
71
|
$packet_s = round(400 * (1 - $packet_sampled / $total_packets_s), 0);
|
72
|
|
73
|
$finscript .= "$('queue{$i}widthb').width='{$packet_s}';";
|
74
|
$finscript .= "$('queue{$i}widtha').width='" . (400 - $packet_s) . "';";
|
75
|
$borrows_txt = "{$borrows} borrows";
|
76
|
$suspends_txt = "{$suspends} suspends";
|
77
|
$drops_txt = "${drops} drops";
|
78
|
$finscript .= "$('queue{$i}pps').value = '{$packet_sampled}/pps';";
|
79
|
$finscript .= "$('queue{$i}bps').value = '{$speed}';";
|
80
|
$finscript .= "$('queue{$i}borrows').value = '{$borrows_txt}';";
|
81
|
$finscript .= "$('queue{$i}suspends').value = '{$suspends_txt}';";
|
82
|
$finscript .= "$('queue{$i}drops').value = '{$drops_txt}';";
|
83
|
$i++;
|
84
|
}
|
85
|
header("Content-type: text/javascript");
|
86
|
echo $finscript;
|
87
|
exit;
|
88
|
}
|
89
|
|
90
|
$a_queues = array();
|
91
|
|
92
|
exec("/sbin/pfctl -vsq", $pfctl_vsq_array);
|
93
|
foreach($pfctl_vsq_array as $pfctl) {
|
94
|
if (preg_match_all("/queue\s+(\w+)\s+(\w+)\s+(\w+)\s+/",$pfctl,$match_array)) {
|
95
|
if (stristr($match_array[1][0],"root_"))
|
96
|
continue;
|
97
|
$a_queues[] = $match_array[1][0] . " on " .
|
98
|
convert_real_interface_to_friendly_descr($match_array[3][0]);
|
99
|
}
|
100
|
}
|
101
|
|
102
|
$pgtitle = array(gettext("Status"),gettext("Traffic shaper"),gettext("Queues"));
|
103
|
include("head.inc");
|
104
|
|
105
|
?>
|
106
|
|
107
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
108
|
<?php include("fbegin.inc"); ?>
|
109
|
<?php
|
110
|
if(!is_array($config['shaper']['queue']) && count($config['shaper']['queue']) < 1) {
|
111
|
echo gettext("Traffic shaping is not configured.");
|
112
|
include("fend.inc");
|
113
|
exit;
|
114
|
}
|
115
|
?>
|
116
|
|
117
|
<form action="status_queues.php" method="post">
|
118
|
<script type="text/javascript">
|
119
|
function getqueueactivity() {
|
120
|
var url = "/status_queues.php";
|
121
|
var pars = 'getactivity=yes';
|
122
|
var myAjax = new Ajax.Request(
|
123
|
url,
|
124
|
{
|
125
|
method: 'post',
|
126
|
parameters: pars,
|
127
|
onComplete: activitycallback
|
128
|
});
|
129
|
}
|
130
|
function activitycallback(transport) {
|
131
|
setTimeout('getqueueactivity()', 5100);
|
132
|
}
|
133
|
document.observe('dom:loaded', function(){
|
134
|
setTimeout('getqueueactivity()', 150);
|
135
|
});
|
136
|
</script>
|
137
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
138
|
<tr>
|
139
|
<td class="listhdr" colspan="1"><?=gettext("Queue"); ?></td>
|
140
|
<td class="listhdr" colspan="6"><?=gettext("Statistics"); ?></td>
|
141
|
</tr>
|
142
|
<?php $i = 0; foreach ($a_queues as $queue): ?>
|
143
|
<tr><td bgcolor="#DDDDDD" colspan="7"> </td></tr>
|
144
|
<tr valign="top">
|
145
|
<td bgcolor="#DDDDDD">
|
146
|
<font color="#000000"> <?echo "<a href=\"firewall_shaper.php?id={$queue}\">" . htmlspecialchars($queue) . "</a>";?> </td>
|
147
|
<td bgcolor="#DDDDDD">
|
148
|
<nobr>
|
149
|
<?php
|
150
|
$cpuUsage = 0;
|
151
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_left.gif' height='10' width='4' border='0' align='absmiddle'>";
|
152
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_blue.gif' height='10' name='queue{$i}widtha' id='queue{$i}widtha' width='" . $cpuUsage . "' border='0' align='absmiddle'>";
|
153
|
echo "<img src='./themes/".$g['theme']."/images/misc/bar_gray.gif' height='10' name='queue{$i}widthb' id='queue{$i}widthb' width='" . (400 - $cpuUsage) . "' border='0' align='absmiddle'>";
|
154
|
echo "<nobr><img src='./themes/".$g['theme']."/images/misc/bar_right.gif' height='10' width='5' border='0' align='absmiddle'> ";
|
155
|
echo "</nobr></td></tr>";
|
156
|
echo "<tr><td bgcolor=\"#DDDDDD\" colspan=\"7\">";
|
157
|
echo " ";
|
158
|
echo "<nobr>";
|
159
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}pps' id='queue{$i}pps' value='(" . gettext("Loading") . ")' align='left'>";
|
160
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}bps' id='queue{$i}bps' value='' align='right'>";
|
161
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}borrows' id='queue{$i}borrows' value='' align='right'>";
|
162
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}suspends' id='queue{$i}suspends' value='' align='right'>";
|
163
|
echo "<input style='border: 0px solid white; background-color:#DDDDDD; color:#000000;' size='10' name='queue{$i}drops' id='queue{$i}drops' value='' align='right'>";
|
164
|
echo "</nobr>";
|
165
|
?>
|
166
|
|
167
|
</td>
|
168
|
</tr>
|
169
|
<tr><td class="vncell" bgcolor="#DDDDDD" colspan="7"> </td></tr>
|
170
|
<?php $i++; endforeach; $total_queues = $i; ?>
|
171
|
</table>
|
172
|
<p>
|
173
|
<strong><span class="red"><?=gettext("Note"); ?>:</span></strong><strong><br></strong>
|
174
|
<?=gettext("Queue graphs take 5 seconds to sample data"); ?>.<br>
|
175
|
<?=gettext("You can configure the Traffic Shaper"); ?> <a href="/firewall_shaper_wizards.php"><?=gettext("here"); ?></a>.
|
176
|
</p>
|
177
|
</form>
|
178
|
<?php include("fend.inc"); ?>
|
179
|
</body>
|
180
|
</html>
|