@@ -32,7 +32,6 @@ |
||
32 | 32 | use OCA\Encryption\KeyManager; |
33 | 33 | use OCA\Encryption\Crypto\Crypt; |
34 | 34 | use OCA\Encryption\Users\Setup; |
35 | -use OCP\App; |
|
36 | 35 | use OCP\ILogger; |
37 | 36 | use OCP\IUserSession; |
38 | 37 | use OCA\Encryption\Util; |
@@ -41,293 +41,293 @@ |
||
41 | 41 | |
42 | 42 | class UserHooks implements IHook { |
43 | 43 | |
44 | - /** |
|
45 | - * list of user for which we perform a password reset |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected static $passwordResetUsers = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var KeyManager |
|
52 | - */ |
|
53 | - private $keyManager; |
|
54 | - /** |
|
55 | - * @var IUserManager |
|
56 | - */ |
|
57 | - private $userManager; |
|
58 | - /** |
|
59 | - * @var ILogger |
|
60 | - */ |
|
61 | - private $logger; |
|
62 | - /** |
|
63 | - * @var Setup |
|
64 | - */ |
|
65 | - private $userSetup; |
|
66 | - /** |
|
67 | - * @var IUserSession |
|
68 | - */ |
|
69 | - private $user; |
|
70 | - /** |
|
71 | - * @var Util |
|
72 | - */ |
|
73 | - private $util; |
|
74 | - /** |
|
75 | - * @var Session |
|
76 | - */ |
|
77 | - private $session; |
|
78 | - /** |
|
79 | - * @var Recovery |
|
80 | - */ |
|
81 | - private $recovery; |
|
82 | - /** |
|
83 | - * @var Crypt |
|
84 | - */ |
|
85 | - private $crypt; |
|
86 | - |
|
87 | - /** |
|
88 | - * UserHooks constructor. |
|
89 | - * |
|
90 | - * @param KeyManager $keyManager |
|
91 | - * @param IUserManager $userManager |
|
92 | - * @param ILogger $logger |
|
93 | - * @param Setup $userSetup |
|
94 | - * @param IUserSession $user |
|
95 | - * @param Util $util |
|
96 | - * @param Session $session |
|
97 | - * @param Crypt $crypt |
|
98 | - * @param Recovery $recovery |
|
99 | - */ |
|
100 | - public function __construct(KeyManager $keyManager, |
|
101 | - IUserManager $userManager, |
|
102 | - ILogger $logger, |
|
103 | - Setup $userSetup, |
|
104 | - IUserSession $user, |
|
105 | - Util $util, |
|
106 | - Session $session, |
|
107 | - Crypt $crypt, |
|
108 | - Recovery $recovery) { |
|
109 | - |
|
110 | - $this->keyManager = $keyManager; |
|
111 | - $this->userManager = $userManager; |
|
112 | - $this->logger = $logger; |
|
113 | - $this->userSetup = $userSetup; |
|
114 | - $this->user = $user; |
|
115 | - $this->util = $util; |
|
116 | - $this->session = $session; |
|
117 | - $this->recovery = $recovery; |
|
118 | - $this->crypt = $crypt; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Connects Hooks |
|
123 | - * |
|
124 | - * @return null |
|
125 | - */ |
|
126 | - public function addHooks() { |
|
127 | - OCUtil::connectHook('OC_User', 'post_login', $this, 'login'); |
|
128 | - OCUtil::connectHook('OC_User', 'logout', $this, 'logout'); |
|
129 | - |
|
130 | - // this hooks only make sense if no master key is used |
|
131 | - if ($this->util->isMasterKeyEnabled() === false) { |
|
132 | - OCUtil::connectHook('OC_User', |
|
133 | - 'post_setPassword', |
|
134 | - $this, |
|
135 | - 'setPassphrase'); |
|
136 | - |
|
137 | - OCUtil::connectHook('OC_User', |
|
138 | - 'pre_setPassword', |
|
139 | - $this, |
|
140 | - 'preSetPassphrase'); |
|
141 | - |
|
142 | - OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController', |
|
143 | - 'post_passwordReset', |
|
144 | - $this, |
|
145 | - 'postPasswordReset'); |
|
146 | - |
|
147 | - OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController', |
|
148 | - 'pre_passwordReset', |
|
149 | - $this, |
|
150 | - 'prePasswordReset'); |
|
151 | - |
|
152 | - OCUtil::connectHook('OC_User', |
|
153 | - 'post_createUser', |
|
154 | - $this, |
|
155 | - 'postCreateUser'); |
|
156 | - |
|
157 | - OCUtil::connectHook('OC_User', |
|
158 | - 'post_deleteUser', |
|
159 | - $this, |
|
160 | - 'postDeleteUser'); |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Startup encryption backend upon user login |
|
167 | - * |
|
168 | - * @note This method should never be called for users using client side encryption |
|
169 | - * @param array $params |
|
170 | - * @return boolean|null |
|
171 | - */ |
|
172 | - public function login($params) { |
|
173 | - // ensure filesystem is loaded |
|
174 | - if (!\OC\Files\Filesystem::$loaded) { |
|
175 | - $this->setupFS($params['uid']); |
|
176 | - } |
|
177 | - if ($this->util->isMasterKeyEnabled() === false) { |
|
178 | - $this->userSetup->setupUser($params['uid'], $params['password']); |
|
179 | - } |
|
180 | - |
|
181 | - $this->keyManager->init($params['uid'], $params['password']); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * remove keys from session during logout |
|
186 | - */ |
|
187 | - public function logout() { |
|
188 | - $this->session->clear(); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * setup encryption backend upon user created |
|
193 | - * |
|
194 | - * @note This method should never be called for users using client side encryption |
|
195 | - * @param array $params |
|
196 | - */ |
|
197 | - public function postCreateUser($params) { |
|
198 | - $this->userSetup->setupUser($params['uid'], $params['password']); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * cleanup encryption backend upon user deleted |
|
203 | - * |
|
204 | - * @param array $params : uid, password |
|
205 | - * @note This method should never be called for users using client side encryption |
|
206 | - */ |
|
207 | - public function postDeleteUser($params) { |
|
208 | - $this->keyManager->deletePublicKey($params['uid']); |
|
209 | - } |
|
210 | - |
|
211 | - public function prePasswordReset($params) { |
|
212 | - $user = $params['uid']; |
|
213 | - self::$passwordResetUsers[$user] = true; |
|
214 | - } |
|
215 | - |
|
216 | - public function postPasswordReset($params) { |
|
217 | - $uid = $params['uid']; |
|
218 | - $password = $params['password']; |
|
219 | - $this->keyManager->backupUserKeys('passwordReset', $uid); |
|
220 | - $this->keyManager->deleteUserKeys($uid); |
|
221 | - $this->userSetup->setupUser($uid, $password); |
|
222 | - unset(self::$passwordResetUsers[$uid]); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * If the password can't be changed within Nextcloud, than update the key password in advance. |
|
227 | - * |
|
228 | - * @param array $params : uid, password |
|
229 | - * @return boolean|null |
|
230 | - */ |
|
231 | - public function preSetPassphrase($params) { |
|
232 | - $user = $this->userManager->get($params['uid']); |
|
233 | - |
|
234 | - if ($user && !$user->canChangePassword()) { |
|
235 | - $this->setPassphrase($params); |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Change a user's encryption passphrase |
|
241 | - * |
|
242 | - * @param array $params keys: uid, password |
|
243 | - * @return boolean|null |
|
244 | - */ |
|
245 | - public function setPassphrase($params) { |
|
246 | - |
|
247 | - // if we are in the process to resetting a user password, we have nothing |
|
248 | - // to do here |
|
249 | - if (isset(self::$passwordResetUsers[$params['uid']])) { |
|
250 | - return true; |
|
251 | - } |
|
252 | - |
|
253 | - // Get existing decrypted private key |
|
254 | - $privateKey = $this->session->getPrivateKey(); |
|
255 | - $user = $this->user->getUser(); |
|
256 | - |
|
257 | - // current logged in user changes his own password |
|
258 | - if ($user && $params['uid'] === $user->getUID() && $privateKey) { |
|
259 | - |
|
260 | - // Encrypt private key with new user pwd as passphrase |
|
261 | - $encryptedPrivateKey = $this->crypt->encryptPrivateKey($privateKey, $params['password'], $params['uid']); |
|
262 | - |
|
263 | - // Save private key |
|
264 | - if ($encryptedPrivateKey) { |
|
265 | - $this->keyManager->setPrivateKey($this->user->getUser()->getUID(), |
|
266 | - $this->crypt->generateHeader() . $encryptedPrivateKey); |
|
267 | - } else { |
|
268 | - $this->logger->error('Encryption could not update users encryption password'); |
|
269 | - } |
|
270 | - |
|
271 | - // NOTE: Session does not need to be updated as the |
|
272 | - // private key has not changed, only the passphrase |
|
273 | - // used to decrypt it has changed |
|
274 | - } else { // admin changed the password for a different user, create new keys and re-encrypt file keys |
|
275 | - $user = $params['uid']; |
|
276 | - $this->initMountPoints($user); |
|
277 | - $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null; |
|
278 | - |
|
279 | - // we generate new keys if... |
|
280 | - // ...we have a recovery password and the user enabled the recovery key |
|
281 | - // ...encryption was activated for the first time (no keys exists) |
|
282 | - // ...the user doesn't have any files |
|
283 | - if ( |
|
284 | - ($this->recovery->isRecoveryEnabledForUser($user) && $recoveryPassword) |
|
285 | - || !$this->keyManager->userHasKeys($user) |
|
286 | - || !$this->util->userHasFiles($user) |
|
287 | - ) { |
|
288 | - |
|
289 | - // backup old keys |
|
290 | - //$this->backupAllKeys('recovery'); |
|
291 | - |
|
292 | - $newUserPassword = $params['password']; |
|
293 | - |
|
294 | - $keyPair = $this->crypt->createKeyPair(); |
|
295 | - |
|
296 | - // Save public key |
|
297 | - $this->keyManager->setPublicKey($user, $keyPair['publicKey']); |
|
298 | - |
|
299 | - // Encrypt private key with new password |
|
300 | - $encryptedKey = $this->crypt->encryptPrivateKey($keyPair['privateKey'], $newUserPassword, $user); |
|
301 | - |
|
302 | - if ($encryptedKey) { |
|
303 | - $this->keyManager->setPrivateKey($user, $this->crypt->generateHeader() . $encryptedKey); |
|
304 | - |
|
305 | - if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files |
|
306 | - $this->recovery->recoverUsersFiles($recoveryPassword, $user); |
|
307 | - } |
|
308 | - } else { |
|
309 | - $this->logger->error('Encryption Could not update users encryption password'); |
|
310 | - } |
|
311 | - } |
|
312 | - } |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * init mount points for given user |
|
317 | - * |
|
318 | - * @param string $user |
|
319 | - * @throws \OC\User\NoUserException |
|
320 | - */ |
|
321 | - protected function initMountPoints($user) { |
|
322 | - Filesystem::initMountPoints($user); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * setup file system for user |
|
327 | - * |
|
328 | - * @param string $uid user id |
|
329 | - */ |
|
330 | - protected function setupFS($uid) { |
|
331 | - \OC_Util::setupFS($uid); |
|
332 | - } |
|
44 | + /** |
|
45 | + * list of user for which we perform a password reset |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected static $passwordResetUsers = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var KeyManager |
|
52 | + */ |
|
53 | + private $keyManager; |
|
54 | + /** |
|
55 | + * @var IUserManager |
|
56 | + */ |
|
57 | + private $userManager; |
|
58 | + /** |
|
59 | + * @var ILogger |
|
60 | + */ |
|
61 | + private $logger; |
|
62 | + /** |
|
63 | + * @var Setup |
|
64 | + */ |
|
65 | + private $userSetup; |
|
66 | + /** |
|
67 | + * @var IUserSession |
|
68 | + */ |
|
69 | + private $user; |
|
70 | + /** |
|
71 | + * @var Util |
|
72 | + */ |
|
73 | + private $util; |
|
74 | + /** |
|
75 | + * @var Session |
|
76 | + */ |
|
77 | + private $session; |
|
78 | + /** |
|
79 | + * @var Recovery |
|
80 | + */ |
|
81 | + private $recovery; |
|
82 | + /** |
|
83 | + * @var Crypt |
|
84 | + */ |
|
85 | + private $crypt; |
|
86 | + |
|
87 | + /** |
|
88 | + * UserHooks constructor. |
|
89 | + * |
|
90 | + * @param KeyManager $keyManager |
|
91 | + * @param IUserManager $userManager |
|
92 | + * @param ILogger $logger |
|
93 | + * @param Setup $userSetup |
|
94 | + * @param IUserSession $user |
|
95 | + * @param Util $util |
|
96 | + * @param Session $session |
|
97 | + * @param Crypt $crypt |
|
98 | + * @param Recovery $recovery |
|
99 | + */ |
|
100 | + public function __construct(KeyManager $keyManager, |
|
101 | + IUserManager $userManager, |
|
102 | + ILogger $logger, |
|
103 | + Setup $userSetup, |
|
104 | + IUserSession $user, |
|
105 | + Util $util, |
|
106 | + Session $session, |
|
107 | + Crypt $crypt, |
|
108 | + Recovery $recovery) { |
|
109 | + |
|
110 | + $this->keyManager = $keyManager; |
|
111 | + $this->userManager = $userManager; |
|
112 | + $this->logger = $logger; |
|
113 | + $this->userSetup = $userSetup; |
|
114 | + $this->user = $user; |
|
115 | + $this->util = $util; |
|
116 | + $this->session = $session; |
|
117 | + $this->recovery = $recovery; |
|
118 | + $this->crypt = $crypt; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Connects Hooks |
|
123 | + * |
|
124 | + * @return null |
|
125 | + */ |
|
126 | + public function addHooks() { |
|
127 | + OCUtil::connectHook('OC_User', 'post_login', $this, 'login'); |
|
128 | + OCUtil::connectHook('OC_User', 'logout', $this, 'logout'); |
|
129 | + |
|
130 | + // this hooks only make sense if no master key is used |
|
131 | + if ($this->util->isMasterKeyEnabled() === false) { |
|
132 | + OCUtil::connectHook('OC_User', |
|
133 | + 'post_setPassword', |
|
134 | + $this, |
|
135 | + 'setPassphrase'); |
|
136 | + |
|
137 | + OCUtil::connectHook('OC_User', |
|
138 | + 'pre_setPassword', |
|
139 | + $this, |
|
140 | + 'preSetPassphrase'); |
|
141 | + |
|
142 | + OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController', |
|
143 | + 'post_passwordReset', |
|
144 | + $this, |
|
145 | + 'postPasswordReset'); |
|
146 | + |
|
147 | + OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController', |
|
148 | + 'pre_passwordReset', |
|
149 | + $this, |
|
150 | + 'prePasswordReset'); |
|
151 | + |
|
152 | + OCUtil::connectHook('OC_User', |
|
153 | + 'post_createUser', |
|
154 | + $this, |
|
155 | + 'postCreateUser'); |
|
156 | + |
|
157 | + OCUtil::connectHook('OC_User', |
|
158 | + 'post_deleteUser', |
|
159 | + $this, |
|
160 | + 'postDeleteUser'); |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Startup encryption backend upon user login |
|
167 | + * |
|
168 | + * @note This method should never be called for users using client side encryption |
|
169 | + * @param array $params |
|
170 | + * @return boolean|null |
|
171 | + */ |
|
172 | + public function login($params) { |
|
173 | + // ensure filesystem is loaded |
|
174 | + if (!\OC\Files\Filesystem::$loaded) { |
|
175 | + $this->setupFS($params['uid']); |
|
176 | + } |
|
177 | + if ($this->util->isMasterKeyEnabled() === false) { |
|
178 | + $this->userSetup->setupUser($params['uid'], $params['password']); |
|
179 | + } |
|
180 | + |
|
181 | + $this->keyManager->init($params['uid'], $params['password']); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * remove keys from session during logout |
|
186 | + */ |
|
187 | + public function logout() { |
|
188 | + $this->session->clear(); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * setup encryption backend upon user created |
|
193 | + * |
|
194 | + * @note This method should never be called for users using client side encryption |
|
195 | + * @param array $params |
|
196 | + */ |
|
197 | + public function postCreateUser($params) { |
|
198 | + $this->userSetup->setupUser($params['uid'], $params['password']); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * cleanup encryption backend upon user deleted |
|
203 | + * |
|
204 | + * @param array $params : uid, password |
|
205 | + * @note This method should never be called for users using client side encryption |
|
206 | + */ |
|
207 | + public function postDeleteUser($params) { |
|
208 | + $this->keyManager->deletePublicKey($params['uid']); |
|
209 | + } |
|
210 | + |
|
211 | + public function prePasswordReset($params) { |
|
212 | + $user = $params['uid']; |
|
213 | + self::$passwordResetUsers[$user] = true; |
|
214 | + } |
|
215 | + |
|
216 | + public function postPasswordReset($params) { |
|
217 | + $uid = $params['uid']; |
|
218 | + $password = $params['password']; |
|
219 | + $this->keyManager->backupUserKeys('passwordReset', $uid); |
|
220 | + $this->keyManager->deleteUserKeys($uid); |
|
221 | + $this->userSetup->setupUser($uid, $password); |
|
222 | + unset(self::$passwordResetUsers[$uid]); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * If the password can't be changed within Nextcloud, than update the key password in advance. |
|
227 | + * |
|
228 | + * @param array $params : uid, password |
|
229 | + * @return boolean|null |
|
230 | + */ |
|
231 | + public function preSetPassphrase($params) { |
|
232 | + $user = $this->userManager->get($params['uid']); |
|
233 | + |
|
234 | + if ($user && !$user->canChangePassword()) { |
|
235 | + $this->setPassphrase($params); |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Change a user's encryption passphrase |
|
241 | + * |
|
242 | + * @param array $params keys: uid, password |
|
243 | + * @return boolean|null |
|
244 | + */ |
|
245 | + public function setPassphrase($params) { |
|
246 | + |
|
247 | + // if we are in the process to resetting a user password, we have nothing |
|
248 | + // to do here |
|
249 | + if (isset(self::$passwordResetUsers[$params['uid']])) { |
|
250 | + return true; |
|
251 | + } |
|
252 | + |
|
253 | + // Get existing decrypted private key |
|
254 | + $privateKey = $this->session->getPrivateKey(); |
|
255 | + $user = $this->user->getUser(); |
|
256 | + |
|
257 | + // current logged in user changes his own password |
|
258 | + if ($user && $params['uid'] === $user->getUID() && $privateKey) { |
|
259 | + |
|
260 | + // Encrypt private key with new user pwd as passphrase |
|
261 | + $encryptedPrivateKey = $this->crypt->encryptPrivateKey($privateKey, $params['password'], $params['uid']); |
|
262 | + |
|
263 | + // Save private key |
|
264 | + if ($encryptedPrivateKey) { |
|
265 | + $this->keyManager->setPrivateKey($this->user->getUser()->getUID(), |
|
266 | + $this->crypt->generateHeader() . $encryptedPrivateKey); |
|
267 | + } else { |
|
268 | + $this->logger->error('Encryption could not update users encryption password'); |
|
269 | + } |
|
270 | + |
|
271 | + // NOTE: Session does not need to be updated as the |
|
272 | + // private key has not changed, only the passphrase |
|
273 | + // used to decrypt it has changed |
|
274 | + } else { // admin changed the password for a different user, create new keys and re-encrypt file keys |
|
275 | + $user = $params['uid']; |
|
276 | + $this->initMountPoints($user); |
|
277 | + $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null; |
|
278 | + |
|
279 | + // we generate new keys if... |
|
280 | + // ...we have a recovery password and the user enabled the recovery key |
|
281 | + // ...encryption was activated for the first time (no keys exists) |
|
282 | + // ...the user doesn't have any files |
|
283 | + if ( |
|
284 | + ($this->recovery->isRecoveryEnabledForUser($user) && $recoveryPassword) |
|
285 | + || !$this->keyManager->userHasKeys($user) |
|
286 | + || !$this->util->userHasFiles($user) |
|
287 | + ) { |
|
288 | + |
|
289 | + // backup old keys |
|
290 | + //$this->backupAllKeys('recovery'); |
|
291 | + |
|
292 | + $newUserPassword = $params['password']; |
|
293 | + |
|
294 | + $keyPair = $this->crypt->createKeyPair(); |
|
295 | + |
|
296 | + // Save public key |
|
297 | + $this->keyManager->setPublicKey($user, $keyPair['publicKey']); |
|
298 | + |
|
299 | + // Encrypt private key with new password |
|
300 | + $encryptedKey = $this->crypt->encryptPrivateKey($keyPair['privateKey'], $newUserPassword, $user); |
|
301 | + |
|
302 | + if ($encryptedKey) { |
|
303 | + $this->keyManager->setPrivateKey($user, $this->crypt->generateHeader() . $encryptedKey); |
|
304 | + |
|
305 | + if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files |
|
306 | + $this->recovery->recoverUsersFiles($recoveryPassword, $user); |
|
307 | + } |
|
308 | + } else { |
|
309 | + $this->logger->error('Encryption Could not update users encryption password'); |
|
310 | + } |
|
311 | + } |
|
312 | + } |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * init mount points for given user |
|
317 | + * |
|
318 | + * @param string $user |
|
319 | + * @throws \OC\User\NoUserException |
|
320 | + */ |
|
321 | + protected function initMountPoints($user) { |
|
322 | + Filesystem::initMountPoints($user); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * setup file system for user |
|
327 | + * |
|
328 | + * @param string $uid user id |
|
329 | + */ |
|
330 | + protected function setupFS($uid) { |
|
331 | + \OC_Util::setupFS($uid); |
|
332 | + } |
|
333 | 333 | } |
@@ -35,118 +35,118 @@ |
||
35 | 35 | |
36 | 36 | class Hooks { |
37 | 37 | |
38 | - public static function connectHooks() { |
|
39 | - // Listen to write signals |
|
40 | - \OCP\Util::connectHook('OC_Filesystem', 'write', 'OCA\Files_Versions\Hooks', 'write_hook'); |
|
41 | - // Listen to delete and rename signals |
|
42 | - \OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Files_Versions\Hooks', 'remove_hook'); |
|
43 | - \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Versions\Hooks', 'pre_remove_hook'); |
|
44 | - \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Files_Versions\Hooks', 'rename_hook'); |
|
45 | - \OCP\Util::connectHook('OC_Filesystem', 'post_copy', 'OCA\Files_Versions\Hooks', 'copy_hook'); |
|
46 | - \OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Files_Versions\Hooks', 'pre_renameOrCopy_hook'); |
|
47 | - \OCP\Util::connectHook('OC_Filesystem', 'copy', 'OCA\Files_Versions\Hooks', 'pre_renameOrCopy_hook'); |
|
38 | + public static function connectHooks() { |
|
39 | + // Listen to write signals |
|
40 | + \OCP\Util::connectHook('OC_Filesystem', 'write', 'OCA\Files_Versions\Hooks', 'write_hook'); |
|
41 | + // Listen to delete and rename signals |
|
42 | + \OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Files_Versions\Hooks', 'remove_hook'); |
|
43 | + \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Versions\Hooks', 'pre_remove_hook'); |
|
44 | + \OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Files_Versions\Hooks', 'rename_hook'); |
|
45 | + \OCP\Util::connectHook('OC_Filesystem', 'post_copy', 'OCA\Files_Versions\Hooks', 'copy_hook'); |
|
46 | + \OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Files_Versions\Hooks', 'pre_renameOrCopy_hook'); |
|
47 | + \OCP\Util::connectHook('OC_Filesystem', 'copy', 'OCA\Files_Versions\Hooks', 'pre_renameOrCopy_hook'); |
|
48 | 48 | |
49 | - $eventDispatcher = \OC::$server->getEventDispatcher(); |
|
50 | - $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', ['OCA\Files_Versions\Hooks', 'onLoadFilesAppScripts']); |
|
51 | - } |
|
49 | + $eventDispatcher = \OC::$server->getEventDispatcher(); |
|
50 | + $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', ['OCA\Files_Versions\Hooks', 'onLoadFilesAppScripts']); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * listen to write event. |
|
55 | - */ |
|
56 | - public static function write_hook( $params ) { |
|
57 | - $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
58 | - if($path !== '') { |
|
59 | - Storage::store($path); |
|
60 | - } |
|
61 | - } |
|
53 | + /** |
|
54 | + * listen to write event. |
|
55 | + */ |
|
56 | + public static function write_hook( $params ) { |
|
57 | + $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
58 | + if($path !== '') { |
|
59 | + Storage::store($path); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * Erase versions of deleted file |
|
66 | - * @param array $params |
|
67 | - * |
|
68 | - * This function is connected to the delete signal of OC_Filesystem |
|
69 | - * cleanup the versions directory if the actual file gets deleted |
|
70 | - */ |
|
71 | - public static function remove_hook($params) { |
|
72 | - $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
73 | - if($path !== '') { |
|
74 | - Storage::delete($path); |
|
75 | - } |
|
76 | - } |
|
64 | + /** |
|
65 | + * Erase versions of deleted file |
|
66 | + * @param array $params |
|
67 | + * |
|
68 | + * This function is connected to the delete signal of OC_Filesystem |
|
69 | + * cleanup the versions directory if the actual file gets deleted |
|
70 | + */ |
|
71 | + public static function remove_hook($params) { |
|
72 | + $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
73 | + if($path !== '') { |
|
74 | + Storage::delete($path); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * mark file as "deleted" so that we can clean up the versions if the file is gone |
|
80 | - * @param array $params |
|
81 | - */ |
|
82 | - public static function pre_remove_hook($params) { |
|
83 | - $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
84 | - if($path !== '') { |
|
85 | - Storage::markDeletedFile($path); |
|
86 | - } |
|
87 | - } |
|
78 | + /** |
|
79 | + * mark file as "deleted" so that we can clean up the versions if the file is gone |
|
80 | + * @param array $params |
|
81 | + */ |
|
82 | + public static function pre_remove_hook($params) { |
|
83 | + $path = $params[\OC\Files\Filesystem::signal_param_path]; |
|
84 | + if($path !== '') { |
|
85 | + Storage::markDeletedFile($path); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * rename/move versions of renamed/moved files |
|
91 | - * @param array $params array with oldpath and newpath |
|
92 | - * |
|
93 | - * This function is connected to the rename signal of OC_Filesystem and adjust the name and location |
|
94 | - * of the stored versions along the actual file |
|
95 | - */ |
|
96 | - public static function rename_hook($params) { |
|
97 | - $oldpath = $params['oldpath']; |
|
98 | - $newpath = $params['newpath']; |
|
99 | - if($oldpath !== '' && $newpath !== '') { |
|
100 | - Storage::renameOrCopy($oldpath, $newpath, 'rename'); |
|
101 | - } |
|
102 | - } |
|
89 | + /** |
|
90 | + * rename/move versions of renamed/moved files |
|
91 | + * @param array $params array with oldpath and newpath |
|
92 | + * |
|
93 | + * This function is connected to the rename signal of OC_Filesystem and adjust the name and location |
|
94 | + * of the stored versions along the actual file |
|
95 | + */ |
|
96 | + public static function rename_hook($params) { |
|
97 | + $oldpath = $params['oldpath']; |
|
98 | + $newpath = $params['newpath']; |
|
99 | + if($oldpath !== '' && $newpath !== '') { |
|
100 | + Storage::renameOrCopy($oldpath, $newpath, 'rename'); |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * copy versions of copied files |
|
106 | - * @param array $params array with oldpath and newpath |
|
107 | - * |
|
108 | - * This function is connected to the copy signal of OC_Filesystem and copies the |
|
109 | - * the stored versions to the new location |
|
110 | - */ |
|
111 | - public static function copy_hook($params) { |
|
112 | - $oldpath = $params['oldpath']; |
|
113 | - $newpath = $params['newpath']; |
|
114 | - if($oldpath !== '' && $newpath !== '') { |
|
115 | - Storage::renameOrCopy($oldpath, $newpath, 'copy'); |
|
116 | - } |
|
117 | - } |
|
104 | + /** |
|
105 | + * copy versions of copied files |
|
106 | + * @param array $params array with oldpath and newpath |
|
107 | + * |
|
108 | + * This function is connected to the copy signal of OC_Filesystem and copies the |
|
109 | + * the stored versions to the new location |
|
110 | + */ |
|
111 | + public static function copy_hook($params) { |
|
112 | + $oldpath = $params['oldpath']; |
|
113 | + $newpath = $params['newpath']; |
|
114 | + if($oldpath !== '' && $newpath !== '') { |
|
115 | + Storage::renameOrCopy($oldpath, $newpath, 'copy'); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Remember owner and the owner path of the source file. |
|
121 | - * If the file already exists, then it was a upload of a existing file |
|
122 | - * over the web interface and we call Storage::store() directly |
|
123 | - * |
|
124 | - * @param array $params array with oldpath and newpath |
|
125 | - * |
|
126 | - */ |
|
127 | - public static function pre_renameOrCopy_hook($params) { |
|
128 | - // if we rename a movable mount point, then the versions don't have |
|
129 | - // to be renamed |
|
130 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']); |
|
131 | - $manager = \OC\Files\Filesystem::getMountManager(); |
|
132 | - $mount = $manager->find($absOldPath); |
|
133 | - $internalPath = $mount->getInternalPath($absOldPath); |
|
134 | - if ($internalPath === '' and $mount instanceof \OC\Files\Mount\MoveableMount) { |
|
135 | - return; |
|
136 | - } |
|
119 | + /** |
|
120 | + * Remember owner and the owner path of the source file. |
|
121 | + * If the file already exists, then it was a upload of a existing file |
|
122 | + * over the web interface and we call Storage::store() directly |
|
123 | + * |
|
124 | + * @param array $params array with oldpath and newpath |
|
125 | + * |
|
126 | + */ |
|
127 | + public static function pre_renameOrCopy_hook($params) { |
|
128 | + // if we rename a movable mount point, then the versions don't have |
|
129 | + // to be renamed |
|
130 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']); |
|
131 | + $manager = \OC\Files\Filesystem::getMountManager(); |
|
132 | + $mount = $manager->find($absOldPath); |
|
133 | + $internalPath = $mount->getInternalPath($absOldPath); |
|
134 | + if ($internalPath === '' and $mount instanceof \OC\Files\Mount\MoveableMount) { |
|
135 | + return; |
|
136 | + } |
|
137 | 137 | |
138 | - $view = new \OC\Files\View(\OCP\User::getUser() . '/files'); |
|
139 | - if ($view->file_exists($params['newpath'])) { |
|
140 | - Storage::store($params['newpath']); |
|
141 | - } else { |
|
142 | - Storage::setSourcePathAndUser($params['oldpath']); |
|
143 | - } |
|
144 | - } |
|
138 | + $view = new \OC\Files\View(\OCP\User::getUser() . '/files'); |
|
139 | + if ($view->file_exists($params['newpath'])) { |
|
140 | + Storage::store($params['newpath']); |
|
141 | + } else { |
|
142 | + Storage::setSourcePathAndUser($params['oldpath']); |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Load additional scripts when the files app is visible |
|
148 | - */ |
|
149 | - public static function onLoadFilesAppScripts() { |
|
150 | - \OCP\Util::addScript('files_versions', 'merged'); |
|
151 | - } |
|
146 | + /** |
|
147 | + * Load additional scripts when the files app is visible |
|
148 | + */ |
|
149 | + public static function onLoadFilesAppScripts() { |
|
150 | + \OCP\Util::addScript('files_versions', 'merged'); |
|
151 | + } |
|
152 | 152 | } |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * listen to write event. |
55 | 55 | */ |
56 | - public static function write_hook( $params ) { |
|
56 | + public static function write_hook($params) { |
|
57 | 57 | $path = $params[\OC\Files\Filesystem::signal_param_path]; |
58 | - if($path !== '') { |
|
58 | + if ($path !== '') { |
|
59 | 59 | Storage::store($path); |
60 | 60 | } |
61 | 61 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public static function remove_hook($params) { |
72 | 72 | $path = $params[\OC\Files\Filesystem::signal_param_path]; |
73 | - if($path !== '') { |
|
73 | + if ($path !== '') { |
|
74 | 74 | Storage::delete($path); |
75 | 75 | } |
76 | 76 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public static function pre_remove_hook($params) { |
83 | 83 | $path = $params[\OC\Files\Filesystem::signal_param_path]; |
84 | - if($path !== '') { |
|
84 | + if ($path !== '') { |
|
85 | 85 | Storage::markDeletedFile($path); |
86 | 86 | } |
87 | 87 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public static function rename_hook($params) { |
97 | 97 | $oldpath = $params['oldpath']; |
98 | 98 | $newpath = $params['newpath']; |
99 | - if($oldpath !== '' && $newpath !== '') { |
|
99 | + if ($oldpath !== '' && $newpath !== '') { |
|
100 | 100 | Storage::renameOrCopy($oldpath, $newpath, 'rename'); |
101 | 101 | } |
102 | 102 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | public static function copy_hook($params) { |
112 | 112 | $oldpath = $params['oldpath']; |
113 | 113 | $newpath = $params['newpath']; |
114 | - if($oldpath !== '' && $newpath !== '') { |
|
114 | + if ($oldpath !== '' && $newpath !== '') { |
|
115 | 115 | Storage::renameOrCopy($oldpath, $newpath, 'copy'); |
116 | 116 | } |
117 | 117 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | public static function pre_renameOrCopy_hook($params) { |
128 | 128 | // if we rename a movable mount point, then the versions don't have |
129 | 129 | // to be renamed |
130 | - $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']); |
|
130 | + $absOldPath = \OC\Files\Filesystem::normalizePath('/'.\OCP\User::getUser().'/files'.$params['oldpath']); |
|
131 | 131 | $manager = \OC\Files\Filesystem::getMountManager(); |
132 | 132 | $mount = $manager->find($absOldPath); |
133 | 133 | $internalPath = $mount->getInternalPath($absOldPath); |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | return; |
136 | 136 | } |
137 | 137 | |
138 | - $view = new \OC\Files\View(\OCP\User::getUser() . '/files'); |
|
138 | + $view = new \OC\Files\View(\OCP\User::getUser().'/files'); |
|
139 | 139 | if ($view->file_exists($params['newpath'])) { |
140 | 140 | Storage::store($params['newpath']); |
141 | 141 | } else { |
@@ -31,22 +31,22 @@ |
||
31 | 31 | |
32 | 32 | class Hooks { |
33 | 33 | |
34 | - /** |
|
35 | - * clean up user specific settings if user gets deleted |
|
36 | - * @param array $params array with uid |
|
37 | - * |
|
38 | - * This function is connected to the pre_deleteUser signal of OC_Users |
|
39 | - * to remove the used space for the trash bin stored in the database |
|
40 | - */ |
|
41 | - public static function deleteUser_hook($params) { |
|
42 | - $uid = $params['uid']; |
|
43 | - Trashbin::deleteUser($uid); |
|
44 | - } |
|
34 | + /** |
|
35 | + * clean up user specific settings if user gets deleted |
|
36 | + * @param array $params array with uid |
|
37 | + * |
|
38 | + * This function is connected to the pre_deleteUser signal of OC_Users |
|
39 | + * to remove the used space for the trash bin stored in the database |
|
40 | + */ |
|
41 | + public static function deleteUser_hook($params) { |
|
42 | + $uid = $params['uid']; |
|
43 | + Trashbin::deleteUser($uid); |
|
44 | + } |
|
45 | 45 | |
46 | - public static function post_write_hook($params) { |
|
47 | - $user = \OCP\User::getUser(); |
|
48 | - if (!empty($user)) { |
|
49 | - Trashbin::resizeTrash($user); |
|
50 | - } |
|
51 | - } |
|
46 | + public static function post_write_hook($params) { |
|
47 | + $user = \OCP\User::getUser(); |
|
48 | + if (!empty($user)) { |
|
49 | + Trashbin::resizeTrash($user); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |