Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NiklasGollenstede/03fbac0a20e341b9f7f0670d77efcca1 to your computer and use it in GitHub Desktop.
Save NiklasGollenstede/03fbac0a20e341b9f7f0670d77efcca1 to your computer and use it in GitHub Desktop.
Lists all Let's Encrypt certificates with their current expiry dates
#!/usr/bin/env node
/// needs root, works with node v7+
module.exports = (async () => { 'use strict';
const CERT_DIR = '/etc/letsencrypt/live';
const FS = require('fs'), ChildProcess = require('child_process');
let names; try { names = FS.readdirSync(CERT_DIR); }
catch (error) { throw new Error('Could not access cert folder, please retry with root peermission'); }
const domains = (await Promise.all(names.map(domain =>
run('openssl x509 -enddate -noout -in "'+ CERT_DIR +'/'+ domain +'/cert.pem"').then(output => ({
name: domain, reverse: domain.split('.').reverse().join('.'),
output: output.replace(/^notAfter=|\s*$/g, ''),
}))
))).sort((a, b) => a.reverse > b.reverse ? 1 : -1);
const maxLength = Math.max(...domains.map(_=>_.name.length));
domains.forEach(({ name, output, reverse, }) => console.log(
' '.repeat(maxLength - name.length) + name +': ',
new Date(output).toISOString().replace('T', ' ').replace('.000Z', ' UTC')
));
return domains;
function run(command) { return new Promise((resolve, reject) => {
ChildProcess.exec(command, (error, stdout, stderr) => error ? reject(Object.assign(error, { stderr, stdout, })) : resolve(stdout));
}); }
})().catch(error => { console.error(error); process.exit(1); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment