1
0

webdav.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. use OC\Files\Filesystem;
  8. use OCA\DAV\Connector\Sabre\Auth;
  9. use OCA\DAV\Connector\Sabre\BearerAuth;
  10. use OCA\DAV\Connector\Sabre\ServerFactory;
  11. use OCA\DAV\Events\SabrePluginAddEvent;
  12. use OCP\EventDispatcher\IEventDispatcher;
  13. use OCP\SabrePluginEvent;
  14. use Psr\Log\LoggerInterface;
  15. // no php execution timeout for webdav
  16. if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
  17. @set_time_limit(0);
  18. }
  19. ignore_user_abort(true);
  20. // Turn off output buffering to prevent memory problems
  21. \OC_Util::obEnd();
  22. $dispatcher = \OC::$server->get(IEventDispatcher::class);
  23. $serverFactory = new ServerFactory(
  24. \OC::$server->getConfig(),
  25. \OC::$server->get(LoggerInterface::class),
  26. \OC::$server->getDatabaseConnection(),
  27. \OC::$server->getUserSession(),
  28. \OC::$server->getMountManager(),
  29. \OC::$server->getTagManager(),
  30. \OC::$server->getRequest(),
  31. \OC::$server->getPreviewManager(),
  32. $dispatcher,
  33. \OC::$server->getL10N('dav')
  34. );
  35. // Backends
  36. $authBackend = new Auth(
  37. \OC::$server->getSession(),
  38. \OC::$server->getUserSession(),
  39. \OC::$server->getRequest(),
  40. \OC::$server->getTwoFactorAuthManager(),
  41. \OC::$server->getBruteForceThrottler(),
  42. 'principals/'
  43. );
  44. $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
  45. $bearerAuthPlugin = new BearerAuth(
  46. \OC::$server->getUserSession(),
  47. \OC::$server->getSession(),
  48. \OC::$server->getRequest()
  49. );
  50. $authPlugin->addBackend($bearerAuthPlugin);
  51. $requestUri = \OC::$server->getRequest()->getRequestUri();
  52. $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () {
  53. // use the view for the logged in user
  54. return Filesystem::getView();
  55. });
  56. // allow setup of additional plugins
  57. $event = new SabrePluginEvent($server);
  58. $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
  59. $event = new SabrePluginAddEvent($server);
  60. $dispatcher->dispatchTyped($event);
  61. // And off we go!
  62. $server->exec();