Skip to content
Snippets Groups Projects
Commit 5f80be76 authored by Michael Gapczynski's avatar Michael Gapczynski
Browse files

Add support for mounting Dropbox in external storage UI

parent 8626f04f
No related branches found
No related tags found
No related merge requests found
<?php
require_once 'Dropbox/autoload.php';
OCP\JSON::checkAppEnabled('files_external');
OCP\JSON::checkLoggedIn();
if (isset($_POST['app_key']) && isset($_POST['app_secret'])) {
$oauth = new Dropbox_OAuth_Curl($_POST['app_key'], $_POST['app_secret']);
if (isset($_POST['step'])) {
switch ($_POST['step']) {
case 1:
try {
if (isset($_POST['callback'])) {
$callback = $_POST['callback'];
} else {
$callback = null;
}
$token = $oauth->getRequestToken();
OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback), 'request_token' => $token['token'], 'request_token_secret' => $token['token_secret'])));
} catch (Exception $exception) {
OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.')));
}
break;
case 2:
if (isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
try {
$oauth->setToken($_POST['request_token'], $_POST['request_token_secret']);
$token = $oauth->getAccessToken();
OCP\JSON::success(array('access_token' => $token['token'], 'access_token_secret' => $token['token_secret']));
} catch (Exception $exception) {
OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.')));
}
}
break;
}
}
} else {
OCP\JSON::error(array('data' => array('message' => 'Please provide a valid Dropbox app key and secret.')));
}
?>
\ No newline at end of file
$(document).ready(function() {
$('#externalStorage tbody tr').each(function() {
if ($(this).find('.backend').data('class') == 'OC_Filestorage_Dropbox') {
var app_key = $(this).find('.configuration [data-parameter="app_key"]').val();
var app_secret = $(this).find('.configuration [data-parameter="app_secret"]').val();
if (app_key == '' && app_secret == '') {
$(this).find('.configuration').append('<a class="button dropbox">Grant access</a>');
} else {
var pos = window.location.search.indexOf('oauth_token') + 12
var token = $(this).find('.configuration [data-parameter="token"]');
if (pos != -1 && window.location.search.substr(pos, $(token).val().length) == $(token).val()) {
var token_secret = $(this).find('.configuration [data-parameter="token_secret"]');
var tr = $(this);
$.post(OC.filePath('files_external', 'ajax', 'dropbox.php'), { step: 2, app_key: app_key, app_secret: app_secret, request_token: $(token).val(), request_token_secret: $(token_secret).val() }, function(result) {
if (result && result.status == 'success') {
$(token).val(result.access_token);
$(token_secret).val(result.access_token_secret);
OC.MountConfig.saveStorage(tr);
} else {
OC.dialogs.alert(result.data.message, 'Error configuring Dropbox storage');
}
});
}
}
return false;
}
});
$('.dropbox').live('click', function(event) {
event.preventDefault();
var app_key = $(this).parent().find('[data-parameter="app_key"]').val();
var app_secret = $(this).parent().find('[data-parameter="app_secret"]').val();
if (app_key != '' && app_secret != '') {
var tr = $(this).parent().parent();
var token = $(this).parent().find('[data-parameter="token"]');
var token_secret = $(this).parent().find('[data-parameter="token_secret"]');
$.post(OC.filePath('files_external', 'ajax', 'dropbox.php'), { step: 1, app_key: app_key, app_secret: app_secret, callback: window.location.href }, function(result) {
if (result && result.status == 'success') {
$(token).val(result.data.request_token);
$(token_secret).val(result.data.request_token_secret);
OC.MountConfig.saveStorage(tr);
window.location = result.data.url;
} else {
OC.dialogs.alert(result.data.message, 'Error configuring Dropbox storage');
}
});
} else {
OC.dialogs.alert('Please provide a valid Dropbox app key and secret.', 'Error configuring Dropbox storage')
}
});
});
$(document).ready(function() { OC.MountConfig={
saveStorage:function(tr) {
$('.chzn-select').chosen();
$('#selectBackend').live('change', function() {
var tr = $(this).parent().parent();
$('#externalStorage tbody').last().append($(tr).clone());
var selected = $(this).find('option:selected').text();
var backendClass = $(this).val();
$(this).parent().text(selected);
$(tr).find('.backend').data('class', $(this).val());
var configurations = $(this).data('configurations');
var td = $(tr).find('td.configuration');
$.each(configurations, function(backend, parameters) {
if (backend == backendClass) {
$.each(parameters['configuration'], function(parameter, placeholder) {
if (placeholder.indexOf('*') != -1) {
td.append('<input type="password" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');
} else if (placeholder.indexOf('!') != -1) {
td.append('<label><input type="checkbox" data-parameter="'+parameter+'" />'+placeholder.substring(1)+'</label>');
} else if (placeholder.indexOf('&') != -1) {
td.append('<input type="text" class="optional" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');
} else {
td.append('<input type="text" data-parameter="'+parameter+'" placeholder="'+placeholder+'" />');
}
});
return false;
}
});
$('.chz-select').chosen();
$(tr).find('td').last().attr('class', 'remove');
$(tr).removeAttr('id');
$(this).remove();
});
$('#externalStorage td').live('change', function() {
var tr = $(this).parent();
var mountPoint = $(tr).find('.mountPoint input').val(); var mountPoint = $(tr).find('.mountPoint input').val();
if (mountPoint == '') { if (mountPoint == '') {
return false; return false;
...@@ -99,6 +64,51 @@ $(document).ready(function() { ...@@ -99,6 +64,51 @@ $(document).ready(function() {
$.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 });
} }
} }
}
}
$(document).ready(function() {
$('.chzn-select').chosen();
$('#selectBackend').live('change', function() {
var tr = $(this).parent().parent();
$('#externalStorage tbody').last().append($(tr).clone());
var selected = $(this).find('option:selected').text();
var backendClass = $(this).val();
$(this).parent().text(selected);
$(tr).find('.backend').data('class', backendClass);
var configurations = $(this).data('configurations');
var td = $(tr).find('td.configuration');
$.each(configurations, function(backend, parameters) {
if (backend == backendClass) {
$.each(parameters['configuration'], function(parameter, placeholder) {
if (placeholder.indexOf('*') != -1) {
td.append('<input type="password" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');
} else if (placeholder.indexOf('!') != -1) {
td.append('<label><input type="checkbox" data-parameter="'+parameter+'" />'+placeholder.substring(1)+'</label>');
} else if (placeholder.indexOf('&') != -1) {
td.append('<input type="text" class="optional" data-parameter="'+parameter+'" placeholder="'+placeholder.substring(1)+'" />');
} else if (placeholder.indexOf('#') != -1) {
td.append('<input type="hidden" data-parameter="'+parameter+'" />');
} else {
td.append('<input type="text" data-parameter="'+parameter+'" placeholder="'+placeholder+'" />');
}
});
if (parameters['custom']) {
OC.addScript('files_external', parameters['custom']);
}
return false;
}
});
$('.chz-select').chosen();
$(tr).find('td').last().attr('class', 'remove');
$(tr).removeAttr('id');
$(this).remove();
});
$('#externalStorage td').live('change', function() {
OC.MountConfig.saveStorage($(this).parent());
}); });
$('td.remove>img').live('click', function() { $('td.remove>img').live('click', function() {
...@@ -130,8 +140,6 @@ $(document).ready(function() { ...@@ -130,8 +140,6 @@ $(document).ready(function() {
$(tr).remove(); $(tr).remove();
}); });
$('#allowUserMounting').bind('change', function() { $('#allowUserMounting').bind('change', function() {
if (this.checked) { if (this.checked) {
OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'yes'); OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'yes');
......
...@@ -30,15 +30,18 @@ class OC_Mount_Config { ...@@ -30,15 +30,18 @@ class OC_Mount_Config {
/** /**
* Get details on each of the external storage backends, used for the mount config UI * 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
* If the configuration parameter should be secret, add a '*' to the beginning of the value * If the configuration parameter should be secret, add a '*' to the beginning of the value
* If the configuration parameter is a boolean, add a '!' to the beginning of the value * If the configuration parameter is a boolean, add a '!' to the beginning of the value
* If the configuration parameter is optional, add a '&' to the beginning of the value * If the configuration parameter is optional, add a '&' to the beginning of the value
* If the configuration parameter is hidden, add a '#' to the begining of the value
* @return array * @return array
*/ */
public static function getBackends() { public static function getBackends() {
return array( return array(
'OC_Filestorage_Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')), 'OC_Filestorage_Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')),
'OC_Filestorage_AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')), 'OC_Filestorage_AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')),
'OC_Filestorage_Dropbox' => array('backend' => 'Dropbox', 'configuration' => array('app_key' => 'App key', 'app_secret' => 'App secret', 'token' => '#token', 'token_secret' => '#token_secret' ), 'custom' => 'dropbox'),
'OC_Filestorage_FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')), 'OC_Filestorage_FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')),
'OC_Filestorage_SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')), 'OC_Filestorage_SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')),
'OC_Filestorage_SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root')), 'OC_Filestorage_SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root')),
......
...@@ -35,16 +35,19 @@ ...@@ -35,16 +35,19 @@
<?php if (isset($_['backends'][$mount['class']]['configuration'][$parameter])): ?> <?php if (isset($_['backends'][$mount['class']]['configuration'][$parameter])): ?>
<?php $placeholder = $_['backends'][$mount['class']]['configuration'][$parameter]; ?> <?php $placeholder = $_['backends'][$mount['class']]['configuration'][$parameter]; ?>
<?php if (strpos($placeholder, '*') !== false): ?> <?php if (strpos($placeholder, '*') !== false): ?>
<input type="password" data-parameter="<?php echo $parameter; ?>" value="<?php echo htmlentities($value); ?>" placeholder="<?php echo substr($placeholder, 1); ?>" /> <input type="password" data-parameter="<?php echo $parameter; ?>" value="<?php echo $value; ?>" placeholder="<?php echo substr($placeholder, 1); ?>" />
<?php elseif(strpos($placeholder, '!') !== false): ?> <?php elseif(strpos($placeholder, '!') !== false): ?>
<label><input type="checkbox" data-parameter="<?php echo $parameter; ?>" <?php if ($value == 'true') echo ' checked="checked"'; ?> /><?php echo substr($placeholder, 1); ?></label> <label><input type="checkbox" data-parameter="<?php echo $parameter; ?>" <?php if ($value == 'true') echo ' checked="checked"'; ?> /><?php echo substr($placeholder, 1); ?></label>
<?php elseif (strpos($placeholder, '&') !== false): ?> <?php elseif (strpos($placeholder, '&') !== false): ?>
<input type="text" class="optional" data-parameter="<?php echo $parameter; ?>" value="<?php echo htmlentities($value); ?>" placeholder="<?php echo substr($placeholder, 1); ?>" /> <input type="text" class="optional" data-parameter="<?php echo $parameter; ?>" value="<?php echo $value; ?>" placeholder="<?php echo substr($placeholder, 1); ?>" />
<?php elseif (strpos($placeholder, '#') !== false): ?>
<input type="hidden" data-parameter="<?php echo $parameter; ?>" value="<?php echo $value; ?>" />
<?php else: ?> <?php else: ?>
<input type="text" data-parameter="<?php echo $parameter; ?>" value="<?php echo htmlentities($value); ?>" placeholder="<?php echo $placeholder; ?>" /> <input type="text" data-parameter="<?php echo $parameter; ?>" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" />
<?php endif; ?> <?php endif; ?>
<?php endif; ?> <?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
<?php if (isset($_['backends'][$mount['class']]['custom'])) OCP\Util::addScript('files_external', $_['backends'][$mount['class']]['custom']); ?>
<?php endif; ?> <?php endif; ?>
</td> </td>
<!--<td class="options"> <!--<td class="options">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment