1<?php
2
3// Pandora FMS - http://pandorafms.com
4// ==================================================
5// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
6// Please see http://pandorafms.org for full contribution list
7
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License
10// as published by the Free Software Foundation for version 2.
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16
17if (! isset($_SESSION['id_usuario'])) {
18	session_start();
19	//session_write_close();
20}
21
22// Global & session management
23require_once ('../../include/config.php');
24require_once ($config['homedir'] . '/include/auth/mysql.php');
25require_once ($config['homedir'] . '/include/functions.php');
26require_once ($config['homedir'] . '/include/functions_db.php');
27require_once ($config['homedir'] . '/include/functions_reporting.php');
28require_once ($config['homedir'] . '/include/functions_graph.php');
29require_once ($config['homedir'] . '/include/functions_modules.php');
30require_once ($config['homedir'] . '/include/functions_agents.php');
31require_once ($config['homedir'] . '/include/functions_tags.php');
32
33check_login ();
34
35// Metaconsole connection to the node
36$server_id = (int) get_parameter("server");
37if (is_metaconsole() && !empty($server_id)) {
38	$server = metaconsole_get_connection_by_id($server_id);
39
40	// Error connecting
41	if (metaconsole_connect($server) !== NOERR) {
42		echo "<html>";
43			echo "<body>";
44				ui_print_error_message(__('There was a problem connecting with the node'));
45			echo "</body>";
46		echo "</html>";
47		exit;
48	}
49}
50
51$user_language = get_user_language ($config['id_user']);
52if (file_exists ('../../include/languages/'.$user_language.'.mo')) {
53	$l10n = new gettext_reader (new CachedFileReader ('../../include/languages/'.$user_language.'.mo'));
54	$l10n->load_tables();
55}
56
57echo '<link rel="stylesheet" href="../../include/styles/pandora.css" type="text/css"/>';
58
59$label = get_parameter('label');
60$label = base64_decode($label);
61$id = get_parameter('id');
62//$label = rawurldecode(urldecode(base64_decode(get_parameter('label', ''))));
63?>
64<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
65<html xmlns="http://www.w3.org/1999/xhtml">
66	<head>
67		<?php
68		// Parsing the refresh before sending any header
69		$refresh = (int) get_parameter ("refresh", -1);
70		if ($refresh > 0) {
71			$query = ui_get_url_refresh (false);
72
73			echo '<meta http-equiv="refresh" content="'.$refresh.'; URL='.$query.'" />';
74		}
75		?>
76		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
77		<title>Pandora FMS Graph (<?php echo modules_get_agentmodule_agent_name ($id) . ' - ' . $label; ?>)</title>
78		<link rel="stylesheet" href="../../include/styles/pandora_minimal.css" type="text/css" />
79		<link rel="stylesheet" href="../../include/styles/jquery-ui-1.10.0.custom.css" type="text/css" />
80		<script type='text/javascript' src='../../include/javascript/pandora.js'></script>
81		<script type='text/javascript' src='../../include/javascript/jquery-1.9.0.js'></script>
82		<script type='text/javascript' src='../../include/javascript/jquery.pandora.js'></script>
83		<script type='text/javascript' src='../../include/javascript/jquery.jquery-ui-1.10.0.custom.js'></script>
84		<script type='text/javascript'>
85			<!--
86			window.onload = function() {
87				// Hack to repeat the init process to period select
88				var periodSelectId = $('[name="period"]').attr('class');
89
90				period_select_init(periodSelectId);
91			};
92
93			function show_others() {
94				if (!$("#checkbox-avg_only").attr('checked')) {
95					$("#hidden-show_other").val(0);
96				}
97				else {
98					$("#hidden-show_other").val(1);
99				}
100			}
101			//-->
102		</script>
103	</head>
104	<body bgcolor="#ffffff" style='background:#ffffff;'>
105		<?php
106
107		// Module id
108		$id = (int) get_parameter ("id", 0);
109		// Agent id
110		$agent_id = (int) modules_get_agentmodule_agent($id);
111		if (empty($id) || empty($agent_id)) {
112			ui_print_error_message(__('There was a problem locating the source of the graph'));
113			exit;
114		}
115
116		// ACL
117		$permission = false;
118		$agent_group = (int) agents_get_agent_group($agent_id);
119		$strict_user = (bool) db_get_value("strict_acl", "tusuario",
120			"id_user", $config['id_user']);
121
122		if (!empty($agent_group)) {
123			if ($strict_user) {
124				$permission = tags_check_acl_by_module($id, $config['id_user'], 'RR') === true;
125			}
126			else {
127				$permission = check_acl($config['id_user'], $agent_group, "RR");
128			}
129		}
130
131		if (!$permission) {
132			require ($config['homedir'] . "/general/noaccess.php");
133			exit;
134		}
135
136		$draw_alerts = get_parameter("draw_alerts", 0);
137		$avg_only = get_parameter ("avg_only", 0);
138		$show_other = (bool)get_parameter('show_other', false);
139		if ($show_other) {
140			$avg_only = 0;
141		}
142		$period = get_parameter ("period", SECONDS_1DAY);
143		$id = get_parameter ("id", 0);
144		$width = get_parameter ("width", STATWIN_DEFAULT_CHART_WIDTH);
145		$height = get_parameter ("height", STATWIN_DEFAULT_CHART_HEIGHT);
146		$label = get_parameter ("label", "");
147		$start_date = get_parameter ("start_date", date("Y/m/d"));
148		$start_time = get_parameter ("start_time", date("H:i:s"));
149		$draw_events = get_parameter ("draw_events", 0);
150		$graph_type = get_parameter ("type", "sparse");
151		$zoom = get_parameter ("zoom", 1);
152		$baseline = get_parameter ("baseline", 0);
153		$show_events_graph = get_parameter ("show_events_graph", 0);
154		$show_percentil_95 = get_parameter ("show_percentil_95", 0);
155		$time_compare_separated = get_parameter ("time_compare_separated", 0);
156		$time_compare_overlapped = get_parameter ("time_compare_overlapped", 0);
157		$unknown_graph = get_parameter_checkbox ("unknown_graph", 1);
158
159		$time_compare = false;
160
161		if ($time_compare_separated) {
162			$time_compare = 'separated';
163		}
164		else if ($time_compare_overlapped) {
165			$time_compare = 'overlapped';
166		}
167
168		if ($zoom > 1) {
169			$height = $height * ($zoom / 2.1);
170			$width = $width * ($zoom / 1.4);
171
172			echo "<script type='text/javascript'>window.resizeTo($width + 80, $height + 120);</script>";
173		}
174
175		// Build date
176		$date = strtotime("$start_date $start_time");
177		$now = time();
178
179		if ($date > $now)
180			$date = $now;
181
182		$urlImage = ui_get_full_url(false, false, false, false);
183
184		$unit = db_get_value('unit', 'tagente_modulo', 'id_agente_modulo', $id);
185
186		// log4x doesnt support flash yet
187		//
188		if ($config['flash_charts'] == 1)
189			echo '<div style="margin-left: 70px; padding-top: 10px;">';
190		else
191			echo '<div style="margin-left: 50px; padding-top: 10px;">';
192
193		switch ($graph_type) {
194			case 'boolean':
195				echo grafico_modulo_boolean ($id, $period, $draw_events,
196					$width, $height, $label, $unit, $draw_alerts,
197					$avg_only, false, $date, false, $urlImage,
198					'adapter_' . $graph_type, $time_compare,
199					$unknown_graph);
200				echo '<br>';
201				if ($show_events_graph)
202					echo graphic_module_events($id, $width, $height,
203						$period, $config['homeurl'], $zoom,
204						'adapted_' . $graph_type, $date, true);
205				break;
206			case 'sparse':
207				echo grafico_modulo_sparse ($id, $period, $draw_events,
208					$width, $height, $label, $unit, $draw_alerts,
209					$avg_only, false, $date, $unit, $baseline, 0, true,
210					false, $urlImage, 1, false,
211					'adapter_' . $graph_type, $time_compare,
212					$unknown_graph, true, 'white',
213					(($show_percentil_95)? 95 : null));
214				echo '<br>';
215				if ($show_events_graph)
216					echo graphic_module_events($id, $width, $height,
217						$period, $config['homeurl'], $zoom,
218						'adapted_' . $graph_type, $date, true);
219				break;
220			case 'string':
221				echo grafico_modulo_string ($id, $period, $draw_events,
222					$width, $height, $label, null, $draw_alerts, 1,
223					false, $date, false, $urlImage,
224					'adapter_' . $graph_type);
225				echo '<br>';
226				if ($show_events_graph)
227					echo graphic_module_events($id, $width, $height,
228						$period, $config['homeurl'], $zoom,
229						'adapted_' . $graph_type, $date, true);
230				break;
231			case 'log4x':
232				echo grafico_modulo_log4x ($id, $period, $draw_events,
233					$width, $height, $label, $unit, $draw_alerts, 1,
234					$pure, $date);
235				echo '<br>';
236				if ($show_events_graph)
237					echo graphic_module_events($id, $width, $height,
238						$period, $config['homeurl'], $zoom, '', $date, true);
239				break;
240			default:
241				echo fs_error_image ('../images');
242				break;
243		}
244		echo '</div>';
245
246		////////////////////////////////////////////////////////////////
247		// SIDE MENU
248		////////////////////////////////////////////////////////////////
249		$params = array();
250		// TOP TEXT
251		//Use the no_meta parameter because this image is only in the base console
252		$params['top_text'] = "<div style='color: white; width: 100%; text-align: center; font-weight: bold; vertical-align: top;'>" . html_print_image('images/wrench_blanco.png', true, array('width' => '16px'), false, false, true) . ' ' . __('Pandora FMS Graph configuration menu') . "</div>";
253		$params['body_text'] = "<div class='menu_sidebar_outer'>";
254		$params['body_text'] .=__('Please, make your changes and apply with the <i>Reload</i> button');
255
256		// MENU
257		$params['body_text'] .= '<form method="get" action="stat_win.php">';
258		$params['body_text'] .= html_print_input_hidden ("id", $id, true);
259		$params['body_text'] .= html_print_input_hidden ("label", $label, true);
260
261		if (!empty($server_id))
262			$params['body_text'] .= html_print_input_hidden ("server", $server_id, true);
263
264		if (isset($_GET["type"])) {
265			$type = get_parameter_get ("type");
266			$params['body_text'] .= html_print_input_hidden ("type", $type, true);
267		}
268
269		// FORM TABLE
270
271		$table = html_get_predefined_table('transparent', 2);
272		$table->width = '98%';
273		$table->id = 'stat_win_form_div';
274		$table->style[0] = 'text-align:left; padding: 7px;';
275		$table->style[1] = 'text-align:left;';
276		//$table->size[0] = '50%';
277		$table->styleTable = 'border-spacing: 4px;';
278		$table->class = 'alternate';
279
280		$data = array();
281		$data[0] = __('Refresh time');
282		$data[1] = html_print_extended_select_for_time("refresh",
283			$refresh, '', '', 0, 7, true);
284		$table->data[] = $data;
285		$table->rowclass[] = '';
286
287		if ($graph_type != "boolean" && $graph_type != "string") {
288			$data = array();
289			$data[0] = __('Avg. Only');
290			$data[1] = html_print_checkbox ("avg_only", 1,
291				(bool)$avg_only, true, false, 'show_others()');
292			$data[1] .= html_print_input_hidden('show_other', 0, true);
293			$table->data[] = $data;
294			$table->rowclass[] = '';
295		}
296
297		$data = array();
298		$data[0] = __('Begin date');
299		$data[1] = html_print_input_text ("start_date", $start_date,'', 10, 20, true);
300		$table->data[] = $data;
301		$table->rowclass[] = '';
302
303		$data = array();
304		$data[0] = __('Begin time');
305		$data[1] = html_print_input_text ("start_time", $start_time,'', 10, 10, true);
306		$table->data[] = $data;
307		$table->rowclass[] = '';
308
309		$data = array();
310		$data[0] = __('Zoom factor');
311		$options = array ();
312		$options[$zoom] = 'x' . $zoom;
313		$options[1] = 'x1';
314		$options[2] = 'x2';
315		$options[3] = 'x3';
316		$options[4] = 'x4';
317		$data[1] = html_print_select ($options, "zoom", $zoom, '', '', 0, true);
318		$table->data[] = $data;
319		$table->rowclass[] = '';
320
321		$data = array();
322		$data[0] = __('Time range');
323		$data[1] = html_print_extended_select_for_time('period',
324			$period, '', '', 0, 7, true);
325		$table->data[] = $data;
326		$table->rowclass[] = '';
327
328		$data = array();
329		$data[0] = __('Show events');
330		$disabled = false;
331		if (isset($config['event_replication'])) {
332			if ($config['event_replication'] && !$config['show_events_in_local']) {
333				$disabled = true;
334			}
335		}
336		$data[1] = html_print_checkbox ("draw_events", 1,
337			(bool)$draw_events, true, $disabled);
338		if ($disabled) {
339			$data[1] .= ui_print_help_tip(
340				__('Show events is disabled because this Pandora node is set the event replication.'), true);
341		}
342		$table->data[] = $data;
343		$table->rowclass[] = '';
344
345		$data = array();
346		$data[0] = __('Show alerts');
347		$data[1] = html_print_checkbox ("draw_alerts", 1, (bool) $draw_alerts, true);
348		$table->data[] = $data;
349		$table->rowclass[] = '';
350
351		$data = array();
352		$data[0] = __('Show event graph');
353		$data[1] = html_print_checkbox ("show_events_graph", 1, (bool) $show_events_graph, true);
354		$table->data[] = $data;
355		$table->rowclass[] = '';
356
357		switch ($graph_type) {
358			case 'boolean':
359			case 'sparse':
360				$data = array();
361				$data[0] = __('Show percentil 95º');
362				$data[1] = html_print_checkbox ("show_percentil_95", 1, (bool) $show_percentil_95, true);
363				$table->data[] = $data;
364				$table->rowclass[] ='';
365
366				$data = array();
367				$data[0] = __('Time compare (Overlapped)');
368				$data[1] = html_print_checkbox ("time_compare_overlapped", 1, (bool) $time_compare_overlapped, true);
369				$table->data[] = $data;
370				$table->rowclass[] = '';
371
372				$data = array();
373				$data[0] = __('Time compare (Separated)');
374				$data[1] = html_print_checkbox ("time_compare_separated", 1, (bool) $time_compare_separated, true);
375				$table->data[] = $data;
376				$table->rowclass[] = '';
377
378				$data = array();
379				$data[0] = __('Show unknown graph');
380				$data[1] = html_print_checkbox ("unknown_graph", 1, (bool) $unknown_graph, true);
381				$table->data[] = $data;
382				$table->rowclass[] = '';
383				break;
384		}
385
386		$form_table = html_print_table($table, true);
387
388		unset($table);
389
390		$table->id = 'stat_win_form';
391		$table->width = '100%';
392		$table->cellspacing = 2;
393		$table->cellpadding = 2;
394		$table->class = 'databox';
395
396		$data = array();
397		$data[0] = html_print_div(array('id' => 'field_list', 'content' => $form_table,
398			'style' => 'overflow: auto; height: 220px'), true);
399		$table->data[] = $data;
400		$table->rowclass[] = '';
401
402		$data = array();
403		$data[0] = '<div style="width:100%; text-align:right;">' .
404			html_print_submit_button(__('Reload'), "submit", false,
405				'class="sub upd"', true) .
406			"</div>";
407		$table->data[] = $data;
408		$table->rowclass[] = '';
409
410		$params['body_text'] .= html_print_table($table, true);
411		$params['body_text'] .= '</form>';
412		$params['body_text'] .= '</div>'; // outer
413
414		// ICONS
415		$params['icon_closed'] = '/images/graphmenu_arrow_hide.png';
416		$params['icon_open'] = '/images/graphmenu_arrow.png';
417
418		// SIZE
419		$params['width'] = 500;
420
421		// POSITION
422		$params['position'] = 'left';
423
424		html_print_side_layer($params);
425
426		// Hidden div to forced title
427		html_print_div(array('id' => 'forced_title_layer',
428			'class' => 'forced_title_layer', 'hidden' => true));
429		?>
430
431	</body>
432</html>
433
434<?php
435// Echo the script tags of the datepicker and the timepicker
436// Modify the user language cause the ui.datepicker language files use - instead _
437$custom_user_language = str_replace('_', '-', $user_language);
438ui_require_jquery_file("ui.datepicker-" . $custom_user_language, "include/javascript/i18n/", true);
439ui_include_time_picker(true);
440?>
441
442<script>
443	$('#checkbox-time_compare_separated').click(function() {
444		$('#checkbox-time_compare_overlapped').removeAttr('checked');
445	});
446	$('#checkbox-time_compare_overlapped').click(function() {
447		$('#checkbox-time_compare_separated').removeAttr('checked');
448	});
449
450
451	<?php
452	//Resize window when show the overview graph.
453	if ($config['flash_charts']) {
454	?>
455		var show_overview = false;
456		var height_window;
457		var width_window;
458		$(document).ready(function() {
459			height_window = $(window).height();
460			width_window = $(window).width();
461		});
462
463		$("*").filter(function() {
464			if (typeof(this.id) == "string")
465				return this.id.match(/menu_overview_graph.*/);
466			else
467				return false;
468			}).click(function() {
469				if (show_overview) {
470					window.resizeTo(width_window + 20, height_window + 50);
471				}
472				else {
473					window.resizeTo(width_window + 20, height_window + 200);
474				}
475				show_overview = !show_overview;
476
477			});
478	<?php
479	}
480	?>
481
482	// Add datepicker and timepicker
483	$("#text-start_date").datepicker({
484		dateFormat: "<?php echo DATE_FORMAT_JS; ?>"
485	});
486	$("#text-start_time").timepicker({
487		showSecond: true,
488		timeFormat: '<?php echo TIME_FORMAT_JS; ?>',
489		timeOnlyTitle: '<?php echo __('Choose time');?>',
490		timeText: '<?php echo __('Time');?>',
491		hourText: '<?php echo __('Hour');?>',
492		minuteText: '<?php echo __('Minute');?>',
493		secondText: '<?php echo __('Second');?>',
494		currentText: '<?php echo __('Now');?>',
495		closeText: '<?php echo __('Close');?>'
496	});
497
498	$.datepicker.setDefaults($.datepicker.regional["<?php echo $custom_user_language; ?>"]);
499
500	forced_title_callback();
501
502	$(window).ready(function() {
503		$("#field_list").css('height', ($(window).height() - 160) + 'px');
504	});
505
506	$(window).resize(function() {
507		$("#field_list").css('height', ($(window).height() - 160) + 'px');
508	});
509</script>
510