Add option to delete clients from list

This commit is contained in:
raul 2024-06-11 12:27:43 +02:00
parent ecf6e1d443
commit bb2620d5ec
2 changed files with 20 additions and 0 deletions

View File

@ -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 {

View File

@ -50,6 +50,9 @@
<td rowspan=2>
<a href="/" hx-post="kill/{{ .ClientID }}" hx-swap="none" id="pointer"><b>KILL</b></a>
</td>
<td rowspan=2>
<a href="/" hx-post="remove/{{ .ClientID }}" hx-swap="none" id="pointer"><b>REMOVE</b></a>
</td>
</tr>
<tr>
<td>{{ .ClientID }}</td>