Fix AGENT button showing the wrong machine: same-subnet fallback matched whichever agent happened to be first in the list, not the actual browsing machine — happens whenever a LAN client hits the dashboard via hairpin NAT/external hostname and the server sees the same reflected IP for every visitor. Exact-match only now; falls through to not-detected instead of misreporting another real machine as yours.

This commit is contained in:
root
2026-07-07 12:41:53 -05:00
parent b5c47d898b
commit 185d2c889f
+11 -4
View File
@@ -1631,11 +1631,18 @@ async function checkAgentStatus() {
sta.textContent = online.length > 0 ? online.length + ' ONLINE' : 'NONE'; sta.textContent = online.length > 0 ? online.length + ' ONLINE' : 'NONE';
const cnt = document.getElementById('net-agent-count'); const cnt = document.getElementById('net-agent-count');
if (cnt) cnt.textContent = online.length + ' AGENT' + (online.length !== 1 ? 'S' : '') + ' ONLINE'; if (cnt) cnt.textContent = online.length + ' AGENT' + (online.length !== 1 ? 'S' : '') + ' ONLINE';
// Fixed 2026-07-07: this used to fall back to "any agent on the same /24
// subnet" when the exact IP didn't match, meant to handle NAT — but when
// a LAN client hits the dashboard via its external hostname (hairpin NAT,
// or through Cloudflare), the server sees the SAME single reflected/proxy
// IP for every visitor on the LAN, not each machine's real one. The exact
// match then always fails, and the subnet fallback just grabbed whichever
// agent happened to be first in the list — showing a *different real
// machine* as "yours", not a harmless guess. Exact match only now; if it
// fails, the button correctly falls through to "not detected" instead of
// reporting someone else's agent as this one.
const myIp = data.my_ip || ''; const myIp = data.my_ip || '';
// Match by exact IP first, then by same /24 subnet (handles NAT behind same router) _myAgent = online.find(a => a.ip_address === myIp) || null;
const mySubnet = myIp.split('.').slice(0,3).join('.');
_myAgent = online.find(a => a.ip_address === myIp)
|| online.find(a => a.ip_address && a.ip_address.startsWith(mySubnet + '.'));
_agentOnline = !!_myAgent; _agentOnline = !!_myAgent;
if (btn) { if (btn) {
const isTablet = detectOS() === 'tablet'; const isTablet = detectOS() === 'tablet';