diff --git a/html/network.php b/html/network.php index b8de5fc..e5b4dc8 100755 --- a/html/network.php +++ b/html/network.php @@ -1,5 +1,4 @@ +include 'header.php'; + +// Load network configuration +$config_file = '/etc/urmi/network.json'; +$network_config = []; + +if (file_exists($config_file)) { + $config_data = file_get_contents($config_file); + $network_config = json_decode($config_data, true); +} + +// Handle form submissions +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['action'])) { + $interface = $_POST['interface']; + $action = $_POST['action']; + + if ($action === 'save') { + // Save configuration + $config = [ + 'interface' => $interface, + 'method' => $_POST['method'], + 'ip' => $_POST['ip'] ?? '', + 'netmask' => $_POST['netmask'] ?? '', + 'gateway' => $_POST['gateway'] ?? '', + 'dns' => $_POST['dns'] ?? '' + ]; + + $network_config[$interface] = $config; + file_put_contents($config_file, json_encode($network_config, JSON_PRETTY_PRINT)); + } elseif ($action === 'activate') { + // Activate interface + exec("sudo ip link set $interface up", $output, $return_code); + } elseif ($action === 'deactivate') { + // Deactivate interface + exec("sudo ip link set $interface down", $output, $return_code); + } + } +} + +// Get network interfaces excluding specific ones +$interfaces = []; +$output = []; +exec('ip addr show', $output); + +$current_interface = null; +$interface_data = []; + +foreach ($output as $line) { + // Match interface name + if (preg_match('/^\d+:\s+([a-zA-Z0-9]+):/', $line, $matches)) { + $current_interface = $matches[1]; + + // Skip interfaces we want to exclude + if (strpos($current_interface, 'enx') === 0) { + $current_interface = null; + continue; + } + + if ($current_interface === 'lo') { + $current_interface = null; + continue; + } + + // Check if interface is a bridge or docker interface + if (strpos($current_interface, 'docker') === 0 || + strpos($current_interface, 'br-') === 0 || + strpos($current_interface, 'veth') === 0) { + $current_interface = null; + continue; + } + + $interface_data[$current_interface] = [ + 'name' => $current_interface, + 'ip' => '', + 'mac' => '', + 'status' => 'down', + 'config' => $network_config[$current_interface] ?? null + ]; + } + + // Extract IP address + if ($current_interface && preg_match('/inet\s+(\d+\.\d+\.\d+\.\d+)/', $line, $matches)) { + $interface_data[$current_interface]['ip'] = $matches[1]; + } + + // Extract MAC address + if ($current_interface && preg_match('/link\/ether\s+([a-f0-9:]+)/', $line, $matches)) { + $interface_data[$current_interface]['mac'] = $matches[1]; + } + + // Check if interface is up + if ($current_interface && strpos($line, 'state UP') !== false) { + $interface_data[$current_interface]['status'] = 'up'; + } +} +?>

Network Interfaces

- - - - - - - - - - - $current_interface, - 'ip' => '', - 'mac' => '', - 'status' => 'down' - ]; - } - - // Extract IP address - if ($current_interface && preg_match('/inet\s+(\d+\.\d+\.\d+\.\d+)/', $line, $matches)) { - $interface_data[$current_interface]['ip'] = $matches[1]; - } - - // Extract MAC address - if ($current_interface && preg_match('/link\/ether\s+([a-f0-9:]+)/', $line, $matches)) { - $interface_data[$current_interface]['mac'] = $matches[1]; - } - - // Check if interface is up - if ($current_interface && strpos($line, 'state UP') !== false) { - $interface_data[$current_interface]['status'] = 'up'; - } - } - - // Display the filtered interfaces - foreach ($interface_data as $interface) { - if (!empty($interface['ip']) || !empty($interface['mac'])) { - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - } - } - ?> - -
Interface NameIP AddressMAC AddressStatus
" . htmlspecialchars($interface['name']) . "" . htmlspecialchars($interface['ip']) . "" . htmlspecialchars($interface['mac']) . "" . htmlspecialchars($interface['status']) . "
+ + + + + +
+ +
+
+
+
+
+
+
+
+

IP Address:

+

MAC Address:

+

Status: + + + +

+
+
+
+ + +
+ +
+ > + +
+
+ > + +
+
+ +
+ + + + + + + + + + + +
+ +
+ +
+ + +
+
+
+
+
+
+
+
+ +
+ + \ No newline at end of file