2020-03-17 12:06:52 -04:00
|
|
|
<?php
|
2023-08-15 02:27:01 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-03-17 12:06:52 -04:00
|
|
|
/**
|
2024-05-24 13:43:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-03-17 12:06:52 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Core\Command\Security;
|
|
|
|
|
|
|
|
|
|
use OC\Core\Command\Base;
|
2023-08-15 02:27:01 -04:00
|
|
|
use OCP\Security\Bruteforce\IThrottler;
|
2020-03-17 12:06:52 -04:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
2023-08-15 02:27:01 -04:00
|
|
|
class BruteforceResetAttempts extends Base {
|
2023-06-13 08:36:16 -04:00
|
|
|
public function __construct(
|
2023-08-15 02:27:01 -04:00
|
|
|
protected IThrottler $throttler,
|
2023-06-13 08:36:16 -04:00
|
|
|
) {
|
2020-03-17 12:06:52 -04:00
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 02:27:01 -04:00
|
|
|
protected function configure(): void {
|
2020-03-17 12:06:52 -04:00
|
|
|
$this
|
|
|
|
|
->setName('security:bruteforce:reset')
|
2023-08-15 02:27:01 -04:00
|
|
|
->setDescription('resets bruteforce attempts for given IP address')
|
2020-03-17 12:06:52 -04:00
|
|
|
->addArgument(
|
|
|
|
|
'ipaddress',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'IP address for which the attempts are to be reset'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 08:54:51 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2020-03-17 12:06:52 -04:00
|
|
|
$ip = $input->getArgument('ipaddress');
|
|
|
|
|
|
|
|
|
|
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
|
|
|
|
|
$output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->throttler->resetDelayForIP($ip);
|
2020-06-26 08:54:51 -04:00
|
|
|
return 0;
|
2020-03-17 12:06:52 -04:00
|
|
|
}
|
|
|
|
|
}
|