@@ -36,434 +36,434 @@ |
||
| 36 | 36 | use OCP\Notification\IManager; |
| 37 | 37 | |
| 38 | 38 | class Manager { |
| 39 | - const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - private $uid; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var \OCP\IDBConnection |
|
| 48 | - */ |
|
| 49 | - private $connection; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var \OC\Files\Mount\Manager |
|
| 53 | - */ |
|
| 54 | - private $mountManager; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var \OCP\Files\Storage\IStorageFactory |
|
| 58 | - */ |
|
| 59 | - private $storageLoader; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var IClientService |
|
| 63 | - */ |
|
| 64 | - private $clientService; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var IManager |
|
| 68 | - */ |
|
| 69 | - private $notificationManager; |
|
| 70 | - /** @var DiscoveryManager */ |
|
| 71 | - private $discoveryManager; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param \OCP\IDBConnection $connection |
|
| 75 | - * @param \OC\Files\Mount\Manager $mountManager |
|
| 76 | - * @param \OCP\Files\Storage\IStorageFactory $storageLoader |
|
| 77 | - * @param IClientService $clientService |
|
| 78 | - * @param IManager $notificationManager |
|
| 79 | - * @param DiscoveryManager $discoveryManager |
|
| 80 | - * @param string $uid |
|
| 81 | - */ |
|
| 82 | - public function __construct(\OCP\IDBConnection $connection, |
|
| 83 | - \OC\Files\Mount\Manager $mountManager, |
|
| 84 | - \OCP\Files\Storage\IStorageFactory $storageLoader, |
|
| 85 | - IClientService $clientService, |
|
| 86 | - IManager $notificationManager, |
|
| 87 | - DiscoveryManager $discoveryManager, |
|
| 88 | - $uid) { |
|
| 89 | - $this->connection = $connection; |
|
| 90 | - $this->mountManager = $mountManager; |
|
| 91 | - $this->storageLoader = $storageLoader; |
|
| 92 | - $this->clientService = $clientService; |
|
| 93 | - $this->uid = $uid; |
|
| 94 | - $this->notificationManager = $notificationManager; |
|
| 95 | - $this->discoveryManager = $discoveryManager; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * add new server-to-server share |
|
| 100 | - * |
|
| 101 | - * @param string $remote |
|
| 102 | - * @param string $token |
|
| 103 | - * @param string $password |
|
| 104 | - * @param string $name |
|
| 105 | - * @param string $owner |
|
| 106 | - * @param boolean $accepted |
|
| 107 | - * @param string $user |
|
| 108 | - * @param int $remoteId |
|
| 109 | - * @return Mount|null |
|
| 110 | - */ |
|
| 111 | - public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { |
|
| 112 | - |
|
| 113 | - $user = $user ? $user : $this->uid; |
|
| 114 | - $accepted = $accepted ? 1 : 0; |
|
| 115 | - $name = Filesystem::normalizePath('/' . $name); |
|
| 116 | - |
|
| 117 | - if (!$accepted) { |
|
| 118 | - // To avoid conflicts with the mount point generation later, |
|
| 119 | - // we only use a temporary mount point name here. The real |
|
| 120 | - // mount point name will be generated when accepting the share, |
|
| 121 | - // using the original share item name. |
|
| 122 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
| 123 | - $mountPoint = $tmpMountPointName; |
|
| 124 | - $hash = md5($tmpMountPointName); |
|
| 125 | - $data = [ |
|
| 126 | - 'remote' => $remote, |
|
| 127 | - 'share_token' => $token, |
|
| 128 | - 'password' => $password, |
|
| 129 | - 'name' => $name, |
|
| 130 | - 'owner' => $owner, |
|
| 131 | - 'user' => $user, |
|
| 132 | - 'mountpoint' => $mountPoint, |
|
| 133 | - 'mountpoint_hash' => $hash, |
|
| 134 | - 'accepted' => $accepted, |
|
| 135 | - 'remote_id' => $remoteId, |
|
| 136 | - ]; |
|
| 137 | - |
|
| 138 | - $i = 1; |
|
| 139 | - while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
| 140 | - // The external share already exists for the user |
|
| 141 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
| 142 | - $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
| 143 | - $i++; |
|
| 144 | - } |
|
| 145 | - return null; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
| 149 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 150 | - $hash = md5($mountPoint); |
|
| 151 | - |
|
| 152 | - $query = $this->connection->prepare(' |
|
| 39 | + const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + private $uid; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var \OCP\IDBConnection |
|
| 48 | + */ |
|
| 49 | + private $connection; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var \OC\Files\Mount\Manager |
|
| 53 | + */ |
|
| 54 | + private $mountManager; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var \OCP\Files\Storage\IStorageFactory |
|
| 58 | + */ |
|
| 59 | + private $storageLoader; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var IClientService |
|
| 63 | + */ |
|
| 64 | + private $clientService; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var IManager |
|
| 68 | + */ |
|
| 69 | + private $notificationManager; |
|
| 70 | + /** @var DiscoveryManager */ |
|
| 71 | + private $discoveryManager; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param \OCP\IDBConnection $connection |
|
| 75 | + * @param \OC\Files\Mount\Manager $mountManager |
|
| 76 | + * @param \OCP\Files\Storage\IStorageFactory $storageLoader |
|
| 77 | + * @param IClientService $clientService |
|
| 78 | + * @param IManager $notificationManager |
|
| 79 | + * @param DiscoveryManager $discoveryManager |
|
| 80 | + * @param string $uid |
|
| 81 | + */ |
|
| 82 | + public function __construct(\OCP\IDBConnection $connection, |
|
| 83 | + \OC\Files\Mount\Manager $mountManager, |
|
| 84 | + \OCP\Files\Storage\IStorageFactory $storageLoader, |
|
| 85 | + IClientService $clientService, |
|
| 86 | + IManager $notificationManager, |
|
| 87 | + DiscoveryManager $discoveryManager, |
|
| 88 | + $uid) { |
|
| 89 | + $this->connection = $connection; |
|
| 90 | + $this->mountManager = $mountManager; |
|
| 91 | + $this->storageLoader = $storageLoader; |
|
| 92 | + $this->clientService = $clientService; |
|
| 93 | + $this->uid = $uid; |
|
| 94 | + $this->notificationManager = $notificationManager; |
|
| 95 | + $this->discoveryManager = $discoveryManager; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * add new server-to-server share |
|
| 100 | + * |
|
| 101 | + * @param string $remote |
|
| 102 | + * @param string $token |
|
| 103 | + * @param string $password |
|
| 104 | + * @param string $name |
|
| 105 | + * @param string $owner |
|
| 106 | + * @param boolean $accepted |
|
| 107 | + * @param string $user |
|
| 108 | + * @param int $remoteId |
|
| 109 | + * @return Mount|null |
|
| 110 | + */ |
|
| 111 | + public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { |
|
| 112 | + |
|
| 113 | + $user = $user ? $user : $this->uid; |
|
| 114 | + $accepted = $accepted ? 1 : 0; |
|
| 115 | + $name = Filesystem::normalizePath('/' . $name); |
|
| 116 | + |
|
| 117 | + if (!$accepted) { |
|
| 118 | + // To avoid conflicts with the mount point generation later, |
|
| 119 | + // we only use a temporary mount point name here. The real |
|
| 120 | + // mount point name will be generated when accepting the share, |
|
| 121 | + // using the original share item name. |
|
| 122 | + $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
| 123 | + $mountPoint = $tmpMountPointName; |
|
| 124 | + $hash = md5($tmpMountPointName); |
|
| 125 | + $data = [ |
|
| 126 | + 'remote' => $remote, |
|
| 127 | + 'share_token' => $token, |
|
| 128 | + 'password' => $password, |
|
| 129 | + 'name' => $name, |
|
| 130 | + 'owner' => $owner, |
|
| 131 | + 'user' => $user, |
|
| 132 | + 'mountpoint' => $mountPoint, |
|
| 133 | + 'mountpoint_hash' => $hash, |
|
| 134 | + 'accepted' => $accepted, |
|
| 135 | + 'remote_id' => $remoteId, |
|
| 136 | + ]; |
|
| 137 | + |
|
| 138 | + $i = 1; |
|
| 139 | + while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
| 140 | + // The external share already exists for the user |
|
| 141 | + $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
| 142 | + $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
| 143 | + $i++; |
|
| 144 | + } |
|
| 145 | + return null; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
| 149 | + $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 150 | + $hash = md5($mountPoint); |
|
| 151 | + |
|
| 152 | + $query = $this->connection->prepare(' |
|
| 153 | 153 | INSERT INTO `*PREFIX*share_external` |
| 154 | 154 | (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`) |
| 155 | 155 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| 156 | 156 | '); |
| 157 | - $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId)); |
|
| 158 | - |
|
| 159 | - $options = array( |
|
| 160 | - 'remote' => $remote, |
|
| 161 | - 'token' => $token, |
|
| 162 | - 'password' => $password, |
|
| 163 | - 'mountpoint' => $mountPoint, |
|
| 164 | - 'owner' => $owner |
|
| 165 | - ); |
|
| 166 | - return $this->mountShare($options); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * get share |
|
| 171 | - * |
|
| 172 | - * @param int $id share id |
|
| 173 | - * @return mixed share of false |
|
| 174 | - */ |
|
| 175 | - public function getShare($id) { |
|
| 176 | - $getShare = $this->connection->prepare(' |
|
| 157 | + $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId)); |
|
| 158 | + |
|
| 159 | + $options = array( |
|
| 160 | + 'remote' => $remote, |
|
| 161 | + 'token' => $token, |
|
| 162 | + 'password' => $password, |
|
| 163 | + 'mountpoint' => $mountPoint, |
|
| 164 | + 'owner' => $owner |
|
| 165 | + ); |
|
| 166 | + return $this->mountShare($options); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * get share |
|
| 171 | + * |
|
| 172 | + * @param int $id share id |
|
| 173 | + * @return mixed share of false |
|
| 174 | + */ |
|
| 175 | + public function getShare($id) { |
|
| 176 | + $getShare = $this->connection->prepare(' |
|
| 177 | 177 | SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
| 178 | 178 | FROM `*PREFIX*share_external` |
| 179 | 179 | WHERE `id` = ? AND `user` = ?'); |
| 180 | - $result = $getShare->execute(array($id, $this->uid)); |
|
| 180 | + $result = $getShare->execute(array($id, $this->uid)); |
|
| 181 | 181 | |
| 182 | - return $result ? $getShare->fetch() : false; |
|
| 183 | - } |
|
| 182 | + return $result ? $getShare->fetch() : false; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * accept server-to-server share |
|
| 187 | - * |
|
| 188 | - * @param int $id |
|
| 189 | - * @return bool True if the share could be accepted, false otherwise |
|
| 190 | - */ |
|
| 191 | - public function acceptShare($id) { |
|
| 185 | + /** |
|
| 186 | + * accept server-to-server share |
|
| 187 | + * |
|
| 188 | + * @param int $id |
|
| 189 | + * @return bool True if the share could be accepted, false otherwise |
|
| 190 | + */ |
|
| 191 | + public function acceptShare($id) { |
|
| 192 | 192 | |
| 193 | - $share = $this->getShare($id); |
|
| 193 | + $share = $this->getShare($id); |
|
| 194 | 194 | |
| 195 | - if ($share) { |
|
| 196 | - $mountPoint = Files::buildNotExistingFileName('/', $share['name']); |
|
| 197 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 198 | - $hash = md5($mountPoint); |
|
| 195 | + if ($share) { |
|
| 196 | + $mountPoint = Files::buildNotExistingFileName('/', $share['name']); |
|
| 197 | + $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 198 | + $hash = md5($mountPoint); |
|
| 199 | 199 | |
| 200 | - $acceptShare = $this->connection->prepare(' |
|
| 200 | + $acceptShare = $this->connection->prepare(' |
|
| 201 | 201 | UPDATE `*PREFIX*share_external` |
| 202 | 202 | SET `accepted` = ?, |
| 203 | 203 | `mountpoint` = ?, |
| 204 | 204 | `mountpoint_hash` = ? |
| 205 | 205 | WHERE `id` = ? AND `user` = ?'); |
| 206 | - $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
| 207 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
| 206 | + $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
| 207 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
| 208 | 208 | |
| 209 | - \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $share['remote']]); |
|
| 209 | + \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $share['remote']]); |
|
| 210 | 210 | |
| 211 | - $this->processNotification($id); |
|
| 212 | - return true; |
|
| 213 | - } |
|
| 211 | + $this->processNotification($id); |
|
| 212 | + return true; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return false; |
|
| 216 | - } |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * decline server-to-server share |
|
| 220 | - * |
|
| 221 | - * @param int $id |
|
| 222 | - * @return bool True if the share could be declined, false otherwise |
|
| 223 | - */ |
|
| 224 | - public function declineShare($id) { |
|
| 218 | + /** |
|
| 219 | + * decline server-to-server share |
|
| 220 | + * |
|
| 221 | + * @param int $id |
|
| 222 | + * @return bool True if the share could be declined, false otherwise |
|
| 223 | + */ |
|
| 224 | + public function declineShare($id) { |
|
| 225 | 225 | |
| 226 | - $share = $this->getShare($id); |
|
| 226 | + $share = $this->getShare($id); |
|
| 227 | 227 | |
| 228 | - if ($share) { |
|
| 229 | - $removeShare = $this->connection->prepare(' |
|
| 228 | + if ($share) { |
|
| 229 | + $removeShare = $this->connection->prepare(' |
|
| 230 | 230 | DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); |
| 231 | - $removeShare->execute(array($id, $this->uid)); |
|
| 232 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 233 | - |
|
| 234 | - $this->processNotification($id); |
|
| 235 | - return true; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - return false; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @param int $remoteShare |
|
| 243 | - */ |
|
| 244 | - public function processNotification($remoteShare) { |
|
| 245 | - $filter = $this->notificationManager->createNotification(); |
|
| 246 | - $filter->setApp('files_sharing') |
|
| 247 | - ->setUser($this->uid) |
|
| 248 | - ->setObject('remote_share', (int) $remoteShare); |
|
| 249 | - $this->notificationManager->markProcessed($filter); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * inform remote server whether server-to-server share was accepted/declined |
|
| 254 | - * |
|
| 255 | - * @param string $remote |
|
| 256 | - * @param string $token |
|
| 257 | - * @param int $remoteId Share id on the remote host |
|
| 258 | - * @param string $feedback |
|
| 259 | - * @return boolean |
|
| 260 | - */ |
|
| 261 | - private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
| 262 | - |
|
| 263 | - $url = rtrim($remote, '/') . $this->discoveryManager->getShareEndpoint($remote) . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
| 264 | - $fields = array('token' => $token); |
|
| 265 | - |
|
| 266 | - $client = $this->clientService->newClient(); |
|
| 267 | - |
|
| 268 | - try { |
|
| 269 | - $response = $client->post( |
|
| 270 | - $url, |
|
| 271 | - [ |
|
| 272 | - 'body' => $fields, |
|
| 273 | - 'connect_timeout' => 10, |
|
| 274 | - ] |
|
| 275 | - ); |
|
| 276 | - } catch (\Exception $e) { |
|
| 277 | - return false; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - $status = json_decode($response->getBody(), true); |
|
| 281 | - |
|
| 282 | - return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * remove '/user/files' from the path and trailing slashes |
|
| 287 | - * |
|
| 288 | - * @param string $path |
|
| 289 | - * @return string |
|
| 290 | - */ |
|
| 291 | - protected function stripPath($path) { |
|
| 292 | - $prefix = '/' . $this->uid . '/files'; |
|
| 293 | - return rtrim(substr($path, strlen($prefix)), '/'); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - public function getMount($data) { |
|
| 297 | - $data['manager'] = $this; |
|
| 298 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 299 | - $data['mountpoint'] = $mountPoint; |
|
| 300 | - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
| 301 | - return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param array $data |
|
| 306 | - * @return Mount |
|
| 307 | - */ |
|
| 308 | - protected function mountShare($data) { |
|
| 309 | - $mount = $this->getMount($data); |
|
| 310 | - $this->mountManager->addMount($mount); |
|
| 311 | - return $mount; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @return \OC\Files\Mount\Manager |
|
| 316 | - */ |
|
| 317 | - public function getMountManager() { |
|
| 318 | - return $this->mountManager; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * @param string $source |
|
| 323 | - * @param string $target |
|
| 324 | - * @return bool |
|
| 325 | - */ |
|
| 326 | - public function setMountPoint($source, $target) { |
|
| 327 | - $source = $this->stripPath($source); |
|
| 328 | - $target = $this->stripPath($target); |
|
| 329 | - $sourceHash = md5($source); |
|
| 330 | - $targetHash = md5($target); |
|
| 331 | - |
|
| 332 | - $query = $this->connection->prepare(' |
|
| 231 | + $removeShare->execute(array($id, $this->uid)); |
|
| 232 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 233 | + |
|
| 234 | + $this->processNotification($id); |
|
| 235 | + return true; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + return false; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @param int $remoteShare |
|
| 243 | + */ |
|
| 244 | + public function processNotification($remoteShare) { |
|
| 245 | + $filter = $this->notificationManager->createNotification(); |
|
| 246 | + $filter->setApp('files_sharing') |
|
| 247 | + ->setUser($this->uid) |
|
| 248 | + ->setObject('remote_share', (int) $remoteShare); |
|
| 249 | + $this->notificationManager->markProcessed($filter); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * inform remote server whether server-to-server share was accepted/declined |
|
| 254 | + * |
|
| 255 | + * @param string $remote |
|
| 256 | + * @param string $token |
|
| 257 | + * @param int $remoteId Share id on the remote host |
|
| 258 | + * @param string $feedback |
|
| 259 | + * @return boolean |
|
| 260 | + */ |
|
| 261 | + private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
| 262 | + |
|
| 263 | + $url = rtrim($remote, '/') . $this->discoveryManager->getShareEndpoint($remote) . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
| 264 | + $fields = array('token' => $token); |
|
| 265 | + |
|
| 266 | + $client = $this->clientService->newClient(); |
|
| 267 | + |
|
| 268 | + try { |
|
| 269 | + $response = $client->post( |
|
| 270 | + $url, |
|
| 271 | + [ |
|
| 272 | + 'body' => $fields, |
|
| 273 | + 'connect_timeout' => 10, |
|
| 274 | + ] |
|
| 275 | + ); |
|
| 276 | + } catch (\Exception $e) { |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + $status = json_decode($response->getBody(), true); |
|
| 281 | + |
|
| 282 | + return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * remove '/user/files' from the path and trailing slashes |
|
| 287 | + * |
|
| 288 | + * @param string $path |
|
| 289 | + * @return string |
|
| 290 | + */ |
|
| 291 | + protected function stripPath($path) { |
|
| 292 | + $prefix = '/' . $this->uid . '/files'; |
|
| 293 | + return rtrim(substr($path, strlen($prefix)), '/'); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + public function getMount($data) { |
|
| 297 | + $data['manager'] = $this; |
|
| 298 | + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 299 | + $data['mountpoint'] = $mountPoint; |
|
| 300 | + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
| 301 | + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param array $data |
|
| 306 | + * @return Mount |
|
| 307 | + */ |
|
| 308 | + protected function mountShare($data) { |
|
| 309 | + $mount = $this->getMount($data); |
|
| 310 | + $this->mountManager->addMount($mount); |
|
| 311 | + return $mount; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @return \OC\Files\Mount\Manager |
|
| 316 | + */ |
|
| 317 | + public function getMountManager() { |
|
| 318 | + return $this->mountManager; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * @param string $source |
|
| 323 | + * @param string $target |
|
| 324 | + * @return bool |
|
| 325 | + */ |
|
| 326 | + public function setMountPoint($source, $target) { |
|
| 327 | + $source = $this->stripPath($source); |
|
| 328 | + $target = $this->stripPath($target); |
|
| 329 | + $sourceHash = md5($source); |
|
| 330 | + $targetHash = md5($target); |
|
| 331 | + |
|
| 332 | + $query = $this->connection->prepare(' |
|
| 333 | 333 | UPDATE `*PREFIX*share_external` |
| 334 | 334 | SET `mountpoint` = ?, `mountpoint_hash` = ? |
| 335 | 335 | WHERE `mountpoint_hash` = ? |
| 336 | 336 | AND `user` = ? |
| 337 | 337 | '); |
| 338 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
| 338 | + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
| 339 | 339 | |
| 340 | - return $result; |
|
| 341 | - } |
|
| 340 | + return $result; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - public function removeShare($mountPoint) { |
|
| 343 | + public function removeShare($mountPoint) { |
|
| 344 | 344 | |
| 345 | - $mountPointObj = $this->mountManager->find($mountPoint); |
|
| 346 | - $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
| 345 | + $mountPointObj = $this->mountManager->find($mountPoint); |
|
| 346 | + $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
| 347 | 347 | |
| 348 | - $mountPoint = $this->stripPath($mountPoint); |
|
| 349 | - $hash = md5($mountPoint); |
|
| 348 | + $mountPoint = $this->stripPath($mountPoint); |
|
| 349 | + $hash = md5($mountPoint); |
|
| 350 | 350 | |
| 351 | - $getShare = $this->connection->prepare(' |
|
| 351 | + $getShare = $this->connection->prepare(' |
|
| 352 | 352 | SELECT `remote`, `share_token`, `remote_id` |
| 353 | 353 | FROM `*PREFIX*share_external` |
| 354 | 354 | WHERE `mountpoint_hash` = ? AND `user` = ?'); |
| 355 | - $result = $getShare->execute(array($hash, $this->uid)); |
|
| 355 | + $result = $getShare->execute(array($hash, $this->uid)); |
|
| 356 | 356 | |
| 357 | - if ($result) { |
|
| 358 | - $share = $getShare->fetch(); |
|
| 359 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 360 | - } |
|
| 361 | - $getShare->closeCursor(); |
|
| 357 | + if ($result) { |
|
| 358 | + $share = $getShare->fetch(); |
|
| 359 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 360 | + } |
|
| 361 | + $getShare->closeCursor(); |
|
| 362 | 362 | |
| 363 | - $query = $this->connection->prepare(' |
|
| 363 | + $query = $this->connection->prepare(' |
|
| 364 | 364 | DELETE FROM `*PREFIX*share_external` |
| 365 | 365 | WHERE `mountpoint_hash` = ? |
| 366 | 366 | AND `user` = ? |
| 367 | 367 | '); |
| 368 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
| 369 | - |
|
| 370 | - if($result) { |
|
| 371 | - $this->removeReShares($id); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - return $result; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * remove re-shares from share table and mapping in the federated_reshares table |
|
| 379 | - * |
|
| 380 | - * @param $mountPointId |
|
| 381 | - */ |
|
| 382 | - protected function removeReShares($mountPointId) { |
|
| 383 | - $selectQuery = $this->connection->getQueryBuilder(); |
|
| 384 | - $query = $this->connection->getQueryBuilder(); |
|
| 385 | - $selectQuery->select('id')->from('share') |
|
| 386 | - ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
| 387 | - $select = $selectQuery->getSQL(); |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - $query->delete('federated_reshares') |
|
| 391 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 392 | - $query->execute(); |
|
| 393 | - |
|
| 394 | - $deleteReShares = $this->connection->getQueryBuilder(); |
|
| 395 | - $deleteReShares->delete('share') |
|
| 396 | - ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
| 397 | - $deleteReShares->execute(); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * remove all shares for user $uid if the user was deleted |
|
| 402 | - * |
|
| 403 | - * @param string $uid |
|
| 404 | - * @return bool |
|
| 405 | - */ |
|
| 406 | - public function removeUserShares($uid) { |
|
| 407 | - $getShare = $this->connection->prepare(' |
|
| 368 | + $result = (bool)$query->execute(array($hash, $this->uid)); |
|
| 369 | + |
|
| 370 | + if($result) { |
|
| 371 | + $this->removeReShares($id); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + return $result; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * remove re-shares from share table and mapping in the federated_reshares table |
|
| 379 | + * |
|
| 380 | + * @param $mountPointId |
|
| 381 | + */ |
|
| 382 | + protected function removeReShares($mountPointId) { |
|
| 383 | + $selectQuery = $this->connection->getQueryBuilder(); |
|
| 384 | + $query = $this->connection->getQueryBuilder(); |
|
| 385 | + $selectQuery->select('id')->from('share') |
|
| 386 | + ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
| 387 | + $select = $selectQuery->getSQL(); |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + $query->delete('federated_reshares') |
|
| 391 | + ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 392 | + $query->execute(); |
|
| 393 | + |
|
| 394 | + $deleteReShares = $this->connection->getQueryBuilder(); |
|
| 395 | + $deleteReShares->delete('share') |
|
| 396 | + ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
| 397 | + $deleteReShares->execute(); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * remove all shares for user $uid if the user was deleted |
|
| 402 | + * |
|
| 403 | + * @param string $uid |
|
| 404 | + * @return bool |
|
| 405 | + */ |
|
| 406 | + public function removeUserShares($uid) { |
|
| 407 | + $getShare = $this->connection->prepare(' |
|
| 408 | 408 | SELECT `remote`, `share_token`, `remote_id` |
| 409 | 409 | FROM `*PREFIX*share_external` |
| 410 | 410 | WHERE `user` = ?'); |
| 411 | - $result = $getShare->execute(array($uid)); |
|
| 411 | + $result = $getShare->execute(array($uid)); |
|
| 412 | 412 | |
| 413 | - if ($result) { |
|
| 414 | - $shares = $getShare->fetchAll(); |
|
| 415 | - foreach($shares as $share) { |
|
| 416 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 417 | - } |
|
| 418 | - } |
|
| 413 | + if ($result) { |
|
| 414 | + $shares = $getShare->fetchAll(); |
|
| 415 | + foreach($shares as $share) { |
|
| 416 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - $query = $this->connection->prepare(' |
|
| 420 | + $query = $this->connection->prepare(' |
|
| 421 | 421 | DELETE FROM `*PREFIX*share_external` |
| 422 | 422 | WHERE `user` = ? |
| 423 | 423 | '); |
| 424 | - return (bool)$query->execute(array($uid)); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * return a list of shares which are not yet accepted by the user |
|
| 429 | - * |
|
| 430 | - * @return array list of open server-to-server shares |
|
| 431 | - */ |
|
| 432 | - public function getOpenShares() { |
|
| 433 | - return $this->getShares(false); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * return a list of shares which are accepted by the user |
|
| 438 | - * |
|
| 439 | - * @return array list of accepted server-to-server shares |
|
| 440 | - */ |
|
| 441 | - public function getAcceptedShares() { |
|
| 442 | - return $this->getShares(true); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * return a list of shares for the user |
|
| 447 | - * |
|
| 448 | - * @param bool|null $accepted True for accepted only, |
|
| 449 | - * false for not accepted, |
|
| 450 | - * null for all shares of the user |
|
| 451 | - * @return array list of open server-to-server shares |
|
| 452 | - */ |
|
| 453 | - private function getShares($accepted) { |
|
| 454 | - $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
| 424 | + return (bool)$query->execute(array($uid)); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * return a list of shares which are not yet accepted by the user |
|
| 429 | + * |
|
| 430 | + * @return array list of open server-to-server shares |
|
| 431 | + */ |
|
| 432 | + public function getOpenShares() { |
|
| 433 | + return $this->getShares(false); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * return a list of shares which are accepted by the user |
|
| 438 | + * |
|
| 439 | + * @return array list of accepted server-to-server shares |
|
| 440 | + */ |
|
| 441 | + public function getAcceptedShares() { |
|
| 442 | + return $this->getShares(true); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * return a list of shares for the user |
|
| 447 | + * |
|
| 448 | + * @param bool|null $accepted True for accepted only, |
|
| 449 | + * false for not accepted, |
|
| 450 | + * null for all shares of the user |
|
| 451 | + * @return array list of open server-to-server shares |
|
| 452 | + */ |
|
| 453 | + private function getShares($accepted) { |
|
| 454 | + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
| 455 | 455 | FROM `*PREFIX*share_external` |
| 456 | 456 | WHERE `user` = ?'; |
| 457 | - $parameters = [$this->uid]; |
|
| 458 | - if (!is_null($accepted)) { |
|
| 459 | - $query .= ' AND `accepted` = ?'; |
|
| 460 | - $parameters[] = (int) $accepted; |
|
| 461 | - } |
|
| 462 | - $query .= ' ORDER BY `id` ASC'; |
|
| 463 | - |
|
| 464 | - $shares = $this->connection->prepare($query); |
|
| 465 | - $result = $shares->execute($parameters); |
|
| 466 | - |
|
| 467 | - return $result ? $shares->fetchAll() : []; |
|
| 468 | - } |
|
| 457 | + $parameters = [$this->uid]; |
|
| 458 | + if (!is_null($accepted)) { |
|
| 459 | + $query .= ' AND `accepted` = ?'; |
|
| 460 | + $parameters[] = (int) $accepted; |
|
| 461 | + } |
|
| 462 | + $query .= ' ORDER BY `id` ASC'; |
|
| 463 | + |
|
| 464 | + $shares = $this->connection->prepare($query); |
|
| 465 | + $result = $shares->execute($parameters); |
|
| 466 | + |
|
| 467 | + return $result ? $shares->fetchAll() : []; |
|
| 468 | + } |
|
| 469 | 469 | } |
@@ -108,18 +108,18 @@ discard block |
||
| 108 | 108 | * @param int $remoteId |
| 109 | 109 | * @return Mount|null |
| 110 | 110 | */ |
| 111 | - public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { |
|
| 111 | + public function addShare($remote, $token, $password, $name, $owner, $accepted = false, $user = null, $remoteId = -1) { |
|
| 112 | 112 | |
| 113 | 113 | $user = $user ? $user : $this->uid; |
| 114 | 114 | $accepted = $accepted ? 1 : 0; |
| 115 | - $name = Filesystem::normalizePath('/' . $name); |
|
| 115 | + $name = Filesystem::normalizePath('/'.$name); |
|
| 116 | 116 | |
| 117 | 117 | if (!$accepted) { |
| 118 | 118 | // To avoid conflicts with the mount point generation later, |
| 119 | 119 | // we only use a temporary mount point name here. The real |
| 120 | 120 | // mount point name will be generated when accepting the share, |
| 121 | 121 | // using the original share item name. |
| 122 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
| 122 | + $tmpMountPointName = '{{TemporaryMountPointName#'.$name.'}}'; |
|
| 123 | 123 | $mountPoint = $tmpMountPointName; |
| 124 | 124 | $hash = md5($tmpMountPointName); |
| 125 | 125 | $data = [ |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | $i = 1; |
| 139 | 139 | while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
| 140 | 140 | // The external share already exists for the user |
| 141 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
| 141 | + $data['mountpoint'] = $tmpMountPointName.'-'.$i; |
|
| 142 | 142 | $data['mountpoint_hash'] = md5($data['mountpoint']); |
| 143 | 143 | $i++; |
| 144 | 144 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $mountPoint = Files::buildNotExistingFileName('/', $name); |
| 149 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 149 | + $mountPoint = Filesystem::normalizePath('/'.$mountPoint); |
|
| 150 | 150 | $hash = md5($mountPoint); |
| 151 | 151 | |
| 152 | 152 | $query = $this->connection->prepare(' |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | if ($share) { |
| 196 | 196 | $mountPoint = Files::buildNotExistingFileName('/', $share['name']); |
| 197 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 197 | + $mountPoint = Filesystem::normalizePath('/'.$mountPoint); |
|
| 198 | 198 | $hash = md5($mountPoint); |
| 199 | 199 | |
| 200 | 200 | $acceptShare = $this->connection->prepare(' |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
| 262 | 262 | |
| 263 | - $url = rtrim($remote, '/') . $this->discoveryManager->getShareEndpoint($remote) . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
| 263 | + $url = rtrim($remote, '/').$this->discoveryManager->getShareEndpoint($remote).'/'.$remoteId.'/'.$feedback.'?format='.\OCP\Share::RESPONSE_FORMAT; |
|
| 264 | 264 | $fields = array('token' => $token); |
| 265 | 265 | |
| 266 | 266 | $client = $this->clientService->newClient(); |
@@ -289,13 +289,13 @@ discard block |
||
| 289 | 289 | * @return string |
| 290 | 290 | */ |
| 291 | 291 | protected function stripPath($path) { |
| 292 | - $prefix = '/' . $this->uid . '/files'; |
|
| 292 | + $prefix = '/'.$this->uid.'/files'; |
|
| 293 | 293 | return rtrim(substr($path, strlen($prefix)), '/'); |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | public function getMount($data) { |
| 297 | 297 | $data['manager'] = $this; |
| 298 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 298 | + $mountPoint = '/'.$this->uid.'/files'.$data['mountpoint']; |
|
| 299 | 299 | $data['mountpoint'] = $mountPoint; |
| 300 | 300 | $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
| 301 | 301 | return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | WHERE `mountpoint_hash` = ? |
| 336 | 336 | AND `user` = ? |
| 337 | 337 | '); |
| 338 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
| 338 | + $result = (bool) $query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
| 339 | 339 | |
| 340 | 340 | return $result; |
| 341 | 341 | } |
@@ -365,9 +365,9 @@ discard block |
||
| 365 | 365 | WHERE `mountpoint_hash` = ? |
| 366 | 366 | AND `user` = ? |
| 367 | 367 | '); |
| 368 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
| 368 | + $result = (bool) $query->execute(array($hash, $this->uid)); |
|
| 369 | 369 | |
| 370 | - if($result) { |
|
| 370 | + if ($result) { |
|
| 371 | 371 | $this->removeReShares($id); |
| 372 | 372 | } |
| 373 | 373 | |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | |
| 389 | 389 | |
| 390 | 390 | $query->delete('federated_reshares') |
| 391 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 391 | + ->where($query->expr()->in('share_id', $query->createFunction('('.$select.')'))); |
|
| 392 | 392 | $query->execute(); |
| 393 | 393 | |
| 394 | 394 | $deleteReShares = $this->connection->getQueryBuilder(); |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | if ($result) { |
| 414 | 414 | $shares = $getShare->fetchAll(); |
| 415 | - foreach($shares as $share) { |
|
| 415 | + foreach ($shares as $share) { |
|
| 416 | 416 | $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
| 417 | 417 | } |
| 418 | 418 | } |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | DELETE FROM `*PREFIX*share_external` |
| 422 | 422 | WHERE `user` = ? |
| 423 | 423 | '); |
| 424 | - return (bool)$query->execute(array($uid)); |
|
| 424 | + return (bool) $query->execute(array($uid)); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -29,43 +29,43 @@ |
||
| 29 | 29 | |
| 30 | 30 | class Mount extends MountPoint implements MoveableMount { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var \OCA\Files_Sharing\External\Manager |
|
| 34 | - */ |
|
| 35 | - protected $manager; |
|
| 32 | + /** |
|
| 33 | + * @var \OCA\Files_Sharing\External\Manager |
|
| 34 | + */ |
|
| 35 | + protected $manager; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param string|\OC\Files\Storage\Storage $storage |
|
| 39 | - * @param string $mountpoint |
|
| 40 | - * @param array $options |
|
| 41 | - * @param \OCA\Files_Sharing\External\Manager $manager |
|
| 42 | - * @param \OC\Files\Storage\StorageFactory $loader |
|
| 43 | - */ |
|
| 44 | - public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
| 45 | - parent::__construct($storage, $mountpoint, $options, $loader); |
|
| 46 | - $this->manager = $manager; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * @param string|\OC\Files\Storage\Storage $storage |
|
| 39 | + * @param string $mountpoint |
|
| 40 | + * @param array $options |
|
| 41 | + * @param \OCA\Files_Sharing\External\Manager $manager |
|
| 42 | + * @param \OC\Files\Storage\StorageFactory $loader |
|
| 43 | + */ |
|
| 44 | + public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
| 45 | + parent::__construct($storage, $mountpoint, $options, $loader); |
|
| 46 | + $this->manager = $manager; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Move the mount point to $target |
|
| 51 | - * |
|
| 52 | - * @param string $target the target mount point |
|
| 53 | - * @return bool |
|
| 54 | - */ |
|
| 55 | - public function moveMount($target) { |
|
| 56 | - $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
| 57 | - $this->setMountPoint($target); |
|
| 49 | + /** |
|
| 50 | + * Move the mount point to $target |
|
| 51 | + * |
|
| 52 | + * @param string $target the target mount point |
|
| 53 | + * @return bool |
|
| 54 | + */ |
|
| 55 | + public function moveMount($target) { |
|
| 56 | + $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
| 57 | + $this->setMountPoint($target); |
|
| 58 | 58 | |
| 59 | - return $result; |
|
| 60 | - } |
|
| 59 | + return $result; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Remove the mount points |
|
| 64 | - * |
|
| 65 | - * @return mixed |
|
| 66 | - * @return bool |
|
| 67 | - */ |
|
| 68 | - public function removeMount() { |
|
| 69 | - return $this->manager->removeShare($this->mountPoint); |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * Remove the mount points |
|
| 64 | + * |
|
| 65 | + * @return mixed |
|
| 66 | + * @return bool |
|
| 67 | + */ |
|
| 68 | + public function removeMount() { |
|
| 69 | + return $this->manager->removeShare($this->mountPoint); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -27,81 +27,81 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Updater { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param array $params |
|
| 32 | - */ |
|
| 33 | - static public function renameHook($params) { |
|
| 34 | - self::renameChildren($params['oldpath'], $params['newpath']); |
|
| 35 | - self::moveShareToShare($params['newpath']); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Fix for https://github.com/owncloud/core/issues/20769 |
|
| 40 | - * |
|
| 41 | - * The owner is allowed to move their files (if they are shared) into a receiving folder |
|
| 42 | - * In this case we need to update the parent of the moved share. Since they are |
|
| 43 | - * effectively handing over ownership of the file the rest of the code needs to know |
|
| 44 | - * they need to build up the reshare tree. |
|
| 45 | - * |
|
| 46 | - * @param string $path |
|
| 47 | - */ |
|
| 48 | - static private function moveShareToShare($path) { |
|
| 49 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 50 | - |
|
| 51 | - // If the user folder can't be constructed (e.g. link share) just return. |
|
| 52 | - if ($userFolder === null) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $src = $userFolder->get($path); |
|
| 57 | - |
|
| 58 | - $shareManager = \OC::$server->getShareManager(); |
|
| 59 | - |
|
| 60 | - $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1); |
|
| 61 | - $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1)); |
|
| 62 | - |
|
| 63 | - // If the path we move is not a share we don't care |
|
| 64 | - if (empty($shares)) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // Check if the destination is inside a share |
|
| 69 | - $mountManager = \OC::$server->getMountManager(); |
|
| 70 | - $dstMount = $mountManager->find($src->getPath()); |
|
| 71 | - if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
|
| 72 | - return; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $newOwner = $dstMount->getShare()->getShareOwner(); |
|
| 76 | - |
|
| 77 | - //Ownership is moved over |
|
| 78 | - foreach ($shares as $share) { |
|
| 79 | - /** @var \OCP\Share\IShare $share */ |
|
| 80 | - $share->setShareOwner($newOwner); |
|
| 81 | - $shareManager->updateShare($share); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * rename mount point from the children if the parent was renamed |
|
| 87 | - * |
|
| 88 | - * @param string $oldPath old path relative to data/user/files |
|
| 89 | - * @param string $newPath new path relative to data/user/files |
|
| 90 | - */ |
|
| 91 | - static private function renameChildren($oldPath, $newPath) { |
|
| 92 | - |
|
| 93 | - $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
| 94 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
| 95 | - |
|
| 96 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 97 | - $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
| 98 | - foreach ($mountedShares as $mount) { |
|
| 99 | - if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
| 100 | - $mountPoint = $mount->getMountPoint(); |
|
| 101 | - $target = str_replace($absOldPath, $absNewPath, $mountPoint); |
|
| 102 | - $mount->moveMount($target); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 30 | + /** |
|
| 31 | + * @param array $params |
|
| 32 | + */ |
|
| 33 | + static public function renameHook($params) { |
|
| 34 | + self::renameChildren($params['oldpath'], $params['newpath']); |
|
| 35 | + self::moveShareToShare($params['newpath']); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Fix for https://github.com/owncloud/core/issues/20769 |
|
| 40 | + * |
|
| 41 | + * The owner is allowed to move their files (if they are shared) into a receiving folder |
|
| 42 | + * In this case we need to update the parent of the moved share. Since they are |
|
| 43 | + * effectively handing over ownership of the file the rest of the code needs to know |
|
| 44 | + * they need to build up the reshare tree. |
|
| 45 | + * |
|
| 46 | + * @param string $path |
|
| 47 | + */ |
|
| 48 | + static private function moveShareToShare($path) { |
|
| 49 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 50 | + |
|
| 51 | + // If the user folder can't be constructed (e.g. link share) just return. |
|
| 52 | + if ($userFolder === null) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $src = $userFolder->get($path); |
|
| 57 | + |
|
| 58 | + $shareManager = \OC::$server->getShareManager(); |
|
| 59 | + |
|
| 60 | + $shares = $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_USER, $src, false, -1); |
|
| 61 | + $shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), \OCP\Share::SHARE_TYPE_GROUP, $src, false, -1)); |
|
| 62 | + |
|
| 63 | + // If the path we move is not a share we don't care |
|
| 64 | + if (empty($shares)) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // Check if the destination is inside a share |
|
| 69 | + $mountManager = \OC::$server->getMountManager(); |
|
| 70 | + $dstMount = $mountManager->find($src->getPath()); |
|
| 71 | + if (!($dstMount instanceof \OCA\Files_Sharing\SharedMount)) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $newOwner = $dstMount->getShare()->getShareOwner(); |
|
| 76 | + |
|
| 77 | + //Ownership is moved over |
|
| 78 | + foreach ($shares as $share) { |
|
| 79 | + /** @var \OCP\Share\IShare $share */ |
|
| 80 | + $share->setShareOwner($newOwner); |
|
| 81 | + $shareManager->updateShare($share); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * rename mount point from the children if the parent was renamed |
|
| 87 | + * |
|
| 88 | + * @param string $oldPath old path relative to data/user/files |
|
| 89 | + * @param string $newPath new path relative to data/user/files |
|
| 90 | + */ |
|
| 91 | + static private function renameChildren($oldPath, $newPath) { |
|
| 92 | + |
|
| 93 | + $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
| 94 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
| 95 | + |
|
| 96 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 97 | + $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
| 98 | + foreach ($mountedShares as $mount) { |
|
| 99 | + if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
| 100 | + $mountPoint = $mount->getMountPoint(); |
|
| 101 | + $target = str_replace($absOldPath, $absNewPath, $mountPoint); |
|
| 102 | + $mount->moveMount($target); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | } |
@@ -90,11 +90,11 @@ |
||
| 90 | 90 | */ |
| 91 | 91 | static private function renameChildren($oldPath, $newPath) { |
| 92 | 92 | |
| 93 | - $absNewPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $newPath); |
|
| 94 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
| 93 | + $absNewPath = \OC\Files\Filesystem::normalizePath('/'.\OCP\User::getUser().'/files/'.$newPath); |
|
| 94 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/'.\OCP\User::getUser().'/files/'.$oldPath); |
|
| 95 | 95 | |
| 96 | 96 | $mountManager = \OC\Files\Filesystem::getMountManager(); |
| 97 | - $mountedShares = $mountManager->findIn('/' . \OCP\User::getUser() . '/files/' . $oldPath); |
|
| 97 | + $mountedShares = $mountManager->findIn('/'.\OCP\User::getUser().'/files/'.$oldPath); |
|
| 98 | 98 | foreach ($mountedShares as $mount) { |
| 99 | 99 | if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
| 100 | 100 | $mountPoint = $mount->getMountPoint(); |
@@ -31,63 +31,63 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class Capabilities implements ICapability { |
| 33 | 33 | |
| 34 | - /** @var IConfig */ |
|
| 35 | - private $config; |
|
| 34 | + /** @var IConfig */ |
|
| 35 | + private $config; |
|
| 36 | 36 | |
| 37 | - public function __construct(IConfig $config) { |
|
| 38 | - $this->config = $config; |
|
| 39 | - } |
|
| 37 | + public function __construct(IConfig $config) { |
|
| 38 | + $this->config = $config; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Return this classes capabilities |
|
| 43 | - * |
|
| 44 | - * @return array |
|
| 45 | - */ |
|
| 46 | - public function getCapabilities() { |
|
| 47 | - $res = []; |
|
| 41 | + /** |
|
| 42 | + * Return this classes capabilities |
|
| 43 | + * |
|
| 44 | + * @return array |
|
| 45 | + */ |
|
| 46 | + public function getCapabilities() { |
|
| 47 | + $res = []; |
|
| 48 | 48 | |
| 49 | - if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
| 50 | - $res['api_enabled'] = false; |
|
| 51 | - $res['public'] = ['enabled' => false]; |
|
| 52 | - $res['user'] = ['send_mail' => false]; |
|
| 53 | - $res['resharing'] = false; |
|
| 54 | - } else { |
|
| 55 | - $res['api_enabled'] = true; |
|
| 49 | + if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
| 50 | + $res['api_enabled'] = false; |
|
| 51 | + $res['public'] = ['enabled' => false]; |
|
| 52 | + $res['user'] = ['send_mail' => false]; |
|
| 53 | + $res['resharing'] = false; |
|
| 54 | + } else { |
|
| 55 | + $res['api_enabled'] = true; |
|
| 56 | 56 | |
| 57 | - $public = []; |
|
| 58 | - $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
| 59 | - if ($public['enabled']) { |
|
| 60 | - $public['password'] = []; |
|
| 61 | - $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'); |
|
| 57 | + $public = []; |
|
| 58 | + $public['enabled'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes') === 'yes'; |
|
| 59 | + if ($public['enabled']) { |
|
| 60 | + $public['password'] = []; |
|
| 61 | + $public['password']['enforced'] = ($this->config->getAppValue('core', 'shareapi_enforce_links_password', 'no') === 'yes'); |
|
| 62 | 62 | |
| 63 | - $public['expire_date'] = []; |
|
| 64 | - $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 65 | - if ($public['expire_date']['enabled']) { |
|
| 66 | - $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 67 | - $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 68 | - } |
|
| 63 | + $public['expire_date'] = []; |
|
| 64 | + $public['expire_date']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_expire_date', 'no') === 'yes'; |
|
| 65 | + if ($public['expire_date']['enabled']) { |
|
| 66 | + $public['expire_date']['days'] = $this->config->getAppValue('core', 'shareapi_expire_after_n_days', '7'); |
|
| 67 | + $public['expire_date']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_expire_date', 'no') === 'yes'; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes'; |
|
| 71 | - $public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 72 | - $public['upload_files_drop'] = $public['upload']; |
|
| 73 | - } |
|
| 74 | - $res["public"] = $public; |
|
| 70 | + $public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes'; |
|
| 71 | + $public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes'; |
|
| 72 | + $public['upload_files_drop'] = $public['upload']; |
|
| 73 | + } |
|
| 74 | + $res["public"] = $public; |
|
| 75 | 75 | |
| 76 | - $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; |
|
| 76 | + $res['resharing'] = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes'; |
|
| 77 | 77 | |
| 78 | - $res['user']['send_mail'] = false; |
|
| 78 | + $res['user']['send_mail'] = false; |
|
| 79 | 79 | |
| 80 | - $res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 81 | - } |
|
| 80 | + $res['group_sharing'] = $this->config->getAppValue('core', 'shareapi_allow_group_sharing', 'yes') === 'yes'; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - //Federated sharing |
|
| 84 | - $res['federation'] = [ |
|
| 85 | - 'outgoing' => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes', |
|
| 86 | - 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes' |
|
| 87 | - ]; |
|
| 83 | + //Federated sharing |
|
| 84 | + $res['federation'] = [ |
|
| 85 | + 'outgoing' => $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'yes', |
|
| 86 | + 'incoming' => $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'yes' |
|
| 87 | + ]; |
|
| 88 | 88 | |
| 89 | - return [ |
|
| 90 | - 'files_sharing' => $res, |
|
| 91 | - ]; |
|
| 92 | - } |
|
| 89 | + return [ |
|
| 90 | + 'files_sharing' => $res, |
|
| 91 | + ]; |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -31,35 +31,35 @@ |
||
| 31 | 31 | |
| 32 | 32 | class Hooks { |
| 33 | 33 | |
| 34 | - public static function deleteUser($params) { |
|
| 35 | - $discoveryManager = new DiscoveryManager( |
|
| 36 | - \OC::$server->getMemCacheFactory(), |
|
| 37 | - \OC::$server->getHTTPClientService() |
|
| 38 | - ); |
|
| 39 | - $manager = new External\Manager( |
|
| 40 | - \OC::$server->getDatabaseConnection(), |
|
| 41 | - \OC\Files\Filesystem::getMountManager(), |
|
| 42 | - \OC\Files\Filesystem::getLoader(), |
|
| 43 | - \OC::$server->getHTTPClientService(), |
|
| 44 | - \OC::$server->getNotificationManager(), |
|
| 45 | - $discoveryManager, |
|
| 46 | - $params['uid']); |
|
| 34 | + public static function deleteUser($params) { |
|
| 35 | + $discoveryManager = new DiscoveryManager( |
|
| 36 | + \OC::$server->getMemCacheFactory(), |
|
| 37 | + \OC::$server->getHTTPClientService() |
|
| 38 | + ); |
|
| 39 | + $manager = new External\Manager( |
|
| 40 | + \OC::$server->getDatabaseConnection(), |
|
| 41 | + \OC\Files\Filesystem::getMountManager(), |
|
| 42 | + \OC\Files\Filesystem::getLoader(), |
|
| 43 | + \OC::$server->getHTTPClientService(), |
|
| 44 | + \OC::$server->getNotificationManager(), |
|
| 45 | + $discoveryManager, |
|
| 46 | + $params['uid']); |
|
| 47 | 47 | |
| 48 | - $manager->removeUserShares($params['uid']); |
|
| 49 | - } |
|
| 48 | + $manager->removeUserShares($params['uid']); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public static function unshareChildren($params) { |
|
| 52 | - $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
| 53 | - $view = new \OC\Files\View('/'); |
|
| 51 | + public static function unshareChildren($params) { |
|
| 52 | + $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
| 53 | + $view = new \OC\Files\View('/'); |
|
| 54 | 54 | |
| 55 | - // find share mount points within $path and unmount them |
|
| 56 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 57 | - $mountedShares = $mountManager->findIn($path); |
|
| 58 | - foreach ($mountedShares as $mount) { |
|
| 59 | - if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
| 60 | - $mountPoint = $mount->getMountPoint(); |
|
| 61 | - $view->unlink($mountPoint); |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 55 | + // find share mount points within $path and unmount them |
|
| 56 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 57 | + $mountedShares = $mountManager->findIn($path); |
|
| 58 | + foreach ($mountedShares as $mount) { |
|
| 59 | + if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { |
|
| 60 | + $mountPoint = $mount->getMountPoint(); |
|
| 61 | + $view->unlink($mountPoint); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -31,36 +31,36 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class DeleteOrphanedSharesJob extends TimedJob { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Default interval in minutes |
|
| 36 | - * |
|
| 37 | - * @var int $defaultIntervalMin |
|
| 38 | - **/ |
|
| 39 | - protected $defaultIntervalMin = 15; |
|
| 34 | + /** |
|
| 35 | + * Default interval in minutes |
|
| 36 | + * |
|
| 37 | + * @var int $defaultIntervalMin |
|
| 38 | + **/ |
|
| 39 | + protected $defaultIntervalMin = 15; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * sets the correct interval for this timed job |
|
| 43 | - */ |
|
| 44 | - public function __construct(){ |
|
| 45 | - $this->interval = $this->defaultIntervalMin * 60; |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * sets the correct interval for this timed job |
|
| 43 | + */ |
|
| 44 | + public function __construct(){ |
|
| 45 | + $this->interval = $this->defaultIntervalMin * 60; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Makes the background job do its work |
|
| 50 | - * |
|
| 51 | - * @param array $argument unused argument |
|
| 52 | - */ |
|
| 53 | - public function run($argument) { |
|
| 54 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 55 | - $logger = \OC::$server->getLogger(); |
|
| 48 | + /** |
|
| 49 | + * Makes the background job do its work |
|
| 50 | + * |
|
| 51 | + * @param array $argument unused argument |
|
| 52 | + */ |
|
| 53 | + public function run($argument) { |
|
| 54 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 55 | + $logger = \OC::$server->getLogger(); |
|
| 56 | 56 | |
| 57 | - $sql = |
|
| 58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
| 59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 60 | - 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
| 57 | + $sql = |
|
| 58 | + 'DELETE FROM `*PREFIX*share` ' . |
|
| 59 | + 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 60 | + 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
|
| 61 | 61 | |
| 62 | - $deletedEntries = $connection->executeUpdate($sql); |
|
| 63 | - $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
| 64 | - } |
|
| 62 | + $deletedEntries = $connection->executeUpdate($sql); |
|
| 63 | + $logger->debug("$deletedEntries orphaned share(s) deleted", ['app' => 'DeleteOrphanedSharesJob']); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | /** |
| 42 | 42 | * sets the correct interval for this timed job |
| 43 | 43 | */ |
| 44 | - public function __construct(){ |
|
| 44 | + public function __construct() { |
|
| 45 | 45 | $this->interval = $this->defaultIntervalMin * 60; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | $logger = \OC::$server->getLogger(); |
| 56 | 56 | |
| 57 | 57 | $sql = |
| 58 | - 'DELETE FROM `*PREFIX*share` ' . |
|
| 59 | - 'WHERE `item_type` in (\'file\', \'folder\') ' . |
|
| 58 | + 'DELETE FROM `*PREFIX*share` '. |
|
| 59 | + 'WHERE `item_type` in (\'file\', \'folder\') '. |
|
| 60 | 60 | 'AND NOT EXISTS (SELECT `fileid` FROM `*PREFIX*filecache` WHERE `file_source` = `fileid`)'; |
| 61 | 61 | |
| 62 | 62 | $deletedEntries = $connection->executeUpdate($sql); |
@@ -10,43 +10,43 @@ |
||
| 10 | 10 | use OCP\Share\IManager; |
| 11 | 11 | |
| 12 | 12 | class OCSShareAPIMiddleware extends Middleware { |
| 13 | - /** @var IManager */ |
|
| 14 | - private $shareManager; |
|
| 15 | - /** @var IL10N */ |
|
| 16 | - private $l; |
|
| 13 | + /** @var IManager */ |
|
| 14 | + private $shareManager; |
|
| 15 | + /** @var IL10N */ |
|
| 16 | + private $l; |
|
| 17 | 17 | |
| 18 | - public function __construct(IManager $shareManager, |
|
| 19 | - IL10N $l) { |
|
| 20 | - $this->shareManager = $shareManager; |
|
| 21 | - $this->l = $l; |
|
| 22 | - } |
|
| 18 | + public function __construct(IManager $shareManager, |
|
| 19 | + IL10N $l) { |
|
| 20 | + $this->shareManager = $shareManager; |
|
| 21 | + $this->l = $l; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param \OCP\AppFramework\Controller $controller |
|
| 26 | - * @param string $methodName |
|
| 27 | - * |
|
| 28 | - * @throws OCSNotFoundException |
|
| 29 | - */ |
|
| 30 | - public function beforeController($controller, $methodName) { |
|
| 31 | - if ($controller instanceof ShareAPIController) { |
|
| 32 | - if (!$this->shareManager->shareApiEnabled()) { |
|
| 33 | - throw new OCSNotFoundException($this->l->t('Share API is disabled')); |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - } |
|
| 24 | + /** |
|
| 25 | + * @param \OCP\AppFramework\Controller $controller |
|
| 26 | + * @param string $methodName |
|
| 27 | + * |
|
| 28 | + * @throws OCSNotFoundException |
|
| 29 | + */ |
|
| 30 | + public function beforeController($controller, $methodName) { |
|
| 31 | + if ($controller instanceof ShareAPIController) { |
|
| 32 | + if (!$this->shareManager->shareApiEnabled()) { |
|
| 33 | + throw new OCSNotFoundException($this->l->t('Share API is disabled')); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param \OCP\AppFramework\Controller $controller |
|
| 40 | - * @param string $methodName |
|
| 41 | - * @param Response $response |
|
| 42 | - * @return Response |
|
| 43 | - */ |
|
| 44 | - public function afterController($controller, $methodName, Response $response) { |
|
| 45 | - if ($controller instanceof ShareAPIController) { |
|
| 46 | - /** @var ShareAPIController $controller */ |
|
| 47 | - $controller->cleanup(); |
|
| 48 | - } |
|
| 38 | + /** |
|
| 39 | + * @param \OCP\AppFramework\Controller $controller |
|
| 40 | + * @param string $methodName |
|
| 41 | + * @param Response $response |
|
| 42 | + * @return Response |
|
| 43 | + */ |
|
| 44 | + public function afterController($controller, $methodName, Response $response) { |
|
| 45 | + if ($controller instanceof ShareAPIController) { |
|
| 46 | + /** @var ShareAPIController $controller */ |
|
| 47 | + $controller->cleanup(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return $response; |
|
| 51 | - } |
|
| 50 | + return $response; |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -45,20 +45,20 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | class SharingCheckMiddleware extends Middleware { |
| 47 | 47 | |
| 48 | - /** @var string */ |
|
| 49 | - protected $appName; |
|
| 50 | - /** @var IConfig */ |
|
| 51 | - protected $config; |
|
| 52 | - /** @var IAppManager */ |
|
| 53 | - protected $appManager; |
|
| 54 | - /** @var IControllerMethodReflector */ |
|
| 55 | - protected $reflector; |
|
| 56 | - /** @var IManager */ |
|
| 57 | - protected $shareManager; |
|
| 58 | - /** @var IRequest */ |
|
| 59 | - protected $request; |
|
| 60 | - |
|
| 61 | - /*** |
|
| 48 | + /** @var string */ |
|
| 49 | + protected $appName; |
|
| 50 | + /** @var IConfig */ |
|
| 51 | + protected $config; |
|
| 52 | + /** @var IAppManager */ |
|
| 53 | + protected $appManager; |
|
| 54 | + /** @var IControllerMethodReflector */ |
|
| 55 | + protected $reflector; |
|
| 56 | + /** @var IManager */ |
|
| 57 | + protected $shareManager; |
|
| 58 | + /** @var IRequest */ |
|
| 59 | + protected $request; |
|
| 60 | + |
|
| 61 | + /*** |
|
| 62 | 62 | * @param string $appName |
| 63 | 63 | * @param IConfig $config |
| 64 | 64 | * @param IAppManager $appManager |
@@ -66,117 +66,117 @@ discard block |
||
| 66 | 66 | * @param IManager $shareManager |
| 67 | 67 | * @param IRequest $request |
| 68 | 68 | */ |
| 69 | - public function __construct($appName, |
|
| 70 | - IConfig $config, |
|
| 71 | - IAppManager $appManager, |
|
| 72 | - IControllerMethodReflector $reflector, |
|
| 73 | - IManager $shareManager, |
|
| 74 | - IRequest $request |
|
| 75 | - ) { |
|
| 76 | - $this->appName = $appName; |
|
| 77 | - $this->config = $config; |
|
| 78 | - $this->appManager = $appManager; |
|
| 79 | - $this->reflector = $reflector; |
|
| 80 | - $this->shareManager = $shareManager; |
|
| 81 | - $this->request = $request; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Check if sharing is enabled before the controllers is executed |
|
| 86 | - * |
|
| 87 | - * @param \OCP\AppFramework\Controller $controller |
|
| 88 | - * @param string $methodName |
|
| 89 | - * @throws NotFoundException |
|
| 90 | - * @throws S2SException |
|
| 91 | - */ |
|
| 92 | - public function beforeController($controller, $methodName) { |
|
| 93 | - if(!$this->isSharingEnabled()) { |
|
| 94 | - throw new NotFoundException('Sharing is disabled.'); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if ($controller instanceof ExternalSharesController && |
|
| 98 | - !$this->externalSharesChecks()) { |
|
| 99 | - throw new S2SException('Federated sharing not allowed'); |
|
| 100 | - } else if ($controller instanceof ShareController) { |
|
| 101 | - $token = $this->request->getParam('token'); |
|
| 102 | - $share = $this->shareManager->getShareByToken($token); |
|
| 103 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
| 104 | - && !$this->isLinkSharingEnabled()) { |
|
| 105 | - throw new NotFoundException('Link sharing is disabled'); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Return 404 page in case of a not found exception |
|
| 112 | - * |
|
| 113 | - * @param \OCP\AppFramework\Controller $controller |
|
| 114 | - * @param string $methodName |
|
| 115 | - * @param \Exception $exception |
|
| 116 | - * @return NotFoundResponse |
|
| 117 | - * @throws \Exception |
|
| 118 | - */ |
|
| 119 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 120 | - if(is_a($exception, '\OCP\Files\NotFoundException')) { |
|
| 121 | - return new NotFoundResponse(); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (is_a($exception, '\OCA\Files_Sharing\Exceptions\S2SException')) { |
|
| 125 | - return new JSONResponse($exception->getMessage(), 405); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - throw $exception; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Checks for externalshares controller |
|
| 133 | - * @return bool |
|
| 134 | - */ |
|
| 135 | - private function externalSharesChecks() { |
|
| 136 | - |
|
| 137 | - if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') && |
|
| 138 | - $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') { |
|
| 139 | - return false; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') && |
|
| 143 | - $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') { |
|
| 144 | - return false; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return true; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Check whether sharing is enabled |
|
| 152 | - * @return bool |
|
| 153 | - */ |
|
| 154 | - private function isSharingEnabled() { |
|
| 155 | - // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app |
|
| 156 | - // Check whether the sharing application is enabled |
|
| 157 | - if(!$this->appManager->isEnabledForUser($this->appName)) { |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return true; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Check if link sharing is allowed |
|
| 166 | - * @return bool |
|
| 167 | - */ |
|
| 168 | - private function isLinkSharingEnabled() { |
|
| 169 | - // Check if the shareAPI is enabled |
|
| 170 | - if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // Check whether public sharing is enabled |
|
| 175 | - if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return true; |
|
| 180 | - } |
|
| 69 | + public function __construct($appName, |
|
| 70 | + IConfig $config, |
|
| 71 | + IAppManager $appManager, |
|
| 72 | + IControllerMethodReflector $reflector, |
|
| 73 | + IManager $shareManager, |
|
| 74 | + IRequest $request |
|
| 75 | + ) { |
|
| 76 | + $this->appName = $appName; |
|
| 77 | + $this->config = $config; |
|
| 78 | + $this->appManager = $appManager; |
|
| 79 | + $this->reflector = $reflector; |
|
| 80 | + $this->shareManager = $shareManager; |
|
| 81 | + $this->request = $request; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Check if sharing is enabled before the controllers is executed |
|
| 86 | + * |
|
| 87 | + * @param \OCP\AppFramework\Controller $controller |
|
| 88 | + * @param string $methodName |
|
| 89 | + * @throws NotFoundException |
|
| 90 | + * @throws S2SException |
|
| 91 | + */ |
|
| 92 | + public function beforeController($controller, $methodName) { |
|
| 93 | + if(!$this->isSharingEnabled()) { |
|
| 94 | + throw new NotFoundException('Sharing is disabled.'); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if ($controller instanceof ExternalSharesController && |
|
| 98 | + !$this->externalSharesChecks()) { |
|
| 99 | + throw new S2SException('Federated sharing not allowed'); |
|
| 100 | + } else if ($controller instanceof ShareController) { |
|
| 101 | + $token = $this->request->getParam('token'); |
|
| 102 | + $share = $this->shareManager->getShareByToken($token); |
|
| 103 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK |
|
| 104 | + && !$this->isLinkSharingEnabled()) { |
|
| 105 | + throw new NotFoundException('Link sharing is disabled'); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Return 404 page in case of a not found exception |
|
| 112 | + * |
|
| 113 | + * @param \OCP\AppFramework\Controller $controller |
|
| 114 | + * @param string $methodName |
|
| 115 | + * @param \Exception $exception |
|
| 116 | + * @return NotFoundResponse |
|
| 117 | + * @throws \Exception |
|
| 118 | + */ |
|
| 119 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 120 | + if(is_a($exception, '\OCP\Files\NotFoundException')) { |
|
| 121 | + return new NotFoundResponse(); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (is_a($exception, '\OCA\Files_Sharing\Exceptions\S2SException')) { |
|
| 125 | + return new JSONResponse($exception->getMessage(), 405); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + throw $exception; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Checks for externalshares controller |
|
| 133 | + * @return bool |
|
| 134 | + */ |
|
| 135 | + private function externalSharesChecks() { |
|
| 136 | + |
|
| 137 | + if (!$this->reflector->hasAnnotation('NoIncomingFederatedSharingRequired') && |
|
| 138 | + $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') !== 'yes') { |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + if (!$this->reflector->hasAnnotation('NoOutgoingFederatedSharingRequired') && |
|
| 143 | + $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') !== 'yes') { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return true; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Check whether sharing is enabled |
|
| 152 | + * @return bool |
|
| 153 | + */ |
|
| 154 | + private function isSharingEnabled() { |
|
| 155 | + // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app |
|
| 156 | + // Check whether the sharing application is enabled |
|
| 157 | + if(!$this->appManager->isEnabledForUser($this->appName)) { |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return true; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Check if link sharing is allowed |
|
| 166 | + * @return bool |
|
| 167 | + */ |
|
| 168 | + private function isLinkSharingEnabled() { |
|
| 169 | + // Check if the shareAPI is enabled |
|
| 170 | + if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // Check whether public sharing is enabled |
|
| 175 | + if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return true; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @throws S2SException |
| 91 | 91 | */ |
| 92 | 92 | public function beforeController($controller, $methodName) { |
| 93 | - if(!$this->isSharingEnabled()) { |
|
| 93 | + if (!$this->isSharingEnabled()) { |
|
| 94 | 94 | throw new NotFoundException('Sharing is disabled.'); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @throws \Exception |
| 118 | 118 | */ |
| 119 | 119 | public function afterException($controller, $methodName, \Exception $exception) { |
| 120 | - if(is_a($exception, '\OCP\Files\NotFoundException')) { |
|
| 120 | + if (is_a($exception, '\OCP\Files\NotFoundException')) { |
|
| 121 | 121 | return new NotFoundResponse(); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | private function isSharingEnabled() { |
| 155 | 155 | // FIXME: This check is done here since the route is globally defined and not inside the files_sharing app |
| 156 | 156 | // Check whether the sharing application is enabled |
| 157 | - if(!$this->appManager->isEnabledForUser($this->appName)) { |
|
| 157 | + if (!$this->appManager->isEnabledForUser($this->appName)) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // Check whether public sharing is enabled |
| 175 | - if($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
| 175 | + if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { |
|
| 176 | 176 | return false; |
| 177 | 177 | } |
| 178 | 178 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | 162 | public function getId() { |
| 163 | - return 'shared::' . $this->getMountPoint(); |
|
| 163 | + return 'shared::'.$this->getMountPoint(); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | $info = array( |
| 259 | - 'target' => $this->getMountPoint() . $path, |
|
| 259 | + 'target' => $this->getMountPoint().$path, |
|
| 260 | 260 | 'source' => $source, |
| 261 | 261 | 'mode' => $mode, |
| 262 | 262 | ); |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | public function file_get_contents($path) { |
| 459 | 459 | $info = [ |
| 460 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
| 460 | + 'target' => $this->getMountPoint().'/'.$path, |
|
| 461 | 461 | 'source' => $this->getSourcePath($path), |
| 462 | 462 | ]; |
| 463 | 463 | \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | |
| 467 | 467 | public function file_put_contents($path, $data) { |
| 468 | 468 | $info = [ |
| 469 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
| 469 | + 'target' => $this->getMountPoint().'/'.$path, |
|
| 470 | 470 | 'source' => $this->getSourcePath($path), |
| 471 | 471 | ]; |
| 472 | 472 | \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
@@ -47,454 +47,454 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { |
| 49 | 49 | |
| 50 | - /** @var \OCP\Share\IShare */ |
|
| 51 | - private $superShare; |
|
| 52 | - |
|
| 53 | - /** @var \OCP\Share\IShare[] */ |
|
| 54 | - private $groupedShares; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var \OC\Files\View |
|
| 58 | - */ |
|
| 59 | - private $ownerView; |
|
| 60 | - |
|
| 61 | - private $initialized = false; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var ICacheEntry |
|
| 65 | - */ |
|
| 66 | - private $sourceRootInfo; |
|
| 67 | - |
|
| 68 | - /** @var string */ |
|
| 69 | - private $user; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var \OCP\ILogger |
|
| 73 | - */ |
|
| 74 | - private $logger; |
|
| 75 | - |
|
| 76 | - /** @var IStorage */ |
|
| 77 | - private $nonMaskedStorage; |
|
| 78 | - |
|
| 79 | - private $options; |
|
| 80 | - |
|
| 81 | - public function __construct($arguments) { |
|
| 82 | - $this->ownerView = $arguments['ownerView']; |
|
| 83 | - $this->logger = \OC::$server->getLogger(); |
|
| 84 | - |
|
| 85 | - $this->superShare = $arguments['superShare']; |
|
| 86 | - $this->groupedShares = $arguments['groupedShares']; |
|
| 87 | - |
|
| 88 | - $this->user = $arguments['user']; |
|
| 89 | - |
|
| 90 | - parent::__construct([ |
|
| 91 | - 'storage' => null, |
|
| 92 | - 'root' => null, |
|
| 93 | - ]); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return ICacheEntry |
|
| 98 | - */ |
|
| 99 | - private function getSourceRootInfo() { |
|
| 100 | - if (is_null($this->sourceRootInfo)) { |
|
| 101 | - if (is_null($this->superShare->getNodeCacheEntry())) { |
|
| 102 | - $this->init(); |
|
| 103 | - $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
| 104 | - } else { |
|
| 105 | - $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - return $this->sourceRootInfo; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - private function init() { |
|
| 112 | - if ($this->initialized) { |
|
| 113 | - return; |
|
| 114 | - } |
|
| 115 | - $this->initialized = true; |
|
| 116 | - try { |
|
| 117 | - Filesystem::initMountPoints($this->superShare->getShareOwner()); |
|
| 118 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 119 | - list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); |
|
| 120 | - $this->storage = new PermissionsMask([ |
|
| 121 | - 'storage' => $this->nonMaskedStorage, |
|
| 122 | - 'mask' => $this->superShare->getPermissions() |
|
| 123 | - ]); |
|
| 124 | - } catch (NotFoundException $e) { |
|
| 125 | - // original file not accessible or deleted, set FailedStorage |
|
| 126 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
| 127 | - $this->cache = new FailedCache(); |
|
| 128 | - $this->rootPath = ''; |
|
| 129 | - } catch (NoUserException $e) { |
|
| 130 | - // sharer user deleted, set FailedStorage |
|
| 131 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
| 132 | - $this->cache = new FailedCache(); |
|
| 133 | - $this->rootPath = ''; |
|
| 134 | - } catch (\Exception $e) { |
|
| 135 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
| 136 | - $this->cache = new FailedCache(); |
|
| 137 | - $this->rootPath = ''; |
|
| 138 | - $this->logger->logException($e); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - if (!$this->nonMaskedStorage) { |
|
| 142 | - $this->nonMaskedStorage = $this->storage; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @inheritdoc |
|
| 148 | - */ |
|
| 149 | - public function instanceOfStorage($class) { |
|
| 150 | - if ($class === '\OC\Files\Storage\Common') { |
|
| 151 | - return true; |
|
| 152 | - } |
|
| 153 | - if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - return parent::instanceOfStorage($class); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function getShareId() { |
|
| 163 | - return $this->superShare->getId(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - private function isValid() { |
|
| 167 | - return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * get id of the mount point |
|
| 172 | - * |
|
| 173 | - * @return string |
|
| 174 | - */ |
|
| 175 | - public function getId() { |
|
| 176 | - return 'shared::' . $this->getMountPoint(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get the permissions granted for a shared file |
|
| 181 | - * |
|
| 182 | - * @param string $target Shared target file path |
|
| 183 | - * @return int CRUDS permissions granted |
|
| 184 | - */ |
|
| 185 | - public function getPermissions($target = '') { |
|
| 186 | - if (!$this->isValid()) { |
|
| 187 | - return 0; |
|
| 188 | - } |
|
| 189 | - $permissions = $this->superShare->getPermissions(); |
|
| 190 | - // part files and the mount point always have delete permissions |
|
| 191 | - if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
| 192 | - $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if (\OCP\Util::isSharingDisabledForUser()) { |
|
| 196 | - $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $permissions; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - public function isCreatable($path) { |
|
| 203 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - public function isReadable($path) { |
|
| 207 | - if (!$this->isValid()) { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - if (!$this->file_exists($path)) { |
|
| 211 | - return false; |
|
| 212 | - } |
|
| 213 | - /** @var IStorage $storage */ |
|
| 214 | - /** @var string $internalPath */ |
|
| 215 | - list($storage, $internalPath) = $this->resolvePath($path); |
|
| 216 | - return $storage->isReadable($internalPath); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - public function isUpdatable($path) { |
|
| 220 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - public function isDeletable($path) { |
|
| 224 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - public function isSharable($path) { |
|
| 228 | - if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - public function fopen($path, $mode) { |
|
| 235 | - if ($source = $this->getSourcePath($path)) { |
|
| 236 | - switch ($mode) { |
|
| 237 | - case 'r+': |
|
| 238 | - case 'rb+': |
|
| 239 | - case 'w+': |
|
| 240 | - case 'wb+': |
|
| 241 | - case 'x+': |
|
| 242 | - case 'xb+': |
|
| 243 | - case 'a+': |
|
| 244 | - case 'ab+': |
|
| 245 | - case 'w': |
|
| 246 | - case 'wb': |
|
| 247 | - case 'x': |
|
| 248 | - case 'xb': |
|
| 249 | - case 'a': |
|
| 250 | - case 'ab': |
|
| 251 | - $creatable = $this->isCreatable($path); |
|
| 252 | - $updatable = $this->isUpdatable($path); |
|
| 253 | - // if neither permissions given, no need to continue |
|
| 254 | - if (!$creatable && !$updatable) { |
|
| 255 | - return false; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - $exists = $this->file_exists($path); |
|
| 259 | - // if a file exists, updatable permissions are required |
|
| 260 | - if ($exists && !$updatable) { |
|
| 261 | - return false; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // part file is allowed if !$creatable but the final file is $updatable |
|
| 265 | - if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
| 266 | - if (!$exists && !$creatable) { |
|
| 267 | - return false; |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - $info = array( |
|
| 272 | - 'target' => $this->getMountPoint() . $path, |
|
| 273 | - 'source' => $source, |
|
| 274 | - 'mode' => $mode, |
|
| 275 | - ); |
|
| 276 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
| 277 | - return $this->nonMaskedStorage->fopen($this->getSourcePath($path), $mode); |
|
| 278 | - } |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * see http://php.net/manual/en/function.rename.php |
|
| 284 | - * |
|
| 285 | - * @param string $path1 |
|
| 286 | - * @param string $path2 |
|
| 287 | - * @return bool |
|
| 288 | - */ |
|
| 289 | - public function rename($path1, $path2) { |
|
| 290 | - $this->init(); |
|
| 291 | - $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
| 292 | - $targetExists = $this->file_exists($path2); |
|
| 293 | - $sameFodler = dirname($path1) === dirname($path2); |
|
| 294 | - |
|
| 295 | - if ($targetExists || ($sameFodler && !$isPartFile)) { |
|
| 296 | - if (!$this->isUpdatable('')) { |
|
| 297 | - return false; |
|
| 298 | - } |
|
| 299 | - } else { |
|
| 300 | - if (!$this->isCreatable('')) { |
|
| 301 | - return false; |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - return $this->nonMaskedStorage->rename($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * return mount point of share, relative to data/user/files |
|
| 310 | - * |
|
| 311 | - * @return string |
|
| 312 | - */ |
|
| 313 | - public function getMountPoint() { |
|
| 314 | - return $this->superShare->getTarget(); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param string $path |
|
| 319 | - */ |
|
| 320 | - public function setMountPoint($path) { |
|
| 321 | - $this->superShare->setTarget($path); |
|
| 322 | - |
|
| 323 | - foreach ($this->groupedShares as $share) { |
|
| 324 | - $share->setTarget($path); |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * get the user who shared the file |
|
| 330 | - * |
|
| 331 | - * @return string |
|
| 332 | - */ |
|
| 333 | - public function getSharedFrom() { |
|
| 334 | - return $this->superShare->getShareOwner(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @return \OCP\Share\IShare |
|
| 339 | - */ |
|
| 340 | - public function getShare() { |
|
| 341 | - return $this->superShare; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * return share type, can be "file" or "folder" |
|
| 346 | - * |
|
| 347 | - * @return string |
|
| 348 | - */ |
|
| 349 | - public function getItemType() { |
|
| 350 | - return $this->superShare->getNodeType(); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @param string $path |
|
| 355 | - * @param null $storage |
|
| 356 | - * @return Cache |
|
| 357 | - */ |
|
| 358 | - public function getCache($path = '', $storage = null) { |
|
| 359 | - if ($this->cache) { |
|
| 360 | - return $this->cache; |
|
| 361 | - } |
|
| 362 | - if (!$storage) { |
|
| 363 | - $storage = $this; |
|
| 364 | - } |
|
| 365 | - if ($this->storage instanceof FailedStorage) { |
|
| 366 | - return new FailedCache(); |
|
| 367 | - } |
|
| 368 | - $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare); |
|
| 369 | - return $this->cache; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - public function getScanner($path = '', $storage = null) { |
|
| 373 | - if (!$storage) { |
|
| 374 | - $storage = $this; |
|
| 375 | - } |
|
| 376 | - return new \OCA\Files_Sharing\Scanner($storage); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - public function getPropagator($storage = null) { |
|
| 380 | - if (isset($this->propagator)) { |
|
| 381 | - return $this->propagator; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if (!$storage) { |
|
| 385 | - $storage = $this; |
|
| 386 | - } |
|
| 387 | - $this->propagator = new \OCA\Files_Sharing\SharedPropagator($storage, \OC::$server->getDatabaseConnection()); |
|
| 388 | - return $this->propagator; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - public function getOwner($path) { |
|
| 392 | - return $this->superShare->getShareOwner(); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * unshare complete storage, also the grouped shares |
|
| 397 | - * |
|
| 398 | - * @return bool |
|
| 399 | - */ |
|
| 400 | - public function unshareStorage() { |
|
| 401 | - foreach ($this->groupedShares as $share) { |
|
| 402 | - \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
| 403 | - } |
|
| 404 | - return true; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @param string $path |
|
| 409 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 410 | - * @param \OCP\Lock\ILockingProvider $provider |
|
| 411 | - * @throws \OCP\Lock\LockedException |
|
| 412 | - */ |
|
| 413 | - public function acquireLock($path, $type, ILockingProvider $provider) { |
|
| 414 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
| 415 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 416 | - $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
| 417 | - // lock the parent folders of the owner when locking the share as recipient |
|
| 418 | - if ($path === '') { |
|
| 419 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 420 | - $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * @param string $path |
|
| 426 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 427 | - * @param \OCP\Lock\ILockingProvider $provider |
|
| 428 | - */ |
|
| 429 | - public function releaseLock($path, $type, ILockingProvider $provider) { |
|
| 430 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
| 431 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 432 | - $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
| 433 | - // unlock the parent folders of the owner when unlocking the share as recipient |
|
| 434 | - if ($path === '') { |
|
| 435 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 436 | - $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @param string $path |
|
| 442 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 443 | - * @param \OCP\Lock\ILockingProvider $provider |
|
| 444 | - */ |
|
| 445 | - public function changeLock($path, $type, ILockingProvider $provider) { |
|
| 446 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
| 447 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 448 | - $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @return array [ available, last_checked ] |
|
| 453 | - */ |
|
| 454 | - public function getAvailability() { |
|
| 455 | - // shares do not participate in availability logic |
|
| 456 | - return [ |
|
| 457 | - 'available' => true, |
|
| 458 | - 'last_checked' => 0 |
|
| 459 | - ]; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * @param bool $available |
|
| 464 | - */ |
|
| 465 | - public function setAvailability($available) { |
|
| 466 | - // shares do not participate in availability logic |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - public function getSourceStorage() { |
|
| 470 | - $this->init(); |
|
| 471 | - return $this->nonMaskedStorage; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - public function getWrapperStorage() { |
|
| 475 | - $this->init(); |
|
| 476 | - return $this->storage; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - public function file_get_contents($path) { |
|
| 480 | - $info = [ |
|
| 481 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
| 482 | - 'source' => $this->getSourcePath($path), |
|
| 483 | - ]; |
|
| 484 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
| 485 | - return parent::file_get_contents($path); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - public function file_put_contents($path, $data) { |
|
| 489 | - $info = [ |
|
| 490 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
| 491 | - 'source' => $this->getSourcePath($path), |
|
| 492 | - ]; |
|
| 493 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
| 494 | - return parent::file_put_contents($path, $data); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - public function setMountOptions(array $options) { |
|
| 498 | - $this->mountOptions = $options; |
|
| 499 | - } |
|
| 50 | + /** @var \OCP\Share\IShare */ |
|
| 51 | + private $superShare; |
|
| 52 | + |
|
| 53 | + /** @var \OCP\Share\IShare[] */ |
|
| 54 | + private $groupedShares; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var \OC\Files\View |
|
| 58 | + */ |
|
| 59 | + private $ownerView; |
|
| 60 | + |
|
| 61 | + private $initialized = false; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var ICacheEntry |
|
| 65 | + */ |
|
| 66 | + private $sourceRootInfo; |
|
| 67 | + |
|
| 68 | + /** @var string */ |
|
| 69 | + private $user; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var \OCP\ILogger |
|
| 73 | + */ |
|
| 74 | + private $logger; |
|
| 75 | + |
|
| 76 | + /** @var IStorage */ |
|
| 77 | + private $nonMaskedStorage; |
|
| 78 | + |
|
| 79 | + private $options; |
|
| 80 | + |
|
| 81 | + public function __construct($arguments) { |
|
| 82 | + $this->ownerView = $arguments['ownerView']; |
|
| 83 | + $this->logger = \OC::$server->getLogger(); |
|
| 84 | + |
|
| 85 | + $this->superShare = $arguments['superShare']; |
|
| 86 | + $this->groupedShares = $arguments['groupedShares']; |
|
| 87 | + |
|
| 88 | + $this->user = $arguments['user']; |
|
| 89 | + |
|
| 90 | + parent::__construct([ |
|
| 91 | + 'storage' => null, |
|
| 92 | + 'root' => null, |
|
| 93 | + ]); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return ICacheEntry |
|
| 98 | + */ |
|
| 99 | + private function getSourceRootInfo() { |
|
| 100 | + if (is_null($this->sourceRootInfo)) { |
|
| 101 | + if (is_null($this->superShare->getNodeCacheEntry())) { |
|
| 102 | + $this->init(); |
|
| 103 | + $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
| 104 | + } else { |
|
| 105 | + $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + return $this->sourceRootInfo; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + private function init() { |
|
| 112 | + if ($this->initialized) { |
|
| 113 | + return; |
|
| 114 | + } |
|
| 115 | + $this->initialized = true; |
|
| 116 | + try { |
|
| 117 | + Filesystem::initMountPoints($this->superShare->getShareOwner()); |
|
| 118 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 119 | + list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); |
|
| 120 | + $this->storage = new PermissionsMask([ |
|
| 121 | + 'storage' => $this->nonMaskedStorage, |
|
| 122 | + 'mask' => $this->superShare->getPermissions() |
|
| 123 | + ]); |
|
| 124 | + } catch (NotFoundException $e) { |
|
| 125 | + // original file not accessible or deleted, set FailedStorage |
|
| 126 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
| 127 | + $this->cache = new FailedCache(); |
|
| 128 | + $this->rootPath = ''; |
|
| 129 | + } catch (NoUserException $e) { |
|
| 130 | + // sharer user deleted, set FailedStorage |
|
| 131 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
| 132 | + $this->cache = new FailedCache(); |
|
| 133 | + $this->rootPath = ''; |
|
| 134 | + } catch (\Exception $e) { |
|
| 135 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
| 136 | + $this->cache = new FailedCache(); |
|
| 137 | + $this->rootPath = ''; |
|
| 138 | + $this->logger->logException($e); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + if (!$this->nonMaskedStorage) { |
|
| 142 | + $this->nonMaskedStorage = $this->storage; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @inheritdoc |
|
| 148 | + */ |
|
| 149 | + public function instanceOfStorage($class) { |
|
| 150 | + if ($class === '\OC\Files\Storage\Common') { |
|
| 151 | + return true; |
|
| 152 | + } |
|
| 153 | + if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + return parent::instanceOfStorage($class); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function getShareId() { |
|
| 163 | + return $this->superShare->getId(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + private function isValid() { |
|
| 167 | + return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * get id of the mount point |
|
| 172 | + * |
|
| 173 | + * @return string |
|
| 174 | + */ |
|
| 175 | + public function getId() { |
|
| 176 | + return 'shared::' . $this->getMountPoint(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get the permissions granted for a shared file |
|
| 181 | + * |
|
| 182 | + * @param string $target Shared target file path |
|
| 183 | + * @return int CRUDS permissions granted |
|
| 184 | + */ |
|
| 185 | + public function getPermissions($target = '') { |
|
| 186 | + if (!$this->isValid()) { |
|
| 187 | + return 0; |
|
| 188 | + } |
|
| 189 | + $permissions = $this->superShare->getPermissions(); |
|
| 190 | + // part files and the mount point always have delete permissions |
|
| 191 | + if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
| 192 | + $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if (\OCP\Util::isSharingDisabledForUser()) { |
|
| 196 | + $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $permissions; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + public function isCreatable($path) { |
|
| 203 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + public function isReadable($path) { |
|
| 207 | + if (!$this->isValid()) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + if (!$this->file_exists($path)) { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 213 | + /** @var IStorage $storage */ |
|
| 214 | + /** @var string $internalPath */ |
|
| 215 | + list($storage, $internalPath) = $this->resolvePath($path); |
|
| 216 | + return $storage->isReadable($internalPath); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + public function isUpdatable($path) { |
|
| 220 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + public function isDeletable($path) { |
|
| 224 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + public function isSharable($path) { |
|
| 228 | + if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + public function fopen($path, $mode) { |
|
| 235 | + if ($source = $this->getSourcePath($path)) { |
|
| 236 | + switch ($mode) { |
|
| 237 | + case 'r+': |
|
| 238 | + case 'rb+': |
|
| 239 | + case 'w+': |
|
| 240 | + case 'wb+': |
|
| 241 | + case 'x+': |
|
| 242 | + case 'xb+': |
|
| 243 | + case 'a+': |
|
| 244 | + case 'ab+': |
|
| 245 | + case 'w': |
|
| 246 | + case 'wb': |
|
| 247 | + case 'x': |
|
| 248 | + case 'xb': |
|
| 249 | + case 'a': |
|
| 250 | + case 'ab': |
|
| 251 | + $creatable = $this->isCreatable($path); |
|
| 252 | + $updatable = $this->isUpdatable($path); |
|
| 253 | + // if neither permissions given, no need to continue |
|
| 254 | + if (!$creatable && !$updatable) { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + $exists = $this->file_exists($path); |
|
| 259 | + // if a file exists, updatable permissions are required |
|
| 260 | + if ($exists && !$updatable) { |
|
| 261 | + return false; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // part file is allowed if !$creatable but the final file is $updatable |
|
| 265 | + if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
| 266 | + if (!$exists && !$creatable) { |
|
| 267 | + return false; |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + $info = array( |
|
| 272 | + 'target' => $this->getMountPoint() . $path, |
|
| 273 | + 'source' => $source, |
|
| 274 | + 'mode' => $mode, |
|
| 275 | + ); |
|
| 276 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
| 277 | + return $this->nonMaskedStorage->fopen($this->getSourcePath($path), $mode); |
|
| 278 | + } |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * see http://php.net/manual/en/function.rename.php |
|
| 284 | + * |
|
| 285 | + * @param string $path1 |
|
| 286 | + * @param string $path2 |
|
| 287 | + * @return bool |
|
| 288 | + */ |
|
| 289 | + public function rename($path1, $path2) { |
|
| 290 | + $this->init(); |
|
| 291 | + $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
| 292 | + $targetExists = $this->file_exists($path2); |
|
| 293 | + $sameFodler = dirname($path1) === dirname($path2); |
|
| 294 | + |
|
| 295 | + if ($targetExists || ($sameFodler && !$isPartFile)) { |
|
| 296 | + if (!$this->isUpdatable('')) { |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 299 | + } else { |
|
| 300 | + if (!$this->isCreatable('')) { |
|
| 301 | + return false; |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + return $this->nonMaskedStorage->rename($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * return mount point of share, relative to data/user/files |
|
| 310 | + * |
|
| 311 | + * @return string |
|
| 312 | + */ |
|
| 313 | + public function getMountPoint() { |
|
| 314 | + return $this->superShare->getTarget(); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param string $path |
|
| 319 | + */ |
|
| 320 | + public function setMountPoint($path) { |
|
| 321 | + $this->superShare->setTarget($path); |
|
| 322 | + |
|
| 323 | + foreach ($this->groupedShares as $share) { |
|
| 324 | + $share->setTarget($path); |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * get the user who shared the file |
|
| 330 | + * |
|
| 331 | + * @return string |
|
| 332 | + */ |
|
| 333 | + public function getSharedFrom() { |
|
| 334 | + return $this->superShare->getShareOwner(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @return \OCP\Share\IShare |
|
| 339 | + */ |
|
| 340 | + public function getShare() { |
|
| 341 | + return $this->superShare; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * return share type, can be "file" or "folder" |
|
| 346 | + * |
|
| 347 | + * @return string |
|
| 348 | + */ |
|
| 349 | + public function getItemType() { |
|
| 350 | + return $this->superShare->getNodeType(); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @param string $path |
|
| 355 | + * @param null $storage |
|
| 356 | + * @return Cache |
|
| 357 | + */ |
|
| 358 | + public function getCache($path = '', $storage = null) { |
|
| 359 | + if ($this->cache) { |
|
| 360 | + return $this->cache; |
|
| 361 | + } |
|
| 362 | + if (!$storage) { |
|
| 363 | + $storage = $this; |
|
| 364 | + } |
|
| 365 | + if ($this->storage instanceof FailedStorage) { |
|
| 366 | + return new FailedCache(); |
|
| 367 | + } |
|
| 368 | + $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare); |
|
| 369 | + return $this->cache; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + public function getScanner($path = '', $storage = null) { |
|
| 373 | + if (!$storage) { |
|
| 374 | + $storage = $this; |
|
| 375 | + } |
|
| 376 | + return new \OCA\Files_Sharing\Scanner($storage); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + public function getPropagator($storage = null) { |
|
| 380 | + if (isset($this->propagator)) { |
|
| 381 | + return $this->propagator; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if (!$storage) { |
|
| 385 | + $storage = $this; |
|
| 386 | + } |
|
| 387 | + $this->propagator = new \OCA\Files_Sharing\SharedPropagator($storage, \OC::$server->getDatabaseConnection()); |
|
| 388 | + return $this->propagator; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + public function getOwner($path) { |
|
| 392 | + return $this->superShare->getShareOwner(); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * unshare complete storage, also the grouped shares |
|
| 397 | + * |
|
| 398 | + * @return bool |
|
| 399 | + */ |
|
| 400 | + public function unshareStorage() { |
|
| 401 | + foreach ($this->groupedShares as $share) { |
|
| 402 | + \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
| 403 | + } |
|
| 404 | + return true; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @param string $path |
|
| 409 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 410 | + * @param \OCP\Lock\ILockingProvider $provider |
|
| 411 | + * @throws \OCP\Lock\LockedException |
|
| 412 | + */ |
|
| 413 | + public function acquireLock($path, $type, ILockingProvider $provider) { |
|
| 414 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
| 415 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 416 | + $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
| 417 | + // lock the parent folders of the owner when locking the share as recipient |
|
| 418 | + if ($path === '') { |
|
| 419 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 420 | + $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * @param string $path |
|
| 426 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 427 | + * @param \OCP\Lock\ILockingProvider $provider |
|
| 428 | + */ |
|
| 429 | + public function releaseLock($path, $type, ILockingProvider $provider) { |
|
| 430 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
| 431 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 432 | + $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
| 433 | + // unlock the parent folders of the owner when unlocking the share as recipient |
|
| 434 | + if ($path === '') { |
|
| 435 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
| 436 | + $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @param string $path |
|
| 442 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
| 443 | + * @param \OCP\Lock\ILockingProvider $provider |
|
| 444 | + */ |
|
| 445 | + public function changeLock($path, $type, ILockingProvider $provider) { |
|
| 446 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
| 447 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
| 448 | + $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @return array [ available, last_checked ] |
|
| 453 | + */ |
|
| 454 | + public function getAvailability() { |
|
| 455 | + // shares do not participate in availability logic |
|
| 456 | + return [ |
|
| 457 | + 'available' => true, |
|
| 458 | + 'last_checked' => 0 |
|
| 459 | + ]; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * @param bool $available |
|
| 464 | + */ |
|
| 465 | + public function setAvailability($available) { |
|
| 466 | + // shares do not participate in availability logic |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + public function getSourceStorage() { |
|
| 470 | + $this->init(); |
|
| 471 | + return $this->nonMaskedStorage; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + public function getWrapperStorage() { |
|
| 475 | + $this->init(); |
|
| 476 | + return $this->storage; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + public function file_get_contents($path) { |
|
| 480 | + $info = [ |
|
| 481 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
| 482 | + 'source' => $this->getSourcePath($path), |
|
| 483 | + ]; |
|
| 484 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
| 485 | + return parent::file_get_contents($path); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + public function file_put_contents($path, $data) { |
|
| 489 | + $info = [ |
|
| 490 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
| 491 | + 'source' => $this->getSourcePath($path), |
|
| 492 | + ]; |
|
| 493 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
| 494 | + return parent::file_put_contents($path, $data); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + public function setMountOptions(array $options) { |
|
| 498 | + $this->mountOptions = $options; |
|
| 499 | + } |
|
| 500 | 500 | } |