Project

General

Profile

Download (15.3 KB) Statistics
| Branch: | Tag: | Revision:
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_MODULE:	system
32
*/
33

    
34
##|+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
require("guiconfig.inc");
42
require_once("filter.inc");
43
require("shaper.inc");
44
require_once("rrd.inc");
45

    
46
/* 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
$rrddbpath = "/var/db/rrd/";
52
chdir($rrddbpath);
53
$databases = glob("*.rrd");
54

    
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['period']) {
67
	$curperiod = $_GET['period'];
68
} else {
69
	$curperiod = "current";
70
}
71

    
72
if ($_GET['option']) {
73
	$curoption = $_GET['option'];
74
} else {
75
	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
			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
			}
112
		default:
113
			$curoption = "wan";
114
			break;
115
	}
116
}
117

    
118
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
if ($_GET['style']) {
143
	$curstyle = $_GET['style'];
144
} else {
145
	if(! empty($config['rrd']['style'])) {
146
		$curstyle = $config['rrd']['style'];
147
	} else {
148
		$curstyle = "inverse";
149
	}
150
}
151

    
152
/* sort names reverse so WAN comes first */
153
rsort($databases);
154

    
155
/* these boilerplate databases are required for the other menu choices */
156
$dbheader = array("allgraphs-traffic.rrd",
157
		"allgraphs-quality.rrd",
158
		"allgraphs-wireless.rrd",
159
		"allgraphs-cellular.rrd",
160
		"allgraphs-packets.rrd",
161
		"system-allgraphs.rrd",
162
		"system-throughput.rrd",
163
		"outbound-quality.rrd",
164
		"outbound-packets.rrd",
165
		"outbound-traffic.rrd");
166

    
167
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
/* append the existing array to the header */
179
$ui_databases = array_merge($dbheader, $databases);
180

    
181
$styles = array('inverse' => 'Inverse',
182
		'absolute' => 'Absolute');
183
$graphs = array("day", "week", "month", "quarter", "year", "4year");
184
$periods = array("current" => "Current Period", "previous" => "Previous Period");
185

    
186
$pgtitle = array("Status","RRD Graphs");
187
include("head.inc");
188

    
189
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
			$start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear);
208
			$end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear);
209
			break;
210
		case "week":
211
			$start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $offset), $curyear);
212
			$end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + 7), $curyear);
213
			break;
214
		case "month":
215
			$start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear);
216
			$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
217
			break;
218
		case "quarter":
219
			$start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear);
220
			$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
221
			break;
222
		case "year":
223
			$start = mktime(0, 0, 0, 1, 0, ($curyear + $offset));
224
			$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
225
			break;
226
		case "4year": 
227
			$start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset));
228
			$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
229
			break;
230
	}
231
	// 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
	$dates = array();
233
	$dates['start'] = $start;
234
	$dates['end'] = $end;
235
	return $dates;
236
}
237

    
238

    
239
?>
240
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
241
<?php include("fbegin.inc"); ?>
242
<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
				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
				if($curcat == "custom") { $tabactive = True; } else { $tabactive = False; }
272
			        $tab_array[] = array("Custom", $tabactive, "status_rrd_graph.php?cat=custom");
273
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
274
			        $tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
275
			        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
					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
					foreach ($ui_databases as $db => $database) {
306
						if(! preg_match("/($curcat)/i", $database)) {
307
							continue;
308
						}
309
						$optionc = split("-", $database);
310
						$search = array("-", ".rrd", $optionc);
311
						$replace = array(" :: ", "", $friendly);
312

    
313
						switch($curcat) {
314
							case "system":
315
								$optioncf = str_replace($search, $replace, $optionc[1]);
316
								echo "<option value=\"$optioncf\"";
317
								$prettyprint = ucwords(str_replace($search, $replace, $optioncf));
318
								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
								if(empty($friendly)) {
324
									$friendly = $optionc;
325
								}
326
								$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
						}
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
					</select>
350
					
351
					<?
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
					}
363
					?>
364

    
365
					</select>
366

    
367
					<?php
368

    
369
					if($curcat == "custom") {
370
						
371
					
372
					}
373
					foreach($graphs as $graph) {
374
						/* check which databases are valid for our category */
375
						foreach($ui_databases as $curdatabase) {
376
							if(! preg_match("/($curcat)/i", $curdatabase)) {
377
								continue;
378
							}
379
							$optionc = split("-", $curdatabase);
380
							$search = array("-", ".rrd", $optionc);
381
							$replace = array(" :: ", "", $friendly);
382
							switch($curoption) {
383
								case "outbound":
384
									/* only show interfaces with a gateway */
385
									$optionc = "$optionc[0]";
386
									if(!interface_has_gateway($optionc)) {
387
										if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
388
											continue 2;
389
										}
390
									}
391
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
392
										continue 2;
393
									}
394
									break;
395
								case "allgraphs":
396
									/* 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
								default:
402
									/* just use the name here */
403
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
404
										continue 2;
405
									}
406
							}
407
							if(in_array($curdatabase, $databases)) {
408
								$dates = get_dates($curperiod, $graph);
409
								$start = $dates['start'];
410
								$end = $dates['end'];
411
								echo "<tr><td colspan=2 class=\"list\">\n";
412
								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
								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
							foreach($graphs as $graph) {
431
								/* 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
											if(!interface_has_gateway($optionc)) {
442
												continue 2; 
443
											}
444
											if(! stristr($curdatabase, $optionc)) {
445
													continue 2;
446
											}
447
											break;
448
										case "allgraphs":
449
											/* 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
										default:
455
											/* just use the name here */
456
											if(! stristr($curdatabase, $curoption)) {
457
												continue 2;
458
											}
459
									}
460
									$dates = get_dates($curperiod, $graph);
461
									$start = $dates['start'];
462
									$end = $dates['end'];
463
									/* generate update events utilizing prototype $('') feature */
464
									echo "\n";
465
									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
									}
467
								}
468
							?>
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

    
482
<?php include("fend.inc"); ?>
483
</body>
484
</html>
(166-166/222)