1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-26 09:14:06 +08:00

mac pro ssh

This commit is contained in:
shaoying 2018-08-03 09:22:09 +08:00
parent 8059414c74
commit b157855067
5 changed files with 38 additions and 23 deletions

View File

@ -1,7 +1,8 @@
~shell1
login root root
source etc/local.shy
~file1
history load etc/history.txt
~shell1
alias import nfs
alias send send

View File

@ -626,8 +626,9 @@ func (m *Message) Sess(key string, arg ...interface{}) *Message { // {{{
// }}}
func (m *Message) Call(cb func(msg *Message) (sub *Message), arg ...interface{}) *Message { // {{{
m.callback = cb
if m.callback = cb; len(arg) > 0 || len(m.Meta["detail"]) > 0 {
m.Cmd(arg...)
}
return m
}

View File

@ -720,7 +720,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
go func() {
bio := bufio.NewScanner(nfs.io)
var e error
for msg, head, body := m.Spawn(), "", ""; bio.Scan(); {
for msg, head, body := m.Sess("target"), "", ""; bio.Scan(); {
line := bio.Text()
m.Capi("nread", len(line)+1)
if len(line) == 0 {
@ -735,7 +735,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
h.Copy(msg, "result").Copy(msg, "append")
h.Remote <- true
}
msg = m.Spawn()
msg = m.Sess("target")
continue
}
@ -1274,20 +1274,34 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
"listen": &ctx.Command{Name: "listen args...", Help: "启动文件服务, args: 参考tcp模块, listen命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if _, ok := m.Target().Server.(*NFS); m.Assert(ok) { //{{{
m.Sess("tcp").Call(func(com *ctx.Message) *ctx.Message {
sub := com.Spawn(c)
m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message {
sub.Start(fmt.Sprintf("file%d", m.Capi("nfile", 1)), "远程文件")
return sub
return sub.Sess("target", m.Source()).Call(func(sub1 *ctx.Message) *ctx.Message {
nfs, ok := sub.Target().Server.(*NFS)
m.Log("fuck", "why%v", sub.Format())
m.Log("fuck", "why%v", ok)
m.Remote = make(chan bool, 1)
nfs.send <- sub1
<-m.Remote
return nil
})
}, m.Meta["detail"])
}
// }}}
}},
"dial": &ctx.Command{Name: "dial args...", Help: "连接文件服务, args: 参考tcp模块, dial命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if _, ok := m.Target().Server.(*NFS); m.Assert(ok) { //{{{
m.Sess("tcp").Call(func(com *ctx.Message) *ctx.Message {
sub := com.Spawn(c)
m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message {
sub.Start(fmt.Sprintf("file%d", m.Capi("nfile", 1)), "远程文件")
return sub
return sub.Sess("target", m.Source()).Call(func(sub1 *ctx.Message) *ctx.Message {
nfs, ok := sub.Target().Server.(*NFS)
m.Log("fuck", "why%v", sub.Format())
m.Log("fuck", "why%v", ok)
m.Remote = make(chan bool, 1)
nfs.send <- sub1
<-m.Remote
return nil
})
}, m.Meta["detail"])
}
// }}}

View File

@ -46,6 +46,7 @@ func (ssh *SSH) Start(m *ctx.Message, arg ...string) bool { // {{{
// }}}
func (ssh *SSH) Close(m *ctx.Message, arg ...string) bool { // {{{
return false
switch ssh.Context {
case m.Target():
case m.Source():
@ -114,10 +115,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
Commands: map[string]*ctx.Command{
"listen": &ctx.Command{Name: "listen address protocol", Help: "监听连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if _, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
m.Find("nfs").Call(func(file *ctx.Message) *ctx.Message {
sub := file.Spawn(m.Target())
m.Sess("nfs").Call(func(sub *ctx.Message) *ctx.Message {
sub.Start(fmt.Sprintf("host%d", Pulse.Capi("nhost", 1)), "远程主机")
m.Sess("ssh", sub)
return sub
}, m.Meta["detail"])
m.Spawn(m.Target()).Cmd("save")
@ -126,13 +125,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}},
"dial": &ctx.Command{Name: "dial address protocol", Help: "建立连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if _, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
m.Find("nfs").CallBack(true, func(file *ctx.Message) *ctx.Message {
sub := file.Spawn(m.Target())
sub.Copy(m, "detail")
m.Sess("nfs").CallBack(true, func(sub *ctx.Message) *ctx.Message {
sub.Target().Start(sub)
m.Sess("ssh", sub)
sub.Spawn(sub.Target()).Cmd("pwd", m.Conf("domain"))
// sub.Spawn().Cmd("pwd", m.Conf("domain"))
return sub
}, m.Meta["detail"])
}
@ -142,6 +137,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
Form: map[string]int{"domain": 1},
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if ssh, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
msg := m.Spawn()
msg.Detail(arg)
ssh.Message.Back(msg)
return
if m.Option("domain") == m.Cap("domain") { //本地命令
msg := m.Spawn(m.Target())

View File

@ -62,7 +62,7 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool { // {{{
m.Log("info", "%s dial %s", m.Cap("nclient"),
m.Option("stream", m.Cap("stream", fmt.Sprintf("%s->%s", tcp.LocalAddr(), tcp.RemoteAddr()))))
m.Put("option", "io", tcp.Conn).Back(m)
m.Put("option", "io", tcp.Conn).Back(m.Spawn(m.Source()))
return false
case "accept":
c, e := m.Data["io"].(net.Conn)
@ -71,7 +71,7 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool { // {{{
m.Log("info", "%s accept %s", m.Cap("nclient"),
m.Option("stream", m.Cap("stream", fmt.Sprintf("%s<-%s", tcp.LocalAddr(), tcp.RemoteAddr()))))
m.Put("option", "io", tcp.Conn).Back(m)
m.Put("option", "io", tcp.Conn).Back(m.Spawn(m.Source()))
return false
default:
if m.Cap("security") != "false" {