diff --git a/servers/servers.go b/servers/servers.go index d3eba83..7b412a4 100644 --- a/servers/servers.go +++ b/servers/servers.go @@ -8,6 +8,7 @@ import ( "log" "net/http" "os" + "strconv" "strings" "time" @@ -499,7 +500,7 @@ func (con Connection) RunCommand(ctx *gin.Context) { type Commands struct { CommandType string `json:"CommandType"` - Arguments []uint `json:"Arguments"` + Arguments string `json:"Arguments"` } func (con Connection) AttachServer(ctx *gin.Context) { @@ -590,7 +591,7 @@ func (con Connection) AttachServer(ctx *gin.Context) { case Command := <-websocketRead: switch Command.CommandType { case "insert": - _, err = hijacked.Conn.Write([]byte(Command.Arguments[0].(string))) + _, err = hijacked.Conn.Write([]byte(Command.Arguments)) if err != nil { log.Printf("Write to docker failed %s", errors.Unwrap(err)) @@ -602,10 +603,20 @@ func (con Connection) AttachServer(ctx *gin.Context) { stop = true case "resize": - log.Printf("Fake resize %dx%d", Command.Arguments[0].(uint), Command.Arguments[1].(uint)) - err2 := con.dockerClient.ContainerResize(context.TODO(), containers[0].ID, container.ResizeOptions{Height: Command.Arguments[1].(uint), Width: Command.Arguments[0].(uint)}) + args := strings.Split(Command.Arguments, "x") + width, err2 := strconv.Atoi(args[0]) if err2 != nil { - log.Printf("Failed to resize container to %dx%d: %s", Command.Arguments[0].(uint), Command.Arguments[1].(uint), err) + break + } + height, err2 := strconv.Atoi(args[1]) + if err2 != nil { + break + } + + log.Printf("Fake resize %dx%d", width, height) + err2 = con.dockerClient.ContainerResize(context.TODO(), containers[0].ID, container.ResizeOptions{Height: uint(height), Width: uint(width)}) + if err2 != nil { + log.Printf("Failed to resize container to %dx%d: %s", width, height, err) } // hijacked, err2 = con.dockerClient.ContainerAttach(context.TODO(), containers[0].ID, container.AttachOptions{Stream: true, Stdin: true, Stdout: true, Stderr: true})