[pve-devel] [PATCH manager 2/2] add node/Certificates.js and use it

Dominik Csapak d.csapak at proxmox.com
Wed Apr 25 11:41:16 CEST 2018


this adds the grid for showing the custom/builtin Certificates
and the means to upload and delete custom ones

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Makefile             |   1 +
 www/manager6/node/Certificates.js | 269 ++++++++++++++++++++++++++++++++++++++
 www/manager6/node/Config.js       |   8 ++
 3 files changed, 278 insertions(+)
 create mode 100644 www/manager6/node/Certificates.js

diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index c29824bf..81ddcc8d 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -97,6 +97,7 @@ JSSRC= 				                 	\
 	node/StatusView.js				\
 	node/Summary.js					\
 	node/Subscription.js				\
+	node/Certificates.js				\
 	node/ACME.js					\
 	node/Config.js					\
 	window/Migrate.js				\
diff --git a/www/manager6/node/Certificates.js b/www/manager6/node/Certificates.js
new file mode 100644
index 00000000..4b880ecb
--- /dev/null
+++ b/www/manager6/node/Certificates.js
@@ -0,0 +1,269 @@
+Ext.define('PVE.node.CertificateView', {
+    extend: 'Ext.container.Container',
+    xtype: 'pveCertificatesView',
+
+    mixins: ['Proxmox.Mixin.CBind' ],
+
+    items: [
+	{
+	    xtype: 'pveCertView',
+	    border: 0,
+	    cbind: {
+		nodename: '{nodename}'
+	    }
+	},
+	{
+	    xtype: 'pveACMEView',
+	    border: 0,
+	    cbind: {
+		nodename: '{nodename}'
+	    }
+	}
+    ]
+
+});
+
+Ext.define('PVE.node.CertUpload', {
+    extend: 'Proxmox.window.Edit',
+    xtype: 'pveCertUpload',
+
+    title: gettext('Upload Custom Certificate'),
+    resizable: false,
+    isCreate: true,
+    submitText: gettext('Upload'),
+    method: 'POST',
+    width: 600,
+
+    callback: function(success, response, options) {
+	if (!success) {
+	    return;
+	}
+
+	var txt = gettext('pveproxy will be restarted with new certificates, please reload the GUI!');
+	Ext.getBody().mask(txt, ['pve-static-mask']);
+	// reload after 10 seconds automatically
+	Ext.defer(function() {
+	    window.location.reload(true);
+	}, 10000);
+    },
+
+    items: [
+	{
+	    fieldLabel: gettext('Private Key (Optional)'),
+	    labelAlign: 'top',
+	    emptyText: gettext('No change'),
+	    name: 'key',
+	    xtype: 'textarea'
+	},
+	{
+	    xtype: 'filebutton',
+	    text: gettext('From File'),
+	    listeners: {
+		change: function(btn, e, value) {
+		    var me = this.up('form');
+		    e = e.event;
+		    Ext.Array.each(e.target.files, function(file) {
+			PVE.Utils.loadSSHKeyFromFile(file, function(res) {
+			    me.down('field[name=key]').setValue(res);
+			});
+		    });
+		    btn.reset();
+		}
+	    }
+	},
+	{
+	    xtype: 'box',
+	    autoEl: 'hr'
+	},
+	{
+	    fieldLabel: gettext('Certificate Chain'),
+	    labelAlign: 'top',
+	    allowBlank: false,
+	    name: 'certificates',
+	    xtype: 'textarea'
+	},
+	{
+	    xtype: 'filebutton',
+	    text: gettext('From File'),
+	    listeners: {
+		change: function(btn, e, value) {
+		    var me = this.up('form');
+		    e = e.event;
+		    Ext.Array.each(e.target.files, function(file) {
+			PVE.Utils.loadSSHKeyFromFile(file, function(res) {
+			    me.down('field[name=certificates]').setValue(res);
+			});
+		    });
+		    btn.reset();
+		}
+	    }
+	},
+	{
+	    xtype: 'hidden',
+	    name: 'restart',
+	    value: '1'
+	},
+	{
+	    xtype: 'hidden',
+	    name: 'force',
+	    value: '1'
+	}
+    ],
+
+    initComponent: function() {
+	var me = this;
+
+	if (!me.nodename) {
+	    throw "no nodename given";
+	}
+
+	me.url = '/nodes/' + me.nodename + '/certificates/custom';
+
+	me.callParent();
+    }
+});
+
+Ext.define('pve-certificate', {
+    extend: 'Ext.data.Model',
+
+    fields: [ 'filename', 'fingerprint', 'issuer', 'notafter', 'notbefore', 'subject', 'san' ],
+    idProperty: 'filename'
+});
+
+Ext.define('PVE.node.Certificates', {
+    extend: 'Ext.grid.Panel',
+    xtype: 'pveCertView',
+
+    tbar: [
+	{
+	    xtype: 'button',
+	    text: gettext('Upload Custom Certificate'),
+	    handler: function() {
+		var me = this.up('grid');
+		var win = Ext.create('PVE.node.CertUpload', {
+		    nodename: me.nodename
+		});
+		win.show();
+		win.on('destroy', me.reload, me);
+	    }
+	},
+	{
+	    xtype: 'button',
+	    itemId: 'deletebtn',
+	    text: gettext('Delete Custom Certificate'),
+	    handler: function() {
+		var me = this.up('grid');
+		Proxmox.Utils.API2Request({
+		    url: '/nodes/' + me.nodename + '/certificates/custom?restart=1',
+		    method: 'DELETE',
+		    success: function(response, opt) {
+			var txt = gettext('pveproxy will be restarted with new certificates, please reload the GUI!');
+			Ext.getBody().mask(txt, ['pve-static-mask']);
+			// reload after 10 seconds automatically
+			Ext.defer(function() {
+			    window.location.reload(true);
+			}, 10000);
+		    },
+		    failure: function(response, opt) {
+			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+		    }
+		});
+	    }
+	}
+    ],
+
+    columns: [
+	{
+	    header: gettext('File'),
+	    width: 150,
+	    dataIndex: 'filename'
+	},
+	{
+	    header: gettext('Issuer'),
+	    flex: 1,
+	    dataIndex: 'issuer'
+	},
+	{
+	    header: gettext('Subject'),
+	    flex: 1,
+	    dataIndex: 'subject'
+	},
+	{
+	    header: gettext('Valid Since'),
+	    width: 150,
+	    dataIndex: 'notbefore',
+	    renderer: Proxmox.Utils.render_timestamp
+	},
+	{
+	    header: gettext('Expires'),
+	    width: 150,
+	    dataIndex: 'notafter',
+	    renderer: Proxmox.Utils.render_timestamp
+	},
+	{
+	    header: gettext('Subject Alternative Names'),
+	    flex: 1,
+	    dataIndex: 'san',
+	    renderer: function(value) {
+		var names = [];
+		if (Ext.isArray(value)) {
+		    value.forEach(function(val) {
+			if (!Ext.isNumber(val)) {
+			    names.push(val);
+			}
+		    });
+		}
+		return names.join('<br>');
+	    }
+	},
+	{
+	    header: gettext('Fingerprint'),
+	    dataIndex: 'fingerprint',
+	    hidden: true
+	},
+	{
+	    header: gettext('PEM'),
+	    dataIndex: 'pem',
+	    hidden: true
+	}
+    ],
+
+    reload: function() {
+	var me = this;
+	me.rstore.load();
+    },
+
+    set_button_status: function() {
+	var me = this;
+	var rec = me.rstore.getById('pveproxy-ssl.pem');
+
+	me.down('#deletebtn').setDisabled(!rec);
+    },
+
+    initComponent: function() {
+	var me = this;
+
+	if (!me.nodename) {
+	    throw "no nodename given";
+	}
+
+	me.rstore = Ext.create('Proxmox.data.UpdateStore', {
+	    storeid: 'certs-' + me.nodename,
+	    model: 'pve-certificate',
+	    proxy: {
+		type: 'proxmox',
+		    url: '/api2/json/nodes/' + me.nodename + '/certificates/info'
+	    }
+	});
+
+	me.store = {
+	    type: 'diff',
+	    rstore: me.rstore
+	};
+
+	me.callParent();
+
+	me.mon(me.rstore, 'load', me.set_button_status, me);
+	me.rstore.startUpdate();
+    }
+});
diff --git a/www/manager6/node/Config.js b/www/manager6/node/Config.js
index bd7784c9..9e9f49c5 100644
--- a/www/manager6/node/Config.js
+++ b/www/manager6/node/Config.js
@@ -169,6 +169,14 @@ Ext.define('PVE.node.Config', {
 		    xtype: 'proxmoxNodeNetworkView'
 		},
 		{
+		    title: gettext('Certificates'),
+		    iconCls: 'fa fa-certificate',
+		    itemId: 'certificates',
+		    groups: ['services'],
+		    nodename: nodename,
+		    xtype: 'pveCertificatesView'
+		},
+		{
 		    title: gettext('DNS'),
 		    iconCls: 'fa fa-globe',
 		    groups: ['services'],
-- 
2.11.0





More information about the pve-devel mailing list