Project

General

Profile

Download (23.6 KB) Statistics
| Branch: | Tag: | Revision:
1 37285f69 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4
	status_rrd_graph.php
5
	Part of pfSense
6 6216690b smos
	Copyright (C) 2007 Seth Mos <seth.mos@dds.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 59418cee Darren Embry
unset($input_errors);
47
48 70281b3a Seth Mos
/* if the rrd graphs are not enabled redirect to settings page */
49
if(! isset($config['rrd']['enable'])) {
50
	header("Location: status_rrd_graph_settings.php");
51
}
52
53 329bb764 Seth Mos
$rrddbpath = "/var/db/rrd/";
54 002bc4ab smos
chdir($rrddbpath);
55
$databases = glob("*.rrd");
56
57 329bb764 Seth Mos
58 89d25faf Seth Mos
if ($_GET['cat']) {
59 034f08e7 Scott Ullrich
	$curcat = htmlspecialchars($_GET['cat']);
60 37285f69 Scott Ullrich
} else {
61 69487053 Seth Mos
	if(! empty($config['rrd']['category'])) {
62
		$curcat = $config['rrd']['category'];
63
	} else {
64
		$curcat = "system";
65
	}
66 89d25faf Seth Mos
}
67
68 cba9d7d9 Renato Botelho
if ($_GET['zone'])
69
	$curzone = $_GET['zone'];
70
else
71
	$curzone = '';
72
73 7d906758 smos
if ($_GET['period']) {
74
	$curperiod = $_GET['period'];
75
} else {
76 97acf646 Erik Fonnesbeck
	if(! empty($config['rrd']['period'])) {
77
		$curperiod = $config['rrd']['period'];
78
	} else {
79
		$curperiod = "absolute";
80
	}
81 7d906758 smos
}
82
83 89d25faf Seth Mos
if ($_GET['option']) {
84
	$curoption = $_GET['option'];
85
} else {
86 329bb764 Seth Mos
	switch($curcat) {
87
		case "system":
88
			$curoption = "processor";
89
			break;
90
		case "queues":
91
			$curoption = "queues";
92
			break;
93
		case "queuedrops":
94
			$curoption = "queuedrops";
95 7432ce7b Seth Mos
			break;
96
		case "quality":
97
			foreach($databases as $database) {
98
				if(preg_match("/[-]quality\.rrd/i", $database)) {
99
					/* pick off the 1st database we find that matches the quality graph */
100
					$name = explode("-", $database);
101
					$curoption = "$name[0]";
102
					continue 2;
103
				}
104
			}
105
		case "wireless":
106
			foreach($databases as $database) {
107
				if(preg_match("/[-]wireless\.rrd/i", $database)) {
108
					/* pick off the 1st database we find that matches the wireless graph */
109
					$name = explode("-", $database);
110
					$curoption = "$name[0]";
111
					continue 2;
112
				}
113
			}
114
		case "cellular":
115
			foreach($databases as $database) {
116
				if(preg_match("/[-]cellular\.rrd/i", $database)) {
117
					/* pick off the 1st database we find that matches the celullar graph */
118
					$name = explode("-", $database);
119
					$curoption = "$name[0]";
120
					continue 2;
121
				}
122 329bb764 Seth Mos
			}
123 edd2d8b7 smos
		case "vpnusers":
124 6b0c5ae6 smos
			foreach($databases as $database) {
125 edd2d8b7 smos
				if(preg_match("/[-]vpnusers\.rrd/i", $database)) {
126 6b0c5ae6 smos
					/* pick off the 1st database we find that matches the VPN graphs */
127
					$name = explode("-", $database);
128
					$curoption = "$name[0]";
129
					continue 2;
130
				}
131
			}
132 20413b72 Warren Baker
		case "captiveportal":
133
			$curoption = "allgraphs";
134
			break;
135 329bb764 Seth Mos
		default:
136
			$curoption = "wan";
137
			break;
138 89d25faf Seth Mos
	}
139 37285f69 Scott Ullrich
}
140
141 6b0c5ae6 smos
$now = time();
142 47e68f48 smos
if($curcat == "custom") {
143
	if (is_numeric($_GET['start'])) {
144 59418cee Darren Embry
		if($start < ($now - (3600 * 24 * 365 * 5))) {
145
			$start = $now - (8 * 3600);
146
		}
147
		$start = $_GET['start'];
148
	} else if ($_GET['start']) {
149
		$start = strtotime($_GET['start']);
150
		if ($start === FALSE || $start === -1) {
151
			$input_errors[] = gettext("Invalid start date/time:") . " '{$_GET['start']}'";
152 c7cfbbd8 smos
			$start = $now - (8 * 3600);
153 59418cee Darren Embry
		}
154
	} else {
155
		$start = $now - (8 * 3600);
156 47e68f48 smos
	}
157
}
158
159
if (is_numeric($_GET['end'])) {
160
        $end = $_GET['end'];
161 59418cee Darren Embry
} else if ($_GET['end']) {
162
	$end = strtotime($_GET['end']);
163
	if ($end === FALSE || $end === -1) {
164
		$input_errors[] = gettext("Invalid end date/time:") . " '{$_GET['end']}'";
165
		$end = $now;
166
	}
167 47e68f48 smos
} else {
168
        $end = $now;
169
}
170
171
/* this should never happen */
172
if($end < $start) {
173 c7cfbbd8 smos
	log_error("start $start is smaller than end $end");
174 47e68f48 smos
        $end = $now;
175
}
176
177
$seconds = $end - $start;
178 5d7791a2 Scott Ullrich
179
$styles = array('inverse' => gettext('Inverse'),
180
		'absolute' => gettext('Absolute'));
