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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
  42. $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory(
  43. \OC::$server->getConfig(),
  44. \OC::$server->getLogger(),
  45. \OC::$server->getDatabaseConnection(),
  46. \OC::$server->getUserSession(),
  47. \OC::$server->getMountManager(),
  48. \OC::$server->getTagManager(),
  49. \OC::$server->getRequest(),
  50. \OC::$server->getPreviewManager()
  51. );
  52. $requestUri = \OC::$server->getRequest()->getRequestUri();
  53. $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin();
  54. $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin();
  55. $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) {
  56. $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
  57. $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
  58. $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider();
  59. if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
  60. // this is what is thrown when trying to access a non-existing share
  61. throw new \Sabre\DAV\Exception\NotAuthenticated();
  62. }
  63. $share = $authBackend->getShare();
  64. $owner = $share->getShareOwner();
  65. $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ;
  66. $fileId = $share->getNodeId();
  67. // FIXME: should not add storage wrappers outside of preSetup, need to find a better way
  68. $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
  69. \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) {
  70. return new \OC\Files\Storage\Wrapper\PermissionsMask(array('storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE));
  71. });
  72. \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
  73. OC_Util::tearDownFS();
  74. OC_Util::setupFS($owner);
  75. $ownerView = new \OC\Files\View('/'. $owner . '/files');
  76. $path = $ownerView->getPath($fileId);
  77. $fileInfo = $ownerView->getFileInfo($path);
  78. $linkCheckPlugin->setFileInfo($fileInfo);
  79. // If not readble (files_drop) enable the filesdrop plugin
  80. if (!$isReadable) {
  81. $filesDropPlugin->enable();
  82. }
  83. $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
  84. $filesDropPlugin->setView($view);
  85. return $view;
  86. });
  87. $server->addPlugin($linkCheckPlugin);
  88. $server->addPlugin($filesDropPlugin);
  89. // And off we go!
  90. $server->exec();