diff options
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r-- | apps/files_external/lib/amazons3.php | 20 | ||||
-rwxr-xr-x | apps/files_external/lib/config.php | 37 | ||||
-rw-r--r-- | apps/files_external/lib/ftp.php | 39 | ||||
-rw-r--r-- | apps/files_external/lib/google.php | 7 | ||||
-rw-r--r-- | apps/files_external/lib/smb.php | 36 | ||||
-rw-r--r-- | apps/files_external/lib/swift.php | 30 | ||||
-rw-r--r-- | apps/files_external/lib/webdav.php | 54 |
7 files changed, 141 insertions, 82 deletions
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index 37e53a3a670..7bcefd4176c 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -33,12 +33,16 @@ class AmazonS3 extends \OC\Files\Storage\Common { private static $tempFiles = array(); - // TODO options: storage class, encryption server side, encrypt before upload? + // TODO Update to new AWS SDK public function __construct($params) { - $this->id = 'amazon::' . $params['key'] . md5($params['secret']); - $this->s3 = new \AmazonS3(array('key' => $params['key'], 'secret' => $params['secret'])); - $this->bucket = $params['bucket']; + if (isset($params['key']) && isset($params['secret']) && isset($params['bucket'])) { + $this->id = 'amazon::' . $params['key'] . md5($params['secret']); + $this->s3 = new \AmazonS3(array('key' => $params['key'], 'secret' => $params['secret'])); + $this->bucket = $params['bucket']; + } else { + throw new \Exception(); + } } private function getObject($path) { @@ -240,4 +244,12 @@ class AmazonS3 extends \OC\Files\Storage\Common { return $response->isOK(); } + public function test() { + $test = $this->s3->get_canonical_user_id(); + if (isset($test['id']) && $test['id'] != '') { + return true; + } + return false; + } + } diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 905c5d50cde..430269e03d9 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -143,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']) + ); } } } @@ -162,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']) + ); } } } @@ -190,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 @@ -238,7 +261,7 @@ class OC_Mount_Config { $mountPoints[$mountType] = $mount; } self::writeData($isPersonal, $mountPoints); - return true; + return self::getBackendStatus($class, $classOptions); } /** diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index 9b6c037bb57..8a7375ebe38 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -18,26 +18,31 @@ class FTP extends \OC\Files\Storage\StreamWrapper{ private static $tempFiles=array(); public function __construct($params) { - $this->host=$params['host']; - $this->user=$params['user']; - $this->password=$params['password']; - if (isset($params['secure'])) { - if (is_string($params['secure'])) { - $this->secure = ($params['secure'] === 'true'); + if (isset($params['host']) && isset($params['user']) && isset($params['password'])) { + $this->host=$params['host']; + $this->user=$params['user']; + $this->password=$params['password']; + if (isset($params['secure'])) { + if (is_string($params['secure'])) { + $this->secure = ($params['secure'] === 'true'); + } else { + $this->secure = (bool)$params['secure']; + } } else { - $this->secure = (bool)$params['secure']; + $this->secure = false; + } + $this->root=isset($params['root'])?$params['root']:'/'; + if ( ! $this->root || $this->root[0]!='/') { + $this->root='/'.$this->root; + } + //create the root folder if necessary + if ( ! $this->is_dir('')) { + $this->mkdir(''); } } else { - $this->secure = false; - } - $this->root=isset($params['root'])?$params['root']:'/'; - if ( ! $this->root || $this->root[0]!='/') { - $this->root='/'.$this->root; - } - //create the root folder if necesary - if ( ! $this->is_dir('')) { - $this->mkdir(''); + throw new \Exception(); } + } public function getId(){ @@ -83,7 +88,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{ } else { $ext=''; } - $tmpFile=OCP\Files::tmpFile($ext); + $tmpFile=\OCP\Files::tmpFile($ext); \OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack')); if ($this->file_exists($path)) { $this->getFile($path, $tmpFile); diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index f9bd4075f3e..ec7de3f3570 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -596,4 +596,11 @@ class Google extends \OC\Files\Storage\Common { } + public function test() { + if ($this->free_space('')) { + return true; + } + return false; + } + } diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index 62f6591d25a..961efb1a50a 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -18,22 +18,26 @@ class SMB extends \OC\Files\Storage\StreamWrapper{ private $share; public function __construct($params) { - $this->host=$params['host']; - $this->user=$params['user']; - $this->password=$params['password']; - $this->share=$params['share']; - $this->root=isset($params['root'])?$params['root']:'/'; - if ( ! $this->root || $this->root[0]!='/') { - $this->root='/'.$this->root; - } - if (substr($this->root, -1, 1)!='/') { - $this->root.='/'; - } - if ( ! $this->share || $this->share[0]!='/') { - $this->share='/'.$this->share; - } - if(substr($this->share, -1, 1)=='/') { - $this->share = substr($this->share, 0, -1); + if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) { + $this->host=$params['host']; + $this->user=$params['user']; + $this->password=$params['password']; + $this->share=$params['share']; + $this->root=isset($params['root'])?$params['root']:'/'; + if ( ! $this->root || $this->root[0]!='/') { + $this->root='/'.$this->root; + } + if (substr($this->root, -1, 1)!='/') { + $this->root.='/'; + } + if ( ! $this->share || $this->share[0]!='/') { + $this->share='/'.$this->share; + } + if (substr($this->share, -1, 1)=='/') { + $this->share = substr($this->share, 0, -1); + } + } else { + throw new \Exception(); } } diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index a00316c1f84..68c4b48f17c 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -264,27 +264,31 @@ class SWIFT extends \OC\Files\Storage\Common{ private function getSubContainerFile($container) { try { return $container->get_object(self::SUBCONTAINER_FILE); - } catch(NoSuchObjectException $e) { + } catch(\NoSuchObjectException $e) { return $container->create_object(self::SUBCONTAINER_FILE); } } public function __construct($params) { - $this->token=$params['token']; - $this->host=$params['host']; - $this->user=$params['user']; - $this->root=isset($params['root'])?$params['root']:'/'; - if (isset($params['secure'])) { - if (is_string($params['secure'])) { - $this->secure = ($params['secure'] === 'true'); + if (isset($params['token']) && isset($params['host']) && isset($params['user'])) { + $this->token=$params['token']; + $this->host=$params['host']; + $this->user=$params['user']; + $this->root=isset($params['root'])?$params['root']:'/'; + if (isset($params['secure'])) { + if (is_string($params['secure'])) { + $this->secure = ($params['secure'] === 'true'); + } else { + $this->secure = (bool)$params['secure']; + } } else { - $this->secure = (bool)$params['secure']; + $this->secure = false; + } + if ( ! $this->root || $this->root[0]!='/') { + $this->root='/'.$this->root; } } else { - $this->secure = false; - } - if ( ! $this->root || $this->root[0]!='/') { - $this->root='/'.$this->root; + throw new \Exception(); } } diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index ea8fe056e6c..3ba7c48cd57 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -23,28 +23,32 @@ class DAV extends \OC\Files\Storage\Common{ private static $tempFiles=array(); public function __construct($params) { - $host = $params['host']; - //remove leading http[s], will be generated in createBaseUri() - if (substr($host, 0, 8) == "https://") $host = substr($host, 8); - else if (substr($host, 0, 7) == "http://") $host = substr($host, 7); - $this->host=$host; - $this->user=$params['user']; - $this->password=$params['password']; - if (isset($params['secure'])) { - if (is_string($params['secure'])) { - $this->secure = ($params['secure'] === 'true'); + if (isset($params['host']) && isset($params['user']) && isset($params['password'])) { + $host = $params['host']; + //remove leading http[s], will be generated in createBaseUri() + if (substr($host, 0, 8) == "https://") $host = substr($host, 8); + else if (substr($host, 0, 7) == "http://") $host = substr($host, 7); + $this->host=$host; + $this->user=$params['user']; + $this->password=$params['password']; + if (isset($params['secure'])) { + if (is_string($params['secure'])) { + $this->secure = ($params['secure'] === 'true'); + } else { + $this->secure = (bool)$params['secure']; + } } else { - $this->secure = (bool)$params['secure']; + $this->secure = false; + } + $this->root=isset($params['root'])?$params['root']:'/'; + if ( ! $this->root || $this->root[0]!='/') { + $this->root='/'.$this->root; + } + if (substr($this->root, -1, 1)!='/') { + $this->root.='/'; } } else { - $this->secure = false; - } - $this->root=isset($params['root'])?$params['root']:'/'; - if ( ! $this->root || $this->root[0]!='/') { - $this->root='/'.$this->root; - } - if (substr($this->root, -1, 1)!='/') { - $this->root.='/'; + throw new \Exception(); } } @@ -54,11 +58,11 @@ class DAV extends \OC\Files\Storage\Common{ } $this->ready = true; - $settings = array( - 'baseUri' => $this->createBaseUri(), - 'userName' => $this->user, - 'password' => $this->password, - ); + $settings = array( + 'baseUri' => $this->createBaseUri(), + 'userName' => $this->user, + 'password' => $this->password, + ); $this->client = new \Sabre_DAV_Client($settings); @@ -69,7 +73,7 @@ class DAV extends \OC\Files\Storage\Common{ $this->client->addTrustedCertificates($certPath); } } - //create the root folder if necesary + //create the root folder if necessary $this->mkdir(''); } |