[pve-devel] [PATCH manager v2 4/5] ui: node/ACME: add ACMEDomainEdit

Dominik Csapak d.csapak at proxmox.com
Wed May 6 16:31:11 CEST 2020


which expects a nodeconfig (for digest and domaincount)
and for the edit case, the parsed 'domain' object

this editwindow has three fields:
* type selector (standalone/dns)
* domain
* plugin (only for dns)

if the user chooses dns but there are already the maximum count of
acmedomainX entries, the type field gets invalid (with a error tooltip)

the onGetValues method is non-trivial, because of the mixing of
acmedomainX and acme.domain values, so we have to be careful
that we delete/edit the correct entry

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/node/ACME.js | 136 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 136 insertions(+)

diff --git a/www/manager6/node/ACME.js b/www/manager6/node/ACME.js
index 40ecc00e..a8bb39d6 100644
--- a/www/manager6/node/ACME.js
+++ b/www/manager6/node/ACME.js
@@ -230,6 +230,142 @@ Ext.define('PVE.node.ACMEAccountView', {
     }
 });
 
+Ext.define('PVE.node.ACMEDomainEdit', {
+    extend: 'Proxmox.window.Edit',
+    alias: 'widget.pveACMEDomainEdit',
+
+    subject: gettext('Domain'),
+    isCreate: false,
+
+    items: [
+	{
+	    xtype: 'inputpanel',
+	    onGetValues: function(values) {
+		let me = this;
+		let win = me.up('pveACMEDomainEdit');
+		let nodeconfig = win.nodeconfig;
+		let olddomain = win.domain || {};
+
+		let params = {
+		    digest: nodeconfig.digest,
+		};
+
+		let configkey = olddomain.configkey;
+		let acmeObj = PVE.Parser.parseACME(nodeconfig.acme) || {};
+
+		if (values.type === 'dns') {
+		    if (!olddomain.configkey || olddomain.configkey === 'acme') {
+			// look for first free slot
+			for (let i = 0; i < PVE.Utils.acmedomain_count; i++) {
+			    if (nodeconfig[`acmedomain${i}`] === undefined) {
+				configkey = `acmedomain${i}`;
+				break;
+			    }
+			}
+			if (olddomain.domain) {
+			    // we have to remove the domain from the acme domainlist
+			    PVE.Utils.remove_domain_from_acme(acmeObj, olddomain.domain);
+			    params.acme = PVE.Parser.printACME(acmeObj);
+			}
+		    }
+
+		    delete values.type;
+		    params[configkey] = PVE.Parser.printPropertyString(values, 'domain');
+		} else {
+		    if (olddomain.configkey && olddomain.configkey !== 'acme') {
+			// delete the old dns entry
+			params.delete = [olddomain.configkey];
+		    }
+
+		    // add new, remove old and make entries unique
+		    PVE.Utils.add_domain_to_acme(acmeObj, values.domain);
+		    PVE.Utils.remove_domain_from_acme(acmeObj, olddomain.domain);
+		    params.acme = PVE.Parser.printACME(acmeObj);
+		}
+
+		return params;
+	    },
+	    items: [
+		{
+		    xtype: 'proxmoxKVComboBox',
+		    name: 'type',
+		    fieldLabel: gettext('Type'),
+		    allowBlank: false,
+		    comboItems: [
+			['standalone', 'standalone'],
+			['dns', 'DNS'],
+		    ],
+		    validator: function(value) {
+			let me = this;
+			let win = me.up('pveACMEDomainEdit');
+			let oldconfigkey = win.domain ? win.domain.configkey : undefined;
+			let val = me.getValue();
+			if (val === 'dns' && (!oldconfigkey || oldconfigkey === 'acme')) {
+			    // we have to check if there is a 'acmedomain' slot left
+			    let found = false;
+			    for (let i = 0; i < PVE.Utils.acmedomain_count; i++) {
+				if (!win.nodeconfig[`acmedomain${i}`]) {
+				    found = true;
+				}
+			    }
+			    if (!found) {
+				return gettext('Only 5 Domains with type DNS can be configured');
+			    }
+			}
+
+			return true;
+		    },
+		    listeners: {
+			change: function(cb, value) {
+			    let me = this;
+			    let view = me.up('pveACMEDomainEdit');
+			    view.down('field[name=plugin]').setDisabled(value !== 'dns');
+			},
+		    },
+		},
+		{
+		    xtype: 'hidden',
+		    name: 'alias',
+		},
+		{
+		    xtype: 'proxmoxtextfield',
+		    name: 'domain',
+		    allowBlank: false,
+		    fieldLabel: gettext('Domain'),
+		},
+		{
+		    xtype: 'pveACMEPluginSelector',
+		    name: 'plugin',
+		    disabled: true,
+		    allowBlank: false,
+		},
+	    ],
+	},
+    ],
+
+    initComponent: function() {
+	let me = this;
+
+	if (!me.nodename) {
+	    throw 'no nodename given';
+	}
+
+	if (!me.nodeconfig) {
+	    throw 'no nodeconfig given';
+	}
+
+	me.isCreate = !me.domain;
+
+	me.url = `/api2/extjs/nodes/${me.nodename}/config`;
+
+	me.callParent();
+
+	if (!me.isCreate) {
+	    me.setValues(me.domain);
+	}
+    },
+});
+
 Ext.define('PVE.node.ACME', {
     extend: 'Proxmox.grid.ObjectGrid',
     xtype: 'pveACMEView',
-- 
2.20.1





More information about the pve-devel mailing list