2016-06-22 11:22:09 +00:00
|
|
|
import * as plugins from "./cert.plugins";
|
2016-06-18 13:59:03 +00:00
|
|
|
import * as paths from "./cert.paths";
|
|
|
|
|
|
|
|
export class Cert {
|
2016-06-23 01:46:37 +00:00
|
|
|
cfEmail: string;
|
|
|
|
cfKey: string;
|
|
|
|
sslDir: string;
|
2016-06-23 02:37:18 +00:00
|
|
|
certificatesPresent:Certificate[];
|
|
|
|
certificatesValid:Certificate[];
|
2016-06-18 13:59:03 +00:00
|
|
|
gitOriginRepo;
|
2016-06-23 01:46:37 +00:00
|
|
|
constructor(optionsArg: {
|
|
|
|
cfEmail: string,
|
|
|
|
cfKey: string,
|
|
|
|
sslDir: string,
|
|
|
|
gitOriginRepo?: string
|
|
|
|
}) {
|
2016-06-18 13:59:03 +00:00
|
|
|
this.cfEmail = optionsArg.cfEmail;
|
|
|
|
this.cfKey = optionsArg.cfKey;
|
|
|
|
this.sslDir = optionsArg.sslDir;
|
|
|
|
this.gitOriginRepo = optionsArg.gitOriginRepo;
|
2016-06-22 11:22:09 +00:00
|
|
|
let config = {
|
|
|
|
cfEmail: this.cfEmail,
|
|
|
|
cfKey: this.cfKey
|
|
|
|
}
|
2016-06-28 03:53:49 +00:00
|
|
|
plugins.smartfile.memory.toFsSync(JSON.stringify(config),plugins.path.join(__dirname, "assets/config.json"));
|
2016-06-22 11:22:09 +00:00
|
|
|
};
|
2016-06-28 03:53:49 +00:00
|
|
|
getDomainCert(domainNameArg: string,optionsArg?:{force:boolean}) {
|
2016-06-22 11:22:09 +00:00
|
|
|
let done = plugins.q.defer();
|
2016-06-23 01:46:37 +00:00
|
|
|
if (!checkDomainStillValid(domainNameArg) || optionsArg.force) {
|
|
|
|
plugins.shelljs.exec("chmod 700 " + paths.letsencryptSh);
|
|
|
|
plugins.shelljs.exec("chmod 700 " + paths.certHook);
|
2016-06-28 03:53:49 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-06-23 01:46:37 +00:00
|
|
|
done.resolve();
|
|
|
|
} else {
|
|
|
|
plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!");
|
|
|
|
done.resolve();
|
|
|
|
}
|
2016-06-22 11:22:09 +00:00
|
|
|
return done.promise;
|
2016-06-18 13:59:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-28 03:53:49 +00:00
|
|
|
export class Certificate {
|
2016-06-23 01:46:37 +00:00
|
|
|
domainName: string;
|
|
|
|
creationDate: Date;
|
|
|
|
expiryDate: Date;
|
|
|
|
constructor() {
|
2016-06-18 13:59:03 +00:00
|
|
|
|
|
|
|
};
|
2016-06-22 11:55:38 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 01:46:37 +00:00
|
|
|
let checkDomainStillValid = (domainNameArg: string): boolean => {
|
|
|
|
return false;
|
|
|
|
}
|
2016-06-22 11:55:38 +00:00
|
|
|
|
2016-06-28 03:53:49 +00:00
|
|
|
let updateSslDir = (domainNameArg) => {
|
|
|
|
|
2016-06-22 11:55:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let updateGitOrigin = () => {
|
2016-06-23 01:46:37 +00:00
|
|
|
|
2016-06-18 13:59:03 +00:00
|
|
|
}
|