Skip to content

Commit a1e3ae7

Browse files
authored
Merge pull request #21 from TNK-Studio/dev
[FIX] fix resize window #20
2 parents a10c29d + bfbe397 commit a1e3ae7

File tree

12 files changed

+48
-30
lines changed

12 files changed

+48
-30
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ bin/
1919
debug
2020
__debug_bin
2121
vendor/*
22-
!vendor/vendor.json
22+
!vendor/vendor.json
23+
./volumes

core/jump/g.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/TNK-Studio/gortal/core/sshd"
1212
"github.com/TNK-Studio/gortal/utils"
1313
"github.com/TNK-Studio/gortal/utils/logger"
14-
"github.com/gliderlabs/ssh"
14+
"github.com/elfgzp/ssh"
1515
gossh "golang.org/x/crypto/ssh"
1616
)
1717

core/pui/g.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/TNK-Studio/gortal/core/sshd"
77
"github.com/TNK-Studio/gortal/utils/logger"
88
"github.com/elfgzp/promptui"
9-
"github.com/gliderlabs/ssh"
9+
"github.com/elfgzp/ssh"
1010
)
1111

1212
// PUI pui

core/pui/menu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66

77
"github.com/TNK-Studio/gortal/config"
88
"github.com/TNK-Studio/gortal/core/sshd"
9-
"github.com/gliderlabs/ssh"
9+
"github.com/elfgzp/ssh"
1010
gossh "golang.org/x/crypto/ssh"
1111
)
1212

core/pui/server.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/TNK-Studio/gortal/utils"
1414
"github.com/TNK-Studio/gortal/utils/logger"
1515
"github.com/elfgzp/promptui"
16-
"github.com/gliderlabs/ssh"
16+
"github.com/elfgzp/ssh"
1717
)
1818

1919
// AddServer add server to config
@@ -258,13 +258,8 @@ func GetServerSSHUsersMenu(server *config.Server) func(int, *MenuItem, *ssh.Sess
258258
Label: sshUser.SSHUsername,
259259
Info: info,
260260
SelectedFunc: func(index int, menuItem *MenuItem, sess *ssh.Session, selectedChain []*MenuItem) error {
261-
err := sshd.Connect(
262-
server.Host,
263-
server.Port,
264-
sshUser.SSHUsername,
265-
sshUser.IdentityFile,
266-
sess,
267-
)
261+
262+
err := sshd.NewTerminal(server, sshUser, sess)
268263
if err != nil {
269264
return err
270265
}

core/pui/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/TNK-Studio/gortal/utils"
1010
"github.com/TNK-Studio/gortal/utils/logger"
1111
"github.com/elfgzp/promptui"
12-
"github.com/gliderlabs/ssh"
12+
"github.com/elfgzp/ssh"
1313
)
1414

1515
// CreateUser new user

core/sshd/scp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/TNK-Studio/gortal/config"
1414
"github.com/TNK-Studio/gortal/utils"
15-
"github.com/gliderlabs/ssh"
15+
"github.com/elfgzp/ssh"
1616
gossh "golang.org/x/crypto/ssh"
1717
)
1818

core/sshd/sshd.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ go 1.12
55
require (
66
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 // indirect
77
github.com/elfgzp/promptui v0.6.1-0.20191206043126-fe9f1cb63392
8+
github.com/elfgzp/ssh v0.2.3-0.20191216171309-38f1cb660799
89
github.com/fatih/color v1.7.0
910
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
10-
github.com/gliderlabs/ssh v0.2.2
11+
github.com/gliderlabs/ssh v0.2.2 // indirect
1112
github.com/helloyi/go-sshclient v0.0.0-20191203124208-f1e205501005
1213
github.com/manifoldco/promptui v0.6.0 // indirect
1314
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1919
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2020
github.com/elfgzp/promptui v0.6.1-0.20191206043126-fe9f1cb63392 h1:x0R9W3lhJkGM/IUU4rdMde20xYtSmFg9dE8lSJAqAsY=
2121
github.com/elfgzp/promptui v0.6.1-0.20191206043126-fe9f1cb63392/go.mod h1:BTKy3EDcFMT26Db0eodL+dqBYHC6YU+uV5esJ9uKUjU=
22+
github.com/elfgzp/ssh v0.2.3-0.20191216164622-8b19b11c3f60 h1:htwrZ6vsjDLQ2kEdOch7Xjqolg6E1NFl8tZwTDWQ1KQ=
23+
github.com/elfgzp/ssh v0.2.3-0.20191216164622-8b19b11c3f60/go.mod h1:v3RDlhmPwxWky2XAjOSnK0XrWX0hNhU/qlY+kwT9gJc=
24+
github.com/elfgzp/ssh v0.2.3-0.20191216171309-38f1cb660799 h1:x51xIMCxP2lqyTKlfCF0JvSmAJnb4fuM0QZHDWMC7Gs=
25+
github.com/elfgzp/ssh v0.2.3-0.20191216171309-38f1cb660799/go.mod h1:v3RDlhmPwxWky2XAjOSnK0XrWX0hNhU/qlY+kwT9gJc=
2226
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
2327
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
2428
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=

0 commit comments

Comments
 (0)