|
|
|
@ -5,6 +5,7 @@ import (
@@ -5,6 +5,7 @@ import (
|
|
|
|
|
"errors" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"log" |
|
|
|
|
"os" |
|
|
|
|
"os/exec" |
|
|
|
|
"path" |
|
|
|
@ -59,18 +60,25 @@ func NewPortal(name string, address string, command []string) (*Portal, error) {
@@ -59,18 +60,25 @@ func NewPortal(name string, address string, command []string) (*Portal, error) {
|
|
|
|
|
if len(command) > 1 { |
|
|
|
|
args = command[1:] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cmd := exec.CommandContext(cmdCtx, command[0], args...) |
|
|
|
|
|
|
|
|
|
cmd.Env = append(sshSession.Environ(), fmt.Sprintf("TERM=%s", ptyReq.Term)) |
|
|
|
|
|
|
|
|
|
stderr, err := cmd.StderrPipe() |
|
|
|
|
if err != nil { |
|
|
|
|
log.Printf("error: failed to create stderr pipe for portal %s: %s", name, err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
go func() { |
|
|
|
|
io.Copy(sshSession.Stderr(), stderr) |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
f, err := pty.Start(cmd) |
|
|
|
|
if err != nil { |
|
|
|
|
io.WriteString(sshSession, fmt.Sprintf("failed to start command: failed to initialize pseudo-terminal: %s\n", err)) |
|
|
|
|
sshSession.Exit(1) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
defer f.Close() |
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
for win := range winCh { |
|
|
|
|
setWinsize(f, win.Width, win.Height) |
|
|
|
@ -82,6 +90,7 @@ func NewPortal(name string, address string, command []string) (*Portal, error) {
@@ -82,6 +90,7 @@ func NewPortal(name string, address string, command []string) (*Portal, error) {
|
|
|
|
|
}() |
|
|
|
|
io.Copy(sshSession, f) |
|
|
|
|
|
|
|
|
|
f.Close() |
|
|
|
|
cmd.Wait() |
|
|
|
|
}, |
|
|
|
|
PtyCallback: func(ctx ssh.Context, pty ssh.Pty) bool { |
|
|
|
|