@@ -99,7 +99,7 @@ |
||
99 | 99 | $emailAddressType = $emailAddressData['type']; |
100 | 100 | } |
101 | 101 | if (isset($contact['FN'])) { |
102 | - $displayName = $contact['FN'] . ' (' . $emailAddress . ')'; |
|
102 | + $displayName = $contact['FN'].' ('.$emailAddress.')'; |
|
103 | 103 | } |
104 | 104 | $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
105 | 105 |
@@ -41,251 +41,251 @@ |
||
41 | 41 | use OCP\Mail\IMailer; |
42 | 42 | |
43 | 43 | class MailPlugin implements ISearchPlugin { |
44 | - /* @var bool */ |
|
45 | - protected $shareWithGroupOnly; |
|
46 | - /* @var bool */ |
|
47 | - protected $shareeEnumeration; |
|
48 | - /* @var bool */ |
|
49 | - protected $shareeEnumerationInGroupOnly; |
|
50 | - /* @var bool */ |
|
51 | - protected $shareeEnumerationPhone; |
|
52 | - /* @var bool */ |
|
53 | - protected $shareeEnumerationFullMatch; |
|
54 | - /* @var bool */ |
|
55 | - protected $shareeEnumerationFullMatchEmail; |
|
44 | + /* @var bool */ |
|
45 | + protected $shareWithGroupOnly; |
|
46 | + /* @var bool */ |
|
47 | + protected $shareeEnumeration; |
|
48 | + /* @var bool */ |
|
49 | + protected $shareeEnumerationInGroupOnly; |
|
50 | + /* @var bool */ |
|
51 | + protected $shareeEnumerationPhone; |
|
52 | + /* @var bool */ |
|
53 | + protected $shareeEnumerationFullMatch; |
|
54 | + /* @var bool */ |
|
55 | + protected $shareeEnumerationFullMatchEmail; |
|
56 | 56 | |
57 | - /** @var IManager */ |
|
58 | - private $contactsManager; |
|
59 | - /** @var ICloudIdManager */ |
|
60 | - private $cloudIdManager; |
|
61 | - /** @var IConfig */ |
|
62 | - private $config; |
|
57 | + /** @var IManager */ |
|
58 | + private $contactsManager; |
|
59 | + /** @var ICloudIdManager */ |
|
60 | + private $cloudIdManager; |
|
61 | + /** @var IConfig */ |
|
62 | + private $config; |
|
63 | 63 | |
64 | - /** @var IGroupManager */ |
|
65 | - private $groupManager; |
|
66 | - /** @var KnownUserService */ |
|
67 | - private $knownUserService; |
|
68 | - /** @var IUserSession */ |
|
69 | - private $userSession; |
|
70 | - /** @var IMailer */ |
|
71 | - private $mailer; |
|
64 | + /** @var IGroupManager */ |
|
65 | + private $groupManager; |
|
66 | + /** @var KnownUserService */ |
|
67 | + private $knownUserService; |
|
68 | + /** @var IUserSession */ |
|
69 | + private $userSession; |
|
70 | + /** @var IMailer */ |
|
71 | + private $mailer; |
|
72 | 72 | |
73 | - public function __construct(IManager $contactsManager, |
|
74 | - ICloudIdManager $cloudIdManager, |
|
75 | - IConfig $config, |
|
76 | - IGroupManager $groupManager, |
|
77 | - KnownUserService $knownUserService, |
|
78 | - IUserSession $userSession, |
|
79 | - IMailer $mailer) { |
|
80 | - $this->contactsManager = $contactsManager; |
|
81 | - $this->cloudIdManager = $cloudIdManager; |
|
82 | - $this->config = $config; |
|
83 | - $this->groupManager = $groupManager; |
|
84 | - $this->knownUserService = $knownUserService; |
|
85 | - $this->userSession = $userSession; |
|
86 | - $this->mailer = $mailer; |
|
73 | + public function __construct(IManager $contactsManager, |
|
74 | + ICloudIdManager $cloudIdManager, |
|
75 | + IConfig $config, |
|
76 | + IGroupManager $groupManager, |
|
77 | + KnownUserService $knownUserService, |
|
78 | + IUserSession $userSession, |
|
79 | + IMailer $mailer) { |
|
80 | + $this->contactsManager = $contactsManager; |
|
81 | + $this->cloudIdManager = $cloudIdManager; |
|
82 | + $this->config = $config; |
|
83 | + $this->groupManager = $groupManager; |
|
84 | + $this->knownUserService = $knownUserService; |
|
85 | + $this->userSession = $userSession; |
|
86 | + $this->mailer = $mailer; |
|
87 | 87 | |
88 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
89 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
90 | - $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
91 | - $this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
92 | - $this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; |
|
93 | - $this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes'; |
|
94 | - } |
|
88 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
89 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
90 | + $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
91 | + $this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
92 | + $this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; |
|
93 | + $this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes'; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * {@inheritdoc} |
|
98 | - */ |
|
99 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
100 | - if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) { |
|
101 | - return false; |
|
102 | - } |
|
96 | + /** |
|
97 | + * {@inheritdoc} |
|
98 | + */ |
|
99 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
100 | + if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) { |
|
101 | + return false; |
|
102 | + } |
|
103 | 103 | |
104 | - // Extract the email address from "Foo Bar <[email protected]>" and then search with "[email protected]" instead |
|
105 | - $result = preg_match('/<([^@]+@.+)>$/', $search, $matches); |
|
106 | - if ($result && filter_var($matches[1], FILTER_VALIDATE_EMAIL)) { |
|
107 | - return $this->search($matches[1], $limit, $offset, $searchResult); |
|
108 | - } |
|
104 | + // Extract the email address from "Foo Bar <[email protected]>" and then search with "[email protected]" instead |
|
105 | + $result = preg_match('/<([^@]+@.+)>$/', $search, $matches); |
|
106 | + if ($result && filter_var($matches[1], FILTER_VALIDATE_EMAIL)) { |
|
107 | + return $this->search($matches[1], $limit, $offset, $searchResult); |
|
108 | + } |
|
109 | 109 | |
110 | - $currentUserId = $this->userSession->getUser()->getUID(); |
|
110 | + $currentUserId = $this->userSession->getUser()->getUID(); |
|
111 | 111 | |
112 | - $result = $userResults = ['wide' => [], 'exact' => []]; |
|
113 | - $userType = new SearchResultType('users'); |
|
114 | - $emailType = new SearchResultType('emails'); |
|
112 | + $result = $userResults = ['wide' => [], 'exact' => []]; |
|
113 | + $userType = new SearchResultType('users'); |
|
114 | + $emailType = new SearchResultType('emails'); |
|
115 | 115 | |
116 | - // Search in contacts |
|
117 | - $addressBookContacts = $this->contactsManager->search( |
|
118 | - $search, |
|
119 | - ['EMAIL', 'FN'], |
|
120 | - [ |
|
121 | - 'limit' => $limit, |
|
122 | - 'offset' => $offset, |
|
123 | - 'enumeration' => (bool) $this->shareeEnumeration, |
|
124 | - 'fullmatch' => (bool) $this->shareeEnumerationFullMatch, |
|
125 | - ] |
|
126 | - ); |
|
127 | - $lowerSearch = strtolower($search); |
|
128 | - foreach ($addressBookContacts as $contact) { |
|
129 | - if (isset($contact['EMAIL'])) { |
|
130 | - $emailAddresses = $contact['EMAIL']; |
|
131 | - if (\is_string($emailAddresses)) { |
|
132 | - $emailAddresses = [$emailAddresses]; |
|
133 | - } |
|
134 | - foreach ($emailAddresses as $type => $emailAddress) { |
|
135 | - $displayName = $emailAddress; |
|
136 | - $emailAddressType = null; |
|
137 | - if (\is_array($emailAddress)) { |
|
138 | - $emailAddressData = $emailAddress; |
|
139 | - $emailAddress = $emailAddressData['value']; |
|
140 | - $emailAddressType = $emailAddressData['type']; |
|
141 | - } |
|
142 | - if (isset($contact['FN'])) { |
|
143 | - $displayName = $contact['FN'] . ' (' . $emailAddress . ')'; |
|
144 | - } |
|
145 | - $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
|
116 | + // Search in contacts |
|
117 | + $addressBookContacts = $this->contactsManager->search( |
|
118 | + $search, |
|
119 | + ['EMAIL', 'FN'], |
|
120 | + [ |
|
121 | + 'limit' => $limit, |
|
122 | + 'offset' => $offset, |
|
123 | + 'enumeration' => (bool) $this->shareeEnumeration, |
|
124 | + 'fullmatch' => (bool) $this->shareeEnumerationFullMatch, |
|
125 | + ] |
|
126 | + ); |
|
127 | + $lowerSearch = strtolower($search); |
|
128 | + foreach ($addressBookContacts as $contact) { |
|
129 | + if (isset($contact['EMAIL'])) { |
|
130 | + $emailAddresses = $contact['EMAIL']; |
|
131 | + if (\is_string($emailAddresses)) { |
|
132 | + $emailAddresses = [$emailAddresses]; |
|
133 | + } |
|
134 | + foreach ($emailAddresses as $type => $emailAddress) { |
|
135 | + $displayName = $emailAddress; |
|
136 | + $emailAddressType = null; |
|
137 | + if (\is_array($emailAddress)) { |
|
138 | + $emailAddressData = $emailAddress; |
|
139 | + $emailAddress = $emailAddressData['value']; |
|
140 | + $emailAddressType = $emailAddressData['type']; |
|
141 | + } |
|
142 | + if (isset($contact['FN'])) { |
|
143 | + $displayName = $contact['FN'] . ' (' . $emailAddress . ')'; |
|
144 | + } |
|
145 | + $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
|
146 | 146 | |
147 | - if (isset($contact['isLocalSystemBook'])) { |
|
148 | - if ($this->shareWithGroupOnly) { |
|
149 | - /* |
|
147 | + if (isset($contact['isLocalSystemBook'])) { |
|
148 | + if ($this->shareWithGroupOnly) { |
|
149 | + /* |
|
150 | 150 | * Check if the user may share with the user associated with the e-mail of the just found contact |
151 | 151 | */ |
152 | - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
153 | - $found = false; |
|
154 | - foreach ($userGroups as $userGroup) { |
|
155 | - if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) { |
|
156 | - $found = true; |
|
157 | - break; |
|
158 | - } |
|
159 | - } |
|
160 | - if (!$found) { |
|
161 | - continue; |
|
162 | - } |
|
163 | - } |
|
164 | - if ($exactEmailMatch && $this->shareeEnumerationFullMatch) { |
|
165 | - try { |
|
166 | - $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
167 | - } catch (\InvalidArgumentException $e) { |
|
168 | - continue; |
|
169 | - } |
|
152 | + $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
153 | + $found = false; |
|
154 | + foreach ($userGroups as $userGroup) { |
|
155 | + if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) { |
|
156 | + $found = true; |
|
157 | + break; |
|
158 | + } |
|
159 | + } |
|
160 | + if (!$found) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + } |
|
164 | + if ($exactEmailMatch && $this->shareeEnumerationFullMatch) { |
|
165 | + try { |
|
166 | + $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
167 | + } catch (\InvalidArgumentException $e) { |
|
168 | + continue; |
|
169 | + } |
|
170 | 170 | |
171 | - if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) { |
|
172 | - $singleResult = [[ |
|
173 | - 'label' => $displayName, |
|
174 | - 'uuid' => $contact['UID'] ?? $emailAddress, |
|
175 | - 'name' => $contact['FN'] ?? $displayName, |
|
176 | - 'value' => [ |
|
177 | - 'shareType' => IShare::TYPE_USER, |
|
178 | - 'shareWith' => $cloud->getUser(), |
|
179 | - ], |
|
180 | - 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() |
|
171 | + if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) { |
|
172 | + $singleResult = [[ |
|
173 | + 'label' => $displayName, |
|
174 | + 'uuid' => $contact['UID'] ?? $emailAddress, |
|
175 | + 'name' => $contact['FN'] ?? $displayName, |
|
176 | + 'value' => [ |
|
177 | + 'shareType' => IShare::TYPE_USER, |
|
178 | + 'shareWith' => $cloud->getUser(), |
|
179 | + ], |
|
180 | + 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() |
|
181 | 181 | |
182 | - ]]; |
|
183 | - $searchResult->addResultSet($userType, [], $singleResult); |
|
184 | - $searchResult->markExactIdMatch($emailType); |
|
185 | - } |
|
186 | - return false; |
|
187 | - } |
|
182 | + ]]; |
|
183 | + $searchResult->addResultSet($userType, [], $singleResult); |
|
184 | + $searchResult->markExactIdMatch($emailType); |
|
185 | + } |
|
186 | + return false; |
|
187 | + } |
|
188 | 188 | |
189 | - if ($this->shareeEnumeration) { |
|
190 | - try { |
|
191 | - $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
192 | - } catch (\InvalidArgumentException $e) { |
|
193 | - continue; |
|
194 | - } |
|
189 | + if ($this->shareeEnumeration) { |
|
190 | + try { |
|
191 | + $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
192 | + } catch (\InvalidArgumentException $e) { |
|
193 | + continue; |
|
194 | + } |
|
195 | 195 | |
196 | - $addToWide = !($this->shareeEnumerationInGroupOnly || $this->shareeEnumerationPhone); |
|
197 | - if (!$addToWide && $this->shareeEnumerationPhone && $this->knownUserService->isKnownToUser($currentUserId, $contact['UID'])) { |
|
198 | - $addToWide = true; |
|
199 | - } |
|
196 | + $addToWide = !($this->shareeEnumerationInGroupOnly || $this->shareeEnumerationPhone); |
|
197 | + if (!$addToWide && $this->shareeEnumerationPhone && $this->knownUserService->isKnownToUser($currentUserId, $contact['UID'])) { |
|
198 | + $addToWide = true; |
|
199 | + } |
|
200 | 200 | |
201 | - if (!$addToWide && $this->shareeEnumerationInGroupOnly) { |
|
202 | - $addToWide = false; |
|
203 | - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
204 | - foreach ($userGroups as $userGroup) { |
|
205 | - if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) { |
|
206 | - $addToWide = true; |
|
207 | - break; |
|
208 | - } |
|
209 | - } |
|
210 | - } |
|
211 | - if ($addToWide && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) { |
|
212 | - $userResults['wide'][] = [ |
|
213 | - 'label' => $displayName, |
|
214 | - 'uuid' => $contact['UID'] ?? $emailAddress, |
|
215 | - 'name' => $contact['FN'] ?? $displayName, |
|
216 | - 'value' => [ |
|
217 | - 'shareType' => IShare::TYPE_USER, |
|
218 | - 'shareWith' => $cloud->getUser(), |
|
219 | - ], |
|
220 | - 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() |
|
221 | - ]; |
|
222 | - continue; |
|
223 | - } |
|
224 | - } |
|
225 | - continue; |
|
226 | - } |
|
201 | + if (!$addToWide && $this->shareeEnumerationInGroupOnly) { |
|
202 | + $addToWide = false; |
|
203 | + $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
204 | + foreach ($userGroups as $userGroup) { |
|
205 | + if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) { |
|
206 | + $addToWide = true; |
|
207 | + break; |
|
208 | + } |
|
209 | + } |
|
210 | + } |
|
211 | + if ($addToWide && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) { |
|
212 | + $userResults['wide'][] = [ |
|
213 | + 'label' => $displayName, |
|
214 | + 'uuid' => $contact['UID'] ?? $emailAddress, |
|
215 | + 'name' => $contact['FN'] ?? $displayName, |
|
216 | + 'value' => [ |
|
217 | + 'shareType' => IShare::TYPE_USER, |
|
218 | + 'shareWith' => $cloud->getUser(), |
|
219 | + ], |
|
220 | + 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() |
|
221 | + ]; |
|
222 | + continue; |
|
223 | + } |
|
224 | + } |
|
225 | + continue; |
|
226 | + } |
|
227 | 227 | |
228 | - if ($exactEmailMatch |
|
229 | - || (isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)) { |
|
230 | - if ($exactEmailMatch) { |
|
231 | - $searchResult->markExactIdMatch($emailType); |
|
232 | - } |
|
233 | - $result['exact'][] = [ |
|
234 | - 'label' => $displayName, |
|
235 | - 'uuid' => $contact['UID'] ?? $emailAddress, |
|
236 | - 'name' => $contact['FN'] ?? $displayName, |
|
237 | - 'type' => $emailAddressType ?? '', |
|
238 | - 'value' => [ |
|
239 | - 'shareType' => IShare::TYPE_EMAIL, |
|
240 | - 'shareWith' => $emailAddress, |
|
241 | - ], |
|
242 | - ]; |
|
243 | - } else { |
|
244 | - $result['wide'][] = [ |
|
245 | - 'label' => $displayName, |
|
246 | - 'uuid' => $contact['UID'] ?? $emailAddress, |
|
247 | - 'name' => $contact['FN'] ?? $displayName, |
|
248 | - 'type' => $emailAddressType ?? '', |
|
249 | - 'value' => [ |
|
250 | - 'shareType' => IShare::TYPE_EMAIL, |
|
251 | - 'shareWith' => $emailAddress, |
|
252 | - ], |
|
253 | - ]; |
|
254 | - } |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
228 | + if ($exactEmailMatch |
|
229 | + || (isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)) { |
|
230 | + if ($exactEmailMatch) { |
|
231 | + $searchResult->markExactIdMatch($emailType); |
|
232 | + } |
|
233 | + $result['exact'][] = [ |
|
234 | + 'label' => $displayName, |
|
235 | + 'uuid' => $contact['UID'] ?? $emailAddress, |
|
236 | + 'name' => $contact['FN'] ?? $displayName, |
|
237 | + 'type' => $emailAddressType ?? '', |
|
238 | + 'value' => [ |
|
239 | + 'shareType' => IShare::TYPE_EMAIL, |
|
240 | + 'shareWith' => $emailAddress, |
|
241 | + ], |
|
242 | + ]; |
|
243 | + } else { |
|
244 | + $result['wide'][] = [ |
|
245 | + 'label' => $displayName, |
|
246 | + 'uuid' => $contact['UID'] ?? $emailAddress, |
|
247 | + 'name' => $contact['FN'] ?? $displayName, |
|
248 | + 'type' => $emailAddressType ?? '', |
|
249 | + 'value' => [ |
|
250 | + 'shareType' => IShare::TYPE_EMAIL, |
|
251 | + 'shareWith' => $emailAddress, |
|
252 | + ], |
|
253 | + ]; |
|
254 | + } |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - $reachedEnd = true; |
|
260 | - if ($this->shareeEnumeration) { |
|
261 | - $reachedEnd = (count($result['wide']) < $offset + $limit) && |
|
262 | - (count($userResults['wide']) < $offset + $limit); |
|
259 | + $reachedEnd = true; |
|
260 | + if ($this->shareeEnumeration) { |
|
261 | + $reachedEnd = (count($result['wide']) < $offset + $limit) && |
|
262 | + (count($userResults['wide']) < $offset + $limit); |
|
263 | 263 | |
264 | - $result['wide'] = array_slice($result['wide'], $offset, $limit); |
|
265 | - $userResults['wide'] = array_slice($userResults['wide'], $offset, $limit); |
|
266 | - } |
|
264 | + $result['wide'] = array_slice($result['wide'], $offset, $limit); |
|
265 | + $userResults['wide'] = array_slice($userResults['wide'], $offset, $limit); |
|
266 | + } |
|
267 | 267 | |
268 | - if (!$searchResult->hasExactIdMatch($emailType) && $this->mailer->validateMailAddress($search)) { |
|
269 | - $result['exact'][] = [ |
|
270 | - 'label' => $search, |
|
271 | - 'uuid' => $search, |
|
272 | - 'value' => [ |
|
273 | - 'shareType' => IShare::TYPE_EMAIL, |
|
274 | - 'shareWith' => $search, |
|
275 | - ], |
|
276 | - ]; |
|
277 | - } |
|
268 | + if (!$searchResult->hasExactIdMatch($emailType) && $this->mailer->validateMailAddress($search)) { |
|
269 | + $result['exact'][] = [ |
|
270 | + 'label' => $search, |
|
271 | + 'uuid' => $search, |
|
272 | + 'value' => [ |
|
273 | + 'shareType' => IShare::TYPE_EMAIL, |
|
274 | + 'shareWith' => $search, |
|
275 | + ], |
|
276 | + ]; |
|
277 | + } |
|
278 | 278 | |
279 | - if (!empty($userResults['wide'])) { |
|
280 | - $searchResult->addResultSet($userType, $userResults['wide'], []); |
|
281 | - } |
|
282 | - $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); |
|
279 | + if (!empty($userResults['wide'])) { |
|
280 | + $searchResult->addResultSet($userType, $userResults['wide'], []); |
|
281 | + } |
|
282 | + $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); |
|
283 | 283 | |
284 | - return !$reachedEnd; |
|
285 | - } |
|
284 | + return !$reachedEnd; |
|
285 | + } |
|
286 | 286 | |
287 | - public function isCurrentUser(ICloudId $cloud): bool { |
|
288 | - $currentUser = $this->userSession->getUser(); |
|
289 | - return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false; |
|
290 | - } |
|
287 | + public function isCurrentUser(ICloudId $cloud): bool { |
|
288 | + $currentUser = $this->userSession->getUser(); |
|
289 | + return $currentUser instanceof IUser ? $currentUser->getUID() === $cloud->getUser() : false; |
|
290 | + } |
|
291 | 291 | } |
@@ -25,92 +25,92 @@ |
||
25 | 25 | namespace OC\OCS; |
26 | 26 | |
27 | 27 | class Provider extends \OCP\AppFramework\Controller { |
28 | - /** @var \OCP\App\IAppManager */ |
|
29 | - private $appManager; |
|
28 | + /** @var \OCP\App\IAppManager */ |
|
29 | + private $appManager; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param string $appName |
|
33 | - * @param \OCP\IRequest $request |
|
34 | - * @param \OCP\App\IAppManager $appManager |
|
35 | - */ |
|
36 | - public function __construct($appName, |
|
37 | - \OCP\IRequest $request, |
|
38 | - \OCP\App\IAppManager $appManager) { |
|
39 | - parent::__construct($appName, $request); |
|
40 | - $this->appManager = $appManager; |
|
41 | - } |
|
31 | + /** |
|
32 | + * @param string $appName |
|
33 | + * @param \OCP\IRequest $request |
|
34 | + * @param \OCP\App\IAppManager $appManager |
|
35 | + */ |
|
36 | + public function __construct($appName, |
|
37 | + \OCP\IRequest $request, |
|
38 | + \OCP\App\IAppManager $appManager) { |
|
39 | + parent::__construct($appName, $request); |
|
40 | + $this->appManager = $appManager; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return \OCP\AppFramework\Http\JSONResponse |
|
45 | - */ |
|
46 | - public function buildProviderList() { |
|
47 | - $services = [ |
|
48 | - 'PRIVATE_DATA' => [ |
|
49 | - 'version' => 1, |
|
50 | - 'endpoints' => [ |
|
51 | - 'store' => '/ocs/v2.php/privatedata/setattribute', |
|
52 | - 'read' => '/ocs/v2.php/privatedata/getattribute', |
|
53 | - 'delete' => '/ocs/v2.php/privatedata/deleteattribute', |
|
54 | - ], |
|
55 | - ], |
|
56 | - ]; |
|
43 | + /** |
|
44 | + * @return \OCP\AppFramework\Http\JSONResponse |
|
45 | + */ |
|
46 | + public function buildProviderList() { |
|
47 | + $services = [ |
|
48 | + 'PRIVATE_DATA' => [ |
|
49 | + 'version' => 1, |
|
50 | + 'endpoints' => [ |
|
51 | + 'store' => '/ocs/v2.php/privatedata/setattribute', |
|
52 | + 'read' => '/ocs/v2.php/privatedata/getattribute', |
|
53 | + 'delete' => '/ocs/v2.php/privatedata/deleteattribute', |
|
54 | + ], |
|
55 | + ], |
|
56 | + ]; |
|
57 | 57 | |
58 | - if ($this->appManager->isEnabledForUser('files_sharing')) { |
|
59 | - $services['SHARING'] = [ |
|
60 | - 'version' => 1, |
|
61 | - 'endpoints' => [ |
|
62 | - 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares', |
|
63 | - ], |
|
64 | - ]; |
|
65 | - $services['FEDERATED_SHARING'] = [ |
|
66 | - 'version' => 1, |
|
67 | - 'endpoints' => [ |
|
68 | - 'share' => '/ocs/v2.php/cloud/shares', |
|
69 | - 'webdav' => '/public.php/webdav/', |
|
70 | - ], |
|
71 | - ]; |
|
72 | - } |
|
58 | + if ($this->appManager->isEnabledForUser('files_sharing')) { |
|
59 | + $services['SHARING'] = [ |
|
60 | + 'version' => 1, |
|
61 | + 'endpoints' => [ |
|
62 | + 'share' => '/ocs/v2.php/apps/files_sharing/api/v1/shares', |
|
63 | + ], |
|
64 | + ]; |
|
65 | + $services['FEDERATED_SHARING'] = [ |
|
66 | + 'version' => 1, |
|
67 | + 'endpoints' => [ |
|
68 | + 'share' => '/ocs/v2.php/cloud/shares', |
|
69 | + 'webdav' => '/public.php/webdav/', |
|
70 | + ], |
|
71 | + ]; |
|
72 | + } |
|
73 | 73 | |
74 | - if ($this->appManager->isEnabledForUser('federation')) { |
|
75 | - if (isset($services['FEDERATED_SHARING'])) { |
|
76 | - $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret'; |
|
77 | - $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system'; |
|
78 | - $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system'; |
|
79 | - } else { |
|
80 | - $services['FEDERATED_SHARING'] = [ |
|
81 | - 'version' => 1, |
|
82 | - 'endpoints' => [ |
|
83 | - 'shared-secret' => '/ocs/v2.php/cloud/shared-secret', |
|
84 | - 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system', |
|
85 | - 'carddav-user' => 'system' |
|
86 | - ], |
|
87 | - ]; |
|
88 | - } |
|
89 | - } |
|
74 | + if ($this->appManager->isEnabledForUser('federation')) { |
|
75 | + if (isset($services['FEDERATED_SHARING'])) { |
|
76 | + $services['FEDERATED_SHARING']['endpoints']['shared-secret'] = '/ocs/v2.php/cloud/shared-secret'; |
|
77 | + $services['FEDERATED_SHARING']['endpoints']['system-address-book'] = '/remote.php/dav/addressbooks/system/system/system'; |
|
78 | + $services['FEDERATED_SHARING']['endpoints']['carddav-user'] = 'system'; |
|
79 | + } else { |
|
80 | + $services['FEDERATED_SHARING'] = [ |
|
81 | + 'version' => 1, |
|
82 | + 'endpoints' => [ |
|
83 | + 'shared-secret' => '/ocs/v2.php/cloud/shared-secret', |
|
84 | + 'system-address-book' => '/remote.php/dav/addressbooks/system/system/system', |
|
85 | + 'carddav-user' => 'system' |
|
86 | + ], |
|
87 | + ]; |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - if ($this->appManager->isEnabledForUser('activity')) { |
|
92 | - $services['ACTIVITY'] = [ |
|
93 | - 'version' => 1, |
|
94 | - 'endpoints' => [ |
|
95 | - 'list' => '/ocs/v2.php/cloud/activity', |
|
96 | - ], |
|
97 | - ]; |
|
98 | - } |
|
91 | + if ($this->appManager->isEnabledForUser('activity')) { |
|
92 | + $services['ACTIVITY'] = [ |
|
93 | + 'version' => 1, |
|
94 | + 'endpoints' => [ |
|
95 | + 'list' => '/ocs/v2.php/cloud/activity', |
|
96 | + ], |
|
97 | + ]; |
|
98 | + } |
|
99 | 99 | |
100 | - if ($this->appManager->isEnabledForUser('provisioning_api')) { |
|
101 | - $services['PROVISIONING'] = [ |
|
102 | - 'version' => 1, |
|
103 | - 'endpoints' => [ |
|
104 | - 'user' => '/ocs/v2.php/cloud/users', |
|
105 | - 'groups' => '/ocs/v2.php/cloud/groups', |
|
106 | - 'apps' => '/ocs/v2.php/cloud/apps', |
|
107 | - ], |
|
108 | - ]; |
|
109 | - } |
|
100 | + if ($this->appManager->isEnabledForUser('provisioning_api')) { |
|
101 | + $services['PROVISIONING'] = [ |
|
102 | + 'version' => 1, |
|
103 | + 'endpoints' => [ |
|
104 | + 'user' => '/ocs/v2.php/cloud/users', |
|
105 | + 'groups' => '/ocs/v2.php/cloud/groups', |
|
106 | + 'apps' => '/ocs/v2.php/cloud/apps', |
|
107 | + ], |
|
108 | + ]; |
|
109 | + } |
|
110 | 110 | |
111 | - return new \OCP\AppFramework\Http\JSONResponse([ |
|
112 | - 'version' => 2, |
|
113 | - 'services' => $services, |
|
114 | - ]); |
|
115 | - } |
|
111 | + return new \OCP\AppFramework\Http\JSONResponse([ |
|
112 | + 'version' => 2, |
|
113 | + 'services' => $services, |
|
114 | + ]); |
|
115 | + } |
|
116 | 116 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | use Throwable; |
31 | 31 | |
32 | 32 | class InvalidProviderException extends Exception { |
33 | - public function __construct(string $providerId, Throwable $previous = null) { |
|
34 | - parent::__construct("The provider '$providerId' does not exist'", 0, $previous); |
|
35 | - } |
|
33 | + public function __construct(string $providerId, Throwable $previous = null) { |
|
34 | + parent::__construct("The provider '$providerId' does not exist'", 0, $previous); |
|
35 | + } |
|
36 | 36 | } |
@@ -28,16 +28,16 @@ |
||
28 | 28 | namespace OC\DB; |
29 | 29 | |
30 | 30 | class MissingIndexInformation { |
31 | - private $listOfMissingIndexes = []; |
|
31 | + private $listOfMissingIndexes = []; |
|
32 | 32 | |
33 | - public function addHintForMissingSubject(string $tableName, string $indexName) { |
|
34 | - $this->listOfMissingIndexes[] = [ |
|
35 | - 'tableName' => $tableName, |
|
36 | - 'indexName' => $indexName |
|
37 | - ]; |
|
38 | - } |
|
33 | + public function addHintForMissingSubject(string $tableName, string $indexName) { |
|
34 | + $this->listOfMissingIndexes[] = [ |
|
35 | + 'tableName' => $tableName, |
|
36 | + 'indexName' => $indexName |
|
37 | + ]; |
|
38 | + } |
|
39 | 39 | |
40 | - public function getListOfMissingIndexes(): array { |
|
41 | - return $this->listOfMissingIndexes; |
|
42 | - } |
|
40 | + public function getListOfMissingIndexes(): array { |
|
41 | + return $this->listOfMissingIndexes; |
|
42 | + } |
|
43 | 43 | } |
@@ -27,16 +27,16 @@ |
||
27 | 27 | namespace OC\DB; |
28 | 28 | |
29 | 29 | class MissingColumnInformation { |
30 | - private $listOfMissingColumns = []; |
|
30 | + private $listOfMissingColumns = []; |
|
31 | 31 | |
32 | - public function addHintForMissingColumn(string $tableName, string $columnName): void { |
|
33 | - $this->listOfMissingColumns[] = [ |
|
34 | - 'tableName' => $tableName, |
|
35 | - 'columnName' => $columnName, |
|
36 | - ]; |
|
37 | - } |
|
32 | + public function addHintForMissingColumn(string $tableName, string $columnName): void { |
|
33 | + $this->listOfMissingColumns[] = [ |
|
34 | + 'tableName' => $tableName, |
|
35 | + 'columnName' => $columnName, |
|
36 | + ]; |
|
37 | + } |
|
38 | 38 | |
39 | - public function getListOfMissingColumns(): array { |
|
40 | - return $this->listOfMissingColumns; |
|
41 | - } |
|
39 | + public function getListOfMissingColumns(): array { |
|
40 | + return $this->listOfMissingColumns; |
|
41 | + } |
|
42 | 42 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $request = $this->prepareRequest($request, $credentials); |
65 | 65 | $stringToSign = $this->createCanonicalizedString($request); |
66 | 66 | $auth = 'AWS ' |
67 | - . $credentials->getAccessKeyId() . ':' |
|
67 | + . $credentials->getAccessKeyId().':' |
|
68 | 68 | . $this->signString($stringToSign, $credentials); |
69 | 69 | |
70 | 70 | return $request->withHeader('Authorization', $auth); |
@@ -148,11 +148,11 @@ discard block |
||
148 | 148 | RequestInterface $request, |
149 | 149 | $expires = null |
150 | 150 | ) { |
151 | - $buffer = $request->getMethod() . "\n"; |
|
151 | + $buffer = $request->getMethod()."\n"; |
|
152 | 152 | |
153 | 153 | // Add the interesting headers |
154 | 154 | foreach ($this->signableHeaders as $header) { |
155 | - $buffer .= $request->getHeaderLine($header) . "\n"; |
|
155 | + $buffer .= $request->getHeaderLine($header)."\n"; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | $date = $expires ?: $request->getHeaderLine('date'); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | if (strpos($name, 'x-amz-') === 0) { |
171 | 171 | $value = implode(',', $header); |
172 | 172 | if (strlen($value) > 0) { |
173 | - $headers[$name] = $name . ':' . $value; |
|
173 | + $headers[$name] = $name.':'.$value; |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | |
182 | 182 | ksort($headers); |
183 | 183 | |
184 | - return implode("\n", $headers) . "\n"; |
|
184 | + return implode("\n", $headers)."\n"; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | private function createCanonicalizedResource(RequestInterface $request) { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | if ($data['bucket']) { |
192 | 192 | $buffer .= $data['bucket']; |
193 | 193 | if (!empty($data['key']) || !$data['path_style']) { |
194 | - $buffer .= '/' . $data['key']; |
|
194 | + $buffer .= '/'.$data['key']; |
|
195 | 195 | } |
196 | 196 | } |
197 | 197 |
@@ -35,188 +35,188 @@ |
||
35 | 35 | * Legacy Amazon S3 signature implementation |
36 | 36 | */ |
37 | 37 | class S3Signature implements SignatureInterface { |
38 | - /** @var array Query string values that must be signed */ |
|
39 | - private $signableQueryString = [ |
|
40 | - 'acl', 'cors', 'delete', 'lifecycle', 'location', 'logging', |
|
41 | - 'notification', 'partNumber', 'policy', 'requestPayment', |
|
42 | - 'response-cache-control', 'response-content-disposition', |
|
43 | - 'response-content-encoding', 'response-content-language', |
|
44 | - 'response-content-type', 'response-expires', 'restore', 'tagging', |
|
45 | - 'torrent', 'uploadId', 'uploads', 'versionId', 'versioning', |
|
46 | - 'versions', 'website' |
|
47 | - ]; |
|
48 | - |
|
49 | - /** @var array Sorted headers that must be signed */ |
|
50 | - private $signableHeaders = ['Content-MD5', 'Content-Type']; |
|
51 | - |
|
52 | - /** @var \Aws\S3\S3UriParser S3 URI parser */ |
|
53 | - private $parser; |
|
54 | - |
|
55 | - public function __construct() { |
|
56 | - $this->parser = new S3UriParser(); |
|
57 | - // Ensure that the signable query string parameters are sorted |
|
58 | - sort($this->signableQueryString); |
|
59 | - } |
|
60 | - |
|
61 | - public function signRequest( |
|
62 | - RequestInterface $request, |
|
63 | - CredentialsInterface $credentials |
|
64 | - ) { |
|
65 | - $request = $this->prepareRequest($request, $credentials); |
|
66 | - $stringToSign = $this->createCanonicalizedString($request); |
|
67 | - $auth = 'AWS ' |
|
68 | - . $credentials->getAccessKeyId() . ':' |
|
69 | - . $this->signString($stringToSign, $credentials); |
|
70 | - |
|
71 | - return $request->withHeader('Authorization', $auth); |
|
72 | - } |
|
73 | - |
|
74 | - public function presign( |
|
75 | - RequestInterface $request, |
|
76 | - CredentialsInterface $credentials, |
|
77 | - $expires, |
|
78 | - array $options = [] |
|
79 | - ) { |
|
80 | - $query = []; |
|
81 | - // URL encoding already occurs in the URI template expansion. Undo that |
|
82 | - // and encode using the same encoding as GET object, PUT object, etc. |
|
83 | - $uri = $request->getUri(); |
|
84 | - $path = S3Client::encodeKey(rawurldecode($uri->getPath())); |
|
85 | - $request = $request->withUri($uri->withPath($path)); |
|
86 | - |
|
87 | - // Make sure to handle temporary credentials |
|
88 | - if ($token = $credentials->getSecurityToken()) { |
|
89 | - $request = $request->withHeader('X-Amz-Security-Token', $token); |
|
90 | - $query['X-Amz-Security-Token'] = $token; |
|
91 | - } |
|
92 | - |
|
93 | - if ($expires instanceof \DateTime) { |
|
94 | - $expires = $expires->getTimestamp(); |
|
95 | - } elseif (!is_numeric($expires)) { |
|
96 | - $expires = strtotime($expires); |
|
97 | - } |
|
98 | - |
|
99 | - // Set query params required for pre-signed URLs |
|
100 | - $query['AWSAccessKeyId'] = $credentials->getAccessKeyId(); |
|
101 | - $query['Expires'] = $expires; |
|
102 | - $query['Signature'] = $this->signString( |
|
103 | - $this->createCanonicalizedString($request, $expires), |
|
104 | - $credentials |
|
105 | - ); |
|
106 | - |
|
107 | - // Move X-Amz-* headers to the query string |
|
108 | - foreach ($request->getHeaders() as $name => $header) { |
|
109 | - $name = strtolower($name); |
|
110 | - if (strpos($name, 'x-amz-') === 0) { |
|
111 | - $query[$name] = implode(',', $header); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - $queryString = http_build_query($query, null, '&', PHP_QUERY_RFC3986); |
|
116 | - |
|
117 | - return $request->withUri($request->getUri()->withQuery($queryString)); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @param RequestInterface $request |
|
122 | - * @param CredentialsInterface $creds |
|
123 | - * |
|
124 | - * @return RequestInterface |
|
125 | - */ |
|
126 | - private function prepareRequest( |
|
127 | - RequestInterface $request, |
|
128 | - CredentialsInterface $creds |
|
129 | - ) { |
|
130 | - $modify = [ |
|
131 | - 'remove_headers' => ['X-Amz-Date'], |
|
132 | - 'set_headers' => ['Date' => gmdate(\DateTimeInterface::RFC2822)] |
|
133 | - ]; |
|
134 | - |
|
135 | - // Add the security token header if one is being used by the credentials |
|
136 | - if ($token = $creds->getSecurityToken()) { |
|
137 | - $modify['set_headers']['X-Amz-Security-Token'] = $token; |
|
138 | - } |
|
139 | - |
|
140 | - return Psr7\Utils::modifyRequest($request, $modify); |
|
141 | - } |
|
142 | - |
|
143 | - private function signString($string, CredentialsInterface $credentials) { |
|
144 | - return base64_encode( |
|
145 | - hash_hmac('sha1', $string, $credentials->getSecretKey(), true) |
|
146 | - ); |
|
147 | - } |
|
148 | - |
|
149 | - private function createCanonicalizedString( |
|
150 | - RequestInterface $request, |
|
151 | - $expires = null |
|
152 | - ) { |
|
153 | - $buffer = $request->getMethod() . "\n"; |
|
154 | - |
|
155 | - // Add the interesting headers |
|
156 | - foreach ($this->signableHeaders as $header) { |
|
157 | - $buffer .= $request->getHeaderLine($header) . "\n"; |
|
158 | - } |
|
159 | - |
|
160 | - $date = $expires ?: $request->getHeaderLine('date'); |
|
161 | - $buffer .= "{$date}\n" |
|
162 | - . $this->createCanonicalizedAmzHeaders($request) |
|
163 | - . $this->createCanonicalizedResource($request); |
|
164 | - |
|
165 | - return $buffer; |
|
166 | - } |
|
167 | - |
|
168 | - private function createCanonicalizedAmzHeaders(RequestInterface $request) { |
|
169 | - $headers = []; |
|
170 | - foreach ($request->getHeaders() as $name => $header) { |
|
171 | - $name = strtolower($name); |
|
172 | - if (strpos($name, 'x-amz-') === 0) { |
|
173 | - $value = implode(',', $header); |
|
174 | - if (strlen($value) > 0) { |
|
175 | - $headers[$name] = $name . ':' . $value; |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - if (!$headers) { |
|
181 | - return ''; |
|
182 | - } |
|
183 | - |
|
184 | - ksort($headers); |
|
185 | - |
|
186 | - return implode("\n", $headers) . "\n"; |
|
187 | - } |
|
188 | - |
|
189 | - private function createCanonicalizedResource(RequestInterface $request) { |
|
190 | - $data = $this->parser->parse($request->getUri()); |
|
191 | - $buffer = '/'; |
|
192 | - |
|
193 | - if ($data['bucket']) { |
|
194 | - $buffer .= $data['bucket']; |
|
195 | - if (!empty($data['key']) || !$data['path_style']) { |
|
196 | - $buffer .= '/' . $data['key']; |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - // Add sub resource parameters if present. |
|
201 | - $query = $request->getUri()->getQuery(); |
|
202 | - |
|
203 | - if ($query) { |
|
204 | - $params = Psr7\Query::parse($query); |
|
205 | - $first = true; |
|
206 | - foreach ($this->signableQueryString as $key) { |
|
207 | - if (array_key_exists($key, $params)) { |
|
208 | - $value = $params[$key]; |
|
209 | - $buffer .= $first ? '?' : '&'; |
|
210 | - $first = false; |
|
211 | - $buffer .= $key; |
|
212 | - // Don't add values for empty sub-resources |
|
213 | - if (strlen($value)) { |
|
214 | - $buffer .= "={$value}"; |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - return $buffer; |
|
221 | - } |
|
38 | + /** @var array Query string values that must be signed */ |
|
39 | + private $signableQueryString = [ |
|
40 | + 'acl', 'cors', 'delete', 'lifecycle', 'location', 'logging', |
|
41 | + 'notification', 'partNumber', 'policy', 'requestPayment', |
|
42 | + 'response-cache-control', 'response-content-disposition', |
|
43 | + 'response-content-encoding', 'response-content-language', |
|
44 | + 'response-content-type', 'response-expires', 'restore', 'tagging', |
|
45 | + 'torrent', 'uploadId', 'uploads', 'versionId', 'versioning', |
|
46 | + 'versions', 'website' |
|
47 | + ]; |
|
48 | + |
|
49 | + /** @var array Sorted headers that must be signed */ |
|
50 | + private $signableHeaders = ['Content-MD5', 'Content-Type']; |
|
51 | + |
|
52 | + /** @var \Aws\S3\S3UriParser S3 URI parser */ |
|
53 | + private $parser; |
|
54 | + |
|
55 | + public function __construct() { |
|
56 | + $this->parser = new S3UriParser(); |
|
57 | + // Ensure that the signable query string parameters are sorted |
|
58 | + sort($this->signableQueryString); |
|
59 | + } |
|
60 | + |
|
61 | + public function signRequest( |
|
62 | + RequestInterface $request, |
|
63 | + CredentialsInterface $credentials |
|
64 | + ) { |
|
65 | + $request = $this->prepareRequest($request, $credentials); |
|
66 | + $stringToSign = $this->createCanonicalizedString($request); |
|
67 | + $auth = 'AWS ' |
|
68 | + . $credentials->getAccessKeyId() . ':' |
|
69 | + . $this->signString($stringToSign, $credentials); |
|
70 | + |
|
71 | + return $request->withHeader('Authorization', $auth); |
|
72 | + } |
|
73 | + |
|
74 | + public function presign( |
|
75 | + RequestInterface $request, |
|
76 | + CredentialsInterface $credentials, |
|
77 | + $expires, |
|
78 | + array $options = [] |
|
79 | + ) { |
|
80 | + $query = []; |
|
81 | + // URL encoding already occurs in the URI template expansion. Undo that |
|
82 | + // and encode using the same encoding as GET object, PUT object, etc. |
|
83 | + $uri = $request->getUri(); |
|
84 | + $path = S3Client::encodeKey(rawurldecode($uri->getPath())); |
|
85 | + $request = $request->withUri($uri->withPath($path)); |
|
86 | + |
|
87 | + // Make sure to handle temporary credentials |
|
88 | + if ($token = $credentials->getSecurityToken()) { |
|
89 | + $request = $request->withHeader('X-Amz-Security-Token', $token); |
|
90 | + $query['X-Amz-Security-Token'] = $token; |
|
91 | + } |
|
92 | + |
|
93 | + if ($expires instanceof \DateTime) { |
|
94 | + $expires = $expires->getTimestamp(); |
|
95 | + } elseif (!is_numeric($expires)) { |
|
96 | + $expires = strtotime($expires); |
|
97 | + } |
|
98 | + |
|
99 | + // Set query params required for pre-signed URLs |
|
100 | + $query['AWSAccessKeyId'] = $credentials->getAccessKeyId(); |
|
101 | + $query['Expires'] = $expires; |
|
102 | + $query['Signature'] = $this->signString( |
|
103 | + $this->createCanonicalizedString($request, $expires), |
|
104 | + $credentials |
|
105 | + ); |
|
106 | + |
|
107 | + // Move X-Amz-* headers to the query string |
|
108 | + foreach ($request->getHeaders() as $name => $header) { |
|
109 | + $name = strtolower($name); |
|
110 | + if (strpos($name, 'x-amz-') === 0) { |
|
111 | + $query[$name] = implode(',', $header); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + $queryString = http_build_query($query, null, '&', PHP_QUERY_RFC3986); |
|
116 | + |
|
117 | + return $request->withUri($request->getUri()->withQuery($queryString)); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @param RequestInterface $request |
|
122 | + * @param CredentialsInterface $creds |
|
123 | + * |
|
124 | + * @return RequestInterface |
|
125 | + */ |
|
126 | + private function prepareRequest( |
|
127 | + RequestInterface $request, |
|
128 | + CredentialsInterface $creds |
|
129 | + ) { |
|
130 | + $modify = [ |
|
131 | + 'remove_headers' => ['X-Amz-Date'], |
|
132 | + 'set_headers' => ['Date' => gmdate(\DateTimeInterface::RFC2822)] |
|
133 | + ]; |
|
134 | + |
|
135 | + // Add the security token header if one is being used by the credentials |
|
136 | + if ($token = $creds->getSecurityToken()) { |
|
137 | + $modify['set_headers']['X-Amz-Security-Token'] = $token; |
|
138 | + } |
|
139 | + |
|
140 | + return Psr7\Utils::modifyRequest($request, $modify); |
|
141 | + } |
|
142 | + |
|
143 | + private function signString($string, CredentialsInterface $credentials) { |
|
144 | + return base64_encode( |
|
145 | + hash_hmac('sha1', $string, $credentials->getSecretKey(), true) |
|
146 | + ); |
|
147 | + } |
|
148 | + |
|
149 | + private function createCanonicalizedString( |
|
150 | + RequestInterface $request, |
|
151 | + $expires = null |
|
152 | + ) { |
|
153 | + $buffer = $request->getMethod() . "\n"; |
|
154 | + |
|
155 | + // Add the interesting headers |
|
156 | + foreach ($this->signableHeaders as $header) { |
|
157 | + $buffer .= $request->getHeaderLine($header) . "\n"; |
|
158 | + } |
|
159 | + |
|
160 | + $date = $expires ?: $request->getHeaderLine('date'); |
|
161 | + $buffer .= "{$date}\n" |
|
162 | + . $this->createCanonicalizedAmzHeaders($request) |
|
163 | + . $this->createCanonicalizedResource($request); |
|
164 | + |
|
165 | + return $buffer; |
|
166 | + } |
|
167 | + |
|
168 | + private function createCanonicalizedAmzHeaders(RequestInterface $request) { |
|
169 | + $headers = []; |
|
170 | + foreach ($request->getHeaders() as $name => $header) { |
|
171 | + $name = strtolower($name); |
|
172 | + if (strpos($name, 'x-amz-') === 0) { |
|
173 | + $value = implode(',', $header); |
|
174 | + if (strlen($value) > 0) { |
|
175 | + $headers[$name] = $name . ':' . $value; |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + if (!$headers) { |
|
181 | + return ''; |
|
182 | + } |
|
183 | + |
|
184 | + ksort($headers); |
|
185 | + |
|
186 | + return implode("\n", $headers) . "\n"; |
|
187 | + } |
|
188 | + |
|
189 | + private function createCanonicalizedResource(RequestInterface $request) { |
|
190 | + $data = $this->parser->parse($request->getUri()); |
|
191 | + $buffer = '/'; |
|
192 | + |
|
193 | + if ($data['bucket']) { |
|
194 | + $buffer .= $data['bucket']; |
|
195 | + if (!empty($data['key']) || !$data['path_style']) { |
|
196 | + $buffer .= '/' . $data['key']; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + // Add sub resource parameters if present. |
|
201 | + $query = $request->getUri()->getQuery(); |
|
202 | + |
|
203 | + if ($query) { |
|
204 | + $params = Psr7\Query::parse($query); |
|
205 | + $first = true; |
|
206 | + foreach ($this->signableQueryString as $key) { |
|
207 | + if (array_key_exists($key, $params)) { |
|
208 | + $value = $params[$key]; |
|
209 | + $buffer .= $first ? '?' : '&'; |
|
210 | + $first = false; |
|
211 | + $buffer .= $key; |
|
212 | + // Don't add values for empty sub-resources |
|
213 | + if (strlen($value)) { |
|
214 | + $buffer .= "={$value}"; |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + return $buffer; |
|
221 | + } |
|
222 | 222 | } |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
176 | - $this->dispatcher->dispatch(IGroup::class . '::preAddUser', new GenericEvent($this, [ |
|
176 | + $this->dispatcher->dispatch(IGroup::class.'::preAddUser', new GenericEvent($this, [ |
|
177 | 177 | 'user' => $user, |
178 | 178 | ])); |
179 | 179 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $this->users[$user->getUID()] = $user; |
188 | 188 | } |
189 | 189 | |
190 | - $this->dispatcher->dispatch(IGroup::class . '::postAddUser', new GenericEvent($this, [ |
|
190 | + $this->dispatcher->dispatch(IGroup::class.'::postAddUser', new GenericEvent($this, [ |
|
191 | 191 | 'user' => $user, |
192 | 192 | ])); |
193 | 193 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function removeUser($user) { |
208 | 208 | $result = false; |
209 | - $this->dispatcher->dispatch(IGroup::class . '::preRemoveUser', new GenericEvent($this, [ |
|
209 | + $this->dispatcher->dispatch(IGroup::class.'::preRemoveUser', new GenericEvent($this, [ |
|
210 | 210 | 'user' => $user, |
211 | 211 | ])); |
212 | 212 | if ($this->emitter) { |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | } |
220 | 220 | } |
221 | 221 | if ($result) { |
222 | - $this->dispatcher->dispatch(IGroup::class . '::postRemoveUser', new GenericEvent($this, [ |
|
222 | + $this->dispatcher->dispatch(IGroup::class.'::postRemoveUser', new GenericEvent($this, [ |
|
223 | 223 | 'user' => $user, |
224 | 224 | ])); |
225 | 225 | if ($this->emitter) { |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | $result = false; |
332 | - $this->dispatcher->dispatch(IGroup::class . '::preDelete', new GenericEvent($this)); |
|
332 | + $this->dispatcher->dispatch(IGroup::class.'::preDelete', new GenericEvent($this)); |
|
333 | 333 | if ($this->emitter) { |
334 | 334 | $this->emitter->emit('\OC\Group', 'preDelete', [$this]); |
335 | 335 | } |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | } |
341 | 341 | } |
342 | 342 | if ($result) { |
343 | - $this->dispatcher->dispatch(IGroup::class . '::postDelete', new GenericEvent($this)); |
|
343 | + $this->dispatcher->dispatch(IGroup::class.'::postDelete', new GenericEvent($this)); |
|
344 | 344 | if ($this->emitter) { |
345 | 345 | $this->emitter->emit('\OC\Group', 'postDelete', [$this]); |
346 | 346 | } |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | * @since 16.0.0 |
399 | 399 | */ |
400 | 400 | public function hideFromCollaboration(): bool { |
401 | - return array_reduce($this->backends, function (bool $hide, GroupInterface $backend) { |
|
401 | + return array_reduce($this->backends, function(bool $hide, GroupInterface $backend) { |
|
402 | 402 | return $hide | ($backend instanceof IHideFromCollaborationBackend && $backend->hideGroup($this->gid)); |
403 | 403 | }, false); |
404 | 404 | } |
@@ -48,380 +48,380 @@ |
||
48 | 48 | use Symfony\Component\EventDispatcher\GenericEvent; |
49 | 49 | |
50 | 50 | class Group implements IGroup { |
51 | - /** @var null|string */ |
|
52 | - protected $displayName; |
|
53 | - |
|
54 | - /** @var string */ |
|
55 | - private $gid; |
|
56 | - |
|
57 | - /** @var \OC\User\User[] */ |
|
58 | - private $users = []; |
|
59 | - |
|
60 | - /** @var bool */ |
|
61 | - private $usersLoaded; |
|
62 | - |
|
63 | - /** @var Backend[] */ |
|
64 | - private $backends; |
|
65 | - /** @var EventDispatcherInterface */ |
|
66 | - private $dispatcher; |
|
67 | - /** @var \OC\User\Manager|IUserManager */ |
|
68 | - private $userManager; |
|
69 | - /** @var PublicEmitter */ |
|
70 | - private $emitter; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param string $gid |
|
75 | - * @param Backend[] $backends |
|
76 | - * @param EventDispatcherInterface $dispatcher |
|
77 | - * @param IUserManager $userManager |
|
78 | - * @param PublicEmitter $emitter |
|
79 | - * @param string $displayName |
|
80 | - */ |
|
81 | - public function __construct(string $gid, array $backends, EventDispatcherInterface $dispatcher, IUserManager $userManager, PublicEmitter $emitter = null, ?string $displayName = null) { |
|
82 | - $this->gid = $gid; |
|
83 | - $this->backends = $backends; |
|
84 | - $this->dispatcher = $dispatcher; |
|
85 | - $this->userManager = $userManager; |
|
86 | - $this->emitter = $emitter; |
|
87 | - $this->displayName = $displayName; |
|
88 | - } |
|
89 | - |
|
90 | - public function getGID() { |
|
91 | - return $this->gid; |
|
92 | - } |
|
93 | - |
|
94 | - public function getDisplayName() { |
|
95 | - if (is_null($this->displayName)) { |
|
96 | - foreach ($this->backends as $backend) { |
|
97 | - if ($backend instanceof IGetDisplayNameBackend) { |
|
98 | - $displayName = $backend->getDisplayName($this->gid); |
|
99 | - if (trim($displayName) !== '') { |
|
100 | - $this->displayName = $displayName; |
|
101 | - return $this->displayName; |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - return $this->gid; |
|
106 | - } |
|
107 | - return $this->displayName; |
|
108 | - } |
|
109 | - |
|
110 | - public function setDisplayName(string $displayName): bool { |
|
111 | - $displayName = trim($displayName); |
|
112 | - if ($displayName !== '') { |
|
113 | - $this->dispatcher->dispatch(new BeforeGroupChangedEvent($this, 'displayName', $displayName, $this->displayName)); |
|
114 | - foreach ($this->backends as $backend) { |
|
115 | - if (($backend instanceof ISetDisplayNameBackend) |
|
116 | - && $backend->setDisplayName($this->gid, $displayName)) { |
|
117 | - $this->displayName = $displayName; |
|
118 | - $this->dispatcher->dispatch(new GroupChangedEvent($this, 'displayName', $displayName, '')); |
|
119 | - return true; |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - return false; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * get all users in the group |
|
128 | - * |
|
129 | - * @return \OC\User\User[] |
|
130 | - */ |
|
131 | - public function getUsers() { |
|
132 | - if ($this->usersLoaded) { |
|
133 | - return $this->users; |
|
134 | - } |
|
135 | - |
|
136 | - $userIds = []; |
|
137 | - foreach ($this->backends as $backend) { |
|
138 | - $diff = array_diff( |
|
139 | - $backend->usersInGroup($this->gid), |
|
140 | - $userIds |
|
141 | - ); |
|
142 | - if ($diff) { |
|
143 | - $userIds = array_merge($userIds, $diff); |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - $this->users = $this->getVerifiedUsers($userIds); |
|
148 | - $this->usersLoaded = true; |
|
149 | - return $this->users; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * check if a user is in the group |
|
154 | - * |
|
155 | - * @param IUser $user |
|
156 | - * @return bool |
|
157 | - */ |
|
158 | - public function inGroup(IUser $user) { |
|
159 | - if (isset($this->users[$user->getUID()])) { |
|
160 | - return true; |
|
161 | - } |
|
162 | - foreach ($this->backends as $backend) { |
|
163 | - if ($backend->inGroup($user->getUID(), $this->gid)) { |
|
164 | - $this->users[$user->getUID()] = $user; |
|
165 | - return true; |
|
166 | - } |
|
167 | - } |
|
168 | - return false; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * add a user to the group |
|
173 | - * |
|
174 | - * @param IUser $user |
|
175 | - */ |
|
176 | - public function addUser(IUser $user) { |
|
177 | - if ($this->inGroup($user)) { |
|
178 | - return; |
|
179 | - } |
|
180 | - |
|
181 | - $this->dispatcher->dispatch(IGroup::class . '::preAddUser', new GenericEvent($this, [ |
|
182 | - 'user' => $user, |
|
183 | - ])); |
|
184 | - |
|
185 | - if ($this->emitter) { |
|
186 | - $this->emitter->emit('\OC\Group', 'preAddUser', [$this, $user]); |
|
187 | - } |
|
188 | - foreach ($this->backends as $backend) { |
|
189 | - if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) { |
|
190 | - $backend->addToGroup($user->getUID(), $this->gid); |
|
191 | - if ($this->users) { |
|
192 | - $this->users[$user->getUID()] = $user; |
|
193 | - } |
|
194 | - |
|
195 | - $this->dispatcher->dispatch(IGroup::class . '::postAddUser', new GenericEvent($this, [ |
|
196 | - 'user' => $user, |
|
197 | - ])); |
|
198 | - |
|
199 | - if ($this->emitter) { |
|
200 | - $this->emitter->emit('\OC\Group', 'postAddUser', [$this, $user]); |
|
201 | - } |
|
202 | - return; |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * remove a user from the group |
|
209 | - * |
|
210 | - * @param \OC\User\User $user |
|
211 | - */ |
|
212 | - public function removeUser($user) { |
|
213 | - $result = false; |
|
214 | - $this->dispatcher->dispatch(IGroup::class . '::preRemoveUser', new GenericEvent($this, [ |
|
215 | - 'user' => $user, |
|
216 | - ])); |
|
217 | - if ($this->emitter) { |
|
218 | - $this->emitter->emit('\OC\Group', 'preRemoveUser', [$this, $user]); |
|
219 | - } |
|
220 | - foreach ($this->backends as $backend) { |
|
221 | - if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { |
|
222 | - $backend->removeFromGroup($user->getUID(), $this->gid); |
|
223 | - $result = true; |
|
224 | - } |
|
225 | - } |
|
226 | - if ($result) { |
|
227 | - $this->dispatcher->dispatch(IGroup::class . '::postRemoveUser', new GenericEvent($this, [ |
|
228 | - 'user' => $user, |
|
229 | - ])); |
|
230 | - if ($this->emitter) { |
|
231 | - $this->emitter->emit('\OC\Group', 'postRemoveUser', [$this, $user]); |
|
232 | - } |
|
233 | - if ($this->users) { |
|
234 | - foreach ($this->users as $index => $groupUser) { |
|
235 | - if ($groupUser->getUID() === $user->getUID()) { |
|
236 | - unset($this->users[$index]); |
|
237 | - return; |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * search for users in the group by userid |
|
246 | - * |
|
247 | - * @param string $search |
|
248 | - * @param int $limit |
|
249 | - * @param int $offset |
|
250 | - * @return \OC\User\User[] |
|
251 | - */ |
|
252 | - public function searchUsers($search, $limit = null, $offset = null) { |
|
253 | - $users = []; |
|
254 | - foreach ($this->backends as $backend) { |
|
255 | - $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
256 | - $users += $this->getVerifiedUsers($userIds); |
|
257 | - if (!is_null($limit) and $limit <= 0) { |
|
258 | - return $users; |
|
259 | - } |
|
260 | - } |
|
261 | - return $users; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * returns the number of users matching the search string |
|
266 | - * |
|
267 | - * @param string $search |
|
268 | - * @return int|bool |
|
269 | - */ |
|
270 | - public function count($search = '') { |
|
271 | - $users = false; |
|
272 | - foreach ($this->backends as $backend) { |
|
273 | - if ($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) { |
|
274 | - if ($users === false) { |
|
275 | - //we could directly add to a bool variable, but this would |
|
276 | - //be ugly |
|
277 | - $users = 0; |
|
278 | - } |
|
279 | - $users += $backend->countUsersInGroup($this->gid, $search); |
|
280 | - } |
|
281 | - } |
|
282 | - return $users; |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * returns the number of disabled users |
|
287 | - * |
|
288 | - * @return int|bool |
|
289 | - */ |
|
290 | - public function countDisabled() { |
|
291 | - $users = false; |
|
292 | - foreach ($this->backends as $backend) { |
|
293 | - if ($backend instanceof ICountDisabledInGroup) { |
|
294 | - if ($users === false) { |
|
295 | - //we could directly add to a bool variable, but this would |
|
296 | - //be ugly |
|
297 | - $users = 0; |
|
298 | - } |
|
299 | - $users += $backend->countDisabledInGroup($this->gid); |
|
300 | - } |
|
301 | - } |
|
302 | - return $users; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * search for users in the group by displayname |
|
307 | - * |
|
308 | - * @param string $search |
|
309 | - * @param int $limit |
|
310 | - * @param int $offset |
|
311 | - * @return \OC\User\User[] |
|
312 | - */ |
|
313 | - public function searchDisplayName($search, $limit = null, $offset = null) { |
|
314 | - $users = []; |
|
315 | - foreach ($this->backends as $backend) { |
|
316 | - $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
317 | - $users = $this->getVerifiedUsers($userIds); |
|
318 | - if (!is_null($limit) and $limit <= 0) { |
|
319 | - return array_values($users); |
|
320 | - } |
|
321 | - } |
|
322 | - return array_values($users); |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Get the names of the backend classes the group is connected to |
|
327 | - * |
|
328 | - * @return string[] |
|
329 | - */ |
|
330 | - public function getBackendNames() { |
|
331 | - $backends = []; |
|
332 | - foreach ($this->backends as $backend) { |
|
333 | - if ($backend instanceof INamedBackend) { |
|
334 | - $backends[] = $backend->getBackendName(); |
|
335 | - } else { |
|
336 | - $backends[] = get_class($backend); |
|
337 | - } |
|
338 | - } |
|
339 | - |
|
340 | - return $backends; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * delete the group |
|
345 | - * |
|
346 | - * @return bool |
|
347 | - */ |
|
348 | - public function delete() { |
|
349 | - // Prevent users from deleting group admin |
|
350 | - if ($this->getGID() === 'admin') { |
|
351 | - return false; |
|
352 | - } |
|
353 | - |
|
354 | - $result = false; |
|
355 | - $this->dispatcher->dispatch(IGroup::class . '::preDelete', new GenericEvent($this)); |
|
356 | - if ($this->emitter) { |
|
357 | - $this->emitter->emit('\OC\Group', 'preDelete', [$this]); |
|
358 | - } |
|
359 | - foreach ($this->backends as $backend) { |
|
360 | - if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) { |
|
361 | - $result = $result || $backend->deleteGroup($this->gid); |
|
362 | - } |
|
363 | - } |
|
364 | - if ($result) { |
|
365 | - $this->dispatcher->dispatch(IGroup::class . '::postDelete', new GenericEvent($this)); |
|
366 | - if ($this->emitter) { |
|
367 | - $this->emitter->emit('\OC\Group', 'postDelete', [$this]); |
|
368 | - } |
|
369 | - } |
|
370 | - return $result; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * returns all the Users from an array that really exists |
|
375 | - * @param string[] $userIds an array containing user IDs |
|
376 | - * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value |
|
377 | - */ |
|
378 | - private function getVerifiedUsers($userIds) { |
|
379 | - if (!is_array($userIds)) { |
|
380 | - return []; |
|
381 | - } |
|
382 | - $users = []; |
|
383 | - foreach ($userIds as $userId) { |
|
384 | - $user = $this->userManager->get($userId); |
|
385 | - if (!is_null($user)) { |
|
386 | - $users[$userId] = $user; |
|
387 | - } |
|
388 | - } |
|
389 | - return $users; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * @return bool |
|
394 | - * @since 14.0.0 |
|
395 | - */ |
|
396 | - public function canRemoveUser() { |
|
397 | - foreach ($this->backends as $backend) { |
|
398 | - if ($backend->implementsActions(GroupInterface::REMOVE_FROM_GOUP)) { |
|
399 | - return true; |
|
400 | - } |
|
401 | - } |
|
402 | - return false; |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * @return bool |
|
407 | - * @since 14.0.0 |
|
408 | - */ |
|
409 | - public function canAddUser() { |
|
410 | - foreach ($this->backends as $backend) { |
|
411 | - if ($backend->implementsActions(GroupInterface::ADD_TO_GROUP)) { |
|
412 | - return true; |
|
413 | - } |
|
414 | - } |
|
415 | - return false; |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * @return bool |
|
420 | - * @since 16.0.0 |
|
421 | - */ |
|
422 | - public function hideFromCollaboration(): bool { |
|
423 | - return array_reduce($this->backends, function (bool $hide, GroupInterface $backend) { |
|
424 | - return $hide | ($backend instanceof IHideFromCollaborationBackend && $backend->hideGroup($this->gid)); |
|
425 | - }, false); |
|
426 | - } |
|
51 | + /** @var null|string */ |
|
52 | + protected $displayName; |
|
53 | + |
|
54 | + /** @var string */ |
|
55 | + private $gid; |
|
56 | + |
|
57 | + /** @var \OC\User\User[] */ |
|
58 | + private $users = []; |
|
59 | + |
|
60 | + /** @var bool */ |
|
61 | + private $usersLoaded; |
|
62 | + |
|
63 | + /** @var Backend[] */ |
|
64 | + private $backends; |
|
65 | + /** @var EventDispatcherInterface */ |
|
66 | + private $dispatcher; |
|
67 | + /** @var \OC\User\Manager|IUserManager */ |
|
68 | + private $userManager; |
|
69 | + /** @var PublicEmitter */ |
|
70 | + private $emitter; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param string $gid |
|
75 | + * @param Backend[] $backends |
|
76 | + * @param EventDispatcherInterface $dispatcher |
|
77 | + * @param IUserManager $userManager |
|
78 | + * @param PublicEmitter $emitter |
|
79 | + * @param string $displayName |
|
80 | + */ |
|
81 | + public function __construct(string $gid, array $backends, EventDispatcherInterface $dispatcher, IUserManager $userManager, PublicEmitter $emitter = null, ?string $displayName = null) { |
|
82 | + $this->gid = $gid; |
|
83 | + $this->backends = $backends; |
|
84 | + $this->dispatcher = $dispatcher; |
|
85 | + $this->userManager = $userManager; |
|
86 | + $this->emitter = $emitter; |
|
87 | + $this->displayName = $displayName; |
|
88 | + } |
|
89 | + |
|
90 | + public function getGID() { |
|
91 | + return $this->gid; |
|
92 | + } |
|
93 | + |
|
94 | + public function getDisplayName() { |
|
95 | + if (is_null($this->displayName)) { |
|
96 | + foreach ($this->backends as $backend) { |
|
97 | + if ($backend instanceof IGetDisplayNameBackend) { |
|
98 | + $displayName = $backend->getDisplayName($this->gid); |
|
99 | + if (trim($displayName) !== '') { |
|
100 | + $this->displayName = $displayName; |
|
101 | + return $this->displayName; |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + return $this->gid; |
|
106 | + } |
|
107 | + return $this->displayName; |
|
108 | + } |
|
109 | + |
|
110 | + public function setDisplayName(string $displayName): bool { |
|
111 | + $displayName = trim($displayName); |
|
112 | + if ($displayName !== '') { |
|
113 | + $this->dispatcher->dispatch(new BeforeGroupChangedEvent($this, 'displayName', $displayName, $this->displayName)); |
|
114 | + foreach ($this->backends as $backend) { |
|
115 | + if (($backend instanceof ISetDisplayNameBackend) |
|
116 | + && $backend->setDisplayName($this->gid, $displayName)) { |
|
117 | + $this->displayName = $displayName; |
|
118 | + $this->dispatcher->dispatch(new GroupChangedEvent($this, 'displayName', $displayName, '')); |
|
119 | + return true; |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + return false; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * get all users in the group |
|
128 | + * |
|
129 | + * @return \OC\User\User[] |
|
130 | + */ |
|
131 | + public function getUsers() { |
|
132 | + if ($this->usersLoaded) { |
|
133 | + return $this->users; |
|
134 | + } |
|
135 | + |
|
136 | + $userIds = []; |
|
137 | + foreach ($this->backends as $backend) { |
|
138 | + $diff = array_diff( |
|
139 | + $backend->usersInGroup($this->gid), |
|
140 | + $userIds |
|
141 | + ); |
|
142 | + if ($diff) { |
|
143 | + $userIds = array_merge($userIds, $diff); |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + $this->users = $this->getVerifiedUsers($userIds); |
|
148 | + $this->usersLoaded = true; |
|
149 | + return $this->users; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * check if a user is in the group |
|
154 | + * |
|
155 | + * @param IUser $user |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | + public function inGroup(IUser $user) { |
|
159 | + if (isset($this->users[$user->getUID()])) { |
|
160 | + return true; |
|
161 | + } |
|
162 | + foreach ($this->backends as $backend) { |
|
163 | + if ($backend->inGroup($user->getUID(), $this->gid)) { |
|
164 | + $this->users[$user->getUID()] = $user; |
|
165 | + return true; |
|
166 | + } |
|
167 | + } |
|
168 | + return false; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * add a user to the group |
|
173 | + * |
|
174 | + * @param IUser $user |
|
175 | + */ |
|
176 | + public function addUser(IUser $user) { |
|
177 | + if ($this->inGroup($user)) { |
|
178 | + return; |
|
179 | + } |
|
180 | + |
|
181 | + $this->dispatcher->dispatch(IGroup::class . '::preAddUser', new GenericEvent($this, [ |
|
182 | + 'user' => $user, |
|
183 | + ])); |
|
184 | + |
|
185 | + if ($this->emitter) { |
|
186 | + $this->emitter->emit('\OC\Group', 'preAddUser', [$this, $user]); |
|
187 | + } |
|
188 | + foreach ($this->backends as $backend) { |
|
189 | + if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) { |
|
190 | + $backend->addToGroup($user->getUID(), $this->gid); |
|
191 | + if ($this->users) { |
|
192 | + $this->users[$user->getUID()] = $user; |
|
193 | + } |
|
194 | + |
|
195 | + $this->dispatcher->dispatch(IGroup::class . '::postAddUser', new GenericEvent($this, [ |
|
196 | + 'user' => $user, |
|
197 | + ])); |
|
198 | + |
|
199 | + if ($this->emitter) { |
|
200 | + $this->emitter->emit('\OC\Group', 'postAddUser', [$this, $user]); |
|
201 | + } |
|
202 | + return; |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * remove a user from the group |
|
209 | + * |
|
210 | + * @param \OC\User\User $user |
|
211 | + */ |
|
212 | + public function removeUser($user) { |
|
213 | + $result = false; |
|
214 | + $this->dispatcher->dispatch(IGroup::class . '::preRemoveUser', new GenericEvent($this, [ |
|
215 | + 'user' => $user, |
|
216 | + ])); |
|
217 | + if ($this->emitter) { |
|
218 | + $this->emitter->emit('\OC\Group', 'preRemoveUser', [$this, $user]); |
|
219 | + } |
|
220 | + foreach ($this->backends as $backend) { |
|
221 | + if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { |
|
222 | + $backend->removeFromGroup($user->getUID(), $this->gid); |
|
223 | + $result = true; |
|
224 | + } |
|
225 | + } |
|
226 | + if ($result) { |
|
227 | + $this->dispatcher->dispatch(IGroup::class . '::postRemoveUser', new GenericEvent($this, [ |
|
228 | + 'user' => $user, |
|
229 | + ])); |
|
230 | + if ($this->emitter) { |
|
231 | + $this->emitter->emit('\OC\Group', 'postRemoveUser', [$this, $user]); |
|
232 | + } |
|
233 | + if ($this->users) { |
|
234 | + foreach ($this->users as $index => $groupUser) { |
|
235 | + if ($groupUser->getUID() === $user->getUID()) { |
|
236 | + unset($this->users[$index]); |
|
237 | + return; |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * search for users in the group by userid |
|
246 | + * |
|
247 | + * @param string $search |
|
248 | + * @param int $limit |
|
249 | + * @param int $offset |
|
250 | + * @return \OC\User\User[] |
|
251 | + */ |
|
252 | + public function searchUsers($search, $limit = null, $offset = null) { |
|
253 | + $users = []; |
|
254 | + foreach ($this->backends as $backend) { |
|
255 | + $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
256 | + $users += $this->getVerifiedUsers($userIds); |
|
257 | + if (!is_null($limit) and $limit <= 0) { |
|
258 | + return $users; |
|
259 | + } |
|
260 | + } |
|
261 | + return $users; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * returns the number of users matching the search string |
|
266 | + * |
|
267 | + * @param string $search |
|
268 | + * @return int|bool |
|
269 | + */ |
|
270 | + public function count($search = '') { |
|
271 | + $users = false; |
|
272 | + foreach ($this->backends as $backend) { |
|
273 | + if ($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) { |
|
274 | + if ($users === false) { |
|
275 | + //we could directly add to a bool variable, but this would |
|
276 | + //be ugly |
|
277 | + $users = 0; |
|
278 | + } |
|
279 | + $users += $backend->countUsersInGroup($this->gid, $search); |
|
280 | + } |
|
281 | + } |
|
282 | + return $users; |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * returns the number of disabled users |
|
287 | + * |
|
288 | + * @return int|bool |
|
289 | + */ |
|
290 | + public function countDisabled() { |
|
291 | + $users = false; |
|
292 | + foreach ($this->backends as $backend) { |
|
293 | + if ($backend instanceof ICountDisabledInGroup) { |
|
294 | + if ($users === false) { |
|
295 | + //we could directly add to a bool variable, but this would |
|
296 | + //be ugly |
|
297 | + $users = 0; |
|
298 | + } |
|
299 | + $users += $backend->countDisabledInGroup($this->gid); |
|
300 | + } |
|
301 | + } |
|
302 | + return $users; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * search for users in the group by displayname |
|
307 | + * |
|
308 | + * @param string $search |
|
309 | + * @param int $limit |
|
310 | + * @param int $offset |
|
311 | + * @return \OC\User\User[] |
|
312 | + */ |
|
313 | + public function searchDisplayName($search, $limit = null, $offset = null) { |
|
314 | + $users = []; |
|
315 | + foreach ($this->backends as $backend) { |
|
316 | + $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
317 | + $users = $this->getVerifiedUsers($userIds); |
|
318 | + if (!is_null($limit) and $limit <= 0) { |
|
319 | + return array_values($users); |
|
320 | + } |
|
321 | + } |
|
322 | + return array_values($users); |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Get the names of the backend classes the group is connected to |
|
327 | + * |
|
328 | + * @return string[] |
|
329 | + */ |
|
330 | + public function getBackendNames() { |
|
331 | + $backends = []; |
|
332 | + foreach ($this->backends as $backend) { |
|
333 | + if ($backend instanceof INamedBackend) { |
|
334 | + $backends[] = $backend->getBackendName(); |
|
335 | + } else { |
|
336 | + $backends[] = get_class($backend); |
|
337 | + } |
|
338 | + } |
|
339 | + |
|
340 | + return $backends; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * delete the group |
|
345 | + * |
|
346 | + * @return bool |
|
347 | + */ |
|
348 | + public function delete() { |
|
349 | + // Prevent users from deleting group admin |
|
350 | + if ($this->getGID() === 'admin') { |
|
351 | + return false; |
|
352 | + } |
|
353 | + |
|
354 | + $result = false; |
|
355 | + $this->dispatcher->dispatch(IGroup::class . '::preDelete', new GenericEvent($this)); |
|
356 | + if ($this->emitter) { |
|
357 | + $this->emitter->emit('\OC\Group', 'preDelete', [$this]); |
|
358 | + } |
|
359 | + foreach ($this->backends as $backend) { |
|
360 | + if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) { |
|
361 | + $result = $result || $backend->deleteGroup($this->gid); |
|
362 | + } |
|
363 | + } |
|
364 | + if ($result) { |
|
365 | + $this->dispatcher->dispatch(IGroup::class . '::postDelete', new GenericEvent($this)); |
|
366 | + if ($this->emitter) { |
|
367 | + $this->emitter->emit('\OC\Group', 'postDelete', [$this]); |
|
368 | + } |
|
369 | + } |
|
370 | + return $result; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * returns all the Users from an array that really exists |
|
375 | + * @param string[] $userIds an array containing user IDs |
|
376 | + * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value |
|
377 | + */ |
|
378 | + private function getVerifiedUsers($userIds) { |
|
379 | + if (!is_array($userIds)) { |
|
380 | + return []; |
|
381 | + } |
|
382 | + $users = []; |
|
383 | + foreach ($userIds as $userId) { |
|
384 | + $user = $this->userManager->get($userId); |
|
385 | + if (!is_null($user)) { |
|
386 | + $users[$userId] = $user; |
|
387 | + } |
|
388 | + } |
|
389 | + return $users; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * @return bool |
|
394 | + * @since 14.0.0 |
|
395 | + */ |
|
396 | + public function canRemoveUser() { |
|
397 | + foreach ($this->backends as $backend) { |
|
398 | + if ($backend->implementsActions(GroupInterface::REMOVE_FROM_GOUP)) { |
|
399 | + return true; |
|
400 | + } |
|
401 | + } |
|
402 | + return false; |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * @return bool |
|
407 | + * @since 14.0.0 |
|
408 | + */ |
|
409 | + public function canAddUser() { |
|
410 | + foreach ($this->backends as $backend) { |
|
411 | + if ($backend->implementsActions(GroupInterface::ADD_TO_GROUP)) { |
|
412 | + return true; |
|
413 | + } |
|
414 | + } |
|
415 | + return false; |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * @return bool |
|
420 | + * @since 16.0.0 |
|
421 | + */ |
|
422 | + public function hideFromCollaboration(): bool { |
|
423 | + return array_reduce($this->backends, function (bool $hide, GroupInterface $backend) { |
|
424 | + return $hide | ($backend instanceof IHideFromCollaborationBackend && $backend->hideGroup($this->gid)); |
|
425 | + }, false); |
|
426 | + } |
|
427 | 427 | } |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
41 | 41 | \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
42 | 42 | ])) { |
43 | - header('Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode($filename) . '"'); |
|
43 | + header('Content-Disposition: '.rawurlencode($type).'; filename="'.rawurlencode($filename).'"'); |
|
44 | 44 | } else { |
45 | - header('Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
46 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
45 | + header('Content-Disposition: '.rawurlencode($type).'; filename*=UTF-8\'\''.rawurlencode($filename) |
|
46 | + . '; filename="'.rawurlencode($filename).'"'); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | . 'connect-src *; ' |
91 | 91 | . 'object-src \'none\'; ' |
92 | 92 | . 'base-uri \'self\'; '; |
93 | - header('Content-Security-Policy:' . $policy); |
|
93 | + header('Content-Security-Policy:'.$policy); |
|
94 | 94 | |
95 | 95 | // Send fallback headers for installations that don't have the possibility to send |
96 | 96 | // custom headers on the webserver side |
@@ -28,79 +28,79 @@ |
||
28 | 28 | * |
29 | 29 | */ |
30 | 30 | class OC_Response { |
31 | - /** |
|
32 | - * Sets the content disposition header (with possible workarounds) |
|
33 | - * @param string $filename file name |
|
34 | - * @param string $type disposition type, either 'attachment' or 'inline' |
|
35 | - */ |
|
36 | - public static function setContentDispositionHeader($filename, $type = 'attachment') { |
|
37 | - if (\OC::$server->getRequest()->isUserAgent( |
|
38 | - [ |
|
39 | - \OC\AppFramework\Http\Request::USER_AGENT_IE, |
|
40 | - \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
41 | - \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
|
42 | - ])) { |
|
43 | - header('Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode($filename) . '"'); |
|
44 | - } else { |
|
45 | - header('Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
46 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
47 | - } |
|
48 | - } |
|
31 | + /** |
|
32 | + * Sets the content disposition header (with possible workarounds) |
|
33 | + * @param string $filename file name |
|
34 | + * @param string $type disposition type, either 'attachment' or 'inline' |
|
35 | + */ |
|
36 | + public static function setContentDispositionHeader($filename, $type = 'attachment') { |
|
37 | + if (\OC::$server->getRequest()->isUserAgent( |
|
38 | + [ |
|
39 | + \OC\AppFramework\Http\Request::USER_AGENT_IE, |
|
40 | + \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
41 | + \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
|
42 | + ])) { |
|
43 | + header('Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode($filename) . '"'); |
|
44 | + } else { |
|
45 | + header('Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
46 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Sets the content length header (with possible workarounds) |
|
52 | - * @param string|int|float $length Length to be sent |
|
53 | - */ |
|
54 | - public static function setContentLengthHeader($length) { |
|
55 | - if (PHP_INT_SIZE === 4) { |
|
56 | - if ($length > PHP_INT_MAX && stripos(PHP_SAPI, 'apache') === 0) { |
|
57 | - // Apache PHP SAPI casts Content-Length headers to PHP integers. |
|
58 | - // This enforces a limit of PHP_INT_MAX (2147483647 on 32-bit |
|
59 | - // platforms). So, if the length is greater than PHP_INT_MAX, |
|
60 | - // we just do not send a Content-Length header to prevent |
|
61 | - // bodies from being received incompletely. |
|
62 | - return; |
|
63 | - } |
|
64 | - // Convert signed integer or float to unsigned base-10 string. |
|
65 | - $lfh = new \OC\LargeFileHelper; |
|
66 | - $length = $lfh->formatUnsignedInteger($length); |
|
67 | - } |
|
68 | - header('Content-Length: '.$length); |
|
69 | - } |
|
50 | + /** |
|
51 | + * Sets the content length header (with possible workarounds) |
|
52 | + * @param string|int|float $length Length to be sent |
|
53 | + */ |
|
54 | + public static function setContentLengthHeader($length) { |
|
55 | + if (PHP_INT_SIZE === 4) { |
|
56 | + if ($length > PHP_INT_MAX && stripos(PHP_SAPI, 'apache') === 0) { |
|
57 | + // Apache PHP SAPI casts Content-Length headers to PHP integers. |
|
58 | + // This enforces a limit of PHP_INT_MAX (2147483647 on 32-bit |
|
59 | + // platforms). So, if the length is greater than PHP_INT_MAX, |
|
60 | + // we just do not send a Content-Length header to prevent |
|
61 | + // bodies from being received incompletely. |
|
62 | + return; |
|
63 | + } |
|
64 | + // Convert signed integer or float to unsigned base-10 string. |
|
65 | + $lfh = new \OC\LargeFileHelper; |
|
66 | + $length = $lfh->formatUnsignedInteger($length); |
|
67 | + } |
|
68 | + header('Content-Length: '.$length); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * This function adds some security related headers to all requests served via base.php |
|
73 | - * The implementation of this function has to happen here to ensure that all third-party |
|
74 | - * components (e.g. SabreDAV) also benefit from this headers. |
|
75 | - */ |
|
76 | - public static function addSecurityHeaders() { |
|
77 | - /** |
|
78 | - * FIXME: Content Security Policy for legacy ownCloud components. This |
|
79 | - * can be removed once \OCP\AppFramework\Http\Response from the AppFramework |
|
80 | - * is used everywhere. |
|
81 | - * @see \OCP\AppFramework\Http\Response::getHeaders |
|
82 | - */ |
|
83 | - $policy = 'default-src \'self\'; ' |
|
84 | - . 'script-src \'self\' \'nonce-'.\OC::$server->getContentSecurityPolicyNonceManager()->getNonce().'\'; ' |
|
85 | - . 'style-src \'self\' \'unsafe-inline\'; ' |
|
86 | - . 'frame-src *; ' |
|
87 | - . 'img-src * data: blob:; ' |
|
88 | - . 'font-src \'self\' data:; ' |
|
89 | - . 'media-src *; ' |
|
90 | - . 'connect-src *; ' |
|
91 | - . 'object-src \'none\'; ' |
|
92 | - . 'base-uri \'self\'; '; |
|
93 | - header('Content-Security-Policy:' . $policy); |
|
71 | + /** |
|
72 | + * This function adds some security related headers to all requests served via base.php |
|
73 | + * The implementation of this function has to happen here to ensure that all third-party |
|
74 | + * components (e.g. SabreDAV) also benefit from this headers. |
|
75 | + */ |
|
76 | + public static function addSecurityHeaders() { |
|
77 | + /** |
|
78 | + * FIXME: Content Security Policy for legacy ownCloud components. This |
|
79 | + * can be removed once \OCP\AppFramework\Http\Response from the AppFramework |
|
80 | + * is used everywhere. |
|
81 | + * @see \OCP\AppFramework\Http\Response::getHeaders |
|
82 | + */ |
|
83 | + $policy = 'default-src \'self\'; ' |
|
84 | + . 'script-src \'self\' \'nonce-'.\OC::$server->getContentSecurityPolicyNonceManager()->getNonce().'\'; ' |
|
85 | + . 'style-src \'self\' \'unsafe-inline\'; ' |
|
86 | + . 'frame-src *; ' |
|
87 | + . 'img-src * data: blob:; ' |
|
88 | + . 'font-src \'self\' data:; ' |
|
89 | + . 'media-src *; ' |
|
90 | + . 'connect-src *; ' |
|
91 | + . 'object-src \'none\'; ' |
|
92 | + . 'base-uri \'self\'; '; |
|
93 | + header('Content-Security-Policy:' . $policy); |
|
94 | 94 | |
95 | - // Send fallback headers for installations that don't have the possibility to send |
|
96 | - // custom headers on the webserver side |
|
97 | - if (getenv('modHeadersAvailable') !== 'true') { |
|
98 | - header('Referrer-Policy: no-referrer'); // https://www.w3.org/TR/referrer-policy/ |
|
99 | - header('X-Content-Type-Options: nosniff'); // Disable sniffing the content type for IE |
|
100 | - header('X-Frame-Options: SAMEORIGIN'); // Disallow iFraming from other domains |
|
101 | - header('X-Permitted-Cross-Domain-Policies: none'); // https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html |
|
102 | - header('X-Robots-Tag: noindex, nofollow'); // https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag |
|
103 | - header('X-XSS-Protection: 1; mode=block'); // Enforce browser based XSS filters |
|
104 | - } |
|
105 | - } |
|
95 | + // Send fallback headers for installations that don't have the possibility to send |
|
96 | + // custom headers on the webserver side |
|
97 | + if (getenv('modHeadersAvailable') !== 'true') { |
|
98 | + header('Referrer-Policy: no-referrer'); // https://www.w3.org/TR/referrer-policy/ |
|
99 | + header('X-Content-Type-Options: nosniff'); // Disable sniffing the content type for IE |
|
100 | + header('X-Frame-Options: SAMEORIGIN'); // Disallow iFraming from other domains |
|
101 | + header('X-Permitted-Cross-Domain-Policies: none'); // https://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html |
|
102 | + header('X-Robots-Tag: noindex, nofollow'); // https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag |
|
103 | + header('X-XSS-Protection: 1; mode=block'); // Enforce browser based XSS filters |
|
104 | + } |
|
105 | + } |
|
106 | 106 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | header('X-Accel-Buffering: no'); |
61 | 61 | $this->fallback = isset($_GET['fallback']) and $_GET['fallback'] == 'true'; |
62 | 62 | if ($this->fallback) { |
63 | - $this->fallBackId = (int)$_GET['fallback_id']; |
|
63 | + $this->fallBackId = (int) $_GET['fallback_id']; |
|
64 | 64 | /** |
65 | 65 | * FIXME: The default content-security-policy of ownCloud forbids inline |
66 | 66 | * JavaScript for security reasons. IE starting on Windows 10 will |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | */ |
74 | 74 | header("Content-Security-Policy: default-src 'none'; script-src 'unsafe-inline'"); |
75 | 75 | header("Content-Type: text/html"); |
76 | - echo str_repeat('<span></span>' . PHP_EOL, 10); //dummy data to keep IE happy |
|
76 | + echo str_repeat('<span></span>'.PHP_EOL, 10); //dummy data to keep IE happy |
|
77 | 77 | } else { |
78 | 78 | header("Content-Type: text/event-stream"); |
79 | 79 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function send($type, $data = null) { |
103 | 103 | if ($data and !preg_match('/^[A-Za-z0-9_]+$/', $type)) { |
104 | - throw new BadMethodCallException('Type needs to be alphanumeric ('. $type .')'); |
|
104 | + throw new BadMethodCallException('Type needs to be alphanumeric ('.$type.')'); |
|
105 | 105 | } |
106 | 106 | $this->init(); |
107 | 107 | if (is_null($data)) { |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | } |
111 | 111 | if ($this->fallback) { |
112 | 112 | $response = '<script type="text/javascript">window.parent.OC.EventSource.fallBackCallBack(' |
113 | - . $this->fallBackId . ',"' . $type . '",' . OC_JSON::encode($data) . ')</script>' . PHP_EOL; |
|
113 | + . $this->fallBackId.',"'.$type.'",'.OC_JSON::encode($data).')</script>'.PHP_EOL; |
|
114 | 114 | echo $response; |
115 | 115 | } else { |
116 | 116 | if ($type) { |
117 | - echo 'event: ' . $type . PHP_EOL; |
|
117 | + echo 'event: '.$type.PHP_EOL; |
|
118 | 118 | } |
119 | - echo 'data: ' . OC_JSON::encode($data) . PHP_EOL; |
|
119 | + echo 'data: '.OC_JSON::encode($data).PHP_EOL; |
|
120 | 120 | } |
121 | 121 | echo PHP_EOL; |
122 | 122 | flush(); |
@@ -27,99 +27,99 @@ |
||
27 | 27 | * |
28 | 28 | */ |
29 | 29 | class OC_EventSource implements \OCP\IEventSource { |
30 | - /** |
|
31 | - * @var bool |
|
32 | - */ |
|
33 | - private $fallback; |
|
30 | + /** |
|
31 | + * @var bool |
|
32 | + */ |
|
33 | + private $fallback; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - private $fallBackId = 0; |
|
35 | + /** |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + private $fallBackId = 0; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var bool |
|
42 | - */ |
|
43 | - private $started = false; |
|
40 | + /** |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | + private $started = false; |
|
44 | 44 | |
45 | - protected function init() { |
|
46 | - if ($this->started) { |
|
47 | - return; |
|
48 | - } |
|
49 | - $this->started = true; |
|
45 | + protected function init() { |
|
46 | + if ($this->started) { |
|
47 | + return; |
|
48 | + } |
|
49 | + $this->started = true; |
|
50 | 50 | |
51 | - // prevent php output buffering, caching and nginx buffering |
|
52 | - OC_Util::obEnd(); |
|
53 | - header('Cache-Control: no-cache'); |
|
54 | - header('X-Accel-Buffering: no'); |
|
55 | - $this->fallback = isset($_GET['fallback']) and $_GET['fallback'] == 'true'; |
|
56 | - if ($this->fallback) { |
|
57 | - $this->fallBackId = (int)$_GET['fallback_id']; |
|
58 | - /** |
|
59 | - * FIXME: The default content-security-policy of ownCloud forbids inline |
|
60 | - * JavaScript for security reasons. IE starting on Windows 10 will |
|
61 | - * however also obey the CSP which will break the event source fallback. |
|
62 | - * |
|
63 | - * As a workaround thus we set a custom policy which allows the execution |
|
64 | - * of inline JavaScript. |
|
65 | - * |
|
66 | - * @link https://github.com/owncloud/core/issues/14286 |
|
67 | - */ |
|
68 | - header("Content-Security-Policy: default-src 'none'; script-src 'unsafe-inline'"); |
|
69 | - header("Content-Type: text/html"); |
|
70 | - echo str_repeat('<span></span>' . PHP_EOL, 10); //dummy data to keep IE happy |
|
71 | - } else { |
|
72 | - header("Content-Type: text/event-stream"); |
|
73 | - } |
|
74 | - if (!\OC::$server->getRequest()->passesStrictCookieCheck()) { |
|
75 | - header('Location: '.\OC::$WEBROOT); |
|
76 | - exit(); |
|
77 | - } |
|
78 | - if (!\OC::$server->getRequest()->passesCSRFCheck()) { |
|
79 | - $this->send('error', 'Possible CSRF attack. Connection will be closed.'); |
|
80 | - $this->close(); |
|
81 | - exit(); |
|
82 | - } |
|
83 | - flush(); |
|
84 | - } |
|
51 | + // prevent php output buffering, caching and nginx buffering |
|
52 | + OC_Util::obEnd(); |
|
53 | + header('Cache-Control: no-cache'); |
|
54 | + header('X-Accel-Buffering: no'); |
|
55 | + $this->fallback = isset($_GET['fallback']) and $_GET['fallback'] == 'true'; |
|
56 | + if ($this->fallback) { |
|
57 | + $this->fallBackId = (int)$_GET['fallback_id']; |
|
58 | + /** |
|
59 | + * FIXME: The default content-security-policy of ownCloud forbids inline |
|
60 | + * JavaScript for security reasons. IE starting on Windows 10 will |
|
61 | + * however also obey the CSP which will break the event source fallback. |
|
62 | + * |
|
63 | + * As a workaround thus we set a custom policy which allows the execution |
|
64 | + * of inline JavaScript. |
|
65 | + * |
|
66 | + * @link https://github.com/owncloud/core/issues/14286 |
|
67 | + */ |
|
68 | + header("Content-Security-Policy: default-src 'none'; script-src 'unsafe-inline'"); |
|
69 | + header("Content-Type: text/html"); |
|
70 | + echo str_repeat('<span></span>' . PHP_EOL, 10); //dummy data to keep IE happy |
|
71 | + } else { |
|
72 | + header("Content-Type: text/event-stream"); |
|
73 | + } |
|
74 | + if (!\OC::$server->getRequest()->passesStrictCookieCheck()) { |
|
75 | + header('Location: '.\OC::$WEBROOT); |
|
76 | + exit(); |
|
77 | + } |
|
78 | + if (!\OC::$server->getRequest()->passesCSRFCheck()) { |
|
79 | + $this->send('error', 'Possible CSRF attack. Connection will be closed.'); |
|
80 | + $this->close(); |
|
81 | + exit(); |
|
82 | + } |
|
83 | + flush(); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * send a message to the client |
|
88 | - * |
|
89 | - * @param string $type |
|
90 | - * @param mixed $data |
|
91 | - * |
|
92 | - * @throws \BadMethodCallException |
|
93 | - * if only one parameter is given, a typeless message will be send with that parameter as data |
|
94 | - * @suppress PhanDeprecatedFunction |
|
95 | - */ |
|
96 | - public function send($type, $data = null) { |
|
97 | - if ($data and !preg_match('/^[A-Za-z0-9_]+$/', $type)) { |
|
98 | - throw new BadMethodCallException('Type needs to be alphanumeric ('. $type .')'); |
|
99 | - } |
|
100 | - $this->init(); |
|
101 | - if (is_null($data)) { |
|
102 | - $data = $type; |
|
103 | - $type = null; |
|
104 | - } |
|
105 | - if ($this->fallback) { |
|
106 | - $response = '<script type="text/javascript">window.parent.OC.EventSource.fallBackCallBack(' |
|
107 | - . $this->fallBackId . ',"' . $type . '",' . OC_JSON::encode($data) . ')</script>' . PHP_EOL; |
|
108 | - echo $response; |
|
109 | - } else { |
|
110 | - if ($type) { |
|
111 | - echo 'event: ' . $type . PHP_EOL; |
|
112 | - } |
|
113 | - echo 'data: ' . OC_JSON::encode($data) . PHP_EOL; |
|
114 | - } |
|
115 | - echo PHP_EOL; |
|
116 | - flush(); |
|
117 | - } |
|
86 | + /** |
|
87 | + * send a message to the client |
|
88 | + * |
|
89 | + * @param string $type |
|
90 | + * @param mixed $data |
|
91 | + * |
|
92 | + * @throws \BadMethodCallException |
|
93 | + * if only one parameter is given, a typeless message will be send with that parameter as data |
|
94 | + * @suppress PhanDeprecatedFunction |
|
95 | + */ |
|
96 | + public function send($type, $data = null) { |
|
97 | + if ($data and !preg_match('/^[A-Za-z0-9_]+$/', $type)) { |
|
98 | + throw new BadMethodCallException('Type needs to be alphanumeric ('. $type .')'); |
|
99 | + } |
|
100 | + $this->init(); |
|
101 | + if (is_null($data)) { |
|
102 | + $data = $type; |
|
103 | + $type = null; |
|
104 | + } |
|
105 | + if ($this->fallback) { |
|
106 | + $response = '<script type="text/javascript">window.parent.OC.EventSource.fallBackCallBack(' |
|
107 | + . $this->fallBackId . ',"' . $type . '",' . OC_JSON::encode($data) . ')</script>' . PHP_EOL; |
|
108 | + echo $response; |
|
109 | + } else { |
|
110 | + if ($type) { |
|
111 | + echo 'event: ' . $type . PHP_EOL; |
|
112 | + } |
|
113 | + echo 'data: ' . OC_JSON::encode($data) . PHP_EOL; |
|
114 | + } |
|
115 | + echo PHP_EOL; |
|
116 | + flush(); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * close the connection of the event source |
|
121 | - */ |
|
122 | - public function close() { |
|
123 | - $this->send('__internal__', 'close'); //server side closing can be an issue, let the client do it |
|
124 | - } |
|
119 | + /** |
|
120 | + * close the connection of the event source |
|
121 | + */ |
|
122 | + public function close() { |
|
123 | + $this->send('__internal__', 'close'); //server side closing can be an issue, let the client do it |
|
124 | + } |
|
125 | 125 | } |