]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/window/ACMEDomains.js
1 Ext
.define('Proxmox.window.ACMEDomainEdit', {
2 extend
: 'Proxmox.window.Edit',
3 xtype
: 'pmxACMEDomainEdit',
4 mixins
: ['Proxmox.Mixin.CBind'],
6 subject
: gettext('Domain'),
9 //onlineHelp: 'sysadmin_certificate_management',
16 // For PMG the we have multiple certificates, so we have a "usage" attribute & column.
17 domainUsages
: undefined,
19 cbindData: function(config
) {
22 pluginsUrl
: `/api2/json/${me.acmeUrl}/plugins`,
23 hasUsage
: !!me
.domainUsages
,
30 onGetValues: function(values
) {
32 let win
= me
.up('pmxACMEDomainEdit');
33 let nodeconfig
= win
.nodeconfig
;
34 let olddomain
= win
.domain
|| {};
37 digest
: nodeconfig
.digest
,
40 let configkey
= olddomain
.configkey
;
41 let acmeObj
= Proxmox
.Utils
.parseACME(nodeconfig
.acme
);
43 let find_free_slot
= () => {
44 for (let i
= 0; i
< Proxmox
.Utils
.acmedomain_count
; i
++) {
45 if (nodeconfig
[`acmedomain${i}`] === undefined) {
46 return `acmedomain${i}`;
49 throw "too many domains configured";
52 // If we have a 'usage' property (pmg), we only use the `acmedomainX` config keys.
53 if (win
.domainUsages
) {
54 if (!configkey
|| configkey
=== 'acme') {
55 configkey
= find_free_slot();
58 params
[configkey
] = Proxmox
.Utils
.printPropertyString(values
, 'domain');
62 // Otherwise we put the standalone entries into the `domains` list of the `acme`
65 // Then insert the domain depending on its type:
66 if (values
.type
=== 'dns') {
67 if (!olddomain
.configkey
|| olddomain
.configkey
=== 'acme') {
68 configkey
= find_free_slot();
69 if (olddomain
.domain
) {
70 // we have to remove the domain from the acme domainlist
71 Proxmox
.Utils
.remove_domain_from_acme(acmeObj
, olddomain
.domain
);
72 params
.acme
= Proxmox
.Utils
.printACME(acmeObj
);
77 params
[configkey
] = Proxmox
.Utils
.printPropertyString(values
, 'domain');
79 if (olddomain
.configkey
&& olddomain
.configkey
!== 'acme') {
80 // delete the old dns entry, unless we need to declare its usage:
81 params
.delete = [olddomain
.configkey
];
84 // add new, remove old and make entries unique
85 Proxmox
.Utils
.add_domain_to_acme(acmeObj
, values
.domain
);
86 if (olddomain
.domain
!== values
.domain
) {
87 Proxmox
.Utils
.remove_domain_from_acme(acmeObj
, olddomain
.domain
);
89 params
.acme
= Proxmox
.Utils
.printACME(acmeObj
);
96 xtype
: 'proxmoxKVComboBox',
98 fieldLabel
: gettext('Challenge Type'),
102 ['standalone', 'HTTP'],
105 validator: function(value
) {
107 let win
= me
.up('pmxACMEDomainEdit');
108 let oldconfigkey
= win
.domain
? win
.domain
.configkey
: undefined;
109 let val
= me
.getValue();
110 if (val
=== 'dns' && (!oldconfigkey
|| oldconfigkey
=== 'acme')) {
111 // we have to check if there is a 'acmedomain' slot left
113 for (let i
= 0; i
< Proxmox
.Utils
.acmedomain_count
; i
++) {
114 if (!win
.nodeconfig
[`acmedomain${i}`]) {
119 return gettext('Only 5 Domains with type DNS can be configured');
126 change: function(cb
, value
) {
128 let view
= me
.up('pmxACMEDomainEdit');
129 let pluginField
= view
.down('field[name=plugin]');
130 pluginField
.setDisabled(value
!== 'dns');
131 pluginField
.setHidden(value
!== 'dns');
140 xtype
: 'pmxACMEPluginSelector',
150 xtype
: 'proxmoxtextfield',
155 fieldLabel
: gettext('Domain'),
162 fieldLabel
: gettext('Usage'),
164 hidden
: '{!hasUsage}',
165 allowBlank
: '{!hasUsage}',
167 fields
: ['usage', 'name'],
168 displayField
: 'name',
172 { usage
: 'api', name
: 'API' },
173 { usage
: 'smtp', name
: 'SMTP' },
181 initComponent: function() {
185 throw 'no url given';
189 throw 'no acmeUrl given';
192 if (!me
.nodeconfig
) {
193 throw 'no nodeconfig given';
196 me
.isCreate
= !me
.domain
;
198 me
.domain
= `${Proxmox.NodeName}.`; // TODO: FQDN of node
204 let values
= { ...me
.domain
};
205 if (Ext
.isDefined(values
.usage
)) {
206 values
.usage
= values
.usage
.split(';');
208 me
.setValues(values
);
210 me
.setValues({ domain
: me
.domain
});