diff --git a/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php b/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php index d21fb92..06a5483 100644 --- a/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php +++ b/Plugin/usr/local/emhttp/plugins/varaverk/include/monitor.php @@ -202,34 +202,26 @@ function vv_network_stats(): array { $speedMbps = (int)@file_get_contents("/sys/class/net/$iface/speed"); - // Local IP — use the NIC defined in HOST*_SYS_WATCHDOG_NIC, fall back to primary iface - $vars = vv_conf_vars(); - $host = vv_detect_host(); - $prefix = $host !== 'unknown' ? strtoupper($host) . '_' : 'HOST1_'; - $nic = $vars[$prefix . 'SYS_WATCHDOG_NIC'] ?? $iface; + // Local IP — use primary iface $localIp = trim(shell_exec( - "ip -4 addr show " . escapeshellarg($nic) . " 2>/dev/null | awk '/inet /{print \$2}' | cut -d/ -f1 | head -1" + "ip -4 addr show " . escapeshellarg($iface) . " 2>/dev/null | awk '/inet /{print \$2}' | cut -d/ -f1 | head -1" ) ?: ''); - // External IP — resolve DDNS domain from conf (no external HTTP; DDNS keeps it current) - $ddnsDomain = $vars[$prefix . 'NETWORK_WATCHDOG_DDNS_DOMAIN'] ?? ''; + // External IP — curl ifconfig.me, cached 5 min so we don't hammer it + $extIpCache = '/tmp/vv_ext_ip.cache'; $extIp = ''; - if ($ddnsDomain) { - $extIpCache = '/tmp/vv_ext_ip.cache'; - if (file_exists($extIpCache) && (time() - filemtime($extIpCache)) < 300) { - $extIp = trim(file_get_contents($extIpCache) ?: ''); - } else { - $resolved = trim(shell_exec( - "dig +short " . escapeshellarg($ddnsDomain) . " @1.1.1.1 2>/dev/null | grep -Eo '[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+' | head -1" - ) ?: ''); - if ($resolved) { $extIp = $resolved; file_put_contents($extIpCache, $extIp); } + if (file_exists($extIpCache) && (time() - filemtime($extIpCache)) < 300) { + $extIp = trim(file_get_contents($extIpCache) ?: ''); + } else { + $fetched = trim(shell_exec('curl -sf --max-time 4 https://ifconfig.me 2>/dev/null') ?: ''); + if (preg_match('/^\d+\.\d+\.\d+\.\d+$/', $fetched)) { + $extIp = $fetched; + file_put_contents($extIpCache, $extIp); } } - // Tailscale IP — read from tailscale0 interface - $tsIp = trim(shell_exec( - "ip -4 addr show tailscale0 2>/dev/null | awk '/inet /{print \$2}' | cut -d/ -f1 | head -1" - ) ?: ''); + // Tailscale IP — use `tailscale ip` CLI (interface name varies: tailscale0, tailscale1, etc.) + $tsIp = trim(shell_exec('tailscale ip -4 2>/dev/null | head -1') ?: ''); return [ 'available' => true,