Merge pull request #101 from theta42/model-redis
Fixed issue with matching wild card
This commit is contained in:
@@ -313,6 +313,23 @@ curl -H "auth-token: your-token-here" \
|
|||||||
- `200` `{"message": "example.com deleted", ...}`
|
- `200` `{"message": "example.com deleted", ...}`
|
||||||
- `404` `{"name": "HostNotFound", "message": "Host does not exists"}`
|
- `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
|
### Renew Wildcard Certificate
|
||||||
|
|
||||||
**PUT** `/api/host/:host/renew`
|
**PUT** `/api/host/:host/renew`
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ class Host extends Table{
|
|||||||
let out = await super.remove(...args);
|
let out = await super.remove(...args);
|
||||||
await Host.buildLookUpObj();
|
await Host.buildLookUpObj();
|
||||||
await this.bustCache(this.host);
|
await this.bustCache(this.host);
|
||||||
await deleteCert(this.host);
|
await deleteCert(this.domain);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
} catch(error){
|
} catch(error){
|
||||||
@@ -345,8 +345,12 @@ class Host extends Table{
|
|||||||
// Hold the last passed long wild card.
|
// Hold the last passed long wild card.
|
||||||
let last_resort = {};
|
let last_resort = {};
|
||||||
|
|
||||||
|
// Hold the parent element
|
||||||
|
let parent = undefined;
|
||||||
|
|
||||||
// Walk over each fragment of the host, from right to left
|
// Walk over each fragment of the host, from right to left
|
||||||
for(let fragment of host.split('.').reverse()){
|
for(let fragment of host.split('.').reverse()){
|
||||||
|
parent = place;
|
||||||
|
|
||||||
// If a long wild card is found on this level, hold on to it
|
// If a long wild card is found on this level, hold on to it
|
||||||
if(place['**']) last_resort = place['**'];
|
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.
|
// After the tree has been traversed, see if we have leaf node to return.
|
||||||
if(place && place['#record']) return place['#record'];
|
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(){
|
static async lookUpReady(){
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ app.host = (function(app){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearCache(callack){
|
||||||
|
app.api.delete('host/cache', function(error, data){
|
||||||
|
callack(error, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getCert,
|
getCert,
|
||||||
list: list,
|
list: list,
|
||||||
@@ -42,5 +48,6 @@ app.host = (function(app){
|
|||||||
add: add,
|
add: add,
|
||||||
edit: edit,
|
edit: edit,
|
||||||
remove: remove,
|
remove: remove,
|
||||||
|
clearCache: clearCache,
|
||||||
}
|
}
|
||||||
})(app);
|
})(app);
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ function formAJAX(btn){
|
|||||||
var method = ($form.attr('method') || 'post').toLowerCase();
|
var method = ($form.attr('method') || 'post').toLowerCase();
|
||||||
|
|
||||||
if($form.validate && !$form.validate()){
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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){
|
router.get('/:item', async function(req, res, next){
|
||||||
try{
|
try{
|
||||||
|
|
||||||
|
|||||||
@@ -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){
|
async function hostMatchWildcard(host){
|
||||||
try{
|
try{
|
||||||
let res = await app.api.get(`host/lookup/${host}`);
|
let res = await app.api.get(`host/lookup/${host}`);
|
||||||
@@ -446,6 +458,10 @@
|
|||||||
Proxy List
|
Proxy List
|
||||||
</span>
|
</span>
|
||||||
<span class="float-end">
|
<span class="float-end">
|
||||||
|
<button type="button" class="btn btn-sm btn-outline-secondary me-2" onclick="hostClearCache(this)" title="Clear cached wildcard subdomain lookups">
|
||||||
|
<i class="fa-solid fa-broom"></i>
|
||||||
|
Clear Cache
|
||||||
|
</button>
|
||||||
<i class="fa-solid fa-circle-minus"></i>
|
<i class="fa-solid fa-circle-minus"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user