]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - src/window/ACMEDomains.js
window: add FileBrowser
[proxmox-widget-toolkit.git] / src / window / ACMEDomains.js
CommitLineData
8915422f
WB
1Ext.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
19 cbindData: function(config) {
20 let me = this;
21 return {
22 pluginsUrl: `/api2/json/${me.acmeUrl}/plugins`,
23 hasUsage: !!me.domainUsages,
24 };
25 },
26
27 items: [
28 {
29 xtype: 'inputpanel',
30 onGetValues: function(values) {
31 let me = this;
32 let win = me.up('pmxACMEDomainEdit');
33 let nodeconfig = win.nodeconfig;
34 let olddomain = win.domain || {};
35
36 let params = {
37 digest: nodeconfig.digest,
38 };
39
40 let configkey = olddomain.configkey;
41 let acmeObj = Proxmox.Utils.parseACME(nodeconfig.acme);
42
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}`;
47 }
48 }
49 throw "too many domains configured";
50 };
51
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();
56 }
57 delete values.type;
58 params[configkey] = Proxmox.Utils.printPropertyString(values, 'domain');
59 return params;
60 }
61
62 // Otherwise we put the standalone entries into the `domains` list of the `acme`
63 // property string.
64
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);
73 }
74 }
75
76 delete values.type;
77 params[configkey] = Proxmox.Utils.printPropertyString(values, 'domain');
78 } else {
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];
82 }
83
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);
88 }
89 params.acme = Proxmox.Utils.printACME(acmeObj);
90 }
91
92 return params;
93 },
94 items: [
95 {
96 xtype: 'proxmoxKVComboBox',
97 name: 'type',
98 fieldLabel: gettext('Challenge Type'),
99 allowBlank: false,
100 value: 'standalone',
101 comboItems: [
102 ['standalone', 'HTTP'],
103 ['dns', 'DNS'],
104 ],
105 validator: function(value) {
106 let me = this;
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
112 let found = false;
113 for (let i = 0; i < Proxmox.Utils.acmedomain_count; i++) {
114 if (!win.nodeconfig[`acmedomain${i}`]) {
115 found = true;
116 }
117 }
118 if (!found) {
119 return gettext('Only 5 Domains with type DNS can be configured');
120 }
121 }
122
123 return true;
124 },
125 listeners: {
126 change: function(cb, value) {
127 let me = this;
128 let view = me.up('pmxACMEDomainEdit');
129 let pluginField = view.down('field[name=plugin]');
130 pluginField.setDisabled(value !== 'dns');
131 pluginField.setHidden(value !== 'dns');
132 },
133 },
134 },
135 {
136 xtype: 'hidden',
137 name: 'alias',
138 },
139 {
140 xtype: 'pmxACMEPluginSelector',
141 name: 'plugin',
142 disabled: true,
143 hidden: true,
144 allowBlank: false,
145 cbind: {
146 url: '{pluginsUrl}',
147 },
148 },
149 {
150 xtype: 'proxmoxtextfield',
151 name: 'domain',
152 allowBlank: false,
153 vtype: 'DnsName',
154 value: '',
155 fieldLabel: gettext('Domain'),
156 },
157 {
158 xtype: 'combobox',
159 name: 'usage',
160 multiSelect: true,
161 editable: false,
162 fieldLabel: gettext('Usage'),
163 cbind: {
164 hidden: '{!hasUsage}',
165 allowBlank: '{!hasUsage}',
166 },
167 fields: ['usage', 'name'],
168 displayField: 'name',
169 valueField: 'usage',
170 store: {
171 data: [
172 { usage: 'api', name: 'API' },
173 { usage: 'smtp', name: 'SMTP' },
174 ],
175 },
176 },
177 ],
178 },
179 ],
180
181 initComponent: function() {
182 let me = this;
183
184 if (!me.url) {
185 throw 'no url given';
186 }
187
188 if (!me.acmeUrl) {
189 throw 'no acmeUrl given';
190 }
191
192 if (!me.nodeconfig) {
193 throw 'no nodeconfig given';
194 }
195
196 me.isCreate = !me.domain;
197 if (me.isCreate) {
198 me.domain = `${Proxmox.NodeName}.`; // TODO: FQDN of node
199 }
200
201 me.callParent();
202
203 if (!me.isCreate) {
204 let values = { ...me.domain };
205 if (Ext.isDefined(values.usage)) {
206 values.usage = values.usage.split(';');
207 }
208 me.setValues(values);
209 } else {
210 me.setValues({ domain: me.domain });
211 }
212 },
213});