now has sslDir implemented
This commit is contained in:
56
ts/index.ts
56
ts/index.ts
@ -2,9 +2,9 @@ import * as plugins from "./cert.plugins";
|
||||
import * as paths from "./cert.paths";
|
||||
|
||||
export class Cert {
|
||||
cfEmail: string;
|
||||
cfKey: string;
|
||||
sslDir: string;
|
||||
private _cfEmail: string;
|
||||
private _cfKey: string;
|
||||
private _sslDir: string;
|
||||
certificatesPresent:Certificate[];
|
||||
certificatesValid:Certificate[];
|
||||
gitOriginRepo;
|
||||
@ -14,25 +14,25 @@ export class Cert {
|
||||
sslDir: string,
|
||||
gitOriginRepo?: string
|
||||
}) {
|
||||
this.cfEmail = optionsArg.cfEmail;
|
||||
this.cfKey = optionsArg.cfKey;
|
||||
this.sslDir = optionsArg.sslDir;
|
||||
this._cfEmail = optionsArg.cfEmail;
|
||||
this._cfKey = optionsArg.cfKey;
|
||||
this._sslDir = optionsArg.sslDir;
|
||||
this.gitOriginRepo = optionsArg.gitOriginRepo;
|
||||
let config = {
|
||||
cfEmail: this.cfEmail,
|
||||
cfKey: this.cfKey
|
||||
cfEmail: this._cfEmail,
|
||||
cfKey: this._cfKey
|
||||
}
|
||||
plugins.smartfile.memory.toFsSync(JSON.stringify(config),plugins.path.join(__dirname, "assets/config.json"));
|
||||
};
|
||||
getDomainCert(domainNameArg: string,optionsArg?:{force:boolean}) {
|
||||
let done = plugins.q.defer();
|
||||
if (!checkDomainStillValid(domainNameArg) || optionsArg.force) {
|
||||
if (!checkDomainsStillValid(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.certDir + "\"");
|
||||
let fetchedCertsArray:string[] = plugins.smartfile.fs.listFoldersSync(paths.certDir);
|
||||
if(fetchedCertsArray.indexOf(domainNameArg) != -1){
|
||||
updateSslDir(domainNameArg);
|
||||
updateSslDirSync(this._sslDir,domainNameArg);
|
||||
}
|
||||
done.resolve();
|
||||
} else {
|
||||
@ -52,12 +52,42 @@ export class Certificate {
|
||||
};
|
||||
}
|
||||
|
||||
let checkDomainStillValid = (domainNameArg: string): boolean => {
|
||||
interface certConfig {
|
||||
domainName:string;
|
||||
created:number;
|
||||
expires:number;
|
||||
}
|
||||
|
||||
let checkDomainsStillValid = (domainNameArg: string): boolean => {
|
||||
return false;
|
||||
}
|
||||
|
||||
let updateSslDir = (domainNameArg) => {
|
||||
|
||||
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 = plugins.smartfile.fs.listFilesSync(domainCertFolder,certRegex)[1];
|
||||
let certTime = parseInt(certRegex.exec(certFileNameWithTime)[1]);
|
||||
let certConfig:certConfig = {
|
||||
domainName: domainNameArg,
|
||||
created: certTime,
|
||||
expires: certTime + 7776000
|
||||
};
|
||||
plugins.smartfile.memory.toFs(
|
||||
JSON.stringify(certConfig),
|
||||
plugins.path.join(sslDirArg,domainNameArg,"config.json")
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
let updateGitOrigin = () => {
|
||||
|
Reference in New Issue
Block a user