1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
harveyshao 2022-11-14 01:27:01 +08:00
parent 1c85d50c56
commit ec9ce046da
10 changed files with 80 additions and 54 deletions

View File

@ -16,49 +16,39 @@ func _role_chain(arg ...string) string {
func _role_black(m *ice.Message, userrole, chain string) { func _role_black(m *ice.Message, userrole, chain string) {
mdb.HashSelectUpdate(m, userrole, func(value ice.Map) { mdb.HashSelectUpdate(m, userrole, func(value ice.Map) {
m.Logs(mdb.INSERT, ROLE, userrole, BLACK, chain) m.Logs(mdb.INSERT, ROLE, userrole, BLACK, chain)
list := value[BLACK].(ice.Map) black := value[BLACK].(ice.Map)
list[chain] = true black[chain] = true
}) })
} }
func _role_white(m *ice.Message, userrole, chain string) { func _role_white(m *ice.Message, userrole, chain string) {
mdb.HashSelectUpdate(m, userrole, func(value ice.Map) { mdb.HashSelectUpdate(m, userrole, func(value ice.Map) {
m.Logs(mdb.INSERT, ROLE, userrole, WHITE, chain) m.Logs(mdb.INSERT, ROLE, userrole, WHITE, chain)
list := value[WHITE].(ice.Map) white := value[WHITE].(ice.Map)
list[chain] = true 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) { func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
if userrole == ROOT { if userrole == ROOT {
return true // 超级权限 return true
} }
mdb.HashSelectDetail(m, kit.Select(VOID, userrole), func(value ice.Map) { 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 { if userrole == TECH {
return // 管理权限 ok = _role_check(value, keys, true)
} } else {
ok = _role_check(value, keys, false)
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 // 用户权限
} }
}) })
return ok return ok
@ -139,10 +129,27 @@ func RoleRight(m *ice.Message, userrole string, arg ...string) bool {
} }
func RoleAction(cmds ...string) ice.Actions { func RoleAction(cmds ...string) ice.Actions {
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { 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, WHITE, VOID, m.PrefixKey())
m.Cmd(ROLE, BLACK, VOID, m.PrefixKey(), "action")
for _, cmd := range cmds { 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)
} }
}}} }}}
} }

View File

@ -88,7 +88,7 @@ func SessCheck(m *ice.Message, sessid string) bool {
m.Option(ice.MSG_USERNICK, "") m.Option(ice.MSG_USERNICK, "")
return sessid != "" && m.Cmdy(SESS, CHECK, sessid).Option(ice.MSG_USERNAME) != "" 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) == "" { if m.Option(ice.MSG_SESSID) == "" {
return 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_USERNAME, value[USERNAME])
m.Option(ice.MSG_USERNICK, value[USERNICK]) 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))) m.Auth(USERROLE, value[USERROLE], USERNAME, value[USERNAME], USERNICK, value[USERNICK], arg, logs.FileLineMeta(logs.FileLine(2, 3)))
} }

View File

@ -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 { func CmdAction(args ...ice.Any) ice.Actions {
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...), return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...),
COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {

View File

@ -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 { 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) return !strings.HasPrefix(k, ice.MSG_SESSID)
})) }))
msg.Target().Cmd(msg, key, cmds...) if len(cmds) > 0 && cmds[0] == ctx.ACTION {
// if len(cmds) > 0 && cmds[0] == ctx.ACTION { msg.Target().Cmd(msg, key, cmds...)
// msg.Target().Cmd(msg, key, cmds...) } else {
// } else { msg.CmdHand(cmd, key, cmds...)
// cmd.Hand(msg, cmds...) }
// }
} }
// 输出响应 // 输出响应

View File

@ -78,7 +78,6 @@ const ACTION = "action"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
web.P(ACTION): {Name: "/action river storm action arg...", Help: "工作台", Actions: ice.MergeActions(ice.Actions{ 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) { mdb.MODIFY: {Hand: func(m *ice.Message, arg ...string) {
m.Cmdy(mdb.MODIFY, RIVER, _storm_key(m), mdb.LIST, m.OptionSimple(mdb.ID), arg) m.Cmdy(mdb.MODIFY, RIVER, _storm_key(m), mdb.LIST, m.OptionSimple(mdb.ID), arg)
}}, }},

View File

@ -20,7 +20,7 @@ func init() {
} }
} }
}}, }},
}, ctx.CmdAction(TITLE, `<a href="mailto:shylinuxc@gmail.com">shylinuxc@gmail.com</a>`), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) { }, ctx.CmdAction(TITLE, `<a href="mailto:shylinuxc@gmail.com">shylinuxc@gmail.com</a>`), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) {
m.Result(m.Configv(TITLE)) m.Result(m.Configv(TITLE))
}}, }},
}) })

View File

@ -77,14 +77,15 @@ func init() {
web.RenderCookie(m, aaa.SessCreate(m, arg[0])) web.RenderCookie(m, aaa.SessCreate(m, arg[0]))
} }
}}, }},
aaa.LOGOUT: {Hand: func(m *ice.Message, arg ...string) { aaa.UserLogout(m) }}, aaa.LOGOUT: {Hand: aaa.UserLogout},
aaa.PASSWORD: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }}, aaa.PASSWORD: {Hand: _header_users},
aaa.USERNICK: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }}, aaa.USERNICK: {Hand: _header_users},
aaa.LANGUAGE: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }}, aaa.LANGUAGE: {Hand: _header_users},
aaa.BACKGROUND: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }}, aaa.BACKGROUND: {Hand: _header_users},
aaa.AVATAR: {Hand: func(m *ice.Message, arg ...string) { _header_users(m, arg...) }}, aaa.AVATAR: {Hand: _header_users},
web.SHARE: {Hand: func(m *ice.Message, arg ...string) { _header_share(m, arg...) }}, web.SHARE: {Hand: _header_share},
}, ctx.ConfAction(aaa.LOGIN, kit.List("密码登录", "扫码授权")), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) { "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...) { if gdb.Event(m, HEADER_AGENT); !_header_check(m, arg...) {
return return
} }

View File

@ -3,7 +3,6 @@ package chat
import ( import (
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/gdb" "shylinux.com/x/icebergs/base/gdb"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
@ -42,7 +41,6 @@ const RIVER = "river"
func init() { func init() {
Index.MergeCommands(ice.Commands{ Index.MergeCommands(ice.Commands{
web.P(RIVER): {Name: "/river hash auto create", Help: "群组", Actions: ice.MergeActions(ice.Actions{ 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) { mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
switch arg[0] { switch arg[0] {
case nfs.TEMPLATE: case nfs.TEMPLATE:

View File

@ -11,7 +11,7 @@ const SEARCH = "search"
func init() { func init() {
Index.MergeCommands(ice.Commands{ 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() m.Cmdy(web.Space(m, m.Option(ice.POD)), mdb.SEARCH, arg).StatusTimeCount()
}}, }},
}) })

19
misc.go
View File

@ -255,6 +255,25 @@ func (m *Message) _command(arg ...Any) *Message {
m.Warn(!ok, ErrNotFound, kit.Format(list)) m.Warn(!ok, ErrNotFound, kit.Format(list))
return m 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 { func (c *Context) _command(m *Message, cmd *Command, key string, arg ...string) *Message {
key = kit.Slice(strings.Split(key, PT), -1)[0] key = kit.Slice(strings.Split(key, PT), -1)[0]
if m._key, m._cmd = key, cmd; cmd == nil { if m._key, m._cmd = key, cmd; cmd == nil {