1
0

DirectHome.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\Direct;
  25. use OC\Security\Bruteforce\Throttler;
  26. use OCA\DAV\Db\DirectMapper;
  27. use OCP\AppFramework\Db\DoesNotExistException;
  28. use OCP\AppFramework\Utility\ITimeFactory;
  29. use OCP\Files\IRootFolder;
  30. use OCP\IRequest;
  31. use Sabre\DAV\Exception\Forbidden;
  32. use Sabre\DAV\Exception\MethodNotAllowed;
  33. use Sabre\DAV\Exception\NotFound;
  34. use Sabre\DAV\ICollection;
  35. class DirectHome implements ICollection {
  36. /** @var IRootFolder */
  37. private $rootFolder;
  38. /** @var DirectMapper */
  39. private $mapper;
  40. /** @var ITimeFactory */
  41. private $timeFactory;
  42. /** @var Throttler */
  43. private $throttler;
  44. /** @var IRequest */
  45. private $request;
  46. public function __construct(IRootFolder $rootFolder,
  47. DirectMapper $mapper,
  48. ITimeFactory $timeFactory,
  49. Throttler $throttler,
  50. IRequest $request) {
  51. $this->rootFolder = $rootFolder;
  52. $this->mapper = $mapper;
  53. $this->timeFactory = $timeFactory;
  54. $this->throttler = $throttler;
  55. $this->request = $request;
  56. }
  57. public function createFile($name, $data = null) {
  58. throw new Forbidden();
  59. }
  60. public function createDirectory($name) {
  61. throw new Forbidden();
  62. }
  63. public function getChild($name): DirectFile {
  64. try {
  65. $direct = $this->mapper->getByToken($name);
  66. // Expired
  67. if ($direct->getExpiration() < $this->timeFactory->getTime()) {
  68. throw new NotFound();
  69. }
  70. return new DirectFile($direct, $this->rootFolder);
  71. } catch (DoesNotExistException $e) {
  72. // Since the token space is so huge only throttle on non exsisting token
  73. $this->throttler->registerAttempt('directlink', $this->request->getRemoteAddress());
  74. $this->throttler->sleepDelay($this->request->getRemoteAddress(), 'directlink');
  75. throw new NotFound();
  76. }
  77. }
  78. public function getChildren() {
  79. throw new MethodNotAllowed('Listing members of this collection is disabled');
  80. }
  81. public function childExists($name): bool {
  82. return false;
  83. }
  84. public function delete() {
  85. throw new Forbidden();
  86. }
  87. public function getName(): string {
  88. return 'direct';
  89. }
  90. public function setName($name) {
  91. throw new Forbidden();
  92. }
  93. public function getLastModified(): int {
  94. return 0;
  95. }
  96. }