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
$databases = glob("{$rrddbpath}*.rrd");
53

    
54
if ($_GET['cat']) {
55
	$curcat = $_GET['cat'];
56
} else {
57
	if(! empty($config['rrd']['category'])) {
58
		$curcat = $config['rrd']['category'];
59
	} else {
60
		$curcat = "system";
61
	}
62
}
63

    
64
if ($_GET['period']) {
65
	$curperiod = $_GET['period'];
66
} else {
67
	$curperiod = "current";
68
}
69

    
70
if ($_GET['option']) {
71
	$curoption = $_GET['option'];
72
} else {
73
	switch($curcat) {
74
		case "system":
75
			$curoption = "processor";
76
			break;
77
		case "queues":
78
			$curoption = "queues";
79
			break;
80
		case "queuedrops":
81
			$curoption = "queuedrops";
82
			break;
83
		case "quality":
84
			foreach($databases as $database) {
85
				if(preg_match("/[-]quality\.rrd/i", $database)) {
86
					/* pick off the 1st database we find that matches the quality graph */
87
					$name = explode("-", $database);
88
					$curoption = "$name[0]";
89
					continue 2;
90
				}
91
			}
92
		case "wireless":
93
			foreach($databases as $database) {
94
				if(preg_match("/[-]wireless\.rrd/i", $database)) {
95
					/* pick off the 1st database we find that matches the wireless graph */
96
					$name = explode("-", $database);
97
					$curoption = "$name[0]";
98
					continue 2;
99
				}
100
			}
101
		case "cellular":
102
			foreach($databases as $database) {
103
				if(preg_match("/[-]cellular\.rrd/i", $database)) {
104
					/* pick off the 1st database we find that matches the celullar graph */
105
					$name = explode("-", $database);
106
					$curoption = "$name[0]";
107
					continue 2;
108
				}
109
			}
110
		default:
111
			$curoption = "wan";
112
			break;
113
	}
114
}
115

    
116
if($curcat == "custom") {
117
	if (is_numeric($_GET['start'])) {
118
			if($start < ($now - (3600 * 24 * 365 * 5))) {
119
					$start = $now - (4 * 3600);
120
			}
121
			$start = $_GET['start'];
122
	} else {
123
			$start = $now - (4 * 3600);
124
	}
125
}
126

    
127
if (is_numeric($_GET['end'])) {
128
        $end = $_GET['end'];
129
} else {
130
        $end = $now;
131
}
132

    
133
/* this should never happen */
134
if($end < $start) {
135
        $end = $now;
136
}
137

    
138
$seconds = $end - $start;
139
					
140
if ($_GET['style']) {
141
	$curstyle = $_GET['style'];
142
} else {
143
	if(! empty($config['rrd']['style'])) {
144
		$curstyle = $config['rrd']['style'];
145
	} else {
146
		$curstyle = "inverse";
147
	}
148
}
149

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

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

    
165
foreach($databases as $database) {
166
	if(stristr($database, "wireless")) {
167
		$wireless = true;
168
	}
169
	if(stristr($database, "queues")) {
170
		$queues = true;
171
	}
172
	if(stristr($database, "cellular")) {
173
		$cellular = true;
174
	}
175
}
176
/* append the existing array to the header */
177
$ui_databases = array_merge($dbheader, $databases);
178

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

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

    
187
function get_dates($curperiod, $graph) {
188
	$now = time();
189
	$end = $now;
190
	$curyear = date('Y', $now);
191
	$curmonth = date('m', $now);
192
	$curweek = date('W', $now);
193
	$curweekday = date('w', $now);
194
	$curday = date('d', $now);
195

    
196
	switch($curperiod) {
197
		case "previous":
198
			$offset = -1;
199
			break;
200
		default:
201
			$offset = 0;
202
	}
203
	switch($graph) {
204
		case "day":
205
			$start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear);
206
			$end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear);
207
			break;
208
		case "week":
209
			$start = mktime(0, 0, 0, $curmonth, (($curday + $curweekday) - $offset), $curyear);
210
			$end = mktime(0, 0, 0, $curmonth, (($curday + $curweekday) + 7), $curyear);
211
			break;
212
		case "month":
213
			$start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear);
214
			$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
215
			break;
216
		case "quarter":
217
			$start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear);
218
			$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
219
			break;
220
		case "year":
221
			$start = mktime(0, 0, 0, 1, 0, ($curyear + $offset));
222
			$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
223
			break;
224
		case "4year": 
225
			$start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset));
226
			$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
227
			break;
228
	}
229
	// 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>";
230
	$dates = array();
231
	$dates['start'] = $start;
232
	$dates['end'] = $end;
233
	return $dates;
234
}
235

    
236

    
237
?>
238
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
239
<?php include("fbegin.inc"); ?>
240
<table width="100%" border="0" cellpadding="0" cellspacing="0">
241
        <tr>
242
                <td>
243
			<form name="form1" action="status_rrd_graph.php" method="get">
244
			<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
245
			<?php
246
			        $tab_array = array();
247
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
248
			        $tab_array[] = array("System", $tabactive, "status_rrd_graph.php?cat=system");
249
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
250
			        $tab_array[] = array("Traffic", $tabactive, "status_rrd_graph.php?cat=traffic");
251
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
252
			        $tab_array[] = array("Packets", $tabactive, "status_rrd_graph.php?cat=packets");
253
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
254
			        $tab_array[] = array("Quality", $tabactive, "status_rrd_graph.php?cat=quality");
255
				if($queues) {
256
					if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
257
					$tab_array[] = array("Queues", $tabactive, "status_rrd_graph.php?cat=queues");
258
					if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
259
					$tab_array[] = array("QueueDrops", $tabactive, "status_rrd_graph.php?cat=queuedrops");
260
				}
261
				if($wireless) {
262
					if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
263
				        $tab_array[] = array("Wireless", $tabactive, "status_rrd_graph.php?cat=wireless");
264
				}
265
				if($cellular) {
266
					if($curcat == "cellular") { $tabactive = True; } else { $tabactive = False; }
267
				        $tab_array[] = array("Cellular", $tabactive, "status_rrd_graph.php?cat=cellular");
268
				}
269
				if($curcat == "custom") { $tabactive = True; } else { $tabactive = False; }
270
			        $tab_array[] = array("Custom", $tabactive, "status_rrd_graph.php?cat=custom");
271
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
272
			        $tab_array[] = array("Settings", $tabactive, "status_rrd_graph_settings.php");
273
			        display_top_tabs($tab_array);
274
			?>
275
                </td>
276
        </tr>
277
        <tr>
278
                <td>
279
                        <div id="mainarea">
280
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
281
                                <tr>
282
                                        <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>
283
				</tr>
284
				<tr>
285
                                        <td colspan="2" class="list">
286
					<?=gettext("Graphs:");?>
287
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
288
					<?php
289

    
290
					if($curcat == "custom") {
291
						foreach ($databases as $db => $database) {
292
							$optionc = split("-", $database);
293
							$search = array("-", ".rrd", $optionc);
294
							$replace = array(" :: ", "", $friendly);
295
							echo "<option value=\"{$database}\"";
296
							$prettyprint = ucwords(str_replace($search, $replace, $database));
297
							if($curoption == $database) {
298
								echo " selected ";
299
							}
300
							echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
301
						}
302
					}
303
					foreach ($ui_databases as $db => $database) {
304
						if(! preg_match("/($curcat)/i", $database)) {
305
							continue;
306
						}
307
						$optionc = split("-", $database);
308
						$search = array("-", ".rrd", $optionc);
309
						$replace = array(" :: ", "", $friendly);
310

    
311
						switch($curcat) {
312
							case "system":
313
								$optioncf = str_replace($search, $replace, $optionc[1]);
314
								echo "<option value=\"$optioncf\"";
315
								$prettyprint = ucwords(str_replace($search, $replace, $optioncf));
316
								break;
317
							default:
318
								/* Deduce a interface if possible and use the description */
319
								$optionc = "$optionc[0]";
320
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
321
								if(empty($friendly)) {
322
									$friendly = $optionc;
323
								}
324
								$search = array("-", ".rrd", $optionc);
325
								$replace = array(" :: ", "", $friendly);
326
								echo "<option value=\"$optionc\"";
327
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
328
						}
329
						if($curoption == $optionc) {
330
							echo " selected ";
331
						}
332
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
333

    
334
					}
335

    
336
					?>
337
					</select>
338

    
339
					<?=gettext("Style:");?>
