acme-dns-01-cli.js/index.js

68 lines
1.9 KiB
JavaScript

'use strict';
var Challenge = module.exports;
Challenge.create = function (defaults) {
return {
options: defaults
, set: Challenge.set
, get: Challenge.get
, remove: Challenge.remove
};
};
// Show the user the token and key and wait for them to be ready to continue
Challenge.set = function (args, cb) {
if (!args.challenge) {
console.error("please update to greenlock v2.7+");
process.exit();
}
var opts = args.challenge;
if (this.leDnsResponse) {
this.leDnsResponse(opts.token, opts.keyAuthorization, opts.dnsAuthorization, opts.dnsHost, opts.altname)
.then(function (/*successMessage*/) {
cb(null);
});
} else {
console.info("");
console.info("Challenge for '" + opts.altname + "'");
console.info("");
console.info("We now present (for you copy-and-paste pleasure) your ACME Challenge");
console.info("");
console.info(opts.dnsHost + "\tTXT " + opts.dnsAuthorization + "\tTTL 60");
console.info("");
console.info(JSON.stringify({
identifier: opts.identifier
, wildcard: opts.wildcard
, altname: opts.altname
, type: opts.type
, token: opts.token
, keyAuthorization: opts.keyAuthorization
, dnsHost: opts.dnsHost
, dnsAuthorization: opts.dnsAuthorization
, expires: opts.expires
}, null, ' ').replace(/^/gm, '\t'));
console.info("");
console.info("hit enter to continue...");
process.stdin.resume();
process.stdin.on('data', function () {
process.stdin.pause();
cb(null);
});
}
};
// nothing to do here, that's why it's manual
Challenge.get = function (defaults, cb) {
// defaults.challenge
cb(null);
};
// might as well tell the user that whatever they were setting up has been checked
Challenge.remove = function (args, cb) {
console.info("Challenge complete. You may remove the DNS-01 challenge record:");
console.info("\t" + args.challenge.altname + "\tTXT\t" + args.challenge.dnsAuthorization);
cb(null);
};