@@ -89,6 +89,9 @@ |
||
| 89 | 89 | $this->user = $user; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | + /** |
|
| 93 | + * @param string $tagId |
|
| 94 | + */ |
|
| 92 | 95 | function createFile($tagId, $data = null) { |
| 93 | 96 | try { |
| 94 | 97 | $tags = $this->tagManager->getTagsByIds([$tagId]); |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | $tags = $this->tagManager->getTagsByIds([$tagId]); |
| 96 | 96 | $tag = current($tags); |
| 97 | 97 | if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
| 98 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 98 | + throw new PreconditionFailed('Tag with id '.$tagId.' does not exist, cannot assign'); |
|
| 99 | 99 | } |
| 100 | 100 | if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
| 101 | - throw new Forbidden('No permission to assign tag ' . $tagId); |
|
| 101 | + throw new Forbidden('No permission to assign tag '.$tagId); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
| 105 | 105 | } catch (TagNotFoundException $e) { |
| 106 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 106 | + throw new PreconditionFailed('Tag with id '.$tagId.' does not exist, cannot assign'); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
@@ -120,11 +120,11 @@ discard block |
||
| 120 | 120 | return $this->makeNode($tag); |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | - throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
| 123 | + throw new NotFound('Tag with id '.$tagId.' not present for object '.$this->objectId); |
|
| 124 | 124 | } catch (\InvalidArgumentException $e) { |
| 125 | 125 | throw new BadRequest('Invalid tag id', 0, $e); |
| 126 | 126 | } catch (TagNotFoundException $e) { |
| 127 | - throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
| 127 | + throw new NotFound('Tag with id '.$tagId.' not found', 0, $e); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
@@ -39,169 +39,169 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class SystemTagsObjectMappingCollection implements ICollection { |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - private $objectId; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 50 | - private $objectType; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var ISystemTagManager |
|
| 54 | - */ |
|
| 55 | - private $tagManager; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var ISystemTagObjectMapper |
|
| 59 | - */ |
|
| 60 | - private $tagMapper; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * User |
|
| 64 | - * |
|
| 65 | - * @var IUser |
|
| 66 | - */ |
|
| 67 | - private $user; |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Constructor |
|
| 72 | - * |
|
| 73 | - * @param string $objectId object id |
|
| 74 | - * @param string $objectType object type |
|
| 75 | - * @param IUser $user user |
|
| 76 | - * @param ISystemTagManager $tagManager tag manager |
|
| 77 | - * @param ISystemTagObjectMapper $tagMapper tag mapper |
|
| 78 | - */ |
|
| 79 | - public function __construct( |
|
| 80 | - $objectId, |
|
| 81 | - $objectType, |
|
| 82 | - IUser $user, |
|
| 83 | - ISystemTagManager $tagManager, |
|
| 84 | - ISystemTagObjectMapper $tagMapper |
|
| 85 | - ) { |
|
| 86 | - $this->tagManager = $tagManager; |
|
| 87 | - $this->tagMapper = $tagMapper; |
|
| 88 | - $this->objectId = $objectId; |
|
| 89 | - $this->objectType = $objectType; |
|
| 90 | - $this->user = $user; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - function createFile($tagId, $data = null) { |
|
| 94 | - try { |
|
| 95 | - $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
| 96 | - $tag = current($tags); |
|
| 97 | - if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 98 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 99 | - } |
|
| 100 | - if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
|
| 101 | - throw new Forbidden('No permission to assign tag ' . $tagId); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
|
| 105 | - } catch (TagNotFoundException $e) { |
|
| 106 | - throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - function createDirectory($name) { |
|
| 111 | - throw new Forbidden('Permission denied to create collections'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - function getChild($tagId) { |
|
| 115 | - try { |
|
| 116 | - if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) { |
|
| 117 | - $tag = $this->tagManager->getTagsByIds([$tagId]); |
|
| 118 | - $tag = current($tag); |
|
| 119 | - if ($this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 120 | - return $this->makeNode($tag); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
| 124 | - } catch (\InvalidArgumentException $e) { |
|
| 125 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
| 126 | - } catch (TagNotFoundException $e) { |
|
| 127 | - throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - function getChildren() { |
|
| 132 | - $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType)); |
|
| 133 | - if (empty($tagIds)) { |
|
| 134 | - return []; |
|
| 135 | - } |
|
| 136 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
| 137 | - |
|
| 138 | - // filter out non-visible tags |
|
| 139 | - $tags = array_filter($tags, function($tag) { |
|
| 140 | - return $this->tagManager->canUserSeeTag($tag, $this->user); |
|
| 141 | - }); |
|
| 142 | - |
|
| 143 | - return array_values(array_map(function($tag) { |
|
| 144 | - return $this->makeNode($tag); |
|
| 145 | - }, $tags)); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - function childExists($tagId) { |
|
| 149 | - try { |
|
| 150 | - $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true); |
|
| 151 | - |
|
| 152 | - if ($result) { |
|
| 153 | - $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
| 154 | - $tag = current($tags); |
|
| 155 | - if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - return $result; |
|
| 161 | - } catch (\InvalidArgumentException $e) { |
|
| 162 | - throw new BadRequest('Invalid tag id', 0, $e); |
|
| 163 | - } catch (TagNotFoundException $e) { |
|
| 164 | - return false; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - function delete() { |
|
| 169 | - throw new Forbidden('Permission denied to delete this collection'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - function getName() { |
|
| 173 | - return $this->objectId; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - function setName($name) { |
|
| 177 | - throw new Forbidden('Permission denied to rename this collection'); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Returns the last modification time, as a unix timestamp |
|
| 182 | - * |
|
| 183 | - * @return int |
|
| 184 | - */ |
|
| 185 | - function getLastModified() { |
|
| 186 | - return null; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Create a sabre node for the mapping of the |
|
| 191 | - * given system tag to the collection's object |
|
| 192 | - * |
|
| 193 | - * @param ISystemTag $tag |
|
| 194 | - * |
|
| 195 | - * @return SystemTagMappingNode |
|
| 196 | - */ |
|
| 197 | - private function makeNode(ISystemTag $tag) { |
|
| 198 | - return new SystemTagMappingNode( |
|
| 199 | - $tag, |
|
| 200 | - $this->objectId, |
|
| 201 | - $this->objectType, |
|
| 202 | - $this->user, |
|
| 203 | - $this->tagManager, |
|
| 204 | - $this->tagMapper |
|
| 205 | - ); |
|
| 206 | - } |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + private $objectId; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | + private $objectType; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var ISystemTagManager |
|
| 54 | + */ |
|
| 55 | + private $tagManager; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var ISystemTagObjectMapper |
|
| 59 | + */ |
|
| 60 | + private $tagMapper; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * User |
|
| 64 | + * |
|
| 65 | + * @var IUser |
|
| 66 | + */ |
|
| 67 | + private $user; |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Constructor |
|
| 72 | + * |
|
| 73 | + * @param string $objectId object id |
|
| 74 | + * @param string $objectType object type |
|
| 75 | + * @param IUser $user user |
|
| 76 | + * @param ISystemTagManager $tagManager tag manager |
|
| 77 | + * @param ISystemTagObjectMapper $tagMapper tag mapper |
|
| 78 | + */ |
|
| 79 | + public function __construct( |
|
| 80 | + $objectId, |
|
| 81 | + $objectType, |
|
| 82 | + IUser $user, |
|
| 83 | + ISystemTagManager $tagManager, |
|
| 84 | + ISystemTagObjectMapper $tagMapper |
|
| 85 | + ) { |
|
| 86 | + $this->tagManager = $tagManager; |
|
| 87 | + $this->tagMapper = $tagMapper; |
|
| 88 | + $this->objectId = $objectId; |
|
| 89 | + $this->objectType = $objectType; |
|
| 90 | + $this->user = $user; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + function createFile($tagId, $data = null) { |
|
| 94 | + try { |
|
| 95 | + $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
| 96 | + $tag = current($tags); |
|
| 97 | + if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 98 | + throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 99 | + } |
|
| 100 | + if (!$this->tagManager->canUserAssignTag($tag, $this->user)) { |
|
| 101 | + throw new Forbidden('No permission to assign tag ' . $tagId); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $this->tagMapper->assignTags($this->objectId, $this->objectType, $tagId); |
|
| 105 | + } catch (TagNotFoundException $e) { |
|
| 106 | + throw new PreconditionFailed('Tag with id ' . $tagId . ' does not exist, cannot assign'); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + function createDirectory($name) { |
|
| 111 | + throw new Forbidden('Permission denied to create collections'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + function getChild($tagId) { |
|
| 115 | + try { |
|
| 116 | + if ($this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true)) { |
|
| 117 | + $tag = $this->tagManager->getTagsByIds([$tagId]); |
|
| 118 | + $tag = current($tag); |
|
| 119 | + if ($this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 120 | + return $this->makeNode($tag); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + throw new NotFound('Tag with id ' . $tagId . ' not present for object ' . $this->objectId); |
|
| 124 | + } catch (\InvalidArgumentException $e) { |
|
| 125 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
| 126 | + } catch (TagNotFoundException $e) { |
|
| 127 | + throw new NotFound('Tag with id ' . $tagId . ' not found', 0, $e); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + function getChildren() { |
|
| 132 | + $tagIds = current($this->tagMapper->getTagIdsForObjects([$this->objectId], $this->objectType)); |
|
| 133 | + if (empty($tagIds)) { |
|
| 134 | + return []; |
|
| 135 | + } |
|
| 136 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
| 137 | + |
|
| 138 | + // filter out non-visible tags |
|
| 139 | + $tags = array_filter($tags, function($tag) { |
|
| 140 | + return $this->tagManager->canUserSeeTag($tag, $this->user); |
|
| 141 | + }); |
|
| 142 | + |
|
| 143 | + return array_values(array_map(function($tag) { |
|
| 144 | + return $this->makeNode($tag); |
|
| 145 | + }, $tags)); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + function childExists($tagId) { |
|
| 149 | + try { |
|
| 150 | + $result = $this->tagMapper->haveTag([$this->objectId], $this->objectType, $tagId, true); |
|
| 151 | + |
|
| 152 | + if ($result) { |
|
| 153 | + $tags = $this->tagManager->getTagsByIds([$tagId]); |
|
| 154 | + $tag = current($tags); |
|
| 155 | + if (!$this->tagManager->canUserSeeTag($tag, $this->user)) { |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + return $result; |
|
| 161 | + } catch (\InvalidArgumentException $e) { |
|
| 162 | + throw new BadRequest('Invalid tag id', 0, $e); |
|
| 163 | + } catch (TagNotFoundException $e) { |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + function delete() { |
|
| 169 | + throw new Forbidden('Permission denied to delete this collection'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + function getName() { |
|
| 173 | + return $this->objectId; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + function setName($name) { |
|
| 177 | + throw new Forbidden('Permission denied to rename this collection'); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Returns the last modification time, as a unix timestamp |
|
| 182 | + * |
|
| 183 | + * @return int |
|
| 184 | + */ |
|
| 185 | + function getLastModified() { |
|
| 186 | + return null; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Create a sabre node for the mapping of the |
|
| 191 | + * given system tag to the collection's object |
|
| 192 | + * |
|
| 193 | + * @param ISystemTag $tag |
|
| 194 | + * |
|
| 195 | + * @return SystemTagMappingNode |
|
| 196 | + */ |
|
| 197 | + private function makeNode(ISystemTag $tag) { |
|
| 198 | + return new SystemTagMappingNode( |
|
| 199 | + $tag, |
|
| 200 | + $this->objectId, |
|
| 201 | + $this->objectType, |
|
| 202 | + $this->user, |
|
| 203 | + $this->tagManager, |
|
| 204 | + $this->tagMapper |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | 207 | } |
@@ -273,6 +273,10 @@ discard block |
||
| 273 | 273 | return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | + /** |
|
| 277 | + * @param integer $step |
|
| 278 | + * @param integer $max |
|
| 279 | + */ |
|
| 276 | 280 | protected function emit($sql, $step, $max) { |
| 277 | 281 | if ($this->noEmit) { |
| 278 | 282 | return; |
@@ -283,6 +287,10 @@ discard block |
||
| 283 | 287 | $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); |
| 284 | 288 | } |
| 285 | 289 | |
| 290 | + /** |
|
| 291 | + * @param integer $step |
|
| 292 | + * @param integer $max |
|
| 293 | + */ |
|
| 286 | 294 | private function emitCheckStep($tableName, $step, $max) { |
| 287 | 295 | if(is_null($this->dispatcher)) { |
| 288 | 296 | return; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | 139 | protected function generateTemporaryTableName($name) { |
| 140 | - return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 140 | + return $this->config->getSystemValue('dbtableprefix', 'oc_').$name.'_'.$this->random->generate(13, ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $indexName = $index->getName(); |
| 189 | 189 | } else { |
| 190 | 190 | // avoid conflicts in index names |
| 191 | - $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER); |
|
| 191 | + $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_').$this->random->generate(13, ISecureRandom::CHAR_LOWER); |
|
| 192 | 192 | } |
| 193 | 193 | $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); |
| 194 | 194 | } |
@@ -268,15 +268,15 @@ discard block |
||
| 268 | 268 | $quotedSource = $this->connection->quoteIdentifier($sourceName); |
| 269 | 269 | $quotedTarget = $this->connection->quoteIdentifier($targetName); |
| 270 | 270 | |
| 271 | - $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')'); |
|
| 272 | - $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource); |
|
| 271 | + $this->connection->exec('CREATE TABLE '.$quotedTarget.' (LIKE '.$quotedSource.')'); |
|
| 272 | + $this->connection->exec('INSERT INTO '.$quotedTarget.' SELECT * FROM '.$quotedSource); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | 276 | * @param string $name |
| 277 | 277 | */ |
| 278 | 278 | protected function dropTable($name) { |
| 279 | - $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name)); |
|
| 279 | + $this->connection->exec('DROP TABLE '.$this->connection->quoteIdentifier($name)); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -284,30 +284,30 @@ discard block |
||
| 284 | 284 | * @return string |
| 285 | 285 | */ |
| 286 | 286 | protected function convertStatementToScript($statement) { |
| 287 | - $script = $statement . ';'; |
|
| 287 | + $script = $statement.';'; |
|
| 288 | 288 | $script .= PHP_EOL; |
| 289 | 289 | $script .= PHP_EOL; |
| 290 | 290 | return $script; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | protected function getFilterExpression() { |
| 294 | - return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 294 | + return '/^'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/'; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | protected function emit($sql, $step, $max) { |
| 298 | 298 | if ($this->noEmit) { |
| 299 | 299 | return; |
| 300 | 300 | } |
| 301 | - if(is_null($this->dispatcher)) { |
|
| 301 | + if (is_null($this->dispatcher)) { |
|
| 302 | 302 | return; |
| 303 | 303 | } |
| 304 | - $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); |
|
| 304 | + $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step + 1, $max])); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | private function emitCheckStep($tableName, $step, $max) { |
| 308 | - if(is_null($this->dispatcher)) { |
|
| 308 | + if (is_null($this->dispatcher)) { |
|
| 309 | 309 | return; |
| 310 | 310 | } |
| 311 | - $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max])); |
|
| 311 | + $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step + 1, $max])); |
|
| 312 | 312 | } |
| 313 | 313 | } |
@@ -43,272 +43,272 @@ |
||
| 43 | 43 | |
| 44 | 44 | class Migrator { |
| 45 | 45 | |
| 46 | - /** @var \Doctrine\DBAL\Connection */ |
|
| 47 | - protected $connection; |
|
| 48 | - |
|
| 49 | - /** @var ISecureRandom */ |
|
| 50 | - private $random; |
|
| 51 | - |
|
| 52 | - /** @var IConfig */ |
|
| 53 | - protected $config; |
|
| 54 | - |
|
| 55 | - /** @var EventDispatcher */ |
|
| 56 | - private $dispatcher; |
|
| 57 | - |
|
| 58 | - /** @var bool */ |
|
| 59 | - private $noEmit = false; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param \Doctrine\DBAL\Connection|Connection $connection |
|
| 63 | - * @param ISecureRandom $random |
|
| 64 | - * @param IConfig $config |
|
| 65 | - * @param EventDispatcher $dispatcher |
|
| 66 | - */ |
|
| 67 | - public function __construct(\Doctrine\DBAL\Connection $connection, |
|
| 68 | - ISecureRandom $random, |
|
| 69 | - IConfig $config, |
|
| 70 | - EventDispatcher $dispatcher = null) { |
|
| 71 | - $this->connection = $connection; |
|
| 72 | - $this->random = $random; |
|
| 73 | - $this->config = $config; |
|
| 74 | - $this->dispatcher = $dispatcher; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 79 | - */ |
|
| 80 | - public function migrate(Schema $targetSchema) { |
|
| 81 | - $this->noEmit = true; |
|
| 82 | - $this->applySchema($targetSchema); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function generateChangeScript(Schema $targetSchema) { |
|
| 90 | - $schemaDiff = $this->getDiff($targetSchema, $this->connection); |
|
| 91 | - |
|
| 92 | - $script = ''; |
|
| 93 | - $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform()); |
|
| 94 | - foreach ($sqls as $sql) { |
|
| 95 | - $script .= $this->convertStatementToScript($sql); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return $script; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param Schema $targetSchema |
|
| 103 | - * @throws \OC\DB\MigrationException |
|
| 104 | - */ |
|
| 105 | - public function checkMigrate(Schema $targetSchema) { |
|
| 106 | - $this->noEmit = true; |
|
| 107 | - /**@var \Doctrine\DBAL\Schema\Table[] $tables */ |
|
| 108 | - $tables = $targetSchema->getTables(); |
|
| 109 | - $filterExpression = $this->getFilterExpression(); |
|
| 110 | - $this->connection->getConfiguration()-> |
|
| 111 | - setFilterSchemaAssetsExpression($filterExpression); |
|
| 112 | - $existingTables = $this->connection->getSchemaManager()->listTableNames(); |
|
| 113 | - |
|
| 114 | - $step = 0; |
|
| 115 | - foreach ($tables as $table) { |
|
| 116 | - if (strpos($table->getName(), '.')) { |
|
| 117 | - list(, $tableName) = explode('.', $table->getName()); |
|
| 118 | - } else { |
|
| 119 | - $tableName = $table->getName(); |
|
| 120 | - } |
|
| 121 | - $this->emitCheckStep($tableName, $step++, count($tables)); |
|
| 122 | - // don't need to check for new tables |
|
| 123 | - if (array_search($tableName, $existingTables) !== false) { |
|
| 124 | - $this->checkTableMigrate($table); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Create a unique name for the temporary table |
|
| 131 | - * |
|
| 132 | - * @param string $name |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - protected function generateTemporaryTableName($name) { |
|
| 136 | - return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Check the migration of a table on a copy so we can detect errors before messing with the real table |
|
| 141 | - * |
|
| 142 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 143 | - * @throws \OC\DB\MigrationException |
|
| 144 | - */ |
|
| 145 | - protected function checkTableMigrate(Table $table) { |
|
| 146 | - $name = $table->getName(); |
|
| 147 | - $tmpName = $this->generateTemporaryTableName($name); |
|
| 148 | - |
|
| 149 | - $this->copyTable($name, $tmpName); |
|
| 150 | - |
|
| 151 | - //create the migration schema for the temporary table |
|
| 152 | - $tmpTable = $this->renameTableSchema($table, $tmpName); |
|
| 153 | - $schemaConfig = new SchemaConfig(); |
|
| 154 | - $schemaConfig->setName($this->connection->getDatabase()); |
|
| 155 | - $schema = new Schema(array($tmpTable), array(), $schemaConfig); |
|
| 156 | - |
|
| 157 | - try { |
|
| 158 | - $this->applySchema($schema); |
|
| 159 | - $this->dropTable($tmpName); |
|
| 160 | - } catch (DBALException $e) { |
|
| 161 | - // pgsql needs to commit it's failed transaction before doing anything else |
|
| 162 | - if ($this->connection->isTransactionActive()) { |
|
| 163 | - $this->connection->commit(); |
|
| 164 | - } |
|
| 165 | - $this->dropTable($tmpName); |
|
| 166 | - throw new MigrationException($table->getName(), $e->getMessage()); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 172 | - * @param string $newName |
|
| 173 | - * @return \Doctrine\DBAL\Schema\Table |
|
| 174 | - */ |
|
| 175 | - protected function renameTableSchema(Table $table, $newName) { |
|
| 176 | - /** |
|
| 177 | - * @var \Doctrine\DBAL\Schema\Index[] $indexes |
|
| 178 | - */ |
|
| 179 | - $indexes = $table->getIndexes(); |
|
| 180 | - $newIndexes = array(); |
|
| 181 | - foreach ($indexes as $index) { |
|
| 182 | - if ($index->isPrimary()) { |
|
| 183 | - // do not rename primary key |
|
| 184 | - $indexName = $index->getName(); |
|
| 185 | - } else { |
|
| 186 | - // avoid conflicts in index names |
|
| 187 | - $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER); |
|
| 188 | - } |
|
| 189 | - $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // foreign keys are not supported so we just set it to an empty array |
|
| 193 | - return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions()); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - public function createSchema() { |
|
| 197 | - $filterExpression = $this->getFilterExpression(); |
|
| 198 | - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 199 | - return $this->connection->getSchemaManager()->createSchema(); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param Schema $targetSchema |
|
| 204 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 205 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 206 | - * @throws DBALException |
|
| 207 | - */ |
|
| 208 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 209 | - // adjust varchar columns with a length higher then getVarcharMaxLength to clob |
|
| 210 | - foreach ($targetSchema->getTables() as $table) { |
|
| 211 | - foreach ($table->getColumns() as $column) { |
|
| 212 | - if ($column->getType() instanceof StringType) { |
|
| 213 | - if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) { |
|
| 214 | - $column->setType(Type::getType('text')); |
|
| 215 | - $column->setLength(null); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $filterExpression = $this->getFilterExpression(); |
|
| 222 | - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 223 | - $sourceSchema = $connection->getSchemaManager()->createSchema(); |
|
| 224 | - |
|
| 225 | - // remove tables we don't know about |
|
| 226 | - /** @var $table \Doctrine\DBAL\Schema\Table */ |
|
| 227 | - foreach ($sourceSchema->getTables() as $table) { |
|
| 228 | - if (!$targetSchema->hasTable($table->getName())) { |
|
| 229 | - $sourceSchema->dropTable($table->getName()); |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - // remove sequences we don't know about |
|
| 233 | - foreach ($sourceSchema->getSequences() as $table) { |
|
| 234 | - if (!$targetSchema->hasSequence($table->getName())) { |
|
| 235 | - $sourceSchema->dropSequence($table->getName()); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - $comparator = new Comparator(); |
|
| 240 | - return $comparator->compare($sourceSchema, $targetSchema); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 245 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 246 | - */ |
|
| 247 | - protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) { |
|
| 248 | - if (is_null($connection)) { |
|
| 249 | - $connection = $this->connection; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $schemaDiff = $this->getDiff($targetSchema, $connection); |
|
| 253 | - |
|
| 254 | - $connection->beginTransaction(); |
|
| 255 | - $sqls = $schemaDiff->toSql($connection->getDatabasePlatform()); |
|
| 256 | - $step = 0; |
|
| 257 | - foreach ($sqls as $sql) { |
|
| 258 | - $this->emit($sql, $step++, count($sqls)); |
|
| 259 | - $connection->query($sql); |
|
| 260 | - } |
|
| 261 | - $connection->commit(); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @param string $sourceName |
|
| 266 | - * @param string $targetName |
|
| 267 | - */ |
|
| 268 | - protected function copyTable($sourceName, $targetName) { |
|
| 269 | - $quotedSource = $this->connection->quoteIdentifier($sourceName); |
|
| 270 | - $quotedTarget = $this->connection->quoteIdentifier($targetName); |
|
| 271 | - |
|
| 272 | - $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')'); |
|
| 273 | - $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @param string $name |
|
| 278 | - */ |
|
| 279 | - protected function dropTable($name) { |
|
| 280 | - $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name)); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @param $statement |
|
| 285 | - * @return string |
|
| 286 | - */ |
|
| 287 | - protected function convertStatementToScript($statement) { |
|
| 288 | - $script = $statement . ';'; |
|
| 289 | - $script .= PHP_EOL; |
|
| 290 | - $script .= PHP_EOL; |
|
| 291 | - return $script; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - protected function getFilterExpression() { |
|
| 295 | - return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - protected function emit($sql, $step, $max) { |
|
| 299 | - if ($this->noEmit) { |
|
| 300 | - return; |
|
| 301 | - } |
|
| 302 | - if(is_null($this->dispatcher)) { |
|
| 303 | - return; |
|
| 304 | - } |
|
| 305 | - $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - private function emitCheckStep($tableName, $step, $max) { |
|
| 309 | - if(is_null($this->dispatcher)) { |
|
| 310 | - return; |
|
| 311 | - } |
|
| 312 | - $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max])); |
|
| 313 | - } |
|
| 46 | + /** @var \Doctrine\DBAL\Connection */ |
|
| 47 | + protected $connection; |
|
| 48 | + |
|
| 49 | + /** @var ISecureRandom */ |
|
| 50 | + private $random; |
|
| 51 | + |
|
| 52 | + /** @var IConfig */ |
|
| 53 | + protected $config; |
|
| 54 | + |
|
| 55 | + /** @var EventDispatcher */ |
|
| 56 | + private $dispatcher; |
|
| 57 | + |
|
| 58 | + /** @var bool */ |
|
| 59 | + private $noEmit = false; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param \Doctrine\DBAL\Connection|Connection $connection |
|
| 63 | + * @param ISecureRandom $random |
|
| 64 | + * @param IConfig $config |
|
| 65 | + * @param EventDispatcher $dispatcher |
|
| 66 | + */ |
|
| 67 | + public function __construct(\Doctrine\DBAL\Connection $connection, |
|
| 68 | + ISecureRandom $random, |
|
| 69 | + IConfig $config, |
|
| 70 | + EventDispatcher $dispatcher = null) { |
|
| 71 | + $this->connection = $connection; |
|
| 72 | + $this->random = $random; |
|
| 73 | + $this->config = $config; |
|
| 74 | + $this->dispatcher = $dispatcher; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 79 | + */ |
|
| 80 | + public function migrate(Schema $targetSchema) { |
|
| 81 | + $this->noEmit = true; |
|
| 82 | + $this->applySchema($targetSchema); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function generateChangeScript(Schema $targetSchema) { |
|
| 90 | + $schemaDiff = $this->getDiff($targetSchema, $this->connection); |
|
| 91 | + |
|
| 92 | + $script = ''; |
|
| 93 | + $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform()); |
|
| 94 | + foreach ($sqls as $sql) { |
|
| 95 | + $script .= $this->convertStatementToScript($sql); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return $script; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param Schema $targetSchema |
|
| 103 | + * @throws \OC\DB\MigrationException |
|
| 104 | + */ |
|
| 105 | + public function checkMigrate(Schema $targetSchema) { |
|
| 106 | + $this->noEmit = true; |
|
| 107 | + /**@var \Doctrine\DBAL\Schema\Table[] $tables */ |
|
| 108 | + $tables = $targetSchema->getTables(); |
|
| 109 | + $filterExpression = $this->getFilterExpression(); |
|
| 110 | + $this->connection->getConfiguration()-> |
|
| 111 | + setFilterSchemaAssetsExpression($filterExpression); |
|
| 112 | + $existingTables = $this->connection->getSchemaManager()->listTableNames(); |
|
| 113 | + |
|
| 114 | + $step = 0; |
|
| 115 | + foreach ($tables as $table) { |
|
| 116 | + if (strpos($table->getName(), '.')) { |
|
| 117 | + list(, $tableName) = explode('.', $table->getName()); |
|
| 118 | + } else { |
|
| 119 | + $tableName = $table->getName(); |
|
| 120 | + } |
|
| 121 | + $this->emitCheckStep($tableName, $step++, count($tables)); |
|
| 122 | + // don't need to check for new tables |
|
| 123 | + if (array_search($tableName, $existingTables) !== false) { |
|
| 124 | + $this->checkTableMigrate($table); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Create a unique name for the temporary table |
|
| 131 | + * |
|
| 132 | + * @param string $name |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + protected function generateTemporaryTableName($name) { |
|
| 136 | + return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Check the migration of a table on a copy so we can detect errors before messing with the real table |
|
| 141 | + * |
|
| 142 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 143 | + * @throws \OC\DB\MigrationException |
|
| 144 | + */ |
|
| 145 | + protected function checkTableMigrate(Table $table) { |
|
| 146 | + $name = $table->getName(); |
|
| 147 | + $tmpName = $this->generateTemporaryTableName($name); |
|
| 148 | + |
|
| 149 | + $this->copyTable($name, $tmpName); |
|
| 150 | + |
|
| 151 | + //create the migration schema for the temporary table |
|
| 152 | + $tmpTable = $this->renameTableSchema($table, $tmpName); |
|
| 153 | + $schemaConfig = new SchemaConfig(); |
|
| 154 | + $schemaConfig->setName($this->connection->getDatabase()); |
|
| 155 | + $schema = new Schema(array($tmpTable), array(), $schemaConfig); |
|
| 156 | + |
|
| 157 | + try { |
|
| 158 | + $this->applySchema($schema); |
|
| 159 | + $this->dropTable($tmpName); |
|
| 160 | + } catch (DBALException $e) { |
|
| 161 | + // pgsql needs to commit it's failed transaction before doing anything else |
|
| 162 | + if ($this->connection->isTransactionActive()) { |
|
| 163 | + $this->connection->commit(); |
|
| 164 | + } |
|
| 165 | + $this->dropTable($tmpName); |
|
| 166 | + throw new MigrationException($table->getName(), $e->getMessage()); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 172 | + * @param string $newName |
|
| 173 | + * @return \Doctrine\DBAL\Schema\Table |
|
| 174 | + */ |
|
| 175 | + protected function renameTableSchema(Table $table, $newName) { |
|
| 176 | + /** |
|
| 177 | + * @var \Doctrine\DBAL\Schema\Index[] $indexes |
|
| 178 | + */ |
|
| 179 | + $indexes = $table->getIndexes(); |
|
| 180 | + $newIndexes = array(); |
|
| 181 | + foreach ($indexes as $index) { |
|
| 182 | + if ($index->isPrimary()) { |
|
| 183 | + // do not rename primary key |
|
| 184 | + $indexName = $index->getName(); |
|
| 185 | + } else { |
|
| 186 | + // avoid conflicts in index names |
|
| 187 | + $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER); |
|
| 188 | + } |
|
| 189 | + $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // foreign keys are not supported so we just set it to an empty array |
|
| 193 | + return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions()); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + public function createSchema() { |
|
| 197 | + $filterExpression = $this->getFilterExpression(); |
|
| 198 | + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 199 | + return $this->connection->getSchemaManager()->createSchema(); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param Schema $targetSchema |
|
| 204 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 205 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 206 | + * @throws DBALException |
|
| 207 | + */ |
|
| 208 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 209 | + // adjust varchar columns with a length higher then getVarcharMaxLength to clob |
|
| 210 | + foreach ($targetSchema->getTables() as $table) { |
|
| 211 | + foreach ($table->getColumns() as $column) { |
|
| 212 | + if ($column->getType() instanceof StringType) { |
|
| 213 | + if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) { |
|
| 214 | + $column->setType(Type::getType('text')); |
|
| 215 | + $column->setLength(null); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $filterExpression = $this->getFilterExpression(); |
|
| 222 | + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 223 | + $sourceSchema = $connection->getSchemaManager()->createSchema(); |
|
| 224 | + |
|
| 225 | + // remove tables we don't know about |
|
| 226 | + /** @var $table \Doctrine\DBAL\Schema\Table */ |
|
| 227 | + foreach ($sourceSchema->getTables() as $table) { |
|
| 228 | + if (!$targetSchema->hasTable($table->getName())) { |
|
| 229 | + $sourceSchema->dropTable($table->getName()); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + // remove sequences we don't know about |
|
| 233 | + foreach ($sourceSchema->getSequences() as $table) { |
|
| 234 | + if (!$targetSchema->hasSequence($table->getName())) { |
|
| 235 | + $sourceSchema->dropSequence($table->getName()); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + $comparator = new Comparator(); |
|
| 240 | + return $comparator->compare($sourceSchema, $targetSchema); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 245 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 246 | + */ |
|
| 247 | + protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) { |
|
| 248 | + if (is_null($connection)) { |
|
| 249 | + $connection = $this->connection; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $schemaDiff = $this->getDiff($targetSchema, $connection); |
|
| 253 | + |
|
| 254 | + $connection->beginTransaction(); |
|
| 255 | + $sqls = $schemaDiff->toSql($connection->getDatabasePlatform()); |
|
| 256 | + $step = 0; |
|
| 257 | + foreach ($sqls as $sql) { |
|
| 258 | + $this->emit($sql, $step++, count($sqls)); |
|
| 259 | + $connection->query($sql); |
|
| 260 | + } |
|
| 261 | + $connection->commit(); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @param string $sourceName |
|
| 266 | + * @param string $targetName |
|
| 267 | + */ |
|
| 268 | + protected function copyTable($sourceName, $targetName) { |
|
| 269 | + $quotedSource = $this->connection->quoteIdentifier($sourceName); |
|
| 270 | + $quotedTarget = $this->connection->quoteIdentifier($targetName); |
|
| 271 | + |
|
| 272 | + $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')'); |
|
| 273 | + $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @param string $name |
|
| 278 | + */ |
|
| 279 | + protected function dropTable($name) { |
|
| 280 | + $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name)); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @param $statement |
|
| 285 | + * @return string |
|
| 286 | + */ |
|
| 287 | + protected function convertStatementToScript($statement) { |
|
| 288 | + $script = $statement . ';'; |
|
| 289 | + $script .= PHP_EOL; |
|
| 290 | + $script .= PHP_EOL; |
|
| 291 | + return $script; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + protected function getFilterExpression() { |
|
| 295 | + return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + protected function emit($sql, $step, $max) { |
|
| 299 | + if ($this->noEmit) { |
|
| 300 | + return; |
|
| 301 | + } |
|
| 302 | + if(is_null($this->dispatcher)) { |
|
| 303 | + return; |
|
| 304 | + } |
|
| 305 | + $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + private function emitCheckStep($tableName, $step, $max) { |
|
| 309 | + if(is_null($this->dispatcher)) { |
|
| 310 | + return; |
|
| 311 | + } |
|
| 312 | + $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max])); |
|
| 313 | + } |
|
| 314 | 314 | } |
@@ -1104,7 +1104,7 @@ |
||
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | /** |
| 1107 | - * @param array $reqs |
|
| 1107 | + * @param string[] $reqs |
|
| 1108 | 1108 | * @return bool |
| 1109 | 1109 | */ |
| 1110 | 1110 | private function checkRequirements($reqs) { |
@@ -42,1320 +42,1320 @@ |
||
| 42 | 42 | use OCP\ILogger; |
| 43 | 43 | |
| 44 | 44 | class Wizard extends LDAPUtility { |
| 45 | - /** @var \OCP\IL10N */ |
|
| 46 | - static protected $l; |
|
| 47 | - protected $access; |
|
| 48 | - protected $cr; |
|
| 49 | - protected $configuration; |
|
| 50 | - protected $result; |
|
| 51 | - protected $resultCache = array(); |
|
| 52 | - |
|
| 53 | - const LRESULT_PROCESSED_OK = 2; |
|
| 54 | - const LRESULT_PROCESSED_INVALID = 3; |
|
| 55 | - const LRESULT_PROCESSED_SKIP = 4; |
|
| 56 | - |
|
| 57 | - const LFILTER_LOGIN = 2; |
|
| 58 | - const LFILTER_USER_LIST = 3; |
|
| 59 | - const LFILTER_GROUP_LIST = 4; |
|
| 60 | - |
|
| 61 | - const LFILTER_MODE_ASSISTED = 2; |
|
| 62 | - const LFILTER_MODE_RAW = 1; |
|
| 63 | - |
|
| 64 | - const LDAP_NW_TIMEOUT = 4; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Constructor |
|
| 68 | - * @param Configuration $configuration an instance of Configuration |
|
| 69 | - * @param ILDAPWrapper $ldap an instance of ILDAPWrapper |
|
| 70 | - * @param Access $access |
|
| 71 | - */ |
|
| 72 | - public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) { |
|
| 73 | - parent::__construct($ldap); |
|
| 74 | - $this->configuration = $configuration; |
|
| 75 | - if(is_null(Wizard::$l)) { |
|
| 76 | - Wizard::$l = \OC::$server->getL10N('user_ldap'); |
|
| 77 | - } |
|
| 78 | - $this->access = $access; |
|
| 79 | - $this->result = new WizardResult(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function __destruct() { |
|
| 83 | - if($this->result->hasChanges()) { |
|
| 84 | - $this->configuration->saveConfiguration(); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * counts entries in the LDAP directory |
|
| 90 | - * |
|
| 91 | - * @param string $filter the LDAP search filter |
|
| 92 | - * @param string $type a string being either 'users' or 'groups'; |
|
| 93 | - * @return int |
|
| 94 | - * @throws \Exception |
|
| 95 | - */ |
|
| 96 | - public function countEntries(string $filter, string $type): int { |
|
| 97 | - $reqs = ['ldapHost', 'ldapPort', 'ldapBase']; |
|
| 98 | - if($type === 'users') { |
|
| 99 | - $reqs[] = 'ldapUserFilter'; |
|
| 100 | - } |
|
| 101 | - if(!$this->checkRequirements($reqs)) { |
|
| 102 | - throw new \Exception('Requirements not met', 400); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $attr = ['dn']; // default |
|
| 106 | - $limit = 1001; |
|
| 107 | - if($type === 'groups') { |
|
| 108 | - $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 109 | - } else if($type === 'users') { |
|
| 110 | - $result = $this->access->countUsers($filter, $attr, $limit); |
|
| 111 | - } else if ($type === 'objects') { |
|
| 112 | - $result = $this->access->countObjects($limit); |
|
| 113 | - } else { |
|
| 114 | - throw new \Exception('Internal error: Invalid object type', 500); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return (int)$result; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * formats the return value of a count operation to the string to be |
|
| 122 | - * inserted. |
|
| 123 | - * |
|
| 124 | - * @param int $count |
|
| 125 | - * @return string |
|
| 126 | - */ |
|
| 127 | - private function formatCountResult(int $count): string { |
|
| 128 | - if($count > 1000) { |
|
| 129 | - return '> 1000'; |
|
| 130 | - } |
|
| 131 | - return (string)$count; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function countGroups() { |
|
| 135 | - $filter = $this->configuration->ldapGroupFilter; |
|
| 136 | - |
|
| 137 | - if(empty($filter)) { |
|
| 138 | - $output = self::$l->n('%s group found', '%s groups found', 0, array(0)); |
|
| 139 | - $this->result->addChange('ldap_group_count', $output); |
|
| 140 | - return $this->result; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - try { |
|
| 144 | - $groupsTotal = $this->countEntries($filter, 'groups'); |
|
| 145 | - } catch (\Exception $e) { |
|
| 146 | - //400 can be ignored, 500 is forwarded |
|
| 147 | - if($e->getCode() === 500) { |
|
| 148 | - throw $e; |
|
| 149 | - } |
|
| 150 | - return false; |
|
| 151 | - } |
|
| 152 | - $output = self::$l->n( |
|
| 153 | - '%s group found', |
|
| 154 | - '%s groups found', |
|
| 155 | - $groupsTotal, |
|
| 156 | - [$this->formatCountResult($groupsTotal)] |
|
| 157 | - ); |
|
| 158 | - $this->result->addChange('ldap_group_count', $output); |
|
| 159 | - return $this->result; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return WizardResult |
|
| 164 | - * @throws \Exception |
|
| 165 | - */ |
|
| 166 | - public function countUsers() { |
|
| 167 | - $filter = $this->access->getFilterForUserCount(); |
|
| 168 | - |
|
| 169 | - $usersTotal = $this->countEntries($filter, 'users'); |
|
| 170 | - $output = self::$l->n( |
|
| 171 | - '%s user found', |
|
| 172 | - '%s users found', |
|
| 173 | - $usersTotal, |
|
| 174 | - [$this->formatCountResult($usersTotal)] |
|
| 175 | - ); |
|
| 176 | - $this->result->addChange('ldap_user_count', $output); |
|
| 177 | - return $this->result; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * counts any objects in the currently set base dn |
|
| 182 | - * |
|
| 183 | - * @return WizardResult |
|
| 184 | - * @throws \Exception |
|
| 185 | - */ |
|
| 186 | - public function countInBaseDN() { |
|
| 187 | - // we don't need to provide a filter in this case |
|
| 188 | - $total = $this->countEntries('', 'objects'); |
|
| 189 | - if($total === false) { |
|
| 190 | - throw new \Exception('invalid results received'); |
|
| 191 | - } |
|
| 192 | - $this->result->addChange('ldap_test_base', $total); |
|
| 193 | - return $this->result; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * counts users with a specified attribute |
|
| 198 | - * @param string $attr |
|
| 199 | - * @param bool $existsCheck |
|
| 200 | - * @return int|bool |
|
| 201 | - */ |
|
| 202 | - public function countUsersWithAttribute($attr, $existsCheck = false) { |
|
| 203 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 204 | - 'ldapPort', |
|
| 205 | - 'ldapBase', |
|
| 206 | - 'ldapUserFilter', |
|
| 207 | - ))) { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $filter = $this->access->combineFilterWithAnd(array( |
|
| 212 | - $this->configuration->ldapUserFilter, |
|
| 213 | - $attr . '=*' |
|
| 214 | - )); |
|
| 215 | - |
|
| 216 | - $limit = ($existsCheck === false) ? null : 1; |
|
| 217 | - |
|
| 218 | - return $this->access->countUsers($filter, array('dn'), $limit); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * detects the display name attribute. If a setting is already present that |
|
| 223 | - * returns at least one hit, the detection will be canceled. |
|
| 224 | - * @return WizardResult|bool |
|
| 225 | - * @throws \Exception |
|
| 226 | - */ |
|
| 227 | - public function detectUserDisplayNameAttribute() { |
|
| 228 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 229 | - 'ldapPort', |
|
| 230 | - 'ldapBase', |
|
| 231 | - 'ldapUserFilter', |
|
| 232 | - ))) { |
|
| 233 | - return false; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - $attr = $this->configuration->ldapUserDisplayName; |
|
| 237 | - if ($attr !== '' && $attr !== 'displayName') { |
|
| 238 | - // most likely not the default value with upper case N, |
|
| 239 | - // verify it still produces a result |
|
| 240 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 241 | - if($count > 0) { |
|
| 242 | - //no change, but we sent it back to make sure the user interface |
|
| 243 | - //is still correct, even if the ajax call was cancelled meanwhile |
|
| 244 | - $this->result->addChange('ldap_display_name', $attr); |
|
| 245 | - return $this->result; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // first attribute that has at least one result wins |
|
| 250 | - $displayNameAttrs = array('displayname', 'cn'); |
|
| 251 | - foreach ($displayNameAttrs as $attr) { |
|
| 252 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 253 | - |
|
| 254 | - if($count > 0) { |
|
| 255 | - $this->applyFind('ldap_display_name', $attr); |
|
| 256 | - return $this->result; |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - throw new \Exception(self::$l->t('Could not detect user display name attribute. Please specify it yourself in advanced LDAP settings.')); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * detects the most often used email attribute for users applying to the |
|
| 265 | - * user list filter. If a setting is already present that returns at least |
|
| 266 | - * one hit, the detection will be canceled. |
|
| 267 | - * @return WizardResult|bool |
|
| 268 | - */ |
|
| 269 | - public function detectEmailAttribute() { |
|
| 270 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 271 | - 'ldapPort', |
|
| 272 | - 'ldapBase', |
|
| 273 | - 'ldapUserFilter', |
|
| 274 | - ))) { |
|
| 275 | - return false; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - $attr = $this->configuration->ldapEmailAttribute; |
|
| 279 | - if ($attr !== '') { |
|
| 280 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 281 | - if($count > 0) { |
|
| 282 | - return false; |
|
| 283 | - } |
|
| 284 | - $writeLog = true; |
|
| 285 | - } else { |
|
| 286 | - $writeLog = false; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - $emailAttributes = array('mail', 'mailPrimaryAddress'); |
|
| 290 | - $winner = ''; |
|
| 291 | - $maxUsers = 0; |
|
| 292 | - foreach($emailAttributes as $attr) { |
|
| 293 | - $count = $this->countUsersWithAttribute($attr); |
|
| 294 | - if($count > $maxUsers) { |
|
| 295 | - $maxUsers = $count; |
|
| 296 | - $winner = $attr; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - if($winner !== '') { |
|
| 301 | - $this->applyFind('ldap_email_attr', $winner); |
|
| 302 | - if($writeLog) { |
|
| 303 | - \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . |
|
| 304 | - 'automatically been reset, because the original value ' . |
|
| 305 | - 'did not return any results.', ILogger::INFO); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - return $this->result; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @return WizardResult |
|
| 314 | - * @throws \Exception |
|
| 315 | - */ |
|
| 316 | - public function determineAttributes() { |
|
| 317 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 318 | - 'ldapPort', |
|
| 319 | - 'ldapBase', |
|
| 320 | - 'ldapUserFilter', |
|
| 321 | - ))) { |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - $attributes = $this->getUserAttributes(); |
|
| 326 | - |
|
| 327 | - natcasesort($attributes); |
|
| 328 | - $attributes = array_values($attributes); |
|
| 329 | - |
|
| 330 | - $this->result->addOptions('ldap_loginfilter_attributes', $attributes); |
|
| 331 | - |
|
| 332 | - $selected = $this->configuration->ldapLoginFilterAttributes; |
|
| 333 | - if(is_array($selected) && !empty($selected)) { |
|
| 334 | - $this->result->addChange('ldap_loginfilter_attributes', $selected); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return $this->result; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * detects the available LDAP attributes |
|
| 342 | - * @return array|false The instance's WizardResult instance |
|
| 343 | - * @throws \Exception |
|
| 344 | - */ |
|
| 345 | - private function getUserAttributes() { |
|
| 346 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 347 | - 'ldapPort', |
|
| 348 | - 'ldapBase', |
|
| 349 | - 'ldapUserFilter', |
|
| 350 | - ))) { |
|
| 351 | - return false; |
|
| 352 | - } |
|
| 353 | - $cr = $this->getConnection(); |
|
| 354 | - if(!$cr) { |
|
| 355 | - throw new \Exception('Could not connect to LDAP'); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - $base = $this->configuration->ldapBase[0]; |
|
| 359 | - $filter = $this->configuration->ldapUserFilter; |
|
| 360 | - $rr = $this->ldap->search($cr, $base, $filter, array(), 1, 1); |
|
| 361 | - if(!$this->ldap->isResource($rr)) { |
|
| 362 | - return false; |
|
| 363 | - } |
|
| 364 | - $er = $this->ldap->firstEntry($cr, $rr); |
|
| 365 | - $attributes = $this->ldap->getAttributes($cr, $er); |
|
| 366 | - $pureAttributes = array(); |
|
| 367 | - for($i = 0; $i < $attributes['count']; $i++) { |
|
| 368 | - $pureAttributes[] = $attributes[$i]; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return $pureAttributes; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * detects the available LDAP groups |
|
| 376 | - * @return WizardResult|false the instance's WizardResult instance |
|
| 377 | - */ |
|
| 378 | - public function determineGroupsForGroups() { |
|
| 379 | - return $this->determineGroups('ldap_groupfilter_groups', |
|
| 380 | - 'ldapGroupFilterGroups', |
|
| 381 | - false); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * detects the available LDAP groups |
|
| 386 | - * @return WizardResult|false the instance's WizardResult instance |
|
| 387 | - */ |
|
| 388 | - public function determineGroupsForUsers() { |
|
| 389 | - return $this->determineGroups('ldap_userfilter_groups', |
|
| 390 | - 'ldapUserFilterGroups'); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * detects the available LDAP groups |
|
| 395 | - * @param string $dbKey |
|
| 396 | - * @param string $confKey |
|
| 397 | - * @param bool $testMemberOf |
|
| 398 | - * @return WizardResult|false the instance's WizardResult instance |
|
| 399 | - * @throws \Exception |
|
| 400 | - */ |
|
| 401 | - private function determineGroups($dbKey, $confKey, $testMemberOf = true) { |
|
| 402 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 403 | - 'ldapPort', |
|
| 404 | - 'ldapBase', |
|
| 405 | - ))) { |
|
| 406 | - return false; |
|
| 407 | - } |
|
| 408 | - $cr = $this->getConnection(); |
|
| 409 | - if(!$cr) { |
|
| 410 | - throw new \Exception('Could not connect to LDAP'); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - $this->fetchGroups($dbKey, $confKey); |
|
| 414 | - |
|
| 415 | - if($testMemberOf) { |
|
| 416 | - $this->configuration->hasMemberOfFilterSupport = $this->testMemberOf(); |
|
| 417 | - $this->result->markChange(); |
|
| 418 | - if(!$this->configuration->hasMemberOfFilterSupport) { |
|
| 419 | - throw new \Exception('memberOf is not supported by the server'); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $this->result; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * fetches all groups from LDAP and adds them to the result object |
|
| 428 | - * |
|
| 429 | - * @param string $dbKey |
|
| 430 | - * @param string $confKey |
|
| 431 | - * @return array $groupEntries |
|
| 432 | - * @throws \Exception |
|
| 433 | - */ |
|
| 434 | - public function fetchGroups($dbKey, $confKey) { |
|
| 435 | - $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'); |
|
| 436 | - |
|
| 437 | - $filterParts = array(); |
|
| 438 | - foreach($obclasses as $obclass) { |
|
| 439 | - $filterParts[] = 'objectclass='.$obclass; |
|
| 440 | - } |
|
| 441 | - //we filter for everything |
|
| 442 | - //- that looks like a group and |
|
| 443 | - //- has the group display name set |
|
| 444 | - $filter = $this->access->combineFilterWithOr($filterParts); |
|
| 445 | - $filter = $this->access->combineFilterWithAnd(array($filter, 'cn=*')); |
|
| 446 | - |
|
| 447 | - $groupNames = array(); |
|
| 448 | - $groupEntries = array(); |
|
| 449 | - $limit = 400; |
|
| 450 | - $offset = 0; |
|
| 451 | - do { |
|
| 452 | - // we need to request dn additionally here, otherwise memberOf |
|
| 453 | - // detection will fail later |
|
| 454 | - $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); |
|
| 455 | - foreach($result as $item) { |
|
| 456 | - if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 457 | - // just in case - no issue known |
|
| 458 | - continue; |
|
| 459 | - } |
|
| 460 | - $groupNames[] = $item['cn'][0]; |
|
| 461 | - $groupEntries[] = $item; |
|
| 462 | - } |
|
| 463 | - $offset += $limit; |
|
| 464 | - } while ($this->access->hasMoreResults()); |
|
| 465 | - |
|
| 466 | - if(count($groupNames) > 0) { |
|
| 467 | - natsort($groupNames); |
|
| 468 | - $this->result->addOptions($dbKey, array_values($groupNames)); |
|
| 469 | - } else { |
|
| 470 | - throw new \Exception(self::$l->t('Could not find the desired feature')); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - $setFeatures = $this->configuration->$confKey; |
|
| 474 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 475 | - //something is already configured? pre-select it. |
|
| 476 | - $this->result->addChange($dbKey, $setFeatures); |
|
| 477 | - } |
|
| 478 | - return $groupEntries; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - public function determineGroupMemberAssoc() { |
|
| 482 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 483 | - 'ldapPort', |
|
| 484 | - 'ldapGroupFilter', |
|
| 485 | - ))) { |
|
| 486 | - return false; |
|
| 487 | - } |
|
| 488 | - $attribute = $this->detectGroupMemberAssoc(); |
|
| 489 | - if($attribute === false) { |
|
| 490 | - return false; |
|
| 491 | - } |
|
| 492 | - $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute)); |
|
| 493 | - $this->result->addChange('ldap_group_member_assoc_attribute', $attribute); |
|
| 494 | - |
|
| 495 | - return $this->result; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Detects the available object classes |
|
| 500 | - * @return WizardResult|false the instance's WizardResult instance |
|
| 501 | - * @throws \Exception |
|
| 502 | - */ |
|
| 503 | - public function determineGroupObjectClasses() { |
|
| 504 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 505 | - 'ldapPort', |
|
| 506 | - 'ldapBase', |
|
| 507 | - ))) { |
|
| 508 | - return false; |
|
| 509 | - } |
|
| 510 | - $cr = $this->getConnection(); |
|
| 511 | - if(!$cr) { |
|
| 512 | - throw new \Exception('Could not connect to LDAP'); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - $obclasses = array('groupOfNames', 'groupOfUniqueNames', 'group', 'posixGroup', '*'); |
|
| 516 | - $this->determineFeature($obclasses, |
|
| 517 | - 'objectclass', |
|
| 518 | - 'ldap_groupfilter_objectclass', |
|
| 519 | - 'ldapGroupFilterObjectclass', |
|
| 520 | - false); |
|
| 521 | - |
|
| 522 | - return $this->result; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * detects the available object classes |
|
| 527 | - * @return WizardResult |
|
| 528 | - * @throws \Exception |
|
| 529 | - */ |
|
| 530 | - public function determineUserObjectClasses() { |
|
| 531 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 532 | - 'ldapPort', |
|
| 533 | - 'ldapBase', |
|
| 534 | - ))) { |
|
| 535 | - return false; |
|
| 536 | - } |
|
| 537 | - $cr = $this->getConnection(); |
|
| 538 | - if(!$cr) { |
|
| 539 | - throw new \Exception('Could not connect to LDAP'); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - $obclasses = array('inetOrgPerson', 'person', 'organizationalPerson', |
|
| 543 | - 'user', 'posixAccount', '*'); |
|
| 544 | - $filter = $this->configuration->ldapUserFilter; |
|
| 545 | - //if filter is empty, it is probably the first time the wizard is called |
|
| 546 | - //then, apply suggestions. |
|
| 547 | - $this->determineFeature($obclasses, |
|
| 548 | - 'objectclass', |
|
| 549 | - 'ldap_userfilter_objectclass', |
|
| 550 | - 'ldapUserFilterObjectclass', |
|
| 551 | - empty($filter)); |
|
| 552 | - |
|
| 553 | - return $this->result; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * @return WizardResult|false |
|
| 558 | - * @throws \Exception |
|
| 559 | - */ |
|
| 560 | - public function getGroupFilter() { |
|
| 561 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 562 | - 'ldapPort', |
|
| 563 | - 'ldapBase', |
|
| 564 | - ))) { |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - //make sure the use display name is set |
|
| 568 | - $displayName = $this->configuration->ldapGroupDisplayName; |
|
| 569 | - if ($displayName === '') { |
|
| 570 | - $d = $this->configuration->getDefaults(); |
|
| 571 | - $this->applyFind('ldap_group_display_name', |
|
| 572 | - $d['ldap_group_display_name']); |
|
| 573 | - } |
|
| 574 | - $filter = $this->composeLdapFilter(self::LFILTER_GROUP_LIST); |
|
| 575 | - |
|
| 576 | - $this->applyFind('ldap_group_filter', $filter); |
|
| 577 | - return $this->result; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * @return WizardResult|false |
|
| 582 | - * @throws \Exception |
|
| 583 | - */ |
|
| 584 | - public function getUserListFilter() { |
|
| 585 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 586 | - 'ldapPort', |
|
| 587 | - 'ldapBase', |
|
| 588 | - ))) { |
|
| 589 | - return false; |
|
| 590 | - } |
|
| 591 | - //make sure the use display name is set |
|
| 592 | - $displayName = $this->configuration->ldapUserDisplayName; |
|
| 593 | - if ($displayName === '') { |
|
| 594 | - $d = $this->configuration->getDefaults(); |
|
| 595 | - $this->applyFind('ldap_display_name', $d['ldap_display_name']); |
|
| 596 | - } |
|
| 597 | - $filter = $this->composeLdapFilter(self::LFILTER_USER_LIST); |
|
| 598 | - if(!$filter) { |
|
| 599 | - throw new \Exception('Cannot create filter'); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - $this->applyFind('ldap_userlist_filter', $filter); |
|
| 603 | - return $this->result; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * @return bool|WizardResult |
|
| 608 | - * @throws \Exception |
|
| 609 | - */ |
|
| 610 | - public function getUserLoginFilter() { |
|
| 611 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 612 | - 'ldapPort', |
|
| 613 | - 'ldapBase', |
|
| 614 | - 'ldapUserFilter', |
|
| 615 | - ))) { |
|
| 616 | - return false; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - $filter = $this->composeLdapFilter(self::LFILTER_LOGIN); |
|
| 620 | - if(!$filter) { |
|
| 621 | - throw new \Exception('Cannot create filter'); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - $this->applyFind('ldap_login_filter', $filter); |
|
| 625 | - return $this->result; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * @return bool|WizardResult |
|
| 630 | - * @param string $loginName |
|
| 631 | - * @throws \Exception |
|
| 632 | - */ |
|
| 633 | - public function testLoginName($loginName) { |
|
| 634 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 635 | - 'ldapPort', |
|
| 636 | - 'ldapBase', |
|
| 637 | - 'ldapLoginFilter', |
|
| 638 | - ))) { |
|
| 639 | - return false; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $cr = $this->access->connection->getConnectionResource(); |
|
| 643 | - if(!$this->ldap->isResource($cr)) { |
|
| 644 | - throw new \Exception('connection error'); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 648 | - === false) { |
|
| 649 | - throw new \Exception('missing placeholder'); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - $users = $this->access->countUsersByLoginName($loginName); |
|
| 653 | - if($this->ldap->errno($cr) !== 0) { |
|
| 654 | - throw new \Exception($this->ldap->error($cr)); |
|
| 655 | - } |
|
| 656 | - $filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter); |
|
| 657 | - $this->result->addChange('ldap_test_loginname', $users); |
|
| 658 | - $this->result->addChange('ldap_test_effective_filter', $filter); |
|
| 659 | - return $this->result; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * Tries to determine the port, requires given Host, User DN and Password |
|
| 664 | - * @return WizardResult|false WizardResult on success, false otherwise |
|
| 665 | - * @throws \Exception |
|
| 666 | - */ |
|
| 667 | - public function guessPortAndTLS() { |
|
| 668 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 669 | - ))) { |
|
| 670 | - return false; |
|
| 671 | - } |
|
| 672 | - $this->checkHost(); |
|
| 673 | - $portSettings = $this->getPortSettingsToTry(); |
|
| 674 | - |
|
| 675 | - if(!is_array($portSettings)) { |
|
| 676 | - throw new \Exception(print_r($portSettings, true)); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - //proceed from the best configuration and return on first success |
|
| 680 | - foreach($portSettings as $setting) { |
|
| 681 | - $p = $setting['port']; |
|
| 682 | - $t = $setting['tls']; |
|
| 683 | - \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, ILogger::DEBUG); |
|
| 684 | - //connectAndBind may throw Exception, it needs to be catched by the |
|
| 685 | - //callee of this method |
|
| 686 | - |
|
| 687 | - try { |
|
| 688 | - $settingsFound = $this->connectAndBind($p, $t); |
|
| 689 | - } catch (\Exception $e) { |
|
| 690 | - // any reply other than -1 (= cannot connect) is already okay, |
|
| 691 | - // because then we found the server |
|
| 692 | - // unavailable startTLS returns -11 |
|
| 693 | - if($e->getCode() > 0) { |
|
| 694 | - $settingsFound = true; |
|
| 695 | - } else { |
|
| 696 | - throw $e; |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - if ($settingsFound === true) { |
|
| 701 | - $config = array( |
|
| 702 | - 'ldapPort' => $p, |
|
| 703 | - 'ldapTLS' => (int)$t |
|
| 704 | - ); |
|
| 705 | - $this->configuration->setConfiguration($config); |
|
| 706 | - \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, ILogger::DEBUG); |
|
| 707 | - $this->result->addChange('ldap_port', $p); |
|
| 708 | - return $this->result; |
|
| 709 | - } |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - //custom port, undetected (we do not brute force) |
|
| 713 | - return false; |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - /** |
|
| 717 | - * tries to determine a base dn from User DN or LDAP Host |
|
| 718 | - * @return WizardResult|false WizardResult on success, false otherwise |
|
| 719 | - */ |
|
| 720 | - public function guessBaseDN() { |
|
| 721 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 722 | - 'ldapPort', |
|
| 723 | - ))) { |
|
| 724 | - return false; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - //check whether a DN is given in the agent name (99.9% of all cases) |
|
| 728 | - $base = null; |
|
| 729 | - $i = stripos($this->configuration->ldapAgentName, 'dc='); |
|
| 730 | - if($i !== false) { |
|
| 731 | - $base = substr($this->configuration->ldapAgentName, $i); |
|
| 732 | - if($this->testBaseDN($base)) { |
|
| 733 | - $this->applyFind('ldap_base', $base); |
|
| 734 | - return $this->result; |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - //this did not help :( |
|
| 739 | - //Let's see whether we can parse the Host URL and convert the domain to |
|
| 740 | - //a base DN |
|
| 741 | - $helper = new Helper(\OC::$server->getConfig()); |
|
| 742 | - $domain = $helper->getDomainFromURL($this->configuration->ldapHost); |
|
| 743 | - if(!$domain) { |
|
| 744 | - return false; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - $dparts = explode('.', $domain); |
|
| 748 | - while(count($dparts) > 0) { |
|
| 749 | - $base2 = 'dc=' . implode(',dc=', $dparts); |
|
| 750 | - if ($base !== $base2 && $this->testBaseDN($base2)) { |
|
| 751 | - $this->applyFind('ldap_base', $base2); |
|
| 752 | - return $this->result; |
|
| 753 | - } |
|
| 754 | - array_shift($dparts); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - return false; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - /** |
|
| 761 | - * sets the found value for the configuration key in the WizardResult |
|
| 762 | - * as well as in the Configuration instance |
|
| 763 | - * @param string $key the configuration key |
|
| 764 | - * @param string $value the (detected) value |
|
| 765 | - * |
|
| 766 | - */ |
|
| 767 | - private function applyFind($key, $value) { |
|
| 768 | - $this->result->addChange($key, $value); |
|
| 769 | - $this->configuration->setConfiguration(array($key => $value)); |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * Checks, whether a port was entered in the Host configuration |
|
| 774 | - * field. In this case the port will be stripped off, but also stored as |
|
| 775 | - * setting. |
|
| 776 | - */ |
|
| 777 | - private function checkHost() { |
|
| 778 | - $host = $this->configuration->ldapHost; |
|
| 779 | - $hostInfo = parse_url($host); |
|
| 780 | - |
|
| 781 | - //removes Port from Host |
|
| 782 | - if(is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 783 | - $port = $hostInfo['port']; |
|
| 784 | - $host = str_replace(':'.$port, '', $host); |
|
| 785 | - $this->applyFind('ldap_host', $host); |
|
| 786 | - $this->applyFind('ldap_port', $port); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - /** |
|
| 791 | - * tries to detect the group member association attribute which is |
|
| 792 | - * one of 'uniqueMember', 'memberUid', 'member', 'gidNumber' |
|
| 793 | - * @return string|false, string with the attribute name, false on error |
|
| 794 | - * @throws \Exception |
|
| 795 | - */ |
|
| 796 | - private function detectGroupMemberAssoc() { |
|
| 797 | - $possibleAttrs = array('uniqueMember', 'memberUid', 'member', 'gidNumber'); |
|
| 798 | - $filter = $this->configuration->ldapGroupFilter; |
|
| 799 | - if(empty($filter)) { |
|
| 800 | - return false; |
|
| 801 | - } |
|
| 802 | - $cr = $this->getConnection(); |
|
| 803 | - if(!$cr) { |
|
| 804 | - throw new \Exception('Could not connect to LDAP'); |
|
| 805 | - } |
|
| 806 | - $base = $this->configuration->ldapBase[0]; |
|
| 807 | - $rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000); |
|
| 808 | - if(!$this->ldap->isResource($rr)) { |
|
| 809 | - return false; |
|
| 810 | - } |
|
| 811 | - $er = $this->ldap->firstEntry($cr, $rr); |
|
| 812 | - while(is_resource($er)) { |
|
| 813 | - $this->ldap->getDN($cr, $er); |
|
| 814 | - $attrs = $this->ldap->getAttributes($cr, $er); |
|
| 815 | - $result = array(); |
|
| 816 | - $possibleAttrsCount = count($possibleAttrs); |
|
| 817 | - for($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 818 | - if(isset($attrs[$possibleAttrs[$i]])) { |
|
| 819 | - $result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count']; |
|
| 820 | - } |
|
| 821 | - } |
|
| 822 | - if(!empty($result)) { |
|
| 823 | - natsort($result); |
|
| 824 | - return key($result); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - $er = $this->ldap->nextEntry($cr, $er); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - return false; |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * Checks whether for a given BaseDN results will be returned |
|
| 835 | - * @param string $base the BaseDN to test |
|
| 836 | - * @return bool true on success, false otherwise |
|
| 837 | - * @throws \Exception |
|
| 838 | - */ |
|
| 839 | - private function testBaseDN($base) { |
|
| 840 | - $cr = $this->getConnection(); |
|
| 841 | - if(!$cr) { |
|
| 842 | - throw new \Exception('Could not connect to LDAP'); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - //base is there, let's validate it. If we search for anything, we should |
|
| 846 | - //get a result set > 0 on a proper base |
|
| 847 | - $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); |
|
| 848 | - if(!$this->ldap->isResource($rr)) { |
|
| 849 | - $errorNo = $this->ldap->errno($cr); |
|
| 850 | - $errorMsg = $this->ldap->error($cr); |
|
| 851 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. |
|
| 852 | - ' Error '.$errorNo.': '.$errorMsg, ILogger::INFO); |
|
| 853 | - return false; |
|
| 854 | - } |
|
| 855 | - $entries = $this->ldap->countEntries($cr, $rr); |
|
| 856 | - return ($entries !== false) && ($entries > 0); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * Checks whether the server supports memberOf in LDAP Filter. |
|
| 861 | - * Note: at least in OpenLDAP, availability of memberOf is dependent on |
|
| 862 | - * a configured objectClass. I.e. not necessarily for all available groups |
|
| 863 | - * memberOf does work. |
|
| 864 | - * |
|
| 865 | - * @return bool true if it does, false otherwise |
|
| 866 | - * @throws \Exception |
|
| 867 | - */ |
|
| 868 | - private function testMemberOf() { |
|
| 869 | - $cr = $this->getConnection(); |
|
| 870 | - if(!$cr) { |
|
| 871 | - throw new \Exception('Could not connect to LDAP'); |
|
| 872 | - } |
|
| 873 | - $result = $this->access->countUsers('memberOf=*', array('memberOf'), 1); |
|
| 874 | - if(is_int($result) && $result > 0) { |
|
| 875 | - return true; |
|
| 876 | - } |
|
| 877 | - return false; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * creates an LDAP Filter from given configuration |
|
| 882 | - * @param integer $filterType int, for which use case the filter shall be created |
|
| 883 | - * can be any of self::LFILTER_USER_LIST, self::LFILTER_LOGIN or |
|
| 884 | - * self::LFILTER_GROUP_LIST |
|
| 885 | - * @return string|false string with the filter on success, false otherwise |
|
| 886 | - * @throws \Exception |
|
| 887 | - */ |
|
| 888 | - private function composeLdapFilter($filterType) { |
|
| 889 | - $filter = ''; |
|
| 890 | - $parts = 0; |
|
| 891 | - switch ($filterType) { |
|
| 892 | - case self::LFILTER_USER_LIST: |
|
| 893 | - $objcs = $this->configuration->ldapUserFilterObjectclass; |
|
| 894 | - //glue objectclasses |
|
| 895 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 896 | - $filter .= '(|'; |
|
| 897 | - foreach($objcs as $objc) { |
|
| 898 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 899 | - } |
|
| 900 | - $filter .= ')'; |
|
| 901 | - $parts++; |
|
| 902 | - } |
|
| 903 | - //glue group memberships |
|
| 904 | - if($this->configuration->hasMemberOfFilterSupport) { |
|
| 905 | - $cns = $this->configuration->ldapUserFilterGroups; |
|
| 906 | - if(is_array($cns) && count($cns) > 0) { |
|
| 907 | - $filter .= '(|'; |
|
| 908 | - $cr = $this->getConnection(); |
|
| 909 | - if(!$cr) { |
|
| 910 | - throw new \Exception('Could not connect to LDAP'); |
|
| 911 | - } |
|
| 912 | - $base = $this->configuration->ldapBase[0]; |
|
| 913 | - foreach($cns as $cn) { |
|
| 914 | - $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, array('dn', 'primaryGroupToken')); |
|
| 915 | - if(!$this->ldap->isResource($rr)) { |
|
| 916 | - continue; |
|
| 917 | - } |
|
| 918 | - $er = $this->ldap->firstEntry($cr, $rr); |
|
| 919 | - $attrs = $this->ldap->getAttributes($cr, $er); |
|
| 920 | - $dn = $this->ldap->getDN($cr, $er); |
|
| 921 | - if ($dn === false || $dn === '') { |
|
| 922 | - continue; |
|
| 923 | - } |
|
| 924 | - $filterPart = '(memberof=' . $dn . ')'; |
|
| 925 | - if(isset($attrs['primaryGroupToken'])) { |
|
| 926 | - $pgt = $attrs['primaryGroupToken'][0]; |
|
| 927 | - $primaryFilterPart = '(primaryGroupID=' . $pgt .')'; |
|
| 928 | - $filterPart = '(|' . $filterPart . $primaryFilterPart . ')'; |
|
| 929 | - } |
|
| 930 | - $filter .= $filterPart; |
|
| 931 | - } |
|
| 932 | - $filter .= ')'; |
|
| 933 | - } |
|
| 934 | - $parts++; |
|
| 935 | - } |
|
| 936 | - //wrap parts in AND condition |
|
| 937 | - if($parts > 1) { |
|
| 938 | - $filter = '(&' . $filter . ')'; |
|
| 939 | - } |
|
| 940 | - if ($filter === '') { |
|
| 941 | - $filter = '(objectclass=*)'; |
|
| 942 | - } |
|
| 943 | - break; |
|
| 944 | - |
|
| 945 | - case self::LFILTER_GROUP_LIST: |
|
| 946 | - $objcs = $this->configuration->ldapGroupFilterObjectclass; |
|
| 947 | - //glue objectclasses |
|
| 948 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 949 | - $filter .= '(|'; |
|
| 950 | - foreach($objcs as $objc) { |
|
| 951 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 952 | - } |
|
| 953 | - $filter .= ')'; |
|
| 954 | - $parts++; |
|
| 955 | - } |
|
| 956 | - //glue group memberships |
|
| 957 | - $cns = $this->configuration->ldapGroupFilterGroups; |
|
| 958 | - if(is_array($cns) && count($cns) > 0) { |
|
| 959 | - $filter .= '(|'; |
|
| 960 | - foreach($cns as $cn) { |
|
| 961 | - $filter .= '(cn=' . $cn . ')'; |
|
| 962 | - } |
|
| 963 | - $filter .= ')'; |
|
| 964 | - } |
|
| 965 | - $parts++; |
|
| 966 | - //wrap parts in AND condition |
|
| 967 | - if($parts > 1) { |
|
| 968 | - $filter = '(&' . $filter . ')'; |
|
| 969 | - } |
|
| 970 | - break; |
|
| 971 | - |
|
| 972 | - case self::LFILTER_LOGIN: |
|
| 973 | - $ulf = $this->configuration->ldapUserFilter; |
|
| 974 | - $loginpart = '=%uid'; |
|
| 975 | - $filterUsername = ''; |
|
| 976 | - $userAttributes = $this->getUserAttributes(); |
|
| 977 | - $userAttributes = array_change_key_case(array_flip($userAttributes)); |
|
| 978 | - $parts = 0; |
|
| 979 | - |
|
| 980 | - if($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 981 | - $attr = ''; |
|
| 982 | - if(isset($userAttributes['uid'])) { |
|
| 983 | - $attr = 'uid'; |
|
| 984 | - } else if(isset($userAttributes['samaccountname'])) { |
|
| 985 | - $attr = 'samaccountname'; |
|
| 986 | - } else if(isset($userAttributes['cn'])) { |
|
| 987 | - //fallback |
|
| 988 | - $attr = 'cn'; |
|
| 989 | - } |
|
| 990 | - if ($attr !== '') { |
|
| 991 | - $filterUsername = '(' . $attr . $loginpart . ')'; |
|
| 992 | - $parts++; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - |
|
| 996 | - $filterEmail = ''; |
|
| 997 | - if($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 998 | - $filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))'; |
|
| 999 | - $parts++; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - $filterAttributes = ''; |
|
| 1003 | - $attrsToFilter = $this->configuration->ldapLoginFilterAttributes; |
|
| 1004 | - if(is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 1005 | - $filterAttributes = '(|'; |
|
| 1006 | - foreach($attrsToFilter as $attribute) { |
|
| 1007 | - $filterAttributes .= '(' . $attribute . $loginpart . ')'; |
|
| 1008 | - } |
|
| 1009 | - $filterAttributes .= ')'; |
|
| 1010 | - $parts++; |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - $filterLogin = ''; |
|
| 1014 | - if($parts > 1) { |
|
| 1015 | - $filterLogin = '(|'; |
|
| 1016 | - } |
|
| 1017 | - $filterLogin .= $filterUsername; |
|
| 1018 | - $filterLogin .= $filterEmail; |
|
| 1019 | - $filterLogin .= $filterAttributes; |
|
| 1020 | - if($parts > 1) { |
|
| 1021 | - $filterLogin .= ')'; |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - $filter = '(&'.$ulf.$filterLogin.')'; |
|
| 1025 | - break; |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Final filter '.$filter, ILogger::DEBUG); |
|
| 1029 | - |
|
| 1030 | - return $filter; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * Connects and Binds to an LDAP Server |
|
| 1035 | - * |
|
| 1036 | - * @param int $port the port to connect with |
|
| 1037 | - * @param bool $tls whether startTLS is to be used |
|
| 1038 | - * @return bool |
|
| 1039 | - * @throws \Exception |
|
| 1040 | - */ |
|
| 1041 | - private function connectAndBind($port, $tls) { |
|
| 1042 | - //connect, does not really trigger any server communication |
|
| 1043 | - $host = $this->configuration->ldapHost; |
|
| 1044 | - $hostInfo = parse_url($host); |
|
| 1045 | - if(!$hostInfo) { |
|
| 1046 | - throw new \Exception(self::$l->t('Invalid Host')); |
|
| 1047 | - } |
|
| 1048 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', ILogger::DEBUG); |
|
| 1049 | - $cr = $this->ldap->connect($host, $port); |
|
| 1050 | - if(!is_resource($cr)) { |
|
| 1051 | - throw new \Exception(self::$l->t('Invalid Host')); |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - //set LDAP options |
|
| 1055 | - $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
| 1056 | - $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
|
| 1057 | - $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
|
| 1058 | - |
|
| 1059 | - try { |
|
| 1060 | - if($tls) { |
|
| 1061 | - $isTlsWorking = @$this->ldap->startTls($cr); |
|
| 1062 | - if(!$isTlsWorking) { |
|
| 1063 | - return false; |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Attemping to Bind ', ILogger::DEBUG); |
|
| 1068 | - //interesting part: do the bind! |
|
| 1069 | - $login = $this->ldap->bind($cr, |
|
| 1070 | - $this->configuration->ldapAgentName, |
|
| 1071 | - $this->configuration->ldapAgentPassword |
|
| 1072 | - ); |
|
| 1073 | - $errNo = $this->ldap->errno($cr); |
|
| 1074 | - $error = ldap_error($cr); |
|
| 1075 | - $this->ldap->unbind($cr); |
|
| 1076 | - } catch(ServerNotAvailableException $e) { |
|
| 1077 | - return false; |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - if($login === true) { |
|
| 1081 | - $this->ldap->unbind($cr); |
|
| 1082 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, ILogger::DEBUG); |
|
| 1083 | - return true; |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - if($errNo === -1) { |
|
| 1087 | - //host, port or TLS wrong |
|
| 1088 | - return false; |
|
| 1089 | - } |
|
| 1090 | - throw new \Exception($error, $errNo); |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - /** |
|
| 1094 | - * checks whether a valid combination of agent and password has been |
|
| 1095 | - * provided (either two values or nothing for anonymous connect) |
|
| 1096 | - * @return bool, true if everything is fine, false otherwise |
|
| 1097 | - */ |
|
| 1098 | - private function checkAgentRequirements() { |
|
| 1099 | - $agent = $this->configuration->ldapAgentName; |
|
| 1100 | - $pwd = $this->configuration->ldapAgentPassword; |
|
| 1101 | - |
|
| 1102 | - return |
|
| 1103 | - ($agent !== '' && $pwd !== '') |
|
| 1104 | - || ($agent === '' && $pwd === '') |
|
| 1105 | - ; |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * @param array $reqs |
|
| 1110 | - * @return bool |
|
| 1111 | - */ |
|
| 1112 | - private function checkRequirements($reqs) { |
|
| 1113 | - $this->checkAgentRequirements(); |
|
| 1114 | - foreach($reqs as $option) { |
|
| 1115 | - $value = $this->configuration->$option; |
|
| 1116 | - if(empty($value)) { |
|
| 1117 | - return false; |
|
| 1118 | - } |
|
| 1119 | - } |
|
| 1120 | - return true; |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - /** |
|
| 1124 | - * does a cumulativeSearch on LDAP to get different values of a |
|
| 1125 | - * specified attribute |
|
| 1126 | - * @param string[] $filters array, the filters that shall be used in the search |
|
| 1127 | - * @param string $attr the attribute of which a list of values shall be returned |
|
| 1128 | - * @param int $dnReadLimit the amount of how many DNs should be analyzed. |
|
| 1129 | - * The lower, the faster |
|
| 1130 | - * @param string $maxF string. if not null, this variable will have the filter that |
|
| 1131 | - * yields most result entries |
|
| 1132 | - * @return array|false an array with the values on success, false otherwise |
|
| 1133 | - */ |
|
| 1134 | - public function cumulativeSearchOnAttribute($filters, $attr, $dnReadLimit = 3, &$maxF = null) { |
|
| 1135 | - $dnRead = array(); |
|
| 1136 | - $foundItems = array(); |
|
| 1137 | - $maxEntries = 0; |
|
| 1138 | - if(!is_array($this->configuration->ldapBase) |
|
| 1139 | - || !isset($this->configuration->ldapBase[0])) { |
|
| 1140 | - return false; |
|
| 1141 | - } |
|
| 1142 | - $base = $this->configuration->ldapBase[0]; |
|
| 1143 | - $cr = $this->getConnection(); |
|
| 1144 | - if(!$this->ldap->isResource($cr)) { |
|
| 1145 | - return false; |
|
| 1146 | - } |
|
| 1147 | - $lastFilter = null; |
|
| 1148 | - if(isset($filters[count($filters)-1])) { |
|
| 1149 | - $lastFilter = $filters[count($filters)-1]; |
|
| 1150 | - } |
|
| 1151 | - foreach($filters as $filter) { |
|
| 1152 | - if($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1153 | - //skip when the filter is a wildcard and results were found |
|
| 1154 | - continue; |
|
| 1155 | - } |
|
| 1156 | - // 20k limit for performance and reason |
|
| 1157 | - $rr = $this->ldap->search($cr, $base, $filter, array($attr), 0, 20000); |
|
| 1158 | - if(!$this->ldap->isResource($rr)) { |
|
| 1159 | - continue; |
|
| 1160 | - } |
|
| 1161 | - $entries = $this->ldap->countEntries($cr, $rr); |
|
| 1162 | - $getEntryFunc = 'firstEntry'; |
|
| 1163 | - if(($entries !== false) && ($entries > 0)) { |
|
| 1164 | - if(!is_null($maxF) && $entries > $maxEntries) { |
|
| 1165 | - $maxEntries = $entries; |
|
| 1166 | - $maxF = $filter; |
|
| 1167 | - } |
|
| 1168 | - $dnReadCount = 0; |
|
| 1169 | - do { |
|
| 1170 | - $entry = $this->ldap->$getEntryFunc($cr, $rr); |
|
| 1171 | - $getEntryFunc = 'nextEntry'; |
|
| 1172 | - if(!$this->ldap->isResource($entry)) { |
|
| 1173 | - continue 2; |
|
| 1174 | - } |
|
| 1175 | - $rr = $entry; //will be expected by nextEntry next round |
|
| 1176 | - $attributes = $this->ldap->getAttributes($cr, $entry); |
|
| 1177 | - $dn = $this->ldap->getDN($cr, $entry); |
|
| 1178 | - if($dn === false || in_array($dn, $dnRead)) { |
|
| 1179 | - continue; |
|
| 1180 | - } |
|
| 1181 | - $newItems = array(); |
|
| 1182 | - $state = $this->getAttributeValuesFromEntry($attributes, |
|
| 1183 | - $attr, |
|
| 1184 | - $newItems); |
|
| 1185 | - $dnReadCount++; |
|
| 1186 | - $foundItems = array_merge($foundItems, $newItems); |
|
| 1187 | - $this->resultCache[$dn][$attr] = $newItems; |
|
| 1188 | - $dnRead[] = $dn; |
|
| 1189 | - } while(($state === self::LRESULT_PROCESSED_SKIP |
|
| 1190 | - || $this->ldap->isResource($entry)) |
|
| 1191 | - && ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit)); |
|
| 1192 | - } |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - return array_unique($foundItems); |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * determines if and which $attr are available on the LDAP server |
|
| 1200 | - * @param string[] $objectclasses the objectclasses to use as search filter |
|
| 1201 | - * @param string $attr the attribute to look for |
|
| 1202 | - * @param string $dbkey the dbkey of the setting the feature is connected to |
|
| 1203 | - * @param string $confkey the confkey counterpart for the $dbkey as used in the |
|
| 1204 | - * Configuration class |
|
| 1205 | - * @param bool $po whether the objectClass with most result entries |
|
| 1206 | - * shall be pre-selected via the result |
|
| 1207 | - * @return array|false list of found items. |
|
| 1208 | - * @throws \Exception |
|
| 1209 | - */ |
|
| 1210 | - private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) { |
|
| 1211 | - $cr = $this->getConnection(); |
|
| 1212 | - if(!$cr) { |
|
| 1213 | - throw new \Exception('Could not connect to LDAP'); |
|
| 1214 | - } |
|
| 1215 | - $p = 'objectclass='; |
|
| 1216 | - foreach($objectclasses as $key => $value) { |
|
| 1217 | - $objectclasses[$key] = $p.$value; |
|
| 1218 | - } |
|
| 1219 | - $maxEntryObjC = ''; |
|
| 1220 | - |
|
| 1221 | - //how deep to dig? |
|
| 1222 | - //When looking for objectclasses, testing few entries is sufficient, |
|
| 1223 | - $dig = 3; |
|
| 1224 | - |
|
| 1225 | - $availableFeatures = |
|
| 1226 | - $this->cumulativeSearchOnAttribute($objectclasses, $attr, |
|
| 1227 | - $dig, $maxEntryObjC); |
|
| 1228 | - if(is_array($availableFeatures) |
|
| 1229 | - && count($availableFeatures) > 0) { |
|
| 1230 | - natcasesort($availableFeatures); |
|
| 1231 | - //natcasesort keeps indices, but we must get rid of them for proper |
|
| 1232 | - //sorting in the web UI. Therefore: array_values |
|
| 1233 | - $this->result->addOptions($dbkey, array_values($availableFeatures)); |
|
| 1234 | - } else { |
|
| 1235 | - throw new \Exception(self::$l->t('Could not find the desired feature')); |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - $setFeatures = $this->configuration->$confkey; |
|
| 1239 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1240 | - //something is already configured? pre-select it. |
|
| 1241 | - $this->result->addChange($dbkey, $setFeatures); |
|
| 1242 | - } else if ($po && $maxEntryObjC !== '') { |
|
| 1243 | - //pre-select objectclass with most result entries |
|
| 1244 | - $maxEntryObjC = str_replace($p, '', $maxEntryObjC); |
|
| 1245 | - $this->applyFind($dbkey, $maxEntryObjC); |
|
| 1246 | - $this->result->addChange($dbkey, $maxEntryObjC); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - return $availableFeatures; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - /** |
|
| 1253 | - * appends a list of values fr |
|
| 1254 | - * @param resource $result the return value from ldap_get_attributes |
|
| 1255 | - * @param string $attribute the attribute values to look for |
|
| 1256 | - * @param array &$known new values will be appended here |
|
| 1257 | - * @return int, state on of the class constants LRESULT_PROCESSED_OK, |
|
| 1258 | - * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP |
|
| 1259 | - */ |
|
| 1260 | - private function getAttributeValuesFromEntry($result, $attribute, &$known) { |
|
| 1261 | - if(!is_array($result) |
|
| 1262 | - || !isset($result['count']) |
|
| 1263 | - || !$result['count'] > 0) { |
|
| 1264 | - return self::LRESULT_PROCESSED_INVALID; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - // strtolower on all keys for proper comparison |
|
| 1268 | - $result = \OCP\Util::mb_array_change_key_case($result); |
|
| 1269 | - $attribute = strtolower($attribute); |
|
| 1270 | - if(isset($result[$attribute])) { |
|
| 1271 | - foreach($result[$attribute] as $key => $val) { |
|
| 1272 | - if($key === 'count') { |
|
| 1273 | - continue; |
|
| 1274 | - } |
|
| 1275 | - if(!in_array($val, $known)) { |
|
| 1276 | - $known[] = $val; |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - return self::LRESULT_PROCESSED_OK; |
|
| 1280 | - } else { |
|
| 1281 | - return self::LRESULT_PROCESSED_SKIP; |
|
| 1282 | - } |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * @return bool|mixed |
|
| 1287 | - */ |
|
| 1288 | - private function getConnection() { |
|
| 1289 | - if(!is_null($this->cr)) { |
|
| 1290 | - return $this->cr; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - $cr = $this->ldap->connect( |
|
| 1294 | - $this->configuration->ldapHost, |
|
| 1295 | - $this->configuration->ldapPort |
|
| 1296 | - ); |
|
| 1297 | - |
|
| 1298 | - $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
| 1299 | - $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
|
| 1300 | - $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
|
| 1301 | - if($this->configuration->ldapTLS === 1) { |
|
| 1302 | - $this->ldap->startTls($cr); |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - $lo = @$this->ldap->bind($cr, |
|
| 1306 | - $this->configuration->ldapAgentName, |
|
| 1307 | - $this->configuration->ldapAgentPassword); |
|
| 1308 | - if($lo === true) { |
|
| 1309 | - $this->$cr = $cr; |
|
| 1310 | - return $cr; |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - return false; |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * @return array |
|
| 1318 | - */ |
|
| 1319 | - private function getDefaultLdapPortSettings() { |
|
| 1320 | - static $settings = array( |
|
| 1321 | - array('port' => 7636, 'tls' => false), |
|
| 1322 | - array('port' => 636, 'tls' => false), |
|
| 1323 | - array('port' => 7389, 'tls' => true), |
|
| 1324 | - array('port' => 389, 'tls' => true), |
|
| 1325 | - array('port' => 7389, 'tls' => false), |
|
| 1326 | - array('port' => 389, 'tls' => false), |
|
| 1327 | - ); |
|
| 1328 | - return $settings; |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - /** |
|
| 1332 | - * @return array |
|
| 1333 | - */ |
|
| 1334 | - private function getPortSettingsToTry() { |
|
| 1335 | - //389 ← LDAP / Unencrypted or StartTLS |
|
| 1336 | - //636 ← LDAPS / SSL |
|
| 1337 | - //7xxx ← UCS. need to be checked first, because both ports may be open |
|
| 1338 | - $host = $this->configuration->ldapHost; |
|
| 1339 | - $port = (int)$this->configuration->ldapPort; |
|
| 1340 | - $portSettings = array(); |
|
| 1341 | - |
|
| 1342 | - //In case the port is already provided, we will check this first |
|
| 1343 | - if($port > 0) { |
|
| 1344 | - $hostInfo = parse_url($host); |
|
| 1345 | - if(!(is_array($hostInfo) |
|
| 1346 | - && isset($hostInfo['scheme']) |
|
| 1347 | - && stripos($hostInfo['scheme'], 'ldaps') !== false)) { |
|
| 1348 | - $portSettings[] = array('port' => $port, 'tls' => true); |
|
| 1349 | - } |
|
| 1350 | - $portSettings[] =array('port' => $port, 'tls' => false); |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - //default ports |
|
| 1354 | - $portSettings = array_merge($portSettings, |
|
| 1355 | - $this->getDefaultLdapPortSettings()); |
|
| 1356 | - |
|
| 1357 | - return $portSettings; |
|
| 1358 | - } |
|
| 45 | + /** @var \OCP\IL10N */ |
|
| 46 | + static protected $l; |
|
| 47 | + protected $access; |
|
| 48 | + protected $cr; |
|
| 49 | + protected $configuration; |
|
| 50 | + protected $result; |
|
| 51 | + protected $resultCache = array(); |
|
| 52 | + |
|
| 53 | + const LRESULT_PROCESSED_OK = 2; |
|
| 54 | + const LRESULT_PROCESSED_INVALID = 3; |
|
| 55 | + const LRESULT_PROCESSED_SKIP = 4; |
|
| 56 | + |
|
| 57 | + const LFILTER_LOGIN = 2; |
|
| 58 | + const LFILTER_USER_LIST = 3; |
|
| 59 | + const LFILTER_GROUP_LIST = 4; |
|
| 60 | + |
|
| 61 | + const LFILTER_MODE_ASSISTED = 2; |
|
| 62 | + const LFILTER_MODE_RAW = 1; |
|
| 63 | + |
|
| 64 | + const LDAP_NW_TIMEOUT = 4; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Constructor |
|
| 68 | + * @param Configuration $configuration an instance of Configuration |
|
| 69 | + * @param ILDAPWrapper $ldap an instance of ILDAPWrapper |
|
| 70 | + * @param Access $access |
|
| 71 | + */ |
|
| 72 | + public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) { |
|
| 73 | + parent::__construct($ldap); |
|
| 74 | + $this->configuration = $configuration; |
|
| 75 | + if(is_null(Wizard::$l)) { |
|
| 76 | + Wizard::$l = \OC::$server->getL10N('user_ldap'); |
|
| 77 | + } |
|
| 78 | + $this->access = $access; |
|
| 79 | + $this->result = new WizardResult(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function __destruct() { |
|
| 83 | + if($this->result->hasChanges()) { |
|
| 84 | + $this->configuration->saveConfiguration(); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * counts entries in the LDAP directory |
|
| 90 | + * |
|
| 91 | + * @param string $filter the LDAP search filter |
|
| 92 | + * @param string $type a string being either 'users' or 'groups'; |
|
| 93 | + * @return int |
|
| 94 | + * @throws \Exception |
|
| 95 | + */ |
|
| 96 | + public function countEntries(string $filter, string $type): int { |
|
| 97 | + $reqs = ['ldapHost', 'ldapPort', 'ldapBase']; |
|
| 98 | + if($type === 'users') { |
|
| 99 | + $reqs[] = 'ldapUserFilter'; |
|
| 100 | + } |
|
| 101 | + if(!$this->checkRequirements($reqs)) { |
|
| 102 | + throw new \Exception('Requirements not met', 400); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $attr = ['dn']; // default |
|
| 106 | + $limit = 1001; |
|
| 107 | + if($type === 'groups') { |
|
| 108 | + $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 109 | + } else if($type === 'users') { |
|
| 110 | + $result = $this->access->countUsers($filter, $attr, $limit); |
|
| 111 | + } else if ($type === 'objects') { |
|
| 112 | + $result = $this->access->countObjects($limit); |
|
| 113 | + } else { |
|
| 114 | + throw new \Exception('Internal error: Invalid object type', 500); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return (int)$result; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * formats the return value of a count operation to the string to be |
|
| 122 | + * inserted. |
|
| 123 | + * |
|
| 124 | + * @param int $count |
|
| 125 | + * @return string |
|
| 126 | + */ |
|
| 127 | + private function formatCountResult(int $count): string { |
|
| 128 | + if($count > 1000) { |
|
| 129 | + return '> 1000'; |
|
| 130 | + } |
|
| 131 | + return (string)$count; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function countGroups() { |
|
| 135 | + $filter = $this->configuration->ldapGroupFilter; |
|
| 136 | + |
|
| 137 | + if(empty($filter)) { |
|
| 138 | + $output = self::$l->n('%s group found', '%s groups found', 0, array(0)); |
|
| 139 | + $this->result->addChange('ldap_group_count', $output); |
|
| 140 | + return $this->result; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + try { |
|
| 144 | + $groupsTotal = $this->countEntries($filter, 'groups'); |
|
| 145 | + } catch (\Exception $e) { |
|
| 146 | + //400 can be ignored, 500 is forwarded |
|
| 147 | + if($e->getCode() === 500) { |
|
| 148 | + throw $e; |
|
| 149 | + } |
|
| 150 | + return false; |
|
| 151 | + } |
|
| 152 | + $output = self::$l->n( |
|
| 153 | + '%s group found', |
|
| 154 | + '%s groups found', |
|
| 155 | + $groupsTotal, |
|
| 156 | + [$this->formatCountResult($groupsTotal)] |
|
| 157 | + ); |
|
| 158 | + $this->result->addChange('ldap_group_count', $output); |
|
| 159 | + return $this->result; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return WizardResult |
|
| 164 | + * @throws \Exception |
|
| 165 | + */ |
|
| 166 | + public function countUsers() { |
|
| 167 | + $filter = $this->access->getFilterForUserCount(); |
|
| 168 | + |
|
| 169 | + $usersTotal = $this->countEntries($filter, 'users'); |
|
| 170 | + $output = self::$l->n( |
|
| 171 | + '%s user found', |
|
| 172 | + '%s users found', |
|
| 173 | + $usersTotal, |
|
| 174 | + [$this->formatCountResult($usersTotal)] |
|
| 175 | + ); |
|
| 176 | + $this->result->addChange('ldap_user_count', $output); |
|
| 177 | + return $this->result; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * counts any objects in the currently set base dn |
|
| 182 | + * |
|
| 183 | + * @return WizardResult |
|
| 184 | + * @throws \Exception |
|
| 185 | + */ |
|
| 186 | + public function countInBaseDN() { |
|
| 187 | + // we don't need to provide a filter in this case |
|
| 188 | + $total = $this->countEntries('', 'objects'); |
|
| 189 | + if($total === false) { |
|
| 190 | + throw new \Exception('invalid results received'); |
|
| 191 | + } |
|
| 192 | + $this->result->addChange('ldap_test_base', $total); |
|
| 193 | + return $this->result; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * counts users with a specified attribute |
|
| 198 | + * @param string $attr |
|
| 199 | + * @param bool $existsCheck |
|
| 200 | + * @return int|bool |
|
| 201 | + */ |
|
| 202 | + public function countUsersWithAttribute($attr, $existsCheck = false) { |
|
| 203 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 204 | + 'ldapPort', |
|
| 205 | + 'ldapBase', |
|
| 206 | + 'ldapUserFilter', |
|
| 207 | + ))) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $filter = $this->access->combineFilterWithAnd(array( |
|
| 212 | + $this->configuration->ldapUserFilter, |
|
| 213 | + $attr . '=*' |
|
| 214 | + )); |
|
| 215 | + |
|
| 216 | + $limit = ($existsCheck === false) ? null : 1; |
|
| 217 | + |
|
| 218 | + return $this->access->countUsers($filter, array('dn'), $limit); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * detects the display name attribute. If a setting is already present that |
|
| 223 | + * returns at least one hit, the detection will be canceled. |
|
| 224 | + * @return WizardResult|bool |
|
| 225 | + * @throws \Exception |
|
| 226 | + */ |
|
| 227 | + public function detectUserDisplayNameAttribute() { |
|
| 228 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 229 | + 'ldapPort', |
|
| 230 | + 'ldapBase', |
|
| 231 | + 'ldapUserFilter', |
|
| 232 | + ))) { |
|
| 233 | + return false; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + $attr = $this->configuration->ldapUserDisplayName; |
|
| 237 | + if ($attr !== '' && $attr !== 'displayName') { |
|
| 238 | + // most likely not the default value with upper case N, |
|
| 239 | + // verify it still produces a result |
|
| 240 | + $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 241 | + if($count > 0) { |
|
| 242 | + //no change, but we sent it back to make sure the user interface |
|
| 243 | + //is still correct, even if the ajax call was cancelled meanwhile |
|
| 244 | + $this->result->addChange('ldap_display_name', $attr); |
|
| 245 | + return $this->result; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // first attribute that has at least one result wins |
|
| 250 | + $displayNameAttrs = array('displayname', 'cn'); |
|
| 251 | + foreach ($displayNameAttrs as $attr) { |
|
| 252 | + $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 253 | + |
|
| 254 | + if($count > 0) { |
|
| 255 | + $this->applyFind('ldap_display_name', $attr); |
|
| 256 | + return $this->result; |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + throw new \Exception(self::$l->t('Could not detect user display name attribute. Please specify it yourself in advanced LDAP settings.')); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * detects the most often used email attribute for users applying to the |
|
| 265 | + * user list filter. If a setting is already present that returns at least |
|
| 266 | + * one hit, the detection will be canceled. |
|
| 267 | + * @return WizardResult|bool |
|
| 268 | + */ |
|
| 269 | + public function detectEmailAttribute() { |
|
| 270 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 271 | + 'ldapPort', |
|
| 272 | + 'ldapBase', |
|
| 273 | + 'ldapUserFilter', |
|
| 274 | + ))) { |
|
| 275 | + return false; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + $attr = $this->configuration->ldapEmailAttribute; |
|
| 279 | + if ($attr !== '') { |
|
| 280 | + $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 281 | + if($count > 0) { |
|
| 282 | + return false; |
|
| 283 | + } |
|
| 284 | + $writeLog = true; |
|
| 285 | + } else { |
|
| 286 | + $writeLog = false; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + $emailAttributes = array('mail', 'mailPrimaryAddress'); |
|
| 290 | + $winner = ''; |
|
| 291 | + $maxUsers = 0; |
|
| 292 | + foreach($emailAttributes as $attr) { |
|
| 293 | + $count = $this->countUsersWithAttribute($attr); |
|
| 294 | + if($count > $maxUsers) { |
|
| 295 | + $maxUsers = $count; |
|
| 296 | + $winner = $attr; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + if($winner !== '') { |
|
| 301 | + $this->applyFind('ldap_email_attr', $winner); |
|
| 302 | + if($writeLog) { |
|
| 303 | + \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . |
|
| 304 | + 'automatically been reset, because the original value ' . |
|
| 305 | + 'did not return any results.', ILogger::INFO); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + return $this->result; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @return WizardResult |
|
| 314 | + * @throws \Exception |
|
| 315 | + */ |
|
| 316 | + public function determineAttributes() { |
|
| 317 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 318 | + 'ldapPort', |
|
| 319 | + 'ldapBase', |
|
| 320 | + 'ldapUserFilter', |
|
| 321 | + ))) { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + $attributes = $this->getUserAttributes(); |
|
| 326 | + |
|
| 327 | + natcasesort($attributes); |
|
| 328 | + $attributes = array_values($attributes); |
|
| 329 | + |
|
| 330 | + $this->result->addOptions('ldap_loginfilter_attributes', $attributes); |
|
| 331 | + |
|
| 332 | + $selected = $this->configuration->ldapLoginFilterAttributes; |
|
| 333 | + if(is_array($selected) && !empty($selected)) { |
|
| 334 | + $this->result->addChange('ldap_loginfilter_attributes', $selected); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return $this->result; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * detects the available LDAP attributes |
|
| 342 | + * @return array|false The instance's WizardResult instance |
|
| 343 | + * @throws \Exception |
|
| 344 | + */ |
|
| 345 | + private function getUserAttributes() { |
|
| 346 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 347 | + 'ldapPort', |
|
| 348 | + 'ldapBase', |
|
| 349 | + 'ldapUserFilter', |
|
| 350 | + ))) { |
|
| 351 | + return false; |
|
| 352 | + } |
|
| 353 | + $cr = $this->getConnection(); |
|
| 354 | + if(!$cr) { |
|
| 355 | + throw new \Exception('Could not connect to LDAP'); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + $base = $this->configuration->ldapBase[0]; |
|
| 359 | + $filter = $this->configuration->ldapUserFilter; |
|
| 360 | + $rr = $this->ldap->search($cr, $base, $filter, array(), 1, 1); |
|
| 361 | + if(!$this->ldap->isResource($rr)) { |
|
| 362 | + return false; |
|
| 363 | + } |
|
| 364 | + $er = $this->ldap->firstEntry($cr, $rr); |
|
| 365 | + $attributes = $this->ldap->getAttributes($cr, $er); |
|
| 366 | + $pureAttributes = array(); |
|
| 367 | + for($i = 0; $i < $attributes['count']; $i++) { |
|
| 368 | + $pureAttributes[] = $attributes[$i]; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return $pureAttributes; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * detects the available LDAP groups |
|
| 376 | + * @return WizardResult|false the instance's WizardResult instance |
|
| 377 | + */ |
|
| 378 | + public function determineGroupsForGroups() { |
|
| 379 | + return $this->determineGroups('ldap_groupfilter_groups', |
|
| 380 | + 'ldapGroupFilterGroups', |
|
| 381 | + false); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * detects the available LDAP groups |
|
| 386 | + * @return WizardResult|false the instance's WizardResult instance |
|
| 387 | + */ |
|
| 388 | + public function determineGroupsForUsers() { |
|
| 389 | + return $this->determineGroups('ldap_userfilter_groups', |
|
| 390 | + 'ldapUserFilterGroups'); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * detects the available LDAP groups |
|
| 395 | + * @param string $dbKey |
|
| 396 | + * @param string $confKey |
|
| 397 | + * @param bool $testMemberOf |
|
| 398 | + * @return WizardResult|false the instance's WizardResult instance |
|
| 399 | + * @throws \Exception |
|
| 400 | + */ |
|
| 401 | + private function determineGroups($dbKey, $confKey, $testMemberOf = true) { |
|
| 402 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 403 | + 'ldapPort', |
|
| 404 | + 'ldapBase', |
|
| 405 | + ))) { |
|
| 406 | + return false; |
|
| 407 | + } |
|
| 408 | + $cr = $this->getConnection(); |
|
| 409 | + if(!$cr) { |
|
| 410 | + throw new \Exception('Could not connect to LDAP'); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + $this->fetchGroups($dbKey, $confKey); |
|
| 414 | + |
|
| 415 | + if($testMemberOf) { |
|
| 416 | + $this->configuration->hasMemberOfFilterSupport = $this->testMemberOf(); |
|
| 417 | + $this->result->markChange(); |
|
| 418 | + if(!$this->configuration->hasMemberOfFilterSupport) { |
|
| 419 | + throw new \Exception('memberOf is not supported by the server'); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $this->result; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * fetches all groups from LDAP and adds them to the result object |
|
| 428 | + * |
|
| 429 | + * @param string $dbKey |
|
| 430 | + * @param string $confKey |
|
| 431 | + * @return array $groupEntries |
|
| 432 | + * @throws \Exception |
|
| 433 | + */ |
|
| 434 | + public function fetchGroups($dbKey, $confKey) { |
|
| 435 | + $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'); |
|
| 436 | + |
|
| 437 | + $filterParts = array(); |
|
| 438 | + foreach($obclasses as $obclass) { |
|
| 439 | + $filterParts[] = 'objectclass='.$obclass; |
|
| 440 | + } |
|
| 441 | + //we filter for everything |
|
| 442 | + //- that looks like a group and |
|
| 443 | + //- has the group display name set |
|
| 444 | + $filter = $this->access->combineFilterWithOr($filterParts); |
|
| 445 | + $filter = $this->access->combineFilterWithAnd(array($filter, 'cn=*')); |
|
| 446 | + |
|
| 447 | + $groupNames = array(); |
|
| 448 | + $groupEntries = array(); |
|
| 449 | + $limit = 400; |
|
| 450 | + $offset = 0; |
|
| 451 | + do { |
|
| 452 | + // we need to request dn additionally here, otherwise memberOf |
|
| 453 | + // detection will fail later |
|
| 454 | + $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); |
|
| 455 | + foreach($result as $item) { |
|
| 456 | + if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 457 | + // just in case - no issue known |
|
| 458 | + continue; |
|
| 459 | + } |
|
| 460 | + $groupNames[] = $item['cn'][0]; |
|
| 461 | + $groupEntries[] = $item; |
|
| 462 | + } |
|
| 463 | + $offset += $limit; |
|
| 464 | + } while ($this->access->hasMoreResults()); |
|
| 465 | + |
|
| 466 | + if(count($groupNames) > 0) { |
|
| 467 | + natsort($groupNames); |
|
| 468 | + $this->result->addOptions($dbKey, array_values($groupNames)); |
|
| 469 | + } else { |
|
| 470 | + throw new \Exception(self::$l->t('Could not find the desired feature')); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + $setFeatures = $this->configuration->$confKey; |
|
| 474 | + if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 475 | + //something is already configured? pre-select it. |
|
| 476 | + $this->result->addChange($dbKey, $setFeatures); |
|
| 477 | + } |
|
| 478 | + return $groupEntries; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + public function determineGroupMemberAssoc() { |
|
| 482 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 483 | + 'ldapPort', |
|
| 484 | + 'ldapGroupFilter', |
|
| 485 | + ))) { |
|
| 486 | + return false; |
|
| 487 | + } |
|
| 488 | + $attribute = $this->detectGroupMemberAssoc(); |
|
| 489 | + if($attribute === false) { |
|
| 490 | + return false; |
|
| 491 | + } |
|
| 492 | + $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute)); |
|
| 493 | + $this->result->addChange('ldap_group_member_assoc_attribute', $attribute); |
|
| 494 | + |
|
| 495 | + return $this->result; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Detects the available object classes |
|
| 500 | + * @return WizardResult|false the instance's WizardResult instance |
|
| 501 | + * @throws \Exception |
|
| 502 | + */ |
|
| 503 | + public function determineGroupObjectClasses() { |
|
| 504 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 505 | + 'ldapPort', |
|
| 506 | + 'ldapBase', |
|
| 507 | + ))) { |
|
| 508 | + return false; |
|
| 509 | + } |
|
| 510 | + $cr = $this->getConnection(); |
|
| 511 | + if(!$cr) { |
|
| 512 | + throw new \Exception('Could not connect to LDAP'); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + $obclasses = array('groupOfNames', 'groupOfUniqueNames', 'group', 'posixGroup', '*'); |
|
| 516 | + $this->determineFeature($obclasses, |
|
| 517 | + 'objectclass', |
|
| 518 | + 'ldap_groupfilter_objectclass', |
|
| 519 | + 'ldapGroupFilterObjectclass', |
|
| 520 | + false); |
|
| 521 | + |
|
| 522 | + return $this->result; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * detects the available object classes |
|
| 527 | + * @return WizardResult |
|
| 528 | + * @throws \Exception |
|
| 529 | + */ |
|
| 530 | + public function determineUserObjectClasses() { |
|
| 531 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 532 | + 'ldapPort', |
|
| 533 | + 'ldapBase', |
|
| 534 | + ))) { |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 537 | + $cr = $this->getConnection(); |
|
| 538 | + if(!$cr) { |
|
| 539 | + throw new \Exception('Could not connect to LDAP'); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + $obclasses = array('inetOrgPerson', 'person', 'organizationalPerson', |
|
| 543 | + 'user', 'posixAccount', '*'); |
|
| 544 | + $filter = $this->configuration->ldapUserFilter; |
|
| 545 | + //if filter is empty, it is probably the first time the wizard is called |
|
| 546 | + //then, apply suggestions. |
|
| 547 | + $this->determineFeature($obclasses, |
|
| 548 | + 'objectclass', |
|
| 549 | + 'ldap_userfilter_objectclass', |
|
| 550 | + 'ldapUserFilterObjectclass', |
|
| 551 | + empty($filter)); |
|
| 552 | + |
|
| 553 | + return $this->result; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * @return WizardResult|false |
|
| 558 | + * @throws \Exception |
|
| 559 | + */ |
|
| 560 | + public function getGroupFilter() { |
|
| 561 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 562 | + 'ldapPort', |
|
| 563 | + 'ldapBase', |
|
| 564 | + ))) { |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + //make sure the use display name is set |
|
| 568 | + $displayName = $this->configuration->ldapGroupDisplayName; |
|
| 569 | + if ($displayName === '') { |
|
| 570 | + $d = $this->configuration->getDefaults(); |
|
| 571 | + $this->applyFind('ldap_group_display_name', |
|
| 572 | + $d['ldap_group_display_name']); |
|
| 573 | + } |
|
| 574 | + $filter = $this->composeLdapFilter(self::LFILTER_GROUP_LIST); |
|
| 575 | + |
|
| 576 | + $this->applyFind('ldap_group_filter', $filter); |
|
| 577 | + return $this->result; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * @return WizardResult|false |
|
| 582 | + * @throws \Exception |
|
| 583 | + */ |
|
| 584 | + public function getUserListFilter() { |
|
| 585 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 586 | + 'ldapPort', |
|
| 587 | + 'ldapBase', |
|
| 588 | + ))) { |
|
| 589 | + return false; |
|
| 590 | + } |
|
| 591 | + //make sure the use display name is set |
|
| 592 | + $displayName = $this->configuration->ldapUserDisplayName; |
|
| 593 | + if ($displayName === '') { |
|
| 594 | + $d = $this->configuration->getDefaults(); |
|
| 595 | + $this->applyFind('ldap_display_name', $d['ldap_display_name']); |
|
| 596 | + } |
|
| 597 | + $filter = $this->composeLdapFilter(self::LFILTER_USER_LIST); |
|
| 598 | + if(!$filter) { |
|
| 599 | + throw new \Exception('Cannot create filter'); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + $this->applyFind('ldap_userlist_filter', $filter); |
|
| 603 | + return $this->result; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * @return bool|WizardResult |
|
| 608 | + * @throws \Exception |
|
| 609 | + */ |
|
| 610 | + public function getUserLoginFilter() { |
|
| 611 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 612 | + 'ldapPort', |
|
| 613 | + 'ldapBase', |
|
| 614 | + 'ldapUserFilter', |
|
| 615 | + ))) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + $filter = $this->composeLdapFilter(self::LFILTER_LOGIN); |
|
| 620 | + if(!$filter) { |
|
| 621 | + throw new \Exception('Cannot create filter'); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + $this->applyFind('ldap_login_filter', $filter); |
|
| 625 | + return $this->result; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * @return bool|WizardResult |
|
| 630 | + * @param string $loginName |
|
| 631 | + * @throws \Exception |
|
| 632 | + */ |
|
| 633 | + public function testLoginName($loginName) { |
|
| 634 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 635 | + 'ldapPort', |
|
| 636 | + 'ldapBase', |
|
| 637 | + 'ldapLoginFilter', |
|
| 638 | + ))) { |
|
| 639 | + return false; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $cr = $this->access->connection->getConnectionResource(); |
|
| 643 | + if(!$this->ldap->isResource($cr)) { |
|
| 644 | + throw new \Exception('connection error'); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 648 | + === false) { |
|
| 649 | + throw new \Exception('missing placeholder'); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + $users = $this->access->countUsersByLoginName($loginName); |
|
| 653 | + if($this->ldap->errno($cr) !== 0) { |
|
| 654 | + throw new \Exception($this->ldap->error($cr)); |
|
| 655 | + } |
|
| 656 | + $filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter); |
|
| 657 | + $this->result->addChange('ldap_test_loginname', $users); |
|
| 658 | + $this->result->addChange('ldap_test_effective_filter', $filter); |
|
| 659 | + return $this->result; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * Tries to determine the port, requires given Host, User DN and Password |
|
| 664 | + * @return WizardResult|false WizardResult on success, false otherwise |
|
| 665 | + * @throws \Exception |
|
| 666 | + */ |
|
| 667 | + public function guessPortAndTLS() { |
|
| 668 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 669 | + ))) { |
|
| 670 | + return false; |
|
| 671 | + } |
|
| 672 | + $this->checkHost(); |
|
| 673 | + $portSettings = $this->getPortSettingsToTry(); |
|
| 674 | + |
|
| 675 | + if(!is_array($portSettings)) { |
|
| 676 | + throw new \Exception(print_r($portSettings, true)); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + //proceed from the best configuration and return on first success |
|
| 680 | + foreach($portSettings as $setting) { |
|
| 681 | + $p = $setting['port']; |
|
| 682 | + $t = $setting['tls']; |
|
| 683 | + \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, ILogger::DEBUG); |
|
| 684 | + //connectAndBind may throw Exception, it needs to be catched by the |
|
| 685 | + //callee of this method |
|
| 686 | + |
|
| 687 | + try { |
|
| 688 | + $settingsFound = $this->connectAndBind($p, $t); |
|
| 689 | + } catch (\Exception $e) { |
|
| 690 | + // any reply other than -1 (= cannot connect) is already okay, |
|
| 691 | + // because then we found the server |
|
| 692 | + // unavailable startTLS returns -11 |
|
| 693 | + if($e->getCode() > 0) { |
|
| 694 | + $settingsFound = true; |
|
| 695 | + } else { |
|
| 696 | + throw $e; |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + if ($settingsFound === true) { |
|
| 701 | + $config = array( |
|
| 702 | + 'ldapPort' => $p, |
|
| 703 | + 'ldapTLS' => (int)$t |
|
| 704 | + ); |
|
| 705 | + $this->configuration->setConfiguration($config); |
|
| 706 | + \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, ILogger::DEBUG); |
|
| 707 | + $this->result->addChange('ldap_port', $p); |
|
| 708 | + return $this->result; |
|
| 709 | + } |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + //custom port, undetected (we do not brute force) |
|
| 713 | + return false; |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + /** |
|
| 717 | + * tries to determine a base dn from User DN or LDAP Host |
|
| 718 | + * @return WizardResult|false WizardResult on success, false otherwise |
|
| 719 | + */ |
|
| 720 | + public function guessBaseDN() { |
|
| 721 | + if(!$this->checkRequirements(array('ldapHost', |
|
| 722 | + 'ldapPort', |
|
| 723 | + ))) { |
|
| 724 | + return false; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + //check whether a DN is given in the agent name (99.9% of all cases) |
|
| 728 | + $base = null; |
|
| 729 | + $i = stripos($this->configuration->ldapAgentName, 'dc='); |
|
| 730 | + if($i !== false) { |
|
| 731 | + $base = substr($this->configuration->ldapAgentName, $i); |
|
| 732 | + if($this->testBaseDN($base)) { |
|
| 733 | + $this->applyFind('ldap_base', $base); |
|
| 734 | + return $this->result; |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + //this did not help :( |
|
| 739 | + //Let's see whether we can parse the Host URL and convert the domain to |
|
| 740 | + //a base DN |
|
| 741 | + $helper = new Helper(\OC::$server->getConfig()); |
|
| 742 | + $domain = $helper->getDomainFromURL($this->configuration->ldapHost); |
|
| 743 | + if(!$domain) { |
|
| 744 | + return false; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + $dparts = explode('.', $domain); |
|
| 748 | + while(count($dparts) > 0) { |
|
| 749 | + $base2 = 'dc=' . implode(',dc=', $dparts); |
|
| 750 | + if ($base !== $base2 && $this->testBaseDN($base2)) { |
|
| 751 | + $this->applyFind('ldap_base', $base2); |
|
| 752 | + return $this->result; |
|
| 753 | + } |
|
| 754 | + array_shift($dparts); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + return false; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + /** |
|
| 761 | + * sets the found value for the configuration key in the WizardResult |
|
| 762 | + * as well as in the Configuration instance |
|
| 763 | + * @param string $key the configuration key |
|
| 764 | + * @param string $value the (detected) value |
|
| 765 | + * |
|
| 766 | + */ |
|
| 767 | + private function applyFind($key, $value) { |
|
| 768 | + $this->result->addChange($key, $value); |
|
| 769 | + $this->configuration->setConfiguration(array($key => $value)); |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * Checks, whether a port was entered in the Host configuration |
|
| 774 | + * field. In this case the port will be stripped off, but also stored as |
|
| 775 | + * setting. |
|
| 776 | + */ |
|
| 777 | + private function checkHost() { |
|
| 778 | + $host = $this->configuration->ldapHost; |
|
| 779 | + $hostInfo = parse_url($host); |
|
| 780 | + |
|
| 781 | + //removes Port from Host |
|
| 782 | + if(is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 783 | + $port = $hostInfo['port']; |
|
| 784 | + $host = str_replace(':'.$port, '', $host); |
|
| 785 | + $this->applyFind('ldap_host', $host); |
|
| 786 | + $this->applyFind('ldap_port', $port); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + /** |
|
| 791 | + * tries to detect the group member association attribute which is |
|
| 792 | + * one of 'uniqueMember', 'memberUid', 'member', 'gidNumber' |
|
| 793 | + * @return string|false, string with the attribute name, false on error |
|
| 794 | + * @throws \Exception |
|
| 795 | + */ |
|
| 796 | + private function detectGroupMemberAssoc() { |
|
| 797 | + $possibleAttrs = array('uniqueMember', 'memberUid', 'member', 'gidNumber'); |
|
| 798 | + $filter = $this->configuration->ldapGroupFilter; |
|
| 799 | + if(empty($filter)) { |
|
| 800 | + return false; |
|
| 801 | + } |
|
| 802 | + $cr = $this->getConnection(); |
|
| 803 | + if(!$cr) { |
|
| 804 | + throw new \Exception('Could not connect to LDAP'); |
|
| 805 | + } |
|
| 806 | + $base = $this->configuration->ldapBase[0]; |
|
| 807 | + $rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000); |
|
| 808 | + if(!$this->ldap->isResource($rr)) { |
|
| 809 | + return false; |
|
| 810 | + } |
|
| 811 | + $er = $this->ldap->firstEntry($cr, $rr); |
|
| 812 | + while(is_resource($er)) { |
|
| 813 | + $this->ldap->getDN($cr, $er); |
|
| 814 | + $attrs = $this->ldap->getAttributes($cr, $er); |
|
| 815 | + $result = array(); |
|
| 816 | + $possibleAttrsCount = count($possibleAttrs); |
|
| 817 | + for($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 818 | + if(isset($attrs[$possibleAttrs[$i]])) { |
|
| 819 | + $result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count']; |
|
| 820 | + } |
|
| 821 | + } |
|
| 822 | + if(!empty($result)) { |
|
| 823 | + natsort($result); |
|
| 824 | + return key($result); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + $er = $this->ldap->nextEntry($cr, $er); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + return false; |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * Checks whether for a given BaseDN results will be returned |
|
| 835 | + * @param string $base the BaseDN to test |
|
| 836 | + * @return bool true on success, false otherwise |
|
| 837 | + * @throws \Exception |
|
| 838 | + */ |
|
| 839 | + private function testBaseDN($base) { |
|
| 840 | + $cr = $this->getConnection(); |
|
| 841 | + if(!$cr) { |
|
| 842 | + throw new \Exception('Could not connect to LDAP'); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + //base is there, let's validate it. If we search for anything, we should |
|
| 846 | + //get a result set > 0 on a proper base |
|
| 847 | + $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); |
|
| 848 | + if(!$this->ldap->isResource($rr)) { |
|
| 849 | + $errorNo = $this->ldap->errno($cr); |
|
| 850 | + $errorMsg = $this->ldap->error($cr); |
|
| 851 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. |
|
| 852 | + ' Error '.$errorNo.': '.$errorMsg, ILogger::INFO); |
|
| 853 | + return false; |
|
| 854 | + } |
|
| 855 | + $entries = $this->ldap->countEntries($cr, $rr); |
|
| 856 | + return ($entries !== false) && ($entries > 0); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * Checks whether the server supports memberOf in LDAP Filter. |
|
| 861 | + * Note: at least in OpenLDAP, availability of memberOf is dependent on |
|
| 862 | + * a configured objectClass. I.e. not necessarily for all available groups |
|
| 863 | + * memberOf does work. |
|
| 864 | + * |
|
| 865 | + * @return bool true if it does, false otherwise |
|
| 866 | + * @throws \Exception |
|
| 867 | + */ |
|
| 868 | + private function testMemberOf() { |
|
| 869 | + $cr = $this->getConnection(); |
|
| 870 | + if(!$cr) { |
|
| 871 | + throw new \Exception('Could not connect to LDAP'); |
|
| 872 | + } |
|
| 873 | + $result = $this->access->countUsers('memberOf=*', array('memberOf'), 1); |
|
| 874 | + if(is_int($result) && $result > 0) { |
|
| 875 | + return true; |
|
| 876 | + } |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * creates an LDAP Filter from given configuration |
|
| 882 | + * @param integer $filterType int, for which use case the filter shall be created |
|
| 883 | + * can be any of self::LFILTER_USER_LIST, self::LFILTER_LOGIN or |
|
| 884 | + * self::LFILTER_GROUP_LIST |
|
| 885 | + * @return string|false string with the filter on success, false otherwise |
|
| 886 | + * @throws \Exception |
|
| 887 | + */ |
|
| 888 | + private function composeLdapFilter($filterType) { |
|
| 889 | + $filter = ''; |
|
| 890 | + $parts = 0; |
|
| 891 | + switch ($filterType) { |
|
| 892 | + case self::LFILTER_USER_LIST: |
|
| 893 | + $objcs = $this->configuration->ldapUserFilterObjectclass; |
|
| 894 | + //glue objectclasses |
|
| 895 | + if(is_array($objcs) && count($objcs) > 0) { |
|
| 896 | + $filter .= '(|'; |
|
| 897 | + foreach($objcs as $objc) { |
|
| 898 | + $filter .= '(objectclass=' . $objc . ')'; |
|
| 899 | + } |
|
| 900 | + $filter .= ')'; |
|
| 901 | + $parts++; |
|
| 902 | + } |
|
| 903 | + //glue group memberships |
|
| 904 | + if($this->configuration->hasMemberOfFilterSupport) { |
|
| 905 | + $cns = $this->configuration->ldapUserFilterGroups; |
|
| 906 | + if(is_array($cns) && count($cns) > 0) { |
|
| 907 | + $filter .= '(|'; |
|
| 908 | + $cr = $this->getConnection(); |
|
| 909 | + if(!$cr) { |
|
| 910 | + throw new \Exception('Could not connect to LDAP'); |
|
| 911 | + } |
|
| 912 | + $base = $this->configuration->ldapBase[0]; |
|
| 913 | + foreach($cns as $cn) { |
|
| 914 | + $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, array('dn', 'primaryGroupToken')); |
|
| 915 | + if(!$this->ldap->isResource($rr)) { |
|
| 916 | + continue; |
|
| 917 | + } |
|
| 918 | + $er = $this->ldap->firstEntry($cr, $rr); |
|
| 919 | + $attrs = $this->ldap->getAttributes($cr, $er); |
|
| 920 | + $dn = $this->ldap->getDN($cr, $er); |
|
| 921 | + if ($dn === false || $dn === '') { |
|
| 922 | + continue; |
|
| 923 | + } |
|
| 924 | + $filterPart = '(memberof=' . $dn . ')'; |
|
| 925 | + if(isset($attrs['primaryGroupToken'])) { |
|
| 926 | + $pgt = $attrs['primaryGroupToken'][0]; |
|
| 927 | + $primaryFilterPart = '(primaryGroupID=' . $pgt .')'; |
|
| 928 | + $filterPart = '(|' . $filterPart . $primaryFilterPart . ')'; |
|
| 929 | + } |
|
| 930 | + $filter .= $filterPart; |
|
| 931 | + } |
|
| 932 | + $filter .= ')'; |
|
| 933 | + } |
|
| 934 | + $parts++; |
|
| 935 | + } |
|
| 936 | + //wrap parts in AND condition |
|
| 937 | + if($parts > 1) { |
|
| 938 | + $filter = '(&' . $filter . ')'; |
|
| 939 | + } |
|
| 940 | + if ($filter === '') { |
|
| 941 | + $filter = '(objectclass=*)'; |
|
| 942 | + } |
|
| 943 | + break; |
|
| 944 | + |
|
| 945 | + case self::LFILTER_GROUP_LIST: |
|
| 946 | + $objcs = $this->configuration->ldapGroupFilterObjectclass; |
|
| 947 | + //glue objectclasses |
|
| 948 | + if(is_array($objcs) && count($objcs) > 0) { |
|
| 949 | + $filter .= '(|'; |
|
| 950 | + foreach($objcs as $objc) { |
|
| 951 | + $filter .= '(objectclass=' . $objc . ')'; |
|
| 952 | + } |
|
| 953 | + $filter .= ')'; |
|
| 954 | + $parts++; |
|
| 955 | + } |
|
| 956 | + //glue group memberships |
|
| 957 | + $cns = $this->configuration->ldapGroupFilterGroups; |
|
| 958 | + if(is_array($cns) && count($cns) > 0) { |
|
| 959 | + $filter .= '(|'; |
|
| 960 | + foreach($cns as $cn) { |
|
| 961 | + $filter .= '(cn=' . $cn . ')'; |
|
| 962 | + } |
|
| 963 | + $filter .= ')'; |
|
| 964 | + } |
|
| 965 | + $parts++; |
|
| 966 | + //wrap parts in AND condition |
|
| 967 | + if($parts > 1) { |
|
| 968 | + $filter = '(&' . $filter . ')'; |
|
| 969 | + } |
|
| 970 | + break; |
|
| 971 | + |
|
| 972 | + case self::LFILTER_LOGIN: |
|
| 973 | + $ulf = $this->configuration->ldapUserFilter; |
|
| 974 | + $loginpart = '=%uid'; |
|
| 975 | + $filterUsername = ''; |
|
| 976 | + $userAttributes = $this->getUserAttributes(); |
|
| 977 | + $userAttributes = array_change_key_case(array_flip($userAttributes)); |
|
| 978 | + $parts = 0; |
|
| 979 | + |
|
| 980 | + if($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 981 | + $attr = ''; |
|
| 982 | + if(isset($userAttributes['uid'])) { |
|
| 983 | + $attr = 'uid'; |
|
| 984 | + } else if(isset($userAttributes['samaccountname'])) { |
|
| 985 | + $attr = 'samaccountname'; |
|
| 986 | + } else if(isset($userAttributes['cn'])) { |
|
| 987 | + //fallback |
|
| 988 | + $attr = 'cn'; |
|
| 989 | + } |
|
| 990 | + if ($attr !== '') { |
|
| 991 | + $filterUsername = '(' . $attr . $loginpart . ')'; |
|
| 992 | + $parts++; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + |
|
| 996 | + $filterEmail = ''; |
|
| 997 | + if($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 998 | + $filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))'; |
|
| 999 | + $parts++; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + $filterAttributes = ''; |
|
| 1003 | + $attrsToFilter = $this->configuration->ldapLoginFilterAttributes; |
|
| 1004 | + if(is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 1005 | + $filterAttributes = '(|'; |
|
| 1006 | + foreach($attrsToFilter as $attribute) { |
|
| 1007 | + $filterAttributes .= '(' . $attribute . $loginpart . ')'; |
|
| 1008 | + } |
|
| 1009 | + $filterAttributes .= ')'; |
|
| 1010 | + $parts++; |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + $filterLogin = ''; |
|
| 1014 | + if($parts > 1) { |
|
| 1015 | + $filterLogin = '(|'; |
|
| 1016 | + } |
|
| 1017 | + $filterLogin .= $filterUsername; |
|
| 1018 | + $filterLogin .= $filterEmail; |
|
| 1019 | + $filterLogin .= $filterAttributes; |
|
| 1020 | + if($parts > 1) { |
|
| 1021 | + $filterLogin .= ')'; |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + $filter = '(&'.$ulf.$filterLogin.')'; |
|
| 1025 | + break; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Final filter '.$filter, ILogger::DEBUG); |
|
| 1029 | + |
|
| 1030 | + return $filter; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * Connects and Binds to an LDAP Server |
|
| 1035 | + * |
|
| 1036 | + * @param int $port the port to connect with |
|
| 1037 | + * @param bool $tls whether startTLS is to be used |
|
| 1038 | + * @return bool |
|
| 1039 | + * @throws \Exception |
|
| 1040 | + */ |
|
| 1041 | + private function connectAndBind($port, $tls) { |
|
| 1042 | + //connect, does not really trigger any server communication |
|
| 1043 | + $host = $this->configuration->ldapHost; |
|
| 1044 | + $hostInfo = parse_url($host); |
|
| 1045 | + if(!$hostInfo) { |
|
| 1046 | + throw new \Exception(self::$l->t('Invalid Host')); |
|
| 1047 | + } |
|
| 1048 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', ILogger::DEBUG); |
|
| 1049 | + $cr = $this->ldap->connect($host, $port); |
|
| 1050 | + if(!is_resource($cr)) { |
|
| 1051 | + throw new \Exception(self::$l->t('Invalid Host')); |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + //set LDAP options |
|
| 1055 | + $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
| 1056 | + $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
|
| 1057 | + $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
|
| 1058 | + |
|
| 1059 | + try { |
|
| 1060 | + if($tls) { |
|
| 1061 | + $isTlsWorking = @$this->ldap->startTls($cr); |
|
| 1062 | + if(!$isTlsWorking) { |
|
| 1063 | + return false; |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Attemping to Bind ', ILogger::DEBUG); |
|
| 1068 | + //interesting part: do the bind! |
|
| 1069 | + $login = $this->ldap->bind($cr, |
|
| 1070 | + $this->configuration->ldapAgentName, |
|
| 1071 | + $this->configuration->ldapAgentPassword |
|
| 1072 | + ); |
|
| 1073 | + $errNo = $this->ldap->errno($cr); |
|
| 1074 | + $error = ldap_error($cr); |
|
| 1075 | + $this->ldap->unbind($cr); |
|
| 1076 | + } catch(ServerNotAvailableException $e) { |
|
| 1077 | + return false; |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + if($login === true) { |
|
| 1081 | + $this->ldap->unbind($cr); |
|
| 1082 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, ILogger::DEBUG); |
|
| 1083 | + return true; |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + if($errNo === -1) { |
|
| 1087 | + //host, port or TLS wrong |
|
| 1088 | + return false; |
|
| 1089 | + } |
|
| 1090 | + throw new \Exception($error, $errNo); |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + /** |
|
| 1094 | + * checks whether a valid combination of agent and password has been |
|
| 1095 | + * provided (either two values or nothing for anonymous connect) |
|
| 1096 | + * @return bool, true if everything is fine, false otherwise |
|
| 1097 | + */ |
|
| 1098 | + private function checkAgentRequirements() { |
|
| 1099 | + $agent = $this->configuration->ldapAgentName; |
|
| 1100 | + $pwd = $this->configuration->ldapAgentPassword; |
|
| 1101 | + |
|
| 1102 | + return |
|
| 1103 | + ($agent !== '' && $pwd !== '') |
|
| 1104 | + || ($agent === '' && $pwd === '') |
|
| 1105 | + ; |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * @param array $reqs |
|
| 1110 | + * @return bool |
|
| 1111 | + */ |
|
| 1112 | + private function checkRequirements($reqs) { |
|
| 1113 | + $this->checkAgentRequirements(); |
|
| 1114 | + foreach($reqs as $option) { |
|
| 1115 | + $value = $this->configuration->$option; |
|
| 1116 | + if(empty($value)) { |
|
| 1117 | + return false; |
|
| 1118 | + } |
|
| 1119 | + } |
|
| 1120 | + return true; |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + /** |
|
| 1124 | + * does a cumulativeSearch on LDAP to get different values of a |
|
| 1125 | + * specified attribute |
|
| 1126 | + * @param string[] $filters array, the filters that shall be used in the search |
|
| 1127 | + * @param string $attr the attribute of which a list of values shall be returned |
|
| 1128 | + * @param int $dnReadLimit the amount of how many DNs should be analyzed. |
|
| 1129 | + * The lower, the faster |
|
| 1130 | + * @param string $maxF string. if not null, this variable will have the filter that |
|
| 1131 | + * yields most result entries |
|
| 1132 | + * @return array|false an array with the values on success, false otherwise |
|
| 1133 | + */ |
|
| 1134 | + public function cumulativeSearchOnAttribute($filters, $attr, $dnReadLimit = 3, &$maxF = null) { |
|
| 1135 | + $dnRead = array(); |
|
| 1136 | + $foundItems = array(); |
|
| 1137 | + $maxEntries = 0; |
|
| 1138 | + if(!is_array($this->configuration->ldapBase) |
|
| 1139 | + || !isset($this->configuration->ldapBase[0])) { |
|
| 1140 | + return false; |
|
| 1141 | + } |
|
| 1142 | + $base = $this->configuration->ldapBase[0]; |
|
| 1143 | + $cr = $this->getConnection(); |
|
| 1144 | + if(!$this->ldap->isResource($cr)) { |
|
| 1145 | + return false; |
|
| 1146 | + } |
|
| 1147 | + $lastFilter = null; |
|
| 1148 | + if(isset($filters[count($filters)-1])) { |
|
| 1149 | + $lastFilter = $filters[count($filters)-1]; |
|
| 1150 | + } |
|
| 1151 | + foreach($filters as $filter) { |
|
| 1152 | + if($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1153 | + //skip when the filter is a wildcard and results were found |
|
| 1154 | + continue; |
|
| 1155 | + } |
|
| 1156 | + // 20k limit for performance and reason |
|
| 1157 | + $rr = $this->ldap->search($cr, $base, $filter, array($attr), 0, 20000); |
|
| 1158 | + if(!$this->ldap->isResource($rr)) { |
|
| 1159 | + continue; |
|
| 1160 | + } |
|
| 1161 | + $entries = $this->ldap->countEntries($cr, $rr); |
|
| 1162 | + $getEntryFunc = 'firstEntry'; |
|
| 1163 | + if(($entries !== false) && ($entries > 0)) { |
|
| 1164 | + if(!is_null($maxF) && $entries > $maxEntries) { |
|
| 1165 | + $maxEntries = $entries; |
|
| 1166 | + $maxF = $filter; |
|
| 1167 | + } |
|
| 1168 | + $dnReadCount = 0; |
|
| 1169 | + do { |
|
| 1170 | + $entry = $this->ldap->$getEntryFunc($cr, $rr); |
|
| 1171 | + $getEntryFunc = 'nextEntry'; |
|
| 1172 | + if(!$this->ldap->isResource($entry)) { |
|
| 1173 | + continue 2; |
|
| 1174 | + } |
|
| 1175 | + $rr = $entry; //will be expected by nextEntry next round |
|
| 1176 | + $attributes = $this->ldap->getAttributes($cr, $entry); |
|
| 1177 | + $dn = $this->ldap->getDN($cr, $entry); |
|
| 1178 | + if($dn === false || in_array($dn, $dnRead)) { |
|
| 1179 | + continue; |
|
| 1180 | + } |
|
| 1181 | + $newItems = array(); |
|
| 1182 | + $state = $this->getAttributeValuesFromEntry($attributes, |
|
| 1183 | + $attr, |
|
| 1184 | + $newItems); |
|
| 1185 | + $dnReadCount++; |
|
| 1186 | + $foundItems = array_merge($foundItems, $newItems); |
|
| 1187 | + $this->resultCache[$dn][$attr] = $newItems; |
|
| 1188 | + $dnRead[] = $dn; |
|
| 1189 | + } while(($state === self::LRESULT_PROCESSED_SKIP |
|
| 1190 | + || $this->ldap->isResource($entry)) |
|
| 1191 | + && ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit)); |
|
| 1192 | + } |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + return array_unique($foundItems); |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * determines if and which $attr are available on the LDAP server |
|
| 1200 | + * @param string[] $objectclasses the objectclasses to use as search filter |
|
| 1201 | + * @param string $attr the attribute to look for |
|
| 1202 | + * @param string $dbkey the dbkey of the setting the feature is connected to |
|
| 1203 | + * @param string $confkey the confkey counterpart for the $dbkey as used in the |
|
| 1204 | + * Configuration class |
|
| 1205 | + * @param bool $po whether the objectClass with most result entries |
|
| 1206 | + * shall be pre-selected via the result |
|
| 1207 | + * @return array|false list of found items. |
|
| 1208 | + * @throws \Exception |
|
| 1209 | + */ |
|
| 1210 | + private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) { |
|
| 1211 | + $cr = $this->getConnection(); |
|
| 1212 | + if(!$cr) { |
|
| 1213 | + throw new \Exception('Could not connect to LDAP'); |
|
| 1214 | + } |
|
| 1215 | + $p = 'objectclass='; |
|
| 1216 | + foreach($objectclasses as $key => $value) { |
|
| 1217 | + $objectclasses[$key] = $p.$value; |
|
| 1218 | + } |
|
| 1219 | + $maxEntryObjC = ''; |
|
| 1220 | + |
|
| 1221 | + //how deep to dig? |
|
| 1222 | + //When looking for objectclasses, testing few entries is sufficient, |
|
| 1223 | + $dig = 3; |
|
| 1224 | + |
|
| 1225 | + $availableFeatures = |
|
| 1226 | + $this->cumulativeSearchOnAttribute($objectclasses, $attr, |
|
| 1227 | + $dig, $maxEntryObjC); |
|
| 1228 | + if(is_array($availableFeatures) |
|
| 1229 | + && count($availableFeatures) > 0) { |
|
| 1230 | + natcasesort($availableFeatures); |
|
| 1231 | + //natcasesort keeps indices, but we must get rid of them for proper |
|
| 1232 | + //sorting in the web UI. Therefore: array_values |
|
| 1233 | + $this->result->addOptions($dbkey, array_values($availableFeatures)); |
|
| 1234 | + } else { |
|
| 1235 | + throw new \Exception(self::$l->t('Could not find the desired feature')); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + $setFeatures = $this->configuration->$confkey; |
|
| 1239 | + if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1240 | + //something is already configured? pre-select it. |
|
| 1241 | + $this->result->addChange($dbkey, $setFeatures); |
|
| 1242 | + } else if ($po && $maxEntryObjC !== '') { |
|
| 1243 | + //pre-select objectclass with most result entries |
|
| 1244 | + $maxEntryObjC = str_replace($p, '', $maxEntryObjC); |
|
| 1245 | + $this->applyFind($dbkey, $maxEntryObjC); |
|
| 1246 | + $this->result->addChange($dbkey, $maxEntryObjC); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + return $availableFeatures; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + /** |
|
| 1253 | + * appends a list of values fr |
|
| 1254 | + * @param resource $result the return value from ldap_get_attributes |
|
| 1255 | + * @param string $attribute the attribute values to look for |
|
| 1256 | + * @param array &$known new values will be appended here |
|
| 1257 | + * @return int, state on of the class constants LRESULT_PROCESSED_OK, |
|
| 1258 | + * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP |
|
| 1259 | + */ |
|
| 1260 | + private function getAttributeValuesFromEntry($result, $attribute, &$known) { |
|
| 1261 | + if(!is_array($result) |
|
| 1262 | + || !isset($result['count']) |
|
| 1263 | + || !$result['count'] > 0) { |
|
| 1264 | + return self::LRESULT_PROCESSED_INVALID; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + // strtolower on all keys for proper comparison |
|
| 1268 | + $result = \OCP\Util::mb_array_change_key_case($result); |
|
| 1269 | + $attribute = strtolower($attribute); |
|
| 1270 | + if(isset($result[$attribute])) { |
|
| 1271 | + foreach($result[$attribute] as $key => $val) { |
|
| 1272 | + if($key === 'count') { |
|
| 1273 | + continue; |
|
| 1274 | + } |
|
| 1275 | + if(!in_array($val, $known)) { |
|
| 1276 | + $known[] = $val; |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + return self::LRESULT_PROCESSED_OK; |
|
| 1280 | + } else { |
|
| 1281 | + return self::LRESULT_PROCESSED_SKIP; |
|
| 1282 | + } |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * @return bool|mixed |
|
| 1287 | + */ |
|
| 1288 | + private function getConnection() { |
|
| 1289 | + if(!is_null($this->cr)) { |
|
| 1290 | + return $this->cr; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + $cr = $this->ldap->connect( |
|
| 1294 | + $this->configuration->ldapHost, |
|
| 1295 | + $this->configuration->ldapPort |
|
| 1296 | + ); |
|
| 1297 | + |
|
| 1298 | + $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
|
| 1299 | + $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
|
| 1300 | + $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
|
| 1301 | + if($this->configuration->ldapTLS === 1) { |
|
| 1302 | + $this->ldap->startTls($cr); |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + $lo = @$this->ldap->bind($cr, |
|
| 1306 | + $this->configuration->ldapAgentName, |
|
| 1307 | + $this->configuration->ldapAgentPassword); |
|
| 1308 | + if($lo === true) { |
|
| 1309 | + $this->$cr = $cr; |
|
| 1310 | + return $cr; |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + return false; |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * @return array |
|
| 1318 | + */ |
|
| 1319 | + private function getDefaultLdapPortSettings() { |
|
| 1320 | + static $settings = array( |
|
| 1321 | + array('port' => 7636, 'tls' => false), |
|
| 1322 | + array('port' => 636, 'tls' => false), |
|
| 1323 | + array('port' => 7389, 'tls' => true), |
|
| 1324 | + array('port' => 389, 'tls' => true), |
|
| 1325 | + array('port' => 7389, 'tls' => false), |
|
| 1326 | + array('port' => 389, 'tls' => false), |
|
| 1327 | + ); |
|
| 1328 | + return $settings; |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + /** |
|
| 1332 | + * @return array |
|
| 1333 | + */ |
|
| 1334 | + private function getPortSettingsToTry() { |
|
| 1335 | + //389 ← LDAP / Unencrypted or StartTLS |
|
| 1336 | + //636 ← LDAPS / SSL |
|
| 1337 | + //7xxx ← UCS. need to be checked first, because both ports may be open |
|
| 1338 | + $host = $this->configuration->ldapHost; |
|
| 1339 | + $port = (int)$this->configuration->ldapPort; |
|
| 1340 | + $portSettings = array(); |
|
| 1341 | + |
|
| 1342 | + //In case the port is already provided, we will check this first |
|
| 1343 | + if($port > 0) { |
|
| 1344 | + $hostInfo = parse_url($host); |
|
| 1345 | + if(!(is_array($hostInfo) |
|
| 1346 | + && isset($hostInfo['scheme']) |
|
| 1347 | + && stripos($hostInfo['scheme'], 'ldaps') !== false)) { |
|
| 1348 | + $portSettings[] = array('port' => $port, 'tls' => true); |
|
| 1349 | + } |
|
| 1350 | + $portSettings[] =array('port' => $port, 'tls' => false); |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + //default ports |
|
| 1354 | + $portSettings = array_merge($portSettings, |
|
| 1355 | + $this->getDefaultLdapPortSettings()); |
|
| 1356 | + |
|
| 1357 | + return $portSettings; |
|
| 1358 | + } |
|
| 1359 | 1359 | |
| 1360 | 1360 | |
| 1361 | 1361 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | public function __construct(Configuration $configuration, ILDAPWrapper $ldap, Access $access) { |
| 73 | 73 | parent::__construct($ldap); |
| 74 | 74 | $this->configuration = $configuration; |
| 75 | - if(is_null(Wizard::$l)) { |
|
| 75 | + if (is_null(Wizard::$l)) { |
|
| 76 | 76 | Wizard::$l = \OC::$server->getL10N('user_ldap'); |
| 77 | 77 | } |
| 78 | 78 | $this->access = $access; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | public function __destruct() { |
| 83 | - if($this->result->hasChanges()) { |
|
| 83 | + if ($this->result->hasChanges()) { |
|
| 84 | 84 | $this->configuration->saveConfiguration(); |
| 85 | 85 | } |
| 86 | 86 | } |
@@ -95,18 +95,18 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function countEntries(string $filter, string $type): int { |
| 97 | 97 | $reqs = ['ldapHost', 'ldapPort', 'ldapBase']; |
| 98 | - if($type === 'users') { |
|
| 98 | + if ($type === 'users') { |
|
| 99 | 99 | $reqs[] = 'ldapUserFilter'; |
| 100 | 100 | } |
| 101 | - if(!$this->checkRequirements($reqs)) { |
|
| 101 | + if (!$this->checkRequirements($reqs)) { |
|
| 102 | 102 | throw new \Exception('Requirements not met', 400); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $attr = ['dn']; // default |
| 106 | 106 | $limit = 1001; |
| 107 | - if($type === 'groups') { |
|
| 108 | - $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 109 | - } else if($type === 'users') { |
|
| 107 | + if ($type === 'groups') { |
|
| 108 | + $result = $this->access->countGroups($filter, $attr, $limit); |
|
| 109 | + } else if ($type === 'users') { |
|
| 110 | 110 | $result = $this->access->countUsers($filter, $attr, $limit); |
| 111 | 111 | } else if ($type === 'objects') { |
| 112 | 112 | $result = $this->access->countObjects($limit); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | throw new \Exception('Internal error: Invalid object type', 500); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - return (int)$result; |
|
| 117 | + return (int) $result; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -125,16 +125,16 @@ discard block |
||
| 125 | 125 | * @return string |
| 126 | 126 | */ |
| 127 | 127 | private function formatCountResult(int $count): string { |
| 128 | - if($count > 1000) { |
|
| 128 | + if ($count > 1000) { |
|
| 129 | 129 | return '> 1000'; |
| 130 | 130 | } |
| 131 | - return (string)$count; |
|
| 131 | + return (string) $count; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | public function countGroups() { |
| 135 | 135 | $filter = $this->configuration->ldapGroupFilter; |
| 136 | 136 | |
| 137 | - if(empty($filter)) { |
|
| 137 | + if (empty($filter)) { |
|
| 138 | 138 | $output = self::$l->n('%s group found', '%s groups found', 0, array(0)); |
| 139 | 139 | $this->result->addChange('ldap_group_count', $output); |
| 140 | 140 | return $this->result; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $groupsTotal = $this->countEntries($filter, 'groups'); |
| 145 | 145 | } catch (\Exception $e) { |
| 146 | 146 | //400 can be ignored, 500 is forwarded |
| 147 | - if($e->getCode() === 500) { |
|
| 147 | + if ($e->getCode() === 500) { |
|
| 148 | 148 | throw $e; |
| 149 | 149 | } |
| 150 | 150 | return false; |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | public function countInBaseDN() { |
| 187 | 187 | // we don't need to provide a filter in this case |
| 188 | 188 | $total = $this->countEntries('', 'objects'); |
| 189 | - if($total === false) { |
|
| 189 | + if ($total === false) { |
|
| 190 | 190 | throw new \Exception('invalid results received'); |
| 191 | 191 | } |
| 192 | 192 | $this->result->addChange('ldap_test_base', $total); |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | * @return int|bool |
| 201 | 201 | */ |
| 202 | 202 | public function countUsersWithAttribute($attr, $existsCheck = false) { |
| 203 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 203 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 204 | 204 | 'ldapPort', |
| 205 | 205 | 'ldapBase', |
| 206 | 206 | 'ldapUserFilter', |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $filter = $this->access->combineFilterWithAnd(array( |
| 212 | 212 | $this->configuration->ldapUserFilter, |
| 213 | - $attr . '=*' |
|
| 213 | + $attr.'=*' |
|
| 214 | 214 | )); |
| 215 | 215 | |
| 216 | 216 | $limit = ($existsCheck === false) ? null : 1; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @throws \Exception |
| 226 | 226 | */ |
| 227 | 227 | public function detectUserDisplayNameAttribute() { |
| 228 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 228 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 229 | 229 | 'ldapPort', |
| 230 | 230 | 'ldapBase', |
| 231 | 231 | 'ldapUserFilter', |
@@ -237,8 +237,8 @@ discard block |
||
| 237 | 237 | if ($attr !== '' && $attr !== 'displayName') { |
| 238 | 238 | // most likely not the default value with upper case N, |
| 239 | 239 | // verify it still produces a result |
| 240 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 241 | - if($count > 0) { |
|
| 240 | + $count = (int) $this->countUsersWithAttribute($attr, true); |
|
| 241 | + if ($count > 0) { |
|
| 242 | 242 | //no change, but we sent it back to make sure the user interface |
| 243 | 243 | //is still correct, even if the ajax call was cancelled meanwhile |
| 244 | 244 | $this->result->addChange('ldap_display_name', $attr); |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | // first attribute that has at least one result wins |
| 250 | 250 | $displayNameAttrs = array('displayname', 'cn'); |
| 251 | 251 | foreach ($displayNameAttrs as $attr) { |
| 252 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 252 | + $count = (int) $this->countUsersWithAttribute($attr, true); |
|
| 253 | 253 | |
| 254 | - if($count > 0) { |
|
| 254 | + if ($count > 0) { |
|
| 255 | 255 | $this->applyFind('ldap_display_name', $attr); |
| 256 | 256 | return $this->result; |
| 257 | 257 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @return WizardResult|bool |
| 268 | 268 | */ |
| 269 | 269 | public function detectEmailAttribute() { |
| 270 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 270 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 271 | 271 | 'ldapPort', |
| 272 | 272 | 'ldapBase', |
| 273 | 273 | 'ldapUserFilter', |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | $attr = $this->configuration->ldapEmailAttribute; |
| 279 | 279 | if ($attr !== '') { |
| 280 | - $count = (int)$this->countUsersWithAttribute($attr, true); |
|
| 281 | - if($count > 0) { |
|
| 280 | + $count = (int) $this->countUsersWithAttribute($attr, true); |
|
| 281 | + if ($count > 0) { |
|
| 282 | 282 | return false; |
| 283 | 283 | } |
| 284 | 284 | $writeLog = true; |
@@ -289,19 +289,19 @@ discard block |
||
| 289 | 289 | $emailAttributes = array('mail', 'mailPrimaryAddress'); |
| 290 | 290 | $winner = ''; |
| 291 | 291 | $maxUsers = 0; |
| 292 | - foreach($emailAttributes as $attr) { |
|
| 292 | + foreach ($emailAttributes as $attr) { |
|
| 293 | 293 | $count = $this->countUsersWithAttribute($attr); |
| 294 | - if($count > $maxUsers) { |
|
| 294 | + if ($count > $maxUsers) { |
|
| 295 | 295 | $maxUsers = $count; |
| 296 | 296 | $winner = $attr; |
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - if($winner !== '') { |
|
| 300 | + if ($winner !== '') { |
|
| 301 | 301 | $this->applyFind('ldap_email_attr', $winner); |
| 302 | - if($writeLog) { |
|
| 303 | - \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . |
|
| 304 | - 'automatically been reset, because the original value ' . |
|
| 302 | + if ($writeLog) { |
|
| 303 | + \OCP\Util::writeLog('user_ldap', 'The mail attribute has '. |
|
| 304 | + 'automatically been reset, because the original value '. |
|
| 305 | 305 | 'did not return any results.', ILogger::INFO); |
| 306 | 306 | } |
| 307 | 307 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @throws \Exception |
| 315 | 315 | */ |
| 316 | 316 | public function determineAttributes() { |
| 317 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 317 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 318 | 318 | 'ldapPort', |
| 319 | 319 | 'ldapBase', |
| 320 | 320 | 'ldapUserFilter', |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $this->result->addOptions('ldap_loginfilter_attributes', $attributes); |
| 331 | 331 | |
| 332 | 332 | $selected = $this->configuration->ldapLoginFilterAttributes; |
| 333 | - if(is_array($selected) && !empty($selected)) { |
|
| 333 | + if (is_array($selected) && !empty($selected)) { |
|
| 334 | 334 | $this->result->addChange('ldap_loginfilter_attributes', $selected); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | * @throws \Exception |
| 344 | 344 | */ |
| 345 | 345 | private function getUserAttributes() { |
| 346 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 346 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 347 | 347 | 'ldapPort', |
| 348 | 348 | 'ldapBase', |
| 349 | 349 | 'ldapUserFilter', |
@@ -351,20 +351,20 @@ discard block |
||
| 351 | 351 | return false; |
| 352 | 352 | } |
| 353 | 353 | $cr = $this->getConnection(); |
| 354 | - if(!$cr) { |
|
| 354 | + if (!$cr) { |
|
| 355 | 355 | throw new \Exception('Could not connect to LDAP'); |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | $base = $this->configuration->ldapBase[0]; |
| 359 | 359 | $filter = $this->configuration->ldapUserFilter; |
| 360 | 360 | $rr = $this->ldap->search($cr, $base, $filter, array(), 1, 1); |
| 361 | - if(!$this->ldap->isResource($rr)) { |
|
| 361 | + if (!$this->ldap->isResource($rr)) { |
|
| 362 | 362 | return false; |
| 363 | 363 | } |
| 364 | 364 | $er = $this->ldap->firstEntry($cr, $rr); |
| 365 | 365 | $attributes = $this->ldap->getAttributes($cr, $er); |
| 366 | 366 | $pureAttributes = array(); |
| 367 | - for($i = 0; $i < $attributes['count']; $i++) { |
|
| 367 | + for ($i = 0; $i < $attributes['count']; $i++) { |
|
| 368 | 368 | $pureAttributes[] = $attributes[$i]; |
| 369 | 369 | } |
| 370 | 370 | |
@@ -399,23 +399,23 @@ discard block |
||
| 399 | 399 | * @throws \Exception |
| 400 | 400 | */ |
| 401 | 401 | private function determineGroups($dbKey, $confKey, $testMemberOf = true) { |
| 402 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 402 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 403 | 403 | 'ldapPort', |
| 404 | 404 | 'ldapBase', |
| 405 | 405 | ))) { |
| 406 | 406 | return false; |
| 407 | 407 | } |
| 408 | 408 | $cr = $this->getConnection(); |
| 409 | - if(!$cr) { |
|
| 409 | + if (!$cr) { |
|
| 410 | 410 | throw new \Exception('Could not connect to LDAP'); |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | $this->fetchGroups($dbKey, $confKey); |
| 414 | 414 | |
| 415 | - if($testMemberOf) { |
|
| 415 | + if ($testMemberOf) { |
|
| 416 | 416 | $this->configuration->hasMemberOfFilterSupport = $this->testMemberOf(); |
| 417 | 417 | $this->result->markChange(); |
| 418 | - if(!$this->configuration->hasMemberOfFilterSupport) { |
|
| 418 | + if (!$this->configuration->hasMemberOfFilterSupport) { |
|
| 419 | 419 | throw new \Exception('memberOf is not supported by the server'); |
| 420 | 420 | } |
| 421 | 421 | } |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames', 'groupOfUniqueNames'); |
| 436 | 436 | |
| 437 | 437 | $filterParts = array(); |
| 438 | - foreach($obclasses as $obclass) { |
|
| 438 | + foreach ($obclasses as $obclass) { |
|
| 439 | 439 | $filterParts[] = 'objectclass='.$obclass; |
| 440 | 440 | } |
| 441 | 441 | //we filter for everything |
@@ -452,8 +452,8 @@ discard block |
||
| 452 | 452 | // we need to request dn additionally here, otherwise memberOf |
| 453 | 453 | // detection will fail later |
| 454 | 454 | $result = $this->access->searchGroups($filter, array('cn', 'dn'), $limit, $offset); |
| 455 | - foreach($result as $item) { |
|
| 456 | - if(!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 455 | + foreach ($result as $item) { |
|
| 456 | + if (!isset($item['cn']) && !is_array($item['cn']) && !isset($item['cn'][0])) { |
|
| 457 | 457 | // just in case - no issue known |
| 458 | 458 | continue; |
| 459 | 459 | } |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | $offset += $limit; |
| 464 | 464 | } while ($this->access->hasMoreResults()); |
| 465 | 465 | |
| 466 | - if(count($groupNames) > 0) { |
|
| 466 | + if (count($groupNames) > 0) { |
|
| 467 | 467 | natsort($groupNames); |
| 468 | 468 | $this->result->addOptions($dbKey, array_values($groupNames)); |
| 469 | 469 | } else { |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | $setFeatures = $this->configuration->$confKey; |
| 474 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 474 | + if (is_array($setFeatures) && !empty($setFeatures)) { |
|
| 475 | 475 | //something is already configured? pre-select it. |
| 476 | 476 | $this->result->addChange($dbKey, $setFeatures); |
| 477 | 477 | } |
@@ -479,14 +479,14 @@ discard block |
||
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | public function determineGroupMemberAssoc() { |
| 482 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 482 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 483 | 483 | 'ldapPort', |
| 484 | 484 | 'ldapGroupFilter', |
| 485 | 485 | ))) { |
| 486 | 486 | return false; |
| 487 | 487 | } |
| 488 | 488 | $attribute = $this->detectGroupMemberAssoc(); |
| 489 | - if($attribute === false) { |
|
| 489 | + if ($attribute === false) { |
|
| 490 | 490 | return false; |
| 491 | 491 | } |
| 492 | 492 | $this->configuration->setConfiguration(array('ldapGroupMemberAssocAttr' => $attribute)); |
@@ -501,14 +501,14 @@ discard block |
||
| 501 | 501 | * @throws \Exception |
| 502 | 502 | */ |
| 503 | 503 | public function determineGroupObjectClasses() { |
| 504 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 504 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 505 | 505 | 'ldapPort', |
| 506 | 506 | 'ldapBase', |
| 507 | 507 | ))) { |
| 508 | 508 | return false; |
| 509 | 509 | } |
| 510 | 510 | $cr = $this->getConnection(); |
| 511 | - if(!$cr) { |
|
| 511 | + if (!$cr) { |
|
| 512 | 512 | throw new \Exception('Could not connect to LDAP'); |
| 513 | 513 | } |
| 514 | 514 | |
@@ -528,14 +528,14 @@ discard block |
||
| 528 | 528 | * @throws \Exception |
| 529 | 529 | */ |
| 530 | 530 | public function determineUserObjectClasses() { |
| 531 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 531 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 532 | 532 | 'ldapPort', |
| 533 | 533 | 'ldapBase', |
| 534 | 534 | ))) { |
| 535 | 535 | return false; |
| 536 | 536 | } |
| 537 | 537 | $cr = $this->getConnection(); |
| 538 | - if(!$cr) { |
|
| 538 | + if (!$cr) { |
|
| 539 | 539 | throw new \Exception('Could not connect to LDAP'); |
| 540 | 540 | } |
| 541 | 541 | |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * @throws \Exception |
| 559 | 559 | */ |
| 560 | 560 | public function getGroupFilter() { |
| 561 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 561 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 562 | 562 | 'ldapPort', |
| 563 | 563 | 'ldapBase', |
| 564 | 564 | ))) { |
@@ -582,7 +582,7 @@ discard block |
||
| 582 | 582 | * @throws \Exception |
| 583 | 583 | */ |
| 584 | 584 | public function getUserListFilter() { |
| 585 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 585 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 586 | 586 | 'ldapPort', |
| 587 | 587 | 'ldapBase', |
| 588 | 588 | ))) { |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | $this->applyFind('ldap_display_name', $d['ldap_display_name']); |
| 596 | 596 | } |
| 597 | 597 | $filter = $this->composeLdapFilter(self::LFILTER_USER_LIST); |
| 598 | - if(!$filter) { |
|
| 598 | + if (!$filter) { |
|
| 599 | 599 | throw new \Exception('Cannot create filter'); |
| 600 | 600 | } |
| 601 | 601 | |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * @throws \Exception |
| 609 | 609 | */ |
| 610 | 610 | public function getUserLoginFilter() { |
| 611 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 611 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 612 | 612 | 'ldapPort', |
| 613 | 613 | 'ldapBase', |
| 614 | 614 | 'ldapUserFilter', |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | $filter = $this->composeLdapFilter(self::LFILTER_LOGIN); |
| 620 | - if(!$filter) { |
|
| 620 | + if (!$filter) { |
|
| 621 | 621 | throw new \Exception('Cannot create filter'); |
| 622 | 622 | } |
| 623 | 623 | |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | * @throws \Exception |
| 632 | 632 | */ |
| 633 | 633 | public function testLoginName($loginName) { |
| 634 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 634 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 635 | 635 | 'ldapPort', |
| 636 | 636 | 'ldapBase', |
| 637 | 637 | 'ldapLoginFilter', |
@@ -640,17 +640,17 @@ discard block |
||
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | $cr = $this->access->connection->getConnectionResource(); |
| 643 | - if(!$this->ldap->isResource($cr)) { |
|
| 643 | + if (!$this->ldap->isResource($cr)) { |
|
| 644 | 644 | throw new \Exception('connection error'); |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if(mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 647 | + if (mb_strpos($this->access->connection->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
| 648 | 648 | === false) { |
| 649 | 649 | throw new \Exception('missing placeholder'); |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | $users = $this->access->countUsersByLoginName($loginName); |
| 653 | - if($this->ldap->errno($cr) !== 0) { |
|
| 653 | + if ($this->ldap->errno($cr) !== 0) { |
|
| 654 | 654 | throw new \Exception($this->ldap->error($cr)); |
| 655 | 655 | } |
| 656 | 656 | $filter = str_replace('%uid', $loginName, $this->access->connection->ldapLoginFilter); |
@@ -665,22 +665,22 @@ discard block |
||
| 665 | 665 | * @throws \Exception |
| 666 | 666 | */ |
| 667 | 667 | public function guessPortAndTLS() { |
| 668 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 668 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 669 | 669 | ))) { |
| 670 | 670 | return false; |
| 671 | 671 | } |
| 672 | 672 | $this->checkHost(); |
| 673 | 673 | $portSettings = $this->getPortSettingsToTry(); |
| 674 | 674 | |
| 675 | - if(!is_array($portSettings)) { |
|
| 675 | + if (!is_array($portSettings)) { |
|
| 676 | 676 | throw new \Exception(print_r($portSettings, true)); |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | //proceed from the best configuration and return on first success |
| 680 | - foreach($portSettings as $setting) { |
|
| 680 | + foreach ($portSettings as $setting) { |
|
| 681 | 681 | $p = $setting['port']; |
| 682 | 682 | $t = $setting['tls']; |
| 683 | - \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, ILogger::DEBUG); |
|
| 683 | + \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '.$p.', TLS '.$t, ILogger::DEBUG); |
|
| 684 | 684 | //connectAndBind may throw Exception, it needs to be catched by the |
| 685 | 685 | //callee of this method |
| 686 | 686 | |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | // any reply other than -1 (= cannot connect) is already okay, |
| 691 | 691 | // because then we found the server |
| 692 | 692 | // unavailable startTLS returns -11 |
| 693 | - if($e->getCode() > 0) { |
|
| 693 | + if ($e->getCode() > 0) { |
|
| 694 | 694 | $settingsFound = true; |
| 695 | 695 | } else { |
| 696 | 696 | throw $e; |
@@ -700,10 +700,10 @@ discard block |
||
| 700 | 700 | if ($settingsFound === true) { |
| 701 | 701 | $config = array( |
| 702 | 702 | 'ldapPort' => $p, |
| 703 | - 'ldapTLS' => (int)$t |
|
| 703 | + 'ldapTLS' => (int) $t |
|
| 704 | 704 | ); |
| 705 | 705 | $this->configuration->setConfiguration($config); |
| 706 | - \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, ILogger::DEBUG); |
|
| 706 | + \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port '.$p, ILogger::DEBUG); |
|
| 707 | 707 | $this->result->addChange('ldap_port', $p); |
| 708 | 708 | return $this->result; |
| 709 | 709 | } |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | * @return WizardResult|false WizardResult on success, false otherwise |
| 719 | 719 | */ |
| 720 | 720 | public function guessBaseDN() { |
| 721 | - if(!$this->checkRequirements(array('ldapHost', |
|
| 721 | + if (!$this->checkRequirements(array('ldapHost', |
|
| 722 | 722 | 'ldapPort', |
| 723 | 723 | ))) { |
| 724 | 724 | return false; |
@@ -727,9 +727,9 @@ discard block |
||
| 727 | 727 | //check whether a DN is given in the agent name (99.9% of all cases) |
| 728 | 728 | $base = null; |
| 729 | 729 | $i = stripos($this->configuration->ldapAgentName, 'dc='); |
| 730 | - if($i !== false) { |
|
| 730 | + if ($i !== false) { |
|
| 731 | 731 | $base = substr($this->configuration->ldapAgentName, $i); |
| 732 | - if($this->testBaseDN($base)) { |
|
| 732 | + if ($this->testBaseDN($base)) { |
|
| 733 | 733 | $this->applyFind('ldap_base', $base); |
| 734 | 734 | return $this->result; |
| 735 | 735 | } |
@@ -740,13 +740,13 @@ discard block |
||
| 740 | 740 | //a base DN |
| 741 | 741 | $helper = new Helper(\OC::$server->getConfig()); |
| 742 | 742 | $domain = $helper->getDomainFromURL($this->configuration->ldapHost); |
| 743 | - if(!$domain) { |
|
| 743 | + if (!$domain) { |
|
| 744 | 744 | return false; |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | $dparts = explode('.', $domain); |
| 748 | - while(count($dparts) > 0) { |
|
| 749 | - $base2 = 'dc=' . implode(',dc=', $dparts); |
|
| 748 | + while (count($dparts) > 0) { |
|
| 749 | + $base2 = 'dc='.implode(',dc=', $dparts); |
|
| 750 | 750 | if ($base !== $base2 && $this->testBaseDN($base2)) { |
| 751 | 751 | $this->applyFind('ldap_base', $base2); |
| 752 | 752 | return $this->result; |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | $hostInfo = parse_url($host); |
| 780 | 780 | |
| 781 | 781 | //removes Port from Host |
| 782 | - if(is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 782 | + if (is_array($hostInfo) && isset($hostInfo['port'])) { |
|
| 783 | 783 | $port = $hostInfo['port']; |
| 784 | 784 | $host = str_replace(':'.$port, '', $host); |
| 785 | 785 | $this->applyFind('ldap_host', $host); |
@@ -796,30 +796,30 @@ discard block |
||
| 796 | 796 | private function detectGroupMemberAssoc() { |
| 797 | 797 | $possibleAttrs = array('uniqueMember', 'memberUid', 'member', 'gidNumber'); |
| 798 | 798 | $filter = $this->configuration->ldapGroupFilter; |
| 799 | - if(empty($filter)) { |
|
| 799 | + if (empty($filter)) { |
|
| 800 | 800 | return false; |
| 801 | 801 | } |
| 802 | 802 | $cr = $this->getConnection(); |
| 803 | - if(!$cr) { |
|
| 803 | + if (!$cr) { |
|
| 804 | 804 | throw new \Exception('Could not connect to LDAP'); |
| 805 | 805 | } |
| 806 | 806 | $base = $this->configuration->ldapBase[0]; |
| 807 | 807 | $rr = $this->ldap->search($cr, $base, $filter, $possibleAttrs, 0, 1000); |
| 808 | - if(!$this->ldap->isResource($rr)) { |
|
| 808 | + if (!$this->ldap->isResource($rr)) { |
|
| 809 | 809 | return false; |
| 810 | 810 | } |
| 811 | 811 | $er = $this->ldap->firstEntry($cr, $rr); |
| 812 | - while(is_resource($er)) { |
|
| 812 | + while (is_resource($er)) { |
|
| 813 | 813 | $this->ldap->getDN($cr, $er); |
| 814 | 814 | $attrs = $this->ldap->getAttributes($cr, $er); |
| 815 | 815 | $result = array(); |
| 816 | 816 | $possibleAttrsCount = count($possibleAttrs); |
| 817 | - for($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 818 | - if(isset($attrs[$possibleAttrs[$i]])) { |
|
| 817 | + for ($i = 0; $i < $possibleAttrsCount; $i++) { |
|
| 818 | + if (isset($attrs[$possibleAttrs[$i]])) { |
|
| 819 | 819 | $result[$possibleAttrs[$i]] = $attrs[$possibleAttrs[$i]]['count']; |
| 820 | 820 | } |
| 821 | 821 | } |
| 822 | - if(!empty($result)) { |
|
| 822 | + if (!empty($result)) { |
|
| 823 | 823 | natsort($result); |
| 824 | 824 | return key($result); |
| 825 | 825 | } |
@@ -838,14 +838,14 @@ discard block |
||
| 838 | 838 | */ |
| 839 | 839 | private function testBaseDN($base) { |
| 840 | 840 | $cr = $this->getConnection(); |
| 841 | - if(!$cr) { |
|
| 841 | + if (!$cr) { |
|
| 842 | 842 | throw new \Exception('Could not connect to LDAP'); |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | //base is there, let's validate it. If we search for anything, we should |
| 846 | 846 | //get a result set > 0 on a proper base |
| 847 | 847 | $rr = $this->ldap->search($cr, $base, 'objectClass=*', array('dn'), 0, 1); |
| 848 | - if(!$this->ldap->isResource($rr)) { |
|
| 848 | + if (!$this->ldap->isResource($rr)) { |
|
| 849 | 849 | $errorNo = $this->ldap->errno($cr); |
| 850 | 850 | $errorMsg = $this->ldap->error($cr); |
| 851 | 851 | \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. |
@@ -867,11 +867,11 @@ discard block |
||
| 867 | 867 | */ |
| 868 | 868 | private function testMemberOf() { |
| 869 | 869 | $cr = $this->getConnection(); |
| 870 | - if(!$cr) { |
|
| 870 | + if (!$cr) { |
|
| 871 | 871 | throw new \Exception('Could not connect to LDAP'); |
| 872 | 872 | } |
| 873 | 873 | $result = $this->access->countUsers('memberOf=*', array('memberOf'), 1); |
| 874 | - if(is_int($result) && $result > 0) { |
|
| 874 | + if (is_int($result) && $result > 0) { |
|
| 875 | 875 | return true; |
| 876 | 876 | } |
| 877 | 877 | return false; |
@@ -892,27 +892,27 @@ discard block |
||
| 892 | 892 | case self::LFILTER_USER_LIST: |
| 893 | 893 | $objcs = $this->configuration->ldapUserFilterObjectclass; |
| 894 | 894 | //glue objectclasses |
| 895 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 895 | + if (is_array($objcs) && count($objcs) > 0) { |
|
| 896 | 896 | $filter .= '(|'; |
| 897 | - foreach($objcs as $objc) { |
|
| 898 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 897 | + foreach ($objcs as $objc) { |
|
| 898 | + $filter .= '(objectclass='.$objc.')'; |
|
| 899 | 899 | } |
| 900 | 900 | $filter .= ')'; |
| 901 | 901 | $parts++; |
| 902 | 902 | } |
| 903 | 903 | //glue group memberships |
| 904 | - if($this->configuration->hasMemberOfFilterSupport) { |
|
| 904 | + if ($this->configuration->hasMemberOfFilterSupport) { |
|
| 905 | 905 | $cns = $this->configuration->ldapUserFilterGroups; |
| 906 | - if(is_array($cns) && count($cns) > 0) { |
|
| 906 | + if (is_array($cns) && count($cns) > 0) { |
|
| 907 | 907 | $filter .= '(|'; |
| 908 | 908 | $cr = $this->getConnection(); |
| 909 | - if(!$cr) { |
|
| 909 | + if (!$cr) { |
|
| 910 | 910 | throw new \Exception('Could not connect to LDAP'); |
| 911 | 911 | } |
| 912 | 912 | $base = $this->configuration->ldapBase[0]; |
| 913 | - foreach($cns as $cn) { |
|
| 914 | - $rr = $this->ldap->search($cr, $base, 'cn=' . $cn, array('dn', 'primaryGroupToken')); |
|
| 915 | - if(!$this->ldap->isResource($rr)) { |
|
| 913 | + foreach ($cns as $cn) { |
|
| 914 | + $rr = $this->ldap->search($cr, $base, 'cn='.$cn, array('dn', 'primaryGroupToken')); |
|
| 915 | + if (!$this->ldap->isResource($rr)) { |
|
| 916 | 916 | continue; |
| 917 | 917 | } |
| 918 | 918 | $er = $this->ldap->firstEntry($cr, $rr); |
@@ -921,11 +921,11 @@ discard block |
||
| 921 | 921 | if ($dn === false || $dn === '') { |
| 922 | 922 | continue; |
| 923 | 923 | } |
| 924 | - $filterPart = '(memberof=' . $dn . ')'; |
|
| 925 | - if(isset($attrs['primaryGroupToken'])) { |
|
| 924 | + $filterPart = '(memberof='.$dn.')'; |
|
| 925 | + if (isset($attrs['primaryGroupToken'])) { |
|
| 926 | 926 | $pgt = $attrs['primaryGroupToken'][0]; |
| 927 | - $primaryFilterPart = '(primaryGroupID=' . $pgt .')'; |
|
| 928 | - $filterPart = '(|' . $filterPart . $primaryFilterPart . ')'; |
|
| 927 | + $primaryFilterPart = '(primaryGroupID='.$pgt.')'; |
|
| 928 | + $filterPart = '(|'.$filterPart.$primaryFilterPart.')'; |
|
| 929 | 929 | } |
| 930 | 930 | $filter .= $filterPart; |
| 931 | 931 | } |
@@ -934,8 +934,8 @@ discard block |
||
| 934 | 934 | $parts++; |
| 935 | 935 | } |
| 936 | 936 | //wrap parts in AND condition |
| 937 | - if($parts > 1) { |
|
| 938 | - $filter = '(&' . $filter . ')'; |
|
| 937 | + if ($parts > 1) { |
|
| 938 | + $filter = '(&'.$filter.')'; |
|
| 939 | 939 | } |
| 940 | 940 | if ($filter === '') { |
| 941 | 941 | $filter = '(objectclass=*)'; |
@@ -945,27 +945,27 @@ discard block |
||
| 945 | 945 | case self::LFILTER_GROUP_LIST: |
| 946 | 946 | $objcs = $this->configuration->ldapGroupFilterObjectclass; |
| 947 | 947 | //glue objectclasses |
| 948 | - if(is_array($objcs) && count($objcs) > 0) { |
|
| 948 | + if (is_array($objcs) && count($objcs) > 0) { |
|
| 949 | 949 | $filter .= '(|'; |
| 950 | - foreach($objcs as $objc) { |
|
| 951 | - $filter .= '(objectclass=' . $objc . ')'; |
|
| 950 | + foreach ($objcs as $objc) { |
|
| 951 | + $filter .= '(objectclass='.$objc.')'; |
|
| 952 | 952 | } |
| 953 | 953 | $filter .= ')'; |
| 954 | 954 | $parts++; |
| 955 | 955 | } |
| 956 | 956 | //glue group memberships |
| 957 | 957 | $cns = $this->configuration->ldapGroupFilterGroups; |
| 958 | - if(is_array($cns) && count($cns) > 0) { |
|
| 958 | + if (is_array($cns) && count($cns) > 0) { |
|
| 959 | 959 | $filter .= '(|'; |
| 960 | - foreach($cns as $cn) { |
|
| 961 | - $filter .= '(cn=' . $cn . ')'; |
|
| 960 | + foreach ($cns as $cn) { |
|
| 961 | + $filter .= '(cn='.$cn.')'; |
|
| 962 | 962 | } |
| 963 | 963 | $filter .= ')'; |
| 964 | 964 | } |
| 965 | 965 | $parts++; |
| 966 | 966 | //wrap parts in AND condition |
| 967 | - if($parts > 1) { |
|
| 968 | - $filter = '(&' . $filter . ')'; |
|
| 967 | + if ($parts > 1) { |
|
| 968 | + $filter = '(&'.$filter.')'; |
|
| 969 | 969 | } |
| 970 | 970 | break; |
| 971 | 971 | |
@@ -977,47 +977,47 @@ discard block |
||
| 977 | 977 | $userAttributes = array_change_key_case(array_flip($userAttributes)); |
| 978 | 978 | $parts = 0; |
| 979 | 979 | |
| 980 | - if($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 980 | + if ($this->configuration->ldapLoginFilterUsername === '1') { |
|
| 981 | 981 | $attr = ''; |
| 982 | - if(isset($userAttributes['uid'])) { |
|
| 982 | + if (isset($userAttributes['uid'])) { |
|
| 983 | 983 | $attr = 'uid'; |
| 984 | - } else if(isset($userAttributes['samaccountname'])) { |
|
| 984 | + } else if (isset($userAttributes['samaccountname'])) { |
|
| 985 | 985 | $attr = 'samaccountname'; |
| 986 | - } else if(isset($userAttributes['cn'])) { |
|
| 986 | + } else if (isset($userAttributes['cn'])) { |
|
| 987 | 987 | //fallback |
| 988 | 988 | $attr = 'cn'; |
| 989 | 989 | } |
| 990 | 990 | if ($attr !== '') { |
| 991 | - $filterUsername = '(' . $attr . $loginpart . ')'; |
|
| 991 | + $filterUsername = '('.$attr.$loginpart.')'; |
|
| 992 | 992 | $parts++; |
| 993 | 993 | } |
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | $filterEmail = ''; |
| 997 | - if($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 997 | + if ($this->configuration->ldapLoginFilterEmail === '1') { |
|
| 998 | 998 | $filterEmail = '(|(mailPrimaryAddress=%uid)(mail=%uid))'; |
| 999 | 999 | $parts++; |
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | $filterAttributes = ''; |
| 1003 | 1003 | $attrsToFilter = $this->configuration->ldapLoginFilterAttributes; |
| 1004 | - if(is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 1004 | + if (is_array($attrsToFilter) && count($attrsToFilter) > 0) { |
|
| 1005 | 1005 | $filterAttributes = '(|'; |
| 1006 | - foreach($attrsToFilter as $attribute) { |
|
| 1007 | - $filterAttributes .= '(' . $attribute . $loginpart . ')'; |
|
| 1006 | + foreach ($attrsToFilter as $attribute) { |
|
| 1007 | + $filterAttributes .= '('.$attribute.$loginpart.')'; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | $filterAttributes .= ')'; |
| 1010 | 1010 | $parts++; |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | $filterLogin = ''; |
| 1014 | - if($parts > 1) { |
|
| 1014 | + if ($parts > 1) { |
|
| 1015 | 1015 | $filterLogin = '(|'; |
| 1016 | 1016 | } |
| 1017 | 1017 | $filterLogin .= $filterUsername; |
| 1018 | 1018 | $filterLogin .= $filterEmail; |
| 1019 | 1019 | $filterLogin .= $filterAttributes; |
| 1020 | - if($parts > 1) { |
|
| 1020 | + if ($parts > 1) { |
|
| 1021 | 1021 | $filterLogin .= ')'; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
@@ -1042,12 +1042,12 @@ discard block |
||
| 1042 | 1042 | //connect, does not really trigger any server communication |
| 1043 | 1043 | $host = $this->configuration->ldapHost; |
| 1044 | 1044 | $hostInfo = parse_url($host); |
| 1045 | - if(!$hostInfo) { |
|
| 1045 | + if (!$hostInfo) { |
|
| 1046 | 1046 | throw new \Exception(self::$l->t('Invalid Host')); |
| 1047 | 1047 | } |
| 1048 | 1048 | \OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', ILogger::DEBUG); |
| 1049 | 1049 | $cr = $this->ldap->connect($host, $port); |
| 1050 | - if(!is_resource($cr)) { |
|
| 1050 | + if (!is_resource($cr)) { |
|
| 1051 | 1051 | throw new \Exception(self::$l->t('Invalid Host')); |
| 1052 | 1052 | } |
| 1053 | 1053 | |
@@ -1057,9 +1057,9 @@ discard block |
||
| 1057 | 1057 | $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
| 1058 | 1058 | |
| 1059 | 1059 | try { |
| 1060 | - if($tls) { |
|
| 1060 | + if ($tls) { |
|
| 1061 | 1061 | $isTlsWorking = @$this->ldap->startTls($cr); |
| 1062 | - if(!$isTlsWorking) { |
|
| 1062 | + if (!$isTlsWorking) { |
|
| 1063 | 1063 | return false; |
| 1064 | 1064 | } |
| 1065 | 1065 | } |
@@ -1073,17 +1073,17 @@ discard block |
||
| 1073 | 1073 | $errNo = $this->ldap->errno($cr); |
| 1074 | 1074 | $error = ldap_error($cr); |
| 1075 | 1075 | $this->ldap->unbind($cr); |
| 1076 | - } catch(ServerNotAvailableException $e) { |
|
| 1076 | + } catch (ServerNotAvailableException $e) { |
|
| 1077 | 1077 | return false; |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | - if($login === true) { |
|
| 1080 | + if ($login === true) { |
|
| 1081 | 1081 | $this->ldap->unbind($cr); |
| 1082 | - \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, ILogger::DEBUG); |
|
| 1082 | + \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '.$port.' TLS '.(int) $tls, ILogger::DEBUG); |
|
| 1083 | 1083 | return true; |
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | - if($errNo === -1) { |
|
| 1086 | + if ($errNo === -1) { |
|
| 1087 | 1087 | //host, port or TLS wrong |
| 1088 | 1088 | return false; |
| 1089 | 1089 | } |
@@ -1111,9 +1111,9 @@ discard block |
||
| 1111 | 1111 | */ |
| 1112 | 1112 | private function checkRequirements($reqs) { |
| 1113 | 1113 | $this->checkAgentRequirements(); |
| 1114 | - foreach($reqs as $option) { |
|
| 1114 | + foreach ($reqs as $option) { |
|
| 1115 | 1115 | $value = $this->configuration->$option; |
| 1116 | - if(empty($value)) { |
|
| 1116 | + if (empty($value)) { |
|
| 1117 | 1117 | return false; |
| 1118 | 1118 | } |
| 1119 | 1119 | } |
@@ -1135,33 +1135,33 @@ discard block |
||
| 1135 | 1135 | $dnRead = array(); |
| 1136 | 1136 | $foundItems = array(); |
| 1137 | 1137 | $maxEntries = 0; |
| 1138 | - if(!is_array($this->configuration->ldapBase) |
|
| 1138 | + if (!is_array($this->configuration->ldapBase) |
|
| 1139 | 1139 | || !isset($this->configuration->ldapBase[0])) { |
| 1140 | 1140 | return false; |
| 1141 | 1141 | } |
| 1142 | 1142 | $base = $this->configuration->ldapBase[0]; |
| 1143 | 1143 | $cr = $this->getConnection(); |
| 1144 | - if(!$this->ldap->isResource($cr)) { |
|
| 1144 | + if (!$this->ldap->isResource($cr)) { |
|
| 1145 | 1145 | return false; |
| 1146 | 1146 | } |
| 1147 | 1147 | $lastFilter = null; |
| 1148 | - if(isset($filters[count($filters)-1])) { |
|
| 1149 | - $lastFilter = $filters[count($filters)-1]; |
|
| 1148 | + if (isset($filters[count($filters) - 1])) { |
|
| 1149 | + $lastFilter = $filters[count($filters) - 1]; |
|
| 1150 | 1150 | } |
| 1151 | - foreach($filters as $filter) { |
|
| 1152 | - if($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1151 | + foreach ($filters as $filter) { |
|
| 1152 | + if ($lastFilter === $filter && count($foundItems) > 0) { |
|
| 1153 | 1153 | //skip when the filter is a wildcard and results were found |
| 1154 | 1154 | continue; |
| 1155 | 1155 | } |
| 1156 | 1156 | // 20k limit for performance and reason |
| 1157 | 1157 | $rr = $this->ldap->search($cr, $base, $filter, array($attr), 0, 20000); |
| 1158 | - if(!$this->ldap->isResource($rr)) { |
|
| 1158 | + if (!$this->ldap->isResource($rr)) { |
|
| 1159 | 1159 | continue; |
| 1160 | 1160 | } |
| 1161 | 1161 | $entries = $this->ldap->countEntries($cr, $rr); |
| 1162 | 1162 | $getEntryFunc = 'firstEntry'; |
| 1163 | - if(($entries !== false) && ($entries > 0)) { |
|
| 1164 | - if(!is_null($maxF) && $entries > $maxEntries) { |
|
| 1163 | + if (($entries !== false) && ($entries > 0)) { |
|
| 1164 | + if (!is_null($maxF) && $entries > $maxEntries) { |
|
| 1165 | 1165 | $maxEntries = $entries; |
| 1166 | 1166 | $maxF = $filter; |
| 1167 | 1167 | } |
@@ -1169,13 +1169,13 @@ discard block |
||
| 1169 | 1169 | do { |
| 1170 | 1170 | $entry = $this->ldap->$getEntryFunc($cr, $rr); |
| 1171 | 1171 | $getEntryFunc = 'nextEntry'; |
| 1172 | - if(!$this->ldap->isResource($entry)) { |
|
| 1172 | + if (!$this->ldap->isResource($entry)) { |
|
| 1173 | 1173 | continue 2; |
| 1174 | 1174 | } |
| 1175 | 1175 | $rr = $entry; //will be expected by nextEntry next round |
| 1176 | 1176 | $attributes = $this->ldap->getAttributes($cr, $entry); |
| 1177 | 1177 | $dn = $this->ldap->getDN($cr, $entry); |
| 1178 | - if($dn === false || in_array($dn, $dnRead)) { |
|
| 1178 | + if ($dn === false || in_array($dn, $dnRead)) { |
|
| 1179 | 1179 | continue; |
| 1180 | 1180 | } |
| 1181 | 1181 | $newItems = array(); |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | $foundItems = array_merge($foundItems, $newItems); |
| 1187 | 1187 | $this->resultCache[$dn][$attr] = $newItems; |
| 1188 | 1188 | $dnRead[] = $dn; |
| 1189 | - } while(($state === self::LRESULT_PROCESSED_SKIP |
|
| 1189 | + } while (($state === self::LRESULT_PROCESSED_SKIP |
|
| 1190 | 1190 | || $this->ldap->isResource($entry)) |
| 1191 | 1191 | && ($dnReadLimit === 0 || $dnReadCount < $dnReadLimit)); |
| 1192 | 1192 | } |
@@ -1209,11 +1209,11 @@ discard block |
||
| 1209 | 1209 | */ |
| 1210 | 1210 | private function determineFeature($objectclasses, $attr, $dbkey, $confkey, $po = false) { |
| 1211 | 1211 | $cr = $this->getConnection(); |
| 1212 | - if(!$cr) { |
|
| 1212 | + if (!$cr) { |
|
| 1213 | 1213 | throw new \Exception('Could not connect to LDAP'); |
| 1214 | 1214 | } |
| 1215 | 1215 | $p = 'objectclass='; |
| 1216 | - foreach($objectclasses as $key => $value) { |
|
| 1216 | + foreach ($objectclasses as $key => $value) { |
|
| 1217 | 1217 | $objectclasses[$key] = $p.$value; |
| 1218 | 1218 | } |
| 1219 | 1219 | $maxEntryObjC = ''; |
@@ -1225,7 +1225,7 @@ discard block |
||
| 1225 | 1225 | $availableFeatures = |
| 1226 | 1226 | $this->cumulativeSearchOnAttribute($objectclasses, $attr, |
| 1227 | 1227 | $dig, $maxEntryObjC); |
| 1228 | - if(is_array($availableFeatures) |
|
| 1228 | + if (is_array($availableFeatures) |
|
| 1229 | 1229 | && count($availableFeatures) > 0) { |
| 1230 | 1230 | natcasesort($availableFeatures); |
| 1231 | 1231 | //natcasesort keeps indices, but we must get rid of them for proper |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | $setFeatures = $this->configuration->$confkey; |
| 1239 | - if(is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1239 | + if (is_array($setFeatures) && !empty($setFeatures)) { |
|
| 1240 | 1240 | //something is already configured? pre-select it. |
| 1241 | 1241 | $this->result->addChange($dbkey, $setFeatures); |
| 1242 | 1242 | } else if ($po && $maxEntryObjC !== '') { |
@@ -1258,7 +1258,7 @@ discard block |
||
| 1258 | 1258 | * LRESULT_PROCESSED_INVALID or LRESULT_PROCESSED_SKIP |
| 1259 | 1259 | */ |
| 1260 | 1260 | private function getAttributeValuesFromEntry($result, $attribute, &$known) { |
| 1261 | - if(!is_array($result) |
|
| 1261 | + if (!is_array($result) |
|
| 1262 | 1262 | || !isset($result['count']) |
| 1263 | 1263 | || !$result['count'] > 0) { |
| 1264 | 1264 | return self::LRESULT_PROCESSED_INVALID; |
@@ -1267,12 +1267,12 @@ discard block |
||
| 1267 | 1267 | // strtolower on all keys for proper comparison |
| 1268 | 1268 | $result = \OCP\Util::mb_array_change_key_case($result); |
| 1269 | 1269 | $attribute = strtolower($attribute); |
| 1270 | - if(isset($result[$attribute])) { |
|
| 1271 | - foreach($result[$attribute] as $key => $val) { |
|
| 1272 | - if($key === 'count') { |
|
| 1270 | + if (isset($result[$attribute])) { |
|
| 1271 | + foreach ($result[$attribute] as $key => $val) { |
|
| 1272 | + if ($key === 'count') { |
|
| 1273 | 1273 | continue; |
| 1274 | 1274 | } |
| 1275 | - if(!in_array($val, $known)) { |
|
| 1275 | + if (!in_array($val, $known)) { |
|
| 1276 | 1276 | $known[] = $val; |
| 1277 | 1277 | } |
| 1278 | 1278 | } |
@@ -1286,7 +1286,7 @@ discard block |
||
| 1286 | 1286 | * @return bool|mixed |
| 1287 | 1287 | */ |
| 1288 | 1288 | private function getConnection() { |
| 1289 | - if(!is_null($this->cr)) { |
|
| 1289 | + if (!is_null($this->cr)) { |
|
| 1290 | 1290 | return $this->cr; |
| 1291 | 1291 | } |
| 1292 | 1292 | |
@@ -1298,14 +1298,14 @@ discard block |
||
| 1298 | 1298 | $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); |
| 1299 | 1299 | $this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0); |
| 1300 | 1300 | $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); |
| 1301 | - if($this->configuration->ldapTLS === 1) { |
|
| 1301 | + if ($this->configuration->ldapTLS === 1) { |
|
| 1302 | 1302 | $this->ldap->startTls($cr); |
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | $lo = @$this->ldap->bind($cr, |
| 1306 | 1306 | $this->configuration->ldapAgentName, |
| 1307 | 1307 | $this->configuration->ldapAgentPassword); |
| 1308 | - if($lo === true) { |
|
| 1308 | + if ($lo === true) { |
|
| 1309 | 1309 | $this->$cr = $cr; |
| 1310 | 1310 | return $cr; |
| 1311 | 1311 | } |
@@ -1336,18 +1336,18 @@ discard block |
||
| 1336 | 1336 | //636 ← LDAPS / SSL |
| 1337 | 1337 | //7xxx ← UCS. need to be checked first, because both ports may be open |
| 1338 | 1338 | $host = $this->configuration->ldapHost; |
| 1339 | - $port = (int)$this->configuration->ldapPort; |
|
| 1339 | + $port = (int) $this->configuration->ldapPort; |
|
| 1340 | 1340 | $portSettings = array(); |
| 1341 | 1341 | |
| 1342 | 1342 | //In case the port is already provided, we will check this first |
| 1343 | - if($port > 0) { |
|
| 1343 | + if ($port > 0) { |
|
| 1344 | 1344 | $hostInfo = parse_url($host); |
| 1345 | - if(!(is_array($hostInfo) |
|
| 1345 | + if (!(is_array($hostInfo) |
|
| 1346 | 1346 | && isset($hostInfo['scheme']) |
| 1347 | 1347 | && stripos($hostInfo['scheme'], 'ldaps') !== false)) { |
| 1348 | 1348 | $portSettings[] = array('port' => $port, 'tls' => true); |
| 1349 | 1349 | } |
| 1350 | - $portSettings[] =array('port' => $port, 'tls' => false); |
|
| 1350 | + $portSettings[] = array('port' => $port, 'tls' => false); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | //default ports |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @param string $newPath |
| 112 | 112 | * @param \OCP\Share\IShare $share |
| 113 | - * @return bool |
|
| 113 | + * @return boolean|null |
|
| 114 | 114 | */ |
| 115 | 115 | private function updateFileTarget($newPath, &$share) { |
| 116 | 116 | $share->setTarget($newPath); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param string $path |
| 127 | 127 | * @param View $view |
| 128 | 128 | * @param SharedMount[] $mountpoints |
| 129 | - * @return mixed |
|
| 129 | + * @return string |
|
| 130 | 130 | */ |
| 131 | 131 | private function generateUniqueTarget($path, $view, array $mountpoints) { |
| 132 | 132 | $pathinfo = pathinfo($path); |
@@ -37,226 +37,226 @@ |
||
| 37 | 37 | * Shared mount points can be moved by the user |
| 38 | 38 | */ |
| 39 | 39 | class SharedMount extends MountPoint implements MoveableMount { |
| 40 | - /** |
|
| 41 | - * @var \OCA\Files_Sharing\SharedStorage $storage |
|
| 42 | - */ |
|
| 43 | - protected $storage = null; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var \OC\Files\View |
|
| 47 | - */ |
|
| 48 | - private $recipientView; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - private $user; |
|
| 54 | - |
|
| 55 | - /** @var \OCP\Share\IShare */ |
|
| 56 | - private $superShare; |
|
| 57 | - |
|
| 58 | - /** @var \OCP\Share\IShare[] */ |
|
| 59 | - private $groupedShares; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $storage |
|
| 63 | - * @param SharedMount[] $mountpoints |
|
| 64 | - * @param array|null $arguments |
|
| 65 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 66 | - */ |
|
| 67 | - public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) { |
|
| 68 | - $this->user = $arguments['user']; |
|
| 69 | - $this->recipientView = new View('/' . $this->user . '/files'); |
|
| 70 | - |
|
| 71 | - $this->superShare = $arguments['superShare']; |
|
| 72 | - $this->groupedShares = $arguments['groupedShares']; |
|
| 73 | - |
|
| 74 | - $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints); |
|
| 75 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 76 | - $arguments['ownerView'] = new View('/' . $this->superShare->getShareOwner() . '/files'); |
|
| 77 | - parent::__construct($storage, $absMountPoint, $arguments, $loader); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * check if the parent folder exists otherwise move the mount point up |
|
| 82 | - * |
|
| 83 | - * @param \OCP\Share\IShare $share |
|
| 84 | - * @param SharedMount[] $mountpoints |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints) { |
|
| 88 | - |
|
| 89 | - $mountPoint = basename($share->getTarget()); |
|
| 90 | - $parent = dirname($share->getTarget()); |
|
| 91 | - |
|
| 92 | - if (!$this->recipientView->is_dir($parent)) { |
|
| 93 | - $parent = Helper::getShareFolder($this->recipientView); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $newMountPoint = $this->generateUniqueTarget( |
|
| 97 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 98 | - $this->recipientView, |
|
| 99 | - $mountpoints |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - if ($newMountPoint !== $share->getTarget()) { |
|
| 103 | - $this->updateFileTarget($newMountPoint, $share); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $newMountPoint; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * update fileTarget in the database if the mount point changed |
|
| 111 | - * |
|
| 112 | - * @param string $newPath |
|
| 113 | - * @param \OCP\Share\IShare $share |
|
| 114 | - * @return bool |
|
| 115 | - */ |
|
| 116 | - private function updateFileTarget($newPath, &$share) { |
|
| 117 | - $share->setTarget($newPath); |
|
| 118 | - |
|
| 119 | - foreach ($this->groupedShares as $tmpShare) { |
|
| 120 | - $tmpShare->setTarget($newPath); |
|
| 121 | - \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * @param string $path |
|
| 128 | - * @param View $view |
|
| 129 | - * @param SharedMount[] $mountpoints |
|
| 130 | - * @return mixed |
|
| 131 | - */ |
|
| 132 | - private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
| 133 | - $pathinfo = pathinfo($path); |
|
| 134 | - $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 135 | - $name = $pathinfo['filename']; |
|
| 136 | - $dir = $pathinfo['dirname']; |
|
| 137 | - |
|
| 138 | - // Helper function to find existing mount points |
|
| 139 | - $mountpointExists = function ($path) use ($mountpoints) { |
|
| 140 | - foreach ($mountpoints as $mountpoint) { |
|
| 141 | - if ($mountpoint->getShare()->getTarget() === $path) { |
|
| 142 | - return true; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - return false; |
|
| 146 | - }; |
|
| 147 | - |
|
| 148 | - $i = 2; |
|
| 149 | - while ($view->file_exists($path) || $mountpointExists($path)) { |
|
| 150 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 151 | - $i++; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $path; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Format a path to be relative to the /user/files/ directory |
|
| 159 | - * |
|
| 160 | - * @param string $path the absolute path |
|
| 161 | - * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
| 162 | - * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
| 163 | - */ |
|
| 164 | - protected function stripUserFilesPath($path) { |
|
| 165 | - $trimmed = ltrim($path, '/'); |
|
| 166 | - $split = explode('/', $trimmed); |
|
| 167 | - |
|
| 168 | - // it is not a file relative to data/user/files |
|
| 169 | - if (count($split) < 3 || $split[1] !== 'files') { |
|
| 170 | - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 171 | - throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // skip 'user' and 'files' |
|
| 175 | - $sliced = array_slice($split, 2); |
|
| 176 | - $relPath = implode('/', $sliced); |
|
| 177 | - |
|
| 178 | - return '/' . $relPath; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Move the mount point to $target |
|
| 183 | - * |
|
| 184 | - * @param string $target the target mount point |
|
| 185 | - * @return bool |
|
| 186 | - */ |
|
| 187 | - public function moveMount($target) { |
|
| 188 | - |
|
| 189 | - $relTargetPath = $this->stripUserFilesPath($target); |
|
| 190 | - $share = $this->storage->getShare(); |
|
| 191 | - |
|
| 192 | - $result = true; |
|
| 193 | - |
|
| 194 | - try { |
|
| 195 | - $this->updateFileTarget($relTargetPath, $share); |
|
| 196 | - $this->setMountPoint($target); |
|
| 197 | - $this->storage->setMountPoint($relTargetPath); |
|
| 198 | - } catch (\Exception $e) { |
|
| 199 | - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $result; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Remove the mount points |
|
| 207 | - * |
|
| 208 | - * @return bool |
|
| 209 | - */ |
|
| 210 | - public function removeMount() { |
|
| 211 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 212 | - /** @var $storage \OCA\Files_Sharing\SharedStorage */ |
|
| 213 | - $storage = $this->getStorage(); |
|
| 214 | - $result = $storage->unshareStorage(); |
|
| 215 | - $mountManager->removeMount($this->mountPoint); |
|
| 216 | - |
|
| 217 | - return $result; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @return \OCP\Share\IShare |
|
| 222 | - */ |
|
| 223 | - public function getShare() { |
|
| 224 | - return $this->superShare; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Get the file id of the root of the storage |
|
| 229 | - * |
|
| 230 | - * @return int |
|
| 231 | - */ |
|
| 232 | - public function getStorageRootId() { |
|
| 233 | - return $this->getShare()->getNodeId(); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @return int |
|
| 238 | - */ |
|
| 239 | - public function getNumericStorageId() { |
|
| 240 | - if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
| 241 | - return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
| 242 | - } else { |
|
| 243 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 244 | - |
|
| 245 | - $query = $builder->select('storage') |
|
| 246 | - ->from('filecache') |
|
| 247 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
| 248 | - |
|
| 249 | - $result = $query->execute(); |
|
| 250 | - $row = $result->fetch(); |
|
| 251 | - $result->closeCursor(); |
|
| 252 | - if ($row) { |
|
| 253 | - return (int)$row['storage']; |
|
| 254 | - } |
|
| 255 | - return -1; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - public function getMountType() { |
|
| 260 | - return 'shared'; |
|
| 261 | - } |
|
| 40 | + /** |
|
| 41 | + * @var \OCA\Files_Sharing\SharedStorage $storage |
|
| 42 | + */ |
|
| 43 | + protected $storage = null; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var \OC\Files\View |
|
| 47 | + */ |
|
| 48 | + private $recipientView; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + private $user; |
|
| 54 | + |
|
| 55 | + /** @var \OCP\Share\IShare */ |
|
| 56 | + private $superShare; |
|
| 57 | + |
|
| 58 | + /** @var \OCP\Share\IShare[] */ |
|
| 59 | + private $groupedShares; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $storage |
|
| 63 | + * @param SharedMount[] $mountpoints |
|
| 64 | + * @param array|null $arguments |
|
| 65 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
| 66 | + */ |
|
| 67 | + public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) { |
|
| 68 | + $this->user = $arguments['user']; |
|
| 69 | + $this->recipientView = new View('/' . $this->user . '/files'); |
|
| 70 | + |
|
| 71 | + $this->superShare = $arguments['superShare']; |
|
| 72 | + $this->groupedShares = $arguments['groupedShares']; |
|
| 73 | + |
|
| 74 | + $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints); |
|
| 75 | + $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 76 | + $arguments['ownerView'] = new View('/' . $this->superShare->getShareOwner() . '/files'); |
|
| 77 | + parent::__construct($storage, $absMountPoint, $arguments, $loader); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * check if the parent folder exists otherwise move the mount point up |
|
| 82 | + * |
|
| 83 | + * @param \OCP\Share\IShare $share |
|
| 84 | + * @param SharedMount[] $mountpoints |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints) { |
|
| 88 | + |
|
| 89 | + $mountPoint = basename($share->getTarget()); |
|
| 90 | + $parent = dirname($share->getTarget()); |
|
| 91 | + |
|
| 92 | + if (!$this->recipientView->is_dir($parent)) { |
|
| 93 | + $parent = Helper::getShareFolder($this->recipientView); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $newMountPoint = $this->generateUniqueTarget( |
|
| 97 | + \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 98 | + $this->recipientView, |
|
| 99 | + $mountpoints |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + if ($newMountPoint !== $share->getTarget()) { |
|
| 103 | + $this->updateFileTarget($newMountPoint, $share); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $newMountPoint; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * update fileTarget in the database if the mount point changed |
|
| 111 | + * |
|
| 112 | + * @param string $newPath |
|
| 113 | + * @param \OCP\Share\IShare $share |
|
| 114 | + * @return bool |
|
| 115 | + */ |
|
| 116 | + private function updateFileTarget($newPath, &$share) { |
|
| 117 | + $share->setTarget($newPath); |
|
| 118 | + |
|
| 119 | + foreach ($this->groupedShares as $tmpShare) { |
|
| 120 | + $tmpShare->setTarget($newPath); |
|
| 121 | + \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * @param string $path |
|
| 128 | + * @param View $view |
|
| 129 | + * @param SharedMount[] $mountpoints |
|
| 130 | + * @return mixed |
|
| 131 | + */ |
|
| 132 | + private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
| 133 | + $pathinfo = pathinfo($path); |
|
| 134 | + $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 135 | + $name = $pathinfo['filename']; |
|
| 136 | + $dir = $pathinfo['dirname']; |
|
| 137 | + |
|
| 138 | + // Helper function to find existing mount points |
|
| 139 | + $mountpointExists = function ($path) use ($mountpoints) { |
|
| 140 | + foreach ($mountpoints as $mountpoint) { |
|
| 141 | + if ($mountpoint->getShare()->getTarget() === $path) { |
|
| 142 | + return true; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + return false; |
|
| 146 | + }; |
|
| 147 | + |
|
| 148 | + $i = 2; |
|
| 149 | + while ($view->file_exists($path) || $mountpointExists($path)) { |
|
| 150 | + $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 151 | + $i++; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $path; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Format a path to be relative to the /user/files/ directory |
|
| 159 | + * |
|
| 160 | + * @param string $path the absolute path |
|
| 161 | + * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
| 162 | + * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
| 163 | + */ |
|
| 164 | + protected function stripUserFilesPath($path) { |
|
| 165 | + $trimmed = ltrim($path, '/'); |
|
| 166 | + $split = explode('/', $trimmed); |
|
| 167 | + |
|
| 168 | + // it is not a file relative to data/user/files |
|
| 169 | + if (count($split) < 3 || $split[1] !== 'files') { |
|
| 170 | + \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 171 | + throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // skip 'user' and 'files' |
|
| 175 | + $sliced = array_slice($split, 2); |
|
| 176 | + $relPath = implode('/', $sliced); |
|
| 177 | + |
|
| 178 | + return '/' . $relPath; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Move the mount point to $target |
|
| 183 | + * |
|
| 184 | + * @param string $target the target mount point |
|
| 185 | + * @return bool |
|
| 186 | + */ |
|
| 187 | + public function moveMount($target) { |
|
| 188 | + |
|
| 189 | + $relTargetPath = $this->stripUserFilesPath($target); |
|
| 190 | + $share = $this->storage->getShare(); |
|
| 191 | + |
|
| 192 | + $result = true; |
|
| 193 | + |
|
| 194 | + try { |
|
| 195 | + $this->updateFileTarget($relTargetPath, $share); |
|
| 196 | + $this->setMountPoint($target); |
|
| 197 | + $this->storage->setMountPoint($relTargetPath); |
|
| 198 | + } catch (\Exception $e) { |
|
| 199 | + \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $result; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Remove the mount points |
|
| 207 | + * |
|
| 208 | + * @return bool |
|
| 209 | + */ |
|
| 210 | + public function removeMount() { |
|
| 211 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 212 | + /** @var $storage \OCA\Files_Sharing\SharedStorage */ |
|
| 213 | + $storage = $this->getStorage(); |
|
| 214 | + $result = $storage->unshareStorage(); |
|
| 215 | + $mountManager->removeMount($this->mountPoint); |
|
| 216 | + |
|
| 217 | + return $result; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @return \OCP\Share\IShare |
|
| 222 | + */ |
|
| 223 | + public function getShare() { |
|
| 224 | + return $this->superShare; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Get the file id of the root of the storage |
|
| 229 | + * |
|
| 230 | + * @return int |
|
| 231 | + */ |
|
| 232 | + public function getStorageRootId() { |
|
| 233 | + return $this->getShare()->getNodeId(); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @return int |
|
| 238 | + */ |
|
| 239 | + public function getNumericStorageId() { |
|
| 240 | + if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
| 241 | + return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
| 242 | + } else { |
|
| 243 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 244 | + |
|
| 245 | + $query = $builder->select('storage') |
|
| 246 | + ->from('filecache') |
|
| 247 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
| 248 | + |
|
| 249 | + $result = $query->execute(); |
|
| 250 | + $row = $result->fetch(); |
|
| 251 | + $result->closeCursor(); |
|
| 252 | + if ($row) { |
|
| 253 | + return (int)$row['storage']; |
|
| 254 | + } |
|
| 255 | + return -1; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + public function getMountType() { |
|
| 260 | + return 'shared'; |
|
| 261 | + } |
|
| 262 | 262 | } |
@@ -66,14 +66,14 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) { |
| 68 | 68 | $this->user = $arguments['user']; |
| 69 | - $this->recipientView = new View('/' . $this->user . '/files'); |
|
| 69 | + $this->recipientView = new View('/'.$this->user.'/files'); |
|
| 70 | 70 | |
| 71 | 71 | $this->superShare = $arguments['superShare']; |
| 72 | 72 | $this->groupedShares = $arguments['groupedShares']; |
| 73 | 73 | |
| 74 | 74 | $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints); |
| 75 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 76 | - $arguments['ownerView'] = new View('/' . $this->superShare->getShareOwner() . '/files'); |
|
| 75 | + $absMountPoint = '/'.$this->user.'/files'.$newMountPoint; |
|
| 76 | + $arguments['ownerView'] = new View('/'.$this->superShare->getShareOwner().'/files'); |
|
| 77 | 77 | parent::__construct($storage, $absMountPoint, $arguments, $loader); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $newMountPoint = $this->generateUniqueTarget( |
| 97 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 97 | + \OC\Files\Filesystem::normalizePath($parent.'/'.$mountPoint), |
|
| 98 | 98 | $this->recipientView, |
| 99 | 99 | $mountpoints |
| 100 | 100 | ); |
@@ -131,12 +131,12 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | private function generateUniqueTarget($path, $view, array $mountpoints) { |
| 133 | 133 | $pathinfo = pathinfo($path); |
| 134 | - $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 134 | + $ext = isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : ''; |
|
| 135 | 135 | $name = $pathinfo['filename']; |
| 136 | 136 | $dir = $pathinfo['dirname']; |
| 137 | 137 | |
| 138 | 138 | // Helper function to find existing mount points |
| 139 | - $mountpointExists = function ($path) use ($mountpoints) { |
|
| 139 | + $mountpointExists = function($path) use ($mountpoints) { |
|
| 140 | 140 | foreach ($mountpoints as $mountpoint) { |
| 141 | 141 | if ($mountpoint->getShare()->getTarget() === $path) { |
| 142 | 142 | return true; |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | $i = 2; |
| 149 | 149 | while ($view->file_exists($path) || $mountpointExists($path)) { |
| 150 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 150 | + $path = Filesystem::normalizePath($dir.'/'.$name.' ('.$i.')'.$ext); |
|
| 151 | 151 | $i++; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | // it is not a file relative to data/user/files |
| 169 | 169 | if (count($split) < 3 || $split[1] !== 'files') { |
| 170 | - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 170 | + \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: '.$path, ['app' => 'files_sharing']); |
|
| 171 | 171 | throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $sliced = array_slice($split, 2); |
| 176 | 176 | $relPath = implode('/', $sliced); |
| 177 | 177 | |
| 178 | - return '/' . $relPath; |
|
| 178 | + return '/'.$relPath; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $this->setMountPoint($target); |
| 197 | 197 | $this->storage->setMountPoint($relTargetPath); |
| 198 | 198 | } catch (\Exception $e) { |
| 199 | - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 199 | + \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "'.$this->getMountPoint().'" to "'.$target.'"']); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | return $result; |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | $row = $result->fetch(); |
| 251 | 251 | $result->closeCursor(); |
| 252 | 252 | if ($row) { |
| 253 | - return (int)$row['storage']; |
|
| 253 | + return (int) $row['storage']; |
|
| 254 | 254 | } |
| 255 | 255 | return -1; |
| 256 | 256 | } |
@@ -95,7 +95,7 @@ |
||
| 95 | 95 | * @param string $key |
| 96 | 96 | * @param mixed $value |
| 97 | 97 | * @param int $ttl |
| 98 | - * @return bool|mixed |
|
| 98 | + * @return boolean |
|
| 99 | 99 | * @throws \OC\ForbiddenException |
| 100 | 100 | */ |
| 101 | 101 | public function set($key, $value, $ttl = 0) { |
@@ -35,170 +35,170 @@ |
||
| 35 | 35 | |
| 36 | 36 | class File implements ICache { |
| 37 | 37 | |
| 38 | - /** @var View */ |
|
| 39 | - protected $storage; |
|
| 38 | + /** @var View */ |
|
| 39 | + protected $storage; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Returns the cache storage for the logged in user |
|
| 43 | - * |
|
| 44 | - * @return \OC\Files\View cache storage |
|
| 45 | - * @throws \OC\ForbiddenException |
|
| 46 | - * @throws \OC\User\NoUserException |
|
| 47 | - */ |
|
| 48 | - protected function getStorage() { |
|
| 49 | - if (isset($this->storage)) { |
|
| 50 | - return $this->storage; |
|
| 51 | - } |
|
| 52 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 53 | - $rootView = new View(); |
|
| 54 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 55 | - Filesystem::initMountPoints($user->getUID()); |
|
| 56 | - if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
| 57 | - $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
| 58 | - } |
|
| 59 | - $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
| 60 | - return $this->storage; |
|
| 61 | - } else { |
|
| 62 | - \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', ILogger::ERROR); |
|
| 63 | - throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
| 64 | - } |
|
| 65 | - } |
|
| 41 | + /** |
|
| 42 | + * Returns the cache storage for the logged in user |
|
| 43 | + * |
|
| 44 | + * @return \OC\Files\View cache storage |
|
| 45 | + * @throws \OC\ForbiddenException |
|
| 46 | + * @throws \OC\User\NoUserException |
|
| 47 | + */ |
|
| 48 | + protected function getStorage() { |
|
| 49 | + if (isset($this->storage)) { |
|
| 50 | + return $this->storage; |
|
| 51 | + } |
|
| 52 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 53 | + $rootView = new View(); |
|
| 54 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 55 | + Filesystem::initMountPoints($user->getUID()); |
|
| 56 | + if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
| 57 | + $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
| 58 | + } |
|
| 59 | + $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
| 60 | + return $this->storage; |
|
| 61 | + } else { |
|
| 62 | + \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', ILogger::ERROR); |
|
| 63 | + throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param string $key |
|
| 69 | - * @return mixed|null |
|
| 70 | - * @throws \OC\ForbiddenException |
|
| 71 | - */ |
|
| 72 | - public function get($key) { |
|
| 73 | - $result = null; |
|
| 74 | - if ($this->hasKey($key)) { |
|
| 75 | - $storage = $this->getStorage(); |
|
| 76 | - $result = $storage->file_get_contents($key); |
|
| 77 | - } |
|
| 78 | - return $result; |
|
| 79 | - } |
|
| 67 | + /** |
|
| 68 | + * @param string $key |
|
| 69 | + * @return mixed|null |
|
| 70 | + * @throws \OC\ForbiddenException |
|
| 71 | + */ |
|
| 72 | + public function get($key) { |
|
| 73 | + $result = null; |
|
| 74 | + if ($this->hasKey($key)) { |
|
| 75 | + $storage = $this->getStorage(); |
|
| 76 | + $result = $storage->file_get_contents($key); |
|
| 77 | + } |
|
| 78 | + return $result; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Returns the size of the stored/cached data |
|
| 83 | - * |
|
| 84 | - * @param string $key |
|
| 85 | - * @return int |
|
| 86 | - */ |
|
| 87 | - public function size($key) { |
|
| 88 | - $result = 0; |
|
| 89 | - if ($this->hasKey($key)) { |
|
| 90 | - $storage = $this->getStorage(); |
|
| 91 | - $result = $storage->filesize($key); |
|
| 92 | - } |
|
| 93 | - return $result; |
|
| 94 | - } |
|
| 81 | + /** |
|
| 82 | + * Returns the size of the stored/cached data |
|
| 83 | + * |
|
| 84 | + * @param string $key |
|
| 85 | + * @return int |
|
| 86 | + */ |
|
| 87 | + public function size($key) { |
|
| 88 | + $result = 0; |
|
| 89 | + if ($this->hasKey($key)) { |
|
| 90 | + $storage = $this->getStorage(); |
|
| 91 | + $result = $storage->filesize($key); |
|
| 92 | + } |
|
| 93 | + return $result; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @param string $key |
|
| 98 | - * @param mixed $value |
|
| 99 | - * @param int $ttl |
|
| 100 | - * @return bool|mixed |
|
| 101 | - * @throws \OC\ForbiddenException |
|
| 102 | - */ |
|
| 103 | - public function set($key, $value, $ttl = 0) { |
|
| 104 | - $storage = $this->getStorage(); |
|
| 105 | - $result = false; |
|
| 106 | - // unique id to avoid chunk collision, just in case |
|
| 107 | - $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
| 108 | - 16, |
|
| 109 | - ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
| 110 | - ); |
|
| 96 | + /** |
|
| 97 | + * @param string $key |
|
| 98 | + * @param mixed $value |
|
| 99 | + * @param int $ttl |
|
| 100 | + * @return bool|mixed |
|
| 101 | + * @throws \OC\ForbiddenException |
|
| 102 | + */ |
|
| 103 | + public function set($key, $value, $ttl = 0) { |
|
| 104 | + $storage = $this->getStorage(); |
|
| 105 | + $result = false; |
|
| 106 | + // unique id to avoid chunk collision, just in case |
|
| 107 | + $uniqueId = \OC::$server->getSecureRandom()->generate( |
|
| 108 | + 16, |
|
| 109 | + ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
| 110 | + ); |
|
| 111 | 111 | |
| 112 | - // use part file to prevent hasKey() to find the key |
|
| 113 | - // while it is being written |
|
| 114 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
| 115 | - if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
| 116 | - if ($ttl === 0) { |
|
| 117 | - $ttl = 86400; // 60*60*24 |
|
| 118 | - } |
|
| 119 | - $result = $storage->touch($keyPart, time() + $ttl); |
|
| 120 | - $result &= $storage->rename($keyPart, $key); |
|
| 121 | - } |
|
| 122 | - return $result; |
|
| 123 | - } |
|
| 112 | + // use part file to prevent hasKey() to find the key |
|
| 113 | + // while it is being written |
|
| 114 | + $keyPart = $key . '.' . $uniqueId . '.part'; |
|
| 115 | + if ($storage and $storage->file_put_contents($keyPart, $value)) { |
|
| 116 | + if ($ttl === 0) { |
|
| 117 | + $ttl = 86400; // 60*60*24 |
|
| 118 | + } |
|
| 119 | + $result = $storage->touch($keyPart, time() + $ttl); |
|
| 120 | + $result &= $storage->rename($keyPart, $key); |
|
| 121 | + } |
|
| 122 | + return $result; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @param string $key |
|
| 127 | - * @return bool |
|
| 128 | - * @throws \OC\ForbiddenException |
|
| 129 | - */ |
|
| 130 | - public function hasKey($key) { |
|
| 131 | - $storage = $this->getStorage(); |
|
| 132 | - if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
| 133 | - return true; |
|
| 134 | - } |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 125 | + /** |
|
| 126 | + * @param string $key |
|
| 127 | + * @return bool |
|
| 128 | + * @throws \OC\ForbiddenException |
|
| 129 | + */ |
|
| 130 | + public function hasKey($key) { |
|
| 131 | + $storage = $this->getStorage(); |
|
| 132 | + if ($storage && $storage->is_file($key) && $storage->isReadable($key)) { |
|
| 133 | + return true; |
|
| 134 | + } |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * @param string $key |
|
| 140 | - * @return bool|mixed |
|
| 141 | - * @throws \OC\ForbiddenException |
|
| 142 | - */ |
|
| 143 | - public function remove($key) { |
|
| 144 | - $storage = $this->getStorage(); |
|
| 145 | - if (!$storage) { |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - return $storage->unlink($key); |
|
| 149 | - } |
|
| 138 | + /** |
|
| 139 | + * @param string $key |
|
| 140 | + * @return bool|mixed |
|
| 141 | + * @throws \OC\ForbiddenException |
|
| 142 | + */ |
|
| 143 | + public function remove($key) { |
|
| 144 | + $storage = $this->getStorage(); |
|
| 145 | + if (!$storage) { |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + return $storage->unlink($key); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * @param string $prefix |
|
| 153 | - * @return bool |
|
| 154 | - * @throws \OC\ForbiddenException |
|
| 155 | - */ |
|
| 156 | - public function clear($prefix = '') { |
|
| 157 | - $storage = $this->getStorage(); |
|
| 158 | - if ($storage and $storage->is_dir('/')) { |
|
| 159 | - $dh = $storage->opendir('/'); |
|
| 160 | - if (is_resource($dh)) { |
|
| 161 | - while (($file = readdir($dh)) !== false) { |
|
| 162 | - if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
| 163 | - $storage->unlink('/' . $file); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 151 | + /** |
|
| 152 | + * @param string $prefix |
|
| 153 | + * @return bool |
|
| 154 | + * @throws \OC\ForbiddenException |
|
| 155 | + */ |
|
| 156 | + public function clear($prefix = '') { |
|
| 157 | + $storage = $this->getStorage(); |
|
| 158 | + if ($storage and $storage->is_dir('/')) { |
|
| 159 | + $dh = $storage->opendir('/'); |
|
| 160 | + if (is_resource($dh)) { |
|
| 161 | + while (($file = readdir($dh)) !== false) { |
|
| 162 | + if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
|
| 163 | + $storage->unlink('/' . $file); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Runs GC |
|
| 173 | - * @throws \OC\ForbiddenException |
|
| 174 | - */ |
|
| 175 | - public function gc() { |
|
| 176 | - $storage = $this->getStorage(); |
|
| 177 | - if ($storage and $storage->is_dir('/')) { |
|
| 178 | - // extra hour safety, in case of stray part chunks that take longer to write, |
|
| 179 | - // because touch() is only called after the chunk was finished |
|
| 180 | - $now = time() - 3600; |
|
| 181 | - $dh = $storage->opendir('/'); |
|
| 182 | - if (!is_resource($dh)) { |
|
| 183 | - return null; |
|
| 184 | - } |
|
| 185 | - while (($file = readdir($dh)) !== false) { |
|
| 186 | - if ($file != '.' and $file != '..') { |
|
| 187 | - try { |
|
| 188 | - $mtime = $storage->filemtime('/' . $file); |
|
| 189 | - if ($mtime < $now) { |
|
| 190 | - $storage->unlink('/' . $file); |
|
| 191 | - } |
|
| 192 | - } catch (\OCP\Lock\LockedException $e) { |
|
| 193 | - // ignore locked chunks |
|
| 194 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 195 | - } catch (\OCP\Files\ForbiddenException $e) { |
|
| 196 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
| 197 | - } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
| 198 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 171 | + /** |
|
| 172 | + * Runs GC |
|
| 173 | + * @throws \OC\ForbiddenException |
|
| 174 | + */ |
|
| 175 | + public function gc() { |
|
| 176 | + $storage = $this->getStorage(); |
|
| 177 | + if ($storage and $storage->is_dir('/')) { |
|
| 178 | + // extra hour safety, in case of stray part chunks that take longer to write, |
|
| 179 | + // because touch() is only called after the chunk was finished |
|
| 180 | + $now = time() - 3600; |
|
| 181 | + $dh = $storage->opendir('/'); |
|
| 182 | + if (!is_resource($dh)) { |
|
| 183 | + return null; |
|
| 184 | + } |
|
| 185 | + while (($file = readdir($dh)) !== false) { |
|
| 186 | + if ($file != '.' and $file != '..') { |
|
| 187 | + try { |
|
| 188 | + $mtime = $storage->filemtime('/' . $file); |
|
| 189 | + if ($mtime < $now) { |
|
| 190 | + $storage->unlink('/' . $file); |
|
| 191 | + } |
|
| 192 | + } catch (\OCP\Lock\LockedException $e) { |
|
| 193 | + // ignore locked chunks |
|
| 194 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 195 | + } catch (\OCP\Files\ForbiddenException $e) { |
|
| 196 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
| 197 | + } catch (\OCP\Files\LockNotAcquiredException $e) { |
|
| 198 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | 204 | } |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | $rootView = new View(); |
| 54 | 54 | $user = \OC::$server->getUserSession()->getUser(); |
| 55 | 55 | Filesystem::initMountPoints($user->getUID()); |
| 56 | - if (!$rootView->file_exists('/' . $user->getUID() . '/cache')) { |
|
| 57 | - $rootView->mkdir('/' . $user->getUID() . '/cache'); |
|
| 56 | + if (!$rootView->file_exists('/'.$user->getUID().'/cache')) { |
|
| 57 | + $rootView->mkdir('/'.$user->getUID().'/cache'); |
|
| 58 | 58 | } |
| 59 | - $this->storage = new View('/' . $user->getUID() . '/cache'); |
|
| 59 | + $this->storage = new View('/'.$user->getUID().'/cache'); |
|
| 60 | 60 | return $this->storage; |
| 61 | 61 | } else { |
| 62 | 62 | \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', ILogger::ERROR); |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | // unique id to avoid chunk collision, just in case |
| 107 | 107 | $uniqueId = \OC::$server->getSecureRandom()->generate( |
| 108 | 108 | 16, |
| 109 | - ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER |
|
| 109 | + ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER |
|
| 110 | 110 | ); |
| 111 | 111 | |
| 112 | 112 | // use part file to prevent hasKey() to find the key |
| 113 | 113 | // while it is being written |
| 114 | - $keyPart = $key . '.' . $uniqueId . '.part'; |
|
| 114 | + $keyPart = $key.'.'.$uniqueId.'.part'; |
|
| 115 | 115 | if ($storage and $storage->file_put_contents($keyPart, $value)) { |
| 116 | 116 | if ($ttl === 0) { |
| 117 | 117 | $ttl = 86400; // 60*60*24 |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | if (is_resource($dh)) { |
| 161 | 161 | while (($file = readdir($dh)) !== false) { |
| 162 | 162 | if ($file != '.' and $file != '..' and ($prefix === '' || strpos($file, $prefix) === 0)) { |
| 163 | - $storage->unlink('/' . $file); |
|
| 163 | + $storage->unlink('/'.$file); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -185,17 +185,17 @@ discard block |
||
| 185 | 185 | while (($file = readdir($dh)) !== false) { |
| 186 | 186 | if ($file != '.' and $file != '..') { |
| 187 | 187 | try { |
| 188 | - $mtime = $storage->filemtime('/' . $file); |
|
| 188 | + $mtime = $storage->filemtime('/'.$file); |
|
| 189 | 189 | if ($mtime < $now) { |
| 190 | - $storage->unlink('/' . $file); |
|
| 190 | + $storage->unlink('/'.$file); |
|
| 191 | 191 | } |
| 192 | 192 | } catch (\OCP\Lock\LockedException $e) { |
| 193 | 193 | // ignore locked chunks |
| 194 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 194 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', array('app' => 'core')); |
|
| 195 | 195 | } catch (\OCP\Files\ForbiddenException $e) { |
| 196 | - \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "' . $file . '"', array('app' => 'core')); |
|
| 196 | + \OC::$server->getLogger()->debug('Could not cleanup forbidden chunk "'.$file.'"', array('app' => 'core')); |
|
| 197 | 197 | } catch (\OCP\Files\LockNotAcquiredException $e) { |
| 198 | - \OC::$server->getLogger()->debug('Could not cleanup locked chunk "' . $file . '"', array('app' => 'core')); |
|
| 198 | + \OC::$server->getLogger()->debug('Could not cleanup locked chunk "'.$file.'"', array('app' => 'core')); |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | 201 | } |
@@ -132,7 +132,7 @@ |
||
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | - * @param $message |
|
| 135 | + * @param string $message |
|
| 136 | 136 | * @param array $additional |
| 137 | 137 | * @return array |
| 138 | 138 | */ |
@@ -57,321 +57,321 @@ |
||
| 57 | 57 | */ |
| 58 | 58 | class LostController extends Controller { |
| 59 | 59 | |
| 60 | - /** @var IURLGenerator */ |
|
| 61 | - protected $urlGenerator; |
|
| 62 | - /** @var IUserManager */ |
|
| 63 | - protected $userManager; |
|
| 64 | - /** @var Defaults */ |
|
| 65 | - protected $defaults; |
|
| 66 | - /** @var IL10N */ |
|
| 67 | - protected $l10n; |
|
| 68 | - /** @var string */ |
|
| 69 | - protected $from; |
|
| 70 | - /** @var IManager */ |
|
| 71 | - protected $encryptionManager; |
|
| 72 | - /** @var IConfig */ |
|
| 73 | - protected $config; |
|
| 74 | - /** @var ISecureRandom */ |
|
| 75 | - protected $secureRandom; |
|
| 76 | - /** @var IMailer */ |
|
| 77 | - protected $mailer; |
|
| 78 | - /** @var ITimeFactory */ |
|
| 79 | - protected $timeFactory; |
|
| 80 | - /** @var ICrypto */ |
|
| 81 | - protected $crypto; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param string $appName |
|
| 85 | - * @param IRequest $request |
|
| 86 | - * @param IURLGenerator $urlGenerator |
|
| 87 | - * @param IUserManager $userManager |
|
| 88 | - * @param Defaults $defaults |
|
| 89 | - * @param IL10N $l10n |
|
| 90 | - * @param IConfig $config |
|
| 91 | - * @param ISecureRandom $secureRandom |
|
| 92 | - * @param string $defaultMailAddress |
|
| 93 | - * @param IManager $encryptionManager |
|
| 94 | - * @param IMailer $mailer |
|
| 95 | - * @param ITimeFactory $timeFactory |
|
| 96 | - * @param ICrypto $crypto |
|
| 97 | - */ |
|
| 98 | - public function __construct($appName, |
|
| 99 | - IRequest $request, |
|
| 100 | - IURLGenerator $urlGenerator, |
|
| 101 | - IUserManager $userManager, |
|
| 102 | - Defaults $defaults, |
|
| 103 | - IL10N $l10n, |
|
| 104 | - IConfig $config, |
|
| 105 | - ISecureRandom $secureRandom, |
|
| 106 | - $defaultMailAddress, |
|
| 107 | - IManager $encryptionManager, |
|
| 108 | - IMailer $mailer, |
|
| 109 | - ITimeFactory $timeFactory, |
|
| 110 | - ICrypto $crypto) { |
|
| 111 | - parent::__construct($appName, $request); |
|
| 112 | - $this->urlGenerator = $urlGenerator; |
|
| 113 | - $this->userManager = $userManager; |
|
| 114 | - $this->defaults = $defaults; |
|
| 115 | - $this->l10n = $l10n; |
|
| 116 | - $this->secureRandom = $secureRandom; |
|
| 117 | - $this->from = $defaultMailAddress; |
|
| 118 | - $this->encryptionManager = $encryptionManager; |
|
| 119 | - $this->config = $config; |
|
| 120 | - $this->mailer = $mailer; |
|
| 121 | - $this->timeFactory = $timeFactory; |
|
| 122 | - $this->crypto = $crypto; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Someone wants to reset their password: |
|
| 127 | - * |
|
| 128 | - * @PublicPage |
|
| 129 | - * @NoCSRFRequired |
|
| 130 | - * |
|
| 131 | - * @param string $token |
|
| 132 | - * @param string $userId |
|
| 133 | - * @return TemplateResponse |
|
| 134 | - */ |
|
| 135 | - public function resetform($token, $userId) { |
|
| 136 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 137 | - return new TemplateResponse('core', 'error', [ |
|
| 138 | - 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
| 139 | - ], |
|
| 140 | - 'guest' |
|
| 141 | - ); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - try { |
|
| 145 | - $this->checkPasswordResetToken($token, $userId); |
|
| 146 | - } catch (\Exception $e) { |
|
| 147 | - return new TemplateResponse( |
|
| 148 | - 'core', 'error', [ |
|
| 149 | - "errors" => array(array("error" => $e->getMessage())) |
|
| 150 | - ], |
|
| 151 | - 'guest' |
|
| 152 | - ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return new TemplateResponse( |
|
| 156 | - 'core', |
|
| 157 | - 'lostpassword/resetpassword', |
|
| 158 | - array( |
|
| 159 | - 'link' => $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', array('userId' => $userId, 'token' => $token)), |
|
| 160 | - ), |
|
| 161 | - 'guest' |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param string $token |
|
| 167 | - * @param string $userId |
|
| 168 | - * @throws \Exception |
|
| 169 | - */ |
|
| 170 | - protected function checkPasswordResetToken($token, $userId) { |
|
| 171 | - $user = $this->userManager->get($userId); |
|
| 172 | - if($user === null || !$user->isEnabled()) { |
|
| 173 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - try { |
|
| 177 | - $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
| 178 | - $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
| 179 | - $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
| 180 | - } catch (\Exception $e) { |
|
| 181 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - $splittedToken = explode(':', $decryptedToken); |
|
| 185 | - if(count($splittedToken) !== 2) { |
|
| 186 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) || |
|
| 190 | - $user->getLastLogin() > $splittedToken[0]) { |
|
| 191 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (!hash_equals($splittedToken[1], $token)) { |
|
| 195 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * @param $message |
|
| 201 | - * @param array $additional |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - private function error($message, array $additional=array()) { |
|
| 205 | - return array_merge(array('status' => 'error', 'msg' => $message), $additional); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @return array |
|
| 210 | - */ |
|
| 211 | - private function success() { |
|
| 212 | - return array('status'=>'success'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @PublicPage |
|
| 217 | - * @BruteForceProtection(action=passwordResetEmail) |
|
| 218 | - * @AnonRateThrottle(limit=10, period=300) |
|
| 219 | - * |
|
| 220 | - * @param string $user |
|
| 221 | - * @return JSONResponse |
|
| 222 | - */ |
|
| 223 | - public function email($user){ |
|
| 224 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 225 | - return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - \OCP\Util::emitHook( |
|
| 229 | - '\OCA\Files_Sharing\API\Server2Server', |
|
| 230 | - 'preLoginNameUsedAsUserName', |
|
| 231 | - ['uid' => &$user] |
|
| 232 | - ); |
|
| 233 | - |
|
| 234 | - // FIXME: use HTTP error codes |
|
| 235 | - try { |
|
| 236 | - $this->sendEmail($user); |
|
| 237 | - } catch (\Exception $e){ |
|
| 238 | - $response = new JSONResponse($this->error($e->getMessage())); |
|
| 239 | - $response->throttle(); |
|
| 240 | - return $response; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $response = new JSONResponse($this->success()); |
|
| 244 | - $response->throttle(); |
|
| 245 | - return $response; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @PublicPage |
|
| 250 | - * @param string $token |
|
| 251 | - * @param string $userId |
|
| 252 | - * @param string $password |
|
| 253 | - * @param boolean $proceed |
|
| 254 | - * @return array |
|
| 255 | - */ |
|
| 256 | - public function setPassword($token, $userId, $password, $proceed) { |
|
| 257 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 258 | - return $this->error($this->l10n->t('Password reset is disabled')); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
| 262 | - return $this->error('', array('encryption' => true)); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - try { |
|
| 266 | - $this->checkPasswordResetToken($token, $userId); |
|
| 267 | - $user = $this->userManager->get($userId); |
|
| 268 | - |
|
| 269 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', array('uid' => $userId, 'password' => $password)); |
|
| 270 | - |
|
| 271 | - if (!$user->setPassword($password)) { |
|
| 272 | - throw new \Exception(); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password)); |
|
| 276 | - |
|
| 277 | - $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
| 278 | - @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
| 279 | - } catch (HintException $e){ |
|
| 280 | - return $this->error($e->getHint()); |
|
| 281 | - } catch (\Exception $e){ |
|
| 282 | - return $this->error($e->getMessage()); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $this->success(); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @param string $input |
|
| 290 | - * @throws \Exception |
|
| 291 | - */ |
|
| 292 | - protected function sendEmail($input) { |
|
| 293 | - $user = $this->findUserByIdOrMail($input); |
|
| 294 | - $email = $user->getEMailAddress(); |
|
| 295 | - |
|
| 296 | - if (empty($email)) { |
|
| 297 | - throw new \Exception( |
|
| 298 | - $this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.') |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // Generate the token. It is stored encrypted in the database with the |
|
| 303 | - // secret being the users' email address appended with the system secret. |
|
| 304 | - // This makes the token automatically invalidate once the user changes |
|
| 305 | - // their email address. |
|
| 306 | - $token = $this->secureRandom->generate( |
|
| 307 | - 21, |
|
| 308 | - ISecureRandom::CHAR_DIGITS. |
|
| 309 | - ISecureRandom::CHAR_LOWER. |
|
| 310 | - ISecureRandom::CHAR_UPPER |
|
| 311 | - ); |
|
| 312 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
| 313 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
| 314 | - $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
| 315 | - |
|
| 316 | - $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token)); |
|
| 317 | - |
|
| 318 | - $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
| 319 | - 'link' => $link, |
|
| 320 | - ]); |
|
| 321 | - |
|
| 322 | - $emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
| 323 | - $emailTemplate->addHeader(); |
|
| 324 | - $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
| 325 | - |
|
| 326 | - $emailTemplate->addBodyText( |
|
| 327 | - htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')), |
|
| 328 | - $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - $emailTemplate->addBodyButton( |
|
| 332 | - htmlspecialchars($this->l10n->t('Reset your password')), |
|
| 333 | - $link, |
|
| 334 | - false |
|
| 335 | - ); |
|
| 336 | - $emailTemplate->addFooter(); |
|
| 337 | - |
|
| 338 | - try { |
|
| 339 | - $message = $this->mailer->createMessage(); |
|
| 340 | - $message->setTo([$email => $user->getUID()]); |
|
| 341 | - $message->setFrom([$this->from => $this->defaults->getName()]); |
|
| 342 | - $message->useTemplate($emailTemplate); |
|
| 343 | - $this->mailer->send($message); |
|
| 344 | - } catch (\Exception $e) { |
|
| 345 | - throw new \Exception($this->l10n->t( |
|
| 346 | - 'Couldn\'t send reset email. Please contact your administrator.' |
|
| 347 | - )); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * @param string $input |
|
| 353 | - * @return IUser |
|
| 354 | - * @throws \InvalidArgumentException |
|
| 355 | - */ |
|
| 356 | - protected function findUserByIdOrMail($input) { |
|
| 357 | - $user = $this->userManager->get($input); |
|
| 358 | - if ($user instanceof IUser) { |
|
| 359 | - if (!$user->isEnabled()) { |
|
| 360 | - throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return $user; |
|
| 364 | - } |
|
| 365 | - $users = $this->userManager->getByEmail($input); |
|
| 366 | - if (count($users) === 1) { |
|
| 367 | - $user = $users[0]; |
|
| 368 | - if (!$user->isEnabled()) { |
|
| 369 | - throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - return $user; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 376 | - } |
|
| 60 | + /** @var IURLGenerator */ |
|
| 61 | + protected $urlGenerator; |
|
| 62 | + /** @var IUserManager */ |
|
| 63 | + protected $userManager; |
|
| 64 | + /** @var Defaults */ |
|
| 65 | + protected $defaults; |
|
| 66 | + /** @var IL10N */ |
|
| 67 | + protected $l10n; |
|
| 68 | + /** @var string */ |
|
| 69 | + protected $from; |
|
| 70 | + /** @var IManager */ |
|
| 71 | + protected $encryptionManager; |
|
| 72 | + /** @var IConfig */ |
|
| 73 | + protected $config; |
|
| 74 | + /** @var ISecureRandom */ |
|
| 75 | + protected $secureRandom; |
|
| 76 | + /** @var IMailer */ |
|
| 77 | + protected $mailer; |
|
| 78 | + /** @var ITimeFactory */ |
|
| 79 | + protected $timeFactory; |
|
| 80 | + /** @var ICrypto */ |
|
| 81 | + protected $crypto; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param string $appName |
|
| 85 | + * @param IRequest $request |
|
| 86 | + * @param IURLGenerator $urlGenerator |
|
| 87 | + * @param IUserManager $userManager |
|
| 88 | + * @param Defaults $defaults |
|
| 89 | + * @param IL10N $l10n |
|
| 90 | + * @param IConfig $config |
|
| 91 | + * @param ISecureRandom $secureRandom |
|
| 92 | + * @param string $defaultMailAddress |
|
| 93 | + * @param IManager $encryptionManager |
|
| 94 | + * @param IMailer $mailer |
|
| 95 | + * @param ITimeFactory $timeFactory |
|
| 96 | + * @param ICrypto $crypto |
|
| 97 | + */ |
|
| 98 | + public function __construct($appName, |
|
| 99 | + IRequest $request, |
|
| 100 | + IURLGenerator $urlGenerator, |
|
| 101 | + IUserManager $userManager, |
|
| 102 | + Defaults $defaults, |
|
| 103 | + IL10N $l10n, |
|
| 104 | + IConfig $config, |
|
| 105 | + ISecureRandom $secureRandom, |
|
| 106 | + $defaultMailAddress, |
|
| 107 | + IManager $encryptionManager, |
|
| 108 | + IMailer $mailer, |
|
| 109 | + ITimeFactory $timeFactory, |
|
| 110 | + ICrypto $crypto) { |
|
| 111 | + parent::__construct($appName, $request); |
|
| 112 | + $this->urlGenerator = $urlGenerator; |
|
| 113 | + $this->userManager = $userManager; |
|
| 114 | + $this->defaults = $defaults; |
|
| 115 | + $this->l10n = $l10n; |
|
| 116 | + $this->secureRandom = $secureRandom; |
|
| 117 | + $this->from = $defaultMailAddress; |
|
| 118 | + $this->encryptionManager = $encryptionManager; |
|
| 119 | + $this->config = $config; |
|
| 120 | + $this->mailer = $mailer; |
|
| 121 | + $this->timeFactory = $timeFactory; |
|
| 122 | + $this->crypto = $crypto; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Someone wants to reset their password: |
|
| 127 | + * |
|
| 128 | + * @PublicPage |
|
| 129 | + * @NoCSRFRequired |
|
| 130 | + * |
|
| 131 | + * @param string $token |
|
| 132 | + * @param string $userId |
|
| 133 | + * @return TemplateResponse |
|
| 134 | + */ |
|
| 135 | + public function resetform($token, $userId) { |
|
| 136 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 137 | + return new TemplateResponse('core', 'error', [ |
|
| 138 | + 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
| 139 | + ], |
|
| 140 | + 'guest' |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + try { |
|
| 145 | + $this->checkPasswordResetToken($token, $userId); |
|
| 146 | + } catch (\Exception $e) { |
|
| 147 | + return new TemplateResponse( |
|
| 148 | + 'core', 'error', [ |
|
| 149 | + "errors" => array(array("error" => $e->getMessage())) |
|
| 150 | + ], |
|
| 151 | + 'guest' |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return new TemplateResponse( |
|
| 156 | + 'core', |
|
| 157 | + 'lostpassword/resetpassword', |
|
| 158 | + array( |
|
| 159 | + 'link' => $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', array('userId' => $userId, 'token' => $token)), |
|
| 160 | + ), |
|
| 161 | + 'guest' |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param string $token |
|
| 167 | + * @param string $userId |
|
| 168 | + * @throws \Exception |
|
| 169 | + */ |
|
| 170 | + protected function checkPasswordResetToken($token, $userId) { |
|
| 171 | + $user = $this->userManager->get($userId); |
|
| 172 | + if($user === null || !$user->isEnabled()) { |
|
| 173 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + try { |
|
| 177 | + $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
| 178 | + $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
| 179 | + $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
| 180 | + } catch (\Exception $e) { |
|
| 181 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + $splittedToken = explode(':', $decryptedToken); |
|
| 185 | + if(count($splittedToken) !== 2) { |
|
| 186 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) || |
|
| 190 | + $user->getLastLogin() > $splittedToken[0]) { |
|
| 191 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (!hash_equals($splittedToken[1], $token)) { |
|
| 195 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * @param $message |
|
| 201 | + * @param array $additional |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + private function error($message, array $additional=array()) { |
|
| 205 | + return array_merge(array('status' => 'error', 'msg' => $message), $additional); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @return array |
|
| 210 | + */ |
|
| 211 | + private function success() { |
|
| 212 | + return array('status'=>'success'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @PublicPage |
|
| 217 | + * @BruteForceProtection(action=passwordResetEmail) |
|
| 218 | + * @AnonRateThrottle(limit=10, period=300) |
|
| 219 | + * |
|
| 220 | + * @param string $user |
|
| 221 | + * @return JSONResponse |
|
| 222 | + */ |
|
| 223 | + public function email($user){ |
|
| 224 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 225 | + return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + \OCP\Util::emitHook( |
|
| 229 | + '\OCA\Files_Sharing\API\Server2Server', |
|
| 230 | + 'preLoginNameUsedAsUserName', |
|
| 231 | + ['uid' => &$user] |
|
| 232 | + ); |
|
| 233 | + |
|
| 234 | + // FIXME: use HTTP error codes |
|
| 235 | + try { |
|
| 236 | + $this->sendEmail($user); |
|
| 237 | + } catch (\Exception $e){ |
|
| 238 | + $response = new JSONResponse($this->error($e->getMessage())); |
|
| 239 | + $response->throttle(); |
|
| 240 | + return $response; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $response = new JSONResponse($this->success()); |
|
| 244 | + $response->throttle(); |
|
| 245 | + return $response; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @PublicPage |
|
| 250 | + * @param string $token |
|
| 251 | + * @param string $userId |
|
| 252 | + * @param string $password |
|
| 253 | + * @param boolean $proceed |
|
| 254 | + * @return array |
|
| 255 | + */ |
|
| 256 | + public function setPassword($token, $userId, $password, $proceed) { |
|
| 257 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
| 258 | + return $this->error($this->l10n->t('Password reset is disabled')); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
| 262 | + return $this->error('', array('encryption' => true)); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + try { |
|
| 266 | + $this->checkPasswordResetToken($token, $userId); |
|
| 267 | + $user = $this->userManager->get($userId); |
|
| 268 | + |
|
| 269 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', array('uid' => $userId, 'password' => $password)); |
|
| 270 | + |
|
| 271 | + if (!$user->setPassword($password)) { |
|
| 272 | + throw new \Exception(); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', array('uid' => $userId, 'password' => $password)); |
|
| 276 | + |
|
| 277 | + $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
| 278 | + @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
| 279 | + } catch (HintException $e){ |
|
| 280 | + return $this->error($e->getHint()); |
|
| 281 | + } catch (\Exception $e){ |
|
| 282 | + return $this->error($e->getMessage()); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $this->success(); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @param string $input |
|
| 290 | + * @throws \Exception |
|
| 291 | + */ |
|
| 292 | + protected function sendEmail($input) { |
|
| 293 | + $user = $this->findUserByIdOrMail($input); |
|
| 294 | + $email = $user->getEMailAddress(); |
|
| 295 | + |
|
| 296 | + if (empty($email)) { |
|
| 297 | + throw new \Exception( |
|
| 298 | + $this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.') |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // Generate the token. It is stored encrypted in the database with the |
|
| 303 | + // secret being the users' email address appended with the system secret. |
|
| 304 | + // This makes the token automatically invalidate once the user changes |
|
| 305 | + // their email address. |
|
| 306 | + $token = $this->secureRandom->generate( |
|
| 307 | + 21, |
|
| 308 | + ISecureRandom::CHAR_DIGITS. |
|
| 309 | + ISecureRandom::CHAR_LOWER. |
|
| 310 | + ISecureRandom::CHAR_UPPER |
|
| 311 | + ); |
|
| 312 | + $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
| 313 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
| 314 | + $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
| 315 | + |
|
| 316 | + $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token)); |
|
| 317 | + |
|
| 318 | + $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
| 319 | + 'link' => $link, |
|
| 320 | + ]); |
|
| 321 | + |
|
| 322 | + $emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
| 323 | + $emailTemplate->addHeader(); |
|
| 324 | + $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
| 325 | + |
|
| 326 | + $emailTemplate->addBodyText( |
|
| 327 | + htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')), |
|
| 328 | + $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + $emailTemplate->addBodyButton( |
|
| 332 | + htmlspecialchars($this->l10n->t('Reset your password')), |
|
| 333 | + $link, |
|
| 334 | + false |
|
| 335 | + ); |
|
| 336 | + $emailTemplate->addFooter(); |
|
| 337 | + |
|
| 338 | + try { |
|
| 339 | + $message = $this->mailer->createMessage(); |
|
| 340 | + $message->setTo([$email => $user->getUID()]); |
|
| 341 | + $message->setFrom([$this->from => $this->defaults->getName()]); |
|
| 342 | + $message->useTemplate($emailTemplate); |
|
| 343 | + $this->mailer->send($message); |
|
| 344 | + } catch (\Exception $e) { |
|
| 345 | + throw new \Exception($this->l10n->t( |
|
| 346 | + 'Couldn\'t send reset email. Please contact your administrator.' |
|
| 347 | + )); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * @param string $input |
|
| 353 | + * @return IUser |
|
| 354 | + * @throws \InvalidArgumentException |
|
| 355 | + */ |
|
| 356 | + protected function findUserByIdOrMail($input) { |
|
| 357 | + $user = $this->userManager->get($input); |
|
| 358 | + if ($user instanceof IUser) { |
|
| 359 | + if (!$user->isEnabled()) { |
|
| 360 | + throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return $user; |
|
| 364 | + } |
|
| 365 | + $users = $this->userManager->getByEmail($input); |
|
| 366 | + if (count($users) === 1) { |
|
| 367 | + $user = $users[0]; |
|
| 368 | + if (!$user->isEnabled()) { |
|
| 369 | + throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + return $user; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + throw new \InvalidArgumentException($this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')); |
|
| 376 | + } |
|
| 377 | 377 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | protected function checkPasswordResetToken($token, $userId) { |
| 171 | 171 | $user = $this->userManager->get($userId); |
| 172 | - if($user === null || !$user->isEnabled()) { |
|
| 172 | + if ($user === null || !$user->isEnabled()) { |
|
| 173 | 173 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -182,11 +182,11 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | $splittedToken = explode(':', $decryptedToken); |
| 185 | - if(count($splittedToken) !== 2) { |
|
| 185 | + if (count($splittedToken) !== 2) { |
|
| 186 | 186 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*12) || |
|
| 189 | + if ($splittedToken[0] < ($this->timeFactory->getTime() - 60 * 60 * 12) || |
|
| 190 | 190 | $user->getLastLogin() > $splittedToken[0]) { |
| 191 | 191 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
| 192 | 192 | } |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @param array $additional |
| 202 | 202 | * @return array |
| 203 | 203 | */ |
| 204 | - private function error($message, array $additional=array()) { |
|
| 204 | + private function error($message, array $additional = array()) { |
|
| 205 | 205 | return array_merge(array('status' => 'error', 'msg' => $message), $additional); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @param string $user |
| 221 | 221 | * @return JSONResponse |
| 222 | 222 | */ |
| 223 | - public function email($user){ |
|
| 223 | + public function email($user) { |
|
| 224 | 224 | if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
| 225 | 225 | return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
| 226 | 226 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | // FIXME: use HTTP error codes |
| 235 | 235 | try { |
| 236 | 236 | $this->sendEmail($user); |
| 237 | - } catch (\Exception $e){ |
|
| 237 | + } catch (\Exception $e) { |
|
| 238 | 238 | $response = new JSONResponse($this->error($e->getMessage())); |
| 239 | 239 | $response->throttle(); |
| 240 | 240 | return $response; |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
| 278 | 278 | @\OC::$server->getUserSession()->unsetMagicInCookie(); |
| 279 | - } catch (HintException $e){ |
|
| 279 | + } catch (HintException $e) { |
|
| 280 | 280 | return $this->error($e->getHint()); |
| 281 | - } catch (\Exception $e){ |
|
| 281 | + } catch (\Exception $e) { |
|
| 282 | 282 | return $this->error($e->getMessage()); |
| 283 | 283 | } |
| 284 | 284 | |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | ISecureRandom::CHAR_LOWER. |
| 310 | 310 | ISecureRandom::CHAR_UPPER |
| 311 | 311 | ); |
| 312 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
| 313 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
| 312 | + $tokenValue = $this->timeFactory->getTime().':'.$token; |
|
| 313 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email.$this->config->getSystemValue('secret')); |
|
| 314 | 314 | $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
| 315 | 315 | |
| 316 | 316 | $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token)); |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | /** |
| 25 | 25 | * BaseResponse constructor. |
| 26 | 26 | * |
| 27 | - * @param DataResponse|null $dataResponse |
|
| 27 | + * @param DataResponse $dataResponse |
|
| 28 | 28 | * @param string $format |
| 29 | 29 | * @param string|null $statusMessage |
| 30 | 30 | * @param int|null $itemsCount |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | use OCP\AppFramework\Http\EmptyContentSecurityPolicy; |
| 27 | 27 | use OCP\AppFramework\Http\Response; |
| 28 | 28 | |
| 29 | -abstract class BaseResponse extends Response { |
|
| 29 | +abstract class BaseResponse extends Response { |
|
| 30 | 30 | /** @var array */ |
| 31 | 31 | protected $data; |
| 32 | 32 | |
@@ -28,121 +28,121 @@ |
||
| 28 | 28 | use OCP\AppFramework\Http\Response; |
| 29 | 29 | |
| 30 | 30 | abstract class BaseResponse extends Response { |
| 31 | - /** @var array */ |
|
| 32 | - protected $data; |
|
| 33 | - |
|
| 34 | - /** @var string */ |
|
| 35 | - protected $format; |
|
| 36 | - |
|
| 37 | - /** @var string */ |
|
| 38 | - protected $statusMessage; |
|
| 39 | - |
|
| 40 | - /** @var int */ |
|
| 41 | - protected $itemsCount; |
|
| 42 | - |
|
| 43 | - /** @var int */ |
|
| 44 | - protected $itemsPerPage; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * BaseResponse constructor. |
|
| 48 | - * |
|
| 49 | - * @param DataResponse|null $dataResponse |
|
| 50 | - * @param string $format |
|
| 51 | - * @param string|null $statusMessage |
|
| 52 | - * @param int|null $itemsCount |
|
| 53 | - * @param int|null $itemsPerPage |
|
| 54 | - */ |
|
| 55 | - public function __construct(DataResponse $dataResponse, |
|
| 56 | - $format = 'xml', |
|
| 57 | - $statusMessage = null, |
|
| 58 | - $itemsCount = null, |
|
| 59 | - $itemsPerPage = null) { |
|
| 60 | - $this->format = $format; |
|
| 61 | - $this->statusMessage = $statusMessage; |
|
| 62 | - $this->itemsCount = $itemsCount; |
|
| 63 | - $this->itemsPerPage = $itemsPerPage; |
|
| 64 | - |
|
| 65 | - $this->data = $dataResponse->getData(); |
|
| 66 | - |
|
| 67 | - $this->setHeaders($dataResponse->getHeaders()); |
|
| 68 | - $this->setStatus($dataResponse->getStatus()); |
|
| 69 | - $this->setETag($dataResponse->getETag()); |
|
| 70 | - $this->setLastModified($dataResponse->getLastModified()); |
|
| 71 | - $this->setCookies($dataResponse->getCookies()); |
|
| 72 | - $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy()); |
|
| 73 | - |
|
| 74 | - if ($format === 'json') { |
|
| 75 | - $this->addHeader( |
|
| 76 | - 'Content-Type', 'application/json; charset=utf-8' |
|
| 77 | - ); |
|
| 78 | - } else { |
|
| 79 | - $this->addHeader( |
|
| 80 | - 'Content-Type', 'application/xml; charset=utf-8' |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param string[] $meta |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - protected function renderResult(array $meta): string { |
|
| 90 | - $status = $this->getStatus(); |
|
| 91 | - if ($status === Http::STATUS_NO_CONTENT || |
|
| 92 | - $status === Http::STATUS_NOT_MODIFIED || |
|
| 93 | - ($status >= 100 && $status <= 199)) { |
|
| 94 | - // Those status codes are not supposed to have a body: |
|
| 95 | - // https://stackoverflow.com/q/8628725 |
|
| 96 | - return ''; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $response = [ |
|
| 100 | - 'ocs' => [ |
|
| 101 | - 'meta' => $meta, |
|
| 102 | - 'data' => $this->data, |
|
| 103 | - ], |
|
| 104 | - ]; |
|
| 105 | - |
|
| 106 | - if ($this->format === 'json') { |
|
| 107 | - return json_encode($response, JSON_HEX_TAG); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $writer = new \XMLWriter(); |
|
| 111 | - $writer->openMemory(); |
|
| 112 | - $writer->setIndent(true); |
|
| 113 | - $writer->startDocument(); |
|
| 114 | - $this->toXML($response, $writer); |
|
| 115 | - $writer->endDocument(); |
|
| 116 | - return $writer->outputMemory(true); |
|
| 117 | - |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param array $array |
|
| 122 | - * @param \XMLWriter $writer |
|
| 123 | - */ |
|
| 124 | - protected function toXML(array $array, \XMLWriter $writer) { |
|
| 125 | - foreach ($array as $k => $v) { |
|
| 126 | - if ($k[0] === '@') { |
|
| 127 | - $writer->writeAttribute(substr($k, 1), $v); |
|
| 128 | - continue; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - if (\is_numeric($k)) { |
|
| 132 | - $k = 'element'; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - if (\is_array($v)) { |
|
| 136 | - $writer->startElement($k); |
|
| 137 | - $this->toXML($v, $writer); |
|
| 138 | - $writer->endElement(); |
|
| 139 | - } else { |
|
| 140 | - $writer->writeElement($k, $v); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function getOCSStatus() { |
|
| 146 | - return parent::getStatus(); |
|
| 147 | - } |
|
| 31 | + /** @var array */ |
|
| 32 | + protected $data; |
|
| 33 | + |
|
| 34 | + /** @var string */ |
|
| 35 | + protected $format; |
|
| 36 | + |
|
| 37 | + /** @var string */ |
|
| 38 | + protected $statusMessage; |
|
| 39 | + |
|
| 40 | + /** @var int */ |
|
| 41 | + protected $itemsCount; |
|
| 42 | + |
|
| 43 | + /** @var int */ |
|
| 44 | + protected $itemsPerPage; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * BaseResponse constructor. |
|
| 48 | + * |
|
| 49 | + * @param DataResponse|null $dataResponse |
|
| 50 | + * @param string $format |
|
| 51 | + * @param string|null $statusMessage |
|
| 52 | + * @param int|null $itemsCount |
|
| 53 | + * @param int|null $itemsPerPage |
|
| 54 | + */ |
|
| 55 | + public function __construct(DataResponse $dataResponse, |
|
| 56 | + $format = 'xml', |
|
| 57 | + $statusMessage = null, |
|
| 58 | + $itemsCount = null, |
|
| 59 | + $itemsPerPage = null) { |
|
| 60 | + $this->format = $format; |
|
| 61 | + $this->statusMessage = $statusMessage; |
|
| 62 | + $this->itemsCount = $itemsCount; |
|
| 63 | + $this->itemsPerPage = $itemsPerPage; |
|
| 64 | + |
|
| 65 | + $this->data = $dataResponse->getData(); |
|
| 66 | + |
|
| 67 | + $this->setHeaders($dataResponse->getHeaders()); |
|
| 68 | + $this->setStatus($dataResponse->getStatus()); |
|
| 69 | + $this->setETag($dataResponse->getETag()); |
|
| 70 | + $this->setLastModified($dataResponse->getLastModified()); |
|
| 71 | + $this->setCookies($dataResponse->getCookies()); |
|
| 72 | + $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy()); |
|
| 73 | + |
|
| 74 | + if ($format === 'json') { |
|
| 75 | + $this->addHeader( |
|
| 76 | + 'Content-Type', 'application/json; charset=utf-8' |
|
| 77 | + ); |
|
| 78 | + } else { |
|
| 79 | + $this->addHeader( |
|
| 80 | + 'Content-Type', 'application/xml; charset=utf-8' |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string[] $meta |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + protected function renderResult(array $meta): string { |
|
| 90 | + $status = $this->getStatus(); |
|
| 91 | + if ($status === Http::STATUS_NO_CONTENT || |
|
| 92 | + $status === Http::STATUS_NOT_MODIFIED || |
|
| 93 | + ($status >= 100 && $status <= 199)) { |
|
| 94 | + // Those status codes are not supposed to have a body: |
|
| 95 | + // https://stackoverflow.com/q/8628725 |
|
| 96 | + return ''; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $response = [ |
|
| 100 | + 'ocs' => [ |
|
| 101 | + 'meta' => $meta, |
|
| 102 | + 'data' => $this->data, |
|
| 103 | + ], |
|
| 104 | + ]; |
|
| 105 | + |
|
| 106 | + if ($this->format === 'json') { |
|
| 107 | + return json_encode($response, JSON_HEX_TAG); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $writer = new \XMLWriter(); |
|
| 111 | + $writer->openMemory(); |
|
| 112 | + $writer->setIndent(true); |
|
| 113 | + $writer->startDocument(); |
|
| 114 | + $this->toXML($response, $writer); |
|
| 115 | + $writer->endDocument(); |
|
| 116 | + return $writer->outputMemory(true); |
|
| 117 | + |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param array $array |
|
| 122 | + * @param \XMLWriter $writer |
|
| 123 | + */ |
|
| 124 | + protected function toXML(array $array, \XMLWriter $writer) { |
|
| 125 | + foreach ($array as $k => $v) { |
|
| 126 | + if ($k[0] === '@') { |
|
| 127 | + $writer->writeAttribute(substr($k, 1), $v); |
|
| 128 | + continue; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + if (\is_numeric($k)) { |
|
| 132 | + $k = 'element'; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + if (\is_array($v)) { |
|
| 136 | + $writer->startElement($k); |
|
| 137 | + $this->toXML($v, $writer); |
|
| 138 | + $writer->endElement(); |
|
| 139 | + } else { |
|
| 140 | + $writer->writeElement($k, $v); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function getOCSStatus() { |
|
| 146 | + return parent::getStatus(); |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -1143,7 +1143,7 @@ discard block |
||
| 1143 | 1143 | * Get the certificate manager for the user |
| 1144 | 1144 | * |
| 1145 | 1145 | * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
| 1146 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1146 | + * @return null|CertificateManager | null if $uid is null and no user is logged in |
|
| 1147 | 1147 | */ |
| 1148 | 1148 | public function getCertificateManager($userId = '') { |
| 1149 | 1149 | if ($userId === '') { |
@@ -1464,6 +1464,7 @@ discard block |
||
| 1464 | 1464 | } |
| 1465 | 1465 | |
| 1466 | 1466 | /** |
| 1467 | + * @param string $app |
|
| 1467 | 1468 | * @return \OCP\Files\IAppData |
| 1468 | 1469 | */ |
| 1469 | 1470 | public function getAppDataDir($app) { |
@@ -116,7 +116,6 @@ |
||
| 116 | 116 | use OC\Template\SCSSCacher; |
| 117 | 117 | use OCA\Theming\ImageManager; |
| 118 | 118 | use OCA\Theming\ThemingDefaults; |
| 119 | - |
|
| 120 | 119 | use OCP\App\IAppManager; |
| 121 | 120 | use OCP\AppFramework\Utility\ITimeFactory; |
| 122 | 121 | use OCP\Collaboration\AutoComplete\IManager; |
@@ -153,1836 +153,1836 @@ |
||
| 153 | 153 | * TODO: hookup all manager classes |
| 154 | 154 | */ |
| 155 | 155 | class Server extends ServerContainer implements IServerContainer { |
| 156 | - /** @var string */ |
|
| 157 | - private $webRoot; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @param string $webRoot |
|
| 161 | - * @param \OC\Config $config |
|
| 162 | - */ |
|
| 163 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 164 | - parent::__construct(); |
|
| 165 | - $this->webRoot = $webRoot; |
|
| 166 | - |
|
| 167 | - // To find out if we are running from CLI or not |
|
| 168 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 169 | - |
|
| 170 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 171 | - return $c; |
|
| 172 | - }); |
|
| 173 | - |
|
| 174 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 175 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 176 | - |
|
| 177 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 178 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 179 | - |
|
| 180 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 184 | - return new PreviewManager( |
|
| 185 | - $c->getConfig(), |
|
| 186 | - $c->getRootFolder(), |
|
| 187 | - $c->getAppDataDir('preview'), |
|
| 188 | - $c->getEventDispatcher(), |
|
| 189 | - $c->getSession()->get('user_id') |
|
| 190 | - ); |
|
| 191 | - }); |
|
| 192 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
| 193 | - |
|
| 194 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 195 | - return new \OC\Preview\Watcher( |
|
| 196 | - $c->getAppDataDir('preview') |
|
| 197 | - ); |
|
| 198 | - }); |
|
| 199 | - |
|
| 200 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
| 201 | - $view = new View(); |
|
| 202 | - $util = new Encryption\Util( |
|
| 203 | - $view, |
|
| 204 | - $c->getUserManager(), |
|
| 205 | - $c->getGroupManager(), |
|
| 206 | - $c->getConfig() |
|
| 207 | - ); |
|
| 208 | - return new Encryption\Manager( |
|
| 209 | - $c->getConfig(), |
|
| 210 | - $c->getLogger(), |
|
| 211 | - $c->getL10N('core'), |
|
| 212 | - new View(), |
|
| 213 | - $util, |
|
| 214 | - new ArrayCache() |
|
| 215 | - ); |
|
| 216 | - }); |
|
| 217 | - |
|
| 218 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 219 | - $util = new Encryption\Util( |
|
| 220 | - new View(), |
|
| 221 | - $c->getUserManager(), |
|
| 222 | - $c->getGroupManager(), |
|
| 223 | - $c->getConfig() |
|
| 224 | - ); |
|
| 225 | - return new Encryption\File( |
|
| 226 | - $util, |
|
| 227 | - $c->getRootFolder(), |
|
| 228 | - $c->getShareManager() |
|
| 229 | - ); |
|
| 230 | - }); |
|
| 231 | - |
|
| 232 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 233 | - $view = new View(); |
|
| 234 | - $util = new Encryption\Util( |
|
| 235 | - $view, |
|
| 236 | - $c->getUserManager(), |
|
| 237 | - $c->getGroupManager(), |
|
| 238 | - $c->getConfig() |
|
| 239 | - ); |
|
| 240 | - |
|
| 241 | - return new Encryption\Keys\Storage($view, $util); |
|
| 242 | - }); |
|
| 243 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 244 | - return new TagMapper($c->getDatabaseConnection()); |
|
| 245 | - }); |
|
| 246 | - |
|
| 247 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 248 | - $tagMapper = $c->query('TagMapper'); |
|
| 249 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
| 250 | - }); |
|
| 251 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
| 252 | - |
|
| 253 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 254 | - $config = $c->getConfig(); |
|
| 255 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 256 | - return new $factoryClass($this); |
|
| 257 | - }); |
|
| 258 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 259 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 260 | - }); |
|
| 261 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
| 262 | - |
|
| 263 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 264 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 265 | - }); |
|
| 266 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 267 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 268 | - $view = new View(); |
|
| 269 | - $root = new Root( |
|
| 270 | - $manager, |
|
| 271 | - $view, |
|
| 272 | - null, |
|
| 273 | - $c->getUserMountCache(), |
|
| 274 | - $this->getLogger(), |
|
| 275 | - $this->getUserManager() |
|
| 276 | - ); |
|
| 277 | - $connector = new HookConnector($root, $view); |
|
| 278 | - $connector->viewToNode(); |
|
| 279 | - |
|
| 280 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 281 | - $previewConnector->connectWatcher(); |
|
| 282 | - |
|
| 283 | - return $root; |
|
| 284 | - }); |
|
| 285 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
| 286 | - |
|
| 287 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 288 | - return new LazyRoot(function () use ($c) { |
|
| 289 | - return $c->query('RootFolder'); |
|
| 290 | - }); |
|
| 291 | - }); |
|
| 292 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
| 293 | - |
|
| 294 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
| 295 | - $config = $c->getConfig(); |
|
| 296 | - return new \OC\User\Manager($config); |
|
| 297 | - }); |
|
| 298 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
| 299 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 300 | - |
|
| 301 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 302 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
| 303 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 304 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
| 305 | - }); |
|
| 306 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 307 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
| 308 | - }); |
|
| 309 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 310 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
| 311 | - }); |
|
| 312 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 313 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
| 314 | - }); |
|
| 315 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 316 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 317 | - }); |
|
| 318 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 319 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 320 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 321 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 322 | - }); |
|
| 323 | - return $groupManager; |
|
| 324 | - }); |
|
| 325 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 326 | - |
|
| 327 | - $this->registerService(Store::class, function (Server $c) { |
|
| 328 | - $session = $c->getSession(); |
|
| 329 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 330 | - $tokenProvider = $c->query(IProvider::class); |
|
| 331 | - } else { |
|
| 332 | - $tokenProvider = null; |
|
| 333 | - } |
|
| 334 | - $logger = $c->getLogger(); |
|
| 335 | - return new Store($session, $logger, $tokenProvider); |
|
| 336 | - }); |
|
| 337 | - $this->registerAlias(IStore::class, Store::class); |
|
| 338 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
| 339 | - $dbConnection = $c->getDatabaseConnection(); |
|
| 340 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 341 | - }); |
|
| 342 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
| 343 | - $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
| 344 | - $crypto = $c->getCrypto(); |
|
| 345 | - $config = $c->getConfig(); |
|
| 346 | - $logger = $c->getLogger(); |
|
| 347 | - $timeFactory = new TimeFactory(); |
|
| 348 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
| 349 | - }); |
|
| 350 | - $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
| 351 | - |
|
| 352 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 353 | - $manager = $c->getUserManager(); |
|
| 354 | - $session = new \OC\Session\Memory(''); |
|
| 355 | - $timeFactory = new TimeFactory(); |
|
| 356 | - // Token providers might require a working database. This code |
|
| 357 | - // might however be called when ownCloud is not yet setup. |
|
| 358 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 359 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
| 360 | - } else { |
|
| 361 | - $defaultTokenProvider = null; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $dispatcher = $c->getEventDispatcher(); |
|
| 365 | - |
|
| 366 | - $userSession = new \OC\User\Session( |
|
| 367 | - $manager, |
|
| 368 | - $session, |
|
| 369 | - $timeFactory, |
|
| 370 | - $defaultTokenProvider, |
|
| 371 | - $c->getConfig(), |
|
| 372 | - $c->getSecureRandom(), |
|
| 373 | - $c->getLockdownManager(), |
|
| 374 | - $c->getLogger() |
|
| 375 | - ); |
|
| 376 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 377 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 378 | - }); |
|
| 379 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 380 | - /** @var $user \OC\User\User */ |
|
| 381 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
| 382 | - }); |
|
| 383 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
| 384 | - /** @var $user \OC\User\User */ |
|
| 385 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
| 386 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 387 | - }); |
|
| 388 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 389 | - /** @var $user \OC\User\User */ |
|
| 390 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
| 391 | - }); |
|
| 392 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 393 | - /** @var $user \OC\User\User */ |
|
| 394 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 395 | - }); |
|
| 396 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 397 | - /** @var $user \OC\User\User */ |
|
| 398 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 399 | - }); |
|
| 400 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 401 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 402 | - }); |
|
| 403 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 404 | - /** @var $user \OC\User\User */ |
|
| 405 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 406 | - }); |
|
| 407 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 408 | - /** @var $user \OC\User\User */ |
|
| 409 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 410 | - }); |
|
| 411 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 412 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 413 | - }); |
|
| 414 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
| 415 | - /** @var $user \OC\User\User */ |
|
| 416 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 417 | - $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
| 418 | - }); |
|
| 419 | - return $userSession; |
|
| 420 | - }); |
|
| 421 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
| 422 | - |
|
| 423 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 424 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
| 425 | - $c->getAppManager(), |
|
| 426 | - $c->getSession(), |
|
| 427 | - $c->getConfig(), |
|
| 428 | - $c->getActivityManager(), |
|
| 429 | - $c->getLogger(), |
|
| 430 | - $c->query(IProvider::class), |
|
| 431 | - $c->query(ITimeFactory::class), |
|
| 432 | - $c->query(EventDispatcherInterface::class) |
|
| 433 | - ); |
|
| 434 | - }); |
|
| 435 | - |
|
| 436 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 437 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 438 | - |
|
| 439 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 440 | - return new \OC\AllConfig( |
|
| 441 | - $c->getSystemConfig() |
|
| 442 | - ); |
|
| 443 | - }); |
|
| 444 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 445 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 446 | - |
|
| 447 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 448 | - return new \OC\SystemConfig($config); |
|
| 449 | - }); |
|
| 450 | - |
|
| 451 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 452 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 453 | - }); |
|
| 454 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 455 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 456 | - |
|
| 457 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 458 | - return new \OC\L10N\Factory( |
|
| 459 | - $c->getConfig(), |
|
| 460 | - $c->getRequest(), |
|
| 461 | - $c->getUserSession(), |
|
| 462 | - \OC::$SERVERROOT |
|
| 463 | - ); |
|
| 464 | - }); |
|
| 465 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 466 | - |
|
| 467 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 468 | - $config = $c->getConfig(); |
|
| 469 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 470 | - $request = $c->getRequest(); |
|
| 471 | - return new \OC\URLGenerator( |
|
| 472 | - $config, |
|
| 473 | - $cacheFactory, |
|
| 474 | - $request |
|
| 475 | - ); |
|
| 476 | - }); |
|
| 477 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 478 | - |
|
| 479 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
| 480 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 481 | - |
|
| 482 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 483 | - return new Cache\File(); |
|
| 484 | - }); |
|
| 485 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 486 | - |
|
| 487 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 488 | - |
|
| 489 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 490 | - ArrayCache::class, |
|
| 491 | - ArrayCache::class, |
|
| 492 | - ArrayCache::class |
|
| 493 | - ); |
|
| 494 | - $config = $c->getConfig(); |
|
| 495 | - $request = $c->getRequest(); |
|
| 496 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
| 497 | - |
|
| 498 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 499 | - $v = \OC_App::getAppVersions(); |
|
| 500 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 501 | - $version = implode(',', $v); |
|
| 502 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 503 | - $path = \OC::$SERVERROOT; |
|
| 504 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 505 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 506 | - $config->getSystemValue('memcache.local', null), |
|
| 507 | - $config->getSystemValue('memcache.distributed', null), |
|
| 508 | - $config->getSystemValue('memcache.locking', null) |
|
| 509 | - ); |
|
| 510 | - } |
|
| 511 | - return $arrayCacheFactory; |
|
| 512 | - |
|
| 513 | - }); |
|
| 514 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 515 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 516 | - |
|
| 517 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 518 | - $systemConfig = $c->getSystemConfig(); |
|
| 519 | - return new RedisFactory($systemConfig); |
|
| 520 | - }); |
|
| 521 | - |
|
| 522 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 523 | - return new \OC\Activity\Manager( |
|
| 524 | - $c->getRequest(), |
|
| 525 | - $c->getUserSession(), |
|
| 526 | - $c->getConfig(), |
|
| 527 | - $c->query(IValidator::class) |
|
| 528 | - ); |
|
| 529 | - }); |
|
| 530 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 531 | - |
|
| 532 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 533 | - return new \OC\Activity\EventMerger( |
|
| 534 | - $c->getL10N('lib') |
|
| 535 | - ); |
|
| 536 | - }); |
|
| 537 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 538 | - |
|
| 539 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 540 | - return new AvatarManager( |
|
| 541 | - $c->query(\OC\User\Manager::class), |
|
| 542 | - $c->getAppDataDir('avatar'), |
|
| 543 | - $c->getL10N('lib'), |
|
| 544 | - $c->getLogger(), |
|
| 545 | - $c->getConfig() |
|
| 546 | - ); |
|
| 547 | - }); |
|
| 548 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
| 549 | - |
|
| 550 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 551 | - |
|
| 552 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 553 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 554 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
| 555 | - $logger = $factory->get($logType); |
|
| 556 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
| 557 | - |
|
| 558 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
| 559 | - }); |
|
| 560 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
| 561 | - |
|
| 562 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 563 | - return new LogFactory($c, $this->getSystemConfig()); |
|
| 564 | - }); |
|
| 565 | - |
|
| 566 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 567 | - $config = $c->getConfig(); |
|
| 568 | - return new \OC\BackgroundJob\JobList( |
|
| 569 | - $c->getDatabaseConnection(), |
|
| 570 | - $config, |
|
| 571 | - new TimeFactory() |
|
| 572 | - ); |
|
| 573 | - }); |
|
| 574 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 575 | - |
|
| 576 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 577 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 578 | - $logger = $c->getLogger(); |
|
| 579 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 580 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 581 | - } else { |
|
| 582 | - $router = new \OC\Route\Router($logger); |
|
| 583 | - } |
|
| 584 | - return $router; |
|
| 585 | - }); |
|
| 586 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 587 | - |
|
| 588 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 589 | - return new Search(); |
|
| 590 | - }); |
|
| 591 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 592 | - |
|
| 593 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
| 594 | - return new \OC\Security\RateLimiting\Limiter( |
|
| 595 | - $this->getUserSession(), |
|
| 596 | - $this->getRequest(), |
|
| 597 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
| 598 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 599 | - ); |
|
| 600 | - }); |
|
| 601 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 602 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 603 | - $this->getMemCacheFactory(), |
|
| 604 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 605 | - ); |
|
| 606 | - }); |
|
| 607 | - |
|
| 608 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 609 | - return new SecureRandom(); |
|
| 610 | - }); |
|
| 611 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 612 | - |
|
| 613 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 614 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 615 | - }); |
|
| 616 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 617 | - |
|
| 618 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 619 | - return new Hasher($c->getConfig()); |
|
| 620 | - }); |
|
| 621 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 622 | - |
|
| 623 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 624 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 625 | - }); |
|
| 626 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 627 | - |
|
| 628 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 629 | - $systemConfig = $c->getSystemConfig(); |
|
| 630 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 631 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 632 | - if (!$factory->isValidType($type)) { |
|
| 633 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 634 | - } |
|
| 635 | - $connectionParams = $factory->createConnectionParams(); |
|
| 636 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 637 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 638 | - return $connection; |
|
| 639 | - }); |
|
| 640 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 644 | - $user = \OC_User::getUser(); |
|
| 645 | - $uid = $user ? $user : null; |
|
| 646 | - return new ClientService( |
|
| 647 | - $c->getConfig(), |
|
| 648 | - new \OC\Security\CertificateManager( |
|
| 649 | - $uid, |
|
| 650 | - new View(), |
|
| 651 | - $c->getConfig(), |
|
| 652 | - $c->getLogger(), |
|
| 653 | - $c->getSecureRandom() |
|
| 654 | - ) |
|
| 655 | - ); |
|
| 656 | - }); |
|
| 657 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 658 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 659 | - $eventLogger = new EventLogger(); |
|
| 660 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 661 | - // In debug mode, module is being activated by default |
|
| 662 | - $eventLogger->activate(); |
|
| 663 | - } |
|
| 664 | - return $eventLogger; |
|
| 665 | - }); |
|
| 666 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 667 | - |
|
| 668 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 669 | - $queryLogger = new QueryLogger(); |
|
| 670 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 671 | - // In debug mode, module is being activated by default |
|
| 672 | - $queryLogger->activate(); |
|
| 673 | - } |
|
| 674 | - return $queryLogger; |
|
| 675 | - }); |
|
| 676 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 677 | - |
|
| 678 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 679 | - return new TempManager( |
|
| 680 | - $c->getLogger(), |
|
| 681 | - $c->getConfig() |
|
| 682 | - ); |
|
| 683 | - }); |
|
| 684 | - $this->registerAlias('TempManager', TempManager::class); |
|
| 685 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 686 | - |
|
| 687 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 688 | - return new \OC\App\AppManager( |
|
| 689 | - $c->getUserSession(), |
|
| 690 | - $c->query(\OC\AppConfig::class), |
|
| 691 | - $c->getGroupManager(), |
|
| 692 | - $c->getMemCacheFactory(), |
|
| 693 | - $c->getEventDispatcher() |
|
| 694 | - ); |
|
| 695 | - }); |
|
| 696 | - $this->registerAlias('AppManager', AppManager::class); |
|
| 697 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 698 | - |
|
| 699 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 700 | - return new DateTimeZone( |
|
| 701 | - $c->getConfig(), |
|
| 702 | - $c->getSession() |
|
| 703 | - ); |
|
| 704 | - }); |
|
| 705 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 706 | - |
|
| 707 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 708 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 709 | - |
|
| 710 | - return new DateTimeFormatter( |
|
| 711 | - $c->getDateTimeZone()->getTimeZone(), |
|
| 712 | - $c->getL10N('lib', $language) |
|
| 713 | - ); |
|
| 714 | - }); |
|
| 715 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 716 | - |
|
| 717 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 718 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 719 | - $listener = new UserMountCacheListener($mountCache); |
|
| 720 | - $listener->listen($c->getUserManager()); |
|
| 721 | - return $mountCache; |
|
| 722 | - }); |
|
| 723 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 724 | - |
|
| 725 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 726 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 727 | - $mountCache = $c->query('UserMountCache'); |
|
| 728 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 729 | - |
|
| 730 | - // builtin providers |
|
| 731 | - |
|
| 732 | - $config = $c->getConfig(); |
|
| 733 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 734 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 735 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 736 | - |
|
| 737 | - return $manager; |
|
| 738 | - }); |
|
| 739 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 740 | - |
|
| 741 | - $this->registerService('IniWrapper', function ($c) { |
|
| 742 | - return new IniGetWrapper(); |
|
| 743 | - }); |
|
| 744 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 745 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 746 | - if ($busClass) { |
|
| 747 | - list($app, $class) = explode('::', $busClass, 2); |
|
| 748 | - if ($c->getAppManager()->isInstalled($app)) { |
|
| 749 | - \OC_App::loadApp($app); |
|
| 750 | - return $c->query($class); |
|
| 751 | - } else { |
|
| 752 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 753 | - } |
|
| 754 | - } else { |
|
| 755 | - $jobList = $c->getJobList(); |
|
| 756 | - return new CronBus($jobList); |
|
| 757 | - } |
|
| 758 | - }); |
|
| 759 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 760 | - return new TrustedDomainHelper($this->getConfig()); |
|
| 761 | - }); |
|
| 762 | - $this->registerService('Throttler', function (Server $c) { |
|
| 763 | - return new Throttler( |
|
| 764 | - $c->getDatabaseConnection(), |
|
| 765 | - new TimeFactory(), |
|
| 766 | - $c->getLogger(), |
|
| 767 | - $c->getConfig() |
|
| 768 | - ); |
|
| 769 | - }); |
|
| 770 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 771 | - // IConfig and IAppManager requires a working database. This code |
|
| 772 | - // might however be called when ownCloud is not yet setup. |
|
| 773 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 774 | - $config = $c->getConfig(); |
|
| 775 | - $appManager = $c->getAppManager(); |
|
| 776 | - } else { |
|
| 777 | - $config = null; |
|
| 778 | - $appManager = null; |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - return new Checker( |
|
| 782 | - new EnvironmentHelper(), |
|
| 783 | - new FileAccessHelper(), |
|
| 784 | - new AppLocator(), |
|
| 785 | - $config, |
|
| 786 | - $c->getMemCacheFactory(), |
|
| 787 | - $appManager, |
|
| 788 | - $c->getTempManager() |
|
| 789 | - ); |
|
| 790 | - }); |
|
| 791 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 792 | - if (isset($this['urlParams'])) { |
|
| 793 | - $urlParams = $this['urlParams']; |
|
| 794 | - } else { |
|
| 795 | - $urlParams = []; |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 799 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 800 | - ) { |
|
| 801 | - $stream = 'fakeinput://data'; |
|
| 802 | - } else { |
|
| 803 | - $stream = 'php://input'; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return new Request( |
|
| 807 | - [ |
|
| 808 | - 'get' => $_GET, |
|
| 809 | - 'post' => $_POST, |
|
| 810 | - 'files' => $_FILES, |
|
| 811 | - 'server' => $_SERVER, |
|
| 812 | - 'env' => $_ENV, |
|
| 813 | - 'cookies' => $_COOKIE, |
|
| 814 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 815 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 816 | - : '', |
|
| 817 | - 'urlParams' => $urlParams, |
|
| 818 | - ], |
|
| 819 | - $this->getSecureRandom(), |
|
| 820 | - $this->getConfig(), |
|
| 821 | - $this->getCsrfTokenManager(), |
|
| 822 | - $stream |
|
| 823 | - ); |
|
| 824 | - }); |
|
| 825 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 826 | - |
|
| 827 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 828 | - return new Mailer( |
|
| 829 | - $c->getConfig(), |
|
| 830 | - $c->getLogger(), |
|
| 831 | - $c->query(Defaults::class), |
|
| 832 | - $c->getURLGenerator(), |
|
| 833 | - $c->getL10N('lib') |
|
| 834 | - ); |
|
| 835 | - }); |
|
| 836 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 837 | - |
|
| 838 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 839 | - $config = $c->getConfig(); |
|
| 840 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 841 | - if (is_null($factoryClass)) { |
|
| 842 | - throw new \Exception('ldapProviderFactory not set'); |
|
| 843 | - } |
|
| 844 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 845 | - $factory = new $factoryClass($this); |
|
| 846 | - return $factory->getLDAPProvider(); |
|
| 847 | - }); |
|
| 848 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 849 | - $ini = $c->getIniWrapper(); |
|
| 850 | - $config = $c->getConfig(); |
|
| 851 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 852 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 853 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 854 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 855 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 856 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 857 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 858 | - } |
|
| 859 | - return new DBLockingProvider( |
|
| 860 | - $c->getDatabaseConnection(), |
|
| 861 | - $c->getLogger(), |
|
| 862 | - new TimeFactory(), |
|
| 863 | - $ttl, |
|
| 864 | - !\OC::$CLI |
|
| 865 | - ); |
|
| 866 | - } |
|
| 867 | - return new NoopLockingProvider(); |
|
| 868 | - }); |
|
| 869 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
| 870 | - |
|
| 871 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 872 | - return new \OC\Files\Mount\Manager(); |
|
| 873 | - }); |
|
| 874 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 875 | - |
|
| 876 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 877 | - return new \OC\Files\Type\Detection( |
|
| 878 | - $c->getURLGenerator(), |
|
| 879 | - \OC::$configDir, |
|
| 880 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 881 | - ); |
|
| 882 | - }); |
|
| 883 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 884 | - |
|
| 885 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 886 | - return new \OC\Files\Type\Loader( |
|
| 887 | - $c->getDatabaseConnection() |
|
| 888 | - ); |
|
| 889 | - }); |
|
| 890 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 891 | - $this->registerService(BundleFetcher::class, function () { |
|
| 892 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 893 | - }); |
|
| 894 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 895 | - return new Manager( |
|
| 896 | - $c->query(IValidator::class) |
|
| 897 | - ); |
|
| 898 | - }); |
|
| 899 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 900 | - |
|
| 901 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 902 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 903 | - $manager->registerCapability(function () use ($c) { |
|
| 904 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 905 | - }); |
|
| 906 | - $manager->registerCapability(function () use ($c) { |
|
| 907 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 908 | - }); |
|
| 909 | - return $manager; |
|
| 910 | - }); |
|
| 911 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 912 | - |
|
| 913 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 914 | - $config = $c->getConfig(); |
|
| 915 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 916 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 917 | - $factory = new $factoryClass($this); |
|
| 918 | - $manager = $factory->getManager(); |
|
| 919 | - |
|
| 920 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
| 921 | - $manager = $c->getUserManager(); |
|
| 922 | - $user = $manager->get($id); |
|
| 923 | - if(is_null($user)) { |
|
| 924 | - $l = $c->getL10N('core'); |
|
| 925 | - $displayName = $l->t('Unknown user'); |
|
| 926 | - } else { |
|
| 927 | - $displayName = $user->getDisplayName(); |
|
| 928 | - } |
|
| 929 | - return $displayName; |
|
| 930 | - }); |
|
| 931 | - |
|
| 932 | - return $manager; |
|
| 933 | - }); |
|
| 934 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 935 | - |
|
| 936 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 937 | - /* |
|
| 156 | + /** @var string */ |
|
| 157 | + private $webRoot; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param string $webRoot |
|
| 161 | + * @param \OC\Config $config |
|
| 162 | + */ |
|
| 163 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 164 | + parent::__construct(); |
|
| 165 | + $this->webRoot = $webRoot; |
|
| 166 | + |
|
| 167 | + // To find out if we are running from CLI or not |
|
| 168 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 169 | + |
|
| 170 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 171 | + return $c; |
|
| 172 | + }); |
|
| 173 | + |
|
| 174 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 175 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 176 | + |
|
| 177 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 178 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 179 | + |
|
| 180 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 184 | + return new PreviewManager( |
|
| 185 | + $c->getConfig(), |
|
| 186 | + $c->getRootFolder(), |
|
| 187 | + $c->getAppDataDir('preview'), |
|
| 188 | + $c->getEventDispatcher(), |
|
| 189 | + $c->getSession()->get('user_id') |
|
| 190 | + ); |
|
| 191 | + }); |
|
| 192 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
| 193 | + |
|
| 194 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 195 | + return new \OC\Preview\Watcher( |
|
| 196 | + $c->getAppDataDir('preview') |
|
| 197 | + ); |
|
| 198 | + }); |
|
| 199 | + |
|
| 200 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
| 201 | + $view = new View(); |
|
| 202 | + $util = new Encryption\Util( |
|
| 203 | + $view, |
|
| 204 | + $c->getUserManager(), |
|
| 205 | + $c->getGroupManager(), |
|
| 206 | + $c->getConfig() |
|
| 207 | + ); |
|
| 208 | + return new Encryption\Manager( |
|
| 209 | + $c->getConfig(), |
|
| 210 | + $c->getLogger(), |
|
| 211 | + $c->getL10N('core'), |
|
| 212 | + new View(), |
|
| 213 | + $util, |
|
| 214 | + new ArrayCache() |
|
| 215 | + ); |
|
| 216 | + }); |
|
| 217 | + |
|
| 218 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 219 | + $util = new Encryption\Util( |
|
| 220 | + new View(), |
|
| 221 | + $c->getUserManager(), |
|
| 222 | + $c->getGroupManager(), |
|
| 223 | + $c->getConfig() |
|
| 224 | + ); |
|
| 225 | + return new Encryption\File( |
|
| 226 | + $util, |
|
| 227 | + $c->getRootFolder(), |
|
| 228 | + $c->getShareManager() |
|
| 229 | + ); |
|
| 230 | + }); |
|
| 231 | + |
|
| 232 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 233 | + $view = new View(); |
|
| 234 | + $util = new Encryption\Util( |
|
| 235 | + $view, |
|
| 236 | + $c->getUserManager(), |
|
| 237 | + $c->getGroupManager(), |
|
| 238 | + $c->getConfig() |
|
| 239 | + ); |
|
| 240 | + |
|
| 241 | + return new Encryption\Keys\Storage($view, $util); |
|
| 242 | + }); |
|
| 243 | + $this->registerService('TagMapper', function (Server $c) { |
|
| 244 | + return new TagMapper($c->getDatabaseConnection()); |
|
| 245 | + }); |
|
| 246 | + |
|
| 247 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 248 | + $tagMapper = $c->query('TagMapper'); |
|
| 249 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
| 250 | + }); |
|
| 251 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
| 252 | + |
|
| 253 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 254 | + $config = $c->getConfig(); |
|
| 255 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 256 | + return new $factoryClass($this); |
|
| 257 | + }); |
|
| 258 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 259 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 260 | + }); |
|
| 261 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
| 262 | + |
|
| 263 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 264 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 265 | + }); |
|
| 266 | + $this->registerService('RootFolder', function (Server $c) { |
|
| 267 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 268 | + $view = new View(); |
|
| 269 | + $root = new Root( |
|
| 270 | + $manager, |
|
| 271 | + $view, |
|
| 272 | + null, |
|
| 273 | + $c->getUserMountCache(), |
|
| 274 | + $this->getLogger(), |
|
| 275 | + $this->getUserManager() |
|
| 276 | + ); |
|
| 277 | + $connector = new HookConnector($root, $view); |
|
| 278 | + $connector->viewToNode(); |
|
| 279 | + |
|
| 280 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 281 | + $previewConnector->connectWatcher(); |
|
| 282 | + |
|
| 283 | + return $root; |
|
| 284 | + }); |
|
| 285 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
| 286 | + |
|
| 287 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 288 | + return new LazyRoot(function () use ($c) { |
|
| 289 | + return $c->query('RootFolder'); |
|
| 290 | + }); |
|
| 291 | + }); |
|
| 292 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
| 293 | + |
|
| 294 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
| 295 | + $config = $c->getConfig(); |
|
| 296 | + return new \OC\User\Manager($config); |
|
| 297 | + }); |
|
| 298 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
| 299 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 300 | + |
|
| 301 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 302 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
| 303 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 304 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
| 305 | + }); |
|
| 306 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 307 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
| 308 | + }); |
|
| 309 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 310 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
| 311 | + }); |
|
| 312 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 313 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
| 314 | + }); |
|
| 315 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 316 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 317 | + }); |
|
| 318 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 319 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 320 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 321 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 322 | + }); |
|
| 323 | + return $groupManager; |
|
| 324 | + }); |
|
| 325 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 326 | + |
|
| 327 | + $this->registerService(Store::class, function (Server $c) { |
|
| 328 | + $session = $c->getSession(); |
|
| 329 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 330 | + $tokenProvider = $c->query(IProvider::class); |
|
| 331 | + } else { |
|
| 332 | + $tokenProvider = null; |
|
| 333 | + } |
|
| 334 | + $logger = $c->getLogger(); |
|
| 335 | + return new Store($session, $logger, $tokenProvider); |
|
| 336 | + }); |
|
| 337 | + $this->registerAlias(IStore::class, Store::class); |
|
| 338 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
| 339 | + $dbConnection = $c->getDatabaseConnection(); |
|
| 340 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 341 | + }); |
|
| 342 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
| 343 | + $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
|
| 344 | + $crypto = $c->getCrypto(); |
|
| 345 | + $config = $c->getConfig(); |
|
| 346 | + $logger = $c->getLogger(); |
|
| 347 | + $timeFactory = new TimeFactory(); |
|
| 348 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
| 349 | + }); |
|
| 350 | + $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
|
| 351 | + |
|
| 352 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 353 | + $manager = $c->getUserManager(); |
|
| 354 | + $session = new \OC\Session\Memory(''); |
|
| 355 | + $timeFactory = new TimeFactory(); |
|
| 356 | + // Token providers might require a working database. This code |
|
| 357 | + // might however be called when ownCloud is not yet setup. |
|
| 358 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 359 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
| 360 | + } else { |
|
| 361 | + $defaultTokenProvider = null; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $dispatcher = $c->getEventDispatcher(); |
|
| 365 | + |
|
| 366 | + $userSession = new \OC\User\Session( |
|
| 367 | + $manager, |
|
| 368 | + $session, |
|
| 369 | + $timeFactory, |
|
| 370 | + $defaultTokenProvider, |
|
| 371 | + $c->getConfig(), |
|
| 372 | + $c->getSecureRandom(), |
|
| 373 | + $c->getLockdownManager(), |
|
| 374 | + $c->getLogger() |
|
| 375 | + ); |
|
| 376 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 377 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 378 | + }); |
|
| 379 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 380 | + /** @var $user \OC\User\User */ |
|
| 381 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
| 382 | + }); |
|
| 383 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
| 384 | + /** @var $user \OC\User\User */ |
|
| 385 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
| 386 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 387 | + }); |
|
| 388 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 389 | + /** @var $user \OC\User\User */ |
|
| 390 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
| 391 | + }); |
|
| 392 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 393 | + /** @var $user \OC\User\User */ |
|
| 394 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 395 | + }); |
|
| 396 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 397 | + /** @var $user \OC\User\User */ |
|
| 398 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 399 | + }); |
|
| 400 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 401 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 402 | + }); |
|
| 403 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 404 | + /** @var $user \OC\User\User */ |
|
| 405 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 406 | + }); |
|
| 407 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 408 | + /** @var $user \OC\User\User */ |
|
| 409 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 410 | + }); |
|
| 411 | + $userSession->listen('\OC\User', 'logout', function () { |
|
| 412 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 413 | + }); |
|
| 414 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
| 415 | + /** @var $user \OC\User\User */ |
|
| 416 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 417 | + $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
|
| 418 | + }); |
|
| 419 | + return $userSession; |
|
| 420 | + }); |
|
| 421 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
| 422 | + |
|
| 423 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 424 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
| 425 | + $c->getAppManager(), |
|
| 426 | + $c->getSession(), |
|
| 427 | + $c->getConfig(), |
|
| 428 | + $c->getActivityManager(), |
|
| 429 | + $c->getLogger(), |
|
| 430 | + $c->query(IProvider::class), |
|
| 431 | + $c->query(ITimeFactory::class), |
|
| 432 | + $c->query(EventDispatcherInterface::class) |
|
| 433 | + ); |
|
| 434 | + }); |
|
| 435 | + |
|
| 436 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 437 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 438 | + |
|
| 439 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 440 | + return new \OC\AllConfig( |
|
| 441 | + $c->getSystemConfig() |
|
| 442 | + ); |
|
| 443 | + }); |
|
| 444 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 445 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 446 | + |
|
| 447 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 448 | + return new \OC\SystemConfig($config); |
|
| 449 | + }); |
|
| 450 | + |
|
| 451 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 452 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 453 | + }); |
|
| 454 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 455 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 456 | + |
|
| 457 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 458 | + return new \OC\L10N\Factory( |
|
| 459 | + $c->getConfig(), |
|
| 460 | + $c->getRequest(), |
|
| 461 | + $c->getUserSession(), |
|
| 462 | + \OC::$SERVERROOT |
|
| 463 | + ); |
|
| 464 | + }); |
|
| 465 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 466 | + |
|
| 467 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 468 | + $config = $c->getConfig(); |
|
| 469 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 470 | + $request = $c->getRequest(); |
|
| 471 | + return new \OC\URLGenerator( |
|
| 472 | + $config, |
|
| 473 | + $cacheFactory, |
|
| 474 | + $request |
|
| 475 | + ); |
|
| 476 | + }); |
|
| 477 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 478 | + |
|
| 479 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
| 480 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 481 | + |
|
| 482 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 483 | + return new Cache\File(); |
|
| 484 | + }); |
|
| 485 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 486 | + |
|
| 487 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 488 | + |
|
| 489 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 490 | + ArrayCache::class, |
|
| 491 | + ArrayCache::class, |
|
| 492 | + ArrayCache::class |
|
| 493 | + ); |
|
| 494 | + $config = $c->getConfig(); |
|
| 495 | + $request = $c->getRequest(); |
|
| 496 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
| 497 | + |
|
| 498 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 499 | + $v = \OC_App::getAppVersions(); |
|
| 500 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 501 | + $version = implode(',', $v); |
|
| 502 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 503 | + $path = \OC::$SERVERROOT; |
|
| 504 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 505 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 506 | + $config->getSystemValue('memcache.local', null), |
|
| 507 | + $config->getSystemValue('memcache.distributed', null), |
|
| 508 | + $config->getSystemValue('memcache.locking', null) |
|
| 509 | + ); |
|
| 510 | + } |
|
| 511 | + return $arrayCacheFactory; |
|
| 512 | + |
|
| 513 | + }); |
|
| 514 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 515 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 516 | + |
|
| 517 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 518 | + $systemConfig = $c->getSystemConfig(); |
|
| 519 | + return new RedisFactory($systemConfig); |
|
| 520 | + }); |
|
| 521 | + |
|
| 522 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 523 | + return new \OC\Activity\Manager( |
|
| 524 | + $c->getRequest(), |
|
| 525 | + $c->getUserSession(), |
|
| 526 | + $c->getConfig(), |
|
| 527 | + $c->query(IValidator::class) |
|
| 528 | + ); |
|
| 529 | + }); |
|
| 530 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 531 | + |
|
| 532 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 533 | + return new \OC\Activity\EventMerger( |
|
| 534 | + $c->getL10N('lib') |
|
| 535 | + ); |
|
| 536 | + }); |
|
| 537 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 538 | + |
|
| 539 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 540 | + return new AvatarManager( |
|
| 541 | + $c->query(\OC\User\Manager::class), |
|
| 542 | + $c->getAppDataDir('avatar'), |
|
| 543 | + $c->getL10N('lib'), |
|
| 544 | + $c->getLogger(), |
|
| 545 | + $c->getConfig() |
|
| 546 | + ); |
|
| 547 | + }); |
|
| 548 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
| 549 | + |
|
| 550 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 551 | + |
|
| 552 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 553 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 554 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
| 555 | + $logger = $factory->get($logType); |
|
| 556 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
| 557 | + |
|
| 558 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
| 559 | + }); |
|
| 560 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
| 561 | + |
|
| 562 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 563 | + return new LogFactory($c, $this->getSystemConfig()); |
|
| 564 | + }); |
|
| 565 | + |
|
| 566 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 567 | + $config = $c->getConfig(); |
|
| 568 | + return new \OC\BackgroundJob\JobList( |
|
| 569 | + $c->getDatabaseConnection(), |
|
| 570 | + $config, |
|
| 571 | + new TimeFactory() |
|
| 572 | + ); |
|
| 573 | + }); |
|
| 574 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 575 | + |
|
| 576 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 577 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 578 | + $logger = $c->getLogger(); |
|
| 579 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 580 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 581 | + } else { |
|
| 582 | + $router = new \OC\Route\Router($logger); |
|
| 583 | + } |
|
| 584 | + return $router; |
|
| 585 | + }); |
|
| 586 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 587 | + |
|
| 588 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 589 | + return new Search(); |
|
| 590 | + }); |
|
| 591 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 592 | + |
|
| 593 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
| 594 | + return new \OC\Security\RateLimiting\Limiter( |
|
| 595 | + $this->getUserSession(), |
|
| 596 | + $this->getRequest(), |
|
| 597 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
| 598 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 599 | + ); |
|
| 600 | + }); |
|
| 601 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 602 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 603 | + $this->getMemCacheFactory(), |
|
| 604 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 605 | + ); |
|
| 606 | + }); |
|
| 607 | + |
|
| 608 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 609 | + return new SecureRandom(); |
|
| 610 | + }); |
|
| 611 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 612 | + |
|
| 613 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 614 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 615 | + }); |
|
| 616 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 617 | + |
|
| 618 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 619 | + return new Hasher($c->getConfig()); |
|
| 620 | + }); |
|
| 621 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 622 | + |
|
| 623 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 624 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 625 | + }); |
|
| 626 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 627 | + |
|
| 628 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 629 | + $systemConfig = $c->getSystemConfig(); |
|
| 630 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 631 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 632 | + if (!$factory->isValidType($type)) { |
|
| 633 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 634 | + } |
|
| 635 | + $connectionParams = $factory->createConnectionParams(); |
|
| 636 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 637 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 638 | + return $connection; |
|
| 639 | + }); |
|
| 640 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 644 | + $user = \OC_User::getUser(); |
|
| 645 | + $uid = $user ? $user : null; |
|
| 646 | + return new ClientService( |
|
| 647 | + $c->getConfig(), |
|
| 648 | + new \OC\Security\CertificateManager( |
|
| 649 | + $uid, |
|
| 650 | + new View(), |
|
| 651 | + $c->getConfig(), |
|
| 652 | + $c->getLogger(), |
|
| 653 | + $c->getSecureRandom() |
|
| 654 | + ) |
|
| 655 | + ); |
|
| 656 | + }); |
|
| 657 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 658 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 659 | + $eventLogger = new EventLogger(); |
|
| 660 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 661 | + // In debug mode, module is being activated by default |
|
| 662 | + $eventLogger->activate(); |
|
| 663 | + } |
|
| 664 | + return $eventLogger; |
|
| 665 | + }); |
|
| 666 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 667 | + |
|
| 668 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 669 | + $queryLogger = new QueryLogger(); |
|
| 670 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 671 | + // In debug mode, module is being activated by default |
|
| 672 | + $queryLogger->activate(); |
|
| 673 | + } |
|
| 674 | + return $queryLogger; |
|
| 675 | + }); |
|
| 676 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 677 | + |
|
| 678 | + $this->registerService(TempManager::class, function (Server $c) { |
|
| 679 | + return new TempManager( |
|
| 680 | + $c->getLogger(), |
|
| 681 | + $c->getConfig() |
|
| 682 | + ); |
|
| 683 | + }); |
|
| 684 | + $this->registerAlias('TempManager', TempManager::class); |
|
| 685 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 686 | + |
|
| 687 | + $this->registerService(AppManager::class, function (Server $c) { |
|
| 688 | + return new \OC\App\AppManager( |
|
| 689 | + $c->getUserSession(), |
|
| 690 | + $c->query(\OC\AppConfig::class), |
|
| 691 | + $c->getGroupManager(), |
|
| 692 | + $c->getMemCacheFactory(), |
|
| 693 | + $c->getEventDispatcher() |
|
| 694 | + ); |
|
| 695 | + }); |
|
| 696 | + $this->registerAlias('AppManager', AppManager::class); |
|
| 697 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 698 | + |
|
| 699 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 700 | + return new DateTimeZone( |
|
| 701 | + $c->getConfig(), |
|
| 702 | + $c->getSession() |
|
| 703 | + ); |
|
| 704 | + }); |
|
| 705 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 706 | + |
|
| 707 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 708 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 709 | + |
|
| 710 | + return new DateTimeFormatter( |
|
| 711 | + $c->getDateTimeZone()->getTimeZone(), |
|
| 712 | + $c->getL10N('lib', $language) |
|
| 713 | + ); |
|
| 714 | + }); |
|
| 715 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 716 | + |
|
| 717 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 718 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 719 | + $listener = new UserMountCacheListener($mountCache); |
|
| 720 | + $listener->listen($c->getUserManager()); |
|
| 721 | + return $mountCache; |
|
| 722 | + }); |
|
| 723 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 724 | + |
|
| 725 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 726 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 727 | + $mountCache = $c->query('UserMountCache'); |
|
| 728 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 729 | + |
|
| 730 | + // builtin providers |
|
| 731 | + |
|
| 732 | + $config = $c->getConfig(); |
|
| 733 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 734 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 735 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 736 | + |
|
| 737 | + return $manager; |
|
| 738 | + }); |
|
| 739 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 740 | + |
|
| 741 | + $this->registerService('IniWrapper', function ($c) { |
|
| 742 | + return new IniGetWrapper(); |
|
| 743 | + }); |
|
| 744 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 745 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 746 | + if ($busClass) { |
|
| 747 | + list($app, $class) = explode('::', $busClass, 2); |
|
| 748 | + if ($c->getAppManager()->isInstalled($app)) { |
|
| 749 | + \OC_App::loadApp($app); |
|
| 750 | + return $c->query($class); |
|
| 751 | + } else { |
|
| 752 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 753 | + } |
|
| 754 | + } else { |
|
| 755 | + $jobList = $c->getJobList(); |
|
| 756 | + return new CronBus($jobList); |
|
| 757 | + } |
|
| 758 | + }); |
|
| 759 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 760 | + return new TrustedDomainHelper($this->getConfig()); |
|
| 761 | + }); |
|
| 762 | + $this->registerService('Throttler', function (Server $c) { |
|
| 763 | + return new Throttler( |
|
| 764 | + $c->getDatabaseConnection(), |
|
| 765 | + new TimeFactory(), |
|
| 766 | + $c->getLogger(), |
|
| 767 | + $c->getConfig() |
|
| 768 | + ); |
|
| 769 | + }); |
|
| 770 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 771 | + // IConfig and IAppManager requires a working database. This code |
|
| 772 | + // might however be called when ownCloud is not yet setup. |
|
| 773 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 774 | + $config = $c->getConfig(); |
|
| 775 | + $appManager = $c->getAppManager(); |
|
| 776 | + } else { |
|
| 777 | + $config = null; |
|
| 778 | + $appManager = null; |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + return new Checker( |
|
| 782 | + new EnvironmentHelper(), |
|
| 783 | + new FileAccessHelper(), |
|
| 784 | + new AppLocator(), |
|
| 785 | + $config, |
|
| 786 | + $c->getMemCacheFactory(), |
|
| 787 | + $appManager, |
|
| 788 | + $c->getTempManager() |
|
| 789 | + ); |
|
| 790 | + }); |
|
| 791 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 792 | + if (isset($this['urlParams'])) { |
|
| 793 | + $urlParams = $this['urlParams']; |
|
| 794 | + } else { |
|
| 795 | + $urlParams = []; |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 799 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 800 | + ) { |
|
| 801 | + $stream = 'fakeinput://data'; |
|
| 802 | + } else { |
|
| 803 | + $stream = 'php://input'; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return new Request( |
|
| 807 | + [ |
|
| 808 | + 'get' => $_GET, |
|
| 809 | + 'post' => $_POST, |
|
| 810 | + 'files' => $_FILES, |
|
| 811 | + 'server' => $_SERVER, |
|
| 812 | + 'env' => $_ENV, |
|
| 813 | + 'cookies' => $_COOKIE, |
|
| 814 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 815 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 816 | + : '', |
|
| 817 | + 'urlParams' => $urlParams, |
|
| 818 | + ], |
|
| 819 | + $this->getSecureRandom(), |
|
| 820 | + $this->getConfig(), |
|
| 821 | + $this->getCsrfTokenManager(), |
|
| 822 | + $stream |
|
| 823 | + ); |
|
| 824 | + }); |
|
| 825 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 826 | + |
|
| 827 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 828 | + return new Mailer( |
|
| 829 | + $c->getConfig(), |
|
| 830 | + $c->getLogger(), |
|
| 831 | + $c->query(Defaults::class), |
|
| 832 | + $c->getURLGenerator(), |
|
| 833 | + $c->getL10N('lib') |
|
| 834 | + ); |
|
| 835 | + }); |
|
| 836 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 837 | + |
|
| 838 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
| 839 | + $config = $c->getConfig(); |
|
| 840 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 841 | + if (is_null($factoryClass)) { |
|
| 842 | + throw new \Exception('ldapProviderFactory not set'); |
|
| 843 | + } |
|
| 844 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 845 | + $factory = new $factoryClass($this); |
|
| 846 | + return $factory->getLDAPProvider(); |
|
| 847 | + }); |
|
| 848 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 849 | + $ini = $c->getIniWrapper(); |
|
| 850 | + $config = $c->getConfig(); |
|
| 851 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 852 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 853 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 854 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 855 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 856 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 857 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 858 | + } |
|
| 859 | + return new DBLockingProvider( |
|
| 860 | + $c->getDatabaseConnection(), |
|
| 861 | + $c->getLogger(), |
|
| 862 | + new TimeFactory(), |
|
| 863 | + $ttl, |
|
| 864 | + !\OC::$CLI |
|
| 865 | + ); |
|
| 866 | + } |
|
| 867 | + return new NoopLockingProvider(); |
|
| 868 | + }); |
|
| 869 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
| 870 | + |
|
| 871 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 872 | + return new \OC\Files\Mount\Manager(); |
|
| 873 | + }); |
|
| 874 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 875 | + |
|
| 876 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 877 | + return new \OC\Files\Type\Detection( |
|
| 878 | + $c->getURLGenerator(), |
|
| 879 | + \OC::$configDir, |
|
| 880 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 881 | + ); |
|
| 882 | + }); |
|
| 883 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 884 | + |
|
| 885 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 886 | + return new \OC\Files\Type\Loader( |
|
| 887 | + $c->getDatabaseConnection() |
|
| 888 | + ); |
|
| 889 | + }); |
|
| 890 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 891 | + $this->registerService(BundleFetcher::class, function () { |
|
| 892 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 893 | + }); |
|
| 894 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 895 | + return new Manager( |
|
| 896 | + $c->query(IValidator::class) |
|
| 897 | + ); |
|
| 898 | + }); |
|
| 899 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 900 | + |
|
| 901 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 902 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 903 | + $manager->registerCapability(function () use ($c) { |
|
| 904 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 905 | + }); |
|
| 906 | + $manager->registerCapability(function () use ($c) { |
|
| 907 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 908 | + }); |
|
| 909 | + return $manager; |
|
| 910 | + }); |
|
| 911 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 912 | + |
|
| 913 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 914 | + $config = $c->getConfig(); |
|
| 915 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 916 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 917 | + $factory = new $factoryClass($this); |
|
| 918 | + $manager = $factory->getManager(); |
|
| 919 | + |
|
| 920 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
| 921 | + $manager = $c->getUserManager(); |
|
| 922 | + $user = $manager->get($id); |
|
| 923 | + if(is_null($user)) { |
|
| 924 | + $l = $c->getL10N('core'); |
|
| 925 | + $displayName = $l->t('Unknown user'); |
|
| 926 | + } else { |
|
| 927 | + $displayName = $user->getDisplayName(); |
|
| 928 | + } |
|
| 929 | + return $displayName; |
|
| 930 | + }); |
|
| 931 | + |
|
| 932 | + return $manager; |
|
| 933 | + }); |
|
| 934 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 935 | + |
|
| 936 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 937 | + /* |
|
| 938 | 938 | * Dark magic for autoloader. |
| 939 | 939 | * If we do a class_exists it will try to load the class which will |
| 940 | 940 | * make composer cache the result. Resulting in errors when enabling |
| 941 | 941 | * the theming app. |
| 942 | 942 | */ |
| 943 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 944 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 945 | - $classExists = true; |
|
| 946 | - } else { |
|
| 947 | - $classExists = false; |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 951 | - return new ThemingDefaults( |
|
| 952 | - $c->getConfig(), |
|
| 953 | - $c->getL10N('theming'), |
|
| 954 | - $c->getURLGenerator(), |
|
| 955 | - $c->getMemCacheFactory(), |
|
| 956 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
| 957 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()), |
|
| 958 | - $c->getAppManager() |
|
| 959 | - ); |
|
| 960 | - } |
|
| 961 | - return new \OC_Defaults(); |
|
| 962 | - }); |
|
| 963 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 964 | - /** @var Factory $cacheFactory */ |
|
| 965 | - $cacheFactory = $c->query(Factory::class); |
|
| 966 | - return new SCSSCacher( |
|
| 967 | - $c->getLogger(), |
|
| 968 | - $c->query(\OC\Files\AppData\Factory::class), |
|
| 969 | - $c->getURLGenerator(), |
|
| 970 | - $c->getConfig(), |
|
| 971 | - $c->getThemingDefaults(), |
|
| 972 | - \OC::$SERVERROOT, |
|
| 973 | - $this->getMemCacheFactory() |
|
| 974 | - ); |
|
| 975 | - }); |
|
| 976 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 977 | - /** @var Factory $cacheFactory */ |
|
| 978 | - $cacheFactory = $c->query(Factory::class); |
|
| 979 | - return new JSCombiner( |
|
| 980 | - $c->getAppDataDir('js'), |
|
| 981 | - $c->getURLGenerator(), |
|
| 982 | - $this->getMemCacheFactory(), |
|
| 983 | - $c->getSystemConfig(), |
|
| 984 | - $c->getLogger() |
|
| 985 | - ); |
|
| 986 | - }); |
|
| 987 | - $this->registerService(EventDispatcher::class, function () { |
|
| 988 | - return new EventDispatcher(); |
|
| 989 | - }); |
|
| 990 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
| 991 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
| 992 | - |
|
| 993 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 994 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 995 | - $request = new Request( |
|
| 996 | - [ |
|
| 997 | - 'get' => $_GET, |
|
| 998 | - 'post' => $_POST, |
|
| 999 | - 'files' => $_FILES, |
|
| 1000 | - 'server' => $_SERVER, |
|
| 1001 | - 'env' => $_ENV, |
|
| 1002 | - 'cookies' => $_COOKIE, |
|
| 1003 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1004 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1005 | - : null, |
|
| 1006 | - ], |
|
| 1007 | - $c->getSecureRandom(), |
|
| 1008 | - $c->getConfig() |
|
| 1009 | - ); |
|
| 1010 | - |
|
| 1011 | - return new CryptoWrapper( |
|
| 1012 | - $c->getConfig(), |
|
| 1013 | - $c->getCrypto(), |
|
| 1014 | - $c->getSecureRandom(), |
|
| 1015 | - $request |
|
| 1016 | - ); |
|
| 1017 | - }); |
|
| 1018 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 1019 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 1020 | - |
|
| 1021 | - return new CsrfTokenManager( |
|
| 1022 | - $tokenGenerator, |
|
| 1023 | - $c->query(SessionStorage::class) |
|
| 1024 | - ); |
|
| 1025 | - }); |
|
| 1026 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1027 | - return new SessionStorage($c->getSession()); |
|
| 1028 | - }); |
|
| 1029 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 1030 | - return new ContentSecurityPolicyManager(); |
|
| 1031 | - }); |
|
| 1032 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 1033 | - |
|
| 1034 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 1035 | - return new ContentSecurityPolicyNonceManager( |
|
| 1036 | - $c->getCsrfTokenManager(), |
|
| 1037 | - $c->getRequest() |
|
| 1038 | - ); |
|
| 1039 | - }); |
|
| 1040 | - |
|
| 1041 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1042 | - $config = $c->getConfig(); |
|
| 1043 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1044 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1045 | - $factory = new $factoryClass($this); |
|
| 1046 | - |
|
| 1047 | - $manager = new \OC\Share20\Manager( |
|
| 1048 | - $c->getLogger(), |
|
| 1049 | - $c->getConfig(), |
|
| 1050 | - $c->getSecureRandom(), |
|
| 1051 | - $c->getHasher(), |
|
| 1052 | - $c->getMountManager(), |
|
| 1053 | - $c->getGroupManager(), |
|
| 1054 | - $c->getL10N('lib'), |
|
| 1055 | - $c->getL10NFactory(), |
|
| 1056 | - $factory, |
|
| 1057 | - $c->getUserManager(), |
|
| 1058 | - $c->getLazyRootFolder(), |
|
| 1059 | - $c->getEventDispatcher(), |
|
| 1060 | - $c->getMailer(), |
|
| 1061 | - $c->getURLGenerator(), |
|
| 1062 | - $c->getThemingDefaults() |
|
| 1063 | - ); |
|
| 1064 | - |
|
| 1065 | - return $manager; |
|
| 1066 | - }); |
|
| 1067 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1068 | - |
|
| 1069 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
| 1070 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1071 | - |
|
| 1072 | - // register default plugins |
|
| 1073 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1074 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1075 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1076 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1077 | - |
|
| 1078 | - return $instance; |
|
| 1079 | - }); |
|
| 1080 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1081 | - |
|
| 1082 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1083 | - |
|
| 1084 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 1085 | - $manager = new \OC\Settings\Manager( |
|
| 1086 | - $c->getLogger(), |
|
| 1087 | - $c->getDatabaseConnection(), |
|
| 1088 | - $c->getL10N('lib'), |
|
| 1089 | - $c->getConfig(), |
|
| 1090 | - $c->getEncryptionManager(), |
|
| 1091 | - $c->getUserManager(), |
|
| 1092 | - $c->getLockingProvider(), |
|
| 1093 | - $c->getRequest(), |
|
| 1094 | - $c->getURLGenerator(), |
|
| 1095 | - $c->query(AccountManager::class), |
|
| 1096 | - $c->getGroupManager(), |
|
| 1097 | - $c->getL10NFactory(), |
|
| 1098 | - $c->getAppManager() |
|
| 1099 | - ); |
|
| 1100 | - return $manager; |
|
| 1101 | - }); |
|
| 1102 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1103 | - return new \OC\Files\AppData\Factory( |
|
| 1104 | - $c->getRootFolder(), |
|
| 1105 | - $c->getSystemConfig() |
|
| 1106 | - ); |
|
| 1107 | - }); |
|
| 1108 | - |
|
| 1109 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1110 | - return new LockdownManager(function () use ($c) { |
|
| 1111 | - return $c->getSession(); |
|
| 1112 | - }); |
|
| 1113 | - }); |
|
| 1114 | - |
|
| 1115 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1116 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1117 | - }); |
|
| 1118 | - |
|
| 1119 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1120 | - return new CloudIdManager(); |
|
| 1121 | - }); |
|
| 1122 | - |
|
| 1123 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1124 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1125 | - |
|
| 1126 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1127 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1128 | - |
|
| 1129 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1130 | - return new Defaults( |
|
| 1131 | - $c->getThemingDefaults() |
|
| 1132 | - ); |
|
| 1133 | - }); |
|
| 1134 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1135 | - |
|
| 1136 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1137 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1138 | - }); |
|
| 1139 | - |
|
| 1140 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1141 | - return new ShareHelper( |
|
| 1142 | - $c->query(\OCP\Share\IManager::class) |
|
| 1143 | - ); |
|
| 1144 | - }); |
|
| 1145 | - |
|
| 1146 | - $this->registerService(Installer::class, function(Server $c) { |
|
| 1147 | - return new Installer( |
|
| 1148 | - $c->getAppFetcher(), |
|
| 1149 | - $c->getHTTPClientService(), |
|
| 1150 | - $c->getTempManager(), |
|
| 1151 | - $c->getLogger(), |
|
| 1152 | - $c->getConfig() |
|
| 1153 | - ); |
|
| 1154 | - }); |
|
| 1155 | - |
|
| 1156 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
| 1157 | - return new ApiFactory($c->getHTTPClientService()); |
|
| 1158 | - }); |
|
| 1159 | - |
|
| 1160 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
| 1161 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1162 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
| 1163 | - }); |
|
| 1164 | - |
|
| 1165 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
| 1166 | - return new ContactsStore( |
|
| 1167 | - $c->getContactsManager(), |
|
| 1168 | - $c->getConfig(), |
|
| 1169 | - $c->getUserManager(), |
|
| 1170 | - $c->getGroupManager() |
|
| 1171 | - ); |
|
| 1172 | - }); |
|
| 1173 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1174 | - |
|
| 1175 | - $this->connectDispatcher(); |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - /** |
|
| 1179 | - * @return \OCP\Calendar\IManager |
|
| 1180 | - */ |
|
| 1181 | - public function getCalendarManager() { |
|
| 1182 | - return $this->query('CalendarManager'); |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - private function connectDispatcher() { |
|
| 1186 | - $dispatcher = $this->getEventDispatcher(); |
|
| 1187 | - |
|
| 1188 | - // Delete avatar on user deletion |
|
| 1189 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
| 1190 | - $logger = $this->getLogger(); |
|
| 1191 | - $manager = $this->getAvatarManager(); |
|
| 1192 | - /** @var IUser $user */ |
|
| 1193 | - $user = $e->getSubject(); |
|
| 1194 | - |
|
| 1195 | - try { |
|
| 1196 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1197 | - $avatar->remove(); |
|
| 1198 | - } catch (NotFoundException $e) { |
|
| 1199 | - // no avatar to remove |
|
| 1200 | - } catch (\Exception $e) { |
|
| 1201 | - // Ignore exceptions |
|
| 1202 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1203 | - } |
|
| 1204 | - }); |
|
| 1205 | - |
|
| 1206 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1207 | - $manager = $this->getAvatarManager(); |
|
| 1208 | - /** @var IUser $user */ |
|
| 1209 | - $user = $e->getSubject(); |
|
| 1210 | - $feature = $e->getArgument('feature'); |
|
| 1211 | - $oldValue = $e->getArgument('oldValue'); |
|
| 1212 | - $value = $e->getArgument('value'); |
|
| 1213 | - |
|
| 1214 | - try { |
|
| 1215 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1216 | - $avatar->userChanged($feature, $oldValue, $value); |
|
| 1217 | - } catch (NotFoundException $e) { |
|
| 1218 | - // no avatar to remove |
|
| 1219 | - } |
|
| 1220 | - }); |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * @return \OCP\Contacts\IManager |
|
| 1225 | - */ |
|
| 1226 | - public function getContactsManager() { |
|
| 1227 | - return $this->query('ContactsManager'); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * @return \OC\Encryption\Manager |
|
| 1232 | - */ |
|
| 1233 | - public function getEncryptionManager() { |
|
| 1234 | - return $this->query('EncryptionManager'); |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * @return \OC\Encryption\File |
|
| 1239 | - */ |
|
| 1240 | - public function getEncryptionFilesHelper() { |
|
| 1241 | - return $this->query('EncryptionFileHelper'); |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - /** |
|
| 1245 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1246 | - */ |
|
| 1247 | - public function getEncryptionKeyStorage() { |
|
| 1248 | - return $this->query('EncryptionKeyStorage'); |
|
| 1249 | - } |
|
| 1250 | - |
|
| 1251 | - /** |
|
| 1252 | - * The current request object holding all information about the request |
|
| 1253 | - * currently being processed is returned from this method. |
|
| 1254 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1255 | - * |
|
| 1256 | - * @return \OCP\IRequest |
|
| 1257 | - */ |
|
| 1258 | - public function getRequest() { |
|
| 1259 | - return $this->query('Request'); |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - /** |
|
| 1263 | - * Returns the preview manager which can create preview images for a given file |
|
| 1264 | - * |
|
| 1265 | - * @return \OCP\IPreview |
|
| 1266 | - */ |
|
| 1267 | - public function getPreviewManager() { |
|
| 1268 | - return $this->query('PreviewManager'); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - /** |
|
| 1272 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1273 | - * |
|
| 1274 | - * @see \OCP\ITagManager::load() |
|
| 1275 | - * @return \OCP\ITagManager |
|
| 1276 | - */ |
|
| 1277 | - public function getTagManager() { |
|
| 1278 | - return $this->query('TagManager'); |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * Returns the system-tag manager |
|
| 1283 | - * |
|
| 1284 | - * @return \OCP\SystemTag\ISystemTagManager |
|
| 1285 | - * |
|
| 1286 | - * @since 9.0.0 |
|
| 1287 | - */ |
|
| 1288 | - public function getSystemTagManager() { |
|
| 1289 | - return $this->query('SystemTagManager'); |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - /** |
|
| 1293 | - * Returns the system-tag object mapper |
|
| 1294 | - * |
|
| 1295 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1296 | - * |
|
| 1297 | - * @since 9.0.0 |
|
| 1298 | - */ |
|
| 1299 | - public function getSystemTagObjectMapper() { |
|
| 1300 | - return $this->query('SystemTagObjectMapper'); |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - /** |
|
| 1304 | - * Returns the avatar manager, used for avatar functionality |
|
| 1305 | - * |
|
| 1306 | - * @return \OCP\IAvatarManager |
|
| 1307 | - */ |
|
| 1308 | - public function getAvatarManager() { |
|
| 1309 | - return $this->query('AvatarManager'); |
|
| 1310 | - } |
|
| 1311 | - |
|
| 1312 | - /** |
|
| 1313 | - * Returns the root folder of ownCloud's data directory |
|
| 1314 | - * |
|
| 1315 | - * @return \OCP\Files\IRootFolder |
|
| 1316 | - */ |
|
| 1317 | - public function getRootFolder() { |
|
| 1318 | - return $this->query('LazyRootFolder'); |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * Returns the root folder of ownCloud's data directory |
|
| 1323 | - * This is the lazy variant so this gets only initialized once it |
|
| 1324 | - * is actually used. |
|
| 1325 | - * |
|
| 1326 | - * @return \OCP\Files\IRootFolder |
|
| 1327 | - */ |
|
| 1328 | - public function getLazyRootFolder() { |
|
| 1329 | - return $this->query('LazyRootFolder'); |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * Returns a view to ownCloud's files folder |
|
| 1334 | - * |
|
| 1335 | - * @param string $userId user ID |
|
| 1336 | - * @return \OCP\Files\Folder|null |
|
| 1337 | - */ |
|
| 1338 | - public function getUserFolder($userId = null) { |
|
| 1339 | - if ($userId === null) { |
|
| 1340 | - $user = $this->getUserSession()->getUser(); |
|
| 1341 | - if (!$user) { |
|
| 1342 | - return null; |
|
| 1343 | - } |
|
| 1344 | - $userId = $user->getUID(); |
|
| 1345 | - } |
|
| 1346 | - $root = $this->getRootFolder(); |
|
| 1347 | - return $root->getUserFolder($userId); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * Returns an app-specific view in ownClouds data directory |
|
| 1352 | - * |
|
| 1353 | - * @return \OCP\Files\Folder |
|
| 1354 | - * @deprecated since 9.2.0 use IAppData |
|
| 1355 | - */ |
|
| 1356 | - public function getAppFolder() { |
|
| 1357 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1358 | - $root = $this->getRootFolder(); |
|
| 1359 | - if (!$root->nodeExists($dir)) { |
|
| 1360 | - $folder = $root->newFolder($dir); |
|
| 1361 | - } else { |
|
| 1362 | - $folder = $root->get($dir); |
|
| 1363 | - } |
|
| 1364 | - return $folder; |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - /** |
|
| 1368 | - * @return \OC\User\Manager |
|
| 1369 | - */ |
|
| 1370 | - public function getUserManager() { |
|
| 1371 | - return $this->query('UserManager'); |
|
| 1372 | - } |
|
| 1373 | - |
|
| 1374 | - /** |
|
| 1375 | - * @return \OC\Group\Manager |
|
| 1376 | - */ |
|
| 1377 | - public function getGroupManager() { |
|
| 1378 | - return $this->query('GroupManager'); |
|
| 1379 | - } |
|
| 1380 | - |
|
| 1381 | - /** |
|
| 1382 | - * @return \OC\User\Session |
|
| 1383 | - */ |
|
| 1384 | - public function getUserSession() { |
|
| 1385 | - return $this->query('UserSession'); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - /** |
|
| 1389 | - * @return \OCP\ISession |
|
| 1390 | - */ |
|
| 1391 | - public function getSession() { |
|
| 1392 | - return $this->query('UserSession')->getSession(); |
|
| 1393 | - } |
|
| 1394 | - |
|
| 1395 | - /** |
|
| 1396 | - * @param \OCP\ISession $session |
|
| 1397 | - */ |
|
| 1398 | - public function setSession(\OCP\ISession $session) { |
|
| 1399 | - $this->query(SessionStorage::class)->setSession($session); |
|
| 1400 | - $this->query('UserSession')->setSession($session); |
|
| 1401 | - $this->query(Store::class)->setSession($session); |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - /** |
|
| 1405 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1406 | - */ |
|
| 1407 | - public function getTwoFactorAuthManager() { |
|
| 1408 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1409 | - } |
|
| 1410 | - |
|
| 1411 | - /** |
|
| 1412 | - * @return \OC\NavigationManager |
|
| 1413 | - */ |
|
| 1414 | - public function getNavigationManager() { |
|
| 1415 | - return $this->query('NavigationManager'); |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - /** |
|
| 1419 | - * @return \OCP\IConfig |
|
| 1420 | - */ |
|
| 1421 | - public function getConfig() { |
|
| 1422 | - return $this->query('AllConfig'); |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - /** |
|
| 1426 | - * @return \OC\SystemConfig |
|
| 1427 | - */ |
|
| 1428 | - public function getSystemConfig() { |
|
| 1429 | - return $this->query('SystemConfig'); |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - /** |
|
| 1433 | - * Returns the app config manager |
|
| 1434 | - * |
|
| 1435 | - * @return \OCP\IAppConfig |
|
| 1436 | - */ |
|
| 1437 | - public function getAppConfig() { |
|
| 1438 | - return $this->query('AppConfig'); |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - /** |
|
| 1442 | - * @return \OCP\L10N\IFactory |
|
| 1443 | - */ |
|
| 1444 | - public function getL10NFactory() { |
|
| 1445 | - return $this->query('L10NFactory'); |
|
| 1446 | - } |
|
| 1447 | - |
|
| 1448 | - /** |
|
| 1449 | - * get an L10N instance |
|
| 1450 | - * |
|
| 1451 | - * @param string $app appid |
|
| 1452 | - * @param string $lang |
|
| 1453 | - * @return IL10N |
|
| 1454 | - */ |
|
| 1455 | - public function getL10N($app, $lang = null) { |
|
| 1456 | - return $this->getL10NFactory()->get($app, $lang); |
|
| 1457 | - } |
|
| 1458 | - |
|
| 1459 | - /** |
|
| 1460 | - * @return \OCP\IURLGenerator |
|
| 1461 | - */ |
|
| 1462 | - public function getURLGenerator() { |
|
| 1463 | - return $this->query('URLGenerator'); |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * @return AppFetcher |
|
| 1468 | - */ |
|
| 1469 | - public function getAppFetcher() { |
|
| 1470 | - return $this->query(AppFetcher::class); |
|
| 1471 | - } |
|
| 1472 | - |
|
| 1473 | - /** |
|
| 1474 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1475 | - * getMemCacheFactory() instead. |
|
| 1476 | - * |
|
| 1477 | - * @return \OCP\ICache |
|
| 1478 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1479 | - */ |
|
| 1480 | - public function getCache() { |
|
| 1481 | - return $this->query('UserCache'); |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - /** |
|
| 1485 | - * Returns an \OCP\CacheFactory instance |
|
| 1486 | - * |
|
| 1487 | - * @return \OCP\ICacheFactory |
|
| 1488 | - */ |
|
| 1489 | - public function getMemCacheFactory() { |
|
| 1490 | - return $this->query('MemCacheFactory'); |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * Returns an \OC\RedisFactory instance |
|
| 1495 | - * |
|
| 1496 | - * @return \OC\RedisFactory |
|
| 1497 | - */ |
|
| 1498 | - public function getGetRedisFactory() { |
|
| 1499 | - return $this->query('RedisFactory'); |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * Returns the current session |
|
| 1505 | - * |
|
| 1506 | - * @return \OCP\IDBConnection |
|
| 1507 | - */ |
|
| 1508 | - public function getDatabaseConnection() { |
|
| 1509 | - return $this->query('DatabaseConnection'); |
|
| 1510 | - } |
|
| 1511 | - |
|
| 1512 | - /** |
|
| 1513 | - * Returns the activity manager |
|
| 1514 | - * |
|
| 1515 | - * @return \OCP\Activity\IManager |
|
| 1516 | - */ |
|
| 1517 | - public function getActivityManager() { |
|
| 1518 | - return $this->query('ActivityManager'); |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - /** |
|
| 1522 | - * Returns an job list for controlling background jobs |
|
| 1523 | - * |
|
| 1524 | - * @return \OCP\BackgroundJob\IJobList |
|
| 1525 | - */ |
|
| 1526 | - public function getJobList() { |
|
| 1527 | - return $this->query('JobList'); |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * Returns a logger instance |
|
| 1532 | - * |
|
| 1533 | - * @return \OCP\ILogger |
|
| 1534 | - */ |
|
| 1535 | - public function getLogger() { |
|
| 1536 | - return $this->query('Logger'); |
|
| 1537 | - } |
|
| 1538 | - |
|
| 1539 | - /** |
|
| 1540 | - * @return ILogFactory |
|
| 1541 | - * @throws \OCP\AppFramework\QueryException |
|
| 1542 | - */ |
|
| 1543 | - public function getLogFactory() { |
|
| 1544 | - return $this->query(ILogFactory::class); |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - /** |
|
| 1548 | - * Returns a router for generating and matching urls |
|
| 1549 | - * |
|
| 1550 | - * @return \OCP\Route\IRouter |
|
| 1551 | - */ |
|
| 1552 | - public function getRouter() { |
|
| 1553 | - return $this->query('Router'); |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - /** |
|
| 1557 | - * Returns a search instance |
|
| 1558 | - * |
|
| 1559 | - * @return \OCP\ISearch |
|
| 1560 | - */ |
|
| 1561 | - public function getSearch() { |
|
| 1562 | - return $this->query('Search'); |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - /** |
|
| 1566 | - * Returns a SecureRandom instance |
|
| 1567 | - * |
|
| 1568 | - * @return \OCP\Security\ISecureRandom |
|
| 1569 | - */ |
|
| 1570 | - public function getSecureRandom() { |
|
| 1571 | - return $this->query('SecureRandom'); |
|
| 1572 | - } |
|
| 1573 | - |
|
| 1574 | - /** |
|
| 1575 | - * Returns a Crypto instance |
|
| 1576 | - * |
|
| 1577 | - * @return \OCP\Security\ICrypto |
|
| 1578 | - */ |
|
| 1579 | - public function getCrypto() { |
|
| 1580 | - return $this->query('Crypto'); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - /** |
|
| 1584 | - * Returns a Hasher instance |
|
| 1585 | - * |
|
| 1586 | - * @return \OCP\Security\IHasher |
|
| 1587 | - */ |
|
| 1588 | - public function getHasher() { |
|
| 1589 | - return $this->query('Hasher'); |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - /** |
|
| 1593 | - * Returns a CredentialsManager instance |
|
| 1594 | - * |
|
| 1595 | - * @return \OCP\Security\ICredentialsManager |
|
| 1596 | - */ |
|
| 1597 | - public function getCredentialsManager() { |
|
| 1598 | - return $this->query('CredentialsManager'); |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - /** |
|
| 1602 | - * Get the certificate manager for the user |
|
| 1603 | - * |
|
| 1604 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1605 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1606 | - */ |
|
| 1607 | - public function getCertificateManager($userId = '') { |
|
| 1608 | - if ($userId === '') { |
|
| 1609 | - $userSession = $this->getUserSession(); |
|
| 1610 | - $user = $userSession->getUser(); |
|
| 1611 | - if (is_null($user)) { |
|
| 1612 | - return null; |
|
| 1613 | - } |
|
| 1614 | - $userId = $user->getUID(); |
|
| 1615 | - } |
|
| 1616 | - return new CertificateManager( |
|
| 1617 | - $userId, |
|
| 1618 | - new View(), |
|
| 1619 | - $this->getConfig(), |
|
| 1620 | - $this->getLogger(), |
|
| 1621 | - $this->getSecureRandom() |
|
| 1622 | - ); |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - /** |
|
| 1626 | - * Returns an instance of the HTTP client service |
|
| 1627 | - * |
|
| 1628 | - * @return \OCP\Http\Client\IClientService |
|
| 1629 | - */ |
|
| 1630 | - public function getHTTPClientService() { |
|
| 1631 | - return $this->query('HttpClientService'); |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - /** |
|
| 1635 | - * Create a new event source |
|
| 1636 | - * |
|
| 1637 | - * @return \OCP\IEventSource |
|
| 1638 | - */ |
|
| 1639 | - public function createEventSource() { |
|
| 1640 | - return new \OC_EventSource(); |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - /** |
|
| 1644 | - * Get the active event logger |
|
| 1645 | - * |
|
| 1646 | - * The returned logger only logs data when debug mode is enabled |
|
| 1647 | - * |
|
| 1648 | - * @return \OCP\Diagnostics\IEventLogger |
|
| 1649 | - */ |
|
| 1650 | - public function getEventLogger() { |
|
| 1651 | - return $this->query('EventLogger'); |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - /** |
|
| 1655 | - * Get the active query logger |
|
| 1656 | - * |
|
| 1657 | - * The returned logger only logs data when debug mode is enabled |
|
| 1658 | - * |
|
| 1659 | - * @return \OCP\Diagnostics\IQueryLogger |
|
| 1660 | - */ |
|
| 1661 | - public function getQueryLogger() { |
|
| 1662 | - return $this->query('QueryLogger'); |
|
| 1663 | - } |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * Get the manager for temporary files and folders |
|
| 1667 | - * |
|
| 1668 | - * @return \OCP\ITempManager |
|
| 1669 | - */ |
|
| 1670 | - public function getTempManager() { |
|
| 1671 | - return $this->query('TempManager'); |
|
| 1672 | - } |
|
| 1673 | - |
|
| 1674 | - /** |
|
| 1675 | - * Get the app manager |
|
| 1676 | - * |
|
| 1677 | - * @return \OCP\App\IAppManager |
|
| 1678 | - */ |
|
| 1679 | - public function getAppManager() { |
|
| 1680 | - return $this->query('AppManager'); |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - /** |
|
| 1684 | - * Creates a new mailer |
|
| 1685 | - * |
|
| 1686 | - * @return \OCP\Mail\IMailer |
|
| 1687 | - */ |
|
| 1688 | - public function getMailer() { |
|
| 1689 | - return $this->query('Mailer'); |
|
| 1690 | - } |
|
| 1691 | - |
|
| 1692 | - /** |
|
| 1693 | - * Get the webroot |
|
| 1694 | - * |
|
| 1695 | - * @return string |
|
| 1696 | - */ |
|
| 1697 | - public function getWebRoot() { |
|
| 1698 | - return $this->webRoot; |
|
| 1699 | - } |
|
| 1700 | - |
|
| 1701 | - /** |
|
| 1702 | - * @return \OC\OCSClient |
|
| 1703 | - */ |
|
| 1704 | - public function getOcsClient() { |
|
| 1705 | - return $this->query('OcsClient'); |
|
| 1706 | - } |
|
| 1707 | - |
|
| 1708 | - /** |
|
| 1709 | - * @return \OCP\IDateTimeZone |
|
| 1710 | - */ |
|
| 1711 | - public function getDateTimeZone() { |
|
| 1712 | - return $this->query('DateTimeZone'); |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - /** |
|
| 1716 | - * @return \OCP\IDateTimeFormatter |
|
| 1717 | - */ |
|
| 1718 | - public function getDateTimeFormatter() { |
|
| 1719 | - return $this->query('DateTimeFormatter'); |
|
| 1720 | - } |
|
| 1721 | - |
|
| 1722 | - /** |
|
| 1723 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1724 | - */ |
|
| 1725 | - public function getMountProviderCollection() { |
|
| 1726 | - return $this->query('MountConfigManager'); |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - /** |
|
| 1730 | - * Get the IniWrapper |
|
| 1731 | - * |
|
| 1732 | - * @return IniGetWrapper |
|
| 1733 | - */ |
|
| 1734 | - public function getIniWrapper() { |
|
| 1735 | - return $this->query('IniWrapper'); |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - /** |
|
| 1739 | - * @return \OCP\Command\IBus |
|
| 1740 | - */ |
|
| 1741 | - public function getCommandBus() { |
|
| 1742 | - return $this->query('AsyncCommandBus'); |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - /** |
|
| 1746 | - * Get the trusted domain helper |
|
| 1747 | - * |
|
| 1748 | - * @return TrustedDomainHelper |
|
| 1749 | - */ |
|
| 1750 | - public function getTrustedDomainHelper() { |
|
| 1751 | - return $this->query('TrustedDomainHelper'); |
|
| 1752 | - } |
|
| 1753 | - |
|
| 1754 | - /** |
|
| 1755 | - * Get the locking provider |
|
| 1756 | - * |
|
| 1757 | - * @return \OCP\Lock\ILockingProvider |
|
| 1758 | - * @since 8.1.0 |
|
| 1759 | - */ |
|
| 1760 | - public function getLockingProvider() { |
|
| 1761 | - return $this->query('LockingProvider'); |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - /** |
|
| 1765 | - * @return \OCP\Files\Mount\IMountManager |
|
| 1766 | - **/ |
|
| 1767 | - function getMountManager() { |
|
| 1768 | - return $this->query('MountManager'); |
|
| 1769 | - } |
|
| 1770 | - |
|
| 1771 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1772 | - function getUserMountCache() { |
|
| 1773 | - return $this->query('UserMountCache'); |
|
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - /** |
|
| 1777 | - * Get the MimeTypeDetector |
|
| 1778 | - * |
|
| 1779 | - * @return \OCP\Files\IMimeTypeDetector |
|
| 1780 | - */ |
|
| 1781 | - public function getMimeTypeDetector() { |
|
| 1782 | - return $this->query('MimeTypeDetector'); |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - /** |
|
| 1786 | - * Get the MimeTypeLoader |
|
| 1787 | - * |
|
| 1788 | - * @return \OCP\Files\IMimeTypeLoader |
|
| 1789 | - */ |
|
| 1790 | - public function getMimeTypeLoader() { |
|
| 1791 | - return $this->query('MimeTypeLoader'); |
|
| 1792 | - } |
|
| 1793 | - |
|
| 1794 | - /** |
|
| 1795 | - * Get the manager of all the capabilities |
|
| 1796 | - * |
|
| 1797 | - * @return \OC\CapabilitiesManager |
|
| 1798 | - */ |
|
| 1799 | - public function getCapabilitiesManager() { |
|
| 1800 | - return $this->query('CapabilitiesManager'); |
|
| 1801 | - } |
|
| 1802 | - |
|
| 1803 | - /** |
|
| 1804 | - * Get the EventDispatcher |
|
| 1805 | - * |
|
| 1806 | - * @return EventDispatcherInterface |
|
| 1807 | - * @since 8.2.0 |
|
| 1808 | - */ |
|
| 1809 | - public function getEventDispatcher() { |
|
| 1810 | - return $this->query('EventDispatcher'); |
|
| 1811 | - } |
|
| 1812 | - |
|
| 1813 | - /** |
|
| 1814 | - * Get the Notification Manager |
|
| 1815 | - * |
|
| 1816 | - * @return \OCP\Notification\IManager |
|
| 1817 | - * @since 8.2.0 |
|
| 1818 | - */ |
|
| 1819 | - public function getNotificationManager() { |
|
| 1820 | - return $this->query('NotificationManager'); |
|
| 1821 | - } |
|
| 1822 | - |
|
| 1823 | - /** |
|
| 1824 | - * @return \OCP\Comments\ICommentsManager |
|
| 1825 | - */ |
|
| 1826 | - public function getCommentsManager() { |
|
| 1827 | - return $this->query('CommentsManager'); |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - /** |
|
| 1831 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1832 | - */ |
|
| 1833 | - public function getThemingDefaults() { |
|
| 1834 | - return $this->query('ThemingDefaults'); |
|
| 1835 | - } |
|
| 1836 | - |
|
| 1837 | - /** |
|
| 1838 | - * @return \OC\IntegrityCheck\Checker |
|
| 1839 | - */ |
|
| 1840 | - public function getIntegrityCodeChecker() { |
|
| 1841 | - return $this->query('IntegrityCodeChecker'); |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - /** |
|
| 1845 | - * @return \OC\Session\CryptoWrapper |
|
| 1846 | - */ |
|
| 1847 | - public function getSessionCryptoWrapper() { |
|
| 1848 | - return $this->query('CryptoWrapper'); |
|
| 1849 | - } |
|
| 1850 | - |
|
| 1851 | - /** |
|
| 1852 | - * @return CsrfTokenManager |
|
| 1853 | - */ |
|
| 1854 | - public function getCsrfTokenManager() { |
|
| 1855 | - return $this->query('CsrfTokenManager'); |
|
| 1856 | - } |
|
| 1857 | - |
|
| 1858 | - /** |
|
| 1859 | - * @return Throttler |
|
| 1860 | - */ |
|
| 1861 | - public function getBruteForceThrottler() { |
|
| 1862 | - return $this->query('Throttler'); |
|
| 1863 | - } |
|
| 1864 | - |
|
| 1865 | - /** |
|
| 1866 | - * @return IContentSecurityPolicyManager |
|
| 1867 | - */ |
|
| 1868 | - public function getContentSecurityPolicyManager() { |
|
| 1869 | - return $this->query('ContentSecurityPolicyManager'); |
|
| 1870 | - } |
|
| 1871 | - |
|
| 1872 | - /** |
|
| 1873 | - * @return ContentSecurityPolicyNonceManager |
|
| 1874 | - */ |
|
| 1875 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1876 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1877 | - } |
|
| 1878 | - |
|
| 1879 | - /** |
|
| 1880 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1881 | - * |
|
| 1882 | - * @return \OCA\Files_External\Service\BackendService |
|
| 1883 | - */ |
|
| 1884 | - public function getStoragesBackendService() { |
|
| 1885 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1886 | - } |
|
| 1887 | - |
|
| 1888 | - /** |
|
| 1889 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1890 | - * |
|
| 1891 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1892 | - */ |
|
| 1893 | - public function getGlobalStoragesService() { |
|
| 1894 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1895 | - } |
|
| 1896 | - |
|
| 1897 | - /** |
|
| 1898 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1899 | - * |
|
| 1900 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1901 | - */ |
|
| 1902 | - public function getUserGlobalStoragesService() { |
|
| 1903 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1904 | - } |
|
| 1905 | - |
|
| 1906 | - /** |
|
| 1907 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1908 | - * |
|
| 1909 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1910 | - */ |
|
| 1911 | - public function getUserStoragesService() { |
|
| 1912 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - /** |
|
| 1916 | - * @return \OCP\Share\IManager |
|
| 1917 | - */ |
|
| 1918 | - public function getShareManager() { |
|
| 1919 | - return $this->query('ShareManager'); |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 1924 | - */ |
|
| 1925 | - public function getCollaboratorSearch() { |
|
| 1926 | - return $this->query('CollaboratorSearch'); |
|
| 1927 | - } |
|
| 1928 | - |
|
| 1929 | - /** |
|
| 1930 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 1931 | - */ |
|
| 1932 | - public function getAutoCompleteManager(){ |
|
| 1933 | - return $this->query(IManager::class); |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - /** |
|
| 1937 | - * Returns the LDAP Provider |
|
| 1938 | - * |
|
| 1939 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 1940 | - */ |
|
| 1941 | - public function getLDAPProvider() { |
|
| 1942 | - return $this->query('LDAPProvider'); |
|
| 1943 | - } |
|
| 1944 | - |
|
| 1945 | - /** |
|
| 1946 | - * @return \OCP\Settings\IManager |
|
| 1947 | - */ |
|
| 1948 | - public function getSettingsManager() { |
|
| 1949 | - return $this->query('SettingsManager'); |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - /** |
|
| 1953 | - * @return \OCP\Files\IAppData |
|
| 1954 | - */ |
|
| 1955 | - public function getAppDataDir($app) { |
|
| 1956 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1957 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 1958 | - return $factory->get($app); |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - /** |
|
| 1962 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 1963 | - */ |
|
| 1964 | - public function getLockdownManager() { |
|
| 1965 | - return $this->query('LockdownManager'); |
|
| 1966 | - } |
|
| 1967 | - |
|
| 1968 | - /** |
|
| 1969 | - * @return \OCP\Federation\ICloudIdManager |
|
| 1970 | - */ |
|
| 1971 | - public function getCloudIdManager() { |
|
| 1972 | - return $this->query(ICloudIdManager::class); |
|
| 1973 | - } |
|
| 1974 | - |
|
| 1975 | - /** |
|
| 1976 | - * @return \OCP\Remote\Api\IApiFactory |
|
| 1977 | - */ |
|
| 1978 | - public function getRemoteApiFactory() { |
|
| 1979 | - return $this->query(IApiFactory::class); |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - /** |
|
| 1983 | - * @return \OCP\Remote\IInstanceFactory |
|
| 1984 | - */ |
|
| 1985 | - public function getRemoteInstanceFactory() { |
|
| 1986 | - return $this->query(IInstanceFactory::class); |
|
| 1987 | - } |
|
| 943 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 944 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 945 | + $classExists = true; |
|
| 946 | + } else { |
|
| 947 | + $classExists = false; |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 951 | + return new ThemingDefaults( |
|
| 952 | + $c->getConfig(), |
|
| 953 | + $c->getL10N('theming'), |
|
| 954 | + $c->getURLGenerator(), |
|
| 955 | + $c->getMemCacheFactory(), |
|
| 956 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
| 957 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator()), |
|
| 958 | + $c->getAppManager() |
|
| 959 | + ); |
|
| 960 | + } |
|
| 961 | + return new \OC_Defaults(); |
|
| 962 | + }); |
|
| 963 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 964 | + /** @var Factory $cacheFactory */ |
|
| 965 | + $cacheFactory = $c->query(Factory::class); |
|
| 966 | + return new SCSSCacher( |
|
| 967 | + $c->getLogger(), |
|
| 968 | + $c->query(\OC\Files\AppData\Factory::class), |
|
| 969 | + $c->getURLGenerator(), |
|
| 970 | + $c->getConfig(), |
|
| 971 | + $c->getThemingDefaults(), |
|
| 972 | + \OC::$SERVERROOT, |
|
| 973 | + $this->getMemCacheFactory() |
|
| 974 | + ); |
|
| 975 | + }); |
|
| 976 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 977 | + /** @var Factory $cacheFactory */ |
|
| 978 | + $cacheFactory = $c->query(Factory::class); |
|
| 979 | + return new JSCombiner( |
|
| 980 | + $c->getAppDataDir('js'), |
|
| 981 | + $c->getURLGenerator(), |
|
| 982 | + $this->getMemCacheFactory(), |
|
| 983 | + $c->getSystemConfig(), |
|
| 984 | + $c->getLogger() |
|
| 985 | + ); |
|
| 986 | + }); |
|
| 987 | + $this->registerService(EventDispatcher::class, function () { |
|
| 988 | + return new EventDispatcher(); |
|
| 989 | + }); |
|
| 990 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
| 991 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
| 992 | + |
|
| 993 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 994 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 995 | + $request = new Request( |
|
| 996 | + [ |
|
| 997 | + 'get' => $_GET, |
|
| 998 | + 'post' => $_POST, |
|
| 999 | + 'files' => $_FILES, |
|
| 1000 | + 'server' => $_SERVER, |
|
| 1001 | + 'env' => $_ENV, |
|
| 1002 | + 'cookies' => $_COOKIE, |
|
| 1003 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1004 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1005 | + : null, |
|
| 1006 | + ], |
|
| 1007 | + $c->getSecureRandom(), |
|
| 1008 | + $c->getConfig() |
|
| 1009 | + ); |
|
| 1010 | + |
|
| 1011 | + return new CryptoWrapper( |
|
| 1012 | + $c->getConfig(), |
|
| 1013 | + $c->getCrypto(), |
|
| 1014 | + $c->getSecureRandom(), |
|
| 1015 | + $request |
|
| 1016 | + ); |
|
| 1017 | + }); |
|
| 1018 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 1019 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 1020 | + |
|
| 1021 | + return new CsrfTokenManager( |
|
| 1022 | + $tokenGenerator, |
|
| 1023 | + $c->query(SessionStorage::class) |
|
| 1024 | + ); |
|
| 1025 | + }); |
|
| 1026 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1027 | + return new SessionStorage($c->getSession()); |
|
| 1028 | + }); |
|
| 1029 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 1030 | + return new ContentSecurityPolicyManager(); |
|
| 1031 | + }); |
|
| 1032 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 1033 | + |
|
| 1034 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 1035 | + return new ContentSecurityPolicyNonceManager( |
|
| 1036 | + $c->getCsrfTokenManager(), |
|
| 1037 | + $c->getRequest() |
|
| 1038 | + ); |
|
| 1039 | + }); |
|
| 1040 | + |
|
| 1041 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1042 | + $config = $c->getConfig(); |
|
| 1043 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1044 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1045 | + $factory = new $factoryClass($this); |
|
| 1046 | + |
|
| 1047 | + $manager = new \OC\Share20\Manager( |
|
| 1048 | + $c->getLogger(), |
|
| 1049 | + $c->getConfig(), |
|
| 1050 | + $c->getSecureRandom(), |
|
| 1051 | + $c->getHasher(), |
|
| 1052 | + $c->getMountManager(), |
|
| 1053 | + $c->getGroupManager(), |
|
| 1054 | + $c->getL10N('lib'), |
|
| 1055 | + $c->getL10NFactory(), |
|
| 1056 | + $factory, |
|
| 1057 | + $c->getUserManager(), |
|
| 1058 | + $c->getLazyRootFolder(), |
|
| 1059 | + $c->getEventDispatcher(), |
|
| 1060 | + $c->getMailer(), |
|
| 1061 | + $c->getURLGenerator(), |
|
| 1062 | + $c->getThemingDefaults() |
|
| 1063 | + ); |
|
| 1064 | + |
|
| 1065 | + return $manager; |
|
| 1066 | + }); |
|
| 1067 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1068 | + |
|
| 1069 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
| 1070 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1071 | + |
|
| 1072 | + // register default plugins |
|
| 1073 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1074 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1075 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1076 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1077 | + |
|
| 1078 | + return $instance; |
|
| 1079 | + }); |
|
| 1080 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1081 | + |
|
| 1082 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1083 | + |
|
| 1084 | + $this->registerService('SettingsManager', function (Server $c) { |
|
| 1085 | + $manager = new \OC\Settings\Manager( |
|
| 1086 | + $c->getLogger(), |
|
| 1087 | + $c->getDatabaseConnection(), |
|
| 1088 | + $c->getL10N('lib'), |
|
| 1089 | + $c->getConfig(), |
|
| 1090 | + $c->getEncryptionManager(), |
|
| 1091 | + $c->getUserManager(), |
|
| 1092 | + $c->getLockingProvider(), |
|
| 1093 | + $c->getRequest(), |
|
| 1094 | + $c->getURLGenerator(), |
|
| 1095 | + $c->query(AccountManager::class), |
|
| 1096 | + $c->getGroupManager(), |
|
| 1097 | + $c->getL10NFactory(), |
|
| 1098 | + $c->getAppManager() |
|
| 1099 | + ); |
|
| 1100 | + return $manager; |
|
| 1101 | + }); |
|
| 1102 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1103 | + return new \OC\Files\AppData\Factory( |
|
| 1104 | + $c->getRootFolder(), |
|
| 1105 | + $c->getSystemConfig() |
|
| 1106 | + ); |
|
| 1107 | + }); |
|
| 1108 | + |
|
| 1109 | + $this->registerService('LockdownManager', function (Server $c) { |
|
| 1110 | + return new LockdownManager(function () use ($c) { |
|
| 1111 | + return $c->getSession(); |
|
| 1112 | + }); |
|
| 1113 | + }); |
|
| 1114 | + |
|
| 1115 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1116 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1117 | + }); |
|
| 1118 | + |
|
| 1119 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1120 | + return new CloudIdManager(); |
|
| 1121 | + }); |
|
| 1122 | + |
|
| 1123 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1124 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1125 | + |
|
| 1126 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1127 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1128 | + |
|
| 1129 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1130 | + return new Defaults( |
|
| 1131 | + $c->getThemingDefaults() |
|
| 1132 | + ); |
|
| 1133 | + }); |
|
| 1134 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1135 | + |
|
| 1136 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1137 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1138 | + }); |
|
| 1139 | + |
|
| 1140 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1141 | + return new ShareHelper( |
|
| 1142 | + $c->query(\OCP\Share\IManager::class) |
|
| 1143 | + ); |
|
| 1144 | + }); |
|
| 1145 | + |
|
| 1146 | + $this->registerService(Installer::class, function(Server $c) { |
|
| 1147 | + return new Installer( |
|
| 1148 | + $c->getAppFetcher(), |
|
| 1149 | + $c->getHTTPClientService(), |
|
| 1150 | + $c->getTempManager(), |
|
| 1151 | + $c->getLogger(), |
|
| 1152 | + $c->getConfig() |
|
| 1153 | + ); |
|
| 1154 | + }); |
|
| 1155 | + |
|
| 1156 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
| 1157 | + return new ApiFactory($c->getHTTPClientService()); |
|
| 1158 | + }); |
|
| 1159 | + |
|
| 1160 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
| 1161 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1162 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
| 1163 | + }); |
|
| 1164 | + |
|
| 1165 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
| 1166 | + return new ContactsStore( |
|
| 1167 | + $c->getContactsManager(), |
|
| 1168 | + $c->getConfig(), |
|
| 1169 | + $c->getUserManager(), |
|
| 1170 | + $c->getGroupManager() |
|
| 1171 | + ); |
|
| 1172 | + }); |
|
| 1173 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1174 | + |
|
| 1175 | + $this->connectDispatcher(); |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + /** |
|
| 1179 | + * @return \OCP\Calendar\IManager |
|
| 1180 | + */ |
|
| 1181 | + public function getCalendarManager() { |
|
| 1182 | + return $this->query('CalendarManager'); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + private function connectDispatcher() { |
|
| 1186 | + $dispatcher = $this->getEventDispatcher(); |
|
| 1187 | + |
|
| 1188 | + // Delete avatar on user deletion |
|
| 1189 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
| 1190 | + $logger = $this->getLogger(); |
|
| 1191 | + $manager = $this->getAvatarManager(); |
|
| 1192 | + /** @var IUser $user */ |
|
| 1193 | + $user = $e->getSubject(); |
|
| 1194 | + |
|
| 1195 | + try { |
|
| 1196 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1197 | + $avatar->remove(); |
|
| 1198 | + } catch (NotFoundException $e) { |
|
| 1199 | + // no avatar to remove |
|
| 1200 | + } catch (\Exception $e) { |
|
| 1201 | + // Ignore exceptions |
|
| 1202 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1203 | + } |
|
| 1204 | + }); |
|
| 1205 | + |
|
| 1206 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1207 | + $manager = $this->getAvatarManager(); |
|
| 1208 | + /** @var IUser $user */ |
|
| 1209 | + $user = $e->getSubject(); |
|
| 1210 | + $feature = $e->getArgument('feature'); |
|
| 1211 | + $oldValue = $e->getArgument('oldValue'); |
|
| 1212 | + $value = $e->getArgument('value'); |
|
| 1213 | + |
|
| 1214 | + try { |
|
| 1215 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1216 | + $avatar->userChanged($feature, $oldValue, $value); |
|
| 1217 | + } catch (NotFoundException $e) { |
|
| 1218 | + // no avatar to remove |
|
| 1219 | + } |
|
| 1220 | + }); |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * @return \OCP\Contacts\IManager |
|
| 1225 | + */ |
|
| 1226 | + public function getContactsManager() { |
|
| 1227 | + return $this->query('ContactsManager'); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * @return \OC\Encryption\Manager |
|
| 1232 | + */ |
|
| 1233 | + public function getEncryptionManager() { |
|
| 1234 | + return $this->query('EncryptionManager'); |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * @return \OC\Encryption\File |
|
| 1239 | + */ |
|
| 1240 | + public function getEncryptionFilesHelper() { |
|
| 1241 | + return $this->query('EncryptionFileHelper'); |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + /** |
|
| 1245 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1246 | + */ |
|
| 1247 | + public function getEncryptionKeyStorage() { |
|
| 1248 | + return $this->query('EncryptionKeyStorage'); |
|
| 1249 | + } |
|
| 1250 | + |
|
| 1251 | + /** |
|
| 1252 | + * The current request object holding all information about the request |
|
| 1253 | + * currently being processed is returned from this method. |
|
| 1254 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1255 | + * |
|
| 1256 | + * @return \OCP\IRequest |
|
| 1257 | + */ |
|
| 1258 | + public function getRequest() { |
|
| 1259 | + return $this->query('Request'); |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + /** |
|
| 1263 | + * Returns the preview manager which can create preview images for a given file |
|
| 1264 | + * |
|
| 1265 | + * @return \OCP\IPreview |
|
| 1266 | + */ |
|
| 1267 | + public function getPreviewManager() { |
|
| 1268 | + return $this->query('PreviewManager'); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + /** |
|
| 1272 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1273 | + * |
|
| 1274 | + * @see \OCP\ITagManager::load() |
|
| 1275 | + * @return \OCP\ITagManager |
|
| 1276 | + */ |
|
| 1277 | + public function getTagManager() { |
|
| 1278 | + return $this->query('TagManager'); |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * Returns the system-tag manager |
|
| 1283 | + * |
|
| 1284 | + * @return \OCP\SystemTag\ISystemTagManager |
|
| 1285 | + * |
|
| 1286 | + * @since 9.0.0 |
|
| 1287 | + */ |
|
| 1288 | + public function getSystemTagManager() { |
|
| 1289 | + return $this->query('SystemTagManager'); |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + /** |
|
| 1293 | + * Returns the system-tag object mapper |
|
| 1294 | + * |
|
| 1295 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1296 | + * |
|
| 1297 | + * @since 9.0.0 |
|
| 1298 | + */ |
|
| 1299 | + public function getSystemTagObjectMapper() { |
|
| 1300 | + return $this->query('SystemTagObjectMapper'); |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + /** |
|
| 1304 | + * Returns the avatar manager, used for avatar functionality |
|
| 1305 | + * |
|
| 1306 | + * @return \OCP\IAvatarManager |
|
| 1307 | + */ |
|
| 1308 | + public function getAvatarManager() { |
|
| 1309 | + return $this->query('AvatarManager'); |
|
| 1310 | + } |
|
| 1311 | + |
|
| 1312 | + /** |
|
| 1313 | + * Returns the root folder of ownCloud's data directory |
|
| 1314 | + * |
|
| 1315 | + * @return \OCP\Files\IRootFolder |
|
| 1316 | + */ |
|
| 1317 | + public function getRootFolder() { |
|
| 1318 | + return $this->query('LazyRootFolder'); |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * Returns the root folder of ownCloud's data directory |
|
| 1323 | + * This is the lazy variant so this gets only initialized once it |
|
| 1324 | + * is actually used. |
|
| 1325 | + * |
|
| 1326 | + * @return \OCP\Files\IRootFolder |
|
| 1327 | + */ |
|
| 1328 | + public function getLazyRootFolder() { |
|
| 1329 | + return $this->query('LazyRootFolder'); |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * Returns a view to ownCloud's files folder |
|
| 1334 | + * |
|
| 1335 | + * @param string $userId user ID |
|
| 1336 | + * @return \OCP\Files\Folder|null |
|
| 1337 | + */ |
|
| 1338 | + public function getUserFolder($userId = null) { |
|
| 1339 | + if ($userId === null) { |
|
| 1340 | + $user = $this->getUserSession()->getUser(); |
|
| 1341 | + if (!$user) { |
|
| 1342 | + return null; |
|
| 1343 | + } |
|
| 1344 | + $userId = $user->getUID(); |
|
| 1345 | + } |
|
| 1346 | + $root = $this->getRootFolder(); |
|
| 1347 | + return $root->getUserFolder($userId); |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + /** |
|
| 1351 | + * Returns an app-specific view in ownClouds data directory |
|
| 1352 | + * |
|
| 1353 | + * @return \OCP\Files\Folder |
|
| 1354 | + * @deprecated since 9.2.0 use IAppData |
|
| 1355 | + */ |
|
| 1356 | + public function getAppFolder() { |
|
| 1357 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1358 | + $root = $this->getRootFolder(); |
|
| 1359 | + if (!$root->nodeExists($dir)) { |
|
| 1360 | + $folder = $root->newFolder($dir); |
|
| 1361 | + } else { |
|
| 1362 | + $folder = $root->get($dir); |
|
| 1363 | + } |
|
| 1364 | + return $folder; |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + /** |
|
| 1368 | + * @return \OC\User\Manager |
|
| 1369 | + */ |
|
| 1370 | + public function getUserManager() { |
|
| 1371 | + return $this->query('UserManager'); |
|
| 1372 | + } |
|
| 1373 | + |
|
| 1374 | + /** |
|
| 1375 | + * @return \OC\Group\Manager |
|
| 1376 | + */ |
|
| 1377 | + public function getGroupManager() { |
|
| 1378 | + return $this->query('GroupManager'); |
|
| 1379 | + } |
|
| 1380 | + |
|
| 1381 | + /** |
|
| 1382 | + * @return \OC\User\Session |
|
| 1383 | + */ |
|
| 1384 | + public function getUserSession() { |
|
| 1385 | + return $this->query('UserSession'); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + /** |
|
| 1389 | + * @return \OCP\ISession |
|
| 1390 | + */ |
|
| 1391 | + public function getSession() { |
|
| 1392 | + return $this->query('UserSession')->getSession(); |
|
| 1393 | + } |
|
| 1394 | + |
|
| 1395 | + /** |
|
| 1396 | + * @param \OCP\ISession $session |
|
| 1397 | + */ |
|
| 1398 | + public function setSession(\OCP\ISession $session) { |
|
| 1399 | + $this->query(SessionStorage::class)->setSession($session); |
|
| 1400 | + $this->query('UserSession')->setSession($session); |
|
| 1401 | + $this->query(Store::class)->setSession($session); |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + /** |
|
| 1405 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1406 | + */ |
|
| 1407 | + public function getTwoFactorAuthManager() { |
|
| 1408 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1409 | + } |
|
| 1410 | + |
|
| 1411 | + /** |
|
| 1412 | + * @return \OC\NavigationManager |
|
| 1413 | + */ |
|
| 1414 | + public function getNavigationManager() { |
|
| 1415 | + return $this->query('NavigationManager'); |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + /** |
|
| 1419 | + * @return \OCP\IConfig |
|
| 1420 | + */ |
|
| 1421 | + public function getConfig() { |
|
| 1422 | + return $this->query('AllConfig'); |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + /** |
|
| 1426 | + * @return \OC\SystemConfig |
|
| 1427 | + */ |
|
| 1428 | + public function getSystemConfig() { |
|
| 1429 | + return $this->query('SystemConfig'); |
|
| 1430 | + } |
|
| 1431 | + |
|
| 1432 | + /** |
|
| 1433 | + * Returns the app config manager |
|
| 1434 | + * |
|
| 1435 | + * @return \OCP\IAppConfig |
|
| 1436 | + */ |
|
| 1437 | + public function getAppConfig() { |
|
| 1438 | + return $this->query('AppConfig'); |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + /** |
|
| 1442 | + * @return \OCP\L10N\IFactory |
|
| 1443 | + */ |
|
| 1444 | + public function getL10NFactory() { |
|
| 1445 | + return $this->query('L10NFactory'); |
|
| 1446 | + } |
|
| 1447 | + |
|
| 1448 | + /** |
|
| 1449 | + * get an L10N instance |
|
| 1450 | + * |
|
| 1451 | + * @param string $app appid |
|
| 1452 | + * @param string $lang |
|
| 1453 | + * @return IL10N |
|
| 1454 | + */ |
|
| 1455 | + public function getL10N($app, $lang = null) { |
|
| 1456 | + return $this->getL10NFactory()->get($app, $lang); |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + /** |
|
| 1460 | + * @return \OCP\IURLGenerator |
|
| 1461 | + */ |
|
| 1462 | + public function getURLGenerator() { |
|
| 1463 | + return $this->query('URLGenerator'); |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * @return AppFetcher |
|
| 1468 | + */ |
|
| 1469 | + public function getAppFetcher() { |
|
| 1470 | + return $this->query(AppFetcher::class); |
|
| 1471 | + } |
|
| 1472 | + |
|
| 1473 | + /** |
|
| 1474 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1475 | + * getMemCacheFactory() instead. |
|
| 1476 | + * |
|
| 1477 | + * @return \OCP\ICache |
|
| 1478 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1479 | + */ |
|
| 1480 | + public function getCache() { |
|
| 1481 | + return $this->query('UserCache'); |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + /** |
|
| 1485 | + * Returns an \OCP\CacheFactory instance |
|
| 1486 | + * |
|
| 1487 | + * @return \OCP\ICacheFactory |
|
| 1488 | + */ |
|
| 1489 | + public function getMemCacheFactory() { |
|
| 1490 | + return $this->query('MemCacheFactory'); |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * Returns an \OC\RedisFactory instance |
|
| 1495 | + * |
|
| 1496 | + * @return \OC\RedisFactory |
|
| 1497 | + */ |
|
| 1498 | + public function getGetRedisFactory() { |
|
| 1499 | + return $this->query('RedisFactory'); |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * Returns the current session |
|
| 1505 | + * |
|
| 1506 | + * @return \OCP\IDBConnection |
|
| 1507 | + */ |
|
| 1508 | + public function getDatabaseConnection() { |
|
| 1509 | + return $this->query('DatabaseConnection'); |
|
| 1510 | + } |
|
| 1511 | + |
|
| 1512 | + /** |
|
| 1513 | + * Returns the activity manager |
|
| 1514 | + * |
|
| 1515 | + * @return \OCP\Activity\IManager |
|
| 1516 | + */ |
|
| 1517 | + public function getActivityManager() { |
|
| 1518 | + return $this->query('ActivityManager'); |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + /** |
|
| 1522 | + * Returns an job list for controlling background jobs |
|
| 1523 | + * |
|
| 1524 | + * @return \OCP\BackgroundJob\IJobList |
|
| 1525 | + */ |
|
| 1526 | + public function getJobList() { |
|
| 1527 | + return $this->query('JobList'); |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * Returns a logger instance |
|
| 1532 | + * |
|
| 1533 | + * @return \OCP\ILogger |
|
| 1534 | + */ |
|
| 1535 | + public function getLogger() { |
|
| 1536 | + return $this->query('Logger'); |
|
| 1537 | + } |
|
| 1538 | + |
|
| 1539 | + /** |
|
| 1540 | + * @return ILogFactory |
|
| 1541 | + * @throws \OCP\AppFramework\QueryException |
|
| 1542 | + */ |
|
| 1543 | + public function getLogFactory() { |
|
| 1544 | + return $this->query(ILogFactory::class); |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + /** |
|
| 1548 | + * Returns a router for generating and matching urls |
|
| 1549 | + * |
|
| 1550 | + * @return \OCP\Route\IRouter |
|
| 1551 | + */ |
|
| 1552 | + public function getRouter() { |
|
| 1553 | + return $this->query('Router'); |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + /** |
|
| 1557 | + * Returns a search instance |
|
| 1558 | + * |
|
| 1559 | + * @return \OCP\ISearch |
|
| 1560 | + */ |
|
| 1561 | + public function getSearch() { |
|
| 1562 | + return $this->query('Search'); |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + /** |
|
| 1566 | + * Returns a SecureRandom instance |
|
| 1567 | + * |
|
| 1568 | + * @return \OCP\Security\ISecureRandom |
|
| 1569 | + */ |
|
| 1570 | + public function getSecureRandom() { |
|
| 1571 | + return $this->query('SecureRandom'); |
|
| 1572 | + } |
|
| 1573 | + |
|
| 1574 | + /** |
|
| 1575 | + * Returns a Crypto instance |
|
| 1576 | + * |
|
| 1577 | + * @return \OCP\Security\ICrypto |
|
| 1578 | + */ |
|
| 1579 | + public function getCrypto() { |
|
| 1580 | + return $this->query('Crypto'); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + /** |
|
| 1584 | + * Returns a Hasher instance |
|
| 1585 | + * |
|
| 1586 | + * @return \OCP\Security\IHasher |
|
| 1587 | + */ |
|
| 1588 | + public function getHasher() { |
|
| 1589 | + return $this->query('Hasher'); |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + /** |
|
| 1593 | + * Returns a CredentialsManager instance |
|
| 1594 | + * |
|
| 1595 | + * @return \OCP\Security\ICredentialsManager |
|
| 1596 | + */ |
|
| 1597 | + public function getCredentialsManager() { |
|
| 1598 | + return $this->query('CredentialsManager'); |
|
| 1599 | + } |
|
| 1600 | + |
|
| 1601 | + /** |
|
| 1602 | + * Get the certificate manager for the user |
|
| 1603 | + * |
|
| 1604 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1605 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1606 | + */ |
|
| 1607 | + public function getCertificateManager($userId = '') { |
|
| 1608 | + if ($userId === '') { |
|
| 1609 | + $userSession = $this->getUserSession(); |
|
| 1610 | + $user = $userSession->getUser(); |
|
| 1611 | + if (is_null($user)) { |
|
| 1612 | + return null; |
|
| 1613 | + } |
|
| 1614 | + $userId = $user->getUID(); |
|
| 1615 | + } |
|
| 1616 | + return new CertificateManager( |
|
| 1617 | + $userId, |
|
| 1618 | + new View(), |
|
| 1619 | + $this->getConfig(), |
|
| 1620 | + $this->getLogger(), |
|
| 1621 | + $this->getSecureRandom() |
|
| 1622 | + ); |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + /** |
|
| 1626 | + * Returns an instance of the HTTP client service |
|
| 1627 | + * |
|
| 1628 | + * @return \OCP\Http\Client\IClientService |
|
| 1629 | + */ |
|
| 1630 | + public function getHTTPClientService() { |
|
| 1631 | + return $this->query('HttpClientService'); |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + /** |
|
| 1635 | + * Create a new event source |
|
| 1636 | + * |
|
| 1637 | + * @return \OCP\IEventSource |
|
| 1638 | + */ |
|
| 1639 | + public function createEventSource() { |
|
| 1640 | + return new \OC_EventSource(); |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + /** |
|
| 1644 | + * Get the active event logger |
|
| 1645 | + * |
|
| 1646 | + * The returned logger only logs data when debug mode is enabled |
|
| 1647 | + * |
|
| 1648 | + * @return \OCP\Diagnostics\IEventLogger |
|
| 1649 | + */ |
|
| 1650 | + public function getEventLogger() { |
|
| 1651 | + return $this->query('EventLogger'); |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + /** |
|
| 1655 | + * Get the active query logger |
|
| 1656 | + * |
|
| 1657 | + * The returned logger only logs data when debug mode is enabled |
|
| 1658 | + * |
|
| 1659 | + * @return \OCP\Diagnostics\IQueryLogger |
|
| 1660 | + */ |
|
| 1661 | + public function getQueryLogger() { |
|
| 1662 | + return $this->query('QueryLogger'); |
|
| 1663 | + } |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * Get the manager for temporary files and folders |
|
| 1667 | + * |
|
| 1668 | + * @return \OCP\ITempManager |
|
| 1669 | + */ |
|
| 1670 | + public function getTempManager() { |
|
| 1671 | + return $this->query('TempManager'); |
|
| 1672 | + } |
|
| 1673 | + |
|
| 1674 | + /** |
|
| 1675 | + * Get the app manager |
|
| 1676 | + * |
|
| 1677 | + * @return \OCP\App\IAppManager |
|
| 1678 | + */ |
|
| 1679 | + public function getAppManager() { |
|
| 1680 | + return $this->query('AppManager'); |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + /** |
|
| 1684 | + * Creates a new mailer |
|
| 1685 | + * |
|
| 1686 | + * @return \OCP\Mail\IMailer |
|
| 1687 | + */ |
|
| 1688 | + public function getMailer() { |
|
| 1689 | + return $this->query('Mailer'); |
|
| 1690 | + } |
|
| 1691 | + |
|
| 1692 | + /** |
|
| 1693 | + * Get the webroot |
|
| 1694 | + * |
|
| 1695 | + * @return string |
|
| 1696 | + */ |
|
| 1697 | + public function getWebRoot() { |
|
| 1698 | + return $this->webRoot; |
|
| 1699 | + } |
|
| 1700 | + |
|
| 1701 | + /** |
|
| 1702 | + * @return \OC\OCSClient |
|
| 1703 | + */ |
|
| 1704 | + public function getOcsClient() { |
|
| 1705 | + return $this->query('OcsClient'); |
|
| 1706 | + } |
|
| 1707 | + |
|
| 1708 | + /** |
|
| 1709 | + * @return \OCP\IDateTimeZone |
|
| 1710 | + */ |
|
| 1711 | + public function getDateTimeZone() { |
|
| 1712 | + return $this->query('DateTimeZone'); |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + /** |
|
| 1716 | + * @return \OCP\IDateTimeFormatter |
|
| 1717 | + */ |
|
| 1718 | + public function getDateTimeFormatter() { |
|
| 1719 | + return $this->query('DateTimeFormatter'); |
|
| 1720 | + } |
|
| 1721 | + |
|
| 1722 | + /** |
|
| 1723 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1724 | + */ |
|
| 1725 | + public function getMountProviderCollection() { |
|
| 1726 | + return $this->query('MountConfigManager'); |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + /** |
|
| 1730 | + * Get the IniWrapper |
|
| 1731 | + * |
|
| 1732 | + * @return IniGetWrapper |
|
| 1733 | + */ |
|
| 1734 | + public function getIniWrapper() { |
|
| 1735 | + return $this->query('IniWrapper'); |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + /** |
|
| 1739 | + * @return \OCP\Command\IBus |
|
| 1740 | + */ |
|
| 1741 | + public function getCommandBus() { |
|
| 1742 | + return $this->query('AsyncCommandBus'); |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + /** |
|
| 1746 | + * Get the trusted domain helper |
|
| 1747 | + * |
|
| 1748 | + * @return TrustedDomainHelper |
|
| 1749 | + */ |
|
| 1750 | + public function getTrustedDomainHelper() { |
|
| 1751 | + return $this->query('TrustedDomainHelper'); |
|
| 1752 | + } |
|
| 1753 | + |
|
| 1754 | + /** |
|
| 1755 | + * Get the locking provider |
|
| 1756 | + * |
|
| 1757 | + * @return \OCP\Lock\ILockingProvider |
|
| 1758 | + * @since 8.1.0 |
|
| 1759 | + */ |
|
| 1760 | + public function getLockingProvider() { |
|
| 1761 | + return $this->query('LockingProvider'); |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + /** |
|
| 1765 | + * @return \OCP\Files\Mount\IMountManager |
|
| 1766 | + **/ |
|
| 1767 | + function getMountManager() { |
|
| 1768 | + return $this->query('MountManager'); |
|
| 1769 | + } |
|
| 1770 | + |
|
| 1771 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1772 | + function getUserMountCache() { |
|
| 1773 | + return $this->query('UserMountCache'); |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + /** |
|
| 1777 | + * Get the MimeTypeDetector |
|
| 1778 | + * |
|
| 1779 | + * @return \OCP\Files\IMimeTypeDetector |
|
| 1780 | + */ |
|
| 1781 | + public function getMimeTypeDetector() { |
|
| 1782 | + return $this->query('MimeTypeDetector'); |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + /** |
|
| 1786 | + * Get the MimeTypeLoader |
|
| 1787 | + * |
|
| 1788 | + * @return \OCP\Files\IMimeTypeLoader |
|
| 1789 | + */ |
|
| 1790 | + public function getMimeTypeLoader() { |
|
| 1791 | + return $this->query('MimeTypeLoader'); |
|
| 1792 | + } |
|
| 1793 | + |
|
| 1794 | + /** |
|
| 1795 | + * Get the manager of all the capabilities |
|
| 1796 | + * |
|
| 1797 | + * @return \OC\CapabilitiesManager |
|
| 1798 | + */ |
|
| 1799 | + public function getCapabilitiesManager() { |
|
| 1800 | + return $this->query('CapabilitiesManager'); |
|
| 1801 | + } |
|
| 1802 | + |
|
| 1803 | + /** |
|
| 1804 | + * Get the EventDispatcher |
|
| 1805 | + * |
|
| 1806 | + * @return EventDispatcherInterface |
|
| 1807 | + * @since 8.2.0 |
|
| 1808 | + */ |
|
| 1809 | + public function getEventDispatcher() { |
|
| 1810 | + return $this->query('EventDispatcher'); |
|
| 1811 | + } |
|
| 1812 | + |
|
| 1813 | + /** |
|
| 1814 | + * Get the Notification Manager |
|
| 1815 | + * |
|
| 1816 | + * @return \OCP\Notification\IManager |
|
| 1817 | + * @since 8.2.0 |
|
| 1818 | + */ |
|
| 1819 | + public function getNotificationManager() { |
|
| 1820 | + return $this->query('NotificationManager'); |
|
| 1821 | + } |
|
| 1822 | + |
|
| 1823 | + /** |
|
| 1824 | + * @return \OCP\Comments\ICommentsManager |
|
| 1825 | + */ |
|
| 1826 | + public function getCommentsManager() { |
|
| 1827 | + return $this->query('CommentsManager'); |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + /** |
|
| 1831 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1832 | + */ |
|
| 1833 | + public function getThemingDefaults() { |
|
| 1834 | + return $this->query('ThemingDefaults'); |
|
| 1835 | + } |
|
| 1836 | + |
|
| 1837 | + /** |
|
| 1838 | + * @return \OC\IntegrityCheck\Checker |
|
| 1839 | + */ |
|
| 1840 | + public function getIntegrityCodeChecker() { |
|
| 1841 | + return $this->query('IntegrityCodeChecker'); |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + /** |
|
| 1845 | + * @return \OC\Session\CryptoWrapper |
|
| 1846 | + */ |
|
| 1847 | + public function getSessionCryptoWrapper() { |
|
| 1848 | + return $this->query('CryptoWrapper'); |
|
| 1849 | + } |
|
| 1850 | + |
|
| 1851 | + /** |
|
| 1852 | + * @return CsrfTokenManager |
|
| 1853 | + */ |
|
| 1854 | + public function getCsrfTokenManager() { |
|
| 1855 | + return $this->query('CsrfTokenManager'); |
|
| 1856 | + } |
|
| 1857 | + |
|
| 1858 | + /** |
|
| 1859 | + * @return Throttler |
|
| 1860 | + */ |
|
| 1861 | + public function getBruteForceThrottler() { |
|
| 1862 | + return $this->query('Throttler'); |
|
| 1863 | + } |
|
| 1864 | + |
|
| 1865 | + /** |
|
| 1866 | + * @return IContentSecurityPolicyManager |
|
| 1867 | + */ |
|
| 1868 | + public function getContentSecurityPolicyManager() { |
|
| 1869 | + return $this->query('ContentSecurityPolicyManager'); |
|
| 1870 | + } |
|
| 1871 | + |
|
| 1872 | + /** |
|
| 1873 | + * @return ContentSecurityPolicyNonceManager |
|
| 1874 | + */ |
|
| 1875 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1876 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1877 | + } |
|
| 1878 | + |
|
| 1879 | + /** |
|
| 1880 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1881 | + * |
|
| 1882 | + * @return \OCA\Files_External\Service\BackendService |
|
| 1883 | + */ |
|
| 1884 | + public function getStoragesBackendService() { |
|
| 1885 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1886 | + } |
|
| 1887 | + |
|
| 1888 | + /** |
|
| 1889 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1890 | + * |
|
| 1891 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1892 | + */ |
|
| 1893 | + public function getGlobalStoragesService() { |
|
| 1894 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1895 | + } |
|
| 1896 | + |
|
| 1897 | + /** |
|
| 1898 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1899 | + * |
|
| 1900 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1901 | + */ |
|
| 1902 | + public function getUserGlobalStoragesService() { |
|
| 1903 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1904 | + } |
|
| 1905 | + |
|
| 1906 | + /** |
|
| 1907 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1908 | + * |
|
| 1909 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1910 | + */ |
|
| 1911 | + public function getUserStoragesService() { |
|
| 1912 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + /** |
|
| 1916 | + * @return \OCP\Share\IManager |
|
| 1917 | + */ |
|
| 1918 | + public function getShareManager() { |
|
| 1919 | + return $this->query('ShareManager'); |
|
| 1920 | + } |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 1924 | + */ |
|
| 1925 | + public function getCollaboratorSearch() { |
|
| 1926 | + return $this->query('CollaboratorSearch'); |
|
| 1927 | + } |
|
| 1928 | + |
|
| 1929 | + /** |
|
| 1930 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 1931 | + */ |
|
| 1932 | + public function getAutoCompleteManager(){ |
|
| 1933 | + return $this->query(IManager::class); |
|
| 1934 | + } |
|
| 1935 | + |
|
| 1936 | + /** |
|
| 1937 | + * Returns the LDAP Provider |
|
| 1938 | + * |
|
| 1939 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 1940 | + */ |
|
| 1941 | + public function getLDAPProvider() { |
|
| 1942 | + return $this->query('LDAPProvider'); |
|
| 1943 | + } |
|
| 1944 | + |
|
| 1945 | + /** |
|
| 1946 | + * @return \OCP\Settings\IManager |
|
| 1947 | + */ |
|
| 1948 | + public function getSettingsManager() { |
|
| 1949 | + return $this->query('SettingsManager'); |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + /** |
|
| 1953 | + * @return \OCP\Files\IAppData |
|
| 1954 | + */ |
|
| 1955 | + public function getAppDataDir($app) { |
|
| 1956 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 1957 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 1958 | + return $factory->get($app); |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + /** |
|
| 1962 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 1963 | + */ |
|
| 1964 | + public function getLockdownManager() { |
|
| 1965 | + return $this->query('LockdownManager'); |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + /** |
|
| 1969 | + * @return \OCP\Federation\ICloudIdManager |
|
| 1970 | + */ |
|
| 1971 | + public function getCloudIdManager() { |
|
| 1972 | + return $this->query(ICloudIdManager::class); |
|
| 1973 | + } |
|
| 1974 | + |
|
| 1975 | + /** |
|
| 1976 | + * @return \OCP\Remote\Api\IApiFactory |
|
| 1977 | + */ |
|
| 1978 | + public function getRemoteApiFactory() { |
|
| 1979 | + return $this->query(IApiFactory::class); |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + /** |
|
| 1983 | + * @return \OCP\Remote\IInstanceFactory |
|
| 1984 | + */ |
|
| 1985 | + public function getRemoteInstanceFactory() { |
|
| 1986 | + return $this->query(IInstanceFactory::class); |
|
| 1987 | + } |
|
| 1988 | 1988 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | // To find out if we are running from CLI or not |
| 168 | 168 | $this->registerParameter('isCLI', \OC::$CLI); |
| 169 | 169 | |
| 170 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 170 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
| 171 | 171 | return $c; |
| 172 | 172 | }); |
| 173 | 173 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
| 181 | 181 | |
| 182 | 182 | |
| 183 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 183 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
| 184 | 184 | return new PreviewManager( |
| 185 | 185 | $c->getConfig(), |
| 186 | 186 | $c->getRootFolder(), |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | }); |
| 192 | 192 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
| 193 | 193 | |
| 194 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 194 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
| 195 | 195 | return new \OC\Preview\Watcher( |
| 196 | 196 | $c->getAppDataDir('preview') |
| 197 | 197 | ); |
| 198 | 198 | }); |
| 199 | 199 | |
| 200 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
| 200 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
| 201 | 201 | $view = new View(); |
| 202 | 202 | $util = new Encryption\Util( |
| 203 | 203 | $view, |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | ); |
| 216 | 216 | }); |
| 217 | 217 | |
| 218 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 218 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
| 219 | 219 | $util = new Encryption\Util( |
| 220 | 220 | new View(), |
| 221 | 221 | $c->getUserManager(), |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | ); |
| 230 | 230 | }); |
| 231 | 231 | |
| 232 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 232 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
| 233 | 233 | $view = new View(); |
| 234 | 234 | $util = new Encryption\Util( |
| 235 | 235 | $view, |
@@ -240,30 +240,30 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | return new Encryption\Keys\Storage($view, $util); |
| 242 | 242 | }); |
| 243 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 243 | + $this->registerService('TagMapper', function(Server $c) { |
|
| 244 | 244 | return new TagMapper($c->getDatabaseConnection()); |
| 245 | 245 | }); |
| 246 | 246 | |
| 247 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 247 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
| 248 | 248 | $tagMapper = $c->query('TagMapper'); |
| 249 | 249 | return new TagManager($tagMapper, $c->getUserSession()); |
| 250 | 250 | }); |
| 251 | 251 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
| 252 | 252 | |
| 253 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 253 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
| 254 | 254 | $config = $c->getConfig(); |
| 255 | 255 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
| 256 | 256 | return new $factoryClass($this); |
| 257 | 257 | }); |
| 258 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 258 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
| 259 | 259 | return $c->query('SystemTagManagerFactory')->getManager(); |
| 260 | 260 | }); |
| 261 | 261 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
| 262 | 262 | |
| 263 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 263 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
| 264 | 264 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
| 265 | 265 | }); |
| 266 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 266 | + $this->registerService('RootFolder', function(Server $c) { |
|
| 267 | 267 | $manager = \OC\Files\Filesystem::getMountManager(null); |
| 268 | 268 | $view = new View(); |
| 269 | 269 | $root = new Root( |
@@ -284,38 +284,38 @@ discard block |
||
| 284 | 284 | }); |
| 285 | 285 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
| 286 | 286 | |
| 287 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 288 | - return new LazyRoot(function () use ($c) { |
|
| 287 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
| 288 | + return new LazyRoot(function() use ($c) { |
|
| 289 | 289 | return $c->query('RootFolder'); |
| 290 | 290 | }); |
| 291 | 291 | }); |
| 292 | 292 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
| 293 | 293 | |
| 294 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
| 294 | + $this->registerService(\OC\User\Manager::class, function(Server $c) { |
|
| 295 | 295 | $config = $c->getConfig(); |
| 296 | 296 | return new \OC\User\Manager($config); |
| 297 | 297 | }); |
| 298 | 298 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
| 299 | 299 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
| 300 | 300 | |
| 301 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 301 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
| 302 | 302 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
| 303 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 303 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
| 304 | 304 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
| 305 | 305 | }); |
| 306 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 306 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
| 307 | 307 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
| 308 | 308 | }); |
| 309 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 309 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
| 310 | 310 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
| 311 | 311 | }); |
| 312 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 312 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
| 313 | 313 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
| 314 | 314 | }); |
| 315 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 315 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 316 | 316 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 317 | 317 | }); |
| 318 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 318 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 319 | 319 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 320 | 320 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
| 321 | 321 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | }); |
| 325 | 325 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
| 326 | 326 | |
| 327 | - $this->registerService(Store::class, function (Server $c) { |
|
| 327 | + $this->registerService(Store::class, function(Server $c) { |
|
| 328 | 328 | $session = $c->getSession(); |
| 329 | 329 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
| 330 | 330 | $tokenProvider = $c->query(IProvider::class); |
@@ -335,11 +335,11 @@ discard block |
||
| 335 | 335 | return new Store($session, $logger, $tokenProvider); |
| 336 | 336 | }); |
| 337 | 337 | $this->registerAlias(IStore::class, Store::class); |
| 338 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
| 338 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
| 339 | 339 | $dbConnection = $c->getDatabaseConnection(); |
| 340 | 340 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
| 341 | 341 | }); |
| 342 | - $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
|
| 342 | + $this->registerService(Authentication\Token\DefaultTokenProvider::class, function(Server $c) { |
|
| 343 | 343 | $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
| 344 | 344 | $crypto = $c->getCrypto(); |
| 345 | 345 | $config = $c->getConfig(); |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | }); |
| 350 | 350 | $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
| 351 | 351 | |
| 352 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
| 352 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
| 353 | 353 | $manager = $c->getUserManager(); |
| 354 | 354 | $session = new \OC\Session\Memory(''); |
| 355 | 355 | $timeFactory = new TimeFactory(); |
@@ -373,45 +373,45 @@ discard block |
||
| 373 | 373 | $c->getLockdownManager(), |
| 374 | 374 | $c->getLogger() |
| 375 | 375 | ); |
| 376 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 376 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 377 | 377 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 378 | 378 | }); |
| 379 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 379 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 380 | 380 | /** @var $user \OC\User\User */ |
| 381 | 381 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
| 382 | 382 | }); |
| 383 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
| 383 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
| 384 | 384 | /** @var $user \OC\User\User */ |
| 385 | 385 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
| 386 | 386 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
| 387 | 387 | }); |
| 388 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 388 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 389 | 389 | /** @var $user \OC\User\User */ |
| 390 | 390 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
| 391 | 391 | }); |
| 392 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 392 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 393 | 393 | /** @var $user \OC\User\User */ |
| 394 | 394 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 395 | 395 | }); |
| 396 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 396 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 397 | 397 | /** @var $user \OC\User\User */ |
| 398 | 398 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 399 | 399 | }); |
| 400 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 400 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 401 | 401 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 402 | 402 | }); |
| 403 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 403 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
| 404 | 404 | /** @var $user \OC\User\User */ |
| 405 | 405 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
| 406 | 406 | }); |
| 407 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 407 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
| 408 | 408 | /** @var $user \OC\User\User */ |
| 409 | 409 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
| 410 | 410 | }); |
| 411 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 411 | + $userSession->listen('\OC\User', 'logout', function() { |
|
| 412 | 412 | \OC_Hook::emit('OC_User', 'logout', array()); |
| 413 | 413 | }); |
| 414 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
| 414 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) use ($dispatcher) { |
|
| 415 | 415 | /** @var $user \OC\User\User */ |
| 416 | 416 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
| 417 | 417 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | }); |
| 421 | 421 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
| 422 | 422 | |
| 423 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
| 423 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
| 424 | 424 | return new \OC\Authentication\TwoFactorAuth\Manager( |
| 425 | 425 | $c->getAppManager(), |
| 426 | 426 | $c->getSession(), |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
| 437 | 437 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
| 438 | 438 | |
| 439 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 439 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
| 440 | 440 | return new \OC\AllConfig( |
| 441 | 441 | $c->getSystemConfig() |
| 442 | 442 | ); |
@@ -444,17 +444,17 @@ discard block |
||
| 444 | 444 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
| 445 | 445 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 446 | 446 | |
| 447 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 447 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
| 448 | 448 | return new \OC\SystemConfig($config); |
| 449 | 449 | }); |
| 450 | 450 | |
| 451 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 451 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
| 452 | 452 | return new \OC\AppConfig($c->getDatabaseConnection()); |
| 453 | 453 | }); |
| 454 | 454 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
| 455 | 455 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
| 456 | 456 | |
| 457 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 457 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
| 458 | 458 | return new \OC\L10N\Factory( |
| 459 | 459 | $c->getConfig(), |
| 460 | 460 | $c->getRequest(), |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | }); |
| 465 | 465 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
| 466 | 466 | |
| 467 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 467 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
| 468 | 468 | $config = $c->getConfig(); |
| 469 | 469 | $cacheFactory = $c->getMemCacheFactory(); |
| 470 | 470 | $request = $c->getRequest(); |
@@ -479,12 +479,12 @@ discard block |
||
| 479 | 479 | $this->registerAlias('AppFetcher', AppFetcher::class); |
| 480 | 480 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
| 481 | 481 | |
| 482 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 482 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
| 483 | 483 | return new Cache\File(); |
| 484 | 484 | }); |
| 485 | 485 | $this->registerAlias('UserCache', \OCP\ICache::class); |
| 486 | 486 | |
| 487 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 487 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 488 | 488 | |
| 489 | 489 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
| 490 | 490 | ArrayCache::class, |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | $version = implode(',', $v); |
| 502 | 502 | $instanceId = \OC_Util::getInstanceId(); |
| 503 | 503 | $path = \OC::$SERVERROOT; |
| 504 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 504 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
| 505 | 505 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
| 506 | 506 | $config->getSystemValue('memcache.local', null), |
| 507 | 507 | $config->getSystemValue('memcache.distributed', null), |
@@ -514,12 +514,12 @@ discard block |
||
| 514 | 514 | $this->registerAlias('MemCacheFactory', Factory::class); |
| 515 | 515 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 516 | 516 | |
| 517 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 517 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 518 | 518 | $systemConfig = $c->getSystemConfig(); |
| 519 | 519 | return new RedisFactory($systemConfig); |
| 520 | 520 | }); |
| 521 | 521 | |
| 522 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 522 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 523 | 523 | return new \OC\Activity\Manager( |
| 524 | 524 | $c->getRequest(), |
| 525 | 525 | $c->getUserSession(), |
@@ -529,14 +529,14 @@ discard block |
||
| 529 | 529 | }); |
| 530 | 530 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
| 531 | 531 | |
| 532 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 532 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 533 | 533 | return new \OC\Activity\EventMerger( |
| 534 | 534 | $c->getL10N('lib') |
| 535 | 535 | ); |
| 536 | 536 | }); |
| 537 | 537 | $this->registerAlias(IValidator::class, Validator::class); |
| 538 | 538 | |
| 539 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
| 539 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
| 540 | 540 | return new AvatarManager( |
| 541 | 541 | $c->query(\OC\User\Manager::class), |
| 542 | 542 | $c->getAppDataDir('avatar'), |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | |
| 550 | 550 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
| 551 | 551 | |
| 552 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
| 552 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
| 553 | 553 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
| 554 | 554 | $factory = new LogFactory($c, $this->getSystemConfig()); |
| 555 | 555 | $logger = $factory->get($logType); |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | }); |
| 560 | 560 | $this->registerAlias('Logger', \OCP\ILogger::class); |
| 561 | 561 | |
| 562 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 562 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
| 563 | 563 | return new LogFactory($c, $this->getSystemConfig()); |
| 564 | 564 | }); |
| 565 | 565 | |
| 566 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 566 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
| 567 | 567 | $config = $c->getConfig(); |
| 568 | 568 | return new \OC\BackgroundJob\JobList( |
| 569 | 569 | $c->getDatabaseConnection(), |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | }); |
| 574 | 574 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
| 575 | 575 | |
| 576 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 576 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
| 577 | 577 | $cacheFactory = $c->getMemCacheFactory(); |
| 578 | 578 | $logger = $c->getLogger(); |
| 579 | 579 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -585,12 +585,12 @@ discard block |
||
| 585 | 585 | }); |
| 586 | 586 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
| 587 | 587 | |
| 588 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 588 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
| 589 | 589 | return new Search(); |
| 590 | 590 | }); |
| 591 | 591 | $this->registerAlias('Search', \OCP\ISearch::class); |
| 592 | 592 | |
| 593 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
| 593 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function(Server $c) { |
|
| 594 | 594 | return new \OC\Security\RateLimiting\Limiter( |
| 595 | 595 | $this->getUserSession(), |
| 596 | 596 | $this->getRequest(), |
@@ -598,34 +598,34 @@ discard block |
||
| 598 | 598 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
| 599 | 599 | ); |
| 600 | 600 | }); |
| 601 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 601 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 602 | 602 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
| 603 | 603 | $this->getMemCacheFactory(), |
| 604 | 604 | new \OC\AppFramework\Utility\TimeFactory() |
| 605 | 605 | ); |
| 606 | 606 | }); |
| 607 | 607 | |
| 608 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 608 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
| 609 | 609 | return new SecureRandom(); |
| 610 | 610 | }); |
| 611 | 611 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
| 612 | 612 | |
| 613 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 613 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
| 614 | 614 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
| 615 | 615 | }); |
| 616 | 616 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
| 617 | 617 | |
| 618 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 618 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
| 619 | 619 | return new Hasher($c->getConfig()); |
| 620 | 620 | }); |
| 621 | 621 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
| 622 | 622 | |
| 623 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 623 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
| 624 | 624 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
| 625 | 625 | }); |
| 626 | 626 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
| 627 | 627 | |
| 628 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 628 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
| 629 | 629 | $systemConfig = $c->getSystemConfig(); |
| 630 | 630 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
| 631 | 631 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -640,7 +640,7 @@ discard block |
||
| 640 | 640 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
| 641 | 641 | |
| 642 | 642 | |
| 643 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 643 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
| 644 | 644 | $user = \OC_User::getUser(); |
| 645 | 645 | $uid = $user ? $user : null; |
| 646 | 646 | return new ClientService( |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | ); |
| 656 | 656 | }); |
| 657 | 657 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
| 658 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 658 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
| 659 | 659 | $eventLogger = new EventLogger(); |
| 660 | 660 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 661 | 661 | // In debug mode, module is being activated by default |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | }); |
| 666 | 666 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
| 667 | 667 | |
| 668 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 668 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
| 669 | 669 | $queryLogger = new QueryLogger(); |
| 670 | 670 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 671 | 671 | // In debug mode, module is being activated by default |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | }); |
| 676 | 676 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
| 677 | 677 | |
| 678 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 678 | + $this->registerService(TempManager::class, function(Server $c) { |
|
| 679 | 679 | return new TempManager( |
| 680 | 680 | $c->getLogger(), |
| 681 | 681 | $c->getConfig() |
@@ -684,7 +684,7 @@ discard block |
||
| 684 | 684 | $this->registerAlias('TempManager', TempManager::class); |
| 685 | 685 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 686 | 686 | |
| 687 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 687 | + $this->registerService(AppManager::class, function(Server $c) { |
|
| 688 | 688 | return new \OC\App\AppManager( |
| 689 | 689 | $c->getUserSession(), |
| 690 | 690 | $c->query(\OC\AppConfig::class), |
@@ -696,7 +696,7 @@ discard block |
||
| 696 | 696 | $this->registerAlias('AppManager', AppManager::class); |
| 697 | 697 | $this->registerAlias(IAppManager::class, AppManager::class); |
| 698 | 698 | |
| 699 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 699 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
| 700 | 700 | return new DateTimeZone( |
| 701 | 701 | $c->getConfig(), |
| 702 | 702 | $c->getSession() |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | }); |
| 705 | 705 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
| 706 | 706 | |
| 707 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 707 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
| 708 | 708 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
| 709 | 709 | |
| 710 | 710 | return new DateTimeFormatter( |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | }); |
| 715 | 715 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
| 716 | 716 | |
| 717 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 717 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
| 718 | 718 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
| 719 | 719 | $listener = new UserMountCacheListener($mountCache); |
| 720 | 720 | $listener->listen($c->getUserManager()); |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | }); |
| 723 | 723 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
| 724 | 724 | |
| 725 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 725 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
| 726 | 726 | $loader = \OC\Files\Filesystem::getLoader(); |
| 727 | 727 | $mountCache = $c->query('UserMountCache'); |
| 728 | 728 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -738,10 +738,10 @@ discard block |
||
| 738 | 738 | }); |
| 739 | 739 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
| 740 | 740 | |
| 741 | - $this->registerService('IniWrapper', function ($c) { |
|
| 741 | + $this->registerService('IniWrapper', function($c) { |
|
| 742 | 742 | return new IniGetWrapper(); |
| 743 | 743 | }); |
| 744 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 744 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
| 745 | 745 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
| 746 | 746 | if ($busClass) { |
| 747 | 747 | list($app, $class) = explode('::', $busClass, 2); |
@@ -756,10 +756,10 @@ discard block |
||
| 756 | 756 | return new CronBus($jobList); |
| 757 | 757 | } |
| 758 | 758 | }); |
| 759 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 759 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
| 760 | 760 | return new TrustedDomainHelper($this->getConfig()); |
| 761 | 761 | }); |
| 762 | - $this->registerService('Throttler', function (Server $c) { |
|
| 762 | + $this->registerService('Throttler', function(Server $c) { |
|
| 763 | 763 | return new Throttler( |
| 764 | 764 | $c->getDatabaseConnection(), |
| 765 | 765 | new TimeFactory(), |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | $c->getConfig() |
| 768 | 768 | ); |
| 769 | 769 | }); |
| 770 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 770 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
| 771 | 771 | // IConfig and IAppManager requires a working database. This code |
| 772 | 772 | // might however be called when ownCloud is not yet setup. |
| 773 | 773 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | $c->getTempManager() |
| 789 | 789 | ); |
| 790 | 790 | }); |
| 791 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 791 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
| 792 | 792 | if (isset($this['urlParams'])) { |
| 793 | 793 | $urlParams = $this['urlParams']; |
| 794 | 794 | } else { |
@@ -824,7 +824,7 @@ discard block |
||
| 824 | 824 | }); |
| 825 | 825 | $this->registerAlias('Request', \OCP\IRequest::class); |
| 826 | 826 | |
| 827 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 827 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
| 828 | 828 | return new Mailer( |
| 829 | 829 | $c->getConfig(), |
| 830 | 830 | $c->getLogger(), |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | }); |
| 836 | 836 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
| 837 | 837 | |
| 838 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 838 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
| 839 | 839 | $config = $c->getConfig(); |
| 840 | 840 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 841 | 841 | if (is_null($factoryClass)) { |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | $factory = new $factoryClass($this); |
| 846 | 846 | return $factory->getLDAPProvider(); |
| 847 | 847 | }); |
| 848 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 848 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
| 849 | 849 | $ini = $c->getIniWrapper(); |
| 850 | 850 | $config = $c->getConfig(); |
| 851 | 851 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -868,49 +868,49 @@ discard block |
||
| 868 | 868 | }); |
| 869 | 869 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
| 870 | 870 | |
| 871 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 871 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
| 872 | 872 | return new \OC\Files\Mount\Manager(); |
| 873 | 873 | }); |
| 874 | 874 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
| 875 | 875 | |
| 876 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 876 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
| 877 | 877 | return new \OC\Files\Type\Detection( |
| 878 | 878 | $c->getURLGenerator(), |
| 879 | 879 | \OC::$configDir, |
| 880 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 880 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 881 | 881 | ); |
| 882 | 882 | }); |
| 883 | 883 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
| 884 | 884 | |
| 885 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 885 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
| 886 | 886 | return new \OC\Files\Type\Loader( |
| 887 | 887 | $c->getDatabaseConnection() |
| 888 | 888 | ); |
| 889 | 889 | }); |
| 890 | 890 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
| 891 | - $this->registerService(BundleFetcher::class, function () { |
|
| 891 | + $this->registerService(BundleFetcher::class, function() { |
|
| 892 | 892 | return new BundleFetcher($this->getL10N('lib')); |
| 893 | 893 | }); |
| 894 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 894 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
| 895 | 895 | return new Manager( |
| 896 | 896 | $c->query(IValidator::class) |
| 897 | 897 | ); |
| 898 | 898 | }); |
| 899 | 899 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
| 900 | 900 | |
| 901 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 901 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
| 902 | 902 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
| 903 | - $manager->registerCapability(function () use ($c) { |
|
| 903 | + $manager->registerCapability(function() use ($c) { |
|
| 904 | 904 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
| 905 | 905 | }); |
| 906 | - $manager->registerCapability(function () use ($c) { |
|
| 906 | + $manager->registerCapability(function() use ($c) { |
|
| 907 | 907 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
| 908 | 908 | }); |
| 909 | 909 | return $manager; |
| 910 | 910 | }); |
| 911 | 911 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
| 912 | 912 | |
| 913 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 913 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
| 914 | 914 | $config = $c->getConfig(); |
| 915 | 915 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
| 916 | 916 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
| 921 | 921 | $manager = $c->getUserManager(); |
| 922 | 922 | $user = $manager->get($id); |
| 923 | - if(is_null($user)) { |
|
| 923 | + if (is_null($user)) { |
|
| 924 | 924 | $l = $c->getL10N('core'); |
| 925 | 925 | $displayName = $l->t('Unknown user'); |
| 926 | 926 | } else { |
@@ -933,7 +933,7 @@ discard block |
||
| 933 | 933 | }); |
| 934 | 934 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
| 935 | 935 | |
| 936 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 936 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 937 | 937 | /* |
| 938 | 938 | * Dark magic for autoloader. |
| 939 | 939 | * If we do a class_exists it will try to load the class which will |
@@ -960,7 +960,7 @@ discard block |
||
| 960 | 960 | } |
| 961 | 961 | return new \OC_Defaults(); |
| 962 | 962 | }); |
| 963 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 963 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
| 964 | 964 | /** @var Factory $cacheFactory */ |
| 965 | 965 | $cacheFactory = $c->query(Factory::class); |
| 966 | 966 | return new SCSSCacher( |
@@ -973,7 +973,7 @@ discard block |
||
| 973 | 973 | $this->getMemCacheFactory() |
| 974 | 974 | ); |
| 975 | 975 | }); |
| 976 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 976 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
| 977 | 977 | /** @var Factory $cacheFactory */ |
| 978 | 978 | $cacheFactory = $c->query(Factory::class); |
| 979 | 979 | return new JSCombiner( |
@@ -984,13 +984,13 @@ discard block |
||
| 984 | 984 | $c->getLogger() |
| 985 | 985 | ); |
| 986 | 986 | }); |
| 987 | - $this->registerService(EventDispatcher::class, function () { |
|
| 987 | + $this->registerService(EventDispatcher::class, function() { |
|
| 988 | 988 | return new EventDispatcher(); |
| 989 | 989 | }); |
| 990 | 990 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
| 991 | 991 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
| 992 | 992 | |
| 993 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 993 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
| 994 | 994 | // FIXME: Instantiiated here due to cyclic dependency |
| 995 | 995 | $request = new Request( |
| 996 | 996 | [ |
@@ -1015,7 +1015,7 @@ discard block |
||
| 1015 | 1015 | $request |
| 1016 | 1016 | ); |
| 1017 | 1017 | }); |
| 1018 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 1018 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
| 1019 | 1019 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
| 1020 | 1020 | |
| 1021 | 1021 | return new CsrfTokenManager( |
@@ -1023,22 +1023,22 @@ discard block |
||
| 1023 | 1023 | $c->query(SessionStorage::class) |
| 1024 | 1024 | ); |
| 1025 | 1025 | }); |
| 1026 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1026 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
| 1027 | 1027 | return new SessionStorage($c->getSession()); |
| 1028 | 1028 | }); |
| 1029 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 1029 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
| 1030 | 1030 | return new ContentSecurityPolicyManager(); |
| 1031 | 1031 | }); |
| 1032 | 1032 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
| 1033 | 1033 | |
| 1034 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 1034 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
| 1035 | 1035 | return new ContentSecurityPolicyNonceManager( |
| 1036 | 1036 | $c->getCsrfTokenManager(), |
| 1037 | 1037 | $c->getRequest() |
| 1038 | 1038 | ); |
| 1039 | 1039 | }); |
| 1040 | 1040 | |
| 1041 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1041 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
| 1042 | 1042 | $config = $c->getConfig(); |
| 1043 | 1043 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
| 1044 | 1044 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1081,7 +1081,7 @@ discard block |
||
| 1081 | 1081 | |
| 1082 | 1082 | $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
| 1083 | 1083 | |
| 1084 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 1084 | + $this->registerService('SettingsManager', function(Server $c) { |
|
| 1085 | 1085 | $manager = new \OC\Settings\Manager( |
| 1086 | 1086 | $c->getLogger(), |
| 1087 | 1087 | $c->getDatabaseConnection(), |
@@ -1099,24 +1099,24 @@ discard block |
||
| 1099 | 1099 | ); |
| 1100 | 1100 | return $manager; |
| 1101 | 1101 | }); |
| 1102 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1102 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
| 1103 | 1103 | return new \OC\Files\AppData\Factory( |
| 1104 | 1104 | $c->getRootFolder(), |
| 1105 | 1105 | $c->getSystemConfig() |
| 1106 | 1106 | ); |
| 1107 | 1107 | }); |
| 1108 | 1108 | |
| 1109 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1110 | - return new LockdownManager(function () use ($c) { |
|
| 1109 | + $this->registerService('LockdownManager', function(Server $c) { |
|
| 1110 | + return new LockdownManager(function() use ($c) { |
|
| 1111 | 1111 | return $c->getSession(); |
| 1112 | 1112 | }); |
| 1113 | 1113 | }); |
| 1114 | 1114 | |
| 1115 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1115 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
| 1116 | 1116 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
| 1117 | 1117 | }); |
| 1118 | 1118 | |
| 1119 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1119 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
| 1120 | 1120 | return new CloudIdManager(); |
| 1121 | 1121 | }); |
| 1122 | 1122 | |
@@ -1126,18 +1126,18 @@ discard block |
||
| 1126 | 1126 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
| 1127 | 1127 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1128 | 1128 | |
| 1129 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1129 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1130 | 1130 | return new Defaults( |
| 1131 | 1131 | $c->getThemingDefaults() |
| 1132 | 1132 | ); |
| 1133 | 1133 | }); |
| 1134 | 1134 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
| 1135 | 1135 | |
| 1136 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1136 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
| 1137 | 1137 | return $c->query(\OCP\IUserSession::class)->getSession(); |
| 1138 | 1138 | }); |
| 1139 | 1139 | |
| 1140 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1140 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
| 1141 | 1141 | return new ShareHelper( |
| 1142 | 1142 | $c->query(\OCP\Share\IManager::class) |
| 1143 | 1143 | ); |
@@ -1199,11 +1199,11 @@ discard block |
||
| 1199 | 1199 | // no avatar to remove |
| 1200 | 1200 | } catch (\Exception $e) { |
| 1201 | 1201 | // Ignore exceptions |
| 1202 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1202 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | }); |
| 1205 | 1205 | |
| 1206 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1206 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
| 1207 | 1207 | $manager = $this->getAvatarManager(); |
| 1208 | 1208 | /** @var IUser $user */ |
| 1209 | 1209 | $user = $e->getSubject(); |
@@ -1354,7 +1354,7 @@ discard block |
||
| 1354 | 1354 | * @deprecated since 9.2.0 use IAppData |
| 1355 | 1355 | */ |
| 1356 | 1356 | public function getAppFolder() { |
| 1357 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1357 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
| 1358 | 1358 | $root = $this->getRootFolder(); |
| 1359 | 1359 | if (!$root->nodeExists($dir)) { |
| 1360 | 1360 | $folder = $root->newFolder($dir); |
@@ -1929,7 +1929,7 @@ discard block |
||
| 1929 | 1929 | /** |
| 1930 | 1930 | * @return \OCP\Collaboration\AutoComplete\IManager |
| 1931 | 1931 | */ |
| 1932 | - public function getAutoCompleteManager(){ |
|
| 1932 | + public function getAutoCompleteManager() { |
|
| 1933 | 1933 | return $this->query(IManager::class); |
| 1934 | 1934 | } |
| 1935 | 1935 | |
@@ -134,7 +134,7 @@ |
||
| 134 | 134 | * @param RequestInterface $request |
| 135 | 135 | * @param ResponseInterface $response |
| 136 | 136 | * |
| 137 | - * @return void|bool |
|
| 137 | + * @return null|false |
|
| 138 | 138 | */ |
| 139 | 139 | public function httpPost(RequestInterface $request, ResponseInterface $response) { |
| 140 | 140 | $path = $request->getPath(); |
@@ -34,194 +34,194 @@ |
||
| 34 | 34 | use OCP\IConfig; |
| 35 | 35 | |
| 36 | 36 | class PublishPlugin extends ServerPlugin { |
| 37 | - const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Reference to SabreDAV server object. |
|
| 41 | - * |
|
| 42 | - * @var \Sabre\DAV\Server |
|
| 43 | - */ |
|
| 44 | - protected $server; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Config instance to get instance secret. |
|
| 48 | - * |
|
| 49 | - * @var IConfig |
|
| 50 | - */ |
|
| 51 | - protected $config; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * URL Generator for absolute URLs. |
|
| 55 | - * |
|
| 56 | - * @var IURLGenerator |
|
| 57 | - */ |
|
| 58 | - protected $urlGenerator; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * PublishPlugin constructor. |
|
| 62 | - * |
|
| 63 | - * @param IConfig $config |
|
| 64 | - * @param IURLGenerator $urlGenerator |
|
| 65 | - */ |
|
| 66 | - public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
| 67 | - $this->config = $config; |
|
| 68 | - $this->urlGenerator = $urlGenerator; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * This method should return a list of server-features. |
|
| 73 | - * |
|
| 74 | - * This is for example 'versioning' and is added to the DAV: header |
|
| 75 | - * in an OPTIONS response. |
|
| 76 | - * |
|
| 77 | - * @return string[] |
|
| 78 | - */ |
|
| 79 | - public function getFeatures() { |
|
| 80 | - // May have to be changed to be detected |
|
| 81 | - return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Returns a plugin name. |
|
| 86 | - * |
|
| 87 | - * Using this name other plugins will be able to access other plugins |
|
| 88 | - * using Sabre\DAV\Server::getPlugin |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function getPluginName() { |
|
| 93 | - return 'oc-calendar-publishing'; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * This initializes the plugin. |
|
| 98 | - * |
|
| 99 | - * This function is called by Sabre\DAV\Server, after |
|
| 100 | - * addPlugin is called. |
|
| 101 | - * |
|
| 102 | - * This method should set up the required event subscriptions. |
|
| 103 | - * |
|
| 104 | - * @param Server $server |
|
| 105 | - */ |
|
| 106 | - public function initialize(Server $server) { |
|
| 107 | - $this->server = $server; |
|
| 108 | - |
|
| 109 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 110 | - $this->server->on('propFind', [$this, 'propFind']); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function propFind(PropFind $propFind, INode $node) { |
|
| 114 | - if ($node instanceof Calendar) { |
|
| 115 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
| 116 | - if ($node->getPublishStatus()) { |
|
| 117 | - // We return the publish-url only if the calendar is published. |
|
| 118 | - $token = $node->getPublishStatus(); |
|
| 119 | - $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
| 120 | - |
|
| 121 | - return new Publisher($publishUrl, true); |
|
| 122 | - } |
|
| 123 | - }); |
|
| 124 | - |
|
| 125 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
| 126 | - return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription()); |
|
| 127 | - }); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * We intercept this to handle POST requests on calendars. |
|
| 133 | - * |
|
| 134 | - * @param RequestInterface $request |
|
| 135 | - * @param ResponseInterface $response |
|
| 136 | - * |
|
| 137 | - * @return void|bool |
|
| 138 | - */ |
|
| 139 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 140 | - $path = $request->getPath(); |
|
| 141 | - |
|
| 142 | - // Only handling xml |
|
| 143 | - $contentType = $request->getHeader('Content-Type'); |
|
| 144 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
| 145 | - return; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // Making sure the node exists |
|
| 149 | - try { |
|
| 150 | - $node = $this->server->tree->getNodeForPath($path); |
|
| 151 | - } catch (NotFound $e) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $requestBody = $request->getBodyAsString(); |
|
| 156 | - |
|
| 157 | - // If this request handler could not deal with this POST request, it |
|
| 158 | - // will return 'null' and other plugins get a chance to handle the |
|
| 159 | - // request. |
|
| 160 | - // |
|
| 161 | - // However, we already requested the full body. This is a problem, |
|
| 162 | - // because a body can only be read once. This is why we preemptively |
|
| 163 | - // re-populated the request body with the existing data. |
|
| 164 | - $request->setBody($requestBody); |
|
| 165 | - |
|
| 166 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 167 | - |
|
| 168 | - switch ($documentType) { |
|
| 169 | - |
|
| 170 | - case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : |
|
| 171 | - |
|
| 172 | - // We can only deal with IShareableCalendar objects |
|
| 173 | - if (!$node instanceof Calendar) { |
|
| 174 | - return; |
|
| 175 | - } |
|
| 176 | - $this->server->transactionType = 'post-publish-calendar'; |
|
| 177 | - |
|
| 178 | - // Getting ACL info |
|
| 179 | - $acl = $this->server->getPlugin('acl'); |
|
| 180 | - |
|
| 181 | - // If there's no ACL support, we allow everything |
|
| 182 | - if ($acl) { |
|
| 183 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $node->setPublishStatus(true); |
|
| 187 | - |
|
| 188 | - // iCloud sends back the 202, so we will too. |
|
| 189 | - $response->setStatus(202); |
|
| 190 | - |
|
| 191 | - // Adding this because sending a response body may cause issues, |
|
| 192 | - // and I wanted some type of indicator the response was handled. |
|
| 193 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 194 | - |
|
| 195 | - // Breaking the event chain |
|
| 196 | - return false; |
|
| 197 | - |
|
| 198 | - case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : |
|
| 199 | - |
|
| 200 | - // We can only deal with IShareableCalendar objects |
|
| 201 | - if (!$node instanceof Calendar) { |
|
| 202 | - return; |
|
| 203 | - } |
|
| 204 | - $this->server->transactionType = 'post-unpublish-calendar'; |
|
| 205 | - |
|
| 206 | - // Getting ACL info |
|
| 207 | - $acl = $this->server->getPlugin('acl'); |
|
| 208 | - |
|
| 209 | - // If there's no ACL support, we allow everything |
|
| 210 | - if ($acl) { |
|
| 211 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $node->setPublishStatus(false); |
|
| 215 | - |
|
| 216 | - $response->setStatus(200); |
|
| 217 | - |
|
| 218 | - // Adding this because sending a response body may cause issues, |
|
| 219 | - // and I wanted some type of indicator the response was handled. |
|
| 220 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 221 | - |
|
| 222 | - // Breaking the event chain |
|
| 223 | - return false; |
|
| 37 | + const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Reference to SabreDAV server object. |
|
| 41 | + * |
|
| 42 | + * @var \Sabre\DAV\Server |
|
| 43 | + */ |
|
| 44 | + protected $server; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Config instance to get instance secret. |
|
| 48 | + * |
|
| 49 | + * @var IConfig |
|
| 50 | + */ |
|
| 51 | + protected $config; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * URL Generator for absolute URLs. |
|
| 55 | + * |
|
| 56 | + * @var IURLGenerator |
|
| 57 | + */ |
|
| 58 | + protected $urlGenerator; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * PublishPlugin constructor. |
|
| 62 | + * |
|
| 63 | + * @param IConfig $config |
|
| 64 | + * @param IURLGenerator $urlGenerator |
|
| 65 | + */ |
|
| 66 | + public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
| 67 | + $this->config = $config; |
|
| 68 | + $this->urlGenerator = $urlGenerator; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * This method should return a list of server-features. |
|
| 73 | + * |
|
| 74 | + * This is for example 'versioning' and is added to the DAV: header |
|
| 75 | + * in an OPTIONS response. |
|
| 76 | + * |
|
| 77 | + * @return string[] |
|
| 78 | + */ |
|
| 79 | + public function getFeatures() { |
|
| 80 | + // May have to be changed to be detected |
|
| 81 | + return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Returns a plugin name. |
|
| 86 | + * |
|
| 87 | + * Using this name other plugins will be able to access other plugins |
|
| 88 | + * using Sabre\DAV\Server::getPlugin |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function getPluginName() { |
|
| 93 | + return 'oc-calendar-publishing'; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * This initializes the plugin. |
|
| 98 | + * |
|
| 99 | + * This function is called by Sabre\DAV\Server, after |
|
| 100 | + * addPlugin is called. |
|
| 101 | + * |
|
| 102 | + * This method should set up the required event subscriptions. |
|
| 103 | + * |
|
| 104 | + * @param Server $server |
|
| 105 | + */ |
|
| 106 | + public function initialize(Server $server) { |
|
| 107 | + $this->server = $server; |
|
| 108 | + |
|
| 109 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
| 110 | + $this->server->on('propFind', [$this, 'propFind']); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function propFind(PropFind $propFind, INode $node) { |
|
| 114 | + if ($node instanceof Calendar) { |
|
| 115 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
| 116 | + if ($node->getPublishStatus()) { |
|
| 117 | + // We return the publish-url only if the calendar is published. |
|
| 118 | + $token = $node->getPublishStatus(); |
|
| 119 | + $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
| 120 | + |
|
| 121 | + return new Publisher($publishUrl, true); |
|
| 122 | + } |
|
| 123 | + }); |
|
| 124 | + |
|
| 125 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
| 126 | + return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription()); |
|
| 127 | + }); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * We intercept this to handle POST requests on calendars. |
|
| 133 | + * |
|
| 134 | + * @param RequestInterface $request |
|
| 135 | + * @param ResponseInterface $response |
|
| 136 | + * |
|
| 137 | + * @return void|bool |
|
| 138 | + */ |
|
| 139 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
| 140 | + $path = $request->getPath(); |
|
| 141 | + |
|
| 142 | + // Only handling xml |
|
| 143 | + $contentType = $request->getHeader('Content-Type'); |
|
| 144 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
| 145 | + return; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // Making sure the node exists |
|
| 149 | + try { |
|
| 150 | + $node = $this->server->tree->getNodeForPath($path); |
|
| 151 | + } catch (NotFound $e) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $requestBody = $request->getBodyAsString(); |
|
| 156 | + |
|
| 157 | + // If this request handler could not deal with this POST request, it |
|
| 158 | + // will return 'null' and other plugins get a chance to handle the |
|
| 159 | + // request. |
|
| 160 | + // |
|
| 161 | + // However, we already requested the full body. This is a problem, |
|
| 162 | + // because a body can only be read once. This is why we preemptively |
|
| 163 | + // re-populated the request body with the existing data. |
|
| 164 | + $request->setBody($requestBody); |
|
| 165 | + |
|
| 166 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
| 167 | + |
|
| 168 | + switch ($documentType) { |
|
| 169 | + |
|
| 170 | + case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : |
|
| 171 | + |
|
| 172 | + // We can only deal with IShareableCalendar objects |
|
| 173 | + if (!$node instanceof Calendar) { |
|
| 174 | + return; |
|
| 175 | + } |
|
| 176 | + $this->server->transactionType = 'post-publish-calendar'; |
|
| 177 | + |
|
| 178 | + // Getting ACL info |
|
| 179 | + $acl = $this->server->getPlugin('acl'); |
|
| 180 | + |
|
| 181 | + // If there's no ACL support, we allow everything |
|
| 182 | + if ($acl) { |
|
| 183 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $node->setPublishStatus(true); |
|
| 187 | + |
|
| 188 | + // iCloud sends back the 202, so we will too. |
|
| 189 | + $response->setStatus(202); |
|
| 190 | + |
|
| 191 | + // Adding this because sending a response body may cause issues, |
|
| 192 | + // and I wanted some type of indicator the response was handled. |
|
| 193 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 194 | + |
|
| 195 | + // Breaking the event chain |
|
| 196 | + return false; |
|
| 197 | + |
|
| 198 | + case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : |
|
| 199 | + |
|
| 200 | + // We can only deal with IShareableCalendar objects |
|
| 201 | + if (!$node instanceof Calendar) { |
|
| 202 | + return; |
|
| 203 | + } |
|
| 204 | + $this->server->transactionType = 'post-unpublish-calendar'; |
|
| 205 | + |
|
| 206 | + // Getting ACL info |
|
| 207 | + $acl = $this->server->getPlugin('acl'); |
|
| 208 | + |
|
| 209 | + // If there's no ACL support, we allow everything |
|
| 210 | + if ($acl) { |
|
| 211 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $node->setPublishStatus(false); |
|
| 215 | + |
|
| 216 | + $response->setStatus(200); |
|
| 217 | + |
|
| 218 | + // Adding this because sending a response body may cause issues, |
|
| 219 | + // and I wanted some type of indicator the response was handled. |
|
| 220 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
| 221 | + |
|
| 222 | + // Breaking the event chain |
|
| 223 | + return false; |
|
| 224 | 224 | |
| 225 | - } |
|
| 226 | - } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | 227 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | - public function getPluginName() { |
|
| 92 | + public function getPluginName() { |
|
| 93 | 93 | return 'oc-calendar-publishing'; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -107,12 +107,12 @@ discard block |
||
| 107 | 107 | $this->server = $server; |
| 108 | 108 | |
| 109 | 109 | $this->server->on('method:POST', [$this, 'httpPost']); |
| 110 | - $this->server->on('propFind', [$this, 'propFind']); |
|
| 110 | + $this->server->on('propFind', [$this, 'propFind']); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | public function propFind(PropFind $propFind, INode $node) { |
| 114 | 114 | if ($node instanceof Calendar) { |
| 115 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
| 115 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function() use ($node) { |
|
| 116 | 116 | if ($node->getPublishStatus()) { |
| 117 | 117 | // We return the publish-url only if the calendar is published. |
| 118 | 118 | $token = $node->getPublishStatus(); |