Fix graph errors wrong content type (#14574)

Some code was returning too soon and messing up the return type
Other code was simply not setting it
This commit is contained in:
Tony Murray
2022-11-03 15:07:17 -05:00
committed by GitHub
parent 95e81a53a8
commit 539ef9ff90
6 changed files with 18 additions and 34 deletions

View File

@@ -11,6 +11,7 @@
*/
use LibreNMS\Config;
use LibreNMS\Enum\ImageFormat;
use LibreNMS\Util\Number;
use LibreNMS\Util\Rewrite;
@@ -436,28 +437,10 @@ function generate_port_image($args)
* @param string $text
* @param int[] $color
*/
function graph_error($text, $color = [128, 0, 0])
function graph_error($text, $short = null, $color = [128, 0, 0])
{
echo \LibreNMS\Util\Graph::error($text, null, 300, null, $color);
}
/**
* Output message to user in image format.
*
* @param string $text string to display
*/
function graph_text_and_exit($text)
{
global $vars;
if ($vars['showcommand'] == 'yes') {
echo $text;
return;
}
graph_error($text, [13, 21, 210]);
exit;
header('Content-Type: ' . ImageFormat::forGraph()->contentType());
echo \LibreNMS\Util\Graph::error($text, $short, 300, null, $color);
}
function print_port_thumbnail($args)

View File

@@ -7,7 +7,7 @@ $ds_out = 'OUTOCTETS';
$ports = dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ? AND `disabled` = 0 AND `deleted` = 0', [$device['device_id']]);
if (empty($ports)) {
graph_text_and_exit('No Ports');
throw new \LibreNMS\Exceptions\RrdGraphException('No Ports');
}
$i = 0;

View File

@@ -3,7 +3,7 @@
$procs = dbFetchRows('SELECT * FROM `processors` where `device_id` = ?', [$device['device_id']]);
if (empty($procs)) {
graph_text_and_exit('No Processors');
throw new \LibreNMS\Exceptions\RrdGraphException('No Processors');
}
if (\LibreNMS\Config::getOsSetting($device['os'], 'processor_stacked')) {

View File

@@ -11,7 +11,7 @@ $rrd_options .= " COMMENT:' Size Used % Used\\l'"
$storages = dbFetchRows('SELECT * FROM storage where device_id = ?', [$device['device_id']]);
if (empty($storages)) {
graph_text_and_exit('No Storage');
throw new \LibreNMS\Exceptions\RrdGraphException('No Storage');
}
foreach ($storages as $storage) {

View File

@@ -42,13 +42,12 @@ if ($auth && is_customoid_graph($type, $subtype)) {
} 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";
} else {
graph_error("$type*$subtype ");
// Graph Template Missing");
graph_error("$type*$subtype Graph Template Missing", "$type*$subtype");
}
if ($auth === null) {
// We are unauthenticated :(
graph_error($width < 200 ? 'No Auth' : 'No Authorization');
graph_error('No Authorization', 'No Auth');
return;
}
@@ -76,7 +75,7 @@ if (! empty($command_only)) {
}
if (empty($rrd_options)) {
graph_error($width < 200 ? 'Def Error' : 'Graph Definition Error');
graph_error('Graph Definition Error', 'Def Error');
return;
}
@@ -98,8 +97,8 @@ try {
}
if (isset($rrd_filename) && ! Rrd::checkRrdExists($rrd_filename)) {
graph_error($width < 200 ? 'No Data' : 'No Data file ' . basename($rrd_filename));
graph_error('No Data file ' . basename($rrd_filename), 'No Data');
} else {
graph_error($width < 200 ? 'Draw Error' : 'Error Drawing Graph: ' . $e->getMessage());
graph_error('Error Drawing Graph: ' . $e->getMessage(), 'Draw Error');
}
}

View File

@@ -1,5 +1,7 @@
<?php
use LibreNMS\Exceptions\RrdGraphException;
if (is_numeric($vars['id'])) {
$acc = dbFetchRow('SELECT * FROM `mac_accounting` AS M, `ports` AS I, `devices` AS D WHERE M.ma_id = ? AND I.port_id = M.port_id AND I.device_id = D.device_id', [$vars['id']]);
@@ -25,14 +27,14 @@ if (is_numeric($vars['id'])) {
$title .= ' :: ' . \LibreNMS\Util\Rewrite::readableMac($acc['mac']);
$auth = true;
} else {
graph_error('file not found');
throw new RrdGraphException('file not found');
}
} else {
graph_error('unauthenticated');
throw new RrdGraphException('unauthenticated');
}
} else {
graph_error('entry not found');
throw new RrdGraphException('entry not found');
}
} else {
graph_error('invalid id');
throw new RrdGraphException('invalid id');
}