mirror of
https://github.com/getnamingo/registry.git
synced 2025-05-29 17:00:06 +02:00
Improved CP error handling and audit log
This commit is contained in:
parent
0c6cb72852
commit
18e6eafb41
5 changed files with 113 additions and 3 deletions
|
@ -128,6 +128,35 @@ class Logger extends \Monolog\Logger
|
||||||
} else {
|
} else {
|
||||||
$logger = new Logger('errors');
|
$logger = new Logger('errors');
|
||||||
ErrorHandler::register($logger);
|
ErrorHandler::register($logger);
|
||||||
|
|
||||||
|
set_exception_handler(function ($e) use ($logger) {
|
||||||
|
http_response_code(500);
|
||||||
|
|
||||||
|
$logger->error("Unhandled exception", [
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine(),
|
||||||
|
'trace' => $e->getTraceAsString()
|
||||||
|
]);
|
||||||
|
|
||||||
|
include '/var/www/cp/resources/error.html';
|
||||||
|
});
|
||||||
|
|
||||||
|
register_shutdown_function(function () use ($logger) {
|
||||||
|
$error = error_get_last();
|
||||||
|
if ($error && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) {
|
||||||
|
http_response_code(500);
|
||||||
|
|
||||||
|
$logger->error("Fatal error", [
|
||||||
|
'message' => $error['message'],
|
||||||
|
'file' => $error['file'],
|
||||||
|
'line' => $error['line'],
|
||||||
|
'type' => $error['type']
|
||||||
|
]);
|
||||||
|
|
||||||
|
include '/var/www/cp/resources/error.html';
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
cp/app/Middleware/AuditMiddleware.php
Normal file
22
cp/app/Middleware/AuditMiddleware.php
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Middleware;
|
||||||
|
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
|
||||||
|
use Pinga\Session;
|
||||||
|
|
||||||
|
class AuditMiddleware extends Middleware
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __invoke(Request $request, RequestHandler $handler)
|
||||||
|
{
|
||||||
|
if (isset($_SESSION['auth_user_id'])) {
|
||||||
|
$userId = (int)$_SESSION['auth_user_id'];
|
||||||
|
$this->container->get('db')->exec("SET @audit_usr_id = $userId");
|
||||||
|
$this->container->get('db')->exec("SET @audit_ses_id = " . crc32(\Pinga\Session\Session::id()));
|
||||||
|
}
|
||||||
|
return $handler->handle($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -261,6 +261,7 @@ $container->set('csrf', function($container) use ($responseFactory) {
|
||||||
return new Slim\Csrf\Guard($responseFactory);
|
return new Slim\Csrf\Guard($responseFactory);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$app->add(new \App\Middleware\AuditMiddleware($container));
|
||||||
$app->add(new \App\Middleware\ValidationErrorsMiddleware($container));
|
$app->add(new \App\Middleware\ValidationErrorsMiddleware($container));
|
||||||
$app->add(new \App\Middleware\OldInputMiddleware($container));
|
$app->add(new \App\Middleware\OldInputMiddleware($container));
|
||||||
$app->add(new \App\Middleware\CsrfViewMiddleware($container));
|
$app->add(new \App\Middleware\CsrfViewMiddleware($container));
|
||||||
|
|
60
cp/resources/error.html
Normal file
60
cp/resources/error.html
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||||
|
<title>Something went wrong | Namingo</title>
|
||||||
|
<meta name="theme-color" content="#066fd1">
|
||||||
|
<!-- CSS files -->
|
||||||
|
<link href="/assets/css/tabler.min.css" rel="stylesheet"/>
|
||||||
|
<link href="/assets/css/tabler-flags.min.css" rel="stylesheet"/>
|
||||||
|
<link href="/assets/css/tabler-payments.min.css" rel="stylesheet"/>
|
||||||
|
<link href="/assets/css/tabler-vendors.min.css" rel="stylesheet"/>
|
||||||
|
<style>
|
||||||
|
@import url('/assets/fonts/inter/inter.css');
|
||||||
|
:root {
|
||||||
|
--tblr-font-sans-serif: "Inter", -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
|
||||||
|
}
|
||||||
|
@supports (font-variation-settings: normal) {
|
||||||
|
:root {
|
||||||
|
--tblr-font-sans-serif: "InterVariable", -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
|
||||||
|
font-optical-sizing: auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="border-top-wide border-primary">
|
||||||
|
<div class="page page-center">
|
||||||
|
<div class="container py-4">
|
||||||
|
<div class="empty">
|
||||||
|
<div class="empty-header">Something went wrong</div>
|
||||||
|
<p class="empty-title">Please try again shortly</p>
|
||||||
|
<p class="empty-subtitle text-secondary">If the problem persists, please contact support.</p>
|
||||||
|
<div class="empty-action">
|
||||||
|
<a href="/." class="btn btn-primary btn-4">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="icon icon-2"
|
||||||
|
>
|
||||||
|
<path d="M5 12l14 0" />
|
||||||
|
<path d="M5 12l6 6" />
|
||||||
|
<path d="M5 12l6 -6" />
|
||||||
|
</svg>
|
||||||
|
Take me home
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="/assets/js/tabler.min.js" defer></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -384,6 +384,4 @@ $app->add(function (Psr\Http\Message\ServerRequestInterface $request, Psr\Http\S
|
||||||
->withHeader('Location', '/')
|
->withHeader('Location', '/')
|
||||||
->withStatus(302);
|
->withStatus(302);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->addErrorMiddleware(false, true, true);
|
|
Loading…
Add table
Add a link
Reference in a new issue