mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix graph output base64 (#14701)
Mostly for people using unauth graphs instead of the api.
This commit is contained in:
@@ -4,7 +4,6 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use LibreNMS\Config;
|
|
||||||
use LibreNMS\Enum\ImageFormat;
|
use LibreNMS\Enum\ImageFormat;
|
||||||
use LibreNMS\Exceptions\RrdGraphException;
|
use LibreNMS\Exceptions\RrdGraphException;
|
||||||
use LibreNMS\Util\Debug;
|
use LibreNMS\Util\Debug;
|
||||||
@@ -19,7 +18,6 @@ class GraphController extends Controller
|
|||||||
public function __invoke(Request $request, string $path = ''): Response
|
public function __invoke(Request $request, string $path = ''): Response
|
||||||
{
|
{
|
||||||
$vars = array_merge(Url::parseLegacyPathVars($request->path()), $request->except(['username', 'password']));
|
$vars = array_merge(Url::parseLegacyPathVars($request->path()), $request->except(['username', 'password']));
|
||||||
$output = $vars['graph_type'] ?? Config::get('webui.graph_type', 'default');
|
|
||||||
|
|
||||||
if (\Auth::check()) {
|
if (\Auth::check()) {
|
||||||
// only allow debug for logged in users
|
// only allow debug for logged in users
|
||||||
@@ -37,8 +35,8 @@ class GraphController extends Controller
|
|||||||
'Content-type' => $graph->contentType(),
|
'Content-type' => $graph->contentType(),
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($output == 'base64') {
|
if ($request->get('output') == 'base64') {
|
||||||
return response($graph, 200, $headers);
|
return response($graph->base64(), 200, $headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response($graph->data, 200, $headers);
|
return response($graph->data, 200, $headers);
|
||||||
|
@@ -89,7 +89,7 @@ try {
|
|||||||
echo '<img src="data:' . ImageFormat::forGraph()->contentType() . ';base64,' . base64_encode($image_data) . '" alt="graph" />';
|
echo '<img src="data:' . ImageFormat::forGraph()->contentType() . ';base64,' . base64_encode($image_data) . '" alt="graph" />';
|
||||||
} else {
|
} else {
|
||||||
header('Content-type: ' . ImageFormat::forGraph()->contentType());
|
header('Content-type: ' . ImageFormat::forGraph()->contentType());
|
||||||
echo $output === 'base64' ? base64_encode($image_data) : $image_data;
|
echo (isset($vars['output']) && $vars['output'] === 'base64') ? base64_encode($image_data) : $image_data;
|
||||||
}
|
}
|
||||||
} catch (\LibreNMS\Exceptions\RrdGraphException $e) {
|
} catch (\LibreNMS\Exceptions\RrdGraphException $e) {
|
||||||
if (\LibreNMS\Util\Debug::isEnabled()) {
|
if (\LibreNMS\Util\Debug::isEnabled()) {
|
||||||
|
Reference in New Issue
Block a user