From ffe18771a1fddc632dc60dbdd7ea27c6c0af620c Mon Sep 17 00:00:00 2001 From: harveyshao Date: Wed, 23 Nov 2022 13:37:27 +0800 Subject: [PATCH] opt aaa --- base/aaa/aaa.go | 2 +- base/aaa/email.go | 12 +++--- base/aaa/offer.go | 21 +++++---- base/aaa/role.go | 101 +++++++++++++++++++------------------------- base/aaa/sess.go | 28 ++++++------ base/aaa/totp.go | 3 +- base/aaa/user.go | 24 +++++------ base/ctx/command.go | 2 +- base/ctx/config.go | 2 +- base/web/serve.go | 4 +- core/chat/action.go | 6 +-- meta.go | 14 +++++- misc.go | 3 +- 13 files changed, 106 insertions(+), 116 deletions(-) diff --git a/base/aaa/aaa.go b/base/aaa/aaa.go index 242e14f5..aa9e64c6 100644 --- a/base/aaa/aaa.go +++ b/base/aaa/aaa.go @@ -11,4 +11,4 @@ const AAA = "aaa" var Index = &ice.Context{Name: AAA, Help: "认证模块"} -func init() { ice.Index.Register(Index, nil, ROLE, SESS, TOTP, USER, RSA) } +func init() { ice.Index.Register(Index, nil, ROLE, SESS, TOTP, USER, OFFER, EMAIL, RSA) } diff --git a/base/aaa/email.go b/base/aaa/email.go index 7abba7ad..9ee3120c 100644 --- a/base/aaa/email.go +++ b/base/aaa/email.go @@ -16,6 +16,7 @@ const EMAIL = "email" func init() { const ( TO = "to" + ADMIN = "admin" SUBJECT = "subject" CONTENT = "content" SERVICE = "service" @@ -26,18 +27,15 @@ func init() { EMAIL: {Name: "email name auto create", Help: "邮件", Actions: ice.MergeActions(ice.Actions{ SEND: {Name: "send to='shylinux@163.com' subject=hi content:textarea=hello", Help: "发送", Hand: func(m *ice.Message, arg ...string) { if m.Option(SERVICE) == "" { - msg := m.Cmd("", "admin") - m.Option(SERVICE, msg.Append(SERVICE)) - m.Option(USERNAME, msg.Append(USERNAME)) - m.Option(PASSWORD, msg.Append(PASSWORD)) + m.Options(m.Cmd("", ADMIN).AppendSimple(SERVICE, USERNAME, PASSWORD)) } - content := []byte(kit.JoinKV(DF, NL, "To", m.Option(TO), "From", m.Option(USERNAME), "Subject", m.Option(SUBJECT), "Content-Type", "text/html; charset=UTF-8")+NL+NL+m.Option(CONTENT)) + content := []byte(kit.JoinKV(DF, NL, "From", m.Option(USERNAME), "To", m.Option(TO), "Subject", m.Option(SUBJECT), "Content-Type", "text/html; charset=UTF-8")+NL+NL+m.Option(CONTENT)) auth := smtp.PlainAuth("", m.Option(USERNAME), m.Option(PASSWORD), kit.Split(m.Option(SERVICE), ice.DF)[0]) m.Warn(smtp.SendMail(m.Option(SERVICE), auth, m.Option(USERNAME), kit.Split(m.Option(TO)), content)) m.Debug("email send %v %v", auth, string(content)) }}, - }, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,username,password,service")), Hand: func(m *ice.Message, arg ...string) { - mdb.HashSelect(m, arg...).PushAction(SEND) + }, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,service,username,password")), Hand: func(m *ice.Message, arg ...string) { + mdb.HashSelect(m, arg...).PushAction(SEND, mdb.REMOVE) }}, }) } diff --git a/base/aaa/offer.go b/base/aaa/offer.go index b227f87a..b2259c9a 100644 --- a/base/aaa/offer.go +++ b/base/aaa/offer.go @@ -6,16 +6,17 @@ import ( kit "shylinux.com/x/toolkits" ) +const ( + INVITE = "invite" + ACCEPT = "accept" +) const OFFER = "offer" func init() { - const ( - ACCEPT = "accept" - ) Index.MergeCommands(ice.Commands{ OFFER: {Name: "offer hash auto", Actions: ice.MergeActions(ice.Actions{ - mdb.CREATE: {Name: "create email", Hand: func(m *ice.Message, arg ...string) { - h := mdb.HashCreate(m, m.OptionSimple(EMAIL), "from", m.Option(ice.MSG_USERNAME)) + INVITE: {Name: "invite email content", Help: "邀请", Hand: func(m *ice.Message, arg ...string) { + h := mdb.HashCreate(m, m.OptionSimple(EMAIL, "content"), "from", m.Option(ice.MSG_USERNAME)) msg := m.Cmd("web.share", mdb.CREATE, mdb.TYPE, "field", mdb.NAME, m.PrefixKey(), mdb.TEXT, kit.Format(kit.List(h)), kit.Dict(ice.MSG_USERNAME, m.Option(EMAIL), ice.MSG_USERNICK, VOID, ice.MSG_USERROLE, VOID)) m.Cmd(EMAIL, SEND, m.Option(EMAIL), "welcome to contents, please continue", ice.Render(m, ice.RENDER_ANCHOR, msg.Option(mdb.LINK))) @@ -24,12 +25,14 @@ func init() { m.Cmd(USER, mdb.CREATE, USERNAME, m.Option(EMAIL)) m.ProcessOpen(kit.MergeURL2(m.Option(ice.MSG_USERWEB), ice.PS, ice.MSG_SESSID, m.Cmdx(SESS, mdb.CREATE, USERNAME, m.Option(EMAIL)))) }}, - }, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,email,from"), RoleAction(ACCEPT)), Hand: func(m *ice.Message, arg ...string) { - if m.Option(ice.MSG_USERROLE) == VOID && len(arg) == 0 { + }, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,from,email,content"), RoleAction(ACCEPT)), Hand: func(m *ice.Message, arg ...string) { + if len(arg) == 0 && m.Option(ice.MSG_USERROLE) == VOID { return } - if mdb.HashSelect(m, arg...).PushAction(ACCEPT); len(arg) == 0 { - m.Action(mdb.CREATE) + if mdb.HashSelect(m, arg...); len(arg) == 0 { + m.Action(INVITE) + } else { + m.PushAction(ACCEPT) } }}, }) diff --git a/base/aaa/role.go b/base/aaa/role.go index 97e5bdc4..bdba451d 100644 --- a/base/aaa/role.go +++ b/base/aaa/role.go @@ -10,58 +10,49 @@ import ( "shylinux.com/x/toolkits/logs" ) -func _role_chain(arg ...string) string { - key := path.Join(strings.ReplaceAll(kit.Keys(arg), ice.PT, ice.PS)) - return strings.TrimPrefix(strings.TrimSuffix(strings.ReplaceAll(key, ice.PS, ice.PT), ice.PT), ice.PT) +func _role_keys(key ...string) string { + return strings.TrimPrefix(strings.TrimSuffix(strings.ReplaceAll(path.Join(strings.ReplaceAll(kit.Keys(key), ice.PT, ice.PS)), ice.PS, ice.PT), ice.PT), ice.PT) } -func _role_set(m *ice.Message, userrole, zone, chain string, status bool) { - m.Logs(mdb.INSERT, ROLE, userrole, zone, chain) - mdb.HashSelectUpdate(m, userrole, func(value ice.Map) { - black := value[zone].(ice.Map) - black[chain] = status - }) +func _role_set(m *ice.Message, role, zone, key string, status bool) { + m.Logs(mdb.INSERT, ROLE, role, zone, key) + mdb.HashSelectUpdate(m, role, func(value ice.Map) { value[zone].(ice.Map)[key] = status }) } -func _role_black(m *ice.Message, userrole, chain string) { - _role_set(m, userrole, BLACK, chain, true) -} -func _role_white(m *ice.Message, userrole, chain string) { - _role_set(m, userrole, 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 { +func _role_white(m *ice.Message, role, key string) { _role_set(m, role, WHITE, key, true) } +func _role_black(m *ice.Message, role, key string) { _role_set(m, role, BLACK, key, true) } +func _role_check(value ice.Map, key []string, ok bool) bool { + white, black := value[WHITE].(ice.Map), value[BLACK].(ice.Map) + for i := 0; i < len(key); i++ { + if v, o := white[kit.Join(key[:i+1], ice.PT)]; o && v == true { ok = true } - if v, o := black[kit.Join(keys[:i+1], ice.PT)]; o && v == true { + if v, o := black[kit.Join(key[: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 { +func _role_right(m *ice.Message, role string, key ...string) (ok bool) { + if role == ROOT { return true } - mdb.HashSelectDetail(m, kit.Select(VOID, userrole), func(value ice.Map) { - ok = _role_check(value, keys, userrole == TECH) + mdb.HashSelectDetail(m, kit.Select(VOID, role), func(value ice.Map) { + ok = _role_check(value, key, role == TECH) }) return } -func _role_list(m *ice.Message, userrole string) *ice.Message { - mdb.HashSelectDetail(m, kit.Select(VOID, userrole), func(value ice.Map) { - kit.Fetch(value[BLACK], func(k string, v ice.Any) { - m.Push(ROLE, kit.Value(value, mdb.NAME)) - m.Push(mdb.ZONE, BLACK) - m.Push(mdb.KEY, k) - m.Push(mdb.VALUE, v) - }) +func _role_list(m *ice.Message, role string) *ice.Message { + mdb.HashSelectDetail(m, kit.Select(VOID, role), func(value ice.Map) { kit.Fetch(value[WHITE], func(k string, v ice.Any) { m.Push(ROLE, kit.Value(value, mdb.NAME)) m.Push(mdb.ZONE, WHITE) m.Push(mdb.KEY, k) - m.Push(mdb.VALUE, v) + m.Push(mdb.STATUS, v) + }) + kit.Fetch(value[BLACK], func(k string, v ice.Any) { + m.Push(ROLE, kit.Value(value, mdb.NAME)) + m.Push(mdb.ZONE, BLACK) + m.Push(mdb.KEY, k) + m.Push(mdb.STATUS, v) }) }) return m.Sort(mdb.KEY).StatusTimeCount() @@ -73,8 +64,8 @@ const ( VOID = "void" ) const ( - BLACK = "black" WHITE = "white" + BLACK = "black" RIGHT = "right" ) const ROLE = "role" @@ -94,14 +85,10 @@ func init() { mdb.DELETE: {Hand: func(m *ice.Message, arg ...string) { _role_set(m, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY), false) }}, - BLACK: {Name: "black role chain", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) { - _role_black(m, arg[0], _role_chain(arg[1:]...)) - }}, - WHITE: {Name: "white role chain", Help: "白名单", Hand: func(m *ice.Message, arg ...string) { - _role_white(m, arg[0], _role_chain(arg[1:]...)) - }}, - RIGHT: {Name: "right role chain", Help: "检查权限", Hand: func(m *ice.Message, arg ...string) { - if _role_right(m, arg[0], kit.Split(_role_chain(arg[1:]...), ice.PT)...) { + WHITE: {Hand: func(m *ice.Message, arg ...string) { _role_white(m, arg[0], _role_keys(arg[1:]...)) }}, + BLACK: {Hand: func(m *ice.Message, arg ...string) { _role_black(m, arg[0], _role_keys(arg[1:]...)) }}, + RIGHT: {Hand: func(m *ice.Message, arg ...string) { + if _role_right(m, arg[0], kit.Split(_role_keys(arg[1:]...), ice.PT)...) { m.Echo(ice.OK) } }}, @@ -111,14 +98,12 @@ func init() { }) } -func Right(m *ice.Message, arg ...ice.Any) bool { - return m.Option(ice.MSG_USERROLE) == ROOT || !m.Warn(m.Cmdx(ROLE, RIGHT, m.Option(ice.MSG_USERROLE), arg) != ice.OK, - ice.ErrNotRight, kit.Join(kit.Simple(arg), ice.PT), USERROLE, m.Option(ice.MSG_USERROLE), logs.FileLineMeta(logs.FileLine(2))) +func Right(m *ice.Message, key ...ice.Any) bool { + return m.Option(ice.MSG_USERROLE) == ROOT || !m.Warn(m.Cmdx(ROLE, RIGHT, m.Option(ice.MSG_USERROLE), key) != ice.OK, + ice.ErrNotRight, kit.Keys(key...), USERROLE, m.Option(ice.MSG_USERROLE), logs.FileLineMeta(logs.FileLine(2))) } -func RoleRight(m *ice.Message, userrole string, arg ...string) bool { - return m.Cmdx(ROLE, RIGHT, userrole, arg) == ice.OK -} -func RoleAction(cmds ...string) ice.Actions { +func RoleRight(m *ice.Message, role string, key ...string) bool { return m.Cmdx(ROLE, RIGHT, role, key) == ice.OK } +func RoleAction(key ...string) ice.Actions { return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { if c, ok := ice.Info.Index[m.CommandKey()].(*ice.Context); ok && c == m.Target() { m.Cmd(ROLE, WHITE, VOID, m.CommandKey()) @@ -126,25 +111,25 @@ func RoleAction(cmds ...string) ice.Actions { } m.Cmd(ROLE, WHITE, VOID, m.PrefixKey()) m.Cmd(ROLE, BLACK, VOID, m.PrefixKey(), ice.ACTION) - for _, cmd := range cmds { - m.Cmd(ROLE, WHITE, VOID, m.PrefixKey(), ice.ACTION, cmd) + for _, key := range key { + m.Cmd(ROLE, WHITE, VOID, m.PrefixKey(), ice.ACTION, key) } }}} } -func WhiteAction(cmds ...string) ice.Actions { +func WhiteAction(key ...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(), ice.ACTION) - for _, cmd := range cmds { - m.Cmd(ROLE, WHITE, VOID, m.CommandKey(), ice.ACTION, cmd) + for _, key := range key { + m.Cmd(ROLE, WHITE, VOID, m.CommandKey(), ice.ACTION, key) } }}} } -func BlackAction(cmds ...string) ice.Actions { +func BlackAction(key ...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(), ice.ACTION, cmd) + for _, key := range key { + m.Cmd(ROLE, BLACK, VOID, m.CommandKey(), ice.ACTION, key) } }}} } diff --git a/base/aaa/sess.go b/base/aaa/sess.go index c5ae5d5d..c8ddb7a4 100644 --- a/base/aaa/sess.go +++ b/base/aaa/sess.go @@ -8,34 +8,32 @@ import ( "shylinux.com/x/toolkits/logs" ) -func _sess_create(m *ice.Message, username string) (h string) { +func _sess_create(m *ice.Message, username string, arg ...string) (h string) { m.Assert(username != "") if msg := m.Cmd(USER, username); msg.Length() > 0 { - h = mdb.HashCreate(m, msg.AppendSimple(USERROLE, USERNAME, USERNICK), IP, m.Option(ice.MSG_USERIP), UA, m.Option(ice.MSG_USERUA)) + h = mdb.HashCreate(m, msg.AppendSimple(USERNAME, USERNICK, USERROLE), arg) } else { - h = mdb.HashCreate(m, m.OptionSimple(USERROLE, USERNAME, USERNICK), IP, m.Option(ice.MSG_USERIP), UA, m.Option(ice.MSG_USERUA)) + h = mdb.HashCreate(m, m.OptionSimple(USERNAME, USERNICK, USERROLE), arg) } gdb.Event(m, SESS_CREATE, SESS, h, USERNAME, username) - return h + return } func _sess_check(m *ice.Message, sessid string) { m.Assert(sessid != "") - val := kit.Dict() - mdb.HashSelectDetail(m, sessid, func(value ice.Map) { + if val := kit.Dict(); mdb.HashSelectDetail(m, sessid, func(value ice.Map) { if !m.WarnTimeNotValid(value[mdb.TIME], sessid) { for k, v := range value { val[k] = v } } - }) - if len(val) > 0 { + }) && len(val) > 0 { SessAuth(m, val) } } const ( - IP = "ip" UA = "ua" + IP = "ip" ) const ( CHECK = "check" @@ -53,33 +51,31 @@ func init() { Index.MergeCommands(ice.Commands{ SESS: {Name: "sess hash auto prunes", Help: "会话", Actions: ice.MergeActions(ice.Actions{ mdb.CREATE: {Name: "create username", Hand: func(m *ice.Message, arg ...string) { - _sess_create(m, m.Option(USERNAME)) + _sess_create(m, m.Option(USERNAME), UA, m.Option(ice.MSG_USERUA), IP, m.Option(ice.MSG_USERIP)) }}, CHECK: {Name: "check sessid", Hand: func(m *ice.Message, arg ...string) { _sess_check(m, m.Option(SESSID)) }}, - }, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,userrole,username,usernick,ip,ua", mdb.EXPIRE, "720h"))}, + }, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,username,usernick,userrole,ua,ip", mdb.EXPIRE, "720h"))}, }) } func SessCreate(m *ice.Message, username string) string { - if m.Warn(username == "", ice.ErrNotValid, username) { + if m.Warn(username == "", ice.ErrNotValid, USERNAME) { return "" } return m.Option(ice.MSG_SESSID, m.Cmdx(SESS, mdb.CREATE, username)) } func SessCheck(m *ice.Message, sessid string) bool { m.Option("log.caller", logs.FileLine(2)) - m.Option(ice.MSG_USERROLE, VOID) - m.Option(ice.MSG_USERNAME, "") - m.Option(ice.MSG_USERNICK, "") + m.Options(ice.MSG_USERNAME, "", ice.MSG_USERNICK, "", ice.MSG_USERROLE, VOID) return sessid != "" && m.Cmdy(SESS, CHECK, sessid).Option(ice.MSG_USERNAME) != "" } func SessAuth(m *ice.Message, value ice.Map, arg ...string) { m.Auth( - USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]), USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]), USERNICK, m.Option(ice.MSG_USERNICK, value[USERNICK]), + USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]), arg, logs.FileLineMeta(kit.Select(logs.FileLine(-1), m.Option("log.caller"))), ) } diff --git a/base/aaa/totp.go b/base/aaa/totp.go index 7328dd63..cb681440 100644 --- a/base/aaa/totp.go +++ b/base/aaa/totp.go @@ -71,8 +71,9 @@ func init() { if len(arg) > 0 { m.PushQRCode(mdb.SCAN, kit.Format(m.Config(mdb.LINK), value[mdb.NAME], value[SECRET])) m.Echo(_totp_get(value[SECRET], kit.Int(value[NUMBER]), kit.Int64(value[PERIOD]))) + } else { + m.StatusTimeCount() } - m.StatusTimeCount() }) }}, }) diff --git a/base/aaa/user.go b/base/aaa/user.go index 8435efc0..d9e1a792 100644 --- a/base/aaa/user.go +++ b/base/aaa/user.go @@ -24,11 +24,15 @@ func _user_login(m *ice.Message, name, word string) { if m.Warn(name == "", ice.ErrNotValid, name) { return } - mdb.HashSelectDetail(m.Spawn(), name, func(value ice.Map) { + if val := kit.Dict(); mdb.HashSelectDetail(m.Spawn(), name, func(value ice.Map) { if !m.Warn(word != "" && word != kit.Format(value[PASSWORD]), ice.ErrNotValid) { - SessAuth(m, value) + for k, v := range value { + val[k] = v + } } - }) + }) && len(val) > 0 { + SessAuth(m, val) + } } const ( @@ -51,8 +55,6 @@ const ( USERROLE = "userrole" USER_CREATE = "user.create" - - INVITE = "invite" ) const USER = "user" @@ -91,17 +93,15 @@ func UserRole(m *ice.Message, username ice.Any) (role string) { return UserInfo(m, username, USERROLE, ice.MSG_USERROLE) } func UserLogin(m *ice.Message, username, password string) bool { - m.Option(ice.MSG_USERROLE, VOID) - m.Option(ice.MSG_USERNAME, "") - m.Option(ice.MSG_USERNICK, "") + m.Options(ice.MSG_USERNAME, "", ice.MSG_USERNICK, "", ice.MSG_USERROLE, VOID) return m.Cmdy(USER, LOGIN, username, password).Option(ice.MSG_USERNAME) != "" } func UserRoot(m *ice.Message, arg ...string) *ice.Message { - username := m.Option(ice.MSG_USERNAME, kit.Select(ice.Info.UserName, arg, 1)) - usernick := m.Option(ice.MSG_USERNICK, kit.Select(UserNick(m, username), arg, 2)) - userrole := m.Option(ice.MSG_USERROLE, kit.Select(ROOT, arg, 3)) + username := m.Option(ice.MSG_USERNAME, kit.Select(ice.Info.UserName, arg, 0)) + usernick := m.Option(ice.MSG_USERNICK, kit.Select(UserNick(m, username), arg, 1)) + userrole := m.Option(ice.MSG_USERROLE, kit.Select(ROOT, arg, 2)) if len(arg) > 0 { - m.Cmd(USER, mdb.CREATE, username, kit.Select("", arg, 0), usernick, "", userrole) + m.Cmd(USER, mdb.CREATE, username, "", usernick, "", userrole) ice.Info.UserName = username } return m diff --git a/base/ctx/command.go b/base/ctx/command.go index 48c48b17..1edc715d 100644 --- a/base/ctx/command.go +++ b/base/ctx/command.go @@ -187,7 +187,7 @@ func FileURI(dir string) string { } func FileCmd(dir string) string { return FileURI(kit.ExtChange(strings.Split(dir, ice.DF)[0], nfs.GO)) } func AddFileCmd(dir, key string) { ice.Info.File[FileCmd(dir)] = key } -func IsOrderCmd(key string) { return key[0] == '/' || key[0] == '_' } +func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' } func GetFileCmd(dir string) string { if strings.HasPrefix(dir, ice.ISH_PLUGED) { dir = path.Join(ice.PS, ice.REQUIRE, strings.TrimPrefix(dir, ice.ISH_PLUGED)) diff --git a/base/ctx/config.go b/base/ctx/config.go index 45646a13..dd91edc5 100644 --- a/base/ctx/config.go +++ b/base/ctx/config.go @@ -64,7 +64,7 @@ func _config_make(m *ice.Message, key string, arg ...string) { } func _config_list(m *ice.Message) { for k, v := range m.Source().Configs { - if IsOrderCmd(key) { + if IsOrderCmd(k) { continue } m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.VALUE, kit.Format(v.Value)) diff --git a/base/web/serve.go b/base/web/serve.go index 9ca8e2cc..7c3b59bd 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -89,7 +89,7 @@ func _serve_start(m *ice.Message) { if cli.NodeInfo(m, SERVER, kit.Select(ice.Info.HostName, m.Option("nodename"))); m.Option(tcp.PORT) == tcp.RANDOM { m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT)) } - aaa.UserRoot(m, m.Option(aaa.PASSWORD), m.Option(aaa.USERNAME), m.Option(aaa.USERNICK)) + aaa.UserRoot(m, m.Option(aaa.USERNAME), m.Option(aaa.USERNICK)) m.Target().Start(m, m.OptionSimple(tcp.HOST, tcp.PORT)...) m.Go(func() { m.Cmd(BROAD, SERVE) }) @@ -360,7 +360,7 @@ func init() { ctx.DisplayStorySpide(m, lex.PREFIX, m.ActionKey(), nfs.ROOT, MergeLink(m, ice.PS)) } }}, - cli.START: {Name: "start dev proto=http host port=9020 nodename password username usernick", Help: "启动", Hand: func(m *ice.Message, arg ...string) { + cli.START: {Name: "start dev proto=http host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) { _serve_start(m) }}, }, mdb.HashAction())}, diff --git a/core/chat/action.go b/core/chat/action.go index a4f84190..71190bb4 100644 --- a/core/chat/action.go +++ b/core/chat/action.go @@ -72,14 +72,10 @@ func init() { m.Cmdy(mdb.MODIFY, RIVER, _storm_key(m), mdb.LIST, m.OptionSimple(mdb.ID), arg) }}, web.SHARE: {Hand: func(m *ice.Message, arg ...string) { _action_share(m, arg...) }}, - }, ctx.CmdAction(), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) { + }, ctx.CmdAction(), aaa.WhiteAction(web.SHARE, ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) { if m.Warn(m.Option(ice.MSG_USERNAME) == "", ice.ErrNotLogin, arg) { return } - if len(arg) == 0 { - _action_share(m, m.Option("share")) - return - } if m.Option(ice.MSG_USERPOD) == "" && m.Warn(!_river_right(m, arg[0]), ice.ErrNotRight, arg) { return } diff --git a/meta.go b/meta.go index 0b7ba1af..86c64b0e 100644 --- a/meta.go +++ b/meta.go @@ -393,8 +393,18 @@ func (m *Message) Detailv(arg ...Any) []string { return m.meta[MSG_DETAIL] } func (m *Message) Options(arg ...Any) Any { - for i := 0; i < len(arg)-1; i += 2 { - m.Optionv(kit.Format(arg[i]), arg[i+1]) + for i := 0; i < len(arg); i += 2 { + switch val := arg[i].(type) { + case []string: + for i := 0; i < len(val) - 1; i += 2 { + m.Optionv(val[i], val[i+1]) + } + i-- + continue + } + if i+1 < len(arg) { + m.Optionv(kit.Format(arg[i]), arg[i+1]) + } } return m.Optionv(kit.Format(arg[0])) } diff --git a/misc.go b/misc.go index 06c78f18..9dfec463 100644 --- a/misc.go +++ b/misc.go @@ -350,6 +350,7 @@ func MergeActions(arg ...Any) Actions { func SplitCmd(name string, actions Actions) (list []Any) { const ( TEXT = "text" + CONTENT = "content" TEXTAREA = "textarea" PASSWORD = "password" SELECT = "select" @@ -387,7 +388,7 @@ func SplitCmd(name string, actions Actions) (list []Any) { push(TEXT, "offend") push(BUTTON, "prev") push(BUTTON, "next") - case ARGS, TEXT, TEXTAREA: + case ARGS, TEXT, TEXTAREA, CONTENT: push(TEXTAREA, ls[i]) case PASSWORD: push(PASSWORD, ls[i])