diff --git a/base/aaa/user.go b/base/aaa/user.go index 9ca422f8..850ee56a 100644 --- a/base/aaa/user.go +++ b/base/aaa/user.go @@ -4,6 +4,8 @@ import ( "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" "github.com/shylinux/toolkits" + + "strings" ) func _user_list(m *ice.Message) { @@ -16,6 +18,7 @@ func _user_login(m *ice.Message, name, word string) (ok bool) { if value[PASSWORD] == "" { ok, value[PASSWORD] = true, word } else if value[PASSWORD] == word { + m.Log_AUTH(USERNAME, name, PASSWORD, strings.Repeat("*", len(word))) ok = true } }) @@ -46,7 +49,6 @@ func UserLogin(m *ice.Message, username, password string) bool { if _user_login(m, username, password) { m.Option(ice.MSG_USERNAME, username) m.Option(ice.MSG_USERROLE, UserRole(m, username)) - m.Option(ice.MSG_SESSID, SessCreate(m, m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE))) return true } return false diff --git a/base/cli/system.go b/base/cli/system.go index 57f13be1..63363b6d 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -28,8 +28,11 @@ func _system_show(m *ice.Message, cmd *exec.Cmd) { err := bytes.NewBuffer(make([]byte, 0, 1024)) cmd.Stdout = out cmd.Stderr = err + defer func() { + m.Cost("%v exit: %v out: %v err: %v ", + cmd.Args, cmd.ProcessState.ExitCode(), out.Len(), err.Len()) + }() - defer m.Cost("%v exit: %v out: %v err: %v ", cmd.Args, 0, out.Len(), err.Len()) if e := cmd.Run(); e != nil { m.Warn(e != nil, "%v run: %s", cmd.Args, kit.Select(e.Error(), err.String())) } diff --git a/base/web/cache.go b/base/web/cache.go index c2510561..cf5bec08 100644 --- a/base/web/cache.go +++ b/base/web/cache.go @@ -103,8 +103,8 @@ func _cache_watch(m *ice.Message, key, file string) { func _cache_catch(m *ice.Message, arg ...string) []string { if r, ok := m.Optionv("response").(*http.Response); ok { return _cache_download(m, r, arg...) - } else if m.R != nil { - return _cache_upload(m, arg...) + // } else if m.R != nil { + // return _cache_upload(m, arg...) } if f, e := os.Open(arg[2]); m.Assert(e) { @@ -187,6 +187,10 @@ func init() { _cache_show(m, "", "", "") } }}, + kit.MDB_INSERT: {Name: "insert type name", Help: "插入", Hand: func(m *ice.Message, arg ...string) { + arg = _cache_catch(m, arg[0], arg[1]) + _cache_save(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...) + }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { _cache_list(m, "") diff --git a/base/web/favor.go b/base/web/favor.go index c4f06c8e..0606700f 100644 --- a/base/web/favor.go +++ b/base/web/favor.go @@ -8,12 +8,6 @@ import ( "os" ) -const ( - EXPORT = "usr/export/web.favor/favor.csv" -) - -var FAVOR = ice.Name("favor", Index) - func _favor_list(m *ice.Message, zone, id string, fields ...string) { m.Richs(FAVOR, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) { if val = val[kit.MDB_META].(map[string]interface{}); zone == "" { @@ -248,6 +242,12 @@ func FavorShow(m *ice.Message, kind string, name, text interface{}, arg ...strin return m } +const ( + EXPORT = "usr/export/web.favor/favor.csv" +) + +var FAVOR = ice.Name("favor", Index) + func init() { Index.Merge(&ice.Context{ Configs: map[string]*ice.Config{ diff --git a/base/web/serve.go b/base/web/serve.go index c0ac8a34..ac09e320 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -26,7 +26,10 @@ func Login(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool { if !msg.Options(ice.MSG_USERNAME) && tcp.IPIsLocal(msg, msg.Option(ice.MSG_USERIP)) { // 自动认证 if aaa.UserLogin(msg, cli.UserName, cli.PassWord) { - Render(msg, "cookie", msg.Option(ice.MSG_SESSID)) + if strings.HasPrefix(msg.Option(ice.MSG_USERUA), "Mozilla/5.0") { + msg.Option(ice.MSG_SESSID, aaa.SessCreate(msg, msg.Option(ice.MSG_USERNAME), msg.Option(ice.MSG_USERROLE))) + Render(msg, "cookie", msg.Option(ice.MSG_SESSID)) + } } } diff --git a/base/web/web.go b/base/web/web.go index c1226e27..885d889a 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -42,7 +42,7 @@ func Format(key string, arg ...interface{}) string { } func Render(msg *ice.Message, cmd string, args ...interface{}) { if cmd != "" { - msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args) + defer func() { msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args) }() } switch arg := kit.Simple(args...); cmd { case ice.RENDER_VOID: @@ -73,6 +73,7 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) { if len(arg) > 0 { msg.W.Write([]byte(kit.Format(arg[0], args[1:]...))) } else { + args = append(args, "length:", len(msg.Result())) msg.W.Write([]byte(msg.Result())) } diff --git a/core/chat/action.go b/core/chat/action.go index 1dbd6de4..d66aeca1 100644 --- a/core/chat/action.go +++ b/core/chat/action.go @@ -167,7 +167,7 @@ func init() { _action_share_show(m, arg[0], arg[1], arg[2], arg[3:]...) return } - if arg[3] == "action" && _action_action(m, arg[3]) { + if len(arg) > 3 && arg[3] == "action" && _action_action(m, arg[3]) { // 前置命令 return } diff --git a/core/chat/chat.go b/core/chat/chat.go index 32f506a0..e429eaf2 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -81,14 +81,11 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", "/storm.add", }), "white", kit.Dict("void", []interface{}{ - "/toast", - "/carte", - "/tutor", - "/login", + "/header", "/river", "/storm", "/action", - "web.wiki.note", + "/footer", }), )}, }, @@ -156,6 +153,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", case "login": // 密码登录 if len(arg) > 2 && aaa.UserLogin(m, arg[1], arg[2]) { + m.Option(ice.MSG_SESSID, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE))) web.Render(m, "cookie", m.Option(ice.MSG_SESSID)) } @@ -175,6 +173,9 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", } } + if m.Right(m.Option(ice.MSG_USERURL), m.Optionv("cmds")) { + return + } // 登录检查 if m.Warn(!m.Options(ice.MSG_USERNAME), "not login") { if m.Option("share") == "" { diff --git a/core/code/pprof.go b/core/code/pprof.go index dcc7d509..2d1618cf 100644 --- a/core/code/pprof.go +++ b/core/code/pprof.go @@ -52,25 +52,26 @@ func _pprof_show(m *ice.Message, zone string, id string) { list := []string{} m.Grows(PPROF, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { task.Put(val, func(task *task.Task) error { + m.Sleep("1s") // 压测命令 - m.Sleep("1s").Log_EXPORT(kit.MDB_META, PPROF, kit.MDB_ZONE, zone, kit.MDB_VALUE, kit.Format(value)) + m.Log_EXPORT(kit.MDB_META, PPROF, kit.MDB_ZONE, zone, kit.MDB_VALUE, kit.Format(value)) cmd := kit.Format(value[kit.MDB_TYPE]) arg := kit.Format(value[kit.MDB_TEXT]) res := web.FavorShow(m.Spawn(), cmd, kit.Format(value[kit.MDB_NAME]), arg, kit.Simple(value[kit.MDB_EXTRA])...).Result() - web.FavorInsert(m, favor, cmd, arg, res) + m.Cmd(web.FAVOR, favor, cmd, arg, res) list = append(list, cmd+": "+arg, res) return nil }) }) // 收藏程序 - bin := web.CacheCatch(m.Spawn(), kit.MIME_FILE, kit.Format(val[BINNARY])).Append(kit.MDB_TEXT) - web.FavorInsert(m, favor, kit.MIME_FILE, bin, val[BINNARY]) + bin := m.Cmd(web.CACHE, "catch", kit.MIME_FILE, kit.Format(val[BINNARY])).Append(kit.MDB_TEXT) + m.Cmd(web.FAVOR, favor, kit.MIME_FILE, bin, val[BINNARY]) // 性能分析 msg := m.Cmd(ice.WEB_SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", val[SERVICE]), "seconds", kit.Select("5", kit.Format(val[SECONDS]))) - web.FavorInsert(m, favor, PPROF, msg.Append(kit.MDB_TEXT), kit.Keys(zone, "pd.gz")) + m.Cmd(web.FAVOR, favor, PPROF, msg.Append(kit.MDB_TEXT), kit.Keys(zone, "pd.gz")) // 结果摘要 cmd := kit.Simple(m.Confv(PPROF, "meta.pprof"), "-text", val[BINNARY], msg.Append(kit.MDB_TEXT)) @@ -78,7 +79,7 @@ func _pprof_show(m *ice.Message, zone string, id string) { if len(res) > 20 { res = res[:20] } - web.FavorInsert(m, favor, ice.TYPE_SHELL, strings.Join(cmd, " "), strings.Join(res, "\n")) + m.Cmd(web.FAVOR, favor, ice.TYPE_SHELL, strings.Join(cmd, " "), strings.Join(res, "\n")) list = append(list, ice.TYPE_SHELL+": "+strings.Join(cmd, " "), strings.Join(res, "\n")) // 结果展示 @@ -88,7 +89,7 @@ func _pprof_show(m *ice.Message, zone string, id string) { m.Cmd(cli.DAEMON, m.Confv(PPROF, "meta.pprof"), "-http="+p, val[BINNARY], msg.Append(kit.MDB_TEXT)) url := "http://" + p + "/ui/top" - web.FavorInsert(m, favor, ice.TYPE_SPIDE, url, msg.Append(kit.MDB_TEXT)) + m.Cmd(web.FAVOR, favor, ice.TYPE_SPIDE, url, msg.Append(kit.MDB_TEXT)) m.Set(ice.MSG_RESULT).Echo(url).Echo(" \n").Echo("\n") m.Echo(strings.Join(list, "\n")).Echo("\n") diff --git a/info.go b/info.go index 7c2a3b30..969b7199 100644 --- a/info.go +++ b/info.go @@ -34,7 +34,7 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message { } switch level { - case LOG_INFO, LOG_WARN, "refer", "form": + case LOG_CMDS, LOG_INFO, LOG_WARN, "refer", "form": default: _, file, line, _ := runtime.Caller(2) ls := strings.Split(file, "/") diff --git a/misc/input/input.go b/misc/input/input.go index 4bd46d72..fe02c28b 100644 --- a/misc/input/input.go +++ b/misc/input/input.go @@ -75,7 +75,7 @@ func _input_find(m *ice.Message, method, word, limit string) { } else { if method == WORD && i == 0 { // 添加收藏 - web.FavorInsert(m, "input.word", "input", line[2], line[4], "id", line[3], WEIGHT, line[6]) + // web.FavorInsert(m.Spawn(), "input.word", "input", line[2], line[4], "id", line[3], WEIGHT, line[6]) } // 输出词汇 diff --git a/type.go b/type.go index bd39f160..6b35208f 100644 --- a/type.go +++ b/type.go @@ -133,7 +133,11 @@ func (c *Context) Register(s *Context, x Server, name ...string) *Context { s.server = x return s } -func (c *Context) Merge(s *Context, x Server) *Context { +func (c *Context) Merge(s *Context, x Server, name ...string) *Context { + for _, n := range name { + Name(n, s) + } + if c.Commands == nil { c.Commands = map[string]*Command{} }