1
0

webdav.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Julius Härtl <jus@bitgrid.net>
  8. * @author Ko- <k.stoffelen@cs.ru.nl>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. * @author Vincent Petry <vincent@nextcloud.com>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. use Psr\Log\LoggerInterface;
  32. // no php execution timeout for webdav
  33. if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
  34. @set_time_limit(0);
  35. }
  36. ignore_user_abort(true);
  37. // Turn off output buffering to prevent memory problems
  38. \OC_Util::obEnd();
  39. $dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);
  40. $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory(
  41. \OC::$server->getConfig(),
  42. \OC::$server->get(LoggerInterface::class),
  43. \OC::$server->getDatabaseConnection(),
  44. \OC::$server->getUserSession(),
  45. \OC::$server->getMountManager(),
  46. \OC::$server->getTagManager(),
  47. \OC::$server->getRequest(),
  48. \OC::$server->getPreviewManager(),
  49. $dispatcher,
  50. \OC::$server->getL10N('dav')
  51. );
  52. // Backends
  53. $authBackend = new \OCA\DAV\Connector\Sabre\Auth(
  54. \OC::$server->getSession(),
  55. \OC::$server->getUserSession(),
  56. \OC::$server->getRequest(),
  57. \OC::$server->getTwoFactorAuthManager(),
  58. \OC::$server->getBruteForceThrottler(),
  59. 'principals/'
  60. );
  61. $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
  62. $bearerAuthPlugin = new \OCA\DAV\Connector\Sabre\BearerAuth(
  63. \OC::$server->getUserSession(),
  64. \OC::$server->getSession(),
  65. \OC::$server->getRequest()
  66. );
  67. $authPlugin->addBackend($bearerAuthPlugin);
  68. $requestUri = \OC::$server->getRequest()->getRequestUri();
  69. $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () {
  70. // use the view for the logged in user
  71. return \OC\Files\Filesystem::getView();
  72. });
  73. // allow setup of additional plugins
  74. $event = new \OCP\SabrePluginEvent($server);
  75. $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
  76. $event = new \OCA\DAV\Events\SabrePluginAddEvent($server);
  77. $dispatcher->dispatchTyped($event);
  78. // And off we go!
  79. $server->exec();