summaryrefslogtreecommitdiffstats
path: root/apps/files_external/js
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-08-12 22:20:08 +0100
committerRobin McCorkell <rmccorkell@owncloud.com>2015-08-28 12:58:47 +0100
commit1084e3adc7636787a139b68335112715b187b3bb (patch)
tree5f3d22280f28ad0328f8ed811bbab3c3c1152831 /apps/files_external/js
parentcb1ef827028126dd55c21fc3f3720723e5cc25a6 (diff)
downloadnextcloud-server-1084e3adc7636787a139b68335112715b187b3bb.tar.gz
nextcloud-server-1084e3adc7636787a139b68335112715b187b3bb.zip
Migrate SFTP_Key external storage to new API
The SFTP backend now supports public key authentication alongside password authentication.
Diffstat (limited to 'apps/files_external/js')
-rw-r--r--apps/files_external/js/public_key.js46
-rw-r--r--apps/files_external/js/sftp_key.js53
2 files changed, 46 insertions, 53 deletions
diff --git a/apps/files_external/js/public_key.js b/apps/files_external/js/public_key.js
new file mode 100644
index 00000000000..a8546067452
--- /dev/null
+++ b/apps/files_external/js/public_key.js
@@ -0,0 +1,46 @@
+$(document).ready(function() {
+
+ OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme) {
+ if (scheme === 'publickey') {
+ var config = $tr.find('.configuration');
+ if ($(config).find('[name="public_key_generate"]').length === 0) {
+ setupTableRow($tr, config);
+ }
+ }
+ });
+
+ $('#externalStorage').on('click', '[name="public_key_generate"]', function(event) {
+ event.preventDefault();
+ var tr = $(this).parent().parent();
+ generateKeys(tr);
+ });
+
+ function setupTableRow(tr, config) {
+ $(config).append($(document.createElement('input'))
+ .addClass('button auth-param')
+ .attr('type', 'button')
+ .attr('value', t('files_external', 'Generate keys'))
+ .attr('name', 'public_key_generate')
+ );
+ // 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', 'public_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);
+ OCA.External.Settings.mountConfig.saveStorageConfig(tr, function() {
+ // Nothing to do
+ });
+ } else {
+ OC.dialogs.alert(result.data.message, t('files_external', 'Error generating key pair') );
+ }
+ });
+ }
+});
diff --git a/apps/files_external/js/sftp_key.js b/apps/files_external/js/sftp_key.js
deleted file mode 100644
index 55b11b1fac9..00000000000
--- a/apps/files_external/js/sftp_key.js
+++ /dev/null
@@ -1,53 +0,0 @@
-$(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);
- OCA.External.mountConfig.saveStorageConfig(tr, function() {
- // Nothing to do
- });
- } else {
- OC.dialogs.alert(result.data.message, t('files_external', 'Error generating key pair') );
- }
- });
- }
-});