publicwebdav.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Lukas Reschke <lukas@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) 2016, 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. // load needed apps
  27. $RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging'];
  28. OC_App::loadApps($RUNTIME_APPTYPES);
  29. OC_Util::obEnd();
  30. // Backends
  31. $authBackend = new OCA\DAV\Connector\PublicAuth(\OC::$server->getConfig());
  32. $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory(
  33. \OC::$server->getConfig(),
  34. \OC::$server->getLogger(),
  35. \OC::$server->getDatabaseConnection(),
  36. \OC::$server->getUserSession(),
  37. \OC::$server->getMountManager(),
  38. \OC::$server->getTagManager(),
  39. \OC::$server->getRequest()
  40. );
  41. $requestUri = \OC::$server->getRequest()->getRequestUri();
  42. $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin();
  43. $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin) {
  44. $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
  45. if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
  46. // this is what is thrown when trying to access a non-existing share
  47. throw new \Sabre\DAV\Exception\NotAuthenticated();
  48. }
  49. $share = $authBackend->getShare();
  50. $rootShare = \OCP\Share::resolveReShare($share);
  51. $owner = $rootShare['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 \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => \OCP\Constants::PERMISSION_READ + \OCP\Constants::PERMISSION_SHARE));
  57. });
  58. }
  59. OC_Util::setupFS($owner);
  60. $ownerView = \OC\Files\Filesystem::getView();
  61. $path = $ownerView->getPath($fileId);
  62. $fileInfo = $ownerView->getFileInfo($path);
  63. $linkCheckPlugin->setFileInfo($fileInfo);
  64. return new \OC\Files\View($ownerView->getAbsolutePath($path));
  65. });
  66. $server->addPlugin($linkCheckPlugin);
  67. // And off we go!
  68. $server->exec();