181
182
// Set default and override later
183
$curstyle = "inverse";
184
185 6ab7ae50 Seth Mos
if ($_GET['style']) {
186 5d7791a2 Scott Ullrich
	foreach($styles as $style) 
187 4ec48253 Scott Ullrich
		if(strtoupper($style) == strtoupper($_GET['style'])) 
188 5d7791a2 Scott Ullrich
			$curstyle = $_GET['style'];
189 37285f69 Scott Ullrich
} else {
190 69487053 Seth Mos
	if(! empty($config['rrd']['style'])) {
191
		$curstyle = $config['rrd']['style'];
192
	} else {
193
		$curstyle = "inverse";
194
	}
195 37285f69 Scott Ullrich
}
196
197 329bb764 Seth Mos
/* sort names reverse so WAN comes first */
198 6ab7ae50 Seth Mos
rsort($databases);
199 37285f69 Scott Ullrich
200 9850b625 Seth Mos
/* these boilerplate databases are required for the other menu choices */
201
$dbheader = array("allgraphs-traffic.rrd",
202
		"allgraphs-quality.rrd",
203 2f80d451 Seth Mos
		"allgraphs-wireless.rrd",
204 ec51a222 thompsa
		"allgraphs-cellular.rrd",
205 edd2d8b7 smos
		"allgraphs-vpnusers.rrd",
206 9850b625 Seth Mos
		"allgraphs-packets.rrd",
207
		"system-allgraphs.rrd",
208 e3d7c123 Seth Mos
		"system-throughput.rrd",
209 9850b625 Seth Mos
		"outbound-quality.rrd",
210
		"outbound-packets.rrd",
211
		"outbound-traffic.rrd");
