]>
git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/panel/Certificates.js
1 Ext
.define('Proxmox.panel.Certificates', {
2 extend
: 'Ext.grid.Panel',
3 xtype
: 'pmxCertificates',
5 // array of { name, id (=filename), url, deletable, reloadUi }
6 uploadButtons
: undefined,
8 // The /info path for the current node.
13 header
: gettext('File'),
15 dataIndex
: 'filename',
18 header
: gettext('Issuer'),
23 header
: gettext('Subject'),
28 header
: gettext('Public Key Alogrithm'),
30 dataIndex
: 'public-key-type',
34 header
: gettext('Public Key Size'),
36 dataIndex
: 'public-key-bits',
40 header
: gettext('Valid Since'),
42 dataIndex
: 'notbefore',
43 renderer
: Proxmox
.Utils
.render_timestamp
,
46 header
: gettext('Expires'),
48 dataIndex
: 'notafter',
49 renderer
: Proxmox
.Utils
.render_timestamp
,
52 header
: gettext('Subject Alternative Names'),
55 renderer
: Proxmox
.Utils
.render_san
,
58 header
: gettext('Fingerprint'),
59 dataIndex
: 'fingerprint',
63 header
: gettext('PEM'),
74 delete_certificate: function() {
77 let rec
= me
.selModel
.getSelection()[0];
82 let cert
= me
.certById
[rec
.id
];
84 Proxmox
.Utils
.API2Request({
85 url
: `/api2/extjs/${url}?restart=1`,
87 success: function(response
, opt
) {
90 gettext('API server will be restarted to use new certificates, please reload web-interface!'),
93 // try to reload after 10 seconds automatically
94 Ext
.defer(() => window
.location
.reload(true), 10000);
97 failure: function(response
, opt
) {
98 Ext
.Msg
.alert(gettext('Error'), response
.htmlStatus
);
104 xclass
: 'Ext.app.ViewController',
105 view_certificate: function() {
107 let view
= me
.getView();
109 let selection
= view
.getSelection();
110 if (!selection
|| selection
.length
< 1) {
113 let win
= Ext
.create('Proxmox.window.CertificateViewer', {
114 cert
: selection
[0].data
.filename
,
115 url
: `/api2/extjs/${view.infoUrl}`,
122 itemdblclick
: 'view_certificate',
125 initComponent: function() {
129 // only used for the store name
130 me
.nodename
= "_all";
133 if (!me
.uploadButtons
) {
134 throw "no upload buttons defined";
138 throw "no certificate store url given";
141 me
.rstore
= Ext
.create('Proxmox.data.UpdateStore', {
142 storeid
: 'certs-' + me
.nodename
,
143 model
: 'proxmox-certificate',
146 url
: `/api2/extjs/${me.infoUrl}`,
157 me
.deletableCertIds
= {};
159 if (me
.uploadButtons
.length
=== 1) {
160 let cert
= me
.uploadButtons
[0];
163 throw "missing certificate url";
166 me
.certById
[cert
.id
] = cert
;
168 if (cert
.deletable
) {
169 me
.deletableCertIds
[cert
.id
] = true;
175 text
: gettext('Upload Custom Certificate'),
176 handler: function() {
177 let grid
= this.up('grid');
178 let win
= Ext
.create('Proxmox.window.CertificateUpload', {
179 url
: `/api2/extjs/${cert.url}`,
180 reloadUi
: cert
.reloadUi
,
183 win
.on('destroy', grid
.reload
, grid
);
190 me
.selModel
= Ext
.create('Ext.selection.RowModel', {});
192 for (const cert
of me
.uploadButtons
) {
194 throw "missing id in certificate entry";
198 throw "missing url in certificate entry";
202 throw "missing name in certificate entry";
205 me
.certById
[cert
.id
] = cert
;
207 if (cert
.deletable
) {
208 me
.deletableCertIds
[cert
.id
] = true;
212 text
: Ext
.String
.format('Upload {0} Certificate', cert
.name
),
213 handler: function() {
214 let grid
= this.up('grid');
215 let win
= Ext
.create('Proxmox.window.CertificateUpload', {
216 url
: `/api2/extjs/${cert.url}`,
217 reloadUi
: cert
.reloadUi
,
220 win
.on('destroy', grid
.reload
, grid
);
227 text
: gettext('Upload Custom Certificate'),
238 xtype
: 'proxmoxButton',
239 text
: gettext('Delete Custom Certificate'),
240 confirmMsg
: rec
=> Ext
.String
.format(
241 gettext('Are you sure you want to remove the certificate used for {0}'),
242 me
.certById
[rec
.id
].name
,
244 callback
: () => me
.reload(),
245 selModel
: me
.selModel
,
247 enableFn
: rec
=> !!me
.deletableCertIds
[rec
.id
],
248 handler: function() { me
.delete_certificate(); },
252 xtype
: 'proxmoxButton',
255 text
: gettext('View Certificate'),
256 handler
: 'view_certificate',
259 Ext
.apply(me
, { tbar
});
263 me
.rstore
.startUpdate();
264 me
.on('destroy', me
.rstore
.stopUpdate
, me
.rstore
);