PR CI / flow (pull_request) Successful in 4s
PR CI / ledger (pull_request) Successful in 4s
PR CI / test (stable) (pull_request) Successful in 35s
PR CI / test (lowest) (pull_request) Successful in 40s
PR CI / security (pull_request) Successful in 51s
PR CI / pr-ci (pull_request) Successful in 1s
PR CI / release-automerge (pull_request) Successful in 4s
34 lines
878 B
PHP
34 lines
878 B
PHP
<?php
|
|
|
|
namespace IriksIT\Manager\Modules\Audit;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Keeps an address with a ban "for the whole site" away from everything. Only added when
|
|
* `manager.audit.whole_site_bans` is on. It runs for every request, so the question is answered
|
|
* from the cache (IpBans::wholeSite) and costs a visitor nothing.
|
|
*/
|
|
class RefuseBannedFromTheSite
|
|
{
|
|
public function __construct(private readonly IpBans $bans) {}
|
|
|
|
/**
|
|
* @param Closure(Request): Response $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$ban = $this->bans->wholeSite($request->ip());
|
|
|
|
if ($ban === null) {
|
|
return $next($request);
|
|
}
|
|
|
|
$this->bans->knocked($ban);
|
|
|
|
return RefuseBannedAddress::answer($request, $ban);
|
|
}
|
|
}
|