mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-22 16:38:28 +00:00
New function get network card (#7703)
* Create a new function to help determine network card * Fix BSD network card capture command
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user