summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-03-19 12:20:48 +0100
committerVincent Petry <pvince81@owncloud.com>2014-03-19 12:45:38 +0100
commit4cb53f77b2e09fa16129700b459e8b4edcd3eb64 (patch)
tree4a812569c5c07396519c46a251c656f5c63976ca /apps
parent80180bea325c994be3f24d14ec7dd0682429396d (diff)
downloadnextcloud-server-4cb53f77b2e09fa16129700b459e8b4edcd3eb64.tar.gz
nextcloud-server-4cb53f77b2e09fa16129700b459e8b4edcd3eb64.zip
Moved external storage mounting code to files_external app
Moved the mounting code for external storage from OC\Filesystem::initMountPoint to files_external using the post_initMountPoints hook
Diffstat (limited to 'apps')
-rw-r--r--apps/files_external/appinfo/app.php3
-rwxr-xr-xapps/files_external/lib/config.php87
2 files changed, 86 insertions, 4 deletions
diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php
index 5b1cd86a170..0e83660f845 100644
--- a/apps/files_external/appinfo/app.php
+++ b/apps/files_external/appinfo/app.php
@@ -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');
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 0a68de1cdb1..28761b4862e 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -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';
@@ -167,6 +167,81 @@ class OC_Mount_Config {
}
/**
+ * 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
* been disabled by the admin.
@@ -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 {