Project

General

Profile

Download (24 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 c7a1d428 N0YB
$graphs = array("eight_hour", "day", "week", "month", "quarter", "year", "four_year");
238 97acf646 Erik Fonnesbeck
$periods = array("absolute" => gettext("Absolute Timespans"), "current" => gettext("Current Period"), "previous" => gettext("Previous Period"));
239
$graph_length = array(
240 c7a1d428 N0YB
	"eight_hour" => 28800,
241 97acf646 Erik Fonnesbeck
	"day" => 86400,
242
	"week" => 604800,
243 91c6c902 N0YB
	"month" => 2678400,
244
	"quarter" => 7948800,
245 97acf646 Erik Fonnesbeck
	"year" => 31622400,
246 c7a1d428 N0YB
	"four_year" => 126230400);
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 c7a1d428 N0YB
<?php }
295
if (isset($closehead))
296
	echo "</head>";
297
?>
298 ce49a7c9 Darren Embry
299
<?php
300 6ab7ae50 Seth Mos
301 7d906758 smos
function get_dates($curperiod, $graph) {
302 97acf646 Erik Fonnesbeck
	global $graph_length;
303 7d906758 smos
	$now = time();
304
	$end = $now;
305
306 97acf646 Erik Fonnesbeck
	if($curperiod == "absolute") {
307
		$start = $end - $graph_length[$graph];
308
	} else {
309
		$curyear = date('Y', $now);
310
		$curmonth = date('m', $now);
311
		$curweek = date('W', $now);
312
		$curweekday = date('N', $now) - 1; // We want to start on monday
313
		$curday = date('d', $now);
314
		$curhour = date('G', $now);
315 c7cfbbd8 smos
316 97acf646 Erik Fonnesbeck
		switch($curperiod) {
317
			case "previous":
318
				$offset = -1;
319
				break;
320
			default:
321
				$offset = 0;
322
		}
323
		switch($graph) {
324 c7a1d428 N0YB
			case "eight_hour":
325 97acf646 Erik Fonnesbeck
				if($curhour < 24)
326
					$starthour = 16;
327
				if($curhour < 16)
328
					$starthour = 8;
329
				if($curhour < 8)
330
					$starthour = 0;
331
332
				switch($offset) {
333
					case 0:
334
						$houroffset = $starthour;
335
						break;
336
					default:
337
						$houroffset = $starthour + ($offset * 8);
338
						break;
339
				}
340
				$start = mktime($houroffset, 0, 0, $curmonth, $curday, $curyear);
341
				if($offset != 0) {
342
					$end = mktime(($houroffset + 8), 0, 0, $curmonth, $curday, $curyear);
343
				}
344
				break;
345
			case "day":
346
				$start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear);
347
				if($offset != 0)
348
					$end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear);
349
				break;
350
			case "week":
351
				switch($offset) {
352
					case 0:
353
						$weekoffset = 0;
354
						break;
355
					default:
356
						$weekoffset = ($offset * 7) - 7;
357
						break;
358
				}
359
				$start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset), $curyear);
360
				if($offset != 0)
361
					$end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset + 7), $curyear);
362
				break;
363
			case "month":
364
				$start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear);
365
				if($offset != 0)
366
					$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
367
				break;
368
			case "quarter":
369
				$start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear);
370
				if($offset != 0)
371
					$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
372
				break;
373
			case "year":
374
				$start = mktime(0, 0, 0, 1, 0, ($curyear + $offset));
375
				if($offset != 0)
376
					$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
377
				break;
378 c7a1d428 N0YB
			case "four_year":
379 97acf646 Erik Fonnesbeck
				$start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset));
380
				if($offset != 0)
381
					$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
382
				break;
383
		}
384 7d906758 smos
	}
385 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>";
386 7d906758 smos
	$dates = array();
387
	$dates['start'] = $start;
388
	$dates['end'] = $end;
389
	return $dates;
390
}
391
392 6ab7ae50 Seth Mos
?>
393 37285f69 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
394
<?php include("fbegin.inc"); ?>
395 59418cee Darren Embry
<?php if ($input_errors && count($input_errors)) { print_input_errors($input_errors); } ?>
396 c7a1d428 N0YB
<form name="form1" action="status_rrd_graph.php" method="get">
397
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
398 89d25faf Seth Mos
        <tr>
399 c7a1d428 N0YB
			<td>
400
				<input type="hidden" name="cat" value="<?php echo "$curcat"; ?>"/>
401 89d25faf Seth Mos
			<?php
402
			        $tab_array = array();
403
				if($curcat == "system") { $tabactive = True; } else { $tabactive = False; }
404 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("System"), $tabactive, "status_rrd_graph.php?cat=system");
405 89d25faf Seth Mos
				if($curcat == "traffic") { $tabactive = True; } else { $tabactive = False; }
406 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Traffic"), $tabactive, "status_rrd_graph.php?cat=traffic");
407 89d25faf Seth Mos
				if($curcat == "packets") { $tabactive = True; } else { $tabactive = False; }
408 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Packets"), $tabactive, "status_rrd_graph.php?cat=packets");
409 89d25faf Seth Mos
				if($curcat == "quality") { $tabactive = True; } else { $tabactive = False; }
410 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Quality"), $tabactive, "status_rrd_graph.php?cat=quality");
411 7432ce7b Seth Mos
				if($queues) {
412
					if($curcat == "queues") { $tabactive = True; } else { $tabactive = False; }
413 d9a0c4b8 Vinicius Coque
						$tab_array[] = array(gettext("Queues"), $tabactive, "status_rrd_graph.php?cat=queues");
414 7432ce7b Seth Mos
					if($curcat == "queuedrops") { $tabactive = True; } else { $tabactive = False; }
415 d9a0c4b8 Vinicius Coque
						$tab_array[] = array(gettext("QueueDrops"), $tabactive, "status_rrd_graph.php?cat=queuedrops");
416 7432ce7b Seth Mos
				}
417
				if($wireless) {
418
					if($curcat == "wireless") { $tabactive = True; } else { $tabactive = False; }
419 4dea46ee Rafael Lucas
				        $tab_array[] = array(gettext("Wireless"), $tabactive, "status_rrd_graph.php?cat=wireless");
420 7432ce7b Seth Mos
				}
421
				if($cellular) {
422
					if($curcat == "cellular") { $tabactive = True; } else { $tabactive = False; }
423 4dea46ee Rafael Lucas
				        $tab_array[] = array(gettext("Cellular"), $tabactive, "status_rrd_graph.php?cat=cellular");
424 7432ce7b Seth Mos
				}
425 edd2d8b7 smos
				if($vpnusers) {
426
					if($curcat == "vpnusers") { $tabactive = True; } else { $tabactive = False; }
427
				        $tab_array[] = array("VPN", $tabactive, "status_rrd_graph.php?cat=vpnusers");
428 6b0c5ae6 smos
				}
429 20413b72 Warren Baker
				if($captiveportal) {
430
					if($curcat == "captiveportal") { $tabactive = True; } else { $tabactive = False; }
431
				        $tab_array[] = array("Captive Portal", $tabactive, "status_rrd_graph.php?cat=captiveportal");
432
				}
433 47e68f48 smos
				if($curcat == "custom") { $tabactive = True; } else { $tabactive = False; }
434 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Custom"), $tabactive, "status_rrd_graph.php?cat=custom");
435 69487053 Seth Mos
				if($curcat == "settings") { $tabactive = True; } else { $tabactive = False; }
436 4dea46ee Rafael Lucas
			        $tab_array[] = array(gettext("Settings"), $tabactive, "status_rrd_graph_settings.php");
437 89d25faf Seth Mos
			        display_top_tabs($tab_array);
438
			?>
439
                </td>
440
        </tr>
441 cba9d7d9 Renato Botelho
	<?php if ($curcat == "captiveportal") : ?>
442
	<tr>
443
		<td class="tabnavtbl">
444
			<?php display_top_tabs($cp_zones_tab_array); ?>
445
		</td>
446
	</tr>
447
	<?php endif; ?>
448 89d25faf Seth Mos
        <tr>
449
                <td>
450
                        <div id="mainarea">
451
                        <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
452
                                <tr>
453
                                        <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>
454
				</tr>
455
				<tr>
456
                                        <td colspan="2" class="list">
457 3e6ec5df Renato Botelho
					<?=gettext("Graphs:");?>
458 be773f24 jim-p
					<?php if (!empty($curzone)): ?>
459
					<input type="hidden" name="zone" value="<?= htmlspecialchars($curzone) ?>">
460
					<?php endif; ?>
461 89d25faf Seth Mos
					<select name="option" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
462
					<?php
463
464 47e68f48 smos
					if($curcat == "custom") {
465 9cd5e6f5 Erik Fonnesbeck
						foreach ($custom_databases as $db => $database) {
466 cfbfd941 smos
							$optionc = explode("-", $database);
467 47e68f48 smos
							$search = array("-", ".rrd", $optionc);
468
							$replace = array(" :: ", "", $friendly);
469
							echo "<option value=\"{$database}\"";
470
							$prettyprint = ucwords(str_replace($search, $replace, $database));
471
							if($curoption == $database) {
472 c7a1d428 N0YB
								echo " selected=\"selected\"";
473 47e68f48 smos
							}
474
							echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
475
						}
476
					}
