Configure rudimentary setup for requesting commands
This commit is contained in:
parent
67051033d8
commit
6d02a4627b
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue