made arguments a string

This commit is contained in:
ACoolName 2024-05-28 00:27:54 +03:00
parent 0beda28e3e
commit 8b3c830bab

View File

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