@@ -79,7 +79,7 @@ type Server struct {
79
79
}
80
80
81
81
func (s * Server ) handler (sess ssh.Session ) {
82
- cmd , err := s .getCommand (sess )
82
+ cmd , payload , err := s .getCommand (sess )
83
83
if err != nil {
84
84
s .exitWithError (sess , errors .Wrap (err , "construct command" ))
85
85
return
@@ -98,9 +98,19 @@ func (s *Server) handler(sess ssh.Session) {
98
98
}
99
99
100
100
// start shell session
101
- ptyReq , winCh , isPty := sess .Pty ()
102
- if isPty && runtime .GOOS != "windows" {
103
- err = sshhelper .HandlePTY (sess , ptyReq , winCh , cmd , func (reader io.Reader ) io.Reader {
101
+ if payload .TTY && runtime .GOOS != "windows" {
102
+ winSizeChan := make (chan ssh.Window , 1 )
103
+ winSizeChan <- ssh.Window {
104
+ Width : payload .Width ,
105
+ Height : payload .Height ,
106
+ }
107
+ err = sshhelper .HandlePTY (sess , ssh.Pty {
108
+ Term : "xterm" ,
109
+ Window : ssh.Window {
110
+ Width : payload .Width ,
111
+ Height : payload .Height ,
112
+ },
113
+ }, winSizeChan , cmd , func (reader io.Reader ) io.Reader {
104
114
return reader
105
115
})
106
116
} else {
@@ -113,19 +123,19 @@ func (s *Server) handler(sess ssh.Session) {
113
123
s .exitWithError (sess , err )
114
124
}
115
125
116
- func (s * Server ) getCommand (sess ssh.Session ) (* exec.Cmd , error ) {
126
+ func (s * Server ) getCommand (sess ssh.Session ) (* exec.Cmd , * types. ProxyCommand , error ) {
117
127
var cmd * exec.Cmd
118
128
rawCommand := sess .RawCommand ()
119
129
if len (rawCommand ) == 0 {
120
- return nil , fmt .Errorf ("command required" )
130
+ return nil , nil , fmt .Errorf ("command required" )
121
131
}
122
132
123
133
command := & types.ProxyCommand {}
124
134
err := json .Unmarshal ([]byte (rawCommand ), & command )
125
135
if err != nil {
126
- return nil , fmt .Errorf ("parse command: %v" , err )
136
+ return nil , nil , fmt .Errorf ("parse command: %v" , err )
127
137
} else if len (command .Args ) == 0 {
128
- return nil , fmt .Errorf ("command is empty" )
138
+ return nil , nil , fmt .Errorf ("command is empty" )
129
139
}
130
140
131
141
var reverseCommand * latest.ProxyCommand
@@ -136,7 +146,7 @@ func (s *Server) getCommand(sess ssh.Session) (*exec.Cmd, error) {
136
146
}
137
147
}
138
148
if reverseCommand == nil {
139
- return nil , fmt .Errorf ("command not allowed" )
149
+ return nil , nil , fmt .Errorf ("command not allowed" )
140
150
}
141
151
142
152
c := reverseCommand .Command
@@ -168,7 +178,7 @@ func (s *Server) getCommand(sess ssh.Session) (*exec.Cmd, error) {
168
178
s .log .Debugf ("run command '%s %s' locally" , c , strings .Join (args , " " ))
169
179
cmd .Env = append (cmd .Env , command .Env ... )
170
180
cmd .Env = append (cmd .Env , os .Environ ()... )
171
- return cmd , nil
181
+ return cmd , command , nil
172
182
}
173
183
174
184
func (s * Server ) transformPath (originalPath string ) string {
0 commit comments