@@ -11,7 +11,7 @@ import (
1111 "github.com/TNK-Studio/gortal/utils"
1212 "github.com/TNK-Studio/gortal/utils/logger"
1313 "github.com/fatih/color"
14- "github.com/gliderlabs /ssh"
14+ "github.com/elfgzp /ssh"
1515 "github.com/helloyi/go-sshclient"
1616 gossh "golang.org/x/crypto/ssh"
1717)
@@ -30,23 +30,40 @@ func GetClientByPasswd(username, host string, port int, passwd string) (*sshclie
3030 return client , nil
3131}
3232
33- // Connect connect server
34- func Connect (host string , port int , username string , privKeyFile string , sess * ssh.Session ) error {
35- client , err := sshclient .DialWithKey (
36- fmt .Sprintf ("%s:%d" , host , port ),
37- username ,
38- utils .FilePath (privKeyFile ),
39- )
33+ // NewTerminal NewTerminal
34+ func NewTerminal (server * config.Server , sshUser * config.SSHUser , sess * ssh.Session ) error {
35+ upstreamClient , err := NewSSHClient (server , sshUser )
36+ if err != nil {
37+ return nil
38+ }
4039
40+ upstreamSess , err := upstreamClient .NewSession ()
4141 if err != nil {
42- return err
42+ return nil
4343 }
44+ defer upstreamSess .Close ()
4445
45- // default terminal
46+ upstreamSess .Stdout = * sess
47+ upstreamSess .Stdin = * sess
48+ upstreamSess .Stderr = * sess
4649
47- terminal := client .Terminal (nil )
48- terminal = terminal .SetStdio (* sess , * sess , * sess )
49- if terminal .Start (); err != nil {
50+ pty , winCh , _ := (* sess ).Pty ()
51+
52+ if err := upstreamSess .RequestPty (pty .Term , pty .Window .Height , pty .Window .Width , pty .TerminalModes ); err != nil {
53+ return err
54+ }
55+
56+ if err := upstreamSess .Shell (); err != nil {
57+ return err
58+ }
59+
60+ go func () {
61+ for win := range winCh {
62+ upstreamSess .WindowChange (win .Height , win .Width )
63+ }
64+ }()
65+
66+ if err := upstreamSess .Wait (); err != nil {
5067 return err
5168 }
5269
0 commit comments