@@ -33,155 +33,155 @@ |
||
33 | 33 | */ |
34 | 34 | class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport { |
35 | 35 | |
36 | - private $backend; |
|
37 | - private $logger; |
|
38 | - private $helper; |
|
39 | - private $deletedUsersIndex; |
|
36 | + private $backend; |
|
37 | + private $logger; |
|
38 | + private $helper; |
|
39 | + private $deletedUsersIndex; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Create new LDAPProvider |
|
43 | - * @param \OCP\IServerContainer $serverContainer |
|
44 | - * @throws \Exception if user_ldap app was not enabled |
|
45 | - */ |
|
46 | - public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { |
|
47 | - $this->logger = $serverContainer->getLogger(); |
|
48 | - $this->helper = $helper; |
|
49 | - $this->deletedUsersIndex = $deletedUsersIndex; |
|
50 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
51 | - $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
|
52 | - if ($backend instanceof IUserLDAP) { |
|
53 | - $this->backend = $backend; |
|
54 | - return; |
|
55 | - } |
|
41 | + /** |
|
42 | + * Create new LDAPProvider |
|
43 | + * @param \OCP\IServerContainer $serverContainer |
|
44 | + * @throws \Exception if user_ldap app was not enabled |
|
45 | + */ |
|
46 | + public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { |
|
47 | + $this->logger = $serverContainer->getLogger(); |
|
48 | + $this->helper = $helper; |
|
49 | + $this->deletedUsersIndex = $deletedUsersIndex; |
|
50 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
51 | + $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
|
52 | + if ($backend instanceof IUserLDAP) { |
|
53 | + $this->backend = $backend; |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | } |
57 | - throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); |
|
58 | - } |
|
57 | + throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Translate an user id to LDAP DN |
|
62 | - * @param string $uid user id |
|
63 | - * @return string with the LDAP DN |
|
64 | - * @throws \Exception if translation was unsuccessful |
|
65 | - */ |
|
66 | - public function getUserDN($uid) { |
|
67 | - if(!$this->backend->userExists($uid)){ |
|
68 | - throw new \Exception('User id not found in LDAP'); |
|
69 | - } |
|
70 | - $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
|
71 | - if(!$result){ |
|
72 | - throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
73 | - } |
|
74 | - return $result; |
|
75 | - } |
|
60 | + /** |
|
61 | + * Translate an user id to LDAP DN |
|
62 | + * @param string $uid user id |
|
63 | + * @return string with the LDAP DN |
|
64 | + * @throws \Exception if translation was unsuccessful |
|
65 | + */ |
|
66 | + public function getUserDN($uid) { |
|
67 | + if(!$this->backend->userExists($uid)){ |
|
68 | + throw new \Exception('User id not found in LDAP'); |
|
69 | + } |
|
70 | + $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
|
71 | + if(!$result){ |
|
72 | + throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
73 | + } |
|
74 | + return $result; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Translate a LDAP DN to an internal user name. If there is no mapping between |
|
79 | - * the DN and the user name, a new one will be created. |
|
80 | - * @param string $dn LDAP DN |
|
81 | - * @return string with the internal user name |
|
82 | - * @throws \Exception if translation was unsuccessful |
|
83 | - */ |
|
84 | - public function getUserName($dn) { |
|
85 | - $result = $this->backend->dn2UserName($dn); |
|
86 | - if(!$result){ |
|
87 | - throw new \Exception('Translation to internal user name unsuccessful'); |
|
88 | - } |
|
89 | - return $result; |
|
90 | - } |
|
77 | + /** |
|
78 | + * Translate a LDAP DN to an internal user name. If there is no mapping between |
|
79 | + * the DN and the user name, a new one will be created. |
|
80 | + * @param string $dn LDAP DN |
|
81 | + * @return string with the internal user name |
|
82 | + * @throws \Exception if translation was unsuccessful |
|
83 | + */ |
|
84 | + public function getUserName($dn) { |
|
85 | + $result = $this->backend->dn2UserName($dn); |
|
86 | + if(!$result){ |
|
87 | + throw new \Exception('Translation to internal user name unsuccessful'); |
|
88 | + } |
|
89 | + return $result; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Convert a stored DN so it can be used as base parameter for LDAP queries. |
|
94 | - * @param string $dn the DN in question |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function DNasBaseParameter($dn) { |
|
98 | - return $this->helper->DNasBaseParameter($dn); |
|
99 | - } |
|
92 | + /** |
|
93 | + * Convert a stored DN so it can be used as base parameter for LDAP queries. |
|
94 | + * @param string $dn the DN in question |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function DNasBaseParameter($dn) { |
|
98 | + return $this->helper->DNasBaseParameter($dn); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Sanitize a DN received from the LDAP server. |
|
103 | - * @param array $dn the DN in question |
|
104 | - * @return array the sanitized DN |
|
105 | - */ |
|
106 | - public function sanitizeDN($dn) { |
|
107 | - return $this->helper->sanitizeDN($dn); |
|
108 | - } |
|
101 | + /** |
|
102 | + * Sanitize a DN received from the LDAP server. |
|
103 | + * @param array $dn the DN in question |
|
104 | + * @return array the sanitized DN |
|
105 | + */ |
|
106 | + public function sanitizeDN($dn) { |
|
107 | + return $this->helper->sanitizeDN($dn); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Return a new LDAP connection resource for the specified user. |
|
112 | - * The connection must be closed manually. |
|
113 | - * @param string $uid user id |
|
114 | - * @return resource of the LDAP connection |
|
115 | - * @throws \Exception if user id was not found in LDAP |
|
116 | - */ |
|
117 | - public function getLDAPConnection($uid) { |
|
118 | - if(!$this->backend->userExists($uid)){ |
|
119 | - throw new \Exception('User id not found in LDAP'); |
|
120 | - } |
|
121 | - return $this->backend->getNewLDAPConnection($uid); |
|
122 | - } |
|
110 | + /** |
|
111 | + * Return a new LDAP connection resource for the specified user. |
|
112 | + * The connection must be closed manually. |
|
113 | + * @param string $uid user id |
|
114 | + * @return resource of the LDAP connection |
|
115 | + * @throws \Exception if user id was not found in LDAP |
|
116 | + */ |
|
117 | + public function getLDAPConnection($uid) { |
|
118 | + if(!$this->backend->userExists($uid)){ |
|
119 | + throw new \Exception('User id not found in LDAP'); |
|
120 | + } |
|
121 | + return $this->backend->getNewLDAPConnection($uid); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Get the LDAP base for users. |
|
126 | - * @param string $uid user id |
|
127 | - * @return string the base for users |
|
128 | - * @throws \Exception if user id was not found in LDAP |
|
129 | - */ |
|
130 | - public function getLDAPBaseUsers($uid) { |
|
131 | - if(!$this->backend->userExists($uid)){ |
|
132 | - throw new \Exception('User id not found in LDAP'); |
|
133 | - } |
|
134 | - return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
|
135 | - } |
|
124 | + /** |
|
125 | + * Get the LDAP base for users. |
|
126 | + * @param string $uid user id |
|
127 | + * @return string the base for users |
|
128 | + * @throws \Exception if user id was not found in LDAP |
|
129 | + */ |
|
130 | + public function getLDAPBaseUsers($uid) { |
|
131 | + if(!$this->backend->userExists($uid)){ |
|
132 | + throw new \Exception('User id not found in LDAP'); |
|
133 | + } |
|
134 | + return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Get the LDAP base for groups. |
|
139 | - * @param string $uid user id |
|
140 | - * @return string the base for groups |
|
141 | - * @throws \Exception if user id was not found in LDAP |
|
142 | - */ |
|
143 | - public function getLDAPBaseGroups($uid) { |
|
144 | - if(!$this->backend->userExists($uid)){ |
|
145 | - throw new \Exception('User id not found in LDAP'); |
|
146 | - } |
|
147 | - return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
|
148 | - } |
|
137 | + /** |
|
138 | + * Get the LDAP base for groups. |
|
139 | + * @param string $uid user id |
|
140 | + * @return string the base for groups |
|
141 | + * @throws \Exception if user id was not found in LDAP |
|
142 | + */ |
|
143 | + public function getLDAPBaseGroups($uid) { |
|
144 | + if(!$this->backend->userExists($uid)){ |
|
145 | + throw new \Exception('User id not found in LDAP'); |
|
146 | + } |
|
147 | + return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Clear the cache if a cache is used, otherwise do nothing. |
|
152 | - * @param string $uid user id |
|
153 | - * @throws \Exception if user id was not found in LDAP |
|
154 | - */ |
|
155 | - public function clearCache($uid) { |
|
156 | - if(!$this->backend->userExists($uid)){ |
|
157 | - throw new \Exception('User id not found in LDAP'); |
|
158 | - } |
|
159 | - $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
|
160 | - } |
|
150 | + /** |
|
151 | + * Clear the cache if a cache is used, otherwise do nothing. |
|
152 | + * @param string $uid user id |
|
153 | + * @throws \Exception if user id was not found in LDAP |
|
154 | + */ |
|
155 | + public function clearCache($uid) { |
|
156 | + if(!$this->backend->userExists($uid)){ |
|
157 | + throw new \Exception('User id not found in LDAP'); |
|
158 | + } |
|
159 | + $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Check whether a LDAP DN exists |
|
164 | - * @param string $dn LDAP DN |
|
165 | - * @return bool whether the DN exists |
|
166 | - */ |
|
167 | - public function dnExists($dn) { |
|
168 | - $result = $this->backend->dn2UserName($dn); |
|
169 | - return !$result ? false : true; |
|
170 | - } |
|
162 | + /** |
|
163 | + * Check whether a LDAP DN exists |
|
164 | + * @param string $dn LDAP DN |
|
165 | + * @return bool whether the DN exists |
|
166 | + */ |
|
167 | + public function dnExists($dn) { |
|
168 | + $result = $this->backend->dn2UserName($dn); |
|
169 | + return !$result ? false : true; |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * Flag record for deletion. |
|
174 | - * @param string $uid user id |
|
175 | - */ |
|
176 | - public function flagRecord($uid) { |
|
177 | - $this->deletedUsersIndex->markUser($uid); |
|
178 | - } |
|
172 | + /** |
|
173 | + * Flag record for deletion. |
|
174 | + * @param string $uid user id |
|
175 | + */ |
|
176 | + public function flagRecord($uid) { |
|
177 | + $this->deletedUsersIndex->markUser($uid); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Unflag record for deletion. |
|
182 | - * @param string $uid user id |
|
183 | - */ |
|
184 | - public function unflagRecord($uid) { |
|
185 | - //do nothing |
|
186 | - } |
|
180 | + /** |
|
181 | + * Unflag record for deletion. |
|
182 | + * @param string $uid user id |
|
183 | + */ |
|
184 | + public function unflagRecord($uid) { |
|
185 | + //do nothing |
|
186 | + } |
|
187 | 187 | } |
@@ -28,13 +28,13 @@ |
||
28 | 28 | * @brief wraps around static ownCloud core methods |
29 | 29 | */ |
30 | 30 | class LogWrapper { |
31 | - protected $app = 'user_ldap'; |
|
31 | + protected $app = 'user_ldap'; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @brief states whether the filesystem was loaded |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - public function log($msg, $level) { |
|
38 | - \OCP\Util::writeLog($this->app, $msg, $level); |
|
39 | - } |
|
33 | + /** |
|
34 | + * @brief states whether the filesystem was loaded |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + public function log($msg, $level) { |
|
38 | + \OCP\Util::writeLog($this->app, $msg, $level); |
|
39 | + } |
|
40 | 40 | } |
@@ -32,44 +32,44 @@ |
||
32 | 32 | $ldapWrapper = new OCA\User_LDAP\LDAP(); |
33 | 33 | $ocConfig = \OC::$server->getConfig(); |
34 | 34 | if(count($configPrefixes) === 1) { |
35 | - $dbc = \OC::$server->getDatabaseConnection(); |
|
36 | - $userManager = new OCA\User_LDAP\User\Manager($ocConfig, |
|
37 | - new OCA\User_LDAP\FilesystemHelper(), |
|
38 | - new OCA\User_LDAP\LogWrapper(), |
|
39 | - \OC::$server->getAvatarManager(), |
|
40 | - new \OCP\Image(), |
|
41 | - $dbc, |
|
42 | - \OC::$server->getUserManager() |
|
43 | - ); |
|
44 | - $connector = new OCA\User_LDAP\Connection($ldapWrapper, $configPrefixes[0]); |
|
45 | - $ldapAccess = new OCA\User_LDAP\Access($connector, $ldapWrapper, $userManager, $helper); |
|
35 | + $dbc = \OC::$server->getDatabaseConnection(); |
|
36 | + $userManager = new OCA\User_LDAP\User\Manager($ocConfig, |
|
37 | + new OCA\User_LDAP\FilesystemHelper(), |
|
38 | + new OCA\User_LDAP\LogWrapper(), |
|
39 | + \OC::$server->getAvatarManager(), |
|
40 | + new \OCP\Image(), |
|
41 | + $dbc, |
|
42 | + \OC::$server->getUserManager() |
|
43 | + ); |
|
44 | + $connector = new OCA\User_LDAP\Connection($ldapWrapper, $configPrefixes[0]); |
|
45 | + $ldapAccess = new OCA\User_LDAP\Access($connector, $ldapWrapper, $userManager, $helper); |
|
46 | 46 | |
47 | - $ldapAccess->setUserMapper(new OCA\User_LDAP\Mapping\UserMapping($dbc)); |
|
48 | - $ldapAccess->setGroupMapper(new OCA\User_LDAP\Mapping\GroupMapping($dbc)); |
|
49 | - $userBackend = new OCA\User_LDAP\User_LDAP($ldapAccess, $ocConfig); |
|
50 | - $groupBackend = new \OCA\User_LDAP\Group_LDAP($ldapAccess); |
|
47 | + $ldapAccess->setUserMapper(new OCA\User_LDAP\Mapping\UserMapping($dbc)); |
|
48 | + $ldapAccess->setGroupMapper(new OCA\User_LDAP\Mapping\GroupMapping($dbc)); |
|
49 | + $userBackend = new OCA\User_LDAP\User_LDAP($ldapAccess, $ocConfig); |
|
50 | + $groupBackend = new \OCA\User_LDAP\Group_LDAP($ldapAccess); |
|
51 | 51 | } else if(count($configPrefixes) > 1) { |
52 | - $userBackend = new OCA\User_LDAP\User_Proxy( |
|
53 | - $configPrefixes, $ldapWrapper, $ocConfig |
|
54 | - ); |
|
55 | - $groupBackend = new OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper); |
|
52 | + $userBackend = new OCA\User_LDAP\User_Proxy( |
|
53 | + $configPrefixes, $ldapWrapper, $ocConfig |
|
54 | + ); |
|
55 | + $groupBackend = new OCA\User_LDAP\Group_Proxy($configPrefixes, $ldapWrapper); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | if(count($configPrefixes) > 0) { |
59 | - // register user backend |
|
60 | - OC_User::useBackend($userBackend); |
|
61 | - OC_Group::useBackend($groupBackend); |
|
59 | + // register user backend |
|
60 | + OC_User::useBackend($userBackend); |
|
61 | + OC_Group::useBackend($groupBackend); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | \OCP\Util::connectHook( |
65 | - '\OCA\Files_Sharing\API\Server2Server', |
|
66 | - 'preLoginNameUsedAsUserName', |
|
67 | - '\OCA\User_LDAP\Helper', |
|
68 | - 'loginName2UserName' |
|
65 | + '\OCA\Files_Sharing\API\Server2Server', |
|
66 | + 'preLoginNameUsedAsUserName', |
|
67 | + '\OCA\User_LDAP\Helper', |
|
68 | + 'loginName2UserName' |
|
69 | 69 | ); |
70 | 70 | |
71 | 71 | if(OCP\App::isEnabled('user_webdavauth')) { |
72 | - OCP\Util::writeLog('user_ldap', |
|
73 | - 'user_ldap and user_webdavauth are incompatible. You may experience unexpected behaviour', |
|
74 | - OCP\Util::WARN); |
|
72 | + OCP\Util::writeLog('user_ldap', |
|
73 | + 'user_ldap and user_webdavauth are incompatible. You may experience unexpected behaviour', |
|
74 | + OCP\Util::WARN); |
|
75 | 75 | } |
@@ -1,47 +1,47 @@ discard block |
||
1 | 1 | <?php |
2 | - use \OCA\Files_External\Lib\Backend\Backend; |
|
3 | - use \OCA\Files_External\Lib\Auth\AuthMechanism; |
|
4 | - use \OCA\Files_External\Lib\DefinitionParameter; |
|
5 | - use \OCA\Files_External\Service\BackendService; |
|
2 | + use \OCA\Files_External\Lib\Backend\Backend; |
|
3 | + use \OCA\Files_External\Lib\Auth\AuthMechanism; |
|
4 | + use \OCA\Files_External\Lib\DefinitionParameter; |
|
5 | + use \OCA\Files_External\Service\BackendService; |
|
6 | 6 | |
7 | - $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting']; |
|
7 | + $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting']; |
|
8 | 8 | |
9 | - $l->t("Enable encryption"); |
|
10 | - $l->t("Enable previews"); |
|
11 | - $l->t("Enable sharing"); |
|
12 | - $l->t("Check for changes"); |
|
13 | - $l->t("Never"); |
|
14 | - $l->t("Once every direct access"); |
|
9 | + $l->t("Enable encryption"); |
|
10 | + $l->t("Enable previews"); |
|
11 | + $l->t("Enable sharing"); |
|
12 | + $l->t("Check for changes"); |
|
13 | + $l->t("Never"); |
|
14 | + $l->t("Once every direct access"); |
|
15 | 15 | |
16 | - script('files_external', 'settings'); |
|
17 | - style('files_external', 'settings'); |
|
16 | + script('files_external', 'settings'); |
|
17 | + style('files_external', 'settings'); |
|
18 | 18 | |
19 | - // load custom JS |
|
20 | - foreach ($_['backends'] as $backend) { |
|
21 | - /** @var Backend $backend */ |
|
22 | - $scripts = $backend->getCustomJs(); |
|
23 | - foreach ($scripts as $script) { |
|
24 | - script('files_external', $script); |
|
25 | - } |
|
26 | - } |
|
27 | - foreach ($_['authMechanisms'] as $authMechanism) { |
|
28 | - /** @var AuthMechanism $authMechanism */ |
|
29 | - $scripts = $authMechanism->getCustomJs(); |
|
30 | - foreach ($scripts as $script) { |
|
31 | - script('files_external', $script); |
|
32 | - } |
|
33 | - } |
|
19 | + // load custom JS |
|
20 | + foreach ($_['backends'] as $backend) { |
|
21 | + /** @var Backend $backend */ |
|
22 | + $scripts = $backend->getCustomJs(); |
|
23 | + foreach ($scripts as $script) { |
|
24 | + script('files_external', $script); |
|
25 | + } |
|
26 | + } |
|
27 | + foreach ($_['authMechanisms'] as $authMechanism) { |
|
28 | + /** @var AuthMechanism $authMechanism */ |
|
29 | + $scripts = $authMechanism->getCustomJs(); |
|
30 | + foreach ($scripts as $script) { |
|
31 | + script('files_external', $script); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - function writeParameterInput($parameter, $options, $classes = []) { |
|
36 | - $value = ''; |
|
37 | - if (isset($options[$parameter->getName()])) { |
|
38 | - $value = $options[$parameter->getName()]; |
|
39 | - } |
|
40 | - $placeholder = $parameter->getText(); |
|
41 | - $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
35 | + function writeParameterInput($parameter, $options, $classes = []) { |
|
36 | + $value = ''; |
|
37 | + if (isset($options[$parameter->getName()])) { |
|
38 | + $value = $options[$parameter->getName()]; |
|
39 | + } |
|
40 | + $placeholder = $parameter->getText(); |
|
41 | + $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
42 | 42 | |
43 | - switch ($parameter->getType()) { |
|
44 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
43 | + switch ($parameter->getType()) { |
|
44 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
45 | 45 | <?php if ($is_optional) { $classes[] = 'optional'; } ?> |
46 | 46 | <input type="password" |
47 | 47 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | placeholder="<?php p($placeholder); ?>" |
51 | 51 | /> |
52 | 52 | <?php |
53 | - break; |
|
54 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
53 | + break; |
|
54 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
55 | 55 | <?php $checkboxId = uniqid("checkbox_"); ?> |
56 | 56 | <div> |
57 | 57 | <label> |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | </label> |
66 | 66 | </div> |
67 | 67 | <?php |
68 | - break; |
|
69 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
68 | + break; |
|
69 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
70 | 70 | <input type="hidden" |
71 | 71 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
72 | 72 | data-parameter="<?php p($parameter->getName()); ?>" |
73 | 73 | value="<?php p($value); ?>" |
74 | 74 | /> |
75 | 75 | <?php |
76 | - break; |
|
77 | - default: ?> |
|
76 | + break; |
|
77 | + default: ?> |
|
78 | 78 | <?php if ($is_optional) { $classes[] = 'optional'; } ?> |
79 | 79 | <input type="text" |
80 | 80 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | placeholder="<?php p($placeholder); ?>" |
84 | 84 | /> |
85 | 85 | <?php |
86 | - } |
|
87 | - } |
|
86 | + } |
|
87 | + } |
|
88 | 88 | ?> |
89 | 89 | |
90 | 90 | <form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | <?php p($l->t('Add storage')); ?> |
123 | 123 | </option> |
124 | 124 | <?php |
125 | - $sortedBackends = array_filter($_['backends'], function($backend) use ($_) { |
|
126 | - return $backend->isVisibleFor($_['visibilityType']); |
|
127 | - }); |
|
128 | - uasort($sortedBackends, function($a, $b) { |
|
129 | - return strcasecmp($a->getText(), $b->getText()); |
|
130 | - }); |
|
131 | - ?> |
|
125 | + $sortedBackends = array_filter($_['backends'], function($backend) use ($_) { |
|
126 | + return $backend->isVisibleFor($_['visibilityType']); |
|
127 | + }); |
|
128 | + uasort($sortedBackends, function($a, $b) { |
|
129 | + return strcasecmp($a->getText(), $b->getText()); |
|
130 | + }); |
|
131 | + ?> |
|
132 | 132 | <?php foreach ($sortedBackends as $backend): ?> |
133 | 133 | <?php if ($backend->getDeprecateTo()) continue; // ignore deprecated backends ?> |
134 | 134 | <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option> |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | <p id="userMountingBackends"<?php if ($_['allowUserMounting'] != 'yes'): ?> class="hidden"<?php endif; ?>> |
170 | 170 | <?php p($l->t('Allow users to mount the following external storage')); ?><br /> |
171 | 171 | <?php |
172 | - $userBackends = array_filter($_['backends'], function($backend) { |
|
173 | - return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
174 | - }); |
|
175 | - ?> |
|
172 | + $userBackends = array_filter($_['backends'], function($backend) { |
|
173 | + return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
174 | + }); |
|
175 | + ?> |
|
176 | 176 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
177 | 177 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
178 | 178 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
@@ -33,42 +33,42 @@ |
||
33 | 33 | |
34 | 34 | // FIXME: currently hard-coded to Dropbox OAuth |
35 | 35 | if (isset($_POST['app_key']) && isset($_POST['app_secret'])) { |
36 | - $oauth = new Dropbox_OAuth_Curl((string)$_POST['app_key'], (string)$_POST['app_secret']); |
|
37 | - if (isset($_POST['step'])) { |
|
38 | - switch ($_POST['step']) { |
|
39 | - case 1: |
|
40 | - try { |
|
41 | - if (isset($_POST['callback'])) { |
|
42 | - $callback = (string)$_POST['callback']; |
|
43 | - } else { |
|
44 | - $callback = null; |
|
45 | - } |
|
46 | - $token = $oauth->getRequestToken(); |
|
47 | - OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback), |
|
48 | - 'request_token' => $token['token'], |
|
49 | - 'request_token_secret' => $token['token_secret']))); |
|
50 | - } catch (Exception $exception) { |
|
51 | - OCP\JSON::error(array('data' => array('message' => |
|
52 | - $l->t('Fetching request tokens failed. Verify that your app key and secret are correct.')) |
|
53 | - )); |
|
54 | - } |
|
55 | - break; |
|
56 | - case 2: |
|
57 | - if (isset($_POST['request_token']) && isset($_POST['request_token_secret'])) { |
|
58 | - try { |
|
59 | - $oauth->setToken((string)$_POST['request_token'], (string)$_POST['request_token_secret']); |
|
60 | - $token = $oauth->getAccessToken(); |
|
61 | - OCP\JSON::success(array('access_token' => $token['token'], |
|
62 | - 'access_token_secret' => $token['token_secret'])); |
|
63 | - } catch (Exception $exception) { |
|
64 | - OCP\JSON::error(array('data' => array('message' => |
|
65 | - $l->t('Fetching access tokens failed. Verify that your app key and secret are correct.')) |
|
66 | - )); |
|
67 | - } |
|
68 | - } |
|
69 | - break; |
|
70 | - } |
|
71 | - } |
|
36 | + $oauth = new Dropbox_OAuth_Curl((string)$_POST['app_key'], (string)$_POST['app_secret']); |
|
37 | + if (isset($_POST['step'])) { |
|
38 | + switch ($_POST['step']) { |
|
39 | + case 1: |
|
40 | + try { |
|
41 | + if (isset($_POST['callback'])) { |
|
42 | + $callback = (string)$_POST['callback']; |
|
43 | + } else { |
|
44 | + $callback = null; |
|
45 | + } |
|
46 | + $token = $oauth->getRequestToken(); |
|
47 | + OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback), |
|
48 | + 'request_token' => $token['token'], |
|
49 | + 'request_token_secret' => $token['token_secret']))); |
|
50 | + } catch (Exception $exception) { |
|
51 | + OCP\JSON::error(array('data' => array('message' => |
|
52 | + $l->t('Fetching request tokens failed. Verify that your app key and secret are correct.')) |
|
53 | + )); |
|
54 | + } |
|
55 | + break; |
|
56 | + case 2: |
|
57 | + if (isset($_POST['request_token']) && isset($_POST['request_token_secret'])) { |
|
58 | + try { |
|
59 | + $oauth->setToken((string)$_POST['request_token'], (string)$_POST['request_token_secret']); |
|
60 | + $token = $oauth->getAccessToken(); |
|
61 | + OCP\JSON::success(array('access_token' => $token['token'], |
|
62 | + 'access_token_secret' => $token['token_secret'])); |
|
63 | + } catch (Exception $exception) { |
|
64 | + OCP\JSON::error(array('data' => array('message' => |
|
65 | + $l->t('Fetching access tokens failed. Verify that your app key and secret are correct.')) |
|
66 | + )); |
|
67 | + } |
|
68 | + } |
|
69 | + break; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } else { |
73 | - OCP\JSON::error(array('data' => array('message' => $l->t('Please provide a valid app key and secret.')))); |
|
73 | + OCP\JSON::error(array('data' => array('message' => $l->t('Please provide a valid app key and secret.')))); |
|
74 | 74 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * |
29 | 29 | */ |
30 | 30 | set_include_path(get_include_path().PATH_SEPARATOR. |
31 | - \OC_App::getAppPath('files_external').'/3rdparty/google-api-php-client/src'); |
|
31 | + \OC_App::getAppPath('files_external').'/3rdparty/google-api-php-client/src'); |
|
32 | 32 | require_once 'Google/autoload.php'; |
33 | 33 | |
34 | 34 | OCP\JSON::checkAppEnabled('files_external'); |
@@ -38,37 +38,37 @@ discard block |
||
38 | 38 | |
39 | 39 | // FIXME: currently hard-coded to Google Drive |
40 | 40 | if (isset($_POST['client_id']) && isset($_POST['client_secret']) && isset($_POST['redirect'])) { |
41 | - $client = new Google_Client(); |
|
42 | - $client->setClientId((string)$_POST['client_id']); |
|
43 | - $client->setClientSecret((string)$_POST['client_secret']); |
|
44 | - $client->setRedirectUri((string)$_POST['redirect']); |
|
45 | - $client->setScopes(array('https://www.googleapis.com/auth/drive')); |
|
46 | - $client->setApprovalPrompt('force'); |
|
47 | - $client->setAccessType('offline'); |
|
48 | - if (isset($_POST['step'])) { |
|
49 | - $step = $_POST['step']; |
|
50 | - if ($step == 1) { |
|
51 | - try { |
|
52 | - $authUrl = $client->createAuthUrl(); |
|
53 | - OCP\JSON::success(array('data' => array( |
|
54 | - 'url' => $authUrl |
|
55 | - ))); |
|
56 | - } catch (Exception $exception) { |
|
57 | - OCP\JSON::error(array('data' => array( |
|
58 | - 'message' => $l->t('Step 1 failed. Exception: %s', array($exception->getMessage())) |
|
59 | - ))); |
|
60 | - } |
|
61 | - } else if ($step == 2 && isset($_POST['code'])) { |
|
62 | - try { |
|
63 | - $token = $client->authenticate((string)$_POST['code']); |
|
64 | - OCP\JSON::success(array('data' => array( |
|
65 | - 'token' => $token |
|
66 | - ))); |
|
67 | - } catch (Exception $exception) { |
|
68 | - OCP\JSON::error(array('data' => array( |
|
69 | - 'message' => $l->t('Step 2 failed. Exception: %s', array($exception->getMessage())) |
|
70 | - ))); |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
41 | + $client = new Google_Client(); |
|
42 | + $client->setClientId((string)$_POST['client_id']); |
|
43 | + $client->setClientSecret((string)$_POST['client_secret']); |
|
44 | + $client->setRedirectUri((string)$_POST['redirect']); |
|
45 | + $client->setScopes(array('https://www.googleapis.com/auth/drive')); |
|
46 | + $client->setApprovalPrompt('force'); |
|
47 | + $client->setAccessType('offline'); |
|
48 | + if (isset($_POST['step'])) { |
|
49 | + $step = $_POST['step']; |
|
50 | + if ($step == 1) { |
|
51 | + try { |
|
52 | + $authUrl = $client->createAuthUrl(); |
|
53 | + OCP\JSON::success(array('data' => array( |
|
54 | + 'url' => $authUrl |
|
55 | + ))); |
|
56 | + } catch (Exception $exception) { |
|
57 | + OCP\JSON::error(array('data' => array( |
|
58 | + 'message' => $l->t('Step 1 failed. Exception: %s', array($exception->getMessage())) |
|
59 | + ))); |
|
60 | + } |
|
61 | + } else if ($step == 2 && isset($_POST['code'])) { |
|
62 | + try { |
|
63 | + $token = $client->authenticate((string)$_POST['code']); |
|
64 | + OCP\JSON::success(array('data' => array( |
|
65 | + 'token' => $token |
|
66 | + ))); |
|
67 | + } catch (Exception $exception) { |
|
68 | + OCP\JSON::error(array('data' => array( |
|
69 | + 'message' => $l->t('Step 2 failed. Exception: %s', array($exception->getMessage())) |
|
70 | + ))); |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | 74 | } |
@@ -30,23 +30,23 @@ |
||
30 | 30 | $limit = null; |
31 | 31 | $offset = null; |
32 | 32 | if (isset($_GET['pattern'])) { |
33 | - $pattern = (string)$_GET['pattern']; |
|
33 | + $pattern = (string)$_GET['pattern']; |
|
34 | 34 | } |
35 | 35 | if (isset($_GET['limit'])) { |
36 | - $limit = (int)$_GET['limit']; |
|
36 | + $limit = (int)$_GET['limit']; |
|
37 | 37 | } |
38 | 38 | if (isset($_GET['offset'])) { |
39 | - $offset = (int)$_GET['offset']; |
|
39 | + $offset = (int)$_GET['offset']; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | $groups = []; |
43 | 43 | foreach (\OC::$server->getGroupManager()->search($pattern, $limit, $offset) as $group) { |
44 | - $groups[$group->getGID()] = $group->getGID(); |
|
44 | + $groups[$group->getGID()] = $group->getGID(); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $users = []; |
48 | 48 | foreach (\OC::$server->getUserManager()->searchDisplayName($pattern, $limit, $offset) as $user) { |
49 | - $users[$user->getUID()] = $user->getDisplayName(); |
|
49 | + $users[$user->getUID()] = $user->getDisplayName(); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | $results = array('groups' => $groups, 'users' => $users); |
@@ -24,25 +24,25 @@ |
||
24 | 24 | namespace OCA\Files_External\Service; |
25 | 25 | |
26 | 26 | class ImportLegacyStoragesService extends LegacyStoragesService { |
27 | - private $data; |
|
27 | + private $data; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @param BackendService $backendService |
|
31 | - */ |
|
32 | - public function __construct(BackendService $backendService) { |
|
33 | - $this->backendService = $backendService; |
|
34 | - } |
|
29 | + /** |
|
30 | + * @param BackendService $backendService |
|
31 | + */ |
|
32 | + public function __construct(BackendService $backendService) { |
|
33 | + $this->backendService = $backendService; |
|
34 | + } |
|
35 | 35 | |
36 | - public function setData($data) { |
|
37 | - $this->data = $data; |
|
38 | - } |
|
36 | + public function setData($data) { |
|
37 | + $this->data = $data; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Read legacy config data |
|
42 | - * |
|
43 | - * @return array list of mount configs |
|
44 | - */ |
|
45 | - protected function readLegacyConfig() { |
|
46 | - return $this->data; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Read legacy config data |
|
42 | + * |
|
43 | + * @return array list of mount configs |
|
44 | + */ |
|
45 | + protected function readLegacyConfig() { |
|
46 | + return $this->data; |
|
47 | + } |
|
48 | 48 | } |
@@ -35,249 +35,249 @@ |
||
35 | 35 | */ |
36 | 36 | class BackendService { |
37 | 37 | |
38 | - /** Visibility constants for VisibilityTrait */ |
|
39 | - const VISIBILITY_NONE = 0; |
|
40 | - const VISIBILITY_PERSONAL = 1; |
|
41 | - const VISIBILITY_ADMIN = 2; |
|
42 | - //const VISIBILITY_ALIENS = 4; |
|
43 | - |
|
44 | - const VISIBILITY_DEFAULT = 3; // PERSONAL | ADMIN |
|
45 | - |
|
46 | - /** Priority constants for PriorityTrait */ |
|
47 | - const PRIORITY_DEFAULT = 100; |
|
48 | - |
|
49 | - /** @var IConfig */ |
|
50 | - protected $config; |
|
51 | - |
|
52 | - /** @var bool */ |
|
53 | - private $userMountingAllowed = true; |
|
54 | - |
|
55 | - /** @var string[] */ |
|
56 | - private $userMountingBackends = []; |
|
57 | - |
|
58 | - /** @var Backend[] */ |
|
59 | - private $backends = []; |
|
60 | - |
|
61 | - /** @var IBackendProvider[] */ |
|
62 | - private $backendProviders = []; |
|
63 | - |
|
64 | - /** @var AuthMechanism[] */ |
|
65 | - private $authMechanisms = []; |
|
66 | - |
|
67 | - /** @var IAuthMechanismProvider[] */ |
|
68 | - private $authMechanismProviders = []; |
|
69 | - |
|
70 | - /** |
|
71 | - * @param IConfig $config |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - IConfig $config |
|
75 | - ) { |
|
76 | - $this->config = $config; |
|
77 | - |
|
78 | - // Load config values |
|
79 | - if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') { |
|
80 | - $this->userMountingAllowed = false; |
|
81 | - } |
|
82 | - $this->userMountingBackends = explode(',', |
|
83 | - $this->config->getAppValue('files_external', 'user_mounting_backends', '') |
|
84 | - ); |
|
85 | - |
|
86 | - // if no backend is in the list an empty string is in the array and user mounting is disabled |
|
87 | - if ($this->userMountingBackends === ['']) { |
|
88 | - $this->userMountingAllowed = false; |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Register a backend provider |
|
94 | - * |
|
95 | - * @since 9.1.0 |
|
96 | - * @param IBackendProvider $provider |
|
97 | - */ |
|
98 | - public function registerBackendProvider(IBackendProvider $provider) { |
|
99 | - $this->backendProviders[] = $provider; |
|
100 | - } |
|
101 | - |
|
102 | - private function loadBackendProviders() { |
|
103 | - foreach ($this->backendProviders as $provider) { |
|
104 | - $this->registerBackends($provider->getBackends()); |
|
105 | - } |
|
106 | - $this->backendProviders = []; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Register an auth mechanism provider |
|
111 | - * |
|
112 | - * @since 9.1.0 |
|
113 | - * @param IAuthMechanismProvider $provider |
|
114 | - */ |
|
115 | - public function registerAuthMechanismProvider(IAuthMechanismProvider $provider) { |
|
116 | - $this->authMechanismProviders[] = $provider; |
|
117 | - } |
|
118 | - |
|
119 | - private function loadAuthMechanismProviders() { |
|
120 | - foreach ($this->authMechanismProviders as $provider) { |
|
121 | - $this->registerAuthMechanisms($provider->getAuthMechanisms()); |
|
122 | - } |
|
123 | - $this->authMechanismProviders = []; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Register a backend |
|
128 | - * |
|
129 | - * @deprecated 9.1.0 use registerBackendProvider() |
|
130 | - * @param Backend $backend |
|
131 | - */ |
|
132 | - public function registerBackend(Backend $backend) { |
|
133 | - if (!$this->isAllowedUserBackend($backend)) { |
|
134 | - $backend->removeVisibility(BackendService::VISIBILITY_PERSONAL); |
|
135 | - } |
|
136 | - foreach ($backend->getIdentifierAliases() as $alias) { |
|
137 | - $this->backends[$alias] = $backend; |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @deprecated 9.1.0 use registerBackendProvider() |
|
143 | - * @param Backend[] $backends |
|
144 | - */ |
|
145 | - public function registerBackends(array $backends) { |
|
146 | - foreach ($backends as $backend) { |
|
147 | - $this->registerBackend($backend); |
|
148 | - } |
|
149 | - } |
|
150 | - /** |
|
151 | - * Register an authentication mechanism |
|
152 | - * |
|
153 | - * @deprecated 9.1.0 use registerAuthMechanismProvider() |
|
154 | - * @param AuthMechanism $authMech |
|
155 | - */ |
|
156 | - public function registerAuthMechanism(AuthMechanism $authMech) { |
|
157 | - if (!$this->isAllowedAuthMechanism($authMech)) { |
|
158 | - $authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL); |
|
159 | - } |
|
160 | - foreach ($authMech->getIdentifierAliases() as $alias) { |
|
161 | - $this->authMechanisms[$alias] = $authMech; |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @deprecated 9.1.0 use registerAuthMechanismProvider() |
|
167 | - * @param AuthMechanism[] $mechanisms |
|
168 | - */ |
|
169 | - public function registerAuthMechanisms(array $mechanisms) { |
|
170 | - foreach ($mechanisms as $mechanism) { |
|
171 | - $this->registerAuthMechanism($mechanism); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get all backends |
|
177 | - * |
|
178 | - * @return Backend[] |
|
179 | - */ |
|
180 | - public function getBackends() { |
|
181 | - $this->loadBackendProviders(); |
|
182 | - // only return real identifiers, no aliases |
|
183 | - $backends = []; |
|
184 | - foreach ($this->backends as $backend) { |
|
185 | - $backends[$backend->getIdentifier()] = $backend; |
|
186 | - } |
|
187 | - return $backends; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Get all available backends |
|
192 | - * |
|
193 | - * @return Backend[] |
|
194 | - */ |
|
195 | - public function getAvailableBackends() { |
|
196 | - return array_filter($this->getBackends(), function($backend) { |
|
197 | - return !($backend->checkDependencies()); |
|
198 | - }); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $identifier |
|
203 | - * @return Backend|null |
|
204 | - */ |
|
205 | - public function getBackend($identifier) { |
|
206 | - $this->loadBackendProviders(); |
|
207 | - if (isset($this->backends[$identifier])) { |
|
208 | - return $this->backends[$identifier]; |
|
209 | - } |
|
210 | - return null; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Get all authentication mechanisms |
|
215 | - * |
|
216 | - * @return AuthMechanism[] |
|
217 | - */ |
|
218 | - public function getAuthMechanisms() { |
|
219 | - $this->loadAuthMechanismProviders(); |
|
220 | - // only return real identifiers, no aliases |
|
221 | - $mechanisms = []; |
|
222 | - foreach ($this->authMechanisms as $mechanism) { |
|
223 | - $mechanisms[$mechanism->getIdentifier()] = $mechanism; |
|
224 | - } |
|
225 | - return $mechanisms; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Get all authentication mechanisms for schemes |
|
230 | - * |
|
231 | - * @param string[] $schemes |
|
232 | - * @return AuthMechanism[] |
|
233 | - */ |
|
234 | - public function getAuthMechanismsByScheme(array $schemes) { |
|
235 | - return array_filter($this->getAuthMechanisms(), function($authMech) use ($schemes) { |
|
236 | - return in_array($authMech->getScheme(), $schemes, true); |
|
237 | - }); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * @param string $identifier |
|
242 | - * @return AuthMechanism|null |
|
243 | - */ |
|
244 | - public function getAuthMechanism($identifier) { |
|
245 | - $this->loadAuthMechanismProviders(); |
|
246 | - if (isset($this->authMechanisms[$identifier])) { |
|
247 | - return $this->authMechanisms[$identifier]; |
|
248 | - } |
|
249 | - return null; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - public function isUserMountingAllowed() { |
|
256 | - return $this->userMountingAllowed; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Check a backend if a user is allowed to mount it |
|
261 | - * |
|
262 | - * @param Backend $backend |
|
263 | - * @return bool |
|
264 | - */ |
|
265 | - protected function isAllowedUserBackend(Backend $backend) { |
|
266 | - if ($this->userMountingAllowed && |
|
267 | - array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends) |
|
268 | - ) { |
|
269 | - return true; |
|
270 | - } |
|
271 | - return false; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Check an authentication mechanism if a user is allowed to use it |
|
276 | - * |
|
277 | - * @param AuthMechanism $authMechanism |
|
278 | - * @return bool |
|
279 | - */ |
|
280 | - protected function isAllowedAuthMechanism(AuthMechanism $authMechanism) { |
|
281 | - return true; // not implemented |
|
282 | - } |
|
38 | + /** Visibility constants for VisibilityTrait */ |
|
39 | + const VISIBILITY_NONE = 0; |
|
40 | + const VISIBILITY_PERSONAL = 1; |
|
41 | + const VISIBILITY_ADMIN = 2; |
|
42 | + //const VISIBILITY_ALIENS = 4; |
|
43 | + |
|
44 | + const VISIBILITY_DEFAULT = 3; // PERSONAL | ADMIN |
|
45 | + |
|
46 | + /** Priority constants for PriorityTrait */ |
|
47 | + const PRIORITY_DEFAULT = 100; |
|
48 | + |
|
49 | + /** @var IConfig */ |
|
50 | + protected $config; |
|
51 | + |
|
52 | + /** @var bool */ |
|
53 | + private $userMountingAllowed = true; |
|
54 | + |
|
55 | + /** @var string[] */ |
|
56 | + private $userMountingBackends = []; |
|
57 | + |
|
58 | + /** @var Backend[] */ |
|
59 | + private $backends = []; |
|
60 | + |
|
61 | + /** @var IBackendProvider[] */ |
|
62 | + private $backendProviders = []; |
|
63 | + |
|
64 | + /** @var AuthMechanism[] */ |
|
65 | + private $authMechanisms = []; |
|
66 | + |
|
67 | + /** @var IAuthMechanismProvider[] */ |
|
68 | + private $authMechanismProviders = []; |
|
69 | + |
|
70 | + /** |
|
71 | + * @param IConfig $config |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + IConfig $config |
|
75 | + ) { |
|
76 | + $this->config = $config; |
|
77 | + |
|
78 | + // Load config values |
|
79 | + if ($this->config->getAppValue('files_external', 'allow_user_mounting', 'yes') !== 'yes') { |
|
80 | + $this->userMountingAllowed = false; |
|
81 | + } |
|
82 | + $this->userMountingBackends = explode(',', |
|
83 | + $this->config->getAppValue('files_external', 'user_mounting_backends', '') |
|
84 | + ); |
|
85 | + |
|
86 | + // if no backend is in the list an empty string is in the array and user mounting is disabled |
|
87 | + if ($this->userMountingBackends === ['']) { |
|
88 | + $this->userMountingAllowed = false; |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Register a backend provider |
|
94 | + * |
|
95 | + * @since 9.1.0 |
|
96 | + * @param IBackendProvider $provider |
|
97 | + */ |
|
98 | + public function registerBackendProvider(IBackendProvider $provider) { |
|
99 | + $this->backendProviders[] = $provider; |
|
100 | + } |
|
101 | + |
|
102 | + private function loadBackendProviders() { |
|
103 | + foreach ($this->backendProviders as $provider) { |
|
104 | + $this->registerBackends($provider->getBackends()); |
|
105 | + } |
|
106 | + $this->backendProviders = []; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Register an auth mechanism provider |
|
111 | + * |
|
112 | + * @since 9.1.0 |
|
113 | + * @param IAuthMechanismProvider $provider |
|
114 | + */ |
|
115 | + public function registerAuthMechanismProvider(IAuthMechanismProvider $provider) { |
|
116 | + $this->authMechanismProviders[] = $provider; |
|
117 | + } |
|
118 | + |
|
119 | + private function loadAuthMechanismProviders() { |
|
120 | + foreach ($this->authMechanismProviders as $provider) { |
|
121 | + $this->registerAuthMechanisms($provider->getAuthMechanisms()); |
|
122 | + } |
|
123 | + $this->authMechanismProviders = []; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Register a backend |
|
128 | + * |
|
129 | + * @deprecated 9.1.0 use registerBackendProvider() |
|
130 | + * @param Backend $backend |
|
131 | + */ |
|
132 | + public function registerBackend(Backend $backend) { |
|
133 | + if (!$this->isAllowedUserBackend($backend)) { |
|
134 | + $backend->removeVisibility(BackendService::VISIBILITY_PERSONAL); |
|
135 | + } |
|
136 | + foreach ($backend->getIdentifierAliases() as $alias) { |
|
137 | + $this->backends[$alias] = $backend; |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @deprecated 9.1.0 use registerBackendProvider() |
|
143 | + * @param Backend[] $backends |
|
144 | + */ |
|
145 | + public function registerBackends(array $backends) { |
|
146 | + foreach ($backends as $backend) { |
|
147 | + $this->registerBackend($backend); |
|
148 | + } |
|
149 | + } |
|
150 | + /** |
|
151 | + * Register an authentication mechanism |
|
152 | + * |
|
153 | + * @deprecated 9.1.0 use registerAuthMechanismProvider() |
|
154 | + * @param AuthMechanism $authMech |
|
155 | + */ |
|
156 | + public function registerAuthMechanism(AuthMechanism $authMech) { |
|
157 | + if (!$this->isAllowedAuthMechanism($authMech)) { |
|
158 | + $authMech->removeVisibility(BackendService::VISIBILITY_PERSONAL); |
|
159 | + } |
|
160 | + foreach ($authMech->getIdentifierAliases() as $alias) { |
|
161 | + $this->authMechanisms[$alias] = $authMech; |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @deprecated 9.1.0 use registerAuthMechanismProvider() |
|
167 | + * @param AuthMechanism[] $mechanisms |
|
168 | + */ |
|
169 | + public function registerAuthMechanisms(array $mechanisms) { |
|
170 | + foreach ($mechanisms as $mechanism) { |
|
171 | + $this->registerAuthMechanism($mechanism); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get all backends |
|
177 | + * |
|
178 | + * @return Backend[] |
|
179 | + */ |
|
180 | + public function getBackends() { |
|
181 | + $this->loadBackendProviders(); |
|
182 | + // only return real identifiers, no aliases |
|
183 | + $backends = []; |
|
184 | + foreach ($this->backends as $backend) { |
|
185 | + $backends[$backend->getIdentifier()] = $backend; |
|
186 | + } |
|
187 | + return $backends; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Get all available backends |
|
192 | + * |
|
193 | + * @return Backend[] |
|
194 | + */ |
|
195 | + public function getAvailableBackends() { |
|
196 | + return array_filter($this->getBackends(), function($backend) { |
|
197 | + return !($backend->checkDependencies()); |
|
198 | + }); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $identifier |
|
203 | + * @return Backend|null |
|
204 | + */ |
|
205 | + public function getBackend($identifier) { |
|
206 | + $this->loadBackendProviders(); |
|
207 | + if (isset($this->backends[$identifier])) { |
|
208 | + return $this->backends[$identifier]; |
|
209 | + } |
|
210 | + return null; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Get all authentication mechanisms |
|
215 | + * |
|
216 | + * @return AuthMechanism[] |
|
217 | + */ |
|
218 | + public function getAuthMechanisms() { |
|
219 | + $this->loadAuthMechanismProviders(); |
|
220 | + // only return real identifiers, no aliases |
|
221 | + $mechanisms = []; |
|
222 | + foreach ($this->authMechanisms as $mechanism) { |
|
223 | + $mechanisms[$mechanism->getIdentifier()] = $mechanism; |
|
224 | + } |
|
225 | + return $mechanisms; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Get all authentication mechanisms for schemes |
|
230 | + * |
|
231 | + * @param string[] $schemes |
|
232 | + * @return AuthMechanism[] |
|
233 | + */ |
|
234 | + public function getAuthMechanismsByScheme(array $schemes) { |
|
235 | + return array_filter($this->getAuthMechanisms(), function($authMech) use ($schemes) { |
|
236 | + return in_array($authMech->getScheme(), $schemes, true); |
|
237 | + }); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * @param string $identifier |
|
242 | + * @return AuthMechanism|null |
|
243 | + */ |
|
244 | + public function getAuthMechanism($identifier) { |
|
245 | + $this->loadAuthMechanismProviders(); |
|
246 | + if (isset($this->authMechanisms[$identifier])) { |
|
247 | + return $this->authMechanisms[$identifier]; |
|
248 | + } |
|
249 | + return null; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + public function isUserMountingAllowed() { |
|
256 | + return $this->userMountingAllowed; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Check a backend if a user is allowed to mount it |
|
261 | + * |
|
262 | + * @param Backend $backend |
|
263 | + * @return bool |
|
264 | + */ |
|
265 | + protected function isAllowedUserBackend(Backend $backend) { |
|
266 | + if ($this->userMountingAllowed && |
|
267 | + array_intersect($backend->getIdentifierAliases(), $this->userMountingBackends) |
|
268 | + ) { |
|
269 | + return true; |
|
270 | + } |
|
271 | + return false; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Check an authentication mechanism if a user is allowed to use it |
|
276 | + * |
|
277 | + * @param AuthMechanism $authMechanism |
|
278 | + * @return bool |
|
279 | + */ |
|
280 | + protected function isAllowedAuthMechanism(AuthMechanism $authMechanism) { |
|
281 | + return true; // not implemented |
|
282 | + } |
|
283 | 283 | } |