2016-08-10 02:39:39 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-10-09 12:54:27 +00:00
|
|
|
var DAY = 24 * 60 * 60 * 1000;
|
|
|
|
|
2018-05-16 01:29:58 +00:00
|
|
|
var Greenlock = require('greenlock');
|
2016-08-10 02:39:39 +00:00
|
|
|
|
|
|
|
module.exports.run = function (args) {
|
|
|
|
var leChallenge;
|
|
|
|
var leStore;
|
|
|
|
var servers;
|
|
|
|
var USE_DNS = {};
|
|
|
|
var challengeType;
|
2018-05-16 01:29:58 +00:00
|
|
|
|
|
|
|
args.acmeUrl = args.server = (args.acmeUrl || args.server);
|
|
|
|
args.root = args.webrootPath = (args.root || args.webrootPath);
|
2016-08-10 02:39:39 +00:00
|
|
|
if (args.dns01) {
|
|
|
|
challengeType = 'dns-01';
|
|
|
|
args.webrootPath = '';
|
|
|
|
args.standalone = USE_DNS;
|
|
|
|
} else /*if (args.http01Port)*/ {
|
|
|
|
challengeType = 'http-01';
|
|
|
|
}
|
|
|
|
|
2016-08-10 03:39:07 +00:00
|
|
|
if (args.manual) {
|
|
|
|
leChallenge = require('le-challenge-manual').create({});
|
|
|
|
}
|
|
|
|
else if (args.webrootPath) {
|
2016-08-10 02:39:39 +00:00
|
|
|
// webrootPath is all that really matters here
|
2016-08-10 03:39:07 +00:00
|
|
|
// TODO rename le-challenge-fs to le-challenge-webroot
|
2016-08-10 02:39:39 +00:00
|
|
|
leChallenge = require('./lib/webroot').create({ webrootPath: args.webrootPath });
|
|
|
|
}
|
|
|
|
else if (USE_DNS !== args.standalone) {
|
2016-08-10 03:39:07 +00:00
|
|
|
leChallenge = require('le-challenge-standalone').create({});
|
2016-10-08 04:16:26 +00:00
|
|
|
servers = require('./lib/servers').create(leChallenge);
|
2016-08-10 02:39:39 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 01:29:58 +00:00
|
|
|
var privkeyPath = args.privkeyPath || args.domainKeyPath || ':configDir/live/:hostname/privkey.pem'; //args.privkeyPath
|
2016-08-10 02:39:39 +00:00
|
|
|
leStore = require('le-store-certbot').create({
|
|
|
|
configDir: args.configDir
|
2016-10-11 15:22:37 +00:00
|
|
|
, privkeyPath: privkeyPath
|
2016-08-10 02:39:39 +00:00
|
|
|
, fullchainPath: args.fullchainPath
|
|
|
|
, certPath: args.certPath
|
|
|
|
, chainPath: args.chainPath
|
2018-05-16 01:29:58 +00:00
|
|
|
, bundlePath: args.bundlePath
|
|
|
|
, webrootPath: args.root
|
2016-08-10 02:39:39 +00:00
|
|
|
, domainKeyPath: args.domainKeyPath
|
|
|
|
, accountKeyPath: args.accountKeyPath
|
|
|
|
});
|
|
|
|
|
2018-05-16 01:29:58 +00:00
|
|
|
if (!args.acmeUrl) {
|
|
|
|
throw new Error("You must specify the ACME server url with --acme-url");
|
|
|
|
}
|
|
|
|
if (!args.acmeVersion) {
|
|
|
|
throw new Error("You must specify the ACME API version with --acme-version");
|
2016-08-11 17:39:10 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 01:29:58 +00:00
|
|
|
// let Greenlock know that we're handling standalone / webroot here
|
2016-10-08 04:16:26 +00:00
|
|
|
var leChallenges = {};
|
|
|
|
leChallenges[challengeType] = leChallenge;
|
2018-05-16 01:29:58 +00:00
|
|
|
var greenlock = Greenlock.create({
|
2016-08-10 02:39:39 +00:00
|
|
|
debug: args.debug
|
2018-05-16 01:29:58 +00:00
|
|
|
, server: args.acmeUrl
|
|
|
|
, version: args.acmeVersion
|
2016-08-10 02:39:39 +00:00
|
|
|
, store: leStore
|
2016-10-08 04:16:26 +00:00
|
|
|
, challenges: leChallenges
|
2016-10-09 12:54:27 +00:00
|
|
|
, renewWithin: args.renewWithin * DAY
|
2016-08-10 02:39:39 +00:00
|
|
|
, duplicate: args.duplicate
|
|
|
|
});
|
|
|
|
|
2016-10-08 04:16:26 +00:00
|
|
|
if (servers) {
|
|
|
|
if (args.tlsSni01Port) {
|
2017-05-17 15:20:36 +00:00
|
|
|
servers.startServers(
|
2016-10-08 04:16:26 +00:00
|
|
|
[], args.tlsSni01Port
|
2018-05-16 01:29:58 +00:00
|
|
|
, { debug: args.debug, tlsOptions: greenlock.tlsOptions }
|
2016-10-08 04:16:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
2017-05-17 15:20:36 +00:00
|
|
|
servers.startServers(
|
2016-10-08 04:16:26 +00:00
|
|
|
args.http01Port || [80], []
|
|
|
|
, { debug: args.debug }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 02:39:39 +00:00
|
|
|
// Note: can't use args directly as null values will overwrite template values
|
2018-05-16 01:29:58 +00:00
|
|
|
return greenlock.register({
|
2016-10-09 12:54:27 +00:00
|
|
|
debug: args.debug
|
2016-08-10 02:39:39 +00:00
|
|
|
, email: args.email
|
|
|
|
, agreeTos: args.agreeTos
|
2018-05-16 01:29:58 +00:00
|
|
|
, communityMember: args.communityMember
|
2016-10-09 12:54:27 +00:00
|
|
|
, domains: args.domains
|
2016-08-10 02:39:39 +00:00
|
|
|
, rsaKeySize: args.rsaKeySize
|
2016-10-09 12:54:27 +00:00
|
|
|
, challengeType: challengeType
|
|
|
|
}).then(function (certs) {
|
2017-08-25 06:56:19 +00:00
|
|
|
if (!certs.renewing) {
|
2016-10-09 12:54:27 +00:00
|
|
|
return certs;
|
|
|
|
}
|
|
|
|
console.log("");
|
|
|
|
console.log("Got certificate(s) for " + certs.altnames.join(', '));
|
|
|
|
console.log("\tIssued at " + new Date(certs.issuedAt).toISOString() + "");
|
|
|
|
console.log("\tValid until " + new Date(certs.expiresAt).toISOString() + "");
|
|
|
|
console.log("");
|
|
|
|
console.log("Renewing them now");
|
2017-08-25 06:56:19 +00:00
|
|
|
return certs.renewing;
|
2016-08-10 02:39:39 +00:00
|
|
|
}).then(function (certs) {
|
2016-10-09 12:54:27 +00:00
|
|
|
console.log("");
|
|
|
|
console.log("Got certificate(s) for " + certs.altnames.join(', '));
|
|
|
|
console.log("\tIssued at " + new Date(certs.issuedAt).toISOString() + "");
|
|
|
|
console.log("\tValid until " + new Date(certs.expiresAt).toISOString() + "");
|
|
|
|
console.log("");
|
2016-10-11 15:22:37 +00:00
|
|
|
console.log('Private key installed at:');
|
|
|
|
console.log(
|
|
|
|
privkeyPath
|
|
|
|
.replace(/:configDir/g, args.configDir)
|
|
|
|
.replace(/:hostname/g, args.domains[0])
|
|
|
|
);
|
|
|
|
console.log("");
|
2016-10-09 12:54:27 +00:00
|
|
|
|
2016-08-10 02:39:39 +00:00
|
|
|
// should get back account, path to certs, pems, etc?
|
2016-10-11 15:22:37 +00:00
|
|
|
console.log('Certificates installed at:');
|
|
|
|
console.log(
|
|
|
|
[
|
2018-05-16 01:29:58 +00:00
|
|
|
// args.privkeyPath
|
2016-10-11 15:22:37 +00:00
|
|
|
args.certPath
|
|
|
|
, args.chainPath
|
|
|
|
, args.fullchainPath
|
2018-05-16 01:29:58 +00:00
|
|
|
, args.bundlePath || ''
|
|
|
|
].join('\n').replace(/\n+/g, '\n')
|
2016-10-11 15:22:37 +00:00
|
|
|
.replace(/:configDir/g, args.configDir)
|
|
|
|
.replace(/:hostname/g, args.domains[0])
|
|
|
|
);
|
|
|
|
console.log("");
|
2016-08-10 02:39:39 +00:00
|
|
|
|
2017-05-17 15:20:36 +00:00
|
|
|
if (servers) {
|
|
|
|
return servers.closeServers({ debug: args.debug }).then(function() {
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-04-16 21:09:23 +00:00
|
|
|
return 0;
|
2016-08-10 02:39:39 +00:00
|
|
|
}, function (err) {
|
2017-01-25 21:42:01 +00:00
|
|
|
console.error('[Error]: greenlock-cli');
|
2016-08-10 02:39:39 +00:00
|
|
|
console.error(err.stack || new Error('get stack').stack);
|
|
|
|
|
2017-04-16 21:09:23 +00:00
|
|
|
return 1;
|
2016-08-10 02:39:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|