From 56c2fb1a5c3dfc19a0125a1f47490e2d0d7df2f5 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Fri, 10 Jul 2026 00:13:40 -0400 Subject: [PATCH] Fixed issue with matching wild card --- nodejs/api.md | 17 +++++++++++++++++ nodejs/models/host.js | 9 ++++++++- nodejs/public/js/app.js | 7 +++++++ nodejs/public/lib/js/app-base.js | 2 +- nodejs/routes/host.js | 13 +++++++++++++ nodejs/views/hosts.ejs | 16 ++++++++++++++++ 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/nodejs/api.md b/nodejs/api.md index f354ec4..faa69e7 100755 --- a/nodejs/api.md +++ b/nodejs/api.md @@ -313,6 +313,23 @@ curl -H "auth-token: your-token-here" \ - `200` `{"message": "example.com deleted", ...}` - `404` `{"name": "HostNotFound", "message": "Host does not exists"}` +### Clear Host Cache + +**DELETE** `/api/host/cache` + +Remove all cached wildcard-subdomain host lookups. Cache entries are created on +demand when a wildcard host serves a subdomain; clearing them forces the next +request for each subdomain to be resolved fresh through the lookup tree. + +```bash +curl -H "auth-token: your-token-here" \ + -X DELETE \ + https://proxy-host.com/api/host/cache +``` + +**Responses:** +- `200` `{"message": "Cleared 3 cached hosts.", "count": 3}` + ### Renew Wildcard Certificate **PUT** `/api/host/:host/renew` diff --git a/nodejs/models/host.js b/nodejs/models/host.js index ed1fc1e..0391fe9 100755 --- a/nodejs/models/host.js +++ b/nodejs/models/host.js @@ -276,7 +276,7 @@ class Host extends Table{ let out = await super.remove(...args); await Host.buildLookUpObj(); await this.bustCache(this.host); - await deleteCert(this.host); + await deleteCert(this.domain); return out; } catch(error){ @@ -345,8 +345,12 @@ class Host extends Table{ // Hold the last passed long wild card. let last_resort = {}; + // Hold the parent element + let parent = undefined; + // Walk over each fragment of the host, from right to left for(let fragment of host.split('.').reverse()){ + parent = place; // If a long wild card is found on this level, hold on to it if(place['**']) last_resort = place['**']; @@ -366,6 +370,9 @@ class Host extends Table{ // After the tree has been traversed, see if we have leaf node to return. if(place && place['#record']) return place['#record']; + + // If the parent has a wild, its the wildcard we want. + if(parent && parent['*']['#record']) return parent['*']['#record']; } static async lookUpReady(){ diff --git a/nodejs/public/js/app.js b/nodejs/public/js/app.js index a733b4c..db2d79f 100755 --- a/nodejs/public/js/app.js +++ b/nodejs/public/js/app.js @@ -35,6 +35,12 @@ app.host = (function(app){ }); } + function clearCache(callack){ + app.api.delete('host/cache', function(error, data){ + callack(error, data); + }); + } + return { getCert, list: list, @@ -42,5 +48,6 @@ app.host = (function(app){ add: add, edit: edit, remove: remove, + clearCache: clearCache, } })(app); diff --git a/nodejs/public/lib/js/app-base.js b/nodejs/public/lib/js/app-base.js index 517eb07..ba4880d 100644 --- a/nodejs/public/lib/js/app-base.js +++ b/nodejs/public/lib/js/app-base.js @@ -415,7 +415,7 @@ function formAJAX(btn){ var method = ($form.attr('method') || 'post').toLowerCase(); if($form.validate && !$form.validate()){ - app.util.actionMessage('Please fix the form errors.', $form, 'danger') + app.util.actionMessage('Please fix the form errors.', $form, 'danger'); return false; } diff --git a/nodejs/routes/host.js b/nodejs/routes/host.js index af6ea33..1d6e86c 100755 --- a/nodejs/routes/host.js +++ b/nodejs/routes/host.js @@ -52,6 +52,19 @@ router.get('/lookupobj', async function(req, res, next){ } }); +router.delete('/cache', async function(req, res, next){ + try{ + let count = await Model.clearCache(); + + return res.json({ + message: `Cleared ${count} cached host${count === 1 ? '' : 's'}.`, + count, + }); + }catch(error){ + return next(error); + } +}); + router.get('/:item', async function(req, res, next){ try{ diff --git a/nodejs/views/hosts.ejs b/nodejs/views/hosts.ejs index fc061ed..8d97cca 100755 --- a/nodejs/views/hosts.ejs +++ b/nodejs/views/hosts.ejs @@ -148,6 +148,18 @@ } } + function hostClearCache(btn){ + let $btn = $(btn); + $btn.prop('disabled', true); + app.host.clearCache(function(error, data){ + $btn.prop('disabled', false); + if(error){ + return app.util.actionMessage(error.message || error, $.scope.hosts.$this, 'danger'); + } + app.util.actionMessage(data.message, $.scope.hosts.$this, 'success'); + }); + } + async function hostMatchWildcard(host){ try{ let res = await app.api.get(`host/lookup/${host}`); @@ -446,6 +458,10 @@ Proxy List +