66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Libraries\RateLimiterService;
|
|
|
|
class RateLimitAdminController extends BaseController
|
|
{
|
|
protected RateLimiterService $limiter;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->limiter = new RateLimiterService();
|
|
}
|
|
|
|
public function index(): void
|
|
{
|
|
$tab = $this->request->getGet('tab');
|
|
if (! in_array($tab, ['ip', 'user'], true)) {
|
|
$tab = 'ip';
|
|
}
|
|
|
|
$data = [
|
|
'title' => 'Rate Limit Blocks',
|
|
'activeTab' => $tab,
|
|
'blockedIps' => $this->limiter->listBlockedIps(),
|
|
'blockedUsers' => $this->limiter->listBlockedUsers(),
|
|
];
|
|
|
|
$this->loadLayout('admin/rate_limit_blocks', $data);
|
|
}
|
|
|
|
public function unblockIp(): \CodeIgniter\HTTP\RedirectResponse
|
|
{
|
|
$fingerprint = trim((string) $this->request->getPost('cache_identifier'));
|
|
$reason = trim((string) $this->request->getPost('reason'));
|
|
$actorId = (int) (session()->get('userid') ?? 0);
|
|
|
|
if ($fingerprint === '') {
|
|
return redirect()->back()->with('error', 'Missing IP block identifier.');
|
|
}
|
|
|
|
$this->limiter->unblockIpByAdmin($fingerprint, $reason !== '' ? $reason : null, $actorId ?: null);
|
|
|
|
return redirect()->to(base_url('security/rate-limits?tab=ip'))
|
|
->with('success', 'Blocked IP entry unblocked successfully.');
|
|
}
|
|
|
|
public function unblockUser(): \CodeIgniter\HTTP\RedirectResponse
|
|
{
|
|
$identity = trim((string) $this->request->getPost('display_identifier'));
|
|
$reason = trim((string) $this->request->getPost('reason'));
|
|
$actorId = (int) (session()->get('userid') ?? 0);
|
|
|
|
if ($identity === '') {
|
|
return redirect()->back()->with('error', 'Missing user identity.');
|
|
}
|
|
|
|
$this->limiter->unblockUserByAdmin($identity, $reason !== '' ? $reason : null, $actorId ?: null);
|
|
|
|
return redirect()->to(base_url('security/rate-limits?tab=user'))
|
|
->with('success', 'Blocked user entry unblocked successfully.');
|
|
}
|
|
}
|
|
|