This commit is contained in:
2026-02-25 19:17:25 -05:00
parent 74b8f1113e
commit 585aa14c0b
5 changed files with 85 additions and 30 deletions
+9
View File
@@ -14,5 +14,14 @@ module.exports = {
socketFile: '/var/run/proxy_lookup.socket', socketFile: '/var/run/proxy_lookup.socket',
redis: { redis: {
prefix: 'proxy_' prefix: 'proxy_'
},
service:{
hostScheduler:{
enabled: true,
initial: 30000,
interval: 86400000,
} }
},
}; };
+23
View File
@@ -0,0 +1,23 @@
'use strict';
// Using https://github.com/simpleworkjs/conf to handle configuration
module.exports = {
userModel: 'redis', // pam, redis, ldap
ldap: {
url: 'ldap://192.168.1.55:389',
bindDN: 'cn=ldapclient service,ou=people,dc=theta42,dc=com',
bindPassword: '__IN SRECREST FILE__',
searchBase: 'ou=people,dc=theta42,dc=com',
userFilter: '(objectClass=inetOrgPerson)',
userNameAttribute: 'uid'
},
socketFile: '/var/run/proxy_lookup.socket',
redis: {
prefix: 'proxy_'
},
service:{
hostScheduler:{
enabled: false,
}
},
};
+18 -2
View File
@@ -82,8 +82,15 @@ class Host extends Table{
static async create(data, ...args){ static async create(data, ...args){
try{ try{
console.log('host create data', data.challengeType, data.challengeType === 'DNS-01-wildcard')
// Validate requested host is valid host and domain // Validate requested host is valid host and domain
if(data.challengeType === 'DNS-01-wildcard') await this.validateWildcardCreate(data, args); if(data.challengeType === 'DNS-01-wildcard'){
data.is_wildcard = true;
data.wildcard_status = "Starting"
await this.validateWildcardCreate(data, args);
}
// Validate requested host has a valid wildcard parent // Validate requested host has a valid wildcard parent
if(data.challengeType === 'wildcardChild'){ if(data.challengeType === 'wildcardChild'){
@@ -96,24 +103,31 @@ class Host extends Table{
} }
} }
console.log('Host create here 102')
// Create the new host entry // Create the new host entry
let out = await super.create(data, ...args); let out = await super.create(data, ...args);
console.log('Host create here 106')
// Update the lookup table to reflect new host // Update the lookup table to reflect new host
await this.buildLookUpObj(); await this.buildLookUpObj();
console.log('Host create here 111')
// Fire the request for the wild card cert // Fire the request for the wild card cert
// This is "back ground" job, await is intentionally missing // This is "back ground" job, await is intentionally missing
if(out.challengeType === 'DNS-01-wildcard') out.createWildcardCert(); if(data.challengeType === 'DNS-01-wildcard') out.createWildcardCert();
console.log('Host create here 111')
return out; return out;
} catch(error){ } catch(error){
console.log(error)
throw error; throw error;
} }
} }
static async validateWildcardCreate(data, ...args){ static async validateWildcardCreate(data, ...args){
console.log('validateWildcardCreate here')
try{ try{
if(!data.host.startsWith('*.')) throw new Error('not wild card'); if(!data.host.startsWith('*.')) throw new Error('not wild card');
await Domain.get(data.host); await Domain.get(data.host);
@@ -125,9 +139,11 @@ class Host extends Table{
} }
async createWildcardCert(){ async createWildcardCert(){
console.log('createWildcardCert here')
if(!this.host.startsWith('*.')) throw new Error('not wild card'); if(!this.host.startsWith('*.')) throw new Error('not wild card');
try{ try{
console.log('createWildcardCert here in try')
let host = this; let host = this;
await host.update({ await host.update({
+16 -9
View File
@@ -1,8 +1,11 @@
'use strict'; 'use strict';
const conf = require('@simpleworkjs/conf');
const {Host} = require('../models/host'); const {Host} = require('../models/host');
/**
function hostSchedulerService(){
/**
* Host Scheduler Service * Host Scheduler Service
* *
* Manages scheduled tasks for host-related operations: * Manages scheduled tasks for host-related operations:
@@ -18,15 +21,19 @@ const {Host} = require('../models/host');
* - Automatically renews certificates that are approaching expiration * - Automatically renews certificates that are approaching expiration
*/ */
// Initial wildcard cert check 30 seconds after app starts // Initial wildcard cert check 30 seconds after app starts
// Delay allows the system to fully initialize before checking certs // Delay allows the system to fully initialize before checking certs
// setTimeout(Host.checkWildcardForRenew.bind(Host), 30000); setTimeout(Host.checkWildcardForRenew.bind(Host), conf.service.hostScheduler.initial);
// Check wildcard certs once every 24 hours // Check wildcard certs once every 24 hours
// Ensures certificates are renewed well before expiration // Ensures certificates are renewed well before expiration
setInterval(Host.checkWildcardForRenew.bind(Host), 86400000); setInterval(Host.checkWildcardForRenew.bind(Host), conf.service.hostScheduler.interval);
console.log('Host scheduler service initialized');
console.log('- Wildcard cert check: 30s after start, then every 24h');
}
if(conf.service.hostScheduler.enabled !== false) hostSchedulerService();
console.log('Host scheduler service initialized');
console.log('- Wildcard cert check: 30s after start, then every 24h');
module.exports = {}; module.exports = {};
+4 -4
View File
@@ -38,16 +38,16 @@ function ModelPs(model){
publish(propKey, res, ...args); publish(propKey, res, ...args);
}).catch(function(error){ }).catch(function(error){
// console.error("Error PS", model.name, propKey, error) console.error("Error async PS", model.name, propKey, error)
console.log('toDo, publish errors...'); // console.log('toDo, publish errors...');
}); });
}else{ }else{
publish(propKey, res, ...args); publish(propKey, res, ...args);
} }
return res; return res;
}catch(error){ }catch(error){
// console.error("Error PS", model.name, propKey, error) console.error("Error PS", model.name, propKey, error)
console.log("toDo, publish errors..."); // console.log("toDo, publish errors...");
} }
} }
} else { } else {