This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @author Björn Schießle <[email protected]> |
||
4 | * @author Joas Schilling <[email protected]> |
||
5 | * @author Lukas Reschke <[email protected]> |
||
6 | * @author Morris Jobke <[email protected]> |
||
7 | * @author Robin Appelman <[email protected]> |
||
8 | * |
||
9 | * @copyright Copyright (c) 2018, ownCloud GmbH |
||
10 | * @license AGPL-3.0 |
||
11 | * |
||
12 | * This code is free software: you can redistribute it and/or modify |
||
13 | * it under the terms of the GNU Affero General Public License, version 3, |
||
14 | * as published by the Free Software Foundation. |
||
15 | * |
||
16 | * This program is distributed in the hope that it will be useful, |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
19 | * GNU Affero General Public License for more details. |
||
20 | * |
||
21 | * You should have received a copy of the GNU Affero General Public License, version 3, |
||
22 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
||
23 | * |
||
24 | */ |
||
25 | |||
26 | namespace OCA\Files_Sharing; |
||
27 | |||
28 | use OC\Files\Filesystem; |
||
29 | use OCA\FederatedFileSharing\DiscoveryManager; |
||
30 | use OCP\IURLGenerator; |
||
31 | use OCP\Files\IRootFolder; |
||
32 | use Symfony\Component\EventDispatcher\EventDispatcher; |
||
33 | use OCP\Share\IShare; |
||
34 | use Symfony\Component\EventDispatcher\GenericEvent; |
||
35 | use OCA\Files_Sharing\Service\NotificationPublisher; |
||
36 | use OCP\Share\Exceptions\ShareNotFound; |
||
37 | |||
38 | class Hooks { |
||
39 | /** |
||
40 | * @var IURLGenerator |
||
41 | */ |
||
42 | private $urlGenerator; |
||
43 | |||
44 | /** |
||
45 | * @var IRootFolder |
||
46 | */ |
||
47 | private $rootFolder; |
||
48 | |||
49 | /** |
||
50 | * @var EventDispatcher |
||
51 | */ |
||
52 | private $eventDispatcher; |
||
53 | |||
54 | /** |
||
55 | * @var \OCP\Share\IManager |
||
56 | */ |
||
57 | private $shareManager; |
||
58 | |||
59 | /** |
||
60 | * @var NotificationPublisher |
||
61 | */ |
||
62 | private $notificationPublisher; |
||
63 | |||
64 | public function __construct( |
||
65 | IRootFolder $rootFolder, |
||
66 | IUrlGenerator $urlGenerator, |
||
67 | EventDispatcher $eventDispatcher, |
||
68 | \OCP\Share\IManager $shareManager, |
||
69 | NotificationPublisher $notificationPublisher |
||
70 | ) { |
||
71 | $this->rootFolder = $rootFolder; |
||
72 | $this->urlGenerator = $urlGenerator; |
||
73 | $this->eventDispatcher = $eventDispatcher; |
||
74 | $this->shareManager = $shareManager; |
||
75 | $this->notificationPublisher = $notificationPublisher; |
||
76 | } |
||
77 | |||
78 | public static function deleteUser($params) { |
||
79 | $discoveryManager = new DiscoveryManager( |
||
80 | \OC::$server->getMemCacheFactory(), |
||
81 | \OC::$server->getHTTPClientService() |
||
82 | ); |
||
83 | $manager = new External\Manager( |
||
84 | \OC::$server->getDatabaseConnection(), |
||
85 | \OC\Files\Filesystem::getMountManager(), |
||
86 | \OC\Files\Filesystem::getLoader(), |
||
87 | \OC::$server->getNotificationManager(), |
||
88 | \OC::$server->getEventDispatcher(), |
||
89 | $params['uid']); |
||
90 | |||
91 | $manager->removeUserShares($params['uid']); |
||
92 | } |
||
93 | |||
94 | public static function unshareChildren($params) { |
||
95 | $path = Filesystem::getView()->getAbsolutePath($params['path']); |
||
96 | $view = new \OC\Files\View('/'); |
||
97 | |||
98 | // find share mount points within $path and unmount them |
||
99 | $mountManager = \OC\Files\Filesystem::getMountManager(); |
||
100 | $mountedShares = $mountManager->findIn($path); |
||
101 | foreach ($mountedShares as $mount) { |
||
102 | if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
||
103 | $mountPoint = $mount->getMountPoint(); |
||
104 | $view->unlink($mountPoint); |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | |||
109 | public function registerListeners() { |
||
110 | $this->eventDispatcher->addListener( |
||
111 | 'files.resolvePrivateLink', |
||
112 | View Code Duplication | function (GenericEvent $event) { |
|
0 ignored issues
–
show
|
|||
113 | $uid = $event->getArgument('uid'); |
||
114 | $fileId = $event->getArgument('fileid'); |
||
115 | |||
116 | $link = $this->resolvePrivateLink($uid, $fileId); |
||
117 | |||
118 | if ($link !== null) { |
||
119 | $event->setArgument('resolvedWebLink', $link); |
||
120 | } |
||
121 | } |
||
122 | ); |
||
123 | |||
124 | $this->eventDispatcher->addListener( |
||
125 | 'share.afterCreate', |
||
126 | function (GenericEvent $event) { |
||
127 | $shareObject = $event->getArgument('shareObject'); |
||
128 | $this->notificationPublisher->sendNotification($shareObject); |
||
129 | } |
||
130 | ); |
||
131 | |||
132 | $this->eventDispatcher->addListener( |
||
133 | 'share.afterDelete', |
||
134 | function (GenericEvent $event) { |
||
135 | $shareObject = $event->getArgument('shareObject'); |
||
136 | $this->notificationPublisher->discardNotification($shareObject); |
||
137 | } |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | private function filterSharesByFileId($shares, $fileId) { |
||
142 | return \array_filter($shares, function (IShare $share) use ($fileId) { |
||
143 | return \strval($share->getNodeId()) === \strval($fileId); |
||
144 | }); |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * Resolves web URL that points to the "shared with you" view of the given file |
||
149 | * |
||
150 | * @param string $uid user id |
||
151 | * @param string $fileId file id |
||
152 | * @return string|null view URL or null if the file is not found or not accessible |
||
153 | */ |
||
154 | private function resolvePrivateLink($uid, $fileId) { |
||
155 | // this is only here to verify that there is indeed such share |
||
156 | $shares = $this->filterSharesByFileId($this->shareManager->getSharedWith($uid, \OCP\Share::SHARE_TYPE_USER), $fileId); |
||
157 | if (empty($shares)) { |
||
158 | $shares = $this->filterSharesByFileId($this->shareManager->getSharedWith($uid, \OCP\Share::SHARE_TYPE_GROUP), $fileId); |
||
159 | } |
||
160 | |||
161 | // if share exists, redirect to view |
||
162 | if (!empty($shares)) { |
||
163 | $params['view'] = 'sharingin'; |
||
164 | // scroll to the entry |
||
165 | $params['scrollto'] = $fileId; |
||
166 | return $this->urlGenerator->linkToRoute('files.view.index', $params); |
||
167 | } |
||
168 | |||
169 | return null; |
||
170 | } |
||
171 | } |
||
172 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.