mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
opt ssh
This commit is contained in:
parent
6fbcf9a95c
commit
f7b2e4db46
@ -1,7 +1,7 @@
|
||||
~chat
|
||||
config save tmp/flow.json flow
|
||||
~ssh
|
||||
config save tmp/cert.json cert trust
|
||||
config save tmp/cert.json work trust
|
||||
~aaa
|
||||
config save tmp/auth.json auth
|
||||
~cli
|
||||
|
@ -3,7 +3,7 @@
|
||||
~aaa
|
||||
config load tmp/auth.json auth
|
||||
~ssh
|
||||
config load tmp/cert.json cert trust
|
||||
config load tmp/cert.json work trust
|
||||
~chat
|
||||
config load tmp/flow.json flow
|
||||
|
||||
|
@ -125,7 +125,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
"auth_expire": &ctx.Config{Name: "auth_expire", Value: "10m", Help: "权限超时"},
|
||||
"auth_type": &ctx.Config{Name: "auth_type", Value: map[string]interface{}{
|
||||
"unique": map[string]interface{}{"session": true, "bench": true, "relay": true},
|
||||
"public": map[string]interface{}{"userrole": true, "username": true, "cert": true},
|
||||
"public": map[string]interface{}{"userrole": true, "username": true, "cert": true, "access": true},
|
||||
"single": map[string]interface{}{"password": true, "token": true, "uuid": true, "ppid": true},
|
||||
"secrete": map[string]interface{}{"password": true, "token": true, "uuid": true, "ppid": true},
|
||||
}, Help: "散列"},
|
||||
@ -133,7 +133,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
"expire": &ctx.Config{Name: "expire(s)", Value: "72000", Help: "会话超时"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"init": &ctx.Command{Name: "init", Help: "数字摘要", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"_init": &ctx.Command{Name: "_init", Help: "数字摘要", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Conf("runtime", "node.cert", m.Cmdx("nfs.load", os.Getenv("node_cert")))
|
||||
m.Conf("runtime", "node.key", m.Cmdx("nfs.load", os.Getenv("node_key")))
|
||||
m.Conf("runtime", "user.cert", m.Cmdx("nfs.load", os.Getenv("user_cert")))
|
||||
@ -164,9 +164,9 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
case "0":
|
||||
if !up {
|
||||
up = true
|
||||
m.Add("append", "up_key", k)
|
||||
m.Add("append", "up_key", k[:6])
|
||||
m.Add("append", "up_type", val["type"])
|
||||
m.Add("append", "up_ship", val["ship"])
|
||||
// m.Add("append", "up_ship", val["ship"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,13 +174,13 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
if !up {
|
||||
m.Add("append", "up_key", "")
|
||||
m.Add("append", "up_type", "")
|
||||
m.Add("append", "up_ship", "")
|
||||
// m.Add("append", "up_ship", "")
|
||||
}
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "type", node["type"])
|
||||
m.Add("append", "meta", node["meta"])
|
||||
})
|
||||
m.Table()
|
||||
m.Sort("type").Table()
|
||||
return
|
||||
}
|
||||
|
||||
@ -393,7 +393,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@ -619,36 +619,38 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
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
|
||||
break
|
||||
}
|
||||
|
||||
// 检查权限
|
||||
m.Cmd("aaa.auth", "ship", "username", m.Option("username"), "userrole").Table(func(node map[string]string) {
|
||||
if m.Options("userrole") && node["meta"] != m.Option("userrole") {
|
||||
return // 失败
|
||||
} else if node["meta"] == "root" { // 超级用户
|
||||
for _, role := range kit.Trans(m.Option("userrole"), m.Cmd("aaa.auth", "ship", "username", m.Option("username"), "userrole").Appendv("meta")) {
|
||||
if role == "" {
|
||||
continue
|
||||
}
|
||||
if role == "root" { // 超级用户
|
||||
|
||||
} else if len(arg) > 2 { // 接口权限
|
||||
if m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", arg[2]) {
|
||||
|
||||
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "componet", arg[1], "check", arg[2]); kit.Right(cid) {
|
||||
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", role, "componet", arg[1], "check", arg[2]); kit.Right(cid) {
|
||||
m.Cmd("aaa.auth", m.Option("bench"), cid)
|
||||
} else {
|
||||
return // 失败
|
||||
continue // 失败
|
||||
}
|
||||
} else if len(arg) > 1 { // 组件权限
|
||||
if m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", arg[1]) {
|
||||
|
||||
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "check", arg[1]); kit.Right(cid) {
|
||||
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", role, "check", arg[1]); kit.Right(cid) {
|
||||
m.Cmd("aaa.auth", m.Option("bench"), cid)
|
||||
} else {
|
||||
return // 失败
|
||||
continue // 失败
|
||||
}
|
||||
}
|
||||
|
||||
m.Log("info", "role: %s %v", node["meta"], arg[1:])
|
||||
m.Echo(node["meta"])
|
||||
})
|
||||
m.Log("info", "role: %s %v", role, arg[1:])
|
||||
m.Echo(role)
|
||||
break
|
||||
}
|
||||
|
||||
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))
|
||||
@ -755,8 +757,8 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
|
||||
// 生成证书
|
||||
template := x509.Certificate{
|
||||
SerialNumber: big.NewInt(1),
|
||||
IsCA: true,
|
||||
SerialNumber: big.NewInt(1),
|
||||
IsCA: true,
|
||||
BasicConstraintsValid: true,
|
||||
KeyUsage: x509.KeyUsageCertSign,
|
||||
Subject: pkix.Name{CommonName: kit.Format(common)},
|
||||
|
@ -141,8 +141,24 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}, Help: "启动脚本"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"ps": &ctx.Command{Name: "ps", Help: "ps", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Cmdy("cli.system", "ps", "-ef", "cmd_parse", "cli")
|
||||
"_init": &ctx.Command{Name: "_init", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Conf("runtime", "host.GOARCH", runtime.GOARCH)
|
||||
m.Conf("runtime", "host.GOOS", runtime.GOOS)
|
||||
m.Conf("runtime", "host.pid", os.Getpid())
|
||||
runtime.GOMAXPROCS(1)
|
||||
|
||||
if name, e := os.Hostname(); e == nil {
|
||||
m.Conf("runtime", "boot.hostname", kit.Select(name, os.Getenv("HOSTNAME")))
|
||||
}
|
||||
if name, e := os.Getwd(); e == nil {
|
||||
_, file := path.Split(name)
|
||||
m.Conf("runtime", "boot.pathname", file)
|
||||
}
|
||||
m.Confm("runtime", "init_env", func(index int, key string) {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
m.Conf("runtime", "boot."+key, kit.Select("", value, value != "-"))
|
||||
}
|
||||
})
|
||||
return
|
||||
}},
|
||||
"runtime": &ctx.Command{Name: "runtime", Help: "runtime", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
@ -167,6 +183,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
m.Append("objects", mem.HeapObjects)
|
||||
m.Append("lookups", mem.Lookups)
|
||||
m.Table()
|
||||
|
||||
default:
|
||||
if len(arg) == 1 {
|
||||
m.Cmdy("ctx.config", "runtime", arg[0])
|
||||
@ -182,6 +199,22 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}
|
||||
return
|
||||
}},
|
||||
"exit": &ctx.Command{Name: "exit", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Confm("daemon", func(key string, info map[string]interface{}) {
|
||||
m.Cmd("cli.system", key, "stop")
|
||||
})
|
||||
return
|
||||
}},
|
||||
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Cmd("cli.source", m.Conf("system", "script.exit"))
|
||||
|
||||
m.GoFunc(m, func(m *ctx.Message) {
|
||||
time.Sleep(time.Second * 3)
|
||||
os.Exit(kit.Int(arg[0]))
|
||||
})
|
||||
return
|
||||
}},
|
||||
|
||||
"system": &ctx.Command{Name: "system word...", Help: []string{"调用系统命令, word: 命令",
|
||||
"cmd_timeout: 命令超时",
|
||||
"cmd_active(true/false): 是否交互",
|
||||
@ -674,42 +707,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
return
|
||||
}},
|
||||
|
||||
"init": &ctx.Command{Name: "init", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Conf("runtime", "host.GOARCH", runtime.GOARCH)
|
||||
m.Conf("runtime", "host.GOOS", runtime.GOOS)
|
||||
m.Conf("runtime", "host.pid", os.Getpid())
|
||||
runtime.GOMAXPROCS(1)
|
||||
|
||||
if name, e := os.Hostname(); e == nil {
|
||||
m.Conf("runtime", "boot.hostname", kit.Select(name, os.Getenv("HOSTNAME")))
|
||||
}
|
||||
if name, e := os.Getwd(); e == nil {
|
||||
_, file := path.Split(name)
|
||||
m.Conf("runtime", "boot.pathname", file)
|
||||
}
|
||||
m.Confm("runtime", "init_env", func(index int, key string) {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
m.Conf("runtime", "boot."+key, kit.Select("", value, value != "-"))
|
||||
}
|
||||
})
|
||||
return
|
||||
}},
|
||||
"exit": &ctx.Command{Name: "exit", Help: "解析脚本, script: 脚本文件, stdio: 命令终端, snippet: 代码片段", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Confm("daemon", func(key string, info map[string]interface{}) {
|
||||
m.Cmd("cli.system", key, "stop")
|
||||
})
|
||||
return
|
||||
}},
|
||||
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Cmd("cli.source", m.Conf("system", "script.exit"))
|
||||
|
||||
m.GoFunc(m, func(m *ctx.Message) {
|
||||
time.Sleep(time.Second * 3)
|
||||
os.Exit(kit.Int(arg[0]))
|
||||
})
|
||||
return
|
||||
}},
|
||||
|
||||
"alias": &ctx.Command{Name: "alias [short [long...]]|[delete short]|[import module [command [alias]]]",
|
||||
Help: "查看、定义或删除命令别名, short: 命令别名, long: 命令原名, delete: 删除别名, import导入模块所有命令",
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
|
@ -1579,7 +1579,7 @@ func (m *Message) Cmd(args ...interface{}) *Message {
|
||||
msg := m
|
||||
if strings.Contains(key, ":") {
|
||||
ps := strings.Split(key, ":")
|
||||
msg, key, arg = msg.Sess("ssh"), "remote", append([]string{"sync", ps[0], ps[1]}, arg...)
|
||||
msg, key, arg = msg.Sess("ssh"), "_route", append([]string{"sync", ps[0], ps[1]}, arg...)
|
||||
defer func() { m.Copy(msg, "append").Copy(msg, "result") }()
|
||||
m.Hand = true
|
||||
|
||||
|
@ -38,7 +38,7 @@ func (ctx *CTX) Begin(m *Message, arg ...string) Server {
|
||||
return ctx
|
||||
}
|
||||
func (ctx *CTX) Start(m *Message, arg ...string) bool {
|
||||
m.Cmd("ctx.init")
|
||||
m.Cmd("ctx._init")
|
||||
if m.Optionv("ps_target", Index); len(arg) == 0 {
|
||||
m.Cap("stream", "shy")
|
||||
m.Cmd("cli.source", m.Conf("system", "script.init")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("system", "script.exit"))
|
||||
@ -94,9 +94,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
||||
"call_timeout": &Config{Name: "call_timeout", Value: "10s", Help: "回调超时"},
|
||||
},
|
||||
Commands: map[string]*Command{
|
||||
"init": &Command{Name: "init", Help: "启动", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||
"_init": &Command{Name: "_init", Help: "启动", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||
for _, x := range []string{"cli", "yac", "nfs", "aaa", "log", "ssh", "web", "gdb"} {
|
||||
m.Cmd(x + ".init")
|
||||
m.Cmd(x + "._init")
|
||||
}
|
||||
return
|
||||
}},
|
||||
@ -121,6 +121,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
||||
m.Echo("^_^ Welcome to context world ^_^\n")
|
||||
m.Echo("Version: 1.0 A New Language, A New Framework\n")
|
||||
m.Echo("More: https://github.com/shylinux/context\n")
|
||||
m.Echo("More: https://shylinux.com/\n")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ var Index = &ctx.Context{Name: "gdb", Help: "调试中心",
|
||||
}},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"init": &ctx.Command{Name: "init", Help: "等待调试", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"_init": &ctx.Command{Name: "_init", Help: "等待调试", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Target().Start(m)
|
||||
return
|
||||
}},
|
||||
|
@ -152,12 +152,13 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
||||
"aaa": map[string]interface{}{
|
||||
"auth": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
|
||||
"hash": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
|
||||
"rsa": map[string]interface{}{"value": map[string]interface{}{"file": "debug.log", "meta": []interface{}{"time", "ship"}, "color_begin": "\033[31m", "color_end": "\033[0m"}},
|
||||
},
|
||||
},
|
||||
}, Help: "日志输出配置"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"init": &ctx.Command{Name: "init", Help: "启动日志", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"_init": &ctx.Command{Name: "_init", Help: "启动日志", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Target().Start(m)
|
||||
return
|
||||
}},
|
||||
|
@ -955,15 +955,6 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool {
|
||||
nfs.Send(meta, v)
|
||||
}
|
||||
for _, k := range msg.Meta[body] {
|
||||
if k == "binary" {
|
||||
switch d := msg.Data[k].(type) {
|
||||
case []byte:
|
||||
nfs.Send("size", len(d))
|
||||
n, e := nfs.io.Write(d)
|
||||
m.Log("info", "send %v %v", n, e)
|
||||
}
|
||||
continue
|
||||
}
|
||||
for _, v := range msg.Meta[k] {
|
||||
nfs.Send(k, v)
|
||||
}
|
||||
@ -992,7 +983,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool {
|
||||
case "":
|
||||
m.Log("recv", "time %v", time.Now().Format(m.Conf("time_format")))
|
||||
if head == "detail" { // 接收请求
|
||||
msg.Detail(-1, "remote")
|
||||
msg.Detail(-1, "_route")
|
||||
msg.Option("remote_code", code)
|
||||
m.GoFunc(msg, func(msg *ctx.Message) {
|
||||
msg.Call(func(msg *ctx.Message) *ctx.Message {
|
||||
@ -1001,9 +992,11 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool {
|
||||
})
|
||||
})
|
||||
} else { // 接收响应
|
||||
if h, ok := nfs.hand[kit.Int(code)]; ok {
|
||||
h.CopyFuck(msg, "result").CopyFuck(msg, "append").Back(h)
|
||||
}
|
||||
m.Set("option", "code", code).GoFunc(msg, func(msg *ctx.Message) {
|
||||
if h, ok := nfs.hand[kit.Int(m.Option("code"))]; ok {
|
||||
h.CopyFuck(msg, "result").CopyFuck(msg, "append").Back(h)
|
||||
}
|
||||
})
|
||||
}
|
||||
msg, code, head, body = nil, "0", "result", "append"
|
||||
|
||||
@ -1141,7 +1134,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
"paths": &ctx.Config{Name: "paths", Value: []interface{}{"var", "usr", "etc", "bin", ""}, Help: "文件路径"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"init": &ctx.Command{Name: "init", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"_init": &ctx.Command{Name: "_init", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Conf("paths", -2, m.Conf("runtime", "boot.ctx_home"))
|
||||
m.Conf("paths", -2, m.Conf("runtime", "boot.ctx_root"))
|
||||
return
|
||||
|
@ -38,7 +38,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"node": &ctx.Config{Name: "node", Value: map[string]interface{}{}, Help: "节点信息"},
|
||||
"cert": &ctx.Config{Name: "cert", Value: map[string]interface{}{}, Help: "用户信息"},
|
||||
"work": &ctx.Config{Name: "work", Value: map[string]interface{}{}, Help: "用户信息"},
|
||||
"file": &ctx.Config{Name: "file", Value: map[string]interface{}{}, Help: "用户信息"},
|
||||
"trust": &ctx.Config{Name: "trust", Value: map[string]interface{}{"fresh": false, "user": true, "up": true}, Help: "可信节点"},
|
||||
"timer": &ctx.Config{Name: "timer", Value: map[string]interface{}{"interval": "10s", "timer": ""}, Help: "断线重连"},
|
||||
@ -64,7 +64,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}, Help: "组件列表"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"init": &ctx.Command{Name: "init", Help: "启动", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"_init": &ctx.Command{Name: "_init", Help: "启动初始化", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if m.Confs("runtime", "boot.ctx_box") {
|
||||
m.Conf("runtime", "node.type", "worker")
|
||||
m.Conf("runtime", "node.name", m.Conf("runtime", "boot.pathname"))
|
||||
@ -74,30 +74,348 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
m.Conf("runtime", "node.route", m.Conf("runtime", "node.name"))
|
||||
m.Conf("runtime", "user.name", m.Conf("runtime", "boot.USER"))
|
||||
|
||||
m.Cmd("aaa.role", "tech", "componet", "remote", "command", "tool")
|
||||
m.Cmd("aaa.role", "tech", "componet", "source", "command", "tool")
|
||||
return
|
||||
}},
|
||||
"node": &ctx.Command{Name: "node [create|delete [name [type module]]]", Help: "节点", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"_node": &ctx.Command{Name: "_node [init|create name type module|delete name]", Help: "节点", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy("ctx.config", "node", "format", "table", "fields", "type", "module", "create_time")
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "create": // 添加节点
|
||||
m.Log("info", "create node %s %s", arg[1], arg[2])
|
||||
m.Confv("node", arg[1], map[string]interface{}{
|
||||
"name": arg[1], "type": arg[2], "module": arg[3],
|
||||
case "init": // 节点证书
|
||||
if !m.Confs("runtime", "node.cert") || !m.Confs("runtime", "node.key") {
|
||||
msg := m.Cmd("aaa.rsa", "gen")
|
||||
m.Conf("runtime", "node.cert", msg.Append("certificate"))
|
||||
m.Conf("runtime", "node.key", msg.Append("private"))
|
||||
m.Echo(m.Conf("runtime", "node.cert"))
|
||||
}
|
||||
|
||||
case "create": // 创建节点
|
||||
name := arg[1]
|
||||
if arg[2] != "master" {
|
||||
for node := m.Confm("node", name); node != nil; node = m.Confm("node", name) {
|
||||
name = kit.Format("%s_%s", arg[1], m.Capi("nnode", 1))
|
||||
}
|
||||
}
|
||||
|
||||
m.Log("info", "create node %s %s", name, arg[2])
|
||||
m.Confv("node", name, map[string]interface{}{
|
||||
"name": name, "type": arg[2], "module": arg[3],
|
||||
"create_time": m.Time(),
|
||||
})
|
||||
m.Echo(name)
|
||||
|
||||
case "delete": // 删除节点
|
||||
m.Log("info", "delete node %s %s", arg[1], kit.Formats(m.Conf("node", arg[1])))
|
||||
m.Cmd("aaa.auth", m.Cmdx("aaa.auth", "nodes", arg[1]), "delete", "node")
|
||||
delete(m.Confm("node"), arg[1])
|
||||
}
|
||||
return
|
||||
}},
|
||||
"cert": &ctx.Command{Name: "cert [node|user|work]", Help: []string{"认证",
|
||||
"node [create|check text|trust node]",
|
||||
"user": &ctx.Command{Name: "user create [node]", Help: "用户", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Echo(m.Conf("runtime", "user.route"))
|
||||
return
|
||||
}
|
||||
switch arg[0] {
|
||||
case "create": // 创建用户
|
||||
m.Cmd("aaa.auth", "username", m.Conf("runtime", "user.name"), "delete", "node")
|
||||
if len(arg) == 1 {
|
||||
msg := m.Cmd("aaa.rsa", "gen")
|
||||
m.Conf("runtime", "user.route", m.Conf("runtime", "node.route"))
|
||||
m.Conf("runtime", "user.cert", msg.Append("certificate"))
|
||||
m.Conf("runtime", "user.key", msg.Append("private"))
|
||||
} else {
|
||||
msg := m.Cmd("ssh._route", arg[1], "_check", "user")
|
||||
m.Conf("runtime", "user.route", msg.Append("user.route"))
|
||||
m.Conf("runtime", "user.cert", msg.Append("user.cert"))
|
||||
m.Conf("runtime", "user.name", msg.Append("user.name"))
|
||||
m.Conf("runtime", "user.key", "")
|
||||
}
|
||||
m.Cmd("aaa.user", "root", m.Conf("runtime", "user.name"))
|
||||
m.Echo(m.Conf("runtime", "user.cert"))
|
||||
}
|
||||
return
|
||||
}},
|
||||
"work": &ctx.Command{Name: "work [serve|create|search]", Help: "工作", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Confm("work", func(key string, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "user", value["user"])
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "serve":
|
||||
m.Conf("runtime", "work.serve", true)
|
||||
m.Conf("runtime", "work.route", m.Conf("runtime", "node.route"))
|
||||
m.Conf("work", m.Conf("runtime", "user.name"), map[string]interface{}{"create_time": m.Time(), "user": m.Conf("runtime", "node.route")})
|
||||
|
||||
case "create":
|
||||
user := m.Conf("runtime", "user.route")
|
||||
if user == "" {
|
||||
m.Echo("error: no user.route")
|
||||
return
|
||||
}
|
||||
|
||||
name := kit.Select(m.Conf("runtime", "user.name"), arg, 1)
|
||||
work := kit.Select(m.Conf("runtime", "work.route"), arg, 2)
|
||||
|
||||
if n := m.Cmdx("ssh._route", work, "_check", "work", name, user); n != "" {
|
||||
m.Conf("runtime", "work.route", work)
|
||||
m.Conf("runtime", "work.name", n)
|
||||
m.Echo(n)
|
||||
} else {
|
||||
m.Echo("error: %s from %s", name, work)
|
||||
}
|
||||
|
||||
case "search":
|
||||
m.Cmdy("ssh._route", m.Conf("runtime", "work.route"), "_check", "work", "search", arg[1:])
|
||||
|
||||
case "delete":
|
||||
delete(m.Confm("ctx.config"), arg[1])
|
||||
}
|
||||
return
|
||||
}},
|
||||
"tool": &ctx.Command{Name: "tool", Help: "用户", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Confm("componet", func(key string, index int, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "index", index)
|
||||
m.Add("append", "name", value["componet_name"])
|
||||
m.Add("append", "help", value["componet_help"])
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "run":
|
||||
tool := m.Confm("componet", []string{arg[1], arg[2]})
|
||||
msg := m.Find(kit.Format(tool["componet_ctx"]))
|
||||
msg.Cmd(tool["componet_cmd"], arg[3:]).CopyTo(m)
|
||||
|
||||
default:
|
||||
m.Confm("componet", arg[0:], func(value map[string]interface{}) {
|
||||
m.Add("append", "name", value["componet_name"])
|
||||
m.Add("append", "help", value["componet_help"])
|
||||
m.Add("append", "view", value["componet_view"])
|
||||
m.Add("append", "init", m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["componet_init"])), -1))
|
||||
m.Add("append", "inputs", kit.Format(value["inputs"]))
|
||||
})
|
||||
m.Table()
|
||||
}
|
||||
return
|
||||
}},
|
||||
"file": &ctx.Command{Name: "file", Help: "用户", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
return
|
||||
}},
|
||||
|
||||
"remote": &ctx.Command{Name: "remote auto|dial|listen args...", Help: "连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmd("_node")
|
||||
return
|
||||
}
|
||||
switch arg[0] {
|
||||
case "auto": // 自动连接
|
||||
if m.Cmd("ssh.remote", "dial", "dev", "/shadow"); !m.Confs("runtime", "boot.ctx_box") {
|
||||
m.Cmd("ssh.remote", "listen", m.Conf("runtime", "boot.ssh_port"))
|
||||
m.Cmd("web.serve", "usr", m.Conf("runtime", "boot.web_port"))
|
||||
}
|
||||
|
||||
case "listen": // 监听连接
|
||||
m.Cmd("ssh._node", "init")
|
||||
|
||||
m.Call(func(nfs *ctx.Message) *ctx.Message {
|
||||
if nfs.Has("node.port") {
|
||||
m.Log("info", "node.port %v", nfs.Optionv("node.port"))
|
||||
m.Conf("runtime", "node.port", nfs.Optionv("node.port"))
|
||||
}
|
||||
return nil
|
||||
}, "nfs.remote", arg)
|
||||
|
||||
case "_redial": // 断线重连
|
||||
if !m.Caps("stream") {
|
||||
m.Cmdx("remote", "dial", arg[1:])
|
||||
}
|
||||
|
||||
case "dial": // 连接主机
|
||||
m.Cmd("ssh._node", "init")
|
||||
|
||||
m.Call(func(nfs *ctx.Message) *ctx.Message {
|
||||
// 删除重连
|
||||
if m.Confs("timer", "timer") {
|
||||
m.Conf("timer", "timer", m.Cmdx("cli.timer", "delete", m.Conf("timer", "timer")))
|
||||
}
|
||||
|
||||
// 注册设备
|
||||
m.Spawn(nfs.Target()).Call(func(node *ctx.Message) *ctx.Message {
|
||||
// 添加网关
|
||||
name := m.Cmd("ssh._node", "create", node.Append("node.name"), "master", m.Cap("stream", nfs.Format("target")))
|
||||
|
||||
// 清理回调
|
||||
nfs.Free(func(nfs *ctx.Message) bool {
|
||||
m.Cmd("ssh._node", "delete", name)
|
||||
|
||||
// 断线重连
|
||||
m.Cap("stream", "")
|
||||
m.Conf("timer", "timer", m.Cmdx("cli.timer", "repeat", m.Conf("timer", "interval"), "context", "ssh", "remote", "_redial", arg[1:]))
|
||||
return true
|
||||
})
|
||||
|
||||
// 本机路由
|
||||
m.Cmd("cli.runtime", "node.route", node.Append("node.route")+"."+node.Result(0))
|
||||
|
||||
// 用户路由
|
||||
if m.Confs("runtime", "user.cert") && m.Confs("runtime", "user.key") {
|
||||
m.Cmd("cli.runtime", "user.route", m.Conf("runtime", "node.route"))
|
||||
|
||||
} else if node.Appends("user.route") && !m.Confs("runtime", "user.route") {
|
||||
m.Cmd("ssh.user", "create", node.Append("user.route"))
|
||||
}
|
||||
|
||||
// 工作路由
|
||||
if node.Appends("work.route") && !m.Confs("runtime", "work.route") {
|
||||
m.Cmd("cli.runtime", "work.route", node.Append("work.route"))
|
||||
}
|
||||
return nil
|
||||
}, "send", "", "_add", m.Conf("runtime", "node.name"), m.Conf("runtime", "node.type"))
|
||||
return nil
|
||||
}, "nfs.remote", arg)
|
||||
|
||||
case "_add":
|
||||
// 添加节点
|
||||
name := m.Cmdx("ssh._node", "create", arg[1], arg[2], m.Format("source"), arg[3:])
|
||||
|
||||
// 清理回调
|
||||
m.Sess("ms_source", false).Free(func(msg *ctx.Message) bool {
|
||||
m.Cmd("ssh._node", "delete", name)
|
||||
return true
|
||||
})
|
||||
|
||||
// 同步信息
|
||||
m.Append("node.name", m.Conf("runtime", "node.name"))
|
||||
m.Append("user.name", m.Conf("runtime", "user.name"))
|
||||
m.Append("work.name", m.Conf("runtime", "work.name"))
|
||||
m.Append("node.route", m.Conf("runtime", "node.route"))
|
||||
m.Append("user.route", m.Conf("runtime", "user.route"))
|
||||
m.Append("work.route", m.Conf("runtime", "work.route"))
|
||||
m.Echo(name).Back(m)
|
||||
|
||||
default:
|
||||
m.Cmd("_route", arg)
|
||||
}
|
||||
return
|
||||
}},
|
||||
"_route": &ctx.Command{Name: "_route", Help: "路由", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
// 同步异步
|
||||
sync := true
|
||||
switch arg[0] {
|
||||
case "async", "sync":
|
||||
sync, arg = arg[0] == "sync", arg[1:]
|
||||
}
|
||||
|
||||
// 局域路由
|
||||
if arg[0] == m.Conf("runtime", "node.name") || arg[0] == m.Conf("runtime", "node.route") {
|
||||
arg[0] = ""
|
||||
}
|
||||
arg[0] = strings.TrimPrefix(arg[0], m.Conf("runtime", "node.route")+".")
|
||||
arg[0] = strings.TrimPrefix(arg[0], m.Conf("runtime", "node.name")+".")
|
||||
|
||||
// 拆分路由
|
||||
route, names, arg := arg[0], strings.SplitN(arg[0], ".", 2), arg[1:]
|
||||
if len(names) > 1 && names[0] == "" && names[1] != "" {
|
||||
names[0], names[1] = names[1], names[0]
|
||||
}
|
||||
|
||||
if rest := kit.Select("", names, 1); names[0] != "" {
|
||||
// 数字签名
|
||||
if !m.Options("remote_code") && arg[0] != "_check" {
|
||||
hash, meta := kit.Hash("rand",
|
||||
m.Option("text.time", m.Time("stamp")),
|
||||
m.Option("text.cmd", strings.Join(arg, " ")),
|
||||
m.Option("text.route", route),
|
||||
m.Option("node.route", m.Conf("runtime", "node.route")),
|
||||
m.Option("user.route", kit.Select(m.Conf("runtime", "node.route"), m.Conf("runtime", "user.route"))),
|
||||
m.Option("user.name", m.Option("username")),
|
||||
m.Option("work.name", m.Conf("runtime", "work.name")),
|
||||
m.Option("work.route", m.Conf("runtime", "work.route")),
|
||||
)
|
||||
m.Option("text.rand", meta[0])
|
||||
m.Option("node.sign", m.Cmdx("aaa.rsa", "sign", m.Conf("runtime", "node.key"), m.Option("text.hash", hash)))
|
||||
}
|
||||
|
||||
// 查找路由
|
||||
ps := []string{}
|
||||
if names[0] == "%" || names[0] == "*" { // 广播命令
|
||||
m.Confm("node", names[0], func(name string, node map[string]interface{}) {
|
||||
if kit.Format(node["type"]) != "master" {
|
||||
ps = append(ps, kit.Format(node["module"]))
|
||||
}
|
||||
})
|
||||
|
||||
} else if m.Confm("node", names[0], func(node map[string]interface{}) { // 单播命令
|
||||
ps = append(ps, kit.Format(node["module"]))
|
||||
|
||||
}) == nil && m.Caps("stream") { // 上报命令
|
||||
rest = strings.Join(names, ".")
|
||||
ps = append(ps, m.Cap("stream"))
|
||||
}
|
||||
if len(ps) == 0 { // 查找失败
|
||||
m.Echo("error: not found %s", names[0]).Back(m)
|
||||
return
|
||||
}
|
||||
|
||||
// 路由转发
|
||||
for _, p := range ps {
|
||||
m.Find(p, true).Copy(m, "option").CallBack(sync, func(sub *ctx.Message) *ctx.Message {
|
||||
return m.CopyFuck(sub, "append").CopyFuck(sub, "result")
|
||||
}, "send", rest, arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
defer func() { m.Back(m) }()
|
||||
|
||||
if !m.Options("remote_code") { // 本地调用
|
||||
m.Cmdm(arg)
|
||||
|
||||
} else if arg[0] == "_check" { // 公有命令
|
||||
m.Cmd(arg)
|
||||
|
||||
} else if arg[0] == "_add" { // 公有命令
|
||||
m.Cmd("remote", arg)
|
||||
|
||||
} else if h := kit.Hashs(
|
||||
m.Option("text.rand"),
|
||||
m.Option("text.time"),
|
||||
m.Option("text.cmd"),
|
||||
m.Option("text.route"),
|
||||
m.Option("node.route"),
|
||||
m.Option("user.route"),
|
||||
m.Option("user.name"),
|
||||
m.Option("work.name"),
|
||||
m.Option("work.route"),
|
||||
); h != m.Option("text.hash") { // 文本验签
|
||||
m.Echo("text error %s != %s", h, m.Option("text.hash"))
|
||||
m.Log("warn", "text error")
|
||||
|
||||
} else if !m.Cmds("ssh._right", "node", "check", h) { // 设备验签
|
||||
m.Echo("node error of %s", m.Option("node.route"))
|
||||
|
||||
} else { // 执行命令
|
||||
m.Cmd("_exec", arg)
|
||||
}
|
||||
return
|
||||
}},
|
||||
"_right": &ctx.Command{Name: "_right [node|user|work]", Help: []string{"认证",
|
||||
"node [check text|trust node]",
|
||||
"user [create|check text|share role node...|proxy node|trust node]",
|
||||
"work [create node name|check node name]",
|
||||
"file [import]",
|
||||
@ -125,15 +443,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
|
||||
switch arg[1] {
|
||||
case "create": // 创建证书
|
||||
msg := m.Cmd("aaa.rsa", "gen")
|
||||
m.Conf("runtime", "node.cert", msg.Append("certificate"))
|
||||
m.Conf("runtime", "node.key", msg.Append("private"))
|
||||
m.Echo(m.Conf("runtime", "node.cert"))
|
||||
|
||||
case "check": // 数字验签
|
||||
if m.Option("node.cert", m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert").Append("meta")); !m.Options("node.cert") {
|
||||
m.Option("node.cert", m.Cmdx("ssh.remote", m.Option("node.route"), "check", "node"))
|
||||
m.Option("node.cert", m.Cmdx("ssh._route", m.Option("node.route"), "_check", "node"))
|
||||
m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert", m.Option("node.cert"))
|
||||
}
|
||||
|
||||
@ -163,16 +475,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
|
||||
switch arg[1] {
|
||||
case "create": // 创建证书
|
||||
msg := m.Cmd("aaa.rsa", "gen")
|
||||
m.Conf("runtime", "user.route", m.Conf("runtime", "node.route"))
|
||||
m.Conf("runtime", "user.cert", msg.Append("certificate"))
|
||||
m.Conf("runtime", "user.key", msg.Append("private"))
|
||||
m.Echo(m.Conf("runtime", "user.cert"))
|
||||
|
||||
case "check": // 数字验签
|
||||
if m.Option("user.cert", m.Cmd("aaa.auth", "username", m.Option("username"), "cert").Append("meta")); !m.Options("user.cert") {
|
||||
m.Option("user.cert", m.Cmd("ssh.remote", m.Option("user.route"), "check", "user").Append("user.cert"))
|
||||
m.Option("user.cert", m.Cmd("ssh._route", m.Option("user.route"), "_check", "user").Append("user.cert"))
|
||||
m.Cmd("aaa.auth", "username", m.Option("username"), "cert", m.Option("user.cert"))
|
||||
m.Cmd("aaa.auth", "username", m.Option("username"), "userrole", "void")
|
||||
}
|
||||
@ -186,7 +491,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
|
||||
case "share": // 共享用户
|
||||
for _, route := range arg[3:] {
|
||||
user := m.Cmd("ssh.remote", route, "check", "user")
|
||||
user := m.Cmd("ssh._route", route, "_check", "user")
|
||||
if m.Cmd("aaa.role", arg[2], "user", user.Append("user.name"), "cert", user.Append("user.cert")); arg[2] == "root" && route != m.Conf("runtime", "node.route") {
|
||||
m.Conf("runtime", "user.route", user.Append("user.route"))
|
||||
m.Conf("runtime", "user.name", user.Append("user.name"))
|
||||
@ -206,8 +511,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
|
||||
case "trust": // 可信代理
|
||||
hash := kit.Hashs("rand", m.Option("text.time", m.Time("stamp")), arg[2])
|
||||
m.Option("user.sign", m.Cmdx("ssh.remote", m.Option("user.route"), "check", "user", arg[2], hash))
|
||||
m.Echo("%s", m.Options("user.sign") && m.Cmds("ssh.check", hash))
|
||||
m.Option("user.sign", m.Cmdx("ssh._route", m.Option("user.route"), "_check", "user", arg[2], hash))
|
||||
m.Echo("%v", m.Options("user.sign") && m.Cmds("ssh._check", hash))
|
||||
}
|
||||
|
||||
case "work": // 公有认证
|
||||
@ -217,34 +522,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
|
||||
switch arg[1] {
|
||||
case "serve": // 注册节点
|
||||
m.Conf("runtime", "work.serve", true)
|
||||
m.Conf("runtime", "work.route", m.Conf("runtime", "node.route"))
|
||||
|
||||
case "create": // 创建证书
|
||||
user := m.Conf("runtime", "user.route")
|
||||
if user == "" {
|
||||
m.Echo("error: no user.route")
|
||||
return
|
||||
}
|
||||
|
||||
name := kit.Select(m.Conf("runtime", "user.name"), arg, 2)
|
||||
work := kit.Select(m.Conf("runtime", "work.route"), arg, 3)
|
||||
|
||||
if n := m.Cmdx("ssh.remote", work, "check", "work", name, user); n != "" {
|
||||
m.Conf("runtime", "work.route", work)
|
||||
m.Conf("runtime", "work.name", n)
|
||||
m.Echo(n)
|
||||
} else {
|
||||
m.Echo("error: %s from %s", name, work)
|
||||
}
|
||||
|
||||
case "search":
|
||||
work := kit.Select(m.Conf("runtime", "work.route"), arg, 3)
|
||||
m.Cmdy("ssh.remote", work, "check", "work", "search")
|
||||
|
||||
case "check": // 数字验签
|
||||
if m.Option("user.route") != m.Cmdx("ssh.remote", arg[2], "check", "work", arg[3]) {
|
||||
if m.Option("user.route") != m.Cmdx("ssh._route", kit.Select(m.Conf("runtime", "work.route"), arg, 3), "_check", "work", arg[2]) {
|
||||
m.Log("warn", "work error")
|
||||
m.Echo("false")
|
||||
} else {
|
||||
@ -252,14 +531,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
}
|
||||
|
||||
case "tool":
|
||||
switch arg[1] {
|
||||
case "check": // 数字验签
|
||||
m.Cmdy("ssh.remote", arg[2], "check", arg[0], arg[3:])
|
||||
case "run":
|
||||
m.Cmdy("ssh.remote", arg[2], "check", arg[0], "run", arg[3:])
|
||||
}
|
||||
|
||||
case "file":
|
||||
switch arg[1] {
|
||||
case "import":
|
||||
@ -283,7 +554,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
break
|
||||
}
|
||||
|
||||
msg := m.Cmd("ssh.remote", arg[3], "check", "file", arg[2])
|
||||
msg := m.Cmd("ssh._route", arg[3], "_check", "file", arg[2])
|
||||
h := msg.Append("hash")
|
||||
m.Conf("file", arg[2], map[string]interface{}{
|
||||
"create_time": m.Time(),
|
||||
@ -303,7 +574,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
f, e := os.Create(p)
|
||||
m.Assert(e)
|
||||
for i := 0; int64(i) < msg.Appendi("size"); i += 1024 {
|
||||
msg := m.Cmd("ssh.remote", arg[3], "check", "file", arg[2], 1, 1024, i)
|
||||
msg := m.Cmd("ssh._route", arg[3], "_check", "file", arg[2], 1, 1024, i)
|
||||
for _, d := range msg.Meta["data"] {
|
||||
b, e := hex.DecodeString(d)
|
||||
m.Assert(e)
|
||||
@ -324,7 +595,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
return
|
||||
}},
|
||||
"check": &ctx.Command{Name: "check node|user|work", Help: []string{"验签",
|
||||
"_check": &ctx.Command{Name: "_check node|user|work", Help: []string{"验签",
|
||||
"node", "user [node text]", "work name [node cert]",
|
||||
}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
switch arg[0] {
|
||||
@ -345,7 +616,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
case "work": // 工作验签
|
||||
switch arg[1] {
|
||||
case "search":
|
||||
m.Confm("cert", func(key string, value map[string]interface{}) {
|
||||
m.Confm("work", func(key string, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "user.route", value["user"])
|
||||
m.Add("append", "create_time", value["create_time"])
|
||||
@ -353,13 +624,13 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
m.Table()
|
||||
|
||||
default:
|
||||
if cert := m.Confm("cert", arg[1]); len(arg) == 2 {
|
||||
if cert := m.Confm("work", arg[1]); len(arg) == 2 {
|
||||
if cert != nil {
|
||||
m.Echo("%s", cert["user"])
|
||||
}
|
||||
} else { // 工作签证
|
||||
if cert == nil {
|
||||
m.Conf("cert", arg[1], map[string]interface{}{"create_time": m.Time(), "user": arg[2]})
|
||||
m.Conf("work", arg[1], map[string]interface{}{"create_time": m.Time(), "user": arg[2]})
|
||||
} else if cert["user"] != arg[2] {
|
||||
return // 签证失败
|
||||
}
|
||||
@ -367,35 +638,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
}
|
||||
|
||||
case "tool":
|
||||
if len(arg) == 1 {
|
||||
m.Confm("componet", func(key string, index int, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "index", index)
|
||||
m.Add("append", "name", value["componet_name"])
|
||||
m.Add("append", "help", value["componet_help"])
|
||||
})
|
||||
m.Table()
|
||||
break
|
||||
}
|
||||
switch arg[1] {
|
||||
case "run":
|
||||
tool := m.Confm("componet", []string{arg[2], arg[3]})
|
||||
msg := m.Find(kit.Format(tool["componet_ctx"]))
|
||||
msg.Cmd(tool["componet_cmd"], arg[4:]).CopyTo(m)
|
||||
|
||||
default:
|
||||
m.Confm("componet", arg[1:], func(value map[string]interface{}) {
|
||||
m.Add("append", "name", value["componet_name"])
|
||||
m.Add("append", "help", value["componet_help"])
|
||||
m.Add("append", "view", value["componet_view"])
|
||||
m.Add("append", "init", m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["componet_init"])), -1))
|
||||
m.Add("append", "inputs", kit.Format(value["inputs"]))
|
||||
})
|
||||
m.Table()
|
||||
}
|
||||
break
|
||||
|
||||
case "file":
|
||||
if len(arg) == 2 {
|
||||
m.Confm("file", arg[1], func(file map[string]interface{}) {
|
||||
@ -432,55 +674,47 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
}
|
||||
return
|
||||
}},
|
||||
"action": &ctx.Command{Name: "action", Help: "命令", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
hash := kit.Hashs(
|
||||
m.Option("text.rand"),
|
||||
m.Option("text.time"),
|
||||
m.Option("text.cmd"),
|
||||
m.Option("text.route"),
|
||||
"_exec": &ctx.Command{Name: "_exec", Help: "命令", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
access := kit.Hashs(
|
||||
m.Option("node.route"),
|
||||
m.Option("user.route"),
|
||||
m.Option("user.name"),
|
||||
m.Option("work.name"),
|
||||
m.Option("work.route"),
|
||||
m.Option("work.name"),
|
||||
m.Option("user.name"),
|
||||
)
|
||||
|
||||
// 文本验签
|
||||
if m.Option("text.hash") != hash {
|
||||
m.Echo("text error %s != %s", m.Option("text.hash"), hash)
|
||||
m.Log("warn", "text error")
|
||||
return
|
||||
}
|
||||
if m.Option("sessid", m.Cmd("aaa.auth", "access", access, "session").Append("key")); m.Option("username", m.Cmd("aaa.sess", "user").Append("meta")) != "" { // 历史会话
|
||||
m.Log("warn", "access: %s", access)
|
||||
m.Log("info", "sessid: %s", m.Option("sessid"))
|
||||
m.Option("trust", m.Cmdx("aaa.auth", "access", access, "data", "trust"))
|
||||
m.Option("userrole", m.Cmdx("aaa.auth", "access", access, "data", "userrole"))
|
||||
|
||||
// 设备验签
|
||||
if !m.Cmds("ssh.cert", "node", "check", hash) {
|
||||
m.Echo("node error of %s", m.Option("node.route"))
|
||||
return
|
||||
}
|
||||
|
||||
// 用户验签
|
||||
m.Option("username", m.Option("user.name"))
|
||||
if !m.Confs("runtime", "user.route") && m.Confs("trust", "fresh") {
|
||||
} else if m.Option("username", m.Option("user.name")); !m.Confs("runtime", "user.route") && m.Confs("trust", "fresh") { // 免签节点
|
||||
m.Log("warn", "trust fresh %s", m.Option("node.route"))
|
||||
m.Option("trust", "fresh")
|
||||
|
||||
} else if m.Cmds("ssh.cert", "node", "trust", m.Option("node.route")) {
|
||||
} else if m.Cmds("ssh._right", "node", "trust", m.Option("node.route")) { // 可信节点
|
||||
m.Log("warn", "trust node %s", m.Option("node.route"))
|
||||
m.Option("trust", "node")
|
||||
|
||||
} else if m.Options("user.route") && m.Cmds("ssh.cert", "node", "trust", m.Option("user.route")) && m.Cmds("ssh.cert", "user", "trust", m.Option("node.route")) {
|
||||
} else if m.Options("user.route") &&
|
||||
m.Cmds("ssh._right", "node", "trust", m.Option("user.route")) &&
|
||||
m.Cmds("ssh._right", "user", "trust", m.Option("node.route")) { // 可信用户
|
||||
m.Log("warn", "trust user %s", m.Option("user.route"))
|
||||
m.Option("trust", "user")
|
||||
|
||||
} else if m.Option("username", m.Option("work.name")); m.Options("work.route") && m.Cmds("ssh.cert", "node", "trust", m.Option("work.route")) && m.Cmds("ssh.cert", "work", "check", m.Option("work.route"), m.Option("username")) {
|
||||
} else if m.Option("username", m.Option("work.name")); m.Options("work.route") &&
|
||||
m.Cmds("ssh._right", "node", "trust", m.Option("work.route")) &&
|
||||
m.Cmds("ssh._right", "work", "check", m.Option("username"), m.Option("work.route")) { // 可信工作
|
||||
m.Log("warn", "trust work %s", m.Option("work.route"))
|
||||
m.Option("userrole", "tech")
|
||||
m.Option("trust", "work")
|
||||
|
||||
} else if m.Option("userrole", "void"); m.Confs("trust", "none") {
|
||||
} else if m.Option("userrole", "void"); m.Confs("trust", "none") { // 免签用户
|
||||
m.Log("warn", "trust none")
|
||||
m.Option("trust", "none")
|
||||
|
||||
} else {
|
||||
} else { // 验证失败
|
||||
m.Log("warn", "user error of %s", m.Option("user.route"))
|
||||
m.Echo("user error")
|
||||
return
|
||||
@ -488,7 +722,11 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
m.Log("info", "username: %s", m.Option("username"))
|
||||
|
||||
// 创建会话
|
||||
m.Option("sessid", m.Cmdx("aaa.user", "session", "select"))
|
||||
if !m.Options("sessid") {
|
||||
m.Option("sessid", m.Cmdx("aaa.user", "session", "select"))
|
||||
m.Cmd("aaa.auth", m.Cmdx("aaa.auth", m.Option("sessid"), "access", access),
|
||||
"data", "trust", m.Option("trust"), "userrole", m.Option("userrole"))
|
||||
}
|
||||
|
||||
// 创建空间
|
||||
m.Option("bench", m.Cmdx("aaa.sess", "bench", "select"))
|
||||
@ -503,185 +741,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
m.Cmdm(arg)
|
||||
return
|
||||
}},
|
||||
"remote": &ctx.Command{Name: "remote auto|dial|listen args...", Help: "连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
// 设备证书
|
||||
if !m.Confs("runtime", "node.cert") || !m.Confs("runtime", "node.key") {
|
||||
m.Cmd("ssh.cert", "node", "create")
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "auto": // 自动连接
|
||||
if m.Cmd("ssh.remote", "dial", "consul", "/shadow"); !m.Confs("runtime", "boot.ctx_box") {
|
||||
m.Cmd("ssh.remote", "listen", m.Conf("runtime", "boot.ssh_port"))
|
||||
m.Cmd("web.serve", "usr", m.Conf("runtime", "boot.web_port"))
|
||||
}
|
||||
|
||||
case "listen": // 监听连接
|
||||
m.Call(func(nfs *ctx.Message) *ctx.Message {
|
||||
if nfs.Has("node.port") {
|
||||
m.Log("info", "node.port %v", nfs.Optionv("node.port"))
|
||||
m.Conf("runtime", "node.port", nfs.Optionv("node.port"))
|
||||
}
|
||||
return nil
|
||||
}, "nfs.remote", arg)
|
||||
|
||||
case "redial": // 断线重连
|
||||
if !m.Caps("stream") {
|
||||
m.Cmdx("remote", "dial", arg[1:])
|
||||
}
|
||||
|
||||
case "dial": // 连接主机
|
||||
m.Call(func(nfs *ctx.Message) *ctx.Message {
|
||||
// 删除重连
|
||||
if m.Confs("timer", "timer") {
|
||||
m.Conf("timer", "timer", m.Cmdx("cli.timer", "delete", m.Conf("timer", "timer")))
|
||||
}
|
||||
|
||||
// 注册设备
|
||||
m.Spawn(nfs.Target()).Call(func(node *ctx.Message) *ctx.Message {
|
||||
// 添加网关
|
||||
m.Cmd("ssh.node", "create", node.Append("node.name"), "master", m.Cap("stream", nfs.Format("target")))
|
||||
|
||||
// 清理回调
|
||||
nfs.Free(func(nfs *ctx.Message) bool {
|
||||
m.Cmd("aaa.auth", m.Cmdx("aaa.auth", "nodes", node.Append("node.name")), "delete", "node")
|
||||
m.Cmd("ssh.node", "delete", node.Append("node.name"))
|
||||
m.Cap("stream", "")
|
||||
|
||||
// 断线重连
|
||||
m.Conf("timer", "timer", m.Cmdx("cli.timer", "repeat", m.Conf("timer", "interval"), "context", "ssh", "remote", "redial", arg[1:]))
|
||||
return true
|
||||
})
|
||||
|
||||
// 本机路由
|
||||
m.Cmd("cli.runtime", "node.route", node.Append("node.route")+"."+node.Result(0))
|
||||
|
||||
// 用户路由
|
||||
if m.Confs("runtime", "user.cert") && m.Confs("runtime", "user.key") {
|
||||
m.Cmd("cli.runtime", "user.route", m.Conf("runtime", "node.route"))
|
||||
|
||||
} else if node.Appends("user.route") && !m.Confs("runtime", "user.route") {
|
||||
m.Cmd("ssh.node", "share", "root", node.Append("user.route"))
|
||||
}
|
||||
|
||||
// 工作路由
|
||||
if node.Appends("work.route") && !m.Confs("runtime", "work.route") {
|
||||
m.Cmd("cli.runtime", "work.route", node.Append("work.route"))
|
||||
}
|
||||
return nil
|
||||
}, "send", "add", m.Conf("runtime", "node.name"), m.Conf("runtime", "node.type"), m.Conf("runtime", "node.cert"))
|
||||
return nil
|
||||
}, "nfs.remote", arg)
|
||||
|
||||
case "add":
|
||||
// 命名节点
|
||||
name := arg[1]
|
||||
for node := m.Confm("node", name); node != nil; node = m.Confm("node", name) {
|
||||
name = kit.Format("%s_%s", arg[1], m.Capi("nnode", 1))
|
||||
}
|
||||
|
||||
// 添加节点
|
||||
m.Cmd("ssh.node", "create", name, arg[2], m.Format("source"))
|
||||
|
||||
// 清理回调
|
||||
m.Sess("ms_source", false).Free(func(msg *ctx.Message) bool {
|
||||
m.Cmd("aaa.auth", m.Cmdx("aaa.auth", "nodes", name), "delete", "node")
|
||||
m.Cmd("ssh.node", "delete", name)
|
||||
return true
|
||||
})
|
||||
|
||||
// 同步信息
|
||||
m.Append("node.name", m.Conf("runtime", "node.name"))
|
||||
m.Append("user.name", m.Conf("runtime", "user.name"))
|
||||
m.Append("node.route", m.Conf("runtime", "node.route"))
|
||||
m.Append("user.route", m.Conf("runtime", "user.route"))
|
||||
m.Append("work.route", m.Conf("runtime", "work.route"))
|
||||
m.Echo(name).Back(m)
|
||||
|
||||
default:
|
||||
// 同步异步
|
||||
sync := true
|
||||
switch arg[0] {
|
||||
case "async", "sync":
|
||||
sync, arg = arg[0] == "sync", arg[1:]
|
||||
}
|
||||
|
||||
// 局域路由
|
||||
if arg[0] == m.Conf("runtime", "node.name") || arg[0] == m.Conf("runtime", "node.route") {
|
||||
arg[0] = ""
|
||||
}
|
||||
arg[0] = strings.TrimPrefix(arg[0], m.Conf("runtime", "node.route")+".")
|
||||
arg[0] = strings.TrimPrefix(arg[0], m.Conf("runtime", "node.name")+".")
|
||||
|
||||
// 拆分路由
|
||||
route, names, arg := arg[0], strings.SplitN(arg[0], ".", 2), arg[1:]
|
||||
if len(names) > 1 && names[0] == "" && names[1] != "" {
|
||||
names[0], names[1] = names[1], names[0]
|
||||
}
|
||||
|
||||
if rest := kit.Select("", names, 1); names[0] != "" {
|
||||
// 数字签名
|
||||
if !m.Options("remote_code") && arg[0] != "check" {
|
||||
hash, meta := kit.Hash("rand",
|
||||
m.Option("text.time", m.Time("stamp")),
|
||||
m.Option("text.cmd", strings.Join(arg, " ")),
|
||||
m.Option("text.route", route),
|
||||
m.Option("node.route", m.Conf("runtime", "node.route")),
|
||||
m.Option("user.route", kit.Select(m.Conf("runtime", "node.route"), m.Conf("runtime", "user.route"))),
|
||||
m.Option("user.name", m.Option("username")),
|
||||
m.Option("work.name", m.Conf("runtime", "work.name")),
|
||||
m.Option("work.route", m.Conf("runtime", "work.route")),
|
||||
)
|
||||
m.Option("text.rand", meta[0])
|
||||
m.Option("node.sign", m.Cmdx("aaa.rsa", "sign", m.Conf("runtime", "node.key"), m.Option("text.hash", hash)))
|
||||
}
|
||||
|
||||
// 查找路由
|
||||
ps := []string{}
|
||||
if names[0] == "%" || names[0] == "*" { // 广播命令
|
||||
m.Confm("node", names[0], func(name string, node map[string]interface{}) {
|
||||
if kit.Format(node["type"]) != "master" {
|
||||
ps = append(ps, kit.Format(node["module"]))
|
||||
}
|
||||
})
|
||||
|
||||
} else if m.Confm("node", names[0], func(node map[string]interface{}) { // 单播命令
|
||||
ps = append(ps, kit.Format(node["module"]))
|
||||
|
||||
}) == nil && m.Caps("stream") { // 上报命令
|
||||
rest = strings.Join(names, ".")
|
||||
ps = append(ps, m.Cap("stream"))
|
||||
}
|
||||
if len(ps) == 0 {
|
||||
m.Echo("error: not found %s", names[0]).Back(m)
|
||||
return
|
||||
}
|
||||
|
||||
// 路由转发
|
||||
for _, p := range ps {
|
||||
m.Find(p, true).Copy(m, "option").CallBack(sync, func(sub *ctx.Message) *ctx.Message {
|
||||
return m.CopyFuck(sub, "append").CopyFuck(sub, "result")
|
||||
}, "send", rest, arg)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 远程回调
|
||||
defer func() { m.Back(m) }()
|
||||
|
||||
// 执行命令
|
||||
if arg[0] == "check" { // 数字验签
|
||||
m.Cmd(arg)
|
||||
|
||||
} else if m.Options("remote_code") { // 远程调用
|
||||
m.Cmd("action", arg)
|
||||
|
||||
} else { // 本地调用
|
||||
m.Cmdm(arg)
|
||||
}
|
||||
}
|
||||
return
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,8 @@ func (tcp *TCP) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||
}
|
||||
func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool {
|
||||
address := []string{}
|
||||
if arg[1] == "consul" {
|
||||
m.Cmd("web.get", "dev", arg[2], "temp", "ports", "format", "object").Table(func(line map[string]string) {
|
||||
if arg[1] == "dev" {
|
||||
m.Cmd("web.get", arg[1], arg[2], "temp", "ports", "format", "object").Table(func(line map[string]string) {
|
||||
address = append(address, line["value"])
|
||||
})
|
||||
if len(address) == 0 {
|
||||
|
@ -437,7 +437,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}, Help: "工具列表"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"init": &ctx.Command{Name: "init", Help: "post请求", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"_init": &ctx.Command{Name: "_init", Help: "post请求", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
m.Cmd("web.spide", "cas", "client", "new", m.Conf("runtime", "boot.ctx_cas"))
|
||||
m.Cmd("web.spide", "dev", "client", "new", kit.Select(m.Conf("runtime", "boot.ctx_dev"), m.Conf("runtime", "boot.ctx_box")))
|
||||
return
|
||||
|
@ -323,7 +323,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
||||
}, Help: "嵌套层级日志的标记"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"init": &ctx.Command{Name: "init", Help: "添加语法规则, page: 语法集合, hash: 语句类型, word: 语法模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"_init": &ctx.Command{Name: "_init", Help: "添加语法规则, page: 语法集合, hash: 语句类型, word: 语法模板", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if yac, ok := m.Target().Server.(*YAC); m.Assert(ok) {
|
||||
yac.Caches["nline"] = &ctx.Cache{Name: "状态数量", Value: "64", Help: "状态机状态的数量"}
|
||||
yac.Caches["nnode"] = &ctx.Cache{Name: "节点数量", Value: "0", Help: "状态机连接的逻辑数量"}
|
||||
|
@ -36,7 +36,8 @@ func Marshal(m *ctx.Message, meta string) string {
|
||||
var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
Caches: map[string]*ctx.Cache{},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{"check": "false"}, Help: "默认组件"},
|
||||
"login": &ctx.Config{Name: "login", Value: map[string]interface{}{"check": "false"}, Help: "默认组件"},
|
||||
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
|
||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||
"index": []interface{}{
|
||||
map[string]interface{}{"componet_name": "chat", "componet_tmpl": "head", "metas": []interface{}{
|
||||
@ -49,32 +50,32 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
|
||||
map[string]interface{}{"componet_name": "ocean", "componet_tmpl": "fieldset",
|
||||
"componet_view": "Ocean", "componet_init": "initOcean",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "flow", "arguments": []interface{}{"ocean"},
|
||||
"componet_ctx": "web.chat", "componet_cmd": "ocean",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "steam", "componet_tmpl": "fieldset",
|
||||
"componet_view": "Steam", "componet_init": "initSteam",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "flow", "arguments": []interface{}{"steam"},
|
||||
"componet_ctx": "web.chat", "componet_cmd": "steam",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "river", "componet_tmpl": "fieldset",
|
||||
"componet_view": "River", "componet_init": "initRiver",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "flow", "arguments": []interface{}{"river"},
|
||||
"componet_ctx": "web.chat", "componet_cmd": "river",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "storm", "componet_tmpl": "fieldset",
|
||||
"componet_view": "Storm", "componet_init": "initStorm",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "flow", "arguments": []interface{}{"storm"},
|
||||
"componet_ctx": "web.chat", "componet_cmd": "storm",
|
||||
},
|
||||
|
||||
map[string]interface{}{"componet_name": "target", "componet_tmpl": "fieldset",
|
||||
"componet_view": "Target", "componet_init": "initTarget",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "flow", "arguments": []interface{}{"target"},
|
||||
"componet_ctx": "web.chat", "componet_cmd": "river",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "source", "componet_tmpl": "fieldset",
|
||||
"componet_view": "Source", "componet_init": "initSource",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "flow", "arguments": []interface{}{"source"},
|
||||
"componet_ctx": "web.chat", "componet_cmd": "storm",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "action", "componet_tmpl": "fieldset",
|
||||
"componet_view": "Action", "componet_init": "initAction",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "flow", "arguments": []interface{}{"action"},
|
||||
"componet_ctx": "web.chat", "componet_cmd": "storm",
|
||||
},
|
||||
|
||||
map[string]interface{}{"componet_name": "footer", "componet_tmpl": "fieldset",
|
||||
@ -86,7 +87,6 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
},
|
||||
},
|
||||
}, Help: "组件列表"},
|
||||
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
|
||||
|
||||
"chat_msg": &ctx.Config{Name: "chat_msg", Value: []interface{}{}, Help: "聊天记录"},
|
||||
"default": &ctx.Config{Name: "default", Value: "", Help: "聊天记录"},
|
||||
@ -114,170 +114,178 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
"flow": &ctx.Config{Name: "flow", Value: map[string]interface{}{}, Help: "聊天记录"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"flow": &ctx.Command{Name: "flow", Help: "信息流", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
"ocean": &ctx.Command{Name: "ocean", Help: "海洋", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy("ssh.work", "search")
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "ocean":
|
||||
m.Cmdy("ssh.cert", "work", "search")
|
||||
case "spawn":
|
||||
h := kit.Select(kit.Hashs("uniq"), arg, 1)
|
||||
user := map[string]interface{}{}
|
||||
for _, v := range arg[3:] {
|
||||
u := m.Cmdx("ssh._route", m.Conf("runtime", "work.route"), "_check", "work", v)
|
||||
user[v] = map[string]interface{}{
|
||||
"user": u,
|
||||
}
|
||||
}
|
||||
|
||||
case "river":
|
||||
if len(arg) == 1 {
|
||||
m.Confm("flow", func(key string, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "name", kit.Chains(value, "conf.name"))
|
||||
m.Add("append", "create_user", kit.Chains(value, "conf.create_user"))
|
||||
m.Add("append", "create_time", kit.Chains(value, "conf.create_time"))
|
||||
m.Conf("flow", h, map[string]interface{}{
|
||||
"conf": map[string]interface{}{
|
||||
"create_user": m.Option("username"),
|
||||
"create_time": m.Time(),
|
||||
"name": kit.Select("what", arg, 2),
|
||||
"route": kit.Select(m.Conf("runtime", "node.route"), m.Option("node.route"), arg[1] != ""),
|
||||
},
|
||||
"user": user,
|
||||
"text": map[string]interface{}{},
|
||||
"tool": map[string]interface{}{},
|
||||
})
|
||||
m.Echo(h)
|
||||
|
||||
if list, ok := kit.Chain(value, "text.list").([]interface{}); ok {
|
||||
m.Add("append", "count", len(list))
|
||||
} else {
|
||||
m.Add("append", "count", 0)
|
||||
}
|
||||
m.Option("username", m.Conf("runtime", "user.name"))
|
||||
m.Confm("flow", []string{h, "user"}, func(key string, value map[string]interface{}) {
|
||||
if kit.Format(value["user"]) != m.Conf("runtime", "node.route") {
|
||||
m.Cmd("ssh._route", value["user"], "context", "chat", "ocean", "spawn", h, arg[2])
|
||||
}
|
||||
})
|
||||
}
|
||||
return
|
||||
}},
|
||||
"river": &ctx.Command{Name: "river", Help: "河流", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Confm("flow", func(key string, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "name", kit.Chains(value, "conf.name"))
|
||||
m.Add("append", "create_user", kit.Chains(value, "conf.create_user"))
|
||||
m.Add("append", "create_time", kit.Chains(value, "conf.create_time"))
|
||||
|
||||
if list, ok := kit.Chain(value, "text.list").([]interface{}); ok {
|
||||
m.Add("append", "count", len(list))
|
||||
} else {
|
||||
m.Add("append", "count", 0)
|
||||
}
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "flow":
|
||||
if len(arg) == 2 {
|
||||
m.Confm("flow", []string{arg[1], "text.list"}, func(index int, value map[string]interface{}) {
|
||||
m.Add("append", "index", index)
|
||||
m.Add("append", "type", value["type"])
|
||||
m.Add("append", "text", value["text"])
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[1] {
|
||||
case "create":
|
||||
h := kit.Select(kit.Hashs("uniq"), arg, 2)
|
||||
user := map[string]interface{}{}
|
||||
for _, v := range arg[4:] {
|
||||
u := m.Cmdx("ssh.remote", m.Conf("runtime", "work.route"), "check", "work", v)
|
||||
user[v] = map[string]interface{}{
|
||||
"user": u,
|
||||
}
|
||||
if m.Conf("flow", []string{arg[1], "conf.route"}) != m.Conf("runtime", "node.route") && len(arg) == 4 {
|
||||
m.Cmdy("ssh._route", m.Conf("flow", []string{arg[1], "conf.route"}),
|
||||
"context", "chat", "river", "flow", arg[1], arg[2], arg[3])
|
||||
m.Log("info", "upstream")
|
||||
return
|
||||
}
|
||||
|
||||
m.Conf("flow", []string{arg[1], "text.list.-2"}, map[string]interface{}{
|
||||
"create_user": m.Option("username"),
|
||||
"create_time": m.Time(),
|
||||
"type": arg[2],
|
||||
"text": arg[3],
|
||||
})
|
||||
|
||||
count := m.Confi("flow", []string{arg[1], "text.count"}) + 1
|
||||
m.Confi("flow", []string{arg[1], "text.count"}, count)
|
||||
m.Echo("%d", count)
|
||||
|
||||
m.Option("username", m.Conf("runtime", "user.name"))
|
||||
m.Confm("flow", []string{arg[1], "user"}, func(key string, value map[string]interface{}) {
|
||||
if kit.Format(value["user"]) != m.Conf("runtime", "node.route") {
|
||||
m.Cmd("ssh._route", value["user"], "context", "chat", "river", "flow", arg[1], arg[2], arg[3], "sync")
|
||||
}
|
||||
})
|
||||
|
||||
m.Conf("flow", h, map[string]interface{}{
|
||||
"conf": map[string]interface{}{
|
||||
"create_user": m.Option("username"),
|
||||
"create_time": m.Time(),
|
||||
"name": kit.Select("what", arg, 3),
|
||||
"route": kit.Select(m.Conf("runtime", "node.route"), m.Option("node.route"), arg[2] != ""),
|
||||
},
|
||||
"user": user,
|
||||
"text": map[string]interface{}{},
|
||||
"tool": map[string]interface{}{},
|
||||
})
|
||||
m.Echo(h)
|
||||
case "wave":
|
||||
m.Option("username", "shy")
|
||||
m.Cmdy("ssh._route", arg[2], "tool", "run", arg[3], arg[4], arg[5:])
|
||||
}
|
||||
return
|
||||
}},
|
||||
"storm": &ctx.Command{Name: "storm", Help: "风雨", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 1 {
|
||||
m.Confm("flow", []string{arg[0], "tool"}, func(key string, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "count", kit.Len(value["list"]))
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
if len(arg) == 2 {
|
||||
m.Confm("flow", []string{arg[0], "tool", arg[1], "list"}, func(index int, tool map[string]interface{}) {
|
||||
m.Add("append", "river", arg[0])
|
||||
m.Add("append", "storm", arg[1])
|
||||
m.Add("append", "action", index)
|
||||
|
||||
m.Option("username", m.Conf("runtime", "user.name"))
|
||||
m.Confm("flow", []string{h, "user"}, func(key string, value map[string]interface{}) {
|
||||
m.Cmd("ssh.remote", value["user"], "context", "chat", "flow", "river", "create", h, arg[3])
|
||||
})
|
||||
m.Add("append", "node", tool["node"])
|
||||
m.Add("append", "group", tool["group"])
|
||||
m.Add("append", "index", tool["index"])
|
||||
|
||||
case "user":
|
||||
if m.Conf("flow", []string{arg[2], "conf.route"}) != m.Conf("runtime", "node.route") {
|
||||
m.Cmdy("ssh.remote", m.Conf("flow", []string{arg[2], "conf.route"}), "context", "chat", "flow", arg)
|
||||
m.Log("info", "upstream")
|
||||
return
|
||||
}
|
||||
m.Option("username", "shy")
|
||||
msg := m.Cmd("ssh._route", tool["node"], "tool", tool["group"], tool["index"])
|
||||
|
||||
if len(arg) == 3 {
|
||||
m.Confm("flow", []string{arg[2], "user"}, func(key string, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "user.route", value["user"])
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
m.Add("append", "name", msg.Append("name"))
|
||||
m.Add("append", "help", msg.Append("help"))
|
||||
m.Add("append", "view", msg.Append("view"))
|
||||
m.Add("append", "init", msg.Append("init"))
|
||||
m.Add("append", "inputs", msg.Append("inputs"))
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
case "wave":
|
||||
if len(arg) == 3 {
|
||||
m.Confm("flow", []string{arg[2], "text.list"}, func(index int, value map[string]interface{}) {
|
||||
m.Add("append", "index", index)
|
||||
m.Add("append", "type", value["type"])
|
||||
m.Add("append", "text", value["text"])
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
if tool := m.Confm("flow", []string{arg[0], "tool", arg[1], "list", arg[2]}); tool != nil {
|
||||
m.Option("username", "shy")
|
||||
m.Cmdy("ssh._route", tool["node"], "tool", "run", tool["group"], tool["index"], arg[3:])
|
||||
return
|
||||
}
|
||||
return
|
||||
}},
|
||||
"steam": &ctx.Command{Name: "steam", Help: "天空", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if m.Conf("flow", []string{arg[0], "conf.route"}) != m.Conf("runtime", "node.route") {
|
||||
m.Cmdy("ssh._remote", m.Conf("flow", []string{arg[0], "conf.route"}), "context", "chat", "steam", arg)
|
||||
m.Log("info", "upstream")
|
||||
return
|
||||
}
|
||||
if len(arg) == 1 {
|
||||
m.Confm("flow", []string{arg[0], "user"}, func(key string, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "user.route", value["user"])
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
if m.Conf("flow", []string{arg[2], "conf.route"}) != m.Conf("runtime", "node.route") && len(arg) == 5 {
|
||||
m.Cmdy("ssh.remote", m.Conf("flow", []string{arg[2], "conf.route"}),
|
||||
"context", "chat", "flow", "river", "wave", arg[2], arg[3], arg[4])
|
||||
m.Log("info", "upstream")
|
||||
return
|
||||
}
|
||||
|
||||
m.Conf("flow", []string{arg[2], "text.list.-2"}, map[string]interface{}{
|
||||
"create_user": m.Option("username"),
|
||||
"create_time": m.Time(),
|
||||
"type": arg[3],
|
||||
"text": arg[4],
|
||||
})
|
||||
|
||||
count := m.Confi("flow", []string{arg[2], "text.count"}) + 1
|
||||
m.Confi("flow", []string{arg[2], "text.count"}, count)
|
||||
m.Echo("%d", count)
|
||||
|
||||
m.Option("username", m.Conf("runtime", "user.name"))
|
||||
m.Confm("flow", []string{arg[2], "user"}, func(key string, value map[string]interface{}) {
|
||||
m.Cmd("ssh.remote", value["user"], "context", "chat", "flow", "river", "wave", arg[2], arg[3], arg[4], "sync")
|
||||
switch arg[1] {
|
||||
case "spawn":
|
||||
list := []interface{}{}
|
||||
for i := 3; i < len(arg)-3; i += 4 {
|
||||
list = append(list, map[string]interface{}{
|
||||
"node": arg[i], "group": arg[i+1], "index": arg[i+2], "name": arg[i+3],
|
||||
})
|
||||
}
|
||||
|
||||
case "storm":
|
||||
switch arg[1] {
|
||||
case "create":
|
||||
list := []interface{}{}
|
||||
for i := 4; i < len(arg)-3; i += 4 {
|
||||
list = append(list, map[string]interface{}{
|
||||
"node": arg[i], "group": arg[i+1], "index": arg[i+2], "name": arg[i+3],
|
||||
})
|
||||
}
|
||||
m.Conf("flow", []string{arg[0], "tool", arg[2]}, map[string]interface{}{
|
||||
"create_user": m.Option("username"),
|
||||
"create_time": m.Time(),
|
||||
"list": list,
|
||||
})
|
||||
|
||||
m.Conf("flow", []string{arg[2], "tool", arg[3]}, map[string]interface{}{
|
||||
"create_user": m.Option("username"),
|
||||
"create_time": m.Time(),
|
||||
"list": list,
|
||||
})
|
||||
|
||||
default:
|
||||
if len(arg) == 2 {
|
||||
m.Confm("flow", []string{arg[1], "tool"}, func(key string, value map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "count", kit.Len(value["list"]))
|
||||
})
|
||||
m.Table()
|
||||
break
|
||||
}
|
||||
|
||||
if len(arg) == 3 {
|
||||
m.Confm("flow", []string{arg[1], "tool", arg[2], "list"}, func(index int, tool map[string]interface{}) {
|
||||
m.Add("append", "river", arg[1])
|
||||
m.Add("append", "storm", arg[2])
|
||||
m.Add("append", "action", index)
|
||||
|
||||
m.Add("append", "node", tool["node"])
|
||||
m.Add("append", "group", tool["group"])
|
||||
m.Add("append", "index", tool["index"])
|
||||
|
||||
m.Option("username", "shy")
|
||||
msg := m.Cmd("ssh.cert", "tool", "check", tool["node"], tool["group"], tool["index"])
|
||||
|
||||
m.Add("append", "name", msg.Append("name"))
|
||||
m.Add("append", "help", msg.Append("help"))
|
||||
m.Add("append", "view", msg.Append("view"))
|
||||
m.Add("append", "init", msg.Append("init"))
|
||||
m.Add("append", "inputs", msg.Append("inputs"))
|
||||
})
|
||||
m.Table()
|
||||
break
|
||||
}
|
||||
|
||||
if tool := m.Confm("flow", []string{arg[1], "tool", arg[2], "list", arg[3]}); tool != nil {
|
||||
m.Option("username", "shy")
|
||||
m.Cmdy("ssh.cert", "tool", "run", tool["node"], tool["group"], tool["index"], arg[4:])
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
case "steam":
|
||||
switch arg[1] {
|
||||
case "tool":
|
||||
m.Cmdy("ssh.cert", "tool", "check", arg[2])
|
||||
}
|
||||
default:
|
||||
m.Option("username", "shy")
|
||||
m.Cmdy("ssh._route", m.Conf("flow", []string{arg[0], "user", arg[1], "user"}), "tool")
|
||||
}
|
||||
return
|
||||
}},
|
||||
|
@ -67,7 +67,7 @@ var page = Page({
|
||||
return
|
||||
}
|
||||
|
||||
var cmd = ["river", "create", "", ui.name.value]
|
||||
var cmd = ["spawn", "", ui.name.value]
|
||||
ui.list.querySelectorAll("pre").forEach(function(item) {
|
||||
cmd.push(item.innerText)
|
||||
})
|
||||
@ -84,7 +84,7 @@ var page = Page({
|
||||
]}])
|
||||
|
||||
pane.Show = function() {
|
||||
pane.ShowDialog() && (table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = "good", form.Run(["ocean"], function(msg) {
|
||||
pane.ShowDialog() && (table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = "good", form.Run([], function(msg) {
|
||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, row, i, tr, event) {
|
||||
tr.style.display = "none"
|
||||
var uis = kit.AppendChild(ui.list, [{text: [row.key], click: function(event) {
|
||||
@ -115,7 +115,7 @@ var page = Page({
|
||||
},
|
||||
initRiver: function(page, pane, form, output) {
|
||||
pane.Show = function() {
|
||||
output.Update(["river"], "text", ["name", "count"], "key", true)
|
||||
output.Update([], "text", ["name", "count"], "key", true)
|
||||
}
|
||||
pane.Show()
|
||||
pane.Action = {
|
||||
@ -133,8 +133,14 @@ var page = Page({
|
||||
},
|
||||
}
|
||||
|
||||
function fun(line, index, event, args, cbs) {
|
||||
var data = JSON.parse(line.text)
|
||||
var cmds = ["wave", river, data.node, data.group, data.index].concat(args)
|
||||
form.Run(cmds, cbs)
|
||||
}
|
||||
|
||||
pane.Show = function() {
|
||||
output.Update(["river", "wave", river], "text", ["text"], "index")
|
||||
output.Update(["flow", river], "text", ["text"], "index", false, fun)
|
||||
}
|
||||
|
||||
pane.postion = page.Sync()
|
||||
@ -143,8 +149,8 @@ var page = Page({
|
||||
}
|
||||
|
||||
pane.Send = function(type, text, cb) {
|
||||
form.Run(["river", "wave", river, type, text], function(msg) {
|
||||
output.Append(type, {text:text, index: msg.result[0]}, ["text"], "index"), typeof cb == "function" && cb()
|
||||
form.Run(["flow", river, type, text], function(msg) {
|
||||
output.Append(type, {text:text, index: msg.result[0]}, ["text"], "index", fun), typeof cb == "function" && cb()
|
||||
})
|
||||
}
|
||||
return [{"text": ["target"]}]
|
||||
@ -184,13 +190,17 @@ var page = Page({
|
||||
},
|
||||
}
|
||||
pane.Show = function() {
|
||||
output.Update(["storm", river, water], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) {
|
||||
var cmds = ["storm", river, water, index].concat(args)
|
||||
output.Update([river, water], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) {
|
||||
var cmds = [river, water, index].concat(args)
|
||||
|
||||
// event.shiftKey? page.target.Send("field", JSON.stringify({
|
||||
// componet_group: "index", componet_name: "river",
|
||||
// cmds: ["wave", river, line.node, line.group, line.index], input: [{type: "input", data: {name: "hi", value: line.cmd}}]
|
||||
//
|
||||
event.shiftKey? page.target.Send("field", JSON.stringify({
|
||||
componet_group: "index", componet_name: "river",
|
||||
cmds: cmds, input: [{type: "input", data: {name: "hi", value: line.cmd}}]
|
||||
|
||||
name: line.name, view: line.view, init: line.init,
|
||||
node: line.node, group: line.group, index: line.index,
|
||||
inputs: line.inputs,
|
||||
})): form.Run(cmds, function(msg) {
|
||||
event.ctrlKey && (msg.append && msg.append[0]?
|
||||
page.target.Send("table", JSON.stringify(ctx.Table(msg))):
|
||||
@ -220,10 +230,11 @@ var page = Page({
|
||||
pane.Listen = {
|
||||
river: function(value, old) {
|
||||
river = value, pane.Show()
|
||||
pane.which.set("")
|
||||
},
|
||||
}
|
||||
pane.Show = function() {
|
||||
output.Update(["storm", river], "text", ["key", "count"], "key", true)
|
||||
output.Update([river], "text", ["key", "count"], "key", true)
|
||||
}
|
||||
pane.Action = {
|
||||
"创建": function(event) {
|
||||
@ -253,7 +264,7 @@ var page = Page({
|
||||
return
|
||||
}
|
||||
|
||||
var cmd = ["storm", "create", river, ui.name.value]
|
||||
var cmd = [river, "spawn", ui.name.value]
|
||||
|
||||
ui.list.querySelectorAll("tr").forEach(function(item) {
|
||||
cmd.push(item.dataset.pod)
|
||||
@ -275,9 +286,9 @@ var page = Page({
|
||||
]}])
|
||||
|
||||
pane.Show = function() {
|
||||
pane.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", form.Run(["river", "user", river], function(msg) {
|
||||
pane.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", form.Run([river], function(msg) {
|
||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, pod, i, tr, event) {
|
||||
form.Run(["steam", "tool", pod["user.route"]], function(msg) {
|
||||
form.Run([river, pod.key], function(msg) {
|
||||
device.innerHTML = "", kit.AppendTable(device, ctx.Table(msg), ["key", "index", "name", "help"], function(value, key, com, i, tr, event) {
|
||||
var last = kit.AppendChild(ui.list, [{type: "tr", list: [
|
||||
{text: [com.key, "td"]}, {text: [com.index, "td"]}, {text: [com.name, "td"]}, {text: [com.help, "td"]},
|
||||
@ -310,9 +321,9 @@ var page = Page({
|
||||
if (type == "table") {
|
||||
kit.OrderTable(ui.last)
|
||||
}
|
||||
if (type == "field") {
|
||||
kit.OrderForm(page, ui.last, ui.form, ui.table, ui.code)
|
||||
}
|
||||
// if (type == "field") {
|
||||
// kit.OrderForm(page, ui.last, ui.form, ui.table, ui.code)
|
||||
// }
|
||||
list.push(ui.last)
|
||||
pane.scrollBy(0, pane.scrollHeight)
|
||||
return ui
|
||||
|
@ -72,23 +72,7 @@ function Page(page) {
|
||||
break
|
||||
|
||||
case "field":
|
||||
var data = JSON.parse(line.text)
|
||||
var input = [{type: "input", style: {"display": "none"}}]
|
||||
for (var i = 0; i < data.input.length; i++) {
|
||||
input.push(data.input[i])
|
||||
}
|
||||
|
||||
var result = [{view: ["", "fieldset"], list: [
|
||||
{text: ["", "legend"]},
|
||||
{name: "form", view: ["", "form"], dataset: {
|
||||
componet_group: data.componet_group,
|
||||
componet_name: data.componet_name,
|
||||
cmds: data.cmds,
|
||||
}, list: input},
|
||||
{name: "table", view: ["", "table"]},
|
||||
{view: ["", "code"], list: [{name: "code", view: ["", "pre"]}]},
|
||||
]}]
|
||||
break
|
||||
line = JSON.parse(line.text)
|
||||
|
||||
case "plugin":
|
||||
var id = "plugin"+page.ID()
|
||||
|
Loading…
x
Reference in New Issue
Block a user