]> source.dussan.org Git - nextcloud-server.git/commitdiff
Moved external storage mounting code to files_external app
authorVincent Petry <pvince81@owncloud.com>
Wed, 19 Mar 2014 11:20:48 +0000 (12:20 +0100)
committerVincent Petry <pvince81@owncloud.com>
Wed, 19 Mar 2014 11:45:38 +0000 (12:45 +0100)
Moved the mounting code for external storage from
OC\Filesystem::initMountPoint to files_external using the
post_initMountPoints hook

apps/files_external/appinfo/app.php
apps/files_external/lib/config.php
lib/private/files/filesystem.php

index 5b1cd86a1709e75f30022413003ca84a48b1f2ef..0e83660f845e6401dd966c60c35d1a88f2f29424 100644 (file)
@@ -25,5 +25,6 @@ if (OCP\Config::getAppValue('files_external', 'allow_user_mounting', 'yes') == '
 }
 
 // connecting hooks
-OCP\Util::connectHook( 'OC_User', 'post_login', 'OC\Files\Storage\iRODS', 'login' );
+OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config', 'initMountPointsHook');
+OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\iRODS', 'login');
 
index 0a68de1cdb17981816268218bf52c490a7ddc13c..28761b4862e035a7ca7809ffc39d53ceea0269ad 100755 (executable)
@@ -27,10 +27,10 @@ set_include_path(
 include('Crypt/AES.php');
 
 /**
-* Class to configure the config/mount.php and data/$user/mount.php files
+ * Class to configure mount.json globally and for users
  */
-// TODO: make this class non-static
 class OC_Mount_Config {
+       // TODO: make this class non-static and give it a proper namespace
 
        const MOUNT_TYPE_GLOBAL = 'global';
        const MOUNT_TYPE_GROUP = 'group';
@@ -166,6 +166,81 @@ class OC_Mount_Config {
                return($backends);
        }
 
+       /**
+        * Init mount points hook
+        * @param array $data
+        */
+       public static function initMountPointsHook($data) {
+               $user = $data['user'];
+               $root = $data['user_dir'];
+
+               $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
+               $mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json");
+
+               //move config file to it's new position
+               if (is_file(\OC::$SERVERROOT . '/config/mount.json')) {
+                       rename(\OC::$SERVERROOT . '/config/mount.json', $mount_file);
+               }
+
+               // Load system mount points
+               $mountConfig = self::readData(false);
+               if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
+                       foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
+                               $options['options'] = self::decryptPasswords($options['options']);
+                               \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+                       }
+               }
+               if (isset($mountConfig[self::MOUNT_TYPE_GROUP])) {
+                       foreach ($mountConfig[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
+                               if (\OC_Group::inGroup($user, $group)) {
+                                       foreach ($mounts as $mountPoint => $options) {
+                                               $mountPoint = self::setUserVars($user, $mountPoint);
+                                               foreach ($options as &$option) {
+                                                       $option = self::setUserVars($user, $option);
+                                               }
+                                               $options['options'] = self::decryptPasswords($options['options']);
+                                               \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+                                       }
+                               }
+                       }
+               }
+               if (isset($mountConfig[self::MOUNT_TYPE_USER])) {
+                       foreach ($mountConfig[self::MOUNT_TYPE_USER] as $mountUser => $mounts) {
+                               if ($mountUser === 'all' or strtolower($mountUser) === strtolower($user)) {
+                                       foreach ($mounts as $mountPoint => $options) {
+                                               $mountPoint = self::setUserVars($user, $mountPoint);
+                                               foreach ($options as &$option) {
+                                                       $option = self::setUserVars($user, $option);
+                                               }
+                                               $options['options'] = self::decryptPasswords($options['options']);
+                                               \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+                                       }
+                               }
+                       }
+               }
+
+               // Load personal mount points
+               $mountConfig = self::readData(true);
+               if (isset($mountConfig[self::MOUNT_TYPE_USER][$user])) {
+                       foreach ($mountConfig[self::MOUNT_TYPE_USER][$user] as $mountPoint => $options) {
+                               $options['options'] = self::decryptPasswords($options['options']);
+                               \OC\Files\Filesystem::mount($options['class'], $options['options'], $mountPoint);
+                       }
+               }
+       }
+
+       /**
+        * fill in the correct values for $user
+        *
+        * @param string $user
+        * @param string $input
+        * @return string
+        */
+       private static function setUserVars($user, $input) {
+               return str_replace('$user', $user, $input);
+       }
+
+
        /**
        * Get details on each of the external storage backends, used for the mount config UI
        * Some backends are not available as a personal backend, f.e. Local and such that have
@@ -288,12 +363,18 @@ class OC_Mount_Config {
                return $personal;
        }
 
+       /**
+        * Test connecting using the given backend configuration
+        * @param string $class backend class name
+        * @param array $options backend configuration options
+        * @return bool true if the connection succeeded, false otherwise
+        */
        private static function getBackendStatus($class, $options) {
                if (self::$skipTest) {
                        return true;
                }
                foreach ($options as &$option) {
-                       $option = str_replace('$user', OCP\User::getUser(), $option);
+                       $option = self::setUserVars(OCP\User::getUser(), $option);
                }
                if (class_exists($class)) {
                        try {
index 6478854eae8c6593bd26922dc61d0334ea605bb2..c31e0c381805812332bfaa6b9d5acf01a226c7fb 100644 (file)
@@ -320,81 +320,11 @@ class Filesystem {
                else {
                        self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user);
                }
-               $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
-               $mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json");
-
-               //move config file to it's new position
-               if (is_file(\OC::$SERVERROOT . '/config/mount.json')) {
-                       rename(\OC::$SERVERROOT . '/config/mount.json', $mount_file);
-               }
-               // Load system mount points
-               if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file($mount_file)) {
-                       if (is_file($mount_file)) {
-                               $mountConfig = json_decode(file_get_contents($mount_file), true);
-                       } elseif (is_file(\OC::$SERVERROOT . '/config/mount.php')) {
-                               $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php'));
-                       }
-                       if (isset($mountConfig['global'])) {
-                               foreach ($mountConfig['global'] as $mountPoint => $options) {
-                                       self::mount($options['class'], $options['options'], $mountPoint);
-                               }
-                       }
-                       if (isset($mountConfig['group'])) {
-                               foreach ($mountConfig['group'] as $group => $mounts) {
-                                       if (\OC_Group::inGroup($user, $group)) {
-                                               foreach ($mounts as $mountPoint => $options) {
-                                                       $mountPoint = self::setUserVars($user, $mountPoint);
-                                                       foreach ($options as &$option) {
-                                                               $option = self::setUserVars($user, $option);
-                                                       }
-                                                       self::mount($options['class'], $options['options'], $mountPoint);
-                                               }
-                                       }
-                               }
-                       }
-                       if (isset($mountConfig['user'])) {
-                               foreach ($mountConfig['user'] as $mountUser => $mounts) {
-                                       if ($mountUser === 'all' or strtolower($mountUser) === strtolower($user)) {
-                                               foreach ($mounts as $mountPoint => $options) {
-                                                       $mountPoint = self::setUserVars($user, $mountPoint);
-                                                       foreach ($options as &$option) {
-                                                               $option = self::setUserVars($user, $option);
-                                                       }
-                                                       self::mount($options['class'], $options['options'], $mountPoint);
-                                               }
-                                       }
-                               }
-                       }
-               }
-               // Load personal mount points
-               if (is_file($root . '/mount.php') or is_file($root . '/mount.json')) {
-                       if (is_file($root . '/mount.json')) {
-                               $mountConfig = json_decode(file_get_contents($root . '/mount.json'), true);
-                       } elseif (is_file($root . '/mount.php')) {
-                               $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php'));
-                       }
-                       if (isset($mountConfig['user'][$user])) {
-                               foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
-                                       self::mount($options['class'], $options['options'], $mountPoint);
-                               }
-                       }
-               }
 
                // Chance to mount for other storages
                \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root));
        }
 
-       /**
-        * fill in the correct values for $user
-        *
-        * @param string $user
-        * @param string $input
-        * @return string
-        */
-       private static function setUserVars($user, $input) {
-               return str_replace('$user', $user, $input);
-       }
-
        /**
         * get the default filesystem view
         *