1 |
37285f69
|
Scott Ullrich
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
status_rrd_graph.php
|
5 |
|
|
Part of pfSense
|
6 |
69487053
|
Seth Mos
|
Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl>
|
7 |
37285f69
|
Scott Ullrich
|
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 |
1d333258
|
Scott Ullrich
|
/*
|
31 |
|
|
pfSense_BUILDER_BINARIES: /usr/bin/find
|
32 |
|
|
pfSense_MODULE: system
|
33 |
|
|
*/
|
34 |
37285f69
|
Scott Ullrich
|
|
35 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
36 |
|
|
##|*IDENT=page-status-rrdgraphs
|
37 |
|
|
##|*NAME=Status: RRD Graphs page
|
38 |
|
|
##|*DESCR=Allow access to the 'Status: RRD Graphs' page.
|
39 |
|
|
##|*MATCH=status_rrd_graph.php*
|
40 |
|
|
##|-PRIV
|
41 |
|
|
|
42 |
37285f69
|
Scott Ullrich
|
require("guiconfig.inc");
|
43 |
5208e648
|
Ermal Lu?i
|
require_once("filter.inc");
|
44 |
|
|
require("shaper.inc");
|
45 |
483e6de8
|
Scott Ullrich
|
require_once("rrd.inc");
|
46 |
37285f69
|
Scott Ullrich
|
|
47 |
70281b3a
|
Seth Mos
|
/* if the rrd graphs are not enabled redirect to settings page */
|
48 |
|
|
if(! isset($config['rrd']['enable'])) {
|
49 |
|
|
header("Location: status_rrd_graph_settings.php");
|
50 |
|
|
}
|
51 |
|
|
|
52 |
329bb764
|
Seth Mos
|
$rrddbpath = "/var/db/rrd/";
|
53 |
|
|
/* XXX: (billm) do we have an exec() type function that does this type of thing? */
|
54 |
|
|
exec("cd $rrddbpath;/usr/bin/find -name *.rrd", $databases);
|
55 |
|
|
|
56 |
89d25faf
|
Seth Mos
|
if ($_GET['cat']) {
|
57 |
|
|
$curcat = $_GET['cat'];
|
58 |
37285f69
|
Scott Ullrich
|
} else {
|
59 |
69487053
|
Seth Mos
|
if(! empty($config['rrd']['category'])) {
|
60 |
|
|
$curcat = $config['rrd']['category'];
|
61 |
|
|
} else {
|
62 |
|
|
$curcat = "system";
|
63 |
|
|
}
|
64 |
89d25faf
|
Seth Mos
|
}
|
65 |
|
|
|
66 |
|
|
if ($_GET['option']) {
|
67 |
|
|
$curoption = $_GET['option'];
|
68 |
|
|
} else {
|
69 |
329bb764
|
Seth Mos
|
switch($curcat) {
|
70 |
|
|
case "system":
|
71 |
|
|
$curoption = "processor";
|
72 |
|
|
break;
|
73 |
|
|
case "queues":
|
74 |
|
|
$curoption = "queues";
|
75 |
|
|
break;
|
76 |
|
|
case "queuedrops":
|
77 |
|
|
$curoption = "queuedrops";
|
78 |
7432ce7b
|
Seth Mos
|
break;
|
79 |
|
|
case "quality":
|
80 |
|
|
foreach($databases as $database) {
|
81 |
|
|
if(preg_match("/[-]quality\.rrd/i", $database)) {
|
82 |
|
|
/* pick off the 1st database we find that matches the quality graph */
|
83 |
|
|
$name = explode("-", $database);
|
84 |
|
|
$curoption = "$name[0]";
|
85 |
|
|
continue 2;
|
86 |
|
|
}
|
87 |
|
|
}
|
88 |
|
|
case "wireless":
|
89 |
|
|
foreach($databases as $database) {
|
90 |
|
|
if(preg_match("/[-]wireless\.rrd/i", $database)) {
|
91 |
|
|
/* pick off the 1st database we find that matches the wireless graph */
|
92 |
|
|
$name = explode("-", $database);
|
93 |
|
|
$curoption = "$name[0]";
|
94 |
|
|
continue 2;
|
95 |
|
|
}
|
96 |
|
|
}
|
97 |
|
|
case "cellular":
|
98 |
|
|
foreach($databases as $database) {
|
99 |
|
|
if(preg_match("/[-]cellular\.rrd/i", $database)) {
|
100 |
|
|
/* pick off the 1st database we find that matches the celullar graph */
|
101 |
|
|
$name = explode("-", $database);
|
102 |
|
|
$curoption = "$name[0]";
|
103 |
|
|
continue 2;
|
104 |
|
|
}
|
105 |
329bb764
|
Seth Mos
|
}
|
106 |
|
|
default:
|
107 |
|
|
$curoption = "wan";
|
108 |
|
|
break;
|
109 |
89d25faf
|
Seth Mos
|
}
|
110 |
37285f69
|
Scott Ullrich
|
}
|
111 |
|
|
|
112 |
6ab7ae50
|
Seth Mos
|
if ($_GET['style']) {
|
113 |
|
|
$curstyle = $_GET['style'];
|
114 |
37285f69
|
Scott Ullrich
|
} else {
|
115 |
69487053
|
Seth Mos
|
if(! empty($config['rrd']['style'])) {
|
116 |
|
|
$curstyle = $config['rrd']['style'];
|
117 |
|
|
} else {
|
118 |
|
|
$curstyle = "inverse";
|
119 |
|
|
}
|
120 |
37285f69
|
Scott Ullrich
|
}
|
121 |
|
|
|
122 |
329bb764
|
Seth Mos
|
/* sort names reverse so WAN comes first */
|
123 |
6ab7ae50
|
Seth Mos
|
rsort($databases);
|
124 |
37285f69
|
Scott Ullrich
|
|
125 |
9850b625
|
Seth Mos
|
/* these boilerplate databases are required for the other menu choices */
|
126 |
|
|
$dbheader = array("allgraphs-traffic.rrd",
|
127 |
|
|
"allgraphs-quality.rrd",
|
128 |
2f80d451
|
Seth Mos
|
"allgraphs-wireless.rrd",
|
129 |
ec51a222
|
thompsa
|
"allgraphs-cellular.rrd",
|
130 |
9850b625
|
Seth Mos
|
"allgraphs-packets.rrd",
|
131 |
|
|
"system-allgraphs.rrd",
|
132 |
e3d7c123
|
Seth Mos
|
"system-throughput.rrd",
|
133 |
9850b625
|
Seth Mos
|
"outbound-quality.rrd",
|
134 |
|
|
"outbound-packets.rrd",
|
135 |
|
|
"outbound-traffic.rrd");
|
136 |
|
|
|
137 |
7432ce7b
|
Seth Mos
|
foreach($databases as $database) {
|
138 |
|
|
if(stristr($database, "wireless")) {
|
139 |
|
|
$wireless = true;
|
140 |
|
|
}
|
141 |
|
|
if(stristr($database, "queues")) {
|
142 |
|
|
$queues = true;
|
143 |
|
|
}
|
144 |
|
|
if(stristr($database, "cellular")) {
|
145 |
|
|
$cellular = true;
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
9850b625
|
Seth Mos
|
/* append the existing array to the header */
|
149 |
a927edff
|
Seth Mos
|
$ui_databases = array_merge($dbheader, $databases);
|
150 |
9850b625
|
Seth Mos
|
|
151 |
89d25faf
|
Seth Mos
|
$styles = array('inverse' => 'Inverse',
|
152 |
|
|
'absolute' => 'Absolute');
|
153 |
7828fd5b
|
Seth Mos
|
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
|
154 |
6ab7ae50
|
Seth Mos
|
|
155 |
d88c6a9f
|
Scott Ullrich
|
$pgtitle = array("Status","RRD Graphs");
|
156 |
89d25faf
|
Seth Mos
|
include("head.inc");
|
157 |
6ab7ae50
|
Seth Mos
|
|
158 |
|
|
?>
|
159 |
37285f69
|
Scott Ullrich
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
160 |
|
|
<?php include("fbegin.inc"); ?>
|
161 |
89d25faf
|
Seth Mos
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
162 |
|
|
<tr>
|
163 |
|
|
<td>
|
164 |
|
|
<form name="form1" action="status_rrd_graph.php" method="get">
|
165 |
|
|
<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
|
166 |
|
|
<?php
|
167 |
|
|
$tab_array = array();
|
168 |
|
|
if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
|
169 |
|
|
$tab_array[] = array("System", $tabactive, "status_rrd_graph.php?cat=system");
|
170 |
|
|
if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
|
171 |
|
|
$tab_array[] = array("Traffic", $tabactive, "status_rrd_graph.php?cat=traffic");
|
172 |
|
|
if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
|
173 |
|
|
$tab_array[] = array("Packets", $tabactive, "status_rrd_graph.php?cat=packets");
|
174 |
|
|
if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
|
175 |
|
|
$tab_array[] = array("Quality", $tabactive, "status_rrd_graph.php?cat=quality");
|
176 |
7432ce7b
|
Seth Mos
|
if($queues) {
|
177 |
|
|
if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
|
178 |
|
|
$tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
|
179 |
|
|
if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
|
180 |
|
|
$tab_array[] = array("QueueDrops", $tabactive, "status_rrd_graph.php?cat=queuedrops");
|
181 |
|
|
}
|
182 |
|
|
if($wireless) {
|
183 |
|
|
if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
|
184 |
|
|
$tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless");
|
185 |
|
|
}
|
186 |
|
|
if($cellular) {
|
187 |
|
|
if($curcat == "cellular") { $tabactive = True; } else { $tabactive = False; }
|
188 |
|
|
$tab_array[] = array("Cellular", $tabactive, "status_rrd_graph.php?cat=cellular");
|
189 |
|
|
}
|
190 |
69487053
|
Seth Mos
|
if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
|
191 |
|
|
$tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
|
192 |
89d25faf
|
Seth Mos
|
display_top_tabs($tab_array);
|
193 |
|
|
?>
|
194 |
|
|
</td>
|
195 |
|
|
</tr>
|
196 |
|
|
<tr>
|
197 |
|
|
<td>
|
198 |
|
|
<div id="mainarea">
|
199 |
|
|
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
|
200 |
|
|
<tr>
|
201 |
|
|
<td colspan="2" class="list"><p><b><?=gettext("Note: Change of color and/or style may not take effect until the next refresh");?></b></p></td>
|
202 |
|
|
</tr>
|
203 |
|
|
<tr>
|
204 |
|
|
<td colspan="2" class="list">
|
205 |
|
|
<?=gettext("Graphs:");?>
|
206 |
|
|
<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
|
207 |
|
|
<?php
|
208 |
|
|
|
209 |
a927edff
|
Seth Mos
|
foreach ($ui_databases as $db => $database) {
|
210 |
2ab73e04
|
Seth Mos
|
if(! preg_match("/($curcat)/i", $database)) {
|
211 |
89d25faf
|
Seth Mos
|
continue;
|
212 |
|
|
}
|
213 |
|
|
$optionc = split("-", $database);
|
214 |
|
|
$search = array("-", ".rrd", $optionc);
|
215 |
35551994
|
Seth Mos
|
$replace = array(" :: ", "", $friendly);
|
216 |
9850b625
|
Seth Mos
|
switch($curcat) {
|
217 |
|
|
case "system":
|
218 |
|
|
$optionc = str_replace($search, $replace, $optionc[1]);
|
219 |
|
|
echo "<option value=\"$optionc\"";
|
220 |
|
|
$prettyprint = ucwords(str_replace($search, $replace, $optionc));
|
221 |
|
|
break;
|
222 |
|
|
default:
|
223 |
|
|
/* Deduce a interface if possible and use the description */
|
224 |
|
|
$optionc = "$optionc[0]";
|
225 |
|
|
$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
|
226 |
d9699f96
|
Seth Mos
|
if(empty($friendly)) {
|
227 |
|
|
$friendly = $optionc;
|
228 |
|
|
}
|
229 |
9850b625
|
Seth Mos
|
$search = array("-", ".rrd", $optionc);
|
230 |
|
|
$replace = array(" :: ", "", $friendly);
|
231 |
|
|
echo "<option value=\"$optionc\"";
|
232 |
|
|
$prettyprint = ucwords(str_replace($search, $replace, $friendly));
|
233 |
|
|
}
|
234 |
|
|
if($curoption == $optionc) {
|
235 |
|
|
echo " selected ";
|
236 |
89d25faf
|
Seth Mos
|
}
|
237 |
|
|
echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
?>
|
241 |
|
|
</select>
|
242 |
|
|
|
243 |
|
|
<?=gettext("Style:");?>
|
244 |
|
|
<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
|
245 |
|
|
<?php
|
246 |
|
|
foreach ($styles as $style => $styled) {
|
247 |
|
|
echo "<option value=\"$style\"";
|
248 |
|
|
if ($style == $curstyle) echo " selected";
|
249 |
|
|
echo ">" . htmlspecialchars($styled) . "</option>\n";
|
250 |
|
|
}
|
251 |
|
|
?>
|
252 |
|
|
|
253 |
|
|
</select>
|
254 |
|
|
|
255 |
|
|
<?php
|
256 |
|
|
|
257 |
|
|
foreach($periods as $period => $interval) {
|
258 |
|
|
/* check which databases are valid for our category */
|
259 |
a927edff
|
Seth Mos
|
foreach($ui_databases as $curdatabase) {
|
260 |
2ab73e04
|
Seth Mos
|
if(! preg_match("/($curcat)/i", $curdatabase)) {
|
261 |
89d25faf
|
Seth Mos
|
continue;
|
262 |
|
|
}
|
263 |
35551994
|
Seth Mos
|
$optionc = split("-", $curdatabase);
|
264 |
|
|
$search = array("-", ".rrd", $optionc);
|
265 |
|
|
$replace = array(" :: ", "", $friendly);
|
266 |
89d25faf
|
Seth Mos
|
switch($curoption) {
|
267 |
|
|
case "outbound":
|
268 |
|
|
/* only show interfaces with a gateway */
|
269 |
35551994
|
Seth Mos
|
$optionc = "$optionc[0]";
|
270 |
2e76e612
|
Seth Mos
|
if(!interface_has_gateway($optionc)) {
|
271 |
a927edff
|
Seth Mos
|
if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
|
272 |
|
|
continue 2;
|
273 |
|
|
}
|
274 |
35551994
|
Seth Mos
|
}
|
275 |
2ab73e04
|
Seth Mos
|
if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
|
276 |
89d25faf
|
Seth Mos
|
continue 2;
|
277 |
|
|
}
|
278 |
9850b625
|
Seth Mos
|
break;
|
279 |
89d25faf
|
Seth Mos
|
case "allgraphs":
|
280 |
9850b625
|
Seth Mos
|
/* make sure we do not show the placeholder databases in the all view */
|
281 |
|
|
if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
|
282 |
|
|
continue 2;
|
283 |
|
|
}
|
284 |
|
|
break;
|
285 |
89d25faf
|
Seth Mos
|
default:
|
286 |
|
|
/* just use the name here */
|
287 |
2ab73e04
|
Seth Mos
|
if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
|
288 |
89d25faf
|
Seth Mos
|
continue 2;
|
289 |
|
|
}
|
290 |
|
|
}
|
291 |
e3d7c123
|
Seth Mos
|
if(in_array($curdatabase, $databases)) {
|
292 |
89d25faf
|
Seth Mos
|
echo "<tr><td colspan=2 class=\"list\">\n";
|
293 |
683bf031
|
Seth Mos
|
echo "<IMG BORDER='0' name='{$interval}-{$curoption}-{$curdatabase}' ";
|
294 |
|
|
echo "id='{$interval}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
|
295 |
|
|
echo "SRC=\"status_rrd_graph_img.php?interval=$interval&database={$curdatabase}&style={$curstyle}\" />\n";
|
296 |
89d25faf
|
Seth Mos
|
echo "<br /><hr><br />\n";
|
297 |
|
|
echo "</td></tr>\n";
|
298 |
|
|
}
|
299 |
|
|
}
|
300 |
|
|
}
|
301 |
|
|
?>
|
302 |
|
|
</td>
|
303 |
|
|
</tr>
|
304 |
|
|
<tr>
|
305 |
|
|
<td colspan=2 class="list">
|
306 |
|
|
<script language="javascript">
|
307 |
|
|
function update_graph_images() {
|
308 |
|
|
//alert('updating');
|
309 |
|
|
var randomid = Math.floor(Math.random()*11);
|
310 |
|
|
<?php
|
311 |
683bf031
|
Seth Mos
|
foreach($periods as $period => $interval) {
|
312 |
|
|
/* check which databases are valid for our category */
|
313 |
|
|
foreach($databases as $curdatabase) {
|
314 |
|
|
if(! stristr($curdatabase, $curcat)) {
|
315 |
|
|
continue;
|
316 |
|
|
}
|
317 |
|
|
$optionc = split("-", $curdatabase);
|
318 |
|
|
$search = array("-", ".rrd", $optionc);
|
319 |
|
|
$replace = array(" :: ", "", $friendly);
|
320 |
|
|
switch($curoption) {
|
321 |
|
|
case "outbound":
|
322 |
2e76e612
|
Seth Mos
|
if(!interface_has_gateway($optionc)) {
|
323 |
683bf031
|
Seth Mos
|
continue 2;
|
324 |
|
|
}
|
325 |
|
|
if(! stristr($curdatabase, $optionc)) {
|
326 |
|
|
continue 2;
|
327 |
|
|
}
|
328 |
9850b625
|
Seth Mos
|
break;
|
329 |
683bf031
|
Seth Mos
|
case "allgraphs":
|
330 |
9850b625
|
Seth Mos
|
/* make sure we do not show the placeholder databases in the all view */
|
331 |
|
|
if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
|
332 |
|
|
continue 2;
|
333 |
|
|
}
|
334 |
|
|
break;
|
335 |
683bf031
|
Seth Mos
|
default:
|
336 |
|
|
/* just use the name here */
|
337 |
|
|
if(! stristr($curdatabase, $curoption)) {
|
338 |
|
|
continue 2;
|
339 |
|
|
}
|
340 |
|
|
}
|
341 |
|
|
/* generate update events utilizing prototype $('') feature */
|
342 |
|
|
echo "\n";
|
343 |
|
|
echo "\t\t\$('{$interval}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?interval={$interval}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n";
|
344 |
|
|
}
|
345 |
|
|
}
|
346 |
89d25faf
|
Seth Mos
|
?>
|
347 |
|
|
window.setTimeout('update_graph_images()', 355000);
|
348 |
|
|
}
|
349 |
|
|
window.setTimeout('update_graph_images()', 355000);
|
350 |
|
|
</script>
|
351 |
|
|
</form>
|
352 |
|
|
</td>
|
353 |
|
|
</tr>
|
354 |
|
|
</table>
|
355 |
|
|
</div>
|
356 |
|
|
</td>
|
357 |
|
|
</tr>
|
358 |
|
|
</table>
|
359 |
37285f69
|
Scott Ullrich
|
|
360 |
|
|
<?php include("fend.inc"); ?>
|
361 |
|
|
</body>
|
362 |
|
|
</html>
|