forked from x/icebergs
opt aaa
This commit is contained in:
parent
ecb66d16d3
commit
81d087ddae
@ -2,7 +2,6 @@ package aaa
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -13,11 +12,10 @@ var Index = &ice.Context{Name: AAA, Help: "认证模块", Commands: map[string]*
|
||||
m.Rich(ROLE, nil, kit.Dict(kit.MDB_NAME, VOID, WHITE, kit.Dict(), BLACK, kit.Dict()))
|
||||
m.Rich(ROLE, nil, kit.Dict(kit.MDB_NAME, TECH, BLACK, kit.Dict(), WHITE, kit.Dict()))
|
||||
m.Load()
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, USER, m.Prefix(USER))
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Save()
|
||||
}},
|
||||
}}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, USER, SESS, ROLE, TOTP) }
|
||||
func init() { ice.Index.Register(Index, nil, ROLE, SESS, TOTP, USER) }
|
||||
|
@ -1,6 +1,6 @@
|
||||
chapter "aaa"
|
||||
|
||||
field "用户" user
|
||||
field "会话" sess
|
||||
field "角色" role
|
||||
field "会话" sess
|
||||
field "令牌" totp
|
||||
field "用户" user
|
||||
|
@ -52,7 +52,7 @@ func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
|
||||
ok = true
|
||||
list := value[BLACK].(map[string]interface{})
|
||||
for i := 0; i < len(keys); i++ {
|
||||
if v, o := list[kit.Join(keys[:i+1], ".")]; o && v == true {
|
||||
if v, o := list[kit.Join(keys[:i+1], ice.PT)]; o && v == true {
|
||||
ok = false
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,7 @@ func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
|
||||
ok = false
|
||||
list = value[WHITE].(map[string]interface{})
|
||||
for i := 0; i < len(keys); i++ {
|
||||
if v, o := list[kit.Join(keys[:i+1], ".")]; o && v == true {
|
||||
if v, o := list[kit.Join(keys[:i+1], ice.PT)]; o && v == true {
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,7 @@ func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
|
||||
}
|
||||
|
||||
func RoleRight(m *ice.Message, userrole string, keys ...string) bool {
|
||||
return _role_right(m, userrole, kit.Split(kit.Keys(keys), ".")...)
|
||||
return _role_right(m, userrole, kit.Split(kit.Keys(keys), ice.PT)...)
|
||||
}
|
||||
|
||||
const ( // 用户角色
|
||||
@ -97,48 +97,45 @@ const ( // 角色操作
|
||||
const ROLE = "role"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
ROLE: {Name: ROLE, Help: "角色", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ROLE: {Name: "role role auto create", Help: "角色", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create role=void,tech zone=white,black key=", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(ROLE, nil, m.Option(ROLE), func(key string, value map[string]interface{}) {
|
||||
list := value[m.Option(kit.MDB_ZONE)].(map[string]interface{})
|
||||
m.Log_CREATE(ROLE, m.Option(ROLE), list[m.Option(kit.MDB_KEY)])
|
||||
list[m.Option(kit.MDB_KEY)] = true
|
||||
})
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(ROLE, nil, m.Option(ROLE), func(key string, value map[string]interface{}) {
|
||||
list := value[m.Option(kit.MDB_ZONE)].(map[string]interface{})
|
||||
m.Log_REMOVE(ROLE, m.Option(ROLE), list[m.Option(kit.MDB_KEY)])
|
||||
delete(list, m.Option(kit.MDB_KEY))
|
||||
})
|
||||
}},
|
||||
|
||||
BLACK: {Name: "black role chain...", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_black(m, arg[0], strings.ReplaceAll(kit.Keys(arg[1:]), "/", "."), true)
|
||||
}},
|
||||
WHITE: {Name: "white role chain...", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_white(m, arg[0], strings.ReplaceAll(kit.Keys(arg[1:]), "/", "."), true)
|
||||
}},
|
||||
RIGHT: {Name: "right role chain...", Help: "查看权限", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _role_right(m, arg[0], kit.Split(strings.ReplaceAll(kit.Keys(arg[1:]), "/", "."), ".")...) {
|
||||
m.Echo(ice.OK)
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) < 2 { // 角色列表
|
||||
_role_list(m, kit.Select("", arg, 0))
|
||||
m.PushAction(mdb.REMOVE)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置角色
|
||||
_role_user(m, arg[0], arg[1:]...)
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
ROLE: {Name: ROLE, Help: "角色", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ROLE: {Name: "role role auto create", Help: "角色", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create role=void,tech zone=white,black key=", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(ROLE, nil, m.Option(ROLE), func(key string, value map[string]interface{}) {
|
||||
list := value[m.Option(kit.MDB_ZONE)].(map[string]interface{})
|
||||
m.Log_CREATE(ROLE, m.Option(ROLE), list[m.Option(kit.MDB_KEY)])
|
||||
list[m.Option(kit.MDB_KEY)] = true
|
||||
})
|
||||
}},
|
||||
},
|
||||
})
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(ROLE, nil, m.Option(ROLE), func(key string, value map[string]interface{}) {
|
||||
list := value[m.Option(kit.MDB_ZONE)].(map[string]interface{})
|
||||
m.Log_REMOVE(ROLE, m.Option(ROLE), list[m.Option(kit.MDB_KEY)])
|
||||
delete(list, m.Option(kit.MDB_KEY))
|
||||
})
|
||||
}},
|
||||
|
||||
BLACK: {Name: "black role chain...", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_black(m, arg[0], strings.ReplaceAll(kit.Keys(arg[1:]), "/", ice.PT), true)
|
||||
}},
|
||||
WHITE: {Name: "white role chain...", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_white(m, arg[0], strings.ReplaceAll(kit.Keys(arg[1:]), "/", ice.PT), true)
|
||||
}},
|
||||
RIGHT: {Name: "right role chain...", Help: "查看权限", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _role_right(m, arg[0], kit.Split(strings.ReplaceAll(kit.Keys(arg[1:]), "/", ice.PT), ice.PT)...) {
|
||||
m.Echo(ice.OK)
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) < 2 { // 角色列表
|
||||
_role_list(m, kit.Select("", arg, 0))
|
||||
m.PushAction(mdb.REMOVE)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置角色
|
||||
_role_user(m, arg[0], arg[1:]...)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -16,24 +14,26 @@ func _sess_check(m *ice.Message, sessid string) {
|
||||
|
||||
m.Log_AUTH(
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, UserRole(m, value[USERNAME])),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, value[USERNICK]),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, value[USERNICK]),
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
func _sess_create(m *ice.Message, username string) string {
|
||||
if username == "" {
|
||||
return ""
|
||||
}
|
||||
if m.Richs(USER, nil, username, nil) == nil {
|
||||
_user_create(m, username, kit.Hashs())
|
||||
}
|
||||
|
||||
h := m.Cmdx(mdb.INSERT, SESS, "", mdb.HASH,
|
||||
USERNAME, username, USERROLE, UserRole(m, username),
|
||||
kit.MDB_TIME, m.Time(m.Conf(SESS, kit.Keym(kit.MDB_EXPIRE))),
|
||||
USERROLE, UserRole(m, username), USERNAME, username,
|
||||
IP, m.Option(ice.MSG_USERIP), UA, m.Option(ice.MSG_USERUA),
|
||||
kit.MDB_TIME, m.Time(m.Conf(SESS, kit.Keym(kit.MDB_EXPIRE))),
|
||||
)
|
||||
m.Log_CREATE(SESS_CREATE, username, kit.MDB_HASH, h)
|
||||
m.Event(SESS_CREATE, username)
|
||||
m.Event(SESS_CREATE, SESS, h, USERNAME, username)
|
||||
return h
|
||||
}
|
||||
|
||||
@ -41,17 +41,8 @@ func SessCheck(m *ice.Message, sessid string) {
|
||||
_sess_check(m, sessid)
|
||||
}
|
||||
func SessCreate(m *ice.Message, username string) string {
|
||||
if username == "" {
|
||||
return ""
|
||||
}
|
||||
return m.Option(ice.MSG_SESSID, _sess_create(m, username))
|
||||
}
|
||||
func SessIsCli(m *ice.Message) bool {
|
||||
if m.Option(ice.MSG_USERUA) == "" || !strings.HasPrefix(m.Option(ice.MSG_USERUA), "Mozilla/5.0") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
IP = "ip"
|
||||
@ -67,31 +58,17 @@ const (
|
||||
const SESS = "sess"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
SESS: {Name: SESS, Help: "会话", Value: kit.Data(kit.MDB_SHORT, "uniq", kit.MDB_EXPIRE, "720h")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
SESS: {Name: "sess hash auto prunes", Help: "会话", Action: map[string]*ice.Action{
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.FIELDS, "time,hash,username,userrole,ip,ua")
|
||||
m.Cmdy(mdb.DELETE, SESS, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||
}},
|
||||
mdb.PRUNES: {Name: "prunes before@date", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.FIELDS, "time,hash,username,userrole,ip,ua")
|
||||
m.Cmd(mdb.PRUNES, SESS, "", mdb.HASH, func(key string, value map[string]interface{}) bool {
|
||||
if value = kit.GetMeta(value); kit.Time(kit.Format(value[kit.MDB_TIME])) < kit.Time(m.Option("before")) {
|
||||
m.Push(key, value, kit.Split(m.Option(mdb.FIELDS)))
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg), "time,hash,username,userrole,ip")
|
||||
m.Cmdy(mdb.SELECT, SESS, "", mdb.HASH, kit.MDB_HASH, arg)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}},
|
||||
},
|
||||
})
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
SESS: {Name: SESS, Help: "会话", Value: kit.Data(
|
||||
kit.MDB_SHORT, "uniq", kit.MDB_FIELD, "time,hash,userrole,username,ip,ua",
|
||||
kit.MDB_EXPIRE, "720h",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
SESS: {Name: "sess hash auto prunes", Help: "会话", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create username", Help: "创建"},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -53,44 +53,34 @@ const (
|
||||
const TOTP = "totp"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
TOTP: {Name: TOTP, Help: "动态令牌", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_LINK, "otpauth://totp/%s?secret=%s",
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
TOTP: {Name: "totp name auto create", Help: "动态令牌", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create name secret period=30 number=6", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(SECRET) == "" { // 创建密钥
|
||||
m.Option(SECRET, _totp_gen(kit.Int64(m.Option(PERIOD))))
|
||||
}
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
TOTP: {Name: TOTP, Help: "动态令牌", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_FIELD, "time,name,secret,period,number",
|
||||
kit.MDB_LINK, "otpauth://totp/%s?secret=%s",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
TOTP: {Name: "totp name auto create", Help: "动态令牌", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create name secret period=30 number=6", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(SECRET) == "" { // 创建密钥
|
||||
m.Option(SECRET, _totp_gen(kit.Int64(m.Option(PERIOD))))
|
||||
}
|
||||
|
||||
m.Cmd(mdb.INSERT, TOTP, "", mdb.HASH, kit.MDB_NAME, m.Option(kit.MDB_NAME),
|
||||
SECRET, m.Option(SECRET), PERIOD, m.Option(PERIOD), NUMBER, m.Option(NUMBER),
|
||||
)
|
||||
m.ProcessRefresh30ms()
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.DELETE, TOTP, "", mdb.HASH, kit.MDB_NAME, m.Option(kit.MDB_NAME))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg), "time,name,secret,period,number")
|
||||
m.Cmd(mdb.SELECT, TOTP, "", mdb.HASH, kit.MDB_NAME, arg).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(kit.MDB_TIME, m.Time())
|
||||
m.Push(kit.MDB_NAME, value[kit.MDB_NAME])
|
||||
|
||||
period := kit.Int64(value[PERIOD])
|
||||
m.Push("rest", period-time.Now().Unix()%period)
|
||||
m.Push("code", _totp_get(value[SECRET], kit.Int(value[NUMBER]), period))
|
||||
|
||||
if len(arg) > 0 {
|
||||
m.PushQRCode("scan", kit.Format(m.Conf(TOTP, kit.Keym(kit.MDB_LINK)), value[kit.MDB_NAME], value[SECRET]))
|
||||
m.Echo(_totp_get(value[SECRET], kit.Int(value[NUMBER]), kit.Int64(value[PERIOD])))
|
||||
}
|
||||
})
|
||||
m.PushAction(mdb.REMOVE)
|
||||
m.Cmd(mdb.INSERT, TOTP, "", mdb.HASH, m.OptionSimple(kit.MDB_NAME, SECRET, PERIOD, NUMBER))
|
||||
}},
|
||||
},
|
||||
})
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m.Spawn(), arg...).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(kit.MDB_TIME, m.Time())
|
||||
m.Push(kit.MDB_NAME, value[kit.MDB_NAME])
|
||||
|
||||
period := kit.Int64(value[PERIOD])
|
||||
m.Push("rest", period-time.Now().Unix()%period)
|
||||
m.Push("code", _totp_get(value[SECRET], kit.Int(value[NUMBER]), period))
|
||||
|
||||
if len(arg) > 0 {
|
||||
m.PushQRCode("scan", kit.Format(m.Config(kit.MDB_LINK), value[kit.MDB_NAME], value[SECRET]))
|
||||
m.Echo(_totp_get(value[SECRET], kit.Int(value[NUMBER]), kit.Int64(value[PERIOD])))
|
||||
}
|
||||
})
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
126
base/aaa/user.go
126
base/aaa/user.go
@ -12,57 +12,34 @@ func _user_login(m *ice.Message, name, word string) (ok bool) {
|
||||
}
|
||||
|
||||
m.Richs(USER, nil, name, func(key string, value map[string]interface{}) {
|
||||
if value[PASSWORD] == word {
|
||||
ok = true
|
||||
}
|
||||
ok = word == value[PASSWORD]
|
||||
})
|
||||
return ok
|
||||
}
|
||||
func _user_create(m *ice.Message, name, word string) {
|
||||
h := m.Rich(USER, nil, kit.Dict(
|
||||
USERNAME, name, PASSWORD, word,
|
||||
USERNICK, name, USERZONE, m.Option(ice.MSG_USERZONE),
|
||||
m.Rich(USER, nil, kit.Dict(
|
||||
USERNAME, name, PASSWORD, word, USERNICK, name,
|
||||
USERZONE, m.Option(ice.MSG_USERZONE),
|
||||
))
|
||||
m.Log_CREATE(USER_CREATE, name, kit.MDB_HASH, h)
|
||||
m.Event(USER_CREATE, name)
|
||||
m.Event(USER_CREATE, USER, name)
|
||||
}
|
||||
func _user_remove(m *ice.Message, name string) {
|
||||
m.Cmdy(mdb.DELETE, USER, "", mdb.HASH, USERNAME, name)
|
||||
m.Log_REMOVE(USER_REMOVE, name, kit.MDB_HASH, kit.Hashs(name))
|
||||
m.Event(USER_REMOVE, name)
|
||||
}
|
||||
func _user_search(m *ice.Message, kind, name, text string) {
|
||||
func _user_search(m *ice.Message, name, text string) {
|
||||
m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); name != "" && name != value[USERNAME] {
|
||||
return
|
||||
}
|
||||
m.PushSearch("cmd", USER, kit.MDB_TYPE, kit.Format(UserRole(m, value[USERNAME])),
|
||||
kit.MDB_NAME, kit.Format(value[USERNICK]), kit.MDB_TEXT, kit.Format(value[USERNAME]), value)
|
||||
m.PushSearch(kit.MDB_TYPE, UserRole(m, value[USERNAME]), kit.MDB_NAME, kit.Format(value[USERNAME]), kit.MDB_TEXT, kit.Format(value[USERNICK]), value)
|
||||
})
|
||||
}
|
||||
|
||||
func UserRoot(m *ice.Message) {
|
||||
m.Option(ice.MSG_USERNAME, ice.Info.UserName)
|
||||
m.Option(ice.MSG_USERROLE, ROOT)
|
||||
m.Option(ice.MSG_USERNAME, ice.Info.UserName)
|
||||
|
||||
if m.Richs(USER, "", ice.Info.UserName, nil) == nil {
|
||||
_user_create(m, ice.Info.UserName, kit.Hashs())
|
||||
}
|
||||
}
|
||||
func UserZone(m *ice.Message, username interface{}) (zone string) {
|
||||
m.Richs(USER, nil, kit.Format(username), func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
zone = kit.Format(value[USERZONE])
|
||||
})
|
||||
return
|
||||
}
|
||||
func UserNick(m *ice.Message, username interface{}) (nick string) {
|
||||
m.Richs(USER, nil, kit.Format(username), func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
nick = kit.Format(value[USERNICK])
|
||||
})
|
||||
return
|
||||
}
|
||||
func UserRole(m *ice.Message, username interface{}) (role string) {
|
||||
if role = VOID; username == ice.Info.UserName {
|
||||
return ROOT
|
||||
@ -74,12 +51,24 @@ func UserRole(m *ice.Message, username interface{}) (role string) {
|
||||
})
|
||||
return
|
||||
}
|
||||
func UserNick(m *ice.Message, username interface{}) (nick string) {
|
||||
m.Richs(USER, nil, kit.Format(username), func(key string, value map[string]interface{}) {
|
||||
nick = kit.Format(kit.GetMeta(value)[USERNICK])
|
||||
})
|
||||
return
|
||||
}
|
||||
func UserZone(m *ice.Message, username interface{}) (zone string) {
|
||||
m.Richs(USER, nil, kit.Format(username), func(key string, value map[string]interface{}) {
|
||||
zone = kit.Format(kit.GetMeta(value)[USERZONE])
|
||||
})
|
||||
return
|
||||
}
|
||||
func UserLogin(m *ice.Message, username, password string) bool {
|
||||
if password == "" || _user_login(m, username, password) {
|
||||
m.Log_AUTH(
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, UserNick(m, username)),
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, UserRole(m, username)),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, username),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, UserNick(m, username)),
|
||||
)
|
||||
return true
|
||||
}
|
||||
@ -87,9 +76,8 @@ func UserLogin(m *ice.Message, username, password string) bool {
|
||||
}
|
||||
|
||||
const (
|
||||
INVITE = "invite"
|
||||
)
|
||||
const (
|
||||
BACKGROUND = "background"
|
||||
|
||||
AVATAR = "avatar"
|
||||
GENDER = "gender"
|
||||
MOBILE = "mobile"
|
||||
@ -99,52 +87,52 @@ const (
|
||||
COUNTRY = "country"
|
||||
PROVINCE = "province"
|
||||
LANGUAGE = "language"
|
||||
|
||||
BACKGROUND = "background"
|
||||
)
|
||||
const (
|
||||
USERZONE = "userzone"
|
||||
USERNICK = "usernick"
|
||||
USERROLE = "userrole"
|
||||
USERNAME = "username"
|
||||
PASSWORD = "password"
|
||||
USERNICK = "usernick"
|
||||
USERZONE = "userzone"
|
||||
)
|
||||
const (
|
||||
USER_CREATE = "user.create"
|
||||
USER_REMOVE = "user.remove"
|
||||
)
|
||||
const (
|
||||
INVITE = "invite"
|
||||
)
|
||||
const USER = "user"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
USER: {Name: USER, Help: "用户", Value: kit.Data(kit.MDB_SHORT, USERNAME)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
USER: {Name: "user username auto create", Help: "用户", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create userrole=void,tech username password", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_user_create(m, m.Option(USERNAME), m.Option(PASSWORD))
|
||||
_role_user(m, m.Option(USERROLE), m.Option(USERNAME))
|
||||
}},
|
||||
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.MODIFY, USER, "", mdb.HASH, USERNAME, m.Option(USERNAME), arg)
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove username", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
_user_remove(m, m.Option(USERNAME))
|
||||
}},
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == USER {
|
||||
_user_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg), "time,username,userzone,usernick")
|
||||
m.Cmdy(mdb.SELECT, USER, "", mdb.HASH, USERNAME, arg)
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(USERROLE, UserRole(m, value[USERNAME]))
|
||||
})
|
||||
m.PushAction(mdb.REMOVE)
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
USER: {Name: USER, Help: "用户", Value: kit.Data(
|
||||
kit.MDB_SHORT, USERNAME, kit.MDB_FIELD, "time,username,usernick,userzone",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, USER, m.Prefix(USER))
|
||||
}},
|
||||
USER: {Name: "user username auto create", Help: "用户", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create userrole=void,tech username password", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_user_create(m, m.Option(USERNAME), m.Option(PASSWORD))
|
||||
_role_user(m, m.Option(USERROLE), m.Option(USERNAME))
|
||||
}},
|
||||
},
|
||||
})
|
||||
mdb.REMOVE: {Name: "remove username", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionFields(m.Config(kit.MDB_FIELD))
|
||||
m.Cmdy(mdb.DELETE, USER, "", mdb.HASH, m.OptionSimple(m.Config(kit.MDB_SHORT)))
|
||||
m.Event(USER_REMOVE, USER, m.Option(m.Config(kit.MDB_SHORT)))
|
||||
}},
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == USER {
|
||||
_user_search(m, arg[1], kit.Select("", arg, 2))
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(USERROLE, UserRole(m, value[USERNAME]))
|
||||
})
|
||||
m.PushAction(mdb.REMOVE)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -8,10 +8,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"github.com/skip2/go-qrcode"
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
var _trans_web = map[string]color.Color{
|
||||
@ -96,7 +95,7 @@ func _qrcode_web(m *ice.Message, text string) {
|
||||
|
||||
func Color(m *ice.Message, c string, str interface{}) string {
|
||||
wrap, color := `<span style="color:%s">%v</span>`, c
|
||||
if aaa.SessIsCli(m) {
|
||||
if m.IsCliUA() {
|
||||
wrap, color = "\033[3%sm%v\033[0m", _trans_cli(c)
|
||||
}
|
||||
return fmt.Sprintf(wrap, color, str)
|
||||
@ -142,7 +141,7 @@ func init() {
|
||||
m.Option(BG, kit.Select(WHITE, arg, 2))
|
||||
m.Option(FG, kit.Select(BLUE, arg, 1))
|
||||
|
||||
if aaa.SessIsCli(m) {
|
||||
if m.IsCliUA() {
|
||||
_qrcode_cli(m, kit.Select(m.Conf("web.share", kit.Keym(kit.MDB_DOMAIN)), arg, 0))
|
||||
} else {
|
||||
_qrcode_web(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
||||
|
@ -144,7 +144,12 @@ func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
const HASH = "hash"
|
||||
|
||||
func HashAction(fields ...string) map[string]*ice.Action {
|
||||
_key := func(m *ice.Message) string { return kit.Select(kit.MDB_HASH, m.Config(kit.MDB_SHORT)) }
|
||||
_key := func(m *ice.Message) string {
|
||||
if m.Config(kit.MDB_HASH) == "uniq" {
|
||||
return kit.MDB_HASH
|
||||
}
|
||||
return kit.Select(kit.MDB_HASH, m.Config(kit.MDB_SHORT))
|
||||
}
|
||||
return ice.SelectAction(map[string]*ice.Action{
|
||||
INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INPUTS, m.PrefixKey(), "", HASH, arg)
|
||||
@ -178,7 +183,8 @@ func HashAction(fields ...string) map[string]*ice.Action {
|
||||
}},
|
||||
}, fields...)
|
||||
}
|
||||
func HashSelect(m *ice.Message, arg ...string) {
|
||||
func HashSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
m.Fields(len(arg), m.Config(kit.MDB_FIELD))
|
||||
m.Cmdy(SELECT, m.PrefixKey(), "", HASH, m.Config(kit.MDB_SHORT), arg)
|
||||
return m
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ func _dir_show(m *ice.Message, root string, name string, level int, deep bool, d
|
||||
|
||||
m.Push(kit.MDB_HASH, kit.Select(hex.EncodeToString(h[:6]), hex.EncodeToString(h[:]), field == kit.MDB_HASH))
|
||||
case ctx.ACTION:
|
||||
if !f.IsDir() && !aaa.SessIsCli(m) && m.Option(ice.MSG_USERROLE) != aaa.VOID {
|
||||
if !f.IsDir() && !m.IsCliUA() && m.Option(ice.MSG_USERROLE) != aaa.VOID {
|
||||
m.PushButton(TRASH)
|
||||
} else {
|
||||
m.Push(field, "")
|
||||
|
3
data.go
3
data.go
@ -8,6 +8,9 @@ import (
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
)
|
||||
|
||||
func (m *Message) CommandKey(arg ...string) string {
|
||||
return strings.TrimPrefix(m._key, "/")
|
||||
}
|
||||
func (m *Message) PrefixKey(arg ...string) string {
|
||||
return kit.Keys(m.Cap(CTX_FOLLOW), strings.TrimPrefix(m._key, "/"), arg)
|
||||
}
|
||||
|
10
render.go
10
render.go
@ -116,16 +116,16 @@ func (m *Message) PushSearch(args ...interface{}) {
|
||||
for _, k := range kit.Split(m.OptionFields()) {
|
||||
switch k {
|
||||
case POD:
|
||||
m.Push(k, "")
|
||||
// m.Push(k, kit.Select(m.Option(MSG_USERPOD), data[kit.SSH_POD]))
|
||||
m.Push(k, kit.Select("", data[k]))
|
||||
// m.Push(k, kit.Select(m.Option(MSG_USERPOD), data[POD]))
|
||||
case CTX:
|
||||
m.Push(k, m.Prefix())
|
||||
m.Push(k, kit.Select(m.Prefix(), data[CTX]))
|
||||
case CMD:
|
||||
m.Push(k, kit.Format(data[CMD]))
|
||||
m.Push(k, kit.Select(m.CommandKey(), data[CMD]))
|
||||
case kit.MDB_TIME:
|
||||
m.Push(k, kit.Select(m.Time(), data[k]))
|
||||
default:
|
||||
m.Push(k, kit.Format(kit.Select("", data[k])))
|
||||
m.Push(k, kit.Select("", data[k]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user