From a4bccc765cc439cc5dc7b65a81344c34b690bbdb Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Tue, 4 Aug 2026 02:40:33 +0530 Subject: [PATCH] fix: show server IP address in Network field instead of "Unavailable" Three-level fallback chain: 1. gethostbyname(gethostname()) - PHP built-in, works on Linux and Windows 2. ip -4 addr show scope global | grep inet - Linux shell fallback 3. hostname -I - Linux shell secondary fallback All results validated with FILTER_VALIDATE_IP before display. --- app/Libraries/SystemOperations.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app/Libraries/SystemOperations.php b/app/Libraries/SystemOperations.php index 396ce50..7957047 100644 --- a/app/Libraries/SystemOperations.php +++ b/app/Libraries/SystemOperations.php @@ -430,12 +430,29 @@ class SystemOperations private function readNetworkStatus(): string { - $result = $this->safeCommand('ip addr 2>/dev/null | head -n 5'); - if ($result === 'Unavailable' || trim($result) === '') { - return 'Unavailable'; + // Try PHP built-in first — works on Linux and Windows without shell + $hostname = gethostname(); + if ($hostname !== false) { + $ip = gethostbyname($hostname); + // gethostbyname returns the hostname unchanged if resolution fails + if ($ip !== $hostname && filter_var($ip, FILTER_VALIDATE_IP)) { + return $ip; + } } - return 'Detected'; + // Fallback: parse first non-loopback IPv4 from ip addr output + $result = $this->safeCommand("ip -4 addr show scope global | grep inet | awk '{print $2}' | cut -d/ -f1 | head -1 2>/dev/null"); + if ($result !== 'Unavailable' && trim($result) !== '' && filter_var(trim($result), FILTER_VALIDATE_IP)) { + return trim($result); + } + + // Fallback: hostname -I + $result = $this->safeCommand('hostname -I 2>/dev/null | awk \'{print $1}\''); + if ($result !== 'Unavailable' && trim($result) !== '' && filter_var(trim($result), FILTER_VALIDATE_IP)) { + return trim($result); + } + + return 'Unavailable'; } private function readInternetStatus(): string