Files

189 lines
6.0 KiB
PHP
Raw Permalink Normal View History

<?php
use LibreNMS\Config;
2011-09-17 19:14:44 +00:00
unset($vars['page']);
2012-05-25 12:24:34 +00:00
// Setup here
2011-09-17 19:14:44 +00:00
2016-08-18 20:28:22 -05:00
if ($_SESSION['widescreen']) {
2015-07-13 20:10:26 +02:00
$graph_width=1700;
$thumb_width=180;
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
$graph_width=1075;
$thumb_width=113;
2011-09-17 19:14:44 +00:00
}
2015-07-13 20:10:26 +02:00
if (!is_numeric($vars['from'])) {
$vars['from'] = $config['time']['day'];
}
if (!is_numeric($vars['to'])) {
$vars['to'] = $config['time']['now'];
}
2011-09-17 19:14:44 +00:00
2012-04-10 17:36:28 +00:00
preg_match('/^(?P<type>[A-Za-z0-9]+)_(?P<subtype>.+)/', $vars['type'], $graphtype);
$type = $graphtype['type'];
$subtype = $graphtype['subtype'];
2011-09-17 19:14:44 +00:00
$id = $vars['id'];
2016-08-18 20:28:22 -05:00
if (is_numeric($vars['device'])) {
2015-07-13 20:10:26 +02:00
$device = device_by_id_cache($vars['device']);
2016-08-18 20:28:22 -05:00
} elseif (!empty($vars['device'])) {
2015-07-13 20:10:26 +02:00
$device = device_by_name($vars['device']);
}
2015-07-13 20:10:26 +02:00
if (is_file("includes/graphs/".$type."/auth.inc.php")) {
require "includes/graphs/".$type."/auth.inc.php";
}
2010-08-01 14:17:06 +00:00
2015-07-13 20:10:26 +02:00
if (!$auth) {
require 'includes/error-no-perm.inc.php';
2016-08-18 20:28:22 -05:00
} else {
2015-07-13 20:10:26 +02:00
if (isset($config['graph_types'][$type][$subtype]['descr'])) {
2017-05-01 23:49:11 -05:00
$title .= " :: " . $config['graph_types'][$type][$subtype]['descr'];
2018-07-07 22:27:46 +09:00
} elseif ($type == "device" && $subtype == "collectd") {
$title .= " :: " . nicecase($subtype) . " :: " . $vars['c_plugin'];
2018-07-07 22:27:46 +09:00
if (isset($vars['c_plugin_instance'])) {
$title .= " - " . $vars['c_plugin_instance'];
}
$title .= " - " . $vars['c_type'];
if (isset($vars['c_type_instance'])) {
$title .= " - " . $vars['c_type_instance'];
}
2016-08-18 20:28:22 -05:00
} else {
$title .= " :: " . nicecase($subtype);
2015-07-13 20:10:26 +02:00
}
$graph_array = $vars;
$graph_array['height'] = "60";
2017-05-01 23:49:11 -05:00
$graph_array['width'] = $thumb_width;
2015-07-13 20:10:26 +02:00
$graph_array['legend'] = "no";
2017-05-01 23:49:11 -05:00
$graph_array['to'] = $config['time']['now'];
2015-07-13 20:10:26 +02:00
print_optionbar_start();
2017-05-01 23:49:11 -05:00
echo $title;
// FIXME allow switching between types for sensor and wireless also restrict types to ones that have data
if ($type != 'sensor') {
2017-05-01 23:49:11 -05:00
echo '<div style="float: right;"><form action="">';
echo "<select name='type' id='type' onchange=\"window.open(this.options[this.selectedIndex].value,'_top')\" >";
foreach (get_graph_subtypes($type, $device) as $avail_type) {
echo "<option value='" . generate_url($vars, array('type' => $type . "_" . $avail_type, 'page' => "graphs")) . "'";
if ($avail_type == $subtype) {
echo(" selected");
}
$display_type = is_mib_graph($type, $avail_type) ? $avail_type : nicecase($avail_type);
echo ">$display_type</option>";
}
echo '</select></form></div>';
}
2015-07-13 20:10:26 +02:00
print_optionbar_end();
$thumb_array = $config['graphs']['row']['normal'];
2017-05-01 23:49:11 -05:00
echo '<table width=100% class="thumbnail_graph_table"><tr>';
2015-07-13 20:10:26 +02:00
foreach ($thumb_array as $period => $text) {
$graph_array['from'] = $config['time'][$period];
2015-07-13 20:10:26 +02:00
$link_array = $vars;
$link_array['from'] = $graph_array['from'];
$link_array['to'] = $graph_array['to'];
$link_array['page'] = "graphs";
$link = generate_url($link_array);
2015-07-13 20:10:26 +02:00
echo('<td align=center>');
2015-10-01 17:01:33 +05:30
echo('<b>'.$text.'</b><br>');
2015-07-13 20:10:26 +02:00
echo('<a href="'.$link.'">');
2015-07-16 12:42:58 -04:00
echo generate_lazy_graph_tag($graph_array);
2015-07-13 20:10:26 +02:00
echo('</a>');
echo('</td>');
}
2015-07-13 20:10:26 +02:00
echo('</tr></table>');
2011-09-17 19:14:44 +00:00
2015-07-13 20:10:26 +02:00
$graph_array = $vars;
2016-04-26 12:56:58 -07:00
$graph_array['height'] = $config['webui']['min_graph_height'];
2015-07-13 20:10:26 +02:00
$graph_array['width'] = $graph_width;
2011-09-20 09:55:11 +00:00
2016-08-18 20:28:22 -05:00
if ($_SESSION['screen_width']) {
if ($_SESSION['screen_width'] > 800) {
$graph_array['width'] = ($_SESSION['screen_width'] - ($_SESSION['screen_width']/10));
2016-08-18 20:28:22 -05:00
} else {
$graph_array['width'] = ($_SESSION['screen_width'] - ($_SESSION['screen_width']/4));
}
}
2016-08-18 20:28:22 -05:00
if ($_SESSION['screen_height']) {
if ($_SESSION['screen_height'] > 960) {
$graph_array['height'] = ($_SESSION['screen_height'] - ($_SESSION['screen_height']/2));
2016-08-18 20:28:22 -05:00
} else {
$graph_array['height'] = max($graph_array['height'], ($_SESSION['screen_height'] - ($_SESSION['screen_height']/1.5)));
}
}
2015-07-13 20:10:26 +02:00
echo("<hr />");
include_once 'includes/print-date-selector.inc.php';
2015-08-23 16:37:21 +05:30
echo ('<div style="padding-top: 5px";></div>');
echo('<center>');
2015-07-13 20:10:26 +02:00
if ($vars['legend'] == "no") {
2016-08-18 20:28:22 -05:00
echo(generate_link("Show Legend", $vars, array('page' => "graphs", 'legend' => null)));
} else {
echo(generate_link("Hide Legend", $vars, array('page' => "graphs", 'legend' => "no")));
2015-07-13 20:10:26 +02:00
}
2015-07-13 20:10:26 +02:00
// FIXME : do this properly
# if ($type == "port" && $subtype == "bits")
# {
2012-04-18 10:51:18 +00:00
echo(' | ');
2015-07-13 20:10:26 +02:00
if ($vars['previous'] == "yes") {
2016-08-18 20:28:22 -05:00
echo(generate_link("Hide Previous", $vars, array('page' => "graphs", 'previous' => null)));
} else {
echo(generate_link("Show Previous", $vars, array('page' => "graphs", 'previous' => "yes")));
2015-07-13 20:10:26 +02:00
}
# }
2012-04-18 10:51:18 +00:00
2015-08-23 16:37:21 +05:30
echo(' | ');
2015-07-13 20:10:26 +02:00
if ($vars['showcommand'] == "yes") {
2016-08-18 20:28:22 -05:00
echo(generate_link("Hide RRD Command", $vars, array('page' => "graphs", 'showcommand' => null)));
} else {
echo(generate_link("Show RRD Command", $vars, array('page' => "graphs", 'showcommand' => "yes")));
2015-07-13 20:10:26 +02:00
}
2015-08-23 16:37:21 +05:30
echo('</center>');
2015-07-13 20:10:26 +02:00
echo generate_graph_js_state($graph_array);
2011-06-14 14:04:56 +00:00
2015-08-22 17:58:10 +05:30
echo('<div style="width: '.$graph_array['width'].'; margin: auto;"><center>');
if (Config::get('webui.dynamic_graphs', false) === true) {
echo generate_dynamic_graph_js($graph_array);
echo generate_dynamic_graph_tag($graph_array);
} else {
echo generate_lazy_graph_tag($graph_array);
}
2015-08-22 17:58:10 +05:30
echo("</center></div>");
2015-07-13 20:10:26 +02:00
if (isset($config['graph_descr'][$vars['type']])) {
print_optionbar_start();
echo('<div style="float: left; width: 30px;">
<div style="margin: auto auto;">
<i class="fa fa-info-circle fa-lg icon-theme" aria-hidden="true"></i>
2015-07-13 20:10:26 +02:00
</div>
</div>');
echo($config['graph_descr'][$vars['type']]);
print_optionbar_end();
}
2015-07-13 20:10:26 +02:00
if ($vars['showcommand']) {
$_GET = $graph_array;
$command_only = 1;
2012-04-06 13:56:23 +00:00
2015-07-13 20:10:26 +02:00
require 'includes/graphs/graph.inc.php';
}
2010-08-01 14:17:06 +00:00
}