@@ -37,144 +37,144 @@ |
||
37 | 37 | use OCP\IUserManager; |
38 | 38 | |
39 | 39 | class RenewPasswordController extends Controller { |
40 | - /** @var IUserManager */ |
|
41 | - private $userManager; |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
44 | - /** @var IL10N */ |
|
45 | - protected $l10n; |
|
46 | - /** @var ISession */ |
|
47 | - private $session; |
|
48 | - /** @var IURLGenerator */ |
|
49 | - private $urlGenerator; |
|
40 | + /** @var IUserManager */ |
|
41 | + private $userManager; |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | + /** @var IL10N */ |
|
45 | + protected $l10n; |
|
46 | + /** @var ISession */ |
|
47 | + private $session; |
|
48 | + /** @var IURLGenerator */ |
|
49 | + private $urlGenerator; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $appName |
|
53 | - * @param IRequest $request |
|
54 | - * @param IUserManager $userManager |
|
55 | - * @param IConfig $config |
|
56 | - * @param IURLGenerator $urlGenerator |
|
57 | - */ |
|
58 | - function __construct($appName, IRequest $request, IUserManager $userManager, |
|
59 | - IConfig $config, IL10N $l10n, ISession $session, IURLGenerator $urlGenerator) { |
|
60 | - parent::__construct($appName, $request); |
|
61 | - $this->userManager = $userManager; |
|
62 | - $this->config = $config; |
|
63 | - $this->l10n = $l10n; |
|
64 | - $this->session = $session; |
|
65 | - $this->urlGenerator = $urlGenerator; |
|
66 | - } |
|
51 | + /** |
|
52 | + * @param string $appName |
|
53 | + * @param IRequest $request |
|
54 | + * @param IUserManager $userManager |
|
55 | + * @param IConfig $config |
|
56 | + * @param IURLGenerator $urlGenerator |
|
57 | + */ |
|
58 | + function __construct($appName, IRequest $request, IUserManager $userManager, |
|
59 | + IConfig $config, IL10N $l10n, ISession $session, IURLGenerator $urlGenerator) { |
|
60 | + parent::__construct($appName, $request); |
|
61 | + $this->userManager = $userManager; |
|
62 | + $this->config = $config; |
|
63 | + $this->l10n = $l10n; |
|
64 | + $this->session = $session; |
|
65 | + $this->urlGenerator = $urlGenerator; |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @PublicPage |
|
70 | - * @NoCSRFRequired |
|
71 | - * |
|
72 | - * @return RedirectResponse |
|
73 | - */ |
|
74 | - public function cancel() { |
|
75 | - return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
76 | - } |
|
68 | + /** |
|
69 | + * @PublicPage |
|
70 | + * @NoCSRFRequired |
|
71 | + * |
|
72 | + * @return RedirectResponse |
|
73 | + */ |
|
74 | + public function cancel() { |
|
75 | + return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @PublicPage |
|
80 | - * @NoCSRFRequired |
|
81 | - * @UseSession |
|
82 | - * |
|
83 | - * @param string $user |
|
84 | - * |
|
85 | - * @return TemplateResponse|RedirectResponse |
|
86 | - */ |
|
87 | - public function showRenewPasswordForm($user) { |
|
88 | - if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') { |
|
89 | - return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
90 | - } |
|
91 | - $parameters = []; |
|
92 | - $renewPasswordMessages = $this->session->get('renewPasswordMessages'); |
|
93 | - $errors = []; |
|
94 | - $messages = []; |
|
95 | - if (is_array($renewPasswordMessages)) { |
|
96 | - list($errors, $messages) = $renewPasswordMessages; |
|
97 | - } |
|
98 | - $this->session->remove('renewPasswordMessages'); |
|
99 | - foreach ($errors as $value) { |
|
100 | - $parameters[$value] = true; |
|
101 | - } |
|
78 | + /** |
|
79 | + * @PublicPage |
|
80 | + * @NoCSRFRequired |
|
81 | + * @UseSession |
|
82 | + * |
|
83 | + * @param string $user |
|
84 | + * |
|
85 | + * @return TemplateResponse|RedirectResponse |
|
86 | + */ |
|
87 | + public function showRenewPasswordForm($user) { |
|
88 | + if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') { |
|
89 | + return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
90 | + } |
|
91 | + $parameters = []; |
|
92 | + $renewPasswordMessages = $this->session->get('renewPasswordMessages'); |
|
93 | + $errors = []; |
|
94 | + $messages = []; |
|
95 | + if (is_array($renewPasswordMessages)) { |
|
96 | + list($errors, $messages) = $renewPasswordMessages; |
|
97 | + } |
|
98 | + $this->session->remove('renewPasswordMessages'); |
|
99 | + foreach ($errors as $value) { |
|
100 | + $parameters[$value] = true; |
|
101 | + } |
|
102 | 102 | |
103 | - $parameters['messages'] = $messages; |
|
104 | - $parameters['user'] = $user; |
|
103 | + $parameters['messages'] = $messages; |
|
104 | + $parameters['user'] = $user; |
|
105 | 105 | |
106 | - $parameters['canResetPassword'] = true; |
|
107 | - $parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', ''); |
|
108 | - if (!$parameters['resetPasswordLink']) { |
|
109 | - $userObj = $this->userManager->get($user); |
|
110 | - if ($userObj instanceof IUser) { |
|
111 | - $parameters['canResetPassword'] = $userObj->canChangePassword(); |
|
112 | - } |
|
113 | - } |
|
114 | - $parameters['cancelLink'] = $this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'); |
|
106 | + $parameters['canResetPassword'] = true; |
|
107 | + $parameters['resetPasswordLink'] = $this->config->getSystemValue('lost_password_link', ''); |
|
108 | + if (!$parameters['resetPasswordLink']) { |
|
109 | + $userObj = $this->userManager->get($user); |
|
110 | + if ($userObj instanceof IUser) { |
|
111 | + $parameters['canResetPassword'] = $userObj->canChangePassword(); |
|
112 | + } |
|
113 | + } |
|
114 | + $parameters['cancelLink'] = $this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'); |
|
115 | 115 | |
116 | - return new TemplateResponse( |
|
117 | - $this->appName, 'renewpassword', $parameters, 'guest' |
|
118 | - ); |
|
119 | - } |
|
116 | + return new TemplateResponse( |
|
117 | + $this->appName, 'renewpassword', $parameters, 'guest' |
|
118 | + ); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @PublicPage |
|
123 | - * @UseSession |
|
124 | - * |
|
125 | - * @param string $user |
|
126 | - * @param string $oldPassword |
|
127 | - * @param string $newPassword |
|
128 | - * |
|
129 | - * @return RedirectResponse |
|
130 | - */ |
|
131 | - public function tryRenewPassword($user, $oldPassword, $newPassword) { |
|
132 | - if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') { |
|
133 | - return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
134 | - } |
|
135 | - $args = !is_null($user) ? ['user' => $user] : []; |
|
136 | - $loginResult = $this->userManager->checkPassword($user, $oldPassword); |
|
137 | - if ($loginResult === false) { |
|
138 | - $this->session->set('renewPasswordMessages', [ |
|
139 | - ['invalidpassword'], [] |
|
140 | - ]); |
|
141 | - return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args)); |
|
142 | - } |
|
121 | + /** |
|
122 | + * @PublicPage |
|
123 | + * @UseSession |
|
124 | + * |
|
125 | + * @param string $user |
|
126 | + * @param string $oldPassword |
|
127 | + * @param string $newPassword |
|
128 | + * |
|
129 | + * @return RedirectResponse |
|
130 | + */ |
|
131 | + public function tryRenewPassword($user, $oldPassword, $newPassword) { |
|
132 | + if($this->config->getUserValue($user, 'user_ldap', 'needsPasswordReset') !== 'true') { |
|
133 | + return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); |
|
134 | + } |
|
135 | + $args = !is_null($user) ? ['user' => $user] : []; |
|
136 | + $loginResult = $this->userManager->checkPassword($user, $oldPassword); |
|
137 | + if ($loginResult === false) { |
|
138 | + $this->session->set('renewPasswordMessages', [ |
|
139 | + ['invalidpassword'], [] |
|
140 | + ]); |
|
141 | + return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args)); |
|
142 | + } |
|
143 | 143 | |
144 | - try { |
|
145 | - if (!is_null($newPassword) && \OC_User::setPassword($user, $newPassword)) { |
|
146 | - $this->session->set('loginMessages', [ |
|
147 | - [], [$this->l10n->t("Please login with the new password")] |
|
148 | - ]); |
|
149 | - $this->config->setUserValue($user, 'user_ldap', 'needsPasswordReset', 'false'); |
|
150 | - return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); |
|
151 | - } else { |
|
152 | - $this->session->set('renewPasswordMessages', [ |
|
153 | - ['internalexception'], [] |
|
154 | - ]); |
|
155 | - } |
|
156 | - } catch (HintException $e) { |
|
157 | - $this->session->set('renewPasswordMessages', [ |
|
158 | - [], [$e->getHint()] |
|
159 | - ]); |
|
160 | - } |
|
144 | + try { |
|
145 | + if (!is_null($newPassword) && \OC_User::setPassword($user, $newPassword)) { |
|
146 | + $this->session->set('loginMessages', [ |
|
147 | + [], [$this->l10n->t("Please login with the new password")] |
|
148 | + ]); |
|
149 | + $this->config->setUserValue($user, 'user_ldap', 'needsPasswordReset', 'false'); |
|
150 | + return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); |
|
151 | + } else { |
|
152 | + $this->session->set('renewPasswordMessages', [ |
|
153 | + ['internalexception'], [] |
|
154 | + ]); |
|
155 | + } |
|
156 | + } catch (HintException $e) { |
|
157 | + $this->session->set('renewPasswordMessages', [ |
|
158 | + [], [$e->getHint()] |
|
159 | + ]); |
|
160 | + } |
|
161 | 161 | |
162 | - return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args)); |
|
163 | - } |
|
162 | + return new RedirectResponse($this->urlGenerator->linkToRoute('user_ldap.renewPassword.showRenewPasswordForm', $args)); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @PublicPage |
|
167 | - * @NoCSRFRequired |
|
168 | - * @UseSession |
|
169 | - * |
|
170 | - * @return RedirectResponse |
|
171 | - */ |
|
172 | - public function showLoginFormInvalidPassword($user) { |
|
173 | - $args = !is_null($user) ? ['user' => $user] : []; |
|
174 | - $this->session->set('loginMessages', [ |
|
175 | - ['invalidpassword'], [] |
|
176 | - ]); |
|
177 | - return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); |
|
178 | - } |
|
165 | + /** |
|
166 | + * @PublicPage |
|
167 | + * @NoCSRFRequired |
|
168 | + * @UseSession |
|
169 | + * |
|
170 | + * @return RedirectResponse |
|
171 | + */ |
|
172 | + public function showLoginFormInvalidPassword($user) { |
|
173 | + $args = !is_null($user) ? ['user' => $user] : []; |
|
174 | + $this->session->set('loginMessages', [ |
|
175 | + ['invalidpassword'], [] |
|
176 | + ]); |
|
177 | + return new RedirectResponse($this->urlGenerator->linkToRoute('core.login.showLoginForm', $args)); |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |
@@ -26,19 +26,19 @@ |
||
26 | 26 | use OC\Files\Storage\Wrapper\Jail; |
27 | 27 | |
28 | 28 | class JailPropagator extends Propagator { |
29 | - /** |
|
30 | - * @var Jail |
|
31 | - */ |
|
32 | - protected $storage; |
|
29 | + /** |
|
30 | + * @var Jail |
|
31 | + */ |
|
32 | + protected $storage; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $internalPath |
|
36 | - * @param int $time |
|
37 | - * @param int $sizeDifference |
|
38 | - */ |
|
39 | - public function propagateChange($internalPath, $time, $sizeDifference = 0) { |
|
40 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
41 | - list($storage, $sourceInternalPath) = $this->storage->resolvePath($internalPath); |
|
42 | - $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference); |
|
43 | - } |
|
34 | + /** |
|
35 | + * @param string $internalPath |
|
36 | + * @param int $time |
|
37 | + * @param int $sizeDifference |
|
38 | + */ |
|
39 | + public function propagateChange($internalPath, $time, $sizeDifference = 0) { |
|
40 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
41 | + list($storage, $sourceInternalPath) = $this->storage->resolvePath($internalPath); |
|
42 | + $storage->getPropagator()->propagateChange($sourceInternalPath, $time, $sizeDifference); |
|
43 | + } |
|
44 | 44 | } |
@@ -47,442 +47,442 @@ |
||
47 | 47 | */ |
48 | 48 | class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage { |
49 | 49 | |
50 | - /** @var \OCP\Share\IShare */ |
|
51 | - private $superShare; |
|
52 | - |
|
53 | - /** @var \OCP\Share\IShare[] */ |
|
54 | - private $groupedShares; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var \OC\Files\View |
|
58 | - */ |
|
59 | - private $ownerView; |
|
60 | - |
|
61 | - private $initialized = false; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var ICacheEntry |
|
65 | - */ |
|
66 | - private $sourceRootInfo; |
|
67 | - |
|
68 | - /** @var string */ |
|
69 | - private $user; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var \OCP\ILogger |
|
73 | - */ |
|
74 | - private $logger; |
|
75 | - |
|
76 | - /** @var IStorage */ |
|
77 | - private $nonMaskedStorage; |
|
78 | - |
|
79 | - private $options; |
|
80 | - |
|
81 | - public function __construct($arguments) { |
|
82 | - $this->ownerView = $arguments['ownerView']; |
|
83 | - $this->logger = \OC::$server->getLogger(); |
|
84 | - |
|
85 | - $this->superShare = $arguments['superShare']; |
|
86 | - $this->groupedShares = $arguments['groupedShares']; |
|
87 | - |
|
88 | - $this->user = $arguments['user']; |
|
89 | - |
|
90 | - parent::__construct([ |
|
91 | - 'storage' => null, |
|
92 | - 'root' => null, |
|
93 | - ]); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return ICacheEntry |
|
98 | - */ |
|
99 | - private function getSourceRootInfo() { |
|
100 | - if (is_null($this->sourceRootInfo)) { |
|
101 | - if (is_null($this->superShare->getNodeCacheEntry())) { |
|
102 | - $this->init(); |
|
103 | - $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
104 | - } else { |
|
105 | - $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
106 | - } |
|
107 | - } |
|
108 | - return $this->sourceRootInfo; |
|
109 | - } |
|
110 | - |
|
111 | - private function init() { |
|
112 | - if ($this->initialized) { |
|
113 | - return; |
|
114 | - } |
|
115 | - $this->initialized = true; |
|
116 | - try { |
|
117 | - Filesystem::initMountPoints($this->superShare->getShareOwner()); |
|
118 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
119 | - list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); |
|
120 | - $this->storage = new PermissionsMask([ |
|
121 | - 'storage' => $this->nonMaskedStorage, |
|
122 | - 'mask' => $this->superShare->getPermissions() |
|
123 | - ]); |
|
124 | - } catch (NotFoundException $e) { |
|
125 | - // original file not accessible or deleted, set FailedStorage |
|
126 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
127 | - $this->cache = new FailedCache(); |
|
128 | - $this->rootPath = ''; |
|
129 | - } catch (NoUserException $e) { |
|
130 | - // sharer user deleted, set FailedStorage |
|
131 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
132 | - $this->cache = new FailedCache(); |
|
133 | - $this->rootPath = ''; |
|
134 | - } catch (\Exception $e) { |
|
135 | - $this->storage = new FailedStorage(['exception' => $e]); |
|
136 | - $this->cache = new FailedCache(); |
|
137 | - $this->rootPath = ''; |
|
138 | - $this->logger->logException($e); |
|
139 | - } |
|
140 | - |
|
141 | - if (!$this->nonMaskedStorage) { |
|
142 | - $this->nonMaskedStorage = $this->storage; |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @inheritdoc |
|
148 | - */ |
|
149 | - public function instanceOfStorage($class) { |
|
150 | - if ($class === '\OC\Files\Storage\Common') { |
|
151 | - return true; |
|
152 | - } |
|
153 | - if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { |
|
154 | - return false; |
|
155 | - } |
|
156 | - return parent::instanceOfStorage($class); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function getShareId() { |
|
163 | - return $this->superShare->getId(); |
|
164 | - } |
|
165 | - |
|
166 | - private function isValid() { |
|
167 | - return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * get id of the mount point |
|
172 | - * |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function getId() { |
|
176 | - return 'shared::' . $this->getMountPoint(); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Get the permissions granted for a shared file |
|
181 | - * |
|
182 | - * @param string $target Shared target file path |
|
183 | - * @return int CRUDS permissions granted |
|
184 | - */ |
|
185 | - public function getPermissions($target = '') { |
|
186 | - if (!$this->isValid()) { |
|
187 | - return 0; |
|
188 | - } |
|
189 | - $permissions = $this->superShare->getPermissions(); |
|
190 | - // part files and the mount point always have delete permissions |
|
191 | - if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
192 | - $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
193 | - } |
|
194 | - |
|
195 | - if (\OCP\Util::isSharingDisabledForUser()) { |
|
196 | - $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
197 | - } |
|
198 | - |
|
199 | - return $permissions; |
|
200 | - } |
|
201 | - |
|
202 | - public function isCreatable($path) { |
|
203 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
204 | - } |
|
205 | - |
|
206 | - public function isReadable($path) { |
|
207 | - if (!$this->isValid()) { |
|
208 | - return false; |
|
209 | - } |
|
210 | - if (!$this->file_exists($path)) { |
|
211 | - return false; |
|
212 | - } |
|
213 | - /** @var IStorage $storage */ |
|
214 | - /** @var string $internalPath */ |
|
215 | - list($storage, $internalPath) = $this->resolvePath($path); |
|
216 | - return $storage->isReadable($internalPath); |
|
217 | - } |
|
218 | - |
|
219 | - public function isUpdatable($path) { |
|
220 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
221 | - } |
|
222 | - |
|
223 | - public function isDeletable($path) { |
|
224 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
225 | - } |
|
226 | - |
|
227 | - public function isSharable($path) { |
|
228 | - if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
229 | - return false; |
|
230 | - } |
|
231 | - return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
232 | - } |
|
233 | - |
|
234 | - public function fopen($path, $mode) { |
|
235 | - if ($source = $this->getUnjailedPath($path)) { |
|
236 | - switch ($mode) { |
|
237 | - case 'r+': |
|
238 | - case 'rb+': |
|
239 | - case 'w+': |
|
240 | - case 'wb+': |
|
241 | - case 'x+': |
|
242 | - case 'xb+': |
|
243 | - case 'a+': |
|
244 | - case 'ab+': |
|
245 | - case 'w': |
|
246 | - case 'wb': |
|
247 | - case 'x': |
|
248 | - case 'xb': |
|
249 | - case 'a': |
|
250 | - case 'ab': |
|
251 | - $creatable = $this->isCreatable($path); |
|
252 | - $updatable = $this->isUpdatable($path); |
|
253 | - // if neither permissions given, no need to continue |
|
254 | - if (!$creatable && !$updatable) { |
|
255 | - return false; |
|
256 | - } |
|
257 | - |
|
258 | - $exists = $this->file_exists($path); |
|
259 | - // if a file exists, updatable permissions are required |
|
260 | - if ($exists && !$updatable) { |
|
261 | - return false; |
|
262 | - } |
|
263 | - |
|
264 | - // part file is allowed if !$creatable but the final file is $updatable |
|
265 | - if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
266 | - if (!$exists && !$creatable) { |
|
267 | - return false; |
|
268 | - } |
|
269 | - } |
|
270 | - } |
|
271 | - $info = array( |
|
272 | - 'target' => $this->getMountPoint() . $path, |
|
273 | - 'source' => $source, |
|
274 | - 'mode' => $mode, |
|
275 | - ); |
|
276 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
277 | - return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); |
|
278 | - } |
|
279 | - return false; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * see http://php.net/manual/en/function.rename.php |
|
284 | - * |
|
285 | - * @param string $path1 |
|
286 | - * @param string $path2 |
|
287 | - * @return bool |
|
288 | - */ |
|
289 | - public function rename($path1, $path2) { |
|
290 | - $this->init(); |
|
291 | - $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
292 | - $targetExists = $this->file_exists($path2); |
|
293 | - $sameFodler = dirname($path1) === dirname($path2); |
|
294 | - |
|
295 | - if ($targetExists || ($sameFodler && !$isPartFile)) { |
|
296 | - if (!$this->isUpdatable('')) { |
|
297 | - return false; |
|
298 | - } |
|
299 | - } else { |
|
300 | - if (!$this->isCreatable('')) { |
|
301 | - return false; |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * return mount point of share, relative to data/user/files |
|
310 | - * |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - public function getMountPoint() { |
|
314 | - return $this->superShare->getTarget(); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * @param string $path |
|
319 | - */ |
|
320 | - public function setMountPoint($path) { |
|
321 | - $this->superShare->setTarget($path); |
|
322 | - |
|
323 | - foreach ($this->groupedShares as $share) { |
|
324 | - $share->setTarget($path); |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * get the user who shared the file |
|
330 | - * |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - public function getSharedFrom() { |
|
334 | - return $this->superShare->getShareOwner(); |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * @return \OCP\Share\IShare |
|
339 | - */ |
|
340 | - public function getShare() { |
|
341 | - return $this->superShare; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * return share type, can be "file" or "folder" |
|
346 | - * |
|
347 | - * @return string |
|
348 | - */ |
|
349 | - public function getItemType() { |
|
350 | - return $this->superShare->getNodeType(); |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * @param string $path |
|
355 | - * @param null $storage |
|
356 | - * @return Cache |
|
357 | - */ |
|
358 | - public function getCache($path = '', $storage = null) { |
|
359 | - if ($this->cache) { |
|
360 | - return $this->cache; |
|
361 | - } |
|
362 | - if (!$storage) { |
|
363 | - $storage = $this; |
|
364 | - } |
|
365 | - if ($this->storage instanceof FailedStorage) { |
|
366 | - return new FailedCache(); |
|
367 | - } |
|
368 | - $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare); |
|
369 | - return $this->cache; |
|
370 | - } |
|
371 | - |
|
372 | - public function getScanner($path = '', $storage = null) { |
|
373 | - if (!$storage) { |
|
374 | - $storage = $this; |
|
375 | - } |
|
376 | - return new \OCA\Files_Sharing\Scanner($storage); |
|
377 | - } |
|
378 | - |
|
379 | - public function getOwner($path) { |
|
380 | - return $this->superShare->getShareOwner(); |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * unshare complete storage, also the grouped shares |
|
385 | - * |
|
386 | - * @return bool |
|
387 | - */ |
|
388 | - public function unshareStorage() { |
|
389 | - foreach ($this->groupedShares as $share) { |
|
390 | - \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
391 | - } |
|
392 | - return true; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * @param string $path |
|
397 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
398 | - * @param \OCP\Lock\ILockingProvider $provider |
|
399 | - * @throws \OCP\Lock\LockedException |
|
400 | - */ |
|
401 | - public function acquireLock($path, $type, ILockingProvider $provider) { |
|
402 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
403 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
404 | - $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
405 | - // lock the parent folders of the owner when locking the share as recipient |
|
406 | - if ($path === '') { |
|
407 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
408 | - $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * @param string $path |
|
414 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
415 | - * @param \OCP\Lock\ILockingProvider $provider |
|
416 | - */ |
|
417 | - public function releaseLock($path, $type, ILockingProvider $provider) { |
|
418 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
419 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
420 | - $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
421 | - // unlock the parent folders of the owner when unlocking the share as recipient |
|
422 | - if ($path === '') { |
|
423 | - $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
424 | - $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
425 | - } |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * @param string $path |
|
430 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
431 | - * @param \OCP\Lock\ILockingProvider $provider |
|
432 | - */ |
|
433 | - public function changeLock($path, $type, ILockingProvider $provider) { |
|
434 | - /** @var \OCP\Files\Storage $targetStorage */ |
|
435 | - list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
436 | - $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * @return array [ available, last_checked ] |
|
441 | - */ |
|
442 | - public function getAvailability() { |
|
443 | - // shares do not participate in availability logic |
|
444 | - return [ |
|
445 | - 'available' => true, |
|
446 | - 'last_checked' => 0 |
|
447 | - ]; |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * @param bool $available |
|
452 | - */ |
|
453 | - public function setAvailability($available) { |
|
454 | - // shares do not participate in availability logic |
|
455 | - } |
|
456 | - |
|
457 | - public function getSourceStorage() { |
|
458 | - $this->init(); |
|
459 | - return $this->nonMaskedStorage; |
|
460 | - } |
|
461 | - |
|
462 | - public function getWrapperStorage() { |
|
463 | - $this->init(); |
|
464 | - return $this->storage; |
|
465 | - } |
|
466 | - |
|
467 | - public function file_get_contents($path) { |
|
468 | - $info = [ |
|
469 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
470 | - 'source' => $this->getUnjailedPath($path), |
|
471 | - ]; |
|
472 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
473 | - return parent::file_get_contents($path); |
|
474 | - } |
|
475 | - |
|
476 | - public function file_put_contents($path, $data) { |
|
477 | - $info = [ |
|
478 | - 'target' => $this->getMountPoint() . '/' . $path, |
|
479 | - 'source' => $this->getUnjailedPath($path), |
|
480 | - ]; |
|
481 | - \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
482 | - return parent::file_put_contents($path, $data); |
|
483 | - } |
|
484 | - |
|
485 | - public function setMountOptions(array $options) { |
|
486 | - $this->mountOptions = $options; |
|
487 | - } |
|
50 | + /** @var \OCP\Share\IShare */ |
|
51 | + private $superShare; |
|
52 | + |
|
53 | + /** @var \OCP\Share\IShare[] */ |
|
54 | + private $groupedShares; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var \OC\Files\View |
|
58 | + */ |
|
59 | + private $ownerView; |
|
60 | + |
|
61 | + private $initialized = false; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var ICacheEntry |
|
65 | + */ |
|
66 | + private $sourceRootInfo; |
|
67 | + |
|
68 | + /** @var string */ |
|
69 | + private $user; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var \OCP\ILogger |
|
73 | + */ |
|
74 | + private $logger; |
|
75 | + |
|
76 | + /** @var IStorage */ |
|
77 | + private $nonMaskedStorage; |
|
78 | + |
|
79 | + private $options; |
|
80 | + |
|
81 | + public function __construct($arguments) { |
|
82 | + $this->ownerView = $arguments['ownerView']; |
|
83 | + $this->logger = \OC::$server->getLogger(); |
|
84 | + |
|
85 | + $this->superShare = $arguments['superShare']; |
|
86 | + $this->groupedShares = $arguments['groupedShares']; |
|
87 | + |
|
88 | + $this->user = $arguments['user']; |
|
89 | + |
|
90 | + parent::__construct([ |
|
91 | + 'storage' => null, |
|
92 | + 'root' => null, |
|
93 | + ]); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return ICacheEntry |
|
98 | + */ |
|
99 | + private function getSourceRootInfo() { |
|
100 | + if (is_null($this->sourceRootInfo)) { |
|
101 | + if (is_null($this->superShare->getNodeCacheEntry())) { |
|
102 | + $this->init(); |
|
103 | + $this->sourceRootInfo = $this->nonMaskedStorage->getCache()->get($this->rootPath); |
|
104 | + } else { |
|
105 | + $this->sourceRootInfo = $this->superShare->getNodeCacheEntry(); |
|
106 | + } |
|
107 | + } |
|
108 | + return $this->sourceRootInfo; |
|
109 | + } |
|
110 | + |
|
111 | + private function init() { |
|
112 | + if ($this->initialized) { |
|
113 | + return; |
|
114 | + } |
|
115 | + $this->initialized = true; |
|
116 | + try { |
|
117 | + Filesystem::initMountPoints($this->superShare->getShareOwner()); |
|
118 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
119 | + list($this->nonMaskedStorage, $this->rootPath) = $this->ownerView->resolvePath($sourcePath); |
|
120 | + $this->storage = new PermissionsMask([ |
|
121 | + 'storage' => $this->nonMaskedStorage, |
|
122 | + 'mask' => $this->superShare->getPermissions() |
|
123 | + ]); |
|
124 | + } catch (NotFoundException $e) { |
|
125 | + // original file not accessible or deleted, set FailedStorage |
|
126 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
127 | + $this->cache = new FailedCache(); |
|
128 | + $this->rootPath = ''; |
|
129 | + } catch (NoUserException $e) { |
|
130 | + // sharer user deleted, set FailedStorage |
|
131 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
132 | + $this->cache = new FailedCache(); |
|
133 | + $this->rootPath = ''; |
|
134 | + } catch (\Exception $e) { |
|
135 | + $this->storage = new FailedStorage(['exception' => $e]); |
|
136 | + $this->cache = new FailedCache(); |
|
137 | + $this->rootPath = ''; |
|
138 | + $this->logger->logException($e); |
|
139 | + } |
|
140 | + |
|
141 | + if (!$this->nonMaskedStorage) { |
|
142 | + $this->nonMaskedStorage = $this->storage; |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @inheritdoc |
|
148 | + */ |
|
149 | + public function instanceOfStorage($class) { |
|
150 | + if ($class === '\OC\Files\Storage\Common') { |
|
151 | + return true; |
|
152 | + } |
|
153 | + if (in_array($class, ['\OC\Files\Storage\Home', '\OC\Files\ObjectStore\HomeObjectStoreStorage'])) { |
|
154 | + return false; |
|
155 | + } |
|
156 | + return parent::instanceOfStorage($class); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function getShareId() { |
|
163 | + return $this->superShare->getId(); |
|
164 | + } |
|
165 | + |
|
166 | + private function isValid() { |
|
167 | + return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * get id of the mount point |
|
172 | + * |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function getId() { |
|
176 | + return 'shared::' . $this->getMountPoint(); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Get the permissions granted for a shared file |
|
181 | + * |
|
182 | + * @param string $target Shared target file path |
|
183 | + * @return int CRUDS permissions granted |
|
184 | + */ |
|
185 | + public function getPermissions($target = '') { |
|
186 | + if (!$this->isValid()) { |
|
187 | + return 0; |
|
188 | + } |
|
189 | + $permissions = $this->superShare->getPermissions(); |
|
190 | + // part files and the mount point always have delete permissions |
|
191 | + if ($target === '' || pathinfo($target, PATHINFO_EXTENSION) === 'part') { |
|
192 | + $permissions |= \OCP\Constants::PERMISSION_DELETE; |
|
193 | + } |
|
194 | + |
|
195 | + if (\OCP\Util::isSharingDisabledForUser()) { |
|
196 | + $permissions &= ~\OCP\Constants::PERMISSION_SHARE; |
|
197 | + } |
|
198 | + |
|
199 | + return $permissions; |
|
200 | + } |
|
201 | + |
|
202 | + public function isCreatable($path) { |
|
203 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_CREATE); |
|
204 | + } |
|
205 | + |
|
206 | + public function isReadable($path) { |
|
207 | + if (!$this->isValid()) { |
|
208 | + return false; |
|
209 | + } |
|
210 | + if (!$this->file_exists($path)) { |
|
211 | + return false; |
|
212 | + } |
|
213 | + /** @var IStorage $storage */ |
|
214 | + /** @var string $internalPath */ |
|
215 | + list($storage, $internalPath) = $this->resolvePath($path); |
|
216 | + return $storage->isReadable($internalPath); |
|
217 | + } |
|
218 | + |
|
219 | + public function isUpdatable($path) { |
|
220 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_UPDATE); |
|
221 | + } |
|
222 | + |
|
223 | + public function isDeletable($path) { |
|
224 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_DELETE); |
|
225 | + } |
|
226 | + |
|
227 | + public function isSharable($path) { |
|
228 | + if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) { |
|
229 | + return false; |
|
230 | + } |
|
231 | + return ($this->getPermissions($path) & \OCP\Constants::PERMISSION_SHARE); |
|
232 | + } |
|
233 | + |
|
234 | + public function fopen($path, $mode) { |
|
235 | + if ($source = $this->getUnjailedPath($path)) { |
|
236 | + switch ($mode) { |
|
237 | + case 'r+': |
|
238 | + case 'rb+': |
|
239 | + case 'w+': |
|
240 | + case 'wb+': |
|
241 | + case 'x+': |
|
242 | + case 'xb+': |
|
243 | + case 'a+': |
|
244 | + case 'ab+': |
|
245 | + case 'w': |
|
246 | + case 'wb': |
|
247 | + case 'x': |
|
248 | + case 'xb': |
|
249 | + case 'a': |
|
250 | + case 'ab': |
|
251 | + $creatable = $this->isCreatable($path); |
|
252 | + $updatable = $this->isUpdatable($path); |
|
253 | + // if neither permissions given, no need to continue |
|
254 | + if (!$creatable && !$updatable) { |
|
255 | + return false; |
|
256 | + } |
|
257 | + |
|
258 | + $exists = $this->file_exists($path); |
|
259 | + // if a file exists, updatable permissions are required |
|
260 | + if ($exists && !$updatable) { |
|
261 | + return false; |
|
262 | + } |
|
263 | + |
|
264 | + // part file is allowed if !$creatable but the final file is $updatable |
|
265 | + if (pathinfo($path, PATHINFO_EXTENSION) !== 'part') { |
|
266 | + if (!$exists && !$creatable) { |
|
267 | + return false; |
|
268 | + } |
|
269 | + } |
|
270 | + } |
|
271 | + $info = array( |
|
272 | + 'target' => $this->getMountPoint() . $path, |
|
273 | + 'source' => $source, |
|
274 | + 'mode' => $mode, |
|
275 | + ); |
|
276 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info); |
|
277 | + return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); |
|
278 | + } |
|
279 | + return false; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * see http://php.net/manual/en/function.rename.php |
|
284 | + * |
|
285 | + * @param string $path1 |
|
286 | + * @param string $path2 |
|
287 | + * @return bool |
|
288 | + */ |
|
289 | + public function rename($path1, $path2) { |
|
290 | + $this->init(); |
|
291 | + $isPartFile = pathinfo($path1, PATHINFO_EXTENSION) === 'part'; |
|
292 | + $targetExists = $this->file_exists($path2); |
|
293 | + $sameFodler = dirname($path1) === dirname($path2); |
|
294 | + |
|
295 | + if ($targetExists || ($sameFodler && !$isPartFile)) { |
|
296 | + if (!$this->isUpdatable('')) { |
|
297 | + return false; |
|
298 | + } |
|
299 | + } else { |
|
300 | + if (!$this->isCreatable('')) { |
|
301 | + return false; |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + return $this->nonMaskedStorage->rename($this->getUnjailedPath($path1), $this->getUnjailedPath($path2)); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * return mount point of share, relative to data/user/files |
|
310 | + * |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + public function getMountPoint() { |
|
314 | + return $this->superShare->getTarget(); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * @param string $path |
|
319 | + */ |
|
320 | + public function setMountPoint($path) { |
|
321 | + $this->superShare->setTarget($path); |
|
322 | + |
|
323 | + foreach ($this->groupedShares as $share) { |
|
324 | + $share->setTarget($path); |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * get the user who shared the file |
|
330 | + * |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + public function getSharedFrom() { |
|
334 | + return $this->superShare->getShareOwner(); |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * @return \OCP\Share\IShare |
|
339 | + */ |
|
340 | + public function getShare() { |
|
341 | + return $this->superShare; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * return share type, can be "file" or "folder" |
|
346 | + * |
|
347 | + * @return string |
|
348 | + */ |
|
349 | + public function getItemType() { |
|
350 | + return $this->superShare->getNodeType(); |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * @param string $path |
|
355 | + * @param null $storage |
|
356 | + * @return Cache |
|
357 | + */ |
|
358 | + public function getCache($path = '', $storage = null) { |
|
359 | + if ($this->cache) { |
|
360 | + return $this->cache; |
|
361 | + } |
|
362 | + if (!$storage) { |
|
363 | + $storage = $this; |
|
364 | + } |
|
365 | + if ($this->storage instanceof FailedStorage) { |
|
366 | + return new FailedCache(); |
|
367 | + } |
|
368 | + $this->cache = new \OCA\Files_Sharing\Cache($storage, $this->getSourceRootInfo(), $this->superShare); |
|
369 | + return $this->cache; |
|
370 | + } |
|
371 | + |
|
372 | + public function getScanner($path = '', $storage = null) { |
|
373 | + if (!$storage) { |
|
374 | + $storage = $this; |
|
375 | + } |
|
376 | + return new \OCA\Files_Sharing\Scanner($storage); |
|
377 | + } |
|
378 | + |
|
379 | + public function getOwner($path) { |
|
380 | + return $this->superShare->getShareOwner(); |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * unshare complete storage, also the grouped shares |
|
385 | + * |
|
386 | + * @return bool |
|
387 | + */ |
|
388 | + public function unshareStorage() { |
|
389 | + foreach ($this->groupedShares as $share) { |
|
390 | + \OC::$server->getShareManager()->deleteFromSelf($share, $this->user); |
|
391 | + } |
|
392 | + return true; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * @param string $path |
|
397 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
398 | + * @param \OCP\Lock\ILockingProvider $provider |
|
399 | + * @throws \OCP\Lock\LockedException |
|
400 | + */ |
|
401 | + public function acquireLock($path, $type, ILockingProvider $provider) { |
|
402 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
403 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
404 | + $targetStorage->acquireLock($targetInternalPath, $type, $provider); |
|
405 | + // lock the parent folders of the owner when locking the share as recipient |
|
406 | + if ($path === '') { |
|
407 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
408 | + $this->ownerView->lockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * @param string $path |
|
414 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
415 | + * @param \OCP\Lock\ILockingProvider $provider |
|
416 | + */ |
|
417 | + public function releaseLock($path, $type, ILockingProvider $provider) { |
|
418 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
419 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
420 | + $targetStorage->releaseLock($targetInternalPath, $type, $provider); |
|
421 | + // unlock the parent folders of the owner when unlocking the share as recipient |
|
422 | + if ($path === '') { |
|
423 | + $sourcePath = $this->ownerView->getPath($this->superShare->getNodeId()); |
|
424 | + $this->ownerView->unlockFile(dirname($sourcePath), ILockingProvider::LOCK_SHARED, true); |
|
425 | + } |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * @param string $path |
|
430 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
431 | + * @param \OCP\Lock\ILockingProvider $provider |
|
432 | + */ |
|
433 | + public function changeLock($path, $type, ILockingProvider $provider) { |
|
434 | + /** @var \OCP\Files\Storage $targetStorage */ |
|
435 | + list($targetStorage, $targetInternalPath) = $this->resolvePath($path); |
|
436 | + $targetStorage->changeLock($targetInternalPath, $type, $provider); |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * @return array [ available, last_checked ] |
|
441 | + */ |
|
442 | + public function getAvailability() { |
|
443 | + // shares do not participate in availability logic |
|
444 | + return [ |
|
445 | + 'available' => true, |
|
446 | + 'last_checked' => 0 |
|
447 | + ]; |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * @param bool $available |
|
452 | + */ |
|
453 | + public function setAvailability($available) { |
|
454 | + // shares do not participate in availability logic |
|
455 | + } |
|
456 | + |
|
457 | + public function getSourceStorage() { |
|
458 | + $this->init(); |
|
459 | + return $this->nonMaskedStorage; |
|
460 | + } |
|
461 | + |
|
462 | + public function getWrapperStorage() { |
|
463 | + $this->init(); |
|
464 | + return $this->storage; |
|
465 | + } |
|
466 | + |
|
467 | + public function file_get_contents($path) { |
|
468 | + $info = [ |
|
469 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
470 | + 'source' => $this->getUnjailedPath($path), |
|
471 | + ]; |
|
472 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info); |
|
473 | + return parent::file_get_contents($path); |
|
474 | + } |
|
475 | + |
|
476 | + public function file_put_contents($path, $data) { |
|
477 | + $info = [ |
|
478 | + 'target' => $this->getMountPoint() . '/' . $path, |
|
479 | + 'source' => $this->getUnjailedPath($path), |
|
480 | + ]; |
|
481 | + \OCP\Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info); |
|
482 | + return parent::file_put_contents($path, $data); |
|
483 | + } |
|
484 | + |
|
485 | + public function setMountOptions(array $options) { |
|
486 | + $this->mountOptions = $options; |
|
487 | + } |
|
488 | 488 | } |
@@ -24,29 +24,29 @@ |
||
24 | 24 | use OCP\IRequest; |
25 | 25 | |
26 | 26 | class Capabilities implements IPublicCapability { |
27 | - /** @var IRequest */ |
|
28 | - private $request; |
|
27 | + /** @var IRequest */ |
|
28 | + private $request; |
|
29 | 29 | |
30 | - /** @var Throttler */ |
|
31 | - private $throttler; |
|
30 | + /** @var Throttler */ |
|
31 | + private $throttler; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Capabilities constructor. |
|
35 | - * |
|
36 | - * @param IRequest $request |
|
37 | - * @param Throttler $throttler |
|
38 | - */ |
|
39 | - public function __construct(IRequest $request, |
|
40 | - Throttler $throttler) { |
|
41 | - $this->request = $request; |
|
42 | - $this->throttler = $throttler; |
|
43 | - } |
|
33 | + /** |
|
34 | + * Capabilities constructor. |
|
35 | + * |
|
36 | + * @param IRequest $request |
|
37 | + * @param Throttler $throttler |
|
38 | + */ |
|
39 | + public function __construct(IRequest $request, |
|
40 | + Throttler $throttler) { |
|
41 | + $this->request = $request; |
|
42 | + $this->throttler = $throttler; |
|
43 | + } |
|
44 | 44 | |
45 | - public function getCapabilities() { |
|
46 | - return [ |
|
47 | - 'bruteforce' => [ |
|
48 | - 'delay' => $this->throttler->getDelay($this->request->getRemoteAddress()) |
|
49 | - ] |
|
50 | - ]; |
|
51 | - } |
|
45 | + public function getCapabilities() { |
|
46 | + return [ |
|
47 | + 'bruteforce' => [ |
|
48 | + 'delay' => $this->throttler->getDelay($this->request->getRemoteAddress()) |
|
49 | + ] |
|
50 | + ]; |
|
51 | + } |
|
52 | 52 | } |
@@ -37,122 +37,122 @@ |
||
37 | 37 | * Note that the read permissions can't be masked |
38 | 38 | */ |
39 | 39 | class PermissionsMask extends Wrapper { |
40 | - /** |
|
41 | - * @var int the permissions bits we want to keep |
|
42 | - */ |
|
43 | - private $mask; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array $arguments ['storage' => $storage, 'mask' => $mask] |
|
47 | - * |
|
48 | - * $storage: The storage the permissions mask should be applied on |
|
49 | - * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants |
|
50 | - */ |
|
51 | - public function __construct($arguments) { |
|
52 | - parent::__construct($arguments); |
|
53 | - $this->mask = $arguments['mask']; |
|
54 | - } |
|
55 | - |
|
56 | - private function checkMask($permissions) { |
|
57 | - return ($this->mask & $permissions) === $permissions; |
|
58 | - } |
|
59 | - |
|
60 | - public function isUpdatable($path) { |
|
61 | - return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); |
|
62 | - } |
|
63 | - |
|
64 | - public function isCreatable($path) { |
|
65 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); |
|
66 | - } |
|
67 | - |
|
68 | - public function isDeletable($path) { |
|
69 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); |
|
70 | - } |
|
71 | - |
|
72 | - public function isSharable($path) { |
|
73 | - return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); |
|
74 | - } |
|
75 | - |
|
76 | - public function getPermissions($path) { |
|
77 | - return $this->storage->getPermissions($path) & $this->mask; |
|
78 | - } |
|
79 | - |
|
80 | - public function rename($path1, $path2) { |
|
81 | - $p = strpos($path1, $path2); |
|
82 | - if ($p === 0) { |
|
83 | - $part = substr($path1, strlen($path2)); |
|
84 | - //This is a rename of the transfer file to the original file |
|
85 | - if (strpos($part, '.ocTransferId') === 0) { |
|
86 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2); |
|
87 | - } |
|
88 | - } |
|
89 | - return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2); |
|
90 | - } |
|
91 | - |
|
92 | - public function copy($path1, $path2) { |
|
93 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2); |
|
94 | - } |
|
95 | - |
|
96 | - public function touch($path, $mtime = null) { |
|
97 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
98 | - return $this->checkMask($permissions) and parent::touch($path, $mtime); |
|
99 | - } |
|
100 | - |
|
101 | - public function mkdir($path) { |
|
102 | - return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); |
|
103 | - } |
|
104 | - |
|
105 | - public function rmdir($path) { |
|
106 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); |
|
107 | - } |
|
108 | - |
|
109 | - public function unlink($path) { |
|
110 | - return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); |
|
111 | - } |
|
112 | - |
|
113 | - public function file_put_contents($path, $data) { |
|
114 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
115 | - return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; |
|
116 | - } |
|
117 | - |
|
118 | - public function fopen($path, $mode) { |
|
119 | - if ($mode === 'r' or $mode === 'rb') { |
|
120 | - return parent::fopen($path, $mode); |
|
121 | - } else { |
|
122 | - $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
123 | - return $this->checkMask($permissions) ? parent::fopen($path, $mode) : false; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * get a cache instance for the storage |
|
129 | - * |
|
130 | - * @param string $path |
|
131 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
132 | - * @return \OC\Files\Cache\Cache |
|
133 | - */ |
|
134 | - public function getCache($path = '', $storage = null) { |
|
135 | - if (!$storage) { |
|
136 | - $storage = $this; |
|
137 | - } |
|
138 | - $sourceCache = parent::getCache($path, $storage); |
|
139 | - return new CachePermissionsMask($sourceCache, $this->mask); |
|
140 | - } |
|
141 | - |
|
142 | - public function getMetaData($path) { |
|
143 | - $data = parent::getMetaData($path); |
|
144 | - |
|
145 | - if ($data && isset($data['permissions'])) { |
|
146 | - $data['scan_permissions'] = isset($data['scan_permissions']) ? $data['scan_permissions'] : $data['permissions']; |
|
147 | - $data['permissions'] &= $this->mask; |
|
148 | - } |
|
149 | - return $data; |
|
150 | - } |
|
151 | - |
|
152 | - public function getScanner($path = '', $storage = null) { |
|
153 | - if (!$storage) { |
|
154 | - $storage = $this->storage; |
|
155 | - } |
|
156 | - return parent::getScanner($path, $storage); |
|
157 | - } |
|
40 | + /** |
|
41 | + * @var int the permissions bits we want to keep |
|
42 | + */ |
|
43 | + private $mask; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array $arguments ['storage' => $storage, 'mask' => $mask] |
|
47 | + * |
|
48 | + * $storage: The storage the permissions mask should be applied on |
|
49 | + * $mask: The permission bits that should be kept, a combination of the \OCP\Constant::PERMISSION_ constants |
|
50 | + */ |
|
51 | + public function __construct($arguments) { |
|
52 | + parent::__construct($arguments); |
|
53 | + $this->mask = $arguments['mask']; |
|
54 | + } |
|
55 | + |
|
56 | + private function checkMask($permissions) { |
|
57 | + return ($this->mask & $permissions) === $permissions; |
|
58 | + } |
|
59 | + |
|
60 | + public function isUpdatable($path) { |
|
61 | + return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); |
|
62 | + } |
|
63 | + |
|
64 | + public function isCreatable($path) { |
|
65 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); |
|
66 | + } |
|
67 | + |
|
68 | + public function isDeletable($path) { |
|
69 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); |
|
70 | + } |
|
71 | + |
|
72 | + public function isSharable($path) { |
|
73 | + return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); |
|
74 | + } |
|
75 | + |
|
76 | + public function getPermissions($path) { |
|
77 | + return $this->storage->getPermissions($path) & $this->mask; |
|
78 | + } |
|
79 | + |
|
80 | + public function rename($path1, $path2) { |
|
81 | + $p = strpos($path1, $path2); |
|
82 | + if ($p === 0) { |
|
83 | + $part = substr($path1, strlen($path2)); |
|
84 | + //This is a rename of the transfer file to the original file |
|
85 | + if (strpos($part, '.ocTransferId') === 0) { |
|
86 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($path1, $path2); |
|
87 | + } |
|
88 | + } |
|
89 | + return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($path1, $path2); |
|
90 | + } |
|
91 | + |
|
92 | + public function copy($path1, $path2) { |
|
93 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($path1, $path2); |
|
94 | + } |
|
95 | + |
|
96 | + public function touch($path, $mtime = null) { |
|
97 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
98 | + return $this->checkMask($permissions) and parent::touch($path, $mtime); |
|
99 | + } |
|
100 | + |
|
101 | + public function mkdir($path) { |
|
102 | + return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); |
|
103 | + } |
|
104 | + |
|
105 | + public function rmdir($path) { |
|
106 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); |
|
107 | + } |
|
108 | + |
|
109 | + public function unlink($path) { |
|
110 | + return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); |
|
111 | + } |
|
112 | + |
|
113 | + public function file_put_contents($path, $data) { |
|
114 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
115 | + return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; |
|
116 | + } |
|
117 | + |
|
118 | + public function fopen($path, $mode) { |
|
119 | + if ($mode === 'r' or $mode === 'rb') { |
|
120 | + return parent::fopen($path, $mode); |
|
121 | + } else { |
|
122 | + $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; |
|
123 | + return $this->checkMask($permissions) ? parent::fopen($path, $mode) : false; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * get a cache instance for the storage |
|
129 | + * |
|
130 | + * @param string $path |
|
131 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache |
|
132 | + * @return \OC\Files\Cache\Cache |
|
133 | + */ |
|
134 | + public function getCache($path = '', $storage = null) { |
|
135 | + if (!$storage) { |
|
136 | + $storage = $this; |
|
137 | + } |
|
138 | + $sourceCache = parent::getCache($path, $storage); |
|
139 | + return new CachePermissionsMask($sourceCache, $this->mask); |
|
140 | + } |
|
141 | + |
|
142 | + public function getMetaData($path) { |
|
143 | + $data = parent::getMetaData($path); |
|
144 | + |
|
145 | + if ($data && isset($data['permissions'])) { |
|
146 | + $data['scan_permissions'] = isset($data['scan_permissions']) ? $data['scan_permissions'] : $data['permissions']; |
|
147 | + $data['permissions'] &= $this->mask; |
|
148 | + } |
|
149 | + return $data; |
|
150 | + } |
|
151 | + |
|
152 | + public function getScanner($path = '', $storage = null) { |
|
153 | + if (!$storage) { |
|
154 | + $storage = $this->storage; |
|
155 | + } |
|
156 | + return parent::getScanner($path, $storage); |
|
157 | + } |
|
158 | 158 | } |
@@ -23,23 +23,23 @@ |
||
23 | 23 | namespace OC\Setup; |
24 | 24 | |
25 | 25 | class Sqlite extends AbstractDatabase { |
26 | - public $dbprettyname = 'Sqlite'; |
|
26 | + public $dbprettyname = 'Sqlite'; |
|
27 | 27 | |
28 | - public function validate($config) { |
|
29 | - return array(); |
|
30 | - } |
|
28 | + public function validate($config) { |
|
29 | + return array(); |
|
30 | + } |
|
31 | 31 | |
32 | - public function initialize($config) { |
|
33 | - } |
|
32 | + public function initialize($config) { |
|
33 | + } |
|
34 | 34 | |
35 | - public function setupDatabase($username) { |
|
36 | - $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
35 | + public function setupDatabase($username) { |
|
36 | + $datadir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
37 | 37 | |
38 | - //delete the old sqlite database first, might cause infinte loops otherwise |
|
39 | - if(file_exists("$datadir/owncloud.db")) { |
|
40 | - unlink("$datadir/owncloud.db"); |
|
41 | - } |
|
42 | - //in case of sqlite, we can always fill the database |
|
43 | - error_log("creating sqlite db"); |
|
44 | - } |
|
38 | + //delete the old sqlite database first, might cause infinte loops otherwise |
|
39 | + if(file_exists("$datadir/owncloud.db")) { |
|
40 | + unlink("$datadir/owncloud.db"); |
|
41 | + } |
|
42 | + //in case of sqlite, we can always fill the database |
|
43 | + error_log("creating sqlite db"); |
|
44 | + } |
|
45 | 45 | } |
@@ -35,118 +35,118 @@ |
||
35 | 35 | |
36 | 36 | abstract class AbstractDatabase { |
37 | 37 | |
38 | - /** @var IL10N */ |
|
39 | - protected $trans; |
|
40 | - /** @var string */ |
|
41 | - protected $dbUser; |
|
42 | - /** @var string */ |
|
43 | - protected $dbPassword; |
|
44 | - /** @var string */ |
|
45 | - protected $dbName; |
|
46 | - /** @var string */ |
|
47 | - protected $dbHost; |
|
48 | - /** @var string */ |
|
49 | - protected $dbPort; |
|
50 | - /** @var string */ |
|
51 | - protected $tablePrefix; |
|
52 | - /** @var SystemConfig */ |
|
53 | - protected $config; |
|
54 | - /** @var ILogger */ |
|
55 | - protected $logger; |
|
56 | - /** @var ISecureRandom */ |
|
57 | - protected $random; |
|
38 | + /** @var IL10N */ |
|
39 | + protected $trans; |
|
40 | + /** @var string */ |
|
41 | + protected $dbUser; |
|
42 | + /** @var string */ |
|
43 | + protected $dbPassword; |
|
44 | + /** @var string */ |
|
45 | + protected $dbName; |
|
46 | + /** @var string */ |
|
47 | + protected $dbHost; |
|
48 | + /** @var string */ |
|
49 | + protected $dbPort; |
|
50 | + /** @var string */ |
|
51 | + protected $tablePrefix; |
|
52 | + /** @var SystemConfig */ |
|
53 | + protected $config; |
|
54 | + /** @var ILogger */ |
|
55 | + protected $logger; |
|
56 | + /** @var ISecureRandom */ |
|
57 | + protected $random; |
|
58 | 58 | |
59 | - public function __construct(IL10N $trans, SystemConfig $config, ILogger $logger, ISecureRandom $random) { |
|
60 | - $this->trans = $trans; |
|
61 | - $this->config = $config; |
|
62 | - $this->logger = $logger; |
|
63 | - $this->random = $random; |
|
64 | - } |
|
59 | + public function __construct(IL10N $trans, SystemConfig $config, ILogger $logger, ISecureRandom $random) { |
|
60 | + $this->trans = $trans; |
|
61 | + $this->config = $config; |
|
62 | + $this->logger = $logger; |
|
63 | + $this->random = $random; |
|
64 | + } |
|
65 | 65 | |
66 | - public function validate($config) { |
|
67 | - $errors = array(); |
|
68 | - if(empty($config['dbuser']) && empty($config['dbname'])) { |
|
69 | - $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname)); |
|
70 | - } else if(empty($config['dbuser'])) { |
|
71 | - $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname)); |
|
72 | - } else if(empty($config['dbname'])) { |
|
73 | - $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname)); |
|
74 | - } |
|
75 | - if(substr_count($config['dbname'], '.') >= 1) { |
|
76 | - $errors[] = $this->trans->t("%s you may not use dots in the database name", array($this->dbprettyname)); |
|
77 | - } |
|
78 | - return $errors; |
|
79 | - } |
|
66 | + public function validate($config) { |
|
67 | + $errors = array(); |
|
68 | + if(empty($config['dbuser']) && empty($config['dbname'])) { |
|
69 | + $errors[] = $this->trans->t("%s enter the database username and name.", array($this->dbprettyname)); |
|
70 | + } else if(empty($config['dbuser'])) { |
|
71 | + $errors[] = $this->trans->t("%s enter the database username.", array($this->dbprettyname)); |
|
72 | + } else if(empty($config['dbname'])) { |
|
73 | + $errors[] = $this->trans->t("%s enter the database name.", array($this->dbprettyname)); |
|
74 | + } |
|
75 | + if(substr_count($config['dbname'], '.') >= 1) { |
|
76 | + $errors[] = $this->trans->t("%s you may not use dots in the database name", array($this->dbprettyname)); |
|
77 | + } |
|
78 | + return $errors; |
|
79 | + } |
|
80 | 80 | |
81 | - public function initialize($config) { |
|
82 | - $dbUser = $config['dbuser']; |
|
83 | - $dbPass = $config['dbpass']; |
|
84 | - $dbName = $config['dbname']; |
|
85 | - $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost'; |
|
86 | - $dbPort = !empty($config['dbport']) ? $config['dbport'] : ''; |
|
87 | - $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; |
|
81 | + public function initialize($config) { |
|
82 | + $dbUser = $config['dbuser']; |
|
83 | + $dbPass = $config['dbpass']; |
|
84 | + $dbName = $config['dbname']; |
|
85 | + $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost'; |
|
86 | + $dbPort = !empty($config['dbport']) ? $config['dbport'] : ''; |
|
87 | + $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; |
|
88 | 88 | |
89 | - $this->config->setValues([ |
|
90 | - 'dbname' => $dbName, |
|
91 | - 'dbhost' => $dbHost, |
|
92 | - 'dbport' => $dbPort, |
|
93 | - 'dbtableprefix' => $dbTablePrefix, |
|
94 | - ]); |
|
89 | + $this->config->setValues([ |
|
90 | + 'dbname' => $dbName, |
|
91 | + 'dbhost' => $dbHost, |
|
92 | + 'dbport' => $dbPort, |
|
93 | + 'dbtableprefix' => $dbTablePrefix, |
|
94 | + ]); |
|
95 | 95 | |
96 | - $this->dbUser = $dbUser; |
|
97 | - $this->dbPassword = $dbPass; |
|
98 | - $this->dbName = $dbName; |
|
99 | - $this->dbHost = $dbHost; |
|
100 | - $this->dbPort = $dbPort; |
|
101 | - $this->tablePrefix = $dbTablePrefix; |
|
102 | - } |
|
96 | + $this->dbUser = $dbUser; |
|
97 | + $this->dbPassword = $dbPass; |
|
98 | + $this->dbName = $dbName; |
|
99 | + $this->dbHost = $dbHost; |
|
100 | + $this->dbPort = $dbPort; |
|
101 | + $this->tablePrefix = $dbTablePrefix; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param array $configOverwrite |
|
106 | - * @return \OC\DB\Connection |
|
107 | - */ |
|
108 | - protected function connect(array $configOverwrite = []) { |
|
109 | - $connectionParams = array( |
|
110 | - 'host' => $this->dbHost, |
|
111 | - 'user' => $this->dbUser, |
|
112 | - 'password' => $this->dbPassword, |
|
113 | - 'tablePrefix' => $this->tablePrefix, |
|
114 | - 'dbname' => $this->dbName |
|
115 | - ); |
|
104 | + /** |
|
105 | + * @param array $configOverwrite |
|
106 | + * @return \OC\DB\Connection |
|
107 | + */ |
|
108 | + protected function connect(array $configOverwrite = []) { |
|
109 | + $connectionParams = array( |
|
110 | + 'host' => $this->dbHost, |
|
111 | + 'user' => $this->dbUser, |
|
112 | + 'password' => $this->dbPassword, |
|
113 | + 'tablePrefix' => $this->tablePrefix, |
|
114 | + 'dbname' => $this->dbName |
|
115 | + ); |
|
116 | 116 | |
117 | - // adding port support through installer |
|
118 | - if (!empty($this->dbPort)) { |
|
119 | - if (ctype_digit($this->dbPort)) { |
|
120 | - $connectionParams['port'] = $this->dbPort; |
|
121 | - } else { |
|
122 | - $connectionParams['unix_socket'] = $this->dbPort; |
|
123 | - } |
|
124 | - } else if (strpos($this->dbHost, ':')) { |
|
125 | - // Host variable may carry a port or socket. |
|
126 | - list($host, $portOrSocket) = explode(':', $this->dbHost, 2); |
|
127 | - if (ctype_digit($portOrSocket)) { |
|
128 | - $connectionParams['port'] = $portOrSocket; |
|
129 | - } else { |
|
130 | - $connectionParams['unix_socket'] = $portOrSocket; |
|
131 | - } |
|
132 | - $connectionParams['host'] = $host; |
|
133 | - } |
|
117 | + // adding port support through installer |
|
118 | + if (!empty($this->dbPort)) { |
|
119 | + if (ctype_digit($this->dbPort)) { |
|
120 | + $connectionParams['port'] = $this->dbPort; |
|
121 | + } else { |
|
122 | + $connectionParams['unix_socket'] = $this->dbPort; |
|
123 | + } |
|
124 | + } else if (strpos($this->dbHost, ':')) { |
|
125 | + // Host variable may carry a port or socket. |
|
126 | + list($host, $portOrSocket) = explode(':', $this->dbHost, 2); |
|
127 | + if (ctype_digit($portOrSocket)) { |
|
128 | + $connectionParams['port'] = $portOrSocket; |
|
129 | + } else { |
|
130 | + $connectionParams['unix_socket'] = $portOrSocket; |
|
131 | + } |
|
132 | + $connectionParams['host'] = $host; |
|
133 | + } |
|
134 | 134 | |
135 | - $connectionParams = array_merge($connectionParams, $configOverwrite); |
|
136 | - $cf = new ConnectionFactory($this->config); |
|
137 | - return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams); |
|
138 | - } |
|
135 | + $connectionParams = array_merge($connectionParams, $configOverwrite); |
|
136 | + $cf = new ConnectionFactory($this->config); |
|
137 | + return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @param string $userName |
|
142 | - */ |
|
143 | - abstract public function setupDatabase($userName); |
|
140 | + /** |
|
141 | + * @param string $userName |
|
142 | + */ |
|
143 | + abstract public function setupDatabase($userName); |
|
144 | 144 | |
145 | - public function runMigrations() { |
|
146 | - if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) { |
|
147 | - return; |
|
148 | - } |
|
149 | - $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); |
|
150 | - $ms->migrate(); |
|
151 | - } |
|
145 | + public function runMigrations() { |
|
146 | + if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) { |
|
147 | + return; |
|
148 | + } |
|
149 | + $ms = new MigrationService('core', \OC::$server->getDatabaseConnection()); |
|
150 | + $ms->migrate(); |
|
151 | + } |
|
152 | 152 | } |
@@ -29,68 +29,68 @@ |
||
29 | 29 | use OCP\Diagnostics\IQueryLogger; |
30 | 30 | |
31 | 31 | class QueryLogger implements IQueryLogger { |
32 | - /** |
|
33 | - * @var \OC\Diagnostics\Query |
|
34 | - */ |
|
35 | - protected $activeQuery; |
|
32 | + /** |
|
33 | + * @var \OC\Diagnostics\Query |
|
34 | + */ |
|
35 | + protected $activeQuery; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var CappedMemoryCache |
|
39 | - */ |
|
40 | - protected $queries; |
|
37 | + /** |
|
38 | + * @var CappedMemoryCache |
|
39 | + */ |
|
40 | + protected $queries; |
|
41 | 41 | |
42 | - /** |
|
43 | - * QueryLogger constructor. |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - $this->queries = new CappedMemoryCache(1024); |
|
47 | - } |
|
42 | + /** |
|
43 | + * QueryLogger constructor. |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + $this->queries = new CappedMemoryCache(1024); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @var bool - Module needs to be activated by some app |
|
52 | - */ |
|
53 | - private $activated = false; |
|
50 | + /** |
|
51 | + * @var bool - Module needs to be activated by some app |
|
52 | + */ |
|
53 | + private $activated = false; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @inheritdoc |
|
57 | - */ |
|
58 | - public function startQuery($sql, array $params = null, array $types = null) { |
|
59 | - if ($this->activated) { |
|
60 | - $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack()); |
|
61 | - } |
|
62 | - } |
|
55 | + /** |
|
56 | + * @inheritdoc |
|
57 | + */ |
|
58 | + public function startQuery($sql, array $params = null, array $types = null) { |
|
59 | + if ($this->activated) { |
|
60 | + $this->activeQuery = new Query($sql, $params, microtime(true), $this->getStack()); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - private function getStack() { |
|
65 | - $stack = debug_backtrace(); |
|
66 | - array_shift($stack); |
|
67 | - array_shift($stack); |
|
68 | - array_shift($stack); |
|
69 | - return $stack; |
|
70 | - } |
|
64 | + private function getStack() { |
|
65 | + $stack = debug_backtrace(); |
|
66 | + array_shift($stack); |
|
67 | + array_shift($stack); |
|
68 | + array_shift($stack); |
|
69 | + return $stack; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @inheritdoc |
|
74 | - */ |
|
75 | - public function stopQuery() { |
|
76 | - if ($this->activated && $this->activeQuery) { |
|
77 | - $this->activeQuery->end(microtime(true)); |
|
78 | - $this->queries[] = $this->activeQuery; |
|
79 | - $this->activeQuery = null; |
|
80 | - } |
|
81 | - } |
|
72 | + /** |
|
73 | + * @inheritdoc |
|
74 | + */ |
|
75 | + public function stopQuery() { |
|
76 | + if ($this->activated && $this->activeQuery) { |
|
77 | + $this->activeQuery->end(microtime(true)); |
|
78 | + $this->queries[] = $this->activeQuery; |
|
79 | + $this->activeQuery = null; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @inheritdoc |
|
85 | - */ |
|
86 | - public function getQueries() { |
|
87 | - return $this->queries->getData(); |
|
88 | - } |
|
83 | + /** |
|
84 | + * @inheritdoc |
|
85 | + */ |
|
86 | + public function getQueries() { |
|
87 | + return $this->queries->getData(); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @inheritdoc |
|
92 | - */ |
|
93 | - public function activate() { |
|
94 | - $this->activated = true; |
|
95 | - } |
|
90 | + /** |
|
91 | + * @inheritdoc |
|
92 | + */ |
|
93 | + public function activate() { |
|
94 | + $this->activated = true; |
|
95 | + } |
|
96 | 96 | } |
@@ -24,15 +24,15 @@ |
||
24 | 24 | namespace OC\Hooks; |
25 | 25 | |
26 | 26 | abstract class LegacyEmitter extends BasicEmitter { |
27 | - /** |
|
28 | - * @param string $scope |
|
29 | - * @param string $method |
|
30 | - * @param array $arguments |
|
31 | - * |
|
32 | - * @suppress PhanAccessMethodProtected |
|
33 | - */ |
|
34 | - protected function emit($scope, $method, array $arguments = array()) { |
|
35 | - \OC_Hook::emit($scope, $method, $arguments); |
|
36 | - parent::emit($scope, $method, $arguments); |
|
37 | - } |
|
27 | + /** |
|
28 | + * @param string $scope |
|
29 | + * @param string $method |
|
30 | + * @param array $arguments |
|
31 | + * |
|
32 | + * @suppress PhanAccessMethodProtected |
|
33 | + */ |
|
34 | + protected function emit($scope, $method, array $arguments = array()) { |
|
35 | + \OC_Hook::emit($scope, $method, $arguments); |
|
36 | + parent::emit($scope, $method, $arguments); |
|
37 | + } |
|
38 | 38 | } |