diff --git a/go.mod b/go.mod index abd029e2..f5a7d2ee 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect github.com/blacknon/crypto11 v1.2.7 // indirect - github.com/blacknon/go-sshlib v0.1.16 + github.com/blacknon/go-sshlib v0.1.17 github.com/blacknon/go-x11auth v0.1.0 // indirect github.com/blacknon/textcol v0.0.1 github.com/c-bata/go-prompt v0.2.6 diff --git a/go.sum b/go.sum index 88d4ef5a..001c54de 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,8 @@ github.com/blacknon/go-nfs-sshlib v0.0.3 h1:tq83kTZibrr99/GCn0pqkJhmBTDMupL/eMI3 github.com/blacknon/go-nfs-sshlib v0.0.3/go.mod h1:jaCmHgFoj8j08rGrBnhJ4nFO7nUWs4xFrUd2vEPwyx8= github.com/blacknon/go-prompt v0.2.7 h1:dVdTqVplKvpT/k4bB9BlbcBYl/k6amYX5tvjYBmuKkI= github.com/blacknon/go-prompt v0.2.7/go.mod h1:zNBmC/BPAyr+3ey1oRhPxuXJS9zz1lEmJpwaoQroe3w= -github.com/blacknon/go-sshlib v0.1.16 h1:de5KXEYalMzknPWwSbKEr/Z3CxgOfMyiQC5+sfzYwLg= -github.com/blacknon/go-sshlib v0.1.16/go.mod h1:upfnjVHf/Lh7ysT3dU1ziHKtzRQ1J62JyrShZ7FlNSI= +github.com/blacknon/go-sshlib v0.1.17 h1:iEMIeYsAJLigapB61i4D3VpdOnFboWpztob0ufhmkhQ= +github.com/blacknon/go-sshlib v0.1.17/go.mod h1:DN5Vkl/FpEzVxGoS0p8uBsBoHpVywiHbALr9UxcfJxw= github.com/blacknon/go-x11auth v0.1.0 h1:SnljCPWcvglWeGAlKc1RAPMHnOfMpM9+GrTGEUQ1lqQ= github.com/blacknon/go-x11auth v0.1.0/go.mod h1:SKOCa19LluXHyB+OaLYobquzceE0SWxVW7e/qU5xGBM= github.com/blacknon/textcol v0.0.1 h1:x9h7yLPGyr8Pdz12XJ30h7Iz5mJlKd0CzfGYxhrmnk8= diff --git a/list/event.go b/list/event.go index 929fc98d..4e6a718c 100644 --- a/list/event.go +++ b/list/event.go @@ -150,8 +150,9 @@ func (l *ListInfo) keyEvent() (lineData []string) { // mouse select line is (ev.MouseY - headLine) line. mouseSelectLine := ev.MouseY - headLine - if mouseSelectLine <= len(l.ViewText)-headLine { - l.CursorLine = mouseSelectLine + pageOffset := (l.CursorLine / height) * height + if mouseSelectLine >= 0 && mouseSelectLine < height && pageOffset+mouseSelectLine < len(l.ViewText) { + l.CursorLine = pageOffset + mouseSelectLine } l.draw() } diff --git a/ssh/connect.go b/ssh/connect.go index f55a2f8b..70a23371 100644 --- a/ssh/connect.go +++ b/ssh/connect.go @@ -10,6 +10,7 @@ import ( "github.com/blacknon/go-sshlib" "github.com/blacknon/lssh/conf" + "golang.org/x/crypto/ssh" "golang.org/x/net/proxy" ) @@ -98,7 +99,15 @@ func (r *Run) CreateSshConnect(server string) (connect *sshlib.Connect, err erro err = connect.CreateClient(s.Addr, s.Port, s.User, r.serverAuthMethodMap[server]) - return + if err != nil { + if client, ok := dialer.(*ssh.Client); ok { + client.Close() + } + + return nil, err + } + + return connect, nil } // proxy struct diff --git a/vendor/github.com/blacknon/go-sshlib/connect.go b/vendor/github.com/blacknon/go-sshlib/connect.go index 2d6d2e51..d4affedb 100644 --- a/vendor/github.com/blacknon/go-sshlib/connect.go +++ b/vendor/github.com/blacknon/go-sshlib/connect.go @@ -6,6 +6,7 @@ package sshlib import ( "context" + "errors" "io" "log" "net" @@ -190,29 +191,29 @@ func (c *Connect) SendKeepAlive(session *ssh.Session) { interval = c.SendKeepAliveInterval } - for { - // timeout channel - tc := make(chan bool, 1) - - go func() { - // Send keep alive packet - _, err := session.SendRequest("keepalive", true, nil) - if err == nil { - tc <- true - } - }() + t := time.NewTicker(time.Duration(c.ConnectTimeout) * time.Second) + defer t.Stop() + for { select { - case <-tc: - case <-time.After(time.Duration(c.ConnectTimeout) * time.Second): - session.Close() - c.Client.Close() - log.Println("keepalive timeout") - return + case <-t.C: + if _, err := session.SendRequest("keepalive@openssh.com", true, nil); err != nil { + if !errors.Is(err, io.EOF) { + log.Println("Failed to send keepalive packet:", err) + session.Close() + c.Client.Close() + break + } else { + // sleep + time.Sleep(time.Duration(interval) * time.Second) + continue + } + } else { + // sleep + time.Sleep(time.Duration(interval) * time.Second) + continue + } } - - // sleep - time.Sleep(time.Duration(interval) * time.Second) } } diff --git a/vendor/github.com/blacknon/go-sshlib/nfs_forward.go b/vendor/github.com/blacknon/go-sshlib/nfs_forward.go index 54e4fd55..5653817d 100644 --- a/vendor/github.com/blacknon/go-sshlib/nfs_forward.go +++ b/vendor/github.com/blacknon/go-sshlib/nfs_forward.go @@ -5,7 +5,9 @@ package sshlib import ( + "fmt" "net" + "strings" nfs "github.com/blacknon/go-nfs-sshlib" nfshelper "github.com/blacknon/go-nfs-sshlib/helpers" @@ -26,6 +28,14 @@ func (c *Connect) NFSForward(address, port, basepoint string) (err error) { return } + // create abs path + homepoint, err := client.RealPath(".") + if err != nil { + return + } + basepoint = getRemoteAbsPath(homepoint, basepoint) + fmt.Println(basepoint) + sftpfsPlusChange := NewChangeSFTPFS(client, basepoint) handler := nfshelper.NewNullAuthHandler(sftpfsPlusChange) @@ -58,3 +68,12 @@ func (c *Connect) NFSReverseForward(address, port, sharepoint string) (err error return } + +func getRemoteAbsPath(wdpath, path string) (result string) { + result = strings.Replace(path, "~", wdpath, 1) + if !strings.HasPrefix(result, "/") { + result = wdpath + "/" + result + } + + return result +} diff --git a/vendor/github.com/blacknon/go-sshlib/nfs_sftpfs.go b/vendor/github.com/blacknon/go-sshlib/nfs_sftpfs.go index 45ae926a..da8b6b93 100644 --- a/vendor/github.com/blacknon/go-sshlib/nfs_sftpfs.go +++ b/vendor/github.com/blacknon/go-sshlib/nfs_sftpfs.go @@ -5,6 +5,7 @@ package sshlib import ( + "fmt" "os" "path/filepath" "strconv" @@ -47,30 +48,25 @@ type SFTPFS struct { // Create func (fs *SFTPFS) Create(filename string) (billy.File, error) { - _, err := fs.Stat(filename) - if err == nil { - return nil, os.ErrExist - } - - dir := filepath.Dir(filename) - err = fs.MkdirAll(dir, os.ModeDir) - if err != nil { - return nil, err - } - - f, err := fs.Client.Create(filename) - if err != nil { - return nil, err - } - return &sftpFile{File: f}, nil + return fs.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) } // OpenFile func (fs *SFTPFS) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error) { - // TODO: create dirをする - // https://github.com/src-d/go-billy/blob/master/osfs/os.go#L31-L54 + return fs.openFile(filename, flag, perm, fs.createDir) +} + +func (fs *SFTPFS) openFile(fn string, flag int, perm os.FileMode, createDir func(string) error) (billy.File, error) { + if flag&os.O_CREATE != 0 { + if createDir == nil { + return nil, fmt.Errorf("createDir func cannot be nil if file needs to be opened in create mode") + } + if err := createDir(fn); err != nil { + return nil, err + } + } - f, err := fs.Client.OpenFile(filename, flag) + f, err := fs.Client.OpenFile(fn, flag) if err != nil { return nil, err } diff --git a/vendor/github.com/blacknon/go-sshlib/proxy.go b/vendor/github.com/blacknon/go-sshlib/proxy.go index 59eb0a17..732cedf5 100644 --- a/vendor/github.com/blacknon/go-sshlib/proxy.go +++ b/vendor/github.com/blacknon/go-sshlib/proxy.go @@ -191,6 +191,12 @@ func (n *NetPipe) Dial(network, addr string) (con net.Conn, err error) { // Start the command err = n.Cmd.Start() + // Close the write end of the pipe + go func() { + n.Cmd.Wait() + srv.Close() + }() + return } diff --git a/vendor/modules.txt b/vendor/modules.txt index 3fc60ccb..c743bb41 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -25,7 +25,7 @@ github.com/blacknon/crypto11 github.com/blacknon/go-nfs-sshlib github.com/blacknon/go-nfs-sshlib/file github.com/blacknon/go-nfs-sshlib/helpers -# github.com/blacknon/go-sshlib v0.1.16 +# github.com/blacknon/go-sshlib v0.1.17 ## explicit; go 1.22.4 github.com/blacknon/go-sshlib # github.com/blacknon/go-x11auth v0.1.0