Project

General

Profile

Download (17.4 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@dds.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
		case "vpnusers":
113
			foreach($databases as $database) {
114
				if(preg_match("/[-]vpnusers\.rrd/i", $database)) {
115
					/* pick off the 1st database we find that matches the VPN graphs */
116
					$name = explode("-", $database);
117
					$curoption = "$name[0]";
118
					continue 2;
119
				}
120
			}
121
		default:
122
			$curoption = "wan";
123
			break;
124
	}
125
}
126

    
127
$now = time();
128
if($curcat == "custom") {
129
	if (is_numeric($_GET['start'])) {
130
			if($start < ($now - (3600 * 24 * 365 * 5))) {
131
					$start = $now - (4 * 3600);
132
			}
133
			$start = $_GET['start'];
134
	} else {
135
			$start = $now - (4 * 3600);
136
	}
137
}
138

    
139
if (is_numeric($_GET['end'])) {
140
        $end = $_GET['end'];
141
} else {
142
        $end = $now;
143
}
144

    
145
/* this should never happen */
146
if($end < $start) {
147
        $end = $now;
148
}
149

    
150
$seconds = $end - $start;
151
					
152
if ($_GET['style']) {
153
	$curstyle = $_GET['style'];
154
} else {
155
	if(! empty($config['rrd']['style'])) {
156
		$curstyle = $config['rrd']['style'];
157
	} else {
158
		$curstyle = "inverse";
159
	}
160
}
161

    
162
/* sort names reverse so WAN comes first */
163
rsort($databases);
164

    
165
/* these boilerplate databases are required for the other menu choices */
166
$dbheader = array("allgraphs-traffic.rrd",
167
		"allgraphs-quality.rrd",
168
		"allgraphs-wireless.rrd",
169
		"allgraphs-cellular.rrd",
170
		"allgraphs-vpnusers.rrd",
171
		"allgraphs-packets.rrd",
172
		"system-allgraphs.rrd",
173
		"system-throughput.rrd",
174
		"outbound-quality.rrd",
175
		"outbound-packets.rrd",
176
		"outbound-traffic.rrd");
177

    
178
foreach($databases as $database) {
179
	if(stristr($database, "-wireless")) {
180
		$wireless = true;
181
	}
182
	if(stristr($database, "-queues")) {
183
		$queues = true;
184
	}
185
	if(stristr($database, "-cellular")) {
186
		$cellular = true;
187
	}
188
	if(stristr($database, "-vpnusers")) {
189
		$vpnusers = true;
190
	}
191
}
192
/* append the existing array to the header */
193
$ui_databases = array_merge($dbheader, $databases);
194

    
195
$styles = array('inverse' => gettext('Inverse'),
196
		'absolute' => gettext('Absolute'));
197
$graphs = array("12hour", "day", "week", "month", "quarter", "year", "4year");
198
$periods = array("current" => gettext("Current Period"), "previous" => gettext("Previous Period"));
199

    
200
$pgtitle = array(gettext("Status"),gettext("RRD Graphs"));
201
include("head.inc");
202

    
203
function get_dates($curperiod, $graph) {
204
	$now = time();
205
	$end = $now;
206
	$curyear = date('Y', $now);
207
	$curmonth = date('m', $now);
208
	$curweek = date('W', $now);
209
	$curweekday = date('N', $now) - 1; // We want to start on monday
210
	$curday = date('d', $now);
211

    
212
	switch($curperiod) {
213
		case "previous":
214
			$offset = -1;
215
			break;
216
		default:
217
			$offset = 0;
218
	}
219
	switch($graph) {
220
		case "12hour":
221
			switch($offset) {
222
				case 0;
223
					$houroffset = 0;
224
					break;
225
				default:
226
					$houroffset = ($offset * 12) - 12;
227
					break;
228
			}
229
			$start = mktime((8 + $houroffset), 0, 0, $curmonth, $curday, $curyear);
230
			$end = mktime((8 + $houroffset) + 12, 0, 0, $curmonth, $curday, $curyear);
231
			break;
232
		case "day":
233
			$start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear);
234
			$end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear);
235
			break;
236
		case "week":
237
			switch($offset) {
238
				case 0;
239
					$weekoffset = 0;
240
					break;
241
				default:
242
					$weekoffset = ($offset * 7) - 7;
243
					break;
244
			}
245
			$start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset), $curyear);
246
			$end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset + 7), $curyear);
247
			break;
248
		case "month":
249
			$start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear);
250
			$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
251
			break;
252
		case "quarter":
253
			$start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear);
254
			$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
255
			break;
256
		case "year":
257
			$start = mktime(0, 0, 0, 1, 0, ($curyear + $offset));
258
			$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
259
			break;
260
		case "4year": 
261
			$start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset));
262
			$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
263
			break;
264
	}
265
	// 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>";
266
	$dates = array();
267
	$dates['start'] = $start;
268
	$dates['end'] = $end;
