publicwebdav.php 3.4 KB

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