mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 09:34:05 +08:00
opt ssh.connect
This commit is contained in:
parent
9163417dbd
commit
9c69a78ee9
@ -12,6 +12,7 @@ import (
|
|||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -30,25 +31,26 @@ func _ssh_conn(m *ice.Message, conn net.Conn, username, hostport string) (*ssh.C
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Debug("question: %v res: %d", questions, len(res))
|
|
||||||
return
|
return
|
||||||
}))
|
}))
|
||||||
|
|
||||||
methods = append(methods, ssh.PublicKeysCallback(func() ([]ssh.Signer, error) {
|
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")))))
|
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
|
return []ssh.Signer{key}, err
|
||||||
}))
|
}))
|
||||||
methods = append(methods, ssh.PasswordCallback(func() (string, error) {
|
methods = append(methods, ssh.PasswordCallback(func() (string, error) {
|
||||||
m.Debug("password")
|
|
||||||
return m.Option(aaa.PASSWORD), nil
|
return m.Option(aaa.PASSWORD), nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
c, chans, reqs, err := ssh.NewClientConn(conn, hostport, &ssh.ClientConfig{
|
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())
|
m.Logs(CONNECT, tcp.HOSTNAME, hostname, tcp.HOSTPORT, remote.String())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
BannerCallback: func(message string) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
return ssh.NewClient(c, chans, reqs), err
|
return ssh.NewClient(c, chans, reqs), err
|
||||||
@ -109,6 +111,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.Option(tcp.DIAL_CB, func(c net.Conn) {
|
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))
|
client, e := _ssh_conn(m, c, m.Option(aaa.USERNAME), m.Option(tcp.HOST)+":"+m.Option(tcp.PORT))
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
|
|
||||||
@ -132,7 +135,18 @@ func init() {
|
|||||||
}
|
}
|
||||||
defer terminal.Restore(fd1, oldState1)
|
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.Stdout = os.Stdout
|
||||||
session.Stderr = os.Stderr
|
session.Stderr = os.Stderr
|
||||||
|
|
||||||
@ -144,6 +158,11 @@ func init() {
|
|||||||
|
|
||||||
session.RequestPty(os.Getenv("TERM"), h, w, modes)
|
session.RequestPty(os.Getenv("TERM"), h, w, modes)
|
||||||
session.Shell()
|
session.Shell()
|
||||||
|
for _, k := range []string{"one", "two"} {
|
||||||
|
if m.Sleep("100ms"); m.Option(k) != "" {
|
||||||
|
pw.Write([]byte(m.Option(k) + "\n"))
|
||||||
|
}
|
||||||
|
}
|
||||||
session.Wait()
|
session.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ func init() {
|
|||||||
m.Copy(msg)
|
m.Copy(msg)
|
||||||
} else {
|
} else {
|
||||||
m.Log_EXPORT("source", main, "target", file)
|
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.PushRender(kit.MDB_LINK, "download", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/publish/"+path.Base(file)))
|
||||||
m.Echo(file)
|
m.Echo(file)
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func init() {
|
|||||||
|
|
||||||
// 下载
|
// 下载
|
||||||
m.Go(func() {
|
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)
|
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))
|
m.Cmdy(nfs.LINK, p, msg.Append(kit.MDB_FILE))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user