1
0
forked from x/icebergs

opt ssh.connect

This commit is contained in:
shaoying 2020-11-26 21:49:36 +08:00
parent 9163417dbd
commit 9c69a78ee9
3 changed files with 26 additions and 6 deletions

View File

@ -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()
})

View File

@ -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)
}

View File

@ -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))