Skip to content

Commit

Permalink
Merge pull request #21 from TNK-Studio/dev
Browse files Browse the repository at this point in the history
[FIX] fix resize window #20
  • Loading branch information
elfgzp authored Dec 16, 2019
2 parents a10c29d + bfbe397 commit a1e3ae7
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ bin/
debug
__debug_bin
vendor/*
!vendor/vendor.json
!vendor/vendor.json
./volumes
2 changes: 1 addition & 1 deletion core/jump/g.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/TNK-Studio/gortal/core/sshd"
"github.com/TNK-Studio/gortal/utils"
"github.com/TNK-Studio/gortal/utils/logger"
"github.com/gliderlabs/ssh"
"github.com/elfgzp/ssh"
gossh "golang.org/x/crypto/ssh"
)

Expand Down
2 changes: 1 addition & 1 deletion core/pui/g.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/TNK-Studio/gortal/core/sshd"
"github.com/TNK-Studio/gortal/utils/logger"
"github.com/elfgzp/promptui"
"github.com/gliderlabs/ssh"
"github.com/elfgzp/ssh"
)

// PUI pui
Expand Down
2 changes: 1 addition & 1 deletion core/pui/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/TNK-Studio/gortal/config"
"github.com/TNK-Studio/gortal/core/sshd"
"github.com/gliderlabs/ssh"
"github.com/elfgzp/ssh"
gossh "golang.org/x/crypto/ssh"
)

Expand Down
11 changes: 3 additions & 8 deletions core/pui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/TNK-Studio/gortal/utils"
"github.com/TNK-Studio/gortal/utils/logger"
"github.com/elfgzp/promptui"
"github.com/gliderlabs/ssh"
"github.com/elfgzp/ssh"
)

// AddServer add server to config
Expand Down Expand Up @@ -258,13 +258,8 @@ func GetServerSSHUsersMenu(server *config.Server) func(int, *MenuItem, *ssh.Sess
Label: sshUser.SSHUsername,
Info: info,
SelectedFunc: func(index int, menuItem *MenuItem, sess *ssh.Session, selectedChain []*MenuItem) error {
err := sshd.Connect(
server.Host,
server.Port,
sshUser.SSHUsername,
sshUser.IdentityFile,
sess,
)

err := sshd.NewTerminal(server, sshUser, sess)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/pui/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/TNK-Studio/gortal/utils"
"github.com/TNK-Studio/gortal/utils/logger"
"github.com/elfgzp/promptui"
"github.com/gliderlabs/ssh"
"github.com/elfgzp/ssh"
)

// CreateUser new user
Expand Down
2 changes: 1 addition & 1 deletion core/sshd/scp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/TNK-Studio/gortal/config"
"github.com/TNK-Studio/gortal/utils"
"github.com/gliderlabs/ssh"
"github.com/elfgzp/ssh"
gossh "golang.org/x/crypto/ssh"
)

Expand Down
43 changes: 30 additions & 13 deletions core/sshd/sshd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/TNK-Studio/gortal/utils"
"github.com/TNK-Studio/gortal/utils/logger"
"github.com/fatih/color"
"github.com/gliderlabs/ssh"
"github.com/elfgzp/ssh"
"github.com/helloyi/go-sshclient"
gossh "golang.org/x/crypto/ssh"
)
Expand All @@ -30,23 +30,40 @@ func GetClientByPasswd(username, host string, port int, passwd string) (*sshclie
return client, nil
}

// Connect connect server
func Connect(host string, port int, username string, privKeyFile string, sess *ssh.Session) error {
client, err := sshclient.DialWithKey(
fmt.Sprintf("%s:%d", host, port),
username,
utils.FilePath(privKeyFile),
)
// NewTerminal NewTerminal
func NewTerminal(server *config.Server, sshUser *config.SSHUser, sess *ssh.Session) error {
upstreamClient, err := NewSSHClient(server, sshUser)
if err != nil {
return nil
}

upstreamSess, err := upstreamClient.NewSession()
if err != nil {
return err
return nil
}
defer upstreamSess.Close()

// default terminal
upstreamSess.Stdout = *sess
upstreamSess.Stdin = *sess
upstreamSess.Stderr = *sess

terminal := client.Terminal(nil)
terminal = terminal.SetStdio(*sess, *sess, *sess)
if terminal.Start(); err != nil {
pty, winCh, _ := (*sess).Pty()

if err := upstreamSess.RequestPty(pty.Term, pty.Window.Height, pty.Window.Width, pty.TerminalModes); err != nil {
return err
}

if err := upstreamSess.Shell(); err != nil {
return err
}

go func () {
for win := range winCh {
upstreamSess.WindowChange(win.Height, win.Width)
}
}()

if err := upstreamSess.Wait(); err != nil {
return err
}

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ go 1.12
require (
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 // indirect
github.com/elfgzp/promptui v0.6.1-0.20191206043126-fe9f1cb63392
github.com/elfgzp/ssh v0.2.3-0.20191216171309-38f1cb660799
github.com/fatih/color v1.7.0
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
github.com/gliderlabs/ssh v0.2.2
github.com/gliderlabs/ssh v0.2.2 // indirect
github.com/helloyi/go-sshclient v0.0.0-20191203124208-f1e205501005
github.com/manifoldco/promptui v0.6.0 // indirect
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elfgzp/promptui v0.6.1-0.20191206043126-fe9f1cb63392 h1:x0R9W3lhJkGM/IUU4rdMde20xYtSmFg9dE8lSJAqAsY=
github.com/elfgzp/promptui v0.6.1-0.20191206043126-fe9f1cb63392/go.mod h1:BTKy3EDcFMT26Db0eodL+dqBYHC6YU+uV5esJ9uKUjU=
github.com/elfgzp/ssh v0.2.3-0.20191216164622-8b19b11c3f60 h1:htwrZ6vsjDLQ2kEdOch7Xjqolg6E1NFl8tZwTDWQ1KQ=
github.com/elfgzp/ssh v0.2.3-0.20191216164622-8b19b11c3f60/go.mod h1:v3RDlhmPwxWky2XAjOSnK0XrWX0hNhU/qlY+kwT9gJc=
github.com/elfgzp/ssh v0.2.3-0.20191216171309-38f1cb660799 h1:x51xIMCxP2lqyTKlfCF0JvSmAJnb4fuM0QZHDWMC7Gs=
github.com/elfgzp/ssh v0.2.3-0.20191216171309-38f1cb660799/go.mod h1:v3RDlhmPwxWky2XAjOSnK0XrWX0hNhU/qlY+kwT9gJc=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/TNK-Studio/gortal/core/sshd"
"github.com/TNK-Studio/gortal/utils"
"github.com/TNK-Studio/gortal/utils/logger"
"github.com/gliderlabs/ssh"
"github.com/elfgzp/ssh"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion utils/func.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utils

import "github.com/gliderlabs/ssh"
import "github.com/elfgzp/ssh"

// If If
func If(condition bool, trueVal, falseVal interface{}) interface{} {
Expand Down

0 comments on commit a1e3ae7

Please sign in to comment.