Add option to delete clients from list
This commit is contained in:
parent
ecf6e1d443
commit
bb2620d5ec
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue