2015-08-12 21:20:08 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
2015-11-22 17:25:32 +00:00
|
|
|
OCA.External.Settings.mountConfig.whenSelectAuthMechanism(function($tr, authMechanism, scheme, onCompletion) {
|
2018-06-07 11:31:39 +00:00
|
|
|
if (scheme === 'publickey' && authMechanism === 'publickey::rsa') {
|
2015-08-12 21:20:08 +00:00
|
|
|
var config = $tr.find('.configuration');
|
|
|
|
if ($(config).find('[name="public_key_generate"]').length === 0) {
|
|
|
|
setupTableRow($tr, config);
|
2015-11-22 17:25:32 +00:00
|
|
|
onCompletion.then(function() {
|
|
|
|
// If there's no private key, build one
|
|
|
|
if (0 === $(config).find('[data-parameter="private_key"]').val().length) {
|
|
|
|
generateKeys($tr);
|
|
|
|
}
|
|
|
|
});
|
2015-08-12 21:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#externalStorage').on('click', '[name="public_key_generate"]', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var tr = $(this).parent().parent();
|
|
|
|
generateKeys(tr);
|
|
|
|
});
|
|
|
|
|
|
|
|
function setupTableRow(tr, config) {
|
2017-06-05 13:42:25 +00:00
|
|
|
var selectList = document.createElement('select');
|
|
|
|
selectList.id = 'keyLength';
|
|
|
|
|
|
|
|
var options = [1024, 2048, 4096];
|
|
|
|
for (var i = 0; i < options.length; i++) {
|
|
|
|
var option = document.createElement('option');
|
|
|
|
option.value = options[i];
|
|
|
|
option.text = options[i];
|
|
|
|
selectList.appendChild(option);
|
|
|
|
}
|
|
|
|
|
|
|
|
$(config).append(selectList);
|
|
|
|
|
2015-08-12 21:20:08 +00:00
|
|
|
$(config).append($(document.createElement('input'))
|
|
|
|
.addClass('button auth-param')
|
|
|
|
.attr('type', 'button')
|
|
|
|
.attr('value', t('files_external', 'Generate keys'))
|
|
|
|
.attr('name', 'public_key_generate')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateKeys(tr) {
|
|
|
|
var config = $(tr).find('.configuration');
|
2017-06-05 13:42:25 +00:00
|
|
|
var keyLength = config.find('#keyLength').val();
|
2015-08-12 21:20:08 +00:00
|
|
|
|
2017-06-05 13:42:25 +00:00
|
|
|
$.post(OC.filePath('files_external', 'ajax', 'public_key.php'), {
|
|
|
|
keyLength: keyLength
|
|
|
|
}, function(result) {
|
2015-08-12 21:20:08 +00:00
|
|
|
if (result && result.status === 'success') {
|
2015-10-20 12:35:45 +00:00
|
|
|
$(config).find('[data-parameter="public_key"]').val(result.data.public_key).keyup();
|
2015-08-12 21:20:08 +00:00
|
|
|
$(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') );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|