mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt ssh
This commit is contained in:
parent
e5dade2619
commit
5d485bb0dd
@ -85,9 +85,9 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func SignalNotify(m *ice.Message, sig int, cb func()) {
|
||||
func SignalNotify(m *ice.Message, sig syscall.Signal, cb func()) {
|
||||
ch := make(chan os.Signal)
|
||||
signal.Notify(ch, syscall.Signal(sig))
|
||||
signal.Notify(ch, sig)
|
||||
m.Go(func() {
|
||||
for {
|
||||
if _, ok := <-ch; ok {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
@ -85,7 +86,7 @@ func _ssh_dial(m *ice.Message, cb func(net.Conn), arg ...string) {
|
||||
s.RequestPty(kit.Env(cli.TERM), h, w, ssh.TerminalModes{ssh.ECHO: 1, ssh.TTY_OP_ISPEED: 14400, ssh.TTY_OP_OSPEED: 14400})
|
||||
defer s.Wait()
|
||||
|
||||
gdb.SignalNotify(m, 28, func() {
|
||||
gdb.SignalNotify(m, syscall.SIGWINCH, func() {
|
||||
w, h, _ := terminal.GetSize(int(os.Stdin.Fd()))
|
||||
s.WindowChange(h, w)
|
||||
})
|
||||
@ -132,7 +133,7 @@ func _ssh_conn(m *ice.Message, cb func(*ssh.Client), arg ...string) {
|
||||
}))
|
||||
|
||||
m.Cmdy(tcp.CLIENT, tcp.DIAL, mdb.TYPE, SSH, mdb.NAME, m.Option(tcp.HOST), m.OptionSimple(tcp.HOST, tcp.PORT), arg, func(c net.Conn) {
|
||||
conn, chans, reqs, err := ssh.NewClientConn(c, m.Option(tcp.HOST)+":"+m.Option(tcp.PORT), &ssh.ClientConfig{
|
||||
conn, chans, reqs, err := ssh.NewClientConn(c, m.Option(tcp.HOST)+ice.DF+m.Option(tcp.PORT), &ssh.ClientConfig{
|
||||
User: m.Option(aaa.USERNAME), Auth: methods, BannerCallback: func(message string) error { return nil },
|
||||
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil },
|
||||
})
|
||||
@ -148,9 +149,8 @@ func init() {
|
||||
psh.Index.MergeCommands(ice.Commands{
|
||||
CONNECT: {Name: "connect name auto", Help: "连接", Actions: ice.MergeActions(ice.Actions{
|
||||
tcp.OPEN: {Name: "open authfile username=shy password verfiy host=shylinux.com port=22 private=.ssh/id_rsa", Help: "终端", Hand: func(m *ice.Message, arg ...string) {
|
||||
aaa.UserRoot(m)
|
||||
defer m.Echo("exit %s@%s:%s\n", m.Option(aaa.USERNAME), m.Option(tcp.HOST), m.Option(tcp.PORT))
|
||||
_ssh_open(nfs.OptionLoad(m, m.Option("authfile")), arg...)
|
||||
m.Echo("exit %s@%s:%s\n", m.Option(aaa.USERNAME), m.Option(tcp.HOST), m.Option(tcp.PORT))
|
||||
}},
|
||||
tcp.DIAL: {Name: "dial name=shylinux host=shylinux.com port=22 username=shy private=.ssh/id_rsa", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Go(func() {
|
||||
@ -176,7 +176,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
}},
|
||||
}, mdb.HashStatusAction(mdb.SHORT, "name", mdb.FIELD, "time,name,status,username,host,port")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashStatusAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,status,username,host,port")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...).Tables(func(value ice.Maps) {
|
||||
m.PushButton(kit.Select("", "command,session", value[mdb.STATUS] == tcp.OPEN), mdb.REMOVE)
|
||||
}); len(arg) == 0 {
|
||||
|
@ -24,29 +24,29 @@ const RSA = "rsa"
|
||||
|
||||
func init() {
|
||||
aaa.Index.MergeCommands(ice.Commands{
|
||||
RSA: {Name: "rsa hash auto", Help: "公钥", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.IMPORT: {Name: "import key=.ssh/id_rsa pub=.ssh/id_rsa.pub", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf(m.PrefixKey(), kit.Keys(mdb.HASH, path.Base(m.Option("key"))), kit.Data(mdb.TIME, m.Time(),
|
||||
"title", kit.Format("%s@%s", ice.Info.UserName, ice.Info.HostName),
|
||||
PRIVATE, m.Cmdx(nfs.CAT, kit.HomePath(m.Option("key"))),
|
||||
PUBLIC, m.Cmdx(nfs.CAT, kit.HomePath(m.Option("pub"))),
|
||||
))
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export key=.ssh/id_rsa pub=.ssh/id_rsa.pub", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(m.PrefixKey(), m.Option(mdb.HASH), func(value ice.Maps) {
|
||||
m.Cmdx(nfs.SAVE, kit.HomePath(m.Option("key")), value[PRIVATE])
|
||||
m.Cmdx(nfs.SAVE, kit.HomePath(m.Option("pub")), value[PUBLIC])
|
||||
})
|
||||
}},
|
||||
RSA: {Name: "rsa hash auto", Help: "密钥", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create bits=2048,4096 title=some", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if key, err := rsa.GenerateKey(rand.Reader, kit.Int(m.Option("bits"))); m.Assert(err) {
|
||||
if pub, err := ssh.NewPublicKey(key.Public()); m.Assert(err) {
|
||||
m.Cmdy(mdb.INSERT, m.PrefixKey(), "", mdb.HASH, m.OptionSimple("title"), PUBLIC, string(ssh.MarshalAuthorizedKey(pub)),
|
||||
mdb.HashCreate(m, m.OptionSimple("title"), PUBLIC, string(ssh.MarshalAuthorizedKey(pub)),
|
||||
PRIVATE, string(pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)})),
|
||||
)
|
||||
}
|
||||
}
|
||||
}},
|
||||
mdb.EXPORT: {Name: "export key=.ssh/id_rsa pub=.ssh/id_rsa.pub", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, m.Option(mdb.HASH)).Tables(func(value ice.Maps) {
|
||||
m.Cmdx(nfs.SAVE, kit.HomePath(m.Option("key")), value[PRIVATE])
|
||||
m.Cmdx(nfs.SAVE, kit.HomePath(m.Option("pub")), value[PUBLIC])
|
||||
})
|
||||
}},
|
||||
mdb.IMPORT: {Name: "import key=.ssh/id_rsa pub=.ssh/id_rsa.pub", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf("", kit.Keys(mdb.HASH, path.Base(m.Option("key"))), kit.Data(mdb.TIME, m.Time(),
|
||||
"title", kit.Format("%s@%s", ice.Info.UserName, ice.Info.HostName),
|
||||
PRIVATE, m.Cmdx(nfs.CAT, kit.HomePath(m.Option("key"))),
|
||||
PUBLIC, m.Cmdx(nfs.CAT, kit.HomePath(m.Option("pub"))),
|
||||
))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.HASH, mdb.FIELD, "time,hash,title,public,private")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...).PushAction(mdb.EXPORT, mdb.REMOVE); len(arg) == 0 {
|
||||
m.Action(mdb.CREATE, mdb.IMPORT)
|
||||
|
@ -112,6 +112,7 @@ func _ssh_prepare(m *ice.Message, channel ssh.Channel, requests <-chan *ssh.Requ
|
||||
if err := ssh.Unmarshal(request.Payload, &env); err != nil {
|
||||
continue
|
||||
}
|
||||
m.Debug("what %v", env)
|
||||
list = append(list, env.Name+"="+env.Value)
|
||||
|
||||
case "shell":
|
||||
|
@ -6,7 +6,7 @@ refer `
|
||||
`
|
||||
|
||||
field "连接" ssh.connect
|
||||
field "通道" ssh.channel
|
||||
field "会话" ssh.session
|
||||
field "服务" ssh.service
|
||||
field "通道" ssh.channel
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user