aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/config.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/config.php')
-rwxr-xr-xapps/files_external/lib/config.php109
1 files changed, 65 insertions, 44 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 6b0df21461b..11d24045fd9 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -38,7 +38,7 @@ class OC_Mount_Config {
* @return array
*/
public static function getBackends() {
-
+
$backends['\OC\Files\Storage\Local']=array(
'backend' => 'Local',
'configuration' => array(
@@ -77,7 +77,7 @@ class OC_Mount_Config {
'token' => '#token',
'token_secret' => '#token secret'),
'custom' => 'google');
-
+
$backends['\OC\Files\Storage\SWIFT']=array(
'backend' => 'OpenStack Swift',
'configuration' => array(
@@ -86,7 +86,7 @@ class OC_Mount_Config {
'token' => '*Token',
'root' => '&Root',
'secure' => '!Secure ftps://'));
-
+
if(OC_Mount_Config::checksmbclient()) $backends['\OC\Files\Storage\SMB']=array(
'backend' => 'SMB / CIFS',
'configuration' => array(
@@ -95,7 +95,7 @@ class OC_Mount_Config {
'password' => '*Password',
'share' => 'Share',
'root' => '&Root'));
-
+
$backends['\OC\Files\Storage\DAV']=array(
'backend' => 'ownCloud / WebDAV',
'configuration' => array(
@@ -105,6 +105,14 @@ class OC_Mount_Config {
'root' => '&Root',
'secure' => '!Secure https://'));
+ $backends['\OC\Files\Storage\SFTP']=array(
+ 'backend' => 'SFTP',
+ 'configuration' => array(
+ 'host' => 'URL',
+ 'user' => 'Username',
+ 'password' => '*Password',
+ 'root' => '&Root'));
+
return($backends);
}
@@ -135,7 +143,9 @@ class OC_Mount_Config {
'class' => $mount['class'],
'backend' => $backends[$mount['class']]['backend'],
'configuration' => $mount['options'],
- 'applicable' => array('groups' => array($group), 'users' => array()));
+ 'applicable' => array('groups' => array($group), 'users' => array()),
+ 'status' => self::getBackendStatus($mount['class'], $mount['options'])
+ );
}
}
}
@@ -154,10 +164,13 @@ class OC_Mount_Config {
$system[$mountPoint]['applicable']['users']
= array_merge($system[$mountPoint]['applicable']['users'], array($user));
} else {
- $system[$mountPoint] = array('class' => $mount['class'],
+ $system[$mountPoint] = array(
+ 'class' => $mount['class'],
'backend' => $backends[$mount['class']]['backend'],
'configuration' => $mount['options'],
- 'applicable' => array('groups' => array(), 'users' => array($user)));
+ 'applicable' => array('groups' => array(), 'users' => array($user)),
+ 'status' => self::getBackendStatus($mount['class'], $mount['options'])
+ );
}
}
}
@@ -182,14 +195,32 @@ class OC_Mount_Config {
$mount['class'] = '\OC\Files\Storage\\'.substr($mount['class'], 15);
}
// Remove '/uid/files/' from mount point
- $personal[substr($mountPoint, strlen($uid) + 8)] = array('class' => $mount['class'],
- 'backend' => $backends[$mount['class']]['backend'],
- 'configuration' => $mount['options']);
+ $personal[substr($mountPoint, strlen($uid) + 8)] = array(
+ 'class' => $mount['class'],
+ 'backend' => $backends[$mount['class']]['backend'],
+ 'configuration' => $mount['options'],
+ 'status' => self::getBackendStatus($mount['class'], $mount['options'])
+ );
}
}
return $personal;
}
+ private static function getBackendStatus($class, $options) {
+ foreach ($options as &$option) {
+ $option = str_replace('$user', OCP\User::getUser(), $option);
+ }
+ if (class_exists($class)) {
+ try {
+ $storage = new $class($options);
+ return $storage->test();
+ } catch (Exception $exception) {
+ return false;
+ }
+ }
+ return false;
+ }
+
/**
* Add a mount point to the filesystem
* @param string Mount point
@@ -230,7 +261,7 @@ class OC_Mount_Config {
$mountPoints[$mountType] = $mount;
}
self::writeData($isPersonal, $mountPoints);
- return true;
+ return self::getBackendStatus($class, $classOptions);
}
/**
@@ -271,13 +302,22 @@ class OC_Mount_Config {
* @return array
*/
private static function readData($isPersonal) {
+ $parser = new \OC\ArrayParser();
if ($isPersonal) {
- $file = OC_User::getHome(OCP\User::getUser()).'/mount.php';
+ $phpFile = OC_User::getHome(OCP\User::getUser()).'/mount.php';
+ $jsonFile = OC_User::getHome(OCP\User::getUser()).'/mount.json';
} else {
- $file = OC::$SERVERROOT.'/config/mount.php';
+ $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
+ $phpFile = OC::$SERVERROOT.'/config/mount.php';
+ $jsonFile = $datadir . '/mount.json';
}
- if (is_file($file)) {
- $mountPoints = include $file;
+ if (is_file($jsonFile)) {
+ $mountPoints = json_decode(file_get_contents($jsonFile), true);
+ if (is_array($mountPoints)) {
+ return $mountPoints;
+ }
+ } elseif (is_file($phpFile)) {
+ $mountPoints = $parser->parsePHP(file_get_contents($phpFile));
if (is_array($mountPoints)) {
return $mountPoints;
}
@@ -292,35 +332,12 @@ class OC_Mount_Config {
*/
private static function writeData($isPersonal, $data) {
if ($isPersonal) {
- $file = OC_User::getHome(OCP\User::getUser()).'/mount.php';
+ $file = OC_User::getHome(OCP\User::getUser()).'/mount.json';
} else {
- $file = OC::$SERVERROOT.'/config/mount.php';
- }
- $content = "<?php return array (\n";
- if (isset($data[self::MOUNT_TYPE_GROUP])) {
- $content .= "\t'group' => array (\n";
- foreach ($data[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
- $content .= "\t\t'".$group."' => array (\n";
- foreach ($mounts as $mountPoint => $mount) {
- $content .= "\t\t\t'".addcslashes($mountPoint,"'")."' => ".str_replace("\n", '', var_export($mount, true)).", \n";
-
- }
- $content .= "\t\t),\n";
- }
- $content .= "\t),\n";
- }
- if (isset($data[self::MOUNT_TYPE_USER])) {
- $content .= "\t'user' => array (\n";
- foreach ($data[self::MOUNT_TYPE_USER] as $user => $mounts) {
- $content .= "\t\t'".$user."' => array (\n";
- foreach ($mounts as $mountPoint => $mount) {
- $content .= "\t\t\t'".addcslashes($mountPoint,"'")."' => ".str_replace("\n", '', var_export($mount, true)).",\n";
- }
- $content .= "\t\t),\n";
- }
- $content .= "\t),\n";
+ $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
+ $file = $datadir . '/mount.json';
}
- $content .= ");\n?>";
+ $content = json_encode($data);
@file_put_contents($file, $content);
}
@@ -402,8 +419,12 @@ class OC_Mount_Config {
public static function checkDependencies() {
$l= new OC_L10N('files_external');
$txt='';
- if(!OC_Mount_Config::checksmbclient()) $txt.=$l->t('<b>Warning:</b> "smbclient" is not installed. Mounting of CIFS/SMB shares is not possible. Please ask your system administrator to install it.').'<br />';
- if(!OC_Mount_Config::checkphpftp()) $txt.=$l->t('<b>Warning:</b> The FTP support in PHP is not enabled or installed. Mounting of FTP shares is not possible. Please ask your system administrator to install it.').'<br />';
+ if(!OC_Mount_Config::checksmbclient()) {
+ $txt.=$l->t('<b>Warning:</b> "smbclient" is not installed. Mounting of CIFS/SMB shares is not possible. Please ask your system administrator to install it.').'<br />';
+ }
+ if(!OC_Mount_Config::checkphpftp()) {
+ $txt.=$l->t('<b>Warning:</b> The FTP support in PHP is not enabled or installed. Mounting of FTP shares is not possible. Please ask your system administrator to install it.').'<br />';
+ }
return($txt);
}