AJ ONeal
5 years ago
8 changed files with 391 additions and 124 deletions
@ -0,0 +1,70 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
var args = process.argv.slice(3); |
||||
|
var cli = require('./cli.js'); |
||||
|
//var path = require('path');
|
||||
|
//var pkgpath = path.join(__dirname, '..', 'package.json');
|
||||
|
//var pkgpath = path.join(process.cwd(), 'package.json');
|
||||
|
|
||||
|
var Flags = require('./flags.js'); |
||||
|
|
||||
|
Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) { |
||||
|
var myFlags = {}; |
||||
|
['subject', 'servername' /*, 'servernames', 'altnames'*/].forEach(function( |
||||
|
k |
||||
|
) { |
||||
|
myFlags[k] = flagOptions[k]; |
||||
|
}); |
||||
|
|
||||
|
cli.parse(myFlags); |
||||
|
cli.main(function(argList, flags) { |
||||
|
Flags.mangleFlags(flags, mconf); |
||||
|
main(argList, flags, rc, greenlock, mconf); |
||||
|
}, args); |
||||
|
}); |
||||
|
|
||||
|
async function main(_, flags, rc, greenlock /*, mconf */) { |
||||
|
var servernames = [flags.subject] |
||||
|
.concat([flags.servername]) |
||||
|
//.concat(flags.servernames)
|
||||
|
//.concat(flags.altnames)
|
||||
|
.filter(Boolean); |
||||
|
delete flags.subject; |
||||
|
delete flags.altnames; |
||||
|
flags.servernames = servernames; |
||||
|
if (flags.servernames.length > 1) { |
||||
|
console.error('Error: should only have one servername'); |
||||
|
process.exit(1); |
||||
|
return; |
||||
|
} else if (flags.servernames.length !== 1) { |
||||
|
console.error('Error: need a servername to check'); |
||||
|
process.exit(1); |
||||
|
return; |
||||
|
} |
||||
|
flags.servername = flags.servernames[0]; |
||||
|
delete flags.servernames; |
||||
|
|
||||
|
greenlock |
||||
|
._config(flags) |
||||
|
.catch(function(err) { |
||||
|
console.error(); |
||||
|
console.error('error:', err.message); |
||||
|
console.log(err.stack); |
||||
|
console.error(); |
||||
|
}) |
||||
|
.then(function(site) { |
||||
|
if (!site) { |
||||
|
console.info(); |
||||
|
console.info('No config found for '); |
||||
|
console.info(); |
||||
|
process.exit(1); |
||||
|
return; |
||||
|
} |
||||
|
console.info(); |
||||
|
console.info( |
||||
|
'Config for ' + JSON.stringify(flags.servername) + ':' |
||||
|
); |
||||
|
console.info(JSON.stringify(site, null, 2)); |
||||
|
console.info(); |
||||
|
}); |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
store: [ |
||||
|
false, |
||||
|
'the npm name or path of the storage module or callbacks file', |
||||
|
'string', |
||||
|
'greenlock-store-fs' |
||||
|
], |
||||
|
'store-xxxx': [ |
||||
|
false, |
||||
|
'an option for the chosen storage module, such as --store-apikey or --store-bucket', |
||||
|
'bag' |
||||
|
], |
||||
|
'store-json': [ |
||||
|
false, |
||||
|
'a JSON string containing all option for the chosen store module (instead of --store-xxxx)', |
||||
|
'json', |
||||
|
'{}' |
||||
|
], |
@ -0,0 +1,138 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
var Flags = module.exports; |
||||
|
|
||||
|
var path = require('path'); |
||||
|
//var pkgpath = path.join(__dirname, '..', 'package.json');
|
||||
|
var pkgpath = path.join(process.cwd(), 'package.json'); |
||||
|
var GreenlockRc = require('./greenlockrc.js'); |
||||
|
|
||||
|
Flags.init = function() { |
||||
|
return GreenlockRc(pkgpath).then(async function(rc) { |
||||
|
var Greenlock = require('../'); |
||||
|
// this is a copy, so it's safe to modify
|
||||
|
rc._bin_mode = true; |
||||
|
var greenlock = Greenlock.create(rc); |
||||
|
var mconf = await greenlock.manager.defaults(); |
||||
|
|
||||
|
var flagOptions = { |
||||
|
subject: [ |
||||
|
false, |
||||
|
'the "subject" (primary domain) of the certificate', |
||||
|
'string' |
||||
|
], |
||||
|
altnames: [ |
||||
|
false, |
||||
|
'the "subject alternative names" (additional domains) on the certificate, the first of which MUST be the subject', |
||||
|
'string' |
||||
|
], |
||||
|
servername: [ |
||||
|
false, |
||||
|
'a name that matches a subject or altname', |
||||
|
'string' |
||||
|
], |
||||
|
servernames: [ |
||||
|
false, |
||||
|
'a list of names that matches a subject or altname', |
||||
|
'string' |
||||
|
], |
||||
|
'renew-offset': [ |
||||
|
false, |
||||
|
"time to wait until renewing the cert such as '45d' (45 days after being issued) or '-3w' (3 weeks before expiration date)", |
||||
|
'string', |
||||
|
mconf.renewOffset |
||||
|
], |
||||
|
'server-key-type': [ |
||||
|
false, |
||||
|
"either 'RSA-2048' or 'P-256' (ECDSA) - although other values are technically supported, they don't make sense and won't work with many services (More bits != More security)", |
||||
|
'string', |
||||
|
mconf.serverKeyType |
||||
|
], |
||||
|
challenge: [ |
||||
|
false, |
||||
|
'the name name of file path of the HTTP-01, DNS-01, or TLS-ALPN-01 challenge module to use', |
||||
|
'string', |
||||
|
Object.keys(mconf.challenges) |
||||
|
.map(function(typ) { |
||||
|
return mconf.challenges[typ].module; |
||||
|
}) |
||||
|
.join(',') |
||||
|
], |
||||
|
'challenge-xxxx': [ |
||||
|
false, |
||||
|
'an option for the chosen challenge module, such as --challenge-apikey or --challenge-bucket', |
||||
|
'bag' |
||||
|
], |
||||
|
'challenge-json': [ |
||||
|
false, |
||||
|
'a JSON string containing all option for the chosen challenge module (instead of --challenge-xxxx)', |
||||
|
'json', |
||||
|
'{}' |
||||
|
], |
||||
|
'force-save': [ |
||||
|
false, |
||||
|
"save all options for this site, even if it's the same as the defaults", |
||||
|
'boolean', |
||||
|
false |
||||
|
] |
||||
|
}; |
||||
|
|
||||
|
return { |
||||
|
flagOptions, |
||||
|
rc, |
||||
|
greenlock, |
||||
|
mconf |
||||
|
}; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
Flags.mangleFlags = function(flags, mconf) { |
||||
|
if ('altnames' in flags) { |
||||
|
flags.altnames = (flags.altnames || '').split(/[,\s]+/).filter(Boolean); |
||||
|
} |
||||
|
if ('servernames' in flags) { |
||||
|
flags.servernames = (flags.servernames || '') |
||||
|
.split(/[,\s]+/) |
||||
|
.filter(Boolean); |
||||
|
} |
||||
|
|
||||
|
Object.keys(flags).forEach(function(k) { |
||||
|
if (flags[k] === mconf[k] && !flags.forceSave) { |
||||
|
delete flags[k]; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
var typ; |
||||
|
var challenge; |
||||
|
if (flags.challenge) { |
||||
|
if (/http-01/.test(flags.challenge)) { |
||||
|
typ = 'http-01'; |
||||
|
} else if (/dns-01/.test(flags.challenge)) { |
||||
|
typ = 'dns-01'; |
||||
|
} else if (/tls-alpn-01/.test(flags.challenge)) { |
||||
|
typ = 'tls-alpn-01'; |
||||
|
} |
||||
|
|
||||
|
challenge = flags.challengeOpts; |
||||
|
challenge.module = flags.challenge; |
||||
|
flags.challenges = {}; |
||||
|
flags.challenges[typ] = challenge; |
||||
|
delete flags.challengeOpts; |
||||
|
delete flags.challenge; |
||||
|
|
||||
|
var chall = mconf.challenges[typ]; |
||||
|
if (challenge.module === chall.module) { |
||||
|
var keys = Object.keys(challenge); |
||||
|
var same = |
||||
|
!keys.length || |
||||
|
keys.every(function(k) { |
||||
|
return chall[k] === challenge[k]; |
||||
|
}); |
||||
|
if (same && !flags.forceSave) { |
||||
|
delete flags.challenges; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
delete flags.forceSave; |
||||
|
}; |
@ -0,0 +1,72 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
var args = process.argv.slice(3); |
||||
|
var cli = require('./cli.js'); |
||||
|
var Flags = require('./flags.js'); |
||||
|
|
||||
|
Flags.init().then(function({ flagOptions, rc, greenlock, mconf }) { |
||||
|
var myFlags = {}; |
||||
|
[ |
||||
|
'subject', |
||||
|
'altnames', |
||||
|
'renew-offset', |
||||
|
'server-key-type', |
||||
|
'challenge', |
||||
|
'challenge-xxxx', |
||||
|
'challenge-json', |
||||
|
'force-save' |
||||
|
].forEach(function(k) { |
||||
|
myFlags[k] = flagOptions[k]; |
||||
|
}); |
||||
|
|
||||
|
cli.parse(myFlags); |
||||
|
cli.main(function(argList, flags) { |
||||
|
main(argList, flags, rc, greenlock, mconf); |
||||
|
}, args); |
||||
|
}); |
||||
|
|
||||
|
async function main(_, flags, rc, greenlock, mconf) { |
||||
|
if (!flags.subject || !flags.altnames) { |
||||
|
console.error( |
||||
|
'--subject and --altnames must be provided and should be valid domains' |
||||
|
); |
||||
|
process.exit(1); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
Flags.mangleFlags(flags, mconf); |
||||
|
|
||||
|
greenlock.update(flags).catch(function(err) { |
||||
|
console.error(); |
||||
|
console.error('error:', err.message); |
||||
|
console.error(); |
||||
|
}) .then(function() { |
||||
|
return greenlock |
||||
|
._config({ servername: flags.subject }) |
||||
|
.then(function(site) { |
||||
|
if (!site) { |
||||
|
console.info(); |
||||
|
console.info('No config found for '); |
||||
|
console.info(); |
||||
|
process.exit(1); |
||||
|
return; |
||||
|
} |
||||
|
console.info(); |
||||
|
console.info("Updated config!"); |
||||
|
console.info(); |
||||
|
|
||||
|
Object.keys(site).forEach(function(k) { |
||||
|
if ('defaults' === k) { |
||||
|
console.info(k + ':'); |
||||
|
Object.keys(site.defaults).forEach(function(key) { |
||||
|
var value = JSON.stringify(site.defaults[key]); |
||||
|
console.info('\t' + key + ':' + value); |
||||
|
}); |
||||
|
} else { |
||||
|
console.info(k + ': ' + JSON.stringify(site[k])); |
||||
|
} |
||||
|
}); |
||||
|
console.info(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
Loading…
Reference in new issue