1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

tce opt ssh

This commit is contained in:
shaoying 2018-08-03 19:03:26 +08:00
parent a468b18bb8
commit cf7f1a0056
6 changed files with 134 additions and 21 deletions

24
etc/cvim.txt Normal file
View File

@ -0,0 +1,24 @@
set showtabindices
imap <C-h> deleteChar
imap <C-d> deleteForwardChar
imap <C-w> deleteWord
imap <C-a> beginningOfLine
imap <C-k> deleteToEnd
map w :tabnew
map m :tabnew
map t goToTab
map q goToTab
map p goToTab
map v nextTab
map c previousTab
map <C-j> nextTab
map <C-k> previousTab
map <C-o> goBack
map <C-i> goForward
map <C-f> createTabbedHint
map s scrollPageUp
map a :history
map e :tabnew google

View File

@ -2029,6 +2029,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
m.Echo(" %s %s\n", k, v.Format()) m.Echo(" %s %s\n", k, v.Format())
} }
} }
if msg.callback != nil {
m.Color(31, "callback(1): %p\n", msg.callback)
}
return return
} }

View File

@ -679,21 +679,26 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
nfs.io = m.Optionv("io").(net.Conn) nfs.io = m.Optionv("io").(net.Conn)
nfs.hand = map[int]*ctx.Message{} nfs.hand = map[int]*ctx.Message{}
nfs.send = make(chan *ctx.Message, 10) nfs.send = make(chan *ctx.Message, 10)
m.Log("fuck", "send %p", nfs.send)
nfs.recv = make(chan *ctx.Message, 10) nfs.recv = make(chan *ctx.Message, 10)
go func() { go func() {
for { for {
select { select {
case msg := <-nfs.send: case msg := <-nfs.send:
m.Log("fuck", "send %p %v", nfs.send, msg.Meta)
m.Log("fuck", "send %p %v", nfs.send, msg.Meta)
head, body := "detail", "option" head, body := "detail", "option"
if msg.Hand { if msg.Hand {
m.Log("fuck", "send %p %v", nfs.send, msg.Meta)
head, body = "result", "append" head, body = "result", "append"
send_code := msg.Option("send_code") send_code := msg.Option("send_code")
msg.Append("send_code", send_code) msg.Append("send_code1", send_code)
m.Log("info", "%s recv: %v %v", msg.Option("recv_code"), msg.Meta[head], msg.Meta[body]) m.Log("info", "%s recv: %v %v", msg.Option("recv_code"), msg.Meta[head], msg.Meta[body])
} else { } else {
m.Log("fuck", "send %p %v", nfs.send, msg.Meta)
m.Log("fuck", "send %p %v", nfs.send, msg.Meta)
m.Log("info", "%d send: %v %v", m.Capi("nsend", 1), msg.Meta[head], msg.Meta[body]) m.Log("info", "%d send: %v %v", m.Capi("nsend", 1), msg.Meta[head], msg.Meta[body])
msg.Meta["detail"] = msg.Meta["detail"][1:]
nfs.hand[m.Capi("nsend")] = msg nfs.hand[m.Capi("nsend")] = msg
msg.Option("send_code", m.Capi("nsend")) msg.Option("send_code", m.Capi("nsend"))
} }
@ -723,16 +728,17 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
var e error var e error
for msg, head, body := m.Sess("target"), "", ""; bio.Scan(); { for msg, head, body := m.Sess("target"), "", ""; bio.Scan(); {
line := bio.Text() line := bio.Text()
m.Log("fuck", "send %p %v", nfs.send, msg.Meta)
m.Capi("nread", len(line)+1) m.Capi("nread", len(line)+1)
if len(line) == 0 { if len(line) == 0 {
if head == "detail" { if head == "detail" {
m.Log("info", "%d recv: %v %v", m.Capi("nrecv", 1), msg.Meta[head], msg.Meta[body]) m.Log("info", "%d recv: %v %v %v", m.Capi("nrecv", 1), msg.Meta[head], msg.Meta[body], msg.Meta)
msg.Option("recv_code", m.Cap("nrecv")) msg.Option("recv_code", m.Cap("nrecv"))
nfs.recv <- msg nfs.recv <- msg
} else { } else {
m.Log("info", "%d send: %v %v", msg.Appendi("send_code"), msg.Meta[head], msg.Meta[body]) m.Log("info", "%d send: %v %v %v", msg.Appendi("send_code1"), msg.Meta[head], msg.Meta[body], msg.Meta)
h := nfs.hand[msg.Appendi("send_code")] h := nfs.hand[msg.Appendi("send_code1")]
h.Copy(msg, "result").Copy(msg, "append") h.Copy(msg, "result").Copy(msg, "append")
h.Remote <- true h.Remote <- true
} }
@ -761,6 +767,8 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
for { for {
select { select {
case msg := <-nfs.recv: case msg := <-nfs.recv:
m.Log("fuck", "why %s %v", msg.Format(), msg.Meta)
nfs.send <- msg.Cmd() nfs.send <- msg.Cmd()
} }
} }
@ -1278,12 +1286,16 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message { m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message {
sub.Start(fmt.Sprintf("file%d", m.Capi("nfile", 1)), "远程文件") sub.Start(fmt.Sprintf("file%d", m.Capi("nfile", 1)), "远程文件")
return sub.Sess("target", m.Source()).Call(func(sub1 *ctx.Message) *ctx.Message { return sub.Sess("target", m.Source()).Call(func(sub1 *ctx.Message) *ctx.Message {
sub.Log("fuck", "send")
nfs, ok := sub.Target().Server.(*NFS) nfs, ok := sub.Target().Server.(*NFS)
m.Log("fuck", "why%v", sub.Format()) sub.Log("fuck", "send %v", ok)
m.Log("fuck", "why%v", ok) m.Log("fuck", "send %p", nfs.send)
m.Remote = make(chan bool, 1) sub1.Remote = make(chan bool, 1)
sub.Log("info", "before send %d", len(nfs.send))
nfs.send <- sub1 nfs.send <- sub1
<-m.Remote sub.Log("info", "middle send %d", len(nfs.send))
<-sub1.Remote
sub.Log("info", "after send %d", len(nfs.send))
return nil return nil
}) })
}, m.Meta["detail"]) }, m.Meta["detail"])
@ -1295,12 +1307,14 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message { m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message {
sub.Start(fmt.Sprintf("file%d", m.Capi("nfile", 1)), "远程文件") sub.Start(fmt.Sprintf("file%d", m.Capi("nfile", 1)), "远程文件")
return sub.Sess("target", m.Source()).Call(func(sub1 *ctx.Message) *ctx.Message { return sub.Sess("target", m.Source()).Call(func(sub1 *ctx.Message) *ctx.Message {
nfs, ok := sub.Target().Server.(*NFS) nfs, _ := sub.Target().Server.(*NFS)
m.Log("fuck", "why%v", sub.Format()) m.Log("fuck", "send %p", nfs.send)
m.Log("fuck", "why%v", ok) sub1.Remote = make(chan bool, 1)
m.Remote = make(chan bool, 1) sub.Log("info", "before send %d", len(nfs.send))
nfs.send <- sub1 nfs.send <- sub1
<-m.Remote sub.Log("info", "middle send %d", len(nfs.send))
<-sub1.Remote
sub.Log("info", "after send %d", len(nfs.send))
return nil return nil
}) })
}, m.Meta["detail"]) }, m.Meta["detail"])

View File

@ -18,10 +18,10 @@ type SSH struct {
} }
func (ssh *SSH) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server { // {{{ func (ssh *SSH) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server { // {{{
c.Caches = map[string]*ctx.Cache{} c.Caches = map[string]*ctx.Cache{
c.Configs = map[string]*ctx.Config{ "hostname": &ctx.Cache{Name: "hostname", Value: "com", Help: "主机数量"},
"domains": &ctx.Config{Name: "domains", Value: "", Help: "主机数量"},
} }
c.Configs = map[string]*ctx.Config{}
s := new(SSH) s := new(SSH)
s.Context = c s.Context = c
@ -30,6 +30,8 @@ func (ssh *SSH) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
// }}} // }}}
func (ssh *SSH) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{ func (ssh *SSH) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
ssh.Message = m
ssh.Caches["hostname"] = &ctx.Cache{Name: "hostname", Value: "", Help: "主机数量"}
if ssh.Context == Index { if ssh.Context == Index {
Pulse = m Pulse = m
} }
@ -100,7 +102,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}, },
Configs: map[string]*ctx.Config{ Configs: map[string]*ctx.Config{
"interval": &ctx.Config{Name: "interval", Value: "3", Help: "主机数量"}, "interval": &ctx.Config{Name: "interval", Value: "3", Help: "主机数量"},
"domain": &ctx.Config{Name: "domain", Value: "com", Help: "主机数量"}, "hostname": &ctx.Config{Name: "hostname", Value: "host", Help: "主机数量"},
"domain.json": &ctx.Config{Name: "domain.json", Value: "var/domain.json", Help: "主机数量"}, "domain.json": &ctx.Config{Name: "domain.json", Value: "var/domain.json", Help: "主机数量"},
"domain.png": &ctx.Config{Name: "domain.png", Value: "var/domain.png", Help: "主机数量"}, "domain.png": &ctx.Config{Name: "domain.png", Value: "var/domain.png", Help: "主机数量"},
@ -127,7 +129,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
if _, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{ if _, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
m.Sess("nfs").CallBack(true, func(sub *ctx.Message) *ctx.Message { m.Sess("nfs").CallBack(true, func(sub *ctx.Message) *ctx.Message {
sub.Target().Start(sub) sub.Target().Start(sub)
// sub.Spawn().Cmd("pwd", m.Conf("domain")) sub.Spawn().Cmd("pwd", m.Conf("hostname"))
return sub return sub
}, m.Meta["detail"]) }, m.Meta["detail"])
} }
@ -136,10 +138,54 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"send": &ctx.Command{Name: "send [domain str] cmd arg...", Help: "远程执行", "send": &ctx.Command{Name: "send [domain str] cmd arg...", Help: "远程执行",
Form: map[string]int{"domain": 1}, Form: map[string]int{"domain": 1},
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
m.Log("why", "send")
if ssh, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{ if ssh, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
msg := m.Spawn() if m.Options("domain") {
find := false
host := strings.SplitN(m.Option("domain"), ".", 2)
m.Travel(func(m *ctx.Message, i int) bool {
if i > 0 {
if m.Cap("hostname") == host[0] {
ssh, ok := m.Target().Server.(*SSH)
m.Assert(ok)
msg := m.Spawn(ssh.Message.Source())
if len(host) > 1 {
msg.Option("domain", host[1])
msg.Detail("send", arg)
} else {
msg.Detail(arg)
}
m.Log("why", "send")
m.Log("why", "send %s", ssh.Message.Format())
ssh.Message.Back(msg)
m.Copy(msg, "result").Copy(msg, "append")
find = true
}
}
return true
}, c)
if !find && m.Cap("domain") != "com" {
ssh, ok := c.Server.(*SSH)
m.Assert(ok)
msg := m.Spawn(ssh.Message.Source())
msg.Option("domain", m.Option("domain"))
m.Log("why", "send------ %s", c.Name)
msg.Detail("send", arg)
m.Log("why", "send %s", ssh.Message.Format())
ssh.Message.Back(msg)
m.Copy(msg, "result").Copy(msg, "append")
find = true
}
return
}
msg := m.Spawn(ssh.Message.Source())
m.Log("why", "send")
msg.Detail(arg) msg.Detail(arg)
m.Log("why", "send %s", ssh.Message.Format())
ssh.Message.Back(msg) ssh.Message.Back(msg)
m.Copy(msg, "result").Copy(msg, "append")
return return
if m.Option("domain") == m.Cap("domain") { //本地命令 if m.Option("domain") == m.Cap("domain") { //本地命令
@ -208,6 +254,24 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
// }}} // }}}
}}, }},
"pwd": &ctx.Command{Name: "pwd", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { "pwd": &ctx.Command{Name: "pwd", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
if len(arg) == 0 {
if m.Target() == c {
m.Echo(m.Cap("domain"))
} else {
m.Echo("%s.%s", m.Cap("domain"), m.Cap("hostname"))
}
return
}
if m.Target() == c {
msg := m.Spawn().Cmd("send", "pwd", arg[0])
m.Copy(msg, "result").Copy(msg, "append")
m.Cap("domain", msg.Result(0))
} else if m.Options("send_code") {
m.Echo("%s.%s", m.Cap("domain"), m.Cap("hostname", arg[0]))
}
return
switch len(arg) { // {{{ switch len(arg) { // {{{
case 0: case 0:
m.Echo(m.Cap("domain")) m.Echo(m.Cap("domain"))

View File

@ -96,7 +96,7 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool { // {{{
m.Assert(e) m.Assert(e)
msg := m.Spawn(Index).Put("option", "io", c).Put("option", "source", m.Source()) msg := m.Spawn(Index).Put("option", "io", c).Put("option", "source", m.Source())
msg.Call(func(com *ctx.Message) *ctx.Message { msg.Call(func(com *ctx.Message) *ctx.Message {
return com return com.Spawn(m.Source())
}, "accept", c.RemoteAddr().String(), m.Cap("security"), m.Cap("protocol")) }, "accept", c.RemoteAddr().String(), m.Cap("security"), m.Cap("protocol"))
} }

View File

@ -920,6 +920,14 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
m.Spawn().Cmd("open", url) m.Spawn().Cmd("open", url)
} }
}}, }},
"add_income": &ctx.Command{Name: "add_income", Help: "浏览器网页", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
// for _, uid := range []string{"98010402293", "96287507642", "98896063791", "98683626189", "95780886494", "95780886494", "98629824072"} {
for _, uid := range []string{"97661734361"} {
for t := 1530777074000; t < 1533268176000; t += 172800000 {
m.Spawn().Cmd("5", "teacher_uid", uid, "valid_time", t, "description_public", "hello")
}
}
}},
}, },
} }