From 084d8797fbcdbd63fe1b46b028796d81f773bcd9 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sat, 23 Mar 2019 17:21:43 +0800 Subject: [PATCH] opt user&sess&work Change-Id: Iabe0d9f7f2153102d396e5c2fddf3e90f5c56f32 --- src/contexts/aaa/aaa.go | 221 +++++++++++++++++++++++------------ src/contexts/cli/cli.go | 15 ++- src/contexts/ctx/ctx_init.go | 11 +- src/contexts/gdb/gdb.go | 2 +- src/contexts/mdb/mdb.go | 48 +++++--- src/contexts/nfs/nfs.go | 36 +++--- src/contexts/ssh/ssh.go | 11 +- src/contexts/tcp/tcp.go | 7 ++ src/contexts/web/web.go | 81 +++++++------ src/examples/code/code.go | 4 +- usr/librarys/code.js | 12 +- usr/librarys/context.js | 11 +- 12 files changed, 279 insertions(+), 180 deletions(-) diff --git a/src/contexts/aaa/aaa.go b/src/contexts/aaa/aaa.go index 5e2a2648..9f31ad40 100644 --- a/src/contexts/aaa/aaa.go +++ b/src/contexts/aaa/aaa.go @@ -199,7 +199,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", case "data": if data := m.Confm("auth", []string{s, "data"}); data != nil { for _, k := range arg[2:] { - m.Log("info", "delete data %s %s %v", s, k, data[k]) + m.Log("info", "delete data %s %s %v", s, k, kit.Formats(data[k])) delete(data, k) } } @@ -213,10 +213,10 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", m.Add("append", "meta", val["meta"]) } - m.Log("info", "delete ship %s %s %v", s, k, ship[k]) + m.Log("info", "delete ship %s %s %v", s, k, kit.Formats(ship[k])) delete(ship, k) if peer := m.Confm("auth", []string{k, "ship"}); peer != nil { - m.Log("info", "delete ship %s %s %v", k, s, peer[s]) + m.Log("info", "delete ship %s %s %v", k, s, kit.Formats(peer[s])) delete(peer, s) } } @@ -232,14 +232,14 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", m.Add("append", "meta", val["meta"]) } - m.Log("info", "delete ship %s %s %v", s, k, ship[k]) + m.Log("info", "delete ship %s %s %v", s, k, kit.Formats(ship[k])) delete(ship, k) if peer := m.Confm("auth", []string{k, "ship"}); peer != nil { - m.Log("info", "delete ship %s %s %v", k, s, peer[s]) + m.Log("info", "delete ship %s %s %v", k, s, kit.Formats(peer[s])) delete(peer, s) } } - m.Log("info", "delete node %s %v", s, m.Confm("auth", s)) + m.Log("info", "delete node %s %v", s, kit.Formats(m.Confm("auth", s))) delete(m.Confm("auth"), s) m.Table() } @@ -356,10 +356,15 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", if arg[i] == "check" { has := "false" m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) { - if ship["meta"] == arg[i+1] { - if ship["expire_time"] == nil || int64(kit.Int(ship["expire_time"])) > time.Now().Unix() { - has = k - } + if i == len(arg)-2 && (ship["meta"] != arg[i+1] || k != arg[i+1]) { + return + } + if i == len(arg)-3 && (ship["type"] != arg[i+1] || ship["meta"] != arg[i+2]) { + return + } + + if ship["expire_time"] == nil || int64(kit.Int(ship["expire_time"])) > time.Now().Unix() { + has = k } }) m.Set("result").Echo(has) @@ -492,77 +497,103 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", } return }}, - "user": &ctx.Command{Name: "user [role username password] [username]", Help: "用户认证", - Auto: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) bool { - switch len(arg) { - case 0: // 查看用户 - Auto(m, "ship", "username") - case 1: // 查看会话 - Auto(m, "ship", "username", arg[0], "session") - } - return true - }, - Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - switch len(arg) { - case 0: // 查看用户 - m.Cmdy("aaa.auth", "ship", "username") - case 1: // 查看角色 - m.Cmdy("aaa.auth", "ship", "username", arg[0], "userrole") - case 2: // 查看会话 - m.Cmdy("aaa.auth", "ship", "username", arg[0], "session", arg[1]) - case 3: // 用户认证 - if (arg[1] == "password" || arg[1] == "uuid") && m.Cmds("aaa.auth", "ship", "username", arg[0]) { - m.Cmdy("aaa.auth", "username", arg[0], arg[1], arg[2]) - break - } - fallthrough - default: // 添加用户 - for i := 1; i < len(arg); i += 2 { - if m.Cmdy("aaa.auth", "ship", "username", arg[i], "userrole", arg[0]); i < len(arg)-1 { - m.Cmd("aaa.auth", "ship", "username", arg[i], "password", arg[i+1]) - } - } - } - return - }}, - "sess": &ctx.Command{Name: "sess [sessid [meta]|[username password password]]|[type ip ip]", Help: "会话管理", - Auto: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) bool { - switch len(arg) { - case 0: // 查看会话 - Auto(m, "ship", "session") - case 1: // 查看会话 - Auto(m, "ship", "session", arg[0]) - } - return true - }, - Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - if len(arg) > 0 && arg[0] == "current" { - switch len(arg) { - case 1: - m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current") - case 2: - m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current."+arg[1]) - default: - m.Cmd("aaa.auth", m.Option("sessid"), "data", "current."+arg[1], arg[2]) - m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current."+arg[1]) - } + "user": &ctx.Command{Name: "user [role username password] [username password|uuid code] [username [sesstype]]", Help: "用户认证, 添加、认证、查询", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if len(arg) > 0 && arg[0] == "session" { + if len(arg) == 1 { // 查看会话 + m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "session") return } - - switch len(arg) { - case 0: // 查看会话 - m.Cmdy("aaa.auth", "ship", "session") - case 1: // 查看会话 - m.Cmdy("aaa.auth", arg[0]) - case 2: // 查询会话 - m.Cmdy("aaa.auth", arg[0], "ship", arg[1]) - case 3: // 创建会话 - m.Cmdy("aaa.auth", "ship", "session", arg[0], arg[1], arg[2]) - case 4: // 用户登录 - m.Cmdy("aaa.auth", arg[0], "ship", "username", arg[1], arg[2], arg[3]) + switch arg[1] { + case "select": // 选择会话 + defer func() { m.Log("info", "sessid: %s", m.Append("key")) }() + if m.Options("sessid") && m.Cmds("aaa.auth", m.Option("sessid"), "ship", "check", "username", m.Option("username")) { + m.Add("append", "key", m.Option("sessid")).Table() + return + } + if m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "session"); m.Appends("key") { + return + } + fallthrough + case "create": // 创建会话 + m.Cmdy("aaa.auth", "ship", "session", kit.Select("web", arg, 2), "username", m.Option("username")) + m.Cmd("aaa.auth", m.Result(0), "data", "current.ctx", "mdb") } return - }}, + } + + switch len(arg) { + case 0: // 查看用户 + m.Cmdy("aaa.auth", "ship", "username") + case 1: // 查看角色 + m.Cmdy("aaa.auth", "ship", "username", arg[0], "userrole") + case 2: // 查看会话 + m.Cmdy("aaa.auth", "ship", "username", arg[0], "session", arg[1]) + case 3: // 用户认证 + if (arg[1] == "password" || arg[1] == "uuid") && m.Cmds("aaa.auth", "ship", "username", arg[0]) { + m.Cmdy("aaa.auth", "username", arg[0], arg[1], arg[2]) + break + } + fallthrough + default: // 添加用户 + for i := 1; i < len(arg); i += 2 { + if m.Cmdy("aaa.auth", "ship", "username", arg[i], "userrole", arg[0]); i < len(arg)-1 { + m.Cmd("aaa.auth", "ship", "username", arg[i], "password", arg[i+1]) + } + } + } + return + }}, + "sess": &ctx.Command{Name: "sess [sessid [meta]|[username password password]]|[type ip ip]", Help: "会话管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if len(arg) > 0 && arg[0] == "bench" { + if len(arg) == 1 { // 查看空间 + m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench") + return + } + switch arg[1] { + case "select": // 选择空间 + defer func() { m.Log("info", "bench: %s", m.Append("key")) }() + if m.Options("bench") && m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", m.Option("sessid")) { + m.Add("append", "key", m.Option("bench")).Table() + return + } + if m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench"); m.Appends("key") { + return + } + fallthrough + case "create": // 创建空间 + m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench", kit.Select("web", arg, 2)) + m.Cmd("aaa.auth", m.Result(0), "data", "name", "web") + } + return + } + + if len(arg) > 0 && arg[0] == "current" { + switch len(arg) { + case 1: + m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current") + case 2: + m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current."+arg[1]) + default: + m.Cmd("aaa.auth", m.Option("sessid"), "data", "current."+arg[1], arg[2]) + m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current."+arg[1]) + } + return + } + + switch len(arg) { + case 0: // 查看会话 + m.Cmdy("aaa.auth", "ship", "session") + case 1: // 查看会话 + m.Cmdy("aaa.auth", arg[0]) + case 2: // 查询会话 + m.Cmdy("aaa.auth", arg[0], "ship", arg[1]) + case 3: // 创建会话 + m.Cmdy("aaa.auth", "ship", "session", arg[0], arg[1], arg[2]) + case 4: // 用户登录 + m.Cmdy("aaa.auth", arg[0], "ship", "username", arg[1], arg[2], arg[3]) + } + return + }}, "work": &ctx.Command{Name: "work [sessid create|select]|[benchid] [right [username [componet name [command name [argument name]]]]]", Help: "工作任务", Auto: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (goon bool) { switch len(arg) { @@ -592,6 +623,42 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心", return true }, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if len(arg) > 0 && arg[0] == "right" { + // 查看权限 + if len(arg) == 1 { + m.Cmd("aaa.auth", m.Option("bench"), "ship", "componet").CopyTo(m, "append") + m.Cmd("aaa.auth", m.Option("bench"), "ship", "command").CopyTo(m, "append") + m.Table() + return + } + + // 检查权限 + m.Cmd("aaa.auth", "ship", "username", m.Option("username"), "userrole").Table(func(node map[string]string) { + if node["meta"] == "root" { // 超级用户 + m.Log("info", "root %s", m.Option("username")) + m.Echo("true") + } else if len(arg) > 2 { // 接口权限 + if m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", arg[2]) { + m.Echo("true") + } else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "componet", arg[1], "check", arg[2]); kit.Right(cid) { + m.Cmd("aaa.auth", m.Option("bench"), cid) + m.Echo("true") + } + } else if len(arg) > 1 { // 组件权限 + if m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", arg[1]) { + m.Echo("true") + } else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "check", arg[1]); kit.Right(cid) { + m.Cmd("aaa.auth", m.Option("bench"), cid) + m.Echo("true") + } + } + }) + + m.Log("right", "bench: %s sessid: %s user: %s com: %v result: %v", + m.Option("bench"), m.Option("sessid"), m.Option("username"), arg[2:], m.Result(0)) + return + } + if len(arg) == 0 { // 查看空间 m.Cmdy("aaa.auth", "ship", "bench") return diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index e134584a..c183cd35 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -230,8 +230,20 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", m.Table() return } + if m.Confm("daemon", arg[0], func(daemon map[string]interface{}) { if cmd, ok := daemon["cmd"].(*exec.Cmd); ok { + if len(arg) == 1 { + m.Add("append", "key", key) + m.Add("append", "create_time", daemon["create_time"]) + m.Add("append", "finish_time", daemon["finish_time"]) + m.Add("append", "pid", cmd.Process.Pid) + m.Add("append", "log", daemon["log"]) + m.Add("append", "cmd", kit.Select(cmd.Args[0], cmd.Args, 1)) + m.Table() + return + } + switch arg[1] { case "stop": cmd.Process.Kill() @@ -553,7 +565,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", // 管道命令 if len(rest) > 0 { - pipe := m.Spawn().Copy(msg, "option") + pipe := msg.Spawn() pipe.Copy(msg, "append").Copy(msg, "result").Cmd("cmd", rest) msg.Set("append").Copy(pipe, "append") msg.Set("result").Copy(pipe, "result") @@ -563,6 +575,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", for _, v := range exports { if v["file"] != "" { m.Sess("nfs").Copy(msg, "option").Copy(msg, "append").Copy(msg, "result").Cmd("export", v["file"]) + msg.Set("result") } if v["cache"] != "" { if v["index"] == "result" { diff --git a/src/contexts/ctx/ctx_init.go b/src/contexts/ctx/ctx_init.go index dcf1a83b..d3e8cc30 100644 --- a/src/contexts/ctx/ctx_init.go +++ b/src/contexts/ctx/ctx_init.go @@ -1234,11 +1234,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, } case string: m.Meta[m.Meta["expand"][j+1]][i] = val - case float64: - m.Meta[m.Meta["expand"][j+1]][i] = fmt.Sprintf("%d", int(val)) default: - b, _ := json.Marshal(val) - m.Meta[m.Meta["expand"][j+1]][i] = string(b) + m.Meta[m.Meta["expand"][j+1]][i] = kit.Format(val) } } } @@ -1262,7 +1259,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, if hides[k] { continue } - msg.Add("append", k, m.Meta[k][i]) + msg.Add("append", k, kit.Select("", m.Meta[k], i)) } } if len(msg.Meta["append"]) == 0 { @@ -1359,7 +1356,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, for i := 0; i < len(m.Meta["format"])-1; i += 2 { format := m.Meta["format"] for j, v := range m.Meta[format[i]] { - m.Meta[format[i]][j] = fmt.Sprintf(format[i+1], v) + if v != "" { + m.Meta[format[i]][j] = fmt.Sprintf(format[i+1], v) + } } } diff --git a/src/contexts/gdb/gdb.go b/src/contexts/gdb/gdb.go index 255f115c..197b3c8f 100644 --- a/src/contexts/gdb/gdb.go +++ b/src/contexts/gdb/gdb.go @@ -84,7 +84,7 @@ func (gdb *GDB) Start(m *ctx.Message, arg ...string) bool { gdb.wait = make(chan interface{}, 10) m.Confm("signal", func(sig string, action string) { - m.Log("signal", "add %s %s", sig, action) + m.Log("error", "signal add %s %s", sig, action) signal.Notify(gdb.goon, syscall.Signal(kit.Int(sig))) }) diff --git a/src/contexts/mdb/mdb.go b/src/contexts/mdb/mdb.go index c1039c16..1f6c3760 100644 --- a/src/contexts/mdb/mdb.go +++ b/src/contexts/mdb/mdb.go @@ -500,7 +500,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", return }}, "note": &ctx.Command{Name: "note [model [name [type name]...]]|[index [name data...]]|[value name data...]|[name model data...]", - Form: map[string]int{"begin": 2, "offset": 1, "limit": 1}, Help: "记事", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + Form: map[string]int{"eq": 2, "begin": 2, "offset": 1, "limit": 1}, Help: "记事", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { offset := kit.Int(kit.Select(m.Conf("page_offset"), m.Option("offset"))) limit := kit.Int(kit.Select(m.Conf("page_limit"), m.Option("limit"))) @@ -528,7 +528,7 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", arg = arg[1:] } if len(arg) == 1 && arg[0] != "show" { - for i := offset; hm != "" && i < limit; hm, i = m.Conf("note", []string{hm, "ship", "prev", "data"}), i+1 { + for i := offset; hm != "" && i < limit+offset; hm, i = m.Conf("note", []string{hm, "ship", "prev", "data"}), i+1 { model := m.Confm("note", hm) m.Add("append", "key", hm) m.Add("append", "create_time", model["create_time"]) @@ -545,14 +545,14 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", switch arg[0] { case "show": - if len(arg) == 1 { + if len(arg) == 1 { // 查看索引 m.Cmdy("mdb.note", "index") break } if len(arg) == 2 { - if arg[1] == "model" { + if arg[1] == "model" { // 查看模型 m.Cmdy("mdb.note", "model") - } else { + } else { // 查看数值 m.Cmdy("mdb.note", "value", arg[1]) } break @@ -567,11 +567,19 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", hv, hn = "prev", m.Conf("note", []string{hm, "ship", "note", "data"}) } - for i := offset; hn != "" && i < limit; hn, i = m.Conf("note", []string{hn, "ship", hv, "data"}), i+1 { + for i := 0; hn != "" && i < limit+offset; hn, i = m.Conf("note", []string{hn, "ship", hv, "data"}), i+1 { + m.Log("fuck", "what hn: %v %v", hn, kit.Formats(m.Confv("note", hn))) + // 翻页 + if i < offset { + continue + } + + // 关系表 note := m.Confm("note", hn) hvs := kit.Trans(note["data"]) hm := kit.Format(kit.Chain(note, "ship.model.data")) + // 值转换 value := []interface{}{} values := map[string]interface{}{} m.Confm("note", []string{hm, "data"}, func(i int, model map[string]interface{}) { @@ -580,11 +588,20 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", values[kit.Format(model["name"])] = v }) + // 行筛选 miss := false - if m.Has("begin") { - for i := 0; i < len(m.Meta["begin"]); i += 2 { - if !strings.HasPrefix(kit.Select(kit.Format(note[m.Meta["begin"][i]]), - kit.Format(values[m.Meta["begin"][i]])), m.Meta["begin"][i+1]) { + if !miss && m.Has("eq") { + for j := 0; j < len(m.Meta["eq"]); j += 2 { + if kit.Select(kit.Format(note[m.Meta["eq"][j]]), kit.Format(values[m.Meta["eq"][j]])) != m.Meta["eq"][j+1] { + miss = true + break + } + } + } + if !miss && m.Has("begin") { + for j := 0; j < len(m.Meta["begin"]); j += 2 { + if !strings.HasPrefix(kit.Select(kit.Format(note[m.Meta["begin"][j]]), + kit.Format(values[m.Meta["begin"][j]])), m.Meta["begin"][j+1]) { miss = true break } @@ -595,12 +612,13 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", continue } - for i := 0; i < len(fields); i++ { - switch fields[i] { + // 列筛选 + for j := 0; j < len(fields); j++ { + switch fields[j] { case "key": m.Add("append", "key", hn) case "create_time", "access_time", "type", "name": - m.Add("append", fields[i], note[fields[i]]) + m.Add("append", fields[j], note[fields[j]]) case "model": m.Add("append", "model", m.Conf("note", []string{hm, "name"})) case "view": @@ -608,9 +626,9 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心", case "value": m.Add("append", "value", kit.Format(value)) case "data", "ship": - m.Add("append", fields[i], kit.Format(note[fields[i]])) + m.Add("append", fields[j], kit.Format(note[fields[j]])) default: - m.Add("append", fields[i], kit.Format(values[fields[i]])) + m.Add("append", fields[j], kit.Format(values[fields[j]])) } } } diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index db532cc1..18663585 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -53,7 +53,12 @@ func dir(m *ctx.Message, name string, level int, deep bool, dir_type string, tri continue } - f, _ := os.Stat(f.Name()) + f, e := os.Stat(f.Name()) + if e != nil { + m.Log("info", "%s", e) + continue + } + if !(dir_type == "file" && f.IsDir() || dir_type == "dir" && !f.IsDir()) && (dir_reg == nil || dir_reg.MatchString(f.Name())) { for _, field := range fields { switch field { @@ -158,20 +163,6 @@ func open(m *ctx.Message, name string, arg ...int) (string, *os.File, error) { m.Log("warn", "%v", e) return name, f, e } -func Format(args ...interface{}) string { - result := []string{} - for _, arg := range args { - switch arg := arg.(type) { - case rune: - result = append(result, string(arg)) - case termbox.Key: - switch arg { - - } - } - } - return strings.Join(result, "") -} func (nfs *NFS) Read(p []byte) (n int, err error) { m := nfs.Context.Message() @@ -402,7 +393,7 @@ func (nfs *NFS) Read(p []byte) (n int, err error) { break } - if change, f, t, i := nfs.Auto(what, Format(ev.Ch), len(what)); change { + if change, f, t, i := nfs.Auto(what, kit.Format(ev.Ch), len(what)); change { frame, table, index, pick = f, t, i, 0 } @@ -874,6 +865,16 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { } if len(arg) > 0 && arg[0] == "scan" { + // 终端用户 + m.Cmd("aaa.user", "root", m.Option("username", m.Conf("runtime", "boot.USER")), "what") + + // 创建会话 + m.Option("sessid", m.Cmd("aaa.user", "session", "select").Append("key")) + + // 创建空间 + m.Option("bench", m.Cmd("aaa.sess", "bench", "select").Append("key")) + + // 默认配置 m.Cap("stream", arg[1]) nfs.Caches["ninput"] = &ctx.Cache{Value: "0"} nfs.Caches["noutput"] = &ctx.Cache{Value: "0"} @@ -882,6 +883,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { nfs.Configs["output"] = &ctx.Config{Value: []interface{}{}} nfs.Configs["prompt"] = &ctx.Config{Value: ""} + // 终端控制 if nfs.in = m.Optionv("in").(*os.File); m.Has("out") { if nfs.out = m.Optionv("out").(*os.File); m.Cap("goos") != "windows" && !m.Options("daemon") { nfs.Term(m, "init") @@ -1113,7 +1115,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", }, Help: "读取文件的缓存区的大小"}, "buf_size": &ctx.Config{Name: "buf_size", Value: "1024", Help: "读取文件的缓存区的大小"}, - "dir_type": &ctx.Config{Name: "dir_type(file/dir/all)", Value: "all", Help: "dir命令输出的文件类型, file: 只输出普通文件, dir: 只输出目录文件, 否则输出所有文件"}, + "dir_type": &ctx.Config{Name: "dir_type(file/dir/both/all)", Value: "both", Help: "dir命令输出的文件类型, file: 只输出普通文件, dir: 只输出目录文件, 否则输出所有文件"}, "dir_fields": &ctx.Config{Name: "dir_fields(time/type/name/size/line/hash)", Value: "time size line filename", Help: "dir命令输出文件名的类型, name: 文件名, tree: 带缩进的文件名, path: 相对路径, full: 绝对路径"}, "git": &ctx.Config{Name: "git", Value: map[string]interface{}{ diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index 8549030f..7c088999 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -371,18 +371,13 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", } // 创建会话 - if m.Option("sessid", m.Cmd("aaa.auth", "username", m.Option("user.name"), "session").Append("key")); !m.Options("sessid") { - m.Option("sessid", m.Cmdx("aaa.sess", "web", "username", m.Option("user.name"))) - m.Cmd("aaa.auth", m.Option("sessid"), "nodes", m.Option("node.route")) - } + m.Option("sessid", m.Cmd("aaa.user", "session", "select").Append("key")) // 创建空间 - if m.Option("bench", m.Cmd("aaa.sess", m.Option("sessid"), "bench").Append("key")); !m.Options("bench") { - m.Option("bench", m.Cmdx("aaa.work", m.Option("sessid"), "nodes")) - } + m.Option("bench", m.Cmd("aaa.sess", "bench", "select").Append("key")) // 权限检查 - if !m.Cmds("aaa.work", m.Option("bench"), "right", m.Option("user.name"), "remote", arg[0]) { + if !m.Cmds("aaa.work", "right", "remote", arg[0]) { m.Echo("no right %s %s", "remote", arg[0]) return } diff --git a/src/contexts/tcp/tcp.go b/src/contexts/tcp/tcp.go index d3870362..714c6d7d 100644 --- a/src/contexts/tcp/tcp.go +++ b/src/contexts/tcp/tcp.go @@ -278,6 +278,13 @@ var Index = &ctx.Context{Name: "tcp", Help: "网络中心", } return }}, + "probe": &ctx.Command{Name: "probe [port]", Help: "端口检测", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { + if t, e := net.DialTimeout("tcp", arg[0], 10*time.Second); e == nil { + m.Echo("active") + t.Close() + } + return + }}, }, } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 1f243c45..848fab16 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -167,7 +167,7 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) { msg.Log("info", "") } for k, v := range r.Form { - msg.Option(k, v) + msg.Add("option", k, v) } switch r.Header.Get("Content-Type") { @@ -547,7 +547,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } req, e := http.NewRequest(method, uri, body) - m.Log("info", "%#v", req) m.Assert(e) m.Log("info", "%s %s", req.Method, req.URL) @@ -566,7 +565,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if m.Options("content_length") { req.Header.Set("Content-Length", m.Option("content_length")) } - m.Log("info", "%#v", req) m.Confm("spide", []string{which, "cookie"}, func(key string, value string) { if key != "" { req.AddCookie(&http.Cookie{Name: key, Value: value}) @@ -927,18 +925,25 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", if m.Confs("login", "check") { if m.Option("username", m.Cmdx("web.session", "login")) == "" { // 没有登录 m.Set("option", "componet_group", "login").Set("option", "componet_name", "").Set("option", "bench", "") + } else { + sessid, bench := m.Option("sessid"), m.Option("bench") - } else if bench := m.Cmdx("web.session", "bench"); bench == "" { // 没有空间 - m.Set("option", "componet_group", "login").Set("option", "componet_name", "").Set("option", "bench", "") + // 创建会话 + if m.Option("sessid", m.Cmd("aaa.user", "session", "select").Append("key")) != sessid { + http.SetCookie(w, &http.Cookie{Name: "sessid", Value: m.Option("sessid"), Path: "/"}) + } - } else if !m.Cmds("web.session", "check", bench, m.Option("username"), m.Confx("componet_group")) { // 没有权限 - m.Set("option", "componet_group", "login").Set("option", "componet_name", "").Set("option", "bench", "") + // 创建空间 + if m.Option("bench", m.Cmd("aaa.sess", "bench", "select").Append("key")) != bench { + m.Append("redirect", merge(m, m.Option("index_url"), "bench", m.Option("bench"))) + return + } + m.Optionv("bench_data", m.Confv("auth", []string{m.Option("bench"), "data"})) - } else if bench != m.Option("bench") { // 没有匹配 - m.Append("redirect", merge(m, m.Option("index_url"), "bench", bench)) - return + if !m.Cmds("aaa.work", "right", m.Confx("componet_group")) { // 没有权限 + m.Set("option", "componet_group", "login").Set("option", "componet_name", "").Set("option", "bench", "") + } } - m.Optionv("bench_data", m.Confv("auth", []string{m.Option("bench"), "data"})) } // 响应模板 @@ -950,34 +955,33 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", continue } - msg := m - if val["componet_cmd"] != nil { - // 查找模块 - context := m.Cap("module") - if val["componet_ctx"] != nil { - context = val["componet_ctx"].(string) - } - msg = m.Find(context) + if kit.Right(val["componet_pod"]) { + arg = append(arg, "sh", "node", kit.Format(m.Magic("session", "current.pod"))) + } + if kit.Right(val["componet_cmd"]) { + arg = append(arg, kit.Format(val["componet_cmd"])) + } + if m.Has("cmds") { + arg = append(arg, kit.Trans(m.Optionv("cmds"))...) + } - // 添加参数值 - args := []string{val["componet_cmd"].(string)} - if kit.Right(val["componet_pod"]) { - args = []string{"sh", "node", kit.Format(m.Magic("session", "current.pod")), val["componet_cmd"].(string)} - } - if val["arguments"] != nil { - for _, v := range val["arguments"].([]interface{}) { - switch value := v.(type) { - case string: - args = append(args, msg.Parse(value)) - } - } - } + msg := m + if len(arg) > 0 { + // 查找模块 + msg = m.Find(kit.Select(m.Cap("module"), val["componet_ctx"])) // 权限检查 - if m.Options("bench") && !m.Cmds("web.session", "check", m.Option("bench"), m.Option("username"), m.Option("componet_group"), args[0]) { + if m.Options("bench") && !m.Cmds("aaa.work", "right", m.Option("componet_group"), arg[0]) { continue } + // 添加参数值 + if value, ok := val["arguments"].([]interface{}); ok { + for _, v := range value { + arg = append(arg, msg.Parse(kit.Format(v))) + } + } + // 添加固定值 msg.Option("componet_name", val["name"].(string)) for k, v := range val { @@ -1006,20 +1010,15 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", // 执行命令 if order != "" || kit.Right(val["pre_run"]) { - if list := m.Confv("auth", []string{m.Option("bench"), "data", "action", msg.Option("componet_name"), "cmd"}); list != nil && order == "" { - // args = kit.Trans(list) - } - - if msg.Cmd(args); m.Options("bench") { + if msg.Cmd(arg); m.Options("bench") { name_alias := "action." + kit.Select(msg.Option("componet_name"), msg.Option("componet_name_alias")) + // 命令历史 msg.Put("option", name_alias, map[string]interface{}{ - "cmd": args, "order": m.Option("componet_name_order"), "action_time": msg.Time(), + "cmd": arg, "order": m.Option("componet_name_order"), "action_time": msg.Time(), }).Cmd("web.session", "bench", m.Option("bench"), "data", "option", name_alias, "modify_time", msg.Time()) - } } - } else { } // 添加响应 diff --git a/src/examples/code/code.go b/src/examples/code/code.go index a595bd97..43792bcc 100644 --- a/src/examples/code/code.go +++ b/src/examples/code/code.go @@ -84,7 +84,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", // }, // }, map[string]interface{}{"name": "dir", "help": "dir", "template": "componet", - "componet_ctx": "nfs", "componet_cmd": "dir", "arguments": []interface{}{"@dir", "dir_sort", "@sort_order", "@sort_field"}, + "componet_ctx": "nfs", "componet_cmd": "dir", "arguments": []interface{}{"@dir", "dir_sort", "@sort_field", "@sort_order"}, "pre_run": true, "display_result": "", "inputs": []interface{}{ map[string]interface{}{"type": "choice", "name": "dir_type", @@ -218,7 +218,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", // "pre_run": true, // "display_result": "", // }, - map[string]interface{}{"name": "mp", "template": "mp"}, + // map[string]interface{}{"name": "mp", "template": "mp"}, map[string]interface{}{"name": "tail", "template": "tail"}, }, }, Help: "组件列表"}, diff --git a/usr/librarys/code.js b/usr/librarys/code.js index ee03957b..f84e135c 100644 --- a/usr/librarys/code.js +++ b/usr/librarys/code.js @@ -894,19 +894,10 @@ function init_toolkit() { location.search = "" return case "rename_fly": - context.GET("", { - "componet_group": "index", - "componet_name": "cmd", - "cmd": "aaa.work "+context.Search("bench")+" rename "+prompt("name"), - }) + context.Command(["work", context.Search("bench"), "rename", prompt("name")]) location.reload() return case "remove_fly": - context.GET("", { - "componet_group": "index", - "componet_name": "cmd", - "cmd": "aaa.work "+context.Search("bench")+" delete", - }) var b = "" document.querySelectorAll("div.workflow>ul.toolkit>li>ul.fly>li[data-key]").forEach(function(item){ if (!b && item.dataset["key"] != context.Search("bench")) { @@ -914,6 +905,7 @@ function init_toolkit() { } }) context.Search("bench", b) + context.Command(["work", context.Search("bench"), "delete"]) return } diff --git a/usr/librarys/context.js b/usr/librarys/context.js index 174980c7..a48b0385 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -1,4 +1,6 @@ context = { + Bench: function(key, value) { + }, Search: function(key, value) { var args = {}; var search = location.search.split("?"); @@ -62,8 +64,13 @@ context = { Command: function(cmd, option, cb) { option = option || {} option["componet_index"] = "index" - option["componet_name"] = "source" - option["cmd"] = cmd + if (typeof cmd == "string") { + option["componet_name"] = "source" + option["cmd"] = cmd + } else { + option["componet_name"] = "head" + option["cmds"] = cmd + } this.GET("", option, function(msg) { typeof cb == "function" && (msg && msg[0]? cb(msg[0]): cb())