smartcert/dist/cert.classes.cert.helpers.js

59 lines
5.3 KiB
JavaScript

"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);
}, 60000);
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,eyJ2ZXJzaW9uIjozLCJmaWxlIj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