publicwebdav.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. $serverFactory = new \OC\Connector\Sabre\ServerFactory(
  32. \OC::$server->getConfig(),
  33. \OC::$server->getLogger(),
  34. \OC::$server->getDatabaseConnection(),
  35. \OC::$server->getUserSession(),
  36. \OC::$server->getMountManager(),
  37. \OC::$server->getTagManager()
  38. );
  39. $requestUri = \OC::$server->getRequest()->getRequestUri();
  40. $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function () use ($authBackend) {
  41. if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false) {
  42. // this is what is thrown when trying to access a non-existing share
  43. throw new \Sabre\DAV\Exception\NotAuthenticated();
  44. }
  45. $share = $authBackend->getShare();
  46. $rootShare = \OCP\Share::resolveReShare($share);
  47. $owner = $rootShare['uid_owner'];
  48. $isWritable = $share['permissions'] & (\OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_CREATE);
  49. $fileId = $share['file_source'];
  50. if (!$isWritable) {
  51. \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, $storage) {
  52. return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => \OCP\Constants::PERMISSION_READ + \OCP\Constants::PERMISSION_SHARE));
  53. });
  54. }
  55. OC_Util::setupFS($owner);
  56. $ownerView = \OC\Files\Filesystem::getView();
  57. $path = $ownerView->getPath($fileId);
  58. return new \OC\Files\View($ownerView->getAbsolutePath($path));
  59. });
  60. // And off we go!
  61. $server->exec();