]>
Commit | Line | Data |
---|---|---|
488be4c2 DC |
1 | Ext.define('PVE.node.ACMEEditor', { |
2 | extend: 'Proxmox.window.Edit', | |
3 | xtype: 'pveACMEEditor', | |
4 | ||
5 | subject: gettext('Domains'), | |
6 | items: [ | |
7 | { | |
8 | xtype: 'inputpanel', | |
9 | items: [ | |
10 | { | |
11 | xtype: 'textarea', | |
12 | fieldLabel: gettext('Domains'), | |
13 | emptyText: "domain1.example.com\ndomain2.example.com", | |
14 | name: 'domains' | |
15 | } | |
16 | ], | |
17 | onGetValues: function(values) { | |
18 | if (!values.domains) { | |
19 | return { | |
20 | 'delete': 'acme' | |
21 | }; | |
22 | } | |
23 | var domains = values.domains.split(/\n/).join(';'); | |
24 | return { | |
25 | 'acme': 'domains=' + domains | |
26 | }; | |
27 | } | |
28 | } | |
29 | ], | |
30 | ||
31 | initComponent: function() { | |
32 | var me = this; | |
33 | me.callParent(); | |
34 | ||
35 | me.load({ | |
36 | success: function(response, opts) { | |
37 | var res = PVE.Parser.parseACME(response.result.data.acme); | |
38 | if (res) { | |
39 | res.domains = res.domains.join(' '); | |
40 | me.setValues(res); | |
41 | } | |
42 | } | |
43 | }); | |
44 | } | |
45 | }); | |
46 | ||
47 | Ext.define('PVE.node.ACMEAccountCreate', { | |
48 | extend: 'Proxmox.window.Edit', | |
49 | ||
50 | width: 400, | |
51 | title: gettext('Register Account'), | |
52 | isCreate: true, | |
53 | method: 'POST', | |
54 | submitText: gettext('Register'), | |
55 | url: '/cluster/acme/account', | |
56 | showTaskViewer: true, | |
57 | ||
58 | items: [ | |
59 | { | |
60 | xtype: 'proxmoxComboGrid', | |
61 | name: 'directory', | |
62 | allowBlank: false, | |
63 | valueField: 'url', | |
64 | displayField: 'name', | |
65 | fieldLabel: gettext('ACME Directory'), | |
66 | store: { | |
67 | autoLoad: true, | |
68 | fields: ['name', 'url'], | |
69 | idProperty: ['name'], | |
70 | proxy: { | |
71 | type: 'proxmox', | |
72 | url: '/api2/json/cluster/acme/directories' | |
73 | }, | |
74 | sorters: { | |
75 | property: 'name', | |
76 | order: 'ASC' | |
77 | } | |
78 | }, | |
79 | listConfig: { | |
80 | columns: [ | |
81 | { | |
82 | header: gettext('Name'), | |
83 | dataIndex: 'name', | |
84 | flex: 1 | |
85 | }, | |
86 | { | |
87 | header: gettext('URL'), | |
88 | dataIndex: 'url', | |
89 | flex: 1 | |
90 | } | |
91 | ] | |
92 | }, | |
93 | listeners: { | |
94 | change: function(combogrid, value) { | |
95 | var me = this; | |
96 | if (!value) { | |
97 | return; | |
98 | } | |
99 | ||
100 | var disp = me.up('window').down('#tos_url_display'); | |
101 | var field = me.up('window').down('#tos_url'); | |
102 | var checkbox = me.up('window').down('#tos_checkbox'); | |
103 | ||
104 | disp.setValue(gettext('Loading')); | |
105 | field.setValue(undefined); | |
106 | checkbox.setValue(undefined); | |
107 | ||
108 | Proxmox.Utils.API2Request({ | |
109 | url: '/cluster/acme/tos', | |
110 | method: 'GET', | |
111 | params: { | |
112 | directory: value | |
113 | }, | |
114 | success: function(response, opt) { | |
115 | me.up('window').down('#tos_url').setValue(response.result.data); | |
116 | me.up('window').down('#tos_url_display').setValue(response.result.data); | |
117 | }, | |
118 | failure: function(response, opt) { | |
119 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
120 | } | |
121 | }); | |
122 | } | |
123 | } | |
124 | }, | |
125 | { | |
126 | xtype: 'displayfield', | |
127 | itemId: 'tos_url_display', | |
128 | fieldLabel: gettext('Terms of Service'), | |
129 | renderer: PVE.Utils.render_optional_url, | |
130 | name: 'tos_url_display' | |
131 | }, | |
132 | { | |
133 | xtype: 'hidden', | |
134 | itemId: 'tos_url', | |
135 | name: 'tos_url' | |
136 | }, | |
137 | { | |
138 | xtype: 'proxmoxcheckbox', | |
139 | itemId: 'tos_checkbox', | |
140 | fieldLabel: gettext('Accept TOS'), | |
141 | submitValue: false, | |
142 | validateValue: function(value) { | |
143 | if (value && this.checked) { | |
144 | return true; | |
145 | } | |
146 | return false; | |
147 | } | |
148 | }, | |
149 | { | |
150 | xtype: 'textfield', | |
151 | name: 'contact', | |
152 | vtype: 'email', | |
153 | allowBlank: false, | |
154 | fieldLabel: gettext('E-Mail') | |
155 | } | |
156 | ] | |
157 | ||
158 | }); | |
159 | ||
160 | Ext.define('PVE.node.ACMEAccountView', { | |
161 | extend: 'Proxmox.window.Edit', | |
162 | ||
163 | width: 600, | |
164 | fieldDefaults: { | |
165 | labelWidth: 140 | |
166 | }, | |
167 | ||
168 | title: gettext('Account'), | |
169 | ||
170 | items: [ | |
171 | { | |
172 | xtype: 'displayfield', | |
173 | fieldLabel: gettext('E-Mail'), | |
174 | name: 'email' | |
175 | }, | |
176 | { | |
177 | xtype: 'displayfield', | |
178 | fieldLabel: gettext('Created'), | |
179 | name: 'createdAt' | |
180 | }, | |
181 | { | |
182 | xtype: 'displayfield', | |
183 | fieldLabel: gettext('Status'), | |
184 | name: 'status' | |
185 | }, | |
186 | { | |
187 | xtype: 'displayfield', | |
188 | fieldLabel: gettext('Directory'), | |
189 | renderer: PVE.Utils.render_optional_url, | |
190 | name: 'directory' | |
191 | }, | |
192 | { | |
193 | xtype: 'displayfield', | |
194 | fieldLabel: gettext('Terms of Services'), | |
195 | renderer: PVE.Utils.render_optional_url, | |
196 | name: 'tos' | |
197 | } | |
198 | ], | |
199 | ||
200 | initComponent: function() { | |
201 | var me = this; | |
202 | ||
203 | if (!me.accountname) { | |
204 | throw "no account name defined"; | |
205 | } | |
206 | ||
207 | me.url = '/cluster/acme/account/' + me.accountname; | |
208 | ||
209 | me.callParent(); | |
210 | ||
211 | // hide OK/Reset button, because we just want to show data | |
212 | me.down('toolbar[dock=bottom]').setVisible(false); | |
213 | ||
214 | me.load({ | |
215 | success: function(response) { | |
216 | var data = response.result.data; | |
217 | data.email = data.account.contact[0]; | |
218 | data.createdAt = data.account.createdAt; | |
219 | data.status = data.account.status; | |
220 | me.setValues(data); | |
221 | } | |
222 | }); | |
223 | } | |
224 | }); | |
225 | ||
226 | Ext.define('PVE.node.ACME', { | |
227 | extend: 'Proxmox.grid.ObjectGrid', | |
228 | xtype: 'pveACMEView', | |
229 | ||
230 | margin: '10 0 0 0', | |
231 | title: 'ACME', | |
232 | ||
233 | tbar: [ | |
234 | { | |
235 | xtype: 'button', | |
236 | itemId: 'edit', | |
237 | text: gettext('Edit Domains'), | |
238 | handler: function() { | |
239 | this.up('grid').run_editor(); | |
240 | } | |
241 | }, | |
242 | { | |
243 | xtype: 'button', | |
244 | itemId: 'createaccount', | |
245 | text: gettext('Register Account'), | |
246 | handler: function() { | |
247 | var me = this.up('grid'); | |
248 | var win = Ext.create('PVE.node.ACMEAccountCreate', { | |
249 | taskDone: function() { | |
250 | me.load_account(); | |
251 | me.reload(); | |
252 | } | |
253 | }); | |
254 | win.show(); | |
255 | } | |
256 | }, | |
257 | { | |
258 | xtype: 'button', | |
259 | itemId: 'viewaccount', | |
260 | text: gettext('View Account'), | |
261 | handler: function() { | |
262 | var me = this.up('grid'); | |
263 | var win = Ext.create('PVE.node.ACMEAccountView', { | |
264 | accountname: 'default' | |
265 | }); | |
266 | win.show(); | |
267 | } | |
268 | }, | |
269 | { | |
270 | xtype: 'button', | |
271 | itemId: 'order', | |
272 | text: gettext('Order Certificate'), | |
273 | handler: function() { | |
274 | var me = this.up('grid'); | |
275 | ||
276 | Proxmox.Utils.API2Request({ | |
277 | method: 'POST', | |
278 | params: { | |
279 | force: 1 | |
280 | }, | |
281 | url: '/nodes/' + me.nodename + '/certificates/acme/certificate', | |
282 | success: function(response, opt) { | |
283 | var win = Ext.create('Proxmox.window.TaskViewer', { | |
284 | upid: response.result.data, | |
285 | taskDone: function(success) { | |
286 | me.certificate_order_finished(success); | |
287 | } | |
288 | }); | |
289 | win.show(); | |
290 | }, | |
291 | failure: function(response, opt) { | |
292 | Ext.Msg.alert(gettext('Error'), response.htmlStatus); | |
293 | } | |
294 | }); | |
295 | } | |
488be4c2 DC |
296 | } |
297 | ], | |
298 | ||
299 | certificate_order_finished: function(success) { | |
300 | if (!success) { | |
301 | return; | |
302 | } | |
303 | var txt = gettext('pveproxy will be restarted with new certificates, please reload the GUI!'); | |
304 | Ext.getBody().mask(txt, ['pve-static-mask']); | |
305 | // reload after 10 seconds automatically | |
306 | Ext.defer(function() { | |
307 | window.location.reload(true); | |
308 | }, 10000); | |
309 | }, | |
310 | ||
311 | set_button_status: function() { | |
312 | var me = this; | |
313 | ||
314 | var account = !!me.account; | |
315 | var acmeObj = PVE.Parser.parseACME(me.getObjectValue('acme')); | |
316 | var domains = acmeObj ? acmeObj.domains.length : 0; | |
317 | ||
318 | var order = me.down('#order'); | |
488be4c2 DC |
319 | order.setVisible(account); |
320 | order.setDisabled(!account || !domains); | |
488be4c2 DC |
321 | |
322 | me.down('#createaccount').setVisible(!account); | |
323 | me.down('#viewaccount').setVisible(account); | |
324 | }, | |
325 | ||
326 | load_account: function() { | |
327 | var me = this; | |
328 | ||
329 | // for now we only use the 'default' account | |
330 | Proxmox.Utils.API2Request({ | |
331 | url: '/cluster/acme/account/default', | |
332 | success: function(response, opt) { | |
333 | me.account = response.result.data; | |
334 | me.set_button_status(); | |
335 | }, | |
336 | failure: function(response, opt) { | |
337 | me.account = undefined; | |
338 | me.set_button_status(); | |
339 | } | |
340 | }); | |
341 | }, | |
342 | ||
343 | run_editor: function() { | |
344 | var me = this; | |
345 | var win = Ext.create(me.rows.acme.editor, me.editorConfig); | |
346 | win.show(); | |
347 | win.on('destroy', me.reload, me); | |
348 | }, | |
349 | ||
350 | listeners: { | |
351 | itemdblclick: 'run_editor' | |
352 | }, | |
353 | ||
354 | // account data gets loaded here | |
355 | account: undefined, | |
356 | ||
357 | disableSelection: true, | |
358 | ||
359 | initComponent: function() { | |
360 | var me = this; | |
361 | ||
362 | if (!me.nodename) { | |
363 | throw "no nodename given"; | |
364 | } | |
365 | ||
366 | me.url = '/api2/json/nodes/' + me.nodename + '/config'; | |
367 | ||
368 | me.editorConfig = { | |
369 | url: '/api2/extjs/nodes/' + me.nodename + '/config' | |
370 | }; | |
371 | /*jslint confusion: true*/ | |
372 | /*acme is a string above*/ | |
373 | me.rows = { | |
374 | acme: { | |
375 | defaultValue: '', | |
376 | header: gettext('Domains'), | |
377 | editor: 'PVE.node.ACMEEditor', | |
378 | renderer: function(value) { | |
379 | var acmeObj = PVE.Parser.parseACME(value); | |
380 | if (acmeObj) { | |
381 | return acmeObj.domains.join('<br>'); | |
382 | } | |
383 | return Proxmox.Utils.noneText; | |
384 | } | |
385 | } | |
386 | }; | |
387 | /*jslint confusion: false*/ | |
388 | ||
389 | me.callParent(); | |
390 | me.mon(me.rstore, 'load', me.set_button_status, me); | |
391 | me.rstore.startUpdate(); | |
392 | me.load_account(); | |
393 | } | |
394 | }); |