From 8a1e3f6c6bafb63ce66e82d7a40f2dcf7bb33f30 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 15 Mar 2018 16:21:34 +0100 Subject: [PATCH] add qemu SSHKey Edit for CloudInit displays all ssh keys in a big textarea, and lets you load one from a file Signed-off-by: Dominik Csapak --- www/manager6/Makefile | 1 + www/manager6/qemu/SSHKey.js | 92 +++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 www/manager6/qemu/SSHKey.js diff --git a/www/manager6/Makefile b/www/manager6/Makefile index f2cfbdd29..e6d07ae07 100644 --- a/www/manager6/Makefile +++ b/www/manager6/Makefile @@ -129,6 +129,7 @@ JSSRC= \ qemu/CreateWizard.js \ qemu/USBEdit.js \ qemu/AgentIPView.js \ + qemu/SSHKey.js \ qemu/IPConfigEdit.js \ lxc/Summary.js \ lxc/Network.js \ diff --git a/www/manager6/qemu/SSHKey.js b/www/manager6/qemu/SSHKey.js new file mode 100644 index 000000000..c79653bb8 --- /dev/null +++ b/www/manager6/qemu/SSHKey.js @@ -0,0 +1,92 @@ +Ext.define('PVE.qemu.SSHKeyInputPanel', { + extend: 'Proxmox.panel.InputPanel', + xtype: 'pveQemuSSHKeyInputPanel', + + insideWizard: false, + + onGetValues: function(values) { + var me = this; + if (values.sshkeys) { + values.sshkeys.trim(); + } + if (!values.sshkeys.length) { + values = {}; + values['delete'] = 'sshkeys'; + return values; + } else { + values.sshkeys = encodeURIComponent(values.sshkeys); + } + return values; + }, + + items: [ + { + xtype: 'textarea', + itemId: 'sshkeys', + name: 'sshkeys', + height: 250 + }, + { + xtype: 'filebutton', + itemId: 'filebutton', + name: 'file', + text: gettext('Load SSH Key File'), + fieldLabel: 'test', + listeners: { + change: function(btn, e, value) { + var me = this.up('inputpanel'); + e = e.event; + Ext.Array.each(e.target.files, function(file) { + PVE.Utils.loadSSHKeyFromFile(file, function(res) { + var keysField = me.down('#sshkeys'); + var old = keysField.getValue(); + keysField.setValue(old + res); + }); + }); + btn.reset(); + } + } + } + ], + + initComponent: function() { + var me = this; + + me.callParent(); + if (!window.FileReader) { + me.down('#filebutton').setVisible(false); + } + + } +}); + +Ext.define('PVE.qemu.SSHKeyEdit', { + extend: 'Proxmox.window.Edit', + + width: 800, + + initComponent : function() { + var me = this; + + var ipanel = Ext.create('PVE.qemu.SSHKeyInputPanel'); + + Ext.apply(me, { + subject: gettext('SSH Keys'), + items: [ ipanel ] + }); + + me.callParent(); + + if (!me.create) { + me.load({ + success: function(response, options) { + var data = response.result.data; + if (data.sshkeys) { + data.sshkeys = decodeURIComponent(data.sshkeys); + ipanel.setValues(data); + } + } + }); + } + } +});