|
|
|
|
@ -35,6 +35,7 @@ class OC_Mount_Config {
|
|
|
|
|
const MOUNT_TYPE_GLOBAL = 'global';
|
|
|
|
|
const MOUNT_TYPE_GROUP = 'group';
|
|
|
|
|
const MOUNT_TYPE_USER = 'user';
|
|
|
|
|
const MOUNT_TYPE_PERSONAL = 'personal';
|
|
|
|
|
|
|
|
|
|
// whether to skip backend test (for unit tests, as this static class is not mockable)
|
|
|
|
|
public static $skipTest = false;
|
|
|
|
|
@ -126,6 +127,8 @@ class OC_Mount_Config {
|
|
|
|
|
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
|
|
|
|
|
$mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json");
|
|
|
|
|
|
|
|
|
|
$backends = self::getBackends();
|
|
|
|
|
|
|
|
|
|
//move config file to it's new position
|
|
|
|
|
if (is_file(\OC::$SERVERROOT . '/config/mount.json')) {
|
|
|
|
|
rename(\OC::$SERVERROOT . '/config/mount.json', $mount_file);
|
|
|
|
|
@ -133,12 +136,45 @@ class OC_Mount_Config {
|
|
|
|
|
|
|
|
|
|
// Load system mount points
|
|
|
|
|
$mountConfig = self::readData();
|
|
|
|
|
|
|
|
|
|
// Global mount points (is this redundant?)
|
|
|
|
|
if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
|
|
|
|
|
foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
|
|
|
|
|
$options['options'] = self::decryptPasswords($options['options']);
|
|
|
|
|
$mountPoints[$mountPoint] = $options;
|
|
|
|
|
if (!isset($options['priority'])) {
|
|
|
|
|
$options['priority'] = $backends[$options['class']]['priority'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Override if priority greater
|
|
|
|
|
if ( (!isset($mountPoints[$mountPoint]))
|
|
|
|
|
|| ($options['priority'] >= $mountPoints[$mountPoint]['priority']) ) {
|
|
|
|
|
$options['priority_type'] = self::MOUNT_TYPE_GLOBAL;
|
|
|
|
|
$mountPoints[$mountPoint] = $options;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// All user mount points
|
|
|
|
|
if (isset($mountConfig[self::MOUNT_TYPE_USER]) && isset($mountConfig[self::MOUNT_TYPE_USER]['all'])) {
|
|
|
|
|
$mounts = $mountConfig[self::MOUNT_TYPE_USER]['all'];
|
|
|
|
|
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']);
|
|
|
|
|
if (!isset($options['priority'])) {
|
|
|
|
|
$options['priority'] = $backends[$options['class']]['priority'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Override if priority greater
|
|
|
|
|
if ( (!isset($mountPoints[$mountPoint]))
|
|
|
|
|
|| ($options['priority'] >= $mountPoints[$mountPoint]['priority']) ) {
|
|
|
|
|
$options['priority_type'] = self::MOUNT_TYPE_GLOBAL;
|
|
|
|
|
$mountPoints[$mountPoint] = $options;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Group mount points
|
|
|
|
|
if (isset($mountConfig[self::MOUNT_TYPE_GROUP])) {
|
|
|
|
|
foreach ($mountConfig[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
|
|
|
|
|
if (\OC_Group::inGroup($user, $group)) {
|
|
|
|
|
@ -148,21 +184,42 @@ class OC_Mount_Config {
|
|
|
|
|
$option = self::setUserVars($user, $option);
|
|
|
|
|
}
|
|
|
|
|
$options['options'] = self::decryptPasswords($options['options']);
|
|
|
|
|
$mountPoints[$mountPoint] = $options;
|
|
|
|
|
if (!isset($options['priority'])) {
|
|
|
|
|
$options['priority'] = $backends[$options['class']]['priority'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Override if priority greater or if priority type different
|
|
|
|
|
if ( (!isset($mountPoints[$mountPoint]))
|
|
|
|
|
|| ($options['priority'] >= $mountPoints[$mountPoint]['priority'])
|
|
|
|
|
|| ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_GROUP) ) {
|
|
|
|
|
$options['priority_type'] = self::MOUNT_TYPE_GROUP;
|
|
|
|
|
$mountPoints[$mountPoint] = $options;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// User mount points
|
|
|
|
|
if (isset($mountConfig[self::MOUNT_TYPE_USER])) {
|
|
|
|
|
foreach ($mountConfig[self::MOUNT_TYPE_USER] as $mountUser => $mounts) {
|
|
|
|
|
if ($mountUser === 'all' or strtolower($mountUser) === strtolower($user)) {
|
|
|
|
|
if (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']);
|
|
|
|
|
$mountPoints[$mountPoint] = $options;
|
|
|
|
|
if (!isset($options['priority'])) {
|
|
|
|
|
$options['priority'] = $backends[$options['class']]['priority'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Override if priority greater or if priority type different
|
|
|
|
|
if ( (!isset($mountPoints[$mountPoint]))
|
|
|
|
|
|| ($options['priority'] >= $mountPoints[$mountPoint]['priority'])
|
|
|
|
|
|| ($mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_USER) ) {
|
|
|
|
|
$options['priority_type'] = self::MOUNT_TYPE_USER;
|
|
|
|
|
$mountPoints[$mountPoint] = $options;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -173,6 +230,9 @@ class OC_Mount_Config {
|
|
|
|
|
if (isset($mountConfig[self::MOUNT_TYPE_USER][$user])) {
|
|
|
|
|
foreach ($mountConfig[self::MOUNT_TYPE_USER][$user] as $mountPoint => $options) {
|
|
|
|
|
$options['options'] = self::decryptPasswords($options['options']);
|
|
|
|
|
|
|
|
|
|
// Always override previous config
|
|
|
|
|
$options['priority_type'] = self::MOUNT_TYPE_PERSONAL;
|
|
|
|
|
$mountPoints[$mountPoint] = $options;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -244,6 +304,9 @@ class OC_Mount_Config {
|
|
|
|
|
$mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15);
|
|
|
|
|
}
|
|
|
|
|
$mount['options'] = self::decryptPasswords($mount['options']);
|
|
|
|
|
if (!isset($mount['priority'])) {
|
|
|
|
|
$mount['priority'] = $backends[$mount['class']]['priority'];
|
|
|
|
|
}
|
|
|
|
|
// Remove '/$user/files/' from mount point
|
|
|
|
|
$mountPoint = substr($mountPoint, 13);
|
|
|
|
|
|
|
|
|
|
@ -251,6 +314,7 @@ class OC_Mount_Config {
|
|
|
|
|
'class' => $mount['class'],
|
|
|
|
|
'mountpoint' => $mountPoint,
|
|
|
|
|
'backend' => $backends[$mount['class']]['backend'],
|
|
|
|
|
'priority' => $mount['priority'],
|
|
|
|
|
'options' => $mount['options'],
|
|
|
|
|
'applicable' => array('groups' => array($group), 'users' => array()),
|
|
|
|
|
'status' => self::getBackendStatus($mount['class'], $mount['options'], false)
|
|
|
|
|
@ -275,12 +339,16 @@ class OC_Mount_Config {
|
|
|
|
|
$mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15);
|
|
|
|
|
}
|
|
|
|
|
$mount['options'] = self::decryptPasswords($mount['options']);
|
|
|
|
|
if (!isset($mount['priority'])) {
|
|
|
|
|
$mount['priority'] = $backends[$mount['class']]['priority'];
|
|
|
|
|
}
|
|
|
|
|
// Remove '/$user/files/' from mount point
|
|
|
|
|
$mountPoint = substr($mountPoint, 13);
|
|
|
|
|
$config = array(
|
|
|
|
|
'class' => $mount['class'],
|
|
|
|
|
'mountpoint' => $mountPoint,
|
|
|
|
|
'backend' => $backends[$mount['class']]['backend'],
|
|
|
|
|
'priority' => $mount['priority'],
|
|
|
|
|
'options' => $mount['options'],
|
|
|
|
|
'applicable' => array('groups' => array(), 'users' => array($user)),
|
|
|
|
|
'status' => self::getBackendStatus($mount['class'], $mount['options'], false)
|
|
|
|
|
@ -363,6 +431,7 @@ class OC_Mount_Config {
|
|
|
|
|
* @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
|
|
|
|
|
* @param string $applicable User or group to apply mount to
|
|
|
|
|
* @param bool $isPersonal Personal or system mount point i.e. is this being called from the personal or admin page
|
|
|
|
|
* @param int|null $priority Mount point priority, null for default
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public static function addMountPoint($mountPoint,
|
|
|
|
|
@ -370,7 +439,8 @@ class OC_Mount_Config {
|
|
|
|
|
$classOptions,
|
|
|
|
|
$mountType,
|
|
|
|
|
$applicable,
|
|
|
|
|
$isPersonal = false) {
|
|
|
|
|
$isPersonal = false,
|
|
|
|
|
$priority = null) {
|
|
|
|
|
$backends = self::getBackends();
|
|
|
|
|
$mountPoint = OC\Files\Filesystem::normalizePath($mountPoint);
|
|
|
|
|
if ($mountPoint === '' || $mountPoint === '/') {
|
|
|
|
|
@ -400,9 +470,24 @@ class OC_Mount_Config {
|
|
|
|
|
'options' => self::encryptPasswords($classOptions))
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
if (! $isPersonal && !is_null($priority)) {
|
|
|
|
|
$mount[$applicable][$mountPoint]['priority'] = $priority;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mountPoints = self::readData($isPersonal ? OCP\User::getUser() : NULL);
|
|
|
|
|
$mountPoints = self::mergeMountPoints($mountPoints, $mount, $mountType);
|
|
|
|
|
|
|
|
|
|
// Set default priority if none set
|
|
|
|
|
if (!isset($mountPoints[$mountType][$applicable][$mountPoint]['priority'])) {
|
|
|
|
|
if (isset($backends[$class]['priority'])) {
|
|
|
|
|
$mountPoints[$mountType][$applicable][$mountPoint]['priority']
|
|
|
|
|
= $backends[$class]['priority'];
|
|
|
|
|
} else {
|
|
|
|
|
$mountPoints[$mountType][$applicable][$mountPoint]['priority']
|
|
|
|
|
= 100;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self::writeData($isPersonal ? OCP\User::getUser() : NULL, $mountPoints);
|
|
|
|
|
|
|
|
|
|
return self::getBackendStatus($class, $classOptions, $isPersonal);
|
|
|
|
|
@ -690,8 +775,16 @@ class OC_Mount_Config {
|
|
|
|
|
*/
|
|
|
|
|
private static function mergeMountPoints($data, $mountPoint, $mountType) {
|
|
|
|
|
$applicable = key($mountPoint);
|
|
|
|
|
$mountPath = key($mountPoint[$applicable]);
|
|
|
|
|
if (isset($data[$mountType])) {
|
|
|
|
|
if (isset($data[$mountType][$applicable])) {
|
|
|
|
|
// Merge priorities
|
|
|
|
|
if (isset($data[$mountType][$applicable][$mountPath])
|
|
|
|
|
&& isset($data[$mountType][$applicable][$mountPath]['priority'])
|
|
|
|
|
&& !isset($mountPoint[$applicable][$mountPath]['priority'])) {
|
|
|
|
|
$mountPoint[$applicable][$mountPath]['priority']
|
|
|
|
|
= $data[$mountType][$applicable][$mountPath]['priority'];
|
|
|
|
|
}
|
|
|
|
|
$data[$mountType][$applicable]
|
|
|
|
|
= array_merge($data[$mountType][$applicable], $mountPoint[$applicable]);
|
|
|
|
|
} else {
|
|
|
|
|
|