1
0

publicwebdav.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. $owner = $share['uid_owner'];
  52. $isWritable = $share['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE);
  53. $fileId = $share['file_source'];
  54. if (!$isWritable) {
  55. \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
  56. return new \OCA\Files_Sharing\ReadOnlyWrapper(array('storage' => $storage));
  57. });
  58. }
  59. OC_Util::setupFS($owner);
  60. $ownerView = \OC\Files\Filesystem::getView();
  61. $path = $ownerView->getPath($fileId);
  62. $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
  63. $rootInfo = $view->getFileInfo('');
  64. // Create ownCloud Dir
  65. if ($rootInfo->getType() === 'dir') {
  66. $root = new \OC\Connector\Sabre\Directory($view, $rootInfo);
  67. } else {
  68. $root = new \OC\Connector\Sabre\File($view, $rootInfo);
  69. }
  70. $mountManager = \OC\Files\Filesystem::getMountManager();
  71. $objectTree->init($root, $view, $mountManager);
  72. $server->addPlugin(new \OC\Connector\Sabre\QuotaPlugin($view));
  73. }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request
  74. // And off we go!
  75. $server->exec();