luci-app-acme: List of certificates
authorSergey Ponomarev <stokito@gmail.com>
Wed, 7 Jun 2023 08:29:32 +0000 (11:29 +0300)
committerSergey Ponomarev <stokito@gmail.com>
Mon, 7 Aug 2023 21:44:32 +0000 (00:44 +0300)
Add Certificates section to help users to see issued certificates and path to them.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
applications/luci-app-acme/htdocs/luci-static/resources/view/acme.js
applications/luci-app-acme/root/usr/share/rpcd/acl.d/luci-app-acme.json

index a7553df9a73eb2f67c22ac4054eb86a86a056cf5..2ddc1a645090f75ff29723d627efc56122cc54f7 100644 (file)
@@ -5,7 +5,19 @@
 '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 certs;
+               });
+       },
+
+       render: function (certs) {
                let wikiUrl = 'https://github.com/acmesh-official/acme.sh/wiki/';
                var wikiInstructionUrl = wikiUrl + 'dnsapi';
                var m, s, o;
@@ -512,7 +524,12 @@ return view.extend({
                o.datatype    = 'uinteger';
                o.modalonly = true;
 
-               return m.render()
+
+               s = m.section(form.GridSection, '_certificates');
+
+               s.render = L.bind(_renderCerts, this, certs);
+
+               return m.render();
        }
 })
 
@@ -560,3 +577,30 @@ function _extractParamValue(paramsKeyVals, paramName) {
 function _handleCheckService(c, event, curVal, newVal) {
        document.getElementById('wikiInstructionUrl').href = 'https://github.com/acmesh-official/acme.sh/wiki/dnsapi#' + newVal;
 }
+
+function _renderCerts(certs) {
+       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'}, _('Private Key')),
+                       E('th', {'class': 'th'}, _('Public Certificate')),
+                       E('th', {'class': 'th'}, _('Issued 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);
+
+       return E('div', {'class': 'cbi-section cbi-tblsection'}, [
+               E('h3', _('Certificates')), table]);
+}
index 110f9c5451798f8716d02bfd5a1cef9226dc1076..bf99dd57458b75a89fa378c1593e7aabead376ef 100644 (file)
@@ -3,8 +3,7 @@
                 "description": "Grant UCI access for luci-app-acme",
                 "read": {
                         "file": {
-                                "/usr/sbin/nginx": [ "read" ],
-                                "/usr/sbin/uhttpd": [ "read" ]
+                                "/etc/ssl/acme": [ "list" ]
                         },
                         "uci": [ "acme" ]
                 },