improve logs and cooldown
This commit is contained in:
@ -7,7 +7,7 @@ import * as paths from "./cert.paths";
|
||||
|
||||
let smartcli = new plugins.smartcli.Smartcli();
|
||||
|
||||
let config = plugins.smartfile.local.toObjectSync(paths.config);
|
||||
let config = plugins.smartfile.fs.toObjectSync(paths.config);
|
||||
let cflare = new plugins.cflare.CflareAccount();
|
||||
cflare.auth({
|
||||
email: config.cfEmail,
|
||||
@ -16,7 +16,10 @@ cflare.auth({
|
||||
|
||||
let setChallenge = (domainNameArg: string, challengeArg: string) => {
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.log("setting challenge for " + domainNameArg);
|
||||
cflare.createRecord(prefixName(domainNameArg), "TXT", challengeArg).then(() => {
|
||||
plugins.beautylog.ok("Challenge has been set!");
|
||||
plugins.beautylog.info("We need to cool down to let DNS propagate to edge locations!");
|
||||
cooldown().then(() => {
|
||||
done.resolve();
|
||||
});
|
||||
@ -26,16 +29,29 @@ let setChallenge = (domainNameArg: string, challengeArg: string) => {
|
||||
|
||||
let cleanChallenge = (domainNameArg) => {
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.log("cleaning challenge for " + domainNameArg);
|
||||
cflare.removeRecord(prefixName(domainNameArg), "TXT");
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
let cooldown = () => {
|
||||
let done = plugins.q.defer();
|
||||
console.log("Cooling down!");
|
||||
setTimeout(() => {
|
||||
done.resolve();
|
||||
}, 20000)
|
||||
let cooldowntime = 40000;
|
||||
let passedTime = 0;
|
||||
plugins.beautylog.log("Cooling down! " + (cooldowntime/1000).toString() + " seconds left");
|
||||
let coolDownCounter = () => {
|
||||
setTimeout(() => {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -4,4 +4,4 @@ import * as plugins from "./cert.plugins";
|
||||
export let certHook = plugins.path.join(__dirname,"cert.hook.js");
|
||||
export let config = plugins.path.join(__dirname,"assets/config.json");
|
||||
export let letsencryptSh = plugins.path.join(__dirname,"assets/letsencrypt.sh");
|
||||
export let sslDir = plugins.path.join(__dirname,"/assets/certs");
|
||||
export let certDir = plugins.path.join(__dirname,"/assets/certs");
|
16
ts/index.ts
16
ts/index.ts
@ -22,14 +22,18 @@ export class Cert {
|
||||
cfEmail: this.cfEmail,
|
||||
cfKey: this.cfKey
|
||||
}
|
||||
plugins.smartfile.memory.toFsSync(JSON.stringify(config), { fileName: "config.json", filePath: plugins.path.join(__dirname, "assets/") });
|
||||
plugins.smartfile.memory.toFsSync(JSON.stringify(config),plugins.path.join(__dirname, "assets/config.json"));
|
||||
};
|
||||
getDomainCert(domainNameArg: string,optionsArg:{force:boolean}) {
|
||||
getDomainCert(domainNameArg: string,optionsArg?:{force:boolean}) {
|
||||
let done = plugins.q.defer();
|
||||
if (!checkDomainStillValid(domainNameArg) || optionsArg.force) {
|
||||
plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh);
|
||||
plugins.shelljs.exec("chmod 700 " + paths.certHook);
|
||||
plugins.shelljs.exec("bash -c \"" + paths.letsencryptSh + " -c -d " + domainNameArg + " -t dns-01 -k " + paths.certHook + " -o " + paths.sslDir + "\"");
|
||||
plugins.shelljs.exec("bash -c \"" + paths.letsencryptSh + " -c -d " + domainNameArg + " -t dns-01 -k " + paths.certHook + " -o " + paths.certDir + "\"");
|
||||
let fetchedCertsArray:string[] = plugins.smartfile.fs.listFoldersSync(paths.certDir);
|
||||
if(fetchedCertsArray.indexOf(domainNameArg) != -1){
|
||||
updateSslDir(domainNameArg);
|
||||
}
|
||||
done.resolve();
|
||||
} else {
|
||||
plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!");
|
||||
@ -39,7 +43,7 @@ export class Cert {
|
||||
};
|
||||
}
|
||||
|
||||
class Certificate {
|
||||
export class Certificate {
|
||||
domainName: string;
|
||||
creationDate: Date;
|
||||
expiryDate: Date;
|
||||
@ -52,8 +56,8 @@ let checkDomainStillValid = (domainNameArg: string): boolean => {
|
||||
return false;
|
||||
}
|
||||
|
||||
let updateSslDir = () => {
|
||||
|
||||
let updateSslDir = (domainNameArg) => {
|
||||
|
||||
}
|
||||
|
||||
let updateGitOrigin = () => {
|
||||
|
Reference in New Issue
Block a user