Project

General

Profile

Download (20 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 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8 37285f69 Scott Ullrich
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 458a6879 sbeaver
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 37285f69 Scott Ullrich
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 cccdc5ce sbeaver
/*
32 3c44b044 sbeaver
	pfSense_MODULE: system
33 1d333258 Scott Ullrich
*/
34 37285f69 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-status-rrdgraphs
37
##|*NAME=Status: RRD Graphs page
38
##|*DESCR=Allow access to the 'Status: RRD Graphs' page.
39
##|*MATCH=status_rrd_graph.php*
40
##|-PRIV
41
42 37285f69 Scott Ullrich
require("guiconfig.inc");
43 5208e648 Ermal Lu?i
require_once("filter.inc");
44
require("shaper.inc");
45 483e6de8 Scott Ullrich
require_once("rrd.inc");
46 37285f69 Scott Ullrich
47 59418cee Darren Embry
unset($input_errors);
48
49 70281b3a Seth Mos
/* if the rrd graphs are not enabled redirect to settings page */
50
if(! isset($config['rrd']['enable'])) {
51
	header("Location: status_rrd_graph_settings.php");
52
}
53
54 3c44b044 sbeaver
$home = getcwd();
55 329bb764 Seth Mos
$rrddbpath = "/var/db/rrd/";
56 002bc4ab smos
chdir($rrddbpath);
57
$databases = glob("*.rrd");
58 3c44b044 sbeaver
chdir($home);
59 329bb764 Seth Mos
60 89d25faf Seth Mos
if ($_GET['cat']) {
61 034f08e7 Scott Ullrich
	$curcat = htmlspecialchars($_GET['cat']);
62 37285f69 Scott Ullrich
} else {
63 69487053 Seth Mos
	if(! empty($config['rrd']['category'])) {
64
		$curcat = $config['rrd']['category'];
65
	} else {
66
		$curcat = "system";
67
	}
68 89d25faf Seth Mos
}
69
70 a564b6e7 sbeaver
if ($_POST['cat']) {
71
	$curcat = htmlspecialchars($_POST['cat']);
72
}
73
74 cba9d7d9 Renato Botelho
if ($_GET['zone'])
75
	$curzone = $_GET['zone'];
76
else
77
	$curzone = '';
78
79 3c44b044 sbeaver
if ($_POST['period']) {
80
	$curperiod = $_POST['period'];
81 7d906758 smos
} else {
82 97acf646 Erik Fonnesbeck
	if(! empty($config['rrd']['period'])) {
83
		$curperiod = $config['rrd']['period'];
84
	} else {
85
		$curperiod = "absolute";
86
	}
87 7d906758 smos
}
88
89 3c44b044 sbeaver
if ($_POST['style']) {
90
	$curstyle = $_POST['style'];
91
} else {
92
	if(! empty($config['rrd']['style'])) {
93
		$curstyle = $config['rrd']['style'];
94
	} else {
95
		$curstyle = "absolute";
96
	}
97
}
98
99
if ($_POST['option']) {
100
	$curoption = $_POST['option'];
101 89d25faf Seth Mos
} else {
102 329bb764 Seth Mos
	switch($curcat) {
103
		case "system":
104
			$curoption = "processor";
105
			break;
106
		case "queues":
107
			$curoption = "queues";
108
			break;
109
		case "queuedrops":
110
			$curoption = "queuedrops";
111 7432ce7b Seth Mos
			break;
112
		case "quality":
113
			foreach($databases as $database) {
114
				if(preg_match("/[-]quality\.rrd/i", $database)) {
115
					/* pick off the 1st database we find that matches the quality graph */
116
					$name = explode("-", $database);
117
					$curoption = "$name[0]";
118
					continue 2;
119
				}
120
			}
121
		case "wireless":
122
			foreach($databases as $database) {
123
				if(preg_match("/[-]wireless\.rrd/i", $database)) {
124
					/* pick off the 1st database we find that matches the wireless graph */
125
					$name = explode("-", $database);
126
					$curoption = "$name[0]";
127
					continue 2;
128
				}
129
			}
130
		case "cellular":
131
			foreach($databases as $database) {
132
				if(preg_match("/[-]cellular\.rrd/i", $database)) {
133
					/* pick off the 1st database we find that matches the celullar graph */
134
					$name = explode("-", $database);
135
					$curoption = "$name[0]";
136
					continue 2;
137
				}
138 329bb764 Seth Mos
			}
139 edd2d8b7 smos
		case "vpnusers":
140 6b0c5ae6 smos
			foreach($databases as $database) {
141 edd2d8b7 smos
				if(preg_match("/[-]vpnusers\.rrd/i", $database)) {
142 6b0c5ae6 smos
					/* pick off the 1st database we find that matches the VPN graphs */
143
					$name = explode("-", $database);
144
					$curoption = "$name[0]";
145
					continue 2;
146
				}
147
			}
148 20413b72 Warren Baker
		case "captiveportal":
149
			$curoption = "allgraphs";
150
			break;
151 2cdb75f8 nagyrobi
		case "ntpd":
152
			if(isset($config['ntpd']['statsgraph'])) {
153
				$curoption = "allgraphs";
154
			} else {
155
				$curoption = "processor";
156
				$curcat = "system";
157
			}
158
			break;
159 329bb764 Seth Mos
		default:
160
			$curoption = "wan";
161
			break;
162 89d25faf Seth Mos
	}
163 37285f69 Scott Ullrich
}
164
165 6b0c5ae6 smos
$now = time();
166 a564b6e7 sbeaver
167 47e68f48 smos
if($curcat == "custom") {
168 a564b6e7 sbeaver
	if (is_numeric($_POST['start'])) {
169 59418cee Darren Embry
		if($start < ($now - (3600 * 24 * 365 * 5))) {
170
			$start = $now - (8 * 3600);
171
		}
172 a564b6e7 sbeaver
173
		$start = $_POST['start'];
174
	} else if ($_POST['start']) {
175
		$start = strtotime($_POST['start']);
176
177 59418cee Darren Embry
		if ($start === FALSE || $start === -1) {
178 a564b6e7 sbeaver
			$input_errors[] = gettext("Invalid start date/time:") . " '{$_POST['start']}'";
179
180
		$start = $now - (8 * 3600);
181 59418cee Darren Embry
		}
182
	} else {
183
		$start = $now - (8 * 3600);
184 47e68f48 smos
	}
185
}
186
187 a564b6e7 sbeaver
if (is_numeric($_POST['end'])) {
188
	$end = $_POST['end'];
189
} else if ($_POST['end']) {
190
	$end = strtotime($_POST['end']);
191
192 59418cee Darren Embry
	if ($end === FALSE || $end === -1) {
193 a564b6e7 sbeaver
		$input_errors[] = gettext("Invalid end date/time:") . " '{$_POST['end']}'";
194
195
	$end = $now;
196 59418cee Darren Embry
	}
197 47e68f48 smos
} else {
198 458a6879 sbeaver
	$end = $now;
199 47e68f48 smos
}
200
201
/* this should never happen */
202
if($end < $start) {
203 c7cfbbd8 smos
	log_error("start $start is smaller than end $end");
204 458a6879 sbeaver
	$end = $now;
205 47e68f48 smos
}
206
207
$seconds = $end - $start;
208 5d7791a2 Scott Ullrich
209
$styles = array('inverse' => gettext('Inverse'),
210 a564b6e7 sbeaver
				'absolute' => gettext('Absolute'));
211 5d7791a2 Scott Ullrich
212 329bb764 Seth Mos
/* sort names reverse so WAN comes first */
213 6ab7ae50 Seth Mos
rsort($databases);
214 37285f69 Scott Ullrich
215 9850b625 Seth Mos
/* these boilerplate databases are required for the other menu choices */
216
$dbheader = array("allgraphs-traffic.rrd",
217
		"allgraphs-quality.rrd",
218 2f80d451 Seth Mos
		"allgraphs-wireless.rrd",
219 ec51a222 thompsa
		"allgraphs-cellular.rrd",
220 edd2d8b7 smos
		"allgraphs-vpnusers.rrd",
221 9850b625 Seth Mos
		"allgraphs-packets.rrd",
222
		"system-allgraphs.rrd",
223 e3d7c123 Seth Mos
		"system-throughput.rrd",
224 9850b625 Seth Mos
		"outbound-quality.rrd",
225
		"outbound-packets.rrd",
226
		"outbound-traffic.rrd");
227
228 9cd5e6f5 Erik Fonnesbeck
/* additional menu choices for the custom tab */
229
$dbheader_custom = array("system-throughput.rrd");
230
231 7432ce7b Seth Mos
foreach($databases as $database) {
232 edd2d8b7 smos
	if(stristr($database, "-wireless")) {
233 7432ce7b Seth Mos
		$wireless = true;
234
	}
235 a564b6e7 sbeaver
236 edd2d8b7 smos
	if(stristr($database, "-queues")) {
237 7432ce7b Seth Mos
		$queues = true;
238
	}
239 a564b6e7 sbeaver
240 17a71003 Ermal
	if(stristr($database, "-cellular") && !empty($config['ppps'])) {
241 7432ce7b Seth Mos
		$cellular = true;
242
	}
243 a564b6e7 sbeaver
244 edd2d8b7 smos
	if(stristr($database, "-vpnusers")) {
245
		$vpnusers = true;
246 6b0c5ae6 smos
	}
247 a564b6e7 sbeaver
248 cba9d7d9 Renato Botelho
	if(stristr($database, "captiveportal-") && is_array($config['captiveportal'])) {
249 20413b72 Warren Baker
		$captiveportal = true;
250
	}
251 a564b6e7 sbeaver
252 2cdb75f8 nagyrobi
	if(stristr($database, "ntpd") && isset($config['ntpd']['statsgraph'])) {
253
		$ntpd = true;
254
	}
255 7432ce7b Seth Mos
}
256 9850b625 Seth Mos
/* append the existing array to the header */
257 a927edff Seth Mos
$ui_databases = array_merge($dbheader, $databases);
258 9cd5e6f5 Erik Fonnesbeck
$custom_databases = array_merge($dbheader_custom, $databases);
259 9850b625 Seth Mos
260 d02491e6 Colin Fleming
$graphs = array("eighthour", "day", "week", "month", "quarter", "year", "fouryear");
261 97acf646 Erik Fonnesbeck
$periods = array("absolute" => gettext("Absolute Timespans"), "current" => gettext("Current Period"), "previous" => gettext("Previous Period"));
262
$graph_length = array(
263 d02491e6 Colin Fleming
	"eighthour" => 28800,
264 97acf646 Erik Fonnesbeck
	"day" => 86400,
265
	"week" => 604800,
266 a35c1cdf N0YB
	"month" => 2678400,
267
	"quarter" => 7948800,
268 97acf646 Erik Fonnesbeck
	"year" => 31622400,
269 d02491e6 Colin Fleming
	"fouryear" => 126230400);
270 6ab7ae50 Seth Mos
271 1d80829e Carlos Eduardo Ramos
$pgtitle = array(gettext("Status"),gettext("RRD Graphs"));
272 ce49a7c9 Darren Embry
273
$closehead = false;
274 cba9d7d9 Renato Botelho
275
/* Load all CP zones */
276 52034432 Renato Botelho
if ($captiveportal && is_array($config['captiveportal'])) {
277 cba9d7d9 Renato Botelho
	$cp_zones_tab_array = array();
278 a564b6e7 sbeaver
279 cba9d7d9 Renato Botelho
	foreach($config['captiveportal'] as $cpkey => $cp) {
280
		if (!isset($cp['enable']))
281
			continue;
282
283
		if ($curzone == '') {
284
			$tabactive = true;
285
			$curzone = $cpkey;
286
		} elseif ($curzone == $cpkey) {
287
			$tabactive = true;
288
		} else {
289
			$tabactive = false;
290
		}
291
292
		$cp_zones_tab_array[] = array($cp['zone'], $tabactive, "status_rrd_graph.php?cat=captiveportal&zone=$cpkey");
293
	}
294
}
295
296 7d906758 smos
function get_dates($curperiod, $graph) {
297 97acf646 Erik Fonnesbeck
	global $graph_length;
298 7d906758 smos
	$now = time();
299
	$end = $now;
300
301 97acf646 Erik Fonnesbeck
	if($curperiod == "absolute") {
302
		$start = $end - $graph_length[$graph];
303
	} else {
304
		$curyear = date('Y', $now);
305
		$curmonth = date('m', $now);
306
		$curweek = date('W', $now);
307
		$curweekday = date('N', $now) - 1; // We want to start on monday
308
		$curday = date('d', $now);
309
		$curhour = date('G', $now);
310 c7cfbbd8 smos
311 97acf646 Erik Fonnesbeck
		switch($curperiod) {
312
			case "previous":
313
				$offset = -1;
314
				break;
315
			default:
316
				$offset = 0;
317
		}
318
		switch($graph) {
319 d02491e6 Colin Fleming
			case "eighthour":
320 97acf646 Erik Fonnesbeck
				if($curhour < 24)
321
					$starthour = 16;
322
				if($curhour < 16)
323
					$starthour = 8;
324
				if($curhour < 8)
325
					$starthour = 0;
326
327
				switch($offset) {
328
					case 0:
329
						$houroffset = $starthour;
330
						break;
331
					default:
332
						$houroffset = $starthour + ($offset * 8);
333
						break;
334
				}
335
				$start = mktime($houroffset, 0, 0, $curmonth, $curday, $curyear);
336
				if($offset != 0) {
337
					$end = mktime(($houroffset + 8), 0, 0, $curmonth, $curday, $curyear);
338
				}
339
				break;
340
			case "day":
341
				$start = mktime(0, 0, 0, $curmonth, ($curday + $offset), $curyear);
342
				if($offset != 0)
343
					$end = mktime(0, 0, 0, $curmonth, (($curday + $offset) + 1), $curyear);
344
				break;
345
			case "week":
346
				switch($offset) {
347
					case 0:
348
						$weekoffset = 0;
349
						break;
350
					default:
351
						$weekoffset = ($offset * 7) - 7;
352
						break;
353
				}
354
				$start = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset), $curyear);
355
				if($offset != 0)
356
					$end = mktime(0, 0, 0, $curmonth, (($curday - $curweekday) + $weekoffset + 7), $curyear);
357
				break;
358
			case "month":
359
				$start = mktime(0, 0, 0, ($curmonth + $offset), 0, $curyear);
360
				if($offset != 0)
361
					$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
362
				break;
363
			case "quarter":
364
				$start = mktime(0, 0, 0, (($curmonth - 2) + $offset), 0, $curyear);
365
				if($offset != 0)
366
					$end = mktime(0, 0, 0, (($curmonth + $offset) + 1), 0, $curyear);
367
				break;
368
			case "year":
369
				$start = mktime(0, 0, 0, 1, 0, ($curyear + $offset));
370
				if($offset != 0)
371
					$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
372
				break;
373 d02491e6 Colin Fleming
			case "fouryear":
374 97acf646 Erik Fonnesbeck
				$start = mktime(0, 0, 0, 1, 0, (($curyear - 3) + $offset));
375
				if($offset != 0)
376
					$end = mktime(0, 0, 0, 1, 0, (($curyear + $offset) +1));
377
				break;
378
		}
379 7d906758 smos
	}
