1 | <?php |
||
2 | /** |
||
3 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
||
4 | * |
||
5 | * @author Bjoern Schiessle <[email protected]> |
||
6 | * @author Björn Schießle <[email protected]> |
||
7 | * @author Christoph Wurst <[email protected]> |
||
8 | * @author Joas Schilling <[email protected]> |
||
9 | * @author Julius Härtl <[email protected]> |
||
10 | * @author Lukas Reschke <[email protected]> |
||
11 | * @author Morris Jobke <[email protected]> |
||
12 | * @author Robin Appelman <[email protected]> |
||
13 | * @author Roeland Jago Douma <[email protected]> |
||
14 | * @author Thomas Müller <[email protected]> |
||
15 | * @author Vincent Petry <[email protected]> |
||
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 | |||
33 | use OCP\BeforeSabrePubliclyLoadedEvent; |
||
34 | use OCP\EventDispatcher\IEventDispatcher; |
||
35 | use Psr\Log\LoggerInterface; |
||
36 | |||
37 | // load needed apps |
||
38 | $RUNTIME_APPTYPES = ['filesystem', 'authentication', 'logging']; |
||
39 | |||
40 | OC_App::loadApps($RUNTIME_APPTYPES); |
||
41 | |||
42 | OC_Util::obEnd(); |
||
43 | \OC::$server->getSession()->close(); |
||
44 | |||
45 | // Backends |
||
46 | $authBackend = new OCA\DAV\Connector\PublicAuth( |
||
47 | \OC::$server->getRequest(), |
||
48 | \OC::$server->getShareManager(), |
||
49 | \OC::$server->getSession(), |
||
50 | \OC::$server->getBruteForceThrottler() |
||
51 | ); |
||
52 | $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); |
||
53 | |||
54 | $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( |
||
55 | \OC::$server->getConfig(), |
||
56 | \OC::$server->get(LoggerInterface::class), |
||
57 | \OC::$server->getDatabaseConnection(), |
||
58 | \OC::$server->getUserSession(), |
||
59 | \OC::$server->getMountManager(), |
||
60 | \OC::$server->getTagManager(), |
||
61 | \OC::$server->getRequest(), |
||
62 | \OC::$server->getPreviewManager(), |
||
63 | \OC::$server->getEventDispatcher(), |
||
64 | \OC::$server->getL10N('dav') |
||
65 | ); |
||
66 | |||
67 | $requestUri = \OC::$server->getRequest()->getRequestUri(); |
||
68 | |||
69 | $linkCheckPlugin = new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin(); |
||
70 | $filesDropPlugin = new \OCA\DAV\Files\Sharing\FilesDropPlugin(); |
||
71 | |||
72 | $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, function (\Sabre\DAV\Server $server) use ($authBackend, $linkCheckPlugin, $filesDropPlugin) { |
||
73 | $isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'); |
||
74 | /** @var \OCA\FederatedFileSharing\FederatedShareProvider $shareProvider */ |
||
75 | $federatedShareProvider = \OC::$server->query(\OCA\FederatedFileSharing\FederatedShareProvider::class); |
||
76 | if ($federatedShareProvider->isOutgoingServer2serverShareEnabled() === false && !$isAjax) { |
||
77 | // this is what is thrown when trying to access a non-existing share |
||
78 | throw new \Sabre\DAV\Exception\NotAuthenticated(); |
||
79 | } |
||
80 | |||
81 | $share = $authBackend->getShare(); |
||
82 | $owner = $share->getShareOwner(); |
||
83 | $isReadable = $share->getPermissions() & \OCP\Constants::PERMISSION_READ; |
||
84 | $fileId = $share->getNodeId(); |
||
85 | |||
86 | // FIXME: should not add storage wrappers outside of preSetup, need to find a better way |
||
87 | $previousLog = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
||
88 | \OC\Files\Filesystem::addStorageWrapper('sharePermissions', function ($mountPoint, $storage) use ($share) { |
||
89 | return new \OC\Files\Storage\Wrapper\PermissionsMask(['storage' => $storage, 'mask' => $share->getPermissions() | \OCP\Constants::PERMISSION_SHARE]); |
||
90 | }); |
||
91 | \OC\Files\Filesystem::addStorageWrapper('shareOwner', function ($mountPoint, $storage) use ($share) { |
||
92 | return new \OCA\DAV\Storage\PublicOwnerWrapper(['storage' => $storage, 'owner' => $share->getShareOwner()]); |
||
93 | }); |
||
94 | \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($previousLog); |
||
95 | |||
96 | OC_Util::tearDownFS(); |
||
97 | OC_Util::setupFS($owner); |
||
98 | $ownerView = new \OC\Files\View('/'. $owner . '/files'); |
||
99 | $path = $ownerView->getPath($fileId); |
||
100 | $fileInfo = $ownerView->getFileInfo($path); |
||
101 | $linkCheckPlugin->setFileInfo($fileInfo); |
||
102 | |||
103 | // If not readable (files_drop) enable the filesdrop plugin |
||
104 | if (!$isReadable) { |
||
105 | $filesDropPlugin->enable(); |
||
106 | } |
||
107 | |||
108 | $view = new \OC\Files\View($ownerView->getAbsolutePath($path)); |
||
109 | $filesDropPlugin->setView($view); |
||
110 | |||
111 | return $view; |
||
112 | }); |
||
113 | |||
114 | $server->addPlugin($linkCheckPlugin); |
||
115 | $server->addPlugin($filesDropPlugin); |
||
116 | // allow setup of additional plugins |
||
117 | $event = new BeforeSabrePubliclyLoadedEvent($server); |
||
118 | /** @var IEventDispatcher $eventDispatcher */ |
||
119 | $eventDispatcher = \OC::$server->get(IEventDispatcher::class); |
||
120 | $eventDispatcher->dispatchTyped($event); |
||
121 | |||
122 | // And off we go! |
||
123 | $server->exec(); |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
124 |