]>
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 // Force the use of 'acmedomainX' properties.
20 separateDomainEntries
: undefined,
22 cbindData: function(config
) {
25 pluginsUrl
: `/api2/json/${me.acmeUrl}/plugins`,
26 hasUsage
: !!me
.domainUsages
,
33 onGetValues: function(values
) {
35 let win
= me
.up('pmxACMEDomainEdit');
36 let nodeconfig
= win
.nodeconfig
;
37 let olddomain
= win
.domain
|| {};
40 digest
: nodeconfig
.digest
,
43 let configkey
= olddomain
.configkey
;
44 let acmeObj
= Proxmox
.Utils
.parseACME(nodeconfig
.acme
);
46 let find_free_slot
= () => {
47 for (let i
= 0; i
< Proxmox
.Utils
.acmedomain_count
; i
++) {
48 if (nodeconfig
[`acmedomain${i}`] === undefined) {
49 return `acmedomain${i}`;
52 throw "too many domains configured";
55 // If we have a 'usage' property (pmg), we only use the `acmedomainX` config keys.
56 if (win
.separateDomainEntries
|| win
.domainUsages
) {
57 if (!configkey
|| configkey
=== 'acme') {
58 configkey
= find_free_slot();
61 params
[configkey
] = Proxmox
.Utils
.printPropertyString(values
, 'domain');
65 // Otherwise we put the standalone entries into the `domains` list of the `acme`
68 // Then insert the domain depending on its type:
69 if (values
.type
=== 'dns') {
70 if (!olddomain
.configkey
|| olddomain
.configkey
=== 'acme') {
71 configkey
= find_free_slot();
72 if (olddomain
.domain
) {
73 // we have to remove the domain from the acme domainlist
74 Proxmox
.Utils
.remove_domain_from_acme(acmeObj
, olddomain
.domain
);
75 params
.acme
= Proxmox
.Utils
.printACME(acmeObj
);
80 params
[configkey
] = Proxmox
.Utils
.printPropertyString(values
, 'domain');
82 if (olddomain
.configkey
&& olddomain
.configkey
!== 'acme') {
83 // delete the old dns entry, unless we need to declare its usage:
84 params
.delete = [olddomain
.configkey
];
87 // add new, remove old and make entries unique
88 Proxmox
.Utils
.add_domain_to_acme(acmeObj
, values
.domain
);
89 if (olddomain
.domain
!== values
.domain
) {
90 Proxmox
.Utils
.remove_domain_from_acme(acmeObj
, olddomain
.domain
);
92 params
.acme
= Proxmox
.Utils
.printACME(acmeObj
);
99 xtype
: 'proxmoxKVComboBox',
101 fieldLabel
: gettext('Challenge Type'),
105 ['standalone', 'HTTP'],
108 validator: function(value
) {
110 let win
= me
.up('pmxACMEDomainEdit');
111 let oldconfigkey
= win
.domain
? win
.domain
.configkey
: undefined;
112 let val
= me
.getValue();
113 if (val
=== 'dns' && (!oldconfigkey
|| oldconfigkey
=== 'acme')) {
114 // we have to check if there is a 'acmedomain' slot left
116 for (let i
= 0; i
< Proxmox
.Utils
.acmedomain_count
; i
++) {
117 if (!win
.nodeconfig
[`acmedomain${i}`]) {
122 return gettext('Only 5 Domains with type DNS can be configured');
129 change: function(cb
, value
) {
131 let view
= me
.up('pmxACMEDomainEdit');
132 let pluginField
= view
.down('field[name=plugin]');
133 pluginField
.setDisabled(value
!== 'dns');
134 pluginField
.setHidden(value
!== 'dns');
143 xtype
: 'pmxACMEPluginSelector',
153 xtype
: 'proxmoxtextfield',
156 vtype
: 'DnsNameOrWildcard',
158 fieldLabel
: gettext('Domain'),
165 fieldLabel
: gettext('Usage'),
167 hidden
: '{!hasUsage}',
168 allowBlank
: '{!hasUsage}',
170 fields
: ['usage', 'name'],
171 displayField
: 'name',
175 { usage
: 'api', name
: 'API' },
176 { usage
: 'smtp', name
: 'SMTP' },
184 initComponent: function() {
188 throw 'no url given';
192 throw 'no acmeUrl given';
195 if (!me
.nodeconfig
) {
196 throw 'no nodeconfig given';
199 me
.isCreate
= !me
.domain
;
201 me
.domain
= `${Proxmox.NodeName}.`; // TODO: FQDN of node
207 let values
= { ...me
.domain
};
208 if (Ext
.isDefined(values
.usage
)) {
209 values
.usage
= values
.usage
.split(';');
211 me
.setValues(values
);
213 me
.setValues({ domain
: me
.domain
});