@@ -25,328 +25,328 @@ |
||
| 25 | 25 | |
| 26 | 26 | class CloudFederationShare implements ICloudFederationShare { |
| 27 | 27 | |
| 28 | - private $share = [ |
|
| 29 | - 'shareWith' => '', |
|
| 30 | - 'shareType' => '', |
|
| 31 | - 'name' => '', |
|
| 32 | - 'resourceType' => '', |
|
| 33 | - 'description' => '', |
|
| 34 | - 'providerId' => '', |
|
| 35 | - 'owner' => '', |
|
| 36 | - 'ownerDisplayName' => '', |
|
| 37 | - 'sharedBy' => '', |
|
| 38 | - 'sharedByDisplayName' => '', |
|
| 39 | - 'protocol' => [] |
|
| 40 | - ]; |
|
| 28 | + private $share = [ |
|
| 29 | + 'shareWith' => '', |
|
| 30 | + 'shareType' => '', |
|
| 31 | + 'name' => '', |
|
| 32 | + 'resourceType' => '', |
|
| 33 | + 'description' => '', |
|
| 34 | + 'providerId' => '', |
|
| 35 | + 'owner' => '', |
|
| 36 | + 'ownerDisplayName' => '', |
|
| 37 | + 'sharedBy' => '', |
|
| 38 | + 'sharedByDisplayName' => '', |
|
| 39 | + 'protocol' => [] |
|
| 40 | + ]; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * get a CloudFederationShare Object to prepare a share you want to send |
|
| 44 | - * |
|
| 45 | - * @param string $shareWith |
|
| 46 | - * @param string $name resource name (e.g. document.odt) |
|
| 47 | - * @param string $description share description (optional) |
|
| 48 | - * @param string $providerId resource UID on the provider side |
|
| 49 | - * @param string $owner provider specific UID of the user who owns the resource |
|
| 50 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
| 51 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 52 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 53 | - * @param string $shareType ('group' or 'user' share) |
|
| 54 | - * @param string $resourceType ('file', 'calendar',...) |
|
| 55 | - * @param string $sharedSecret |
|
| 56 | - */ |
|
| 57 | - public function __construct($shareWith = '', |
|
| 58 | - $name = '', |
|
| 59 | - $description = '', |
|
| 60 | - $providerId = '', |
|
| 61 | - $owner = '', |
|
| 62 | - $ownerDisplayName = '', |
|
| 63 | - $sharedBy = '', |
|
| 64 | - $sharedByDisplayName = '', |
|
| 65 | - $shareType = '', |
|
| 66 | - $resourceType = '', |
|
| 67 | - $sharedSecret = '' |
|
| 68 | - ) { |
|
| 69 | - $this->setShareWith($shareWith); |
|
| 70 | - $this->setResourceName($name); |
|
| 71 | - $this->setDescription($description); |
|
| 72 | - $this->setProviderId($providerId); |
|
| 73 | - $this->setOwner($owner); |
|
| 74 | - $this->setOwnerDisplayName($ownerDisplayName); |
|
| 75 | - $this->setSharedBy($sharedBy); |
|
| 76 | - $this->setSharedByDisplayName($sharedByDisplayName); |
|
| 77 | - $this->setProtocol([ |
|
| 78 | - 'name' => 'webdav', |
|
| 79 | - 'options' => [ |
|
| 80 | - 'sharedSecret' => $sharedSecret, |
|
| 81 | - 'permissions' => '{http://open-collaboration-services.org/ns}share-permissions' |
|
| 82 | - ] |
|
| 83 | - ]); |
|
| 84 | - $this->setShareType($shareType); |
|
| 85 | - $this->setResourceType($resourceType); |
|
| 42 | + /** |
|
| 43 | + * get a CloudFederationShare Object to prepare a share you want to send |
|
| 44 | + * |
|
| 45 | + * @param string $shareWith |
|
| 46 | + * @param string $name resource name (e.g. document.odt) |
|
| 47 | + * @param string $description share description (optional) |
|
| 48 | + * @param string $providerId resource UID on the provider side |
|
| 49 | + * @param string $owner provider specific UID of the user who owns the resource |
|
| 50 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
| 51 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 52 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 53 | + * @param string $shareType ('group' or 'user' share) |
|
| 54 | + * @param string $resourceType ('file', 'calendar',...) |
|
| 55 | + * @param string $sharedSecret |
|
| 56 | + */ |
|
| 57 | + public function __construct($shareWith = '', |
|
| 58 | + $name = '', |
|
| 59 | + $description = '', |
|
| 60 | + $providerId = '', |
|
| 61 | + $owner = '', |
|
| 62 | + $ownerDisplayName = '', |
|
| 63 | + $sharedBy = '', |
|
| 64 | + $sharedByDisplayName = '', |
|
| 65 | + $shareType = '', |
|
| 66 | + $resourceType = '', |
|
| 67 | + $sharedSecret = '' |
|
| 68 | + ) { |
|
| 69 | + $this->setShareWith($shareWith); |
|
| 70 | + $this->setResourceName($name); |
|
| 71 | + $this->setDescription($description); |
|
| 72 | + $this->setProviderId($providerId); |
|
| 73 | + $this->setOwner($owner); |
|
| 74 | + $this->setOwnerDisplayName($ownerDisplayName); |
|
| 75 | + $this->setSharedBy($sharedBy); |
|
| 76 | + $this->setSharedByDisplayName($sharedByDisplayName); |
|
| 77 | + $this->setProtocol([ |
|
| 78 | + 'name' => 'webdav', |
|
| 79 | + 'options' => [ |
|
| 80 | + 'sharedSecret' => $sharedSecret, |
|
| 81 | + 'permissions' => '{http://open-collaboration-services.org/ns}share-permissions' |
|
| 82 | + ] |
|
| 83 | + ]); |
|
| 84 | + $this->setShareType($shareType); |
|
| 85 | + $this->setResourceType($resourceType); |
|
| 86 | 86 | |
| 87 | - } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * set uid of the recipient |
|
| 91 | - * |
|
| 92 | - * @param string $user |
|
| 93 | - * |
|
| 94 | - * @since 14.0.0 |
|
| 95 | - */ |
|
| 96 | - public function setShareWith($user) { |
|
| 97 | - $this->share['shareWith'] = $user; |
|
| 98 | - } |
|
| 89 | + /** |
|
| 90 | + * set uid of the recipient |
|
| 91 | + * |
|
| 92 | + * @param string $user |
|
| 93 | + * |
|
| 94 | + * @since 14.0.0 |
|
| 95 | + */ |
|
| 96 | + public function setShareWith($user) { |
|
| 97 | + $this->share['shareWith'] = $user; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * set resource name (e.g. document.odt) |
|
| 102 | - * |
|
| 103 | - * @param string $name |
|
| 104 | - * |
|
| 105 | - * @since 14.0.0 |
|
| 106 | - */ |
|
| 107 | - public function setResourceName($name) { |
|
| 108 | - $this->share['name'] = $name; |
|
| 109 | - } |
|
| 100 | + /** |
|
| 101 | + * set resource name (e.g. document.odt) |
|
| 102 | + * |
|
| 103 | + * @param string $name |
|
| 104 | + * |
|
| 105 | + * @since 14.0.0 |
|
| 106 | + */ |
|
| 107 | + public function setResourceName($name) { |
|
| 108 | + $this->share['name'] = $name; |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * set resource type (e.g. file, calendar, contact,...) |
|
| 113 | - * |
|
| 114 | - * @param string $resourceType |
|
| 115 | - * |
|
| 116 | - * @since 14.0.0 |
|
| 117 | - */ |
|
| 118 | - public function setResourceType($resourceType) { |
|
| 119 | - $this->share['resourceType'] = $resourceType; |
|
| 120 | - } |
|
| 111 | + /** |
|
| 112 | + * set resource type (e.g. file, calendar, contact,...) |
|
| 113 | + * |
|
| 114 | + * @param string $resourceType |
|
| 115 | + * |
|
| 116 | + * @since 14.0.0 |
|
| 117 | + */ |
|
| 118 | + public function setResourceType($resourceType) { |
|
| 119 | + $this->share['resourceType'] = $resourceType; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * set resource description (optional) |
|
| 124 | - * |
|
| 125 | - * @param string $description |
|
| 126 | - * |
|
| 127 | - * @since 14.0.0 |
|
| 128 | - */ |
|
| 129 | - public function setDescription($description) { |
|
| 130 | - $this->share['description'] = $description; |
|
| 131 | - } |
|
| 122 | + /** |
|
| 123 | + * set resource description (optional) |
|
| 124 | + * |
|
| 125 | + * @param string $description |
|
| 126 | + * |
|
| 127 | + * @since 14.0.0 |
|
| 128 | + */ |
|
| 129 | + public function setDescription($description) { |
|
| 130 | + $this->share['description'] = $description; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * set provider ID (e.g. file ID) |
|
| 135 | - * |
|
| 136 | - * @param string $providerId |
|
| 137 | - * |
|
| 138 | - * @since 14.0.0 |
|
| 139 | - */ |
|
| 140 | - public function setProviderId($providerId) { |
|
| 141 | - $this->share['providerId'] = $providerId; |
|
| 142 | - } |
|
| 133 | + /** |
|
| 134 | + * set provider ID (e.g. file ID) |
|
| 135 | + * |
|
| 136 | + * @param string $providerId |
|
| 137 | + * |
|
| 138 | + * @since 14.0.0 |
|
| 139 | + */ |
|
| 140 | + public function setProviderId($providerId) { |
|
| 141 | + $this->share['providerId'] = $providerId; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * set owner UID |
|
| 146 | - * |
|
| 147 | - * @param string $owner |
|
| 148 | - * |
|
| 149 | - * @since 14.0.0 |
|
| 150 | - */ |
|
| 151 | - public function setOwner($owner) { |
|
| 152 | - $this->share['owner'] = $owner; |
|
| 153 | - } |
|
| 144 | + /** |
|
| 145 | + * set owner UID |
|
| 146 | + * |
|
| 147 | + * @param string $owner |
|
| 148 | + * |
|
| 149 | + * @since 14.0.0 |
|
| 150 | + */ |
|
| 151 | + public function setOwner($owner) { |
|
| 152 | + $this->share['owner'] = $owner; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * set owner display name |
|
| 157 | - * |
|
| 158 | - * @param string $ownerDisplayName |
|
| 159 | - * |
|
| 160 | - * @since 14.0.0 |
|
| 161 | - */ |
|
| 162 | - public function setOwnerDisplayName($ownerDisplayName) { |
|
| 163 | - $this->share['ownerDisplayName'] = $ownerDisplayName; |
|
| 164 | - } |
|
| 155 | + /** |
|
| 156 | + * set owner display name |
|
| 157 | + * |
|
| 158 | + * @param string $ownerDisplayName |
|
| 159 | + * |
|
| 160 | + * @since 14.0.0 |
|
| 161 | + */ |
|
| 162 | + public function setOwnerDisplayName($ownerDisplayName) { |
|
| 163 | + $this->share['ownerDisplayName'] = $ownerDisplayName; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * set UID of the user who sends the share |
|
| 168 | - * |
|
| 169 | - * @param string $sharedBy |
|
| 170 | - * |
|
| 171 | - * @since 14.0.0 |
|
| 172 | - */ |
|
| 173 | - public function setSharedBy($sharedBy) { |
|
| 174 | - $this->share['sharedBy'] = $sharedBy; |
|
| 175 | - } |
|
| 166 | + /** |
|
| 167 | + * set UID of the user who sends the share |
|
| 168 | + * |
|
| 169 | + * @param string $sharedBy |
|
| 170 | + * |
|
| 171 | + * @since 14.0.0 |
|
| 172 | + */ |
|
| 173 | + public function setSharedBy($sharedBy) { |
|
| 174 | + $this->share['sharedBy'] = $sharedBy; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * set display name of the user who sends the share |
|
| 179 | - * |
|
| 180 | - * @param $sharedByDisplayName |
|
| 181 | - * |
|
| 182 | - * @since 14.0.0 |
|
| 183 | - */ |
|
| 184 | - public function setSharedByDisplayName($sharedByDisplayName) { |
|
| 185 | - $this->share['sharedByDisplayName'] = $sharedByDisplayName; |
|
| 186 | - } |
|
| 177 | + /** |
|
| 178 | + * set display name of the user who sends the share |
|
| 179 | + * |
|
| 180 | + * @param $sharedByDisplayName |
|
| 181 | + * |
|
| 182 | + * @since 14.0.0 |
|
| 183 | + */ |
|
| 184 | + public function setSharedByDisplayName($sharedByDisplayName) { |
|
| 185 | + $this->share['sharedByDisplayName'] = $sharedByDisplayName; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * set protocol specification |
|
| 190 | - * |
|
| 191 | - * @param array $protocol |
|
| 192 | - * |
|
| 193 | - * @since 14.0.0 |
|
| 194 | - */ |
|
| 195 | - public function setProtocol(array $protocol) { |
|
| 196 | - $this->share['protocol'] = $protocol; |
|
| 197 | - } |
|
| 188 | + /** |
|
| 189 | + * set protocol specification |
|
| 190 | + * |
|
| 191 | + * @param array $protocol |
|
| 192 | + * |
|
| 193 | + * @since 14.0.0 |
|
| 194 | + */ |
|
| 195 | + public function setProtocol(array $protocol) { |
|
| 196 | + $this->share['protocol'] = $protocol; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * share type (group or user) |
|
| 201 | - * |
|
| 202 | - * @param string $shareType |
|
| 203 | - * |
|
| 204 | - * @since 14.0.0 |
|
| 205 | - */ |
|
| 206 | - public function setShareType($shareType) { |
|
| 207 | - $this->share['shareType'] = $shareType; |
|
| 208 | - } |
|
| 199 | + /** |
|
| 200 | + * share type (group or user) |
|
| 201 | + * |
|
| 202 | + * @param string $shareType |
|
| 203 | + * |
|
| 204 | + * @since 14.0.0 |
|
| 205 | + */ |
|
| 206 | + public function setShareType($shareType) { |
|
| 207 | + $this->share['shareType'] = $shareType; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * get the whole share, ready to send out |
|
| 212 | - * |
|
| 213 | - * @return array |
|
| 214 | - * |
|
| 215 | - * @since 14.0.0 |
|
| 216 | - */ |
|
| 217 | - public function getShare() { |
|
| 218 | - return $this->share; |
|
| 219 | - } |
|
| 210 | + /** |
|
| 211 | + * get the whole share, ready to send out |
|
| 212 | + * |
|
| 213 | + * @return array |
|
| 214 | + * |
|
| 215 | + * @since 14.0.0 |
|
| 216 | + */ |
|
| 217 | + public function getShare() { |
|
| 218 | + return $this->share; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * get uid of the recipient |
|
| 223 | - * |
|
| 224 | - * @return string |
|
| 225 | - * |
|
| 226 | - * @since 14.0.0 |
|
| 227 | - */ |
|
| 228 | - public function getShareWith() { |
|
| 229 | - return $this->share['shareWith']; |
|
| 230 | - } |
|
| 221 | + /** |
|
| 222 | + * get uid of the recipient |
|
| 223 | + * |
|
| 224 | + * @return string |
|
| 225 | + * |
|
| 226 | + * @since 14.0.0 |
|
| 227 | + */ |
|
| 228 | + public function getShareWith() { |
|
| 229 | + return $this->share['shareWith']; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * get resource name (e.g. file, calendar, contact,...) |
|
| 234 | - * |
|
| 235 | - * @return string |
|
| 236 | - * |
|
| 237 | - * @since 14.0.0 |
|
| 238 | - */ |
|
| 239 | - public function getResourceName() { |
|
| 240 | - return $this->share['name']; |
|
| 241 | - } |
|
| 232 | + /** |
|
| 233 | + * get resource name (e.g. file, calendar, contact,...) |
|
| 234 | + * |
|
| 235 | + * @return string |
|
| 236 | + * |
|
| 237 | + * @since 14.0.0 |
|
| 238 | + */ |
|
| 239 | + public function getResourceName() { |
|
| 240 | + return $this->share['name']; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * get resource type (e.g. file, calendar, contact,...) |
|
| 245 | - * |
|
| 246 | - * @return string |
|
| 247 | - * |
|
| 248 | - * @since 14.0.0 |
|
| 249 | - */ |
|
| 250 | - public function getResourceType() { |
|
| 251 | - return $this->share['resourceType']; |
|
| 252 | - } |
|
| 243 | + /** |
|
| 244 | + * get resource type (e.g. file, calendar, contact,...) |
|
| 245 | + * |
|
| 246 | + * @return string |
|
| 247 | + * |
|
| 248 | + * @since 14.0.0 |
|
| 249 | + */ |
|
| 250 | + public function getResourceType() { |
|
| 251 | + return $this->share['resourceType']; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** |
|
| 255 | - * get resource description (optional) |
|
| 256 | - * |
|
| 257 | - * @return string |
|
| 258 | - * |
|
| 259 | - * @since 14.0.0 |
|
| 260 | - */ |
|
| 261 | - public function getDescription() { |
|
| 262 | - return $this->share['description']; |
|
| 263 | - } |
|
| 254 | + /** |
|
| 255 | + * get resource description (optional) |
|
| 256 | + * |
|
| 257 | + * @return string |
|
| 258 | + * |
|
| 259 | + * @since 14.0.0 |
|
| 260 | + */ |
|
| 261 | + public function getDescription() { |
|
| 262 | + return $this->share['description']; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * get provider ID (e.g. file ID) |
|
| 267 | - * |
|
| 268 | - * @return string |
|
| 269 | - * |
|
| 270 | - * @since 14.0.0 |
|
| 271 | - */ |
|
| 272 | - public function getProviderId() { |
|
| 273 | - return $this->share['providerId']; |
|
| 274 | - } |
|
| 265 | + /** |
|
| 266 | + * get provider ID (e.g. file ID) |
|
| 267 | + * |
|
| 268 | + * @return string |
|
| 269 | + * |
|
| 270 | + * @since 14.0.0 |
|
| 271 | + */ |
|
| 272 | + public function getProviderId() { |
|
| 273 | + return $this->share['providerId']; |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * get owner UID |
|
| 278 | - * |
|
| 279 | - * @return string |
|
| 280 | - * |
|
| 281 | - * @since 14.0.0 |
|
| 282 | - */ |
|
| 283 | - public function getOwner() { |
|
| 284 | - return $this->share['owner']; |
|
| 285 | - } |
|
| 276 | + /** |
|
| 277 | + * get owner UID |
|
| 278 | + * |
|
| 279 | + * @return string |
|
| 280 | + * |
|
| 281 | + * @since 14.0.0 |
|
| 282 | + */ |
|
| 283 | + public function getOwner() { |
|
| 284 | + return $this->share['owner']; |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * get owner display name |
|
| 289 | - * |
|
| 290 | - * @return string |
|
| 291 | - * |
|
| 292 | - * @since 14.0.0 |
|
| 293 | - */ |
|
| 294 | - public function getOwnerDisplayName() { |
|
| 295 | - return $this->share['ownerDisplayName']; |
|
| 296 | - } |
|
| 287 | + /** |
|
| 288 | + * get owner display name |
|
| 289 | + * |
|
| 290 | + * @return string |
|
| 291 | + * |
|
| 292 | + * @since 14.0.0 |
|
| 293 | + */ |
|
| 294 | + public function getOwnerDisplayName() { |
|
| 295 | + return $this->share['ownerDisplayName']; |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * get UID of the user who sends the share |
|
| 300 | - * |
|
| 301 | - * @return string |
|
| 302 | - * |
|
| 303 | - * @since 14.0.0 |
|
| 304 | - */ |
|
| 305 | - public function getSharedBy() { |
|
| 306 | - return $this->share['sharedBy']; |
|
| 307 | - } |
|
| 298 | + /** |
|
| 299 | + * get UID of the user who sends the share |
|
| 300 | + * |
|
| 301 | + * @return string |
|
| 302 | + * |
|
| 303 | + * @since 14.0.0 |
|
| 304 | + */ |
|
| 305 | + public function getSharedBy() { |
|
| 306 | + return $this->share['sharedBy']; |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * get display name of the user who sends the share |
|
| 311 | - * |
|
| 312 | - * @return string |
|
| 313 | - * |
|
| 314 | - * @since 14.0.0 |
|
| 315 | - */ |
|
| 316 | - public function getSharedByDisplayName() { |
|
| 317 | - return $this->share['sharedByDisplayName']; |
|
| 318 | - } |
|
| 309 | + /** |
|
| 310 | + * get display name of the user who sends the share |
|
| 311 | + * |
|
| 312 | + * @return string |
|
| 313 | + * |
|
| 314 | + * @since 14.0.0 |
|
| 315 | + */ |
|
| 316 | + public function getSharedByDisplayName() { |
|
| 317 | + return $this->share['sharedByDisplayName']; |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * get share type (group or user) |
|
| 322 | - * |
|
| 323 | - * @return string |
|
| 324 | - * |
|
| 325 | - * @since 14.0.0 |
|
| 326 | - */ |
|
| 327 | - public function getShareType() { |
|
| 328 | - return $this->share['shareType']; |
|
| 329 | - } |
|
| 320 | + /** |
|
| 321 | + * get share type (group or user) |
|
| 322 | + * |
|
| 323 | + * @return string |
|
| 324 | + * |
|
| 325 | + * @since 14.0.0 |
|
| 326 | + */ |
|
| 327 | + public function getShareType() { |
|
| 328 | + return $this->share['shareType']; |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * get share Secret |
|
| 333 | - * |
|
| 334 | - * @return string |
|
| 335 | - * |
|
| 336 | - * @since 14.0.0 |
|
| 337 | - */ |
|
| 338 | - public function getShareSecret() { |
|
| 339 | - return $this->share['protocol']['options']['sharedSecret']; |
|
| 340 | - } |
|
| 331 | + /** |
|
| 332 | + * get share Secret |
|
| 333 | + * |
|
| 334 | + * @return string |
|
| 335 | + * |
|
| 336 | + * @since 14.0.0 |
|
| 337 | + */ |
|
| 338 | + public function getShareSecret() { |
|
| 339 | + return $this->share['protocol']['options']['sharedSecret']; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * get protocol specification |
|
| 344 | - * |
|
| 345 | - * @return array |
|
| 346 | - * |
|
| 347 | - * @since 14.0.0 |
|
| 348 | - */ |
|
| 349 | - public function getProtocol() { |
|
| 350 | - return $this->share['protocol']; |
|
| 351 | - } |
|
| 342 | + /** |
|
| 343 | + * get protocol specification |
|
| 344 | + * |
|
| 345 | + * @return array |
|
| 346 | + * |
|
| 347 | + * @since 14.0.0 |
|
| 348 | + */ |
|
| 349 | + public function getProtocol() { |
|
| 350 | + return $this->share['protocol']; |
|
| 351 | + } |
|
| 352 | 352 | } |
@@ -27,37 +27,37 @@ |
||
| 27 | 27 | |
| 28 | 28 | class CloudFederationFactory implements ICloudFederationFactory { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * get a CloudFederationShare Object to prepare a share you want to send |
|
| 32 | - * |
|
| 33 | - * @param string $shareWith |
|
| 34 | - * @param string $name resource name (e.g. document.odt) |
|
| 35 | - * @param string $description share description (optional) |
|
| 36 | - * @param string $providerId resource UID on the provider side |
|
| 37 | - * @param string $owner provider specific UID of the user who owns the resource |
|
| 38 | - * @param string $ownerDisplayName display name of the user who shared the item |
|
| 39 | - * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 40 | - * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 41 | - * @param string $sharedSecret used to authenticate requests across servers |
|
| 42 | - * @param string $shareType ('group' or 'user' share) |
|
| 43 | - * @param $resourceType ('file', 'calendar',...) |
|
| 44 | - * @return ICloudFederationShare |
|
| 45 | - * |
|
| 46 | - * @since 14.0.0 |
|
| 47 | - */ |
|
| 48 | - public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType) { |
|
| 49 | - return new CloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $shareType, $resourceType, $sharedSecret); |
|
| 50 | - } |
|
| 30 | + /** |
|
| 31 | + * get a CloudFederationShare Object to prepare a share you want to send |
|
| 32 | + * |
|
| 33 | + * @param string $shareWith |
|
| 34 | + * @param string $name resource name (e.g. document.odt) |
|
| 35 | + * @param string $description share description (optional) |
|
| 36 | + * @param string $providerId resource UID on the provider side |
|
| 37 | + * @param string $owner provider specific UID of the user who owns the resource |
|
| 38 | + * @param string $ownerDisplayName display name of the user who shared the item |
|
| 39 | + * @param string $sharedBy provider specific UID of the user who shared the resource |
|
| 40 | + * @param string $sharedByDisplayName display name of the user who shared the resource |
|
| 41 | + * @param string $sharedSecret used to authenticate requests across servers |
|
| 42 | + * @param string $shareType ('group' or 'user' share) |
|
| 43 | + * @param $resourceType ('file', 'calendar',...) |
|
| 44 | + * @return ICloudFederationShare |
|
| 45 | + * |
|
| 46 | + * @since 14.0.0 |
|
| 47 | + */ |
|
| 48 | + public function getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $sharedSecret, $shareType, $resourceType) { |
|
| 49 | + return new CloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, $shareType, $resourceType, $sharedSecret); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * get a Cloud FederationNotification object to prepare a notification you |
|
| 54 | - * want to send |
|
| 55 | - * |
|
| 56 | - * @return ICloudFederationNotification |
|
| 57 | - * |
|
| 58 | - * @since 14.0.0 |
|
| 59 | - */ |
|
| 60 | - public function getCloudFederationNotification() { |
|
| 61 | - return new CloudFederationNotification(); |
|
| 62 | - } |
|
| 52 | + /** |
|
| 53 | + * get a Cloud FederationNotification object to prepare a notification you |
|
| 54 | + * want to send |
|
| 55 | + * |
|
| 56 | + * @return ICloudFederationNotification |
|
| 57 | + * |
|
| 58 | + * @since 14.0.0 |
|
| 59 | + */ |
|
| 60 | + public function getCloudFederationNotification() { |
|
| 61 | + return new CloudFederationNotification(); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -28,37 +28,37 @@ |
||
| 28 | 28 | |
| 29 | 29 | class Capabilities implements ICapability { |
| 30 | 30 | |
| 31 | - /** @var IURLGenerator */ |
|
| 32 | - private $urlGenerator; |
|
| 31 | + /** @var IURLGenerator */ |
|
| 32 | + private $urlGenerator; |
|
| 33 | 33 | |
| 34 | - public function __construct(IURLGenerator $urlGenerator) { |
|
| 35 | - $this->urlGenerator = $urlGenerator; |
|
| 36 | - } |
|
| 34 | + public function __construct(IURLGenerator $urlGenerator) { |
|
| 35 | + $this->urlGenerator = $urlGenerator; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Function an app uses to return the capabilities |
|
| 40 | - * |
|
| 41 | - * @return array Array containing the apps capabilities |
|
| 42 | - * @since 8.2.0 |
|
| 43 | - */ |
|
| 44 | - public function getCapabilities() { |
|
| 45 | - $url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare'); |
|
| 46 | - $capabilities = ['ocm' => |
|
| 47 | - [ |
|
| 48 | - 'enabled' => true, |
|
| 49 | - 'apiVersion' => '1.0-proposal1', |
|
| 50 | - 'endPoint' => substr($url, 0, strrpos($url, '/')), |
|
| 51 | - 'shareTypes' => [ |
|
| 52 | - [ |
|
| 53 | - 'name' => 'file', |
|
| 54 | - 'protocols' => [ |
|
| 55 | - 'webdav' => '/public.php/webdav/', |
|
| 56 | - ] |
|
| 57 | - ], |
|
| 58 | - ] |
|
| 59 | - ] |
|
| 60 | - ]; |
|
| 38 | + /** |
|
| 39 | + * Function an app uses to return the capabilities |
|
| 40 | + * |
|
| 41 | + * @return array Array containing the apps capabilities |
|
| 42 | + * @since 8.2.0 |
|
| 43 | + */ |
|
| 44 | + public function getCapabilities() { |
|
| 45 | + $url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare'); |
|
| 46 | + $capabilities = ['ocm' => |
|
| 47 | + [ |
|
| 48 | + 'enabled' => true, |
|
| 49 | + 'apiVersion' => '1.0-proposal1', |
|
| 50 | + 'endPoint' => substr($url, 0, strrpos($url, '/')), |
|
| 51 | + 'shareTypes' => [ |
|
| 52 | + [ |
|
| 53 | + 'name' => 'file', |
|
| 54 | + 'protocols' => [ |
|
| 55 | + 'webdav' => '/public.php/webdav/', |
|
| 56 | + ] |
|
| 57 | + ], |
|
| 58 | + ] |
|
| 59 | + ] |
|
| 60 | + ]; |
|
| 61 | 61 | |
| 62 | - return $capabilities; |
|
| 63 | - } |
|
| 62 | + return $capabilities; |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -44,512 +44,512 @@ |
||
| 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 id of the share |
|
| 328 | - * @param string $feedback |
|
| 329 | - * @return bool |
|
| 330 | - */ |
|
| 331 | - protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
| 332 | - switch ($feedback) { |
|
| 333 | - case 'accept': |
|
| 334 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 335 | - $notification->setMessage( |
|
| 336 | - 'SHARE_ACCEPTED', |
|
| 337 | - 'file', |
|
| 338 | - $remoteId, |
|
| 339 | - [ |
|
| 340 | - 'sharedSecret' => $token, |
|
| 341 | - 'message' => 'Recipient accept the share' |
|
| 342 | - ] |
|
| 343 | - |
|
| 344 | - ); |
|
| 345 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 346 | - case 'decline': |
|
| 347 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 348 | - $notification->setMessage( |
|
| 349 | - 'SHARE_DECLINED', |
|
| 350 | - 'file', |
|
| 351 | - $remoteId, |
|
| 352 | - [ |
|
| 353 | - 'sharedSecret' => $token, |
|
| 354 | - 'message' => 'Recipient declined the share' |
|
| 355 | - ] |
|
| 356 | - |
|
| 357 | - ); |
|
| 358 | - return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return false; |
|
| 362 | - |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * remove '/user/files' from the path and trailing slashes |
|
| 368 | - * |
|
| 369 | - * @param string $path |
|
| 370 | - * @return string |
|
| 371 | - */ |
|
| 372 | - protected function stripPath($path) { |
|
| 373 | - $prefix = '/' . $this->uid . '/files'; |
|
| 374 | - return rtrim(substr($path, strlen($prefix)), '/'); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - public function getMount($data) { |
|
| 378 | - $data['manager'] = $this; |
|
| 379 | - $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 380 | - $data['mountpoint'] = $mountPoint; |
|
| 381 | - $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
| 382 | - return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @param array $data |
|
| 387 | - * @return Mount |
|
| 388 | - */ |
|
| 389 | - protected function mountShare($data) { |
|
| 390 | - $mount = $this->getMount($data); |
|
| 391 | - $this->mountManager->addMount($mount); |
|
| 392 | - return $mount; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @return \OC\Files\Mount\Manager |
|
| 397 | - */ |
|
| 398 | - public function getMountManager() { |
|
| 399 | - return $this->mountManager; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * @param string $source |
|
| 404 | - * @param string $target |
|
| 405 | - * @return bool |
|
| 406 | - */ |
|
| 407 | - public function setMountPoint($source, $target) { |
|
| 408 | - $source = $this->stripPath($source); |
|
| 409 | - $target = $this->stripPath($target); |
|
| 410 | - $sourceHash = md5($source); |
|
| 411 | - $targetHash = md5($target); |
|
| 412 | - |
|
| 413 | - $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 id of the share |
|
| 328 | + * @param string $feedback |
|
| 329 | + * @return bool |
|
| 330 | + */ |
|
| 331 | + protected function tryOCMEndPoint($remoteDomain, $token, $remoteId, $feedback) { |
|
| 332 | + switch ($feedback) { |
|
| 333 | + case 'accept': |
|
| 334 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 335 | + $notification->setMessage( |
|
| 336 | + 'SHARE_ACCEPTED', |
|
| 337 | + 'file', |
|
| 338 | + $remoteId, |
|
| 339 | + [ |
|
| 340 | + 'sharedSecret' => $token, |
|
| 341 | + 'message' => 'Recipient accept the share' |
|
| 342 | + ] |
|
| 343 | + |
|
| 344 | + ); |
|
| 345 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 346 | + case 'decline': |
|
| 347 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 348 | + $notification->setMessage( |
|
| 349 | + 'SHARE_DECLINED', |
|
| 350 | + 'file', |
|
| 351 | + $remoteId, |
|
| 352 | + [ |
|
| 353 | + 'sharedSecret' => $token, |
|
| 354 | + 'message' => 'Recipient declined the share' |
|
| 355 | + ] |
|
| 356 | + |
|
| 357 | + ); |
|
| 358 | + return $this->cloudFederationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return false; |
|
| 362 | + |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * remove '/user/files' from the path and trailing slashes |
|
| 368 | + * |
|
| 369 | + * @param string $path |
|
| 370 | + * @return string |
|
| 371 | + */ |
|
| 372 | + protected function stripPath($path) { |
|
| 373 | + $prefix = '/' . $this->uid . '/files'; |
|
| 374 | + return rtrim(substr($path, strlen($prefix)), '/'); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + public function getMount($data) { |
|
| 378 | + $data['manager'] = $this; |
|
| 379 | + $mountPoint = '/' . $this->uid . '/files' . $data['mountpoint']; |
|
| 380 | + $data['mountpoint'] = $mountPoint; |
|
| 381 | + $data['certificateManager'] = \OC::$server->getCertificateManager($this->uid); |
|
| 382 | + return new Mount(self::STORAGE, $mountPoint, $data, $this, $this->storageLoader); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @param array $data |
|
| 387 | + * @return Mount |
|
| 388 | + */ |
|
| 389 | + protected function mountShare($data) { |
|
| 390 | + $mount = $this->getMount($data); |
|
| 391 | + $this->mountManager->addMount($mount); |
|
| 392 | + return $mount; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @return \OC\Files\Mount\Manager |
|
| 397 | + */ |
|
| 398 | + public function getMountManager() { |
|
| 399 | + return $this->mountManager; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * @param string $source |
|
| 404 | + * @param string $target |
|
| 405 | + * @return bool |
|
| 406 | + */ |
|
| 407 | + public function setMountPoint($source, $target) { |
|
| 408 | + $source = $this->stripPath($source); |
|
| 409 | + $target = $this->stripPath($target); |
|
| 410 | + $sourceHash = md5($source); |
|
| 411 | + $targetHash = md5($target); |
|
| 412 | + |
|
| 413 | + $query = $this->connection->prepare(' |
|
| 414 | 414 | UPDATE `*PREFIX*share_external` |
| 415 | 415 | SET `mountpoint` = ?, `mountpoint_hash` = ? |
| 416 | 416 | WHERE `mountpoint_hash` = ? |
| 417 | 417 | AND `user` = ? |
| 418 | 418 | '); |
| 419 | - $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
| 419 | + $result = (bool)$query->execute(array($target, $targetHash, $sourceHash, $this->uid)); |
|
| 420 | 420 | |
| 421 | - return $result; |
|
| 422 | - } |
|
| 421 | + return $result; |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - public function removeShare($mountPoint) { |
|
| 424 | + public function removeShare($mountPoint) { |
|
| 425 | 425 | |
| 426 | - $mountPointObj = $this->mountManager->find($mountPoint); |
|
| 427 | - $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
| 426 | + $mountPointObj = $this->mountManager->find($mountPoint); |
|
| 427 | + $id = $mountPointObj->getStorage()->getCache()->getId(''); |
|
| 428 | 428 | |
| 429 | - $mountPoint = $this->stripPath($mountPoint); |
|
| 430 | - $hash = md5($mountPoint); |
|
| 429 | + $mountPoint = $this->stripPath($mountPoint); |
|
| 430 | + $hash = md5($mountPoint); |
|
| 431 | 431 | |
| 432 | - $getShare = $this->connection->prepare(' |
|
| 432 | + $getShare = $this->connection->prepare(' |
|
| 433 | 433 | SELECT `remote`, `share_token`, `remote_id` |
| 434 | 434 | FROM `*PREFIX*share_external` |
| 435 | 435 | WHERE `mountpoint_hash` = ? AND `user` = ?'); |
| 436 | - $result = $getShare->execute(array($hash, $this->uid)); |
|
| 437 | - |
|
| 438 | - if ($result) { |
|
| 439 | - try { |
|
| 440 | - $share = $getShare->fetch(); |
|
| 441 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 442 | - } catch (\Exception $e) { |
|
| 443 | - // if we fail to notify the remote (probably cause the remote is down) |
|
| 444 | - // we still want the share to be gone to prevent undeletable remotes |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - $getShare->closeCursor(); |
|
| 448 | - |
|
| 449 | - $query = $this->connection->prepare(' |
|
| 436 | + $result = $getShare->execute(array($hash, $this->uid)); |
|
| 437 | + |
|
| 438 | + if ($result) { |
|
| 439 | + try { |
|
| 440 | + $share = $getShare->fetch(); |
|
| 441 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 442 | + } catch (\Exception $e) { |
|
| 443 | + // if we fail to notify the remote (probably cause the remote is down) |
|
| 444 | + // we still want the share to be gone to prevent undeletable remotes |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + $getShare->closeCursor(); |
|
| 448 | + |
|
| 449 | + $query = $this->connection->prepare(' |
|
| 450 | 450 | DELETE FROM `*PREFIX*share_external` |
| 451 | 451 | WHERE `mountpoint_hash` = ? |
| 452 | 452 | AND `user` = ? |
| 453 | 453 | '); |
| 454 | - $result = (bool)$query->execute(array($hash, $this->uid)); |
|
| 455 | - |
|
| 456 | - if($result) { |
|
| 457 | - $this->removeReShares($id); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - return $result; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * remove re-shares from share table and mapping in the federated_reshares table |
|
| 465 | - * |
|
| 466 | - * @param $mountPointId |
|
| 467 | - */ |
|
| 468 | - protected function removeReShares($mountPointId) { |
|
| 469 | - $selectQuery = $this->connection->getQueryBuilder(); |
|
| 470 | - $query = $this->connection->getQueryBuilder(); |
|
| 471 | - $selectQuery->select('id')->from('share') |
|
| 472 | - ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
| 473 | - $select = $selectQuery->getSQL(); |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - $query->delete('federated_reshares') |
|
| 477 | - ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 478 | - $query->execute(); |
|
| 479 | - |
|
| 480 | - $deleteReShares = $this->connection->getQueryBuilder(); |
|
| 481 | - $deleteReShares->delete('share') |
|
| 482 | - ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
| 483 | - $deleteReShares->execute(); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * remove all shares for user $uid if the user was deleted |
|
| 488 | - * |
|
| 489 | - * @param string $uid |
|
| 490 | - * @return bool |
|
| 491 | - */ |
|
| 492 | - public function removeUserShares($uid) { |
|
| 493 | - $getShare = $this->connection->prepare(' |
|
| 454 | + $result = (bool)$query->execute(array($hash, $this->uid)); |
|
| 455 | + |
|
| 456 | + if($result) { |
|
| 457 | + $this->removeReShares($id); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + return $result; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * remove re-shares from share table and mapping in the federated_reshares table |
|
| 465 | + * |
|
| 466 | + * @param $mountPointId |
|
| 467 | + */ |
|
| 468 | + protected function removeReShares($mountPointId) { |
|
| 469 | + $selectQuery = $this->connection->getQueryBuilder(); |
|
| 470 | + $query = $this->connection->getQueryBuilder(); |
|
| 471 | + $selectQuery->select('id')->from('share') |
|
| 472 | + ->where($selectQuery->expr()->eq('file_source', $query->createNamedParameter($mountPointId))); |
|
| 473 | + $select = $selectQuery->getSQL(); |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + $query->delete('federated_reshares') |
|
| 477 | + ->where($query->expr()->in('share_id', $query->createFunction('(' . $select . ')'))); |
|
| 478 | + $query->execute(); |
|
| 479 | + |
|
| 480 | + $deleteReShares = $this->connection->getQueryBuilder(); |
|
| 481 | + $deleteReShares->delete('share') |
|
| 482 | + ->where($deleteReShares->expr()->eq('file_source', $deleteReShares->createNamedParameter($mountPointId))); |
|
| 483 | + $deleteReShares->execute(); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * remove all shares for user $uid if the user was deleted |
|
| 488 | + * |
|
| 489 | + * @param string $uid |
|
| 490 | + * @return bool |
|
| 491 | + */ |
|
| 492 | + public function removeUserShares($uid) { |
|
| 493 | + $getShare = $this->connection->prepare(' |
|
| 494 | 494 | SELECT `remote`, `share_token`, `remote_id` |
| 495 | 495 | FROM `*PREFIX*share_external` |
| 496 | 496 | WHERE `user` = ?'); |
| 497 | - $result = $getShare->execute(array($uid)); |
|
| 497 | + $result = $getShare->execute(array($uid)); |
|
| 498 | 498 | |
| 499 | - if ($result) { |
|
| 500 | - $shares = $getShare->fetchAll(); |
|
| 501 | - foreach($shares as $share) { |
|
| 502 | - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 503 | - } |
|
| 504 | - } |
|
| 499 | + if ($result) { |
|
| 500 | + $shares = $getShare->fetchAll(); |
|
| 501 | + foreach($shares as $share) { |
|
| 502 | + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - $query = $this->connection->prepare(' |
|
| 506 | + $query = $this->connection->prepare(' |
|
| 507 | 507 | DELETE FROM `*PREFIX*share_external` |
| 508 | 508 | WHERE `user` = ? |
| 509 | 509 | '); |
| 510 | - return (bool)$query->execute(array($uid)); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * return a list of shares which are not yet accepted by the user |
|
| 515 | - * |
|
| 516 | - * @return array list of open server-to-server shares |
|
| 517 | - */ |
|
| 518 | - public function getOpenShares() { |
|
| 519 | - return $this->getShares(false); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * return a list of shares which are accepted by the user |
|
| 524 | - * |
|
| 525 | - * @return array list of accepted server-to-server shares |
|
| 526 | - */ |
|
| 527 | - public function getAcceptedShares() { |
|
| 528 | - return $this->getShares(true); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * return a list of shares for the user |
|
| 533 | - * |
|
| 534 | - * @param bool|null $accepted True for accepted only, |
|
| 535 | - * false for not accepted, |
|
| 536 | - * null for all shares of the user |
|
| 537 | - * @return array list of open server-to-server shares |
|
| 538 | - */ |
|
| 539 | - private function getShares($accepted) { |
|
| 540 | - $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
| 510 | + return (bool)$query->execute(array($uid)); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * return a list of shares which are not yet accepted by the user |
|
| 515 | + * |
|
| 516 | + * @return array list of open server-to-server shares |
|
| 517 | + */ |
|
| 518 | + public function getOpenShares() { |
|
| 519 | + return $this->getShares(false); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * return a list of shares which are accepted by the user |
|
| 524 | + * |
|
| 525 | + * @return array list of accepted server-to-server shares |
|
| 526 | + */ |
|
| 527 | + public function getAcceptedShares() { |
|
| 528 | + return $this->getShares(true); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * return a list of shares for the user |
|
| 533 | + * |
|
| 534 | + * @param bool|null $accepted True for accepted only, |
|
| 535 | + * false for not accepted, |
|
| 536 | + * null for all shares of the user |
|
| 537 | + * @return array list of open server-to-server shares |
|
| 538 | + */ |
|
| 539 | + private function getShares($accepted) { |
|
| 540 | + $query = 'SELECT `id`, `remote`, `remote_id`, `share_token`, `name`, `owner`, `user`, `mountpoint`, `accepted` |
|
| 541 | 541 | FROM `*PREFIX*share_external` |
| 542 | 542 | WHERE `user` = ?'; |
| 543 | - $parameters = [$this->uid]; |
|
| 544 | - if (!is_null($accepted)) { |
|
| 545 | - $query .= ' AND `accepted` = ?'; |
|
| 546 | - $parameters[] = (int) $accepted; |
|
| 547 | - } |
|
| 548 | - $query .= ' ORDER BY `id` ASC'; |
|
| 549 | - |
|
| 550 | - $shares = $this->connection->prepare($query); |
|
| 551 | - $result = $shares->execute($parameters); |
|
| 552 | - |
|
| 553 | - return $result ? $shares->fetchAll() : []; |
|
| 554 | - } |
|
| 543 | + $parameters = [$this->uid]; |
|
| 544 | + if (!is_null($accepted)) { |
|
| 545 | + $query .= ' AND `accepted` = ?'; |
|
| 546 | + $parameters[] = (int) $accepted; |
|
| 547 | + } |
|
| 548 | + $query .= ' ORDER BY `id` ASC'; |
|
| 549 | + |
|
| 550 | + $shares = $this->connection->prepare($query); |
|
| 551 | + $result = $shares->execute($parameters); |
|
| 552 | + |
|
| 553 | + return $result ? $shares->fetchAll() : []; |
|
| 554 | + } |
|
| 555 | 555 | } |
@@ -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 bool |
|
| 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 bool |
|
| 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 mixed |
|
| 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 mixed |
|
| 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 | } |
@@ -39,114 +39,114 @@ |
||
| 39 | 39 | |
| 40 | 40 | class Application extends App { |
| 41 | 41 | |
| 42 | - /** @var FederatedShareProvider */ |
|
| 43 | - protected $federatedShareProvider; |
|
| 42 | + /** @var FederatedShareProvider */ |
|
| 43 | + protected $federatedShareProvider; |
|
| 44 | 44 | |
| 45 | - public function __construct() { |
|
| 46 | - parent::__construct('federatedfilesharing'); |
|
| 45 | + public function __construct() { |
|
| 46 | + parent::__construct('federatedfilesharing'); |
|
| 47 | 47 | |
| 48 | - $container = $this->getContainer(); |
|
| 49 | - $server = $container->getServer(); |
|
| 48 | + $container = $this->getContainer(); |
|
| 49 | + $server = $container->getServer(); |
|
| 50 | 50 | |
| 51 | - $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
| 52 | - $cloudFederationManager->addCloudFederationProvider('file', |
|
| 53 | - 'Federated Files Sharing', |
|
| 54 | - function() use ($container) { |
|
| 55 | - $server = $container->getServer(); |
|
| 56 | - return new CloudFederationProviderFiles( |
|
| 57 | - $server->getAppManager(), |
|
| 58 | - $server->query(FederatedShareProvider::class), |
|
| 59 | - $server->query(AddressHandler::class), |
|
| 60 | - $server->getLogger(), |
|
| 61 | - $server->getUserManager(), |
|
| 62 | - $server->getCloudIdManager(), |
|
| 63 | - $server->getActivityManager(), |
|
| 64 | - $server->getNotificationManager(), |
|
| 65 | - $server->getURLGenerator(), |
|
| 66 | - $server->getCloudFederationFactory(), |
|
| 67 | - $server->getCloudFederationProviderManager(), |
|
| 68 | - $server->getDatabaseConnection() |
|
| 69 | - ); |
|
| 70 | - }); |
|
| 51 | + $cloudFederationManager = $server->getCloudFederationProviderManager(); |
|
| 52 | + $cloudFederationManager->addCloudFederationProvider('file', |
|
| 53 | + 'Federated Files Sharing', |
|
| 54 | + function() use ($container) { |
|
| 55 | + $server = $container->getServer(); |
|
| 56 | + return new CloudFederationProviderFiles( |
|
| 57 | + $server->getAppManager(), |
|
| 58 | + $server->query(FederatedShareProvider::class), |
|
| 59 | + $server->query(AddressHandler::class), |
|
| 60 | + $server->getLogger(), |
|
| 61 | + $server->getUserManager(), |
|
| 62 | + $server->getCloudIdManager(), |
|
| 63 | + $server->getActivityManager(), |
|
| 64 | + $server->getNotificationManager(), |
|
| 65 | + $server->getURLGenerator(), |
|
| 66 | + $server->getCloudFederationFactory(), |
|
| 67 | + $server->getCloudFederationProviderManager(), |
|
| 68 | + $server->getDatabaseConnection() |
|
| 69 | + ); |
|
| 70 | + }); |
|
| 71 | 71 | |
| 72 | - $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
| 73 | - $addressHandler = new AddressHandler( |
|
| 74 | - $server->getURLGenerator(), |
|
| 75 | - $server->getL10N('federatedfilesharing'), |
|
| 76 | - $server->getCloudIdManager() |
|
| 77 | - ); |
|
| 78 | - $notification = new Notifications( |
|
| 79 | - $addressHandler, |
|
| 80 | - $server->getHTTPClientService(), |
|
| 81 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 82 | - \OC::$server->getJobList(), |
|
| 83 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 84 | - \OC::$server->getCloudFederationFactory() |
|
| 85 | - ); |
|
| 86 | - return new RequestHandlerController( |
|
| 87 | - $c->query('AppName'), |
|
| 88 | - $server->getRequest(), |
|
| 89 | - $this->getFederatedShareProvider(), |
|
| 90 | - $server->getDatabaseConnection(), |
|
| 91 | - $server->getShareManager(), |
|
| 92 | - $notification, |
|
| 93 | - $addressHandler, |
|
| 94 | - $server->getUserManager(), |
|
| 95 | - $server->getCloudIdManager(), |
|
| 96 | - $server->getLogger(), |
|
| 97 | - $server->getCloudFederationFactory(), |
|
| 98 | - $server->getCloudFederationProviderManager() |
|
| 99 | - ); |
|
| 100 | - }); |
|
| 101 | - } |
|
| 72 | + $container->registerService('RequestHandlerController', function(SimpleContainer $c) use ($server) { |
|
| 73 | + $addressHandler = new AddressHandler( |
|
| 74 | + $server->getURLGenerator(), |
|
| 75 | + $server->getL10N('federatedfilesharing'), |
|
| 76 | + $server->getCloudIdManager() |
|
| 77 | + ); |
|
| 78 | + $notification = new Notifications( |
|
| 79 | + $addressHandler, |
|
| 80 | + $server->getHTTPClientService(), |
|
| 81 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 82 | + \OC::$server->getJobList(), |
|
| 83 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 84 | + \OC::$server->getCloudFederationFactory() |
|
| 85 | + ); |
|
| 86 | + return new RequestHandlerController( |
|
| 87 | + $c->query('AppName'), |
|
| 88 | + $server->getRequest(), |
|
| 89 | + $this->getFederatedShareProvider(), |
|
| 90 | + $server->getDatabaseConnection(), |
|
| 91 | + $server->getShareManager(), |
|
| 92 | + $notification, |
|
| 93 | + $addressHandler, |
|
| 94 | + $server->getUserManager(), |
|
| 95 | + $server->getCloudIdManager(), |
|
| 96 | + $server->getLogger(), |
|
| 97 | + $server->getCloudFederationFactory(), |
|
| 98 | + $server->getCloudFederationProviderManager() |
|
| 99 | + ); |
|
| 100 | + }); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * get instance of federated share provider |
|
| 105 | - * |
|
| 106 | - * @return FederatedShareProvider |
|
| 107 | - */ |
|
| 108 | - public function getFederatedShareProvider() { |
|
| 109 | - if ($this->federatedShareProvider === null) { |
|
| 110 | - $this->initFederatedShareProvider(); |
|
| 111 | - } |
|
| 112 | - return $this->federatedShareProvider; |
|
| 113 | - } |
|
| 103 | + /** |
|
| 104 | + * get instance of federated share provider |
|
| 105 | + * |
|
| 106 | + * @return FederatedShareProvider |
|
| 107 | + */ |
|
| 108 | + public function getFederatedShareProvider() { |
|
| 109 | + if ($this->federatedShareProvider === null) { |
|
| 110 | + $this->initFederatedShareProvider(); |
|
| 111 | + } |
|
| 112 | + return $this->federatedShareProvider; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * initialize federated share provider |
|
| 117 | - */ |
|
| 118 | - protected function initFederatedShareProvider() { |
|
| 119 | - $c = $this->getContainer(); |
|
| 120 | - $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
| 121 | - \OC::$server->getURLGenerator(), |
|
| 122 | - \OC::$server->getL10N('federatedfilesharing'), |
|
| 123 | - \OC::$server->getCloudIdManager() |
|
| 124 | - ); |
|
| 125 | - $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
| 126 | - $addressHandler, |
|
| 127 | - \OC::$server->getHTTPClientService(), |
|
| 128 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 129 | - \OC::$server->getJobList(), |
|
| 130 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 131 | - \OC::$server->getCloudFederationFactory() |
|
| 132 | - ); |
|
| 133 | - $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
| 134 | - \OC::$server->getSecureRandom() |
|
| 135 | - ); |
|
| 115 | + /** |
|
| 116 | + * initialize federated share provider |
|
| 117 | + */ |
|
| 118 | + protected function initFederatedShareProvider() { |
|
| 119 | + $c = $this->getContainer(); |
|
| 120 | + $addressHandler = new \OCA\FederatedFileSharing\AddressHandler( |
|
| 121 | + \OC::$server->getURLGenerator(), |
|
| 122 | + \OC::$server->getL10N('federatedfilesharing'), |
|
| 123 | + \OC::$server->getCloudIdManager() |
|
| 124 | + ); |
|
| 125 | + $notifications = new \OCA\FederatedFileSharing\Notifications( |
|
| 126 | + $addressHandler, |
|
| 127 | + \OC::$server->getHTTPClientService(), |
|
| 128 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 129 | + \OC::$server->getJobList(), |
|
| 130 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 131 | + \OC::$server->getCloudFederationFactory() |
|
| 132 | + ); |
|
| 133 | + $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( |
|
| 134 | + \OC::$server->getSecureRandom() |
|
| 135 | + ); |
|
| 136 | 136 | |
| 137 | - $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
| 138 | - \OC::$server->getDatabaseConnection(), |
|
| 139 | - $addressHandler, |
|
| 140 | - $notifications, |
|
| 141 | - $tokenHandler, |
|
| 142 | - \OC::$server->getL10N('federatedfilesharing'), |
|
| 143 | - \OC::$server->getLogger(), |
|
| 144 | - \OC::$server->getLazyRootFolder(), |
|
| 145 | - \OC::$server->getConfig(), |
|
| 146 | - \OC::$server->getUserManager(), |
|
| 147 | - \OC::$server->getCloudIdManager(), |
|
| 148 | - $c->query(IConfig::class) |
|
| 149 | - ); |
|
| 150 | - } |
|
| 137 | + $this->federatedShareProvider = new \OCA\FederatedFileSharing\FederatedShareProvider( |
|
| 138 | + \OC::$server->getDatabaseConnection(), |
|
| 139 | + $addressHandler, |
|
| 140 | + $notifications, |
|
| 141 | + $tokenHandler, |
|
| 142 | + \OC::$server->getL10N('federatedfilesharing'), |
|
| 143 | + \OC::$server->getLogger(), |
|
| 144 | + \OC::$server->getLazyRootFolder(), |
|
| 145 | + \OC::$server->getConfig(), |
|
| 146 | + \OC::$server->getUserManager(), |
|
| 147 | + \OC::$server->getCloudIdManager(), |
|
| 148 | + $c->query(IConfig::class) |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | } |
@@ -33,434 +33,434 @@ |
||
| 33 | 33 | use OCP\OCS\IDiscoveryService; |
| 34 | 34 | |
| 35 | 35 | class Notifications { |
| 36 | - const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
| 37 | - |
|
| 38 | - /** @var AddressHandler */ |
|
| 39 | - private $addressHandler; |
|
| 40 | - |
|
| 41 | - /** @var IClientService */ |
|
| 42 | - private $httpClientService; |
|
| 43 | - |
|
| 44 | - /** @var IDiscoveryService */ |
|
| 45 | - private $discoveryService; |
|
| 46 | - |
|
| 47 | - /** @var IJobList */ |
|
| 48 | - private $jobList; |
|
| 49 | - |
|
| 50 | - /** @var ICloudFederationProviderManager */ |
|
| 51 | - private $federationProviderManager; |
|
| 52 | - |
|
| 53 | - /** @var ICloudFederationFactory */ |
|
| 54 | - private $cloudFederationFactory; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param AddressHandler $addressHandler |
|
| 58 | - * @param IClientService $httpClientService |
|
| 59 | - * @param IDiscoveryService $discoveryService |
|
| 60 | - * @param IJobList $jobList |
|
| 61 | - * @param ICloudFederationProviderManager $federationProviderManager |
|
| 62 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
| 63 | - */ |
|
| 64 | - public function __construct( |
|
| 65 | - AddressHandler $addressHandler, |
|
| 66 | - IClientService $httpClientService, |
|
| 67 | - IDiscoveryService $discoveryService, |
|
| 68 | - IJobList $jobList, |
|
| 69 | - ICloudFederationProviderManager $federationProviderManager, |
|
| 70 | - ICloudFederationFactory $cloudFederationFactory |
|
| 71 | - ) { |
|
| 72 | - $this->addressHandler = $addressHandler; |
|
| 73 | - $this->httpClientService = $httpClientService; |
|
| 74 | - $this->discoveryService = $discoveryService; |
|
| 75 | - $this->jobList = $jobList; |
|
| 76 | - $this->federationProviderManager = $federationProviderManager; |
|
| 77 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * send server-to-server share to remote server |
|
| 82 | - * |
|
| 83 | - * @param string $token |
|
| 84 | - * @param string $shareWith |
|
| 85 | - * @param string $name |
|
| 86 | - * @param int $remote_id |
|
| 87 | - * @param string $owner |
|
| 88 | - * @param string $ownerFederatedId |
|
| 89 | - * @param string $sharedBy |
|
| 90 | - * @param string $sharedByFederatedId |
|
| 91 | - * @return bool |
|
| 92 | - * @throws \OC\HintException |
|
| 93 | - * @throws \OC\ServerNotAvailableException |
|
| 94 | - */ |
|
| 95 | - public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
|
| 96 | - |
|
| 97 | - list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
| 98 | - |
|
| 99 | - if ($user && $remote) { |
|
| 100 | - $local = $this->addressHandler->generateRemoteURL(); |
|
| 101 | - |
|
| 102 | - $fields = array( |
|
| 103 | - 'shareWith' => $user, |
|
| 104 | - 'token' => $token, |
|
| 105 | - 'name' => $name, |
|
| 106 | - 'remoteId' => $remote_id, |
|
| 107 | - 'owner' => $owner, |
|
| 108 | - 'ownerFederatedId' => $ownerFederatedId, |
|
| 109 | - 'sharedBy' => $sharedBy, |
|
| 110 | - 'sharedByFederatedId' => $sharedByFederatedId, |
|
| 111 | - 'remote' => $local, |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
| 115 | - $status = json_decode($result['result'], true); |
|
| 116 | - |
|
| 117 | - $ocsStatus = isset($status['ocs']); |
|
| 118 | - $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
| 119 | - |
|
| 120 | - if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { |
|
| 121 | - \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
| 122 | - return true; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return false; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * ask owner to re-share the file with the given user |
|
| 132 | - * |
|
| 133 | - * @param string $token |
|
| 134 | - * @param int $id remote Id |
|
| 135 | - * @param int $shareId internal share Id |
|
| 136 | - * @param string $remote remote address of the owner |
|
| 137 | - * @param string $shareWith |
|
| 138 | - * @param int $permission |
|
| 139 | - * @param string $filename |
|
| 140 | - * @return bool |
|
| 141 | - * @throws \OC\HintException |
|
| 142 | - * @throws \OC\ServerNotAvailableException |
|
| 143 | - */ |
|
| 144 | - public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission, $filename) { |
|
| 145 | - |
|
| 146 | - $fields = array( |
|
| 147 | - 'shareWith' => $shareWith, |
|
| 148 | - 'token' => $token, |
|
| 149 | - 'permission' => $permission, |
|
| 150 | - 'remoteId' => $shareId, |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - $ocmFields = $fields; |
|
| 154 | - $ocmFields['remoteId'] = $id; |
|
| 155 | - $ocmFields['localId'] = $shareId; |
|
| 156 | - $ocmFields['name'] = $filename; |
|
| 157 | - |
|
| 158 | - $ocmResult = $this->tryOCMEndPoint($remote, $ocmFields, 'reshare'); |
|
| 159 | - if (is_array($ocmResult) && isset($ocmResult['token']) && isset($ocmResult['providerId'])) { |
|
| 160 | - return [$ocmResult['token'], $ocmResult['providerId']]; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
| 164 | - $status = json_decode($result['result'], true); |
|
| 165 | - |
|
| 166 | - $httpRequestSuccessful = $result['success']; |
|
| 167 | - $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
| 168 | - $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
| 169 | - $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
| 170 | - |
|
| 171 | - if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
| 172 | - return [ |
|
| 173 | - $status['ocs']['data']['token'], |
|
| 174 | - (int)$status['ocs']['data']['remoteId'] |
|
| 175 | - ]; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return false; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * send server-to-server unshare to remote server |
|
| 183 | - * |
|
| 184 | - * @param string $remote url |
|
| 185 | - * @param int $id share id |
|
| 186 | - * @param string $token |
|
| 187 | - * @return bool |
|
| 188 | - */ |
|
| 189 | - public function sendRemoteUnShare($remote, $id, $token) { |
|
| 190 | - $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * send server-to-server unshare to remote server |
|
| 195 | - * |
|
| 196 | - * @param string $remote url |
|
| 197 | - * @param int $id share id |
|
| 198 | - * @param string $token |
|
| 199 | - * @return bool |
|
| 200 | - */ |
|
| 201 | - public function sendRevokeShare($remote, $id, $token) { |
|
| 202 | - $this->sendUpdateToRemote($remote, $id, $token, 'reshare_undo'); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * send notification to remote server if the permissions was changed |
|
| 207 | - * |
|
| 208 | - * @param string $remote |
|
| 209 | - * @param int $remoteId |
|
| 210 | - * @param string $token |
|
| 211 | - * @param int $permissions |
|
| 212 | - * @return bool |
|
| 213 | - */ |
|
| 214 | - public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
| 215 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * forward accept reShare to remote server |
|
| 220 | - * |
|
| 221 | - * @param string $remote |
|
| 222 | - * @param int $remoteId |
|
| 223 | - * @param string $token |
|
| 224 | - */ |
|
| 225 | - public function sendAcceptShare($remote, $remoteId, $token) { |
|
| 226 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * forward decline reShare to remote server |
|
| 231 | - * |
|
| 232 | - * @param string $remote |
|
| 233 | - * @param int $remoteId |
|
| 234 | - * @param string $token |
|
| 235 | - */ |
|
| 236 | - public function sendDeclineShare($remote, $remoteId, $token) { |
|
| 237 | - $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * inform remote server whether server-to-server share was accepted/declined |
|
| 242 | - * |
|
| 243 | - * @param string $remote |
|
| 244 | - * @param string $token |
|
| 245 | - * @param int $remoteId Share id on the remote host |
|
| 246 | - * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
| 247 | - * @param array $data |
|
| 248 | - * @param int $try |
|
| 249 | - * @return boolean |
|
| 250 | - */ |
|
| 251 | - public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
| 252 | - |
|
| 253 | - $fields = [ |
|
| 254 | - 'token' => $token, |
|
| 255 | - 'remoteId' => $remoteId |
|
| 256 | - ]; |
|
| 257 | - foreach ($data as $key => $value) { |
|
| 258 | - $fields[$key] = $value; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action); |
|
| 262 | - $status = json_decode($result['result'], true); |
|
| 263 | - |
|
| 264 | - if ($result['success'] && |
|
| 265 | - ($status['ocs']['meta']['statuscode'] === 100 || |
|
| 266 | - $status['ocs']['meta']['statuscode'] === 200 |
|
| 267 | - ) |
|
| 268 | - ) { |
|
| 269 | - return true; |
|
| 270 | - } elseif ($try === 0) { |
|
| 271 | - // only add new job on first try |
|
| 272 | - $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
| 273 | - [ |
|
| 274 | - 'remote' => $remote, |
|
| 275 | - 'remoteId' => $remoteId, |
|
| 276 | - 'token' => $token, |
|
| 277 | - 'action' => $action, |
|
| 278 | - 'data' => json_encode($data), |
|
| 279 | - 'try' => $try, |
|
| 280 | - 'lastRun' => $this->getTimestamp() |
|
| 281 | - ] |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return false; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * return current timestamp |
|
| 291 | - * |
|
| 292 | - * @return int |
|
| 293 | - */ |
|
| 294 | - protected function getTimestamp() { |
|
| 295 | - return time(); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * try http post with the given protocol, if no protocol is given we pick |
|
| 300 | - * the secure one (https) |
|
| 301 | - * |
|
| 302 | - * @param string $remoteDomain |
|
| 303 | - * @param string $urlSuffix |
|
| 304 | - * @param array $fields post parameters |
|
| 305 | - * @param string $action define the action (possible values: share, reshare, accept, decline, unshare, revoke, permissions) |
|
| 306 | - * @return array |
|
| 307 | - * @throws \Exception |
|
| 308 | - */ |
|
| 309 | - protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") { |
|
| 310 | - |
|
| 311 | - if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
| 312 | - $remoteDomain = 'https://' . $remoteDomain; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $result = [ |
|
| 316 | - 'success' => false, |
|
| 317 | - 'result' => '', |
|
| 318 | - ]; |
|
| 319 | - |
|
| 320 | - // if possible we use the new OCM API |
|
| 321 | - $ocmResult = $this->tryOCMEndPoint($remoteDomain, $fields, $action); |
|
| 322 | - if (is_array($ocmResult)) { |
|
| 323 | - $result['success'] = true; |
|
| 324 | - $result['result'] = json_encode([ |
|
| 325 | - 'ocs' => ['meta' => ['statuscode' => 200]]]); |
|
| 326 | - return $result; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return $this->tryLegacyEndPoint($remoteDomain, $urlSuffix, $fields); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * try old federated sharing API if the OCM api doesn't work |
|
| 334 | - * |
|
| 335 | - * @param $remoteDomain |
|
| 336 | - * @param $urlSuffix |
|
| 337 | - * @param array $fields |
|
| 338 | - * @return mixed |
|
| 339 | - * @throws \Exception |
|
| 340 | - */ |
|
| 341 | - protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) { |
|
| 342 | - |
|
| 343 | - $result = [ |
|
| 344 | - 'success' => false, |
|
| 345 | - 'result' => '', |
|
| 346 | - ]; |
|
| 347 | - |
|
| 348 | - // Fall back to old API |
|
| 349 | - $client = $this->httpClientService->newClient(); |
|
| 350 | - $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
| 351 | - $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
| 352 | - try { |
|
| 353 | - $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
| 354 | - 'body' => $fields, |
|
| 355 | - 'timeout' => 10, |
|
| 356 | - 'connect_timeout' => 10, |
|
| 357 | - ]); |
|
| 358 | - $result['result'] = $response->getBody(); |
|
| 359 | - $result['success'] = true; |
|
| 360 | - } catch (\Exception $e) { |
|
| 361 | - // if flat re-sharing is not supported by the remote server |
|
| 362 | - // we re-throw the exception and fall back to the old behaviour. |
|
| 363 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
| 364 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
| 365 | - throw $e; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - return $result; |
|
| 370 | - |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * check if server supports the new OCM api and ask for the correct end-point |
|
| 375 | - * |
|
| 376 | - * @param string $url |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - protected function getOCMEndPoint($url) { |
|
| 380 | - $client = $this->httpClientService->newClient(); |
|
| 381 | - try { |
|
| 382 | - $response = $client->get($url, ['timeout' => 10, 'connect_timeout' => 10]); |
|
| 383 | - } catch (\Exception $e) { |
|
| 384 | - return ''; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $result = $response->getBody(); |
|
| 388 | - $result = json_decode($result, true); |
|
| 389 | - |
|
| 390 | - if (isset($result['end-point'])) { |
|
| 391 | - return $result['end-point']; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - return ''; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * send action regarding federated sharing to the remote server using the OCM API |
|
| 399 | - * |
|
| 400 | - * @param $remoteDomain |
|
| 401 | - * @param $fields |
|
| 402 | - * @param $action |
|
| 403 | - * |
|
| 404 | - * @return bool |
|
| 405 | - */ |
|
| 406 | - protected function tryOCMEndPoint($remoteDomain, $fields, $action) { |
|
| 407 | - switch ($action) { |
|
| 408 | - case 'share': |
|
| 409 | - $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
| 410 | - $fields['shareWith'] . '@' . $remoteDomain, |
|
| 411 | - $fields['name'], |
|
| 412 | - '', |
|
| 413 | - $fields['remoteId'], |
|
| 414 | - $fields['ownerFederatedId'], |
|
| 415 | - $fields['owner'], |
|
| 416 | - $fields['sharedByFederatedId'], |
|
| 417 | - $fields['sharedBy'], |
|
| 418 | - $fields['token'], |
|
| 419 | - 'user', |
|
| 420 | - 'file' |
|
| 421 | - ); |
|
| 422 | - return $this->federationProviderManager->sendShare($share); |
|
| 423 | - case 'reshare': |
|
| 424 | - // ask owner to reshare a file |
|
| 425 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 426 | - $notification->setMessage('REQUEST_RESHARE', |
|
| 427 | - 'file', |
|
| 428 | - $fields['remoteId'], |
|
| 429 | - [ |
|
| 430 | - 'sharedSecret' => $fields['token'], |
|
| 431 | - 'shareWith' => $fields['shareWith'], |
|
| 432 | - 'senderId' => $fields['localId'], |
|
| 433 | - 'message' => 'Ask owner to reshare the file' |
|
| 434 | - ] |
|
| 435 | - ); |
|
| 436 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 437 | - case 'unshare': |
|
| 438 | - //owner unshares the file from the recipient again |
|
| 439 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 440 | - $notification->setMessage('SHARE_UNSHARED', |
|
| 441 | - 'file', |
|
| 442 | - $fields['remoteId'], |
|
| 443 | - [ |
|
| 444 | - 'sharedSecret' => $fields['token'], |
|
| 445 | - 'messgage' => 'file is no longer shared with you' |
|
| 446 | - ] |
|
| 447 | - ); |
|
| 448 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 449 | - case 'reshare_undo': |
|
| 450 | - // if a reshare was unshared we send the information to the initiator/owner |
|
| 451 | - $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 452 | - $notification->setMessage('RESHARE_UNDO', |
|
| 453 | - 'file', |
|
| 454 | - $fields['remoteId'], |
|
| 455 | - [ |
|
| 456 | - 'sharedSecret' => $fields['token'], |
|
| 457 | - 'message' => 'reshare was revoked' |
|
| 458 | - ] |
|
| 459 | - ); |
|
| 460 | - return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - return false; |
|
| 464 | - |
|
| 465 | - } |
|
| 36 | + const RESPONSE_FORMAT = 'json'; // default response format for ocs calls |
|
| 37 | + |
|
| 38 | + /** @var AddressHandler */ |
|
| 39 | + private $addressHandler; |
|
| 40 | + |
|
| 41 | + /** @var IClientService */ |
|
| 42 | + private $httpClientService; |
|
| 43 | + |
|
| 44 | + /** @var IDiscoveryService */ |
|
| 45 | + private $discoveryService; |
|
| 46 | + |
|
| 47 | + /** @var IJobList */ |
|
| 48 | + private $jobList; |
|
| 49 | + |
|
| 50 | + /** @var ICloudFederationProviderManager */ |
|
| 51 | + private $federationProviderManager; |
|
| 52 | + |
|
| 53 | + /** @var ICloudFederationFactory */ |
|
| 54 | + private $cloudFederationFactory; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param AddressHandler $addressHandler |
|
| 58 | + * @param IClientService $httpClientService |
|
| 59 | + * @param IDiscoveryService $discoveryService |
|
| 60 | + * @param IJobList $jobList |
|
| 61 | + * @param ICloudFederationProviderManager $federationProviderManager |
|
| 62 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
| 63 | + */ |
|
| 64 | + public function __construct( |
|
| 65 | + AddressHandler $addressHandler, |
|
| 66 | + IClientService $httpClientService, |
|
| 67 | + IDiscoveryService $discoveryService, |
|
| 68 | + IJobList $jobList, |
|
| 69 | + ICloudFederationProviderManager $federationProviderManager, |
|
| 70 | + ICloudFederationFactory $cloudFederationFactory |
|
| 71 | + ) { |
|
| 72 | + $this->addressHandler = $addressHandler; |
|
| 73 | + $this->httpClientService = $httpClientService; |
|
| 74 | + $this->discoveryService = $discoveryService; |
|
| 75 | + $this->jobList = $jobList; |
|
| 76 | + $this->federationProviderManager = $federationProviderManager; |
|
| 77 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * send server-to-server share to remote server |
|
| 82 | + * |
|
| 83 | + * @param string $token |
|
| 84 | + * @param string $shareWith |
|
| 85 | + * @param string $name |
|
| 86 | + * @param int $remote_id |
|
| 87 | + * @param string $owner |
|
| 88 | + * @param string $ownerFederatedId |
|
| 89 | + * @param string $sharedBy |
|
| 90 | + * @param string $sharedByFederatedId |
|
| 91 | + * @return bool |
|
| 92 | + * @throws \OC\HintException |
|
| 93 | + * @throws \OC\ServerNotAvailableException |
|
| 94 | + */ |
|
| 95 | + public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ownerFederatedId, $sharedBy, $sharedByFederatedId) { |
|
| 96 | + |
|
| 97 | + list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith); |
|
| 98 | + |
|
| 99 | + if ($user && $remote) { |
|
| 100 | + $local = $this->addressHandler->generateRemoteURL(); |
|
| 101 | + |
|
| 102 | + $fields = array( |
|
| 103 | + 'shareWith' => $user, |
|
| 104 | + 'token' => $token, |
|
| 105 | + 'name' => $name, |
|
| 106 | + 'remoteId' => $remote_id, |
|
| 107 | + 'owner' => $owner, |
|
| 108 | + 'ownerFederatedId' => $ownerFederatedId, |
|
| 109 | + 'sharedBy' => $sharedBy, |
|
| 110 | + 'sharedByFederatedId' => $sharedByFederatedId, |
|
| 111 | + 'remote' => $local, |
|
| 112 | + ); |
|
| 113 | + |
|
| 114 | + $result = $this->tryHttpPostToShareEndpoint($remote, '', $fields); |
|
| 115 | + $status = json_decode($result['result'], true); |
|
| 116 | + |
|
| 117 | + $ocsStatus = isset($status['ocs']); |
|
| 118 | + $ocsSuccess = $ocsStatus && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200); |
|
| 119 | + |
|
| 120 | + if ($result['success'] && (!$ocsStatus ||$ocsSuccess)) { |
|
| 121 | + \OC_Hook::emit('OCP\Share', 'federated_share_added', ['server' => $remote]); |
|
| 122 | + return true; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * ask owner to re-share the file with the given user |
|
| 132 | + * |
|
| 133 | + * @param string $token |
|
| 134 | + * @param int $id remote Id |
|
| 135 | + * @param int $shareId internal share Id |
|
| 136 | + * @param string $remote remote address of the owner |
|
| 137 | + * @param string $shareWith |
|
| 138 | + * @param int $permission |
|
| 139 | + * @param string $filename |
|
| 140 | + * @return bool |
|
| 141 | + * @throws \OC\HintException |
|
| 142 | + * @throws \OC\ServerNotAvailableException |
|
| 143 | + */ |
|
| 144 | + public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission, $filename) { |
|
| 145 | + |
|
| 146 | + $fields = array( |
|
| 147 | + 'shareWith' => $shareWith, |
|
| 148 | + 'token' => $token, |
|
| 149 | + 'permission' => $permission, |
|
| 150 | + 'remoteId' => $shareId, |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + $ocmFields = $fields; |
|
| 154 | + $ocmFields['remoteId'] = $id; |
|
| 155 | + $ocmFields['localId'] = $shareId; |
|
| 156 | + $ocmFields['name'] = $filename; |
|
| 157 | + |
|
| 158 | + $ocmResult = $this->tryOCMEndPoint($remote, $ocmFields, 'reshare'); |
|
| 159 | + if (is_array($ocmResult) && isset($ocmResult['token']) && isset($ocmResult['providerId'])) { |
|
| 160 | + return [$ocmResult['token'], $ocmResult['providerId']]; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + $result = $this->tryLegacyEndPoint(rtrim($remote, '/'), '/' . $id . '/reshare', $fields); |
|
| 164 | + $status = json_decode($result['result'], true); |
|
| 165 | + |
|
| 166 | + $httpRequestSuccessful = $result['success']; |
|
| 167 | + $ocsCallSuccessful = $status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200; |
|
| 168 | + $validToken = isset($status['ocs']['data']['token']) && is_string($status['ocs']['data']['token']); |
|
| 169 | + $validRemoteId = isset($status['ocs']['data']['remoteId']); |
|
| 170 | + |
|
| 171 | + if ($httpRequestSuccessful && $ocsCallSuccessful && $validToken && $validRemoteId) { |
|
| 172 | + return [ |
|
| 173 | + $status['ocs']['data']['token'], |
|
| 174 | + (int)$status['ocs']['data']['remoteId'] |
|
| 175 | + ]; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * send server-to-server unshare to remote server |
|
| 183 | + * |
|
| 184 | + * @param string $remote url |
|
| 185 | + * @param int $id share id |
|
| 186 | + * @param string $token |
|
| 187 | + * @return bool |
|
| 188 | + */ |
|
| 189 | + public function sendRemoteUnShare($remote, $id, $token) { |
|
| 190 | + $this->sendUpdateToRemote($remote, $id, $token, 'unshare'); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * send server-to-server unshare to remote server |
|
| 195 | + * |
|
| 196 | + * @param string $remote url |
|
| 197 | + * @param int $id share id |
|
| 198 | + * @param string $token |
|
| 199 | + * @return bool |
|
| 200 | + */ |
|
| 201 | + public function sendRevokeShare($remote, $id, $token) { |
|
| 202 | + $this->sendUpdateToRemote($remote, $id, $token, 'reshare_undo'); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * send notification to remote server if the permissions was changed |
|
| 207 | + * |
|
| 208 | + * @param string $remote |
|
| 209 | + * @param int $remoteId |
|
| 210 | + * @param string $token |
|
| 211 | + * @param int $permissions |
|
| 212 | + * @return bool |
|
| 213 | + */ |
|
| 214 | + public function sendPermissionChange($remote, $remoteId, $token, $permissions) { |
|
| 215 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'permissions', ['permissions' => $permissions]); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * forward accept reShare to remote server |
|
| 220 | + * |
|
| 221 | + * @param string $remote |
|
| 222 | + * @param int $remoteId |
|
| 223 | + * @param string $token |
|
| 224 | + */ |
|
| 225 | + public function sendAcceptShare($remote, $remoteId, $token) { |
|
| 226 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'accept'); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * forward decline reShare to remote server |
|
| 231 | + * |
|
| 232 | + * @param string $remote |
|
| 233 | + * @param int $remoteId |
|
| 234 | + * @param string $token |
|
| 235 | + */ |
|
| 236 | + public function sendDeclineShare($remote, $remoteId, $token) { |
|
| 237 | + $this->sendUpdateToRemote($remote, $remoteId, $token, 'decline'); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * inform remote server whether server-to-server share was accepted/declined |
|
| 242 | + * |
|
| 243 | + * @param string $remote |
|
| 244 | + * @param string $token |
|
| 245 | + * @param int $remoteId Share id on the remote host |
|
| 246 | + * @param string $action possible actions: accept, decline, unshare, revoke, permissions |
|
| 247 | + * @param array $data |
|
| 248 | + * @param int $try |
|
| 249 | + * @return boolean |
|
| 250 | + */ |
|
| 251 | + public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { |
|
| 252 | + |
|
| 253 | + $fields = [ |
|
| 254 | + 'token' => $token, |
|
| 255 | + 'remoteId' => $remoteId |
|
| 256 | + ]; |
|
| 257 | + foreach ($data as $key => $value) { |
|
| 258 | + $fields[$key] = $value; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $result = $this->tryHttpPostToShareEndpoint(rtrim($remote, '/'), '/' . $remoteId . '/' . $action, $fields, $action); |
|
| 262 | + $status = json_decode($result['result'], true); |
|
| 263 | + |
|
| 264 | + if ($result['success'] && |
|
| 265 | + ($status['ocs']['meta']['statuscode'] === 100 || |
|
| 266 | + $status['ocs']['meta']['statuscode'] === 200 |
|
| 267 | + ) |
|
| 268 | + ) { |
|
| 269 | + return true; |
|
| 270 | + } elseif ($try === 0) { |
|
| 271 | + // only add new job on first try |
|
| 272 | + $this->jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob', |
|
| 273 | + [ |
|
| 274 | + 'remote' => $remote, |
|
| 275 | + 'remoteId' => $remoteId, |
|
| 276 | + 'token' => $token, |
|
| 277 | + 'action' => $action, |
|
| 278 | + 'data' => json_encode($data), |
|
| 279 | + 'try' => $try, |
|
| 280 | + 'lastRun' => $this->getTimestamp() |
|
| 281 | + ] |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return false; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * return current timestamp |
|
| 291 | + * |
|
| 292 | + * @return int |
|
| 293 | + */ |
|
| 294 | + protected function getTimestamp() { |
|
| 295 | + return time(); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * try http post with the given protocol, if no protocol is given we pick |
|
| 300 | + * the secure one (https) |
|
| 301 | + * |
|
| 302 | + * @param string $remoteDomain |
|
| 303 | + * @param string $urlSuffix |
|
| 304 | + * @param array $fields post parameters |
|
| 305 | + * @param string $action define the action (possible values: share, reshare, accept, decline, unshare, revoke, permissions) |
|
| 306 | + * @return array |
|
| 307 | + * @throws \Exception |
|
| 308 | + */ |
|
| 309 | + protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $fields, $action="share") { |
|
| 310 | + |
|
| 311 | + if ($this->addressHandler->urlContainProtocol($remoteDomain) === false) { |
|
| 312 | + $remoteDomain = 'https://' . $remoteDomain; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $result = [ |
|
| 316 | + 'success' => false, |
|
| 317 | + 'result' => '', |
|
| 318 | + ]; |
|
| 319 | + |
|
| 320 | + // if possible we use the new OCM API |
|
| 321 | + $ocmResult = $this->tryOCMEndPoint($remoteDomain, $fields, $action); |
|
| 322 | + if (is_array($ocmResult)) { |
|
| 323 | + $result['success'] = true; |
|
| 324 | + $result['result'] = json_encode([ |
|
| 325 | + 'ocs' => ['meta' => ['statuscode' => 200]]]); |
|
| 326 | + return $result; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return $this->tryLegacyEndPoint($remoteDomain, $urlSuffix, $fields); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * try old federated sharing API if the OCM api doesn't work |
|
| 334 | + * |
|
| 335 | + * @param $remoteDomain |
|
| 336 | + * @param $urlSuffix |
|
| 337 | + * @param array $fields |
|
| 338 | + * @return mixed |
|
| 339 | + * @throws \Exception |
|
| 340 | + */ |
|
| 341 | + protected function tryLegacyEndPoint($remoteDomain, $urlSuffix, array $fields) { |
|
| 342 | + |
|
| 343 | + $result = [ |
|
| 344 | + 'success' => false, |
|
| 345 | + 'result' => '', |
|
| 346 | + ]; |
|
| 347 | + |
|
| 348 | + // Fall back to old API |
|
| 349 | + $client = $this->httpClientService->newClient(); |
|
| 350 | + $federationEndpoints = $this->discoveryService->discover($remoteDomain, 'FEDERATED_SHARING'); |
|
| 351 | + $endpoint = isset($federationEndpoints['share']) ? $federationEndpoints['share'] : '/ocs/v2.php/cloud/shares'; |
|
| 352 | + try { |
|
| 353 | + $response = $client->post($remoteDomain . $endpoint . $urlSuffix . '?format=' . self::RESPONSE_FORMAT, [ |
|
| 354 | + 'body' => $fields, |
|
| 355 | + 'timeout' => 10, |
|
| 356 | + 'connect_timeout' => 10, |
|
| 357 | + ]); |
|
| 358 | + $result['result'] = $response->getBody(); |
|
| 359 | + $result['success'] = true; |
|
| 360 | + } catch (\Exception $e) { |
|
| 361 | + // if flat re-sharing is not supported by the remote server |
|
| 362 | + // we re-throw the exception and fall back to the old behaviour. |
|
| 363 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
| 364 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
| 365 | + throw $e; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + return $result; |
|
| 370 | + |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * check if server supports the new OCM api and ask for the correct end-point |
|
| 375 | + * |
|
| 376 | + * @param string $url |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + protected function getOCMEndPoint($url) { |
|
| 380 | + $client = $this->httpClientService->newClient(); |
|
| 381 | + try { |
|
| 382 | + $response = $client->get($url, ['timeout' => 10, 'connect_timeout' => 10]); |
|
| 383 | + } catch (\Exception $e) { |
|
| 384 | + return ''; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $result = $response->getBody(); |
|
| 388 | + $result = json_decode($result, true); |
|
| 389 | + |
|
| 390 | + if (isset($result['end-point'])) { |
|
| 391 | + return $result['end-point']; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + return ''; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * send action regarding federated sharing to the remote server using the OCM API |
|
| 399 | + * |
|
| 400 | + * @param $remoteDomain |
|
| 401 | + * @param $fields |
|
| 402 | + * @param $action |
|
| 403 | + * |
|
| 404 | + * @return bool |
|
| 405 | + */ |
|
| 406 | + protected function tryOCMEndPoint($remoteDomain, $fields, $action) { |
|
| 407 | + switch ($action) { |
|
| 408 | + case 'share': |
|
| 409 | + $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
| 410 | + $fields['shareWith'] . '@' . $remoteDomain, |
|
| 411 | + $fields['name'], |
|
| 412 | + '', |
|
| 413 | + $fields['remoteId'], |
|
| 414 | + $fields['ownerFederatedId'], |
|
| 415 | + $fields['owner'], |
|
| 416 | + $fields['sharedByFederatedId'], |
|
| 417 | + $fields['sharedBy'], |
|
| 418 | + $fields['token'], |
|
| 419 | + 'user', |
|
| 420 | + 'file' |
|
| 421 | + ); |
|
| 422 | + return $this->federationProviderManager->sendShare($share); |
|
| 423 | + case 'reshare': |
|
| 424 | + // ask owner to reshare a file |
|
| 425 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 426 | + $notification->setMessage('REQUEST_RESHARE', |
|
| 427 | + 'file', |
|
| 428 | + $fields['remoteId'], |
|
| 429 | + [ |
|
| 430 | + 'sharedSecret' => $fields['token'], |
|
| 431 | + 'shareWith' => $fields['shareWith'], |
|
| 432 | + 'senderId' => $fields['localId'], |
|
| 433 | + 'message' => 'Ask owner to reshare the file' |
|
| 434 | + ] |
|
| 435 | + ); |
|
| 436 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 437 | + case 'unshare': |
|
| 438 | + //owner unshares the file from the recipient again |
|
| 439 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 440 | + $notification->setMessage('SHARE_UNSHARED', |
|
| 441 | + 'file', |
|
| 442 | + $fields['remoteId'], |
|
| 443 | + [ |
|
| 444 | + 'sharedSecret' => $fields['token'], |
|
| 445 | + 'messgage' => 'file is no longer shared with you' |
|
| 446 | + ] |
|
| 447 | + ); |
|
| 448 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 449 | + case 'reshare_undo': |
|
| 450 | + // if a reshare was unshared we send the information to the initiator/owner |
|
| 451 | + $notification = $this->cloudFederationFactory->getCloudFederationNotification(); |
|
| 452 | + $notification->setMessage('RESHARE_UNDO', |
|
| 453 | + 'file', |
|
| 454 | + $fields['remoteId'], |
|
| 455 | + [ |
|
| 456 | + 'sharedSecret' => $fields['token'], |
|
| 457 | + 'message' => 'reshare was revoked' |
|
| 458 | + ] |
|
| 459 | + ); |
|
| 460 | + return $this->federationProviderManager->sendNotification($remoteDomain, $notification); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + return false; |
|
| 464 | + |
|
| 465 | + } |
|
| 466 | 466 | } |
@@ -52,454 +52,454 @@ |
||
| 52 | 52 | |
| 53 | 53 | class RequestHandlerController extends OCSController { |
| 54 | 54 | |
| 55 | - /** @var FederatedShareProvider */ |
|
| 56 | - private $federatedShareProvider; |
|
| 57 | - |
|
| 58 | - /** @var IDBConnection */ |
|
| 59 | - private $connection; |
|
| 60 | - |
|
| 61 | - /** @var Share\IManager */ |
|
| 62 | - private $shareManager; |
|
| 63 | - |
|
| 64 | - /** @var Notifications */ |
|
| 65 | - private $notifications; |
|
| 66 | - |
|
| 67 | - /** @var AddressHandler */ |
|
| 68 | - private $addressHandler; |
|
| 69 | - |
|
| 70 | - /** @var IUserManager */ |
|
| 71 | - private $userManager; |
|
| 72 | - |
|
| 73 | - /** @var string */ |
|
| 74 | - private $shareTable = 'share'; |
|
| 75 | - |
|
| 76 | - /** @var ICloudIdManager */ |
|
| 77 | - private $cloudIdManager; |
|
| 78 | - |
|
| 79 | - /** @var ILogger */ |
|
| 80 | - private $logger; |
|
| 81 | - |
|
| 82 | - /** @var ICloudFederationFactory */ |
|
| 83 | - private $cloudFederationFactory; |
|
| 84 | - |
|
| 85 | - /** @var ICloudFederationProviderManager */ |
|
| 86 | - private $cloudFederationProviderManager; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Server2Server constructor. |
|
| 90 | - * |
|
| 91 | - * @param string $appName |
|
| 92 | - * @param IRequest $request |
|
| 93 | - * @param FederatedShareProvider $federatedShareProvider |
|
| 94 | - * @param IDBConnection $connection |
|
| 95 | - * @param Share\IManager $shareManager |
|
| 96 | - * @param Notifications $notifications |
|
| 97 | - * @param AddressHandler $addressHandler |
|
| 98 | - * @param IUserManager $userManager |
|
| 99 | - * @param ICloudIdManager $cloudIdManager |
|
| 100 | - * @param ILogger $logger |
|
| 101 | - * @param ICloudFederationFactory $cloudFederationFactory |
|
| 102 | - * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 103 | - */ |
|
| 104 | - public function __construct($appName, |
|
| 105 | - IRequest $request, |
|
| 106 | - FederatedShareProvider $federatedShareProvider, |
|
| 107 | - IDBConnection $connection, |
|
| 108 | - Share\IManager $shareManager, |
|
| 109 | - Notifications $notifications, |
|
| 110 | - AddressHandler $addressHandler, |
|
| 111 | - IUserManager $userManager, |
|
| 112 | - ICloudIdManager $cloudIdManager, |
|
| 113 | - ILogger $logger, |
|
| 114 | - ICloudFederationFactory $cloudFederationFactory, |
|
| 115 | - ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 116 | - ) { |
|
| 117 | - parent::__construct($appName, $request); |
|
| 118 | - |
|
| 119 | - $this->federatedShareProvider = $federatedShareProvider; |
|
| 120 | - $this->connection = $connection; |
|
| 121 | - $this->shareManager = $shareManager; |
|
| 122 | - $this->notifications = $notifications; |
|
| 123 | - $this->addressHandler = $addressHandler; |
|
| 124 | - $this->userManager = $userManager; |
|
| 125 | - $this->cloudIdManager = $cloudIdManager; |
|
| 126 | - $this->logger = $logger; |
|
| 127 | - $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 128 | - $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @NoCSRFRequired |
|
| 133 | - * @PublicPage |
|
| 134 | - * |
|
| 135 | - * create a new share |
|
| 136 | - * |
|
| 137 | - * @return Http\DataResponse |
|
| 138 | - * @throws OCSException |
|
| 139 | - */ |
|
| 140 | - public function createShare() { |
|
| 141 | - |
|
| 142 | - $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
| 143 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
| 144 | - $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
| 145 | - $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
| 146 | - $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
| 147 | - $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
| 148 | - $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
| 149 | - $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
| 150 | - $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
| 151 | - |
|
| 152 | - if ($ownerFederatedId === null) { |
|
| 153 | - $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
| 154 | - } |
|
| 155 | - // if the owner of the share and the initiator are the same user |
|
| 156 | - // we also complete the federated share ID for the initiator |
|
| 157 | - if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
| 158 | - $sharedByFederatedId = $ownerFederatedId; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
| 162 | - $shareWith, |
|
| 163 | - $name, |
|
| 164 | - '', |
|
| 165 | - $remoteId, |
|
| 166 | - $ownerFederatedId, |
|
| 167 | - $owner, |
|
| 168 | - $sharedByFederatedId, |
|
| 169 | - $sharedBy, |
|
| 170 | - $token, |
|
| 171 | - 'user', |
|
| 172 | - 'file' |
|
| 173 | - ); |
|
| 174 | - |
|
| 175 | - try { |
|
| 176 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 177 | - $provider->shareReceived($share); |
|
| 178 | - } catch (ProviderDoesNotExistsException $e) { |
|
| 179 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 180 | - } catch (ProviderCouldNotAddShareException $e) { |
|
| 181 | - throw new OCSException($e->getMessage(), $e->getCode()); |
|
| 182 | - } catch (\Exception $e) { |
|
| 183 | - throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - return new Http\DataResponse(); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @NoCSRFRequired |
|
| 191 | - * @PublicPage |
|
| 192 | - * |
|
| 193 | - * create re-share on behalf of another user |
|
| 194 | - * |
|
| 195 | - * @param int $id |
|
| 196 | - * @return Http\DataResponse |
|
| 197 | - * @throws OCSBadRequestException |
|
| 198 | - * @throws OCSException |
|
| 199 | - * @throws OCSForbiddenException |
|
| 200 | - */ |
|
| 201 | - public function reShare($id) { |
|
| 202 | - |
|
| 203 | - $token = $this->request->getParam('token', null); |
|
| 204 | - $shareWith = $this->request->getParam('shareWith', null); |
|
| 205 | - $permission = (int)$this->request->getParam('permission', null); |
|
| 206 | - $remoteId = (int)$this->request->getParam('remoteId', null); |
|
| 207 | - |
|
| 208 | - if ($id === null || |
|
| 209 | - $token === null || |
|
| 210 | - $shareWith === null || |
|
| 211 | - $permission === null || |
|
| 212 | - $remoteId === null |
|
| 213 | - ) { |
|
| 214 | - throw new OCSBadRequestException(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $notification = [ |
|
| 218 | - 'sharedSecret' => $token, |
|
| 219 | - 'shareWith' => $shareWith, |
|
| 220 | - 'senderId' => $remoteId, |
|
| 221 | - 'message' => 'Recipient of a share ask the owner to reshare the file' |
|
| 222 | - ]; |
|
| 223 | - |
|
| 224 | - try { |
|
| 225 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 226 | - list($newToken, $localId) = $provider->notificationReceived('REQUEST_RESHARE', $id, $notification); |
|
| 227 | - return new Http\DataResponse([ |
|
| 228 | - 'token' => $newToken, |
|
| 229 | - 'remoteId' => $localId |
|
| 230 | - ]); |
|
| 231 | - } catch (ProviderDoesNotExistsException $e) { |
|
| 232 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 233 | - } catch (ShareNotFound $e) { |
|
| 234 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
| 235 | - } catch (\Exception $e) { |
|
| 236 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - throw new OCSBadRequestException(); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @NoCSRFRequired |
|
| 245 | - * @PublicPage |
|
| 246 | - * |
|
| 247 | - * accept server-to-server share |
|
| 248 | - * |
|
| 249 | - * @param int $id |
|
| 250 | - * @return Http\DataResponse |
|
| 251 | - * @throws OCSException |
|
| 252 | - * @throws ShareNotFound |
|
| 253 | - * @throws \OC\HintException |
|
| 254 | - */ |
|
| 255 | - public function acceptShare($id) { |
|
| 256 | - |
|
| 257 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
| 258 | - |
|
| 259 | - $notification = [ |
|
| 260 | - 'sharedSecret' => $token, |
|
| 261 | - 'message' => 'Recipient accept the share' |
|
| 262 | - ]; |
|
| 263 | - |
|
| 264 | - try { |
|
| 265 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 266 | - $provider->notificationReceived('SHARE_ACCEPTED', $id, $notification); |
|
| 267 | - } catch (ProviderDoesNotExistsException $e) { |
|
| 268 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 269 | - } catch (ShareNotFound $e) { |
|
| 270 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
| 271 | - } catch (\Exception $e) { |
|
| 272 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return new Http\DataResponse(); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @NoCSRFRequired |
|
| 280 | - * @PublicPage |
|
| 281 | - * |
|
| 282 | - * decline server-to-server share |
|
| 283 | - * |
|
| 284 | - * @param int $id |
|
| 285 | - * @return Http\DataResponse |
|
| 286 | - * @throws OCSException |
|
| 287 | - */ |
|
| 288 | - public function declineShare($id) { |
|
| 289 | - |
|
| 290 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
| 291 | - |
|
| 292 | - $notification = [ |
|
| 293 | - 'sharedSecret' => $token, |
|
| 294 | - 'message' => 'Recipient declined the share' |
|
| 295 | - ]; |
|
| 296 | - |
|
| 297 | - try { |
|
| 298 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 299 | - $provider->notificationReceived('SHARE_DECLINED', $id, $notification); |
|
| 300 | - } catch (ProviderDoesNotExistsException $e) { |
|
| 301 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 302 | - } catch (ShareNotFound $e) { |
|
| 303 | - $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
| 304 | - } catch (\Exception $e) { |
|
| 305 | - $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return new Http\DataResponse(); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @NoCSRFRequired |
|
| 313 | - * @PublicPage |
|
| 314 | - * |
|
| 315 | - * remove server-to-server share if it was unshared by the owner |
|
| 316 | - * |
|
| 317 | - * @param int $id |
|
| 318 | - * @return Http\DataResponse |
|
| 319 | - * @throws OCSException |
|
| 320 | - */ |
|
| 321 | - public function unshare($id) { |
|
| 322 | - |
|
| 323 | - if (!$this->isS2SEnabled()) { |
|
| 324 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
| 328 | - |
|
| 329 | - try { |
|
| 330 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 331 | - $notification = ['sharedSecret' => $token]; |
|
| 332 | - $provider->notificationReceived('SHARE_UNSHARED', $id, $notification); |
|
| 333 | - } catch (\Exception $e) { |
|
| 334 | - $this->logger->debug('processing unshare notification failed: ' . $e->getMessage()); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return new Http\DataResponse(); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - private function cleanupRemote($remote) { |
|
| 341 | - $remote = substr($remote, strpos($remote, '://') + 3); |
|
| 342 | - |
|
| 343 | - return rtrim($remote, '/'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @NoCSRFRequired |
|
| 349 | - * @PublicPage |
|
| 350 | - * |
|
| 351 | - * federated share was revoked, either by the owner or the re-sharer |
|
| 352 | - * |
|
| 353 | - * @param int $id |
|
| 354 | - * @return Http\DataResponse |
|
| 355 | - * @throws OCSBadRequestException |
|
| 356 | - */ |
|
| 357 | - public function revoke($id) { |
|
| 358 | - |
|
| 359 | - $token = $this->request->getParam('token'); |
|
| 360 | - |
|
| 361 | - try { |
|
| 362 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 363 | - $notification = ['sharedSecret' => $token]; |
|
| 364 | - $provider->notificationReceived('RESHARE_UNDO', $id, $notification); |
|
| 365 | - return new Http\DataResponse(); |
|
| 366 | - } catch (\Exception $e) { |
|
| 367 | - throw new OCSBadRequestException(); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * get share |
|
| 374 | - * |
|
| 375 | - * @param int $id |
|
| 376 | - * @param string $token |
|
| 377 | - * @return array|bool |
|
| 378 | - */ |
|
| 379 | - protected function getShare($id, $token) { |
|
| 380 | - $query = $this->connection->getQueryBuilder(); |
|
| 381 | - $query->select('*')->from($this->shareTable) |
|
| 382 | - ->where($query->expr()->eq('token', $query->createNamedParameter($token))) |
|
| 383 | - ->andWhere($query->expr()->eq('share_type', $query->createNamedParameter(FederatedShareProvider::SHARE_TYPE_REMOTE))) |
|
| 384 | - ->andWhere($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
| 385 | - |
|
| 386 | - $result = $query->execute()->fetchAll(); |
|
| 387 | - |
|
| 388 | - if (!empty($result) && isset($result[0])) { |
|
| 389 | - return $result[0]; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return false; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * check if server-to-server sharing is enabled |
|
| 397 | - * |
|
| 398 | - * @param bool $incoming |
|
| 399 | - * @return bool |
|
| 400 | - */ |
|
| 401 | - private function isS2SEnabled($incoming = false) { |
|
| 402 | - |
|
| 403 | - $result = \OCP\App::isEnabled('files_sharing'); |
|
| 404 | - |
|
| 405 | - if ($incoming) { |
|
| 406 | - $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
| 407 | - } else { |
|
| 408 | - $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - return $result; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @NoCSRFRequired |
|
| 416 | - * @PublicPage |
|
| 417 | - * |
|
| 418 | - * update share information to keep federated re-shares in sync |
|
| 419 | - * |
|
| 420 | - * @param int $id |
|
| 421 | - * @return Http\DataResponse |
|
| 422 | - * @throws OCSBadRequestException |
|
| 423 | - */ |
|
| 424 | - public function updatePermissions($id) { |
|
| 425 | - $token = $this->request->getParam('token', null); |
|
| 426 | - $ncPermissions = $this->request->getParam('permissions', null); |
|
| 427 | - |
|
| 428 | - try { |
|
| 429 | - $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 430 | - $ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions); |
|
| 431 | - $notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions]; |
|
| 432 | - $provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification); |
|
| 433 | - } catch (\Exception $e) { |
|
| 434 | - $this->logger->debug($e->getMessage()); |
|
| 435 | - throw new OCSBadRequestException(); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return new Http\DataResponse(); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * translate Nextcloud permissions to OCM Permissions |
|
| 443 | - * |
|
| 444 | - * @param $ncPermissions |
|
| 445 | - * @return array |
|
| 446 | - */ |
|
| 447 | - protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
| 448 | - |
|
| 449 | - $ocmPermissions = []; |
|
| 450 | - |
|
| 451 | - if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
| 452 | - $ocmPermissions[] = 'share'; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - if ($ncPermissions & Constants::PERMISSION_READ) { |
|
| 456 | - $ocmPermissions[] = 'read'; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
| 460 | - ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
| 461 | - $ocmPermissions[] = 'write'; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return $ocmPermissions; |
|
| 465 | - |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * @NoCSRFRequired |
|
| 470 | - * @PublicPage |
|
| 471 | - * |
|
| 472 | - * change the owner of a server-to-server share |
|
| 473 | - * |
|
| 474 | - * @param int $id |
|
| 475 | - * @return Http\DataResponse |
|
| 476 | - * @throws \InvalidArgumentException |
|
| 477 | - * @throws OCSException |
|
| 478 | - */ |
|
| 479 | - public function move($id) { |
|
| 480 | - |
|
| 481 | - if (!$this->isS2SEnabled()) { |
|
| 482 | - throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - $token = $this->request->getParam('token'); |
|
| 486 | - $remote = $this->request->getParam('remote'); |
|
| 487 | - $newRemoteId = $this->request->getParam('remote_id', $id); |
|
| 488 | - $cloudId = $this->cloudIdManager->resolveCloudId($remote); |
|
| 489 | - |
|
| 490 | - $qb = $this->connection->getQueryBuilder(); |
|
| 491 | - $query = $qb->update('share_external') |
|
| 492 | - ->set('remote', $qb->createNamedParameter($cloudId->getRemote())) |
|
| 493 | - ->set('owner', $qb->createNamedParameter($cloudId->getUser())) |
|
| 494 | - ->set('remote_id', $qb->createNamedParameter($newRemoteId)) |
|
| 495 | - ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id))) |
|
| 496 | - ->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token))); |
|
| 497 | - $affected = $query->execute(); |
|
| 498 | - |
|
| 499 | - if ($affected > 0) { |
|
| 500 | - return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]); |
|
| 501 | - } else { |
|
| 502 | - throw new OCSBadRequestException('Share not found or token invalid'); |
|
| 503 | - } |
|
| 504 | - } |
|
| 55 | + /** @var FederatedShareProvider */ |
|
| 56 | + private $federatedShareProvider; |
|
| 57 | + |
|
| 58 | + /** @var IDBConnection */ |
|
| 59 | + private $connection; |
|
| 60 | + |
|
| 61 | + /** @var Share\IManager */ |
|
| 62 | + private $shareManager; |
|
| 63 | + |
|
| 64 | + /** @var Notifications */ |
|
| 65 | + private $notifications; |
|
| 66 | + |
|
| 67 | + /** @var AddressHandler */ |
|
| 68 | + private $addressHandler; |
|
| 69 | + |
|
| 70 | + /** @var IUserManager */ |
|
| 71 | + private $userManager; |
|
| 72 | + |
|
| 73 | + /** @var string */ |
|
| 74 | + private $shareTable = 'share'; |
|
| 75 | + |
|
| 76 | + /** @var ICloudIdManager */ |
|
| 77 | + private $cloudIdManager; |
|
| 78 | + |
|
| 79 | + /** @var ILogger */ |
|
| 80 | + private $logger; |
|
| 81 | + |
|
| 82 | + /** @var ICloudFederationFactory */ |
|
| 83 | + private $cloudFederationFactory; |
|
| 84 | + |
|
| 85 | + /** @var ICloudFederationProviderManager */ |
|
| 86 | + private $cloudFederationProviderManager; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Server2Server constructor. |
|
| 90 | + * |
|
| 91 | + * @param string $appName |
|
| 92 | + * @param IRequest $request |
|
| 93 | + * @param FederatedShareProvider $federatedShareProvider |
|
| 94 | + * @param IDBConnection $connection |
|
| 95 | + * @param Share\IManager $shareManager |
|
| 96 | + * @param Notifications $notifications |
|
| 97 | + * @param AddressHandler $addressHandler |
|
| 98 | + * @param IUserManager $userManager |
|
| 99 | + * @param ICloudIdManager $cloudIdManager |
|
| 100 | + * @param ILogger $logger |
|
| 101 | + * @param ICloudFederationFactory $cloudFederationFactory |
|
| 102 | + * @param ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 103 | + */ |
|
| 104 | + public function __construct($appName, |
|
| 105 | + IRequest $request, |
|
| 106 | + FederatedShareProvider $federatedShareProvider, |
|
| 107 | + IDBConnection $connection, |
|
| 108 | + Share\IManager $shareManager, |
|
| 109 | + Notifications $notifications, |
|
| 110 | + AddressHandler $addressHandler, |
|
| 111 | + IUserManager $userManager, |
|
| 112 | + ICloudIdManager $cloudIdManager, |
|
| 113 | + ILogger $logger, |
|
| 114 | + ICloudFederationFactory $cloudFederationFactory, |
|
| 115 | + ICloudFederationProviderManager $cloudFederationProviderManager |
|
| 116 | + ) { |
|
| 117 | + parent::__construct($appName, $request); |
|
| 118 | + |
|
| 119 | + $this->federatedShareProvider = $federatedShareProvider; |
|
| 120 | + $this->connection = $connection; |
|
| 121 | + $this->shareManager = $shareManager; |
|
| 122 | + $this->notifications = $notifications; |
|
| 123 | + $this->addressHandler = $addressHandler; |
|
| 124 | + $this->userManager = $userManager; |
|
| 125 | + $this->cloudIdManager = $cloudIdManager; |
|
| 126 | + $this->logger = $logger; |
|
| 127 | + $this->cloudFederationFactory = $cloudFederationFactory; |
|
| 128 | + $this->cloudFederationProviderManager = $cloudFederationProviderManager; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @NoCSRFRequired |
|
| 133 | + * @PublicPage |
|
| 134 | + * |
|
| 135 | + * create a new share |
|
| 136 | + * |
|
| 137 | + * @return Http\DataResponse |
|
| 138 | + * @throws OCSException |
|
| 139 | + */ |
|
| 140 | + public function createShare() { |
|
| 141 | + |
|
| 142 | + $remote = isset($_POST['remote']) ? $_POST['remote'] : null; |
|
| 143 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
| 144 | + $name = isset($_POST['name']) ? $_POST['name'] : null; |
|
| 145 | + $owner = isset($_POST['owner']) ? $_POST['owner'] : null; |
|
| 146 | + $sharedBy = isset($_POST['sharedBy']) ? $_POST['sharedBy'] : null; |
|
| 147 | + $shareWith = isset($_POST['shareWith']) ? $_POST['shareWith'] : null; |
|
| 148 | + $remoteId = isset($_POST['remoteId']) ? (int)$_POST['remoteId'] : null; |
|
| 149 | + $sharedByFederatedId = isset($_POST['sharedByFederatedId']) ? $_POST['sharedByFederatedId'] : null; |
|
| 150 | + $ownerFederatedId = isset($_POST['ownerFederatedId']) ? $_POST['ownerFederatedId'] : null; |
|
| 151 | + |
|
| 152 | + if ($ownerFederatedId === null) { |
|
| 153 | + $ownerFederatedId = $this->cloudIdManager->getCloudId($owner, $this->cleanupRemote($remote))->getId(); |
|
| 154 | + } |
|
| 155 | + // if the owner of the share and the initiator are the same user |
|
| 156 | + // we also complete the federated share ID for the initiator |
|
| 157 | + if ($sharedByFederatedId === null && $owner === $sharedBy) { |
|
| 158 | + $sharedByFederatedId = $ownerFederatedId; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $share = $this->cloudFederationFactory->getCloudFederationShare( |
|
| 162 | + $shareWith, |
|
| 163 | + $name, |
|
| 164 | + '', |
|
| 165 | + $remoteId, |
|
| 166 | + $ownerFederatedId, |
|
| 167 | + $owner, |
|
| 168 | + $sharedByFederatedId, |
|
| 169 | + $sharedBy, |
|
| 170 | + $token, |
|
| 171 | + 'user', |
|
| 172 | + 'file' |
|
| 173 | + ); |
|
| 174 | + |
|
| 175 | + try { |
|
| 176 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 177 | + $provider->shareReceived($share); |
|
| 178 | + } catch (ProviderDoesNotExistsException $e) { |
|
| 179 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 180 | + } catch (ProviderCouldNotAddShareException $e) { |
|
| 181 | + throw new OCSException($e->getMessage(), $e->getCode()); |
|
| 182 | + } catch (\Exception $e) { |
|
| 183 | + throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + return new Http\DataResponse(); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @NoCSRFRequired |
|
| 191 | + * @PublicPage |
|
| 192 | + * |
|
| 193 | + * create re-share on behalf of another user |
|
| 194 | + * |
|
| 195 | + * @param int $id |
|
| 196 | + * @return Http\DataResponse |
|
| 197 | + * @throws OCSBadRequestException |
|
| 198 | + * @throws OCSException |
|
| 199 | + * @throws OCSForbiddenException |
|
| 200 | + */ |
|
| 201 | + public function reShare($id) { |
|
| 202 | + |
|
| 203 | + $token = $this->request->getParam('token', null); |
|
| 204 | + $shareWith = $this->request->getParam('shareWith', null); |
|
| 205 | + $permission = (int)$this->request->getParam('permission', null); |
|
| 206 | + $remoteId = (int)$this->request->getParam('remoteId', null); |
|
| 207 | + |
|
| 208 | + if ($id === null || |
|
| 209 | + $token === null || |
|
| 210 | + $shareWith === null || |
|
| 211 | + $permission === null || |
|
| 212 | + $remoteId === null |
|
| 213 | + ) { |
|
| 214 | + throw new OCSBadRequestException(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $notification = [ |
|
| 218 | + 'sharedSecret' => $token, |
|
| 219 | + 'shareWith' => $shareWith, |
|
| 220 | + 'senderId' => $remoteId, |
|
| 221 | + 'message' => 'Recipient of a share ask the owner to reshare the file' |
|
| 222 | + ]; |
|
| 223 | + |
|
| 224 | + try { |
|
| 225 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 226 | + list($newToken, $localId) = $provider->notificationReceived('REQUEST_RESHARE', $id, $notification); |
|
| 227 | + return new Http\DataResponse([ |
|
| 228 | + 'token' => $newToken, |
|
| 229 | + 'remoteId' => $localId |
|
| 230 | + ]); |
|
| 231 | + } catch (ProviderDoesNotExistsException $e) { |
|
| 232 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 233 | + } catch (ShareNotFound $e) { |
|
| 234 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
| 235 | + } catch (\Exception $e) { |
|
| 236 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + throw new OCSBadRequestException(); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @NoCSRFRequired |
|
| 245 | + * @PublicPage |
|
| 246 | + * |
|
| 247 | + * accept server-to-server share |
|
| 248 | + * |
|
| 249 | + * @param int $id |
|
| 250 | + * @return Http\DataResponse |
|
| 251 | + * @throws OCSException |
|
| 252 | + * @throws ShareNotFound |
|
| 253 | + * @throws \OC\HintException |
|
| 254 | + */ |
|
| 255 | + public function acceptShare($id) { |
|
| 256 | + |
|
| 257 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
| 258 | + |
|
| 259 | + $notification = [ |
|
| 260 | + 'sharedSecret' => $token, |
|
| 261 | + 'message' => 'Recipient accept the share' |
|
| 262 | + ]; |
|
| 263 | + |
|
| 264 | + try { |
|
| 265 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 266 | + $provider->notificationReceived('SHARE_ACCEPTED', $id, $notification); |
|
| 267 | + } catch (ProviderDoesNotExistsException $e) { |
|
| 268 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 269 | + } catch (ShareNotFound $e) { |
|
| 270 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
| 271 | + } catch (\Exception $e) { |
|
| 272 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return new Http\DataResponse(); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @NoCSRFRequired |
|
| 280 | + * @PublicPage |
|
| 281 | + * |
|
| 282 | + * decline server-to-server share |
|
| 283 | + * |
|
| 284 | + * @param int $id |
|
| 285 | + * @return Http\DataResponse |
|
| 286 | + * @throws OCSException |
|
| 287 | + */ |
|
| 288 | + public function declineShare($id) { |
|
| 289 | + |
|
| 290 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
| 291 | + |
|
| 292 | + $notification = [ |
|
| 293 | + 'sharedSecret' => $token, |
|
| 294 | + 'message' => 'Recipient declined the share' |
|
| 295 | + ]; |
|
| 296 | + |
|
| 297 | + try { |
|
| 298 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 299 | + $provider->notificationReceived('SHARE_DECLINED', $id, $notification); |
|
| 300 | + } catch (ProviderDoesNotExistsException $e) { |
|
| 301 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 302 | + } catch (ShareNotFound $e) { |
|
| 303 | + $this->logger->debug('Share not found: ' . $e->getMessage()); |
|
| 304 | + } catch (\Exception $e) { |
|
| 305 | + $this->logger->debug('internal server error, can not process notification: ' . $e->getMessage()); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return new Http\DataResponse(); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @NoCSRFRequired |
|
| 313 | + * @PublicPage |
|
| 314 | + * |
|
| 315 | + * remove server-to-server share if it was unshared by the owner |
|
| 316 | + * |
|
| 317 | + * @param int $id |
|
| 318 | + * @return Http\DataResponse |
|
| 319 | + * @throws OCSException |
|
| 320 | + */ |
|
| 321 | + public function unshare($id) { |
|
| 322 | + |
|
| 323 | + if (!$this->isS2SEnabled()) { |
|
| 324 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $token = isset($_POST['token']) ? $_POST['token'] : null; |
|
| 328 | + |
|
| 329 | + try { |
|
| 330 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 331 | + $notification = ['sharedSecret' => $token]; |
|
| 332 | + $provider->notificationReceived('SHARE_UNSHARED', $id, $notification); |
|
| 333 | + } catch (\Exception $e) { |
|
| 334 | + $this->logger->debug('processing unshare notification failed: ' . $e->getMessage()); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return new Http\DataResponse(); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + private function cleanupRemote($remote) { |
|
| 341 | + $remote = substr($remote, strpos($remote, '://') + 3); |
|
| 342 | + |
|
| 343 | + return rtrim($remote, '/'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @NoCSRFRequired |
|
| 349 | + * @PublicPage |
|
| 350 | + * |
|
| 351 | + * federated share was revoked, either by the owner or the re-sharer |
|
| 352 | + * |
|
| 353 | + * @param int $id |
|
| 354 | + * @return Http\DataResponse |
|
| 355 | + * @throws OCSBadRequestException |
|
| 356 | + */ |
|
| 357 | + public function revoke($id) { |
|
| 358 | + |
|
| 359 | + $token = $this->request->getParam('token'); |
|
| 360 | + |
|
| 361 | + try { |
|
| 362 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 363 | + $notification = ['sharedSecret' => $token]; |
|
| 364 | + $provider->notificationReceived('RESHARE_UNDO', $id, $notification); |
|
| 365 | + return new Http\DataResponse(); |
|
| 366 | + } catch (\Exception $e) { |
|
| 367 | + throw new OCSBadRequestException(); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * get share |
|
| 374 | + * |
|
| 375 | + * @param int $id |
|
| 376 | + * @param string $token |
|
| 377 | + * @return array|bool |
|
| 378 | + */ |
|
| 379 | + protected function getShare($id, $token) { |
|
| 380 | + $query = $this->connection->getQueryBuilder(); |
|
| 381 | + $query->select('*')->from($this->shareTable) |
|
| 382 | + ->where($query->expr()->eq('token', $query->createNamedParameter($token))) |
|
| 383 | + ->andWhere($query->expr()->eq('share_type', $query->createNamedParameter(FederatedShareProvider::SHARE_TYPE_REMOTE))) |
|
| 384 | + ->andWhere($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
| 385 | + |
|
| 386 | + $result = $query->execute()->fetchAll(); |
|
| 387 | + |
|
| 388 | + if (!empty($result) && isset($result[0])) { |
|
| 389 | + return $result[0]; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return false; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * check if server-to-server sharing is enabled |
|
| 397 | + * |
|
| 398 | + * @param bool $incoming |
|
| 399 | + * @return bool |
|
| 400 | + */ |
|
| 401 | + private function isS2SEnabled($incoming = false) { |
|
| 402 | + |
|
| 403 | + $result = \OCP\App::isEnabled('files_sharing'); |
|
| 404 | + |
|
| 405 | + if ($incoming) { |
|
| 406 | + $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled(); |
|
| 407 | + } else { |
|
| 408 | + $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + return $result; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @NoCSRFRequired |
|
| 416 | + * @PublicPage |
|
| 417 | + * |
|
| 418 | + * update share information to keep federated re-shares in sync |
|
| 419 | + * |
|
| 420 | + * @param int $id |
|
| 421 | + * @return Http\DataResponse |
|
| 422 | + * @throws OCSBadRequestException |
|
| 423 | + */ |
|
| 424 | + public function updatePermissions($id) { |
|
| 425 | + $token = $this->request->getParam('token', null); |
|
| 426 | + $ncPermissions = $this->request->getParam('permissions', null); |
|
| 427 | + |
|
| 428 | + try { |
|
| 429 | + $provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file'); |
|
| 430 | + $ocmPermissions = $this->ncPermissions2ocmPermissions((int)$ncPermissions); |
|
| 431 | + $notification = ['sharedSecret' => $token, 'permission' => $ocmPermissions]; |
|
| 432 | + $provider->notificationReceived('RESHARE_CHANGE_PERMISSION', $id, $notification); |
|
| 433 | + } catch (\Exception $e) { |
|
| 434 | + $this->logger->debug($e->getMessage()); |
|
| 435 | + throw new OCSBadRequestException(); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return new Http\DataResponse(); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * translate Nextcloud permissions to OCM Permissions |
|
| 443 | + * |
|
| 444 | + * @param $ncPermissions |
|
| 445 | + * @return array |
|
| 446 | + */ |
|
| 447 | + protected function ncPermissions2ocmPermissions($ncPermissions) { |
|
| 448 | + |
|
| 449 | + $ocmPermissions = []; |
|
| 450 | + |
|
| 451 | + if ($ncPermissions & Constants::PERMISSION_SHARE) { |
|
| 452 | + $ocmPermissions[] = 'share'; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + if ($ncPermissions & Constants::PERMISSION_READ) { |
|
| 456 | + $ocmPermissions[] = 'read'; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + if (($ncPermissions & Constants::PERMISSION_CREATE) || |
|
| 460 | + ($ncPermissions & Constants::PERMISSION_UPDATE)) { |
|
| 461 | + $ocmPermissions[] = 'write'; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return $ocmPermissions; |
|
| 465 | + |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * @NoCSRFRequired |
|
| 470 | + * @PublicPage |
|
| 471 | + * |
|
| 472 | + * change the owner of a server-to-server share |
|
| 473 | + * |
|
| 474 | + * @param int $id |
|
| 475 | + * @return Http\DataResponse |
|
| 476 | + * @throws \InvalidArgumentException |
|
| 477 | + * @throws OCSException |
|
| 478 | + */ |
|
| 479 | + public function move($id) { |
|
| 480 | + |
|
| 481 | + if (!$this->isS2SEnabled()) { |
|
| 482 | + throw new OCSException('Server does not support federated cloud sharing', 503); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + $token = $this->request->getParam('token'); |
|
| 486 | + $remote = $this->request->getParam('remote'); |
|
| 487 | + $newRemoteId = $this->request->getParam('remote_id', $id); |
|
| 488 | + $cloudId = $this->cloudIdManager->resolveCloudId($remote); |
|
| 489 | + |
|
| 490 | + $qb = $this->connection->getQueryBuilder(); |
|
| 491 | + $query = $qb->update('share_external') |
|
| 492 | + ->set('remote', $qb->createNamedParameter($cloudId->getRemote())) |
|
| 493 | + ->set('owner', $qb->createNamedParameter($cloudId->getUser())) |
|
| 494 | + ->set('remote_id', $qb->createNamedParameter($newRemoteId)) |
|
| 495 | + ->where($qb->expr()->eq('remote_id', $qb->createNamedParameter($id))) |
|
| 496 | + ->andWhere($qb->expr()->eq('share_token', $qb->createNamedParameter($token))); |
|
| 497 | + $affected = $query->execute(); |
|
| 498 | + |
|
| 499 | + if ($affected > 0) { |
|
| 500 | + return new Http\DataResponse(['remote' => $cloudId->getRemote(), 'owner' => $cloudId->getUser()]); |
|
| 501 | + } else { |
|
| 502 | + throw new OCSBadRequestException('Share not found or token invalid'); |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | 505 | } |
@@ -39,42 +39,42 @@ |
||
| 39 | 39 | |
| 40 | 40 | interface ICloudFederationProvider { |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * get the name of the share type, handled by this provider |
|
| 44 | - * |
|
| 45 | - * @return string |
|
| 46 | - * |
|
| 47 | - * @since 14.0.0 |
|
| 48 | - */ |
|
| 49 | - public function getShareType(); |
|
| 42 | + /** |
|
| 43 | + * get the name of the share type, handled by this provider |
|
| 44 | + * |
|
| 45 | + * @return string |
|
| 46 | + * |
|
| 47 | + * @since 14.0.0 |
|
| 48 | + */ |
|
| 49 | + public function getShareType(); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * share received from another server |
|
| 53 | - * |
|
| 54 | - * @param ICloudFederationShare $share |
|
| 55 | - * @return string provider specific unique ID of the share |
|
| 56 | - * |
|
| 57 | - * @throws ProviderCouldNotAddShareException |
|
| 58 | - * |
|
| 59 | - * @since 14.0.0 |
|
| 60 | - */ |
|
| 61 | - public function shareReceived(ICloudFederationShare $share); |
|
| 51 | + /** |
|
| 52 | + * share received from another server |
|
| 53 | + * |
|
| 54 | + * @param ICloudFederationShare $share |
|
| 55 | + * @return string provider specific unique ID of the share |
|
| 56 | + * |
|
| 57 | + * @throws ProviderCouldNotAddShareException |
|
| 58 | + * |
|
| 59 | + * @since 14.0.0 |
|
| 60 | + */ |
|
| 61 | + public function shareReceived(ICloudFederationShare $share); |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * notification received from another server |
|
| 65 | - * |
|
| 66 | - * @param string $notificationType (e.g SHARE_ACCEPTED) |
|
| 67 | - * @param string $providerId share ID |
|
| 68 | - * @param array $notification provider specific notification |
|
| 69 | - * @return array $data send back to sender |
|
| 70 | - * |
|
| 71 | - * @throws ShareNotFound |
|
| 72 | - * @throws ActionNotSupportedException |
|
| 73 | - * @throws BadRequestException |
|
| 74 | - * @throws AuthenticationFailedException |
|
| 75 | - * |
|
| 76 | - * @since 14.0.0 |
|
| 77 | - */ |
|
| 78 | - public function notificationReceived($notificationType, $providerId, array $notification); |
|
| 63 | + /** |
|
| 64 | + * notification received from another server |
|
| 65 | + * |
|
| 66 | + * @param string $notificationType (e.g SHARE_ACCEPTED) |
|
| 67 | + * @param string $providerId share ID |
|
| 68 | + * @param array $notification provider specific notification |
|
| 69 | + * @return array $data send back to sender |
|
| 70 | + * |
|
| 71 | + * @throws ShareNotFound |
|
| 72 | + * @throws ActionNotSupportedException |
|
| 73 | + * @throws BadRequestException |
|
| 74 | + * @throws AuthenticationFailedException |
|
| 75 | + * |
|
| 76 | + * @since 14.0.0 |
|
| 77 | + */ |
|
| 78 | + public function notificationReceived($notificationType, $providerId, array $notification); |
|
| 79 | 79 | |
| 80 | 80 | } |