This commit is contained in:
Devdatt Bhatt 2026-06-08 00:20:25 +00:00
parent a60557679c
commit 082244f358
1 changed files with 94 additions and 77 deletions

View File

@ -103,70 +103,84 @@ foreach ($output as $line) {
$interface_data[$current_interface]['status'] = 'up'; $interface_data[$current_interface]['status'] = 'up';
} }
} }
// Get selected interface from GET parameter or first interface
$selected_interface = $_GET['interface'] ?? array_keys($interface_data)[0] ?? null;
?> ?>
<div class="container"> <div class="container">
<h2>Network Configuration</h2> <h2>Network Configuration</h2>
<!-- Interface selection -->
<div class="interface-selector">
<h4>Select Interface:</h4>
<div class="interface-list">
<?php foreach ($interface_data as $interface): ?>
<a href="?interface=<?php echo urlencode($interface['name']); ?>"
class="btn <?php echo $selected_interface === $interface['name'] ? 'btn-primary' : 'btn-outline-primary'; ?>">
<?php echo htmlspecialchars($interface['name']); ?>
</a>
<?php endforeach; ?>
</div>
</div>
<!-- Main container for network settings --> <!-- Main container for network settings -->
<div class="network-settings-container"> <div class="network-settings-container">
<!-- Network Interfaces in horizontal line --> <?php if ($selected_interface && isset($interface_data[$selected_interface])): ?>
<div class="network-interfaces-horizontal">
<?php foreach ($interface_data as $interface): ?>
<div class="interface-card"> <div class="interface-card">
<div class="interface-header"> <div class="interface-header">
<h5><?php echo htmlspecialchars($interface['name']); ?></h5> <h5><?php echo htmlspecialchars($interface_data[$selected_interface]['name']); ?></h5>
<span class="badge bg-<?php echo $interface['status'] === 'up' ? 'success' : 'secondary'; ?>"> <span class="badge bg-<?php echo $interface_data[$selected_interface]['status'] === 'up' ? 'success' : 'secondary'; ?>">
<?php echo htmlspecialchars($interface['status']); ?> <?php echo htmlspecialchars($interface_data[$selected_interface]['status']); ?>
</span> </span>
</div> </div>
<div class="interface-body"> <div class="interface-body">
<p><strong>IP Address:</strong> <?php echo htmlspecialchars($interface['ip'] ?: 'N/A'); ?></p> <p><strong>IP Address:</strong> <?php echo htmlspecialchars($interface_data[$selected_interface]['ip'] ?: 'N/A'); ?></p>
<p><strong>MAC Address:</strong> <?php echo htmlspecialchars($interface['mac'] ?: 'N/A'); ?></p> <p><strong>MAC Address:</strong> <?php echo htmlspecialchars($interface_data[$selected_interface]['mac'] ?: 'N/A'); ?></p>
</div> </div>
<div class="interface-footer"> <div class="interface-footer">
<form method="post" action="" class="interface-form"> <form method="post" action="" class="interface-form">
<input type="hidden" name="interface" value="<?php echo htmlspecialchars($interface['name']); ?>"> <input type="hidden" name="interface" value="<?php echo htmlspecialchars($selected_interface); ?>">
<input type="hidden" name="action" value="save"> <input type="hidden" name="action" value="save">
<div class="mb-3"> <div class="mb-3">
<label class="form-label">Configuration Method</label> <label class="form-label">Configuration Method</label>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="radio" name="method" id="dhcp-<?php echo $interface['name']; ?>" <input class="form-check-input" type="radio" name="method" id="dhcp-<?php echo $selected_interface; ?>"
value="dhcp" <?php echo ($interface['config']['method'] ?? '') === 'dhcp' ? 'checked' : ''; ?>> value="dhcp" <?php echo ($interface_data[$selected_interface]['config']['method'] ?? '') === 'dhcp' ? 'checked' : ''; ?>>
<label class="form-check-label" for="dhcp-<?php echo $interface['name']; ?>"> <label class="form-check-label" for="dhcp-<?php echo $selected_interface; ?>">
DHCP DHCP
</label> </label>
</div> </div>
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="radio" name="method" id="static-<?php echo $interface['name']; ?>" <input class="form-check-input" type="radio" name="method" id="static-<?php echo $selected_interface; ?>"
value="static" <?php echo ($interface['config']['method'] ?? '') === 'static' ? 'checked' : ''; ?>> value="static" <?php echo ($interface_data[$selected_interface]['config']['method'] ?? '') === 'static' ? 'checked' : ''; ?>>
<label class="form-check-label" for="static-<?php echo $interface['name']; ?>"> <label class="form-check-label" for="static-<?php echo $selected_interface; ?>">
Static IP Static IP
</label> </label>
</div> </div>
</div> </div>
<div class="mb-3" id="static-ip-fields-<?php echo $interface['name']; ?>" <div class="mb-3" id="static-ip-fields-<?php echo $selected_interface; ?>"
style="<?php echo ($interface['config']['method'] ?? '') === 'static' ? 'display: block;' : 'display: none;'; ?>"> style="<?php echo ($interface_data[$selected_interface]['config']['method'] ?? '') === 'static' ? 'display: block;' : 'display: none;'; ?>">
<label class="form-label">IP Address</label> <label class="form-label">IP Address</label>
<input type="text" class="form-control" name="ip" <input type="text" class="form-control" name="ip"
value="<?php echo htmlspecialchars($interface['config']['ip'] ?? ''); ?>" value="<?php echo htmlspecialchars($interface_data[$selected_interface]['config']['ip'] ?? ''); ?>"
placeholder="192.168.1.100"> placeholder="192.168.1.100">
<label class="form-label mt-2">Netmask</label> <label class="form-label mt-2">Netmask</label>
<input type="text" class="form-control" name="netmask" <input type="text" class="form-control" name="netmask"
value="<?php echo htmlspecialchars($interface['config']['netmask'] ?? ''); ?>" value="<?php echo htmlspecialchars($interface_data[$selected_interface]['config']['netmask'] ?? ''); ?>"
placeholder="255.255.255.0"> placeholder="255.255.255.0">
<label class="form-label mt-2">Gateway</label> <label class="form-label mt-2">Gateway</label>
<input type="text" class="form-control" name="gateway" <input type="text" class="form-control" name="gateway"
value="<?php echo htmlspecialchars($interface['config']['gateway'] ?? ''); ?>" value="<?php echo htmlspecialchars($interface_data[$selected_interface]['config']['gateway'] ?? ''); ?>"
placeholder="192.168.1.1"> placeholder="192.168.1.1">
<label class="form-label mt-2">DNS Server</label> <label class="form-label mt-2">DNS Server</label>
<input type="text" class="form-control" name="dns" <input type="text" class="form-control" name="dns"
value="<?php echo htmlspecialchars($interface['config']['dns'] ?? ''); ?>" value="<?php echo htmlspecialchars($interface_data[$selected_interface]['config']['dns'] ?? ''); ?>"
placeholder="8.8.8.8"> placeholder="8.8.8.8">
</div> </div>
@ -174,11 +188,11 @@ foreach ($output as $line) {
<button type="submit" class="btn btn-primary">Save Configuration</button> <button type="submit" class="btn btn-primary">Save Configuration</button>
<div> <div>
<button type="submit" name="action" value="activate" <button type="submit" name="action" value="activate"
class="btn btn-success <?php echo $interface['status'] === 'up' ? 'disabled' : ''; ?>"> class="btn btn-success <?php echo $interface_data[$selected_interface]['status'] === 'up' ? 'disabled' : ''; ?>">
Activate Activate
</button> </button>
<button type="submit" name="action" value="deactivate" <button type="submit" name="action" value="deactivate"
class="btn btn-danger <?php echo $interface['status'] === 'down' ? 'disabled' : ''; ?>"> class="btn btn-danger <?php echo $interface_data[$selected_interface]['status'] === 'down' ? 'disabled' : ''; ?>">
Deactivate Deactivate
</button> </button>
</div> </div>
@ -186,8 +200,11 @@ foreach ($output as $line) {
</form> </form>
</div> </div>
</div> </div>
<?php endforeach; ?> <?php else: ?>
<div class="alert alert-info">
No network interfaces found or selected.
</div> </div>
<?php endif; ?>
</div> </div>
</div> </div>