mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Email Transport: embed graphs by default (#14270)
* 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
This commit is contained in:
@@ -5,39 +5,38 @@ 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
|
||||
{
|
||||
define('IGNORE_ERRORS', true);
|
||||
|
||||
include_once base_path('includes/dbFacile.php');
|
||||
include_once base_path('includes/common.php');
|
||||
include_once base_path('includes/html/functions.inc.php');
|
||||
include_once base_path('includes/rewrites.php');
|
||||
|
||||
$auth = \Auth::guest(); // if user not logged in, assume we authenticated via signed url, allow_unauth_graphs or allow_unauth_graphs_cidr
|
||||
$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']));
|
||||
}
|
||||
|
||||
// TODO, import graph.inc.php code and call Rrd::graph() directly
|
||||
chdir(base_path());
|
||||
ob_start();
|
||||
include base_path('includes/html/graphs/graph.inc.php');
|
||||
$output = ob_get_clean();
|
||||
ob_end_clean();
|
||||
$headers = [
|
||||
'Content-type' => Graph::imageType($vars['graph_type']),
|
||||
];
|
||||
|
||||
$headers = [];
|
||||
if (! Debug::isEnabled()) {
|
||||
$headers['Content-type'] = (Config::get('webui.graph_type') == 'svg' ? 'image/svg+xml' : 'image/png');
|
||||
try {
|
||||
return response(Graph::get($vars), 200, Debug::isEnabled() ? [] : $headers);
|
||||
} catch (RrdGraphException $e) {
|
||||
if (Debug::isEnabled()) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return response($e->generateErrorImage(), 500, $headers);
|
||||
}
|
||||
|
||||
return response($output, 200, $headers);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user