From 8f125bbd3a353ba981324fd1e74f7ae464b81794 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 19 Aug 2018 21:31:41 +0800 Subject: [PATCH] tce opt web.share --- src/contexts/aaa/aaa.go | 60 +++++++------- src/contexts/ctx.go | 8 ++ src/contexts/web/web.go | 139 +++++++++++++++++++++++++++------ usr/template/common/login.html | 47 +++++------ 4 files changed, 175 insertions(+), 79 deletions(-) diff --git a/src/contexts/aaa/aaa.go b/src/contexts/aaa/aaa.go index 52a03312..ca7c4916 100644 --- a/src/contexts/aaa/aaa.go +++ b/src/contexts/aaa/aaa.go @@ -74,7 +74,7 @@ func (aaa *AAA) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server "expire": &ctx.Cache{Name: "expire", Value: fmt.Sprintf("%d", int64(m.Confi("expire"))+time.Now().Unix()), Help: "会话超时"}, } c.Configs = map[string]*ctx.Config{ - "lark": &ctx.Config{Name: "lark", Value: []interface{}{}, Help: "用户密码,加密存储"}, + "lark": &ctx.Config{Name: "lark", Value: map[string]interface{}{}, Help: "用户密码,加密存储"}, } s := new(AAA) @@ -110,13 +110,12 @@ func (aaa *AAA) Start(m *ctx.Message, arg ...string) bool { // {{{ for { msg := <-aaa.lark + from := msg.Option("username") m.Log("lark", "%v", msg.Meta["detail"]) m.Travel(func(m *ctx.Message, n int) bool { if m.Cap("username") == msg.Detail(1) { - m.Confv("lark", -2, map[string]interface{}{ - "from": msg.Option("username"), - "time": msg.Time(), - "text": msg.Detail(2)}) + m.Confv("lark", strings.Join([]string{from, "-2"}, "."), + map[string]interface{}{"time": msg.Time(), "type": "recv", "text": msg.Detail(2)}) } return true }) @@ -657,31 +656,38 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", "lark": &ctx.Command{Name: "lark who message", Help: "散列", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { if aaa, ok := c.Server.(*AAA); m.Assert(ok) && aaa.lark != nil { // {{{ - switch len(arg) { - case 0: - m.Travel(func(m *ctx.Message, n int) bool { - if n > 0 { - m.Add("append", "user", m.Cap("username")) - } + m.Travel(func(m *ctx.Message, n int) bool { + if n == 0 { return true - }, c) - case 1: - m.Travel(func(m *ctx.Message, n int) bool { - if m.Cap("username") == arg[0] { - for _, v := range m.Confv("lark").([]interface{}) { - lark := v.(map[string]interface{}) - m.Add("append", "time", lark["time"]) - m.Add("append", "from", lark["from"]) - m.Add("append", "text", lark["text"]) + } + if m.Cap("username") == m.Option("username") { + switch len(arg) { + case 0: + for k, v := range m.Confv("lark").(map[string]interface{}) { + for _, x := range v.([]interface{}) { + val := x.(map[string]interface{}) + m.Add("append", "friend", k) + m.Add("append", "time", val["time"]) + m.Add("append", "type", val["type"]) + m.Add("append", "text", val["text"]) + } } - return false + case 1: + for _, v := range m.Confv("lark", arg[0]).([]interface{}) { + val := v.(map[string]interface{}) + m.Add("append", "time", val["time"]) + m.Add("append", "text", val["text"]) + } + case 2: + m.Confv("lark", strings.Join([]string{arg[0], "-2"}, "."), + map[string]interface{}{"time": m.Time(), "type": "send", "text": arg[1]}) + aaa.lark <- m + m.Echo("%s send done", m.Time()) } - return true - }, c) - case 2: - aaa.lark <- m - m.Echo("%s send done", m.Time()) - } + return false + } + return true + }) } // }}} }}, diff --git a/src/contexts/ctx.go b/src/contexts/ctx.go index 9d57edcd..61785f59 100644 --- a/src/contexts/ctx.go +++ b/src/contexts/ctx.go @@ -200,6 +200,12 @@ func Chain(m *Message, data interface{}, args ...interface{}) interface{} { // { value[index] = args[i+1] } } + switch p := parent.(type) { + case map[string]interface{}: + p[parent_key] = value + case []interface{}: + p[parent_index] = value + } parent, data, parent_index = value, value[index], index } @@ -1622,9 +1628,11 @@ func (m *Message) Confv(key string, args ...interface{}) interface{} { // {{{ x.Value = args[0] default: for i := 0; i < len(args); i += 2 { + m.Log("fuck", "b %v", x.Value) if i < len(args)-1 { x.Value = Chain(m, x.Value, args[i], args[i+1]) } + m.Log("fuck", "b %v", x.Value) if i == len(args)-2 { return Chain(m, x.Value, args[len(args)-2]) } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 9fb172ad..00faecbd 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -277,10 +277,11 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", "nroute": &ctx.Cache{Name: "nroute", Value: "0", Help: "路由数量"}, }, Configs: map[string]*ctx.Config{ - "cmd": &ctx.Config{Name: "cmd", Value: "tmux", Help: "路由数量"}, - "cert": &ctx.Config{Name: "cert", Value: "etc/cert.pem", Help: "路由数量"}, - "key": &ctx.Config{Name: "key", Value: "etc/key.pem", Help: "路由数量"}, - "root_index": &ctx.Config{Name: "root_index(true/false)", Value: "true", Help: "路由数量"}, + "cmd": &ctx.Config{Name: "cmd", Value: "tmux", Help: "路由数量"}, + "cert": &ctx.Config{Name: "cert", Value: "etc/cert.pem", Help: "路由数量"}, + "key": &ctx.Config{Name: "key", Value: "etc/key.pem", Help: "路由数量"}, + "root_index": &ctx.Config{Name: "root_index(true/false)", Value: "true", Help: "路由数量"}, + "auto_create": &ctx.Config{Name: "auto_create(true/false)", Value: "true", Help: "路由数量"}, "check": &ctx.Config{Name: "check", Value: map[string]interface{}{ "login": []interface{}{ map[string]interface{}{ @@ -313,6 +314,12 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", map[string]interface{}{ "template": "userinfo", "title": "userinfo", }, + map[string]interface{}{ + "from": "root", "to": []interface{}{}, + "module": "aaa", "command": "lark", + "argument": []interface{}{}, + "template": "append", "title": "lark_friend", + }, map[string]interface{}{ "module": "aaa", "detail": []interface{}{"lark"}, "template": "detail", "title": "send_lark", @@ -328,82 +335,81 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", "argument": []interface{}{"dir_type", "all", "dir_deep", "false", "dir_field", "time size line filename", "sort_field", "time", "sort_order", "time_r"}, "template": "append", "title": "", }, - map[string]interface{}{ - "template": "upload", "title": "upload", - }, - map[string]interface{}{ - "template": "create", "title": "create", - }, - map[string]interface{}{ - "module": "nfs", "detail": []interface{}{"pwd"}, - "template": "detail", "title": "pwd", - }, }, "shy": []interface{}{ map[string]interface{}{ + "from": "root", "to": []interface{}{"duyu", "haojie"}, "template": "userinfo", "title": "userinfo", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "aaa", "command": "lark", "argument": []interface{}{}, "template": "append", "title": "lark_friend", }, map[string]interface{}{ - "module": "aaa", "command": "lark", - "argument": []interface{}{"shy"}, - "template": "append", "title": "lark", - }, - map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "aaa", "detail": []interface{}{"lark"}, "template": "detail", "title": "send_lark", "option": map[string]interface{}{"ninput": 2}, }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "web", "command": "/share", "argument": []interface{}{}, "template": "share", "title": "share", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "cli", "command": "system", "argument": []interface{}{"tmux", "list-clients"}, "template": "result", "title": "client", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "cli", "command": "system", "argument": []interface{}{"tmux", "list-sessions"}, "template": "result", "title": "session", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "cli", "command": "system", "argument": []interface{}{"tmux", "show-buffer"}, "template": "result", "title": "buffer", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "nfs", "command": "git", "argument": []interface{}{}, "template": "result", "title": "git", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "nfs", "command": "dir", "argument": []interface{}{"dir_type", "all", "dir_deep", "false", "dir_field", "time size line filename", "sort_field", "time", "sort_order", "time_r"}, "template": "append", "title": "", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "template": "upload", "title": "upload", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "template": "create", "title": "create", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "nfs", "detail": []interface{}{"pwd"}, "template": "detail", "title": "pwd", }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "cli", "detail": []interface{}{"time"}, "template": "detail", "title": "time", "option": map[string]interface{}{"ninput": 1}, }, map[string]interface{}{ + "from": "root", "to": []interface{}{}, "module": "nfs", "detail": []interface{}{"json"}, "template": "detail", "title": "json", "option": map[string]interface{}{"ninput": 1}, @@ -1024,17 +1030,91 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", m.Copy(check, "append") return } + m.Option("username", m.Append("username")) - if m.Options("friend") && m.Options("module") { - m.Copy(m.Appendv("aaa").(*ctx.Message).Find(m.Option("module")).Cmd("right", m.Option("friend"), m.Option("action"), m.Optionv("share")), "result") - if m.Confv("index", m.Option("friend")) == nil { - m.Confv("index", m.Option("friend"), m.Confv("index", m.Append("username"))) + // if m.Options("friend") && m.Options("module") { + // m.Copy(m.Appendv("aaa").(*ctx.Message).Find(m.Option("module")).Cmd("right", m.Option("friend"), m.Option("action"), m.Optionv("share")), "result") + // if m.Confv("index", m.Option("friend")) == nil { + // m.Confv("index", m.Option("friend"), m.Confv("index", m.Append("username"))) + // } + // return + // } + // + // msg := m.Spawn().Cmd("right", "target", m.Option("module"), m.Append("username"), "show", "context") + // m.Copy(msg, "append") + if m.Options("friend") && m.Options("template") && m.Options("title") { + for i, v := range m.Confv("index", m.Option("username")).([]interface{}) { + if v == nil { + continue + } + val := v.(map[string]interface{}) + if val["template"].(string) == m.Option("template") && val["title"].(string) == m.Option("title") { + if m.Option("action") == "del" { + friends := m.Confv("index", strings.Join([]string{m.Option("username"), fmt.Sprintf("%d", i), "to"}, ".")).([]interface{}) + for j, x := range friends { + if x.(string) == m.Option("friend") { + m.Confv("index", strings.Join([]string{m.Option("username"), fmt.Sprintf("%d", i), "to", fmt.Sprintf("%d", j)}, "."), nil) + } + } + + temps := m.Confv("index", strings.Join([]string{m.Option("friend")}, ".")).([]interface{}) + for j, x := range temps { + if x == nil { + continue + } + val = x.(map[string]interface{}) + if val["template"].(string) == m.Option("template") && val["title"].(string) == m.Option("title") { + m.Confv("index", strings.Join([]string{m.Option("friend"), fmt.Sprintf("%d", j)}, "."), nil) + } + } + + break + } + + if m.Confv("index", m.Option("friend")) == nil && !m.Confs("auto_create") { + break + } + m.Confv("index", strings.Join([]string{m.Option("username"), fmt.Sprintf("%d", i), "to", "-2"}, "."), m.Option("friend")) + + item := map[string]interface{}{ + "template": val["template"], + "title": val["title"], + "from": m.Option("username"), + } + if val["command"] != nil { + item["module"] = val["module"] + item["command"] = val["command"] + item["argument"] = val["argument"] + } else if val["detail"] != nil { + item["module"] = val["module"] + item["detail"] = val["detail"] + item["option"] = val["option"] + } + + m.Confv("index", strings.Join([]string{m.Option("friend"), fmt.Sprintf("%d", -2)}, "."), item) + m.Appendv("aaa").(*ctx.Message).Spawn(c).Cmd("right", m.Option("friend"), "add", "command", "/index/", "dir", m.Cap("directory")) + os.Mkdir(path.Join(m.Cap("directory"), m.Option("friend")), 0666) + break + } } return } - - msg := m.Spawn().Cmd("right", "target", m.Option("module"), m.Append("username"), "show", "context") - m.Copy(msg, "append") + for _, v := range m.Confv("index", m.Option("username")).([]interface{}) { + val := v.(map[string]interface{}) + m.Add("append", "template", val["template"]) + m.Add("append", "titles", val["title"]) + m.Add("append", "from", val["from"]) + m.Add("append", "to", "") + if val["to"] == nil { + continue + } + for _, u := range val["to"].([]interface{}) { + m.Add("append", "template", val["template"]) + m.Add("append", "titles", val["title"]) + m.Add("append", "from", val["from"]) + m.Add("append", "to", u) + } + } // }}} }}, "/check": &ctx.Command{Name: "/check arg...", Help: "权限检查, cache|config|command: 接口类型, name: 接口名称, args: 其它参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) { @@ -1089,8 +1169,15 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", []byte{27, 91, 109}, []byte(""), } + if m.Confv("index", arg[0]) == nil { + arg[0] = "notice" + } + m.Assert(tpl.ExecuteTemplate(w, "head", m)) for _, v := range m.Confv("index", arg[0]).([]interface{}) { + if v == nil { + continue + } val := v.(map[string]interface{}) //命令模板 if detail, ok := val["detail"].([]interface{}); ok { diff --git a/usr/template/common/login.html b/usr/template/common/login.html index 99a4f37a..472887a7 100644 --- a/usr/template/common/login.html +++ b/usr/template/common/login.html @@ -30,10 +30,6 @@ {{define "share"}}
share -
- - -
{{$msg := .}} {{$ncol := append . |len}} @@ -44,7 +40,13 @@ {{range append $msg}} {{$value := append $msg . $row}}
- {{if eq . "value"}} + {{if eq . "to"}} + {{if eq $value ""}} + + {{else}} + {{$value}} + {{end}} + {{else if eq . "value"}} {{$value}} {{else}} {{$value}} @@ -56,34 +58,27 @@
{{end}}