269
	return $dates;
270
}
271

    
272

    
273
?>
274
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
275
<?php include("fbegin.inc"); ?>
276
<table width="100%" border="0" cellpadding="0" cellspacing="0">
277
        <tr>
278
                <td>
279
			<form name="form1" action="status_rrd_graph.php" method="get">
280
			<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
281
			<?php
282
			        $tab_array = array();
283
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
284
			        $tab_array[] = array(gettext("System"), $tabactive, "status_rrd_graph.php?cat=system");
285
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
286
			        $tab_array[] = array(gettext("Traffic"), $tabactive, "status_rrd_graph.php?cat=traffic");
287
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
288
			        $tab_array[] = array(gettext("Packets"), $tabactive, "status_rrd_graph.php?cat=packets");
289
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
290
			        $tab_array[] = array(gettext("Quality"), $tabactive, "status_rrd_graph.php?cat=quality");
291
				if($queues) {
292
					if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
293
						$tab_array[] = array(gettext("Queues"), $tabactive, "status_rrd_graph.php?cat=queues");
294
					if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
295
						$tab_array[] = array(gettext("QueueDrops"), $tabactive, "status_rrd_graph.php?cat=queuedrops");
296
				}
297
				if($wireless) {
298
					if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
299
				        $tab_array[] = array(gettext("Wireless"), $tabactive, "status_rrd_graph.php?cat=wireless");
300
				}
301
				if($cellular) {
302
					if($curcat == "cellular") { $tabactive = True; } else { $tabactive = False; }
303
				        $tab_array[] = array(gettext("Cellular"), $tabactive, "status_rrd_graph.php?cat=cellular");
304
				}
305
				if($vpnusers) {
306
					if($curcat == "vpnusers") { $tabactive = True; } else { $tabactive = False; }
307
				        $tab_array[] = array("VPN", $tabactive, "status_rrd_graph.php?cat=vpnusers");
308
				}
309
				if($curcat == "custom") { $tabactive = True; } else { $tabactive = False; }
310
			        $tab_array[] = array(gettext("Custom"), $tabactive, "status_rrd_graph.php?cat=custom");
311
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
312
			        $tab_array[] = array(gettext("Settings"), $tabactive, "status_rrd_graph_settings.php");
313
			        display_top_tabs($tab_array);
314
			?>
315
                </td>
316
        </tr>
317
        <tr>
318
                <td>
319
                        <div id="mainarea">
320
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
321
                                <tr>
322
                                        <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>
323
				</tr>
324
				<tr>
325
                                        <td colspan="2" class="list">
326
					<?=gettext("Graphs");?>:
327
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
328
					<?php
329

    
330
					if($curcat == "custom") {
331
						foreach ($databases as $db => $database) {
332
							$optionc = split("-", $database);
333
							$search = array("-", ".rrd", $optionc);
334
							$replace = array(" :: ", "", $friendly);
335
							echo "<option value=\"{$database}\"";
336
							$prettyprint = ucwords(str_replace($search, $replace, $database));
337
							if($curoption == $database) {
338
								echo " selected";
339
							}
340
							echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
341
						}
342
					}
343
					foreach ($ui_databases as $db => $database) {
344
						if(! preg_match("/($curcat)/i", $database)) {
345
							continue;
346
						}
347
						$optionc = split("-", $database);
348
						$search = array("-", ".rrd", $optionc);
349
						$replace = array(" :: ", "", $friendly);
350

    
351
						switch($curcat) {
352
							case "system":
353
								$optioncf = str_replace($search, $replace, $optionc[1]);
354
								echo "<option value=\"$optioncf\"";
355
								$prettyprint = ucwords(str_replace($search, $replace, $optioncf));
356
								break;
357
							default:
358
								/* Deduce a interface if possible and use the description */
359
								$optionc = "$optionc[0]";
360
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
361
								if(empty($friendly)) {
362
									$friendly = $optionc;
363
								}
364
								$search = array("-", ".rrd", $optionc);
365
								$replace = array(" :: ", "", $friendly);
366
								echo "<option value=\"$optionc\"";
367
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
368
						}
369
						if($curoption == $optionc) {
370
							echo " selected";
371
						}
372
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
373
					}
374

    
375
					?>
376
					</select>
377

    
378
					<?=gettext("Style");?>:
379
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
380
					<?php
381
					foreach ($styles as $style => $styled) {
382
						echo "<option value=\"$style\"";
383
						if ($style == $curstyle) echo " selected";
384
						echo ">" . htmlspecialchars($styled) . "</option>\n";
385
					}
386
					?>
387
					</select>
388
					
389
					<?
390
					if($curcat <> "custom") {
391
					?>
392
						<?=gettext("Period");?>:
393
						<select name="period" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
394
						<?php
395
						foreach ($periods as $period => $value) {
396
							echo "<option value=\"$period\"";
397
							if ($period == $curperiod) echo " selected";
398
							echo ">" . htmlspecialchars($value) . "</option>\n";
399
						}
400
					}