477 a927edff Seth Mos
					foreach ($ui_databases as $db => $database) {
478 cba9d7d9 Renato Botelho
						if(! preg_match("/($curcat)/i", $database))
479 89d25faf Seth Mos
							continue;
480 cba9d7d9 Renato Botelho
481 8878f4bb Renato Botelho
						if (($curcat == "captiveportal") && !empty($curzone) && !preg_match("/captiveportal-{$curzone}/i", $database))
482 cba9d7d9 Renato Botelho
							continue;
483
484 cfbfd941 smos
						$optionc = explode("-", $database);
485 89d25faf Seth Mos
						$search = array("-", ".rrd", $optionc);
486 35551994 Seth Mos
						$replace = array(" :: ", "", $friendly);
487 47e68f48 smos
488 9850b625 Seth Mos
						switch($curcat) {
489 20413b72 Warren Baker
							case "captiveportal":
490 cba9d7d9 Renato Botelho
								$optionc = str_replace($search, $replace, $optionc[2]);
491 20413b72 Warren Baker
								echo "<option value=\"$optionc\"";
492
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
493
								break;
494 9850b625 Seth Mos
							case "system":
495 85a4aab6 Erik Fonnesbeck
								$optionc = str_replace($search, $replace, $optionc[1]);
496
								echo "<option value=\"$optionc\"";
497
								$prettyprint = ucwords(str_replace($search, $replace, $optionc));
498 9850b625 Seth Mos
								break;
499
							default:
500
								/* Deduce a interface if possible and use the description */
501
								$optionc = "$optionc[0]";
502
								$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
503 d9699f96 Seth Mos
								if(empty($friendly)) {
504
									$friendly = $optionc;
505
								}
506 9850b625 Seth Mos
								$search = array("-", ".rrd", $optionc);
507
								$replace = array(" :: ", "", $friendly);
508
								echo "<option value=\"$optionc\"";
509
								$prettyprint = ucwords(str_replace($search, $replace, $friendly));
510
						}
511
						if($curoption == $optionc) {
512 c7a1d428 N0YB
							echo " selected=\"selected\"";
513 89d25faf Seth Mos
						}
514
						echo ">" . htmlspecialchars($prettyprint) . "</option>\n";
515
					}
516
517
					?>
518
					</select>
519
520 3e6ec5df Renato Botelho
					<?=gettext("Style:");?>
521 89d25faf Seth Mos
					<select name="style" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
522
					<?php
523
					foreach ($styles as $style => $styled) {
524
						echo "<option value=\"$style\"";
525 c7a1d428 N0YB
						if ($style == $curstyle) echo " selected=\"selected\"";
526 89d25faf Seth Mos
						echo ">" . htmlspecialchars($styled) . "</option>\n";
527
					}
528
					?>
529 7d906758 smos
					</select>
530
					
531 e4b57d26 Renato Botelho
					<?php
532 47e68f48 smos
					if($curcat <> "custom") {
533
					?>
534 3e6ec5df Renato Botelho
						<?=gettext("Period:");?>
535 47e68f48 smos
						<select name="period" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
536
						<?php
537
						foreach ($periods as $period => $value) {
538
							echo "<option value=\"$period\"";
539 c7a1d428 N0YB
							if ($period == $curperiod) echo " selected=\"selected\"";
540 47e68f48 smos
							echo ">" . htmlspecialchars($value) . "</option>\n";
541
						}
542 c7a1d428 N0YB
						?>
543
						</select>
544
					<?php
545 7d906758 smos
					}
546
					?>
547 89d25faf Seth Mos
548 c7a1d428 N0YB
					<?php
549 47e68f48 smos
					if($curcat == "custom") {
550 59418cee Darren Embry
						$tz = date_default_timezone_get();
551
						$tz_msg = gettext("Enter date and/or time. Current timezone:") . " $tz";
552 ce49a7c9 Darren Embry
						$start_fmt = strftime("%m/%d/%Y %H:%M:%S", $start);
553
						$end_fmt   = strftime("%m/%d/%Y %H:%M:%S", $end);
554 6b0c5ae6 smos
						?>
555
						<?=gettext("Start:");?>
556 c7a1d428 N0YB
						<input id="startDateTime" title="<?= htmlentities($tz_msg); ?>." type="text" name="start" class="formfldunknown" size="24" maxlength="32" value="<?= htmlentities($start_fmt); ?>"/>
557 6b0c5ae6 smos
						<?=gettext("End:");?>
558 c7a1d428 N0YB
						<input id="endDateTime" title="<?= htmlentities($tz_msg); ?>." type="text" name="end" class="formfldunknown" size="24" maxlength="32" value="<?= htmlentities($end_fmt); ?>"/>
559
						<input type="submit" name="Submit" value="<?=gettext("Go"); ?>"/>
560 3e6ec5df Renato Botelho
						<?php
561 6b0c5ae6 smos
						$curdatabase = $curoption;
562
						$graph = "custom-$curdatabase";
563 9cd5e6f5 Erik Fonnesbeck
						if(in_array($curdatabase, $custom_databases)) {
564 3a83296f Darren Embry
							$id = "{$graph}-{$curoption}-{$curdatabase}";
565
							$id = preg_replace('/\./', '_', $id);
566
567 c7a1d428 N0YB
							echo "<table><tr><td colspan=\"2\" class=\"list\">\n";
568
							echo "<img border='0' name='{$id}' ";
569
							echo "id='{$id}' alt=\"$prettydb Graph\" ";
570
							echo "src=\"status_rrd_graph_img.php?start={$start}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
571
							echo "<br /><hr /><br />\n";								
572
							echo "</td></tr></table>\n";
573 6b0c5ae6 smos
						}
574
					} else {
575
						foreach($graphs as $graph) {
576
							/* check which databases are valid for our category */
577
							foreach($ui_databases as $curdatabase) {
578 cba9d7d9 Renato Botelho
								if(! preg_match("/($curcat)/i", $curdatabase))
579 6b0c5ae6 smos
									continue;
580 cba9d7d9 Renato Botelho
581 8878f4bb Renato Botelho
								if (($curcat == "captiveportal") && !empty($curzone) && !preg_match("/captiveportal-{$curzone}/i", $curdatabase))
582 cba9d7d9 Renato Botelho
									continue;
583
584 cfbfd941 smos
								$optionc = explode("-", $curdatabase);
585 6b0c5ae6 smos
								$search = array("-", ".rrd", $optionc);
586
								$replace = array(" :: ", "", $friendly);
587
								switch($curoption) {
588
									case "outbound":
589 2103b252 Erik Fonnesbeck
										/* make sure we do not show the placeholder databases in the outbound view */
590
										if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
591
											continue 2;
592
										}
593 6b0c5ae6 smos
										/* only show interfaces with a gateway */
594
										$optionc = "$optionc[0]";
595
										if(!interface_has_gateway($optionc)) {
596 2103b252 Erik Fonnesbeck
											if(!isset($gateways_arr)) {
597
												if(preg_match("/quality/i", $curdatabase))
598
													$gateways_arr = return_gateways_array();
599
												else
600
													$gateways_arr = array();
601
											}
602 44aef543 Erik Fonnesbeck
											$found_gateway = false;
603
											foreach ($gateways_arr as $gw) {
604
												if ($gw['name'] == $optionc) {
605
													$found_gateway = true;
606
													break;
607
												}
608
											}
609
											if(!$found_gateway) {
610 6b0c5ae6 smos
												continue 2;
611
											}
612
										}
613 44aef543 Erik Fonnesbeck
										if(! preg_match("/(^$optionc-|-$optionc\\.)/i", $curdatabase)) {
614 a927edff Seth Mos
											continue 2;
615
										}
616 6b0c5ae6 smos
										break;
617
									case "allgraphs":
618
										/* make sure we do not show the placeholder databases in the all view */
619
										if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
620
											continue 2;
621
										}
622
										break;
623
									default:
624
										/* just use the name here */
625 44aef543 Erik Fonnesbeck
										if(! preg_match("/(^$curoption-|-$curoption\\.)/i", $curdatabase)) {
626 6b0c5ae6 smos
											continue 2;
627
										}
628
								}
629 9cd5e6f5 Erik Fonnesbeck
								if(in_array($curdatabase, $ui_databases)) {
630 3a83296f Darren Embry
									$id = "{$graph}-{$curoption}-{$curdatabase}";
631
									$id = preg_replace('/\./', '_', $id);
632
633 6b0c5ae6 smos
									$dates = get_dates($curperiod, $graph);
634
									$start = $dates['start'];
635
									$end = $dates['end'];
636 c7a1d428 N0YB
									echo "<table><tr><td colspan=\"2\" class=\"list\">\n";
637
									echo "<img border='0' name='{$id}' ";
638
									echo "id='{$id}' alt=\"$prettydb Graph\" ";
639
									echo "src=\"status_rrd_graph_img.php?start={$start}&amp;end={$end}&amp;database={$curdatabase}&amp;style={$curstyle}&amp;graph={$graph}\" />\n";
640
									echo "<br /><hr /><br />\n";								
641
									echo "</td></tr></table>\n";
642 6b0c5ae6 smos
								}
643 89d25faf Seth Mos
							}
