]> source.dussan.org Git - nextcloud-server.git/commitdiff
Move OC_Mount_Config to proper classname and remove OC::$CLASSPATH usage in files_ext... 21785/head
authorMorris Jobke <hey@morrisjobke.de>
Thu, 9 Jul 2020 21:39:58 +0000 (23:39 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Thu, 9 Jul 2020 22:02:59 +0000 (00:02 +0200)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
24 files changed:
apps/files_external/appinfo/app.php
apps/files_external/appinfo/routes.php
apps/files_external/js/settings.js
apps/files_external/lib/Command/Verify.php
apps/files_external/lib/Config/ConfigAdapter.php
apps/files_external/lib/Controller/ApiController.php
apps/files_external/lib/Controller/StoragesController.php
apps/files_external/lib/Lib/Backend/LegacyBackend.php
apps/files_external/lib/MountConfig.php [new file with mode: 0644]
apps/files_external/lib/Service/GlobalStoragesService.php
apps/files_external/lib/Service/LegacyStoragesService.php
apps/files_external/lib/Service/UserLegacyStoragesService.php
apps/files_external/lib/Service/UserStoragesService.php
apps/files_external/lib/Settings/Admin.php
apps/files_external/lib/Settings/Personal.php
apps/files_external/lib/config.php [deleted file]
apps/files_external/tests/Controller/StoragesControllerTest.php
apps/files_external/tests/Service/GlobalStoragesServiceTest.php
apps/files_external/tests/Service/StoragesServiceTest.php
apps/files_external/tests/Service/UserStoragesServiceTest.php
apps/files_external/tests/Settings/AdminTest.php
lib/private/Encryption/File.php
lib/private/Encryption/Util.php
lib/private/Log/ExceptionSerializer.php

index 861096953530475c4518498f10abe883b5c0e352..96699d4635ebf7b524e353c22ccae8465357a94a 100644 (file)
 
 use OCA\Files_External\Config\ConfigAdapter;
 
-OC::$CLASSPATH['OC_Mount_Config'] = 'files_external/lib/config.php';
-
 require_once __DIR__ . '/../3rdparty/autoload.php';
 
 // register Application object singleton
-\OC_Mount_Config::$app = \OC::$server->query(\OCA\Files_External\AppInfo\Application::class);
-\OC_Mount_Config::$app->registerListeners();
+\OCA\Files_External\MountConfig::$app = \OC::$server->query(\OCA\Files_External\AppInfo\Application::class);
+\OCA\Files_External\MountConfig::$app->registerListeners();
 
-$appContainer = \OC_Mount_Config::$app->getContainer();
+$appContainer = \OCA\Files_External\MountConfig::$app->getContainer();
 
 \OCA\Files\App::getNavigationManager()->add(function () {
        $l = \OC::$server->getL10N('files_external');
index 743c0b101f8770a3818565a525e102d6e35eeb21..9085ca9f7db30cbcd9d1dd6d21a71488d4f891ab 100644 (file)
@@ -30,7 +30,7 @@
 /**
  * @var $this \OCP\Route\IRouter
  **/
-\OC_Mount_Config::$app->registerRoutes(
+\OCA\Files_External\MountConfig::$app->registerRoutes(
        $this,
        [
                'resources' => [
index 93a27d5f75dd0752e4acdaea31d6f2325cf10a70..dff352eea3dee65563a93b302ed7a5e49f88f91c 100644 (file)
@@ -171,7 +171,7 @@ var StorageConfig = function(id) {
        this.id = id;
        this.backendOptions = {};
 };
-// Keep this in sync with \OC_Mount_Config::STATUS_*
+// Keep this in sync with \OCA\Files_External\MountConfig::STATUS_*
 StorageConfig.Status = {
        IN_PROGRESS: -1,
        SUCCESS: 0,
index e5bfb3052eead4b85fac8cce1b2be3da4885fab7..dbc6960e969ac3e80d775449c2b8e7984995dc4d 100644 (file)
@@ -118,7 +118,7 @@ class Verify extends Base {
                        $backend = $storage->getBackend();
                        // update status (can be time-consuming)
                        $storage->setStatus(
-                               \OC_Mount_Config::getBackendStatus(
+                               \OCA\Files_External\MountConfig::getBackendStatus(
                                        $backend->getStorageClass(),
                                        $storage->getBackendOptions(),
                                        false
index fa33f3de793fa22f7518305cdbb90cf8cb5a3ea6..24610ec4bf63ec96f577feb75e0dc778e8b3cc01 100644 (file)
@@ -80,7 +80,7 @@ class ConfigAdapter implements IMountProvider {
         */
        private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
                foreach ($storage->getBackendOptions() as $option => $value) {
-                       $storage->setBackendOption($option, \OC_Mount_Config::substitutePlaceholdersInConfig($value, $user->getUID()));
+                       $storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
                }
 
                $objectStore = $storage->getBackendOption('objectstore');
index 6418e5d73ad5df3a1004316d261ef21e4a74c303..de2942e554add5b7f74e6452a1f64ea6031fcd8a 100644 (file)
@@ -99,7 +99,7 @@ class ApiController extends OCSController {
                $entries = [];
                $user = $this->userSession->getUser()->getUID();
 
-               $mounts = \OC_Mount_Config::getAbsoluteMountPoints($user);
+               $mounts = \OCA\Files_External\MountConfig::getAbsoluteMountPoints($user);
                foreach ($mounts as $mountPoint => $mount) {
                        $entries[] = $this->formatMount($mountPoint, $mount);
                }
index a3a2712520a0f3f89fe1dec9ba14110fbf68a78e..d92aa9e416984a15cba28b3724fddde4da431a24 100644 (file)
@@ -250,7 +250,7 @@ abstract class StoragesController extends Controller {
                        $backend = $storage->getBackend();
                        // update status (can be time-consuming)
                        $storage->setStatus(
-                               \OC_Mount_Config::getBackendStatus(
+                               \OCA\Files_External\MountConfig::getBackendStatus(
                                        $backend->getStorageClass(),
                                        $storage->getBackendOptions(),
                                        false,
index 87dabda8bb69e4d196a4ea5148dcabfa88b776ea..710f907608af9668c45096c370525c61366134a9 100644 (file)
@@ -29,7 +29,7 @@ use OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
 use OCA\Files_External\Lib\MissingDependency;
 
 /**
- * Legacy compatibility for OC_Mount_Config::registerBackend()
+ * Legacy compatibility for OCA\Files_External\MountConfig::registerBackend()
  */
 class LegacyBackend extends Backend {
        use LegacyDependencyCheckPolyfill {
diff --git a/apps/files_external/lib/MountConfig.php b/apps/files_external/lib/MountConfig.php
new file mode 100644 (file)
index 0000000..0257123
--- /dev/null
@@ -0,0 +1,446 @@
+<?php
+/**
+ * @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 Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Frank Karlitschek <frank@karlitschek.de>
+ * @author Jesús Macias <jmacias@solidgear.es>
+ * @author Joas Schilling <coding@schilljs.com>
+ * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
+ * @author Julius Härtl <jus@bitgrid.net>
+ * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Michael Gapczynski <GapczynskiM@gmail.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Philipp Kapfer <philipp.kapfer@gmx.at>
+ * @author Robin Appelman <robin@icewind.nl>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Vincent Petry <pvince81@owncloud.com>
+ *
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External;
+
+use OCA\Files_External\AppInfo\Application;
+use OCA\Files_External\Config\IConfigHandler;
+use OCA\Files_External\Config\UserContext;
+use OCA\Files_External\Config\UserPlaceholderHandler;
+use OCA\Files_External\Lib\Auth\Builtin;
+use OCA\Files_External\Lib\Backend\Backend;
+use OCA\Files_External\Lib\Backend\LegacyBackend;
+use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\Service\BackendService;
+use OCA\Files_External\Service\GlobalStoragesService;
+use OCA\Files_External\Service\UserGlobalStoragesService;
+use OCA\Files_External\Service\UserStoragesService;
+use OCP\Files\StorageNotAvailableException;
+use OCP\IUserManager;
+use phpseclib\Crypt\AES;
+
+/**
+ * Class to configure mount.json globally and for users
+ */
+class MountConfig {
+       // TODO: make this class non-static and give it a proper namespace
+
+       public const MOUNT_TYPE_GLOBAL = 'global';
+       public const MOUNT_TYPE_GROUP = 'group';
+       public const MOUNT_TYPE_USER = 'user';
+       public const MOUNT_TYPE_PERSONAL = 'personal';
+
+       // whether to skip backend test (for unit tests, as this static class is not mockable)
+       public static $skipTest = false;
+
+       /** @var Application */
+       public static $app;
+
+       /**
+        * @param string $class
+        * @param array $definition
+        * @return bool
+        * @deprecated 8.2.0 use \OCA\Files_External\Service\BackendService::registerBackend()
+        */
+       public static function registerBackend($class, $definition) {
+               $backendService = self::$app->getContainer()->query(BackendService::class);
+               $auth = self::$app->getContainer()->query(Builtin::class);
+
+               $backendService->registerBackend(new LegacyBackend($class, $definition, $auth));
+
+               return true;
+       }
+
+       /**
+        * Returns the mount points for the given user.
+        * The mount point is relative to the data directory.
+        *
+        * @param string $uid user
+        * @return array of mount point string as key, mountpoint config as value
+        *
+        * @deprecated 8.2.0 use UserGlobalStoragesService::getStorages() and UserStoragesService::getStorages()
+        */
+       public static function getAbsoluteMountPoints($uid) {
+               $mountPoints = [];
+
+               $userGlobalStoragesService = self::$app->getContainer()->query(UserGlobalStoragesService::class);
+               $userStoragesService = self::$app->getContainer()->query(UserStoragesService::class);
+               $user = self::$app->getContainer()->query(IUserManager::class)->get($uid);
+
+               $userGlobalStoragesService->setUser($user);
+               $userStoragesService->setUser($user);
+
+               foreach ($userGlobalStoragesService->getStorages() as $storage) {
+                       /** @var \OCA\Files_External\Lib\StorageConfig $storage */
+                       $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
+                       $mountEntry = self::prepareMountPointEntry($storage, false);
+                       foreach ($mountEntry['options'] as &$option) {
+                               $option = self::substitutePlaceholdersInConfig($option, $uid);
+                       }
+                       $mountPoints[$mountPoint] = $mountEntry;
+               }
+
+               foreach ($userStoragesService->getStorages() as $storage) {
+                       $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
+                       $mountEntry = self::prepareMountPointEntry($storage, true);
+                       foreach ($mountEntry['options'] as &$option) {
+                               $option = self::substitutePlaceholdersInConfig($option, $uid);
+                       }
+                       $mountPoints[$mountPoint] = $mountEntry;
+               }
+
+               $userGlobalStoragesService->resetUser();
+               $userStoragesService->resetUser();
+
+               return $mountPoints;
+       }
+
+       /**
+        * Get the system mount points
+        *
+        * @return array
+        *
+        * @deprecated 8.2.0 use GlobalStoragesService::getStorages()
+        */
+       public static function getSystemMountPoints() {
+               $mountPoints = [];
+               $service = self::$app->getContainer()->query(GlobalStoragesService::class);
+
+               foreach ($service->getStorages() as $storage) {
+                       $mountPoints[] = self::prepareMountPointEntry($storage, false);
+               }
+
+               return $mountPoints;
+       }
+
+       /**
+        * Get the personal mount points of the current user
+        *
+        * @return array
+        *
+        * @deprecated 8.2.0 use UserStoragesService::getStorages()
+        */
+       public static function getPersonalMountPoints() {
+               $mountPoints = [];
+               $service = self::$app->getContainer()->query(UserStoragesService::class);
+
+               foreach ($service->getStorages() as $storage) {
+                       $mountPoints[] = self::prepareMountPointEntry($storage, true);
+               }
+
+               return $mountPoints;
+       }
+
+       /**
+        * Convert a StorageConfig to the legacy mountPoints array format
+        * There's a lot of extra information in here, to satisfy all of the legacy functions
+        *
+        * @param StorageConfig $storage
+        * @param bool $isPersonal
+        * @return array
+        */
+       private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal) {
+               $mountEntry = [];
+
+               $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash
+               $mountEntry['class'] = $storage->getBackend()->getIdentifier();
+               $mountEntry['backend'] = $storage->getBackend()->getText();
+               $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier();
+               $mountEntry['personal'] = $isPersonal;
+               $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions());
+               $mountEntry['mountOptions'] = $storage->getMountOptions();
+               $mountEntry['priority'] = $storage->getPriority();
+               $mountEntry['applicable'] = [
+                       'groups' => $storage->getApplicableGroups(),
+                       'users' => $storage->getApplicableUsers(),
+               ];
+               // if mountpoint is applicable to all users the old API expects ['all']
+               if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) {
+                       $mountEntry['applicable']['users'] = ['all'];
+               }
+
+               $mountEntry['id'] = $storage->getId();
+
+               return $mountEntry;
+       }
+
+       /**
+        * fill in the correct values for $user
+        *
+        * @param string $user user value
+        * @param string|array $input
+        * @return string
+        * @deprecated use self::substitutePlaceholdersInConfig($input)
+        */
+       public static function setUserVars($user, $input) {
+               $handler = self::$app->getContainer()->query(UserPlaceholderHandler::class);
+               return $handler->handle($input);
+       }
+
+       /**
+        * @param mixed $input
+        * @param string|null $userId
+        * @return mixed
+        * @throws \OCP\AppFramework\QueryException
+        * @since 16.0.0
+        */
+       public static function substitutePlaceholdersInConfig($input, string $userId = null) {
+               /** @var BackendService $backendService */
+               $backendService = self::$app->getContainer()->query(BackendService::class);
+               /** @var IConfigHandler[] $handlers */
+               $handlers = $backendService->getConfigHandlers();
+               foreach ($handlers as $handler) {
+                       if ($handler instanceof UserContext && $userId !== null) {
+                               $handler->setUserId($userId);
+                       }
+                       $input = $handler->handle($input);
+               }
+               return $input;
+       }
+
+       /**
+        * Test connecting using the given backend configuration
+        *
+        * @param string $class backend class name
+        * @param array $options backend configuration options
+        * @param boolean $isPersonal
+        * @return int see self::STATUS_*
+        * @throws Exception
+        */
+       public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) {
+               if (self::$skipTest) {
+                       return StorageNotAvailableException::STATUS_SUCCESS;
+               }
+               foreach ($options as $key => &$option) {
+                       if ($key === 'password') {
+                               // no replacements in passwords
+                               continue;
+                       }
+                       $option = self::substitutePlaceholdersInConfig($option);
+               }
+               if (class_exists($class)) {
+                       try {
+                               /** @var \OC\Files\Storage\Common $storage */
+                               $storage = new $class($options);
+
+                               try {
+                                       $result = $storage->test($isPersonal, $testOnly);
+                                       $storage->setAvailability($result);
+                                       if ($result) {
+                                               return StorageNotAvailableException::STATUS_SUCCESS;
+                                       }
+                               } catch (\Exception $e) {
+                                       $storage->setAvailability(false);
+                                       throw $e;
+                               }
+                       } catch (Exception $exception) {
+                               \OC::$server->getLogger()->logException($exception, ['app' => 'files_external']);
+                               throw $exception;
+                       }
+               }
+               return StorageNotAvailableException::STATUS_ERROR;
+       }
+
+       /**
+        * Read the mount points in the config file into an array
+        *
+        * @param string|null $user If not null, personal for $user, otherwise system
+        * @return array
+        */
+       public static function readData($user = null) {
+               if (isset($user)) {
+                       $jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json';
+               } else {
+                       $config = \OC::$server->getConfig();
+                       $datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
+                       $jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json');
+               }
+               if (is_file($jsonFile)) {
+                       $mountPoints = json_decode(file_get_contents($jsonFile), true);
+                       if (is_array($mountPoints)) {
+                               return $mountPoints;
+                       }
+               }
+               return [];
+       }
+
+       /**
+        * Get backend dependency message
+        * TODO: move into AppFramework along with templates
+        *
+        * @param Backend[] $backends
+        * @return string
+        */
+       public static function dependencyMessage($backends) {
+               $l = \OC::$server->getL10N('files_external');
+               $message = '';
+               $dependencyGroups = [];
+
+               foreach ($backends as $backend) {
+                       foreach ($backend->checkDependencies() as $dependency) {
+                               if ($message = $dependency->getMessage()) {
+                                       $message .= '<p>' . $message . '</p>';
+                               } else {
+                                       $dependencyGroups[$dependency->getDependency()][] = $backend;
+                               }
+                       }
+               }
+
+               foreach ($dependencyGroups as $module => $dependants) {
+                       $backends = implode(', ', array_map(function ($backend) {
+                               return '"' . $backend->getText() . '"';
+                       }, $dependants));
+                       $message .= '<p>' . MountConfig::getSingleDependencyMessage($l, $module, $backends) . '</p>';
+               }
+
+               return $message;
+       }
+
+       /**
+        * Returns a dependency missing message
+        *
+        * @param \OCP\IL10N $l
+        * @param string $module
+        * @param string $backend
+        * @return string
+        */
+       private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) {
+               switch (strtolower($module)) {
+                       case 'curl':
+                               return (string)$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]);
+                       case 'ftp':
+                               return (string)$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]);
+                       default:
+                               return (string)$l->t('"%1$s" is not installed. Mounting of %2$s is not possible. Please ask your system administrator to install it.', [$module, $backend]);
+               }
+       }
+
+       /**
+        * Encrypt passwords in the given config options
+        *
+        * @param array $options mount options
+        * @return array updated options
+        */
+       public static function encryptPasswords($options) {
+               if (isset($options['password'])) {
+                       $options['password_encrypted'] = self::encryptPassword($options['password']);
+                       // do not unset the password, we want to keep the keys order
+                       // on load... because that's how the UI currently works
+                       $options['password'] = '';
+               }
+               return $options;
+       }
+
+       /**
+        * Decrypt passwords in the given config options
+        *
+        * @param array $options mount options
+        * @return array updated options
+        */
+       public static function decryptPasswords($options) {
+               // note: legacy options might still have the unencrypted password in the "password" field
+               if (isset($options['password_encrypted'])) {
+                       $options['password'] = self::decryptPassword($options['password_encrypted']);
+                       unset($options['password_encrypted']);
+               }
+               return $options;
+       }
+
+       /**
+        * Encrypt a single password
+        *
+        * @param string $password plain text password
+        * @return string encrypted password
+        */
+       private static function encryptPassword($password) {
+               $cipher = self::getCipher();
+               $iv = \OC::$server->getSecureRandom()->generate(16);
+               $cipher->setIV($iv);
+               return base64_encode($iv . $cipher->encrypt($password));
+       }
+
+       /**
+        * Decrypts a single password
+        *
+        * @param string $encryptedPassword encrypted password
+        * @return string plain text password
+        */
+       private static function decryptPassword($encryptedPassword) {
+               $cipher = self::getCipher();
+               $binaryPassword = base64_decode($encryptedPassword);
+               $iv = substr($binaryPassword, 0, 16);
+               $cipher->setIV($iv);
+               $binaryPassword = substr($binaryPassword, 16);
+               return $cipher->decrypt($binaryPassword);
+       }
+
+       /**
+        * Returns the encryption cipher
+        *
+        * @return AES
+        */
+       private static function getCipher() {
+               $cipher = new AES(AES::MODE_CBC);
+               $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null));
+               return $cipher;
+       }
+
+       /**
+        * Computes a hash based on the given configuration.
+        * This is mostly used to find out whether configurations
+        * are the same.
+        *
+        * @param array $config
+        * @return string
+        */
+       public static function makeConfigHash($config) {
+               $data = json_encode(
+                       [
+                               'c' => $config['backend'],
+                               'a' => $config['authMechanism'],
+                               'm' => $config['mountpoint'],
+                               'o' => $config['options'],
+                               'p' => isset($config['priority']) ? $config['priority'] : -1,
+                               'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [],
+                       ]
+               );
+               return hash('md5', $data);
+       }
+}
index 95a7c47665dc4c39d914080baab06089de174784..2905e08883edb1340b31d9a10eb76aa6c337eaf1 100644 (file)
@@ -51,7 +51,7 @@ class GlobalStoragesService extends StoragesService {
                        $this->triggerApplicableHooks(
                                $signal,
                                $storage->getMountPoint(),
-                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                ['all']
                        );
                        return;
@@ -60,13 +60,13 @@ class GlobalStoragesService extends StoragesService {
                $this->triggerApplicableHooks(
                        $signal,
                        $storage->getMountPoint(),
-                       \OC_Mount_Config::MOUNT_TYPE_USER,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                        $applicableUsers
                );
                $this->triggerApplicableHooks(
                        $signal,
                        $storage->getMountPoint(),
-                       \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                        $applicableGroups
                );
        }
@@ -100,7 +100,7 @@ class GlobalStoragesService extends StoragesService {
                        $this->triggerApplicableHooks(
                                Filesystem::signal_delete_mount,
                                $oldStorage->getMountPoint(),
-                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                ['all']
                        );
                }
@@ -109,7 +109,7 @@ class GlobalStoragesService extends StoragesService {
                $this->triggerApplicableHooks(
                        Filesystem::signal_delete_mount,
                        $oldStorage->getMountPoint(),
-                       \OC_Mount_Config::MOUNT_TYPE_USER,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                        $userDeletions
                );
 
@@ -117,7 +117,7 @@ class GlobalStoragesService extends StoragesService {
                $this->triggerApplicableHooks(
                        Filesystem::signal_delete_mount,
                        $oldStorage->getMountPoint(),
-                       \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                        $groupDeletions
                );
 
@@ -125,7 +125,7 @@ class GlobalStoragesService extends StoragesService {
                $this->triggerApplicableHooks(
                        Filesystem::signal_create_mount,
                        $newStorage->getMountPoint(),
-                       \OC_Mount_Config::MOUNT_TYPE_USER,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                        $userAdditions
                );
 
@@ -133,7 +133,7 @@ class GlobalStoragesService extends StoragesService {
                $this->triggerApplicableHooks(
                        Filesystem::signal_create_mount,
                        $newStorage->getMountPoint(),
-                       \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                        $groupAdditions
                );
 
@@ -145,7 +145,7 @@ class GlobalStoragesService extends StoragesService {
                        $this->triggerApplicableHooks(
                                Filesystem::signal_create_mount,
                                $newStorage->getMountPoint(),
-                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                ['all']
                        );
                }
index fef746a35c081930644fd81f382e8763b1948de1..faaf40ba0286881eda5982093e8754ff79834df1 100644 (file)
@@ -83,13 +83,13 @@ abstract class LegacyStoragesService {
                        $storageOptions['priority'] = $backend->getPriority();
                }
                $storageConfig->setPriority($storageOptions['priority']);
-               if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) {
+               if ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_USER) {
                        $applicableUsers = $storageConfig->getApplicableUsers();
                        if ($applicable !== 'all') {
                                $applicableUsers[] = $applicable;
                                $storageConfig->setApplicableUsers($applicableUsers);
                        }
-               } elseif ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) {
+               } elseif ($mountType === \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP) {
                        $applicableGroups = $storageConfig->getApplicableGroups();
                        $applicableGroups[] = $applicable;
                        $storageConfig->setApplicableGroups($applicableGroups);
@@ -150,7 +150,7 @@ abstract class LegacyStoragesService {
                                        $relativeMountPath = rtrim($parts[2], '/');
                                        // note: we cannot do this after the loop because the decrypted config
                                        // options might be needed for the config hash
-                                       $storageOptions['options'] = \OC_Mount_Config::decryptPasswords($storageOptions['options']);
+                                       $storageOptions['options'] = \OCA\Files_External\MountConfig::decryptPasswords($storageOptions['options']);
                                        if (!isset($storageOptions['backend'])) {
                                                $storageOptions['backend'] = $storageOptions['class']; // legacy compat
                                        }
@@ -168,7 +168,7 @@ abstract class LegacyStoragesService {
                                                // but at this point we don't know the max-id, so use
                                                // first group it by config hash
                                                $storageOptions['mountpoint'] = $rootMountPath;
-                                               $configId = \OC_Mount_Config::makeConfigHash($storageOptions);
+                                               $configId = \OCA\Files_External\MountConfig::makeConfigHash($storageOptions);
                                                if (isset($storagesWithConfigHash[$configId])) {
                                                        $currentStorage = $storagesWithConfigHash[$configId];
                                                }
index 3ffd49863b9ed2235431ecec6a6f9051da42d5f3..ea3794384ba2a72cb5954348ff963541a52de4b9 100644 (file)
@@ -51,6 +51,6 @@ class UserLegacyStoragesService extends LegacyStoragesService {
        protected function readLegacyConfig() {
                // read user config
                $user = $this->userSession->getUser()->getUID();
-               return \OC_Mount_Config::readData($user);
+               return \OCA\Files_External\MountConfig::readData($user);
        }
 }
index 7b793ca819e66974c71d04e0462b0541b3edc5f3..411a1a54dd6ab51c265c07e2acaebd6525c8233c 100644 (file)
@@ -78,7 +78,7 @@ class UserStoragesService extends StoragesService {
                $this->triggerApplicableHooks(
                        $signal,
                        $storage->getMountPoint(),
-                       \OC_Mount_Config::MOUNT_TYPE_USER,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                        [$user]
                );
        }
index d3c2c07aa831d2d6191f806aea2b5b12f2ec0db2..b0b1615b0ebefc81d3a275d40b7711375c55330d 100644 (file)
@@ -66,7 +66,7 @@ class Admin implements ISettings {
                        'storages'             => $this->globalStoragesService->getStorages(),
                        'backends'             => $this->backendService->getAvailableBackends(),
                        'authMechanisms'       => $this->backendService->getAuthMechanisms(),
-                       'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
+                       'dependencies'         => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
                        'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
                        'globalCredentials'    => $this->globalAuth->getAuth(''),
                        'globalCredentialsUid' => '',
index de94793a6af8bc385a1b5ef03194e6a3d9058ee5..b863d4751488bd3bcac69fc55140304923fa6f86 100644 (file)
@@ -74,7 +74,7 @@ class Personal implements ISettings {
                        'storages'             => $this->userGlobalStoragesService->getStorages(),
                        'backends'             => $this->backendService->getAvailableBackends(),
                        'authMechanisms'       => $this->backendService->getAuthMechanisms(),
-                       'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
+                       'dependencies'         => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
                        'allowUserMounting'    => $this->backendService->isUserMountingAllowed(),
                        'globalCredentials'    => $this->globalAuth->getAuth($uid),
                        'globalCredentialsUid' => $uid,
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
deleted file mode 100644 (file)
index 745f2da..0000000
+++ /dev/null
@@ -1,444 +0,0 @@
-<?php
-/**
- * @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 Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Frank Karlitschek <frank@karlitschek.de>
- * @author Jesús Macias <jmacias@solidgear.es>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Michael Gapczynski <GapczynskiM@gmail.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Philipp Kapfer <philipp.kapfer@gmx.at>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-use OCA\Files_External\AppInfo\Application;
-use OCA\Files_External\Config\IConfigHandler;
-use OCA\Files_External\Config\UserContext;
-use OCA\Files_External\Config\UserPlaceholderHandler;
-use OCA\Files_External\Lib\Auth\Builtin;
-use OCA\Files_External\Lib\Backend\Backend;
-use OCA\Files_External\Lib\Backend\LegacyBackend;
-use OCA\Files_External\Lib\StorageConfig;
-use OCA\Files_External\Service\BackendService;
-use OCA\Files_External\Service\GlobalStoragesService;
-use OCA\Files_External\Service\UserGlobalStoragesService;
-use OCA\Files_External\Service\UserStoragesService;
-use OCP\Files\StorageNotAvailableException;
-use OCP\IUserManager;
-use phpseclib\Crypt\AES;
-
-/**
- * Class to configure mount.json globally and for users
- */
-class OC_Mount_Config {
-       // TODO: make this class non-static and give it a proper namespace
-
-       public const MOUNT_TYPE_GLOBAL = 'global';
-       public const MOUNT_TYPE_GROUP = 'group';
-       public const MOUNT_TYPE_USER = 'user';
-       public const MOUNT_TYPE_PERSONAL = 'personal';
-
-       // whether to skip backend test (for unit tests, as this static class is not mockable)
-       public static $skipTest = false;
-
-       /** @var Application */
-       public static $app;
-
-       /**
-        * @param string $class
-        * @param array $definition
-        * @return bool
-        * @deprecated 8.2.0 use \OCA\Files_External\Service\BackendService::registerBackend()
-        */
-       public static function registerBackend($class, $definition) {
-               $backendService = self::$app->getContainer()->query(BackendService::class);
-               $auth = self::$app->getContainer()->query(Builtin::class);
-
-               $backendService->registerBackend(new LegacyBackend($class, $definition, $auth));
-
-               return true;
-       }
-
-       /**
-        * Returns the mount points for the given user.
-        * The mount point is relative to the data directory.
-        *
-        * @param string $uid user
-        * @return array of mount point string as key, mountpoint config as value
-        *
-        * @deprecated 8.2.0 use UserGlobalStoragesService::getStorages() and UserStoragesService::getStorages()
-        */
-       public static function getAbsoluteMountPoints($uid) {
-               $mountPoints = [];
-
-               $userGlobalStoragesService = self::$app->getContainer()->query(UserGlobalStoragesService::class);
-               $userStoragesService = self::$app->getContainer()->query(UserStoragesService::class);
-               $user = self::$app->getContainer()->query(IUserManager::class)->get($uid);
-
-               $userGlobalStoragesService->setUser($user);
-               $userStoragesService->setUser($user);
-
-               foreach ($userGlobalStoragesService->getStorages() as $storage) {
-                       /** @var \OCA\Files_External\Lib\StorageConfig $storage */
-                       $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
-                       $mountEntry = self::prepareMountPointEntry($storage, false);
-                       foreach ($mountEntry['options'] as &$option) {
-                               $option = self::substitutePlaceholdersInConfig($option, $uid);
-                       }
-                       $mountPoints[$mountPoint] = $mountEntry;
-               }
-
-               foreach ($userStoragesService->getStorages() as $storage) {
-                       $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
-                       $mountEntry = self::prepareMountPointEntry($storage, true);
-                       foreach ($mountEntry['options'] as &$option) {
-                               $option = self::substitutePlaceholdersInConfig($option, $uid);
-                       }
-                       $mountPoints[$mountPoint] = $mountEntry;
-               }
-
-               $userGlobalStoragesService->resetUser();
-               $userStoragesService->resetUser();
-
-               return $mountPoints;
-       }
-
-       /**
-        * Get the system mount points
-        *
-        * @return array
-        *
-        * @deprecated 8.2.0 use GlobalStoragesService::getStorages()
-        */
-       public static function getSystemMountPoints() {
-               $mountPoints = [];
-               $service = self::$app->getContainer()->query(GlobalStoragesService::class);
-
-               foreach ($service->getStorages() as $storage) {
-                       $mountPoints[] = self::prepareMountPointEntry($storage, false);
-               }
-
-               return $mountPoints;
-       }
-
-       /**
-        * Get the personal mount points of the current user
-        *
-        * @return array
-        *
-        * @deprecated 8.2.0 use UserStoragesService::getStorages()
-        */
-       public static function getPersonalMountPoints() {
-               $mountPoints = [];
-               $service = self::$app->getContainer()->query(UserStoragesService::class);
-
-               foreach ($service->getStorages() as $storage) {
-                       $mountPoints[] = self::prepareMountPointEntry($storage, true);
-               }
-
-               return $mountPoints;
-       }
-
-       /**
-        * Convert a StorageConfig to the legacy mountPoints array format
-        * There's a lot of extra information in here, to satisfy all of the legacy functions
-        *
-        * @param StorageConfig $storage
-        * @param bool $isPersonal
-        * @return array
-        */
-       private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal) {
-               $mountEntry = [];
-
-               $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash
-               $mountEntry['class'] = $storage->getBackend()->getIdentifier();
-               $mountEntry['backend'] = $storage->getBackend()->getText();
-               $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier();
-               $mountEntry['personal'] = $isPersonal;
-               $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions());
-               $mountEntry['mountOptions'] = $storage->getMountOptions();
-               $mountEntry['priority'] = $storage->getPriority();
-               $mountEntry['applicable'] = [
-                       'groups' => $storage->getApplicableGroups(),
-                       'users' => $storage->getApplicableUsers(),
-               ];
-               // if mountpoint is applicable to all users the old API expects ['all']
-               if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) {
-                       $mountEntry['applicable']['users'] = ['all'];
-               }
-
-               $mountEntry['id'] = $storage->getId();
-
-               return $mountEntry;
-       }
-
-       /**
-        * fill in the correct values for $user
-        *
-        * @param string $user user value
-        * @param string|array $input
-        * @return string
-        * @deprecated use self::substitutePlaceholdersInConfig($input)
-        */
-       public static function setUserVars($user, $input) {
-               $handler = self::$app->getContainer()->query(UserPlaceholderHandler::class);
-               return $handler->handle($input);
-       }
-
-       /**
-        * @param mixed $input
-        * @param string|null $userId
-        * @return mixed
-        * @throws \OCP\AppFramework\QueryException
-        * @since 16.0.0
-        */
-       public static function substitutePlaceholdersInConfig($input, string $userId = null) {
-               /** @var BackendService $backendService */
-               $backendService = self::$app->getContainer()->query(BackendService::class);
-               /** @var IConfigHandler[] $handlers */
-               $handlers = $backendService->getConfigHandlers();
-               foreach ($handlers as $handler) {
-                       if ($handler instanceof UserContext && $userId !== null) {
-                               $handler->setUserId($userId);
-                       }
-                       $input = $handler->handle($input);
-               }
-               return $input;
-       }
-
-       /**
-        * Test connecting using the given backend configuration
-        *
-        * @param string $class backend class name
-        * @param array $options backend configuration options
-        * @param boolean $isPersonal
-        * @return int see self::STATUS_*
-        * @throws Exception
-        */
-       public static function getBackendStatus($class, $options, $isPersonal, $testOnly = true) {
-               if (self::$skipTest) {
-                       return StorageNotAvailableException::STATUS_SUCCESS;
-               }
-               foreach ($options as $key => &$option) {
-                       if ($key === 'password') {
-                               // no replacements in passwords
-                               continue;
-                       }
-                       $option = self::substitutePlaceholdersInConfig($option);
-               }
-               if (class_exists($class)) {
-                       try {
-                               /** @var \OC\Files\Storage\Common $storage */
-                               $storage = new $class($options);
-
-                               try {
-                                       $result = $storage->test($isPersonal, $testOnly);
-                                       $storage->setAvailability($result);
-                                       if ($result) {
-                                               return StorageNotAvailableException::STATUS_SUCCESS;
-                                       }
-                               } catch (\Exception $e) {
-                                       $storage->setAvailability(false);
-                                       throw $e;
-                               }
-                       } catch (Exception $exception) {
-                               \OC::$server->getLogger()->logException($exception, ['app' => 'files_external']);
-                               throw $exception;
-                       }
-               }
-               return StorageNotAvailableException::STATUS_ERROR;
-       }
-
-       /**
-        * Read the mount points in the config file into an array
-        *
-        * @param string|null $user If not null, personal for $user, otherwise system
-        * @return array
-        */
-       public static function readData($user = null) {
-               if (isset($user)) {
-                       $jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json';
-               } else {
-                       $config = \OC::$server->getConfig();
-                       $datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
-                       $jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json');
-               }
-               if (is_file($jsonFile)) {
-                       $mountPoints = json_decode(file_get_contents($jsonFile), true);
-                       if (is_array($mountPoints)) {
-                               return $mountPoints;
-                       }
-               }
-               return [];
-       }
-
-       /**
-        * Get backend dependency message
-        * TODO: move into AppFramework along with templates
-        *
-        * @param Backend[] $backends
-        * @return string
-        */
-       public static function dependencyMessage($backends) {
-               $l = \OC::$server->getL10N('files_external');
-               $message = '';
-               $dependencyGroups = [];
-
-               foreach ($backends as $backend) {
-                       foreach ($backend->checkDependencies() as $dependency) {
-                               if ($message = $dependency->getMessage()) {
-                                       $message .= '<p>' . $message . '</p>';
-                               } else {
-                                       $dependencyGroups[$dependency->getDependency()][] = $backend;
-                               }
-                       }
-               }
-
-               foreach ($dependencyGroups as $module => $dependants) {
-                       $backends = implode(', ', array_map(function ($backend) {
-                               return '"' . $backend->getText() . '"';
-                       }, $dependants));
-                       $message .= '<p>' . OC_Mount_Config::getSingleDependencyMessage($l, $module, $backends) . '</p>';
-               }
-
-               return $message;
-       }
-
-       /**
-        * Returns a dependency missing message
-        *
-        * @param \OCP\IL10N $l
-        * @param string $module
-        * @param string $backend
-        * @return string
-        */
-       private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) {
-               switch (strtolower($module)) {
-                       case 'curl':
-                               return (string)$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]);
-                       case 'ftp':
-                               return (string)$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]);
-                       default:
-                               return (string)$l->t('"%1$s" is not installed. Mounting of %2$s is not possible. Please ask your system administrator to install it.', [$module, $backend]);
-               }
-       }
-
-       /**
-        * Encrypt passwords in the given config options
-        *
-        * @param array $options mount options
-        * @return array updated options
-        */
-       public static function encryptPasswords($options) {
-               if (isset($options['password'])) {
-                       $options['password_encrypted'] = self::encryptPassword($options['password']);
-                       // do not unset the password, we want to keep the keys order
-                       // on load... because that's how the UI currently works
-                       $options['password'] = '';
-               }
-               return $options;
-       }
-
-       /**
-        * Decrypt passwords in the given config options
-        *
-        * @param array $options mount options
-        * @return array updated options
-        */
-       public static function decryptPasswords($options) {
-               // note: legacy options might still have the unencrypted password in the "password" field
-               if (isset($options['password_encrypted'])) {
-                       $options['password'] = self::decryptPassword($options['password_encrypted']);
-                       unset($options['password_encrypted']);
-               }
-               return $options;
-       }
-
-       /**
-        * Encrypt a single password
-        *
-        * @param string $password plain text password
-        * @return string encrypted password
-        */
-       private static function encryptPassword($password) {
-               $cipher = self::getCipher();
-               $iv = \OC::$server->getSecureRandom()->generate(16);
-               $cipher->setIV($iv);
-               return base64_encode($iv . $cipher->encrypt($password));
-       }
-
-       /**
-        * Decrypts a single password
-        *
-        * @param string $encryptedPassword encrypted password
-        * @return string plain text password
-        */
-       private static function decryptPassword($encryptedPassword) {
-               $cipher = self::getCipher();
-               $binaryPassword = base64_decode($encryptedPassword);
-               $iv = substr($binaryPassword, 0, 16);
-               $cipher->setIV($iv);
-               $binaryPassword = substr($binaryPassword, 16);
-               return $cipher->decrypt($binaryPassword);
-       }
-
-       /**
-        * Returns the encryption cipher
-        *
-        * @return AES
-        */
-       private static function getCipher() {
-               $cipher = new AES(AES::MODE_CBC);
-               $cipher->setKey(\OC::$server->getConfig()->getSystemValue('passwordsalt', null));
-               return $cipher;
-       }
-
-       /**
-        * Computes a hash based on the given configuration.
-        * This is mostly used to find out whether configurations
-        * are the same.
-        *
-        * @param array $config
-        * @return string
-        */
-       public static function makeConfigHash($config) {
-               $data = json_encode(
-                       [
-                               'c' => $config['backend'],
-                               'a' => $config['authMechanism'],
-                               'm' => $config['mountpoint'],
-                               'o' => $config['options'],
-                               'p' => isset($config['priority']) ? $config['priority'] : -1,
-                               'mo' => isset($config['mountOptions']) ? $config['mountOptions'] : [],
-                       ]
-               );
-               return hash('md5', $data);
-       }
-}
index 617ad11c4594b735f131e9b90e4f51c4deb1ae5b..7572da25752118cc2a5bcbd9d8bb20ff35c7050d 100644 (file)
@@ -50,11 +50,11 @@ abstract class StoragesControllerTest extends \Test\TestCase {
        protected $service;
 
        protected function setUp(): void {
-               \OC_Mount_Config::$skipTest = true;
+               \OCA\Files_External\MountConfig::$skipTest = true;
        }
 
        protected function tearDown(): void {
-               \OC_Mount_Config::$skipTest = false;
+               \OCA\Files_External\MountConfig::$skipTest = false;
        }
 
        /**
index afbece9241a3d9dc23c3a7d61567fb5a3d03cd92..d08b8079d12ff8aa3a8fc07f6f725e7aa1868818 100644 (file)
@@ -202,7 +202,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'all'
                                        ],
                                ],
@@ -215,7 +215,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user1',
                                        ],
                                ],
@@ -228,7 +228,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group1',
                                        ],
                                ],
@@ -240,12 +240,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user1',
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user2',
                                        ],
                                ],
@@ -258,12 +258,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group1'
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group2'
                                        ],
                                ],
@@ -276,22 +276,22 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user1',
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user2',
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group1'
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group2'
                                        ],
                                ],
@@ -334,27 +334,27 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                        // delete the "all entry"
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'all',
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user1',
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user2',
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group1'
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group2'
                                        ],
                                ],
@@ -369,12 +369,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user2',
                                        ],
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group2'
                                        ],
                                ],
@@ -389,12 +389,12 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user2',
                                        ],
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group2'
                                        ],
                                ],
@@ -409,18 +409,18 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user1',
                                        ],
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group1'
                                        ],
                                        // create the "all" entry
                                        [
                                                Filesystem::signal_create_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'all'
                                        ],
                                ],
@@ -472,7 +472,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                }
        }
 
-       
+
        public function testHooksRenameMountPoint() {
                $storage = $this->makeTestStorageData();
                $storage->setApplicableUsers(['user1', 'user2']);
@@ -491,50 +491,50 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                        [
                                Filesystem::signal_delete_mount,
                                '/mountpoint',
-                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                'user1',
                        ],
                        [
                                Filesystem::signal_delete_mount,
                                '/mountpoint',
-                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                'user2',
                        ],
                        [
                                Filesystem::signal_delete_mount,
                                '/mountpoint',
-                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                'group1',
                        ],
                        [
                                Filesystem::signal_delete_mount,
                                '/mountpoint',
-                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                'group2',
                        ],
                        // creates new one
                        [
                                Filesystem::signal_create_mount,
                                '/renamedMountpoint',
-                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                'user1',
                        ],
                        [
                                Filesystem::signal_create_mount,
                                '/renamedMountpoint',
-                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                'user2',
                        ],
                        [
                                Filesystem::signal_create_mount,
                                '/renamedMountpoint',
-                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                'group1',
                        ],
                        [
                                Filesystem::signal_create_mount,
                                '/renamedMountpoint',
-                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                'group2',
                        ],
                ];
@@ -561,22 +561,22 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user1',
                                        ],
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'user2',
                                        ],
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group1'
                                        ],
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_GROUP,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_GROUP,
                                                'group2'
                                        ],
                                ],
@@ -588,7 +588,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest {
                                [
                                        [
                                                Filesystem::signal_delete_mount,
-                                               \OC_Mount_Config::MOUNT_TYPE_USER,
+                                               \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                                                'all',
                                        ],
                                ],
index 049c0a2989ecc9af5bebb218c34fbaa086fdeb2e..76f0a09c14bfc629cac19138c4ec1f5e04371765 100644 (file)
@@ -102,7 +102,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
                        'datadirectory',
                        \OC::$SERVERROOT . '/data/'
                );
-               \OC_Mount_Config::$skipTest = true;
+               \OCA\Files_External\MountConfig::$skipTest = true;
 
                $this->mountCache = $this->createMock(IUserMountCache::class);
 
@@ -169,15 +169,15 @@ abstract class StoragesServiceTest extends \Test\TestCase {
                                }
                        });
 
-               \OC_Mount_Config::$app = $this->getMockBuilder('\OCA\Files_External\Appinfo\Application')
+               \OCA\Files_External\MountConfig::$app = $this->getMockBuilder('\OCA\Files_External\Appinfo\Application')
                        ->disableOriginalConstructor()
                        ->getMock();
-               \OC_Mount_Config::$app->method('getContainer')
+               \OCA\Files_External\MountConfig::$app->method('getContainer')
                        ->willReturn($containerMock);
        }
 
        protected function tearDown(): void {
-               \OC_Mount_Config::$skipTest = false;
+               \OCA\Files_External\MountConfig::$skipTest = false;
                self::$hookCalls = [];
                if ($this->dbConfig) {
                        $this->dbConfig->clean();
index 7d177f76904a94808134d44d5436a35dd04582f3..9dd4a570c334ba0141b969e61dc81b80aa17c461 100644 (file)
@@ -106,7 +106,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
                        current(self::$hookCalls),
                        Filesystem::signal_create_mount,
                        $storage->getMountPoint(),
-                       \OC_Mount_Config::MOUNT_TYPE_USER,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                        $this->userId
                );
 
@@ -157,7 +157,7 @@ class UserStoragesServiceTest extends StoragesServiceTest {
                        self::$hookCalls[1],
                        Filesystem::signal_delete_mount,
                        '/mountpoint',
-                       \OC_Mount_Config::MOUNT_TYPE_USER,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                        $this->userId
                );
        }
@@ -178,19 +178,19 @@ class UserStoragesServiceTest extends StoragesServiceTest {
                        self::$hookCalls[0],
                        Filesystem::signal_delete_mount,
                        '/mountpoint',
-                       \OC_Mount_Config::MOUNT_TYPE_USER,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                        $this->userId
                );
                $this->assertHookCall(
                        self::$hookCalls[1],
                        Filesystem::signal_create_mount,
                        '/renamedMountpoint',
-                       \OC_Mount_Config::MOUNT_TYPE_USER,
+                       \OCA\Files_External\MountConfig::MOUNT_TYPE_USER,
                        $this->userId
                );
        }
 
-       
+
        public function testGetAdminStorage() {
                $this->expectException(\OCA\Files_External\NotFoundException::class);
 
index 8edca14f3b18406a0fd2577123f1e0f4b7be7d83..f8d6bce1d62a1aa8c0694a3d9b030570ce8c90fc 100644 (file)
@@ -95,7 +95,7 @@ class AdminTest extends TestCase {
                        'storages'             => ['a', 'b', 'c'],
                        'backends'             => ['d', 'e', 'f'],
                        'authMechanisms'       => ['g', 'h', 'i'],
-                       'dependencies'         => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()),
+                       'dependencies'         => \OCA\Files_External\MountConfig::dependencyMessage($this->backendService->getBackends()),
                        'allowUserMounting'    => true,
                        'globalCredentials'    => 'asdf:asdf',
                        'globalCredentialsUid' => '',
index 13879c02cdc49ff14c40e6af478211138b72fbf5..b631e4fc63f56ed3d871c9467db872c43fd8eabf 100644 (file)
@@ -110,7 +110,7 @@ class File implements \OCP\Encryption\IFile {
 
                // check if it is a group mount
                if (\OCP\App::isEnabled("files_external")) {
-                       $mounts = \OC_Mount_Config::getSystemMountPoints();
+                       $mounts = \OCA\Files_External\MountConfig::getSystemMountPoints();
                        foreach ($mounts as $mount) {
                                if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
                                        $mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
index 8b3360c30e0e665415e5f673de8735591f04bca9..0bda00a5cbc7f8e37309ce42f1390f738f96614d 100644 (file)
@@ -299,7 +299,7 @@ class Util {
         */
        public function isSystemWideMountPoint($path, $uid) {
                if (\OCP\App::isEnabled("files_external")) {
-                       $mounts = \OC_Mount_Config::getSystemMountPoints();
+                       $mounts = \OCA\Files_External\MountConfig::getSystemMountPoints();
                        foreach ($mounts as $mount) {
                                if (strpos($path, '/files/' . $mount['mountpoint']) === 0) {
                                        if ($this->isMountPointApplicableToUser($mount, $uid)) {
index 587d6ff37db15b42f1acf0faec69256b758a93d9..a2bc1963003f2961c1a28ce576c45e8fa258cfde 100644 (file)
@@ -81,7 +81,7 @@ class ExceptionSerializer {
                'storeKeyPair',
                'setupUser',
 
-               // files_external: OC_Mount_Config
+               // files_external: OCA\Files_External\MountConfig
                'getBackendStatus',
 
                // files_external: UserStoragesController