Project

General

Profile

Download (15.3 KB) Statistics
| Branch: | Tag: | Revision:
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_MODULE:	system
32
*/
33 37285f69 Scott Ullrich
34 6b07c15a Matthew Grooms
##|+PRIV
35
##|*IDENT=page-status-rrdgraphs
36
##|*NAME=Status: RRD Graphs page
37
##|*DESCR=Allow access to the 'Status: RRD Graphs' page.
38
##|*MATCH=status_rrd_graph.php*
39
##|-PRIV
40
41 37285f69 Scott Ullrich
require("guiconfig.inc");
42 5208e648 Ermal Lu?i
require_once("filter.inc");
43
require("shaper.inc");
44 483e6de8 Scott Ullrich
require_once("rrd.inc");
45 37285f69 Scott Ullrich
46 70281b3a Seth Mos
/* if the rrd graphs are not enabled redirect to settings page */
47
if(! isset($config['rrd']['enable'])) {
48
	header("Location: status_rrd_graph_settings.php");
49
}
50
51 329bb764 Seth Mos
$rrddbpath = "/var/db/rrd/";
52 002bc4ab smos
chdir($rrddbpath);
53
$databases = glob("*.rrd");
54
55 329bb764 Seth Mos
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 7d906758 smos
if ($_GET['period']) {
67
	$curperiod = $_GET['period'];
68
} else {
69
	$curperiod = "current";
70
}
71
72 89d25faf Seth Mos
if ($_GET['option']) {
73
	$curoption = $_GET['option'];
74
} else {
75 329bb764 Seth Mos
	switch($curcat) {
76
		case "system":
77
			$curoption = "processor";
78
			break;
79
		case "queues":
80
			$curoption = "queues";
81
			break;
82
		case "queuedrops":
83
			$curoption = "queuedrops";
84 7432ce7b Seth Mos
			break;
85
		case "quality":
86
			foreach($databases as $database) {
87
				if(preg_match("/[-]quality\.rrd/i", $database)) {
88
					/* pick off the 1st database we find that matches the quality graph */
89
					$name = explode("-", $database);
90
					$curoption = "$name[0]";
91
					continue 2;
92
				}
93
			}
94
		case "wireless":
95
			foreach($databases as $database) {
96
				if(preg_match("/[-]wireless\.rrd/i", $database)) {
97
					/* pick off the 1st database we find that matches the wireless graph */
98
					$name = explode("-", $database);
99
					$curoption = "$name[0]";
100
					continue 2;
101
				}
102
			}
103
		case "cellular":
104
			foreach($databases as $database) {
105
				if(preg_match("/[-]cellular\.rrd/i", $database)) {
106
					/* pick off the 1st database we find that matches the celullar graph */
107
					$name = explode("-", $database);
108
					$curoption = "$name[0]";
109
					continue 2;
110
				}
111 329bb764 Seth Mos
			}
112
		default:
113
			$curoption = "wan";
114
			break;
115 89d25faf Seth Mos
	}
116 37285f69 Scott Ullrich
}
117
118 47e68f48 smos
if($curcat == "custom") {
119
	if (is_numeric($_GET['start'])) {
120
			if($start < ($now - (3600 * 24 * 365 * 5))) {
121
					$start = $now - (4 * 3600);
122
			}
123
			$start = $_GET['start'];
124
	} else {
125
			$start = $now - (4 * 3600);
126
	}
127
}
128
129
if (is_numeric($_GET['end'])) {
130
        $end = $_GET['end'];
131
} else {
132
        $end = $now;
133
}
134
135
/* this should never happen */
136
if($end < $start) {
137
        $end = $now;
138
}
139
140
$seconds = $end - $start;
141
					
142 6ab7ae50 Seth Mos
if ($_GET['style']) {
143
	$curstyle = $_GET['style'];
144 37285f69 Scott Ullrich
} else {
145 69487053 Seth Mos
	if(! empty($config['rrd']['style'])) {
146
		$curstyle = $config['rrd']['style'];
147
	} else {
148
		$curstyle = "inverse";
149
	}
150 37285f69 Scott Ullrich
}
151
152 329bb764 Seth Mos
/* sort names reverse so WAN comes first */
153 6ab7ae50 Seth Mos
rsort($databases);
154 37285f69 Scott Ullrich
155 9850b625 Seth Mos
/* these boilerplate databases are required for the other menu choices */
156
$dbheader = array("allgraphs-traffic.rrd",
157
		"allgraphs-quality.rrd",
158 2f80d451 Seth Mos
		"allgraphs-wireless.rrd",
159 ec51a222 thompsa
		"allgraphs-cellular.rrd",
160 9850b625 Seth Mos
		"allgraphs-packets.rrd",
161
		"system-allgraphs.rrd",
162 e3d7c123 Seth Mos
		"system-throughput.rrd",
163 9850b625 Seth Mos
		"outbound-quality.rrd",
164
		"outbound-packets.rrd",
165
		"outbound-traffic.rrd");
166
167 7432ce7b Seth Mos
foreach($databases as $database) {
168
	if(stristr($database, "wireless")) {
169
		$wireless = true;
170
	}
171
	if(stristr($database, "queues")) {
172
		$queues = true;
173
	}
174
	if(stristr($database, "cellular")) {
175
		$cellular = true;
176
	}
177
}
178 9850b625 Seth Mos
/* append the existing array to the header */
179 a927edff Seth Mos
$ui_databases = array_merge($dbheader, $databases);
180 9850b625 Seth Mos
181 89d25faf Seth Mos
$styles = array('inverse' => 'Inverse',
182
		'absolute' => 'Absolute');
183 7d906758 smos
$graphs = array("day", "week", "month", "quarter", "year", "4year");
184
$periods = array("current" => "Current Period", "previous" => "Previous Period");
185 6ab7ae50 Seth Mos
186 d88c6a9f Scott Ullrich
$pgtitle = array("Status","RRD Graphs");
187 89d25faf Seth Mos
include("head.inc");
188 6ab7ae50 Seth Mos
189 7d906758 smos
function get_dates($curperiod, $graph) {
190
	$now = time();
191
	$end = $now;
192
	$curyear = date('Y', $now);
193
	$curmonth = date('m', $now);
194
	$curweek = date('W', $now);
195
	$curweekday = date('w', $now);
196
	$curday = date('d', $now);
197
198
	switch($curperiod) {
199
		case "previous":
200
			$offset = -1;
201
			break;
202
		default:
203
			$offset = 0;
204
	}
205
	switch($graph) {
206
		case "day":
207 6a8cf738 smos
			$start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear);
208
			$end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear);
209 7d906758 smos
			break;
210
		case "week":
211 002bc4ab smos
			$start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $offset), $curyear);
212
			$end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + 7), $curyear);
213 7d906758 smos
			break;
214
		case "month":
215 6a8cf738 smos
			$start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear);
216
			$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
217 7d906758 smos
			break;
218
		case "quarter":
219 6a8cf738 smos
			$start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear);
220
			$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
221 7d906758 smos
			break;
222
		case "year":
223 6a8cf738 smos
			$start = mktime(0, 0, 0, 1, 0, ($curyear + $offset));
224 0423bf2c smos
			$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
225 7d906758 smos
			break;
226 6a8cf738 smos
		case "4year": 
227
			$start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset));
228 0423bf2c smos
			$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
229 7d906758 smos
			break;
230
	}
231 6a8cf738 smos
	// echo "start $start ". date('l jS \of F Y h:i:s A', $start) .", end $end ". date('l jS \of F Y h:i:s A', $end) ."<br>";
232 7d906758 smos
	$dates = array();
233
	$dates['start'] = $start;
234
	$dates['end'] = $end;
235
	return $dates;
236
}
237
238
239 6ab7ae50 Seth Mos
?>
240 37285f69 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
241
<?php include("fbegin.inc"); ?>
242 89d25faf Seth Mos
<table width="100%" border="0" cellpadding="0" cellspacing="0">
243
        <tr>
244
                <td>
245
			<form name="form1" action="status_rrd_graph.php" method="get">
246
			<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
247
			<?php
248
			        $tab_array = array();
249
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
250
			        $tab_array[] = array("System", $tabactive, "status_rrd_graph.php?cat=system");
251
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
252
			        $tab_array[] = array("Traffic", $tabactive, "status_rrd_graph.php?cat=traffic");
253
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
254
			        $tab_array[] = array("Packets", $tabactive, "status_rrd_graph.php?cat=packets");
255
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
256
			        $tab_array[] = array("Quality", $tabactive, "status_rrd_graph.php?cat=quality");
257 7432ce7b Seth Mos
				if($queues) {
258
					if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
259
					$tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
260
					if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
261
					$tab_array[] = array("QueueDrops", $tabactive, "status_rrd_graph.php?cat=queuedrops");
262
				}
