1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
status_rrd_graph.php
|
5
|
Part of pfSense
|
6
|
Copyright (C) 2007 Seth Mos <seth.mos@xs4all.nl>
|
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
|
pfSense_BUILDER_BINARIES: /usr/bin/find
|
32
|
pfSense_MODULE: system
|
33
|
*/
|
34
|
|
35
|
##|+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
|
require("guiconfig.inc");
|
43
|
require_once("filter.inc");
|
44
|
require("shaper.inc");
|
45
|
require_once("rrd.inc");
|
46
|
|
47
|
/* 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
|
$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
|
if ($_GET['cat']) {
|
57
|
$curcat = $_GET['cat'];
|
58
|
} else {
|
59
|
if(! empty($config['rrd']['category'])) {
|
60
|
$curcat = $config['rrd']['category'];
|
61
|
} else {
|
62
|
$curcat = "system";
|
63
|
}
|
64
|
}
|
65
|
|
66
|
if ($_GET['option']) {
|
67
|
$curoption = $_GET['option'];
|
68
|
} else {
|
69
|
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
|
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
|
}
|
106
|
default:
|
107
|
$curoption = "wan";
|
108
|
break;
|
109
|
}
|
110
|
}
|
111
|
|
112
|
if ($_GET['style']) {
|
113
|
$curstyle = $_GET['style'];
|
114
|
} else {
|
115
|
if(! empty($config['rrd']['style'])) {
|
116
|
$curstyle = $config['rrd']['style'];
|
117
|
} else {
|
118
|
$curstyle = "inverse";
|
119
|
}
|
120
|
}
|
121
|
|
122
|
/* sort names reverse so WAN comes first */
|
123
|
rsort($databases);
|
124
|
|
125
|
/* these boilerplate databases are required for the other menu choices */
|
126
|
$dbheader = array("allgraphs-traffic.rrd",
|
127
|
"allgraphs-quality.rrd",
|
128
|
"allgraphs-wireless.rrd",
|
129
|
"allgraphs-cellular.rrd",
|
130
|
"allgraphs-packets.rrd",
|
131
|
"system-allgraphs.rrd",
|
132
|
"system-throughput.rrd",
|
133
|
"outbound-quality.rrd",
|
134
|
"outbound-packets.rrd",
|
135
|
"outbound-traffic.rrd");
|
136
|
|
137
|
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
|
/* append the existing array to the header */
|
149
|
$ui_databases = array_merge($dbheader, $databases);
|
150
|
|
151
|
$styles = array('inverse' => 'Inverse',
|
152
|
'absolute' => 'Absolute');
|
153
|
$periods = array("4h", "16h", "48h", "32d", "6m", "1y", "4y");
|
154
|
|
155
|
$pgtitle = array("Status","RRD Graphs");
|
156
|
include("head.inc");
|
157
|
|
158
|
?>
|
159
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
160
|
<?php include("fbegin.inc"); ?>
|
161
|
<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
|
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
|
if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
|
191
|
$tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
|
192
|
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
|
foreach ($ui_databases as $db => $database) {
|
210
|
if(! preg_match("/($curcat)/i", $database)) {
|
211
|
continue;
|
212
|
}
|
213
|
$optionc = split("-", $database);
|
214
|
$search = array("-", ".rrd", $optionc);
|
215
|
$replace = array(" :: ", "", $friendly);
|
216
|
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
|
if(empty($friendly)) {
|
227
|
$friendly = $optionc;
|
228
|
}
|
229
|
$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
|
}
|
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
|
foreach($ui_databases as $curdatabase) {
|
260
|
if(! preg_match("/($curcat)/i", $curdatabase)) {
|
261
|
continue;
|
262
|
}
|
263
|
$optionc = split("-", $curdatabase);
|
264
|
$search = array("-", ".rrd", $optionc);
|
265
|
$replace = array(" :: ", "", $friendly);
|
266
|
switch($curoption) {
|
267
|
case "outbound":
|
268
|
/* only show interfaces with a gateway */
|
269
|
$optionc = "$optionc[0]";
|
270
|
if(!interface_has_gateway($optionc)) {
|
271
|
if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
|
272
|
continue 2;
|
273
|
}
|
274
|
}
|
275
|
if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
|
276
|
continue 2;
|
277
|
}
|
278
|
break;
|
279
|
case "allgraphs":
|
280
|
/* 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
|
default:
|
286
|
/* just use the name here */
|
287
|
if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
|
288
|
continue 2;
|
289
|
}
|
290
|
}
|
291
|
if(in_array($curdatabase, $databases)) {
|
292
|
echo "<tr><td colspan=2 class=\"list\">\n";
|
293
|
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
|
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
|
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
|
if(!interface_has_gateway($optionc)) {
|
323
|
continue 2;
|
324
|
}
|
325
|
if(! stristr($curdatabase, $optionc)) {
|
326
|
continue 2;
|
327
|
}
|
328
|
break;
|
329
|
case "allgraphs":
|
330
|
/* 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
|
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
|
?>
|
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
|
|
360
|
<?php include("fend.inc"); ?>
|
361
|
</body>
|
362
|
</html>
|