Skip to content

Commit

Permalink
Make ssl wildcard easier
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Nov 11, 2024
1 parent 38b601b commit 7613a77
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "domcloud-bridge",
"version": "0.68.0",
"version": "0.69.0",
"description": "Deployment runner for DOM Cloud",
"main": "app.js",
"engines": {
Expand Down
37 changes: 28 additions & 9 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import path from 'path';
import path, { dirname } from 'path';
import { spawn } from 'child_process';
import { lock } from 'proper-lockfile';
import fs from 'fs';
import binaries from './binaries/metadata.cjs';
import { virtualminExec } from './executor/virtualmin';
const {
javaVersionsList,
javaVersionsMap,
Expand All @@ -16,7 +17,7 @@ let tokenSecret, allowIps, sudoutil, version, revision;
// https://packagist.org/php-statistics
let phpVersionsList = [];
/**
* @type {Record<string, string>}
* @type {Record<string, {domain: string, id: string, path: string}>}
*/
let sslWildcardsMap = {};

Expand All @@ -31,13 +32,6 @@ export const initUtils = () => {
const rev = cat('.git/HEAD').trim();
revision = rev.indexOf(':') === -1 ? rev : cat('.git/' + rev.substring(5)).trim();
revision = revision.substring(0, 7);
sslWildcardsMap = (process.env.SSL_WILDCARDS || '').split(',').reduce((a, b) => {
var splits = b.split(':', 2);
if (splits.length == 2) {
a[splits[0].toLowerCase()] = splits[1];
}
return a;
}, {});
try {
const phpPath = process.env.PHPFPM_REMILIST || '/etc/opt/remi/';
const phpFiles = fs.readdirSync(phpPath, { withFileTypes: true });
Expand All @@ -48,7 +42,32 @@ export const initUtils = () => {
} catch (error) {
phpVersionsList = [];
}
updateWildcardData();
}

async function updateWildcardData() {
sslWildcardsMap = {};
var cachepath = path.join(process.cwd(), '/.tmp/wildcardssl.json');
try {
sslWildcardsMap = JSON.parse(cat(cachepath));
for (const domain of (process.env.SSL_WILDCARDS || '').split(',')) {
if (!(domain in sslWildcardsMap) || ['id', 'domain', 'path'].every(k => !(k in sslWildcardsMap[domain]))) {
throw new Error();
}
}
return
} catch (error) {

}
const domains = (process.env.SSL_WILDCARDS || '').split(',').map(x => x.split(':')[0]);
for (const [domain, d] of Object.entries(await virtualminExec.getDomainInfo(domains, true))) {
sslWildcardsMap[domain] = {
id: d['ID'] + '',
path: dirname(d['SSL key file'] + ''),
domain,
}
}
writeTo(cachepath, JSON.stringify(sslWildcardsMap))
}

export const getLtsPhp = (/** @type {string} */ major) => {
Expand Down

0 comments on commit 7613a77

Please sign in to comment.