@@ -111,7 +111,7 @@ |
||
111 | 111 | while (!empty($parents)) { |
112 | 112 | $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
113 | 113 | |
114 | - $parents = array_map(function ($parent) use ($qb) { |
|
114 | + $parents = array_map(function($parent) use ($qb) { |
|
115 | 115 | return $qb->createNamedParameter($parent); |
116 | 116 | }, $parents); |
117 | 117 |
@@ -30,108 +30,108 @@ |
||
30 | 30 | |
31 | 31 | class Folder extends File implements \OCP\Share_Backend_Collection { |
32 | 32 | |
33 | - /** |
|
34 | - * get shared parents |
|
35 | - * |
|
36 | - * @param int $itemSource item source ID |
|
37 | - * @param string $shareWith with whom should the item be shared |
|
38 | - * @param string $owner owner of the item |
|
39 | - * @return array with shares |
|
40 | - */ |
|
41 | - public function getParents($itemSource, $shareWith = null, $owner = null) { |
|
42 | - $result = []; |
|
43 | - $parent = $this->getParentId($itemSource); |
|
33 | + /** |
|
34 | + * get shared parents |
|
35 | + * |
|
36 | + * @param int $itemSource item source ID |
|
37 | + * @param string $shareWith with whom should the item be shared |
|
38 | + * @param string $owner owner of the item |
|
39 | + * @return array with shares |
|
40 | + */ |
|
41 | + public function getParents($itemSource, $shareWith = null, $owner = null) { |
|
42 | + $result = []; |
|
43 | + $parent = $this->getParentId($itemSource); |
|
44 | 44 | |
45 | - $userManager = \OC::$server->getUserManager(); |
|
45 | + $userManager = \OC::$server->getUserManager(); |
|
46 | 46 | |
47 | - while ($parent) { |
|
48 | - $shares = \OCP\Share::getItemSharedWithUser('folder', $parent, $shareWith, $owner); |
|
49 | - if ($shares) { |
|
50 | - foreach ($shares as $share) { |
|
51 | - $name = basename($share['path']); |
|
52 | - $share['collection']['path'] = $name; |
|
53 | - $share['collection']['item_type'] = 'folder'; |
|
54 | - $share['file_path'] = $name; |
|
47 | + while ($parent) { |
|
48 | + $shares = \OCP\Share::getItemSharedWithUser('folder', $parent, $shareWith, $owner); |
|
49 | + if ($shares) { |
|
50 | + foreach ($shares as $share) { |
|
51 | + $name = basename($share['path']); |
|
52 | + $share['collection']['path'] = $name; |
|
53 | + $share['collection']['item_type'] = 'folder'; |
|
54 | + $share['file_path'] = $name; |
|
55 | 55 | |
56 | - $ownerUser = $userManager->get($share['uid_owner']); |
|
57 | - $displayNameOwner = $ownerUser === null ? $share['uid_owner'] : $ownerUser->getDisplayName(); |
|
58 | - $shareWithUser = $userManager->get($share['share_with']); |
|
59 | - $displayNameShareWith = $shareWithUser === null ? $share['share_with'] : $shareWithUser->getDisplayName(); |
|
60 | - $share['displayname_owner'] = $displayNameOwner ? $displayNameOwner : $share['uid_owner']; |
|
61 | - $share['share_with_displayname'] = $displayNameShareWith ? $displayNameShareWith : $share['uid_owner']; |
|
56 | + $ownerUser = $userManager->get($share['uid_owner']); |
|
57 | + $displayNameOwner = $ownerUser === null ? $share['uid_owner'] : $ownerUser->getDisplayName(); |
|
58 | + $shareWithUser = $userManager->get($share['share_with']); |
|
59 | + $displayNameShareWith = $shareWithUser === null ? $share['share_with'] : $shareWithUser->getDisplayName(); |
|
60 | + $share['displayname_owner'] = $displayNameOwner ? $displayNameOwner : $share['uid_owner']; |
|
61 | + $share['share_with_displayname'] = $displayNameShareWith ? $displayNameShareWith : $share['uid_owner']; |
|
62 | 62 | |
63 | - $result[] = $share; |
|
64 | - } |
|
65 | - } |
|
66 | - $parent = $this->getParentId($parent); |
|
67 | - } |
|
63 | + $result[] = $share; |
|
64 | + } |
|
65 | + } |
|
66 | + $parent = $this->getParentId($parent); |
|
67 | + } |
|
68 | 68 | |
69 | - return $result; |
|
70 | - } |
|
69 | + return $result; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * get file cache ID of parent |
|
74 | - * |
|
75 | - * @param int $child file cache ID of child |
|
76 | - * @return mixed parent ID or null |
|
77 | - */ |
|
78 | - private function getParentId($child) { |
|
79 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
80 | - $qb->select('parent') |
|
81 | - ->from('filecache') |
|
82 | - ->where( |
|
83 | - $qb->expr()->eq('fileid', $qb->createNamedParameter($child)) |
|
84 | - ); |
|
85 | - $result = $qb->execute(); |
|
86 | - $row = $result->fetch(); |
|
87 | - $result->closeCursor(); |
|
88 | - return $row ? $row['parent'] : null; |
|
89 | - } |
|
72 | + /** |
|
73 | + * get file cache ID of parent |
|
74 | + * |
|
75 | + * @param int $child file cache ID of child |
|
76 | + * @return mixed parent ID or null |
|
77 | + */ |
|
78 | + private function getParentId($child) { |
|
79 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
80 | + $qb->select('parent') |
|
81 | + ->from('filecache') |
|
82 | + ->where( |
|
83 | + $qb->expr()->eq('fileid', $qb->createNamedParameter($child)) |
|
84 | + ); |
|
85 | + $result = $qb->execute(); |
|
86 | + $row = $result->fetch(); |
|
87 | + $result->closeCursor(); |
|
88 | + return $row ? $row['parent'] : null; |
|
89 | + } |
|
90 | 90 | |
91 | - public function getChildren($itemSource) { |
|
92 | - $children = []; |
|
93 | - $parents = [$itemSource]; |
|
91 | + public function getChildren($itemSource) { |
|
92 | + $children = []; |
|
93 | + $parents = [$itemSource]; |
|
94 | 94 | |
95 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
96 | - $qb->select('id') |
|
97 | - ->from('mimetypes') |
|
98 | - ->where( |
|
99 | - $qb->expr()->eq('mimetype', $qb->createNamedParameter('httpd/unix-directory')) |
|
100 | - ); |
|
101 | - $result = $qb->execute(); |
|
102 | - $row = $result->fetch(); |
|
103 | - $result->closeCursor(); |
|
95 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
96 | + $qb->select('id') |
|
97 | + ->from('mimetypes') |
|
98 | + ->where( |
|
99 | + $qb->expr()->eq('mimetype', $qb->createNamedParameter('httpd/unix-directory')) |
|
100 | + ); |
|
101 | + $result = $qb->execute(); |
|
102 | + $row = $result->fetch(); |
|
103 | + $result->closeCursor(); |
|
104 | 104 | |
105 | - if ($row = $result->fetchRow()) { |
|
106 | - $mimetype = (int) $row['id']; |
|
107 | - } else { |
|
108 | - $mimetype = -1; |
|
109 | - } |
|
110 | - while (!empty($parents)) { |
|
111 | - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
105 | + if ($row = $result->fetchRow()) { |
|
106 | + $mimetype = (int) $row['id']; |
|
107 | + } else { |
|
108 | + $mimetype = -1; |
|
109 | + } |
|
110 | + while (!empty($parents)) { |
|
111 | + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
112 | 112 | |
113 | - $parents = array_map(function ($parent) use ($qb) { |
|
114 | - return $qb->createNamedParameter($parent); |
|
115 | - }, $parents); |
|
113 | + $parents = array_map(function ($parent) use ($qb) { |
|
114 | + return $qb->createNamedParameter($parent); |
|
115 | + }, $parents); |
|
116 | 116 | |
117 | - $qb->select('`fileid', 'name', '`mimetype') |
|
118 | - ->from('filecache') |
|
119 | - ->where( |
|
120 | - $qb->expr()->in('parent', $parents) |
|
121 | - ); |
|
117 | + $qb->select('`fileid', 'name', '`mimetype') |
|
118 | + ->from('filecache') |
|
119 | + ->where( |
|
120 | + $qb->expr()->in('parent', $parents) |
|
121 | + ); |
|
122 | 122 | |
123 | - $result = $qb->execute(); |
|
123 | + $result = $qb->execute(); |
|
124 | 124 | |
125 | - $parents = []; |
|
126 | - while ($file = $result->fetch()) { |
|
127 | - $children[] = ['source' => $file['fileid'], 'file_path' => $file['name']]; |
|
128 | - // If a child folder is found look inside it |
|
129 | - if ((int) $file['mimetype'] === $mimetype) { |
|
130 | - $parents[] = $file['fileid']; |
|
131 | - } |
|
132 | - } |
|
133 | - $result->closeCursor(); |
|
134 | - } |
|
135 | - return $children; |
|
136 | - } |
|
125 | + $parents = []; |
|
126 | + while ($file = $result->fetch()) { |
|
127 | + $children[] = ['source' => $file['fileid'], 'file_path' => $file['name']]; |
|
128 | + // If a child folder is found look inside it |
|
129 | + if ((int) $file['mimetype'] === $mimetype) { |
|
130 | + $parents[] = $file['fileid']; |
|
131 | + } |
|
132 | + } |
|
133 | + $result->closeCursor(); |
|
134 | + } |
|
135 | + return $children; |
|
136 | + } |
|
137 | 137 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | } |
61 | 61 | $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
62 | 62 | /** @var Node[] $nodes */ |
63 | - $nodes = $userFolder->getById((int)$context['itemId']); |
|
63 | + $nodes = $userFolder->getById((int) $context['itemId']); |
|
64 | 64 | if (count($nodes) === 0) { |
65 | 65 | return; |
66 | 66 | } |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | // at least on PHP 5.6 usort turned out to be not stable. So we add |
75 | 75 | // the current index to the value and compare it on a draw |
76 | 76 | $i = 0; |
77 | - $workArray = array_map(function ($element) use (&$i) { |
|
77 | + $workArray = array_map(function($element) use (&$i) { |
|
78 | 78 | return [$i++, $element]; |
79 | 79 | }, $byType); |
80 | 80 | |
81 | - usort($workArray, function ($a, $b) use ($al, $type) { |
|
81 | + usort($workArray, function($a, $b) use ($al, $type) { |
|
82 | 82 | $result = $this->compare($a[1], $b[1], $al[$type]); |
83 | 83 | if ($result === 0) { |
84 | 84 | $result = $a[0] - $b[0]; |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | $a = $a['value']['shareWith']; |
102 | 102 | $b = $b['value']['shareWith']; |
103 | 103 | |
104 | - $valueA = (int)in_array($a, $al, true); |
|
105 | - $valueB = (int)in_array($b, $al, true); |
|
104 | + $valueA = (int) in_array($a, $al, true); |
|
105 | + $valueB = (int) in_array($b, $al, true); |
|
106 | 106 | |
107 | 107 | return $valueB - $valueA; |
108 | 108 | } |
@@ -32,75 +32,75 @@ |
||
32 | 32 | |
33 | 33 | class ShareRecipientSorter implements ISorter { |
34 | 34 | |
35 | - private IManager $shareManager; |
|
36 | - private IRootFolder $rootFolder; |
|
37 | - private IUserSession $userSession; |
|
35 | + private IManager $shareManager; |
|
36 | + private IRootFolder $rootFolder; |
|
37 | + private IUserSession $userSession; |
|
38 | 38 | |
39 | - public function __construct(IManager $shareManager, IRootFolder $rootFolder, IUserSession $userSession) { |
|
40 | - $this->shareManager = $shareManager; |
|
41 | - $this->rootFolder = $rootFolder; |
|
42 | - $this->userSession = $userSession; |
|
43 | - } |
|
39 | + public function __construct(IManager $shareManager, IRootFolder $rootFolder, IUserSession $userSession) { |
|
40 | + $this->shareManager = $shareManager; |
|
41 | + $this->rootFolder = $rootFolder; |
|
42 | + $this->userSession = $userSession; |
|
43 | + } |
|
44 | 44 | |
45 | - public function getId(): string { |
|
46 | - return 'share-recipients'; |
|
47 | - } |
|
45 | + public function getId(): string { |
|
46 | + return 'share-recipients'; |
|
47 | + } |
|
48 | 48 | |
49 | - public function sort(array &$sortArray, array $context) { |
|
50 | - // let's be tolerant. Comments uses "files" by default, other usages are often singular |
|
51 | - if ($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { |
|
52 | - return; |
|
53 | - } |
|
54 | - $user = $this->userSession->getUser(); |
|
55 | - if ($user === null) { |
|
56 | - return; |
|
57 | - } |
|
58 | - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
59 | - /** @var Node[] $nodes */ |
|
60 | - $nodes = $userFolder->getById((int)$context['itemId']); |
|
61 | - if (count($nodes) === 0) { |
|
62 | - return; |
|
63 | - } |
|
64 | - $al = $this->shareManager->getAccessList($nodes[0]); |
|
49 | + public function sort(array &$sortArray, array $context) { |
|
50 | + // let's be tolerant. Comments uses "files" by default, other usages are often singular |
|
51 | + if ($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { |
|
52 | + return; |
|
53 | + } |
|
54 | + $user = $this->userSession->getUser(); |
|
55 | + if ($user === null) { |
|
56 | + return; |
|
57 | + } |
|
58 | + $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
59 | + /** @var Node[] $nodes */ |
|
60 | + $nodes = $userFolder->getById((int)$context['itemId']); |
|
61 | + if (count($nodes) === 0) { |
|
62 | + return; |
|
63 | + } |
|
64 | + $al = $this->shareManager->getAccessList($nodes[0]); |
|
65 | 65 | |
66 | - foreach ($sortArray as $type => &$byType) { |
|
67 | - if (!isset($al[$type]) || !is_array($al[$type])) { |
|
68 | - continue; |
|
69 | - } |
|
66 | + foreach ($sortArray as $type => &$byType) { |
|
67 | + if (!isset($al[$type]) || !is_array($al[$type])) { |
|
68 | + continue; |
|
69 | + } |
|
70 | 70 | |
71 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
72 | - // the current index to the value and compare it on a draw |
|
73 | - $i = 0; |
|
74 | - $workArray = array_map(function ($element) use (&$i) { |
|
75 | - return [$i++, $element]; |
|
76 | - }, $byType); |
|
71 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
72 | + // the current index to the value and compare it on a draw |
|
73 | + $i = 0; |
|
74 | + $workArray = array_map(function ($element) use (&$i) { |
|
75 | + return [$i++, $element]; |
|
76 | + }, $byType); |
|
77 | 77 | |
78 | - usort($workArray, function ($a, $b) use ($al, $type) { |
|
79 | - $result = $this->compare($a[1], $b[1], $al[$type]); |
|
80 | - if ($result === 0) { |
|
81 | - $result = $a[0] - $b[0]; |
|
82 | - } |
|
83 | - return $result; |
|
84 | - }); |
|
78 | + usort($workArray, function ($a, $b) use ($al, $type) { |
|
79 | + $result = $this->compare($a[1], $b[1], $al[$type]); |
|
80 | + if ($result === 0) { |
|
81 | + $result = $a[0] - $b[0]; |
|
82 | + } |
|
83 | + return $result; |
|
84 | + }); |
|
85 | 85 | |
86 | - // and remove the index values again |
|
87 | - $byType = array_column($workArray, 1); |
|
88 | - } |
|
89 | - } |
|
86 | + // and remove the index values again |
|
87 | + $byType = array_column($workArray, 1); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param array $a |
|
93 | - * @param array $b |
|
94 | - * @param array $al |
|
95 | - * @return int |
|
96 | - */ |
|
97 | - protected function compare(array $a, array $b, array $al) { |
|
98 | - $a = $a['value']['shareWith']; |
|
99 | - $b = $b['value']['shareWith']; |
|
91 | + /** |
|
92 | + * @param array $a |
|
93 | + * @param array $b |
|
94 | + * @param array $al |
|
95 | + * @return int |
|
96 | + */ |
|
97 | + protected function compare(array $a, array $b, array $al) { |
|
98 | + $a = $a['value']['shareWith']; |
|
99 | + $b = $b['value']['shareWith']; |
|
100 | 100 | |
101 | - $valueA = (int)in_array($a, $al, true); |
|
102 | - $valueB = (int)in_array($b, $al, true); |
|
101 | + $valueA = (int)in_array($a, $al, true); |
|
102 | + $valueB = (int)in_array($b, $al, true); |
|
103 | 103 | |
104 | - return $valueB - $valueA; |
|
105 | - } |
|
104 | + return $valueB - $valueA; |
|
105 | + } |
|
106 | 106 | } |
@@ -38,47 +38,47 @@ |
||
38 | 38 | |
39 | 39 | class UserShareAcceptanceListener implements IEventListener { |
40 | 40 | |
41 | - /** @var IConfig */ |
|
42 | - private $config; |
|
43 | - /** @var IManager */ |
|
44 | - private $shareManager; |
|
45 | - /** @var IGroupManager */ |
|
46 | - private $groupManager; |
|
41 | + /** @var IConfig */ |
|
42 | + private $config; |
|
43 | + /** @var IManager */ |
|
44 | + private $shareManager; |
|
45 | + /** @var IGroupManager */ |
|
46 | + private $groupManager; |
|
47 | 47 | |
48 | - public function __construct(IConfig $config, IManager $shareManager, IGroupManager $groupManager) { |
|
49 | - $this->config = $config; |
|
50 | - $this->shareManager = $shareManager; |
|
51 | - $this->groupManager = $groupManager; |
|
52 | - } |
|
48 | + public function __construct(IConfig $config, IManager $shareManager, IGroupManager $groupManager) { |
|
49 | + $this->config = $config; |
|
50 | + $this->shareManager = $shareManager; |
|
51 | + $this->groupManager = $groupManager; |
|
52 | + } |
|
53 | 53 | |
54 | - public function handle(Event $event): void { |
|
55 | - if (!($event instanceof ShareCreatedEvent)) { |
|
56 | - return; |
|
57 | - } |
|
54 | + public function handle(Event $event): void { |
|
55 | + if (!($event instanceof ShareCreatedEvent)) { |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $share = $event->getShare(); |
|
59 | + $share = $event->getShare(); |
|
60 | 60 | |
61 | - if ($share->getShareType() === IShare::TYPE_USER) { |
|
62 | - $this->handleAutoAccept($share, $share->getSharedWith()); |
|
63 | - } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
64 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
61 | + if ($share->getShareType() === IShare::TYPE_USER) { |
|
62 | + $this->handleAutoAccept($share, $share->getSharedWith()); |
|
63 | + } elseif ($share->getShareType() === IShare::TYPE_GROUP) { |
|
64 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
65 | 65 | |
66 | - if ($group === null) { |
|
67 | - return; |
|
68 | - } |
|
66 | + if ($group === null) { |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - $users = $group->getUsers(); |
|
71 | - foreach ($users as $user) { |
|
72 | - $this->handleAutoAccept($share, $user->getUID()); |
|
73 | - } |
|
74 | - } |
|
75 | - } |
|
70 | + $users = $group->getUsers(); |
|
71 | + foreach ($users as $user) { |
|
72 | + $this->handleAutoAccept($share, $user->getUID()); |
|
73 | + } |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - private function handleAutoAccept(IShare $share, string $userId) { |
|
78 | - $defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes'; |
|
79 | - $acceptDefault = $this->config->getUserValue($userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes'; |
|
80 | - if (!$this->config->getSystemValueBool('sharing.force_share_accept', false) && $acceptDefault) { |
|
81 | - $this->shareManager->acceptShare($share, $userId); |
|
82 | - } |
|
83 | - } |
|
77 | + private function handleAutoAccept(IShare $share, string $userId) { |
|
78 | + $defaultAcceptSystemConfig = $this->config->getSystemValueBool('sharing.enable_share_accept', false) ? 'no' : 'yes'; |
|
79 | + $acceptDefault = $this->config->getUserValue($userId, Application::APP_ID, 'default_accept', $defaultAcceptSystemConfig) === 'yes'; |
|
80 | + if (!$this->config->getSystemValueBool('sharing.force_share_accept', false) && $acceptDefault) { |
|
81 | + $this->shareManager->acceptShare($share, $userId); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | $client = $this->httpClientService->newClient(); |
232 | 232 | try { |
233 | 233 | $result = $client->get( |
234 | - $url . '/status.php', |
|
234 | + $url.'/status.php', |
|
235 | 235 | [ |
236 | 236 | 'timeout' => 3, |
237 | 237 | 'connect_timeout' => 3, |
@@ -284,6 +284,6 @@ discard block |
||
284 | 284 | return $url; |
285 | 285 | } |
286 | 286 | |
287 | - return 'https://' . $url; |
|
287 | + return 'https://'.$url; |
|
288 | 288 | } |
289 | 289 | } |
@@ -42,176 +42,176 @@ |
||
42 | 42 | |
43 | 43 | class TrustedServers { |
44 | 44 | |
45 | - /** after a user list was exchanged at least once successfully */ |
|
46 | - public const STATUS_OK = 1; |
|
47 | - /** waiting for shared secret or initial user list exchange */ |
|
48 | - public const STATUS_PENDING = 2; |
|
49 | - /** something went wrong, misconfigured server, software bug,... user interaction needed */ |
|
50 | - public const STATUS_FAILURE = 3; |
|
51 | - /** remote server revoked access */ |
|
52 | - public const STATUS_ACCESS_REVOKED = 4; |
|
53 | - |
|
54 | - private DbHandler $dbHandler; |
|
55 | - private IClientService $httpClientService; |
|
56 | - private LoggerInterface $logger; |
|
57 | - private IJobList $jobList; |
|
58 | - private ISecureRandom $secureRandom; |
|
59 | - private IConfig $config; |
|
60 | - private IEventDispatcher $dispatcher; |
|
61 | - private ITimeFactory $timeFactory; |
|
62 | - |
|
63 | - public function __construct( |
|
64 | - DbHandler $dbHandler, |
|
65 | - IClientService $httpClientService, |
|
66 | - LoggerInterface $logger, |
|
67 | - IJobList $jobList, |
|
68 | - ISecureRandom $secureRandom, |
|
69 | - IConfig $config, |
|
70 | - IEventDispatcher $dispatcher, |
|
71 | - ITimeFactory $timeFactory |
|
72 | - ) { |
|
73 | - $this->dbHandler = $dbHandler; |
|
74 | - $this->httpClientService = $httpClientService; |
|
75 | - $this->logger = $logger; |
|
76 | - $this->jobList = $jobList; |
|
77 | - $this->secureRandom = $secureRandom; |
|
78 | - $this->config = $config; |
|
79 | - $this->dispatcher = $dispatcher; |
|
80 | - $this->timeFactory = $timeFactory; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Add server to the list of trusted servers |
|
85 | - */ |
|
86 | - public function addServer(string $url): int { |
|
87 | - $url = $this->updateProtocol($url); |
|
88 | - $result = $this->dbHandler->addServer($url); |
|
89 | - if ($result) { |
|
90 | - $token = $this->secureRandom->generate(16); |
|
91 | - $this->dbHandler->addToken($url, $token); |
|
92 | - $this->jobList->add( |
|
93 | - RequestSharedSecret::class, |
|
94 | - [ |
|
95 | - 'url' => $url, |
|
96 | - 'token' => $token, |
|
97 | - 'created' => $this->timeFactory->getTime() |
|
98 | - ] |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - return $result; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Get shared secret for the given server |
|
107 | - */ |
|
108 | - public function getSharedSecret(string $url): string { |
|
109 | - return $this->dbHandler->getSharedSecret($url); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Add shared secret for the given server |
|
114 | - */ |
|
115 | - public function addSharedSecret(string $url, string $sharedSecret): void { |
|
116 | - $this->dbHandler->addSharedSecret($url, $sharedSecret); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Remove server from the list of trusted servers |
|
121 | - */ |
|
122 | - public function removeServer(int $id): void { |
|
123 | - $server = $this->dbHandler->getServerById($id); |
|
124 | - $this->dbHandler->removeServer($id); |
|
125 | - $this->dispatcher->dispatchTyped(new TrustedServerRemovedEvent($server['url_hash'])); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Get all trusted servers |
|
130 | - * @return list<array{id: int, url: string, url_hash: string, shared_secret: string, status: int, sync_token: string}> |
|
131 | - */ |
|
132 | - public function getServers() { |
|
133 | - return $this->dbHandler->getAllServer(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Check if given server is a trusted Nextcloud server |
|
138 | - */ |
|
139 | - public function isTrustedServer(string $url): bool { |
|
140 | - return $this->dbHandler->serverExists($url); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Set server status |
|
145 | - */ |
|
146 | - public function setServerStatus(string $url, int $status): void { |
|
147 | - $this->dbHandler->setServerStatus($url, $status); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Get server status |
|
152 | - */ |
|
153 | - public function getServerStatus(string $url): int { |
|
154 | - return $this->dbHandler->getServerStatus($url); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Check if URL point to a ownCloud/Nextcloud server |
|
159 | - */ |
|
160 | - public function isNextcloudServer(string $url): bool { |
|
161 | - $isValidNextcloud = false; |
|
162 | - $client = $this->httpClientService->newClient(); |
|
163 | - try { |
|
164 | - $result = $client->get( |
|
165 | - $url . '/status.php', |
|
166 | - [ |
|
167 | - 'timeout' => 3, |
|
168 | - 'connect_timeout' => 3, |
|
169 | - ] |
|
170 | - ); |
|
171 | - if ($result->getStatusCode() === Http::STATUS_OK) { |
|
172 | - $body = $result->getBody(); |
|
173 | - if (is_resource($body)) { |
|
174 | - $body = stream_get_contents($body) ?: ''; |
|
175 | - } |
|
176 | - $isValidNextcloud = $this->checkNextcloudVersion($body); |
|
177 | - } |
|
178 | - } catch (\Exception $e) { |
|
179 | - $this->logger->error('No Nextcloud server.', [ |
|
180 | - 'app' => 'federation', |
|
181 | - 'exception' => $e, |
|
182 | - ]); |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - return $isValidNextcloud; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Check if ownCloud/Nextcloud version is >= 9.0 |
|
191 | - * @throws HintException |
|
192 | - */ |
|
193 | - protected function checkNextcloudVersion(string $status): bool { |
|
194 | - $decoded = json_decode($status, true); |
|
195 | - if (!empty($decoded) && isset($decoded['version'])) { |
|
196 | - if (!version_compare($decoded['version'], '9.0.0', '>=')) { |
|
197 | - throw new HintException('Remote server version is too low. 9.0 is required.'); |
|
198 | - } |
|
199 | - return true; |
|
200 | - } |
|
201 | - return false; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Check if the URL contain a protocol, if not add https |
|
206 | - */ |
|
207 | - protected function updateProtocol(string $url): string { |
|
208 | - if ( |
|
209 | - strpos($url, 'https://') === 0 |
|
210 | - || strpos($url, 'http://') === 0 |
|
211 | - ) { |
|
212 | - return $url; |
|
213 | - } |
|
214 | - |
|
215 | - return 'https://' . $url; |
|
216 | - } |
|
45 | + /** after a user list was exchanged at least once successfully */ |
|
46 | + public const STATUS_OK = 1; |
|
47 | + /** waiting for shared secret or initial user list exchange */ |
|
48 | + public const STATUS_PENDING = 2; |
|
49 | + /** something went wrong, misconfigured server, software bug,... user interaction needed */ |
|
50 | + public const STATUS_FAILURE = 3; |
|
51 | + /** remote server revoked access */ |
|
52 | + public const STATUS_ACCESS_REVOKED = 4; |
|
53 | + |
|
54 | + private DbHandler $dbHandler; |
|
55 | + private IClientService $httpClientService; |
|
56 | + private LoggerInterface $logger; |
|
57 | + private IJobList $jobList; |
|
58 | + private ISecureRandom $secureRandom; |
|
59 | + private IConfig $config; |
|
60 | + private IEventDispatcher $dispatcher; |
|
61 | + private ITimeFactory $timeFactory; |
|
62 | + |
|
63 | + public function __construct( |
|
64 | + DbHandler $dbHandler, |
|
65 | + IClientService $httpClientService, |
|
66 | + LoggerInterface $logger, |
|
67 | + IJobList $jobList, |
|
68 | + ISecureRandom $secureRandom, |
|
69 | + IConfig $config, |
|
70 | + IEventDispatcher $dispatcher, |
|
71 | + ITimeFactory $timeFactory |
|
72 | + ) { |
|
73 | + $this->dbHandler = $dbHandler; |
|
74 | + $this->httpClientService = $httpClientService; |
|
75 | + $this->logger = $logger; |
|
76 | + $this->jobList = $jobList; |
|
77 | + $this->secureRandom = $secureRandom; |
|
78 | + $this->config = $config; |
|
79 | + $this->dispatcher = $dispatcher; |
|
80 | + $this->timeFactory = $timeFactory; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Add server to the list of trusted servers |
|
85 | + */ |
|
86 | + public function addServer(string $url): int { |
|
87 | + $url = $this->updateProtocol($url); |
|
88 | + $result = $this->dbHandler->addServer($url); |
|
89 | + if ($result) { |
|
90 | + $token = $this->secureRandom->generate(16); |
|
91 | + $this->dbHandler->addToken($url, $token); |
|
92 | + $this->jobList->add( |
|
93 | + RequestSharedSecret::class, |
|
94 | + [ |
|
95 | + 'url' => $url, |
|
96 | + 'token' => $token, |
|
97 | + 'created' => $this->timeFactory->getTime() |
|
98 | + ] |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + return $result; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Get shared secret for the given server |
|
107 | + */ |
|
108 | + public function getSharedSecret(string $url): string { |
|
109 | + return $this->dbHandler->getSharedSecret($url); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Add shared secret for the given server |
|
114 | + */ |
|
115 | + public function addSharedSecret(string $url, string $sharedSecret): void { |
|
116 | + $this->dbHandler->addSharedSecret($url, $sharedSecret); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Remove server from the list of trusted servers |
|
121 | + */ |
|
122 | + public function removeServer(int $id): void { |
|
123 | + $server = $this->dbHandler->getServerById($id); |
|
124 | + $this->dbHandler->removeServer($id); |
|
125 | + $this->dispatcher->dispatchTyped(new TrustedServerRemovedEvent($server['url_hash'])); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Get all trusted servers |
|
130 | + * @return list<array{id: int, url: string, url_hash: string, shared_secret: string, status: int, sync_token: string}> |
|
131 | + */ |
|
132 | + public function getServers() { |
|
133 | + return $this->dbHandler->getAllServer(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Check if given server is a trusted Nextcloud server |
|
138 | + */ |
|
139 | + public function isTrustedServer(string $url): bool { |
|
140 | + return $this->dbHandler->serverExists($url); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Set server status |
|
145 | + */ |
|
146 | + public function setServerStatus(string $url, int $status): void { |
|
147 | + $this->dbHandler->setServerStatus($url, $status); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Get server status |
|
152 | + */ |
|
153 | + public function getServerStatus(string $url): int { |
|
154 | + return $this->dbHandler->getServerStatus($url); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Check if URL point to a ownCloud/Nextcloud server |
|
159 | + */ |
|
160 | + public function isNextcloudServer(string $url): bool { |
|
161 | + $isValidNextcloud = false; |
|
162 | + $client = $this->httpClientService->newClient(); |
|
163 | + try { |
|
164 | + $result = $client->get( |
|
165 | + $url . '/status.php', |
|
166 | + [ |
|
167 | + 'timeout' => 3, |
|
168 | + 'connect_timeout' => 3, |
|
169 | + ] |
|
170 | + ); |
|
171 | + if ($result->getStatusCode() === Http::STATUS_OK) { |
|
172 | + $body = $result->getBody(); |
|
173 | + if (is_resource($body)) { |
|
174 | + $body = stream_get_contents($body) ?: ''; |
|
175 | + } |
|
176 | + $isValidNextcloud = $this->checkNextcloudVersion($body); |
|
177 | + } |
|
178 | + } catch (\Exception $e) { |
|
179 | + $this->logger->error('No Nextcloud server.', [ |
|
180 | + 'app' => 'federation', |
|
181 | + 'exception' => $e, |
|
182 | + ]); |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + return $isValidNextcloud; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Check if ownCloud/Nextcloud version is >= 9.0 |
|
191 | + * @throws HintException |
|
192 | + */ |
|
193 | + protected function checkNextcloudVersion(string $status): bool { |
|
194 | + $decoded = json_decode($status, true); |
|
195 | + if (!empty($decoded) && isset($decoded['version'])) { |
|
196 | + if (!version_compare($decoded['version'], '9.0.0', '>=')) { |
|
197 | + throw new HintException('Remote server version is too low. 9.0 is required.'); |
|
198 | + } |
|
199 | + return true; |
|
200 | + } |
|
201 | + return false; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Check if the URL contain a protocol, if not add https |
|
206 | + */ |
|
207 | + protected function updateProtocol(string $url): string { |
|
208 | + if ( |
|
209 | + strpos($url, 'https://') === 0 |
|
210 | + || strpos($url, 'http://') === 0 |
|
211 | + ) { |
|
212 | + return $url; |
|
213 | + } |
|
214 | + |
|
215 | + return 'https://' . $url; |
|
216 | + } |
|
217 | 217 | } |
@@ -20,12 +20,12 @@ |
||
20 | 20 | <ul id="listOfTrustedServers"> |
21 | 21 | <?php foreach ($_['trustedServers'] as $trustedServer) { ?> |
22 | 22 | <li id="<?php p($trustedServer['id']); ?>"> |
23 | - <?php if ((int)$trustedServer['status'] === TrustedServers::STATUS_OK) { ?> |
|
23 | + <?php if ((int) $trustedServer['status'] === TrustedServers::STATUS_OK) { ?> |
|
24 | 24 | <span class="status success"></span> |
25 | 25 | <?php |
26 | 26 | } elseif ( |
27 | - (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
28 | - (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
27 | + (int) $trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
28 | + (int) $trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
29 | 29 | ) { ?> |
30 | 30 | <span class="status indeterminate"></span> |
31 | 31 | <?php } else {?> |
@@ -16,10 +16,10 @@ |
||
16 | 16 | <?php if ((int)$trustedServer['status'] === TrustedServers::STATUS_OK) { ?> |
17 | 17 | <span class="status success"></span> |
18 | 18 | <?php |
19 | - } elseif ( |
|
20 | - (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
21 | - (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
22 | - ) { ?> |
|
19 | + } elseif ( |
|
20 | + (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING || |
|
21 | + (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED |
|
22 | + ) { ?> |
|
23 | 23 | <span class="status indeterminate"></span> |
24 | 24 | <?php } else {?> |
25 | 25 | <span class="status error"></span> |
@@ -32,23 +32,23 @@ |
||
32 | 32 | * OAuth1 authentication |
33 | 33 | */ |
34 | 34 | class OAuth1 extends AuthMechanism { |
35 | - public function __construct(IL10N $l) { |
|
36 | - $this |
|
37 | - ->setIdentifier('oauth1::oauth1') |
|
38 | - ->setScheme(self::SCHEME_OAUTH1) |
|
39 | - ->setText($l->t('OAuth1')) |
|
40 | - ->addParameters([ |
|
41 | - (new DefinitionParameter('configured', 'configured')) |
|
42 | - ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
43 | - new DefinitionParameter('app_key', $l->t('App key')), |
|
44 | - (new DefinitionParameter('app_secret', $l->t('App secret'))) |
|
45 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
46 | - (new DefinitionParameter('token', 'token')) |
|
47 | - ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
48 | - (new DefinitionParameter('token_secret', 'token_secret')) |
|
49 | - ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
50 | - ]) |
|
51 | - ->addCustomJs('oauth1') |
|
52 | - ; |
|
53 | - } |
|
35 | + public function __construct(IL10N $l) { |
|
36 | + $this |
|
37 | + ->setIdentifier('oauth1::oauth1') |
|
38 | + ->setScheme(self::SCHEME_OAUTH1) |
|
39 | + ->setText($l->t('OAuth1')) |
|
40 | + ->addParameters([ |
|
41 | + (new DefinitionParameter('configured', 'configured')) |
|
42 | + ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
43 | + new DefinitionParameter('app_key', $l->t('App key')), |
|
44 | + (new DefinitionParameter('app_secret', $l->t('App secret'))) |
|
45 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
46 | + (new DefinitionParameter('token', 'token')) |
|
47 | + ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
48 | + (new DefinitionParameter('token_secret', 'token_secret')) |
|
49 | + ->setType(DefinitionParameter::VALUE_HIDDEN), |
|
50 | + ]) |
|
51 | + ->addCustomJs('oauth1') |
|
52 | + ; |
|
53 | + } |
|
54 | 54 | } |
@@ -33,18 +33,18 @@ |
||
33 | 33 | * OpenStack Keystone authentication |
34 | 34 | */ |
35 | 35 | class OpenStackV2 extends AuthMechanism { |
36 | - public function __construct(IL10N $l) { |
|
37 | - $this |
|
38 | - ->setIdentifier('openstack::openstack') |
|
39 | - ->setScheme(self::SCHEME_OPENSTACK) |
|
40 | - ->setText($l->t('OpenStack v2')) |
|
41 | - ->addParameters([ |
|
42 | - new DefinitionParameter('user', $l->t('Username')), |
|
43 | - (new DefinitionParameter('password', $l->t('Password'))) |
|
44 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
45 | - new DefinitionParameter('tenant', $l->t('Tenant name')), |
|
46 | - new DefinitionParameter('url', $l->t('Identity endpoint URL')), |
|
47 | - ]) |
|
48 | - ; |
|
49 | - } |
|
36 | + public function __construct(IL10N $l) { |
|
37 | + $this |
|
38 | + ->setIdentifier('openstack::openstack') |
|
39 | + ->setScheme(self::SCHEME_OPENSTACK) |
|
40 | + ->setText($l->t('OpenStack v2')) |
|
41 | + ->addParameters([ |
|
42 | + new DefinitionParameter('user', $l->t('Username')), |
|
43 | + (new DefinitionParameter('password', $l->t('Password'))) |
|
44 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
45 | + new DefinitionParameter('tenant', $l->t('Tenant name')), |
|
46 | + new DefinitionParameter('url', $l->t('Identity endpoint URL')), |
|
47 | + ]) |
|
48 | + ; |
|
49 | + } |
|
50 | 50 | } |
@@ -32,16 +32,16 @@ |
||
32 | 32 | * Rackspace authentication |
33 | 33 | */ |
34 | 34 | class Rackspace extends AuthMechanism { |
35 | - public function __construct(IL10N $l) { |
|
36 | - $this |
|
37 | - ->setIdentifier('openstack::rackspace') |
|
38 | - ->setScheme(self::SCHEME_OPENSTACK) |
|
39 | - ->setText($l->t('Rackspace')) |
|
40 | - ->addParameters([ |
|
41 | - new DefinitionParameter('user', $l->t('Username')), |
|
42 | - (new DefinitionParameter('key', $l->t('API key'))) |
|
43 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
44 | - ]) |
|
45 | - ; |
|
46 | - } |
|
35 | + public function __construct(IL10N $l) { |
|
36 | + $this |
|
37 | + ->setIdentifier('openstack::rackspace') |
|
38 | + ->setScheme(self::SCHEME_OPENSTACK) |
|
39 | + ->setText($l->t('Rackspace')) |
|
40 | + ->addParameters([ |
|
41 | + new DefinitionParameter('user', $l->t('Username')), |
|
42 | + (new DefinitionParameter('key', $l->t('API key'))) |
|
43 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
44 | + ]) |
|
45 | + ; |
|
46 | + } |
|
47 | 47 | } |
@@ -32,15 +32,15 @@ |
||
32 | 32 | * Basic password authentication mechanism |
33 | 33 | */ |
34 | 34 | class Password extends AuthMechanism { |
35 | - public function __construct(IL10N $l) { |
|
36 | - $this |
|
37 | - ->setIdentifier('password::password') |
|
38 | - ->setScheme(self::SCHEME_PASSWORD) |
|
39 | - ->setText($l->t('Username and password')) |
|
40 | - ->addParameters([ |
|
41 | - new DefinitionParameter('user', $l->t('Username')), |
|
42 | - (new DefinitionParameter('password', $l->t('Password'))) |
|
43 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
44 | - ]); |
|
45 | - } |
|
35 | + public function __construct(IL10N $l) { |
|
36 | + $this |
|
37 | + ->setIdentifier('password::password') |
|
38 | + ->setScheme(self::SCHEME_PASSWORD) |
|
39 | + ->setText($l->t('Username and password')) |
|
40 | + ->addParameters([ |
|
41 | + new DefinitionParameter('user', $l->t('Username')), |
|
42 | + (new DefinitionParameter('password', $l->t('Password'))) |
|
43 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
44 | + ]); |
|
45 | + } |
|
46 | 46 | } |