380 8cd558b6 ayvis
	// 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 />";
381 7d906758 smos
	$dates = array();
382
	$dates['start'] = $start;
383
	$dates['end'] = $end;
384
	return $dates;
385
}
386
387 3c44b044 sbeaver
function make_tabs() {
388
	global $curcat;
389
390
	$tab_array = array();
391 cccdc5ce sbeaver
	$tab_array[] = array(gettext("System"), ($curcat == "system"), "status_rrd_graph.php?cat=system");
392
	$tab_array[] = array(gettext("Traffic"), ($curcat == "traffic"), "status_rrd_graph.php?cat=traffic");
393
	$tab_array[] = array(gettext("Packets"), ($curcat == "packets"), "status_rrd_graph.php?cat=packets");
394
	$tab_array[] = array(gettext("Quality"), ($curcat == "quality"), "status_rrd_graph.php?cat=quality");
395 3c44b044 sbeaver
396
	if($queues) {
397 cccdc5ce sbeaver
		$tab_array[] = array(gettext("Queues"), ($curcat == "queues"), "status_rrd_graph.php?cat=queues");
398
		$tab_array[] = array(gettext("QueueDrops"), ($curcat == "queuedrops"), "status_rrd_graph.php?cat=queuedrops");
399 3c44b044 sbeaver
	}
400
401
	if($wireless) {
402 cccdc5ce sbeaver
		$tab_array[] = array(gettext("Wireless"), ($curcat == "wireless"), "status_rrd_graph.php?cat=wireless");
403 3c44b044 sbeaver
	}
404
405
	if($cellular) {
406 cccdc5ce sbeaver
		$tab_array[] = array(gettext("Cellular"), ($curcat == "cellular"), "status_rrd_graph.php?cat=cellular");
407 3c44b044 sbeaver
	}
408
409
	if($vpnusers) {
410 cccdc5ce sbeaver
		$tab_array[] = array(gettext("VPN"), ($curcat == "vpnusers"), "status_rrd_graph.php?cat=vpnusers");
411 3c44b044 sbeaver
	}
412 cccdc5ce sbeaver
413 3c44b044 sbeaver
	if($captiveportal) {
414 cccdc5ce sbeaver
		$tab_array[] = array(gettext("Captive Portal"), ($curcat == "captiveportal"), "status_rrd_graph.php?cat=captiveportal");
415 3c44b044 sbeaver
	}
416
417
	if(isset($config['ntpd']['statsgraph'])) {
418 cccdc5ce sbeaver
		$tab_array[] = array("NTP", ($curcat == "ntpd"), "status_rrd_graph.php?cat=ntpd");
419 3c44b044 sbeaver
	}
420
421 cccdc5ce sbeaver
	$tab_array[] = array(gettext("Custom"), ($curcat == "custom"), "status_rrd_graph.php?cat=custom");
422
	$tab_array[] = array(gettext("Settings"), ($curcat == "settings"), "status_rrd_graph_settings.php");
423 3c44b044 sbeaver
424
	return($tab_array);
425
}
426
427
// Create the selectable list of graphs
428
function build_options() {
429 cccdc5ce sbeaver
	global $curcat, $custom_databases, $ui_databases;
430 3c44b044 sbeaver
431
	$optionslist = array();
432
433
	if($curcat == "custom") {
434
		foreach ($custom_databases as $db => $database) {
435
			$optionc = explode("-", $database);
436
			$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc[0]));
437
			if (empty($friendly)) {
438
				$friendly = $optionc[0];
439
			}
440
441
			$search = array("-", ".rrd", $optionc[0]);
442
			$replace = array(" :: ", "", $friendly);
443
			$prettyprint = ucwords(str_replace($search, $replace, $database));
444
			$optionslist[$database] = htmlspecialchars($prettyprint);
445
			}
