Add initial width and height
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 19s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 19s
This commit is contained in:
43
.gitignore
vendored
Normal file
43
.gitignore
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
sshserver
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (uncomment if using dep or similar)
|
||||
# vendor/
|
||||
|
||||
# Go workspace file
|
||||
go.work
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# IDE files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Temporary files
|
||||
*.tmp
|
||||
|
||||
# SSH host key
|
||||
host_key
|
||||
22
main.go
22
main.go
@@ -95,15 +95,32 @@ func handleConn(conn net.Conn, config *ssh.ServerConfig) {
|
||||
func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) {
|
||||
defer channel.Close()
|
||||
var ptmx *os.File
|
||||
var termWidth, termHeight uint32 = 15, 15
|
||||
for req := range requests {
|
||||
switch req.Type {
|
||||
case "pty-req":
|
||||
if len(req.Payload) >= 8 {
|
||||
width := binary.BigEndian.Uint32(req.Payload[len(req.Payload)-8:])
|
||||
height := binary.BigEndian.Uint32(req.Payload[len(req.Payload)-4:])
|
||||
if width > 0 {
|
||||
termWidth = width
|
||||
}
|
||||
if height > 0 {
|
||||
termHeight = height
|
||||
}
|
||||
}
|
||||
req.Reply(true, nil)
|
||||
case "window-change":
|
||||
if ptmx != nil {
|
||||
width := binary.BigEndian.Uint32(req.Payload)
|
||||
height := binary.BigEndian.Uint32(req.Payload[4:])
|
||||
pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(width), Rows: uint16(height)})
|
||||
if width > 0 {
|
||||
termWidth = width
|
||||
}
|
||||
if height > 0 {
|
||||
termHeight = height
|
||||
}
|
||||
if ptmx != nil {
|
||||
pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)})
|
||||
}
|
||||
req.Reply(true, nil)
|
||||
case "shell":
|
||||
@@ -121,6 +138,7 @@ func handleChannel(channel ssh.Channel, requests <-chan *ssh.Request) {
|
||||
log.Println("PTY start error:", err)
|
||||
return
|
||||
}
|
||||
pty.Setsize(ptmx, &pty.Winsize{Cols: uint16(termWidth), Rows: uint16(termHeight)})
|
||||
go func() {
|
||||
defer ptmx.Close()
|
||||
go io.Copy(channel, ptmx)
|
||||
|
||||
Reference in New Issue
Block a user