2010-07-24 19:14:41 +00:00
|
|
|
<?php
|
|
|
|
|
2019-05-01 10:52:07 +02:00
|
|
|
use LibreNMS\Config;
|
|
|
|
|
2021-05-03 09:48:15 -05:00
|
|
|
global $debug;
|
|
|
|
|
2012-05-11 13:26:14 +00:00
|
|
|
// Push $_GET into $vars to be compatible with web interface naming
|
|
|
|
foreach ($_GET as $name => $value) {
|
|
|
|
$vars[$name] = $value;
|
|
|
|
}
|
|
|
|
|
2019-08-12 09:46:36 -05:00
|
|
|
[$type, $subtype] = extract_graph_type($vars['type']);
|
2012-05-11 13:26:14 +00:00
|
|
|
|
2022-08-30 12:55:37 -05:00
|
|
|
if (isset($vars['device'])) {
|
|
|
|
$device = is_numeric($vars['device'])
|
|
|
|
? device_by_id_cache($vars['device'])
|
|
|
|
: device_by_name($vars['device']);
|
2012-05-11 13:26:14 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 12:24:34 +00:00
|
|
|
// FIXME -- remove these
|
2012-05-11 13:26:14 +00:00
|
|
|
$width = $vars['width'];
|
|
|
|
$height = $vars['height'];
|
2022-08-30 12:55:37 -05:00
|
|
|
$title = $vars['title'] ?? '';
|
|
|
|
$vertical = $vars['vertical'] ?? '';
|
|
|
|
$legend = $vars['legend'] ?? false;
|
2018-04-11 09:02:04 -04:00
|
|
|
$output = (! empty($vars['output']) ? $vars['output'] : 'default');
|
2022-08-30 12:55:37 -05:00
|
|
|
$from = empty($_GET['from']) ? Config::get('time.day') : parse_at_time($_GET['from']);
|
|
|
|
$to = empty($_GET['to']) ? Config::get('time.now') : parse_at_time($_GET['to']);
|
2012-04-17 13:29:27 +00:00
|
|
|
$period = ($to - $from);
|
|
|
|
$prev_from = ($from - $period);
|
|
|
|
|
2021-05-03 09:48:15 -05:00
|
|
|
$graph_image_type = $vars['graph_type'] ?? Config::get('webui.graph_type');
|
|
|
|
$rrd_options = '';
|
2011-09-22 13:39:03 +00:00
|
|
|
|
2019-06-23 00:29:12 -05:00
|
|
|
require Config::get('install_dir') . "/includes/html/graphs/$type/auth.inc.php";
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2019-11-29 16:20:18 +01:00
|
|
|
//set default graph title
|
|
|
|
$graph_title = format_hostname($device);
|
|
|
|
|
2020-07-23 09:57:22 -05:00
|
|
|
if ($auth && is_customoid_graph($type, $subtype)) {
|
2019-12-19 01:17:21 +01:00
|
|
|
$unit = $vars['unit'];
|
|
|
|
include Config::get('install_dir') . '/includes/html/graphs/customoid/customoid.inc.php';
|
2019-06-23 00:29:12 -05:00
|
|
|
} elseif ($auth && is_file(Config::get('install_dir') . "/includes/html/graphs/$type/$subtype.inc.php")) {
|
|
|
|
include Config::get('install_dir') . "/includes/html/graphs/$type/$subtype.inc.php";
|
2016-08-18 20:28:22 -05:00
|
|
|
} else {
|
2012-05-21 18:17:23 +00:00
|
|
|
graph_error("$type*$subtype ");
|
|
|
|
// Graph Template Missing");
|
2010-07-24 19:14:41 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 09:48:15 -05:00
|
|
|
if (! empty($error_msg)) {
|
2012-05-25 12:24:34 +00:00
|
|
|
// We have an error :(
|
2021-05-03 09:48:15 -05:00
|
|
|
graph_error($error_msg);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($auth === null) {
|
2012-05-25 12:24:34 +00:00
|
|
|
// We are unauthenticated :(
|
2021-01-13 07:23:47 -06:00
|
|
|
graph_error($width < 200 ? 'No Auth' : 'No Authorization');
|
2021-05-03 09:48:15 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($graph_image_type === 'svg') {
|
|
|
|
$rrd_options .= ' --imgformat=SVG';
|
|
|
|
if ($width < 350) {
|
|
|
|
$rrd_options .= ' -m 0.75 -R light';
|
2017-02-22 12:08:18 +00:00
|
|
|
}
|
2021-05-03 09:48:15 -05:00
|
|
|
}
|
2017-02-22 12:08:18 +00:00
|
|
|
|
2021-05-03 09:48:15 -05:00
|
|
|
// command output requested
|
|
|
|
if (! empty($command_only)) {
|
|
|
|
echo "<div class='infobox'>";
|
|
|
|
echo "<p style='font-size: 16px; font-weight: bold;'>RRDTool Command</p>";
|
|
|
|
echo "<pre class='rrd-pre'>";
|
2021-05-13 11:27:05 -05:00
|
|
|
echo escapeshellcmd('rrdtool ' . Rrd::buildCommand('graph', Config::get('temp_dir') . '/' . strgen(), $rrd_options));
|
2021-05-03 09:48:15 -05:00
|
|
|
echo '</pre>';
|
|
|
|
try {
|
|
|
|
Rrd::graph($rrd_options);
|
|
|
|
} catch (\LibreNMS\Exceptions\RrdGraphException $e) {
|
2017-04-05 07:54:55 +01:00
|
|
|
echo "<p style='font-size: 16px; font-weight: bold;'>RRDTool Output</p>";
|
|
|
|
echo "<pre class='rrd-pre'>";
|
2021-05-03 09:48:15 -05:00
|
|
|
echo $e->getMessage();
|
2017-04-05 07:54:55 +01:00
|
|
|
echo '</pre>';
|
2021-05-03 09:48:15 -05:00
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// graph sent file not found flag
|
|
|
|
if (! empty($no_file)) {
|
|
|
|
graph_error($width < 200 ? 'No Data' : 'No Data file ' . $no_file);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($rrd_options)) {
|
|
|
|
graph_error($width < 200 ? 'Def Error' : 'Graph Definition Error');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generating the graph!
|
|
|
|
try {
|
|
|
|
$image_data = Rrd::graph($rrd_options);
|
|
|
|
|
|
|
|
// output the graph
|
|
|
|
if (\LibreNMS\Util\Debug::isEnabled()) {
|
|
|
|
echo '<img src="data:' . get_image_type($graph_image_type) . ';base64,' . base64_encode($image_data) . '" alt="graph" />';
|
|
|
|
} else {
|
|
|
|
header('Content-type: ' . get_image_type(Config::get('webui.graph_type')));
|
|
|
|
echo $output === 'base64' ? base64_encode($image_data) : $image_data;
|
|
|
|
}
|
|
|
|
} catch (\LibreNMS\Exceptions\RrdGraphException $e) {
|
|
|
|
if (isset($rrd_filename) && ! Rrd::checkRrdExists($rrd_filename)) {
|
|
|
|
graph_error($width < 200 ? 'No Data' : 'No Data file ' . basename($rrd_filename));
|
2021-01-13 07:23:47 -06:00
|
|
|
} else {
|
2021-05-03 09:48:15 -05:00
|
|
|
graph_error($width < 200 ? 'Draw Error' : 'Error Drawing Graph: ' . $e->getMessage());
|
2010-12-02 17:41:12 +00:00
|
|
|
}
|
2010-08-01 17:25:44 +00:00
|
|
|
}
|