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);
|
|
}
|
|
}
|