263
				if($wireless) {
264
					if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
265
				        $tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless");
266
				}
267
				if($cellular) {
268
					if($curcat == "cellular") { $tabactive = True; } else { $tabactive = False; }
269
				        $tab_array[] = array("Cellular", $tabactive, "status_rrd_graph.php?cat=cellular");
270
				}
271 47e68f48 smos
				if($curcat == "custom") { $tabactive = True; } else { $tabactive = False; }
272
			        $tab_array[] = array("Custom", $tabactive, "status_rrd_graph.php?cat=custom");
273 69487053 Seth Mos
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
274
			        $tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
275 89d25faf Seth Mos
			        display_top_tabs($tab_array);
276
			?>
277
                </td>
278
        </tr>
279
        <tr>
280
                <td>
281
                        <div id="mainarea">
282
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
283
                                <tr>
284
                                        <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>
285
				</tr>
286
				<tr>
287
                                        <td colspan="2" class="list">
288
					<?=gettext("Graphs:");?>
289
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
290
					<?php
291
292 47e68f48 smos
					if($curcat == "custom") {
293
						foreach ($databases as $db => $database) {
294
							$optionc = split("-", $database);
295
							$search = array("-", ".rrd", $optionc);
296
							$replace = array(" :: ", "", $friendly);
297
							echo "<option value=\"{$database}\"";
298
							$prettyprint = ucwords(str_replace($search, $replace, $database));
299
							if($curoption == $database) {
300
								echo " selected ";
301
							}
302
							echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
303
						}
304
					}
305 a927edff Seth Mos
					foreach ($ui_databases as $db => $database) {
306 2ab73e04 Seth Mos
						if(! preg_match("/($curcat)/i", $database)) {
307 89d25faf Seth Mos
							continue;
308
						}
309
						$optionc = split("-", $database);
310
						$search = array("-", ".rrd", $optionc);
311 35551994 Seth Mos
						$replace = array(" :: ", "", $friendly);
312 47e68f48 smos
313 9850b625 Seth Mos
						switch($curcat) {
314
							case "system":
315 47e68f48 smos
								$optioncf = str_replace($search, $replace, $optionc[1]);
316
								echo "<option value=\"$optioncf\"";
317
								$prettyprint = ucwords(str_replace($search, $replace, $optioncf));
318 9850b625 Seth Mos
								break;
319
							default:
320
								/* Deduce a interface if possible and use the description */
321
								$optionc = "$optionc[0]";
322
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
323 d9699f96 Seth Mos
								if(empty($friendly)) {
324
									$friendly = $optionc;
325
								}
326 9850b625 Seth Mos
								$search = array("-", ".rrd", $optionc);
327
								$replace = array(" :: ", "", $friendly);
328
								echo "<option value=\"$optionc\"";
329
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
330
						}
331
						if($curoption == $optionc) {
332
							echo " selected ";
333 89d25faf Seth Mos
						}
334
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
335
					}
336
337
					?>
338
					</select>
339
340
					<?=gettext("Style:");?>
341
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
342
					<?php
343
					foreach ($styles as $style => $styled) {
344
						echo "<option value=\"$style\"";
345
						if ($style == $curstyle) echo " selected";
346
						echo ">" . htmlspecialchars($styled) . "</option>\n";
347
					}
348
					?>
349 7d906758 smos
					</select>
350
					
351 47e68f48 smos
					<?
352
					if($curcat <> "custom") {
353
					?>
354
						<?=gettext("Period:");?>
355
						<select name="period" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
356
						<?php
357
						foreach ($periods as $period => $value) {
358
							echo "<option value=\"$period\"";
359
							if ($period == $curperiod) echo " selected";
360
							echo ">" . htmlspecialchars($value) . "</option>\n";
361
						}
362 7d906758 smos
					}
363
					?>
364 89d25faf Seth Mos
365
					</select>
366
367
					<?php
368
369 47e68f48 smos
					if($curcat == "custom") {
370
						
371
					
372
					}
