From 6d02a4627b704fd2a018354b957db152f76740ad Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 5 Jun 2024 09:47:16 +0200 Subject: [PATCH] Configure rudimentary setup for requesting commands --- cmd/httpServer.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cmd/httpServer.go b/cmd/httpServer.go index 63de8e3..254771a 100644 --- a/cmd/httpServer.go +++ b/cmd/httpServer.go @@ -2,7 +2,9 @@ package cmd import ( "embed" + "fmt" "net/http" + "strconv" "github.com/gin-gonic/gin" "github.com/spf13/viper" @@ -26,6 +28,8 @@ func WebServer() { r.StaticFileFS("/style.css", "./templates/style.css", http.FS(templatesFolder)) r.StaticFileFS("/htmx.js", "./templates/htmx.js", http.FS(templatesFolder)) r.GET("/", getRoot) + r.GET("/command/:clientid", getCommands) + r.POST("/command/:clientid", execCMD) r.Run(":" + WebPort) } @@ -35,3 +39,25 @@ func getRoot(c *gin.Context) { "Clients": clientList, }) } + +func getCommands(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 + } + client, err := returnClient(intClientID) + if err != nil { + c.String(http.StatusNotFound, "Client not found") + return + } + c.HTML(http.StatusOK, "templates/command.html", gin.H{ + "UserAgent": c.Request.UserAgent(), + "client": client, + }) +} + +func execCMD(c *gin.Context) { + fmt.Println("HELLO") +}