401
					?>
402
					</select>
403
					<?php
404

    
405
					if($curcat == "custom") {
406
						?>
407
						<?=gettext("Start:");?>
408
						<input type="text" name="start" class="formfldunknown" length="32" value="<?php echo $start;?>">
409
						<?=gettext("End:");?>
410
						<input type="text" name="end" class="formfldunknown" length="32" value="<?php echo $now;?>">
411
						<input type="submit" name="Submit" value="<?=gettext("Go"); ?>">
412
						<?
413
						$curdatabase = $curoption;
414
						$graph = "custom-$curdatabase";
415
						if(in_array($curdatabase, $databases)) {
416
							echo "<tr><td colspan=2 class=\"list\">\n";
417
							echo "<IMG BORDER='0' name='{$graph}-{$curoption}-{$curdatabase}' ";
418
							echo "id='{$graph}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
419
							echo "SRC=\"status_rrd_graph_img.php?start={$start}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
420
							echo "<br /><hr><br />\n";								
421
							echo "</td></tr>\n";
422
						}
423
					} else {
424
						foreach($graphs as $graph) {
425
							/* check which databases are valid for our category */
426
							foreach($ui_databases as $curdatabase) {
427
								if(! preg_match("/($curcat)/i", $curdatabase)) {
428
									continue;
429
								}
430
								$optionc = split("-", $curdatabase);
431
								$search = array("-", ".rrd", $optionc);
432
								$replace = array(" :: ", "", $friendly);
433
								switch($curoption) {
434
									case "outbound":
435
										/* only show interfaces with a gateway */
436
										$optionc = "$optionc[0]";
437
										if(!interface_has_gateway($optionc)) {
438
											if(!preg_match("/($optionc)-(quality)/", $curdatabase)) {
439
												continue 2;
440
											}
441
										}
442
										if(! preg_match("/($optionc)[-.]/i", $curdatabase)) {
443
											continue 2;
444
										}
445
										break;
446
									case "allgraphs":
447
										/* make sure we do not show the placeholder databases in the all view */
448
										if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
449
											continue 2;
450
										}
451
										break;
452
									default:
453
										/* just use the name here */
454
										if(! preg_match("/($curoption)[-.]/i", $curdatabase)) {
455
											continue 2;
456
										}
457
								}
458
								if(in_array($curdatabase, $databases)) {
459
									$dates = get_dates($curperiod, $graph);
460
									$start = $dates['start'];
461
									$end = $dates['end'];
462
									echo "<tr><td colspan=2 class=\"list\">\n";
463
									echo "<IMG BORDER='0' name='{$graph}-{$curoption}-{$curdatabase}' ";
464
									echo "id='{$graph}-{$curoption}-{$curdatabase}' ALT=\"$prettydb Graph\" ";
465
									echo "SRC=\"status_rrd_graph_img.php?start={$start}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
466
									echo "<br /><hr><br />\n";								
467
									echo "</td></tr>\n";
468
								}
469
							}
470
						}
471
					}
472
					?>
473
					</td>
474
				</tr>
475
				<tr>
476
					<td colspan=2 class="list">
477
					<script language="javascript">
478
						function update_graph_images() {
479
							//alert('updating');
480
							var randomid = Math.floor(Math.random()*11);
481
							<?php
482
							foreach($graphs as $graph) {
483
								/* check which databases are valid for our category */
484
								foreach($databases as $curdatabase) {
485
									if(! stristr($curdatabase, $curcat)) {
486
										continue;
487
									}
488
									$optionc = split("-", $curdatabase);
489
									$search = array("-", ".rrd", $optionc);
490
									$replace = array(" :: ", "", $friendly);
491
									switch($curoption) {
492
										case "outbound":
493
											if(!interface_has_gateway($optionc)) {
494
												continue 2; 
495
											}
496
											if(! stristr($curdatabase, $optionc)) {
497
													continue 2;
498
											}
499
											break;
500
										case "allgraphs":
501
											/* make sure we do not show the placeholder databases in the all view */
502
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
503
												continue 2;
504
											}
505
											break;
506
										default:
507
											/* just use the name here */
508
											if(! stristr($curdatabase, $curoption)) {
509
												continue 2;
510
											}
511
									}
512
									$dates = get_dates($curperiod, $graph);
513
									$start = $dates['start'];
514
									$end = $dates['end'];
515
									/* generate update events utilizing prototype $('') feature */
516
									echo "\n";
517
									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";
518
									}
519
								}
520
							?>
521
							window.setTimeout('update_graph_images()', 355000);
522
						}
523
						window.setTimeout('update_graph_images()', 355000);
524
					</script>
525
					</form>
526
					</td>
527
				</tr>
528
			</table>
529
		</div>
530
		</td>
531
	</tr>
532
</table>
533

    
534
<?php include("fend.inc"); ?>
535
</body>
536
</html>
(166-166/222)