212
213 9cd5e6f5 Erik Fonnesbeck
/* additional menu choices for the custom tab */
214
$dbheader_custom = array("system-throughput.rrd");
215
216 7432ce7b Seth Mos
foreach($databases as $database) {
217 edd2d8b7 smos
	if(stristr($database, "-wireless")) {
218 7432ce7b Seth Mos
		$wireless = true;
219
	}
220 edd2d8b7 smos
	if(stristr($database, "-queues")) {
221 7432ce7b Seth Mos
		$queues = true;
222
	}
223 17a71003 Ermal
	if(stristr($database, "-cellular") && !empty($config['ppps'])) {
224 7432ce7b Seth Mos
		$cellular = true;
225
	}
226 edd2d8b7 smos
	if(stristr($database, "-vpnusers")) {
227
		$vpnusers = true;
228 6b0c5ae6 smos
	}
229 cba9d7d9 Renato Botelho
	if(stristr($database, "captiveportal-") && is_array($config['captiveportal'])) {
230 20413b72 Warren Baker
		$captiveportal = true;
231
	}
232 7432ce7b Seth Mos
}
233 9850b625 Seth Mos
/* append the existing array to the header */
234 a927edff Seth Mos
$ui_databases = array_merge($dbheader, $databases);
235 9cd5e6f5 Erik Fonnesbeck
$custom_databases = array_merge($dbheader_custom, $databases);
236 9850b625 Seth Mos
237 c7cfbbd8 smos
$graphs = array("8hour", "day", "week", "month", "quarter", "year", "4year");
238 97acf646 Erik Fonnesbeck
$periods = array("absolute" => gettext("Absolute Timespans"), "current" => gettext("Current Period"), "previous" => gettext("Previous Period"));
239
$graph_length = array(
240
	"8hour" => 28800,
241
	"day" => 86400,
242
	"week" => 604800,
243
	"month" => 2764800,
244
	"quarter" => 8035200,
245
	"year" => 31622400,
246
	"4year" => 126489600);
247 6ab7ae50 Seth Mos
248 1d80829e Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("RRD Graphs"));
249 ce49a7c9 Darren Embry
250
$closehead = false;
251 cba9d7d9 Renato Botelho
252
/* Load all CP zones */
253 52034432 Renato Botelho
if ($captiveportal && is_array($config['captiveportal'])) {
254 cba9d7d9 Renato Botelho
	$cp_zones_tab_array = array();
255
	foreach($config['captiveportal'] as $cpkey => $cp) {
256
		if (!isset($cp['enable']))
257
			continue;
258
259
		if ($curzone == '') {
260
			$tabactive = true;
261
			$curzone = $cpkey;
262
		} elseif ($curzone == $cpkey) {
263
			$tabactive = true;
264
		} else {
265
			$tabactive = false;
266
		}
267
268
		$cp_zones_tab_array[] = array($cp['zone'], $tabactive, "status_rrd_graph.php?cat=captiveportal&zone=$cpkey");
269
	}
270
}
271
272 89d25faf Seth Mos
include("head.inc");
273 ce49a7c9 Darren Embry
?>
274
275
<?php if ($curcat === "custom") { ?>
276
	<link rel="stylesheet" type="text/css" href="/javascript/jquery-ui-timepicker-addon/css/jquery-ui-timepicker-addon.css" />
277 31d6f24b Darren Embry
	<?php if (file_exists("{$g['www_path']}/themes/{$g['theme']}/jquery-ui.custom.css")) { ?>
278
		<link rel="stylesheet" type="text/css" href="/themes/<?= $g['theme'] ?>/jquery-ui.custom.css" />
279
	<?php } else { ?>
280
		<link rel="stylesheet" type="text/css" href="/javascript/jquery/jquery-ui.custom.css" />
281
	<?php } ?>
282 ce49a7c9 Darren Embry
	<script type="text/javascript" src="/javascript/jquery-ui-timepicker-addon/js/jquery-ui-timepicker-addon.js"></script>
283
	<script type="text/javascript">
284
		jQuery(function ($) {
285
			var options = {
286
				dateFormat: 'mm/dd/yy',
287
				timeFormat: 'hh:mm:ss',
288
				showSecond: true
289
			};
290
			$("#startDateTime").datetimepicker(options);
291
			$("#endDateTime").datetimepicker(options);
292
		});
293
	</script>
294
	</head>
295
<?php } ?>
296
297
<?php
298 6ab7ae50 Seth Mos
299 7d906758 smos
function get_dates($curperiod, $graph) {
300 97acf646 Erik Fonnesbeck
	global $graph_length;
301 7d906758 smos
	$now = time();
302
	$end = $now;
303
304 97acf646 Erik Fonnesbeck
	if($curperiod == "absolute") {
305
		$start = $end - $graph_length[$graph];
306
	} else {
307
		$curyear = date('Y', $now);
308
		$curmonth = date('m', $now);
309
		$curweek = date('W', $now);
310
		$curweekday = date('N', $now) - 1; // We want to start on monday
311
		$curday = date('d', $now);
312
		$curhour = date('G', $now);
313 c7cfbbd8 smos
314 97acf646 Erik Fonnesbeck
		switch($curperiod) {
315
			case "previous":
316
				$offset = -1;
317
				break;
318
			default:
319
				$offset = 0;
320
		}
321
		switch($graph) {
322
			case "8hour":
323
				if($curhour < 24)
324
					$starthour = 16;
325
				if($curhour < 16)
326
					$starthour = 8;
327
				if($curhour < 8)
328
					$starthour = 0;
329
330
				switch($offset) {
331
					case 0:
332
						$houroffset = $starthour;
333
						break;
334
					default:
335
						$houroffset = $starthour + ($offset * 8);
336
						break;
337
				}
338
				$start = mktime($houroffset, 0, 0, $curmonth, $curday, $curyear);
339
				if($offset != 0) {
340
					$end = mktime(($houroffset + 8), 0, 0, $curmonth, $curday, $curyear);
341
				}
342
				break;
343
			case "day":
344
				$start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear);
345
				if($offset != 0)
346
					$end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear);
347
				break;
348
			case "week":
349
				switch($offset) {
350
					case 0:
351
						$weekoffset = 0;
352
						break;
353
					default:
354
						$weekoffset = ($offset * 7) - 7;
355
						break;
356
				}
357
				$start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset), $curyear);
