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,