summaryrefslogtreecommitdiffstats
path: root/apps/files_external/js
diff options
context:
space:
mode:
authorRoss Nicoll <jrn@jrn.me.uk>2014-12-19 17:23:24 +0000
committerRoss Nicoll <jrn@jrn.me.uk>2015-01-14 17:00:34 +0000
commit64f4f8fc84fd8fc27f0e9e316a2c4c2500c7134f (patch)
tree52ea57272b9dfd18d8a21b33a42be2627c661d37 /apps/files_external/js
parentc8fa85451c2481b6afb438f41f12144b2929d320 (diff)
downloadnextcloud-server-64f4f8fc84fd8fc27f0e9e316a2c4c2500c7134f.tar.gz
nextcloud-server-64f4f8fc84fd8fc27f0e9e316a2c4c2500c7134f.zip
Add support for SFTP key authentication
Add support for external files accessed via SFTP using public key exchange authentication. Keys are generated automatically when the configuration is added, or can be regenerated on demand if a key is compromised. Creation of a new configuration row now triggers focus on that row. This is used to trigger auto-configuration for SFTP keys. Generated public keys are saved in user's data directory for easy retrieval by an external application. Add controller for SFTP key generation AJAX SFTP class initialisation no longer produces a warning if the password field is missing. Add unit tests for SFTP with key authentication backend
Diffstat (limited to 'apps/files_external/js')
-rw-r--r--apps/files_external/js/sftp_key.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/files_external/js/sftp_key.js b/apps/files_external/js/sftp_key.js
new file mode 100644
index 00000000000..2b39628247c
--- /dev/null
+++ b/apps/files_external/js/sftp_key.js
@@ -0,0 +1,53 @@
+$(document).ready(function() {
+
+ $('#externalStorage tbody tr.\\\\OC\\\\Files\\\\Storage\\\\SFTP_Key').each(function() {
+ var tr = $(this);
+ var config = $(tr).find('.configuration');
+ if ($(config).find('.sftp_key').length === 0) {
+ setupTableRow(tr, config);
+ }
+ });
+
+ // We can't catch the DOM elements being added, but we can pick up when
+ // they receive focus
+ $('#externalStorage').on('focus', 'tbody tr.\\\\OC\\\\Files\\\\Storage\\\\SFTP_Key', function() {
+ var tr = $(this);
+ var config = $(tr).find('.configuration');
+
+ if ($(config).find('.sftp_key').length === 0) {
+ setupTableRow(tr, config);
+ }
+ });
+
+ $('#externalStorage').on('click', '.sftp_key', function(event) {
+ event.preventDefault();
+ var tr = $(this).parent().parent();
+ generateKeys(tr);
+ });
+
+ function setupTableRow(tr, config) {
+ $(config).append($(document.createElement('input')).addClass('button sftp_key')
+ .attr('type', 'button')
+ .attr('value', t('files_external', 'Generate keys')));
+ // If there's no private key, build one
+ if (0 === $(config).find('[data-parameter="private_key"]').val().length) {
+ generateKeys(tr);
+ }
+ }
+
+ function generateKeys(tr) {
+ var config = $(tr).find('.configuration');
+
+ $.post(OC.filePath('files_external', 'ajax', 'sftp_key.php'), {}, function(result) {
+ if (result && result.status === 'success') {
+ $(config).find('[data-parameter="public_key"]').val(result.data.public_key);
+ $(config).find('[data-parameter="private_key"]').val(result.data.private_key);
+ OC.MountConfig.saveStorage(tr, function() {
+ // Nothing to do
+ });
+ } else {
+ OC.dialogs.alert(result.data.message, t('files_external', 'Error generating key pair') );
+ }
+ });
+ }
+});