358
				if($offset != 0)
359
					$end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset + 7), $curyear);
360
				break;
361
			case "month":
362
				$start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear);
363
				if($offset != 0)
364
					$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
365
				break;
366
			case "quarter":
367
				$start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear);
368
				if($offset != 0)
369
					$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
370
				break;
371
			case "year":
372
				$start = mktime(0, 0, 0, 1, 0, ($curyear + $offset));
373
				if($offset != 0)
374
					$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
375
				break;
376
			case "4year":
377
				$start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset));
378
				if($offset != 0)
379
					$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
380
				break;
381
		}
382 7d906758 smos
	}
383 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>";
384 7d906758 smos
	$dates = array();
385
	$dates['start'] = $start;
386
	$dates['end'] = $end;
387
	return $dates;
388
}
389
390 6ab7ae50 Seth Mos
?>
391 37285f69 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
392
<?php include("fbegin.inc"); ?>
393 59418cee Darren Embry
<?php if ($input_errors && count($input_errors)) { print_input_errors($input_errors); } ?>
394 89d25faf Seth Mos
<table width="100%" border="0" cellpadding="0" cellspacing="0">
395
        <tr>
396
                <td>
397
			<form name="form1" action="status_rrd_graph.php" method="get">
398
			<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>">
399
			<?php
400
			        $tab_array = array();
401
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
402 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("System"), $tabactive, "status_rrd_graph.php?cat=system");
403 89d25faf Seth Mos
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
404 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Traffic"), $tabactive, "status_rrd_graph.php?cat=traffic");
405 89d25faf Seth Mos
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
406 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Packets"), $tabactive, "status_rrd_graph.php?cat=packets");
407 89d25faf Seth Mos
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
408 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Quality"), $tabactive, "status_rrd_graph.php?cat=quality");
409 7432ce7b Seth Mos
				if($queues) {
410
					if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
411 d9a0c4b8 Vinicius Coque
						$tab_array[] = array(gettext("Queues"), $tabactive, "status_rrd_graph.php?cat=queues");
412 7432ce7b Seth Mos
					if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
413 d9a0c4b8 Vinicius Coque
						$tab_array[] = array(gettext("QueueDrops"), $tabactive, "status_rrd_graph.php?cat=queuedrops");
414 7432ce7b Seth Mos
				}