644
						}
645
					}
646
					?>
647
					</td>
648
				</tr>
649
				<tr>
650 c7a1d428 N0YB
					<td colspan="2" class="list">
651
					<script type="text/javascript">
652 89d25faf Seth Mos
						function update_graph_images() {
653
							//alert('updating');
654 c7a1d428 N0YB
							var amp = decodeURIComponent("%26");
655 89d25faf Seth Mos
							var randomid = Math.floor(Math.random()*11);
656
							<?php
657 7d906758 smos
							foreach($graphs as $graph) {
658 683bf031 Seth Mos
								/* check which databases are valid for our category */
659 9cd5e6f5 Erik Fonnesbeck
								foreach($ui_databases as $curdatabase) {
660 683bf031 Seth Mos
									if(! stristr($curdatabase, $curcat)) {
661
										continue;
662
									}
663 cfbfd941 smos
									$optionc = explode("-", $curdatabase);
664 683bf031 Seth Mos
									$search = array("-", ".rrd", $optionc);
665
									$replace = array(" :: ", "", $friendly);
666
									switch($curoption) {
667
										case "outbound":
668 2103b252 Erik Fonnesbeck
											/* make sure we do not show the placeholder databases in the outbound view */
669
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
670
												continue 2;
671
											}
672
											/* only show interfaces with a gateway */
673 44aef543 Erik Fonnesbeck
											$optionc = "$optionc[0]";
674 2e76e612 Seth Mos
											if(!interface_has_gateway($optionc)) {
675 44aef543 Erik Fonnesbeck
												if(!isset($gateways_arr))
676 2103b252 Erik Fonnesbeck
													if(preg_match("/quality/i", $curdatabase))
677
														$gateways_arr = return_gateways_array();
678
													else
679
														$gateways_arr = array();
680 44aef543 Erik Fonnesbeck
												$found_gateway = false;
681
												foreach ($gateways_arr as $gw) {
682
													if ($gw['name'] == $optionc) {
683
														$found_gateway = true;
684
														break;
685
													}
686
												}
687
												if(!$found_gateway) {
688 683bf031 Seth Mos
													continue 2;
689 44aef543 Erik Fonnesbeck
												}
690
											}
691
											if(! preg_match("/(^$optionc-|-$optionc\\.)/i", $curdatabase)) {
692
												continue 2;
693 683bf031 Seth Mos
											}
694 9850b625 Seth Mos
											break;
695 683bf031 Seth Mos
										case "allgraphs":
696 9850b625 Seth Mos
											/* make sure we do not show the placeholder databases in the all view */
697
											if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
698
												continue 2;
699
											}
700
											break;
701 683bf031 Seth Mos
										default:
702
											/* just use the name here */
703 44aef543 Erik Fonnesbeck
											if(! preg_match("/(^$curoption-|-$curoption\\.)/i", $curdatabase)) {
704 683bf031 Seth Mos
												continue 2;
705
											}
706
									}
707 7d906758 smos
									$dates = get_dates($curperiod, $graph);
708
									$start = $dates['start'];
709 d60f510a smos
									if($curperiod == "current") {
710
										$end = $dates['end'];
711
									}
712 78d84a88 Vinicius Coque
									/* generate update events utilizing jQuery('') feature */
713 3a83296f Darren Embry
									$id = "{$graph}-{$curoption}-{$curdatabase}";
714
									$id = preg_replace('/\./', '_', $id);
715
716 683bf031 Seth Mos
									echo "\n";
717 c7a1d428 N0YB
									echo "\t\tjQuery('#{$id}').attr('src','status_rrd_graph_img.php?start={$start}' + amp + 'graph={$graph}' + amp + 'database={$curdatabase}' + amp + 'style={$curstyle}' + amp + 'tmp=' + randomid);\n";
718 683bf031 Seth Mos
									}
719
								}
720 89d25faf Seth Mos
							?>
721
							window.setTimeout('update_graph_images()', 355000);
722
						}
723
						window.setTimeout('update_graph_images()', 355000);
724
					</script>
725
					</td>
726
				</tr>
727
			</table>
728
		</div>
729
		</td>
730
	</tr>
731
</table>
732 c7a1d428 N0YB
</form>
733 37285f69 Scott Ullrich
734
<?php include("fend.inc"); ?>
735
</body>
736
</html>