diff --git a/etc/cvim.txt b/etc/cvim.txt new file mode 100644 index 00000000..e0253c53 --- /dev/null +++ b/etc/cvim.txt @@ -0,0 +1,24 @@ +set showtabindices + +imap deleteChar +imap deleteForwardChar +imap deleteWord +imap beginningOfLine +imap deleteToEnd + +map w :tabnew +map m :tabnew +map t goToTab +map q goToTab +map p goToTab +map v nextTab +map c previousTab +map nextTab +map previousTab +map goBack +map goForward +map createTabbedHint + +map s scrollPageUp +map a :history +map e :tabnew google diff --git a/src/contexts/ctx.go b/src/contexts/ctx.go index 68ca75d0..b5cf8a7e 100644 --- a/src/contexts/ctx.go +++ b/src/contexts/ctx.go @@ -2029,6 +2029,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心", m.Echo(" %s %s\n", k, v.Format()) } } + if msg.callback != nil { + m.Color(31, "callback(1): %p\n", msg.callback) + } return } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index 0888d8e2..ad263486 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -679,21 +679,26 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{ nfs.io = m.Optionv("io").(net.Conn) nfs.hand = map[int]*ctx.Message{} nfs.send = make(chan *ctx.Message, 10) + m.Log("fuck", "send %p", nfs.send) nfs.recv = make(chan *ctx.Message, 10) go func() { for { select { 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" if msg.Hand { + m.Log("fuck", "send %p %v", nfs.send, msg.Meta) head, body = "result", "append" 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]) } 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]) - msg.Meta["detail"] = msg.Meta["detail"][1:] nfs.hand[m.Capi("nsend")] = msg msg.Option("send_code", m.Capi("nsend")) } @@ -723,16 +728,17 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{ var e error for msg, head, body := m.Sess("target"), "", ""; bio.Scan(); { line := bio.Text() + m.Log("fuck", "send %p %v", nfs.send, msg.Meta) m.Capi("nread", len(line)+1) if len(line) == 0 { 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")) nfs.recv <- msg } else { - m.Log("info", "%d send: %v %v", msg.Appendi("send_code"), msg.Meta[head], msg.Meta[body]) - h := nfs.hand[msg.Appendi("send_code")] + 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_code1")] h.Copy(msg, "result").Copy(msg, "append") h.Remote <- true } @@ -761,6 +767,8 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{ for { select { case msg := <-nfs.recv: + m.Log("fuck", "why %s %v", msg.Format(), msg.Meta) + 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 { sub.Start(fmt.Sprintf("file%d", m.Capi("nfile", 1)), "远程文件") return sub.Sess("target", m.Source()).Call(func(sub1 *ctx.Message) *ctx.Message { + sub.Log("fuck", "send") 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) + sub.Log("fuck", "send %v", ok) + m.Log("fuck", "send %p", nfs.send) + sub1.Remote = make(chan bool, 1) + sub.Log("info", "before send %d", len(nfs.send)) 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 }) }, m.Meta["detail"]) @@ -1295,12 +1307,14 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message { sub.Start(fmt.Sprintf("file%d", m.Capi("nfile", 1)), "远程文件") 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, _ := sub.Target().Server.(*NFS) + m.Log("fuck", "send %p", nfs.send) + sub1.Remote = make(chan bool, 1) + sub.Log("info", "before send %d", len(nfs.send)) 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 }) }, m.Meta["detail"]) diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index 814e3fd5..1f5bb741 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -18,10 +18,10 @@ type SSH struct { } func (ssh *SSH) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server { // {{{ - c.Caches = map[string]*ctx.Cache{} - c.Configs = map[string]*ctx.Config{ - "domains": &ctx.Config{Name: "domains", Value: "", Help: "主机数量"}, + c.Caches = map[string]*ctx.Cache{ + "hostname": &ctx.Cache{Name: "hostname", Value: "com", Help: "主机数量"}, } + c.Configs = map[string]*ctx.Config{} s := new(SSH) 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 { // {{{ + ssh.Message = m + ssh.Caches["hostname"] = &ctx.Cache{Name: "hostname", Value: "", Help: "主机数量"} if ssh.Context == Index { Pulse = m } @@ -100,7 +102,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", }, Configs: map[string]*ctx.Config{ "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.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) { // {{{ m.Sess("nfs").CallBack(true, func(sub *ctx.Message) *ctx.Message { sub.Target().Start(sub) - // sub.Spawn().Cmd("pwd", m.Conf("domain")) + sub.Spawn().Cmd("pwd", m.Conf("hostname")) return sub }, m.Meta["detail"]) } @@ -136,10 +138,54 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", "send": &ctx.Command{Name: "send [domain str] cmd arg...", Help: "远程执行", Form: map[string]int{"domain": 1}, 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) { // {{{ - 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) + m.Log("why", "send %s", ssh.Message.Format()) ssh.Message.Back(msg) + m.Copy(msg, "result").Copy(msg, "append") return 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) { + 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) { // {{{ case 0: m.Echo(m.Cap("domain")) diff --git a/src/contexts/tcp/tcp.go b/src/contexts/tcp/tcp.go index 9423473b..f06f628d 100644 --- a/src/contexts/tcp/tcp.go +++ b/src/contexts/tcp/tcp.go @@ -96,7 +96,7 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool { // {{{ m.Assert(e) msg := m.Spawn(Index).Put("option", "io", c).Put("option", "source", m.Source()) 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")) } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 005fecf1..721e758b 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -920,6 +920,14 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", 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") + } + } + }}, }, }