webdav.php 2.6 KB

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