now working
This commit is contained in:
@ -1,3 +1,58 @@
|
||||
import * as smartcli from "smartcli";
|
||||
import * as cflare from "cflare";
|
||||
#!/usr/bin/env node
|
||||
// the shebang line above makes sure this script will get interpreted by node
|
||||
|
||||
import "typings-global";
|
||||
import * as plugins from "./cert.plugins";
|
||||
import * as paths from "./cert.paths";
|
||||
|
||||
let smartcli = new plugins.smartcli.Smartcli();
|
||||
|
||||
let config = plugins.smartfile.local.toObjectSync(paths.config);
|
||||
let cflare = new plugins.cflare.CflareAccount();
|
||||
cflare.auth({
|
||||
email: config.cfEmail,
|
||||
key: config.cfKey
|
||||
});
|
||||
|
||||
let setChallenge = (domainNameArg: string, challengeArg: string) => {
|
||||
let done = plugins.q.defer();
|
||||
cflare.createRecord(prefixName(domainNameArg), "TXT", challengeArg).then(() => {
|
||||
cooldown().then(() => {
|
||||
done.resolve();
|
||||
});
|
||||
});
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
let cleanChallenge = (domainNameArg) => {
|
||||
let done = plugins.q.defer();
|
||||
cflare.removeRecord(prefixName(domainNameArg), "TXT");
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
let cooldown = () => {
|
||||
let done = plugins.q.defer();
|
||||
console.log("Cooling down!");
|
||||
setTimeout(() => {
|
||||
done.resolve();
|
||||
}, 20000)
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
let prefixName = (domainNameArg: string): string => {
|
||||
return "_acme-challenge." + domainNameArg;
|
||||
}
|
||||
|
||||
smartcli.addCommand({
|
||||
commandName: "deploy_challenge"
|
||||
}).then((argv) => {
|
||||
setChallenge(argv._[1], argv._[3]);
|
||||
});
|
||||
|
||||
smartcli.addCommand({
|
||||
commandName: "clean_challenge"
|
||||
}).then((argv) => {
|
||||
cleanChallenge(argv._[1]);
|
||||
});
|
||||
|
||||
smartcli.startParse();
|
||||
|
@ -1,3 +1,7 @@
|
||||
import "typings-global";
|
||||
export import path = require("path");
|
||||
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");
|
@ -1,6 +1,11 @@
|
||||
import "typings-global";
|
||||
export import beautylog = require("beautylog");
|
||||
export import cflare = require("cflare");
|
||||
export let fs = require("fs-extra");
|
||||
export import path = require("path");
|
||||
export let q = require("q");
|
||||
export let shelljs = require("shelljs");
|
||||
export import smartcli = require("smartcli");
|
||||
export import smartfile = require("smartfile");
|
||||
export import smartstring = require("smartstring");
|
||||
|
||||
|
15
ts/index.ts
15
ts/index.ts
@ -1,3 +1,4 @@
|
||||
import * as plugins from "./cert.plugins";
|
||||
import * as paths from "./cert.paths";
|
||||
|
||||
export class Cert {
|
||||
@ -17,8 +18,20 @@ export class Cert {
|
||||
this.cfKey = optionsArg.cfKey;
|
||||
this.sslDir = optionsArg.sslDir;
|
||||
this.gitOriginRepo = optionsArg.gitOriginRepo;
|
||||
let config = {
|
||||
cfEmail: this.cfEmail,
|
||||
cfKey: this.cfKey
|
||||
}
|
||||
plugins.smartfile.memory.toFsSync(JSON.stringify(config),{fileName:"config.json",filePath:plugins.path.join(__dirname,"assets/")});
|
||||
};
|
||||
getDomainCert(domainNameArg:string){
|
||||
let done = plugins.q.defer();
|
||||
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 + "\"");
|
||||
done.resolve();
|
||||
return done.promise;
|
||||
};
|
||||
getDomainCert(){};
|
||||
}
|
||||
|
||||
export class Certificate {
|
||||
|
@ -1,13 +1,23 @@
|
||||
import * as beautylog from "beautylog";
|
||||
import * as path from "path";
|
||||
import * as smartfile from "smartfile";
|
||||
let fs = require("fs-extra");
|
||||
beautylog.info("installing letsencrypt.sh locally...");
|
||||
import * as plugins from "./cert.plugins";
|
||||
import * as paths from "./cert.paths";
|
||||
|
||||
fs.ensureDir(path.join(__dirname,"assets/"));
|
||||
smartfile.remote.toFs(
|
||||
"https://raw.githubusercontent.com/lukas2511/letsencrypt.sh/master/letsencrypt.sh",
|
||||
path.join(__dirname,"assets/","le.sh")
|
||||
).then(() => {
|
||||
beautylog.success("Done!");
|
||||
});
|
||||
export let startInstall = () => {
|
||||
let done = plugins.q.defer();
|
||||
plugins.beautylog.info("installing letsencrypt.sh locally...");
|
||||
|
||||
plugins.fs.ensureDir(plugins.path.join(__dirname, "assets/"));
|
||||
plugins.smartfile.remote.toFs(
|
||||
"https://raw.githubusercontent.com/lukas2511/letsencrypt.sh/master/letsencrypt.sh",
|
||||
paths.letsencryptSh
|
||||
).then(() => {
|
||||
plugins.beautylog.success("Done!");
|
||||
done.resolve();
|
||||
});
|
||||
return done.promise;
|
||||
};
|
||||
|
||||
let smartcli = new plugins.smartcli.Smartcli();
|
||||
smartcli.addCommand({
|
||||
commandName:"install"
|
||||
}).then(startInstall);
|
||||
smartcli.startParse();
|
Reference in New Issue
Block a user