]>
Commit | Line | Data |
---|---|---|
8915422f WB |
1 | Ext.define('Proxmox.window.ACMEDomainEdit', { |
2 | extend: 'Proxmox.window.Edit', | |
3 | xtype: 'pmxACMEDomainEdit', | |
4 | mixins: ['Proxmox.Mixin.CBind'], | |
5 | ||
6 | subject: gettext('Domain'), | |
7 | isCreate: false, | |
8 | width: 450, | |
9 | //onlineHelp: 'sysadmin_certificate_management', | |
10 | ||
11 | acmeUrl: undefined, | |
12 | ||
13 | // config url | |
14 | url: undefined, | |
15 | ||
16 | // For PMG the we have multiple certificates, so we have a "usage" attribute & column. | |
17 | domainUsages: undefined, | |
18 | ||
ef7a8290 WB |
19 | // Force the use of 'acmedomainX' properties. |
20 | separateDomainEntries: undefined, | |
21 | ||
8915422f WB |
22 | cbindData: function(config) { |
23 | let me = this; | |
24 | return { | |
25 | pluginsUrl: `/api2/json/${me.acmeUrl}/plugins`, | |
26 | hasUsage: !!me.domainUsages, | |
27 | }; | |
28 | }, | |
29 | ||
30 | items: [ | |
31 | { | |
32 | xtype: 'inputpanel', | |
33 | onGetValues: function(values) { | |
34 | let me = this; | |
35 | let win = me.up('pmxACMEDomainEdit'); | |
36 | let nodeconfig = win.nodeconfig; | |
37 | let olddomain = win.domain || {}; | |
38 | ||
39 | let params = { | |
40 | digest: nodeconfig.digest, | |
41 | }; | |
42 | ||
43 | let configkey = olddomain.configkey; | |
44 | let acmeObj = Proxmox.Utils.parseACME(nodeconfig.acme); | |
45 | ||
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}`; | |
50 | } | |
51 | } | |
52 | throw "too many domains configured"; | |
53 | }; | |
54 | ||
55 | // If we have a 'usage' property (pmg), we only use the `acmedomainX` config keys. | |
ef7a8290 | 56 | if (win.separateDomainEntries || win.domainUsages) { |
8915422f WB |
57 | if (!configkey || configkey === 'acme') { |
58 | configkey = find_free_slot(); | |
59 | } | |
60 | delete values.type; | |
61 | params[configkey] = Proxmox.Utils.printPropertyString(values, 'domain'); | |
62 | return params; | |
63 | } | |
64 | ||
65 | // Otherwise we put the standalone entries into the `domains` list of the `acme` | |
66 | // property string. | |
67 | ||
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); | |
76 | } | |
77 | } | |
78 | ||
79 | delete values.type; | |
80 | params[configkey] = Proxmox.Utils.printPropertyString(values, 'domain'); | |
81 | } else { | |
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]; | |
85 | } | |
86 | ||
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); | |
91 | } | |
92 | params.acme = Proxmox.Utils.printACME(acmeObj); | |
93 | } | |
94 | ||
95 | return params; | |
96 | }, | |
97 | items: [ | |
98 | { | |
99 | xtype: 'proxmoxKVComboBox', | |
100 | name: 'type', | |
101 | fieldLabel: gettext('Challenge Type'), | |
102 | allowBlank: false, | |
103 | value: 'standalone', | |
104 | comboItems: [ | |
105 | ['standalone', 'HTTP'], | |
106 | ['dns', 'DNS'], | |
107 | ], | |
108 | validator: function(value) { | |
109 | let me = this; | |
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 | |
115 | let found = false; | |
116 | for (let i = 0; i < Proxmox.Utils.acmedomain_count; i++) { | |
117 | if (!win.nodeconfig[`acmedomain${i}`]) { | |
118 | found = true; | |
119 | } | |
120 | } | |
121 | if (!found) { | |
122 | return gettext('Only 5 Domains with type DNS can be configured'); | |
123 | } | |
124 | } | |
125 | ||
126 | return true; | |
127 | }, | |
128 | listeners: { | |
129 | change: function(cb, value) { | |
130 | let me = this; | |
131 | let view = me.up('pmxACMEDomainEdit'); | |
132 | let pluginField = view.down('field[name=plugin]'); | |
133 | pluginField.setDisabled(value !== 'dns'); | |
134 | pluginField.setHidden(value !== 'dns'); | |
135 | }, | |
136 | }, | |
137 | }, | |
138 | { | |
139 | xtype: 'hidden', | |
140 | name: 'alias', | |
141 | }, | |
142 | { | |
143 | xtype: 'pmxACMEPluginSelector', | |
144 | name: 'plugin', | |
145 | disabled: true, | |
146 | hidden: true, | |
147 | allowBlank: false, | |
148 | cbind: { | |
149 | url: '{pluginsUrl}', | |
150 | }, | |
151 | }, | |
152 | { | |
153 | xtype: 'proxmoxtextfield', | |
154 | name: 'domain', | |
155 | allowBlank: false, | |
66c5ceb8 | 156 | vtype: 'DnsNameOrWildcard', |
8915422f WB |
157 | value: '', |
158 | fieldLabel: gettext('Domain'), | |
159 | }, | |
160 | { | |
161 | xtype: 'combobox', | |
162 | name: 'usage', | |
163 | multiSelect: true, | |
164 | editable: false, | |
165 | fieldLabel: gettext('Usage'), | |
166 | cbind: { | |
167 | hidden: '{!hasUsage}', | |
168 | allowBlank: '{!hasUsage}', | |
169 | }, | |
170 | fields: ['usage', 'name'], | |
171 | displayField: 'name', | |
172 | valueField: 'usage', | |
173 | store: { | |
174 | data: [ | |
175 | { usage: 'api', name: 'API' }, | |
176 | { usage: 'smtp', name: 'SMTP' }, | |
177 | ], | |
178 | }, | |
179 | }, | |
180 | ], | |
181 | }, | |
182 | ], | |
183 | ||
184 | initComponent: function() { | |
185 | let me = this; | |
186 | ||
187 | if (!me.url) { | |
188 | throw 'no url given'; | |
189 | } | |
190 | ||
191 | if (!me.acmeUrl) { | |
192 | throw 'no acmeUrl given'; | |
193 | } | |
194 | ||
195 | if (!me.nodeconfig) { | |
196 | throw 'no nodeconfig given'; | |
197 | } | |
198 | ||
199 | me.isCreate = !me.domain; | |
200 | if (me.isCreate) { | |
201 | me.domain = `${Proxmox.NodeName}.`; // TODO: FQDN of node | |
202 | } | |
203 | ||
204 | me.callParent(); | |
205 | ||
206 | if (!me.isCreate) { | |
207 | let values = { ...me.domain }; | |
208 | if (Ext.isDefined(values.usage)) { | |
209 | values.usage = values.usage.split(';'); | |
210 | } | |
211 | me.setValues(values); | |
212 | } else { | |
213 | me.setValues({ domain: me.domain }); | |
214 | } | |
215 | }, | |
216 | }); |