publicwebdav.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) {
  9. return false;
  10. }
  11. // load needed apps
  12. $RUNTIME_APPTYPES = array('filesystem', 'authentication', 'logging');
  13. OC_App::loadApps($RUNTIME_APPTYPES);
  14. OC_Util::obEnd();
  15. // Backends
  16. $authBackend = new OCA\Files_Sharing\Connector\PublicAuth(\OC::$server->getConfig());
  17. $lockBackend = new OC_Connector_Sabre_Locks();
  18. $requestBackend = new OC_Connector_Sabre_Request();
  19. // Fire up server
  20. $objectTree = new \OC\Connector\Sabre\ObjectTree();
  21. $server = new OC_Connector_Sabre_Server($objectTree);
  22. $server->httpRequest = $requestBackend;
  23. $server->setBaseUri($baseuri);
  24. // Load plugins
  25. $defaults = new OC_Defaults();
  26. $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $defaults->getName()));
  27. $server->addPlugin(new \Sabre\DAV\Locks\Plugin($lockBackend));
  28. $server->addPlugin(new \Sabre\DAV\Browser\Plugin(false)); // Show something in the Browser, but no upload
  29. $server->addPlugin(new OC_Connector_Sabre_FilesPlugin());
  30. $server->addPlugin(new OC_Connector_Sabre_MaintenancePlugin());
  31. $server->addPlugin(new OC_Connector_Sabre_ExceptionLoggerPlugin('webdav'));
  32. // wait with registering these until auth is handled and the filesystem is setup
  33. $server->subscribeEvent('beforeMethod', function () use ($server, $objectTree, $authBackend) {
  34. $share = $authBackend->getShare();
  35. $owner = $share['uid_owner'];
  36. $isWritable = $share['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE);
  37. $fileId = $share['file_source'];
  38. if (!$isWritable) {
  39. \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
  40. return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
  41. });
  42. }
  43. OC_Util::setupFS($owner);
  44. $ownerView = \OC\Files\Filesystem::getView();
  45. $path = $ownerView->getPath($fileId);
  46. $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
  47. $rootInfo = $view->getFileInfo('');
  48. // Create ownCloud Dir
  49. if ($rootInfo->getType() === 'dir') {
  50. $root = new OC_Connector_Sabre_Directory($view, $rootInfo);
  51. } else {
  52. $root = new OC_Connector_Sabre_File($view, $rootInfo);
  53. }
  54. $mountManager = \OC\Files\Filesystem::getMountManager();
  55. $objectTree->init($root, $view, $mountManager);
  56. $server->addPlugin(new OC_Connector_Sabre_QuotaPlugin($view));
  57. }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
  58. // And off we go!
  59. $server->exec();