340
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
341
					<?php
342
					foreach ($styles as $style => $styled) {
343
						echo "<option value=\"$style\"";
344
						if ($style == $curstyle) echo " selected";
345
						echo ">" . htmlspecialchars($styled) . "</option>\n";
346
					}
347
					?>
348
					</select>
349
					
350
					<?
351
					if($curcat <> "custom") {
352
					?>
353
						<?=gettext("Period:");?>
354
						<select name="period" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
355
						<?php
356
						foreach ($periods as $period => $value) {
357
							echo "<option value=\"$period\"";
358
							if ($period == $curperiod) echo " selected";
359
							echo ">" . htmlspecialchars($value) . "</option>\n";
360
						}
361
					}
362
					?>
363

    
364
					</select>
365

    
366
					<?php
367

    
368
					if($curcat == "custom") {
369
						
370
					
371
					}
372
					foreach($graphs as $graph) {
373
						/* check which databases are valid for our category */
374
						foreach($ui_databases as $curdatabase) {
375
							if(! preg_match("/($curcat)/i", $curdatabase)) {
376
								continue;
377
							}
378
							$optionc = split("-", $curdatabase);
379
							$search = array("-", ".rrd", $optionc);
380
							$replace = array(" :: ", "", $friendly);
381
							switch($curoption) {
382
								case "outbound":
383
									/* only show interfaces with a gateway */
384
									$optionc = "$optionc[0]";
385
									if(!interface_has_gateway($optionc)) {
386
										if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
387
											continue 2;
388
										}
389
									}
390
									if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
391
										continue 2;
392
									}
393
									break;
394
								case "allgraphs":
395
									/* make sure we do not show the placeholder databases in the all view */
396
									if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
397
										continue 2;
398
									}
399
									break;
400
								default:
401
									/* just use the name here */
402
									if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
403
										continue 2;
404
									}
405
							}
406
							if(in_array($curdatabase, $databases)) {
407
								$dates = get_dates($curperiod, $graph);
408
								$start = $dates['start'];
409
								$end = $dates['end'];
410
								echo "<tr><td colspan=2 class=\"list\">\n";
411
								echo "<IMG BORDER='0' name='{$graph}-{$curoption}-{$curdatabase}' ";
412
								echo "id='{$graph}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
413
								echo "SRC=\"status_rrd_graph_img.php?start={$start}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
414
								echo "<br /><hr><br />\n";								
415
								echo "</td></tr>\n";
416
							}
417
						}
418
					}
419
					?>
420
					</td>
421
				</tr>
422
				<tr>
423
					<td colspan=2 class="list">
424
					<script language="javascript">
425
						function update_graph_images() {
426
							//alert('updating');
427
							var randomid = Math.floor(Math.random()*11);
428
							<?php
429
							foreach($graphs as $graph) {
430
								/* check which databases are valid for our category */
431
								foreach($databases as $curdatabase) {
432
									if(! stristr($curdatabase, $curcat)) {
433
										continue;
434
									}
435
									$optionc = split("-", $curdatabase);
436
									$search = array("-", ".rrd", $optionc);
437
									$replace = array(" :: ", "", $friendly);
438
									switch($curoption) {
439
										case "outbound":
440
											if(!interface_has_gateway($optionc)) {
441
												continue 2; 
442
											}
443
											if(! stristr($curdatabase, $optionc)) {
444
													continue 2;
445
											}
446
											break;
447
										case "allgraphs":
448
											/* make sure we do not show the placeholder databases in the all view */
449
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
450
												continue 2;
451
											}
452
											break;
453
										default:
454
											/* just use the name here */
455
											if(! stristr($curdatabase, $curoption)) {
456
												continue 2;
457
											}
458
									}
459
									$dates = get_dates($curperiod, $graph);
460
									$start = $dates['start'];
461
									$end = $dates['end'];
462
									/* generate update events utilizing prototype $('') feature */
463
									echo "\n";
464
									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";
465
									}
466
								}
467
							?>
468
							window.setTimeout('update_graph_images()', 355000);
469
						}
470
						window.setTimeout('update_graph_images()', 355000);
471
					</script>
472
					</form>
473
					</td>
474
				</tr>
475
			</table>
476
		</div>
477
		</td>
478
	</tr>
479
</table>
480

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