diff options
Diffstat (limited to 'apps/files_external/lib/config.php')
-rw-r--r-- | apps/files_external/lib/config.php | 67 |
1 files changed, 54 insertions, 13 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 7fb118c2de5..65e8ae387bd 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -3,6 +3,7 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Andreas Fischer <bantu@owncloud.com> + * @author Arthur Schiwon <blizzz@arthur-schiwon.de> * @author Bart Visscher <bartv@thisnet.nl> * @author Björn Schießle <bjoern@schiessle.org> * @author Frank Karlitschek <frank@karlitschek.de> @@ -35,6 +36,8 @@ * */ +use OCA\Files_External\Config\IConfigHandler; +use OCA\Files_External\Config\UserPlaceholderHandler; use phpseclib\Crypt\AES; use \OCA\Files_External\AppInfo\Application; use \OCA\Files_External\Lib\Backend\LegacyBackend; @@ -104,7 +107,7 @@ class OC_Mount_Config { $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); $mountEntry = self::prepareMountPointEntry($storage, false); foreach ($mountEntry['options'] as &$option) { - $option = self::setUserVars($uid, $option); + $option = self::substitutePlaceholdersInConfig($option); } $mountPoints[$mountPoint] = $mountEntry; } @@ -113,7 +116,7 @@ class OC_Mount_Config { $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); $mountEntry = self::prepareMountPointEntry($storage, true); foreach ($mountEntry['options'] as &$option) { - $option = self::setUserVars($uid, $option); + $option = self::substitutePlaceholdersInConfig($uid, $option); } $mountPoints[$mountPoint] = $mountEntry; } @@ -199,18 +202,26 @@ class OC_Mount_Config { * @param string $user user value * @param string|array $input * @return string + * @deprecated use self::substitutePlaceholdersInConfig($input) */ public static function setUserVars($user, $input) { - if (is_array($input)) { - foreach ($input as &$value) { - if (is_string($value)) { - $value = str_replace('$user', $user, $value); - } - } - } else { - if (is_string($input)) { - $input = str_replace('$user', $user, $input); - } + $handler = self::$app->getContainer()->query(UserPlaceholderHandler::class); + return $handler->handle($input); + } + + /** + * @param mixed $input + * @return mixed + * @throws \OCP\AppFramework\QueryException + * @since 16.0.0 + */ + public static function substitutePlaceholdersInConfig($input) { + /** @var BackendService $backendService */ + $backendService = self::$app->getContainer()->query(BackendService::class); + /** @var IConfigHandler[] $handlers */ + $handlers = $backendService->getConfigHandlers(); + foreach ($handlers as $handler) { + $input = $handler->handle($input); } return $input; } @@ -229,7 +240,21 @@ class OC_Mount_Config { return StorageNotAvailableException::STATUS_SUCCESS; } foreach ($options as &$option) { - $option = self::setUserVars(OCP\User::getUser(), $option); + $option = self::substitutePlaceholdersInConfig($option); + if(!self::arePlaceholdersSubstituted($option)) { + \OC::$server->getLogger()->error( + 'A placeholder was not substituted: {option} for mount type {class}', + [ + 'app' => 'files_external', + 'option' => $option, + 'class' => $class, + ] + ); + throw new StorageNotAvailableException( + 'Mount configuration incomplete', + StorageNotAvailableException::STATUS_INCOMPLETE_CONF + ); + } } if (class_exists($class)) { try { @@ -254,6 +279,22 @@ class OC_Mount_Config { return StorageNotAvailableException::STATUS_ERROR; } + public static function arePlaceholdersSubstituted($option):bool { + $result = true; + if(is_array($option)) { + foreach ($option as $optionItem) { + if(is_array($optionItem)) { + $result = $result && self::arePlaceholdersSubstituted($option); + } + } + } else if (is_string($option)) { + if (strpos($option, '$') !== false) { + $result = false; + } + } + return $result; + } + /** * Read the mount points in the config file into an array * |