authentication and security

This commit is contained in:
2025-09-28 16:01:27 +01:00
parent f81b0f3c28
commit 22185904be
13 changed files with 1176 additions and 33 deletions
+15 -2
View File
@@ -169,7 +169,12 @@
vnc: parseInt(document.getElementById('port-vnc').value, 10),
}
};
const res = await fetch('/api/settings', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
const headers = { 'Content-Type': 'application/json' };
const csrfToken = '{{ .CSRFToken }}';
if (csrfToken) {
headers['X-CSRF-Token'] = csrfToken;
}
const res = await fetch('/api/settings', { method: 'POST', headers: headers, body: JSON.stringify(payload) });
const out = await res.json().catch(() => ({}));
const el = document.getElementById('save-status');
if (res.ok) {
@@ -181,10 +186,18 @@
}
}
async function restartApp() {
const res = await fetch('/api/restart', { method: 'POST' });
const headers = {};
const csrfToken = '{{ .CSRFToken }}';
if (csrfToken) {
headers['X-CSRF-Token'] = csrfToken;
}
const res = await fetch('/api/restart', { method: 'POST', headers: headers });
if (res.ok) {
document.getElementById('save-status').textContent = 'Restarting...';
setTimeout(() => location.reload(), 1200);
} else {
document.getElementById('save-status').textContent = 'Restart failed';
document.getElementById('save-status').className = 'text-sm text-red-400';
}
}
document.getElementById('btn-save').addEventListener('click', saveSettings);