diff --git a/cmd/httpServer.go b/cmd/httpServer.go index af02830..beadf2c 100644 --- a/cmd/httpServer.go +++ b/cmd/httpServer.go @@ -40,6 +40,7 @@ func WebServer() { r.POST("/kill/:clientid", sendKillswitch) r.GET("/dump", dumpClients) r.POST("/save", saveClients) + r.POST("/remove/:clientid", removeClient) r.Run(":" + WebPort) } @@ -68,6 +69,22 @@ func saveClients(c *gin.Context) { log.Println("SUCCESS!") } +func removeClient(c *gin.Context) { + clientID := c.Param("clientid") + intClientID, err := strconv.Atoi(clientID) + if err != nil { + c.String(http.StatusInternalServerError, "Error happened fetching client: %v", err) + return + } + log.Printf("Removing client %v\n", intClientID) + if len(clientList) != 1 { + clientList = append(clientList[:intClientID], clientList[intClientID+1:]...) + } else { + clientList = nil + } + log.Printf("Success!") +} + func marshalClients() ClientJSON { jsonClients := ClientJSON{Date: time.Now()} for _, v := range clientList { diff --git a/cmd/templates/index.html b/cmd/templates/index.html index 3cd0428..4f99aaa 100644 --- a/cmd/templates/index.html +++ b/cmd/templates/index.html @@ -50,6 +50,9 @@ KILL + + REMOVE + {{ .ClientID }}