Skip to content

Commit

Permalink
feat: host contains sert and key
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Jan 6, 2024
1 parent 574718b commit 11380ac
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,28 @@ class CoCreateAcme {
if (!organization.host || !organization.host.includes(host))
return false

let safeKey = host.replace(/\./g, '_');
if (organization.ssl && organization.ssl[safeKey]) {
let cert = organization.ssl[safeKey].cert
let key = organization.ssl[safeKey].key
if (cert && key) {
let expires = await forge.readCertificateInfo(cert);
expires = expires.notAfter;
if (this.isValid(expires)) {
this.setCertificate(host, expires, organization_id)
if (!fs.existsSync(hostKeyPath)) {
fs.mkdirSync(hostKeyPath, { recursive: true });
if (organization.host) {
for (let i = 0; i < host; i++) {
if (organization.host[i].name === hostname) {
if (organization.host[i].cert && organization.host[i].key) {
let expires = await forge.readCertificateInfo(organization.host[i].cert);
expires = expires.notAfter;
if (this.isValid(expires)) {
this.setCertificate(host, expires, organization_id)
if (!fs.existsSync(hostKeyPath)) {
fs.mkdirSync(hostKeyPath, { recursive: true });
}

fs.writeFileSync(hostKeyPath + 'fullchain.pem', organization.host[i].cert);
// fs.chmodSync(keyPath + 'fullchain.pem', '444')
fs.writeFileSync(hostKeyPath + 'private-key.pem', organization.host[i].key);
// fs.chmodSync(keyPath + 'private-key.pem', '400')

this.proxy.createServer(host)
return true
}
}

fs.writeFileSync(hostKeyPath + 'fullchain.pem', cert);
// fs.chmodSync(keyPath + 'fullchain.pem', '444')
fs.writeFileSync(hostKeyPath + 'private-key.pem', key);
// fs.chmodSync(keyPath + 'private-key.pem', '400')

this.proxy.createServer(host)
return true
break
}
}
}
Expand Down

0 comments on commit 11380ac

Please sign in to comment.