publicwebdav.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Vincent Petry <pvince81@owncloud.com>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. // load needed apps
  31. $RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging'];
  32. OC_App::loadApps($RUNTIME_APPTYPES);
  33. OC_Util::obEnd();
  34. \OC::$server->getSession()->close();
  35. // Backends
  36. $authBackend = new OCA\DAV\Connector\PublicAuth(
  37. \OC::$server->getRequest(),
  38. \OC::$server->getShareManager(),
  39. \OC::$server->getSession()
  40. );
  41. $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory(
  42. \OC::$server->getConfig(),
  43. \OC::$server->getLogger(),
  44. \OC::$server->getDatabaseConnection(),
  45. \OC::$server->getUserSession(),
  46. \OC::$server->getMountManager(),
  47. \OC::$server->getTagManager(),
  48. \OC::$server->getRequest(),
  49. \OC::$server->getPreviewManager()
  50. );
  51. $requestUri = \OC::$server->getRequest()->getRequestUri();
  52. $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin();
  53. $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin) {
  54. $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
  55. $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
  56. $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider();
  57. if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
  58. // this is what is thrown when trying to access a non-existing share
  59. throw new \Sabre\DAV\Exception\NotAuthenticated();
  60. }
  61. $share = $authBackend->getShare();
  62. $owner = $share->getShareOwner();
  63. $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ;
  64. $fileId = $share->getNodeId();
  65. if (!$isReadable) {
  66. return false;
  67. }
  68. \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
  69. return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE));
  70. });
  71. OC_Util::setupFS($owner);
  72. $ownerView = \OC\Files\Filesystem::getView();
  73. $path = $ownerView->getPath($fileId);
  74. $fileInfo = $ownerView->getFileInfo($path);
  75. $linkCheckPlugin->setFileInfo($fileInfo);
  76. return new \OC\Files\View($ownerView->getAbsolutePath($path));
  77. });
  78. $server->addPlugin($linkCheckPlugin);
  79. // And off we go!
  80. $server->exec();