68 lines
8.6 KiB
JavaScript
Executable File
68 lines
8.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
"use strict";
|
|
require("typings-global");
|
|
var plugins = require("./cert.plugins");
|
|
var paths = require("./cert.paths");
|
|
var smartcli = new plugins.smartcli.Smartcli();
|
|
var config = plugins.smartfile.fs.toObjectSync(paths.config);
|
|
var cflare = new plugins.cflare.CflareAccount();
|
|
cflare.auth({
|
|
email: config.cfEmail,
|
|
key: config.cfKey
|
|
});
|
|
var setChallenge = function (domainNameArg, challengeArg) {
|
|
var done = plugins.q.defer();
|
|
plugins.beautylog.log("setting challenge for " + domainNameArg);
|
|
cflare.createRecord(prefixName(domainNameArg), "TXT", challengeArg).then(function () {
|
|
plugins.beautylog.ok("Challenge has been set!");
|
|
plugins.beautylog.info("We need to cool down to let DNS propagate to edge locations!");
|
|
cooldown().then(function () {
|
|
done.resolve();
|
|
});
|
|
});
|
|
return done.promise;
|
|
};
|
|
var cleanChallenge = function (domainNameArg) {
|
|
var done = plugins.q.defer();
|
|
plugins.beautylog.log("cleaning challenge for " + domainNameArg);
|
|
cflare.removeRecord(prefixName(domainNameArg), "TXT");
|
|
return done.promise;
|
|
};
|
|
var cooldown = function () {
|
|
var done = plugins.q.defer();
|
|
var cooldowntime = 40000;
|
|
var passedTime = 0;
|
|
plugins.beautylog.log("Cooling down! " + (cooldowntime / 1000).toString() + " seconds left");
|
|
var coolDownCounter = function () {
|
|
setTimeout(function () {
|
|
if (cooldowntime <= passedTime) {
|
|
plugins.beautylog.ok("Cooled down!");
|
|
done.resolve();
|
|
}
|
|
else {
|
|
passedTime = passedTime + 5000;
|
|
plugins.beautylog.log("Cooling down! " + ((cooldowntime - passedTime) / 1000).toString() + " seconds left");
|
|
coolDownCounter();
|
|
}
|
|
}, 5000);
|
|
};
|
|
coolDownCounter();
|
|
return done.promise;
|
|
};
|
|
var prefixName = function (domainNameArg) {
|
|
return "_acme-challenge." + domainNameArg;
|
|
};
|
|
smartcli.addCommand({
|
|
commandName: "deploy_challenge"
|
|
}).then(function (argv) {
|
|
setChallenge(argv._[1], argv._[3]);
|
|
});
|
|
smartcli.addCommand({
|
|
commandName: "clean_challenge"
|
|
}).then(function (argv) {
|
|
cleanChallenge(argv._[1]);
|
|
});
|
|
smartcli.startParse();
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImNlcnQuaG9vay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUdBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUN4QixJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBQzFDLElBQVksS0FBSyxXQUFNLGNBQWMsQ0FBQyxDQUFBO0FBRXRDLElBQUksUUFBUSxHQUFHLElBQUksT0FBTyxDQUFDLFFBQVEsQ0FBQyxRQUFRLEVBQUUsQ0FBQztBQUUvQyxJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxZQUFZLENBQUMsS0FBSyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0FBQzdELElBQUksTUFBTSxHQUFHLElBQUksT0FBTyxDQUFDLE1BQU0sQ0FBQyxhQUFhLEVBQUUsQ0FBQztBQUNoRCxNQUFNLENBQUMsSUFBSSxDQUFDO0lBQ1IsS0FBSyxFQUFFLE1BQU0sQ0FBQyxPQUFPO0lBQ3JCLEdBQUcsRUFBRSxNQUFNLENBQUMsS0FBSztDQUNwQixDQUFDLENBQUM7QUFFSCxJQUFJLFlBQVksR0FBRyxVQUFDLGFBQXFCLEVBQUUsWUFBb0I7SUFDM0QsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixPQUFPLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyx3QkFBd0IsR0FBRyxhQUFhLENBQUMsQ0FBQztJQUNoR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AgbGV0IGNvb2xkb3dudGltZSA9IDQwMDAwO1xuICAgIGxldCBwYXNzZWRUaW1lID0gMDtcbiAgICBwbHVnaW5zLmJlYXV0eWxvZy5sb2coXCJDb29saW5nIGRvd24hIFwiICsgKGNvb2xkb3dudGltZS8xMDAwKS50b1N0cmluZygpICsgXCIgc2Vjb25kcyBsZWZ0XCIpO1xuICAgIGxldCBjb29sRG93bkNvdW50ZXIgPSAoKSA9PiB7XG4gICAgICAgIHNldFRpbWVvdXQoKCkgPT4ge1xuICAgICAgICAgICAgaWYoY29vbGRvd250aW1lIDw9IHBhc3NlZFRpbWUpe1xuICAgICAgICAgICAgICAgIHBsdWdpbnMuYmVhdXR5bG9nLm9rKFwiQ29vbGVkIGRvd24hXCIpO1xuICAgICAgICAgICAgICAgIGRvbmUucmVzb2x2ZSgpO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBwYXNzZWRUaW1lID0gcGFzc2VkVGltZSArIDUwMDA7XG4gICAgICAgICAgICAgICAgcGx1Z2lucy5iZWF1dHlsb2cubG9nKFwiQ29vbGluZyBkb3duISBcIiArICgoY29vbGRvd250aW1lIC0gcGFzc2VkVGltZSkvMTAwMCkudG9TdHJpbmcoKSArIFwiIHNlY29uZHMgbGVmdFwiKTtcbiAgICAgICAgICAgICAgICBjb29sRG93bkNvdW50ZXIoKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSwgNTAwMCk7XG4gICAgfVxuICAgIGNvb2xEb3duQ291bnRlcigpO1xuICAgIHJldHVybiBkb25lLnByb21pc2U7XG59XG5cbmxldCBwcmVmaXhOYW1lID0gKGRvbWFpbk5hbWVBcmc6IHN0cmluZyk6IHN0cmluZyA9PiB7XG4gICAgcmV0dXJuIFwiX2FjbWUtY2hhbGxlbmdlLlwiICsgZG9tYWluTmFtZUFyZztcbn1cblxuc21hcnRjbGkuYWRkQ29tbWFuZCh7XG4gICAgY29tbWFuZE5hbWU6IFwiZGVwbG95X2NoYWxsZW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