4ee91a7918
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KTXC\Console\Firewall;
|
|
|
|
use KTXC\Service\FirewallService;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
#[AsCommand(name: 'firewall:maintenance', description: 'Remove expired firewall data and record the outcome')]
|
|
final class FirewallMaintenanceCommand extends Command
|
|
{
|
|
public function __construct(private readonly FirewallService $firewall)
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
try {
|
|
$result = $this->firewall->cleanup();
|
|
} catch (\Throwable $error) {
|
|
$io->error('Firewall maintenance failed: '.$error->getMessage());
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$io->success(sprintf(
|
|
'Firewall maintenance complete: %d expired rules, %d old logs, and %d expired claims removed.',
|
|
$result['expiredRules'],
|
|
$result['oldLogs'],
|
|
$result['expiredBruteForceClaims']
|
|
));
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|