]> source.dussan.org Git - nextcloud-server.git/commitdiff
Modified app to dynamically register backends instead of hard-coding them
authorPhilipp Kapfer <philipp.kapfer@gmx.at>
Fri, 8 Mar 2013 17:15:20 +0000 (18:15 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Thu, 3 Apr 2014 14:21:52 +0000 (16:21 +0200)
Moved dependency check to the individual backends instead of the config

Conflicts:
apps/files_external/appinfo/app.php
apps/files_external/lib/config.php

apps/files_external/appinfo/app.php
apps/files_external/lib/config.php
apps/files_external/lib/ftp.php
apps/files_external/lib/smb.php

index aeb7a2cb23a8cb1aff83c3696529d8e9169b6fa0..d6238932cdb04774e41703522cfaa88133098717 100644 (file)
@@ -31,3 +31,78 @@ OCP\Util::connectHook('OC_Filesystem', 'post_initMountPoints', '\OC_Mount_Config
 OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\iRODS', 'login');
 OCP\Util::connectHook('OC_User', 'post_login', 'OC\Files\Storage\SMB_OC', 'login');
 
+OC_Mount_Config::registerBackend('\OC\Files\Storage\Local', array(
+       'backend' => 'Local',
+       'configuration' => array(
+               'datadir' => 'Location')));
+
+OC_Mount_Config::registerBackend('\OC\Files\Storage\AmazonS3', array(
+       'backend' => 'Amazon S3',
+       'configuration' => array(
+               'key' => 'Key',
+               'secret' => '*Secret',
+               'bucket' => 'Bucket')));
+
+OC_Mount_Config::registerBackend('\OC\Files\Storage\Dropbox', array(
+       'backend' => 'Dropbox',
+       'configuration' => array(
+               'configured' => '#configured',
+               'app_key' => 'App key',
+               'app_secret' => 'App secret',
+               'token' => '#token',
+               'token_secret' => '#token_secret'),
+       'custom' => 'dropbox'));
+
+OC_Mount_Config::registerBackend('\OC\Files\Storage\FTP', array(
+       'backend' => 'FTP',
+       'configuration' => array(
+               'host' => 'URL',
+               'user' => 'Username',
+               'password' => '*Password',
+               'root' => '&Root',
+               'secure' => '!Secure ftps://'),
+       'has_dependencies' => true));
+
+OC_Mount_Config::registerBackend('\OC\Files\Storage\Google', array(
+       'backend' => 'Google Drive',
+       'configuration' => array(
+               'configured' => '#configured',
+               'token' => '#token',
+               'token_secret' => '#token secret'),
+       'custom' => 'google'));
+
+OC_Mount_Config::registerBackend('\OC\Files\Storage\SWIFT', array(
+       'backend' => 'OpenStack Swift',
+       'configuration' => array(
+               'host' => 'URL',
+               'user' => 'Username',
+               'token' => '*Token',
+               'root' => '&Root',
+               'secure' => '!Secure ftps://')));
+
+OC_Mount_Config::registerBackend('\OC\Files\Storage\SMB', array(
+       'backend' => 'SMB / CIFS',
+       'configuration' => array(
+               'host' => 'URL',
+               'user' => 'Username',
+               'password' => '*Password',
+               'share' => 'Share',
+               'root' => '&Root'),
+       'has_dependencies' => true));
+
+OC_Mount_Config::registerBackend('\OC\Files\Storage\DAV', array(
+       'backend' => 'ownCloud / WebDAV',
+       'configuration' => array(
+               'host' => 'URL',
+               'user' => 'Username',
+               'password' => '*Password',
+               'root' => '&Root',
+               'secure' => '!Secure https://')));
+
+OC_Mount_Config::registerBackend('\OC\Files\Storage\SFTP', array(
+       'backend' => 'SFTP',
+       'configuration' => array(
+               'host' => 'URL',
+               'user' => 'Username',
+               'password' => '*Password',
+               'root' => '&Root')));
index 472c3963d51d28305b3c3825da536aff3aa42627..00f77ea686b6d6f084a3746dbf608944b28d5e89 100755 (executable)
@@ -39,6 +39,17 @@ class OC_Mount_Config {
        // whether to skip backend test (for unit tests, as this static class is not mockable)
        public static $skipTest = false;
 
+       private static $backends = array();
+
+       public static function registerBackend($class, $definition) {
+               if (!isset($definition['backend'])) {
+                       return false;
+               }
+
+               OC_Mount_Config::$backends[$class] = $definition;
+               return true;
+       }
+
        /**
        * Get details on each of the external storage backends, used for the mount config UI
        * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded
@@ -49,127 +60,20 @@ class OC_Mount_Config {
        * @return string
        */
        public static function getBackends() {
-
-               // FIXME: do not rely on php key order for the options order in the UI
-               $backends['\OC\Files\Storage\Local']=array(
-                               'backend' => 'Local',
-                               'configuration' => array(
-                                       'datadir' => 'Location'));
-
-               $backends['\OC\Files\Storage\AmazonS3']=array(
-                       'backend' => 'Amazon S3 and compliant',
-                       'configuration' => array(
-                               'key' => 'Access Key',
-                               'secret' => '*Secret Key',
-                               'bucket' => 'Bucket',
-                               'hostname' => '&Hostname (optional)',
-                               'port' => '&Port (optional)',
-                               'region' => '&Region (optional)',
-                               'use_ssl' => '!Enable SSL',
-                               'use_path_style' => '!Enable Path Style'));
-
-               $backends['\OC\Files\Storage\Dropbox']=array(
-                       'backend' => 'Dropbox',
-                       'configuration' => array(
-                               'configured' => '#configured',
-                               'app_key' => 'App key',
-                               'app_secret' => '*App secret',
-                               'token' => '#token',
-                               'token_secret' => '#token_secret'),
-                               'custom' => 'dropbox');
-
-               if(OC_Mount_Config::checkphpftp()) $backends['\OC\Files\Storage\FTP']=array(
-                       'backend' => 'FTP',
-                       'configuration' => array(
-                               'host' => 'Hostname',
-                               'user' => 'Username',
-                               'password' => '*Password',
-                               'root' => '&Root',
-                               'secure' => '!Secure ftps://'));
-
-               if(OC_Mount_Config::checkcurl()) $backends['\OC\Files\Storage\Google']=array(
-                       'backend' => 'Google Drive',
-                       'configuration' => array(
-                               'configured' => '#configured',
-                               'client_id' => 'Client ID',
-                               'client_secret' => '*Client secret',
-                               'token' => '#token'),
-                               'custom' => 'google');
-
-               if(OC_Mount_Config::checkcurl()) {
-                       $backends['\OC\Files\Storage\Swift'] = array(
-                               'backend' => 'OpenStack Object Storage',
-                               'configuration' => array(
-                                       'user' => 'Username (required)',
-                                       'bucket' => 'Bucket (required)',
-                                       'region' => '&Region (optional for OpenStack Object Storage)',
-                                       'key' => '*API Key (required for Rackspace Cloud Files)',
-                                       'tenant' => '&Tenantname (required for OpenStack Object Storage)',
-                                       'password' => '*Password (required for OpenStack Object Storage)',
-                                       'service_name' => '&Service Name (required for OpenStack Object Storage)',
-                                       'url' => '&URL of identity endpoint (required for OpenStack Object Storage)',
-                                       'timeout' => '&Timeout of HTTP requests in seconds (optional)',
-                               )
-                       );
-                }
-
-               if (!OC_Util::runningOnWindows()) {
-                       if (OC_Mount_Config::checksmbclient()) {
-                               $backends['\OC\Files\Storage\SMB'] = array(
-                                       'backend' => 'SMB / CIFS',
-                                       'configuration' => array(
-                                               'host' => 'URL',
-                                               'user' => 'Username',
-                                               'password' => '*Password',
-                                               'share' => 'Share',
-                                               'root' => '&Root'));
-                               $backends['\OC\Files\Storage\SMB_OC'] = array(
-                                       'backend' => 'SMB / CIFS using OC login',
-                                       'configuration' => array(
-                                               'host' => 'URL',
-                                               'username_as_share' => '!Username as share',
-                                               'share' => '&Share',
-                                               'root' => '&Root'));
+               $sortFunc = function($a, $b) {
+                       return strcasecmp($a['backend'], $b['backend']);
+               };
+
+               foreach (OC_Mount_Config::$backends as $class => $backend) {
+                       if (isset($backend['has_dependencies']) and $backend['has_dependencies'] === true) {
+                               if ($class::checkDependencies() !== true) {
+                                       continue;
+                               }
                        }
+                       $backends[$class] = $backend;
                }
 
-               if(OC_Mount_Config::checkcurl()){
-                       $backends['\OC\Files\Storage\DAV']=array(
-                               'backend' => 'WebDAV',
-                               'configuration' => array(
-                                       'host' => 'URL',
-                                       'user' => 'Username',
-                                       'password' => '*Password',
-                                       'root' => '&Root',
-                                       'secure' => '!Secure https://'));
-                       $backends['\OC\Files\Storage\OwnCloud']=array(
-                               'backend' => 'ownCloud',
-                               'configuration' => array(
-                                       'host' => 'URL',
-                                       'user' => 'Username',
-                                       'password' => '*Password',
-                                       'root' => '&Remote subfolder',
-                                       'secure' => '!Secure https://'));
-               }
-
-               $backends['\OC\Files\Storage\SFTP']=array(
-                       'backend' => 'SFTP',
-                       'configuration' => array(
-                               'host' => 'URL',
-                               'user' => 'Username',
-                               'password' => '*Password',
-                               'root' => '&Root'));
-
-               $backends['\OC\Files\Storage\iRODS']=array(
-                       'backend' => 'iRODS',
-                       'configuration' => array(
-                               'host' => 'Host',
-                               'port' => 'Port',
-                               'use_logon_credentials' => '!Use ownCloud login',
-                               'user' => 'Username',
-                               'password' => '*Password',
-                               'auth_mode' => 'Authentication Mode',
-                               'zone' => 'Zone'));
+               uasort($backends, $sortFunc);
 
                return($backends);
        }
@@ -613,53 +517,19 @@ class OC_Mount_Config {
                return true;
        }
 
-       /**
-        * check if smbclient is installed
-        */
-       public static function checksmbclient() {
-               if(function_exists('shell_exec')) {
-                       $output=shell_exec('command -v smbclient 2> /dev/null');
-                       return !empty($output);
-               }else{
-                       return false;
-               }
-       }
-
-       /**
-        * check if php-ftp is installed
-        */
-       public static function checkphpftp() {
-               if(function_exists('ftp_login')) {
-                       return true;
-               }else{
-                       return false;
-               }
-       }
-
-       /**
-        * check if curl is installed
-        */
-       public static function checkcurl() {
-               return function_exists('curl_init');
-       }
-
        /**
         * check dependencies
         */
        public static function checkDependencies() {
-               $l= new OC_L10N('files_external');
                $txt='';
-               if (!OC_Util::runningOnWindows()) {
-                       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 />';
+               foreach (OC_Mount_Config::$backends as $class => $backend) {
+                       if (isset($backend['has_dependencies']) and $backend['has_dependencies'] === true) {
+                               $result = $class::checkDependencies();
+                               if ($result !== true) {
+                                       $txt.=$result.'<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::checkcurl()) {
-                       $txt.=$l->t('<b>Warning:</b> The Curl support in PHP is not enabled or installed. Mounting of ownCloud / WebDAV or GoogleDrive is not possible. Please ask your system administrator to install it.').'<br />';
-               }
 
                return $txt;
        }
index 00bf7a189cebabba35e76880e8aec7b69edf8b6c..43635f7f94e35da0104518d5df350ec25a86ac13 100644 (file)
@@ -17,6 +17,18 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
 
        private static $tempFiles=array();
 
+       /**
+        * check if php-ftp is installed
+        */
+       public static function checkDependencies() {
+               if (function_exists('ftp_login')) {
+                       return(true);
+               } else {
+                       $l = new \OC_L10N('files_external');
+                       return $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.');
+               }
+       }
+
        public function __construct($params) {
                if (isset($params['host']) && isset($params['user']) && isset($params['password'])) {
                        $this->host=$params['host'];
index f3f3b3ed7f39b55e8b9fc30d628ab1c64747f1ce..bfe494e867e2a0f6d66c70af5821ecbaadb83c6d 100644 (file)
@@ -17,6 +17,20 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
        private $root;
        private $share;
 
+       /**
+        * check if smbclient is installed
+        */
+       public static function checkDependencies() {
+               if (function_exists('shell_exec')) {
+                       $output = shell_exec('which smbclient');
+                       if (!empty($output)) {
+                               return true;
+                       }
+               }
+               $l = new \OC_L10N('files_external');
+               return $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.');
+       }
+
        public function __construct($params) {
                if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) {
                        $this->host=$params['host'];