BruteforceResetAttempts.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Command\Security;
  8. use OC\Core\Command\Base;
  9. use OCP\Security\Bruteforce\IThrottler;
  10. use Symfony\Component\Console\Input\InputArgument;
  11. use Symfony\Component\Console\Input\InputInterface;
  12. use Symfony\Component\Console\Output\OutputInterface;
  13. class BruteforceResetAttempts extends Base {
  14. public function __construct(
  15. protected IThrottler $throttler,
  16. ) {
  17. parent::__construct();
  18. }
  19. protected function configure(): void {
  20. $this
  21. ->setName('security:bruteforce:reset')
  22. ->setDescription('resets bruteforce attempts for given IP address')
  23. ->addArgument(
  24. 'ipaddress',
  25. InputArgument::REQUIRED,
  26. 'IP address for which the attempts are to be reset'
  27. );
  28. }
  29. protected function execute(InputInterface $input, OutputInterface $output): int {
  30. $ip = $input->getArgument('ipaddress');
  31. if (!filter_var($ip, FILTER_VALIDATE_IP)) {
  32. $output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
  33. return 1;
  34. }
  35. $this->throttler->resetDelayForIP($ip);
  36. return 0;
  37. }
  38. }