mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-17 05:53:15 +02:00
Implement IP-lookup fallback uris, after cloudflaire downtime
This commit is contained in:
@@ -1182,14 +1182,40 @@
|
|||||||
|
|
||||||
// Fetch and display own external IP for webUI
|
// Fetch and display own external IP for webUI
|
||||||
function displayExternalIP() {
|
function displayExternalIP() {
|
||||||
fetch('https://api.ipify.org?format=json')
|
const target = document.getElementById('external-ip');
|
||||||
.then(res => res.json())
|
if (!target) return;
|
||||||
.then(data => {
|
|
||||||
document.getElementById('external-ip').textContent = data.ip;
|
const providers = [
|
||||||
})
|
{ url: 'https://api.ipify.org?format=json', extract: data => data.ip },
|
||||||
.catch(() => {
|
{ url: 'https://ipapi.co/json/', extract: data => data && (data.ip || data.ip_address) },
|
||||||
document.getElementById('external-ip').textContent = 'Unavailable';
|
{ url: 'https://ipv4.jsonip.com/', extract: data => data.ip }
|
||||||
});
|
];
|
||||||
|
|
||||||
|
const tryProvider = (index) => {
|
||||||
|
if (index >= providers.length) {
|
||||||
|
target.textContent = 'Unavailable';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const provider = providers[index];
|
||||||
|
fetch(provider.url, { headers: { 'Accept': 'application/json' } })
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
const ip = provider.extract(data);
|
||||||
|
if (ip) {
|
||||||
|
target.textContent = ip;
|
||||||
|
} else {
|
||||||
|
throw new Error('Missing IP');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
tryProvider(index + 1);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
tryProvider(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to initialize tooltips
|
// Function to initialize tooltips
|
||||||
|
|||||||
Reference in New Issue
Block a user