From 9c69a78ee91f873a8113397cab79cd9e07ef93fa Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 26 Nov 2020 21:49:36 +0800 Subject: [PATCH] opt ssh.connect --- base/ssh/connect.go | 29 ++++++++++++++++++++++++----- core/code/compile.go | 1 + core/code/install.go | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/base/ssh/connect.go b/base/ssh/connect.go index 9f5a5fb6..d7a0373f 100644 --- a/base/ssh/connect.go +++ b/base/ssh/connect.go @@ -12,6 +12,7 @@ import ( "golang.org/x/crypto/ssh/terminal" "encoding/json" + "io" "net" "os" "path" @@ -30,25 +31,26 @@ func _ssh_conn(m *ice.Message, conn net.Conn, username, hostport string) (*ssh.C default: } } - m.Debug("question: %v res: %d", questions, len(res)) return })) methods = append(methods, ssh.PublicKeysCallback(func() ([]ssh.Signer, error) { key, err := ssh.ParsePrivateKey([]byte(m.Cmdx(nfs.CAT, path.Join(os.Getenv("HOME"), m.Option("private"))))) - m.Debug("publickeys") return []ssh.Signer{key}, err })) methods = append(methods, ssh.PasswordCallback(func() (string, error) { - m.Debug("password") return m.Option(aaa.PASSWORD), nil })) c, chans, reqs, err := ssh.NewClientConn(conn, hostport, &ssh.ClientConfig{ - User: username, Auth: methods, HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { + User: username, Auth: methods, + HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { m.Logs(CONNECT, tcp.HOSTNAME, hostname, tcp.HOSTPORT, remote.String()) return nil }, + BannerCallback: func(message string) error { + return nil + }, }) return ssh.NewClient(c, chans, reqs), err @@ -109,6 +111,7 @@ func init() { } m.Option(tcp.DIAL_CB, func(c net.Conn) { + pr, pw := io.Pipe() client, e := _ssh_conn(m, c, m.Option(aaa.USERNAME), m.Option(tcp.HOST)+":"+m.Option(tcp.PORT)) m.Assert(e) @@ -132,7 +135,18 @@ func init() { } defer terminal.Restore(fd1, oldState1) - session.Stdin = os.Stdin + m.Go(func() { + go func() { + buf := make([]byte, 1024) + for { + if n, e := os.Stdin.Read(buf); m.Assert(e) { + pw.Write(buf[:n]) + } + } + }() + }) + + session.Stdin = pr session.Stdout = os.Stdout session.Stderr = os.Stderr @@ -144,6 +158,11 @@ func init() { session.RequestPty(os.Getenv("TERM"), h, w, modes) session.Shell() + for _, k := range []string{"one", "two"} { + if m.Sleep("100ms"); m.Option(k) != "" { + pw.Write([]byte(m.Option(k) + "\n")) + } + } session.Wait() }) diff --git a/core/code/compile.go b/core/code/compile.go index 1af93f73..e97299a8 100644 --- a/core/code/compile.go +++ b/core/code/compile.go @@ -69,6 +69,7 @@ func init() { m.Copy(msg) } else { m.Log_EXPORT("source", main, "target", file) + m.Push(kit.MDB_TIME, m.Time()) m.PushRender(kit.MDB_LINK, "download", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/publish/"+path.Base(file))) m.Echo(file) } diff --git a/core/code/install.go b/core/code/install.go index c53d7bd4..010732b2 100644 --- a/core/code/install.go +++ b/core/code/install.go @@ -62,7 +62,7 @@ func init() { // 下载 m.Go(func() { - m.Option(cli.CMD_DIR, m.Conf(INSTALL, kit.META_PATH)) + os.MkdirAll(m.Option(cli.CMD_DIR, m.Conf(INSTALL, kit.META_PATH)), ice.MOD_DIR) msg := m.Cmd(web.SPIDE, web.SPIDE_DEV, web.SPIDE_CACHE, web.SPIDE_GET, link) m.Cmdy(nfs.LINK, p, msg.Append(kit.MDB_FILE))