446
		}
447
448
	foreach ($ui_databases as $db => $database) {
449
		if(! preg_match("/($curcat)/i", $database))
450
			continue;
451
452
		if (($curcat == "captiveportal") && !empty($curzone) && !preg_match("/captiveportal-{$curzone}/i", $database))
453
			continue;
454
455
		$optionc = explode("-", $database);
456
		$search = array("-", ".rrd", $optionc);
457
		$replace = array(" :: ", "", $friendly);
458
459
		switch($curcat) {
460
			case "captiveportal":
461
				$optionc = str_replace($search, $replace, $optionc[2]);
462
				$prettyprint = ucwords(str_replace($search, $replace, $optionc));
463
				$optionslist[$optionc] = htmlspecialchars($prettyprint);
464
				break;
465
			case "system":
466
				$optionc = str_replace($search, $replace, $optionc[1]);
467
				$prettyprint = ucwords(str_replace($search, $replace, $optionc));
468
				$optionslist[$optionc] = htmlspecialchars($prettyprint);
469
				break;
470
			default:
471
				/* Deduce an interface if possible and use the description */
472
				$optionc = "$optionc[0]";
473
				$friendly = convert_friendly_interface_to_friendly_descr(strtolower($optionc));
474
				if(empty($friendly)) {
475
					$friendly = $optionc;
476 2cdb75f8 nagyrobi
				}
477 3c44b044 sbeaver
				$search = array("-", ".rrd", $optionc);
478
				$replace = array(" :: ", "", $friendly);
479
				$prettyprint = ucwords(str_replace($search, $replace, $friendly));
480
				$optionslist[$optionc] = htmlspecialchars($prettyprint);
481
		}
482
	}
