mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix graph_type variable (svg / png) (#15972)
This commit is contained in:
@ -27,6 +27,7 @@ namespace LibreNMS\Data\Store;
|
||||
|
||||
use App\Polling\Measure\Measurement;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Enum\ImageFormat;
|
||||
use LibreNMS\Exceptions\FileExistsException;
|
||||
use LibreNMS\Exceptions\RrdGraphException;
|
||||
use LibreNMS\Proc;
|
||||
@ -596,8 +597,11 @@ class Rrd extends BaseDatastore
|
||||
}
|
||||
|
||||
// if valid image is returned with error, extract image and feedback
|
||||
$image_type = Config::get('webui.graph_type', 'svg');
|
||||
$search = $this->getImageEnd($image_type);
|
||||
// rrdtool defaults to png if imgformat not specified
|
||||
$graph_type = preg_match('/--imgformat=([^\s]+)/', $options, $matches) ? strtolower($matches[1]) : 'png';
|
||||
$imageFormat = ImageFormat::forGraph($graph_type);
|
||||
|
||||
$search = $imageFormat->getImageEnd();
|
||||
if (($position = strrpos($process->getOutput(), $search)) !== false) {
|
||||
$position += strlen($search);
|
||||
throw new RrdGraphException(
|
||||
@ -615,16 +619,6 @@ class Rrd extends BaseDatastore
|
||||
throw new RrdGraphException($error, null, null, null, $process->getExitCode());
|
||||
}
|
||||
|
||||
private function getImageEnd(string $type): string
|
||||
{
|
||||
$image_suffixes = [
|
||||
'png' => hex2bin('0000000049454e44ae426082'),
|
||||
'svg' => '</svg>',
|
||||
];
|
||||
|
||||
return $image_suffixes[$type] ?? '';
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
|
@ -41,4 +41,14 @@ enum ImageFormat: string
|
||||
{
|
||||
return $this->value == 'svg' ? 'image/svg+xml' : 'image/png';
|
||||
}
|
||||
|
||||
public function getImageEnd(): string
|
||||
{
|
||||
$image_suffixes = [
|
||||
'png' => hex2bin('0000000049454e44ae426082'),
|
||||
'svg' => '</svg>',
|
||||
];
|
||||
|
||||
return $image_suffixes[$this->value] ?? '';
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class Graph
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return new GraphImage(ImageFormat::forGraph(), 'Error', $e->generateErrorImage());
|
||||
return new GraphImage(ImageFormat::forGraph($vars['graph_type'] ?? null), 'Error', $e->generateErrorImage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ class GraphController extends Controller
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return response($e->generateErrorImage(), 500, ['Content-type' => ImageFormat::forGraph()->contentType()]);
|
||||
return response($e->generateErrorImage(), 500, ['Content-type' => ImageFormat::forGraph($vars['graph_type'] ?? null)->contentType()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,9 +96,9 @@ try {
|
||||
|
||||
// output the graph
|
||||
if (\LibreNMS\Util\Debug::isEnabled()) {
|
||||
echo '<img src="data:' . ImageFormat::forGraph()->contentType() . ';base64,' . base64_encode($image_data) . '" alt="graph" />';
|
||||
echo '<img src="data:' . ImageFormat::forGraph($vars['graph_type'] ?? null)->contentType() . ';base64,' . base64_encode($image_data) . '" alt="graph" />';
|
||||
} else {
|
||||
header('Content-type: ' . ImageFormat::forGraph()->contentType());
|
||||
header('Content-type: ' . ImageFormat::forGraph($vars['graph_type'] ?? null)->contentType());
|
||||
echo (isset($vars['output']) && $vars['output'] === 'base64') ? base64_encode($image_data) : $image_data;
|
||||
}
|
||||
} catch (\LibreNMS\Exceptions\RrdGraphException $e) {
|
||||
|
Reference in New Issue
Block a user