2016-06-22 11:22:09 +00:00
|
|
|
#!/usr/bin/env node
|
2016-06-18 13:42:49 +00:00
|
|
|
"use strict";
|
2016-07-21 12:58:05 +00:00
|
|
|
const plugins = require("./cert.plugins");
|
|
|
|
const paths = require("./cert.paths");
|
|
|
|
let smartcli = new plugins.smartcli.Smartcli();
|
|
|
|
let config = plugins.smartfile.fs.toObjectSync(paths.config);
|
|
|
|
let cflare = new plugins.cflare.CflareAccount();
|
2016-06-22 11:22:09 +00:00
|
|
|
cflare.auth({
|
|
|
|
email: config.cfEmail,
|
|
|
|
key: config.cfKey
|
|
|
|
});
|
2016-07-21 12:58:05 +00:00
|
|
|
let setChallenge = (domainNameArg, challengeArg) => {
|
|
|
|
let done = plugins.q.defer();
|
2016-06-28 03:53:49 +00:00
|
|
|
plugins.beautylog.log("setting challenge for " + domainNameArg);
|
2016-07-21 12:58:05 +00:00
|
|
|
cflare.createRecord(prefixName(domainNameArg), "TXT", challengeArg).then(() => {
|
2016-06-28 03:53:49 +00:00
|
|
|
plugins.beautylog.ok("Challenge has been set!");
|
|
|
|
plugins.beautylog.info("We need to cool down to let DNS propagate to edge locations!");
|
2016-07-21 12:58:05 +00:00
|
|
|
cooldown().then(() => {
|
2016-06-22 11:22:09 +00:00
|
|
|
done.resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-07-21 12:58:05 +00:00
|
|
|
let cleanChallenge = (domainNameArg) => {
|
|
|
|
let done = plugins.q.defer();
|
2016-06-28 03:53:49 +00:00
|
|
|
plugins.beautylog.log("cleaning challenge for " + domainNameArg);
|
2016-06-22 11:22:09 +00:00
|
|
|
cflare.removeRecord(prefixName(domainNameArg), "TXT");
|
2016-07-24 17:56:32 +00:00
|
|
|
cooldown().then(() => {
|
|
|
|
done.resolve();
|
|
|
|
});
|
2016-06-22 11:22:09 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|
2016-07-21 12:58:05 +00:00
|
|
|
let cooldown = () => {
|
|
|
|
let done = plugins.q.defer();
|
2016-07-24 17:56:32 +00:00
|
|
|
let cooldowntime = 60000;
|
2016-07-21 12:58:05 +00:00
|
|
|
let passedTime = 0;
|
2016-06-28 03:53:49 +00:00
|
|
|
plugins.beautylog.log("Cooling down! " + (cooldowntime / 1000).toString() + " seconds left");
|
2016-07-21 12:58:05 +00:00
|
|
|
let coolDownCounter = () => {
|
|
|
|
setTimeout(() => {
|
2016-06-28 03:53:49 +00:00
|
|
|
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();
|
2016-06-22 11:22:09 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|
2016-07-21 12:58:05 +00:00
|
|
|
let prefixName = (domainNameArg) => {
|
2016-06-22 11:22:09 +00:00
|
|
|
return "_acme-challenge." + domainNameArg;
|
|
|
|
};
|
|
|
|
smartcli.addCommand({
|
|
|
|
commandName: "deploy_challenge"
|
2016-07-21 12:58:05 +00:00
|
|
|
}).then((argv) => {
|
2016-06-22 11:22:09 +00:00
|
|
|
setChallenge(argv._[1], argv._[3]);
|
|
|
|
});
|
|
|
|
smartcli.addCommand({
|
|
|
|
commandName: "clean_challenge"
|
2016-07-21 12:58:05 +00:00
|
|
|
}).then((argv) => {
|
2016-06-22 11:22:09 +00:00
|
|
|
cleanChallenge(argv._[1]);
|
|
|
|
});
|
|
|
|
smartcli.startParse();
|
2016-07-24 17:56:32 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5ob29rLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMv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