483
484
	return($optionslist);
485
}
486 a564b6e7 sbeaver
include("head.inc");
487 3c44b044 sbeaver
488
display_top_tabs(make_tabs());
489
490
if ($input_errors && count($input_errors))
491
	print_input_errors($input_errors);
492
493
require('classes/Form.class.php');
494
495 a564b6e7 sbeaver
$form = new Form(new Form_Button(
496
	'submit',
497
	'Go!'
498
	));
499
500 3c44b044 sbeaver
$form->addClass('auto-submit');
501
502
$section = new Form_Section('Graph settings');
503
504
$group = new Form_Group('Options');
505
506
$group->add(new Form_Select(
507
	'option',
508
	'Graphs',
509
	$curoption,
510
	build_options()
511
))->setHelp('Graph');
512
513
$group->add(new Form_Select(
514
	'style',
515
	'Style',
516
	$curstyle,
517
	$styles
518
))->setHelp('Style');
519
520
$group->add(new Form_Select(
521
	'period',
522
	'Period',
523
	$curperiod,
524
	$periods
525
))->setHelp('Period');
526
527
if($curcat == 'custom')
528 a564b6e7 sbeaver
	$group->setHelp('Any changes to these option may not take affect until the next auto-refresh.');
529 3c44b044 sbeaver
530
$section->add($group);
531
532 a564b6e7 sbeaver
if($curcat == 'custom') {
533 3c44b044 sbeaver
534 a564b6e7 sbeaver
	$section->addInput(new Form_Input(
535
		'cat',
536
		null,
537
		'hidden',
538
		'custom'
539
	 ));
540
541
	$tz = date_default_timezone_get();
542
	$tz_msg = gettext("Enter date and/or time. Current timezone:") . " $tz";
543
	$start_fmt = strftime("%m/%d/%Y %H:%M:%S", $start);
544
	$end_fmt   = strftime("%m/%d/%Y %H:%M:%S", $end);
545
546
	$group = new Form_Group('');
547 3c44b044 sbeaver
548
	$group->add(new Form_Input(
549 a564b6e7 sbeaver
		'start',
550
		'Start',
551
		'datetime',
552
		$start_fmt
553 3c44b044 sbeaver
	))->setHelp('Start');
554
555
	$group->add(new Form_Input(
556 a564b6e7 sbeaver
		'end',
557
		'End',
558
		'datetime',
559
		$end_fmt
560 3c44b044 sbeaver
	))->setHelp('End');
561
562
	if($curcat != 'custom')
563 a564b6e7 sbeaver
		$group->setHelp('Any changes to these option may not take affect until the next auto-refresh');
564 3c44b044 sbeaver
565
	$section->add($group);
566
567
	$form->add($section);
568 a564b6e7 sbeaver
	print($form);
569 3c44b044 sbeaver
570
	$curdatabase = $curoption;
571
	$graph = "custom-$curdatabase";
572
	if(in_array($curdatabase, $custom_databases)) {
573
		$id = "{$graph}-{$curoption}-{$curdatabase}";
574
		$id = preg_replace('/\./', '_', $id);
575
?>
576
		<div class="panel panel-default">
577
			<img align="center" name="<?=$id?>" id="<?=$id?>" alt="<?=$prettydb?> Graph" src="status_rrd_graph_img.php?start=<?=$start?>&amp;end={<?=$end?>&amp;database=<?=$curdatabase?>&amp;style=<?=$curstyle?>&amp;graph=<?=$graph?>" />
578
		</div>
579
<?php
580
581
	}
582
} else {
583 a564b6e7 sbeaver
	$form->add($section);
584
	print($form);
585
586 3c44b044 sbeaver
	foreach($graphs as $graph) {
587
		/* check which databases are valid for our category */
588
		foreach($ui_databases as $curdatabase) {
589
			if(! preg_match("/($curcat)/i", $curdatabase))
590
				continue;
591
592
			if (($curcat == "captiveportal") && !empty($curzone) && !preg_match("/captiveportal-{$curzone}/i", $curdatabase))
593
				continue;
594
595
			$optionc = explode("-", $curdatabase);
596
			$search = array("-", ".rrd", $optionc);
597
			$replace = array(" :: ", "", $friendly);
598 a564b6e7 sbeaver
599 3c44b044 sbeaver
			switch($curoption) {
600
				case "outbound":
601
					/* make sure we do not show the placeholder databases in the outbound view */
602
					if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
603
						continue 2;
604 47e68f48 smos
					}
605 3c44b044 sbeaver
					/* only show interfaces with a gateway */
606
					$optionc = "$optionc[0]";
607
					if(!interface_has_gateway($optionc)) {
608
						if(!isset($gateways_arr)) {
609
							if(preg_match("/quality/i", $curdatabase))
610
								$gateways_arr = return_gateways_array();
611
							else
612
								$gateways_arr = array();
613
						}
614
						$found_gateway = false;
615
						foreach ($gateways_arr as $gw) {
616
							if ($gw['name'] == $optionc) {
617
								$found_gateway = true;
618 9850b625 Seth Mos
								break;
619 3c44b044 sbeaver
							}
620 9850b625 Seth Mos
						}
621 3c44b044 sbeaver
						if(!$found_gateway) {
622
							continue 2;
623 89d25faf Seth Mos
						}
624
					}
625 a564b6e7 sbeaver
626 3c44b044 sbeaver
					if(! preg_match("/(^$optionc-|-$optionc\\.)/i", $curdatabase)) {
627
						continue 2;
628 89d25faf Seth Mos
					}
629 3c44b044 sbeaver
					break;
630
				case "allgraphs":
631
					/* make sure we do not show the placeholder databases in the all view */
632
					if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
633
						continue 2;
634 7d906758 smos
					}
635 3c44b044 sbeaver
					break;
636
				default:
637
					/* just use the name here */
638
					if(! preg_match("/(^$curoption-|-$curoption\\.)/i", $curdatabase)) {
639
						continue 2;
640
					}
641
			}
642 a564b6e7 sbeaver
643 3c44b044 sbeaver
			if(in_array($curdatabase, $ui_databases)) {
644
				$id = "{$graph}-{$curoption}-{$curdatabase}";
645
				$id = preg_replace('/\./', '_', $id);
646
647
				$dates = get_dates($curperiod, $graph);
648
				$start = $dates['start'];
649
				$end = $dates['end'];
650
?>
651
				<div class="panel panel-default" align="center">
652
					<img name="<?=$id?>" id="<?=$id?>" alt="<?=$prettydb?> Graph" src="status_rrd_graph_img.php?start=<?=$start?>&amp;end={<?=$end?>&amp;database=<?=$curdatabase?>&amp;style=<?=$curstyle?>&amp;graph=<?=$graph?>" />
653
				</div>
654
<?php
655
			}
656
		}
657
	}
658
}
659 a564b6e7 sbeaver
660 3c44b044 sbeaver
?>
661
<script type="text/javascript">
662
//<![CDATA[
663
	function update_graph_images() {
664
		//alert('updating');
665
		var randomid = Math.floor(Math.random()*11);
666
		<?php
667
		foreach($graphs as $graph) {
668
			/* check which databases are valid for our category */
669
			foreach($ui_databases as $curdatabase) {
670
				if(! stristr($curdatabase, $curcat)) {
671
					continue;
672
				}
673
				$optionc = explode("-", $curdatabase);
674
				$search = array("-", ".rrd", $optionc);
675
				$replace = array(" :: ", "", $friendly);
676
				switch($curoption) {
677
					case "outbound":
678
						/* make sure we do not show the placeholder databases in the outbound view */
679
						if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
680
							continue 2;
681 6b0c5ae6 smos
						}
682 3c44b044 sbeaver
						/* only show interfaces with a gateway */
683
						$optionc = "$optionc[0]";
684
						if(!interface_has_gateway($optionc)) {
685
							if(!isset($gateways_arr))
686
								if(preg_match("/quality/i", $curdatabase))
687
									$gateways_arr = return_gateways_array();
688
								else
689
									$gateways_arr = array();
690
							$found_gateway = false;
691
							foreach ($gateways_arr as $gw) {
692
								if ($gw['name'] == $optionc) {
693
									$found_gateway = true;
694
									break;
695 6b0c5ae6 smos
								}
696 89d25faf Seth Mos
							}
697 3c44b044 sbeaver
							if(!$found_gateway) {
698
								continue 2;
699
							}
700 89d25faf Seth Mos
						}
701 3c44b044 sbeaver
						if(! preg_match("/(^$optionc-|-$optionc\\.)/i", $curdatabase)) {
702
							continue 2;
703 89d25faf Seth Mos
						}
704 3c44b044 sbeaver
						break;
705
					case "allgraphs":
706
						/* make sure we do not show the placeholder databases in the all view */
707
						if((stristr($curdatabase, "outbound")) || (stristr($curdatabase, "allgraphs"))) {
708
							continue 2;
709
						}
710
						break;
711
					default:
712
						/* just use the name here */
713
						if(! preg_match("/(^$curoption-|-$curoption\\.)/i", $curdatabase)) {
714
							continue 2;
715
						}
716
				}
717
				$dates = get_dates($curperiod, $graph);
718
				$start = $dates['start'];
719
				if($curperiod == "current") {
720
					$end = $dates['end'];
721
				}
722
				/* generate update events utilizing jQuery('') feature */
723
				$id = "{$graph}-{$curoption}-{$curdatabase}";
724
				$id = preg_replace('/\./', '_', $id);
725
726
				echo "\n";
727
				echo "\t\tjQuery('#{$id}').attr('src','status_rrd_graph_img.php?start={$start}&graph={$graph}&database={$curdatabase}&style={$curstyle}&tmp=' + randomid);\n";
728
				}
729
			}
730
		?>
731
		window.setTimeout('update_graph_images()', 355000);
732
	}
733
	window.setTimeout('update_graph_images()', 355000);
734
//]]>
735
</script>
736
737
<script>
738
events.push(function(){
739
	$('.auto-submit').on('change', function(){
740 a564b6e7 sbeaver
		$(this).submit();
741 3c44b044 sbeaver
	});
742
});
743
</script>
744
745 a564b6e7 sbeaver
<?php include("foot.inc");