ui upadte
This commit is contained in:
parent
038550bb45
commit
30a3525a08
166
html/network.php
166
html/network.php
|
|
@ -23,7 +23,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
if (isset($_POST['action'])) {
|
if (isset($_POST['action'])) {
|
||||||
$interface = $_POST['interface'] ?? '';
|
$interface = $_POST['interface'] ?? '';
|
||||||
$action = $_POST['action'];
|
$action = $_POST['action'];
|
||||||
|
|
||||||
if ($action === 'save') {
|
if ($action === 'save') {
|
||||||
// Save configuration
|
// Save configuration
|
||||||
$config = [
|
$config = [
|
||||||
|
|
@ -34,7 +34,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
'gateway' => $_POST['gateway'] ?? '',
|
'gateway' => $_POST['gateway'] ?? '',
|
||||||
'dns' => $_POST['dns'] ?? ''
|
'dns' => $_POST['dns'] ?? ''
|
||||||
];
|
];
|
||||||
|
|
||||||
$network_config[$interface] = $config;
|
$network_config[$interface] = $config;
|
||||||
file_put_contents($config_file, json_encode($network_config, JSON_PRETTY_PRINT));
|
file_put_contents($config_file, json_encode($network_config, JSON_PRETTY_PRINT));
|
||||||
} elseif ($action === 'activate') {
|
} elseif ($action === 'activate') {
|
||||||
|
|
@ -51,7 +51,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
'ntp_servers' => $_POST['ntp_servers'] ?? '',
|
'ntp_servers' => $_POST['ntp_servers'] ?? '',
|
||||||
'proxy' => $_POST['proxy'] ?? ''
|
'proxy' => $_POST['proxy'] ?? ''
|
||||||
];
|
];
|
||||||
|
|
||||||
$network_config['general'] = $general_config;
|
$network_config['general'] = $general_config;
|
||||||
file_put_contents($config_file, json_encode($network_config, JSON_PRETTY_PRINT));
|
file_put_contents($config_file, json_encode($network_config, JSON_PRETTY_PRINT));
|
||||||
}
|
}
|
||||||
|
|
@ -70,28 +70,26 @@ foreach ($output as $line) {
|
||||||
// Match interface name
|
// Match interface name
|
||||||
if (preg_match('/^\d+:\s+([a-zA-Z0-9]+):/', $line, $matches)) {
|
if (preg_match('/^\d+:\s+([a-zA-Z0-9]+):/', $line, $matches)) {
|
||||||
$current_interface = $matches[1];
|
$current_interface = $matches[1];
|
||||||
|
|
||||||
// Skip interfaces we want to exclude
|
// Skip interfaces we want to exclude
|
||||||
if (strpos($current_interface, 'enx') === 0) {
|
if (strpos($current_interface, 'enx') === 0) {
|
||||||
$current_interface = null;
|
$current_interface = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($current_interface === 'lo') {
|
if ($current_interface === 'lo') {
|
||||||
$current_interface = null;
|
$current_interface = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if interface is a bridge or docker interface
|
// Check if interface is a bridge or docker interface
|
||||||
if (
|
if (strpos($current_interface, 'docker') === 0 ||
|
||||||
strpos($current_interface, 'docker') === 0 ||
|
|
||||||
strpos($current_interface, 'br-') === 0 ||
|
strpos($current_interface, 'br-') === 0 ||
|
||||||
strpos($current_interface, 'veth') === 0
|
strpos($current_interface, 'veth') === 0) {
|
||||||
) {
|
|
||||||
$current_interface = null;
|
$current_interface = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$interface_data[$current_interface] = [
|
$interface_data[$current_interface] = [
|
||||||
'name' => $current_interface,
|
'name' => $current_interface,
|
||||||
'ip' => '',
|
'ip' => '',
|
||||||
|
|
@ -100,17 +98,17 @@ foreach ($output as $line) {
|
||||||
'config' => $network_config[$current_interface] ?? null
|
'config' => $network_config[$current_interface] ?? null
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract IP address
|
// Extract IP address
|
||||||
if ($current_interface && preg_match('/inet\s+(\d+\.\d+\.\d+\.\d+)/', $line, $matches)) {
|
if ($current_interface && preg_match('/inet\s+(\d+\.\d+\.\d+\.\d+)/', $line, $matches)) {
|
||||||
$interface_data[$current_interface]['ip'] = $matches[1];
|
$interface_data[$current_interface]['ip'] = $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract MAC address
|
// Extract MAC address
|
||||||
if ($current_interface && preg_match('/link\/ether\s+([a-f0-9:]+)/', $line, $matches)) {
|
if ($current_interface && preg_match('/link\/ether\s+([a-f0-9:]+)/', $line, $matches)) {
|
||||||
$interface_data[$current_interface]['mac'] = $matches[1];
|
$interface_data[$current_interface]['mac'] = $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if interface is up
|
// Check if interface is up
|
||||||
if ($current_interface && strpos($line, 'state UP') !== false) {
|
if ($current_interface && strpos($line, 'state UP') !== false) {
|
||||||
$interface_data[$current_interface]['status'] = 'up';
|
$interface_data[$current_interface]['status'] = 'up';
|
||||||
|
|
@ -128,7 +126,7 @@ $general_config = $network_config['general'] ?? [
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h2>Network Configuration</h2>
|
<h2>Network Configuration</h2>
|
||||||
|
|
||||||
<!-- Main container for network settings -->
|
<!-- Main container for network settings -->
|
||||||
<div class="network-settings-container">
|
<div class="network-settings-container">
|
||||||
<!-- Tabs for different sections -->
|
<!-- Tabs for different sections -->
|
||||||
|
|
@ -144,7 +142,7 @@ $general_config = $network_config['general'] ?? [
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<!-- Tab Content -->
|
<!-- Tab Content -->
|
||||||
<div class="tab-content" id="networkTabContent">
|
<div class="tab-content" id="networkTabContent">
|
||||||
<!-- General Settings -->
|
<!-- General Settings -->
|
||||||
|
|
@ -156,37 +154,37 @@ $general_config = $network_config['general'] ?? [
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<input type="hidden" name="action" value="save_general">
|
<input type="hidden" name="action" value="save_general">
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="hostname" class="form-label">Hostname</label>
|
<label for="hostname" class="form-label">Hostname</label>
|
||||||
<input type="text" class="form-control" id="hostname" name="hostname"
|
<input type="text" class="form-control" id="hostname" name="hostname"
|
||||||
value="<?php echo htmlspecialchars($general_config['hostname']); ?>">
|
value="<?php echo htmlspecialchars($general_config['hostname']); ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="dns_servers" class="form-label">DNS Servers (comma separated)</label>
|
<label for="dns_servers" class="form-label">DNS Servers (comma separated)</label>
|
||||||
<input type="text" class="form-control" id="dns_servers" name="dns_servers"
|
<input type="text" class="form-control" id="dns_servers" name="dns_servers"
|
||||||
value="<?php echo htmlspecialchars($general_config['dns_servers']); ?>">
|
value="<?php echo htmlspecialchars($general_config['dns_servers']); ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="ntp_servers" class="form-label">NTP Servers (comma separated)</label>
|
<label for="ntp_servers" class="form-label">NTP Servers (comma separated)</label>
|
||||||
<input type="text" class="form-control" id="ntp_servers" name="ntp_servers"
|
<input type="text" class="form-control" id="ntp_servers" name="ntp_servers"
|
||||||
value="<?php echo htmlspecialchars($general_config['ntp_servers']); ?>">
|
value="<?php echo htmlspecialchars($general_config['ntp_servers']); ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="proxy" class="form-label">Proxy Server</label>
|
<label for="proxy" class="form-label">Proxy Server</label>
|
||||||
<input type="text" class="form-control" id="proxy" name="proxy"
|
<input type="text" class="form-control" id="proxy" name="proxy"
|
||||||
value="<?php echo htmlspecialchars($general_config['proxy']); ?>">
|
value="<?php echo htmlspecialchars($general_config['proxy']); ?>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-primary">Save General Settings</button>
|
<button type="submit" class="btn btn-primary">Save General Settings</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Interfaces Tab -->
|
<!-- Interfaces Tab -->
|
||||||
<div class="tab-pane fade" id="interfaces" role="tabpanel">
|
<div class="tab-pane fade" id="interfaces" role="tabpanel">
|
||||||
<div class="card mt-3">
|
<div class="card mt-3">
|
||||||
|
|
@ -196,35 +194,32 @@ $general_config = $network_config['general'] ?? [
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<!-- Interface Tabs -->
|
<!-- Interface Tabs -->
|
||||||
<ul class="nav nav-tabs interface-tabs" id="interfaceTabs" role="tablist">
|
<ul class="nav nav-tabs interface-tabs" id="interfaceTabs" role="tablist">
|
||||||
<?php $first = true;
|
<?php $first = true; foreach ($interface_data as $interface): ?>
|
||||||
foreach ($interface_data as $interface): ?>
|
|
||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation">
|
||||||
<button class="nav-link <?php echo $first ? 'active' : ''; ?>"
|
<button class="nav-link <?php echo $first ? 'active' : ''; ?>"
|
||||||
id="tab-<?php echo $interface['name']; ?>"
|
id="tab-<?php echo $interface['name']; ?>"
|
||||||
data-bs-toggle="tab"
|
data-bs-toggle="tab"
|
||||||
data-bs-target="#<?php echo $interface['name']; ?>"
|
data-bs-target="#<?php echo $interface['name']; ?>"
|
||||||
type="button"
|
type="button"
|
||||||
role="tab">
|
role="tab">
|
||||||
<?php echo htmlspecialchars($interface['name']); ?>
|
<?php echo htmlspecialchars($interface['name']); ?>
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
<?php $first = false;
|
<?php $first = false; endforeach; ?>
|
||||||
endforeach; ?>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<!-- Interface Tab Content -->
|
<!-- Interface Tab Content -->
|
||||||
<div class="tab-content interface-tab-content" id="interfaceTabContent">
|
<div class="tab-content interface-tab-content" id="interfaceTabContent">
|
||||||
<?php $first = true;
|
<?php $first = true; foreach ($interface_data as $interface): ?>
|
||||||
foreach ($interface_data as $interface): ?>
|
<div class="tab-pane fade <?php echo $first ? 'show active' : ''; ?>"
|
||||||
<div class="tab-pane fade <?php echo $first ? 'show active' : ''; ?>"
|
id="<?php echo $interface['name']; ?>"
|
||||||
id="<?php echo $interface['name']; ?>"
|
role="tabpanel">
|
||||||
role="tabpanel">
|
|
||||||
<div class="interface-settings">
|
<div class="interface-settings">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<p><strong>IP Address:</strong> <?php echo htmlspecialchars($interface['ip'] ?: 'N/A'); ?></p>
|
<p><strong>IP Address:</strong> <?php echo htmlspecialchars($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['mac'] ?: 'N/A'); ?></p>
|
||||||
<p><strong>Status:</strong>
|
<p><strong>Status:</strong>
|
||||||
<span class="badge bg-<?php echo $interface['status'] === 'up' ? 'success' : 'secondary'; ?>">
|
<span class="badge bg-<?php echo $interface['status'] === 'up' ? 'success' : 'secondary'; ?>">
|
||||||
<?php echo htmlspecialchars($interface['status']); ?>
|
<?php echo htmlspecialchars($interface['status']); ?>
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -234,51 +229,57 @@ $general_config = $network_config['general'] ?? [
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<input type="hidden" name="interface" value="<?php echo htmlspecialchars($interface['name']); ?>">
|
<input type="hidden" name="interface" value="<?php echo htmlspecialchars($interface['name']); ?>">
|
||||||
<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 $interface['name']; ?>"
|
||||||
value="dhcp" <?php echo ($interface['config']['method'] ?? '') === 'dhcp' ? 'checked' : ''; ?>>
|
value="dhcp" <?php echo ($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 $interface['name']; ?>">
|
||||||
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 $interface['name']; ?>"
|
||||||
value="static" <?php echo ($interface['config']['method'] ?? '') === 'static' ? 'checked' : ''; ?>>
|
value="static" <?php echo ($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 $interface['name']; ?>">
|
||||||
Static IP
|
Static IP
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3" id="static-ip-fields-<?php echo $interface['name']; ?>"
|
|
||||||
style="<?php echo ($interface['config']['method'] ?? '') === 'static' ? 'display: block;' : 'display: none;'; ?>">
|
<div class="mb-3" id="static-ip-fields-<?php echo $interface['name']; ?>"
|
||||||
|
style="<?php echo ($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['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['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['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['config']['dns'] ?? ''); ?>"
|
||||||
placeholder="8.8.8.8">
|
placeholder="8.8.8.8">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
<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['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['status'] === 'down' ? 'disabled' : ''; ?>">
|
||||||
Deactivate
|
Deactivate
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -288,8 +289,7 @@ $general_config = $network_config['general'] ?? [
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<?php $first = false;
|
<?php $first = false; endforeach; ?>
|
||||||
endforeach; ?>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -299,19 +299,19 @@ $general_config = $network_config['general'] ?? [
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Toggle static IP fields based on method selection
|
// Toggle static IP fields based on method selection
|
||||||
document.querySelectorAll('input[name^="method"]').forEach(radio => {
|
document.querySelectorAll('input[name^="method"]').forEach(radio => {
|
||||||
radio.addEventListener('change', function() {
|
radio.addEventListener('change', function() {
|
||||||
const interfaceName = this.name.replace('method', '');
|
const interfaceName = this.name.replace('method', '');
|
||||||
const staticFields = document.getElementById(`static-ip-fields-${interfaceName}`);
|
const staticFields = document.getElementById(`static-ip-fields-${interfaceName}`);
|
||||||
|
|
||||||
if (this.value === 'static') {
|
if (this.value === 'static') {
|
||||||
staticFields.style.display = 'block';
|
staticFields.style.display = 'block';
|
||||||
} else {
|
} else {
|
||||||
staticFields.style.display = 'none';
|
staticFields.style.display = 'none';
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<?php include 'footer.php' ?>
|
<?php include 'footer.php' ?>
|
||||||
Loading…
Reference in New Issue