@@ -29,19 +29,19 @@ |
||
29 | 29 | |
30 | 30 | class AddLogRotateJob implements IRepairStep { |
31 | 31 | |
32 | - /** @var IJobList */ |
|
33 | - private $jobList; |
|
32 | + /** @var IJobList */ |
|
33 | + private $jobList; |
|
34 | 34 | |
35 | - public function __construct(IJobList $jobList) { |
|
36 | - $this->jobList = $jobList; |
|
37 | - } |
|
35 | + public function __construct(IJobList $jobList) { |
|
36 | + $this->jobList = $jobList; |
|
37 | + } |
|
38 | 38 | |
39 | - public function getName() { |
|
40 | - return 'Add log rotate job'; |
|
41 | - } |
|
39 | + public function getName() { |
|
40 | + return 'Add log rotate job'; |
|
41 | + } |
|
42 | 42 | |
43 | - public function run(IOutput $output) { |
|
44 | - $this->jobList->add(Rotate::class); |
|
45 | - } |
|
43 | + public function run(IOutput $output) { |
|
44 | + $this->jobList->add(Rotate::class); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -31,22 +31,22 @@ |
||
31 | 31 | |
32 | 32 | class Hooks { |
33 | 33 | |
34 | - /** |
|
35 | - * clean up user specific settings if user gets deleted |
|
36 | - * @param array $params array with uid |
|
37 | - * |
|
38 | - * This function is connected to the pre_deleteUser signal of OC_Users |
|
39 | - * to remove the used space for the trash bin stored in the database |
|
40 | - */ |
|
41 | - public static function deleteUser_hook($params) { |
|
42 | - $uid = $params['uid']; |
|
43 | - Trashbin::deleteUser($uid); |
|
44 | - } |
|
34 | + /** |
|
35 | + * clean up user specific settings if user gets deleted |
|
36 | + * @param array $params array with uid |
|
37 | + * |
|
38 | + * This function is connected to the pre_deleteUser signal of OC_Users |
|
39 | + * to remove the used space for the trash bin stored in the database |
|
40 | + */ |
|
41 | + public static function deleteUser_hook($params) { |
|
42 | + $uid = $params['uid']; |
|
43 | + Trashbin::deleteUser($uid); |
|
44 | + } |
|
45 | 45 | |
46 | - public static function post_write_hook($params) { |
|
47 | - $user = \OCP\User::getUser(); |
|
48 | - if (!empty($user)) { |
|
49 | - Trashbin::resizeTrash($user); |
|
50 | - } |
|
51 | - } |
|
46 | + public static function post_write_hook($params) { |
|
47 | + $user = \OCP\User::getUser(); |
|
48 | + if (!empty($user)) { |
|
49 | + Trashbin::resizeTrash($user); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | } |
@@ -29,60 +29,60 @@ |
||
29 | 29 | |
30 | 30 | class SearchResult implements ISearchResult { |
31 | 31 | |
32 | - protected $result = [ |
|
33 | - 'exact' => [], |
|
34 | - ]; |
|
32 | + protected $result = [ |
|
33 | + 'exact' => [], |
|
34 | + ]; |
|
35 | 35 | |
36 | - protected $exactIdMatches = []; |
|
36 | + protected $exactIdMatches = []; |
|
37 | 37 | |
38 | - public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
|
39 | - $type = $type->getLabel(); |
|
40 | - if(!isset($this->result[$type])) { |
|
41 | - $this->result[$type] = []; |
|
42 | - $this->result['exact'][$type] = []; |
|
43 | - } |
|
38 | + public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null) { |
|
39 | + $type = $type->getLabel(); |
|
40 | + if(!isset($this->result[$type])) { |
|
41 | + $this->result[$type] = []; |
|
42 | + $this->result['exact'][$type] = []; |
|
43 | + } |
|
44 | 44 | |
45 | - $this->result[$type] = array_merge($this->result[$type], $matches); |
|
46 | - if(is_array($exactMatches)) { |
|
47 | - $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
|
48 | - } |
|
49 | - } |
|
45 | + $this->result[$type] = array_merge($this->result[$type], $matches); |
|
46 | + if(is_array($exactMatches)) { |
|
47 | + $this->result['exact'][$type] = array_merge($this->result['exact'][$type], $exactMatches); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - public function markExactIdMatch(SearchResultType $type) { |
|
52 | - $this->exactIdMatches[$type->getLabel()] = 1; |
|
53 | - } |
|
51 | + public function markExactIdMatch(SearchResultType $type) { |
|
52 | + $this->exactIdMatches[$type->getLabel()] = 1; |
|
53 | + } |
|
54 | 54 | |
55 | - public function hasExactIdMatch(SearchResultType $type) { |
|
56 | - return isset($this->exactIdMatches[$type->getLabel()]); |
|
57 | - } |
|
55 | + public function hasExactIdMatch(SearchResultType $type) { |
|
56 | + return isset($this->exactIdMatches[$type->getLabel()]); |
|
57 | + } |
|
58 | 58 | |
59 | - public function hasResult(SearchResultType $type, $collaboratorId) { |
|
60 | - $type = $type->getLabel(); |
|
61 | - if(!isset($this->result[$type])) { |
|
62 | - return false; |
|
63 | - } |
|
59 | + public function hasResult(SearchResultType $type, $collaboratorId) { |
|
60 | + $type = $type->getLabel(); |
|
61 | + if(!isset($this->result[$type])) { |
|
62 | + return false; |
|
63 | + } |
|
64 | 64 | |
65 | - $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
|
66 | - foreach($resultArrays as $resultArray) { |
|
67 | - foreach ($resultArray as $result) { |
|
68 | - if ($result['value']['shareWith'] === $collaboratorId) { |
|
69 | - return true; |
|
70 | - } |
|
71 | - } |
|
72 | - } |
|
65 | + $resultArrays = [$this->result['exact'][$type], $this->result[$type]]; |
|
66 | + foreach($resultArrays as $resultArray) { |
|
67 | + foreach ($resultArray as $result) { |
|
68 | + if ($result['value']['shareWith'] === $collaboratorId) { |
|
69 | + return true; |
|
70 | + } |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - return false; |
|
75 | - } |
|
74 | + return false; |
|
75 | + } |
|
76 | 76 | |
77 | - public function asArray() { |
|
78 | - return $this->result; |
|
79 | - } |
|
77 | + public function asArray() { |
|
78 | + return $this->result; |
|
79 | + } |
|
80 | 80 | |
81 | - public function unsetResult(SearchResultType $type) { |
|
82 | - $type = $type->getLabel(); |
|
83 | - $this->result[$type] = []; |
|
84 | - if(isset($this->result['exact'][$type])) { |
|
85 | - $this->result['exact'][$type] = []; |
|
86 | - } |
|
87 | - } |
|
81 | + public function unsetResult(SearchResultType $type) { |
|
82 | + $type = $type->getLabel(); |
|
83 | + $this->result[$type] = []; |
|
84 | + if(isset($this->result['exact'][$type])) { |
|
85 | + $this->result['exact'][$type] = []; |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |
@@ -41,291 +41,291 @@ |
||
41 | 41 | * @package OC\Files\Type |
42 | 42 | */ |
43 | 43 | class Detection implements IMimeTypeDetector { |
44 | - protected $mimetypes = []; |
|
45 | - protected $secureMimeTypes = []; |
|
46 | - |
|
47 | - protected $mimetypeIcons = []; |
|
48 | - /** @var string[] */ |
|
49 | - protected $mimeTypeAlias = []; |
|
50 | - |
|
51 | - /** @var IURLGenerator */ |
|
52 | - private $urlGenerator; |
|
53 | - |
|
54 | - /** @var string */ |
|
55 | - private $customConfigDir; |
|
56 | - |
|
57 | - /** @var string */ |
|
58 | - private $defaultConfigDir; |
|
59 | - |
|
60 | - /** |
|
61 | - * @param IURLGenerator $urlGenerator |
|
62 | - * @param string $customConfigDir |
|
63 | - * @param string $defaultConfigDir |
|
64 | - */ |
|
65 | - public function __construct(IURLGenerator $urlGenerator, |
|
66 | - $customConfigDir, |
|
67 | - $defaultConfigDir) { |
|
68 | - $this->urlGenerator = $urlGenerator; |
|
69 | - $this->customConfigDir = $customConfigDir; |
|
70 | - $this->defaultConfigDir = $defaultConfigDir; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Add an extension -> mimetype mapping |
|
75 | - * |
|
76 | - * $mimetype is the assumed correct mime type |
|
77 | - * The optional $secureMimeType is an alternative to send to send |
|
78 | - * to avoid potential XSS. |
|
79 | - * |
|
80 | - * @param string $extension |
|
81 | - * @param string $mimetype |
|
82 | - * @param string|null $secureMimeType |
|
83 | - */ |
|
84 | - public function registerType($extension, |
|
85 | - $mimetype, |
|
86 | - $secureMimeType = null) { |
|
87 | - $this->mimetypes[$extension] = array($mimetype, $secureMimeType); |
|
88 | - $this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Add an array of extension -> mimetype mappings |
|
93 | - * |
|
94 | - * The mimetype value is in itself an array where the first index is |
|
95 | - * the assumed correct mimetype and the second is either a secure alternative |
|
96 | - * or null if the correct is considered secure. |
|
97 | - * |
|
98 | - * @param array $types |
|
99 | - */ |
|
100 | - public function registerTypeArray($types) { |
|
101 | - $this->mimetypes = array_merge($this->mimetypes, $types); |
|
102 | - |
|
103 | - // Update the alternative mimetypes to avoid having to look them up each time. |
|
104 | - foreach ($this->mimetypes as $mimeType) { |
|
105 | - $this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0]; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Add the mimetype aliases if they are not yet present |
|
111 | - */ |
|
112 | - private function loadAliases() { |
|
113 | - if (!empty($this->mimeTypeAlias)) { |
|
114 | - return; |
|
115 | - } |
|
116 | - |
|
117 | - $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true); |
|
118 | - |
|
119 | - if (file_exists($this->customConfigDir . '/mimetypealiases.json')) { |
|
120 | - $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true); |
|
121 | - $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string[] |
|
127 | - */ |
|
128 | - public function getAllAliases() { |
|
129 | - $this->loadAliases(); |
|
130 | - return $this->mimeTypeAlias; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Add mimetype mappings if they are not yet present |
|
135 | - */ |
|
136 | - private function loadMappings() { |
|
137 | - if (!empty($this->mimetypes)) { |
|
138 | - return; |
|
139 | - } |
|
140 | - |
|
141 | - $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true); |
|
142 | - |
|
143 | - //Check if need to load custom mappings |
|
144 | - if (file_exists($this->customConfigDir . '/mimetypemapping.json')) { |
|
145 | - $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true); |
|
146 | - $mimetypeMapping = array_merge($mimetypeMapping, $custom); |
|
147 | - } |
|
148 | - |
|
149 | - $this->registerTypeArray($mimetypeMapping); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - public function getAllMappings() { |
|
156 | - $this->loadMappings(); |
|
157 | - return $this->mimetypes; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * detect mimetype only based on filename, content of file is not used |
|
162 | - * |
|
163 | - * @param string $path |
|
164 | - * @return string |
|
165 | - */ |
|
166 | - public function detectPath($path) { |
|
167 | - $this->loadMappings(); |
|
168 | - |
|
169 | - $fileName = basename($path); |
|
170 | - |
|
171 | - // remove leading dot on hidden files with a file extension |
|
172 | - $fileName = ltrim($fileName, '.'); |
|
173 | - |
|
174 | - // note: leading dot doesn't qualify as extension |
|
175 | - if (strpos($fileName, '.') > 0) { |
|
176 | - |
|
177 | - // remove versioning extension: name.v1508946057 and transfer extension: name.ocTransferId2057600214.part |
|
178 | - $fileName = preg_replace('!((\.v\d+)|((.ocTransferId\d+)?.part))$!', '', $fileName); |
|
179 | - |
|
180 | - //try to guess the type by the file extension |
|
181 | - $extension = strtolower(strrchr($fileName, '.')); |
|
182 | - $extension = substr($extension, 1); //remove leading . |
|
183 | - return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0])) |
|
184 | - ? $this->mimetypes[$extension][0] |
|
185 | - : 'application/octet-stream'; |
|
186 | - } else { |
|
187 | - return 'application/octet-stream'; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * detect mimetype based on both filename and content |
|
193 | - * |
|
194 | - * @param string $path |
|
195 | - * @return string |
|
196 | - */ |
|
197 | - public function detect($path) { |
|
198 | - $this->loadMappings(); |
|
199 | - |
|
200 | - if (@is_dir($path)) { |
|
201 | - // directories are easy |
|
202 | - return "httpd/unix-directory"; |
|
203 | - } |
|
204 | - |
|
205 | - $mimeType = $this->detectPath($path); |
|
206 | - |
|
207 | - if ($mimeType === 'application/octet-stream' and function_exists('finfo_open') |
|
208 | - and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME) |
|
209 | - ) { |
|
210 | - $info = @strtolower(finfo_file($finfo, $path)); |
|
211 | - finfo_close($finfo); |
|
212 | - if ($info) { |
|
213 | - $mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info; |
|
214 | - return empty($mimeType) ? 'application/octet-stream' : $mimeType; |
|
215 | - } |
|
216 | - |
|
217 | - } |
|
218 | - $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); |
|
219 | - if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) { |
|
220 | - // use mime magic extension if available |
|
221 | - $mimeType = mime_content_type($path); |
|
222 | - } |
|
223 | - if (!$isWrapped and $mimeType === 'application/octet-stream' && \OC_Helper::canExecute("file")) { |
|
224 | - // it looks like we have a 'file' command, |
|
225 | - // lets see if it does have mime support |
|
226 | - $path = escapeshellarg($path); |
|
227 | - $fp = popen("file -b --mime-type $path 2>/dev/null", "r"); |
|
228 | - $reply = fgets($fp); |
|
229 | - pclose($fp); |
|
230 | - |
|
231 | - //trim the newline |
|
232 | - $mimeType = trim($reply); |
|
233 | - |
|
234 | - if (empty($mimeType)) { |
|
235 | - $mimeType = 'application/octet-stream'; |
|
236 | - } |
|
237 | - |
|
238 | - } |
|
239 | - return $mimeType; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * detect mimetype based on the content of a string |
|
244 | - * |
|
245 | - * @param string $data |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function detectString($data) { |
|
249 | - if (function_exists('finfo_open') and function_exists('finfo_file')) { |
|
250 | - $finfo = finfo_open(FILEINFO_MIME); |
|
251 | - $info = finfo_buffer($finfo, $data); |
|
252 | - return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info; |
|
253 | - } else { |
|
254 | - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile(); |
|
255 | - $fh = fopen($tmpFile, 'wb'); |
|
256 | - fwrite($fh, $data, 8024); |
|
257 | - fclose($fh); |
|
258 | - $mime = $this->detect($tmpFile); |
|
259 | - unset($tmpFile); |
|
260 | - return $mime; |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Get a secure mimetype that won't expose potential XSS. |
|
266 | - * |
|
267 | - * @param string $mimeType |
|
268 | - * @return string |
|
269 | - */ |
|
270 | - public function getSecureMimeType($mimeType) { |
|
271 | - $this->loadMappings(); |
|
272 | - |
|
273 | - return isset($this->secureMimeTypes[$mimeType]) |
|
274 | - ? $this->secureMimeTypes[$mimeType] |
|
275 | - : 'application/octet-stream'; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Get path to the icon of a file type |
|
280 | - * @param string $mimetype the MIME type |
|
281 | - * @return string the url |
|
282 | - */ |
|
283 | - public function mimeTypeIcon($mimetype) { |
|
284 | - $this->loadAliases(); |
|
285 | - |
|
286 | - while (isset($this->mimeTypeAlias[$mimetype])) { |
|
287 | - $mimetype = $this->mimeTypeAlias[$mimetype]; |
|
288 | - } |
|
289 | - if (isset($this->mimetypeIcons[$mimetype])) { |
|
290 | - return $this->mimetypeIcons[$mimetype]; |
|
291 | - } |
|
292 | - |
|
293 | - // Replace slash and backslash with a minus |
|
294 | - $icon = str_replace('/', '-', $mimetype); |
|
295 | - $icon = str_replace('\\', '-', $icon); |
|
296 | - |
|
297 | - // Is it a dir? |
|
298 | - if ($mimetype === 'dir') { |
|
299 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg'); |
|
300 | - return $this->mimetypeIcons[$mimetype]; |
|
301 | - } |
|
302 | - if ($mimetype === 'dir-shared') { |
|
303 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-shared.svg'); |
|
304 | - return $this->mimetypeIcons[$mimetype]; |
|
305 | - } |
|
306 | - if ($mimetype === 'dir-external') { |
|
307 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-external.svg'); |
|
308 | - return $this->mimetypeIcons[$mimetype]; |
|
309 | - } |
|
310 | - |
|
311 | - // Icon exists? |
|
312 | - try { |
|
313 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg'); |
|
314 | - return $this->mimetypeIcons[$mimetype]; |
|
315 | - } catch (\RuntimeException $e) { |
|
316 | - // Specified image not found |
|
317 | - } |
|
318 | - |
|
319 | - // Try only the first part of the filetype |
|
320 | - $mimePart = substr($icon, 0, strpos($icon, '-')); |
|
321 | - try { |
|
322 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg'); |
|
323 | - return $this->mimetypeIcons[$mimetype]; |
|
324 | - } catch (\RuntimeException $e) { |
|
325 | - // Image for the first part of the mimetype not found |
|
326 | - } |
|
327 | - |
|
328 | - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg'); |
|
329 | - return $this->mimetypeIcons[$mimetype]; |
|
330 | - } |
|
44 | + protected $mimetypes = []; |
|
45 | + protected $secureMimeTypes = []; |
|
46 | + |
|
47 | + protected $mimetypeIcons = []; |
|
48 | + /** @var string[] */ |
|
49 | + protected $mimeTypeAlias = []; |
|
50 | + |
|
51 | + /** @var IURLGenerator */ |
|
52 | + private $urlGenerator; |
|
53 | + |
|
54 | + /** @var string */ |
|
55 | + private $customConfigDir; |
|
56 | + |
|
57 | + /** @var string */ |
|
58 | + private $defaultConfigDir; |
|
59 | + |
|
60 | + /** |
|
61 | + * @param IURLGenerator $urlGenerator |
|
62 | + * @param string $customConfigDir |
|
63 | + * @param string $defaultConfigDir |
|
64 | + */ |
|
65 | + public function __construct(IURLGenerator $urlGenerator, |
|
66 | + $customConfigDir, |
|
67 | + $defaultConfigDir) { |
|
68 | + $this->urlGenerator = $urlGenerator; |
|
69 | + $this->customConfigDir = $customConfigDir; |
|
70 | + $this->defaultConfigDir = $defaultConfigDir; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Add an extension -> mimetype mapping |
|
75 | + * |
|
76 | + * $mimetype is the assumed correct mime type |
|
77 | + * The optional $secureMimeType is an alternative to send to send |
|
78 | + * to avoid potential XSS. |
|
79 | + * |
|
80 | + * @param string $extension |
|
81 | + * @param string $mimetype |
|
82 | + * @param string|null $secureMimeType |
|
83 | + */ |
|
84 | + public function registerType($extension, |
|
85 | + $mimetype, |
|
86 | + $secureMimeType = null) { |
|
87 | + $this->mimetypes[$extension] = array($mimetype, $secureMimeType); |
|
88 | + $this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Add an array of extension -> mimetype mappings |
|
93 | + * |
|
94 | + * The mimetype value is in itself an array where the first index is |
|
95 | + * the assumed correct mimetype and the second is either a secure alternative |
|
96 | + * or null if the correct is considered secure. |
|
97 | + * |
|
98 | + * @param array $types |
|
99 | + */ |
|
100 | + public function registerTypeArray($types) { |
|
101 | + $this->mimetypes = array_merge($this->mimetypes, $types); |
|
102 | + |
|
103 | + // Update the alternative mimetypes to avoid having to look them up each time. |
|
104 | + foreach ($this->mimetypes as $mimeType) { |
|
105 | + $this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0]; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Add the mimetype aliases if they are not yet present |
|
111 | + */ |
|
112 | + private function loadAliases() { |
|
113 | + if (!empty($this->mimeTypeAlias)) { |
|
114 | + return; |
|
115 | + } |
|
116 | + |
|
117 | + $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true); |
|
118 | + |
|
119 | + if (file_exists($this->customConfigDir . '/mimetypealiases.json')) { |
|
120 | + $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true); |
|
121 | + $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string[] |
|
127 | + */ |
|
128 | + public function getAllAliases() { |
|
129 | + $this->loadAliases(); |
|
130 | + return $this->mimeTypeAlias; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Add mimetype mappings if they are not yet present |
|
135 | + */ |
|
136 | + private function loadMappings() { |
|
137 | + if (!empty($this->mimetypes)) { |
|
138 | + return; |
|
139 | + } |
|
140 | + |
|
141 | + $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true); |
|
142 | + |
|
143 | + //Check if need to load custom mappings |
|
144 | + if (file_exists($this->customConfigDir . '/mimetypemapping.json')) { |
|
145 | + $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true); |
|
146 | + $mimetypeMapping = array_merge($mimetypeMapping, $custom); |
|
147 | + } |
|
148 | + |
|
149 | + $this->registerTypeArray($mimetypeMapping); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + public function getAllMappings() { |
|
156 | + $this->loadMappings(); |
|
157 | + return $this->mimetypes; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * detect mimetype only based on filename, content of file is not used |
|
162 | + * |
|
163 | + * @param string $path |
|
164 | + * @return string |
|
165 | + */ |
|
166 | + public function detectPath($path) { |
|
167 | + $this->loadMappings(); |
|
168 | + |
|
169 | + $fileName = basename($path); |
|
170 | + |
|
171 | + // remove leading dot on hidden files with a file extension |
|
172 | + $fileName = ltrim($fileName, '.'); |
|
173 | + |
|
174 | + // note: leading dot doesn't qualify as extension |
|
175 | + if (strpos($fileName, '.') > 0) { |
|
176 | + |
|
177 | + // remove versioning extension: name.v1508946057 and transfer extension: name.ocTransferId2057600214.part |
|
178 | + $fileName = preg_replace('!((\.v\d+)|((.ocTransferId\d+)?.part))$!', '', $fileName); |
|
179 | + |
|
180 | + //try to guess the type by the file extension |
|
181 | + $extension = strtolower(strrchr($fileName, '.')); |
|
182 | + $extension = substr($extension, 1); //remove leading . |
|
183 | + return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0])) |
|
184 | + ? $this->mimetypes[$extension][0] |
|
185 | + : 'application/octet-stream'; |
|
186 | + } else { |
|
187 | + return 'application/octet-stream'; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * detect mimetype based on both filename and content |
|
193 | + * |
|
194 | + * @param string $path |
|
195 | + * @return string |
|
196 | + */ |
|
197 | + public function detect($path) { |
|
198 | + $this->loadMappings(); |
|
199 | + |
|
200 | + if (@is_dir($path)) { |
|
201 | + // directories are easy |
|
202 | + return "httpd/unix-directory"; |
|
203 | + } |
|
204 | + |
|
205 | + $mimeType = $this->detectPath($path); |
|
206 | + |
|
207 | + if ($mimeType === 'application/octet-stream' and function_exists('finfo_open') |
|
208 | + and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME) |
|
209 | + ) { |
|
210 | + $info = @strtolower(finfo_file($finfo, $path)); |
|
211 | + finfo_close($finfo); |
|
212 | + if ($info) { |
|
213 | + $mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info; |
|
214 | + return empty($mimeType) ? 'application/octet-stream' : $mimeType; |
|
215 | + } |
|
216 | + |
|
217 | + } |
|
218 | + $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); |
|
219 | + if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) { |
|
220 | + // use mime magic extension if available |
|
221 | + $mimeType = mime_content_type($path); |
|
222 | + } |
|
223 | + if (!$isWrapped and $mimeType === 'application/octet-stream' && \OC_Helper::canExecute("file")) { |
|
224 | + // it looks like we have a 'file' command, |
|
225 | + // lets see if it does have mime support |
|
226 | + $path = escapeshellarg($path); |
|
227 | + $fp = popen("file -b --mime-type $path 2>/dev/null", "r"); |
|
228 | + $reply = fgets($fp); |
|
229 | + pclose($fp); |
|
230 | + |
|
231 | + //trim the newline |
|
232 | + $mimeType = trim($reply); |
|
233 | + |
|
234 | + if (empty($mimeType)) { |
|
235 | + $mimeType = 'application/octet-stream'; |
|
236 | + } |
|
237 | + |
|
238 | + } |
|
239 | + return $mimeType; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * detect mimetype based on the content of a string |
|
244 | + * |
|
245 | + * @param string $data |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function detectString($data) { |
|
249 | + if (function_exists('finfo_open') and function_exists('finfo_file')) { |
|
250 | + $finfo = finfo_open(FILEINFO_MIME); |
|
251 | + $info = finfo_buffer($finfo, $data); |
|
252 | + return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info; |
|
253 | + } else { |
|
254 | + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile(); |
|
255 | + $fh = fopen($tmpFile, 'wb'); |
|
256 | + fwrite($fh, $data, 8024); |
|
257 | + fclose($fh); |
|
258 | + $mime = $this->detect($tmpFile); |
|
259 | + unset($tmpFile); |
|
260 | + return $mime; |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Get a secure mimetype that won't expose potential XSS. |
|
266 | + * |
|
267 | + * @param string $mimeType |
|
268 | + * @return string |
|
269 | + */ |
|
270 | + public function getSecureMimeType($mimeType) { |
|
271 | + $this->loadMappings(); |
|
272 | + |
|
273 | + return isset($this->secureMimeTypes[$mimeType]) |
|
274 | + ? $this->secureMimeTypes[$mimeType] |
|
275 | + : 'application/octet-stream'; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Get path to the icon of a file type |
|
280 | + * @param string $mimetype the MIME type |
|
281 | + * @return string the url |
|
282 | + */ |
|
283 | + public function mimeTypeIcon($mimetype) { |
|
284 | + $this->loadAliases(); |
|
285 | + |
|
286 | + while (isset($this->mimeTypeAlias[$mimetype])) { |
|
287 | + $mimetype = $this->mimeTypeAlias[$mimetype]; |
|
288 | + } |
|
289 | + if (isset($this->mimetypeIcons[$mimetype])) { |
|
290 | + return $this->mimetypeIcons[$mimetype]; |
|
291 | + } |
|
292 | + |
|
293 | + // Replace slash and backslash with a minus |
|
294 | + $icon = str_replace('/', '-', $mimetype); |
|
295 | + $icon = str_replace('\\', '-', $icon); |
|
296 | + |
|
297 | + // Is it a dir? |
|
298 | + if ($mimetype === 'dir') { |
|
299 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg'); |
|
300 | + return $this->mimetypeIcons[$mimetype]; |
|
301 | + } |
|
302 | + if ($mimetype === 'dir-shared') { |
|
303 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-shared.svg'); |
|
304 | + return $this->mimetypeIcons[$mimetype]; |
|
305 | + } |
|
306 | + if ($mimetype === 'dir-external') { |
|
307 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-external.svg'); |
|
308 | + return $this->mimetypeIcons[$mimetype]; |
|
309 | + } |
|
310 | + |
|
311 | + // Icon exists? |
|
312 | + try { |
|
313 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg'); |
|
314 | + return $this->mimetypeIcons[$mimetype]; |
|
315 | + } catch (\RuntimeException $e) { |
|
316 | + // Specified image not found |
|
317 | + } |
|
318 | + |
|
319 | + // Try only the first part of the filetype |
|
320 | + $mimePart = substr($icon, 0, strpos($icon, '-')); |
|
321 | + try { |
|
322 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg'); |
|
323 | + return $this->mimetypeIcons[$mimetype]; |
|
324 | + } catch (\RuntimeException $e) { |
|
325 | + // Image for the first part of the mimetype not found |
|
326 | + } |
|
327 | + |
|
328 | + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg'); |
|
329 | + return $this->mimetypeIcons[$mimetype]; |
|
330 | + } |
|
331 | 331 | } |
@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | $helper = new Helper(\OC::$server->getConfig()); |
35 | 35 | $ocConfig = \OC::$server->getConfig(); |
36 | 36 | $uBackend = new User_Proxy( |
37 | - $helper->getServerConfigurationPrefixes(true), |
|
38 | - new LDAP(), |
|
39 | - $ocConfig, |
|
40 | - \OC::$server->getNotificationManager(), |
|
41 | - \OC::$server->getUserSession(), |
|
42 | - \OC::$server->query('LDAPUserPluginManager') |
|
37 | + $helper->getServerConfigurationPrefixes(true), |
|
38 | + new LDAP(), |
|
39 | + $ocConfig, |
|
40 | + \OC::$server->getNotificationManager(), |
|
41 | + \OC::$server->getUserSession(), |
|
42 | + \OC::$server->query('LDAPUserPluginManager') |
|
43 | 43 | ); |
44 | 44 | $deletedUsersIndex = new DeletedUsersIndex( |
45 | - $ocConfig, $dbConnection, $userMapping |
|
45 | + $ocConfig, $dbConnection, $userMapping |
|
46 | 46 | ); |
47 | 47 | |
48 | 48 | $application->add(new OCA\User_LDAP\Command\ShowConfig($helper)); |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | $application->add(new OCA\User_LDAP\Command\DeleteConfig($helper)); |
53 | 53 | $application->add(new OCA\User_LDAP\Command\Search($ocConfig)); |
54 | 54 | $application->add(new OCA\User_LDAP\Command\ShowRemnants( |
55 | - $deletedUsersIndex, \OC::$server->getDateTimeFormatter()) |
|
55 | + $deletedUsersIndex, \OC::$server->getDateTimeFormatter()) |
|
56 | 56 | ); |
57 | 57 | $application->add(new OCA\User_LDAP\Command\CheckUser( |
58 | - $uBackend, $helper, $deletedUsersIndex, $userMapping) |
|
58 | + $uBackend, $helper, $deletedUsersIndex, $userMapping) |
|
59 | 59 | ); |
@@ -37,314 +37,314 @@ |
||
37 | 37 | use OCP\Notification\IManager as INotificationManager; |
38 | 38 | |
39 | 39 | class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP { |
40 | - private $backends = array(); |
|
41 | - private $refBackend = null; |
|
40 | + private $backends = array(); |
|
41 | + private $refBackend = null; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor |
|
45 | - * |
|
46 | - * @param array $serverConfigPrefixes array containing the config Prefixes |
|
47 | - * @param ILDAPWrapper $ldap |
|
48 | - * @param IConfig $ocConfig |
|
49 | - * @param INotificationManager $notificationManager |
|
50 | - * @param IUserSession $userSession |
|
51 | - */ |
|
52 | - public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig, |
|
53 | - INotificationManager $notificationManager, IUserSession $userSession, |
|
54 | - UserPluginManager $userPluginManager) { |
|
55 | - parent::__construct($ldap); |
|
56 | - foreach($serverConfigPrefixes as $configPrefix) { |
|
57 | - $this->backends[$configPrefix] = |
|
58 | - new User_LDAP($this->getAccess($configPrefix), $ocConfig, $notificationManager, $userSession, $userPluginManager); |
|
43 | + /** |
|
44 | + * Constructor |
|
45 | + * |
|
46 | + * @param array $serverConfigPrefixes array containing the config Prefixes |
|
47 | + * @param ILDAPWrapper $ldap |
|
48 | + * @param IConfig $ocConfig |
|
49 | + * @param INotificationManager $notificationManager |
|
50 | + * @param IUserSession $userSession |
|
51 | + */ |
|
52 | + public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig, |
|
53 | + INotificationManager $notificationManager, IUserSession $userSession, |
|
54 | + UserPluginManager $userPluginManager) { |
|
55 | + parent::__construct($ldap); |
|
56 | + foreach($serverConfigPrefixes as $configPrefix) { |
|
57 | + $this->backends[$configPrefix] = |
|
58 | + new User_LDAP($this->getAccess($configPrefix), $ocConfig, $notificationManager, $userSession, $userPluginManager); |
|
59 | 59 | |
60 | - if(is_null($this->refBackend)) { |
|
61 | - $this->refBackend = &$this->backends[$configPrefix]; |
|
62 | - } |
|
63 | - } |
|
64 | - } |
|
60 | + if(is_null($this->refBackend)) { |
|
61 | + $this->refBackend = &$this->backends[$configPrefix]; |
|
62 | + } |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Tries the backends one after the other until a positive result is returned from the specified method |
|
68 | - * @param string $uid the uid connected to the request |
|
69 | - * @param string $method the method of the user backend that shall be called |
|
70 | - * @param array $parameters an array of parameters to be passed |
|
71 | - * @return mixed the result of the method or false |
|
72 | - */ |
|
73 | - protected function walkBackends($uid, $method, $parameters) { |
|
74 | - $cacheKey = $this->getUserCacheKey($uid); |
|
75 | - foreach($this->backends as $configPrefix => $backend) { |
|
76 | - $instance = $backend; |
|
77 | - if(!method_exists($instance, $method) |
|
78 | - && method_exists($this->getAccess($configPrefix), $method)) { |
|
79 | - $instance = $this->getAccess($configPrefix); |
|
80 | - } |
|
81 | - if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
82 | - $this->writeToCache($cacheKey, $configPrefix); |
|
83 | - return $result; |
|
84 | - } |
|
85 | - } |
|
86 | - return false; |
|
87 | - } |
|
66 | + /** |
|
67 | + * Tries the backends one after the other until a positive result is returned from the specified method |
|
68 | + * @param string $uid the uid connected to the request |
|
69 | + * @param string $method the method of the user backend that shall be called |
|
70 | + * @param array $parameters an array of parameters to be passed |
|
71 | + * @return mixed the result of the method or false |
|
72 | + */ |
|
73 | + protected function walkBackends($uid, $method, $parameters) { |
|
74 | + $cacheKey = $this->getUserCacheKey($uid); |
|
75 | + foreach($this->backends as $configPrefix => $backend) { |
|
76 | + $instance = $backend; |
|
77 | + if(!method_exists($instance, $method) |
|
78 | + && method_exists($this->getAccess($configPrefix), $method)) { |
|
79 | + $instance = $this->getAccess($configPrefix); |
|
80 | + } |
|
81 | + if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
82 | + $this->writeToCache($cacheKey, $configPrefix); |
|
83 | + return $result; |
|
84 | + } |
|
85 | + } |
|
86 | + return false; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
91 | - * @param string $uid the uid connected to the request |
|
92 | - * @param string $method the method of the user backend that shall be called |
|
93 | - * @param array $parameters an array of parameters to be passed |
|
94 | - * @param mixed $passOnWhen the result matches this variable |
|
95 | - * @return mixed the result of the method or false |
|
96 | - */ |
|
97 | - protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) { |
|
98 | - $cacheKey = $this->getUserCacheKey($uid); |
|
99 | - $prefix = $this->getFromCache($cacheKey); |
|
100 | - //in case the uid has been found in the past, try this stored connection first |
|
101 | - if(!is_null($prefix)) { |
|
102 | - if(isset($this->backends[$prefix])) { |
|
103 | - $instance = $this->backends[$prefix]; |
|
104 | - if(!method_exists($instance, $method) |
|
105 | - && method_exists($this->getAccess($prefix), $method)) { |
|
106 | - $instance = $this->getAccess($prefix); |
|
107 | - } |
|
108 | - $result = call_user_func_array(array($instance, $method), $parameters); |
|
109 | - if($result === $passOnWhen) { |
|
110 | - //not found here, reset cache to null if user vanished |
|
111 | - //because sometimes methods return false with a reason |
|
112 | - $userExists = call_user_func_array( |
|
113 | - array($this->backends[$prefix], 'userExists'), |
|
114 | - array($uid) |
|
115 | - ); |
|
116 | - if(!$userExists) { |
|
117 | - $this->writeToCache($cacheKey, null); |
|
118 | - } |
|
119 | - } |
|
120 | - return $result; |
|
121 | - } |
|
122 | - } |
|
123 | - return false; |
|
124 | - } |
|
89 | + /** |
|
90 | + * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
91 | + * @param string $uid the uid connected to the request |
|
92 | + * @param string $method the method of the user backend that shall be called |
|
93 | + * @param array $parameters an array of parameters to be passed |
|
94 | + * @param mixed $passOnWhen the result matches this variable |
|
95 | + * @return mixed the result of the method or false |
|
96 | + */ |
|
97 | + protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) { |
|
98 | + $cacheKey = $this->getUserCacheKey($uid); |
|
99 | + $prefix = $this->getFromCache($cacheKey); |
|
100 | + //in case the uid has been found in the past, try this stored connection first |
|
101 | + if(!is_null($prefix)) { |
|
102 | + if(isset($this->backends[$prefix])) { |
|
103 | + $instance = $this->backends[$prefix]; |
|
104 | + if(!method_exists($instance, $method) |
|
105 | + && method_exists($this->getAccess($prefix), $method)) { |
|
106 | + $instance = $this->getAccess($prefix); |
|
107 | + } |
|
108 | + $result = call_user_func_array(array($instance, $method), $parameters); |
|
109 | + if($result === $passOnWhen) { |
|
110 | + //not found here, reset cache to null if user vanished |
|
111 | + //because sometimes methods return false with a reason |
|
112 | + $userExists = call_user_func_array( |
|
113 | + array($this->backends[$prefix], 'userExists'), |
|
114 | + array($uid) |
|
115 | + ); |
|
116 | + if(!$userExists) { |
|
117 | + $this->writeToCache($cacheKey, null); |
|
118 | + } |
|
119 | + } |
|
120 | + return $result; |
|
121 | + } |
|
122 | + } |
|
123 | + return false; |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Check if backend implements actions |
|
128 | - * @param int $actions bitwise-or'ed actions |
|
129 | - * @return boolean |
|
130 | - * |
|
131 | - * Returns the supported actions as int to be |
|
132 | - * compared with \OC\User\Backend::CREATE_USER etc. |
|
133 | - */ |
|
134 | - public function implementsActions($actions) { |
|
135 | - //it's the same across all our user backends obviously |
|
136 | - return $this->refBackend->implementsActions($actions); |
|
137 | - } |
|
126 | + /** |
|
127 | + * Check if backend implements actions |
|
128 | + * @param int $actions bitwise-or'ed actions |
|
129 | + * @return boolean |
|
130 | + * |
|
131 | + * Returns the supported actions as int to be |
|
132 | + * compared with \OC\User\Backend::CREATE_USER etc. |
|
133 | + */ |
|
134 | + public function implementsActions($actions) { |
|
135 | + //it's the same across all our user backends obviously |
|
136 | + return $this->refBackend->implementsActions($actions); |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Backend name to be shown in user management |
|
141 | - * @return string the name of the backend to be shown |
|
142 | - */ |
|
143 | - public function getBackendName() { |
|
144 | - return $this->refBackend->getBackendName(); |
|
145 | - } |
|
139 | + /** |
|
140 | + * Backend name to be shown in user management |
|
141 | + * @return string the name of the backend to be shown |
|
142 | + */ |
|
143 | + public function getBackendName() { |
|
144 | + return $this->refBackend->getBackendName(); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Get a list of all users |
|
149 | - * |
|
150 | - * @param string $search |
|
151 | - * @param null|int $limit |
|
152 | - * @param null|int $offset |
|
153 | - * @return string[] an array of all uids |
|
154 | - */ |
|
155 | - public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
156 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
157 | - $users = array(); |
|
158 | - foreach($this->backends as $backend) { |
|
159 | - $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
160 | - if (is_array($backendUsers)) { |
|
161 | - $users = array_merge($users, $backendUsers); |
|
162 | - } |
|
163 | - } |
|
164 | - return $users; |
|
165 | - } |
|
147 | + /** |
|
148 | + * Get a list of all users |
|
149 | + * |
|
150 | + * @param string $search |
|
151 | + * @param null|int $limit |
|
152 | + * @param null|int $offset |
|
153 | + * @return string[] an array of all uids |
|
154 | + */ |
|
155 | + public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
156 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
157 | + $users = array(); |
|
158 | + foreach($this->backends as $backend) { |
|
159 | + $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
160 | + if (is_array($backendUsers)) { |
|
161 | + $users = array_merge($users, $backendUsers); |
|
162 | + } |
|
163 | + } |
|
164 | + return $users; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * check if a user exists |
|
169 | - * @param string $uid the username |
|
170 | - * @return boolean |
|
171 | - */ |
|
172 | - public function userExists($uid) { |
|
173 | - return $this->handleRequest($uid, 'userExists', array($uid)); |
|
174 | - } |
|
167 | + /** |
|
168 | + * check if a user exists |
|
169 | + * @param string $uid the username |
|
170 | + * @return boolean |
|
171 | + */ |
|
172 | + public function userExists($uid) { |
|
173 | + return $this->handleRequest($uid, 'userExists', array($uid)); |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * check if a user exists on LDAP |
|
178 | - * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user |
|
179 | - * name or an instance of that user |
|
180 | - * @return boolean |
|
181 | - */ |
|
182 | - public function userExistsOnLDAP($user) { |
|
183 | - $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
184 | - return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); |
|
185 | - } |
|
176 | + /** |
|
177 | + * check if a user exists on LDAP |
|
178 | + * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user |
|
179 | + * name or an instance of that user |
|
180 | + * @return boolean |
|
181 | + */ |
|
182 | + public function userExistsOnLDAP($user) { |
|
183 | + $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
184 | + return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Check if the password is correct |
|
189 | - * @param string $uid The username |
|
190 | - * @param string $password The password |
|
191 | - * @return bool |
|
192 | - * |
|
193 | - * Check if the password is correct without logging in the user |
|
194 | - */ |
|
195 | - public function checkPassword($uid, $password) { |
|
196 | - return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); |
|
197 | - } |
|
187 | + /** |
|
188 | + * Check if the password is correct |
|
189 | + * @param string $uid The username |
|
190 | + * @param string $password The password |
|
191 | + * @return bool |
|
192 | + * |
|
193 | + * Check if the password is correct without logging in the user |
|
194 | + */ |
|
195 | + public function checkPassword($uid, $password) { |
|
196 | + return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * returns the username for the given login name, if available |
|
201 | - * |
|
202 | - * @param string $loginName |
|
203 | - * @return string|false |
|
204 | - */ |
|
205 | - public function loginName2UserName($loginName) { |
|
206 | - $id = 'LOGINNAME,' . $loginName; |
|
207 | - return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
|
208 | - } |
|
199 | + /** |
|
200 | + * returns the username for the given login name, if available |
|
201 | + * |
|
202 | + * @param string $loginName |
|
203 | + * @return string|false |
|
204 | + */ |
|
205 | + public function loginName2UserName($loginName) { |
|
206 | + $id = 'LOGINNAME,' . $loginName; |
|
207 | + return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * returns the username for the given LDAP DN, if available |
|
212 | - * |
|
213 | - * @param string $dn |
|
214 | - * @return string|false with the username |
|
215 | - */ |
|
216 | - public function dn2UserName($dn) { |
|
217 | - $id = 'DN,' . $dn; |
|
218 | - return $this->handleRequest($id, 'dn2UserName', array($dn)); |
|
219 | - } |
|
210 | + /** |
|
211 | + * returns the username for the given LDAP DN, if available |
|
212 | + * |
|
213 | + * @param string $dn |
|
214 | + * @return string|false with the username |
|
215 | + */ |
|
216 | + public function dn2UserName($dn) { |
|
217 | + $id = 'DN,' . $dn; |
|
218 | + return $this->handleRequest($id, 'dn2UserName', array($dn)); |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * get the user's home directory |
|
223 | - * @param string $uid the username |
|
224 | - * @return boolean |
|
225 | - */ |
|
226 | - public function getHome($uid) { |
|
227 | - return $this->handleRequest($uid, 'getHome', array($uid)); |
|
228 | - } |
|
221 | + /** |
|
222 | + * get the user's home directory |
|
223 | + * @param string $uid the username |
|
224 | + * @return boolean |
|
225 | + */ |
|
226 | + public function getHome($uid) { |
|
227 | + return $this->handleRequest($uid, 'getHome', array($uid)); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * get display name of the user |
|
232 | - * @param string $uid user ID of the user |
|
233 | - * @return string display name |
|
234 | - */ |
|
235 | - public function getDisplayName($uid) { |
|
236 | - return $this->handleRequest($uid, 'getDisplayName', array($uid)); |
|
237 | - } |
|
230 | + /** |
|
231 | + * get display name of the user |
|
232 | + * @param string $uid user ID of the user |
|
233 | + * @return string display name |
|
234 | + */ |
|
235 | + public function getDisplayName($uid) { |
|
236 | + return $this->handleRequest($uid, 'getDisplayName', array($uid)); |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * set display name of the user |
|
241 | - * |
|
242 | - * @param string $uid user ID of the user |
|
243 | - * @param string $displayName new display name |
|
244 | - * @return string display name |
|
245 | - */ |
|
246 | - public function setDisplayName($uid, $displayName) { |
|
247 | - return $this->handleRequest($uid, 'setDisplayName', array($uid, $displayName)); |
|
248 | - } |
|
239 | + /** |
|
240 | + * set display name of the user |
|
241 | + * |
|
242 | + * @param string $uid user ID of the user |
|
243 | + * @param string $displayName new display name |
|
244 | + * @return string display name |
|
245 | + */ |
|
246 | + public function setDisplayName($uid, $displayName) { |
|
247 | + return $this->handleRequest($uid, 'setDisplayName', array($uid, $displayName)); |
|
248 | + } |
|
249 | 249 | |
250 | - /** |
|
251 | - * checks whether the user is allowed to change his avatar in Nextcloud |
|
252 | - * @param string $uid the Nextcloud user name |
|
253 | - * @return boolean either the user can or cannot |
|
254 | - */ |
|
255 | - public function canChangeAvatar($uid) { |
|
256 | - return $this->handleRequest($uid, 'canChangeAvatar', array($uid)); |
|
257 | - } |
|
250 | + /** |
|
251 | + * checks whether the user is allowed to change his avatar in Nextcloud |
|
252 | + * @param string $uid the Nextcloud user name |
|
253 | + * @return boolean either the user can or cannot |
|
254 | + */ |
|
255 | + public function canChangeAvatar($uid) { |
|
256 | + return $this->handleRequest($uid, 'canChangeAvatar', array($uid)); |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * Get a list of all display names and user ids. |
|
261 | - * @param string $search |
|
262 | - * @param string|null $limit |
|
263 | - * @param string|null $offset |
|
264 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
265 | - */ |
|
266 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
267 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
268 | - $users = array(); |
|
269 | - foreach($this->backends as $backend) { |
|
270 | - $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
271 | - if (is_array($backendUsers)) { |
|
272 | - $users = $users + $backendUsers; |
|
273 | - } |
|
274 | - } |
|
275 | - return $users; |
|
276 | - } |
|
259 | + /** |
|
260 | + * Get a list of all display names and user ids. |
|
261 | + * @param string $search |
|
262 | + * @param string|null $limit |
|
263 | + * @param string|null $offset |
|
264 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
265 | + */ |
|
266 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
267 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
268 | + $users = array(); |
|
269 | + foreach($this->backends as $backend) { |
|
270 | + $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
271 | + if (is_array($backendUsers)) { |
|
272 | + $users = $users + $backendUsers; |
|
273 | + } |
|
274 | + } |
|
275 | + return $users; |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * delete a user |
|
280 | - * @param string $uid The username of the user to delete |
|
281 | - * @return bool |
|
282 | - * |
|
283 | - * Deletes a user |
|
284 | - */ |
|
285 | - public function deleteUser($uid) { |
|
286 | - return $this->handleRequest($uid, 'deleteUser', array($uid)); |
|
287 | - } |
|
278 | + /** |
|
279 | + * delete a user |
|
280 | + * @param string $uid The username of the user to delete |
|
281 | + * @return bool |
|
282 | + * |
|
283 | + * Deletes a user |
|
284 | + */ |
|
285 | + public function deleteUser($uid) { |
|
286 | + return $this->handleRequest($uid, 'deleteUser', array($uid)); |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * Set password |
|
291 | - * @param string $uid The username |
|
292 | - * @param string $password The new password |
|
293 | - * @return bool |
|
294 | - * |
|
295 | - */ |
|
296 | - public function setPassword($uid, $password) { |
|
297 | - return $this->handleRequest($uid, 'setPassword', array($uid, $password)); |
|
298 | - } |
|
289 | + /** |
|
290 | + * Set password |
|
291 | + * @param string $uid The username |
|
292 | + * @param string $password The new password |
|
293 | + * @return bool |
|
294 | + * |
|
295 | + */ |
|
296 | + public function setPassword($uid, $password) { |
|
297 | + return $this->handleRequest($uid, 'setPassword', array($uid, $password)); |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * @return bool |
|
302 | - */ |
|
303 | - public function hasUserListings() { |
|
304 | - return $this->refBackend->hasUserListings(); |
|
305 | - } |
|
300 | + /** |
|
301 | + * @return bool |
|
302 | + */ |
|
303 | + public function hasUserListings() { |
|
304 | + return $this->refBackend->hasUserListings(); |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * Count the number of users |
|
309 | - * @return int|bool |
|
310 | - */ |
|
311 | - public function countUsers() { |
|
312 | - $users = false; |
|
313 | - foreach($this->backends as $backend) { |
|
314 | - $backendUsers = $backend->countUsers(); |
|
315 | - if ($backendUsers !== false) { |
|
316 | - $users += $backendUsers; |
|
317 | - } |
|
318 | - } |
|
319 | - return $users; |
|
320 | - } |
|
307 | + /** |
|
308 | + * Count the number of users |
|
309 | + * @return int|bool |
|
310 | + */ |
|
311 | + public function countUsers() { |
|
312 | + $users = false; |
|
313 | + foreach($this->backends as $backend) { |
|
314 | + $backendUsers = $backend->countUsers(); |
|
315 | + if ($backendUsers !== false) { |
|
316 | + $users += $backendUsers; |
|
317 | + } |
|
318 | + } |
|
319 | + return $users; |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Return access for LDAP interaction. |
|
324 | - * @param string $uid |
|
325 | - * @return Access instance of Access for LDAP interaction |
|
326 | - */ |
|
327 | - public function getLDAPAccess($uid) { |
|
328 | - return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); |
|
329 | - } |
|
322 | + /** |
|
323 | + * Return access for LDAP interaction. |
|
324 | + * @param string $uid |
|
325 | + * @return Access instance of Access for LDAP interaction |
|
326 | + */ |
|
327 | + public function getLDAPAccess($uid) { |
|
328 | + return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * Return a new LDAP connection for the specified user. |
|
333 | - * The connection needs to be closed manually. |
|
334 | - * @param string $uid |
|
335 | - * @return resource of the LDAP connection |
|
336 | - */ |
|
337 | - public function getNewLDAPConnection($uid) { |
|
338 | - return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); |
|
339 | - } |
|
331 | + /** |
|
332 | + * Return a new LDAP connection for the specified user. |
|
333 | + * The connection needs to be closed manually. |
|
334 | + * @param string $uid |
|
335 | + * @return resource of the LDAP connection |
|
336 | + */ |
|
337 | + public function getNewLDAPConnection($uid) { |
|
338 | + return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); |
|
339 | + } |
|
340 | 340 | |
341 | - /** |
|
342 | - * Creates a new user in LDAP |
|
343 | - * @param $username |
|
344 | - * @param $password |
|
345 | - * @return bool |
|
346 | - */ |
|
347 | - public function createUser($username, $password) { |
|
348 | - return $this->handleRequest($username, 'createUser', array($username,$password)); |
|
349 | - } |
|
341 | + /** |
|
342 | + * Creates a new user in LDAP |
|
343 | + * @param $username |
|
344 | + * @param $password |
|
345 | + * @return bool |
|
346 | + */ |
|
347 | + public function createUser($username, $password) { |
|
348 | + return $this->handleRequest($username, 'createUser', array($username,$password)); |
|
349 | + } |
|
350 | 350 | } |
@@ -30,10 +30,10 @@ |
||
30 | 30 | use OCP\IConfig; |
31 | 31 | |
32 | 32 | class UUIDFixGroup extends UUIDFix { |
33 | - public function __construct(GroupMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) { |
|
34 | - $this->mapper = $mapper; |
|
35 | - $this->proxy = new User_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config, |
|
36 | - \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), |
|
37 | - \OC::$server->query('LDAPUserPluginManager')); |
|
38 | - } |
|
33 | + public function __construct(GroupMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) { |
|
34 | + $this->mapper = $mapper; |
|
35 | + $this->proxy = new User_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config, |
|
36 | + \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), |
|
37 | + \OC::$server->query('LDAPUserPluginManager')); |
|
38 | + } |
|
39 | 39 | } |
@@ -28,54 +28,54 @@ |
||
28 | 28 | use OCP\IServerContainer; |
29 | 29 | |
30 | 30 | class Manager implements IManager { |
31 | - /** @var string[] */ |
|
32 | - protected $sorters =[]; |
|
31 | + /** @var string[] */ |
|
32 | + protected $sorters =[]; |
|
33 | 33 | |
34 | - /** @var ISorter[] */ |
|
35 | - protected $sorterInstances = []; |
|
36 | - /** @var IServerContainer */ |
|
37 | - private $c; |
|
34 | + /** @var ISorter[] */ |
|
35 | + protected $sorterInstances = []; |
|
36 | + /** @var IServerContainer */ |
|
37 | + private $c; |
|
38 | 38 | |
39 | - public function __construct(IServerContainer $container) { |
|
40 | - $this->c = $container; |
|
41 | - } |
|
39 | + public function __construct(IServerContainer $container) { |
|
40 | + $this->c = $container; |
|
41 | + } |
|
42 | 42 | |
43 | - public function runSorters(array $sorters, array &$sortArray, array $context) { |
|
44 | - $sorterInstances = $this->getSorters(); |
|
45 | - while($sorter = array_shift($sorters)) { |
|
46 | - if(isset($sorterInstances[$sorter])) { |
|
47 | - $sorterInstances[$sorter]->sort($sortArray, $context); |
|
48 | - } else { |
|
49 | - $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ |
|
50 | - 'app' => 'core', 'id' => $sorter |
|
51 | - ]); |
|
52 | - } |
|
53 | - } |
|
54 | - } |
|
43 | + public function runSorters(array $sorters, array &$sortArray, array $context) { |
|
44 | + $sorterInstances = $this->getSorters(); |
|
45 | + while($sorter = array_shift($sorters)) { |
|
46 | + if(isset($sorterInstances[$sorter])) { |
|
47 | + $sorterInstances[$sorter]->sort($sortArray, $context); |
|
48 | + } else { |
|
49 | + $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ |
|
50 | + 'app' => 'core', 'id' => $sorter |
|
51 | + ]); |
|
52 | + } |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - public function registerSorter($className) { |
|
57 | - $this->sorters[] = $className; |
|
58 | - } |
|
56 | + public function registerSorter($className) { |
|
57 | + $this->sorters[] = $className; |
|
58 | + } |
|
59 | 59 | |
60 | - protected function getSorters() { |
|
61 | - if(count($this->sorterInstances) === 0) { |
|
62 | - foreach ($this->sorters as $sorter) { |
|
63 | - /** @var ISorter $instance */ |
|
64 | - $instance = $this->c->resolve($sorter); |
|
65 | - if(!$instance instanceof ISorter) { |
|
66 | - $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', |
|
67 | - ['app' => 'core', 'class' => $sorter]); |
|
68 | - continue; |
|
69 | - } |
|
70 | - $sorterId = trim($instance->getId()); |
|
71 | - if(trim($sorterId) === '') { |
|
72 | - $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', |
|
73 | - ['app' => 'core', 'class' => $sorter]); |
|
74 | - continue; |
|
75 | - } |
|
76 | - $this->sorterInstances[$sorterId] = $instance; |
|
77 | - } |
|
78 | - } |
|
79 | - return $this->sorterInstances; |
|
80 | - } |
|
60 | + protected function getSorters() { |
|
61 | + if(count($this->sorterInstances) === 0) { |
|
62 | + foreach ($this->sorters as $sorter) { |
|
63 | + /** @var ISorter $instance */ |
|
64 | + $instance = $this->c->resolve($sorter); |
|
65 | + if(!$instance instanceof ISorter) { |
|
66 | + $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', |
|
67 | + ['app' => 'core', 'class' => $sorter]); |
|
68 | + continue; |
|
69 | + } |
|
70 | + $sorterId = trim($instance->getId()); |
|
71 | + if(trim($sorterId) === '') { |
|
72 | + $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', |
|
73 | + ['app' => 'core', 'class' => $sorter]); |
|
74 | + continue; |
|
75 | + } |
|
76 | + $this->sorterInstances[$sorterId] = $instance; |
|
77 | + } |
|
78 | + } |
|
79 | + return $this->sorterInstances; |
|
80 | + } |
|
81 | 81 | } |
@@ -27,19 +27,19 @@ |
||
27 | 27 | use OCP\IServerContainer; |
28 | 28 | |
29 | 29 | class JSSettingsHelper { |
30 | - /** @var IServerContainer */ |
|
31 | - private $c; |
|
30 | + /** @var IServerContainer */ |
|
31 | + private $c; |
|
32 | 32 | |
33 | - public function __construct(IServerContainer $c) { |
|
34 | - $this->c = $c; |
|
35 | - } |
|
33 | + public function __construct(IServerContainer $c) { |
|
34 | + $this->c = $c; |
|
35 | + } |
|
36 | 36 | |
37 | - public function extend(array $settings) { |
|
38 | - $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
37 | + public function extend(array $settings) { |
|
38 | + $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
39 | 39 | |
40 | - $value = (int)$this->c->getConfig()->getAppValue('comments', 'maxAutoCompleteResults', 10); |
|
41 | - $appConfig['comments']['maxAutoCompleteResults'] = $value; |
|
40 | + $value = (int)$this->c->getConfig()->getAppValue('comments', 'maxAutoCompleteResults', 10); |
|
41 | + $appConfig['comments']['maxAutoCompleteResults'] = $value; |
|
42 | 42 | |
43 | - $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
44 | - } |
|
43 | + $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
44 | + } |
|
45 | 45 | } |