Files

190 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
if (session('widescreen')) {
2020-09-21 15:40:17 +02:00
$graph_width = 1700;
$thumb_width = 180;
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 15:40:17 +02:00
$graph_width = 1075;
$thumb_width = 113;
2011-09-17 19:14:44 +00:00
}
$vars['from'] = parse_at_time($vars['from']) ?: Config::get('time.day');
$vars['to'] = parse_at_time($vars['to']) ?: Config::get('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);
2019-04-11 23:26:42 -05:00
$type = basename($graphtype['type']);
$subtype = basename($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']);
2020-09-21 15:40:17 +02:00
} elseif (! empty($vars['device'])) {
2015-07-13 20:10:26 +02:00
$device = device_by_name($vars['device']);
}
2020-09-21 15:59:34 +02:00
if (is_file('includes/html/graphs/' . $type . '/auth.inc.php')) {
require 'includes/html/graphs/' . $type . '/auth.inc.php';
}
2010-08-01 14:17:06 +00:00
2020-09-21 15:40:17 +02:00
if (! $auth) {
2019-04-11 23:26:42 -05:00
require 'includes/html/error-no-perm.inc.php';
2016-08-18 20:28:22 -05:00
} else {
2019-06-23 00:29:12 -05:00
if (Config::has("graph_types.$type.$subtype.descr")) {
2020-09-21 15:59:34 +02:00
$title .= ' :: ' . Config::get("graph_types.$type.$subtype.descr");
} 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'])) {
2020-09-21 15:59:34 +02:00
$title .= ' - ' . $vars['c_plugin_instance'];
2018-07-07 22:27:46 +09:00
}
2020-09-21 15:59:34 +02:00
$title .= ' - ' . $vars['c_type'];
2018-07-07 22:27:46 +09:00
if (isset($vars['c_type_instance'])) {
2020-09-21 15:59:34 +02:00
$title .= ' - ' . $vars['c_type_instance'];
2018-07-07 22:27:46 +09:00
}
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 15:59:34 +02:00
$title .= ' :: ' . nicecase($subtype);
2015-07-13 20:10:26 +02:00
}
$graph_array = $vars;
2020-09-21 15:59:34 +02:00
$graph_array['height'] = '60';
2017-05-01 23:49:11 -05:00
$graph_array['width'] = $thumb_width;
2020-09-21 15:59:34 +02:00
$graph_array['legend'] = 'no';
2019-06-23 00:29:12 -05:00
$graph_array['to'] = Config::get('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="">';
2019-07-17 07:20:26 -05:00
echo csrf_field();
2017-05-01 23:49:11 -05:00
echo "<select name='type' id='type' onchange=\"window.open(this.options[this.selectedIndex].value,'_top')\" >";
foreach (get_graph_subtypes($type, $device) as $avail_type) {
2020-09-21 15:59:34 +02:00
echo "<option value='" . generate_url($vars, ['type' => $type . '_' . $avail_type, 'page' => 'graphs']) . "'";
2017-05-01 23:49:11 -05:00
if ($avail_type == $subtype) {
2020-09-21 15:59:34 +02:00
echo ' selected';
2017-05-01 23:49:11 -05:00
}
$display_type = nicecase($avail_type);
2017-05-01 23:49:11 -05:00
echo ">$display_type</option>";
}
echo '</select></form></div>';
}
2015-07-13 20:10:26 +02:00
print_optionbar_end();
2019-06-23 00:29:12 -05:00
$thumb_array = Config::get('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) {
2019-06-23 00:29:12 -05:00
$graph_array['from'] = Config::get("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'];
2020-09-21 15:59:34 +02:00
$link_array['page'] = 'graphs';
2015-07-13 20:10:26 +02:00
$link = generate_url($link_array);
2020-09-21 15:40:17 +02:00
echo '<td align=center>';
echo '<b>' . $text . '</b><br>';
echo '<a href="' . $link . '">';
2015-07-16 12:42:58 -04:00
echo generate_lazy_graph_tag($graph_array);
2020-09-21 15:40:17 +02:00
echo '</a>';
echo '</td>';
2015-07-13 20:10:26 +02:00
}
2020-09-21 15:40:17 +02:00
echo '</tr></table>';
2011-09-17 19:14:44 +00:00
2015-07-13 20:10:26 +02:00
$graph_array = $vars;
2019-06-23 00:29:12 -05:00
$graph_array['height'] = Config::get('webui.min_graph_height');
2020-09-21 15:40:17 +02:00
$graph_array['width'] = $graph_width;
2011-09-20 09:55:11 +00:00
if ($screen_width = Session::get('screen_width')) {
if ($screen_width > 800) {
2020-09-21 15:40:17 +02:00
$graph_array['width'] = ($screen_width - ($screen_width / 10));
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 15:40:17 +02:00
$graph_array['width'] = ($screen_width - ($screen_width / 4));
}
}
if ($screen_height = Session::get('screen_height')) {
if ($screen_height > 960) {
2020-09-21 15:40:17 +02:00
$graph_array['height'] = ($screen_height - ($screen_height / 2));
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 15:40:17 +02:00
$graph_array['height'] = max($graph_array['height'], ($screen_height - ($screen_height / 1.5)));
}
}
2020-09-21 15:59:34 +02:00
echo '<hr />';
2019-04-11 23:26:42 -05:00
include_once 'includes/html/print-date-selector.inc.php';
2020-09-21 15:40:17 +02:00
echo '<div style="padding-top: 5px";></div>';
echo '<center>';
2020-09-21 15:59:34 +02:00
if ($vars['legend'] == 'no') {
echo generate_link('Show Legend', $vars, ['page' => 'graphs', 'legend' => null]);
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 15:59:34 +02:00
echo generate_link('Hide Legend', $vars, ['page' => 'graphs', 'legend' => 'no']);
2015-07-13 20:10:26 +02:00
}
2015-07-13 20:10:26 +02:00
// FIXME : do this properly
2020-09-21 15:40:17 +02:00
// if ($type == "port" && $subtype == "bits")
// {
echo ' | ';
2020-09-21 15:59:34 +02:00
if ($vars['previous'] == 'yes') {
echo generate_link('Hide Previous', $vars, ['page' => 'graphs', 'previous' => null]);
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 15:59:34 +02:00
echo generate_link('Show Previous', $vars, ['page' => 'graphs', 'previous' => 'yes']);
2015-07-13 20:10:26 +02:00
}
2020-09-21 15:40:17 +02:00
// }
2012-04-18 10:51:18 +00:00
2020-09-21 15:40:17 +02:00
echo ' | ';
2020-09-21 15:59:34 +02:00
if ($vars['showcommand'] == 'yes') {
echo generate_link('Hide RRD Command', $vars, ['page' => 'graphs', 'showcommand' => null]);
2016-08-18 20:28:22 -05:00
} else {
2020-09-21 15:59:34 +02:00
echo generate_link('Show RRD Command', $vars, ['page' => 'graphs', 'showcommand' => 'yes']);
2015-07-13 20:10:26 +02:00
}
2019-09-02 13:12:27 +00:00
if ($vars['type'] == 'port_bits') {
echo ' | To show trend, set to future date';
}
2020-09-21 15:40:17 +02:00
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
2020-09-21 15:40:17 +02:00
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);
}
2020-09-21 15:59:34 +02:00
echo '</center></div>';
2019-06-23 00:29:12 -05:00
if (Config::has('graph_descr.' . $vars['type'])) {
2015-07-13 20:10:26 +02:00
print_optionbar_start();
2020-09-21 15:40:17 +02:00
echo '<div style="float: left; width: 30px;">
2015-07-13 20:10:26 +02:00
<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>
2020-09-21 15:40:17 +02:00
</div>';
echo Config::get('graph_descr.' . $vars['type']);
2015-07-13 20:10:26 +02:00
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
2019-04-11 23:26:42 -05:00
require 'includes/html/graphs/graph.inc.php';
2015-07-13 20:10:26 +02:00
}
2010-08-01 14:17:06 +00:00
}