Skip to content

Commit

Permalink
luci-app-acme: List of certificates
Browse files Browse the repository at this point in the history
Add a Certificates section to help users to find all issied certificates and path to them.

Signed-off-by: Sergey Ponomarev <[email protected]>
  • Loading branch information
stokito committed Jun 7, 2023
1 parent ec13186 commit 654964d
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
'require view';

return view.extend({
render: function (stats) {
load: function() {
return L.resolveDefault(fs.list('/etc/ssl/acme'), []).then(function(entries) {
var certs = [];
for (var i = 0; i < entries.length; i++)
if (entries[i].type == 'file' && entries[i].name.match(/\.key$/)) {
certs.push(entries[i]);
}

return Promise.all(certs);
});
},

render: function (certs) {
console.log(certs);
var m, s, o;

m = new form.Map("acme", _("ACME certificates"),
Expand Down Expand Up @@ -274,6 +287,36 @@ return view.extend({
o.datatype = 'uinteger';
o.modalonly = true;


s = m.section(form.GridSection, '_certificates');

s.render = L.bind(function(view, section_id) {
var table = E('table', { 'class': 'table cbi-section-table', 'id': 'certificates_table' }, [
E('tr', { 'class': 'tr table-titles' }, [
E('th', { 'class': 'th' }, _('Main Domain')),
E('th', { 'class': 'th' }, _('Path Private Key')),
E('th', { 'class': 'th' }, _('Path Public Certificate')),
E('th', { 'class': 'th' }, _('Issied on')),
])
]);

var rows = certs.map(function(cert) {
let domain = cert.name.substring(0, cert.name.length - 4);
let issueDate = new Date(cert.mtime * 1000).toLocaleDateString();
return [
domain,
"/etc/ssl/acme/" + domain + ".key",
"/etc/ssl/acme/" + domain + ".fullchain.crt",
issueDate,
];
});

cbi_update_table(table, rows, E('em', _('There are no certificates.')));

return E('div', { 'class': 'cbi-section cbi-tblsection' }, [
E('h3', _('Certificates')), table ]);
}, o, this);

return m.render()
}
})
Expand Down

0 comments on commit 654964d

Please sign in to comment.