diff --git a/app/system/resources/classes/bsd_system_information.php b/app/system/resources/classes/bsd_system_information.php index 0d12508fdd..b2bd3f6675 100644 --- a/app/system/resources/classes/bsd_system_information.php +++ b/app/system/resources/classes/bsd_system_information.php @@ -31,6 +31,20 @@ */ class bsd_system_information extends system_information { + /** + * Returns the network card information. + * + * @param string|null $default_value The default value to return if the network card information cannot be determined. + * + * @return string|null The network card information or the default value. + */ + public function get_network_card(?string $default_value = null): ?string { + // Implementation for BSD systems + $result = shell_exec("ifconfig -a | head -n1 | awk '{print $1}'"); + $network_card = trim($result, " :"); + return $network_card ?: $default_value; + } + /** * Returns the number of CPU cores available on the system. * diff --git a/app/system/resources/classes/linux_system_information.php b/app/system/resources/classes/linux_system_information.php index 5037aa6002..c866febb7e 100644 --- a/app/system/resources/classes/linux_system_information.php +++ b/app/system/resources/classes/linux_system_information.php @@ -184,4 +184,31 @@ class linux_system_information extends system_information { return ['rx_bps' => 0, 'tx_bps' => 0]; } + + /** + * Attempts to detect the network card + * + * @param $default_value string|null Default network card + * + * @return string|null + */ + public function get_network_card(?string $default_value = null): ?string { + // Use the default route to find the network interface + $result = shell_exec("ip route show default 2>/dev/null"); + if (!empty($result)) { + + // Parse the output to find the interface name + $parts = array_map('trim', explode(' ', $result)); + $dev_index = array_search('dev', $parts, true); + + // Ensure 'dev' is found and there is a following part to be found + if ($dev_index !== false && isset($parts[$dev_index + 1])) { + // Return the interface name found after 'dev' + $default_value = $parts[$dev_index + 1]; + } + } + + // Return the detected or default value + return $default_value; + } } diff --git a/app/system/resources/classes/system_information.php b/app/system/resources/classes/system_information.php index d93ba12513..2b35db817d 100644 --- a/app/system/resources/classes/system_information.php +++ b/app/system/resources/classes/system_information.php @@ -36,6 +36,7 @@ abstract class system_information { abstract public function get_cpu_percent(): float; abstract public function get_cpu_percent_per_core(): array; abstract public function get_network_speed(string $interface = 'eth0'): array; + abstract public function get_network_card(?string $default_value = null): ?string; /** * Returns the system load average. diff --git a/app/system/resources/dashboard/system_network_status.php b/app/system/resources/dashboard/system_network_status.php index 6b50827a90..23ee943edf 100644 --- a/app/system/resources/dashboard/system_network_status.php +++ b/app/system/resources/dashboard/system_network_status.php @@ -26,18 +26,7 @@ $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; -// //get the network details -// if (stristr(PHP_OS, 'Linux')) { -// $result = shell_exec("ls /sys/class/net | tr '\n' ' '"); -// $cards = array_map('trim', explode(' ', $result)); -// $selected_card = $settings->get('system', 'network_interface', ''); -// if (!in_array($selected_card, $cards, true)) { -// // Selected card not in list -// return; -// } -// -// } - +//create token $token = (new token())->create($_SERVER['PHP_SELF']); // Register as a subscriber for the dashboard information service