diff --git a/base/aaa/role.go b/base/aaa/role.go
index 10e35d63..e106409a 100644
--- a/base/aaa/role.go
+++ b/base/aaa/role.go
@@ -16,49 +16,39 @@ func _role_chain(arg ...string) string {
func _role_black(m *ice.Message, userrole, chain string) {
mdb.HashSelectUpdate(m, userrole, func(value ice.Map) {
m.Logs(mdb.INSERT, ROLE, userrole, BLACK, chain)
- list := value[BLACK].(ice.Map)
- list[chain] = true
+ black := value[BLACK].(ice.Map)
+ black[chain] = true
})
}
func _role_white(m *ice.Message, userrole, chain string) {
mdb.HashSelectUpdate(m, userrole, func(value ice.Map) {
m.Logs(mdb.INSERT, ROLE, userrole, WHITE, chain)
- list := value[WHITE].(ice.Map)
- list[chain] = true
+ white := value[WHITE].(ice.Map)
+ white[chain] = true
})
}
+func _role_check(value ice.Map, keys []string, ok bool) bool {
+ white := value[WHITE].(ice.Map)
+ black := value[BLACK].(ice.Map)
+ for i := 0; i < len(keys); i++ {
+ if v, o := white[kit.Join(keys[:i+1], ice.PT)]; o && v == true {
+ ok = true
+ }
+ if v, o := black[kit.Join(keys[:i+1], ice.PT)]; o && v == true {
+ ok = false
+ }
+ }
+ return ok
+}
func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
if userrole == ROOT {
- return true // 超级权限
+ return true
}
-
mdb.HashSelectDetail(m, kit.Select(VOID, userrole), func(value ice.Map) {
- ok = true
- list := value[BLACK].(ice.Map)
- for i := 0; i < len(keys); i++ {
- if v, o := list[kit.Join(keys[:i+1], ice.PT)]; o && v == true {
- ok = false // 在黑名单
- }
- }
- if !ok {
- return // 没有权限
- }
if userrole == TECH {
- return // 管理权限
- }
-
- ok = false
- list = value[WHITE].(ice.Map)
- for i := 0; i < len(keys); i++ {
- if v, o := list[kit.Join(keys[:i+1], ice.PT)]; o && v == true {
- ok = true // 在白名单
- }
- }
- if !ok {
- return // 没有权限
- }
- if userrole == VOID {
- return // 用户权限
+ ok = _role_check(value, keys, true)
+ } else {
+ ok = _role_check(value, keys, false)
}
})
return ok
@@ -139,10 +129,27 @@ func RoleRight(m *ice.Message, userrole string, arg ...string) bool {
}
func RoleAction(cmds ...string) ice.Actions {
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
- m.Cmd(ROLE, WHITE, VOID, m.CommandKey())
m.Cmd(ROLE, WHITE, VOID, m.PrefixKey())
+ m.Cmd(ROLE, BLACK, VOID, m.PrefixKey(), "action")
for _, cmd := range cmds {
- m.Cmd(ROLE, WHITE, VOID, cmd)
+ m.Cmd(ROLE, WHITE, VOID, m.PrefixKey(), "action", cmd)
+ }
+ }}}
+}
+func WhiteAction(cmds ...string) ice.Actions {
+ return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
+ m.Cmd(ROLE, WHITE, VOID, m.CommandKey())
+ m.Cmd(ROLE, BLACK, VOID, m.CommandKey(), "action")
+ for _, cmd := range cmds {
+ m.Cmd(ROLE, WHITE, VOID, m.CommandKey(), "action", cmd)
+ }
+ }}}
+}
+func BlackAction(cmds ...string) ice.Actions {
+ return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
+ m.Cmd(ROLE, WHITE, VOID, m.CommandKey())
+ for _, cmd := range cmds {
+ m.Cmd(ROLE, BLACK, VOID, m.CommandKey(), "action", cmd)
}
}}}
}
diff --git a/base/aaa/sess.go b/base/aaa/sess.go
index 32cba2ca..2609fcb1 100644
--- a/base/aaa/sess.go
+++ b/base/aaa/sess.go
@@ -88,7 +88,7 @@ func SessCheck(m *ice.Message, sessid string) bool {
m.Option(ice.MSG_USERNICK, "")
return sessid != "" && m.Cmdy(SESS, CHECK, sessid).Option(ice.MSG_USERNAME) != ""
}
-func UserLogout(m *ice.Message) {
+func UserLogout(m *ice.Message, arg ...string) {
if m.Option(ice.MSG_SESSID) == "" {
return
}
@@ -99,4 +99,4 @@ func SessAuth(m *ice.Message, value ice.Maps, arg ...string) {
m.Option(ice.MSG_USERNAME, value[USERNAME])
m.Option(ice.MSG_USERNICK, value[USERNICK])
m.Auth(USERROLE, value[USERROLE], USERNAME, value[USERNAME], USERNICK, value[USERNICK], arg, logs.FileLineMeta(logs.FileLine(2, 3)))
-}
\ No newline at end of file
+}
diff --git a/base/ctx/command.go b/base/ctx/command.go
index 2421ce98..3da51f57 100644
--- a/base/ctx/command.go
+++ b/base/ctx/command.go
@@ -123,6 +123,9 @@ func init() {
})
}
+func CmdHandler(args ...ice.Any) ice.Handler {
+ return func(m *ice.Message, arg ...string) { m.Cmdy(args...) }
+}
func CmdAction(args ...ice.Any) ice.Actions {
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...),
COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
diff --git a/base/web/serve.go b/base/web/serve.go
index a14d38c5..775e49c8 100644
--- a/base/web/serve.go
+++ b/base/web/serve.go
@@ -268,12 +268,11 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
msg.Option(ice.MSG_OPTS, kit.Filter(kit.Simple(msg.Optionv(ice.MSG_OPTION)), func(k string) bool {
return !strings.HasPrefix(k, ice.MSG_SESSID)
}))
- msg.Target().Cmd(msg, key, cmds...)
- // if len(cmds) > 0 && cmds[0] == ctx.ACTION {
- // msg.Target().Cmd(msg, key, cmds...)
- // } else {
- // cmd.Hand(msg, cmds...)
- // }
+ if len(cmds) > 0 && cmds[0] == ctx.ACTION {
+ msg.Target().Cmd(msg, key, cmds...)
+ } else {
+ msg.CmdHand(cmd, key, cmds...)
+ }
}
// 输出响应
diff --git a/core/chat/action.go b/core/chat/action.go
index 0fb82c23..71844c9c 100644
--- a/core/chat/action.go
+++ b/core/chat/action.go
@@ -78,7 +78,6 @@ const ACTION = "action"
func init() {
Index.MergeCommands(ice.Commands{
web.P(ACTION): {Name: "/action river storm action arg...", Help: "工作台", Actions: ice.MergeActions(ice.Actions{
- ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(aaa.ROLE, aaa.BLACK, aaa.VOID, m.CommandKey(), ctx.ACTION) }},
mdb.MODIFY: {Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.MODIFY, RIVER, _storm_key(m), mdb.LIST, m.OptionSimple(mdb.ID), arg)
}},
diff --git a/core/chat/footer.go b/core/chat/footer.go
index c7bb74bf..e4977eb2 100644
--- a/core/chat/footer.go
+++ b/core/chat/footer.go
@@ -20,7 +20,7 @@ func init() {
}
}
}},
- }, ctx.CmdAction(TITLE, `shylinuxc@gmail.com`), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
+ }, ctx.CmdAction(TITLE, `shylinuxc@gmail.com`), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) {
m.Result(m.Configv(TITLE))
}},
})
diff --git a/core/chat/header.go b/core/chat/header.go
index 012a1b12..8f93fe0b 100644
--- a/core/chat/header.go
+++ b/core/chat/header.go
@@ -77,14 +77,15 @@ func init() {
web.RenderCookie(m, aaa.SessCreate(m, arg[0]))
}
}},
- aaa.LOGOUT: {Hand: func(m *ice.Message, arg ...string) { aaa.UserLogout(m) }},
- aaa.PASSWORD: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }},
- aaa.USERNICK: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }},
- aaa.LANGUAGE: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }},
- aaa.BACKGROUND: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }},
- aaa.AVATAR: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }},
- web.SHARE: {Hand: func(m *ice.Message, arg ...string) { _header_share(m, arg...) }},
- }, ctx.ConfAction(aaa.LOGIN, kit.List("密码登录", "扫码授权")), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
+ aaa.LOGOUT: {Hand: aaa.UserLogout},
+ aaa.PASSWORD: {Hand: _header_users},
+ aaa.USERNICK: {Hand: _header_users},
+ aaa.LANGUAGE: {Hand: _header_users},
+ aaa.BACKGROUND: {Hand: _header_users},
+ aaa.AVATAR: {Hand: _header_users},
+ web.SHARE: {Hand: _header_share},
+ "webpack": {Hand: ctx.CmdHandler("webpack", "build")},
+ }, ctx.ConfAction(aaa.LOGIN, kit.List("密码登录", "扫码授权")), aaa.BlackAction("webpack")), Hand: func(m *ice.Message, arg ...string) {
if gdb.Event(m, HEADER_AGENT); !_header_check(m, arg...) {
return
}
diff --git a/core/chat/river.go b/core/chat/river.go
index f85f899c..21049b43 100644
--- a/core/chat/river.go
+++ b/core/chat/river.go
@@ -3,7 +3,6 @@ package chat
import (
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
- "shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/gdb"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
@@ -42,7 +41,6 @@ const RIVER = "river"
func init() {
Index.MergeCommands(ice.Commands{
web.P(RIVER): {Name: "/river hash auto create", Help: "群组", Actions: ice.MergeActions(ice.Actions{
- ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(aaa.ROLE, aaa.BLACK, aaa.VOID, m.CommandKey(), ctx.ACTION) }},
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
switch arg[0] {
case nfs.TEMPLATE:
diff --git a/core/chat/search.go b/core/chat/search.go
index 2500584d..011ce696 100644
--- a/core/chat/search.go
+++ b/core/chat/search.go
@@ -11,7 +11,7 @@ const SEARCH = "search"
func init() {
Index.MergeCommands(ice.Commands{
- web.P(SEARCH): {Name: "/search", Help: "搜索引擎", Actions: ctx.CmdAction(), Hand: func(m *ice.Message, arg ...string) {
+ web.P(SEARCH): {Name: "/search", Help: "搜索框", Actions: ctx.CmdAction(), Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(web.Space(m, m.Option(ice.POD)), mdb.SEARCH, arg).StatusTimeCount()
}},
})
diff --git a/misc.go b/misc.go
index 64fc4f08..34a35d47 100644
--- a/misc.go
+++ b/misc.go
@@ -255,6 +255,25 @@ func (m *Message) _command(arg ...Any) *Message {
m.Warn(!ok, ErrNotFound, kit.Format(list))
return m
}
+func (m *Message) CmdHand(cmd *Command, key string, arg ...string) *Message {
+ if m._key, m._cmd = key, cmd; cmd == nil {
+ return m
+ }
+ if m._target = kit.FileLine(cmd.Hand, 3); cmd.RawHand != nil {
+ m._target = kit.Format(cmd.RawHand)
+ }
+ if fileline := kit.Select(m._target, m._source, m.target.Name == MDB); key == "select" {
+ m.Log(LOG_CMDS, "%s.%s %d %v %v", m.Target().Name, key, len(arg), arg, m.Optionv(MSG_FIELDS), logs.FileLineMeta(fileline))
+ } else {
+ m.Log(LOG_CMDS, "%s.%s %d %v", m.Target().Name, key, len(arg), arg, logs.FileLineMeta(fileline))
+ }
+ if cmd.Hand != nil {
+ cmd.Hand(m, arg...)
+ } else if cmd.Actions != nil && cmd.Actions["select"] != nil {
+ cmd.Actions["select"].Hand(m, arg...)
+ }
+ return m
+}
func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string) *Message {
key = kit.Slice(strings.Split(key, PT), -1)[0]
if m._key, m._cmd = key, cmd; cmd == nil {