From 857b97a7dc22a962506e8ec9c0308602efbc1c1e Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 22 Feb 2018 14:17:37 +0100 Subject: [PATCH] ui: move loadSSHKeyFromFile from lxc/Create to Utils Signed-off-by: Thomas Lamprecht --- www/manager6/Utils.js | 19 +++++++++++++++++++ www/manager6/lxc/CreateWizard.js | 25 ++++++------------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js index 8f80c76a..87699e56 100644 --- a/www/manager6/Utils.js +++ b/www/manager6/Utils.js @@ -875,6 +875,25 @@ Ext.define('PVE.Utils', { utilities: { delete values[fieldname]; } + }, + + loadSSHKeyFromFile: function(file, callback) { + // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with + // a user@host comment, 1420 for 8192 bits; current max is 16kbit + // assume: 740*8 for max. 32kbit (5920 byte file) + // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space + if (file.size > 8192) { + Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size); + return; + } + /*global + FileReader + */ + var reader = new FileReader(); + reader.onload = function(evt) { + callback(evt.target.result); + }; + reader.readAsText(file); } }, diff --git a/www/manager6/lxc/CreateWizard.js b/www/manager6/lxc/CreateWizard.js index 5b069317..65b1348d 100644 --- a/www/manager6/lxc/CreateWizard.js +++ b/www/manager6/lxc/CreateWizard.js @@ -5,23 +5,6 @@ Ext.define('PVE.lxc.CreateWizard', { extend: 'PVE.window.Wizard', - loadSSHKeyFromFile: function(file) { - var me = this; - // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with - // a user@host comment, 1420 for 8192 bits; current max is 16kbit - // assume: 740*8 for max. 32kbit (5920 byte file) - // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space - if (file.size > 8192) { - Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size); - return; - } - var reader = new FileReader(); - reader.onload = function(evt) { - me.sshkeyfield.setValue(evt.target.result); - }; - reader.readAsText(file); - }, - initComponent: function() { var me = this; @@ -125,7 +108,9 @@ Ext.define('PVE.lxc.CreateWizard', { ev.preventDefault(); } var files = ev.dataTransfer.files; - me.loadSSHKeyFromFile(files[0]); + PVE.Utils.loadSSHKeyFromFile(files[0], function (v) { + me.sshkeyfield.setValue(v); + }); }); } }); @@ -166,7 +151,9 @@ Ext.define('PVE.lxc.CreateWizard', { listeners: { change: function(btn, e, value) { e = e.event; - me.loadSSHKeyFromFile(e.target.files[0]); + PVE.Utils.loadSSHKeyFromFile(e.target.files[0], function (v) { + me.sshkeyfield.setValue(v); + }); btn.reset(); } } -- 2.39.2