415
				if($wireless) {
416
					if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
417 4dea46ee Rafael Lucas
				        $tab_array[] = array(gettext("Wireless"), $tabactive, "status_rrd_graph.php?cat=wireless");
418 7432ce7b Seth Mos
				}
419
				if($cellular) {
420
					if($curcat == "cellular") { $tabactive = True; } else { $tabactive = False; }
421 4dea46ee Rafael Lucas
				        $tab_array[] = array(gettext("Cellular"), $tabactive, "status_rrd_graph.php?cat=cellular");
422 7432ce7b Seth Mos
				}
423 edd2d8b7 smos
				if($vpnusers) {
424
					if($curcat == "vpnusers") { $tabactive = True; } else { $tabactive = False; }
425
				        $tab_array[] = array("VPN", $tabactive, "status_rrd_graph.php?cat=vpnusers");
426 6b0c5ae6 smos
				}
427 20413b72 Warren Baker
				if($captiveportal) {
428
					if($curcat == "captiveportal") { $tabactive = True; } else { $tabactive = False; }
429
				        $tab_array[] = array("Captive Portal", $tabactive, "status_rrd_graph.php?cat=captiveportal");
430
				}
431 47e68f48 smos
				if($curcat == "custom") { $tabactive = True; } else { $tabactive = False; }
432 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Custom"), $tabactive, "status_rrd_graph.php?cat=custom");
433 69487053 Seth Mos
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
434 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Settings"), $tabactive, "status_rrd_graph_settings.php");
435 89d25faf Seth Mos
			        display_top_tabs($tab_array);
436
			?>
437
                </td>
438
        </tr>
439 cba9d7d9 Renato Botelho
	<?php if ($curcat == "captiveportal") : ?>
440
	<tr>
441
		<td class="tabnavtbl">
442
			<?php display_top_tabs($cp_zones_tab_array); ?>
443
		</td>
444
	</tr>
445
	<?php endif; ?>
446 89d25faf Seth Mos
        <tr>
447
                <td>
448
                        <div id="mainarea">
449
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
450
                                <tr>
451
                                        <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>
452
				</tr>
453
				<tr>
454
                                        <td colspan="2" class="list">
455 3e6ec5df Renato Botelho
					<?=gettext("Graphs:");?>
456 89d25faf Seth Mos
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
457
					<?php
458
459 47e68f48 smos
					if($curcat == "custom") {
460 9cd5e6f5 Erik Fonnesbeck
						foreach ($custom_databases as $db => $database) {
461 cfbfd941 smos
							$optionc = explode("-", $database);
462 47e68f48 smos
							$search = array("-", ".rrd", $optionc);
463
							$replace = array(" :: ", "", $friendly);
464
							echo "<option value=\"{$database}\"";
465
							$prettyprint = ucwords(str_replace($search, $replace, $database));
466
							if($curoption == $database) {
467 1d80829e Carlos Eduardo Ramos
								echo " selected";
468 47e68f48 smos
							}
469
							echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
470
						}
471
					}
