From 88c86f2a196b2afa47b986193b75fb789a647bcd Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Thu, 15 Dec 2022 15:58:56 -0600 Subject: [PATCH] Fix graph output base64 (#14701) Mostly for people using unauth graphs instead of the api. --- app/Http/Controllers/GraphController.php | 6 ++---- includes/html/graphs/graph.inc.php | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/GraphController.php b/app/Http/Controllers/GraphController.php index c422eef8cc..b12188f27b 100644 --- a/app/Http/Controllers/GraphController.php +++ b/app/Http/Controllers/GraphController.php @@ -4,7 +4,6 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; -use LibreNMS\Config; use LibreNMS\Enum\ImageFormat; use LibreNMS\Exceptions\RrdGraphException; use LibreNMS\Util\Debug; @@ -19,7 +18,6 @@ class GraphController extends Controller public function __invoke(Request $request, string $path = ''): Response { $vars = array_merge(Url::parseLegacyPathVars($request->path()), $request->except(['username', 'password'])); - $output = $vars['graph_type'] ?? Config::get('webui.graph_type', 'default'); if (\Auth::check()) { // only allow debug for logged in users @@ -37,8 +35,8 @@ class GraphController extends Controller 'Content-type' => $graph->contentType(), ]; - if ($output == 'base64') { - return response($graph, 200, $headers); + if ($request->get('output') == 'base64') { + return response($graph->base64(), 200, $headers); } return response($graph->data, 200, $headers); diff --git a/includes/html/graphs/graph.inc.php b/includes/html/graphs/graph.inc.php index 28afba7ad1..03c3358e01 100644 --- a/includes/html/graphs/graph.inc.php +++ b/includes/html/graphs/graph.inc.php @@ -89,7 +89,7 @@ try { echo 'graph'; } else { 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) { if (\LibreNMS\Util\Debug::isEnabled()) {