From e7e24b231013af03802c7291b77d86531ddd1590 Mon Sep 17 00:00:00 2001 From: raul Date: Fri, 7 Jun 2024 11:07:35 +0200 Subject: [PATCH] Create endpoint for dumping client list json --- cmd/httpServer.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/httpServer.go b/cmd/httpServer.go index 27c34c5..5cb330b 100644 --- a/cmd/httpServer.go +++ b/cmd/httpServer.go @@ -6,11 +6,17 @@ import ( "net/http" "strconv" "strings" + "time" "github.com/gin-gonic/gin" "github.com/spf13/viper" ) +type ClientJSON struct { + Date time.Time + List []ClientBasicInfo +} + var ( WebPort string = "8080" ) @@ -32,9 +38,18 @@ func WebServer() { r.GET("/command/:clientid", getCommands) r.POST("/command/:clientid", execCMD) r.POST("/kill/:clientid", sendKillswitch) + r.GET("/dump", dumpClients) r.Run(":" + WebPort) } +func dumpClients(c *gin.Context) { + jsonClients := ClientJSON{Date: time.Now()} + for _, v := range clientList { + jsonClients.List = append(jsonClients.List, v.ClientBasicInfo) + } + c.IndentedJSON(http.StatusOK, jsonClients) +} + func getRoot(c *gin.Context) { c.HTML(http.StatusOK, "templates/index.html", gin.H{ "Clients": clientList,