Create endpoint for dumping client list json

This commit is contained in:
raul 2024-06-07 11:07:35 +02:00
parent 6be659e177
commit e7e24b2310
1 changed files with 15 additions and 0 deletions

View File

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