publicwebdav.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. * @author Robin Appelman <icewind@owncloud.com>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. * @author Vincent Petry <pvince81@owncloud.com>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. // load needed apps
  26. $RUNTIME_APPTYPES = array('filesystem', 'authentication', 'logging');
  27. OC_App::loadApps($RUNTIME_APPTYPES);
  28. OC_Util::obEnd();
  29. // Backends
  30. $authBackend = new OCA\Files_Sharing\Connector\PublicAuth(\OC::$server->getConfig());
  31. // Fire up server
  32. $objectTree = new \OC\Connector\Sabre\ObjectTree();
  33. $server = new \OC\Connector\Sabre\Server($objectTree);
  34. // Set URL explicitly due to reverse-proxy situations
  35. $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri());
  36. $server->setBaseUri($baseuri);
  37. // Load plugins
  38. $defaults = new OC_Defaults();
  39. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $defaults->getName()));
  40. // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to /
  41. $server->addPlugin(new \OC\Connector\Sabre\DummyGetResponsePlugin());
  42. $server->addPlugin(new \OC\Connector\Sabre\FilesPlugin($objectTree));
  43. $server->addPlugin(new \OC\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
  44. $server->addPlugin(new \OC\Connector\Sabre\ExceptionLoggerPlugin('webdav', \OC::$server->getLogger()));
  45. // wait with registering these until auth is handled and the filesystem is setup
  46. $server->on('beforeMethod', function () use ($server, $objectTree, $authBackend) {
  47. if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) {
  48. // this is what is thrown when trying to access a non-existing share
  49. throw new \Sabre\DAV\Exception\NotAuthenticated();
  50. }
  51. $share = $authBackend->getShare();
  52. $rootShare = \OCP\Share::resolveReShare($share);
  53. $owner = $rootShare['uid_owner'];
  54. $isWritable = $share['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE);
  55. $fileId = $share['file_source'];
  56. if (!$isWritable) {
  57. \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
  58. return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
  59. });
  60. }
  61. OC_Util::setupFS($owner);
  62. $ownerView = \OC\Files\Filesystem::getView();
  63. $path = $ownerView->getPath($fileId);
  64. $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
  65. $rootInfo = $view->getFileInfo('');
  66. // Create ownCloud Dir
  67. if ($rootInfo->getType() === 'dir') {
  68. $root = new \OC\Connector\Sabre\Directory($view, $rootInfo);
  69. } else {
  70. $root = new \OC\Connector\Sabre\File($view, $rootInfo);
  71. }
  72. $mountManager = \OC\Files\Filesystem::getMountManager();
  73. $objectTree->init($root, $view, $mountManager);
  74. $server->addPlugin(new \OC\Connector\Sabre\QuotaPlugin($view));
  75. }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
  76. // And off we go!
  77. $server->exec();