373 7d906758 smos
					foreach($graphs as $graph) {
374 89d25faf Seth Mos
						/* check which databases are valid for our category */
375 a927edff Seth Mos
						foreach($ui_databases as $curdatabase) {
376 2ab73e04 Seth Mos
							if(! preg_match("/($curcat)/i", $curdatabase)) {
377 89d25faf Seth Mos
								continue;
378
							}
379 35551994 Seth Mos
							$optionc = split("-", $curdatabase);
380
							$search = array("-", ".rrd", $optionc);
381
							$replace = array(" :: ", "", $friendly);
382 89d25faf Seth Mos
							switch($curoption) {
383
								case "outbound":
384
									/* only show interfaces with a gateway */
385 35551994 Seth Mos
									$optionc = "$optionc[0]";
386 2e76e612 Seth Mos
									if(!interface_has_gateway($optionc)) {
387 a927edff Seth Mos
										if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
388
											continue 2;
389
										}
390 35551994 Seth Mos
									}
391 2ab73e04 Seth Mos
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
392 89d25faf Seth Mos
										continue 2;
393
									}
394 9850b625 Seth Mos
									break;
395 89d25faf Seth Mos
								case "allgraphs":
396 9850b625 Seth Mos
									/* make sure we do not show the placeholder databases in the all view */
397
									if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
398
										continue 2;
399
									}
400
									break;
401 89d25faf Seth Mos
								default:
402
									/* just use the name here */
403 2ab73e04 Seth Mos
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
404 89d25faf Seth Mos
										continue 2;
405
									}
406
							}
407 e3d7c123 Seth Mos
							if(in_array($curdatabase, $databases)) {
408 7d906758 smos
								$dates = get_dates($curperiod, $graph);
409
								$start = $dates['start'];
410
								$end = $dates['end'];
411 89d25faf Seth Mos
								echo "<tr><td colspan=2 class=\"list\">\n";
412 7d906758 smos
								echo "<IMG BORDER='0' name='{$graph}-{$curoption}-{$curdatabase}' ";
413
								echo "id='{$graph}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
414
								echo "SRC=\"status_rrd_graph_img.php?start={$start}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
415 89d25faf Seth Mos
								echo "<br /><hr><br />\n";								
416
								echo "</td></tr>\n";
417
							}
418
						}
419
					}
420
					?>
421
					</td>
422
				</tr>
423
				<tr>
424
					<td colspan=2 class="list">
425
					<script language="javascript">
426
						function update_graph_images() {
427
							//alert('updating');
428
							var randomid = Math.floor(Math.random()*11);
429
							<?php
430 7d906758 smos
							foreach($graphs as $graph) {
431 683bf031 Seth Mos
								/* check which databases are valid for our category */
432
								foreach($databases as $curdatabase) {
433
									if(! stristr($curdatabase, $curcat)) {
434
										continue;
435
									}
436
									$optionc = split("-", $curdatabase);
437
									$search = array("-", ".rrd", $optionc);
438
									$replace = array(" :: ", "", $friendly);
439
									switch($curoption) {
440
										case "outbound":
441 2e76e612 Seth Mos
											if(!interface_has_gateway($optionc)) {
442 683bf031 Seth Mos
												continue 2; 
443
											}
444
											if(! stristr($curdatabase, $optionc)) {
445
													continue 2;
446
											}
447 9850b625 Seth Mos
											break;
448 683bf031 Seth Mos
										case "allgraphs":
449 9850b625 Seth Mos
											/* make sure we do not show the placeholder databases in the all view */
450
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
451
												continue 2;
452
											}
453
											break;
454 683bf031 Seth Mos
										default:
455
											/* just use the name here */
456
											if(! stristr($curdatabase, $curoption)) {
457
												continue 2;
458
											}
459
									}
460 7d906758 smos
									$dates = get_dates($curperiod, $graph);
461
									$start = $dates['start'];
462
									$end = $dates['end'];
463 683bf031 Seth Mos
									/* generate update events utilizing prototype $('') feature */
464
									echo "\n";
465 7d906758 smos
									echo "\t\t\$('{$graph}-{$curoption}-{$curdatabase}').src='status_rrd_graph_img.php?start={$start}&end={$end}&graph={$graph}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid;\n";
466 683bf031 Seth Mos
									}
467
								}
468 89d25faf Seth Mos
							?>
469
							window.setTimeout('update_graph_images()', 355000);
470
						}
471
						window.setTimeout('update_graph_images()', 355000);
472
					</script>
473
					</form>
474
					</td>
475
				</tr>
476
			</table>
477
		</div>
478
		</td>
479
	</tr>
480
</table>
481 37285f69 Scott Ullrich
482
<?php include("fend.inc"); ?>
483
</body>
484
</html>