From 079342ba8c964881a9f77ca23a32fc09b11ba4ed Mon Sep 17 00:00:00 2001 From: harveyshao Date: Mon, 3 Jan 2022 14:05:36 +0800 Subject: [PATCH] opt sso --- base/aaa/sess.go | 2 +- base/aaa/user.go | 15 +++++++++---- base/gdb/event.go | 4 +--- base/gdb/routine.go | 4 +--- base/gdb/signal.go | 23 ++++++++++---------- base/lex/matrix.go | 6 +++--- base/web/space.go | 5 +++++ base/yac/matrix.go | 4 +--- core/chat/header.go | 5 +++-- core/code/pprof.go | 28 ++++++++++++------------- core/code/shy.go | 12 +++++------ core/wiki/image.go | 6 +++--- core/wiki/spark.go | 51 +++++++++++++++++++++++---------------------- 13 files changed, 86 insertions(+), 79 deletions(-) diff --git a/base/aaa/sess.go b/base/aaa/sess.go index 41ba78a0..2a869c67 100644 --- a/base/aaa/sess.go +++ b/base/aaa/sess.go @@ -71,7 +71,7 @@ const SESS = "sess" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ SESS: {Name: SESS, Help: "会话", Value: kit.Data( - mdb.SHORT, "uniq", mdb.FIELD, "time,hash,userrole,username,ip,ua", mdb.EXPIRE, "720h", + mdb.SHORT, "uniq", mdb.FIELD, "time,hash,userrole,username,usernick,ip,ua", mdb.EXPIRE, "720h", )}, }, Commands: map[string]*ice.Command{ SESS: {Name: "sess hash auto prunes", Help: "会话", Action: ice.MergeAction(map[string]*ice.Action{ diff --git a/base/aaa/user.go b/base/aaa/user.go index 8062a911..586b43c2 100644 --- a/base/aaa/user.go +++ b/base/aaa/user.go @@ -26,6 +26,9 @@ func _user_login(m *ice.Message, name, word string) (ok bool) { return ok } func _user_create(m *ice.Message, role, name, word string) { + if name == "" { + return + } if word == "" { word = kit.Hashs() } @@ -52,15 +55,19 @@ func UserRole(m *ice.Message, username interface{}) (role string) { if role = VOID; username == ice.Info.UserName { return ROOT } - m.Richs(USER, nil, kit.Format(username), func(key string, value map[string]interface{}) { + if m.Richs(USER, nil, kit.Format(username), func(key string, value map[string]interface{}) { role = kit.Format(kit.GetMeta(value)[USERROLE]) - }) + }) == nil && kit.Format(username) == m.Option(ice.MSG_USERNAME) { + return m.Option(ice.MSG_USERROLE) + } return } func UserNick(m *ice.Message, username interface{}) (nick string) { - m.Richs(USER, nil, kit.Format(username), func(key string, value map[string]interface{}) { + if m.Richs(USER, nil, kit.Format(username), func(key string, value map[string]interface{}) { nick = kit.Format(kit.GetMeta(value)[USERNICK]) - }) + }) == nil && kit.Format(username) == m.Option(ice.MSG_USERNAME) { + return m.Option(ice.MSG_USERNICK) + } return } func UserZone(m *ice.Message, username interface{}) (zone string) { diff --git a/base/gdb/event.go b/base/gdb/event.go index fcbbf15d..d97f5042 100644 --- a/base/gdb/event.go +++ b/base/gdb/event.go @@ -20,9 +20,7 @@ const EVENT = "event" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ - EVENT: {Name: EVENT, Help: "事件流", Value: kit.Data( - mdb.SHORT, EVENT, mdb.FIELD, "time,id,cmd", - )}, + EVENT: {Name: EVENT, Help: "事件流", Value: kit.Data(mdb.SHORT, EVENT, mdb.FIELD, "time,id,cmd")}, }, Commands: map[string]*ice.Command{ EVENT: {Name: "event event id auto listen", Help: "事件流", Action: ice.MergeAction(map[string]*ice.Action{ LISTEN: {Name: "listen event cmd", Help: "监听", Hand: func(m *ice.Message, arg ...string) { diff --git a/base/gdb/routine.go b/base/gdb/routine.go index 0c46c747..0cbba1af 100644 --- a/base/gdb/routine.go +++ b/base/gdb/routine.go @@ -13,9 +13,7 @@ const ROUTINE = "routine" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ - ROUTINE: {Name: ROUTINE, Help: "协程池", Value: kit.Data( - mdb.SHORT, "time,hash,status,fileline", - )}, + ROUTINE: {Name: ROUTINE, Help: "协程池", Value: kit.Data(mdb.SHORT, "time,hash,status,fileline")}, }, Commands: map[string]*ice.Command{ ROUTINE: {Name: "routine hash auto prunes", Help: "协程池", Action: ice.MergeAction(map[string]*ice.Action{ mdb.CREATE: {Name: "create fileline status", Help: "创建"}, diff --git a/base/gdb/signal.go b/base/gdb/signal.go index af40037f..c5d71dc2 100644 --- a/base/gdb/signal.go +++ b/base/gdb/signal.go @@ -47,21 +47,20 @@ const SIGNAL = "signal" func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ SIGNAL: {Name: SIGNAL, Help: "信号器", Value: kit.Data( - mdb.SHORT, SIGNAL, mdb.FIELD, "time,signal,name,cmd", - nfs.PATH, path.Join(ice.VAR_RUN, "ice.pid"), + mdb.SHORT, SIGNAL, mdb.FIELD, "time,signal,name,cmd", nfs.PATH, path.Join(ice.VAR_RUN, "ice.pid"), )}, }, Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if log.LogDisable { - return // 禁用日志 - } - m.Cmd(nfs.SAVE, kit.Select(m.Conf(SIGNAL, kit.META_PATH), m.Conf(cli.RUNTIME, kit.Keys(cli.CONF, cli.CTX_PID))), - m.Conf(cli.RUNTIME, kit.Keys(cli.HOST, cli.PID))) - - m.Cmd(SIGNAL, LISTEN, SIGNAL, "3", mdb.NAME, "退出", ice.CMD, "exit 0") - m.Cmd(SIGNAL, LISTEN, SIGNAL, "2", mdb.NAME, "重启", ice.CMD, "exit 1") - }}, SIGNAL: {Name: "signal signal auto listen", Help: "信号器", Action: ice.MergeAction(map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + if log.LogDisable { + return // 禁用日志 + } + m.Cmd(nfs.SAVE, kit.Select(m.Config(nfs.PATH), m.Conf(cli.RUNTIME, kit.Keys(cli.CONF, cli.CTX_PID))), + m.Conf(cli.RUNTIME, kit.Keys(cli.HOST, cli.PID))) + + m.Cmd(SIGNAL, LISTEN, SIGNAL, "3", mdb.NAME, "退出", ice.CMD, "exit 0") + m.Cmd(SIGNAL, LISTEN, SIGNAL, "2", mdb.NAME, "重启", ice.CMD, "exit 1") + }}, LISTEN: {Name: "listen signal name cmd", Help: "监听", Hand: func(m *ice.Message, arg ...string) { _signal_listen(m, kit.Int(m.Option(SIGNAL)), arg...) }}, diff --git a/base/lex/matrix.go b/base/lex/matrix.go index 9f243825..8c71aecc 100644 --- a/base/lex/matrix.go +++ b/base/lex/matrix.go @@ -388,10 +388,10 @@ func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ MATRIX: {Name: MATRIX, Help: "魔方矩阵", Value: kit.Data()}, }, Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { - // _lex_load(m.Load()) - }}, MATRIX: {Name: "matrix hash npage text auto", Help: "魔方矩阵", Action: map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + // _lex_load(m.Load()) + }}, mdb.CREATE: {Name: "create nlang=32 ncell=128", Help: "创建", Hand: func(m *ice.Message, arg ...string) { mat := NewMatrix(m, kit.Int(kit.Select("32", m.Option(NLANG))), kit.Int(kit.Select("128", m.Option(NCELL)))) h := m.Rich(m.Prefix(MATRIX), "", kit.Data(mdb.TIME, m.Time(), MATRIX, mat, NLANG, mat.nlang, NCELL, mat.ncell)) diff --git a/base/web/space.go b/base/web/space.go index 2517dd9d..24f6fb24 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -286,6 +286,11 @@ func init() { case cli.PWD: link := kit.MergeURL(_space_domain(msg), aaa.GRANT, name) msg.Sleep300ms(SPACE, name, cli.PWD, name, link, msg.Cmdx(cli.QRCODE, link)) + case "sso": + link := _space_domain(msg) + ls := strings.Split(kit.ParseURL(link).Path, ice.PS) + link = kit.MergeURL2(_space_domain(msg), "/chat/sso", "space", kit.Select("", ls, 3), "back", m.Option(ice.MSG_USERWEB)) + msg.Sleep300ms(SPACE, name, cli.PWD, name, link, msg.Cmdx(cli.QRCODE, link)) default: msg.Sleep300ms(SPACE, name, cli.PWD, name) } diff --git a/base/yac/matrix.go b/base/yac/matrix.go index 7d3816da..73e09460 100644 --- a/base/yac/matrix.go +++ b/base/yac/matrix.go @@ -347,10 +347,8 @@ func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ MATRIX: {Name: MATRIX, Help: "魔方矩阵", Value: kit.Data(mdb.SHORT, mdb.NAME)}, }, Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { - _yac_load(m) - }}, MATRIX: {Name: "matrix name npage text auto", Help: "魔方矩阵", Action: map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _yac_load(m) }}, mdb.CREATE: {Name: "create name=shy nlang=32 ncell=32", Help: "创建", Hand: func(m *ice.Message, arg ...string) { mat := NewMatrix(m, kit.Int(kit.Select("32", m.Option(NLANG))), kit.Int(kit.Select("32", m.Option(NCELL)))) h := m.Rich(m.Prefix(MATRIX), "", kit.Data( diff --git a/core/chat/header.go b/core/chat/header.go index 0677eb67..1f80b94a 100644 --- a/core/chat/header.go +++ b/core/chat/header.go @@ -81,7 +81,7 @@ func init() { Index.Merge(&ice.Context{Configs: map[string]*ice.Config{ HEADER: {Name: HEADER, Help: "标题栏", Value: kit.Data( TITLE, "shylinux.com/x/contexts", MENUS, kit.List("header", kit.List("setting", "black", "white", "print", "webpack", "devpack")), - aaa.LOGIN, kit.List("登录", "扫码"), + aaa.LOGIN, kit.List("登录", "扫码", "授权"), )}, }, Commands: map[string]*ice.Command{ web.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -143,8 +143,9 @@ func init() { m.Cmdy(code.WEBPACK, mdb.REMOVE) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option(aaa.USERNICK, m.Option(ice.MSG_USERNICK)) msg := m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME)) - for _, k := range []string{aaa.USERNICK, aaa.LANGUAGE, aaa.BACKGROUND, aaa.AVATAR} { + for _, k := range []string{aaa.LANGUAGE, aaa.BACKGROUND, aaa.AVATAR} { m.Option(k, msg.Append(k)) } diff --git a/core/code/pprof.go b/core/code/pprof.go index 9e39fb6b..38a1ad1e 100644 --- a/core/code/pprof.go +++ b/core/code/pprof.go @@ -30,21 +30,16 @@ func init() { PPROF, kit.List(GO, "tool", PPROF), )}, }, Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool { - if p := r.URL.Path; strings.HasPrefix(p, "/debug") { - r.URL.Path = strings.Replace(r.URL.Path, "/debug", "/code", -1) - m.Debug("rewrite %v -> %v", p, r.URL.Path) - } - return false - }) - }}, - "/pprof/": {Name: "/pprof/", Help: "性能分析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - defer m.Render(ice.RENDER_VOID) - m.R.URL.Path = "/debug" + m.R.URL.Path - http.DefaultServeMux.ServeHTTP(m.W, m.R) - }}, PPROF: {Name: "pprof zone id auto", Help: "性能分析", Action: ice.MergeAction(map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool { + if p := r.URL.Path; strings.HasPrefix(p, "/debug") { + r.URL.Path = strings.Replace(r.URL.Path, "/debug", "/code", -1) + m.Debug("rewrite %v -> %v", p, r.URL.Path) + } + return false + }) + }}, mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { switch arg[0] { case BINNARY: @@ -89,5 +84,10 @@ func init() { m.PushButton(web.SERVE) }) }}, + "/pprof/": {Name: "/pprof/", Help: "性能分析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + defer m.Render(ice.RENDER_VOID) + m.R.URL.Path = "/debug" + m.R.URL.Path + http.DefaultServeMux.ServeHTTP(m.W, m.R) + }}, }}) } diff --git a/core/code/shy.go b/core/code/shy.go index 211fe5ca..2352e685 100644 --- a/core/code/shy.go +++ b/core/code/shy.go @@ -12,13 +12,13 @@ const SHY = "shy" func init() { Index.Register(&ice.Context{Name: SHY, Help: "脚本", Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - for _, cmd := range []string{mdb.PLUGIN, mdb.RENDER, mdb.ENGINE, mdb.SEARCH} { - m.Cmd(cmd, mdb.CREATE, SHY, m.Prefix(SHY)) - } - LoadPlug(m, SHY) - }}, SHY: {Name: SHY, Help: "脚本", Action: ice.MergeAction(map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + for _, cmd := range []string{mdb.PLUGIN, mdb.RENDER, mdb.ENGINE, mdb.SEARCH} { + m.Cmd(cmd, mdb.CREATE, SHY, m.Prefix(SHY)) + } + LoadPlug(m, SHY) + }}, mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.wiki.word", path.Join(arg[2], arg[1])) }}, diff --git a/core/wiki/image.go b/core/wiki/image.go index 5f26f984..bd35b914 100644 --- a/core/wiki/image.go +++ b/core/wiki/image.go @@ -23,10 +23,10 @@ const IMAGE = "image" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.Prefix(IMAGE)) - }}, IMAGE: {Name: "image url", Help: "图片", Action: map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + m.Cmd(mdb.RENDER, mdb.CREATE, PNG, m.PrefixKey()) + }}, mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { _image_show(m, path.Join(arg[2], arg[1])) }}, diff --git a/core/wiki/spark.go b/core/wiki/spark.go index 051ffda8..3fcb5a04 100644 --- a/core/wiki/spark.go +++ b/core/wiki/spark.go @@ -45,34 +45,35 @@ const SPARK = "spark" func init() { Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ - ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...interface{}) string { - arg := kit.Simple(args...) - if m.IsCliUA() { - if len(arg) > 1 { - arg = arg[1:] + SPARK: {Name: "spark [name] text auto field:text value:text", Help: "段落", Action: map[string]*ice.Action{ + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { + ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...interface{}) string { + arg := kit.Simple(args...) + if m.IsCliUA() { + if len(arg) > 1 { + arg = arg[1:] + } + return strings.Join(arg, ice.NL) } - return strings.Join(arg, ice.NL) - } - if len(arg) == 1 && arg[0] != BREAK { - arg = []string{SHELL, arg[0]} - } - list := []string{kit.Format(`
`, arg[0])} - for _, l := range strings.Split(strings.Join(arg[1:], ice.NL), ice.NL) { - switch list = append(list, "
"); arg[0] { - case SHELL: - list = append(list, "") - default: - list = append(list, "") + if len(arg) == 1 && arg[0] != BREAK { + arg = []string{SHELL, arg[0]} + } + list := []string{kit.Format(`
`, arg[0])} + for _, l := range strings.Split(strings.Join(arg[1:], ice.NL), ice.NL) { + switch list = append(list, "
"); arg[0] { + case SHELL: + list = append(list, "") + default: + list = append(list, "") + } + list = append(list, "", l, "") + list = append(list, "
") } - list = append(list, "", l, "") list = append(list, "
") - } - list = append(list, "
") - return strings.Join(list, "") - }) - }}, - SPARK: {Name: "spark [name] text auto field:text value:text", Help: "段落", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + return strings.Join(list, "") + }) + }}, + }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { m.Echo(`
`) return