@@ -23,10 +23,10 @@ |
||
23 | 23 | |
24 | 24 | //.doc, .dot |
25 | 25 | class MSOfficeDoc extends Office { |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getMimeType() { |
|
30 | - return '/application\/msword/'; |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getMimeType() { |
|
30 | + return '/application\/msword/'; |
|
31 | + } |
|
32 | 32 | } |
@@ -24,10 +24,10 @@ |
||
24 | 24 | |
25 | 25 | // .otf, .ttf and .pfb |
26 | 26 | class Font extends Bitmap { |
27 | - /** |
|
28 | - * {@inheritDoc} |
|
29 | - */ |
|
30 | - public function getMimeType() { |
|
31 | - return '/application\/(?:font-sfnt|x-font$)/'; |
|
32 | - } |
|
27 | + /** |
|
28 | + * {@inheritDoc} |
|
29 | + */ |
|
30 | + public function getMimeType() { |
|
31 | + return '/application\/(?:font-sfnt|x-font$)/'; |
|
32 | + } |
|
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -25,10 +25,10 @@ |
||
25 | 25 | |
26 | 26 | //.eps |
27 | 27 | class Postscript extends Bitmap { |
28 | - /** |
|
29 | - * {@inheritDoc} |
|
30 | - */ |
|
31 | - public function getMimeType() { |
|
32 | - return '/application\/postscript/'; |
|
33 | - } |
|
28 | + /** |
|
29 | + * {@inheritDoc} |
|
30 | + */ |
|
31 | + public function getMimeType() { |
|
32 | + return '/application\/postscript/'; |
|
33 | + } |
|
34 | 34 | } |
@@ -22,15 +22,15 @@ |
||
22 | 22 | namespace OC\Share20; |
23 | 23 | |
24 | 24 | class Hooks { |
25 | - public static function post_deleteUser($arguments) { |
|
26 | - \OC::$server->getShareManager()->userDeleted($arguments['uid']); |
|
27 | - } |
|
25 | + public static function post_deleteUser($arguments) { |
|
26 | + \OC::$server->getShareManager()->userDeleted($arguments['uid']); |
|
27 | + } |
|
28 | 28 | |
29 | - public static function post_deleteGroup($arguments) { |
|
30 | - \OC::$server->getShareManager()->groupDeleted($arguments['gid']); |
|
31 | - } |
|
29 | + public static function post_deleteGroup($arguments) { |
|
30 | + \OC::$server->getShareManager()->groupDeleted($arguments['gid']); |
|
31 | + } |
|
32 | 32 | |
33 | - public static function post_removeFromGroup($arguments) { |
|
34 | - \OC::$server->getShareManager()->userDeletedFromGroup($arguments['uid'], $arguments['gid']); |
|
35 | - } |
|
33 | + public static function post_removeFromGroup($arguments) { |
|
34 | + \OC::$server->getShareManager()->userDeletedFromGroup($arguments['uid'], $arguments['gid']); |
|
35 | + } |
|
36 | 36 | } |
@@ -32,408 +32,408 @@ |
||
32 | 32 | |
33 | 33 | class Share implements \OCP\Share\IShare { |
34 | 34 | |
35 | - /** @var string */ |
|
36 | - private $id; |
|
37 | - /** @var string */ |
|
38 | - private $providerId; |
|
39 | - /** @var Node */ |
|
40 | - private $node; |
|
41 | - /** @var int */ |
|
42 | - private $fileId; |
|
43 | - /** @var string */ |
|
44 | - private $nodeType; |
|
45 | - /** @var int */ |
|
46 | - private $shareType; |
|
47 | - /** @var string */ |
|
48 | - private $sharedWith; |
|
49 | - /** @var string */ |
|
50 | - private $sharedBy; |
|
51 | - /** @var string */ |
|
52 | - private $shareOwner; |
|
53 | - /** @var int */ |
|
54 | - private $permissions; |
|
55 | - /** @var \DateTime */ |
|
56 | - private $expireDate; |
|
57 | - /** @var string */ |
|
58 | - private $password; |
|
59 | - /** @var string */ |
|
60 | - private $token; |
|
61 | - /** @var int */ |
|
62 | - private $parent; |
|
63 | - /** @var string */ |
|
64 | - private $target; |
|
65 | - /** @var \DateTime */ |
|
66 | - private $shareTime; |
|
67 | - /** @var bool */ |
|
68 | - private $mailSend; |
|
69 | - |
|
70 | - /** @var IRootFolder */ |
|
71 | - private $rootFolder; |
|
72 | - |
|
73 | - /** @var IUserManager */ |
|
74 | - private $userManager; |
|
75 | - |
|
76 | - /** @var ICacheEntry|null */ |
|
77 | - private $nodeCacheEntry; |
|
78 | - |
|
79 | - public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
80 | - $this->rootFolder = $rootFolder; |
|
81 | - $this->userManager = $userManager; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @inheritdoc |
|
86 | - */ |
|
87 | - public function setId($id) { |
|
88 | - if (is_int($id)) { |
|
89 | - $id = (string)$id; |
|
90 | - } |
|
91 | - |
|
92 | - if(!is_string($id)) { |
|
93 | - throw new \InvalidArgumentException('String expected.'); |
|
94 | - } |
|
95 | - |
|
96 | - if ($this->id !== null) { |
|
97 | - throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
98 | - } |
|
99 | - |
|
100 | - $this->id = trim($id); |
|
101 | - return $this; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @inheritdoc |
|
106 | - */ |
|
107 | - public function getId() { |
|
108 | - return $this->id; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @inheritdoc |
|
113 | - */ |
|
114 | - public function getFullId() { |
|
115 | - if ($this->providerId === null || $this->id === null) { |
|
116 | - throw new \UnexpectedValueException; |
|
117 | - } |
|
118 | - return $this->providerId . ':' . $this->id; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @inheritdoc |
|
123 | - */ |
|
124 | - public function setProviderId($id) { |
|
125 | - if(!is_string($id)) { |
|
126 | - throw new \InvalidArgumentException('String expected.'); |
|
127 | - } |
|
128 | - |
|
129 | - if ($this->providerId !== null) { |
|
130 | - throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
131 | - } |
|
132 | - |
|
133 | - $this->providerId = trim($id); |
|
134 | - return $this; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @inheritdoc |
|
139 | - */ |
|
140 | - public function setNode(Node $node) { |
|
141 | - $this->fileId = null; |
|
142 | - $this->nodeType = null; |
|
143 | - $this->node = $node; |
|
144 | - return $this; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @inheritdoc |
|
149 | - */ |
|
150 | - public function getNode() { |
|
151 | - if ($this->node === null) { |
|
152 | - |
|
153 | - if ($this->shareOwner === null || $this->fileId === null) { |
|
154 | - throw new NotFoundException(); |
|
155 | - } |
|
156 | - |
|
157 | - // for federated shares the owner can be a remote user, in this |
|
158 | - // case we use the initiator |
|
159 | - if($this->userManager->userExists($this->shareOwner)) { |
|
160 | - $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
161 | - } else { |
|
162 | - $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
163 | - } |
|
164 | - |
|
165 | - $nodes = $userFolder->getById($this->fileId); |
|
166 | - if (empty($nodes)) { |
|
167 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
168 | - } |
|
169 | - |
|
170 | - $this->node = $nodes[0]; |
|
171 | - } |
|
172 | - |
|
173 | - return $this->node; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @inheritdoc |
|
178 | - */ |
|
179 | - public function setNodeId($fileId) { |
|
180 | - $this->node = null; |
|
181 | - $this->fileId = $fileId; |
|
182 | - return $this; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @inheritdoc |
|
187 | - */ |
|
188 | - public function getNodeId() { |
|
189 | - if ($this->fileId === null) { |
|
190 | - $this->fileId = $this->getNode()->getId(); |
|
191 | - } |
|
192 | - |
|
193 | - return $this->fileId; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @inheritdoc |
|
198 | - */ |
|
199 | - public function setNodeType($type) { |
|
200 | - if ($type !== 'file' && $type !== 'folder') { |
|
201 | - throw new \InvalidArgumentException(); |
|
202 | - } |
|
203 | - |
|
204 | - $this->nodeType = $type; |
|
205 | - return $this; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @inheritdoc |
|
210 | - */ |
|
211 | - public function getNodeType() { |
|
212 | - if ($this->nodeType === null) { |
|
213 | - $node = $this->getNode(); |
|
214 | - $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
215 | - } |
|
216 | - |
|
217 | - return $this->nodeType; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @inheritdoc |
|
222 | - */ |
|
223 | - public function setShareType($shareType) { |
|
224 | - $this->shareType = $shareType; |
|
225 | - return $this; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @inheritdoc |
|
230 | - */ |
|
231 | - public function getShareType() { |
|
232 | - return $this->shareType; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @inheritdoc |
|
237 | - */ |
|
238 | - public function setSharedWith($sharedWith) { |
|
239 | - if (!is_string($sharedWith)) { |
|
240 | - throw new \InvalidArgumentException(); |
|
241 | - } |
|
242 | - $this->sharedWith = $sharedWith; |
|
243 | - return $this; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @inheritdoc |
|
248 | - */ |
|
249 | - public function getSharedWith() { |
|
250 | - return $this->sharedWith; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * @inheritdoc |
|
255 | - */ |
|
256 | - public function setPermissions($permissions) { |
|
257 | - //TODO checkes |
|
258 | - |
|
259 | - $this->permissions = $permissions; |
|
260 | - return $this; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * @inheritdoc |
|
265 | - */ |
|
266 | - public function getPermissions() { |
|
267 | - return $this->permissions; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * @inheritdoc |
|
272 | - */ |
|
273 | - public function setExpirationDate($expireDate) { |
|
274 | - //TODO checks |
|
275 | - |
|
276 | - $this->expireDate = $expireDate; |
|
277 | - return $this; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * @inheritdoc |
|
282 | - */ |
|
283 | - public function getExpirationDate() { |
|
284 | - return $this->expireDate; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @inheritdoc |
|
289 | - */ |
|
290 | - public function setSharedBy($sharedBy) { |
|
291 | - if (!is_string($sharedBy)) { |
|
292 | - throw new \InvalidArgumentException(); |
|
293 | - } |
|
294 | - //TODO checks |
|
295 | - $this->sharedBy = $sharedBy; |
|
296 | - |
|
297 | - return $this; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * @inheritdoc |
|
302 | - */ |
|
303 | - public function getSharedBy() { |
|
304 | - //TODO check if set |
|
305 | - return $this->sharedBy; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * @inheritdoc |
|
310 | - */ |
|
311 | - public function setShareOwner($shareOwner) { |
|
312 | - if (!is_string($shareOwner)) { |
|
313 | - throw new \InvalidArgumentException(); |
|
314 | - } |
|
315 | - //TODO checks |
|
316 | - |
|
317 | - $this->shareOwner = $shareOwner; |
|
318 | - return $this; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * @inheritdoc |
|
323 | - */ |
|
324 | - public function getShareOwner() { |
|
325 | - //TODO check if set |
|
326 | - return $this->shareOwner; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * @inheritdoc |
|
331 | - */ |
|
332 | - public function setPassword($password) { |
|
333 | - $this->password = $password; |
|
334 | - return $this; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * @inheritdoc |
|
339 | - */ |
|
340 | - public function getPassword() { |
|
341 | - return $this->password; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * @inheritdoc |
|
346 | - */ |
|
347 | - public function setToken($token) { |
|
348 | - $this->token = $token; |
|
349 | - return $this; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * @inheritdoc |
|
354 | - */ |
|
355 | - public function getToken() { |
|
356 | - return $this->token; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Set the parent of this share |
|
361 | - * |
|
362 | - * @param int parent |
|
363 | - * @return \OCP\Share\IShare |
|
364 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
365 | - */ |
|
366 | - public function setParent($parent) { |
|
367 | - $this->parent = $parent; |
|
368 | - return $this; |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get the parent of this share. |
|
373 | - * |
|
374 | - * @return int |
|
375 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
376 | - */ |
|
377 | - public function getParent() { |
|
378 | - return $this->parent; |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * @inheritdoc |
|
383 | - */ |
|
384 | - public function setTarget($target) { |
|
385 | - $this->target = $target; |
|
386 | - return $this; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * @inheritdoc |
|
391 | - */ |
|
392 | - public function getTarget() { |
|
393 | - return $this->target; |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * @inheritdoc |
|
398 | - */ |
|
399 | - public function setShareTime(\DateTime $shareTime) { |
|
400 | - $this->shareTime = $shareTime; |
|
401 | - return $this; |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * @inheritdoc |
|
406 | - */ |
|
407 | - public function getShareTime() { |
|
408 | - return $this->shareTime; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * @inheritdoc |
|
413 | - */ |
|
414 | - public function setMailSend($mailSend) { |
|
415 | - $this->mailSend = $mailSend; |
|
416 | - return $this; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * @inheritdoc |
|
421 | - */ |
|
422 | - public function getMailSend() { |
|
423 | - return $this->mailSend; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * @inheritdoc |
|
428 | - */ |
|
429 | - public function setNodeCacheEntry(ICacheEntry $entry) { |
|
430 | - $this->nodeCacheEntry = $entry; |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * @inheritdoc |
|
435 | - */ |
|
436 | - public function getNodeCacheEntry() { |
|
437 | - return $this->nodeCacheEntry; |
|
438 | - } |
|
35 | + /** @var string */ |
|
36 | + private $id; |
|
37 | + /** @var string */ |
|
38 | + private $providerId; |
|
39 | + /** @var Node */ |
|
40 | + private $node; |
|
41 | + /** @var int */ |
|
42 | + private $fileId; |
|
43 | + /** @var string */ |
|
44 | + private $nodeType; |
|
45 | + /** @var int */ |
|
46 | + private $shareType; |
|
47 | + /** @var string */ |
|
48 | + private $sharedWith; |
|
49 | + /** @var string */ |
|
50 | + private $sharedBy; |
|
51 | + /** @var string */ |
|
52 | + private $shareOwner; |
|
53 | + /** @var int */ |
|
54 | + private $permissions; |
|
55 | + /** @var \DateTime */ |
|
56 | + private $expireDate; |
|
57 | + /** @var string */ |
|
58 | + private $password; |
|
59 | + /** @var string */ |
|
60 | + private $token; |
|
61 | + /** @var int */ |
|
62 | + private $parent; |
|
63 | + /** @var string */ |
|
64 | + private $target; |
|
65 | + /** @var \DateTime */ |
|
66 | + private $shareTime; |
|
67 | + /** @var bool */ |
|
68 | + private $mailSend; |
|
69 | + |
|
70 | + /** @var IRootFolder */ |
|
71 | + private $rootFolder; |
|
72 | + |
|
73 | + /** @var IUserManager */ |
|
74 | + private $userManager; |
|
75 | + |
|
76 | + /** @var ICacheEntry|null */ |
|
77 | + private $nodeCacheEntry; |
|
78 | + |
|
79 | + public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
80 | + $this->rootFolder = $rootFolder; |
|
81 | + $this->userManager = $userManager; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @inheritdoc |
|
86 | + */ |
|
87 | + public function setId($id) { |
|
88 | + if (is_int($id)) { |
|
89 | + $id = (string)$id; |
|
90 | + } |
|
91 | + |
|
92 | + if(!is_string($id)) { |
|
93 | + throw new \InvalidArgumentException('String expected.'); |
|
94 | + } |
|
95 | + |
|
96 | + if ($this->id !== null) { |
|
97 | + throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
98 | + } |
|
99 | + |
|
100 | + $this->id = trim($id); |
|
101 | + return $this; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @inheritdoc |
|
106 | + */ |
|
107 | + public function getId() { |
|
108 | + return $this->id; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @inheritdoc |
|
113 | + */ |
|
114 | + public function getFullId() { |
|
115 | + if ($this->providerId === null || $this->id === null) { |
|
116 | + throw new \UnexpectedValueException; |
|
117 | + } |
|
118 | + return $this->providerId . ':' . $this->id; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @inheritdoc |
|
123 | + */ |
|
124 | + public function setProviderId($id) { |
|
125 | + if(!is_string($id)) { |
|
126 | + throw new \InvalidArgumentException('String expected.'); |
|
127 | + } |
|
128 | + |
|
129 | + if ($this->providerId !== null) { |
|
130 | + throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
131 | + } |
|
132 | + |
|
133 | + $this->providerId = trim($id); |
|
134 | + return $this; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @inheritdoc |
|
139 | + */ |
|
140 | + public function setNode(Node $node) { |
|
141 | + $this->fileId = null; |
|
142 | + $this->nodeType = null; |
|
143 | + $this->node = $node; |
|
144 | + return $this; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @inheritdoc |
|
149 | + */ |
|
150 | + public function getNode() { |
|
151 | + if ($this->node === null) { |
|
152 | + |
|
153 | + if ($this->shareOwner === null || $this->fileId === null) { |
|
154 | + throw new NotFoundException(); |
|
155 | + } |
|
156 | + |
|
157 | + // for federated shares the owner can be a remote user, in this |
|
158 | + // case we use the initiator |
|
159 | + if($this->userManager->userExists($this->shareOwner)) { |
|
160 | + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
161 | + } else { |
|
162 | + $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
163 | + } |
|
164 | + |
|
165 | + $nodes = $userFolder->getById($this->fileId); |
|
166 | + if (empty($nodes)) { |
|
167 | + throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
168 | + } |
|
169 | + |
|
170 | + $this->node = $nodes[0]; |
|
171 | + } |
|
172 | + |
|
173 | + return $this->node; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @inheritdoc |
|
178 | + */ |
|
179 | + public function setNodeId($fileId) { |
|
180 | + $this->node = null; |
|
181 | + $this->fileId = $fileId; |
|
182 | + return $this; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @inheritdoc |
|
187 | + */ |
|
188 | + public function getNodeId() { |
|
189 | + if ($this->fileId === null) { |
|
190 | + $this->fileId = $this->getNode()->getId(); |
|
191 | + } |
|
192 | + |
|
193 | + return $this->fileId; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @inheritdoc |
|
198 | + */ |
|
199 | + public function setNodeType($type) { |
|
200 | + if ($type !== 'file' && $type !== 'folder') { |
|
201 | + throw new \InvalidArgumentException(); |
|
202 | + } |
|
203 | + |
|
204 | + $this->nodeType = $type; |
|
205 | + return $this; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @inheritdoc |
|
210 | + */ |
|
211 | + public function getNodeType() { |
|
212 | + if ($this->nodeType === null) { |
|
213 | + $node = $this->getNode(); |
|
214 | + $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
215 | + } |
|
216 | + |
|
217 | + return $this->nodeType; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @inheritdoc |
|
222 | + */ |
|
223 | + public function setShareType($shareType) { |
|
224 | + $this->shareType = $shareType; |
|
225 | + return $this; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @inheritdoc |
|
230 | + */ |
|
231 | + public function getShareType() { |
|
232 | + return $this->shareType; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @inheritdoc |
|
237 | + */ |
|
238 | + public function setSharedWith($sharedWith) { |
|
239 | + if (!is_string($sharedWith)) { |
|
240 | + throw new \InvalidArgumentException(); |
|
241 | + } |
|
242 | + $this->sharedWith = $sharedWith; |
|
243 | + return $this; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @inheritdoc |
|
248 | + */ |
|
249 | + public function getSharedWith() { |
|
250 | + return $this->sharedWith; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * @inheritdoc |
|
255 | + */ |
|
256 | + public function setPermissions($permissions) { |
|
257 | + //TODO checkes |
|
258 | + |
|
259 | + $this->permissions = $permissions; |
|
260 | + return $this; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * @inheritdoc |
|
265 | + */ |
|
266 | + public function getPermissions() { |
|
267 | + return $this->permissions; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * @inheritdoc |
|
272 | + */ |
|
273 | + public function setExpirationDate($expireDate) { |
|
274 | + //TODO checks |
|
275 | + |
|
276 | + $this->expireDate = $expireDate; |
|
277 | + return $this; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * @inheritdoc |
|
282 | + */ |
|
283 | + public function getExpirationDate() { |
|
284 | + return $this->expireDate; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @inheritdoc |
|
289 | + */ |
|
290 | + public function setSharedBy($sharedBy) { |
|
291 | + if (!is_string($sharedBy)) { |
|
292 | + throw new \InvalidArgumentException(); |
|
293 | + } |
|
294 | + //TODO checks |
|
295 | + $this->sharedBy = $sharedBy; |
|
296 | + |
|
297 | + return $this; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * @inheritdoc |
|
302 | + */ |
|
303 | + public function getSharedBy() { |
|
304 | + //TODO check if set |
|
305 | + return $this->sharedBy; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * @inheritdoc |
|
310 | + */ |
|
311 | + public function setShareOwner($shareOwner) { |
|
312 | + if (!is_string($shareOwner)) { |
|
313 | + throw new \InvalidArgumentException(); |
|
314 | + } |
|
315 | + //TODO checks |
|
316 | + |
|
317 | + $this->shareOwner = $shareOwner; |
|
318 | + return $this; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * @inheritdoc |
|
323 | + */ |
|
324 | + public function getShareOwner() { |
|
325 | + //TODO check if set |
|
326 | + return $this->shareOwner; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * @inheritdoc |
|
331 | + */ |
|
332 | + public function setPassword($password) { |
|
333 | + $this->password = $password; |
|
334 | + return $this; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * @inheritdoc |
|
339 | + */ |
|
340 | + public function getPassword() { |
|
341 | + return $this->password; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * @inheritdoc |
|
346 | + */ |
|
347 | + public function setToken($token) { |
|
348 | + $this->token = $token; |
|
349 | + return $this; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * @inheritdoc |
|
354 | + */ |
|
355 | + public function getToken() { |
|
356 | + return $this->token; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Set the parent of this share |
|
361 | + * |
|
362 | + * @param int parent |
|
363 | + * @return \OCP\Share\IShare |
|
364 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
365 | + */ |
|
366 | + public function setParent($parent) { |
|
367 | + $this->parent = $parent; |
|
368 | + return $this; |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get the parent of this share. |
|
373 | + * |
|
374 | + * @return int |
|
375 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
376 | + */ |
|
377 | + public function getParent() { |
|
378 | + return $this->parent; |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * @inheritdoc |
|
383 | + */ |
|
384 | + public function setTarget($target) { |
|
385 | + $this->target = $target; |
|
386 | + return $this; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * @inheritdoc |
|
391 | + */ |
|
392 | + public function getTarget() { |
|
393 | + return $this->target; |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * @inheritdoc |
|
398 | + */ |
|
399 | + public function setShareTime(\DateTime $shareTime) { |
|
400 | + $this->shareTime = $shareTime; |
|
401 | + return $this; |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * @inheritdoc |
|
406 | + */ |
|
407 | + public function getShareTime() { |
|
408 | + return $this->shareTime; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * @inheritdoc |
|
413 | + */ |
|
414 | + public function setMailSend($mailSend) { |
|
415 | + $this->mailSend = $mailSend; |
|
416 | + return $this; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * @inheritdoc |
|
421 | + */ |
|
422 | + public function getMailSend() { |
|
423 | + return $this->mailSend; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * @inheritdoc |
|
428 | + */ |
|
429 | + public function setNodeCacheEntry(ICacheEntry $entry) { |
|
430 | + $this->nodeCacheEntry = $entry; |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * @inheritdoc |
|
435 | + */ |
|
436 | + public function getNodeCacheEntry() { |
|
437 | + return $this->nodeCacheEntry; |
|
438 | + } |
|
439 | 439 | } |
@@ -27,12 +27,12 @@ |
||
27 | 27 | |
28 | 28 | class ModuleAlreadyExistsException extends GenericEncryptionException { |
29 | 29 | |
30 | - /** |
|
31 | - * @param string $id |
|
32 | - * @param string $name |
|
33 | - */ |
|
34 | - public function __construct($id, $name) { |
|
35 | - parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); |
|
36 | - } |
|
30 | + /** |
|
31 | + * @param string $id |
|
32 | + * @param string $name |
|
33 | + */ |
|
34 | + public function __construct($id, $name) { |
|
35 | + parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | } |
@@ -28,8 +28,8 @@ |
||
28 | 28 | |
29 | 29 | class EncryptionHeaderToLargeException extends GenericEncryptionException { |
30 | 30 | |
31 | - public function __construct() { |
|
32 | - parent::__construct('max header size exceeded'); |
|
33 | - } |
|
31 | + public function __construct() { |
|
32 | + parent::__construct('max header size exceeded'); |
|
33 | + } |
|
34 | 34 | |
35 | 35 | } |
@@ -27,10 +27,10 @@ |
||
27 | 27 | |
28 | 28 | class EncryptionHeaderKeyExistsException extends GenericEncryptionException { |
29 | 29 | |
30 | - /** |
|
31 | - * @param string $key |
|
32 | - */ |
|
33 | - public function __construct($key) { |
|
34 | - parent::__construct('header key "'. $key . '" already reserved by ownCloud'); |
|
35 | - } |
|
30 | + /** |
|
31 | + * @param string $key |
|
32 | + */ |
|
33 | + public function __construct($key) { |
|
34 | + parent::__construct('header key "'. $key . '" already reserved by ownCloud'); |
|
35 | + } |
|
36 | 36 | } |
@@ -36,255 +36,255 @@ |
||
36 | 36 | |
37 | 37 | class DecryptAll { |
38 | 38 | |
39 | - /** @var OutputInterface */ |
|
40 | - protected $output; |
|
41 | - |
|
42 | - /** @var InputInterface */ |
|
43 | - protected $input; |
|
44 | - |
|
45 | - /** @var Manager */ |
|
46 | - protected $encryptionManager; |
|
47 | - |
|
48 | - /** @var IUserManager */ |
|
49 | - protected $userManager; |
|
50 | - |
|
51 | - /** @var View */ |
|
52 | - protected $rootView; |
|
53 | - |
|
54 | - /** @var array files which couldn't be decrypted */ |
|
55 | - protected $failed; |
|
56 | - |
|
57 | - /** |
|
58 | - * @param Manager $encryptionManager |
|
59 | - * @param IUserManager $userManager |
|
60 | - * @param View $rootView |
|
61 | - */ |
|
62 | - public function __construct( |
|
63 | - Manager $encryptionManager, |
|
64 | - IUserManager $userManager, |
|
65 | - View $rootView |
|
66 | - ) { |
|
67 | - $this->encryptionManager = $encryptionManager; |
|
68 | - $this->userManager = $userManager; |
|
69 | - $this->rootView = $rootView; |
|
70 | - $this->failed = []; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * start to decrypt all files |
|
75 | - * |
|
76 | - * @param InputInterface $input |
|
77 | - * @param OutputInterface $output |
|
78 | - * @param string $user which users data folder should be decrypted, default = all users |
|
79 | - * @return bool |
|
80 | - * @throws \Exception |
|
81 | - */ |
|
82 | - public function decryptAll(InputInterface $input, OutputInterface $output, $user = '') { |
|
83 | - |
|
84 | - $this->input = $input; |
|
85 | - $this->output = $output; |
|
86 | - |
|
87 | - if ($user !== '' && $this->userManager->userExists($user) === false) { |
|
88 | - $this->output->writeln('User "' . $user . '" does not exist. Please check the username and try again'); |
|
89 | - return false; |
|
90 | - } |
|
91 | - |
|
92 | - $this->output->writeln('prepare encryption modules...'); |
|
93 | - if ($this->prepareEncryptionModules($user) === false) { |
|
94 | - return false; |
|
95 | - } |
|
96 | - $this->output->writeln(' done.'); |
|
97 | - |
|
98 | - $this->decryptAllUsersFiles($user); |
|
99 | - |
|
100 | - if (empty($this->failed)) { |
|
101 | - $this->output->writeln('all files could be decrypted successfully!'); |
|
102 | - } else { |
|
103 | - $this->output->writeln('Files for following users couldn\'t be decrypted, '); |
|
104 | - $this->output->writeln('maybe the user is not set up in a way that supports this operation: '); |
|
105 | - foreach ($this->failed as $uid => $paths) { |
|
106 | - $this->output->writeln(' ' . $uid); |
|
107 | - } |
|
108 | - $this->output->writeln(''); |
|
109 | - } |
|
110 | - |
|
111 | - return true; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * prepare encryption modules to perform the decrypt all function |
|
116 | - * |
|
117 | - * @param $user |
|
118 | - * @return bool |
|
119 | - */ |
|
120 | - protected function prepareEncryptionModules($user) { |
|
121 | - // prepare all encryption modules for decrypt all |
|
122 | - $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
123 | - foreach ($encryptionModules as $moduleDesc) { |
|
124 | - /** @var IEncryptionModule $module */ |
|
125 | - $module = call_user_func($moduleDesc['callback']); |
|
126 | - $this->output->writeln(''); |
|
127 | - $this->output->writeln('Prepare "' . $module->getDisplayName() . '"'); |
|
128 | - $this->output->writeln(''); |
|
129 | - if ($module->prepareDecryptAll($this->input, $this->output, $user) === false) { |
|
130 | - $this->output->writeln('Module "' . $moduleDesc['displayName'] . '" does not support the functionality to decrypt all files again or the initialization of the module failed!'); |
|
131 | - return false; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - return true; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * iterate over all user and encrypt their files |
|
140 | - * |
|
141 | - * @param string $user which users files should be decrypted, default = all users |
|
142 | - */ |
|
143 | - protected function decryptAllUsersFiles($user = '') { |
|
144 | - |
|
145 | - $this->output->writeln("\n"); |
|
146 | - |
|
147 | - $userList = []; |
|
148 | - if ($user === '') { |
|
149 | - |
|
150 | - $fetchUsersProgress = new ProgressBar($this->output); |
|
151 | - $fetchUsersProgress->setFormat(" %message% \n [%bar%]"); |
|
152 | - $fetchUsersProgress->start(); |
|
153 | - $fetchUsersProgress->setMessage("Fetch list of users..."); |
|
154 | - $fetchUsersProgress->advance(); |
|
155 | - |
|
156 | - foreach ($this->userManager->getBackends() as $backend) { |
|
157 | - $limit = 500; |
|
158 | - $offset = 0; |
|
159 | - do { |
|
160 | - $users = $backend->getUsers('', $limit, $offset); |
|
161 | - foreach ($users as $user) { |
|
162 | - $userList[] = $user; |
|
163 | - } |
|
164 | - $offset += $limit; |
|
165 | - $fetchUsersProgress->advance(); |
|
166 | - } while (count($users) >= $limit); |
|
167 | - $fetchUsersProgress->setMessage("Fetch list of users... finished"); |
|
168 | - $fetchUsersProgress->finish(); |
|
169 | - } |
|
170 | - } else { |
|
171 | - $userList[] = $user; |
|
172 | - } |
|
173 | - |
|
174 | - $this->output->writeln("\n\n"); |
|
175 | - |
|
176 | - $progress = new ProgressBar($this->output); |
|
177 | - $progress->setFormat(" %message% \n [%bar%]"); |
|
178 | - $progress->start(); |
|
179 | - $progress->setMessage("starting to decrypt files..."); |
|
180 | - $progress->advance(); |
|
181 | - |
|
182 | - $numberOfUsers = count($userList); |
|
183 | - $userNo = 1; |
|
184 | - foreach ($userList as $uid) { |
|
185 | - $userCount = "$uid ($userNo of $numberOfUsers)"; |
|
186 | - $this->decryptUsersFiles($uid, $progress, $userCount); |
|
187 | - $userNo++; |
|
188 | - } |
|
189 | - |
|
190 | - $progress->setMessage("starting to decrypt files... finished"); |
|
191 | - $progress->finish(); |
|
192 | - |
|
193 | - $this->output->writeln("\n\n"); |
|
194 | - |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * encrypt files from the given user |
|
199 | - * |
|
200 | - * @param string $uid |
|
201 | - * @param ProgressBar $progress |
|
202 | - * @param string $userCount |
|
203 | - */ |
|
204 | - protected function decryptUsersFiles($uid, ProgressBar $progress, $userCount) { |
|
205 | - |
|
206 | - $this->setupUserFS($uid); |
|
207 | - $directories = array(); |
|
208 | - $directories[] = '/' . $uid . '/files'; |
|
209 | - |
|
210 | - while ($root = array_pop($directories)) { |
|
211 | - $content = $this->rootView->getDirectoryContent($root); |
|
212 | - foreach ($content as $file) { |
|
213 | - // only decrypt files owned by the user |
|
214 | - if($file->getStorage()->instanceOfStorage('OCA\Files_Sharing\SharedStorage')) { |
|
215 | - continue; |
|
216 | - } |
|
217 | - $path = $root . '/' . $file['name']; |
|
218 | - if ($this->rootView->is_dir($path)) { |
|
219 | - $directories[] = $path; |
|
220 | - continue; |
|
221 | - } else { |
|
222 | - try { |
|
223 | - $progress->setMessage("decrypt files for user $userCount: $path"); |
|
224 | - $progress->advance(); |
|
225 | - if ($file->isEncrypted() === false) { |
|
226 | - $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)"); |
|
227 | - $progress->advance(); |
|
228 | - } else { |
|
229 | - if ($this->decryptFile($path) === false) { |
|
230 | - $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)"); |
|
231 | - $progress->advance(); |
|
232 | - } |
|
233 | - } |
|
234 | - } catch (\Exception $e) { |
|
235 | - if (isset($this->failed[$uid])) { |
|
236 | - $this->failed[$uid][] = $path; |
|
237 | - } else { |
|
238 | - $this->failed[$uid] = [$path]; |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * encrypt file |
|
248 | - * |
|
249 | - * @param string $path |
|
250 | - * @return bool |
|
251 | - */ |
|
252 | - protected function decryptFile($path) { |
|
253 | - |
|
254 | - $source = $path; |
|
255 | - $target = $path . '.decrypted.' . $this->getTimestamp(); |
|
256 | - |
|
257 | - try { |
|
258 | - $this->rootView->copy($source, $target); |
|
259 | - $this->rootView->rename($target, $source); |
|
260 | - } catch (DecryptionFailedException $e) { |
|
261 | - if ($this->rootView->file_exists($target)) { |
|
262 | - $this->rootView->unlink($target); |
|
263 | - } |
|
264 | - return false; |
|
265 | - } |
|
266 | - |
|
267 | - return true; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * get current timestamp |
|
272 | - * |
|
273 | - * @return int |
|
274 | - */ |
|
275 | - protected function getTimestamp() { |
|
276 | - return time(); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * setup user file system |
|
282 | - * |
|
283 | - * @param string $uid |
|
284 | - */ |
|
285 | - protected function setupUserFS($uid) { |
|
286 | - \OC_Util::tearDownFS(); |
|
287 | - \OC_Util::setupFS($uid); |
|
288 | - } |
|
39 | + /** @var OutputInterface */ |
|
40 | + protected $output; |
|
41 | + |
|
42 | + /** @var InputInterface */ |
|
43 | + protected $input; |
|
44 | + |
|
45 | + /** @var Manager */ |
|
46 | + protected $encryptionManager; |
|
47 | + |
|
48 | + /** @var IUserManager */ |
|
49 | + protected $userManager; |
|
50 | + |
|
51 | + /** @var View */ |
|
52 | + protected $rootView; |
|
53 | + |
|
54 | + /** @var array files which couldn't be decrypted */ |
|
55 | + protected $failed; |
|
56 | + |
|
57 | + /** |
|
58 | + * @param Manager $encryptionManager |
|
59 | + * @param IUserManager $userManager |
|
60 | + * @param View $rootView |
|
61 | + */ |
|
62 | + public function __construct( |
|
63 | + Manager $encryptionManager, |
|
64 | + IUserManager $userManager, |
|
65 | + View $rootView |
|
66 | + ) { |
|
67 | + $this->encryptionManager = $encryptionManager; |
|
68 | + $this->userManager = $userManager; |
|
69 | + $this->rootView = $rootView; |
|
70 | + $this->failed = []; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * start to decrypt all files |
|
75 | + * |
|
76 | + * @param InputInterface $input |
|
77 | + * @param OutputInterface $output |
|
78 | + * @param string $user which users data folder should be decrypted, default = all users |
|
79 | + * @return bool |
|
80 | + * @throws \Exception |
|
81 | + */ |
|
82 | + public function decryptAll(InputInterface $input, OutputInterface $output, $user = '') { |
|
83 | + |
|
84 | + $this->input = $input; |
|
85 | + $this->output = $output; |
|
86 | + |
|
87 | + if ($user !== '' && $this->userManager->userExists($user) === false) { |
|
88 | + $this->output->writeln('User "' . $user . '" does not exist. Please check the username and try again'); |
|
89 | + return false; |
|
90 | + } |
|
91 | + |
|
92 | + $this->output->writeln('prepare encryption modules...'); |
|
93 | + if ($this->prepareEncryptionModules($user) === false) { |
|
94 | + return false; |
|
95 | + } |
|
96 | + $this->output->writeln(' done.'); |
|
97 | + |
|
98 | + $this->decryptAllUsersFiles($user); |
|
99 | + |
|
100 | + if (empty($this->failed)) { |
|
101 | + $this->output->writeln('all files could be decrypted successfully!'); |
|
102 | + } else { |
|
103 | + $this->output->writeln('Files for following users couldn\'t be decrypted, '); |
|
104 | + $this->output->writeln('maybe the user is not set up in a way that supports this operation: '); |
|
105 | + foreach ($this->failed as $uid => $paths) { |
|
106 | + $this->output->writeln(' ' . $uid); |
|
107 | + } |
|
108 | + $this->output->writeln(''); |
|
109 | + } |
|
110 | + |
|
111 | + return true; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * prepare encryption modules to perform the decrypt all function |
|
116 | + * |
|
117 | + * @param $user |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | + protected function prepareEncryptionModules($user) { |
|
121 | + // prepare all encryption modules for decrypt all |
|
122 | + $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
123 | + foreach ($encryptionModules as $moduleDesc) { |
|
124 | + /** @var IEncryptionModule $module */ |
|
125 | + $module = call_user_func($moduleDesc['callback']); |
|
126 | + $this->output->writeln(''); |
|
127 | + $this->output->writeln('Prepare "' . $module->getDisplayName() . '"'); |
|
128 | + $this->output->writeln(''); |
|
129 | + if ($module->prepareDecryptAll($this->input, $this->output, $user) === false) { |
|
130 | + $this->output->writeln('Module "' . $moduleDesc['displayName'] . '" does not support the functionality to decrypt all files again or the initialization of the module failed!'); |
|
131 | + return false; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + return true; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * iterate over all user and encrypt their files |
|
140 | + * |
|
141 | + * @param string $user which users files should be decrypted, default = all users |
|
142 | + */ |
|
143 | + protected function decryptAllUsersFiles($user = '') { |
|
144 | + |
|
145 | + $this->output->writeln("\n"); |
|
146 | + |
|
147 | + $userList = []; |
|
148 | + if ($user === '') { |
|
149 | + |
|
150 | + $fetchUsersProgress = new ProgressBar($this->output); |
|
151 | + $fetchUsersProgress->setFormat(" %message% \n [%bar%]"); |
|
152 | + $fetchUsersProgress->start(); |
|
153 | + $fetchUsersProgress->setMessage("Fetch list of users..."); |
|
154 | + $fetchUsersProgress->advance(); |
|
155 | + |
|
156 | + foreach ($this->userManager->getBackends() as $backend) { |
|
157 | + $limit = 500; |
|
158 | + $offset = 0; |
|
159 | + do { |
|
160 | + $users = $backend->getUsers('', $limit, $offset); |
|
161 | + foreach ($users as $user) { |
|
162 | + $userList[] = $user; |
|
163 | + } |
|
164 | + $offset += $limit; |
|
165 | + $fetchUsersProgress->advance(); |
|
166 | + } while (count($users) >= $limit); |
|
167 | + $fetchUsersProgress->setMessage("Fetch list of users... finished"); |
|
168 | + $fetchUsersProgress->finish(); |
|
169 | + } |
|
170 | + } else { |
|
171 | + $userList[] = $user; |
|
172 | + } |
|
173 | + |
|
174 | + $this->output->writeln("\n\n"); |
|
175 | + |
|
176 | + $progress = new ProgressBar($this->output); |
|
177 | + $progress->setFormat(" %message% \n [%bar%]"); |
|
178 | + $progress->start(); |
|
179 | + $progress->setMessage("starting to decrypt files..."); |
|
180 | + $progress->advance(); |
|
181 | + |
|
182 | + $numberOfUsers = count($userList); |
|
183 | + $userNo = 1; |
|
184 | + foreach ($userList as $uid) { |
|
185 | + $userCount = "$uid ($userNo of $numberOfUsers)"; |
|
186 | + $this->decryptUsersFiles($uid, $progress, $userCount); |
|
187 | + $userNo++; |
|
188 | + } |
|
189 | + |
|
190 | + $progress->setMessage("starting to decrypt files... finished"); |
|
191 | + $progress->finish(); |
|
192 | + |
|
193 | + $this->output->writeln("\n\n"); |
|
194 | + |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * encrypt files from the given user |
|
199 | + * |
|
200 | + * @param string $uid |
|
201 | + * @param ProgressBar $progress |
|
202 | + * @param string $userCount |
|
203 | + */ |
|
204 | + protected function decryptUsersFiles($uid, ProgressBar $progress, $userCount) { |
|
205 | + |
|
206 | + $this->setupUserFS($uid); |
|
207 | + $directories = array(); |
|
208 | + $directories[] = '/' . $uid . '/files'; |
|
209 | + |
|
210 | + while ($root = array_pop($directories)) { |
|
211 | + $content = $this->rootView->getDirectoryContent($root); |
|
212 | + foreach ($content as $file) { |
|
213 | + // only decrypt files owned by the user |
|
214 | + if($file->getStorage()->instanceOfStorage('OCA\Files_Sharing\SharedStorage')) { |
|
215 | + continue; |
|
216 | + } |
|
217 | + $path = $root . '/' . $file['name']; |
|
218 | + if ($this->rootView->is_dir($path)) { |
|
219 | + $directories[] = $path; |
|
220 | + continue; |
|
221 | + } else { |
|
222 | + try { |
|
223 | + $progress->setMessage("decrypt files for user $userCount: $path"); |
|
224 | + $progress->advance(); |
|
225 | + if ($file->isEncrypted() === false) { |
|
226 | + $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)"); |
|
227 | + $progress->advance(); |
|
228 | + } else { |
|
229 | + if ($this->decryptFile($path) === false) { |
|
230 | + $progress->setMessage("decrypt files for user $userCount: $path (already decrypted)"); |
|
231 | + $progress->advance(); |
|
232 | + } |
|
233 | + } |
|
234 | + } catch (\Exception $e) { |
|
235 | + if (isset($this->failed[$uid])) { |
|
236 | + $this->failed[$uid][] = $path; |
|
237 | + } else { |
|
238 | + $this->failed[$uid] = [$path]; |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * encrypt file |
|
248 | + * |
|
249 | + * @param string $path |
|
250 | + * @return bool |
|
251 | + */ |
|
252 | + protected function decryptFile($path) { |
|
253 | + |
|
254 | + $source = $path; |
|
255 | + $target = $path . '.decrypted.' . $this->getTimestamp(); |
|
256 | + |
|
257 | + try { |
|
258 | + $this->rootView->copy($source, $target); |
|
259 | + $this->rootView->rename($target, $source); |
|
260 | + } catch (DecryptionFailedException $e) { |
|
261 | + if ($this->rootView->file_exists($target)) { |
|
262 | + $this->rootView->unlink($target); |
|
263 | + } |
|
264 | + return false; |
|
265 | + } |
|
266 | + |
|
267 | + return true; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * get current timestamp |
|
272 | + * |
|
273 | + * @return int |
|
274 | + */ |
|
275 | + protected function getTimestamp() { |
|
276 | + return time(); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * setup user file system |
|
282 | + * |
|
283 | + * @param string $uid |
|
284 | + */ |
|
285 | + protected function setupUserFS($uid) { |
|
286 | + \OC_Util::tearDownFS(); |
|
287 | + \OC_Util::setupFS($uid); |
|
288 | + } |
|
289 | 289 | |
290 | 290 | } |