1
0

publicwebdav.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin();
  54. $server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) {
  55. $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
  56. $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application();
  57. $federatedShareProvider = $federatedSharingApp->getFederatedShareProvider();
  58. if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
  59. // this is what is thrown when trying to access a non-existing share
  60. throw new \Sabre\DAV\Exception\NotAuthenticated();
  61. }
  62. $share = $authBackend->getShare();
  63. $owner = $share->getShareOwner();
  64. $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ;
  65. $fileId = $share->getNodeId();
  66. // FIXME: should not add storage wrappers outside of preSetup, need to find a better way
  67. $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false);
  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\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog);
  72. OC_Util::setupFS($owner);
  73. $ownerView = \OC\Files\Filesystem::getView();
  74. $path = $ownerView->getPath($fileId);
  75. $fileInfo = $ownerView->getFileInfo($path);
  76. $linkCheckPlugin->setFileInfo($fileInfo);
  77. // If not readble (files_drop) enable the filesdrop plugin
  78. if (!$isReadable) {
  79. $filesDropPlugin->enable();
  80. }
  81. $view = new \OC\Files\View($ownerView->getAbsolutePath($path));
  82. $filesDropPlugin->setView($view);
  83. return $view;
  84. });
  85. $server->addPlugin($linkCheckPlugin);
  86. $server->addPlugin($filesDropPlugin);
  87. // And off we go!
  88. $server->exec();