From b9537f841968df5256da06acf311e84a5bbe702a Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 28 Oct 2019 02:23:23 -0600 Subject: [PATCH] minor bugfixes --- README.md | 2 +- manager.js | 93 +++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 72 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 53bedf1..ff86bfc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # greenlock-manager-fs.js -A simple file-based management strategy for greenlock \ No newline at end of file +A simple file-based management strategy for greenlock diff --git a/manager.js b/manager.js index affc0ab..f01065f 100644 --- a/manager.js +++ b/manager.js @@ -17,9 +17,7 @@ Manage.create = function(opts) { } if (!opts.configFile) { opts.configFile = '~/.config/greenlock/manager.json'; - console.info( - "[Manager] using default config file:\n\t'" + opts.configFile + "'" - ); + console.info('Greenlock Manager Config File: ' + opts.configFile); } opts.configFile = opts.configFile.replace('~/', homedir + '/'); @@ -29,9 +27,7 @@ Manage.create = function(opts) { return Manage._ping(manage, opts); }; - manage._txPromise = new Promise(function(resolve) { - resolve(); - }); + manage._txPromise = Promise.resolve(); manage.config = function(conf) { // get / set default site settings such as @@ -87,7 +83,7 @@ Manage.create = function(opts) { config[k] = conf[k]; }); - return manage.save(config); + return manage._save(config); }); }; @@ -129,6 +125,7 @@ Manage.create = function(opts) { // if the fs has changed since we last wrote, get the lastest from disk return Manage._getLatest(manage, opts).then(function(config) { // TODO move to Greenlock.add + var subscriberEmail = args.subscriberEmail; var subject = args.subject || args.domain; var primary = subject; var altnames = args.altnames || args.domains; @@ -160,10 +157,14 @@ Manage.create = function(opts) { // and to make deterministic auto-corrections // TODO added, removed, moved (duplicate), changed - site.subscriberEmail = site.subscriberEmail; + if (subscriberEmail) { + site.subscriberEmail = subscriberEmail; + } site.subject = subject; site.altnames = altnames; - site.issuedAt = site.issuedAt || 0; + if (!site.issuedAt) { + site.issuedAt = 0; + } site.expiresAt = site.expiresAt || 0; site.lastAttemptAt = site.lastAttemptAt || 0; // re-add if this was deleted @@ -183,11 +184,15 @@ Manage.create = function(opts) { } // These should usually be empty, for most situations - site.subscriberEmail = args.subscriberEmail; - site.customerEmail = args.customerEmail; - site.challenges = args.challenges; - site.store = args.store; - console.log('[debug] save site', site); + if (args.customerEmail) { + site.customerEmail = args.customerEmail; + } + if (args.challenges) { + site.challenges = args.challenges; + } + if (args.store) { + site.store = args.store; + } return manage._save(config).then(function() { return JSON.parse(JSON.stringify(site)); @@ -204,11 +209,18 @@ Manage.create = function(opts) { // i.e. find certs more that will expire in less than 45 days //args.expiresBefore = Date.now() + 45 * 24 * 60 * 60 * 1000; var issuedBefore = args.issuedBefore || 0; - var expiresBefore = - args.expiresBefore || Date.now() + 21 * 24 * 60 * 60 * 1000; + var expiresBefore = args.expiresBefore || Infinity; //Date.now() + 21 * 24 * 60 * 60 * 1000; + + var altnames = (args.altnames || args.domains || []).slice(0); + if (args.servername && !altnames.includes(args.servername)) { + altnames.push(args.servername); + } + if (args.subject && !altnames.includes(args.subject)) { + altnames.push(args.subject); + } // TODO match ANY domain on any cert - var sites = Object.keys(config.sites) + var sites = Object.keys(config.sites || {}) .filter(function(sub) { var site = config.sites[sub]; if ( @@ -216,14 +228,13 @@ Manage.create = function(opts) { site.expiresAt < expiresBefore || site.issuedAt < issuedBefore ) { - if (!args.subject || sub === args.subject) { - return true; - } + return (site.altnames || []).some(function(name) { + return altnames.includes(name); + }); } }) .map(function(name) { var site = config.sites[name]; - console.debug('debug', site); return { subject: site.subject, altnames: site.altnames, @@ -269,7 +280,45 @@ Manage.create = function(opts) { } // TODO define message types - console.info(ev, args); + if (!manage._notify_notice) { + console.info( + 'set greenlockOptions.notify to override the default logger' + ); + manage._notify_notice = true; + } + switch (ev) { + case 'error': + /* falls through */ + case 'warning': + console.error( + 'Error%s:', + args.context ? ' ' + args.context : '' + ); + console.error(args.message); + if (args.description) { + console.error(args.description); + } + if (args.code) { + console.error('code:', args.code); + } + break; + default: + if (/status/.test(ev)) { + console.info( + ev, + args.altname || args.subject || '', + args.status || '' + ); + if (!args.status) { + console.log(args); + } + break; + } + console.info( + ev, + '(more info available: ' + Object.keys(args).join(' ') + ')' + ); + } }; manage.errors = function(err) {