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.0KB

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