@@ -46,138 +46,138 @@ |
||
46 | 46 | */ |
47 | 47 | class ConfigAdapter implements IMountProvider { |
48 | 48 | |
49 | - /** @var UserStoragesService */ |
|
50 | - private $userStoragesService; |
|
51 | - |
|
52 | - /** @var UserGlobalStoragesService */ |
|
53 | - private $userGlobalStoragesService; |
|
54 | - |
|
55 | - /** |
|
56 | - * @param UserStoragesService $userStoragesService |
|
57 | - * @param UserGlobalStoragesService $userGlobalStoragesService |
|
58 | - */ |
|
59 | - public function __construct( |
|
60 | - UserStoragesService $userStoragesService, |
|
61 | - UserGlobalStoragesService $userGlobalStoragesService |
|
62 | - ) { |
|
63 | - $this->userStoragesService = $userStoragesService; |
|
64 | - $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Process storage ready for mounting |
|
69 | - * |
|
70 | - * @param StorageConfig $storage |
|
71 | - * @param IUser $user |
|
72 | - * @throws \OCP\AppFramework\QueryException |
|
73 | - */ |
|
74 | - private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { |
|
75 | - foreach ($storage->getBackendOptions() as $option => $value) { |
|
76 | - $storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID())); |
|
77 | - } |
|
78 | - |
|
79 | - $objectStore = $storage->getBackendOption('objectstore'); |
|
80 | - if ($objectStore) { |
|
81 | - $objectClass = $objectStore['class']; |
|
82 | - if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) { |
|
83 | - throw new \InvalidArgumentException('Invalid object store'); |
|
84 | - } |
|
85 | - $storage->setBackendOption('objectstore', new $objectClass($objectStore)); |
|
86 | - } |
|
87 | - |
|
88 | - $storage->getAuthMechanism()->manipulateStorageConfig($storage, $user); |
|
89 | - $storage->getBackend()->manipulateStorageConfig($storage, $user); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Construct the storage implementation |
|
94 | - * |
|
95 | - * @param StorageConfig $storageConfig |
|
96 | - * @return Storage |
|
97 | - */ |
|
98 | - private function constructStorage(StorageConfig $storageConfig) { |
|
99 | - $class = $storageConfig->getBackend()->getStorageClass(); |
|
100 | - $storage = new $class($storageConfig->getBackendOptions()); |
|
101 | - |
|
102 | - // auth mechanism should fire first |
|
103 | - $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
104 | - $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
105 | - |
|
106 | - return $storage; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get all mountpoints applicable for the user |
|
111 | - * |
|
112 | - * @param \OCP\IUser $user |
|
113 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
114 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
115 | - */ |
|
116 | - public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
117 | - $this->userStoragesService->setUser($user); |
|
118 | - $this->userGlobalStoragesService->setUser($user); |
|
119 | - |
|
120 | - $storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser(); |
|
121 | - |
|
122 | - $storages = array_map(function (StorageConfig $storageConfig) use ($user) { |
|
123 | - try { |
|
124 | - $this->prepareStorageConfig($storageConfig, $user); |
|
125 | - return $this->constructStorage($storageConfig); |
|
126 | - } catch (\Exception $e) { |
|
127 | - // propagate exception into filesystem |
|
128 | - return new FailedStorage(['exception' => $e]); |
|
129 | - } |
|
130 | - }, $storageConfigs); |
|
131 | - |
|
132 | - |
|
133 | - \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) { |
|
134 | - return $storage->getId(); |
|
135 | - }, $storages)); |
|
136 | - |
|
137 | - $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) { |
|
138 | - try { |
|
139 | - $availability = $storage->getAvailability(); |
|
140 | - if (!$availability['available'] && !Availability::shouldRecheck($availability)) { |
|
141 | - $storage = new FailedStorage([ |
|
142 | - 'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available') |
|
143 | - ]); |
|
144 | - } |
|
145 | - } catch (\Exception $e) { |
|
146 | - // propagate exception into filesystem |
|
147 | - $storage = new FailedStorage(['exception' => $e]); |
|
148 | - } |
|
149 | - return $storage; |
|
150 | - }, $storages, $storageConfigs); |
|
151 | - |
|
152 | - $mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) { |
|
153 | - if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) { |
|
154 | - return new PersonalMount( |
|
155 | - $this->userStoragesService, |
|
156 | - $storageConfig, |
|
157 | - $storageConfig->getId(), |
|
158 | - $storage, |
|
159 | - '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), |
|
160 | - null, |
|
161 | - $loader, |
|
162 | - $storageConfig->getMountOptions(), |
|
163 | - $storageConfig->getId() |
|
164 | - ); |
|
165 | - } else { |
|
166 | - return new ExternalMountPoint( |
|
167 | - $storageConfig, |
|
168 | - $storage, |
|
169 | - '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), |
|
170 | - null, |
|
171 | - $loader, |
|
172 | - $storageConfig->getMountOptions(), |
|
173 | - $storageConfig->getId() |
|
174 | - ); |
|
175 | - } |
|
176 | - }, $storageConfigs, $availableStorages); |
|
177 | - |
|
178 | - $this->userStoragesService->resetUser(); |
|
179 | - $this->userGlobalStoragesService->resetUser(); |
|
180 | - |
|
181 | - return $mounts; |
|
182 | - } |
|
49 | + /** @var UserStoragesService */ |
|
50 | + private $userStoragesService; |
|
51 | + |
|
52 | + /** @var UserGlobalStoragesService */ |
|
53 | + private $userGlobalStoragesService; |
|
54 | + |
|
55 | + /** |
|
56 | + * @param UserStoragesService $userStoragesService |
|
57 | + * @param UserGlobalStoragesService $userGlobalStoragesService |
|
58 | + */ |
|
59 | + public function __construct( |
|
60 | + UserStoragesService $userStoragesService, |
|
61 | + UserGlobalStoragesService $userGlobalStoragesService |
|
62 | + ) { |
|
63 | + $this->userStoragesService = $userStoragesService; |
|
64 | + $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Process storage ready for mounting |
|
69 | + * |
|
70 | + * @param StorageConfig $storage |
|
71 | + * @param IUser $user |
|
72 | + * @throws \OCP\AppFramework\QueryException |
|
73 | + */ |
|
74 | + private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { |
|
75 | + foreach ($storage->getBackendOptions() as $option => $value) { |
|
76 | + $storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID())); |
|
77 | + } |
|
78 | + |
|
79 | + $objectStore = $storage->getBackendOption('objectstore'); |
|
80 | + if ($objectStore) { |
|
81 | + $objectClass = $objectStore['class']; |
|
82 | + if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) { |
|
83 | + throw new \InvalidArgumentException('Invalid object store'); |
|
84 | + } |
|
85 | + $storage->setBackendOption('objectstore', new $objectClass($objectStore)); |
|
86 | + } |
|
87 | + |
|
88 | + $storage->getAuthMechanism()->manipulateStorageConfig($storage, $user); |
|
89 | + $storage->getBackend()->manipulateStorageConfig($storage, $user); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Construct the storage implementation |
|
94 | + * |
|
95 | + * @param StorageConfig $storageConfig |
|
96 | + * @return Storage |
|
97 | + */ |
|
98 | + private function constructStorage(StorageConfig $storageConfig) { |
|
99 | + $class = $storageConfig->getBackend()->getStorageClass(); |
|
100 | + $storage = new $class($storageConfig->getBackendOptions()); |
|
101 | + |
|
102 | + // auth mechanism should fire first |
|
103 | + $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
104 | + $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
105 | + |
|
106 | + return $storage; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get all mountpoints applicable for the user |
|
111 | + * |
|
112 | + * @param \OCP\IUser $user |
|
113 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
114 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
115 | + */ |
|
116 | + public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
117 | + $this->userStoragesService->setUser($user); |
|
118 | + $this->userGlobalStoragesService->setUser($user); |
|
119 | + |
|
120 | + $storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser(); |
|
121 | + |
|
122 | + $storages = array_map(function (StorageConfig $storageConfig) use ($user) { |
|
123 | + try { |
|
124 | + $this->prepareStorageConfig($storageConfig, $user); |
|
125 | + return $this->constructStorage($storageConfig); |
|
126 | + } catch (\Exception $e) { |
|
127 | + // propagate exception into filesystem |
|
128 | + return new FailedStorage(['exception' => $e]); |
|
129 | + } |
|
130 | + }, $storageConfigs); |
|
131 | + |
|
132 | + |
|
133 | + \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) { |
|
134 | + return $storage->getId(); |
|
135 | + }, $storages)); |
|
136 | + |
|
137 | + $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) { |
|
138 | + try { |
|
139 | + $availability = $storage->getAvailability(); |
|
140 | + if (!$availability['available'] && !Availability::shouldRecheck($availability)) { |
|
141 | + $storage = new FailedStorage([ |
|
142 | + 'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available') |
|
143 | + ]); |
|
144 | + } |
|
145 | + } catch (\Exception $e) { |
|
146 | + // propagate exception into filesystem |
|
147 | + $storage = new FailedStorage(['exception' => $e]); |
|
148 | + } |
|
149 | + return $storage; |
|
150 | + }, $storages, $storageConfigs); |
|
151 | + |
|
152 | + $mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) { |
|
153 | + if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) { |
|
154 | + return new PersonalMount( |
|
155 | + $this->userStoragesService, |
|
156 | + $storageConfig, |
|
157 | + $storageConfig->getId(), |
|
158 | + $storage, |
|
159 | + '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), |
|
160 | + null, |
|
161 | + $loader, |
|
162 | + $storageConfig->getMountOptions(), |
|
163 | + $storageConfig->getId() |
|
164 | + ); |
|
165 | + } else { |
|
166 | + return new ExternalMountPoint( |
|
167 | + $storageConfig, |
|
168 | + $storage, |
|
169 | + '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), |
|
170 | + null, |
|
171 | + $loader, |
|
172 | + $storageConfig->getMountOptions(), |
|
173 | + $storageConfig->getId() |
|
174 | + ); |
|
175 | + } |
|
176 | + }, $storageConfigs, $availableStorages); |
|
177 | + |
|
178 | + $this->userStoragesService->resetUser(); |
|
179 | + $this->userGlobalStoragesService->resetUser(); |
|
180 | + |
|
181 | + return $mounts; |
|
182 | + } |
|
183 | 183 | } |
@@ -54,237 +54,237 @@ |
||
54 | 54 | * Class to configure mount.json globally and for users |
55 | 55 | */ |
56 | 56 | class MountConfig { |
57 | - // TODO: make this class non-static and give it a proper namespace |
|
57 | + // TODO: make this class non-static and give it a proper namespace |
|
58 | 58 | |
59 | - public const MOUNT_TYPE_GLOBAL = 'global'; |
|
60 | - public const MOUNT_TYPE_GROUP = 'group'; |
|
61 | - public const MOUNT_TYPE_USER = 'user'; |
|
62 | - public const MOUNT_TYPE_PERSONAL = 'personal'; |
|
59 | + public const MOUNT_TYPE_GLOBAL = 'global'; |
|
60 | + public const MOUNT_TYPE_GROUP = 'group'; |
|
61 | + public const MOUNT_TYPE_USER = 'user'; |
|
62 | + public const MOUNT_TYPE_PERSONAL = 'personal'; |
|
63 | 63 | |
64 | - // whether to skip backend test (for unit tests, as this static class is not mockable) |
|
65 | - public static $skipTest = false; |
|
64 | + // whether to skip backend test (for unit tests, as this static class is not mockable) |
|
65 | + public static $skipTest = false; |
|
66 | 66 | |
67 | - /** @var UserGlobalStoragesService */ |
|
68 | - private $userGlobalStorageService; |
|
69 | - /** @var UserStoragesService */ |
|
70 | - private $userStorageService; |
|
71 | - /** @var GlobalStoragesService */ |
|
72 | - private $globalStorageService; |
|
67 | + /** @var UserGlobalStoragesService */ |
|
68 | + private $userGlobalStorageService; |
|
69 | + /** @var UserStoragesService */ |
|
70 | + private $userStorageService; |
|
71 | + /** @var GlobalStoragesService */ |
|
72 | + private $globalStorageService; |
|
73 | 73 | |
74 | - public function __construct( |
|
75 | - UserGlobalStoragesService $userGlobalStorageService, |
|
76 | - UserStoragesService $userStorageService, |
|
77 | - GlobalStoragesService $globalStorageService |
|
78 | - ) { |
|
79 | - $this->userGlobalStorageService = $userGlobalStorageService; |
|
80 | - $this->userStorageService = $userStorageService; |
|
81 | - $this->globalStorageService = $globalStorageService; |
|
82 | - } |
|
74 | + public function __construct( |
|
75 | + UserGlobalStoragesService $userGlobalStorageService, |
|
76 | + UserStoragesService $userStorageService, |
|
77 | + GlobalStoragesService $globalStorageService |
|
78 | + ) { |
|
79 | + $this->userGlobalStorageService = $userGlobalStorageService; |
|
80 | + $this->userStorageService = $userStorageService; |
|
81 | + $this->globalStorageService = $globalStorageService; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @param mixed $input |
|
86 | - * @param string|null $userId |
|
87 | - * @return mixed |
|
88 | - * @throws \OCP\AppFramework\QueryException |
|
89 | - * @since 16.0.0 |
|
90 | - */ |
|
91 | - public static function substitutePlaceholdersInConfig($input, string $userId = null) { |
|
92 | - /** @var BackendService $backendService */ |
|
93 | - $backendService = \OC::$server->get(BackendService::class); |
|
94 | - /** @var IConfigHandler[] $handlers */ |
|
95 | - $handlers = $backendService->getConfigHandlers(); |
|
96 | - foreach ($handlers as $handler) { |
|
97 | - if ($handler instanceof UserContext && $userId !== null) { |
|
98 | - $handler->setUserId($userId); |
|
99 | - } |
|
100 | - $input = $handler->handle($input); |
|
101 | - } |
|
102 | - return $input; |
|
103 | - } |
|
84 | + /** |
|
85 | + * @param mixed $input |
|
86 | + * @param string|null $userId |
|
87 | + * @return mixed |
|
88 | + * @throws \OCP\AppFramework\QueryException |
|
89 | + * @since 16.0.0 |
|
90 | + */ |
|
91 | + public static function substitutePlaceholdersInConfig($input, string $userId = null) { |
|
92 | + /** @var BackendService $backendService */ |
|
93 | + $backendService = \OC::$server->get(BackendService::class); |
|
94 | + /** @var IConfigHandler[] $handlers */ |
|
95 | + $handlers = $backendService->getConfigHandlers(); |
|
96 | + foreach ($handlers as $handler) { |
|
97 | + if ($handler instanceof UserContext && $userId !== null) { |
|
98 | + $handler->setUserId($userId); |
|
99 | + } |
|
100 | + $input = $handler->handle($input); |
|
101 | + } |
|
102 | + return $input; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Test connecting using the given backend configuration |
|
107 | - * |
|
108 | - * @param string $class backend class name |
|
109 | - * @param array $options backend configuration options |
|
110 | - * @param boolean $isPersonal |
|
111 | - * @return int see self::STATUS_* |
|
112 | - * @throws \Exception |
|
113 | - */ |
|
114 | - public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) { |
|
115 | - if (self::$skipTest) { |
|
116 | - return StorageNotAvailableException::STATUS_SUCCESS; |
|
117 | - } |
|
118 | - foreach ($options as $key => &$option) { |
|
119 | - if ($key === 'password') { |
|
120 | - // no replacements in passwords |
|
121 | - continue; |
|
122 | - } |
|
123 | - $option = self::substitutePlaceholdersInConfig($option); |
|
124 | - } |
|
125 | - if (class_exists($class)) { |
|
126 | - try { |
|
127 | - /** @var \OC\Files\Storage\Common $storage */ |
|
128 | - $storage = new $class($options); |
|
105 | + /** |
|
106 | + * Test connecting using the given backend configuration |
|
107 | + * |
|
108 | + * @param string $class backend class name |
|
109 | + * @param array $options backend configuration options |
|
110 | + * @param boolean $isPersonal |
|
111 | + * @return int see self::STATUS_* |
|
112 | + * @throws \Exception |
|
113 | + */ |
|
114 | + public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) { |
|
115 | + if (self::$skipTest) { |
|
116 | + return StorageNotAvailableException::STATUS_SUCCESS; |
|
117 | + } |
|
118 | + foreach ($options as $key => &$option) { |
|
119 | + if ($key === 'password') { |
|
120 | + // no replacements in passwords |
|
121 | + continue; |
|
122 | + } |
|
123 | + $option = self::substitutePlaceholdersInConfig($option); |
|
124 | + } |
|
125 | + if (class_exists($class)) { |
|
126 | + try { |
|
127 | + /** @var \OC\Files\Storage\Common $storage */ |
|
128 | + $storage = new $class($options); |
|
129 | 129 | |
130 | - try { |
|
131 | - $result = $storage->test($isPersonal, $testOnly); |
|
132 | - $storage->setAvailability($result); |
|
133 | - if ($result) { |
|
134 | - return StorageNotAvailableException::STATUS_SUCCESS; |
|
135 | - } |
|
136 | - } catch (\Exception $e) { |
|
137 | - $storage->setAvailability(false); |
|
138 | - throw $e; |
|
139 | - } |
|
140 | - } catch (\Exception $exception) { |
|
141 | - \OC::$server->getLogger()->logException($exception, ['app' => 'files_external']); |
|
142 | - throw $exception; |
|
143 | - } |
|
144 | - } |
|
145 | - return StorageNotAvailableException::STATUS_ERROR; |
|
146 | - } |
|
130 | + try { |
|
131 | + $result = $storage->test($isPersonal, $testOnly); |
|
132 | + $storage->setAvailability($result); |
|
133 | + if ($result) { |
|
134 | + return StorageNotAvailableException::STATUS_SUCCESS; |
|
135 | + } |
|
136 | + } catch (\Exception $e) { |
|
137 | + $storage->setAvailability(false); |
|
138 | + throw $e; |
|
139 | + } |
|
140 | + } catch (\Exception $exception) { |
|
141 | + \OC::$server->getLogger()->logException($exception, ['app' => 'files_external']); |
|
142 | + throw $exception; |
|
143 | + } |
|
144 | + } |
|
145 | + return StorageNotAvailableException::STATUS_ERROR; |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * Get backend dependency message |
|
150 | - * TODO: move into AppFramework along with templates |
|
151 | - * |
|
152 | - * @param Backend[] $backends |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public static function dependencyMessage($backends) { |
|
156 | - $l = \OC::$server->getL10N('files_external'); |
|
157 | - $message = ''; |
|
158 | - $dependencyGroups = []; |
|
148 | + /** |
|
149 | + * Get backend dependency message |
|
150 | + * TODO: move into AppFramework along with templates |
|
151 | + * |
|
152 | + * @param Backend[] $backends |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public static function dependencyMessage($backends) { |
|
156 | + $l = \OC::$server->getL10N('files_external'); |
|
157 | + $message = ''; |
|
158 | + $dependencyGroups = []; |
|
159 | 159 | |
160 | - foreach ($backends as $backend) { |
|
161 | - foreach ($backend->checkDependencies() as $dependency) { |
|
162 | - if ($message = $dependency->getMessage()) { |
|
163 | - $message .= '<p>' . $message . '</p>'; |
|
164 | - } else { |
|
165 | - $dependencyGroups[$dependency->getDependency()][] = $backend; |
|
166 | - } |
|
167 | - } |
|
168 | - } |
|
160 | + foreach ($backends as $backend) { |
|
161 | + foreach ($backend->checkDependencies() as $dependency) { |
|
162 | + if ($message = $dependency->getMessage()) { |
|
163 | + $message .= '<p>' . $message . '</p>'; |
|
164 | + } else { |
|
165 | + $dependencyGroups[$dependency->getDependency()][] = $backend; |
|
166 | + } |
|
167 | + } |
|
168 | + } |
|
169 | 169 | |
170 | - foreach ($dependencyGroups as $module => $dependants) { |
|
171 | - $backends = implode(', ', array_map(function ($backend) { |
|
172 | - return '"' . $backend->getText() . '"'; |
|
173 | - }, $dependants)); |
|
174 | - $message .= '<p>' . MountConfig::getSingleDependencyMessage($l, $module, $backends) . '</p>'; |
|
175 | - } |
|
170 | + foreach ($dependencyGroups as $module => $dependants) { |
|
171 | + $backends = implode(', ', array_map(function ($backend) { |
|
172 | + return '"' . $backend->getText() . '"'; |
|
173 | + }, $dependants)); |
|
174 | + $message .= '<p>' . MountConfig::getSingleDependencyMessage($l, $module, $backends) . '</p>'; |
|
175 | + } |
|
176 | 176 | |
177 | - return $message; |
|
178 | - } |
|
177 | + return $message; |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Returns a dependency missing message |
|
182 | - * |
|
183 | - * @param \OCP\IL10N $l |
|
184 | - * @param string $module |
|
185 | - * @param string $backend |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) { |
|
189 | - switch (strtolower($module)) { |
|
190 | - case 'curl': |
|
191 | - return $l->t('The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', [$backend]); |
|
192 | - case 'ftp': |
|
193 | - return $l->t('The FTP support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', [$backend]); |
|
194 | - default: |
|
195 | - return $l->t('"%1$s" is not installed. Mounting of %2$s is not possible. Please ask your system administrator to install it.', [$module, $backend]); |
|
196 | - } |
|
197 | - } |
|
180 | + /** |
|
181 | + * Returns a dependency missing message |
|
182 | + * |
|
183 | + * @param \OCP\IL10N $l |
|
184 | + * @param string $module |
|
185 | + * @param string $backend |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) { |
|
189 | + switch (strtolower($module)) { |
|
190 | + case 'curl': |
|
191 | + return $l->t('The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', [$backend]); |
|
192 | + case 'ftp': |
|
193 | + return $l->t('The FTP support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', [$backend]); |
|
194 | + default: |
|
195 | + return $l->t('"%1$s" is not installed. Mounting of %2$s is not possible. Please ask your system administrator to install it.', [$module, $backend]); |
|
196 | + } |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * Encrypt passwords in the given config options |
|
201 | - * |
|
202 | - * @param array $options mount options |
|
203 | - * @return array updated options |
|
204 | - */ |
|
205 | - public static function encryptPasswords($options) { |
|
206 | - if (isset($options['password'])) { |
|
207 | - $options['password_encrypted'] = self::encryptPassword($options['password']); |
|
208 | - // do not unset the password, we want to keep the keys order |
|
209 | - // on load... because that's how the UI currently works |
|
210 | - $options['password'] = ''; |
|
211 | - } |
|
212 | - return $options; |
|
213 | - } |
|
199 | + /** |
|
200 | + * Encrypt passwords in the given config options |
|
201 | + * |
|
202 | + * @param array $options mount options |
|
203 | + * @return array updated options |
|
204 | + */ |
|
205 | + public static function encryptPasswords($options) { |
|
206 | + if (isset($options['password'])) { |
|
207 | + $options['password_encrypted'] = self::encryptPassword($options['password']); |
|
208 | + // do not unset the password, we want to keep the keys order |
|
209 | + // on load... because that's how the UI currently works |
|
210 | + $options['password'] = ''; |
|
211 | + } |
|
212 | + return $options; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Decrypt passwords in the given config options |
|
217 | - * |
|
218 | - * @param array $options mount options |
|
219 | - * @return array updated options |
|
220 | - */ |
|
221 | - public static function decryptPasswords($options) { |
|
222 | - // note: legacy options might still have the unencrypted password in the "password" field |
|
223 | - if (isset($options['password_encrypted'])) { |
|
224 | - $options['password'] = self::decryptPassword($options['password_encrypted']); |
|
225 | - unset($options['password_encrypted']); |
|
226 | - } |
|
227 | - return $options; |
|
228 | - } |
|
215 | + /** |
|
216 | + * Decrypt passwords in the given config options |
|
217 | + * |
|
218 | + * @param array $options mount options |
|
219 | + * @return array updated options |
|
220 | + */ |
|
221 | + public static function decryptPasswords($options) { |
|
222 | + // note: legacy options might still have the unencrypted password in the "password" field |
|
223 | + if (isset($options['password_encrypted'])) { |
|
224 | + $options['password'] = self::decryptPassword($options['password_encrypted']); |
|
225 | + unset($options['password_encrypted']); |
|
226 | + } |
|
227 | + return $options; |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * Encrypt a single password |
|
232 | - * |
|
233 | - * @param string $password plain text password |
|
234 | - * @return string encrypted password |
|
235 | - */ |
|
236 | - private static function encryptPassword($password) { |
|
237 | - $cipher = self::getCipher(); |
|
238 | - $iv = \OC::$server->getSecureRandom()->generate(16); |
|
239 | - $cipher->setIV($iv); |
|
240 | - return base64_encode($iv . $cipher->encrypt($password)); |
|
241 | - } |
|
230 | + /** |
|
231 | + * Encrypt a single password |
|
232 | + * |
|
233 | + * @param string $password plain text password |
|
234 | + * @return string encrypted password |
|
235 | + */ |
|
236 | + private static function encryptPassword($password) { |
|
237 | + $cipher = self::getCipher(); |
|
238 | + $iv = \OC::$server->getSecureRandom()->generate(16); |
|
239 | + $cipher->setIV($iv); |
|
240 | + return base64_encode($iv . $cipher->encrypt($password)); |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Decrypts a single password |
|
245 | - * |
|
246 | - * @param string $encryptedPassword encrypted password |
|
247 | - * @return string plain text password |
|
248 | - */ |
|
249 | - private static function decryptPassword($encryptedPassword) { |
|
250 | - $cipher = self::getCipher(); |
|
251 | - $binaryPassword = base64_decode($encryptedPassword); |
|
252 | - $iv = substr($binaryPassword, 0, 16); |
|
253 | - $cipher->setIV($iv); |
|
254 | - $binaryPassword = substr($binaryPassword, 16); |
|
255 | - return $cipher->decrypt($binaryPassword); |
|
256 | - } |
|
243 | + /** |
|
244 | + * Decrypts a single password |
|
245 | + * |
|
246 | + * @param string $encryptedPassword encrypted password |
|
247 | + * @return string plain text password |
|
248 | + */ |
|
249 | + private static function decryptPassword($encryptedPassword) { |
|
250 | + $cipher = self::getCipher(); |
|
251 | + $binaryPassword = base64_decode($encryptedPassword); |
|
252 | + $iv = substr($binaryPassword, 0, 16); |
|
253 | + $cipher->setIV($iv); |
|
254 | + $binaryPassword = substr($binaryPassword, 16); |
|
255 | + return $cipher->decrypt($binaryPassword); |
|
256 | + } |
|
257 | 257 | |
258 | - /** |
|
259 | - * Returns the encryption cipher |
|
260 | - * |
|
261 | - * @return AES |
|
262 | - */ |
|
263 | - private static function getCipher() { |
|
264 | - $cipher = new AES(AES::MODE_CBC); |
|
265 | - $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null)); |
|
266 | - return $cipher; |
|
267 | - } |
|
258 | + /** |
|
259 | + * Returns the encryption cipher |
|
260 | + * |
|
261 | + * @return AES |
|
262 | + */ |
|
263 | + private static function getCipher() { |
|
264 | + $cipher = new AES(AES::MODE_CBC); |
|
265 | + $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null)); |
|
266 | + return $cipher; |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
270 | - * Computes a hash based on the given configuration. |
|
271 | - * This is mostly used to find out whether configurations |
|
272 | - * are the same. |
|
273 | - * |
|
274 | - * @param array $config |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - public static function makeConfigHash($config) { |
|
278 | - $data = json_encode( |
|
279 | - [ |
|
280 | - 'c' => $config['backend'], |
|
281 | - 'a' => $config['authMechanism'], |
|
282 | - 'm' => $config['mountpoint'], |
|
283 | - 'o' => $config['options'], |
|
284 | - 'p' => isset($config['priority']) ? $config['priority'] : -1, |
|
285 | - 'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [], |
|
286 | - ] |
|
287 | - ); |
|
288 | - return hash('md5', $data); |
|
289 | - } |
|
269 | + /** |
|
270 | + * Computes a hash based on the given configuration. |
|
271 | + * This is mostly used to find out whether configurations |
|
272 | + * are the same. |
|
273 | + * |
|
274 | + * @param array $config |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + public static function makeConfigHash($config) { |
|
278 | + $data = json_encode( |
|
279 | + [ |
|
280 | + 'c' => $config['backend'], |
|
281 | + 'a' => $config['authMechanism'], |
|
282 | + 'm' => $config['mountpoint'], |
|
283 | + 'o' => $config['options'], |
|
284 | + 'p' => isset($config['priority']) ? $config['priority'] : -1, |
|
285 | + 'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [], |
|
286 | + ] |
|
287 | + ); |
|
288 | + return hash('md5', $data); |
|
289 | + } |
|
290 | 290 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | foreach ($backends as $backend) { |
161 | 161 | foreach ($backend->checkDependencies() as $dependency) { |
162 | 162 | if ($message = $dependency->getMessage()) { |
163 | - $message .= '<p>' . $message . '</p>'; |
|
163 | + $message .= '<p>'.$message.'</p>'; |
|
164 | 164 | } else { |
165 | 165 | $dependencyGroups[$dependency->getDependency()][] = $backend; |
166 | 166 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | foreach ($dependencyGroups as $module => $dependants) { |
171 | - $backends = implode(', ', array_map(function ($backend) { |
|
172 | - return '"' . $backend->getText() . '"'; |
|
171 | + $backends = implode(', ', array_map(function($backend) { |
|
172 | + return '"'.$backend->getText().'"'; |
|
173 | 173 | }, $dependants)); |
174 | - $message .= '<p>' . MountConfig::getSingleDependencyMessage($l, $module, $backends) . '</p>'; |
|
174 | + $message .= '<p>'.MountConfig::getSingleDependencyMessage($l, $module, $backends).'</p>'; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | return $message; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $cipher = self::getCipher(); |
238 | 238 | $iv = \OC::$server->getSecureRandom()->generate(16); |
239 | 239 | $cipher->setIV($iv); |
240 | - return base64_encode($iv . $cipher->encrypt($password)); |
|
240 | + return base64_encode($iv.$cipher->encrypt($password)); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |