summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorMichael Gapczynski <mtgap@owncloud.com>2012-12-24 13:45:52 -0500
committerMichael Gapczynski <mtgap@owncloud.com>2012-12-24 13:45:52 -0500
commit0dbf1d02600ef4075ceffe9c62c1ed32cc24592f (patch)
tree2db27ca226035add120fec8f2ca529c84001d0f6 /apps/files_external
parent5fb4ed2d92b28bfcd0647233421a3614b00e6d4c (diff)
downloadnextcloud-server-0dbf1d02600ef4075ceffe9c62c1ed32cc24592f.tar.gz
nextcloud-server-0dbf1d02600ef4075ceffe9c62c1ed32cc24592f.zip
Show status icons for mount points in external storage UI
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/ajax/addMountPoint.php5
-rw-r--r--apps/files_external/css/settings.css5
-rw-r--r--apps/files_external/img/error.pngbin0 -> 533 bytes
-rw-r--r--apps/files_external/img/success.pngbin0 -> 545 bytes
-rw-r--r--apps/files_external/img/waiting.pngbin0 -> 512 bytes
-rw-r--r--apps/files_external/js/settings.js21
-rw-r--r--apps/files_external/lib/amazons3.php14
-rwxr-xr-xapps/files_external/lib/config.php37
-rwxr-xr-xapps/files_external/lib/dropbox.php5
-rw-r--r--apps/files_external/lib/ftp.php41
-rw-r--r--apps/files_external/lib/google.php4
-rw-r--r--apps/files_external/lib/smb.php50
-rw-r--r--apps/files_external/lib/swift.php45
-rw-r--r--apps/files_external/lib/webdav.php77
-rw-r--r--apps/files_external/templates/settings.php6
15 files changed, 203 insertions, 107 deletions
diff --git a/apps/files_external/ajax/addMountPoint.php b/apps/files_external/ajax/addMountPoint.php
index 4cd8871b310..fed2ddfcf3d 100644
--- a/apps/files_external/ajax/addMountPoint.php
+++ b/apps/files_external/ajax/addMountPoint.php
@@ -10,9 +10,10 @@ if ($_POST['isPersonal'] == 'true') {
OCP\JSON::checkAdminUser();
$isPersonal = false;
}
-OC_Mount_Config::addMountPoint($_POST['mountPoint'],
+$status = OC_Mount_Config::addMountPoint($_POST['mountPoint'],
$_POST['class'],
$_POST['classOptions'],
$_POST['mountType'],
$_POST['applicable'],
- $isPersonal); \ No newline at end of file
+ $isPersonal);
+OCP\JSON::success(array('data' => array('message' => $status))); \ No newline at end of file
diff --git a/apps/files_external/css/settings.css b/apps/files_external/css/settings.css
index ca4b1c3ba89..94b453793b1 100644
--- a/apps/files_external/css/settings.css
+++ b/apps/files_external/css/settings.css
@@ -1,4 +1,7 @@
-.error { color: #FF3B3B; }
+td.status>span { display:inline-block; height:16px; width:16px; }
+span.success { background-image: url('../img/success.png'); background-repeat:no-repeat; }
+span.error { background-image: url('../img/error.png'); background-repeat:no-repeat; }
+span.waiting { background-image: url('../img/waiting.png'); background-repeat:no-repeat; }
td.mountPoint, td.backend { width:10em; }
td.remove>img { visibility:hidden; padding-top:0.8em; }
tr:hover>td.remove>img { visibility:visible; cursor:pointer; }
diff --git a/apps/files_external/img/error.png b/apps/files_external/img/error.png
new file mode 100644
index 00000000000..e8cf45e7a41
--- /dev/null
+++ b/apps/files_external/img/error.png
Binary files differ
diff --git a/apps/files_external/img/success.png b/apps/files_external/img/success.png
new file mode 100644
index 00000000000..6f7022ee7f5
--- /dev/null
+++ b/apps/files_external/img/success.png
Binary files differ
diff --git a/apps/files_external/img/waiting.png b/apps/files_external/img/waiting.png
new file mode 100644
index 00000000000..02a8cbff0da
--- /dev/null
+++ b/apps/files_external/img/waiting.png
Binary files differ
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js
index 0dc983ca8ad..eb74dd487f7 100644
--- a/apps/files_external/js/settings.js
+++ b/apps/files_external/js/settings.js
@@ -4,6 +4,7 @@ OC.MountConfig={
if (mountPoint == '') {
return false;
}
+ var statusSpan = $(tr).find('.status span');
var backendClass = $(tr).find('.backend').data('class');
var configuration = $(tr).find('.configuration input');
var addMountPoint = true;
@@ -27,6 +28,7 @@ OC.MountConfig={
}
});
if (addMountPoint) {
+ var status = false;
if ($('#externalStorage').data('admin') === true) {
var isPersonal = false;
var multiselect = $(tr).find('.chzn-select').val();
@@ -47,7 +49,14 @@ OC.MountConfig={
oldUsers.splice($.inArray(applicable, oldUsers), 1);
}
}
- $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
+ $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal }, function(result) {
+ statusSpan.removeClass();
+ if (result && result.status == 'success' && result.data.message) {
+ statusSpan.addClass('success');
+ } else {
+ statusSpan.addClass('error');
+ }
+ });
});
var mountType = 'group';
$.each(oldGroups, function(index, applicable) {
@@ -61,7 +70,14 @@ OC.MountConfig={
var isPersonal = true;
var mountType = 'user';
var applicable = OC.currentUser;
- $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal });
+ $.post(OC.filePath('files_external', 'ajax', 'addMountPoint.php'), { mountPoint: mountPoint, class: backendClass, classOptions: classOptions, mountType: mountType, applicable: applicable, isPersonal: isPersonal }, function(result) {
+ statusSpan.removeClass();
+ if (result && result.status == 'success' && result.data.message) {
+ statusSpan.addClass('success');
+ } else {
+ statusSpan.addClass('error');
+ }
+ });
}
return true;
}
@@ -82,6 +98,7 @@ $(document).ready(function() {
$(tr).find('.mountPoint input').val(suggestMountPoint(selected.replace(/\s+/g, '')));
}
$(tr).addClass(backendClass);
+ $(tr).find('.status').append('<span class="waiting"></span>');
$(tr).find('.backend').data('class', backendClass);
var configurations = $(this).data('configurations');
var td = $(tr).find('td.configuration');
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php
index 235ade06db6..c1b2e889bba 100644
--- a/apps/files_external/lib/amazons3.php
+++ b/apps/files_external/lib/amazons3.php
@@ -30,11 +30,19 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_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->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->s3 = new AmazonS3(array('key' => $params['key'], 'secret' => $params['secret']));
+ $this->bucket = $params['bucket'];
+ $test = $this->s3->get_canonical_user_id();
+ if (!isset($test['id']) || $test['id'] == '') {
+ throw new Exception();
+ }
+ } else {
+ throw new Exception();
+ }
}
private function getObject($path) {
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 1be544fbc07..99d31c5aa2d 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -131,7 +131,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'])
+ );
}
}
}
@@ -146,10 +148,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'])
+ );
}
}
}
@@ -170,14 +175,32 @@ class OC_Mount_Config {
if (isset($mountPoints[self::MOUNT_TYPE_USER][$uid])) {
foreach ($mountPoints[self::MOUNT_TYPE_USER][$uid] as $mountPoint => $mount) {
// 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 {
+ new $class($options);
+ return true;
+ } catch (Exception $exception) {
+ return false;
+ }
+ }
+ return false;
+ }
+
/**
* Add directory for mount point to the filesystem
* @param OC_Fileview instance $view
@@ -259,7 +282,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/dropbox.php b/apps/files_external/lib/dropbox.php
index 33ca14cab15..a4f3f678344 100755
--- a/apps/files_external/lib/dropbox.php
+++ b/apps/files_external/lib/dropbox.php
@@ -41,7 +41,10 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common {
$oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']);
$oauth->setToken($params['token'], $params['token_secret']);
$this->dropbox = new Dropbox_API($oauth, 'dropbox');
- $this->mkdir('');
+ $test = $this->stat('');
+ if (!$test) {
+ throw new Exception('Creating OC_Filestorage_Dropbox storage failed');
+ }
} else {
throw new Exception('Creating OC_Filestorage_Dropbox storage failed');
}
diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php
index e796ae446bf..ac487156c18 100644
--- a/apps/files_external/lib/ftp.php
+++ b/apps/files_external/lib/ftp.php
@@ -16,26 +16,35 @@ class OC_FileStorage_FTP extends OC_FileStorage_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;
+ }
+ $test = $this->stat('');
+ if (!$test) {
+ throw new Exception();
+ }
+ //create the root folder if necesary
+ 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();
}
+
}
/**
diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php
index c836a5a07c0..19772d4d37f 100644
--- a/apps/files_external/lib/google.php
+++ b/apps/files_external/lib/google.php
@@ -42,6 +42,10 @@ class OC_Filestorage_Google extends OC_Filestorage_Common {
$this->oauth_token = new OAuthToken($params['token'], $params['token_secret']);
$this->sig_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->entries = array();
+ $test = $this->free_space('');
+ if (!$test) {
+ throw new Exception();
+ }
} else {
throw new Exception('Creating OC_Filestorage_Google storage failed');
}
diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php
index 071a9cd5f95..97454b46015 100644
--- a/apps/files_external/lib/smb.php
+++ b/apps/files_external/lib/smb.php
@@ -16,28 +16,36 @@ class OC_FileStorage_SMB extends OC_FileStorage_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);
- }
-
- //create the root folder if necesary
- if ( ! $this->is_dir('')) {
- $this->mkdir('');
+ 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);
+ }
+ $test = $this->stat('');
+ if (!$test) {
+ throw new Exception();
+ }
+ //create the root folder if necesary
+ if ( ! $this->is_dir('')) {
+ $this->mkdir('');
+ }
+ } else {
+ throw new Exception();
}
+
}
public function constructUrl($path) {
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index a071dfdbb03..e2add2c9873 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -267,32 +267,37 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
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;
}
- } else {
- $this->secure = false;
- }
- if ( ! $this->root || $this->root[0]!='/') {
- $this->root='/'.$this->root;
- }
- $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host);
- $this->auth->authenticate();
+ if ( ! $this->root || $this->root[0]!='/') {
+ $this->root='/'.$this->root;
+ }
+ $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host);
+ $this->auth->authenticate();
- $this->conn = new CF_Connection($this->auth);
+ $this->conn = new CF_Connection($this->auth);
- if ( ! $this->containerExists('/')) {
- $this->rootContainer=$this->createContainer('/');
+ if ( ! $this->containerExists('/')) {
+ $this->rootContainer=$this->createContainer('/');
+ } else {
+ $this->rootContainer=$this->getContainer('/');
+ }
} else {
- $this->rootContainer=$this->getContainer('/');
+ throw new Exception();
}
+
}
diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php
index 68aca228bc5..cfe073a1f1c 100644
--- a/apps/files_external/lib/webdav.php
+++ b/apps/files_external/lib/webdav.php
@@ -20,47 +20,56 @@ class OC_FileStorage_DAV extends OC_Filestorage_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.='/';
- }
- $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 OC_Connector_Sabre_Client($settings);
+ $this->client = new OC_Connector_Sabre_Client($settings);
- $caview = \OCP\Files::getStorage('files_external');
- if ($caview) {
- $certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt';
- if (file_exists($certPath)) {
- $this->client->addTrustedCertificates($certPath);
+ $caview = \OCP\Files::getStorage('files_external');
+ if ($caview) {
+ $certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt';
+ if (file_exists($certPath)) {
+ $this->client->addTrustedCertificates($certPath);
+ }
+ }
+ $test = $this->stat('');
+ if (!$test) {
+ throw new Exception();
}
+ //create the root folder if necesary
+ $this->mkdir('');
+ } else {
+ throw new Exception();
}
- //create the root folder if necesary
- $this->mkdir('');
+
}
private function createBaseUri() {
diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php
index dd537d779a6..9702ebfb4c7 100644
--- a/apps/files_external/templates/settings.php
+++ b/apps/files_external/templates/settings.php
@@ -5,6 +5,7 @@
<table id="externalStorage" data-admin='<?php echo json_encode($_['isAdminPage']); ?>'>
<thead>
<tr>
+ <th></th>
<th><?php echo $l->t('Mount point'); ?></th>
<th><?php echo $l->t('Backend'); ?></th>
<th><?php echo $l->t('Configuration'); ?></th>
@@ -17,6 +18,11 @@
<?php $_['mounts'] = array_merge($_['mounts'], array('' => array())); ?>
<?php foreach ($_['mounts'] as $mountPoint => $mount): ?>
<tr <?php echo ($mountPoint != '') ? 'class="'.$mount['class'].'"' : 'id="addMountPoint"'; ?>>
+ <td class="status">
+ <?php if (isset($mount['status'])): ?>
+ <span class="<?php echo ($mount['status']) ? 'success' : 'error'; ?>"></span>
+ <?php endif; ?>
+ </td>
<td class="mountPoint"><input type="text" name="mountPoint"
value="<?php echo $mountPoint; ?>"
placeholder="<?php echo $l->t('Mount point'); ?>" /></td>