diff --git a/cmd/httpServer.go b/cmd/httpServer.go index 254771a..0e38c8d 100644 --- a/cmd/httpServer.go +++ b/cmd/httpServer.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "github.com/gin-gonic/gin" "github.com/spf13/viper" @@ -54,10 +55,25 @@ func getCommands(c *gin.Context) { } c.HTML(http.StatusOK, "templates/command.html", gin.H{ "UserAgent": c.Request.UserAgent(), - "client": client, + "Client": client, }) } func execCMD(c *gin.Context) { - fmt.Println("HELLO") + id := c.Param("clientid") + idInt, err := strconv.Atoi(id) + if err != nil { + c.String(http.StatusInternalServerError, "Error happened, please make this a proper error later") + return + } + command, _ := c.GetPostForm("cmd") + + out, err := sendCommand(idInt, command) + if err != nil { + e := fmt.Sprintf("Error happened executing command: %v\n", err) + c.String(http.StatusOK, e) + return + } + prettyOut := strings.Replace(out, "\n", "
", -1) + c.String(http.StatusOK, "$ "+prettyOut) }