2022-09-03 12:48:43 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use LibreNMS\Config;
|
2022-09-05 20:41:55 -05:00
|
|
|
use LibreNMS\Exceptions\RrdGraphException;
|
2022-09-03 12:48:43 -05:00
|
|
|
use LibreNMS\Util\Debug;
|
2022-09-05 20:41:55 -05:00
|
|
|
use LibreNMS\Util\Graph;
|
2022-09-03 12:48:43 -05:00
|
|
|
use LibreNMS\Util\Url;
|
|
|
|
|
|
|
|
|
|
class GraphController extends Controller
|
|
|
|
|
{
|
2022-09-05 20:41:55 -05:00
|
|
|
/**
|
|
|
|
|
* @throws \LibreNMS\Exceptions\RrdGraphException
|
|
|
|
|
*/
|
2022-09-03 12:48:43 -05:00
|
|
|
public function __invoke(Request $request, string $path = ''): Response
|
|
|
|
|
{
|
|
|
|
|
$vars = array_merge(Url::parseLegacyPathVars($request->path()), $request->except(['username', 'password']));
|
2022-09-05 20:41:55 -05:00
|
|
|
$vars['graph_type'] = $vars['graph_type'] ?? Config::get('webui.graph_type');
|
|
|
|
|
|
2022-09-03 12:48:43 -05:00
|
|
|
if (\Auth::check()) {
|
|
|
|
|
// only allow debug for logged in users
|
|
|
|
|
Debug::set(! empty($vars['debug']));
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-05 20:41:55 -05:00
|
|
|
$headers = [
|
|
|
|
|
'Content-type' => Graph::imageType($vars['graph_type']),
|
|
|
|
|
];
|
2022-09-03 12:48:43 -05:00
|
|
|
|
2022-09-05 20:41:55 -05:00
|
|
|
try {
|
|
|
|
|
return response(Graph::get($vars), 200, Debug::isEnabled() ? [] : $headers);
|
|
|
|
|
} catch (RrdGraphException $e) {
|
|
|
|
|
if (Debug::isEnabled()) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2022-09-03 12:48:43 -05:00
|
|
|
|
2022-09-05 20:41:55 -05:00
|
|
|
return response($e->generateErrorImage(), 500, $headers);
|
|
|
|
|
}
|
2022-09-03 12:48:43 -05:00
|
|
|
}
|
|
|
|
|
}
|