472 a927edff Seth Mos
					foreach ($ui_databases as $db => $database) {
473 cba9d7d9 Renato Botelho
						if(! preg_match("/($curcat)/i", $database))
474 89d25faf Seth Mos
							continue;
475 cba9d7d9 Renato Botelho
476 8878f4bb Renato Botelho
						if (($curcat == "captiveportal") && !empty($curzone) && !preg_match("/captiveportal-{$curzone}/i", $database))
477 cba9d7d9 Renato Botelho
							continue;
478
479 cfbfd941 smos
						$optionc = explode("-", $database);
480 89d25faf Seth Mos
						$search = array("-", ".rrd", $optionc);
481 35551994 Seth Mos
						$replace = array(" :: ", "", $friendly);
482 47e68f48 smos
483 9850b625 Seth Mos
						switch($curcat) {
484 20413b72 Warren Baker
							case "captiveportal":
485 cba9d7d9 Renato Botelho
								$optionc = str_replace($search, $replace, $optionc[2]);
486 20413b72 Warren Baker
								echo "<option value=\"$optionc\"";
487
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
488
								break;
489 9850b625 Seth Mos
							case "system":
490 85a4aab6 Erik Fonnesbeck
								$optionc = str_replace($search, $replace, $optionc[1]);
491
								echo "<option value=\"$optionc\"";
492
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
493 9850b625 Seth Mos
								break;
494
							default:
495
								/* Deduce a interface if possible and use the description */
496
								$optionc = "$optionc[0]";
497
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
498 d9699f96 Seth Mos
								if(empty($friendly)) {
499
									$friendly = $optionc;
500
								}
501 9850b625 Seth Mos
								$search = array("-", ".rrd", $optionc);
502
								$replace = array(" :: ", "", $friendly);
503
								echo "<option value=\"$optionc\"";
504
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
505
						}
506
						if($curoption == $optionc) {
507 1d80829e Carlos Eduardo Ramos
							echo " selected";
508 89d25faf Seth Mos
						}
509
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
510
					}
511
512
					?>
513
					</select>
514
515 3e6ec5df Renato Botelho
					<?=gettext("Style:");?>
516 89d25faf Seth Mos
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
517
					<?php
518
					foreach ($styles as $style => $styled) {
519
						echo "<option value=\"$style\"";
520
						if ($style == $curstyle) echo " selected";
521
						echo ">" . htmlspecialchars($styled) . "</option>\n";
522
					}
523
					?>
524 7d906758 smos
					</select>
525
					
526 e4b57d26 Renato Botelho
					<?php
527 47e68f48 smos
					if($curcat <> "custom") {
528
					?>
529 3e6ec5df Renato Botelho
						<?=gettext("Period:");?>
530 47e68f48 smos
						<select name="period" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
531
						<?php
532
						foreach ($periods as $period => $value) {
533
							echo "<option value=\"$period\"";
534 1d80829e Carlos Eduardo Ramos
							if ($period == $curperiod) echo " selected";
535 47e68f48 smos
							echo ">" . htmlspecialchars($value) . "</option>\n";
536
						}
537 7d906758 smos
					}
538
					?>
539 89d25faf Seth Mos
					</select>
540
					<?php
541
542 47e68f48 smos
					if($curcat == "custom") {
543 59418cee Darren Embry
						$tz = date_default_timezone_get();
544
						$tz_msg = gettext("Enter date and/or time. Current timezone:") . " $tz";
545 ce49a7c9 Darren Embry
						$start_fmt = strftime("%m/%d/%Y %H:%M:%S", $start);
546
						$end_fmt   = strftime("%m/%d/%Y %H:%M:%S", $end);
547 6b0c5ae6 smos
						?>
548
						<?=gettext("Start:");?>
549 ce49a7c9 Darren Embry
						<input id="startDateTime" title="<?= htmlentities($tz_msg); ?>." type="text" name="start" class="formfldunknown" size="24" length="32" value="<?= htmlentities($start_fmt); ?>">
550 6b0c5ae6 smos
						<?=gettext("End:");?>
551 ce49a7c9 Darren Embry
						<input id="endDateTime" title="<?= htmlentities($tz_msg); ?>." type="text" name="end" class="formfldunknown" size="24" length="32" value="<?= htmlentities($end_fmt); ?>">
552 b8219006 Carlos Eduardo Ramos
						<input type="submit" name="Submit" value="<?=gettext("Go"); ?>">
553 3e6ec5df Renato Botelho
						<?php
554 6b0c5ae6 smos
						$curdatabase = $curoption;
555
						$graph = "custom-$curdatabase";
556 9cd5e6f5 Erik Fonnesbeck
						if(in_array($curdatabase, $custom_databases)) {
557 3a83296f Darren Embry
							$id = "{$graph}-{$curoption}-{$curdatabase}";
558
							$id = preg_replace('/\./', '_', $id);
559
560 6b0c5ae6 smos
							echo "<tr><td colspan=2 class=\"list\">\n";
561 3a83296f Darren Embry
							echo "<IMG BORDER='0' name='{$id}' ";
562
							echo "id='{$id}' ALT=\"$prettydb Graph\" ";
563 6b0c5ae6 smos
							echo "SRC=\"status_rrd_graph_img.php?start={$start}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
564
							echo "<br /><hr><br />\n";								
565
							echo "</td></tr>\n";
566
						}
567
					} else {
568
						foreach($graphs as $graph) {
569
							/* check which databases are valid for our category */
570
							foreach($ui_databases as $curdatabase) {
571 cba9d7d9 Renato Botelho
								if(! preg_match("/($curcat)/i", $curdatabase))
572 6b0c5ae6 smos
									continue;
573 cba9d7d9 Renato Botelho
574 8878f4bb Renato Botelho
								if (($curcat == "captiveportal") && !empty($curzone) && !preg_match("/captiveportal-{$curzone}/i", $curdatabase))
575 cba9d7d9 Renato Botelho
									continue;
576
577 cfbfd941 smos
								$optionc = explode("-", $curdatabase);
578 6b0c5ae6 smos
								$search = array("-", ".rrd", $optionc);
579
								$replace = array(" :: ", "", $friendly);
580
								switch($curoption) {
581
									case "outbound":
582 2103b252 Erik Fonnesbeck
										/* make sure we do not show the placeholder databases in the outbound view */
583
										if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
584
											continue 2;
585
										}
586 6b0c5ae6 smos
										/* only show interfaces with a gateway */
587
										$optionc = "$optionc[0]";
588
										if(!interface_has_gateway($optionc)) {
589 2103b252 Erik Fonnesbeck
											if(!isset($gateways_arr)) {
590
												if(preg_match("/quality/i", $curdatabase))
591
													$gateways_arr = return_gateways_array();
592
												else
593
													$gateways_arr = array();
594
											}
595 44aef543 Erik Fonnesbeck
											$found_gateway = false;
596
											foreach ($gateways_arr as $gw) {
597
												if ($gw['name'] == $optionc) {
598
													$found_gateway = true;
599
													break;
600
												}
601
											}
602
											if(!$found_gateway) {
603 6b0c5ae6 smos
												continue 2;
604
											}
605
										}
606 44aef543 Erik Fonnesbeck
										if(! preg_match("/(^$optionc-|-$optionc\\.)/i", $curdatabase)) {
607 a927edff Seth Mos
											continue 2;
608
										}
609 6b0c5ae6 smos
										break;
610
									case "allgraphs":
611
										/* make sure we do not show the placeholder databases in the all view */
612
										if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
613
											continue 2;
614
										}
615
										break;
616
									default:
617
										/* just use the name here */
618 44aef543 Erik Fonnesbeck
										if(! preg_match("/(^$curoption-|-$curoption\\.)/i", $curdatabase)) {
619 6b0c5ae6 smos
											continue 2;
620
										}
621
								}
622 9cd5e6f5 Erik Fonnesbeck
								if(in_array($curdatabase, $ui_databases)) {
623 3a83296f Darren Embry
									$id = "{$graph}-{$curoption}-{$curdatabase}";
624
									$id = preg_replace('/\./', '_', $id);
625
626 6b0c5ae6 smos
									$dates = get_dates($curperiod, $graph);
627
									$start = $dates['start'];
628
									$end = $dates['end'];
629
									echo "<tr><td colspan=2 class=\"list\">\n";
630 3a83296f Darren Embry
									echo "<IMG BORDER='0' name='{$id}' ";
631
									echo "id='{$id}' ALT=\"$prettydb Graph\" ";
632 6b0c5ae6 smos
									echo "SRC=\"status_rrd_graph_img.php?start={$start}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
633
									echo "<br /><hr><br />\n";								
634
									echo "</td></tr>\n";
635
								}
636 89d25faf Seth Mos
							}
