webdav.php 1.9 KB

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