webdav.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <pvince81@owncloud.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. // no php execution timeout for webdav
  32. if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
  33. @set_time_limit(0);
  34. }
  35. ignore_user_abort(true);
  36. // Turn off output buffering to prevent memory problems
  37. \OC_Util::obEnd();
  38. $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory(
  39. \OC::$server->getConfig(),
  40. \OC::$server->getLogger(),
  41. \OC::$server->getDatabaseConnection(),
  42. \OC::$server->getUserSession(),
  43. \OC::$server->getMountManager(),
  44. \OC::$server->getTagManager(),
  45. \OC::$server->getRequest(),
  46. \OC::$server->getPreviewManager(),
  47. \OC::$server->getEventDispatcher(),
  48. \OC::$server->getL10N('dav')
  49. );
  50. // Backends
  51. $authBackend = new \OCA\DAV\Connector\Sabre\Auth(
  52. \OC::$server->getSession(),
  53. \OC::$server->getUserSession(),
  54. \OC::$server->getRequest(),
  55. \OC::$server->getTwoFactorAuthManager(),
  56. \OC::$server->getBruteForceThrottler(),
  57. 'principals/'
  58. );
  59. $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
  60. $bearerAuthPlugin = new \OCA\DAV\Connector\Sabre\BearerAuth(
  61. \OC::$server->getUserSession(),
  62. \OC::$server->getSession(),
  63. \OC::$server->getRequest()
  64. );
  65. $authPlugin->addBackend($bearerAuthPlugin);
  66. $requestUri = \OC::$server->getRequest()->getRequestUri();
  67. $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function () {
  68. // use the view for the logged in user
  69. return \OC\Files\Filesystem::getView();
  70. });
  71. $dispatcher = \OC::$server->getEventDispatcher();
  72. // allow setup of additional plugins
  73. $event = new \OCP\SabrePluginEvent($server);
  74. $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
  75. // And off we go!
  76. $server->exec();