Status check improvement

This commit is contained in:
2025-11-11 15:25:34 +01:00
parent a2a37b7e6c
commit 570d527309

View File

@@ -22,7 +22,6 @@ auth_require();
Tor Relay Panel
</span>
<div class="ms-auto d-flex align-items-center gap-2">
<!-- NEW: Tor Log button -->
<button id="btnTorLog" class="btn btn-sm btn-outline-light">View Tor Log</button>
<button id="btnTheme" class="btn btn-sm btn-outline-light">Theme</button>
<a class="btn btn-sm btn-outline-light" href="/logout.php">Logout</a>
@@ -391,10 +390,13 @@ async function refreshChart(){
setChartData(labels, rx, tx);
}
async function loadReach(){
const r = await fetch('api/reach.php');
try{
const r = await fetch('api/reach.php', {cache:'no-store'});
const j = await r.json();
if (!j.ok) return;
if (!j.ok) return false;
if (el.reachNick) el.reachNick.textContent = j.nickname || '—';
if (el.reachFP) el.reachFP.textContent = j.fingerprint || '—';
if (el.reachPort) el.reachPort.textContent = j.orport || '—';
@@ -409,11 +411,20 @@ async function loadReach(){
if (j.onionoo.last_seen) seenStr = 'Last seen: ' + new Date(j.onionoo.last_seen).toLocaleString();
}
const running = !!(j.onionoo && j.onionoo.running);
if (el.reachBadge){
el.reachBadge.textContent = running ? 'Running (publicly reachable)' : (j.onionoo && j.onionoo.found ? 'Not Running yet' : 'Not in consensus yet');
el.reachBadge.className = 'badge ' + (running ? 'bg-success' : (j.onionoo && j.onionoo.found ? 'bg-warning' : 'bg-danger'));
el.reachBadge.title = 'Last checked: ' + new Date().toLocaleString();
}
if (el.reachFlags) el.reachFlags.textContent = flagStr;
if (el.reachSeen) el.reachSeen.textContent = seenStr;
if (el.reachHelp) el.reachHelp.style.display = running ? 'none' : 'block';
return running;
}catch(e){
return false;
}
}
if (el.btnEditCfg){
@@ -454,6 +465,26 @@ if (el.cfgForm){
});
}
if (el.reachRefresh){
el.reachRefresh.addEventListener('click', async ()=>{
const btn = el.reachRefresh;
const originalClasses = btn.className;
btn.disabled = true;
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-1" role="status" aria-hidden="true"></span>Checking…';
const running = await loadReach();
btn.className = running ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger';
btn.innerHTML = running ? 'Reachable ✓' : 'Not reachable ✗';
setTimeout(()=>{
btn.className = originalClasses;
btn.innerHTML = 'Check status';
btn.disabled = false;
}, 1500);
});
}
(function initTheme(){
const t = preferredTheme();
document.documentElement.setAttribute('data-theme', t);