1
0

Capabilities.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017 Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author J0WI <J0WI@users.noreply.github.com>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OC\Security\Bruteforce;
  27. use OCP\Capabilities\IPublicCapability;
  28. use OCP\Capabilities\IInitialStateExcludedCapability;
  29. use OCP\IRequest;
  30. class Capabilities implements IPublicCapability, IInitialStateExcludedCapability {
  31. /** @var IRequest */
  32. private $request;
  33. /** @var Throttler */
  34. private $throttler;
  35. /**
  36. * Capabilities constructor.
  37. *
  38. * @param IRequest $request
  39. * @param Throttler $throttler
  40. */
  41. public function __construct(IRequest $request,
  42. Throttler $throttler) {
  43. $this->request = $request;
  44. $this->throttler = $throttler;
  45. }
  46. public function getCapabilities(): array {
  47. if (version_compare(\OC::$server->getConfig()->getSystemValueString('version', '0.0.0.0'), '12.0.0.0', '<')) {
  48. return [];
  49. }
  50. return [
  51. 'bruteforce' => [
  52. 'delay' => $this->throttler->getDelay($this->request->getRemoteAddress())
  53. ]
  54. ];
  55. }
  56. }