mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
302a989d4e
* Email embed graphs * Allow attachment for non-html Add setting to webui Correct $auth setting * Cleanups, throw RrdGraphException instead of returning an error image. Generate the error image later, giving more control. Reduce code duplication a little * Style and lint fixes Change to flags * Add baseline for lint errors I don't know how to resolve * oopsie, changed the code after generating the baseline * Tiny cleanups. Make set DeviceCache primary, it is free. * Docs. * email_html note * Allow control of graph embed at the email transport level to override the global config. * Allow control of graph embed at the email transport level to override the global config. * Add INLINE_BASE64 to make it easier to create inline image tags
43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use LibreNMS\Config;
|
|
use LibreNMS\Exceptions\RrdGraphException;
|
|
use LibreNMS\Util\Debug;
|
|
use LibreNMS\Util\Graph;
|
|
use LibreNMS\Util\Url;
|
|
|
|
class GraphController extends Controller
|
|
{
|
|
/**
|
|
* @throws \LibreNMS\Exceptions\RrdGraphException
|
|
*/
|
|
public function __invoke(Request $request, string $path = ''): Response
|
|
{
|
|
$vars = array_merge(Url::parseLegacyPathVars($request->path()), $request->except(['username', 'password']));
|
|
$vars['graph_type'] = $vars['graph_type'] ?? Config::get('webui.graph_type');
|
|
|
|
if (\Auth::check()) {
|
|
// only allow debug for logged in users
|
|
Debug::set(! empty($vars['debug']));
|
|
}
|
|
|
|
$headers = [
|
|
'Content-type' => Graph::imageType($vars['graph_type']),
|
|
];
|
|
|
|
try {
|
|
return response(Graph::get($vars), 200, Debug::isEnabled() ? [] : $headers);
|
|
} catch (RrdGraphException $e) {
|
|
if (Debug::isEnabled()) {
|
|
throw $e;
|
|
}
|
|
|
|
return response($e->generateErrorImage(), 500, $headers);
|
|
}
|
|
}
|
|
}
|