From 2e8cfd00d240f99e7eb7163081dc49c4a90a22ce Mon Sep 17 00:00:00 2001 From: PhilKunz Date: Sun, 24 Jul 2016 19:39:20 +0200 Subject: [PATCH] now paying respect to same zone subdomains --- dist/cert.classes.cert.d.ts | 44 ++++++ dist/cert.classes.cert.helpers.d.ts | 20 +++ dist/cert.classes.cert.helpers.js | 59 ++++++++ dist/cert.classes.cert.js | 137 +++++++++++++++++++ dist/cert.helpers.d.ts | 5 - dist/cert.helpers.js | 25 ---- dist/cert.hook.js | 4 +- dist/index.d.ts | 45 +----- dist/index.js | 161 +--------------------- package.json | 6 +- test/test.js | 6 +- test/test.ts | 4 +- ts/cert.classes.cert.helpers.ts | 86 ++++++++++++ ts/cert.classes.cert.ts | 160 ++++++++++++++++++++++ ts/cert.helpers.ts | 25 ---- ts/index.ts | 203 +--------------------------- 16 files changed, 522 insertions(+), 468 deletions(-) create mode 100644 dist/cert.classes.cert.d.ts create mode 100644 dist/cert.classes.cert.helpers.d.ts create mode 100644 dist/cert.classes.cert.helpers.js create mode 100644 dist/cert.classes.cert.js delete mode 100644 dist/cert.helpers.d.ts delete mode 100644 dist/cert.helpers.js create mode 100644 ts/cert.classes.cert.helpers.ts create mode 100644 ts/cert.classes.cert.ts delete mode 100644 ts/cert.helpers.ts diff --git a/dist/cert.classes.cert.d.ts b/dist/cert.classes.cert.d.ts new file mode 100644 index 0000000..a739484 --- /dev/null +++ b/dist/cert.classes.cert.d.ts @@ -0,0 +1,44 @@ +/// +import * as plugins from "./cert.plugins"; +export interface ICertConstructorOptions { + cfEmail: string; + cfKey: string; + sslDir?: string; + gitOriginRepo?: string; + testMode?: boolean; +} +export declare class Cert { + private _cfEmail; + private _cfKey; + private _sslDir; + private _gitOriginRepo; + private _testMode; + domainCertRequestMap: plugins.lik.Stringmap; + certificatesPresent: Certificate[]; + certificatesValid: Certificate[]; + /** + * Constructor for Cert object + */ + constructor(optionsArg: ICertConstructorOptions); + /** + * Pulls already requested certificates from git origin + */ + sslGitOriginPull: () => void; + /** + * Pushes all new requested certificates to git origin + */ + sslGitOriginAddCommitPush: () => void; + /** + * gets a ssl cert for a given domain + */ + getDomainCert(domainNameArg: string, optionsArg?: { + force: boolean; + }): plugins.q.Promise<{}>; + cleanOldCertificates(): void; +} +export declare class Certificate { + domainName: string; + creationDate: Date; + expiryDate: Date; + constructor(); +} diff --git a/dist/cert.classes.cert.helpers.d.ts b/dist/cert.classes.cert.helpers.d.ts new file mode 100644 index 0000000..6806147 --- /dev/null +++ b/dist/cert.classes.cert.helpers.d.ts @@ -0,0 +1,20 @@ +/// +import { Cert } from "./index.ts"; +import * as plugins from "./cert.plugins"; +/** + * schedule a retry of certificate request + */ +export declare let scheduleRetry: (domainArg: string, certClassArg: Cert) => plugins.q.Promise<{}>; +/** + * check if a given domainCert is still valid + */ +export declare let checkDomainsStillValid: (domainNameArg: string, sslDirArg: string) => boolean; +export interface certConfig { + domainName: string; + created: number; + expires: number; +} +/** + * update a ssl directory + */ +export declare let updateSslDirSync: (sslDirArg: string, domainNameArg: string) => void; diff --git a/dist/cert.classes.cert.helpers.js b/dist/cert.classes.cert.helpers.js new file mode 100644 index 0000000..6d0d10a --- /dev/null +++ b/dist/cert.classes.cert.helpers.js @@ -0,0 +1,59 @@ +"use strict"; +const plugins = require("./cert.plugins"); +const paths = require("./cert.paths"); +/** + * schedule a retry of certificate request + */ +exports.scheduleRetry = (domainArg, certClassArg) => { + let done = plugins.q.defer(); + setTimeout(() => { + certClassArg.getDomainCert(domainArg) + .then(done.resolve); + }, 20000); + return done.promise; +}; +/** + * check if a given domainCert is still valid + */ +exports.checkDomainsStillValid = (domainNameArg, sslDirArg) => { + let domainConfigPath = plugins.path.join(sslDirArg, domainNameArg, "config.json"); + if (plugins.smartfile.fs.fileExistsSync(domainConfigPath)) { + let domainConfig = plugins.smartfile.fs.toObjectSync(domainConfigPath, "json"); + if (Date.now() >= ((domainConfig.expires - 604800) * 1000)) { + return false; + } + else { + return true; + } + } + else { + return false; + } +}; +; +/** + * update a ssl directory + */ +exports.updateSslDirSync = (sslDirArg, domainNameArg) => { + plugins.smartfile.fs.ensureDirSync(sslDirArg); + let domainCertFolder = plugins.path.join(paths.certDir, domainNameArg); + if (plugins.smartfile.fs.listFoldersSync(paths.certDir).indexOf(domainNameArg) != -1) { + plugins.smartfile.fs.copySync(plugins.path.join(domainCertFolder, "fullchain.pem"), plugins.path.join(sslDirArg, domainNameArg, "fullchain.pem")); + plugins.smartfile.fs.copySync(plugins.path.join(domainCertFolder, "privkey.pem"), plugins.path.join(sslDirArg, domainNameArg, "privkey.pem")); + // create cert config + let certRegex = /.*\-([0-9]*)\.pem/; + let certFileNameWithTime = plugins.smartfile.fs.listFilesSync(domainCertFolder, certRegex)[0]; + let certTime = parseInt(certRegex.exec(certFileNameWithTime)[1]); + let certConfig = { + domainName: domainNameArg, + created: certTime, + expires: certTime + 7776000 + }; + plugins.smartfile.memory.toFsSync(JSON.stringify(certConfig), plugins.path.join(sslDirArg, domainNameArg, "config.json")); + } + ; +}; +let updateGitOrigin = (syncDirectionArg) => { +}; +updateGitOrigin(0 /* toOrigin */); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5jbGFzc2VzLmNlcnQuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2NlcnQuY2xhc3Nlcy5jZXJ0LmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUNBLE1BQVksT0FBTyxXQUFNLGdCQUFnQixDQUFDLENBQUE7QUFDMUMsTUFBWSxLQUFLLFdBQU0sY0FBYyxDQUFDLENBQUE7QUFJdEM7O0dBRUc7QUFDUSxxQkFBYSxHQUFHLENBQUMsU0FBZ0IsRUFBQyxZQUFpQjtJQUMxRCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQzdCLFVBQVUsQ0FBQzt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UFhLENBQUMsZ0JBQWdCLEVBQUUsU0FBUyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDdEcsSUFBSSxRQUFRLEdBQUcsUUFBUSxDQUFDLFNBQVMsQ0FBQyxJQUFJLENBQUMsb0JBQW9CLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO1FBQ2pFLElBQUksVUFBVSxHQUFlO1lBQ3pCLFVBQVUsRUFBRSxhQUFhO1lBQ3pCLE9BQU8sRUFBRSxRQUFRO1lBQ2pCLE9BQU8sRUFBRSxRQUFRLEdBQUcsT0FBTztTQUM5QixDQUFDO1FBQ0YsT0FBTyxDQUFDLFNBQVMsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUM3QixJQUFJLENBQUMsU0FBUyxDQUFDLFVBQVUsQ0FBQyxFQUMxQixPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsYUFBYSxFQUFFLGFBQWEsQ0FBQyxDQUM3RCxDQUFDO0lBQ04sQ0FBQztJQUFBLENBQUM7QUFDTixDQUFDLENBQUE7QUFPRCxJQUFJLGVBQWUsR0FBRyxDQUFDLGdCQUFrQztBQUV6RCxDQUFDLENBQUM7QUFFRixlQUFlLENBQUMsZ0JBQXlCLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/dist/cert.classes.cert.js b/dist/cert.classes.cert.js new file mode 100644 index 0000000..a11ea23 --- /dev/null +++ b/dist/cert.classes.cert.js @@ -0,0 +1,137 @@ +"use strict"; +const plugins = require("./cert.plugins"); +const paths = require("./cert.paths"); +const helpers = require("./cert.classes.cert.helpers"); +; +class Cert { + /** + * Constructor for Cert object + */ + constructor(optionsArg) { + this.domainCertRequestMap = new plugins.lik.Stringmap(); + /** + * Pulls already requested certificates from git origin + */ + this.sslGitOriginPull = () => { + if (this._gitOriginRepo) { + plugins.smartgit.pull(this._sslDir, "origin", "master"); + } + }; + /** + * Pushes all new requested certificates to git origin + */ + this.sslGitOriginAddCommitPush = () => { + if (this._gitOriginRepo) { + plugins.smartgit.add.addAll(this._sslDir); + plugins.smartgit.commit(this._sslDir, "added new SSL certificates and deleted obsolete ones."); + plugins.smartgit.push(this._sslDir, "origin", "master"); + } + }; + this._cfEmail = optionsArg.cfEmail; + this._cfKey = optionsArg.cfKey; + this._sslDir = optionsArg.sslDir; + this._gitOriginRepo = optionsArg.gitOriginRepo; + this._testMode = optionsArg.testMode; + // write hook config + let config = { + cfEmail: this._cfEmail, + cfKey: this._cfKey + }; + plugins.smartfile.memory.toFsSync(JSON.stringify(config), plugins.path.join(__dirname, "assets/config.json")); + // setup sslDir + if (!this._sslDir) + this._sslDir = paths.defaultSslDir; + // setup Git + if (this._gitOriginRepo) { + plugins.smartgit.init(this._sslDir); + plugins.smartgit.remote.add(this._sslDir, "origin", this._gitOriginRepo); + this.sslGitOriginPull(); + } + // setup leSh config; + let leShConfigString; + if (this._testMode) { + leShConfigString = `CA="https://acme-staging.api.letsencrypt.org/directory"\n`; + } + else { + leShConfigString = " "; + } + ; + plugins.smartfile.memory.toFsSync(leShConfigString, paths.leShConfig); + plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh); + plugins.shelljs.exec("chmod 700 " + paths.certHook); + plugins.shelljs.exec(`bash -c "${paths.letsencryptSh} -c --no-lock -f ${paths.leShConfig} -d notthere.notthere -t dns-01 -k ${paths.certHook} -o ${paths.certDir}"`, { + silent: true + }); + } + ; + /** + * gets a ssl cert for a given domain + */ + getDomainCert(domainNameArg, optionsArg = { force: false }) { + let done = plugins.q.defer(); + let domainStringData = new plugins.smartstring.Domain(domainNameArg); + let sameZoneRequesting = this.domainCertRequestMap.checkMinimatch("*" + domainStringData.zoneName); + // make sure no one else requires the same domain at the same time + if (!this.domainCertRequestMap.checkString(domainNameArg)) { + this.domainCertRequestMap.addString(domainNameArg); + if (!helpers.checkDomainsStillValid(domainNameArg, this._sslDir) || optionsArg.force) { + if (!sameZoneRequesting) { + plugins.smartfile.fs.ensureDir(paths.certDir); + plugins.beautylog.info(`getting cert for ${domainNameArg}`); + plugins.shelljs.exec(`bash -c "${paths.letsencryptSh} -c --no-lock -f ${paths.leShConfig} -d ${domainNameArg} -t dns-01 -k ${paths.certHook} -o ${paths.certDir}"`, { + silent: true + }, (codeArg, stdoutArg) => { + if (codeArg == 0) { + console.log(stdoutArg); + let fetchedCertsArray = plugins.smartfile.fs.listFoldersSync(paths.certDir); + if (fetchedCertsArray.indexOf(domainNameArg) != -1) { + helpers.updateSslDirSync(this._sslDir, domainNameArg); + plugins.smartfile.fs.removeSync(plugins.path.join(paths.certDir, domainNameArg)); + } + ; + done.resolve(); + } + else { + plugins.beautylog.warn(`${domainNameArg} scheduled for retry`); + helpers.scheduleRetry(domainNameArg, this).then(done.resolve); + } + this.domainCertRequestMap.removeString(domainNameArg); + }); + } + else { + plugins.beautylog.info(`${domainNameArg} is waiting for domains names of same zone to finish`); + this.domainCertRequestMap.removeString(domainNameArg); + this.domainCertRequestMap.registerUntilTrue(() => { + return !this.domainCertRequestMap.checkMinimatch("*" + domainStringData.zoneName); + }, () => { + this.getDomainCert(domainNameArg).then(done.resolve); + }); + } + } + else { + plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!"); + this.domainCertRequestMap.removeString(domainNameArg); + done.resolve(); + } + ; + } + else { + plugins.beautylog.warn(`${domainNameArg} is already requesting`); + } + ; + return done.promise; + } + ; + cleanOldCertificates() { + } + ; +} +exports.Cert = Cert; +class Certificate { + constructor() { + } + ; +} +exports.Certificate = Certificate; +; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5jbGFzc2VzLmNlcnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9jZXJ0LmNsYXNzZXMuY2VydC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sZ0JBQWdCLENBQUMsQ0FBQTtBQUMxQy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FBRUQ7SUFJSTtJQUVBLENBQUM7O0FBQ0wsQ0FBQztBQVBZLG1CQUFXLGNBT3ZCLENBQUE7QUFBQSxDQUFDIn0= \ No newline at end of file diff --git a/dist/cert.helpers.d.ts b/dist/cert.helpers.d.ts deleted file mode 100644 index 612c343..0000000 --- a/dist/cert.helpers.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/// -import { Cert } from "./index.ts"; -import * as plugins from "./cert.plugins"; -export declare let accountsKeyPresent: () => plugins.q.Promise<{}>; -export declare let scheduleRetry: (domainArg: string, certClassArg: Cert) => plugins.q.Promise<{}>; diff --git a/dist/cert.helpers.js b/dist/cert.helpers.js deleted file mode 100644 index 43153ba..0000000 --- a/dist/cert.helpers.js +++ /dev/null @@ -1,25 +0,0 @@ -"use strict"; -const plugins = require("./cert.plugins"); -let firstCall = true; -let enoughTime = false; -exports.accountsKeyPresent = () => { - let done = plugins.q.defer(); - if (firstCall) { - done.resolve(); - firstCall = false; - } - else { - setTimeout(done.resolve, 5000); - } - ; - return done.promise; -}; -exports.scheduleRetry = (domainArg, certClassArg) => { - let done = plugins.q.defer(); - setTimeout(() => { - certClassArg.getDomainCert(domainArg) - .then(done.resolve); - }, 20000); - return done.promise; -}; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvY2VydC5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFDQSxNQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBRzFDLElBQUksU0FBUyxHQUFHLElBQUksQ0FBQztBQUNyQixJQUFJLFVBQVUsR0FBRyxLQUFLLENBQUM7QUFDWiwwQkFBa0IsR0FBRztJQUM1QixJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQzdCLEVBQUUsQ0FBQyxDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUM7UUFDWixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7UUFDZixTQUFTLEdBQUcsS0FBSyxDQUFDO0lBQ3RCLENBQUM7SUFBRSxJQUFJLENBQUMsQ0FBQztRQUNMLFVBQVUsQ0FBQyxJQUFJLENBQUMsT0FBTyxFQUFDLElBQUksQ0FBQyxDQUFDO0lBQ2xDLENBQUM7SUFBQSxDQUFDO0lBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDeEIsQ0FBQyxDQUFDO0FBRVMscUJBQWEsR0FBRyxDQUFDLFNBQWdCLEVBQUMsWUFBaUI7SUFDMUQsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUM3QixVQUFVLENBQUM7UUFDUCxZQUFZLENBQUMsYUFBYSxDQUFDLFNBQVMsQ0FBQzthQUNoQyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzVCLENBQUMsRUFBQyxLQUFLLENBQUMsQ0FBQztJQUNULE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO0FBQ3hCLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/dist/cert.hook.js b/dist/cert.hook.js index 9483691..8f496ae 100755 --- a/dist/cert.hook.js +++ b/dist/cert.hook.js @@ -29,7 +29,7 @@ let cleanChallenge = (domainNameArg) => { }; let cooldown = () => { let done = plugins.q.defer(); - let cooldowntime = 120000; + let cooldowntime = 40000; let passedTime = 0; plugins.beautylog.log("Cooling down! " + (cooldowntime / 1000).toString() + " seconds left"); let coolDownCounter = () => { @@ -62,4 +62,4 @@ smartcli.addCommand({ cleanChallenge(argv._[1]); }); smartcli.startParse(); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2VydC5ob29rLmpzIi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BWSxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLEVBQUUsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3ZDLENBQUMsQ0FBQyxDQUFDO0FBRUgsUUFBUSxDQUFDLFVBQVUsQ0FBQztJQUNoQixXQUFXLEVBQUUsaUJBQWlCO0NBQ2pDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxJQUFJO0lBQ1QsY0FBYyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztBQUM5QixDQUFDLENBQUMsQ0FBQztBQUVILFFBQVEsQ0FBQyxVQUFVLEVBQUUsQ0FBQyJ9 \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 0ce6043..b406cb4 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,44 +1 @@ -/// -import * as plugins from "./cert.plugins"; -export interface ICertConstructorOptions { - cfEmail: string; - cfKey: string; - sslDir?: string; - gitOriginRepo?: string; - testMode?: boolean; -} -export declare class Cert { - private _cfEmail; - private _cfKey; - private _sslDir; - private _gitOriginRepo; - private _testMode; - domainsCurrentlyRequesting: plugins.lik.Stringmap; - certificatesPresent: Certificate[]; - certificatesValid: Certificate[]; - /** - * Constructor for Cert object - */ - constructor(optionsArg: ICertConstructorOptions); - /** - * Pulls already requested certificates from git origin - */ - sslGitOriginPull: () => void; - /** - * Pushes all new requested certificates to git origin - */ - sslGitOriginAddCommitPush: () => void; - /** - * gets a ssl cert for a given domain - */ - getDomainCert(domainNameArg: string, optionsArg?: { - force: boolean; - }): plugins.q.Promise<{}>; - cleanOldCertificates(): void; -} -export declare class Certificate { - domainName: string; - creationDate: Date; - expiryDate: Date; - constructor(); -} +export * from "./cert.classes.cert"; diff --git a/dist/index.js b/dist/index.js index 55f9a9d..bf83e15 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,159 +1,6 @@ "use strict"; -const plugins = require("./cert.plugins"); -const paths = require("./cert.paths"); -const helpers = require("./cert.helpers"); -; -class Cert { - /** - * Constructor for Cert object - */ - constructor(optionsArg) { - this.domainsCurrentlyRequesting = new plugins.lik.Stringmap(); - /** - * Pulls already requested certificates from git origin - */ - this.sslGitOriginPull = () => { - if (this._gitOriginRepo) { - plugins.smartgit.pull(this._sslDir, "origin", "master"); - } - }; - /** - * Pushes all new requested certificates to git origin - */ - this.sslGitOriginAddCommitPush = () => { - if (this._gitOriginRepo) { - plugins.smartgit.add.addAll(this._sslDir); - plugins.smartgit.commit(this._sslDir, "added new SSL certificates and deleted obsolete ones."); - plugins.smartgit.push(this._sslDir, "origin", "master"); - } - }; - this._cfEmail = optionsArg.cfEmail; - this._cfKey = optionsArg.cfKey; - this._sslDir = optionsArg.sslDir; - this._gitOriginRepo = optionsArg.gitOriginRepo; - this._testMode = optionsArg.testMode; - // write hook config - let config = { - cfEmail: this._cfEmail, - cfKey: this._cfKey - }; - plugins.smartfile.memory.toFsSync(JSON.stringify(config), plugins.path.join(__dirname, "assets/config.json")); - // setup sslDir - if (!this._sslDir) - this._sslDir = paths.defaultSslDir; - // setup Git - if (this._gitOriginRepo) { - plugins.smartgit.init(this._sslDir); - plugins.smartgit.remote.add(this._sslDir, "origin", this._gitOriginRepo); - this.sslGitOriginPull(); - } - // setup leSh config; - let leShConfigString; - if (this._testMode) { - leShConfigString = `CA="https://acme-staging.api.letsencrypt.org/directory"\n`; - } - else { - leShConfigString = " "; - } - ; - plugins.smartfile.memory.toFsSync(leShConfigString, paths.leShConfig); - plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh); - plugins.shelljs.exec("chmod 700 " + paths.certHook); - } - ; - /** - * gets a ssl cert for a given domain - */ - getDomainCert(domainNameArg, optionsArg = { force: false }) { - let done = plugins.q.defer(); - // make sure no one else requires the same domain at the same time - helpers.accountsKeyPresent().then(() => { - if (!this.domainsCurrentlyRequesting.checkString(domainNameArg)) { - this.domainsCurrentlyRequesting.addString(domainNameArg); - if (!checkDomainsStillValid(domainNameArg, this._sslDir) || optionsArg.force) { - plugins.smartfile.fs.ensureDir(paths.certDir); - plugins.beautylog.info(`getting cert for ${domainNameArg}`); - plugins.shelljs.exec(`bash -c "${paths.letsencryptSh} -c --no-lock -f ${paths.leShConfig} -d ${domainNameArg} -t dns-01 -k ${paths.certHook} -o ${paths.certDir}"`, { - silent: true - }, (codeArg, stdoutArg) => { - if (codeArg == 0) { - console.log(stdoutArg); - let fetchedCertsArray = plugins.smartfile.fs.listFoldersSync(paths.certDir); - if (fetchedCertsArray.indexOf(domainNameArg) != -1) { - updateSslDirSync(this._sslDir, domainNameArg); - plugins.smartfile.fs.removeSync(plugins.path.join(paths.certDir, domainNameArg)); - } - this.domainsCurrentlyRequesting.removeString(domainNameArg); - done.resolve(); - } - else { - this.domainsCurrentlyRequesting.removeString(domainNameArg); - plugins.beautylog.warn(`${domainNameArg} scheduled for retry`); - helpers.scheduleRetry(domainNameArg, this).then(done.resolve); - } - }); - } - else { - plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!"); - this.domainsCurrentlyRequesting.removeString(domainNameArg); - done.resolve(); - } - ; - } - else { - plugins.beautylog.warn(`${domainNameArg} is already requesting`); - } - ; - }); - return done.promise; - } - ; - cleanOldCertificates() { - } - ; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } -exports.Cert = Cert; -class Certificate { - constructor() { - } - ; -} -exports.Certificate = Certificate; -let checkDomainsStillValid = (domainNameArg, sslDirArg) => { - let domainConfigPath = plugins.path.join(sslDirArg, domainNameArg, "config.json"); - if (plugins.smartfile.fs.fileExistsSync(domainConfigPath)) { - let domainConfig = plugins.smartfile.fs.toObjectSync(domainConfigPath, "json"); - if (Date.now() >= ((domainConfig.expires - 604800) * 1000)) { - return false; - } - else { - return true; - } - } - else { - return false; - } -}; -let updateSslDirSync = (sslDirArg, domainNameArg) => { - plugins.smartfile.fs.ensureDirSync(sslDirArg); - let domainCertFolder = plugins.path.join(paths.certDir, domainNameArg); - if (plugins.smartfile.fs.listFoldersSync(paths.certDir).indexOf(domainNameArg) != -1) { - plugins.smartfile.fs.copySync(plugins.path.join(domainCertFolder, "fullchain.pem"), plugins.path.join(sslDirArg, domainNameArg, "fullchain.pem")); - plugins.smartfile.fs.copySync(plugins.path.join(domainCertFolder, "privkey.pem"), plugins.path.join(sslDirArg, domainNameArg, "privkey.pem")); - // create cert config - let certRegex = /.*\-([0-9]*)\.pem/; - let certFileNameWithTime = plugins.smartfile.fs.listFilesSync(domainCertFolder, certRegex)[0]; - let certTime = parseInt(certRegex.exec(certFileNameWithTime)[1]); - let certConfig = { - domainName: domainNameArg, - created: certTime, - expires: certTime + 7776000 - }; - plugins.smartfile.memory.toFsSync(JSON.stringify(certConfig), plugins.path.join(sslDirArg, domainNameArg, "config.json")); - } - ; -}; -let updateGitOrigin = (syncDirectionArg) => { -}; -updateGitOrigin(0 /* toOrigin */); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sZ0JBQWdCLENBQUMsQ0FBQTtBQUMxQyxNQUFZLEtBQUssV0FBTSxjQUFjLENBQUMsQ0FBQTtBQUN0QyxNQUFZLE9BQU8sV0FBTSxnQkFFekIsQ0FBQyxDQUZ3QztBQVF4QyxDQUFDO0FBRUY7SUFVSTs7T0FFRztJQUNILFlBQVksVUFBbUM7UUFQL0MsK0JBQTBCLEdBQTBCLElBQUksT0FBTyxDQUFDLEdBQUcsQ0FBQyxTQUFTLEVBQUUsQ0FBQztRQTZDaEY7O1dBRUc7UUFDSCxxQkFBZ0IsR0FBRztZQUNmLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxjQUFjLENBQUMsQ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QUMsU0FBUyxDQUFDLFVBQVUsQ0FBQyxFQUMxQixPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxTQUFTLEVBQUUsYUFBYSxFQUFFLGFBQWEsQ0FBQyxDQUM3RCxDQUFDO0lBQ04sQ0FBQztJQUFBLENBQUM7QUFDTixDQUFDLENBQUE7QUFPRCxJQUFJLGVBQWUsR0FBRyxDQUFDLGdCQUFrQztBQUV6RCxDQUFDLENBQUM7QUFFRixlQUFlLENBQUMsZ0JBQXlCLENBQUMsQ0FBQyJ9 \ No newline at end of file +__export(require("./cert.classes.cert")); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBR0EsaUJBQWMscUJBQXFCLENBQUMsRUFBQSJ9 \ No newline at end of file diff --git a/package.json b/package.json index ee2747f..60493a4 100644 --- a/package.json +++ b/package.json @@ -30,12 +30,12 @@ "@types/minimatch": "^2.0.28", "@types/q": "^0.0.27", "@types/shelljs": "^0.3.27", - "beautylog": "^5.0.14", + "beautylog": "^5.0.18", "cflare": "0.0.9", "fs-extra": "^0.30.0", - "lik": "^1.0.2", + "lik": "^1.0.5", "q": "^1.4.1", - "shelljs": "^0.7.0", + "shelljs": "^0.7.1", "smartcli": "^1.0.4", "smartfile": "^4.0.12", "smartgit": "0.1.9", diff --git a/test/test.js b/test/test.js index 981e373..47a3f91 100644 --- a/test/test.js +++ b/test/test.js @@ -36,12 +36,12 @@ describe("cert", function () { return Math.floor(Math.random() * (max - min) + min); } promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1, 100000)}.bleu.de`)); - //promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1,100000)}.bleu.de`)); - //promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1,100000)}.bleu.de`)); + promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1, 100000)}.bleu.de`)); + promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1, 100000)}.bleu.de`)); q.all(promiseArray).then(() => { done(); }); }); }); }); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUNoQix1QkFBbUIsTUFBTSxDQUFDLENBQUE7QUFDMUIsTUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsTUFBTyxDQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDeEIsMEJBQTJCLGlCQUFpQixDQUFDLENBQUE7QUFDN0MsTUFBWSxJQUFJLFdBQU0sZUFBZSxDQUFDLENBQUE7QUFHdEMsSUFBSSxRQUFRLEdBQUcsSUFBSSxXQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsRUFBRSxFQUFFLE9BQU8sQ0FBQyxHQUFHLEVBQUUsR0FBRyxTQUFTLENBQUMsQ0FBQztBQUVsRSxJQUFJLFFBQWtCLENBQUM7QUFFdkIsUUFBUSxDQUFDLE1BQU0sRUFBQztJQUNaLFFBQVEsQ0FBQyxTQUFTLEVBQUM7UUFDZixFQUFFLENBQUMsZ0NBQWdDLEVBQUMsVUFBUyxJQUFJO1lBQzdDLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7WUFDbkIsc0JBQVksRUFBRSxDQUFDLElBQUksQ0FBQztnQkFDaEIsSUFBSSxFQUFFLENBQUM7WUFDWCxDQUFDLENBQUMsQ0FBQTtRQUNOLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQU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FBRyxDQUFDLENBQUM7WUFDekQsQ0FBQztZQUNELFlBQVksQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDLGFBQWEsQ0FBQyxVQUFVLGtCQUFrQixDQUFDLENBQUMsRUFBQyxNQUFNLENBQUMsVUFBVSxDQUFDLENBQUMsQ0FBQztZQUM1RixZQUFZLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxhQUFhLENBQUMsVUFBVSxrQkFBa0IsQ0FBQyxDQUFDLEVBQUMsTUFBTSxDQUFDLFVBQVUsQ0FBQyxDQUFDLENBQUM7WUFDNUYsWUFBWSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsYUFBYSxDQUFDLFVBQVUsa0JBQWtCLENBQUMsQ0FBQyxFQUFDLE1BQU0sQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFDO1lBQzVGLENBQUMsQ0FBQyxHQUFHLENBQUMsWUFBWSxDQUFDLENBQUMsSUFBSSxDQUFDO2dCQUNyQixJQUFJLEVBQUUsQ0FBQztZQUNYLENBQUMsQ0FBQyxDQUFDO1FBQ1AsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFDIn0= \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 85b40d9..cc25a7b 100644 --- a/test/test.ts +++ b/test/test.ts @@ -39,8 +39,8 @@ describe("cert",function(){ return Math.floor(Math.random() * (max - min) + min); } promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1,100000)}.bleu.de`)); - //promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1,100000)}.bleu.de`)); - //promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1,100000)}.bleu.de`)); + promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1,100000)}.bleu.de`)); + promiseArray.push(testCert.getDomainCert(`testing${getRandomArbitrary(1,100000)}.bleu.de`)); q.all(promiseArray).then(() => { done(); }); diff --git a/ts/cert.classes.cert.helpers.ts b/ts/cert.classes.cert.helpers.ts new file mode 100644 index 0000000..cbef911 --- /dev/null +++ b/ts/cert.classes.cert.helpers.ts @@ -0,0 +1,86 @@ +import {Cert} from "./index.ts"; +import * as plugins from "./cert.plugins"; +import * as paths from "./cert.paths"; + + + +/** + * schedule a retry of certificate request + */ +export let scheduleRetry = (domainArg:string,certClassArg:Cert) => { + let done = plugins.q.defer(); + setTimeout(() => { + certClassArg.getDomainCert(domainArg) + .then(done.resolve); + },20000); + return done.promise; +}; + +/** + * check if a given domainCert is still valid + */ +export let checkDomainsStillValid = (domainNameArg: string, sslDirArg: string): boolean => { + let domainConfigPath = plugins.path.join(sslDirArg, domainNameArg, "config.json"); + if (plugins.smartfile.fs.fileExistsSync(domainConfigPath)) { + let domainConfig = plugins.smartfile.fs.toObjectSync( + domainConfigPath, + "json" + ); + if (Date.now() >= ((domainConfig.expires - 604800) * 1000)) { + return false; + } else { + return true; + } + } else { + return false; + } + +} + +export interface certConfig { + domainName: string; + created: number; + expires: number; +}; + +/** + * update a ssl directory + */ +export let updateSslDirSync = (sslDirArg: string, domainNameArg: string) => { + plugins.smartfile.fs.ensureDirSync(sslDirArg); + let domainCertFolder = plugins.path.join(paths.certDir, domainNameArg) + if (plugins.smartfile.fs.listFoldersSync(paths.certDir).indexOf(domainNameArg) != -1) { + plugins.smartfile.fs.copySync( + plugins.path.join(domainCertFolder, "fullchain.pem"), + plugins.path.join(sslDirArg, domainNameArg, "fullchain.pem") + ); + plugins.smartfile.fs.copySync( + plugins.path.join(domainCertFolder, "privkey.pem"), + plugins.path.join(sslDirArg, domainNameArg, "privkey.pem") + ); + // create cert config + let certRegex = /.*\-([0-9]*)\.pem/; + let certFileNameWithTime: string = plugins.smartfile.fs.listFilesSync(domainCertFolder, certRegex)[0]; + let certTime = parseInt(certRegex.exec(certFileNameWithTime)[1]); + let certConfig: certConfig = { + domainName: domainNameArg, + created: certTime, + expires: certTime + 7776000 + }; + plugins.smartfile.memory.toFsSync( + JSON.stringify(certConfig), + plugins.path.join(sslDirArg, domainNameArg, "config.json") + ); + }; +} + +const enum gitSyncDirection { + toOrigin, + fromOrigin +} + +let updateGitOrigin = (syncDirectionArg: gitSyncDirection) => { + +}; + +updateGitOrigin(gitSyncDirection.toOrigin); \ No newline at end of file diff --git a/ts/cert.classes.cert.ts b/ts/cert.classes.cert.ts new file mode 100644 index 0000000..d4730d9 --- /dev/null +++ b/ts/cert.classes.cert.ts @@ -0,0 +1,160 @@ +import * as plugins from "./cert.plugins"; +import * as paths from "./cert.paths"; +import * as helpers from "./cert.classes.cert.helpers" + +export interface ICertConstructorOptions { + cfEmail: string, + cfKey: string, + sslDir?: string, + gitOriginRepo?: string, + testMode?: boolean +}; + +export class Cert { + private _cfEmail: string; + private _cfKey: string; + private _sslDir: string; + private _gitOriginRepo: string; + private _testMode: boolean; + domainCertRequestMap: plugins.lik.Stringmap = new plugins.lik.Stringmap(); + certificatesPresent: Certificate[]; + certificatesValid: Certificate[]; + + /** + * Constructor for Cert object + */ + constructor(optionsArg: ICertConstructorOptions) { + this._cfEmail = optionsArg.cfEmail; + this._cfKey = optionsArg.cfKey; + this._sslDir = optionsArg.sslDir; + this._gitOriginRepo = optionsArg.gitOriginRepo; + this._testMode = optionsArg.testMode; + // write hook config + let config = { + cfEmail: this._cfEmail, + cfKey: this._cfKey + } + plugins.smartfile.memory.toFsSync( + JSON.stringify(config), + plugins.path.join(__dirname, "assets/config.json") + ); + // setup sslDir + if (!this._sslDir) this._sslDir = paths.defaultSslDir; + // setup Git + if (this._gitOriginRepo) { + plugins.smartgit.init(this._sslDir); + plugins.smartgit.remote.add(this._sslDir, "origin", this._gitOriginRepo); + this.sslGitOriginPull(); + } + // setup leSh config; + let leShConfigString; + if (this._testMode) { + leShConfigString = `CA="https://acme-staging.api.letsencrypt.org/directory"\n`; + } else { + leShConfigString = " "; + }; + plugins.smartfile.memory.toFsSync( + leShConfigString, + paths.leShConfig + ); + plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh); + plugins.shelljs.exec("chmod 700 " + paths.certHook); + plugins.shelljs.exec( + `bash -c "${paths.letsencryptSh} -c --no-lock -f ${paths.leShConfig} -d notthere.notthere -t dns-01 -k ${paths.certHook} -o ${paths.certDir}"`, + { + silent: true + }); + }; + + /** + * Pulls already requested certificates from git origin + */ + sslGitOriginPull = () => { + if (this._gitOriginRepo) { + plugins.smartgit.pull(this._sslDir, "origin", "master"); + } + }; + + /** + * Pushes all new requested certificates to git origin + */ + sslGitOriginAddCommitPush = () => { + if (this._gitOriginRepo) { + plugins.smartgit.add.addAll(this._sslDir); + plugins.smartgit.commit(this._sslDir, "added new SSL certificates and deleted obsolete ones."); + plugins.smartgit.push(this._sslDir, "origin", "master"); + } + }; + + /** + * gets a ssl cert for a given domain + */ + getDomainCert(domainNameArg: string, optionsArg: { force: boolean } = { force: false }) { + let done = plugins.q.defer(); + let domainStringData = new plugins.smartstring.Domain(domainNameArg); + let sameZoneRequesting: boolean = this.domainCertRequestMap.checkMinimatch("*" + domainStringData.zoneName) + // make sure no one else requires the same domain at the same time + if (!this.domainCertRequestMap.checkString(domainNameArg)) { + this.domainCertRequestMap.addString(domainNameArg); + if (!helpers.checkDomainsStillValid(domainNameArg, this._sslDir) || optionsArg.force) { + if (!sameZoneRequesting) { + plugins.smartfile.fs.ensureDir(paths.certDir); + plugins.beautylog.info(`getting cert for ${domainNameArg}`); + plugins.shelljs.exec( + `bash -c "${paths.letsencryptSh} -c --no-lock -f ${paths.leShConfig} -d ${domainNameArg} -t dns-01 -k ${paths.certHook} -o ${paths.certDir}"`, + { + silent: true + }, + (codeArg, stdoutArg) => { + if (codeArg == 0) { + console.log(stdoutArg); + let fetchedCertsArray: string[] = plugins.smartfile.fs.listFoldersSync(paths.certDir); + if (fetchedCertsArray.indexOf(domainNameArg) != -1) { + helpers.updateSslDirSync(this._sslDir, domainNameArg); + plugins.smartfile.fs.removeSync(plugins.path.join(paths.certDir, domainNameArg)); + }; + done.resolve(); + } else { + plugins.beautylog.warn(`${domainNameArg} scheduled for retry`); + helpers.scheduleRetry(domainNameArg, this).then(done.resolve); + } + this.domainCertRequestMap.removeString(domainNameArg); + } + ); + } else { + plugins.beautylog.info(`${domainNameArg} is waiting for domains names of same zone to finish`); + this.domainCertRequestMap.removeString(domainNameArg); + this.domainCertRequestMap.registerUntilTrue( + () => { + return !this.domainCertRequestMap.checkMinimatch("*" + domainStringData.zoneName); + }, + () => { + this.getDomainCert(domainNameArg).then(done.resolve); + } + ); + } + } else { + plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!"); + this.domainCertRequestMap.removeString(domainNameArg); + done.resolve(); + }; + } else { + plugins.beautylog.warn(`${domainNameArg} is already requesting`); + }; + + return done.promise; + }; + cleanOldCertificates() { + + }; +} + +export class Certificate { + domainName: string; + creationDate: Date; + expiryDate: Date; + constructor() { + + }; +}; + diff --git a/ts/cert.helpers.ts b/ts/cert.helpers.ts deleted file mode 100644 index db9d150..0000000 --- a/ts/cert.helpers.ts +++ /dev/null @@ -1,25 +0,0 @@ -import {Cert} from "./index.ts"; -import * as plugins from "./cert.plugins"; -import * as paths from "./cert.paths"; - -let firstCall = true; -let enoughTime = false; -export let accountsKeyPresent = () => { - let done = plugins.q.defer(); - if (firstCall) { - done.resolve(); - firstCall = false; - }  else { - setTimeout(done.resolve,5000); - }; - return done.promise; -}; - -export let scheduleRetry = (domainArg:string,certClassArg:Cert) => { - let done = plugins.q.defer(); - setTimeout(() => { - certClassArg.getDomainCert(domainArg) - .then(done.resolve); - },20000); - return done.promise; -}; \ No newline at end of file diff --git a/ts/index.ts b/ts/index.ts index 02c565d..6c686ef 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,205 +1,4 @@ import * as plugins from "./cert.plugins"; import * as paths from "./cert.paths"; -import * as helpers from "./cert.helpers" -export interface ICertConstructorOptions { - cfEmail: string, - cfKey: string, - sslDir?: string, - gitOriginRepo?: string, - testMode?: boolean -}; - -export class Cert { - private _cfEmail: string; - private _cfKey: string; - private _sslDir: string; - private _gitOriginRepo: string; - private _testMode: boolean; - domainsCurrentlyRequesting: plugins.lik.Stringmap = new plugins.lik.Stringmap(); - certificatesPresent: Certificate[]; - certificatesValid: Certificate[]; - - /** - * Constructor for Cert object - */ - constructor(optionsArg: ICertConstructorOptions) { - this._cfEmail = optionsArg.cfEmail; - this._cfKey = optionsArg.cfKey; - this._sslDir = optionsArg.sslDir; - this._gitOriginRepo = optionsArg.gitOriginRepo; - this._testMode = optionsArg.testMode; - // write hook config - let config = { - cfEmail: this._cfEmail, - cfKey: this._cfKey - } - plugins.smartfile.memory.toFsSync( - JSON.stringify(config), - plugins.path.join(__dirname, "assets/config.json") - ); - // setup sslDir - if (!this._sslDir) this._sslDir = paths.defaultSslDir; - // setup Git - if (this._gitOriginRepo) { - plugins.smartgit.init(this._sslDir); - plugins.smartgit.remote.add(this._sslDir, "origin", this._gitOriginRepo); - this.sslGitOriginPull(); - } - // setup leSh config; - let leShConfigString; - if (this._testMode) { - leShConfigString = `CA="https://acme-staging.api.letsencrypt.org/directory"\n`; - } else { - leShConfigString = " "; - }; - plugins.smartfile.memory.toFsSync( - leShConfigString, - paths.leShConfig - ); - plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh); - plugins.shelljs.exec("chmod 700 " + paths.certHook); - }; - - /** - * Pulls already requested certificates from git origin - */ - sslGitOriginPull = () => { - if (this._gitOriginRepo) { - plugins.smartgit.pull(this._sslDir, "origin", "master"); - } - }; - - /** - * Pushes all new requested certificates to git origin - */ - sslGitOriginAddCommitPush = () => { - if (this._gitOriginRepo) { - plugins.smartgit.add.addAll(this._sslDir); - plugins.smartgit.commit(this._sslDir, "added new SSL certificates and deleted obsolete ones."); - plugins.smartgit.push(this._sslDir, "origin", "master"); - } - }; - - /** - * gets a ssl cert for a given domain - */ - getDomainCert(domainNameArg: string, optionsArg: { force: boolean } = { force: false }) { - let done = plugins.q.defer(); - // make sure no one else requires the same domain at the same time - helpers.accountsKeyPresent().then(() => { - if (!this.domainsCurrentlyRequesting.checkString(domainNameArg)) { - this.domainsCurrentlyRequesting.addString(domainNameArg); - if (!checkDomainsStillValid(domainNameArg, this._sslDir) || optionsArg.force) { - plugins.smartfile.fs.ensureDir(paths.certDir); - plugins.beautylog.info(`getting cert for ${domainNameArg}`); - plugins.shelljs.exec( - `bash -c "${paths.letsencryptSh} -c --no-lock -f ${paths.leShConfig} -d ${domainNameArg} -t dns-01 -k ${paths.certHook} -o ${paths.certDir}"`, - { - silent: true - }, - (codeArg, stdoutArg) => { - if (codeArg == 0) { - console.log(stdoutArg); - let fetchedCertsArray: string[] = plugins.smartfile.fs.listFoldersSync(paths.certDir); - if (fetchedCertsArray.indexOf(domainNameArg) != -1) { - updateSslDirSync(this._sslDir, domainNameArg); - plugins.smartfile.fs.removeSync(plugins.path.join(paths.certDir, domainNameArg)); - } - this.domainsCurrentlyRequesting.removeString(domainNameArg); - done.resolve(); - } else { - this.domainsCurrentlyRequesting.removeString(domainNameArg); - plugins.beautylog.warn(`${domainNameArg} scheduled for retry`); - helpers.scheduleRetry(domainNameArg,this).then(done.resolve); - } - } - ); - } else { - plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!"); - this.domainsCurrentlyRequesting.removeString(domainNameArg); - done.resolve(); - }; - } else { - plugins.beautylog.warn(`${domainNameArg} is already requesting`); - }; - }); - - return done.promise; - }; - cleanOldCertificates() { - - }; -} - -export class Certificate { - domainName: string; - creationDate: Date; - expiryDate: Date; - constructor() { - - }; -} - -interface certConfig { - domainName: string; - created: number; - expires: number; -} - -let checkDomainsStillValid = (domainNameArg: string, sslDirArg: string): boolean => { - let domainConfigPath = plugins.path.join(sslDirArg, domainNameArg, "config.json"); - if (plugins.smartfile.fs.fileExistsSync(domainConfigPath)) { - let domainConfig = plugins.smartfile.fs.toObjectSync( - domainConfigPath, - "json" - ); - if (Date.now() >= ((domainConfig.expires - 604800) * 1000)) { - return false; - } else { - return true; - } - } else { - return false; - } - -} - -let updateSslDirSync = (sslDirArg: string, domainNameArg: string) => { - plugins.smartfile.fs.ensureDirSync(sslDirArg); - let domainCertFolder = plugins.path.join(paths.certDir, domainNameArg) - if (plugins.smartfile.fs.listFoldersSync(paths.certDir).indexOf(domainNameArg) != -1) { - plugins.smartfile.fs.copySync( - plugins.path.join(domainCertFolder, "fullchain.pem"), - plugins.path.join(sslDirArg, domainNameArg, "fullchain.pem") - ); - plugins.smartfile.fs.copySync( - plugins.path.join(domainCertFolder, "privkey.pem"), - plugins.path.join(sslDirArg, domainNameArg, "privkey.pem") - ); - // create cert config - let certRegex = /.*\-([0-9]*)\.pem/; - let certFileNameWithTime: string = plugins.smartfile.fs.listFilesSync(domainCertFolder, certRegex)[0]; - let certTime = parseInt(certRegex.exec(certFileNameWithTime)[1]); - let certConfig: certConfig = { - domainName: domainNameArg, - created: certTime, - expires: certTime + 7776000 - }; - plugins.smartfile.memory.toFsSync( - JSON.stringify(certConfig), - plugins.path.join(sslDirArg, domainNameArg, "config.json") - ); - }; -} - -const enum gitSyncDirection { - toOrigin, - fromOrigin -} - -let updateGitOrigin = (syncDirectionArg: gitSyncDirection) => { - -}; - -updateGitOrigin(gitSyncDirection.toOrigin); \ No newline at end of file +export * from "./cert.classes.cert"; \ No newline at end of file