33 lines
949 B
PHP
33 lines
949 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
|
|
class LogViewerPassword
|
|
{
|
|
public function handle($request, Closure $next)
|
|
{
|
|
$password = config('logviewer.password');
|
|
|
|
if (!is_string($password) || $password === '') {
|
|
return response('Akses log belum dikonfigurasi.', 503)
|
|
->header('Cache-Control', 'no-store');
|
|
}
|
|
|
|
$provided = $request->getPassword();
|
|
if ($request->getUser() !== 'logs' || !is_string($provided) ||
|
|
!hash_equals(hash('sha256', $password), hash('sha256', $provided))) {
|
|
return response('Kata laluan diperlukan untuk mengakses log.', 401, [
|
|
'WWW-Authenticate' => 'Basic realm="Log Viewer", charset="UTF-8"',
|
|
'Cache-Control' => 'no-store',
|
|
]);
|
|
}
|
|
|
|
$response = $next($request);
|
|
$response->headers->set('Cache-Control', 'no-store');
|
|
|
|
return $response;
|
|
}
|
|
}
|