keypatch/data/portconfig.html

65 lines
2.3 KiB
HTML

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<title>Port Konfiguration</title>
</head>
<body>
<h1>Port Konfiguration</h1>
<form id="portForm">
<div id="portsContainer"></div>
<input type="submit" value="Speichern">
</form>
<a href="/admin.html">Zurück</a>
<script>
async function loadConfig() {
try {
const response = await fetch('/portconfig/data');
const data = await response.json();
const container = document.getElementById('portsContainer');
container.innerHTML = '';
data.ports.forEach((port, index) => {
const div = document.createElement('div');
div.innerHTML = `
<label>
Name: <input type="text" name="name${index}" value="${port.name}">
Aktiviert: <input type="checkbox" name="enabled${index}" ${port.enabled ? 'checked' : ''}>
</label>
`;
container.appendChild(div);
});
} catch (error) {
console.error('Fehler beim Laden der Konfiguration:', error);
}
}
document.getElementById('portForm').addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(e.target);
const ports = [];
for (let i = 0; i < 16; i++) {
ports.push({
name: formData.get(`name${i}`) || `Port ${i}`,
enabled: formData.has(`enabled${i}`)
});
}
try {
await fetch('/portconfig', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ports })
});
alert('Konfiguration gespeichert!');
loadConfig(); // Reload
} catch (error) {
console.error('Fehler beim Speichern:', error);
}
});
loadConfig();
</script>
</body>
</html>