ResetBruteforceAttempts.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2020, Johannes Riedel (johannes@johannes-riedel.de)
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace OC\Core\Command\Security;
  22. use OC\Core\Command\Base;
  23. use OC\Security\Bruteforce\Throttler;
  24. use Symfony\Component\Console\Input\InputArgument;
  25. use Symfony\Component\Console\Input\InputInterface;
  26. use Symfony\Component\Console\Output\OutputInterface;
  27. class ResetBruteforceAttempts extends Base {
  28. /** @var Throttler */
  29. protected $throttler;
  30. public function __construct(Throttler $throttler) {
  31. $this->throttler = $throttler;
  32. parent::__construct();
  33. }
  34. protected function configure() {
  35. $this
  36. ->setName('security:bruteforce:reset')
  37. ->setDescription('resets bruteforce attemps for given IP address')
  38. ->addArgument(
  39. 'ipaddress',
  40. InputArgument::REQUIRED,
  41. 'IP address for which the attempts are to be reset'
  42. );
  43. }
  44. protected function execute(InputInterface $input, OutputInterface $output): int {
  45. $ip = $input->getArgument('ipaddress');
  46. if (!filter_var($ip, FILTER_VALIDATE_IP)) {
  47. $output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
  48. return 1;
  49. }
  50. $this->throttler->resetDelayForIP($ip);
  51. return 0;
  52. }
  53. }