smartcert/dist/index.js

72 lines
11 KiB
JavaScript

"use strict";
var plugins = require("./cert.plugins");
var paths = require("./cert.paths");
var Cert = (function () {
function Cert(optionsArg) {
this._cfEmail = optionsArg.cfEmail;
this._cfKey = optionsArg.cfKey;
this._sslDir = optionsArg.sslDir;
this.gitOriginRepo = optionsArg.gitOriginRepo;
var config = {
cfEmail: this._cfEmail,
cfKey: this._cfKey
};
plugins.smartfile.memory.toFsSync(JSON.stringify(config), plugins.path.join(__dirname, "assets/config.json"));
}
;
Cert.prototype.getDomainCert = function (domainNameArg, optionsArg) {
var done = plugins.q.defer();
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 + "\"");
var fetchedCertsArray = plugins.smartfile.fs.listFoldersSync(paths.certDir);
if (fetchedCertsArray.indexOf(domainNameArg) != -1) {
updateSslDirSync(this._sslDir, domainNameArg);
}
done.resolve();
}
else {
plugins.beautylog.info("certificate for " + domainNameArg + " is still valid! Not fetching new one!");
done.resolve();
}
return done.promise;
};
;
return Cert;
}());
exports.Cert = Cert;
var Certificate = (function () {
function Certificate() {
}
;
return Certificate;
}());
exports.Certificate = Certificate;
var checkDomainsStillValid = function (domainNameArg) {
return false;
};
var updateSslDirSync = function (sslDirArg, domainNameArg) {
plugins.smartfile.fs.ensureDirSync(sslDirArg);
var 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
var certRegex = /.*\-([0-9]*)\.pem/;
var certFileNameWithTime = plugins.smartfile.fs.listFilesSync(domainCertFolder, certRegex)[0];
var certTime = parseInt(certRegex.exec(certFileNameWithTime)[1]);
var certConfig = {
domainName: domainNameArg,
created: certTime,
expires: certTime + 7776000
};
plugins.smartfile.memory.toFs(JSON.stringify(certConfig), plugins.path.join(sslDirArg, domainNameArg, "config.json"));
}
;
};
var updateGitOrigin = function () {
};
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFZLE9BQU8sV0FBTSxnQkFBZ0IsQ0FBQyxDQUFBO0FBQzFDLElBQVksS0FBSyxXQUFNLGNBQWMsQ0FBQyxDQUFBO0FBRXRDO0lBT0ksY0FBWSxVQUtYO1FBQ0csSUFBSSxDQUFDLFFBQVEsR0FBRyxVQUFVLENBQUMsT0FBTyxDQUFDO1FBQ25DLElBQUksQ0FBQyxNQUFNLEdBQUcsVUFBVSxDQUFDLEtBQUssQ0FBQztRQUMvQixJQUFJLENBQUMsT0FBTyxHQUFHLFVBQVUsQ0FBQyxNQUFNLENBQUM7UUFDakMsSUFBSSxDQUFDLGFBQWEsR0FBRyxVQUFVLENBQUMsYUFBYSxDQUFDO1FBQzlDLElBQUksTUFBTSxHQUFHO1lBQ1QsT0FBTyxFQUFFLElBQUksQ0FBQyxRQUFRO1lBQ3RCLEtBQUssRUFBRSxJQUFJLENBQUMsTUFBTTtTQUNyQixDQUFBO1FBQ0QsT0FBTyxDQUFDLFNBQVMsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDLEVBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFFLG9CQUFvQixDQUFDLENBQUMsQ0FBQztJQUNqSCxDQUFDOzt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WUsXG4gICAgICAgICAgICBleHBpcmVzOiBjZXJ0VGltZSArIDc3NzYwMDBcbiAgICAgICAgfTtcbiAgICAgICAgcGx1Z2lucy5zbWFydGZpbGUubWVtb3J5LnRvRnMoXG4gICAgICAgICAgICBKU09OLnN0cmluZ2lmeShjZXJ0Q29uZmlnKSxcbiAgICAgICAgICAgIHBsdWdpbnMucGF0aC5qb2luKHNzbERpckFyZyxkb21haW5OYW1lQXJnLFwiY29uZmlnLmpzb25cIilcbiAgICAgICAgKTtcbiAgICB9O1xufVxuXG5sZXQgdXBkYXRlR2l0T3JpZ2luID0gKCkgPT4ge1xuXG59Il19