From bfd7477b4e781ba8ac9e97769ed004d516e3d606 Mon Sep 17 00:00:00 2001 From: shylinux Date: Sun, 5 Jan 2020 19:27:40 +0800 Subject: [PATCH] add 401 --- base/nfs/nfs.go | 15 ++++++++++++-- base/tcp/tcp.go | 1 - base/web/web.go | 9 ++++++++- conf.go | 1 - core/chat/chat.go | 51 +++++++++++++++++++++++++++++++++-------------- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/base/nfs/nfs.go b/base/nfs/nfs.go index 3e73c983..a0484841 100644 --- a/base/nfs/nfs.go +++ b/base/nfs/nfs.go @@ -19,6 +19,13 @@ import ( func dir(m *ice.Message, root string, name string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string, format string) { if fs, e := ioutil.ReadDir(path.Join(root, name)); e != nil { + if f, e := os.Open(path.Join(root, name)); e == nil { + defer f.Close() + if b, e := ioutil.ReadAll(f); e == nil { + m.Echo(string(b)) + return + } + } m.Log(ice.LOG_WARN, "%s", e) } else { for _, f := range fs { @@ -138,9 +145,13 @@ var Index = &ice.Context{Name: "nfs", Help: "文件模块", ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }}, - "dir": {Name: "dir", Help: "目录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "dir": {Name: "dir", Help: "目录", List: kit.List( + kit.MDB_INPUT, "text", "name", "path", "action", "auto", + kit.MDB_INPUT, "button", "name", "查看", + kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", + ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { rg, _ := regexp.Compile(m.Option("dir_reg")) - dir(m, arg[0], arg[1], 0, false, "both", rg, + dir(m, kit.Select("./", m.Option("dir_root")), kit.Select("", arg, 0), 0, false, "both", rg, strings.Split(kit.Select("time size line path", arg, 2), " "), ice.ICE_TIME) }}, "save": {Name: "save path text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/base/tcp/tcp.go b/base/tcp/tcp.go index f17da547..fddbe90e 100644 --- a/base/tcp/tcp.go +++ b/base/tcp/tcp.go @@ -40,7 +40,6 @@ var Index = &ice.Context{Name: "tcp", Help: "网络模块", } } } - m.Table() } }}, }, diff --git a/base/web/web.go b/base/web/web.go index 41e4b8e0..78256078 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -224,6 +224,7 @@ func (web *Frame) HandleCmd(m *ice.Message, key string, cmd *ice.Command) { switch msg.Append("_output") { case "void": case "status": + msg.Info("status %s", msg.Result()) w.WriteHeader(kit.Int(kit.Select("200", msg.Result()))) case "file": @@ -242,6 +243,12 @@ func (web *Frame) HandleCmd(m *ice.Message, key string, cmd *ice.Command) { default: fmt.Fprint(w, msg.Formats("meta")) } + } else { + switch msg.Append("_output") { + case "status": + msg.Info("status %s", msg.Result()) + w.WriteHeader(kit.Int(kit.Select("200", msg.Result()))) + } } }) }) @@ -899,7 +906,7 @@ var Index = &ice.Context{Name: "web", Help: "网页模块", kit.Value(extra, arg[i], arg[i+1]) } index := m.Grow(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, favor), kit.Dict( - kit.MDB_TYPE, arg[1], kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3], + kit.MDB_TYPE, arg[1], kit.MDB_NAME, arg[2], kit.MDB_TEXT, kit.Select("", arg, 3), "extra", extra, )) m.Log(ice.LOG_INSERT, "favor: %s index: %d name: %s", favor, index, arg[2]) diff --git a/conf.go b/conf.go index a21379b5..b1913666 100644 --- a/conf.go +++ b/conf.go @@ -152,7 +152,6 @@ const ( // TYPE const ( // FAVOR FAVOR_CHAT = "chat.init" FAVOR_TMUX = "tmux.init" - FAVOR_RIVER = "river.init" FAVOR_START = "favor.start" FAVOR_MISS = "miss" ) diff --git a/core/chat/chat.go b/core/chat/chat.go index 93a310ba..259f05fa 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -15,9 +15,8 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmd(ice.CTX_CONFIG, "load", "chat.json") - m.Watch(ice.SYSTEM_INIT, "web.chat.init") - m.Watch(ice.USER_CREATE, "web.chat./ocean", "spawn", "") + m.Watch(ice.USER_CREATE, "web.chat./tutor", "init") }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmd(ice.CTX_CONFIG, "save", "chat.json", ice.CHAT_RIVER) @@ -26,17 +25,15 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", "init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(m.Confm(ice.CHAT_RIVER, "hash")) == 0 { // 系统群组 - m.Option(ice.MSG_USERROLE, ice.ROLE_ROOT) - m.Option(ice.MSG_USERNAME, m.Conf(ice.CLI_RUNTIME, "boot.username")) - river := m.Cmdx("web.chat./ocean", "spawn", "meet", m.Conf(ice.CLI_RUNTIME, "boot.username")) - river = m.Cmdx("web.chat./steam", river, "spawn", "miss", - "", "", "spide", "", - "", "", "space", "", - "", "", "dream", "", - "", "", "favor", "", - "", "", "story", "", - "", "", "share", "", - ) + if m.Richs(ice.WEB_FAVOR, nil, "river.root", nil) == nil { + m.Cmd(ice.WEB_FAVOR, "river.root", "storm", "miss") + m.Cmd(ice.WEB_FAVOR, "river.root", "field", "spide") + m.Cmd(ice.WEB_FAVOR, "river.root", "field", "space") + m.Cmd(ice.WEB_FAVOR, "river.root", "field", "dream") + m.Cmd(ice.WEB_FAVOR, "river.root", "field", "favor") + m.Cmd(ice.WEB_FAVOR, "river.root", "field", "story") + m.Cmd(ice.WEB_FAVOR, "river.root", "field", "share") + } // 用户权限 m.Cmd(ice.AAA_ROLE, "white", ice.ROLE_VOID, "enable", "/river") @@ -75,15 +72,39 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", // 登录检查 if m.Warn(!m.Options(ice.MSG_SESSID) || !m.Options(ice.MSG_USERNAME), "not login") { m.Option(ice.MSG_USERURL, "") + m.Push("_output", "status") + m.Set("result").Echo("401") + return } // 权限检查 if !m.Right(m.Option(ice.MSG_USERURL), m.Optionv("cmds")) { m.Option(ice.MSG_USERURL, "") + m.Push("_output", "status") + m.Set("result").Echo("403") } }}, "/toast": {Name: "/toast", Help: "提示", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, - "/tutor": {Name: "/tutor", Help: "向导", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, + "/tutor": {Name: "/tutor", Help: "向导", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + switch arg[0] { + case "init": + m.Richs(ice.AAA_USER, nil, arg[1], func(key string, value map[string]interface{}) { + m.Option(ice.MSG_USERNAME, value["username"]) + m.Option(ice.MSG_USERROLE, m.Cmdx(ice.AAA_ROLE, "check", value["username"])) + storm, river := "", m.Option(ice.MSG_RIVER, m.Cmdx("/ocean", "spawn", kit.Select(arg[1], value["nickname"])+"@"+m.Conf(ice.CLI_RUNTIME, "boot.hostname"), m.Option(ice.MSG_USERNAME))) + m.Richs(ice.WEB_FAVOR, nil, kit.Keys("river", m.Option(ice.MSG_USERROLE)), func(key string, value map[string]interface{}) { + m.Grows(ice.WEB_FAVOR, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) { + switch value["type"] { + case "storm": + storm = m.Option(ice.MSG_STORM, m.Cmdx("/steam", river, "spawn", value["name"])) + case "field": + m.Cmd("/storm", river, storm, "add", "", kit.Select("", value["text"]), value["name"], "") + } + }) + }) + }) + } + }}, "/debug": {Name: "/debug", Help: "调试", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, "/carte": {Name: "/carte", Help: "菜单", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -119,7 +140,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", case "spawn": // 创建群组 river := m.Rich(ice.CHAT_RIVER, nil, kit.Dict( - kit.MDB_META, kit.Dict(kit.MDB_NAME, kit.Select(arg[2]+"@"+m.Conf(ice.CLI_RUNTIME, "boot.hostname"), arg[1])), + kit.MDB_META, kit.Dict(kit.MDB_NAME, arg[1]), "user", kit.Data(kit.MDB_SHORT, "username"), "tool", kit.Data(), ))