You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

publicwebdav.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <robin@icewind.nl>
  13. * @author Roeland Jago Douma <roeland@famdouma.nl>
  14. * @author Thomas Müller <thomas.mueller@tmit.eu>
  15. * @author Vincent Petry <vincent@nextcloud.com>
  16. *
  17. * @license AGPL-3.0
  18. *
  19. * This code is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU Affero General Public License, version 3,
  21. * as published by the Free Software Foundation.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License, version 3,
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>
  30. *
  31. */
  32. // load needed apps
  33. $RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging'];
  34. OC_App::loadApps($RUNTIME_APPTYPES);
  35. OC_Util::obEnd();
  36. \OC::$server->getSession()->close();
  37. // Backends
  38. $authBackend = new OCA\DAV\Connector\PublicAuth(
  39. \OC::$server->getRequest(),
  40. \OC::$server->getShareManager(),
  41. \OC::$server->getSession()
  42. );
  43. $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
  44. $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory(
  45. \OC::$server->getConfig(),
  46. \OC::$server->getLogger(),
  47. \OC::$server->getDatabaseConnection(),
  48. \OC::$server->getUserSession(),
  49. \OC::$server->getMountManager(),
  50. \OC::$server->getTagManager(),
  51. \OC::$server->getRequest(),
  52. \OC::$server->getPreviewManager(),
  53. \OC::$server->getEventDispatcher(),
  54. \OC::$server->getL10N('dav')
  55. );
  56. $requestUri = \OC::$server->getRequest()->getRequestUri();
  57. $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin();
  58. $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin();
  59. $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) {
  60. $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
  61. /** @var \OCA\FederatedFileSharing\FederatedShareProvider $shareProvider */
  62. $federatedShareProvider = \OC::$server->query(\OCA\FederatedFileSharing\FederatedShareProvider::class);
  63. if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
  64. // this is what is thrown when trying to access a non-existing share
  65. throw new \Sabre\DAV\Exception\NotAuthenticated();
  66. }
  67. $share = $authBackend->getShare();
  68. $owner = $share->getShareOwner();
  69. $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ;
  70. $fileId = $share->getNodeId();
  71. // FIXME: should not add storage wrappers outside of preSetup, need to find a better way
  72. $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
  73. \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
  74. return new \OC\Files\Storage\Wrapper\PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE]);
  75. });
  76. \OC\Files\Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) {
  77. return new \OCA\DAV\Storage\PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]);
  78. });
  79. \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
  80. OC_Util::tearDownFS();
  81. OC_Util::setupFS($owner);
  82. $ownerView = new \OC\Files\View('/'. $owner . '/files');
  83. $path = $ownerView->getPath($fileId);
  84. $fileInfo = $ownerView->getFileInfo($path);
  85. $linkCheckPlugin->setFileInfo($fileInfo);
  86. // If not readble (files_drop) enable the filesdrop plugin
  87. if (!$isReadable) {
  88. $filesDropPlugin->enable();
  89. }
  90. $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
  91. $filesDropPlugin->setView($view);
  92. return $view;
  93. });
  94. $server->addPlugin($linkCheckPlugin);
  95. $server->addPlugin($filesDropPlugin);
  96. // And off we go!
  97. $server->exec();