@@ -25,28 +25,28 @@ |
||
| 25 | 25 | |
| 26 | 26 | class CloudFederationNotification implements ICloudFederationNotification { |
| 27 | 27 | |
| 28 | - private $message = []; |
|
| 28 | + private $message = []; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * add a message to the notification |
|
| 32 | - * |
|
| 33 | - * @param string $identifier |
|
| 34 | - * @param string $message |
|
| 35 | - * |
|
| 36 | - * @since 14.0.0 |
|
| 37 | - */ |
|
| 38 | - public function setMessage($identifier, $message) { |
|
| 39 | - $this->message[$identifier] = $message; |
|
| 40 | - } |
|
| 30 | + /** |
|
| 31 | + * add a message to the notification |
|
| 32 | + * |
|
| 33 | + * @param string $identifier |
|
| 34 | + * @param string $message |
|
| 35 | + * |
|
| 36 | + * @since 14.0.0 |
|
| 37 | + */ |
|
| 38 | + public function setMessage($identifier, $message) { |
|
| 39 | + $this->message[$identifier] = $message; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * get message, ready to send out |
|
| 44 | - * |
|
| 45 | - * @return array |
|
| 46 | - * |
|
| 47 | - * @since 14.0.0 |
|
| 48 | - */ |
|
| 49 | - public function getMessage() { |
|
| 50 | - return $this->message; |
|
| 51 | - } |
|
| 42 | + /** |
|
| 43 | + * get message, ready to send out |
|
| 44 | + * |
|
| 45 | + * @return array |
|
| 46 | + * |
|
| 47 | + * @since 14.0.0 |
|
| 48 | + */ |
|
| 49 | + public function getMessage() { |
|
| 50 | + return $this->message; |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -42,186 +42,186 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class CloudFederationProviderManager implements ICloudFederationProviderManager { |
| 44 | 44 | |
| 45 | - /** @var array list of available cloud federation providers */ |
|
| 46 | - private $cloudFederationProvider; |
|
| 47 | - |
|
| 48 | - /** @var IAppManager */ |
|
| 49 | - private $appManager; |
|
| 50 | - |
|
| 51 | - /** @var IClientService */ |
|
| 52 | - private $httpClientService; |
|
| 53 | - |
|
| 54 | - /** @var ICloudIdManager */ |
|
| 55 | - private $cloudIdManager; |
|
| 56 | - |
|
| 57 | - /** @var ILogger */ |
|
| 58 | - private $logger; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * CloudFederationProviderManager constructor. |
|
| 62 | - * |
|
| 63 | - * @param IAppManager $appManager |
|
| 64 | - * @param IClientService $httpClientService |
|
| 65 | - * @param ICloudIdManager $cloudIdManager |
|
| 66 | - * @param ILogger $logger |
|
| 67 | - */ |
|
| 68 | - public function __construct(IAppManager $appManager, |
|
| 69 | - IClientService $httpClientService, |
|
| 70 | - ICloudIdManager $cloudIdManager, |
|
| 71 | - ILogger $logger) { |
|
| 72 | - $this->cloudFederationProvider= []; |
|
| 73 | - $this->appManager = $appManager; |
|
| 74 | - $this->httpClientService = $httpClientService; |
|
| 75 | - $this->cloudIdManager = $cloudIdManager; |
|
| 76 | - $this->logger = $logger; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Registers an callback function which must return an cloud federation provider |
|
| 82 | - * |
|
| 83 | - * @param string $shareType which share type does the provider handles |
|
| 84 | - * @param string $displayName user facing name of the federated share provider |
|
| 85 | - * @param callable $callback |
|
| 86 | - */ |
|
| 87 | - public function addCloudFederationProvider($shareType, $displayName, callable $callback) { |
|
| 88 | - \OC::$server->getRemoteApiFactory(); |
|
| 89 | - |
|
| 90 | - $this->cloudFederationProvider[$shareType] = [ |
|
| 91 | - 'shareType' => $shareType, |
|
| 92 | - 'displayName' => $displayName, |
|
| 93 | - 'callback' => $callback, |
|
| 94 | - ]; |
|
| 95 | - |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * remove cloud federation provider |
|
| 100 | - * |
|
| 101 | - * @param string $providerId |
|
| 102 | - */ |
|
| 103 | - public function removeCloudFederationProvider($providerId) { |
|
| 104 | - unset($this->cloudFederationProvider[$providerId]); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * get a list of all cloudFederationProviders |
|
| 109 | - * |
|
| 110 | - * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
| 111 | - */ |
|
| 112 | - public function getAllCloudFederationProviders() { |
|
| 113 | - return $this->cloudFederationProvider; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * get a specific cloud federation provider |
|
| 118 | - * |
|
| 119 | - * @param string $shareType |
|
| 120 | - * @return ICloudFederationProvider |
|
| 121 | - * @throws ProviderDoesNotExistsException |
|
| 122 | - */ |
|
| 123 | - public function getCloudFederationProvider($shareType) { |
|
| 124 | - if (isset($this->cloudFederationProvider[$shareType])) { |
|
| 125 | - return call_user_func($this->cloudFederationProvider[$shareType]['callback']); |
|
| 126 | - } else { |
|
| 127 | - throw new ProviderDoesNotExistsException($shareType); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - public function sendShare(ICloudFederationShare $share) { |
|
| 132 | - $ocmEndPoint = $this->getOCMEndPoint($share->getShareWith()); |
|
| 133 | - |
|
| 134 | - if (empty($ocmEndPoint)) { |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $client = $this->httpClientService->newClient(); |
|
| 139 | - try { |
|
| 140 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
| 141 | - 'body' => $share->getShare(), |
|
| 142 | - 'timeout' => 10, |
|
| 143 | - 'connect_timeout' => 10, |
|
| 144 | - ]); |
|
| 145 | - |
|
| 146 | - if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 147 | - return true; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - } catch (\Exception $e) { |
|
| 151 | - // if flat re-sharing is not supported by the remote server |
|
| 152 | - // we re-throw the exception and fall back to the old behaviour. |
|
| 153 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
| 154 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
| 155 | - throw $e; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return false; |
|
| 160 | - |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param string $url |
|
| 165 | - * @param ICloudFederationNotification $notification |
|
| 166 | - * @return bool |
|
| 167 | - */ |
|
| 168 | - public function sendNotification($url, ICloudFederationNotification $notification) { |
|
| 169 | - $ocmEndPoint = $this->getOCMEndPoint($url); |
|
| 170 | - |
|
| 171 | - if (empty($ocmEndPoint)) { |
|
| 172 | - return false; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - $client = $this->httpClientService->newClient(); |
|
| 176 | - try { |
|
| 177 | - $response = $client->post($ocmEndPoint . '/notifications', [ |
|
| 178 | - 'body' => $notification->getMessage(), |
|
| 179 | - 'timeout' => 10, |
|
| 180 | - 'connect_timeout' => 10, |
|
| 181 | - ]); |
|
| 182 | - if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 183 | - return true; |
|
| 184 | - } |
|
| 185 | - } catch (\Exception $e) { |
|
| 186 | - // log the error and return false |
|
| 187 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * check if the new cloud federation API is ready to be used |
|
| 195 | - * |
|
| 196 | - * @return bool |
|
| 197 | - */ |
|
| 198 | - public function isReady() { |
|
| 199 | - return $this->appManager->isEnabledForUser('cloud_federation_api', false); |
|
| 200 | - } |
|
| 201 | - /** |
|
| 202 | - * check if server supports the new OCM api and ask for the correct end-point |
|
| 203 | - * |
|
| 204 | - * @param string $recipient full federated cloud ID of the recipient of a share |
|
| 205 | - * @return string |
|
| 206 | - */ |
|
| 207 | - protected function getOCMEndPoint($recipient) { |
|
| 208 | - $cloudId = $this->cloudIdManager->resolveCloudId($recipient); |
|
| 209 | - $client = $this->httpClientService->newClient(); |
|
| 210 | - try { |
|
| 211 | - $response = $client->get($cloudId->getRemote() . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
| 212 | - } catch (\Exception $e) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $result = $response->getBody(); |
|
| 217 | - $result = json_decode($result, true); |
|
| 218 | - |
|
| 219 | - if (isset($result['end-point'])) { |
|
| 220 | - return $result['end-point']; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return ''; |
|
| 224 | - } |
|
| 45 | + /** @var array list of available cloud federation providers */ |
|
| 46 | + private $cloudFederationProvider; |
|
| 47 | + |
|
| 48 | + /** @var IAppManager */ |
|
| 49 | + private $appManager; |
|
| 50 | + |
|
| 51 | + /** @var IClientService */ |
|
| 52 | + private $httpClientService; |
|
| 53 | + |
|
| 54 | + /** @var ICloudIdManager */ |
|
| 55 | + private $cloudIdManager; |
|
| 56 | + |
|
| 57 | + /** @var ILogger */ |
|
| 58 | + private $logger; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * CloudFederationProviderManager constructor. |
|
| 62 | + * |
|
| 63 | + * @param IAppManager $appManager |
|
| 64 | + * @param IClientService $httpClientService |
|
| 65 | + * @param ICloudIdManager $cloudIdManager |
|
| 66 | + * @param ILogger $logger |
|
| 67 | + */ |
|
| 68 | + public function __construct(IAppManager $appManager, |
|
| 69 | + IClientService $httpClientService, |
|
| 70 | + ICloudIdManager $cloudIdManager, |
|
| 71 | + ILogger $logger) { |
|
| 72 | + $this->cloudFederationProvider= []; |
|
| 73 | + $this->appManager = $appManager; |
|
| 74 | + $this->httpClientService = $httpClientService; |
|
| 75 | + $this->cloudIdManager = $cloudIdManager; |
|
| 76 | + $this->logger = $logger; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Registers an callback function which must return an cloud federation provider |
|
| 82 | + * |
|
| 83 | + * @param string $shareType which share type does the provider handles |
|
| 84 | + * @param string $displayName user facing name of the federated share provider |
|
| 85 | + * @param callable $callback |
|
| 86 | + */ |
|
| 87 | + public function addCloudFederationProvider($shareType, $displayName, callable $callback) { |
|
| 88 | + \OC::$server->getRemoteApiFactory(); |
|
| 89 | + |
|
| 90 | + $this->cloudFederationProvider[$shareType] = [ |
|
| 91 | + 'shareType' => $shareType, |
|
| 92 | + 'displayName' => $displayName, |
|
| 93 | + 'callback' => $callback, |
|
| 94 | + ]; |
|
| 95 | + |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * remove cloud federation provider |
|
| 100 | + * |
|
| 101 | + * @param string $providerId |
|
| 102 | + */ |
|
| 103 | + public function removeCloudFederationProvider($providerId) { |
|
| 104 | + unset($this->cloudFederationProvider[$providerId]); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * get a list of all cloudFederationProviders |
|
| 109 | + * |
|
| 110 | + * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
| 111 | + */ |
|
| 112 | + public function getAllCloudFederationProviders() { |
|
| 113 | + return $this->cloudFederationProvider; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * get a specific cloud federation provider |
|
| 118 | + * |
|
| 119 | + * @param string $shareType |
|
| 120 | + * @return ICloudFederationProvider |
|
| 121 | + * @throws ProviderDoesNotExistsException |
|
| 122 | + */ |
|
| 123 | + public function getCloudFederationProvider($shareType) { |
|
| 124 | + if (isset($this->cloudFederationProvider[$shareType])) { |
|
| 125 | + return call_user_func($this->cloudFederationProvider[$shareType]['callback']); |
|
| 126 | + } else { |
|
| 127 | + throw new ProviderDoesNotExistsException($shareType); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + public function sendShare(ICloudFederationShare $share) { |
|
| 132 | + $ocmEndPoint = $this->getOCMEndPoint($share->getShareWith()); |
|
| 133 | + |
|
| 134 | + if (empty($ocmEndPoint)) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $client = $this->httpClientService->newClient(); |
|
| 139 | + try { |
|
| 140 | + $response = $client->post($ocmEndPoint . '/shares', [ |
|
| 141 | + 'body' => $share->getShare(), |
|
| 142 | + 'timeout' => 10, |
|
| 143 | + 'connect_timeout' => 10, |
|
| 144 | + ]); |
|
| 145 | + |
|
| 146 | + if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 147 | + return true; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + } catch (\Exception $e) { |
|
| 151 | + // if flat re-sharing is not supported by the remote server |
|
| 152 | + // we re-throw the exception and fall back to the old behaviour. |
|
| 153 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
| 154 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
| 155 | + throw $e; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return false; |
|
| 160 | + |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param string $url |
|
| 165 | + * @param ICloudFederationNotification $notification |
|
| 166 | + * @return bool |
|
| 167 | + */ |
|
| 168 | + public function sendNotification($url, ICloudFederationNotification $notification) { |
|
| 169 | + $ocmEndPoint = $this->getOCMEndPoint($url); |
|
| 170 | + |
|
| 171 | + if (empty($ocmEndPoint)) { |
|
| 172 | + return false; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + $client = $this->httpClientService->newClient(); |
|
| 176 | + try { |
|
| 177 | + $response = $client->post($ocmEndPoint . '/notifications', [ |
|
| 178 | + 'body' => $notification->getMessage(), |
|
| 179 | + 'timeout' => 10, |
|
| 180 | + 'connect_timeout' => 10, |
|
| 181 | + ]); |
|
| 182 | + if ($response->getStatusCode() === Http::STATUS_OK) { |
|
| 183 | + return true; |
|
| 184 | + } |
|
| 185 | + } catch (\Exception $e) { |
|
| 186 | + // log the error and return false |
|
| 187 | + $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * check if the new cloud federation API is ready to be used |
|
| 195 | + * |
|
| 196 | + * @return bool |
|
| 197 | + */ |
|
| 198 | + public function isReady() { |
|
| 199 | + return $this->appManager->isEnabledForUser('cloud_federation_api', false); |
|
| 200 | + } |
|
| 201 | + /** |
|
| 202 | + * check if server supports the new OCM api and ask for the correct end-point |
|
| 203 | + * |
|
| 204 | + * @param string $recipient full federated cloud ID of the recipient of a share |
|
| 205 | + * @return string |
|
| 206 | + */ |
|
| 207 | + protected function getOCMEndPoint($recipient) { |
|
| 208 | + $cloudId = $this->cloudIdManager->resolveCloudId($recipient); |
|
| 209 | + $client = $this->httpClientService->newClient(); |
|
| 210 | + try { |
|
| 211 | + $response = $client->get($cloudId->getRemote() . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
| 212 | + } catch (\Exception $e) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $result = $response->getBody(); |
|
| 217 | + $result = json_decode($result, true); |
|
| 218 | + |
|
| 219 | + if (isset($result['end-point'])) { |
|
| 220 | + return $result['end-point']; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return ''; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | 226 | |
| 227 | 227 | } |
@@ -23,22 +23,22 @@ |
||
| 23 | 23 | |
| 24 | 24 | interface ICloudFederationNotification { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * add a message to the notification |
|
| 28 | - * |
|
| 29 | - * @param string $identifier |
|
| 30 | - * @param string $message |
|
| 31 | - * |
|
| 32 | - * @since 14.0.0 |
|
| 33 | - */ |
|
| 34 | - public function setMessage($identifier, $message); |
|
| 26 | + /** |
|
| 27 | + * add a message to the notification |
|
| 28 | + * |
|
| 29 | + * @param string $identifier |
|
| 30 | + * @param string $message |
|
| 31 | + * |
|
| 32 | + * @since 14.0.0 |
|
| 33 | + */ |
|
| 34 | + public function setMessage($identifier, $message); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * get message, ready to send out |
|
| 38 | - * |
|
| 39 | - * @return string |
|
| 40 | - * |
|
| 41 | - * @since 14.0.0 |
|
| 42 | - */ |
|
| 43 | - public function getMessage(); |
|
| 36 | + /** |
|
| 37 | + * get message, ready to send out |
|
| 38 | + * |
|
| 39 | + * @return string |
|
| 40 | + * |
|
| 41 | + * @since 14.0.0 |
|
| 42 | + */ |
|
| 43 | + public function getMessage(); |
|
| 44 | 44 | } |
@@ -36,37 +36,37 @@ |
||
| 36 | 36 | |
| 37 | 37 | interface ICloudFederationProvider { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * get the name of the share type, handled by this provider |
|
| 41 | - * |
|
| 42 | - * @return string |
|
| 43 | - * |
|
| 44 | - * @since 14.0.0 |
|
| 45 | - */ |
|
| 46 | - public function getShareType(); |
|
| 39 | + /** |
|
| 40 | + * get the name of the share type, handled by this provider |
|
| 41 | + * |
|
| 42 | + * @return string |
|
| 43 | + * |
|
| 44 | + * @since 14.0.0 |
|
| 45 | + */ |
|
| 46 | + public function getShareType(); |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * share received from another server |
|
| 50 | - * |
|
| 51 | - * @param ICloudFederationShare $share |
|
| 52 | - * @return string provider specific unique ID of the share |
|
| 53 | - * |
|
| 54 | - * @throws ProviderCouldNotAddShareException |
|
| 55 | - * |
|
| 56 | - * @since 14.0.0 |
|
| 57 | - */ |
|
| 58 | - public function shareReceived(ICloudFederationShare $share); |
|
| 48 | + /** |
|
| 49 | + * share received from another server |
|
| 50 | + * |
|
| 51 | + * @param ICloudFederationShare $share |
|
| 52 | + * @return string provider specific unique ID of the share |
|
| 53 | + * |
|
| 54 | + * @throws ProviderCouldNotAddShareException |
|
| 55 | + * |
|
| 56 | + * @since 14.0.0 |
|
| 57 | + */ |
|
| 58 | + public function shareReceived(ICloudFederationShare $share); |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * notification received from another server |
|
| 62 | - * |
|
| 63 | - * @param string $id unique ID of a already existing share |
|
| 64 | - * @param array $notification provider specific notification |
|
| 65 | - * |
|
| 66 | - * @throws ShareNotFoundException |
|
| 67 | - * |
|
| 68 | - * @since 14.0.0 |
|
| 69 | - */ |
|
| 70 | - public function notificationReceived($id, $notification); |
|
| 60 | + /** |
|
| 61 | + * notification received from another server |
|
| 62 | + * |
|
| 63 | + * @param string $id unique ID of a already existing share |
|
| 64 | + * @param array $notification provider specific notification |
|
| 65 | + * |
|
| 66 | + * @throws ShareNotFoundException |
|
| 67 | + * |
|
| 68 | + * @since 14.0.0 |
|
| 69 | + */ |
|
| 70 | + public function notificationReceived($id, $notification); |
|
| 71 | 71 | |
| 72 | 72 | } |
@@ -32,76 +32,76 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface ICloudFederationProviderManager { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Registers an callback function which must return an cloud federation provider |
|
| 37 | - * |
|
| 38 | - * @param string $shareType which share type does the provider handles |
|
| 39 | - * @param string $displayName user facing name of the federated share provider |
|
| 40 | - * @param callable $callback |
|
| 41 | - * @throws Exceptions\ProviderAlreadyExistsException |
|
| 42 | - * |
|
| 43 | - * @since 14.0.0 |
|
| 44 | - */ |
|
| 45 | - public function addCloudFederationProvider($shareType, $displayName, callable $callback); |
|
| 35 | + /** |
|
| 36 | + * Registers an callback function which must return an cloud federation provider |
|
| 37 | + * |
|
| 38 | + * @param string $shareType which share type does the provider handles |
|
| 39 | + * @param string $displayName user facing name of the federated share provider |
|
| 40 | + * @param callable $callback |
|
| 41 | + * @throws Exceptions\ProviderAlreadyExistsException |
|
| 42 | + * |
|
| 43 | + * @since 14.0.0 |
|
| 44 | + */ |
|
| 45 | + public function addCloudFederationProvider($shareType, $displayName, callable $callback); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * remove cloud federation provider |
|
| 49 | - * |
|
| 50 | - * @param string $shareType |
|
| 51 | - * |
|
| 52 | - * @since 14.0.0 |
|
| 53 | - */ |
|
| 54 | - public function removeCloudFederationProvider($shareType); |
|
| 47 | + /** |
|
| 48 | + * remove cloud federation provider |
|
| 49 | + * |
|
| 50 | + * @param string $shareType |
|
| 51 | + * |
|
| 52 | + * @since 14.0.0 |
|
| 53 | + */ |
|
| 54 | + public function removeCloudFederationProvider($shareType); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * get a list of all cloudFederationProviders |
|
| 58 | - * |
|
| 59 | - * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
| 60 | - * |
|
| 61 | - * @since 14.0.0 |
|
| 62 | - */ |
|
| 63 | - public function getAllCloudFederationProviders(); |
|
| 56 | + /** |
|
| 57 | + * get a list of all cloudFederationProviders |
|
| 58 | + * |
|
| 59 | + * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
| 60 | + * |
|
| 61 | + * @since 14.0.0 |
|
| 62 | + */ |
|
| 63 | + public function getAllCloudFederationProviders(); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * get a specific cloud federation provider |
|
| 67 | - * |
|
| 68 | - * @param string $shareType |
|
| 69 | - * @return ICloudFederationProvider |
|
| 70 | - * @throws Exceptions\ProviderDoesNotExistsException; |
|
| 71 | - * |
|
| 72 | - * @since 14.0.0 |
|
| 73 | - */ |
|
| 74 | - public function getCloudFederationProvider($shareType); |
|
| 65 | + /** |
|
| 66 | + * get a specific cloud federation provider |
|
| 67 | + * |
|
| 68 | + * @param string $shareType |
|
| 69 | + * @return ICloudFederationProvider |
|
| 70 | + * @throws Exceptions\ProviderDoesNotExistsException; |
|
| 71 | + * |
|
| 72 | + * @since 14.0.0 |
|
| 73 | + */ |
|
| 74 | + public function getCloudFederationProvider($shareType); |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * send federated share |
|
| 78 | - * |
|
| 79 | - * @param ICloudFederationShare $share |
|
| 80 | - * @return mixed |
|
| 81 | - * |
|
| 82 | - * @since 14.0.0 |
|
| 83 | - */ |
|
| 84 | - public function sendShare(ICloudFederationShare $share); |
|
| 76 | + /** |
|
| 77 | + * send federated share |
|
| 78 | + * |
|
| 79 | + * @param ICloudFederationShare $share |
|
| 80 | + * @return mixed |
|
| 81 | + * |
|
| 82 | + * @since 14.0.0 |
|
| 83 | + */ |
|
| 84 | + public function sendShare(ICloudFederationShare $share); |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * send notification about existing share |
|
| 88 | - * |
|
| 89 | - * @param string $url |
|
| 90 | - * @param ICloudFederationNotification $notification |
|
| 91 | - * @return bool |
|
| 92 | - * |
|
| 93 | - * @since 14.0.0 |
|
| 94 | - */ |
|
| 95 | - public function sendNotification($url, ICloudFederationNotification $notification); |
|
| 86 | + /** |
|
| 87 | + * send notification about existing share |
|
| 88 | + * |
|
| 89 | + * @param string $url |
|
| 90 | + * @param ICloudFederationNotification $notification |
|
| 91 | + * @return bool |
|
| 92 | + * |
|
| 93 | + * @since 14.0.0 |
|
| 94 | + */ |
|
| 95 | + public function sendNotification($url, ICloudFederationNotification $notification); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * check if the new cloud federation API is ready to be used |
|
| 99 | - * |
|
| 100 | - * @return bool |
|
| 101 | - * |
|
| 102 | - * @since 14.0.0 |
|
| 103 | - */ |
|
| 104 | - public function isReady(); |
|
| 97 | + /** |
|
| 98 | + * check if the new cloud federation API is ready to be used |
|
| 99 | + * |
|
| 100 | + * @return bool |
|
| 101 | + * |
|
| 102 | + * @since 14.0.0 |
|
| 103 | + */ |
|
| 104 | + public function isReady(); |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | } |
@@ -44,496 +44,496 @@ |
||
| 44 | 44 | use OCP\Share; |
| 45 | 45 | |
| 46 | 46 | class Manager { |
| 47 | - const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - private $uid; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var IDBConnection |
|
| 56 | - */ |
|
| 57 | - private $connection; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var \OC\Files\Mount\Manager |
|
| 61 | - */ |
|
| 62 | - private $mountManager; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var IStorageFactory |
|
| 66 | - */ |
|
| 67 | - private $storageLoader; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @var IClientService |
|
| 71 | - */ |
|
| 72 | - private $clientService; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @var IManager |
|
| 76 | - */ |
|
| 77 | - private $notificationManager; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @var IDiscoveryService |
|
| 81 | - */ |
|
| 82 | - private $discoveryService; |
|
| 83 | - |
|
| 84 | - /** @var ICloudFederationProviderManager */ |
|
| 85 | - private $cloudFederationProviderManager; |
|
| 86 | - |
|
| 87 | - /** @var ICloudFederationFactory */ |
|
| 88 | - private $cloudFederationFactory; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @param IDBConnection $connection |
|
| 92 | - * @param \OC\Files\Mount\Manager $mountManager |
|
| 93 | - * @param IStorageFactory $storageLoader |
|
| 94 | - * @param IClientService $clientService |
|
| 95 | - * @param IManager $notificationManager |
|
| 96 | - * @param IDiscoveryService $discoveryService |
|
| 97 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 98 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
| 99 | - * @param string $uid |
|
| 100 | - */ |
|
| 101 | - public function __construct(IDBConnection $connection, |
|
| 102 | - \OC\Files\Mount\Manager $mountManager, |
|
| 103 | - IStorageFactory $storageLoader, |
|
| 104 | - IClientService $clientService, |
|
| 105 | - IManager $notificationManager, |
|
| 106 | - IDiscoveryService $discoveryService, |
|
| 107 | - ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 108 | - ICloudFederationFactory $cloudFederationFactory, |
|
| 109 | - $uid) { |
|
| 110 | - $this->connection = $connection; |
|
| 111 | - $this->mountManager = $mountManager; |
|
| 112 | - $this->storageLoader = $storageLoader; |
|
| 113 | - $this->clientService = $clientService; |
|
| 114 | - $this->uid = $uid; |
|
| 115 | - $this->notificationManager = $notificationManager; |
|
| 116 | - $this->discoveryService = $discoveryService; |
|
| 117 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 118 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * add new server-to-server share |
|
| 123 | - * |
|
| 124 | - * @param string $remote |
|
| 125 | - * @param string $token |
|
| 126 | - * @param string $password |
|
| 127 | - * @param string $name |
|
| 128 | - * @param string $owner |
|
| 129 | - * @param boolean $accepted |
|
| 130 | - * @param string $user |
|
| 131 | - * @param int $remoteId |
|
| 132 | - * @return Mount|null |
|
| 133 | - */ |
|
| 134 | - public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { |
|
| 135 | - |
|
| 136 | - $user = $user ? $user : $this->uid; |
|
| 137 | - $accepted = $accepted ? 1 : 0; |
|
| 138 | - $name = Filesystem::normalizePath('/' . $name); |
|
| 139 | - |
|
| 140 | - if (!$accepted) { |
|
| 141 | - // To avoid conflicts with the mount point generation later, |
|
| 142 | - // we only use a temporary mount point name here. The real |
|
| 143 | - // mount point name will be generated when accepting the share, |
|
| 144 | - // using the original share item name. |
|
| 145 | - $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
| 146 | - $mountPoint = $tmpMountPointName; |
|
| 147 | - $hash = md5($tmpMountPointName); |
|
| 148 | - $data = [ |
|
| 149 | - 'remote' => $remote, |
|
| 150 | - 'share_token' => $token, |
|
| 151 | - 'password' => $password, |
|
| 152 | - 'name' => $name, |
|
| 153 | - 'owner' => $owner, |
|
| 154 | - 'user' => $user, |
|
| 155 | - 'mountpoint' => $mountPoint, |
|
| 156 | - 'mountpoint_hash' => $hash, |
|
| 157 | - 'accepted' => $accepted, |
|
| 158 | - 'remote_id' => $remoteId, |
|
| 159 | - ]; |
|
| 160 | - |
|
| 161 | - $i = 1; |
|
| 162 | - while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
| 163 | - // The external share already exists for the user |
|
| 164 | - $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
| 165 | - $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
| 166 | - $i++; |
|
| 167 | - } |
|
| 168 | - return null; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
| 172 | - $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 173 | - $hash = md5($mountPoint); |
|
| 174 | - |
|
| 175 | - $query = $this->connection->prepare(' |
|
| 47 | + const STORAGE = '\OCA\Files_Sharing\External\Storage'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + private $uid; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var IDBConnection |
|
| 56 | + */ |
|
| 57 | + private $connection; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var \OC\Files\Mount\Manager |
|
| 61 | + */ |
|
| 62 | + private $mountManager; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var IStorageFactory |
|
| 66 | + */ |
|
| 67 | + private $storageLoader; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @var IClientService |
|
| 71 | + */ |
|
| 72 | + private $clientService; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @var IManager |
|
| 76 | + */ |
|
| 77 | + private $notificationManager; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @var IDiscoveryService |
|
| 81 | + */ |
|
| 82 | + private $discoveryService; |
|
| 83 | + |
|
| 84 | + /** @var ICloudFederationProviderManager */ |
|
| 85 | + private $cloudFederationProviderManager; |
|
| 86 | + |
|
| 87 | + /** @var ICloudFederationFactory */ |
|
| 88 | + private $cloudFederationFactory; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @param IDBConnection $connection |
|
| 92 | + * @param \OC\Files\Mount\Manager $mountManager |
|
| 93 | + * @param IStorageFactory $storageLoader |
|
| 94 | + * @param IClientService $clientService |
|
| 95 | + * @param IManager $notificationManager |
|
| 96 | + * @param IDiscoveryService $discoveryService |
|
| 97 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 98 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
| 99 | + * @param string $uid |
|
| 100 | + */ |
|
| 101 | + public function __construct(IDBConnection $connection, |
|
| 102 | + \OC\Files\Mount\Manager $mountManager, |
|
| 103 | + IStorageFactory $storageLoader, |
|
| 104 | + IClientService $clientService, |
|
| 105 | + IManager $notificationManager, |
|
| 106 | + IDiscoveryService $discoveryService, |
|
| 107 | + ICloudFederationProviderManager $cloudFederationProviderManager, |
|
| 108 | + ICloudFederationFactory $cloudFederationFactory, |
|
| 109 | + $uid) { |
|
| 110 | + $this->connection = $connection; |
|
| 111 | + $this->mountManager = $mountManager; |
|
| 112 | + $this->storageLoader = $storageLoader; |
|
| 113 | + $this->clientService = $clientService; |
|
| 114 | + $this->uid = $uid; |
|
| 115 | + $this->notificationManager = $notificationManager; |
|
| 116 | + $this->discoveryService = $discoveryService; |
|
| 117 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 118 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * add new server-to-server share |
|
| 123 | + * |
|
| 124 | + * @param string $remote |
|
| 125 | + * @param string $token |
|
| 126 | + * @param string $password |
|
| 127 | + * @param string $name |
|
| 128 | + * @param string $owner |
|
| 129 | + * @param boolean $accepted |
|
| 130 | + * @param string $user |
|
| 131 | + * @param int $remoteId |
|
| 132 | + * @return Mount|null |
|
| 133 | + */ |
|
| 134 | + public function addShare($remote, $token, $password, $name, $owner, $accepted=false, $user = null, $remoteId = -1) { |
|
| 135 | + |
|
| 136 | + $user = $user ? $user : $this->uid; |
|
| 137 | + $accepted = $accepted ? 1 : 0; |
|
| 138 | + $name = Filesystem::normalizePath('/' . $name); |
|
| 139 | + |
|
| 140 | + if (!$accepted) { |
|
| 141 | + // To avoid conflicts with the mount point generation later, |
|
| 142 | + // we only use a temporary mount point name here. The real |
|
| 143 | + // mount point name will be generated when accepting the share, |
|
| 144 | + // using the original share item name. |
|
| 145 | + $tmpMountPointName = '{{TemporaryMountPointName#' . $name . '}}'; |
|
| 146 | + $mountPoint = $tmpMountPointName; |
|
| 147 | + $hash = md5($tmpMountPointName); |
|
| 148 | + $data = [ |
|
| 149 | + 'remote' => $remote, |
|
| 150 | + 'share_token' => $token, |
|
| 151 | + 'password' => $password, |
|
| 152 | + 'name' => $name, |
|
| 153 | + 'owner' => $owner, |
|
| 154 | + 'user' => $user, |
|
| 155 | + 'mountpoint' => $mountPoint, |
|
| 156 | + 'mountpoint_hash' => $hash, |
|
| 157 | + 'accepted' => $accepted, |
|
| 158 | + 'remote_id' => $remoteId, |
|
| 159 | + ]; |
|
| 160 | + |
|
| 161 | + $i = 1; |
|
| 162 | + while (!$this->connection->insertIfNotExist('*PREFIX*share_external', $data, ['user', 'mountpoint_hash'])) { |
|
| 163 | + // The external share already exists for the user |
|
| 164 | + $data['mountpoint'] = $tmpMountPointName . '-' . $i; |
|
| 165 | + $data['mountpoint_hash'] = md5($data['mountpoint']); |
|
| 166 | + $i++; |
|
| 167 | + } |
|
| 168 | + return null; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $mountPoint = Files::buildNotExistingFileName('/', $name); |
|
| 172 | + $mountPoint = Filesystem::normalizePath('/' . $mountPoint); |
|
| 173 | + $hash = md5($mountPoint); |
|
| 174 | + |
|
| 175 | + $query = $this->connection->prepare(' |
|
| 176 | 176 | INSERT INTO `*PREFIX*share_external` |
| 177 | 177 | (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`) |
| 178 | 178 | VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| 179 | 179 | '); |
| 180 | - $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId)); |
|
| 181 | - |
|
| 182 | - $options = array( |
|
| 183 | - 'remote' => $remote, |
|
| 184 | - 'token' => $token, |
|
| 185 | - 'password' => $password, |
|
| 186 | - 'mountpoint' => $mountPoint, |
|
| 187 | - 'owner' => $owner |
|
| 188 | - ); |
|
| 189 | - return $this->mountShare($options); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * get share |
|
| 194 | - * |
|
| 195 | - * @param int $id share id |
|
| 196 | - * @return mixed share of false |
|
| 197 | - */ |
|
| 198 | - public function getShare($id) { |
|
| 199 | - $getShare = $this->connection->prepare(' |
|
| 180 | + $query->execute(array($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId)); |
|
| 181 | + |
|
| 182 | + $options = array( |
|
| 183 | + 'remote' => $remote, |
|
| 184 | + 'token' => $token, |
|
| 185 | + 'password' => $password, |
|
| 186 | + 'mountpoint' => $mountPoint, |
|
| 187 | + 'owner' => $owner |
|
| 188 | + ); |
|
| 189 | + return $this->mountShare($options); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * get share |
|
| 194 | + * |
|
| 195 | + * @param int $id share id |
|
| 196 | + * @return mixed share of false |
|
| 197 | + */ |
|
| 198 | + public function getShare($id) { |
|
| 199 | + $getShare = $this->connection->prepare(' |
|
| 200 | 200 | SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
| 201 | 201 | FROM `*PREFIX*share_external` |
| 202 | 202 | WHERE `id` = ? AND `user` = ?'); |
| 203 | - $result = $getShare->execute(array($id, $this->uid)); |
|
| 204 | - |
|
| 205 | - return $result ? $getShare->fetch() : false; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * accept server-to-server share |
|
| 210 | - * |
|
| 211 | - * @param int $id |
|
| 212 | - * @return bool True if the share could be accepted, false otherwise |
|
| 213 | - */ |
|
| 214 | - public function acceptShare($id) { |
|
| 215 | - |
|
| 216 | - $share = $this->getShare($id); |
|
| 217 | - $result = false; |
|
| 218 | - |
|
| 219 | - if ($share) { |
|
| 220 | - \OC_Util::setupFS($this->uid); |
|
| 221 | - $shareFolder = Helper::getShareFolder(); |
|
| 222 | - $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
| 223 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
| 224 | - $hash = md5($mountPoint); |
|
| 225 | - |
|
| 226 | - $acceptShare = $this->connection->prepare(' |
|
| 203 | + $result = $getShare->execute(array($id, $this->uid)); |
|
| 204 | + |
|
| 205 | + return $result ? $getShare->fetch() : false; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * accept server-to-server share |
|
| 210 | + * |
|
| 211 | + * @param int $id |
|
| 212 | + * @return bool True if the share could be accepted, false otherwise |
|
| 213 | + */ |
|
| 214 | + public function acceptShare($id) { |
|
| 215 | + |
|
| 216 | + $share = $this->getShare($id); |
|
| 217 | + $result = false; |
|
| 218 | + |
|
| 219 | + if ($share) { |
|
| 220 | + \OC_Util::setupFS($this->uid); |
|
| 221 | + $shareFolder = Helper::getShareFolder(); |
|
| 222 | + $mountPoint = Files::buildNotExistingFileName($shareFolder, $share['name']); |
|
| 223 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
| 224 | + $hash = md5($mountPoint); |
|
| 225 | + |
|
| 226 | + $acceptShare = $this->connection->prepare(' |
|
| 227 | 227 | UPDATE `*PREFIX*share_external` |
| 228 | 228 | SET `accepted` = ?, |
| 229 | 229 | `mountpoint` = ?, |
| 230 | 230 | `mountpoint_hash` = ? |
| 231 | 231 | WHERE `id` = ? AND `user` = ?'); |
| 232 | - $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
| 233 | - if ($updated === true) { |
|
| 234 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
| 235 | - \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); |
|
| 236 | - $result = true; |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // Make sure the user has no notification for something that does not exist anymore. |
|
| 241 | - $this->processNotification($id); |
|
| 242 | - |
|
| 243 | - return $result; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * decline server-to-server share |
|
| 248 | - * |
|
| 249 | - * @param int $id |
|
| 250 | - * @return bool True if the share could be declined, false otherwise |
|
| 251 | - */ |
|
| 252 | - public function declineShare($id) { |
|
| 253 | - |
|
| 254 | - $share = $this->getShare($id); |
|
| 255 | - |
|
| 256 | - if ($share) { |
|
| 257 | - $removeShare = $this->connection->prepare(' |
|
| 232 | + $updated = $acceptShare->execute(array(1, $mountPoint, $hash, $id, $this->uid)); |
|
| 233 | + if ($updated === true) { |
|
| 234 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); |
|
| 235 | + \OC_Hook::emit(Share::class, 'federated_share_added', ['server' => $share['remote']]); |
|
| 236 | + $result = true; |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // Make sure the user has no notification for something that does not exist anymore. |
|
| 241 | + $this->processNotification($id); |
|
| 242 | + |
|
| 243 | + return $result; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * decline server-to-server share |
|
| 248 | + * |
|
| 249 | + * @param int $id |
|
| 250 | + * @return bool True if the share could be declined, false otherwise |
|
| 251 | + */ |
|
| 252 | + public function declineShare($id) { |
|
| 253 | + |
|
| 254 | + $share = $this->getShare($id); |
|
| 255 | + |
|
| 256 | + if ($share) { |
|
| 257 | + $removeShare = $this->connection->prepare(' |
|
| 258 | 258 | DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'); |
| 259 | - $removeShare->execute(array($id, $this->uid)); |
|
| 260 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 261 | - |
|
| 262 | - $this->processNotification($id); |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return false; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @param int $remoteShare |
|
| 271 | - */ |
|
| 272 | - public function processNotification($remoteShare) { |
|
| 273 | - $filter = $this->notificationManager->createNotification(); |
|
| 274 | - $filter->setApp('files_sharing') |
|
| 275 | - ->setUser($this->uid) |
|
| 276 | - ->setObject('remote_share', (int) $remoteShare); |
|
| 277 | - $this->notificationManager->markProcessed($filter); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * inform remote server whether server-to-server share was accepted/declined |
|
| 282 | - * |
|
| 283 | - * @param string $remote |
|
| 284 | - * @param string $token |
|
| 285 | - * @param int $remoteId Share id on the remote host |
|
| 286 | - * @param string $feedback |
|
| 287 | - * @return boolean |
|
| 288 | - */ |
|
| 289 | - private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
| 290 | - |
|
| 291 | - $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
| 292 | - |
|
| 293 | - if($result === true) { |
|
| 294 | - return true; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
| 298 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
| 299 | - |
|
| 300 | - $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
| 301 | - $fields = array('token' => $token); |
|
| 302 | - |
|
| 303 | - $client = $this->clientService->newClient(); |
|
| 304 | - |
|
| 305 | - try { |
|
| 306 | - $response = $client->post( |
|
| 307 | - $url, |
|
| 308 | - [ |
|
| 309 | - 'body' => $fields, |
|
| 310 | - 'connect_timeout' => 10, |
|
| 311 | - ] |
|
| 312 | - ); |
|
| 313 | - } catch (\Exception $e) { |
|
| 314 | - return false; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - $status = json_decode($response->getBody(), true); |
|
| 318 | - |
|
| 319 | - return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * try send accept message to ocm end-point |
|
| 324 | - * |
|
| 325 | - * @param string $remoteDomain |
|
| 326 | - * @param string $token |
|
| 327 | - * @param $remoteId |
|
| 328 | - * @param string $feedback |
|
| 329 | - * @return mixed |
|
| 330 | - */ |
|
| 331 | - protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
| 332 | - switch ($feedback) { |
|
| 333 | - case 'accept': |
|
| 334 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 335 | - $notification->setMessage( |
|
| 336 | - [ |
|
| 337 | - 'access_token' => $token, |
|
| 338 | - 'id' => $remoteId, |
|
| 339 | - 'message' => 'accepted', |
|
| 340 | - 'createdAt' => time(), |
|
| 341 | - 'resourceType' => 'file' |
|
| 342 | - ] |
|
| 343 | - ); |
|
| 344 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * remove '/user/files' from the path and trailing slashes |
|
| 352 | - * |
|
| 353 | - * @param string $path |
|
| 354 | - * @return string |
|
| 355 | - */ |
|
| 356 | - protected function stripPath($path) { |
|
| 357 | - $prefix = '/' . $this->uid . '/files'; |
|
| 358 | - return rtrim(substr($path, strlen($prefix)), '/'); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - public function getMount($data) { |
|
| 362 | - $data['manager'] = $this; |
|
| 363 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 364 | - $data['mountpoint'] = $mountPoint; |
|
| 365 | - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
| 366 | - return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @param array $data |
|
| 371 | - * @return Mount |
|
| 372 | - */ |
|
| 373 | - protected function mountShare($data) { |
|
| 374 | - $mount = $this->getMount($data); |
|
| 375 | - $this->mountManager->addMount($mount); |
|
| 376 | - return $mount; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * @return \OC\Files\Mount\Manager |
|
| 381 | - */ |
|
| 382 | - public function getMountManager() { |
|
| 383 | - return $this->mountManager; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * @param string $source |
|
| 388 | - * @param string $target |
|
| 389 | - * @return bool |
|
| 390 | - */ |
|
| 391 | - public function setMountPoint($source, $target) { |
|
| 392 | - $source = $this->stripPath($source); |
|
| 393 | - $target = $this->stripPath($target); |
|
| 394 | - $sourceHash = md5($source); |
|
| 395 | - $targetHash = md5($target); |
|
| 396 | - |
|
| 397 | - $query = $this->connection->prepare(' |
|
| 259 | + $removeShare->execute(array($id, $this->uid)); |
|
| 260 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 261 | + |
|
| 262 | + $this->processNotification($id); |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @param int $remoteShare |
|
| 271 | + */ |
|
| 272 | + public function processNotification($remoteShare) { |
|
| 273 | + $filter = $this->notificationManager->createNotification(); |
|
| 274 | + $filter->setApp('files_sharing') |
|
| 275 | + ->setUser($this->uid) |
|
| 276 | + ->setObject('remote_share', (int) $remoteShare); |
|
| 277 | + $this->notificationManager->markProcessed($filter); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * inform remote server whether server-to-server share was accepted/declined |
|
| 282 | + * |
|
| 283 | + * @param string $remote |
|
| 284 | + * @param string $token |
|
| 285 | + * @param int $remoteId Share id on the remote host |
|
| 286 | + * @param string $feedback |
|
| 287 | + * @return boolean |
|
| 288 | + */ |
|
| 289 | + private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback) { |
|
| 290 | + |
|
| 291 | + $result = $this->tryOCMEndPoint($remote, $token, $remoteId, $feedback); |
|
| 292 | + |
|
| 293 | + if($result === true) { |
|
| 294 | + return true; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + $federationEndpoints = $this->discoveryService->discover($remote, 'FEDERATED_SHARING'); |
|
| 298 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
| 299 | + |
|
| 300 | + $url = rtrim($remote, '/') . $endpoint . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT; |
|
| 301 | + $fields = array('token' => $token); |
|
| 302 | + |
|
| 303 | + $client = $this->clientService->newClient(); |
|
| 304 | + |
|
| 305 | + try { |
|
| 306 | + $response = $client->post( |
|
| 307 | + $url, |
|
| 308 | + [ |
|
| 309 | + 'body' => $fields, |
|
| 310 | + 'connect_timeout' => 10, |
|
| 311 | + ] |
|
| 312 | + ); |
|
| 313 | + } catch (\Exception $e) { |
|
| 314 | + return false; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + $status = json_decode($response->getBody(), true); |
|
| 318 | + |
|
| 319 | + return ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * try send accept message to ocm end-point |
|
| 324 | + * |
|
| 325 | + * @param string $remoteDomain |
|
| 326 | + * @param string $token |
|
| 327 | + * @param $remoteId |
|
| 328 | + * @param string $feedback |
|
| 329 | + * @return mixed |
|
| 330 | + */ |
|
| 331 | + protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
| 332 | + switch ($feedback) { |
|
| 333 | + case 'accept': |
|
| 334 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 335 | + $notification->setMessage( |
|
| 336 | + [ |
|
| 337 | + 'access_token' => $token, |
|
| 338 | + 'id' => $remoteId, |
|
| 339 | + 'message' => 'accepted', |
|
| 340 | + 'createdAt' => time(), |
|
| 341 | + 'resourceType' => 'file' |
|
| 342 | + ] |
|
| 343 | + ); |
|
| 344 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * remove '/user/files' from the path and trailing slashes |
|
| 352 | + * |
|
| 353 | + * @param string $path |
|
| 354 | + * @return string |
|
| 355 | + */ |
|
| 356 | + protected function stripPath($path) { |
|
| 357 | + $prefix = '/' . $this->uid . '/files'; |
|
| 358 | + return rtrim(substr($path, strlen($prefix)), '/'); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + public function getMount($data) { |
|
| 362 | + $data['manager'] = $this; |
|
| 363 | + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 364 | + $data['mountpoint'] = $mountPoint; |
|
| 365 | + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
| 366 | + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @param array $data |
|
| 371 | + * @return Mount |
|
| 372 | + */ |
|
| 373 | + protected function mountShare($data) { |
|
| 374 | + $mount = $this->getMount($data); |
|
| 375 | + $this->mountManager->addMount($mount); |
|
| 376 | + return $mount; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * @return \OC\Files\Mount\Manager |
|
| 381 | + */ |
|
| 382 | + public function getMountManager() { |
|
| 383 | + return $this->mountManager; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * @param string $source |
|
| 388 | + * @param string $target |
|
| 389 | + * @return bool |
|
| 390 | + */ |
|
| 391 | + public function setMountPoint($source, $target) { |
|
| 392 | + $source = $this->stripPath($source); |
|
| 393 | + $target = $this->stripPath($target); |
|
| 394 | + $sourceHash = md5($source); |
|
| 395 | + $targetHash = md5($target); |
|
| 396 | + |
|
| 397 | + $query = $this->connection->prepare(' |
|
| 398 | 398 | UPDATE `*PREFIX*share_external` |
| 399 | 399 | SET `mountpoint` = ?, `mountpoint_hash` = ? |
| 400 | 400 | WHERE `mountpoint_hash` = ? |
| 401 | 401 | AND `user` = ? |
| 402 | 402 | '); |
| 403 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
| 403 | + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
| 404 | 404 | |
| 405 | - return $result; |
|
| 406 | - } |
|
| 405 | + return $result; |
|
| 406 | + } |
|
| 407 | 407 | |
| 408 | - public function removeShare($mountPoint) { |
|
| 408 | + public function removeShare($mountPoint) { |
|
| 409 | 409 | |
| 410 | - $mountPointObj = $this->mountManager->find($mountPoint); |
|
| 411 | - $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
| 410 | + $mountPointObj = $this->mountManager->find($mountPoint); |
|
| 411 | + $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
| 412 | 412 | |
| 413 | - $mountPoint = $this->stripPath($mountPoint); |
|
| 414 | - $hash = md5($mountPoint); |
|
| 413 | + $mountPoint = $this->stripPath($mountPoint); |
|
| 414 | + $hash = md5($mountPoint); |
|
| 415 | 415 | |
| 416 | - $getShare = $this->connection->prepare(' |
|
| 416 | + $getShare = $this->connection->prepare(' |
|
| 417 | 417 | SELECT `remote`, `share_token`, `remote_id` |
| 418 | 418 | FROM `*PREFIX*share_external` |
| 419 | 419 | WHERE `mountpoint_hash` = ? AND `user` = ?'); |
| 420 | - $result = $getShare->execute(array($hash, $this->uid)); |
|
| 421 | - |
|
| 422 | - if ($result) { |
|
| 423 | - try { |
|
| 424 | - $share = $getShare->fetch(); |
|
| 425 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 426 | - } catch (\Exception $e) { |
|
| 427 | - // if we fail to notify the remote (probably cause the remote is down) |
|
| 428 | - // we still want the share to be gone to prevent undeletable remotes |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - $getShare->closeCursor(); |
|
| 432 | - |
|
| 433 | - $query = $this->connection->prepare(' |
|
| 420 | + $result = $getShare->execute(array($hash, $this->uid)); |
|
| 421 | + |
|
| 422 | + if ($result) { |
|
| 423 | + try { |
|
| 424 | + $share = $getShare->fetch(); |
|
| 425 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 426 | + } catch (\Exception $e) { |
|
| 427 | + // if we fail to notify the remote (probably cause the remote is down) |
|
| 428 | + // we still want the share to be gone to prevent undeletable remotes |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + $getShare->closeCursor(); |
|
| 432 | + |
|
| 433 | + $query = $this->connection->prepare(' |
|
| 434 | 434 | DELETE FROM `*PREFIX*share_external` |
| 435 | 435 | WHERE `mountpoint_hash` = ? |
| 436 | 436 | AND `user` = ? |
| 437 | 437 | '); |
| 438 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
| 439 | - |
|
| 440 | - if($result) { |
|
| 441 | - $this->removeReShares($id); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - return $result; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * remove re-shares from share table and mapping in the federated_reshares table |
|
| 449 | - * |
|
| 450 | - * @param $mountPointId |
|
| 451 | - */ |
|
| 452 | - protected function removeReShares($mountPointId) { |
|
| 453 | - $selectQuery = $this->connection->getQueryBuilder(); |
|
| 454 | - $query = $this->connection->getQueryBuilder(); |
|
| 455 | - $selectQuery->select('id')->from('share') |
|
| 456 | - ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
| 457 | - $select = $selectQuery->getSQL(); |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - $query->delete('federated_reshares') |
|
| 461 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 462 | - $query->execute(); |
|
| 463 | - |
|
| 464 | - $deleteReShares = $this->connection->getQueryBuilder(); |
|
| 465 | - $deleteReShares->delete('share') |
|
| 466 | - ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
| 467 | - $deleteReShares->execute(); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * remove all shares for user $uid if the user was deleted |
|
| 472 | - * |
|
| 473 | - * @param string $uid |
|
| 474 | - * @return bool |
|
| 475 | - */ |
|
| 476 | - public function removeUserShares($uid) { |
|
| 477 | - $getShare = $this->connection->prepare(' |
|
| 438 | + $result = (bool)$query->execute(array($hash, $this->uid)); |
|
| 439 | + |
|
| 440 | + if($result) { |
|
| 441 | + $this->removeReShares($id); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + return $result; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * remove re-shares from share table and mapping in the federated_reshares table |
|
| 449 | + * |
|
| 450 | + * @param $mountPointId |
|
| 451 | + */ |
|
| 452 | + protected function removeReShares($mountPointId) { |
|
| 453 | + $selectQuery = $this->connection->getQueryBuilder(); |
|
| 454 | + $query = $this->connection->getQueryBuilder(); |
|
| 455 | + $selectQuery->select('id')->from('share') |
|
| 456 | + ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
| 457 | + $select = $selectQuery->getSQL(); |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + $query->delete('federated_reshares') |
|
| 461 | + ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 462 | + $query->execute(); |
|
| 463 | + |
|
| 464 | + $deleteReShares = $this->connection->getQueryBuilder(); |
|
| 465 | + $deleteReShares->delete('share') |
|
| 466 | + ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
| 467 | + $deleteReShares->execute(); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * remove all shares for user $uid if the user was deleted |
|
| 472 | + * |
|
| 473 | + * @param string $uid |
|
| 474 | + * @return bool |
|
| 475 | + */ |
|
| 476 | + public function removeUserShares($uid) { |
|
| 477 | + $getShare = $this->connection->prepare(' |
|
| 478 | 478 | SELECT `remote`, `share_token`, `remote_id` |
| 479 | 479 | FROM `*PREFIX*share_external` |
| 480 | 480 | WHERE `user` = ?'); |
| 481 | - $result = $getShare->execute(array($uid)); |
|
| 481 | + $result = $getShare->execute(array($uid)); |
|
| 482 | 482 | |
| 483 | - if ($result) { |
|
| 484 | - $shares = $getShare->fetchAll(); |
|
| 485 | - foreach($shares as $share) { |
|
| 486 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 487 | - } |
|
| 488 | - } |
|
| 483 | + if ($result) { |
|
| 484 | + $shares = $getShare->fetchAll(); |
|
| 485 | + foreach($shares as $share) { |
|
| 486 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | 489 | |
| 490 | - $query = $this->connection->prepare(' |
|
| 490 | + $query = $this->connection->prepare(' |
|
| 491 | 491 | DELETE FROM `*PREFIX*share_external` |
| 492 | 492 | WHERE `user` = ? |
| 493 | 493 | '); |
| 494 | - return (bool)$query->execute(array($uid)); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * return a list of shares which are not yet accepted by the user |
|
| 499 | - * |
|
| 500 | - * @return array list of open server-to-server shares |
|
| 501 | - */ |
|
| 502 | - public function getOpenShares() { |
|
| 503 | - return $this->getShares(false); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * return a list of shares which are accepted by the user |
|
| 508 | - * |
|
| 509 | - * @return array list of accepted server-to-server shares |
|
| 510 | - */ |
|
| 511 | - public function getAcceptedShares() { |
|
| 512 | - return $this->getShares(true); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * return a list of shares for the user |
|
| 517 | - * |
|
| 518 | - * @param bool|null $accepted True for accepted only, |
|
| 519 | - * false for not accepted, |
|
| 520 | - * null for all shares of the user |
|
| 521 | - * @return array list of open server-to-server shares |
|
| 522 | - */ |
|
| 523 | - private function getShares($accepted) { |
|
| 524 | - $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
| 494 | + return (bool)$query->execute(array($uid)); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * return a list of shares which are not yet accepted by the user |
|
| 499 | + * |
|
| 500 | + * @return array list of open server-to-server shares |
|
| 501 | + */ |
|
| 502 | + public function getOpenShares() { |
|
| 503 | + return $this->getShares(false); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * return a list of shares which are accepted by the user |
|
| 508 | + * |
|
| 509 | + * @return array list of accepted server-to-server shares |
|
| 510 | + */ |
|
| 511 | + public function getAcceptedShares() { |
|
| 512 | + return $this->getShares(true); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * return a list of shares for the user |
|
| 517 | + * |
|
| 518 | + * @param bool|null $accepted True for accepted only, |
|
| 519 | + * false for not accepted, |
|
| 520 | + * null for all shares of the user |
|
| 521 | + * @return array list of open server-to-server shares |
|
| 522 | + */ |
|
| 523 | + private function getShares($accepted) { |
|
| 524 | + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
| 525 | 525 | FROM `*PREFIX*share_external` |
| 526 | 526 | WHERE `user` = ?'; |
| 527 | - $parameters = [$this->uid]; |
|
| 528 | - if (!is_null($accepted)) { |
|
| 529 | - $query .= ' AND `accepted` = ?'; |
|
| 530 | - $parameters[] = (int) $accepted; |
|
| 531 | - } |
|
| 532 | - $query .= ' ORDER BY `id` ASC'; |
|
| 533 | - |
|
| 534 | - $shares = $this->connection->prepare($query); |
|
| 535 | - $result = $shares->execute($parameters); |
|
| 536 | - |
|
| 537 | - return $result ? $shares->fetchAll() : []; |
|
| 538 | - } |
|
| 527 | + $parameters = [$this->uid]; |
|
| 528 | + if (!is_null($accepted)) { |
|
| 529 | + $query .= ' AND `accepted` = ?'; |
|
| 530 | + $parameters[] = (int) $accepted; |
|
| 531 | + } |
|
| 532 | + $query .= ' ORDER BY `id` ASC'; |
|
| 533 | + |
|
| 534 | + $shares = $this->connection->prepare($query); |
|
| 535 | + $result = $shares->execute($parameters); |
|
| 536 | + |
|
| 537 | + return $result ? $shares->fetchAll() : []; |
|
| 538 | + } |
|
| 539 | 539 | } |
@@ -32,32 +32,32 @@ |
||
| 32 | 32 | |
| 33 | 33 | class Hooks { |
| 34 | 34 | |
| 35 | - public static function deleteUser($params) { |
|
| 36 | - $manager = new External\Manager( |
|
| 37 | - \OC::$server->getDatabaseConnection(), |
|
| 38 | - \OC\Files\Filesystem::getMountManager(), |
|
| 39 | - \OC\Files\Filesystem::getLoader(), |
|
| 40 | - \OC::$server->getHTTPClientService(), |
|
| 41 | - \OC::$server->getNotificationManager(), |
|
| 42 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 43 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 44 | - $params['uid']); |
|
| 35 | + public static function deleteUser($params) { |
|
| 36 | + $manager = new External\Manager( |
|
| 37 | + \OC::$server->getDatabaseConnection(), |
|
| 38 | + \OC\Files\Filesystem::getMountManager(), |
|
| 39 | + \OC\Files\Filesystem::getLoader(), |
|
| 40 | + \OC::$server->getHTTPClientService(), |
|
| 41 | + \OC::$server->getNotificationManager(), |
|
| 42 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 43 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 44 | + $params['uid']); |
|
| 45 | 45 | |
| 46 | - $manager->removeUserShares($params['uid']); |
|
| 47 | - } |
|
| 46 | + $manager->removeUserShares($params['uid']); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - public static function unshareChildren($params) { |
|
| 50 | - $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
| 51 | - $view = new \OC\Files\View('/'); |
|
| 49 | + public static function unshareChildren($params) { |
|
| 50 | + $path = Filesystem::getView()->getAbsolutePath($params['path']); |
|
| 51 | + $view = new \OC\Files\View('/'); |
|
| 52 | 52 | |
| 53 | - // find share mount points within $path and unmount them |
|
| 54 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 55 | - $mountedShares = $mountManager->findIn($path); |
|
| 56 | - foreach ($mountedShares as $mount) { |
|
| 57 | - if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { |
|
| 58 | - $mountPoint = $mount->getMountPoint(); |
|
| 59 | - $view->unlink($mountPoint); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 53 | + // find share mount points within $path and unmount them |
|
| 54 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 55 | + $mountedShares = $mountManager->findIn($path); |
|
| 56 | + foreach ($mountedShares as $mount) { |
|
| 57 | + if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) { |
|
| 58 | + $mountPoint = $mount->getMountPoint(); |
|
| 59 | + $view->unlink($mountPoint); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -45,135 +45,135 @@ |
||
| 45 | 45 | use OCA\Files_Sharing\External\Manager; |
| 46 | 46 | |
| 47 | 47 | class Application extends App { |
| 48 | - public function __construct(array $urlParams = array()) { |
|
| 49 | - parent::__construct('files_sharing', $urlParams); |
|
| 48 | + public function __construct(array $urlParams = array()) { |
|
| 49 | + parent::__construct('files_sharing', $urlParams); |
|
| 50 | 50 | |
| 51 | - $container = $this->getContainer(); |
|
| 52 | - /** @var IServerContainer $server */ |
|
| 53 | - $server = $container->getServer(); |
|
| 51 | + $container = $this->getContainer(); |
|
| 52 | + /** @var IServerContainer $server */ |
|
| 53 | + $server = $container->getServer(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Controllers |
|
| 57 | - */ |
|
| 58 | - $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
| 59 | - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 60 | - return new ShareController( |
|
| 61 | - $c->query('AppName'), |
|
| 62 | - $c->query('Request'), |
|
| 63 | - $server->getConfig(), |
|
| 64 | - $server->getURLGenerator(), |
|
| 65 | - $server->getUserManager(), |
|
| 66 | - $server->getLogger(), |
|
| 67 | - $server->getActivityManager(), |
|
| 68 | - $server->getShareManager(), |
|
| 69 | - $server->getSession(), |
|
| 70 | - $server->getPreviewManager(), |
|
| 71 | - $server->getRootFolder(), |
|
| 72 | - $federatedSharingApp->getFederatedShareProvider(), |
|
| 73 | - $server->getEventDispatcher(), |
|
| 74 | - $server->getL10N($c->query('AppName')), |
|
| 75 | - $server->query(Defaults::class) |
|
| 76 | - ); |
|
| 77 | - }); |
|
| 78 | - $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
| 79 | - return new ExternalSharesController( |
|
| 80 | - $c->query('AppName'), |
|
| 81 | - $c->query('Request'), |
|
| 82 | - $c->query('ExternalManager'), |
|
| 83 | - $c->query('HttpClientService') |
|
| 84 | - ); |
|
| 85 | - }); |
|
| 55 | + /** |
|
| 56 | + * Controllers |
|
| 57 | + */ |
|
| 58 | + $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
| 59 | + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
| 60 | + return new ShareController( |
|
| 61 | + $c->query('AppName'), |
|
| 62 | + $c->query('Request'), |
|
| 63 | + $server->getConfig(), |
|
| 64 | + $server->getURLGenerator(), |
|
| 65 | + $server->getUserManager(), |
|
| 66 | + $server->getLogger(), |
|
| 67 | + $server->getActivityManager(), |
|
| 68 | + $server->getShareManager(), |
|
| 69 | + $server->getSession(), |
|
| 70 | + $server->getPreviewManager(), |
|
| 71 | + $server->getRootFolder(), |
|
| 72 | + $federatedSharingApp->getFederatedShareProvider(), |
|
| 73 | + $server->getEventDispatcher(), |
|
| 74 | + $server->getL10N($c->query('AppName')), |
|
| 75 | + $server->query(Defaults::class) |
|
| 76 | + ); |
|
| 77 | + }); |
|
| 78 | + $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
| 79 | + return new ExternalSharesController( |
|
| 80 | + $c->query('AppName'), |
|
| 81 | + $c->query('Request'), |
|
| 82 | + $c->query('ExternalManager'), |
|
| 83 | + $c->query('HttpClientService') |
|
| 84 | + ); |
|
| 85 | + }); |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Core class wrappers |
|
| 89 | - */ |
|
| 90 | - $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
| 91 | - return $server->getHTTPClientService(); |
|
| 92 | - }); |
|
| 93 | - $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
| 94 | - return $server->getCloudIdManager(); |
|
| 95 | - }); |
|
| 96 | - $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
| 97 | - $user = $server->getUserSession()->getUser(); |
|
| 98 | - $uid = $user ? $user->getUID() : null; |
|
| 99 | - return new \OCA\Files_Sharing\External\Manager( |
|
| 100 | - $server->getDatabaseConnection(), |
|
| 101 | - \OC\Files\Filesystem::getMountManager(), |
|
| 102 | - \OC\Files\Filesystem::getLoader(), |
|
| 103 | - $server->getHTTPClientService(), |
|
| 104 | - $server->getNotificationManager(), |
|
| 105 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 106 | - $server->getCloudFederationProviderManager(), |
|
| 107 | - $uid |
|
| 108 | - ); |
|
| 109 | - }); |
|
| 110 | - $container->registerAlias(Manager::class, 'ExternalManager'); |
|
| 87 | + /** |
|
| 88 | + * Core class wrappers |
|
| 89 | + */ |
|
| 90 | + $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
| 91 | + return $server->getHTTPClientService(); |
|
| 92 | + }); |
|
| 93 | + $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
| 94 | + return $server->getCloudIdManager(); |
|
| 95 | + }); |
|
| 96 | + $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
| 97 | + $user = $server->getUserSession()->getUser(); |
|
| 98 | + $uid = $user ? $user->getUID() : null; |
|
| 99 | + return new \OCA\Files_Sharing\External\Manager( |
|
| 100 | + $server->getDatabaseConnection(), |
|
| 101 | + \OC\Files\Filesystem::getMountManager(), |
|
| 102 | + \OC\Files\Filesystem::getLoader(), |
|
| 103 | + $server->getHTTPClientService(), |
|
| 104 | + $server->getNotificationManager(), |
|
| 105 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 106 | + $server->getCloudFederationProviderManager(), |
|
| 107 | + $uid |
|
| 108 | + ); |
|
| 109 | + }); |
|
| 110 | + $container->registerAlias(Manager::class, 'ExternalManager'); |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Middleware |
|
| 114 | - */ |
|
| 115 | - $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
| 116 | - return new SharingCheckMiddleware( |
|
| 117 | - $c->query('AppName'), |
|
| 118 | - $server->getConfig(), |
|
| 119 | - $server->getAppManager(), |
|
| 120 | - $c['ControllerMethodReflector'], |
|
| 121 | - $server->getShareManager(), |
|
| 122 | - $server->getRequest() |
|
| 123 | - ); |
|
| 124 | - }); |
|
| 112 | + /** |
|
| 113 | + * Middleware |
|
| 114 | + */ |
|
| 115 | + $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
| 116 | + return new SharingCheckMiddleware( |
|
| 117 | + $c->query('AppName'), |
|
| 118 | + $server->getConfig(), |
|
| 119 | + $server->getAppManager(), |
|
| 120 | + $c['ControllerMethodReflector'], |
|
| 121 | + $server->getShareManager(), |
|
| 122 | + $server->getRequest() |
|
| 123 | + ); |
|
| 124 | + }); |
|
| 125 | 125 | |
| 126 | - $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
| 127 | - return new OCSShareAPIMiddleware( |
|
| 128 | - $server->getShareManager(), |
|
| 129 | - $server->getL10N($c->query('AppName')) |
|
| 130 | - ); |
|
| 131 | - }); |
|
| 126 | + $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
| 127 | + return new OCSShareAPIMiddleware( |
|
| 128 | + $server->getShareManager(), |
|
| 129 | + $server->getL10N($c->query('AppName')) |
|
| 130 | + ); |
|
| 131 | + }); |
|
| 132 | 132 | |
| 133 | - $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
| 134 | - return new ShareInfoMiddleware( |
|
| 135 | - $server->getShareManager() |
|
| 136 | - ); |
|
| 137 | - }); |
|
| 133 | + $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
| 134 | + return new ShareInfoMiddleware( |
|
| 135 | + $server->getShareManager() |
|
| 136 | + ); |
|
| 137 | + }); |
|
| 138 | 138 | |
| 139 | - // Execute middlewares |
|
| 140 | - $container->registerMiddleWare('SharingCheckMiddleware'); |
|
| 141 | - $container->registerMiddleWare('OCSShareAPIMiddleware'); |
|
| 142 | - $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
| 139 | + // Execute middlewares |
|
| 140 | + $container->registerMiddleWare('SharingCheckMiddleware'); |
|
| 141 | + $container->registerMiddleWare('OCSShareAPIMiddleware'); |
|
| 142 | + $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
| 143 | 143 | |
| 144 | - $container->registerService('MountProvider', function (IContainer $c) { |
|
| 145 | - /** @var \OCP\IServerContainer $server */ |
|
| 146 | - $server = $c->query('ServerContainer'); |
|
| 147 | - return new MountProvider( |
|
| 148 | - $server->getConfig(), |
|
| 149 | - $server->getShareManager(), |
|
| 150 | - $server->getLogger() |
|
| 151 | - ); |
|
| 152 | - }); |
|
| 144 | + $container->registerService('MountProvider', function (IContainer $c) { |
|
| 145 | + /** @var \OCP\IServerContainer $server */ |
|
| 146 | + $server = $c->query('ServerContainer'); |
|
| 147 | + return new MountProvider( |
|
| 148 | + $server->getConfig(), |
|
| 149 | + $server->getShareManager(), |
|
| 150 | + $server->getLogger() |
|
| 151 | + ); |
|
| 152 | + }); |
|
| 153 | 153 | |
| 154 | - $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
| 155 | - /** @var \OCP\IServerContainer $server */ |
|
| 156 | - $server = $c->query('ServerContainer'); |
|
| 157 | - return new \OCA\Files_Sharing\External\MountProvider( |
|
| 158 | - $server->getDatabaseConnection(), |
|
| 159 | - function() use ($c) { |
|
| 160 | - return $c->query('ExternalManager'); |
|
| 161 | - }, |
|
| 162 | - $server->getCloudIdManager() |
|
| 163 | - ); |
|
| 164 | - }); |
|
| 154 | + $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
| 155 | + /** @var \OCP\IServerContainer $server */ |
|
| 156 | + $server = $c->query('ServerContainer'); |
|
| 157 | + return new \OCA\Files_Sharing\External\MountProvider( |
|
| 158 | + $server->getDatabaseConnection(), |
|
| 159 | + function() use ($c) { |
|
| 160 | + return $c->query('ExternalManager'); |
|
| 161 | + }, |
|
| 162 | + $server->getCloudIdManager() |
|
| 163 | + ); |
|
| 164 | + }); |
|
| 165 | 165 | |
| 166 | - /* |
|
| 166 | + /* |
|
| 167 | 167 | * Register capabilities |
| 168 | 168 | */ |
| 169 | - $container->registerCapability(Capabilities::class); |
|
| 170 | - } |
|
| 169 | + $container->registerCapability(Capabilities::class); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - public function registerMountProviders() { |
|
| 173 | - /** @var \OCP\IServerContainer $server */ |
|
| 174 | - $server = $this->getContainer()->query('ServerContainer'); |
|
| 175 | - $mountProviderCollection = $server->getMountProviderCollection(); |
|
| 176 | - $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); |
|
| 177 | - $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
| 178 | - } |
|
| 172 | + public function registerMountProviders() { |
|
| 173 | + /** @var \OCP\IServerContainer $server */ |
|
| 174 | + $server = $this->getContainer()->query('ServerContainer'); |
|
| 175 | + $mountProviderCollection = $server->getMountProviderCollection(); |
|
| 176 | + $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); |
|
| 177 | + $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
| 178 | + } |
|
| 179 | 179 | } |
@@ -38,227 +38,227 @@ |
||
| 38 | 38 | |
| 39 | 39 | class CloudFederationProviderFiles implements ICloudFederationProvider { |
| 40 | 40 | |
| 41 | - /** @var IAppManager */ |
|
| 42 | - private $appManager; |
|
| 43 | - |
|
| 44 | - /** @var FederatedShareProvider */ |
|
| 45 | - private $federatedShareProvider; |
|
| 46 | - |
|
| 47 | - /** @var AddressHandler */ |
|
| 48 | - private $addressHandler; |
|
| 49 | - |
|
| 50 | - /** @var ILogger */ |
|
| 51 | - private $logger; |
|
| 52 | - |
|
| 53 | - /** @var IUserManager */ |
|
| 54 | - private $userManager; |
|
| 55 | - |
|
| 56 | - /** @var ICloudIdManager */ |
|
| 57 | - private $cloudIdManager; |
|
| 58 | - |
|
| 59 | - /** @var IActivityManager */ |
|
| 60 | - private $activityManager; |
|
| 61 | - |
|
| 62 | - /** @var INotificationManager */ |
|
| 63 | - private $notificationManager; |
|
| 64 | - |
|
| 65 | - /** @var IURLGenerator */ |
|
| 66 | - private $urlGenerator; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * CloudFederationProvider constructor. |
|
| 70 | - * |
|
| 71 | - * @param IAppManager $appManager |
|
| 72 | - * @param FederatedShareProvider $federatedShareProvider |
|
| 73 | - * @param AddressHandler $addressHandler |
|
| 74 | - * @param ILogger $logger |
|
| 75 | - * @param IUserManager $userManager |
|
| 76 | - * @param ICloudIdManager $cloudIdManager |
|
| 77 | - * @param IActivityManager $activityManager |
|
| 78 | - * @param INotificationManager $notificationManager |
|
| 79 | - * @param IURLGenerator $urlGenerator |
|
| 80 | - */ |
|
| 81 | - public function __construct(IAppManager $appManager, |
|
| 82 | - FederatedShareProvider $federatedShareProvider, |
|
| 83 | - AddressHandler $addressHandler, |
|
| 84 | - ILogger $logger, |
|
| 85 | - IUserManager $userManager, |
|
| 86 | - ICloudIdManager $cloudIdManager, |
|
| 87 | - IActivityManager $activityManager, |
|
| 88 | - INotificationManager $notificationManager, |
|
| 89 | - IURLGenerator $urlGenerator |
|
| 90 | - ) { |
|
| 91 | - $this->appManager = $appManager; |
|
| 92 | - $this->federatedShareProvider = $federatedShareProvider; |
|
| 93 | - $this->addressHandler = $addressHandler; |
|
| 94 | - $this->logger = $logger; |
|
| 95 | - $this->userManager = $userManager; |
|
| 96 | - $this->cloudIdManager = $cloudIdManager; |
|
| 97 | - $this->activityManager = $activityManager; |
|
| 98 | - $this->notificationManager = $notificationManager; |
|
| 99 | - $this->urlGenerator = $urlGenerator; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @return string |
|
| 106 | - */ |
|
| 107 | - public function getShareType() { |
|
| 108 | - return 'file'; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * share received from another server |
|
| 113 | - * |
|
| 114 | - * @param ICloudFederationShare $share |
|
| 115 | - * @return string provider specific unique ID of the share |
|
| 116 | - * |
|
| 117 | - * @throws ProviderCouldNotAddShareException |
|
| 118 | - * @throws \OCP\AppFramework\QueryException |
|
| 119 | - * @throws \OC\HintException |
|
| 120 | - * @since 14.0.0 |
|
| 121 | - */ |
|
| 122 | - public function shareReceived(ICloudFederationShare $share) { |
|
| 123 | - |
|
| 124 | - if (!$this->isS2SEnabled(true)) { |
|
| 125 | - throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $protocol = $share->getProtocol(); |
|
| 129 | - if ($protocol['name'] !== 'webdav') { |
|
| 130 | - throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner()); |
|
| 134 | - |
|
| 135 | - $remote = $remote; |
|
| 136 | - $token = isset($protocol['options']['access_token']) ? $protocol['options']['access_token'] : null; |
|
| 137 | - $name = $share->getResourceName(); |
|
| 138 | - $owner = $share->getOwnerDisplayName(); |
|
| 139 | - $sharedBy = $share->getSharedByDisplayName(); |
|
| 140 | - $shareWith = $share->getShareWith(); |
|
| 141 | - $remoteId = $share->getProviderId(); |
|
| 142 | - $sharedByFederatedId = $share->getSharedBy(); |
|
| 143 | - $ownerFederatedId = $share->getOwner(); |
|
| 144 | - |
|
| 145 | - // if no explicit information about the person who created the share was send |
|
| 146 | - // we assume that the share comes from the owner |
|
| 147 | - if ($sharedByFederatedId === null) { |
|
| 148 | - $sharedBy = $owner; |
|
| 149 | - $sharedByFederatedId = $ownerFederatedId; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
| 153 | - |
|
| 154 | - if (!\OCP\Util::isValidFileName($name)) { |
|
| 155 | - throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // FIXME this should be a method in the user management instead |
|
| 159 | - $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 160 | - \OCP\Util::emitHook( |
|
| 161 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 162 | - 'preLoginNameUsedAsUserName', |
|
| 163 | - array('uid' => &$shareWith) |
|
| 164 | - ); |
|
| 165 | - $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 166 | - |
|
| 167 | - if (!$this->userManager->userExists($shareWith)) { |
|
| 168 | - throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - \OC_Util::setupFS($shareWith); |
|
| 172 | - |
|
| 173 | - $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
| 174 | - \OC::$server->getDatabaseConnection(), |
|
| 175 | - \OC\Files\Filesystem::getMountManager(), |
|
| 176 | - \OC\Files\Filesystem::getLoader(), |
|
| 177 | - \OC::$server->getHTTPClientService(), |
|
| 178 | - \OC::$server->getNotificationManager(), |
|
| 179 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 180 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 181 | - $shareWith |
|
| 182 | - ); |
|
| 183 | - |
|
| 184 | - try { |
|
| 185 | - $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); |
|
| 186 | - $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
| 187 | - |
|
| 188 | - $event = $this->activityManager->generateEvent(); |
|
| 189 | - $event->setApp('files_sharing') |
|
| 190 | - ->setType('remote_share') |
|
| 191 | - ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 192 | - ->setAffectedUser($shareWith) |
|
| 193 | - ->setObject('remote_share', (int)$shareId, $name); |
|
| 194 | - \OC::$server->getActivityManager()->publish($event); |
|
| 195 | - |
|
| 196 | - $notification = $this->notificationManager->createNotification(); |
|
| 197 | - $notification->setApp('files_sharing') |
|
| 198 | - ->setUser($shareWith) |
|
| 199 | - ->setDateTime(new \DateTime()) |
|
| 200 | - ->setObject('remote_share', $shareId) |
|
| 201 | - ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
| 202 | - |
|
| 203 | - $declineAction = $notification->createAction(); |
|
| 204 | - $declineAction->setLabel('decline') |
|
| 205 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
| 206 | - $notification->addAction($declineAction); |
|
| 207 | - |
|
| 208 | - $acceptAction = $notification->createAction(); |
|
| 209 | - $acceptAction->setLabel('accept') |
|
| 210 | - ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
| 211 | - $notification->addAction($acceptAction); |
|
| 212 | - |
|
| 213 | - $this->notificationManager->notify($notification); |
|
| 214 | - |
|
| 215 | - return $shareId; |
|
| 216 | - } catch (\Exception $e) { |
|
| 217 | - $this->logger->logException($e, [ |
|
| 218 | - 'message' => 'Server can not add remote share.', |
|
| 219 | - 'level' => \OCP\Util::ERROR, |
|
| 220 | - 'app' => 'files_sharing' |
|
| 221 | - ]); |
|
| 222 | - throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); |
|
| 227 | - |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * notification received from another server |
|
| 232 | - * |
|
| 233 | - * @param string $id unique ID of a already existing share |
|
| 234 | - * @param array $notification provider specific notification |
|
| 235 | - * |
|
| 236 | - * @throws \OCP\Federation\Exceptions\ShareNotFoundException |
|
| 237 | - * |
|
| 238 | - * @since 14.0.0 |
|
| 239 | - */ |
|
| 240 | - public function notificationReceived($id, $notification) { |
|
| 241 | - // TODO: Implement notificationReceived() method. |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * check if server-to-server sharing is enabled |
|
| 246 | - * |
|
| 247 | - * @param bool $incoming |
|
| 248 | - * @return bool |
|
| 249 | - */ |
|
| 250 | - private function isS2SEnabled($incoming = false) { |
|
| 251 | - |
|
| 252 | - $result = $this->appManager->isEnabledForUser('files_sharing'); |
|
| 253 | - |
|
| 254 | - if ($incoming) { |
|
| 255 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
| 256 | - } else { |
|
| 257 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return $result; |
|
| 261 | - } |
|
| 41 | + /** @var IAppManager */ |
|
| 42 | + private $appManager; |
|
| 43 | + |
|
| 44 | + /** @var FederatedShareProvider */ |
|
| 45 | + private $federatedShareProvider; |
|
| 46 | + |
|
| 47 | + /** @var AddressHandler */ |
|
| 48 | + private $addressHandler; |
|
| 49 | + |
|
| 50 | + /** @var ILogger */ |
|
| 51 | + private $logger; |
|
| 52 | + |
|
| 53 | + /** @var IUserManager */ |
|
| 54 | + private $userManager; |
|
| 55 | + |
|
| 56 | + /** @var ICloudIdManager */ |
|
| 57 | + private $cloudIdManager; |
|
| 58 | + |
|
| 59 | + /** @var IActivityManager */ |
|
| 60 | + private $activityManager; |
|
| 61 | + |
|
| 62 | + /** @var INotificationManager */ |
|
| 63 | + private $notificationManager; |
|
| 64 | + |
|
| 65 | + /** @var IURLGenerator */ |
|
| 66 | + private $urlGenerator; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * CloudFederationProvider constructor. |
|
| 70 | + * |
|
| 71 | + * @param IAppManager $appManager |
|
| 72 | + * @param FederatedShareProvider $federatedShareProvider |
|
| 73 | + * @param AddressHandler $addressHandler |
|
| 74 | + * @param ILogger $logger |
|
| 75 | + * @param IUserManager $userManager |
|
| 76 | + * @param ICloudIdManager $cloudIdManager |
|
| 77 | + * @param IActivityManager $activityManager |
|
| 78 | + * @param INotificationManager $notificationManager |
|
| 79 | + * @param IURLGenerator $urlGenerator |
|
| 80 | + */ |
|
| 81 | + public function __construct(IAppManager $appManager, |
|
| 82 | + FederatedShareProvider $federatedShareProvider, |
|
| 83 | + AddressHandler $addressHandler, |
|
| 84 | + ILogger $logger, |
|
| 85 | + IUserManager $userManager, |
|
| 86 | + ICloudIdManager $cloudIdManager, |
|
| 87 | + IActivityManager $activityManager, |
|
| 88 | + INotificationManager $notificationManager, |
|
| 89 | + IURLGenerator $urlGenerator |
|
| 90 | + ) { |
|
| 91 | + $this->appManager = $appManager; |
|
| 92 | + $this->federatedShareProvider = $federatedShareProvider; |
|
| 93 | + $this->addressHandler = $addressHandler; |
|
| 94 | + $this->logger = $logger; |
|
| 95 | + $this->userManager = $userManager; |
|
| 96 | + $this->cloudIdManager = $cloudIdManager; |
|
| 97 | + $this->activityManager = $activityManager; |
|
| 98 | + $this->notificationManager = $notificationManager; |
|
| 99 | + $this->urlGenerator = $urlGenerator; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @return string |
|
| 106 | + */ |
|
| 107 | + public function getShareType() { |
|
| 108 | + return 'file'; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * share received from another server |
|
| 113 | + * |
|
| 114 | + * @param ICloudFederationShare $share |
|
| 115 | + * @return string provider specific unique ID of the share |
|
| 116 | + * |
|
| 117 | + * @throws ProviderCouldNotAddShareException |
|
| 118 | + * @throws \OCP\AppFramework\QueryException |
|
| 119 | + * @throws \OC\HintException |
|
| 120 | + * @since 14.0.0 |
|
| 121 | + */ |
|
| 122 | + public function shareReceived(ICloudFederationShare $share) { |
|
| 123 | + |
|
| 124 | + if (!$this->isS2SEnabled(true)) { |
|
| 125 | + throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $protocol = $share->getProtocol(); |
|
| 129 | + if ($protocol['name'] !== 'webdav') { |
|
| 130 | + throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner()); |
|
| 134 | + |
|
| 135 | + $remote = $remote; |
|
| 136 | + $token = isset($protocol['options']['access_token']) ? $protocol['options']['access_token'] : null; |
|
| 137 | + $name = $share->getResourceName(); |
|
| 138 | + $owner = $share->getOwnerDisplayName(); |
|
| 139 | + $sharedBy = $share->getSharedByDisplayName(); |
|
| 140 | + $shareWith = $share->getShareWith(); |
|
| 141 | + $remoteId = $share->getProviderId(); |
|
| 142 | + $sharedByFederatedId = $share->getSharedBy(); |
|
| 143 | + $ownerFederatedId = $share->getOwner(); |
|
| 144 | + |
|
| 145 | + // if no explicit information about the person who created the share was send |
|
| 146 | + // we assume that the share comes from the owner |
|
| 147 | + if ($sharedByFederatedId === null) { |
|
| 148 | + $sharedBy = $owner; |
|
| 149 | + $sharedByFederatedId = $ownerFederatedId; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + if ($remote && $token && $name && $owner && $remoteId && $shareWith) { |
|
| 153 | + |
|
| 154 | + if (!\OCP\Util::isValidFileName($name)) { |
|
| 155 | + throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // FIXME this should be a method in the user management instead |
|
| 159 | + $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 160 | + \OCP\Util::emitHook( |
|
| 161 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 162 | + 'preLoginNameUsedAsUserName', |
|
| 163 | + array('uid' => &$shareWith) |
|
| 164 | + ); |
|
| 165 | + $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']); |
|
| 166 | + |
|
| 167 | + if (!$this->userManager->userExists($shareWith)) { |
|
| 168 | + throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + \OC_Util::setupFS($shareWith); |
|
| 172 | + |
|
| 173 | + $externalManager = new \OCA\Files_Sharing\External\Manager( |
|
| 174 | + \OC::$server->getDatabaseConnection(), |
|
| 175 | + \OC\Files\Filesystem::getMountManager(), |
|
| 176 | + \OC\Files\Filesystem::getLoader(), |
|
| 177 | + \OC::$server->getHTTPClientService(), |
|
| 178 | + \OC::$server->getNotificationManager(), |
|
| 179 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 180 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 181 | + $shareWith |
|
| 182 | + ); |
|
| 183 | + |
|
| 184 | + try { |
|
| 185 | + $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId); |
|
| 186 | + $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external'); |
|
| 187 | + |
|
| 188 | + $event = $this->activityManager->generateEvent(); |
|
| 189 | + $event->setApp('files_sharing') |
|
| 190 | + ->setType('remote_share') |
|
| 191 | + ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')]) |
|
| 192 | + ->setAffectedUser($shareWith) |
|
| 193 | + ->setObject('remote_share', (int)$shareId, $name); |
|
| 194 | + \OC::$server->getActivityManager()->publish($event); |
|
| 195 | + |
|
| 196 | + $notification = $this->notificationManager->createNotification(); |
|
| 197 | + $notification->setApp('files_sharing') |
|
| 198 | + ->setUser($shareWith) |
|
| 199 | + ->setDateTime(new \DateTime()) |
|
| 200 | + ->setObject('remote_share', $shareId) |
|
| 201 | + ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]); |
|
| 202 | + |
|
| 203 | + $declineAction = $notification->createAction(); |
|
| 204 | + $declineAction->setLabel('decline') |
|
| 205 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE'); |
|
| 206 | + $notification->addAction($declineAction); |
|
| 207 | + |
|
| 208 | + $acceptAction = $notification->createAction(); |
|
| 209 | + $acceptAction->setLabel('accept') |
|
| 210 | + ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST'); |
|
| 211 | + $notification->addAction($acceptAction); |
|
| 212 | + |
|
| 213 | + $this->notificationManager->notify($notification); |
|
| 214 | + |
|
| 215 | + return $shareId; |
|
| 216 | + } catch (\Exception $e) { |
|
| 217 | + $this->logger->logException($e, [ |
|
| 218 | + 'message' => 'Server can not add remote share.', |
|
| 219 | + 'level' => \OCP\Util::ERROR, |
|
| 220 | + 'app' => 'files_sharing' |
|
| 221 | + ]); |
|
| 222 | + throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST); |
|
| 227 | + |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * notification received from another server |
|
| 232 | + * |
|
| 233 | + * @param string $id unique ID of a already existing share |
|
| 234 | + * @param array $notification provider specific notification |
|
| 235 | + * |
|
| 236 | + * @throws \OCP\Federation\Exceptions\ShareNotFoundException |
|
| 237 | + * |
|
| 238 | + * @since 14.0.0 |
|
| 239 | + */ |
|
| 240 | + public function notificationReceived($id, $notification) { |
|
| 241 | + // TODO: Implement notificationReceived() method. |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * check if server-to-server sharing is enabled |
|
| 246 | + * |
|
| 247 | + * @param bool $incoming |
|
| 248 | + * @return bool |
|
| 249 | + */ |
|
| 250 | + private function isS2SEnabled($incoming = false) { |
|
| 251 | + |
|
| 252 | + $result = $this->appManager->isEnabledForUser('files_sharing'); |
|
| 253 | + |
|
| 254 | + if ($incoming) { |
|
| 255 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
| 256 | + } else { |
|
| 257 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return $result; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | 263 | |
| 264 | 264 | } |