webdav.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Vincent Petry <pvince81@owncloud.com>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. // no php execution timeout for webdav
  31. if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
  32. @set_time_limit(0);
  33. }
  34. ignore_user_abort(true);
  35. // Turn off output buffering to prevent memory problems
  36. \OC_Util::obEnd();
  37. $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory(
  38. \OC::$server->getConfig(),
  39. \OC::$server->getLogger(),
  40. \OC::$server->getDatabaseConnection(),
  41. \OC::$server->getUserSession(),
  42. \OC::$server->getMountManager(),
  43. \OC::$server->getTagManager(),
  44. \OC::$server->getRequest(),
  45. \OC::$server->getPreviewManager(),
  46. \OC::$server->getEventDispatcher(),
  47. \OC::$server->getL10N('dav')
  48. );
  49. // Backends
  50. $authBackend = new \OCA\DAV\Connector\Sabre\Auth(
  51. \OC::$server->getSession(),
  52. \OC::$server->getUserSession(),
  53. \OC::$server->getRequest(),
  54. \OC::$server->getTwoFactorAuthManager(),
  55. \OC::$server->getBruteForceThrottler(),
  56. 'principals/'
  57. );
  58. $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
  59. $bearerAuthPlugin = new \OCA\DAV\Connector\Sabre\BearerAuth(
  60. \OC::$server->getUserSession(),
  61. \OC::$server->getSession(),
  62. \OC::$server->getRequest()
  63. );
  64. $authPlugin->addBackend($bearerAuthPlugin);
  65. $requestUri = \OC::$server->getRequest()->getRequestUri();
  66. $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () {
  67. // use the view for the logged in user
  68. return \OC\Files\Filesystem::getView();
  69. });
  70. $dispatcher = \OC::$server->getEventDispatcher();
  71. // allow setup of additional plugins
  72. $event = new \OCP\SabrePluginEvent($server);
  73. $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
  74. // And off we go!
  75. $server->exec();