pi hole setup

This commit is contained in:
2026-03-09 02:24:29 +01:00
parent c144d9bcd2
commit 8de05d5552
6 changed files with 138 additions and 7 deletions

View File

@@ -49,6 +49,44 @@
});
});
const apiCall = async (action, payload = {}) => {
const res = await fetch(`/module/pihole/api?action=${encodeURIComponent(action)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
const data = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`);
return data;
};
document.querySelectorAll('[data-instance-test]').forEach((btn) => {
btn.addEventListener('click', async () => {
const card = btn.closest('[data-instance-id]');
if (!card) return;
const instanceId = card.dataset.instanceId || '';
const resultEl = card.querySelector('[data-instance-result]');
if (resultEl) {
resultEl.classList.remove('is-ok', 'is-auth', 'is-unreachable', 'is-invalid', 'is-error');
resultEl.textContent = 'Teste Verbindung...';
}
try {
const res = await apiCall('test', { instance: instanceId });
if (resultEl) {
const statusClass = res.status ? `is-${res.status}` : 'is-ok';
resultEl.classList.add(statusClass);
resultEl.textContent = res.message || 'Verbindung OK.';
}
} catch (err) {
if (resultEl) {
const msg = err.message || 'Fehler';
resultEl.classList.add('is-error');
resultEl.textContent = `Test fehlgeschlagen: ${msg}`;
}
}
});
});
if (newBtn) {
newBtn.addEventListener('click', () => {
resetForm();