637
						}
638
					}
639
					?>
640
					</td>
641
				</tr>
642
				<tr>
643
					<td colspan=2 class="list">
644
					<script language="javascript">
645
						function update_graph_images() {
646
							//alert('updating');
647
							var randomid = Math.floor(Math.random()*11);
648
							<?php
649 7d906758 smos
							foreach($graphs as $graph) {
650 683bf031 Seth Mos
								/* check which databases are valid for our category */
651 9cd5e6f5 Erik Fonnesbeck
								foreach($ui_databases as $curdatabase) {
652 683bf031 Seth Mos
									if(! stristr($curdatabase, $curcat)) {
653
										continue;
654
									}
655 cfbfd941 smos
									$optionc = explode("-", $curdatabase);
656 683bf031 Seth Mos
									$search = array("-", ".rrd", $optionc);
657
									$replace = array(" :: ", "", $friendly);
658
									switch($curoption) {
659
										case "outbound":
660 2103b252 Erik Fonnesbeck
											/* make sure we do not show the placeholder databases in the outbound view */
661
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
662
												continue 2;
663
											}
664
											/* only show interfaces with a gateway */
665 44aef543 Erik Fonnesbeck
											$optionc = "$optionc[0]";
666 2e76e612 Seth Mos
											if(!interface_has_gateway($optionc)) {
667 44aef543 Erik Fonnesbeck
												if(!isset($gateways_arr))
668 2103b252 Erik Fonnesbeck
													if(preg_match("/quality/i", $curdatabase))
669
														$gateways_arr = return_gateways_array();
670
													else
671
														$gateways_arr = array();
672 44aef543 Erik Fonnesbeck
												$found_gateway = false;
673
												foreach ($gateways_arr as $gw) {
674
													if ($gw['name'] == $optionc) {
675
														$found_gateway = true;
676
														break;
677
													}
678
												}
679
												if(!$found_gateway) {
680 683bf031 Seth Mos
													continue 2;
681 44aef543 Erik Fonnesbeck
												}
682
											}
683
											if(! preg_match("/(^$optionc-|-$optionc\\.)/i", $curdatabase)) {
684
												continue 2;
685 683bf031 Seth Mos
											}
686 9850b625 Seth Mos
											break;
687 683bf031 Seth Mos
										case "allgraphs":
688 9850b625 Seth Mos
											/* make sure we do not show the placeholder databases in the all view */
689
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
690
												continue 2;
691
											}
692
											break;
693 683bf031 Seth Mos
										default:
694
											/* just use the name here */
695 44aef543 Erik Fonnesbeck
											if(! preg_match("/(^$curoption-|-$curoption\\.)/i", $curdatabase)) {
696 683bf031 Seth Mos
												continue 2;
697
											}
698
									}
699 7d906758 smos
									$dates = get_dates($curperiod, $graph);
700
									$start = $dates['start'];
701 d60f510a smos
									if($curperiod == "current") {
702
										$end = $dates['end'];
703
									}
704 78d84a88 Vinicius Coque
									/* generate update events utilizing jQuery('') feature */
705 3a83296f Darren Embry
									$id = "{$graph}-{$curoption}-{$curdatabase}";
706
									$id = preg_replace('/\./', '_', $id);
707
708 683bf031 Seth Mos
									echo "\n";
709 3a83296f Darren Embry
									echo "\t\tjQuery('#{$id}').attr('src','status_rrd_graph_img.php?start={$start}&graph={$graph}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid);\n";
710 683bf031 Seth Mos
									}
711
								}
712 89d25faf Seth Mos
							?>
713
							window.setTimeout('update_graph_images()', 355000);
714
						}
715
						window.setTimeout('update_graph_images()', 355000);
716
					</script>
717
					</form>
718
					</td>
719
				</tr>
720
			</table>
721
		</div>
722
		</td>
723
	</tr>
724
</table>
725 37285f69 Scott Ullrich
726
<?php include("fend.inc"); ?>
727
</body>
728
</html>