forked from x/icebergs
opt base
This commit is contained in:
parent
73580d0df5
commit
fadcac3ddb
@ -1,8 +1,6 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const (
|
||||
RSA = "rsa"
|
||||
|
@ -25,17 +25,15 @@ func init() {
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
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) {
|
||||
SEND: {Name: "send to*='shylinux@163.com' subject*=hi content*:textarea=hello", Help: "发送", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(SERVICE) == "" {
|
||||
m.Options(m.Cmd("", ADMIN).AppendSimple(SERVICE, USERNAME, PASSWORD))
|
||||
}
|
||||
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.Logs(mdb.EXPORT, EMAIL, auth, string(content))
|
||||
m.Logs(mdb.EXPORT, EMAIL, string(content))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,service,username,password"), mdb.ClearHashOnExitAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).PushAction(SEND, mdb.REMOVE)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,service,username,password", ice.ACTION, SEND))},
|
||||
})
|
||||
}
|
||||
|
@ -15,17 +15,22 @@ const OFFER = "offer"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
OFFER: {Name: "offer hash auto", Help: "邀请", Actions: ice.MergeActions(ice.Actions{
|
||||
INVITE: {Name: "invite email='shylinux@163.com' content", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
|
||||
h := mdb.HashCreate(m, m.OptionSimple(EMAIL, "content"), "from", m.Option(ice.MSG_USERNAME))
|
||||
INVITE: {Name: "invite email*='shylinux@163.com' content", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
|
||||
h := mdb.HashCreate(m, m.OptionSimple(EMAIL, "content"), "from", m.Option(ice.MSG_USERNAME), mdb.STATUS, INVITE)
|
||||
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)))
|
||||
}},
|
||||
ACCEPT: {Help: "接受", Hand: func(m *ice.Message, arg ...string) {
|
||||
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))))
|
||||
if m.Warn(m.Option(mdb.HASH) == "", ice.ErrNotValid, mdb.HASH) {
|
||||
return
|
||||
}
|
||||
msg := m.Cmd("", m.Option(mdb.HASH))
|
||||
m.Cmd(USER, mdb.CREATE, USERNAME, msg.Option(EMAIL))
|
||||
m.ProcessOpen(kit.MergeURL2(m.Option(ice.MSG_USERWEB), ice.PS, ice.MSG_SESSID, SessCreate(m, msg.Option(EMAIL))))
|
||||
mdb.HashModify(m, m.OptionSimple(mdb.HASH), mdb.STATUS, ACCEPT)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,from,email,content"), RoleAction(ACCEPT)), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,status,from,email,content"), RoleAction(ACCEPT)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 && m.Option(ice.MSG_USERROLE) == VOID {
|
||||
return
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func init() {
|
||||
mdb.Rich(m, ROLE, nil, kit.Dict(mdb.NAME, role, BLACK, kit.Dict(), WHITE, kit.Dict()))
|
||||
}
|
||||
}},
|
||||
mdb.INSERT: {Name: "insert role=void,tech zone=white,black key", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.INSERT: {Name: "insert role*=void,tech zone*=white,black key*", Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_set(m, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY), true)
|
||||
}},
|
||||
mdb.DELETE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -92,7 +92,7 @@ func init() {
|
||||
m.Echo(ice.OK)
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME), mdb.ClearHashOnExitAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME)), Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_list(m, kit.Select("", arg, 0)).PushAction(mdb.DELETE)
|
||||
}},
|
||||
})
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
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(USERNAME, USERNICK, USERROLE), arg)
|
||||
} else {
|
||||
@ -19,14 +18,7 @@ func _sess_create(m *ice.Message, username string, arg ...string) (h string) {
|
||||
return
|
||||
}
|
||||
func _sess_check(m *ice.Message, sessid string) {
|
||||
m.Assert(sessid != "")
|
||||
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
|
||||
}
|
||||
}
|
||||
}) && len(val) > 0 {
|
||||
if val := mdb.HashSelectDetails(m, sessid, func(value ice.Map) bool { return !m.WarnTimeNotValid(value[mdb.TIME], sessid) }); len(val) > 0 {
|
||||
SessAuth(m, val)
|
||||
}
|
||||
}
|
||||
@ -50,10 +42,10 @@ const SESS = "sess"
|
||||
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) {
|
||||
mdb.CREATE: {Name: "create username*", Hand: func(m *ice.Message, arg ...string) {
|
||||
_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) {
|
||||
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,username,usernick,userrole,ua,ip", mdb.EXPIRE, "720h"))},
|
||||
@ -61,14 +53,10 @@ func init() {
|
||||
}
|
||||
|
||||
func SessCreate(m *ice.Message, username string) string {
|
||||
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("aaa.checker", logs.FileLine(-1))
|
||||
m.Options(ice.MSG_USERNAME, "", ice.MSG_USERNICK, "", ice.MSG_USERROLE, VOID)
|
||||
m.Options(ice.MSG_USERNAME, "", ice.MSG_USERNICK, "", ice.MSG_USERROLE, VOID, "aaa.checker", logs.FileLine(-1))
|
||||
return sessid != "" && m.Cmdy(SESS, CHECK, sessid, logs.FileLineMeta(-1)).Option(ice.MSG_USERNAME) != ""
|
||||
}
|
||||
func SessAuth(m *ice.Message, value ice.Any, arg ...string) *ice.Message {
|
||||
|
@ -21,9 +21,8 @@ func _totp_gen(per int64) string {
|
||||
b := hmac.New(sha1.New, buf.Bytes()).Sum(nil)
|
||||
return strings.ToUpper(base32.StdEncoding.EncodeToString(b[:]))
|
||||
}
|
||||
func _totp_get(key string, num int, per int64) string {
|
||||
now := kit.Int64(time.Now().Unix() / per)
|
||||
buf := []byte{}
|
||||
func _totp_get(key string, per int64, num int) string {
|
||||
buf, now := []byte{}, kit.Int64(time.Now().Unix() / per)
|
||||
for i := 0; i < 8; i++ {
|
||||
buf = append(buf, byte((uint64(now) >> uint64(((7 - i) * 8)))))
|
||||
}
|
||||
@ -52,7 +51,7 @@ func init() {
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TOTP: {Name: "totp name auto create", Help: "令牌", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name=hi secret period=30 number=6", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create name*=hi secret period*=30 number*=6", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(SECRET) == "" {
|
||||
m.Option(SECRET, _totp_gen(kit.Int64(m.Option(PERIOD))))
|
||||
}
|
||||
@ -67,10 +66,10 @@ func init() {
|
||||
m.Push(mdb.NAME, value[mdb.NAME])
|
||||
period := kit.Int64(value[PERIOD])
|
||||
m.Push(mdb.EXPIRE, period-time.Now().Unix()%period)
|
||||
m.Push(mdb.VALUE, _totp_get(value[SECRET], kit.Int(value[NUMBER]), period))
|
||||
m.Push(mdb.VALUE, _totp_get(value[SECRET], period, kit.Int(value[NUMBER])))
|
||||
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])))
|
||||
m.Echo(m.Append(mdb.VALUE))
|
||||
} else {
|
||||
m.StatusTimeCount()
|
||||
}
|
||||
@ -79,4 +78,4 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func TOTP_GET(key string, num int, per int64) string { return _totp_get(key, num, per) }
|
||||
func TOTP_GET(key string, per int64, num int) string { return _totp_get(key, per, num) }
|
||||
|
@ -8,29 +8,17 @@ import (
|
||||
)
|
||||
|
||||
func _user_create(m *ice.Message, name, word string, arg ...string) {
|
||||
if m.Warn(name == "", ice.ErrNotValid, name) {
|
||||
return
|
||||
}
|
||||
if word == "" {
|
||||
word = m.CmdAppend(USER, name, PASSWORD)
|
||||
}
|
||||
if word == "" {
|
||||
word = kit.Hashs()
|
||||
}
|
||||
mdb.HashCreate(m, USERNAME, name, PASSWORD, word, arg)
|
||||
mdb.HashCreate(m, USERNAME, name, PASSWORD, kit.GetValid(
|
||||
func() string { return word },
|
||||
func() string { return m.CmdAppend(USER, name, PASSWORD) },
|
||||
func() string { return kit.Hashs() },
|
||||
), arg)
|
||||
gdb.Event(m, USER_CREATE, USER, name)
|
||||
}
|
||||
func _user_login(m *ice.Message, name, word string) {
|
||||
if m.Warn(name == "", ice.ErrNotValid, name) {
|
||||
return
|
||||
}
|
||||
if val := kit.Dict(); mdb.HashSelectDetail(m.Spawn(), name, func(value ice.Map) {
|
||||
if !m.Warn(word != "" && word != kit.Format(value[PASSWORD]), ice.ErrNotValid) {
|
||||
for k, v := range value {
|
||||
val[k] = v
|
||||
}
|
||||
}
|
||||
}) && len(val) > 0 {
|
||||
if val := mdb.HashSelectDetails(m.Spawn(), name, func(value ice.Map) bool {
|
||||
return !m.Warn(word != "" && word != kit.Format(value[PASSWORD]), ice.ErrNotValid)
|
||||
}); len(val) > 0 {
|
||||
SessAuth(m, val)
|
||||
}
|
||||
}
|
||||
@ -101,8 +89,8 @@ func UserRoot(m *ice.Message, arg ...string) *ice.Message {
|
||||
usernick := kit.Select(UserNick(m, username), arg, 1)
|
||||
userrole := kit.Select(ROOT, arg, 2)
|
||||
if len(arg) > 0 {
|
||||
ice.Info.UserName = username
|
||||
m.Cmd(USER, mdb.CREATE, username, "", usernick, "", userrole)
|
||||
ice.Info.UserName = username
|
||||
}
|
||||
return SessAuth(m, kit.Dict(USERNAME, username, USERNICK, usernick, USERROLE, userrole))
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ func init() {
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashPrunesValue(m, mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE)
|
||||
}},
|
||||
START: {Name: "start cmd dir env", Hand: func(m *ice.Message, arg ...string) {
|
||||
START: {Name: "start cmd* dir env", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Options(CMD_DIR, m.Option(DIR), CMD_ENV, kit.Split(m.Option(ENV), " ="))
|
||||
_daemon_exec(m, _system_cmd(m, kit.Split(m.Option(ice.CMD))...))
|
||||
}},
|
||||
|
@ -25,8 +25,7 @@ const MIRRORS = "mirrors"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
MIRRORS: {Name: "mirrors cli auto", Help: "软件镜像", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", kit.Keys(mdb.HASH), "") }},
|
||||
mdb.INSERT: {Name: "insert cli osid cmd"},
|
||||
mdb.INSERT: {Name: "insert cli* osid cmd*"},
|
||||
CMD: {Name: "cmd cli osid", Hand: func(m *ice.Message, arg ...string) {
|
||||
osid := kit.Select(m.Conf(RUNTIME, kit.Keys(HOST, OSID)), m.Option(OSID))
|
||||
mdb.ZoneSelectCB(m, m.Option(CLI), func(value ice.Map) {
|
||||
@ -36,7 +35,7 @@ func init() {
|
||||
})
|
||||
}},
|
||||
ALPINE: {Name: "alpine cli cmd", Hand: func(m *ice.Message, arg ...string) { IsAlpine(m, arg...) }},
|
||||
}, mdb.ZoneAction(mdb.SHORT, CLI, mdb.FIELD, "time,id,osid,cmd"))},
|
||||
}, mdb.ZoneAction(mdb.SHORT, CLI, mdb.FIELD, "time,id,osid,cmd"), mdb.ClearHashOnExitAction())},
|
||||
})
|
||||
}
|
||||
|
||||
@ -61,8 +60,7 @@ func insert(m *ice.Message, sys, cmd string, arg ...string) bool {
|
||||
}
|
||||
if len(arg) > 0 {
|
||||
m.Go(func() {
|
||||
m.Sleep300ms()
|
||||
m.Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, sys, CMD, cmd+ice.SP+kit.Select(arg[0], arg, 1))
|
||||
m.Sleep300ms().Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, sys, CMD, cmd+ice.SP+kit.Select(arg[0], arg, 1))
|
||||
})
|
||||
}
|
||||
return true
|
||||
|
@ -49,19 +49,14 @@ func _runtime_init(m *ice.Message) {
|
||||
ice.Info.PathName = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME))
|
||||
ice.Info.UserName = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME))
|
||||
aaa.UserRoot(ice.Pulse, ice.Info.UserName)
|
||||
bin := _system_find(m, os.Args[0])
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), bin)
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.TIME), m.Time())
|
||||
if s, e := nfs.StatFile(m, bin); e == nil {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), kit.FmtSize(s.Size()))
|
||||
if f, e := nfs.OpenFile(m, bin); e == nil {
|
||||
defer f.Close()
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), kit.Hashs(f))
|
||||
}
|
||||
}
|
||||
msg := m.Cmd(nfs.DIR, _system_find(m, os.Args[0]), "time,path,size,hash")
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), msg.Append(nfs.PATH))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), msg.Append(nfs.SIZE))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), msg.Append(mdb.HASH))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.TIME), msg.Append(mdb.TIME))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1)
|
||||
m.Conf(RUNTIME, mdb.META, "")
|
||||
m.Conf(RUNTIME, mdb.HASH, "")
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))+1)
|
||||
}
|
||||
func _runtime_hostinfo(m *ice.Message) {
|
||||
m.Push("nCPU", strings.Count(m.Cmdx(nfs.CAT, "/proc/cpuinfo"), "processor"))
|
||||
@ -107,8 +102,8 @@ const (
|
||||
)
|
||||
const (
|
||||
PATH = "PATH"
|
||||
HOME = "HOME"
|
||||
USER = "USER"
|
||||
HOME = "HOME"
|
||||
TERM = "TERM"
|
||||
SHELL = "SHELL"
|
||||
)
|
||||
@ -154,7 +149,7 @@ const RUNTIME = "runtime"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,diskinfo,bootinfo,api,cli,cmd,env auto", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
|
||||
RUNTIME: {Name: "runtime info=ifconfig,hostinfo,hostname,userinfo,procinfo,diskinfo,bootinfo,api,cli,cmd,env,chain auto", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _runtime_init(m) }},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", "", nil) }},
|
||||
IFCONFIG: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("tcp.host") }},
|
||||
@ -209,6 +204,9 @@ func init() {
|
||||
m.Echo(kit.MergePOD(os.Getenv(CTX_DEV), os.Getenv(CTX_POD)))
|
||||
}
|
||||
}},
|
||||
"chain": {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(m.FormatChain())
|
||||
}},
|
||||
}, ctx.ConfAction("")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == BOOTINFO {
|
||||
arg = arg[1:]
|
||||
|
@ -137,9 +137,6 @@ const SYSTEM = "system"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SYSTEM: {Name: "system cmd run", Help: "系统命令", Actions: ice.Actions{
|
||||
"find": {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_system_find(m, arg[0], arg[1:]...))
|
||||
}},
|
||||
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, p := range arg {
|
||||
if !strings.Contains(m.Cmdx(nfs.CAT, ice.ETC_PATH), p) {
|
||||
@ -148,6 +145,9 @@ func init() {
|
||||
}
|
||||
m.Cmdy(nfs.CAT, ice.ETC_PATH)
|
||||
}},
|
||||
"find": {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_system_find(m, arg[0], arg[1:]...))
|
||||
}},
|
||||
MAN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, "")
|
||||
|
@ -20,8 +20,7 @@ func _config_only(v ice.Any, arg ...string) bool {
|
||||
if len(v) > len(arg) {
|
||||
return false
|
||||
}
|
||||
kit.Sort(arg)
|
||||
for _, k := range kit.SortedKey(v) {
|
||||
for k := range v {
|
||||
if kit.IndexOf(arg, k) == -1 {
|
||||
return false
|
||||
}
|
||||
@ -31,10 +30,8 @@ func _config_only(v ice.Any, arg ...string) bool {
|
||||
return false
|
||||
}
|
||||
func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
msg := m.Spawn(m.Source())
|
||||
data := ice.Map{}
|
||||
data, msg := ice.Map{}, m.Spawn(m.Source())
|
||||
for _, k := range arg {
|
||||
// if v := msg.Confv(k); _config_only(v, mdb.META) && _config_only(kit.Value(v, mdb.META), mdb.FIELD, mdb.SHORT) {
|
||||
if v := msg.Confv(k); _config_only(v, mdb.META) {
|
||||
continue
|
||||
} else {
|
||||
@ -44,9 +41,8 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
if len(data) == 0 {
|
||||
return
|
||||
}
|
||||
if f, p, e := miss.CreateFile(path.Join(ice.VAR_CONF, name)); m.Assert(e) {
|
||||
if f, _, e := miss.CreateFile(path.Join(ice.VAR_CONF, name)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
if s, e := json.MarshalIndent(data, "", " "); !m.Warn(e) {
|
||||
if _, e := f.Write(s); !m.Warn(e) {
|
||||
}
|
||||
@ -54,11 +50,9 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
}
|
||||
}
|
||||
func _config_load(m *ice.Message, name string, arg ...string) {
|
||||
name = path.Join(ice.VAR_CONF, name)
|
||||
if f, e := miss.OpenFile(name); e == nil {
|
||||
if f, e := miss.OpenFile(path.Join(ice.VAR_CONF, name)); e == nil {
|
||||
defer f.Close()
|
||||
msg := m.Spawn(m.Source())
|
||||
data := ice.Map{}
|
||||
data, msg := ice.Map{}, m.Spawn(m.Source())
|
||||
json.NewDecoder(f).Decode(&data)
|
||||
for k, v := range data {
|
||||
msg.Search(k, func(p *ice.Context, s *ice.Context, key string) {
|
||||
|
@ -4,9 +4,7 @@ import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -26,20 +24,7 @@ const CONTEXT = "context"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CONTEXT: {Name: "context name=web action=context,command,config key auto spide", Help: "模块", Actions: ice.MergeActions(ice.Actions{
|
||||
"spide": {Name: "spide", Help: "架构图", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || arg[1] == CONTEXT {
|
||||
m.Cmdy(CONTEXT, kit.Select(ice.ICE, arg, 0), CONTEXT)
|
||||
DisplayStorySpide(m, lex.PREFIX, m.ActionKey(), nfs.ROOT, kit.Select(ice.ICE, arg, 0), lex.SPLIT, ice.PT)
|
||||
} else if index := kit.Keys(arg[1]); strings.HasSuffix(index, arg[2]) {
|
||||
m.Cmdy(CONTEXT, index, COMMAND, func(value ice.Maps) {
|
||||
m.Push(nfs.FILE, arg[1])
|
||||
})
|
||||
} else {
|
||||
m.Cmdy(COMMAND, kit.Keys(index, strings.Split(arg[2], ice.SP)[0]))
|
||||
}
|
||||
}},
|
||||
}, CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
CONTEXT: {Name: "context name=web action=context,command,config key auto", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, m.Source().Cap(ice.CTX_FOLLOW))
|
||||
}
|
||||
|
@ -18,16 +18,15 @@ var list map[string]int = map[string]int{}
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
EVENT: {Name: "event event id auto listen happen", Help: "事件流", Actions: ice.MergeActions(ice.Actions{
|
||||
LISTEN: {Name: "listen event cmd", Help: "监听", Hand: func(m *ice.Message, arg ...string) {
|
||||
LISTEN: {Name: "listen event* cmd*", Help: "监听", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.ZoneInsert(m, m.OptionSimple(EVENT, ice.CMD))
|
||||
list[m.Option(EVENT)]++
|
||||
}},
|
||||
HAPPEN: {Name: "happen event", Help: "触发", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer m.Cost()
|
||||
HAPPEN: {Name: "happen event*", Help: "触发", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionCB(mdb.SELECT, "")
|
||||
mdb.ZoneSelect(m.Spawn(ice.OptionFields("")), m.Option(EVENT)).Tables(func(value ice.Maps) {
|
||||
m.Cmdy(kit.Split(value[ice.CMD]), m.Option(EVENT), arg[2:], ice.OptionFields(""))
|
||||
})
|
||||
}).Cost()
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, EVENT, mdb.FIELD, "time,id,cmd"))},
|
||||
})
|
||||
|
@ -13,7 +13,7 @@ func _timer_action(m *ice.Message, now time.Time, arg ...string) {
|
||||
if value[mdb.COUNT] == "0" {
|
||||
return
|
||||
}
|
||||
if kit.Time(value[mdb.TIME]) > kit.Int64(now) {
|
||||
if value[mdb.TIME] > now.Format(ice.MOD_TIME) {
|
||||
return
|
||||
}
|
||||
m.Cmd(ROUTINE, mdb.CREATE, mdb.NAME, value[mdb.NAME], kit.Keycb(ROUTINE), value[ice.CMD])
|
||||
@ -31,10 +31,10 @@ const TIMER = "timer"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TIMER: {Name: "timer hash auto create prunes", Help: "定时器", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name=hi delay=10ms interval=10s count=3 cmd=runtime"},
|
||||
mdb.CREATE: {Name: "create name*=hi delay=10ms interval=10s count=3 cmd*=runtime"},
|
||||
mdb.PRUNES: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.COUNT, "0") }},
|
||||
HAPPEN: {Hand: func(m *ice.Message, arg ...string) { _timer_action(m, time.Now(), arg...) }},
|
||||
RESTART: {Name: "restart count=3", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||
RESTART: {Name: "restart count=3", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashModify(m, m.OptionSimple(mdb.HashShort(m)), arg)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,name,delay,interval,count,cmd", TICK, "60s"))},
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"io"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -13,8 +14,8 @@ import (
|
||||
func _tail_create(m *ice.Message, arg ...string) {
|
||||
h := mdb.HashCreate(m, arg)
|
||||
kit.Fetch(kit.Split(m.Option(FILE)), func(file string) {
|
||||
m.Options("cmd_output", Pipe(m, func(text string) { mdb.ZoneInsert(m, h, FILE, file, nfs.SIZE, len(text), mdb.TEXT, text) }), mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE)
|
||||
m.Cmd("cli.daemon", TAIL, "-n", "0", "-f", file)
|
||||
m.Options(cli.CMD_OUTPUT, Pipe(m, func(text string) { mdb.ZoneInsert(m, h, FILE, file, nfs.SIZE, len(text), mdb.TEXT, text) }), mdb.CACHE_CLEAR_ON_EXIT, ice.TRUE)
|
||||
m.Cmd(cli.DAEMON, TAIL, "-n", "0", "-f", file)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
package mdb
|
@ -1,8 +1,6 @@
|
||||
package mdb
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const ENGINE = "engine"
|
||||
|
||||
|
@ -128,7 +128,10 @@ const (
|
||||
const HASH = "hash"
|
||||
|
||||
func HashAction(arg ...Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: AutoConfig(append(kit.List(FIELD, HASH_FIELD), arg...)...), ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { HashSelectClose(m) }},
|
||||
return ice.Actions{
|
||||
ice.CTX_INIT: AutoConfig(append(kit.List(FIELD, HASH_FIELD), arg...)...),
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { HashSelectClose(m) }},
|
||||
|
||||
INPUTS: {Hand: func(m *ice.Message, arg ...string) { HashInputs(m, arg) }},
|
||||
CREATE: {Hand: func(m *ice.Message, arg ...string) { HashCreate(m, arg) }},
|
||||
REMOVE: {Hand: func(m *ice.Message, arg ...string) { HashRemove(m, arg) }},
|
||||
@ -147,9 +150,7 @@ func StatusHashAction(arg ...Any) ice.Actions {
|
||||
}, HashAction(arg...))
|
||||
}
|
||||
func ClearHashOnExitAction() ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Conf("", HASH, "")
|
||||
}}})
|
||||
return ice.MergeActions(ice.Actions{ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", HASH, "") }}})
|
||||
}
|
||||
|
||||
func HashKey(m *ice.Message) string {
|
||||
@ -236,6 +237,17 @@ func HashSelectDetail(m *ice.Message, key string, cb Any) (has bool) {
|
||||
})
|
||||
return
|
||||
}
|
||||
func HashSelectDetails(m *ice.Message, key string, cb func(ice.Map) bool) ice.Map {
|
||||
val := kit.Dict()
|
||||
HashSelectDetail(m, key, func(value ice.Map) {
|
||||
if cb(value) {
|
||||
for k, v := range value {
|
||||
val[k] = v
|
||||
}
|
||||
}
|
||||
})
|
||||
return val
|
||||
}
|
||||
func HashSelectField(m *ice.Message, key string, field string) (value string) {
|
||||
HashSelectDetail(m, key, func(key string, val ice.Map) {
|
||||
if field == HASH {
|
||||
|
@ -293,3 +293,12 @@ func getLock(m *ice.Message, key string) *task.Lock {
|
||||
}
|
||||
func Lock(m *ice.Message, arg ...ice.Any) func() { return getLock(m, kit.Keys(arg...)).Lock() }
|
||||
func RLock(m *ice.Message, arg ...ice.Any) func() { return getLock(m, kit.Keys(arg...)).RLock() }
|
||||
|
||||
func Config(m *ice.Message, key string, arg ...ice.Any) string {
|
||||
if len(arg) > 0 {
|
||||
defer Lock(m, m.PrefixKey(), key)()
|
||||
} else {
|
||||
defer RLock(m, m.PrefixKey(), key)()
|
||||
}
|
||||
return m.Config(key, arg...)
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package mdb
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const PLUGIN = "plugin"
|
||||
|
||||
|
@ -33,7 +33,6 @@ func RenderAction(args ...ice.Any) ice.Actions {
|
||||
}
|
||||
for _, k := range kit.Split(arg[0]) {
|
||||
HashSelect(m.Spawn(ice.OptionFields("")), k).Tables(func(value ice.Maps) {
|
||||
m.Debug("what %v", m.OptionFields())
|
||||
m.Cmdy(kit.Keys(value[TEXT], value[NAME]), m.CommandKey(), k, arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3))
|
||||
})
|
||||
}
|
||||
|
@ -133,16 +133,14 @@ const (
|
||||
const CAT = "cat"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: ice.Configs{
|
||||
CAT: {Value: kit.Data(SOURCE, kit.DictList(
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CAT: {Name: "cat path auto", Help: "文件", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, ice.SRC_MAIN_JS, ice.SRC_MAIN_GO, ice.SRC_MAIN_SHY) }},
|
||||
}, ctx.ConfAction(SOURCE, kit.DictList(
|
||||
HTML, CSS, JS, GO, SH, SHY, CSV, JSON,
|
||||
PY, MD, TXT, XML, YML, ZML, IML,
|
||||
"license", "makefile", "configure", "conf",
|
||||
))},
|
||||
}, Commands: ice.Commands{
|
||||
CAT: {Name: "cat path auto", Help: "文件", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, ice.SRC_MAIN_JS, ice.SRC_MAIN_GO, ice.SRC_MAIN_SHY) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
))), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], ice.PS) {
|
||||
m.Cmdy(DIR, arg)
|
||||
return
|
||||
@ -152,7 +150,7 @@ func init() {
|
||||
}
|
||||
_cat_list(m, arg[0])
|
||||
}},
|
||||
}})
|
||||
})
|
||||
}
|
||||
func IsSourceFile(m *ice.Message, ext string) bool {
|
||||
return m.Conf(CAT, kit.Keym(SOURCE, ext)) == ice.TRUE
|
||||
|
@ -4,7 +4,7 @@ import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const NFS = "nfs"
|
||||
|
||||
var Index = &ice.Context{Name: "nfs", Help: "存储模块"}
|
||||
var Index = &ice.Context{Name: NFS, Help: "存储模块"}
|
||||
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, GREP, TRASH)
|
||||
|
@ -20,9 +20,6 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PACK: {Name: "pack path auto upload create", Help: "文件系统", Actions: ice.Actions{
|
||||
mdb.UPLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(kit.Simple(m.Optionv(ice.MSG_UPLOAD))) == 1 {
|
||||
m.Cmdy("web.cache", "upload")
|
||||
}
|
||||
if c, e := DiskFile.OpenFile(m.Option(FILE)); m.Assert(e) {
|
||||
defer c.Close()
|
||||
if f, p, e := pack.CreateFile(path.Join(m.Option(PATH), m.Option(mdb.NAME))); m.Assert(e) {
|
||||
@ -33,7 +30,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create path=src/hi/hi.txt text=hello", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create path*=src/hi/hi.txt text*=hello", Hand: func(m *ice.Message, arg ...string) {
|
||||
if f, p, e := pack.CreateFile(m.Option(PATH)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
if n, e := f.Write([]byte(m.Option(mdb.TEXT))); m.Assert(e) {
|
||||
|
@ -59,6 +59,12 @@ func (f *Frame) prompt(m *ice.Message, list ...string) *Frame {
|
||||
return f
|
||||
}
|
||||
func (f *Frame) printf(m *ice.Message, str string, arg ...ice.Any) *Frame {
|
||||
if f.source != STDIO {
|
||||
return f
|
||||
}
|
||||
if m.Target().Cap(ice.CTX_STATUS) == ice.CTX_CLOSE {
|
||||
return f
|
||||
}
|
||||
fmt.Fprint(f.stdout, kit.Format(str, arg...))
|
||||
return f
|
||||
}
|
||||
@ -159,7 +165,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
r, w, _ := os.Pipe()
|
||||
go func() { io.Copy(w, os.Stdin) }()
|
||||
f.pipe, f.stdin, f.stdout = w, r, os.Stdout
|
||||
m.Option(ice.MSG_OPTS, ice.MSG_USERNAME, ice.MSG_USERROLE)
|
||||
m.Optionv(ice.MSG_OPTS, ice.MSG_USERNAME, ice.MSG_USERROLE)
|
||||
f.scan(m, STDIO, "")
|
||||
default:
|
||||
if m.Option(ice.MSG_SCRIPT) != "" {
|
||||
|
@ -68,10 +68,9 @@ const CLIENT = "client"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CLIENT: {Name: "client hash auto prunes", Help: "客户端", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", mdb.HASH, "") }},
|
||||
DIAL: {Name: "dial type name port=9010 host=", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
_client_dial(m, arg...)
|
||||
}},
|
||||
}, mdb.StatusHashAction(mdb.FIELD, "time,hash,status,type,name,host,port,error,nread,nwrite"))},
|
||||
}, mdb.StatusHashAction(mdb.FIELD, "time,hash,status,type,name,host,port,error,nread,nwrite"), mdb.ClearHashOnExitAction())},
|
||||
})
|
||||
}
|
||||
|
@ -62,7 +62,6 @@ const SERVER = "server"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SERVER: {Name: "server hash auto prunes", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", mdb.HASH, "") }},
|
||||
LISTEN: {Name: "listen type name port=9030 host=", Hand: func(m *ice.Message, arg ...string) {
|
||||
_server_listen(m, arg...)
|
||||
}},
|
||||
|
@ -19,7 +19,9 @@ import (
|
||||
)
|
||||
|
||||
func _serve_start(m *ice.Message) {
|
||||
aaa.UserRoot(m, m.Option(aaa.USERNAME), m.Option(aaa.USERNICK))
|
||||
if m.Option(aaa.USERNAME) != "" {
|
||||
aaa.UserRoot(m, m.Option(aaa.USERNAME), m.Option(aaa.USERNICK))
|
||||
}
|
||||
if cli.NodeInfo(m, kit.Select(ice.Info.HostName, m.Option("nodename")), SERVER); m.Option(tcp.PORT) == tcp.RANDOM {
|
||||
m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT))
|
||||
}
|
||||
@ -202,7 +204,11 @@ func init() {
|
||||
_share_local(m, ice.USR_PUBLISH, path.Join(arg...))
|
||||
}},
|
||||
PP(ice.REQUIRE): {Name: "/require/shylinux.com/x/volcanos/proto.js", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
|
||||
// _share_repos(m, path.Join(arg[0], arg[1], arg[2]), arg[3:]...)
|
||||
p := path.Join(ice.ISH_PLUGED, path.Join(arg...))
|
||||
if !nfs.ExistsFile(m, p) {
|
||||
m.Cmd(cli.SYSTEM, "git", "clone", "https://"+path.Join(arg[:3]...), path.Join(ice.ISH_PLUGED, path.Join(arg[:3])))
|
||||
}
|
||||
m.RenderDownload(p)
|
||||
}},
|
||||
PP(ice.REQUIRE, ice.NODE_MODULES): {Name: "/require/node_modules/", Help: "依赖库", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := path.Join(ice.SRC, ice.NODE_MODULES, path.Join(arg...))
|
||||
|
@ -103,7 +103,7 @@ var Index = &ice.Context{Name: OAUTH, Help: "认证授权", Commands: ice.Comman
|
||||
if m.Option(ACCESS_TOKEN) == "" {
|
||||
m.RenderStatusBadRequest() // 参数错误
|
||||
|
||||
} else if msg := m.Cmd(OFFER, m.Option(ACCESS_TOKEN), ice.OptionFields("time,scope")); kit.Time(msg.Append(mdb.TIME)) < kit.Time(msg.Time()) {
|
||||
} else if msg := m.Cmd(OFFER, m.Option(ACCESS_TOKEN), ice.OptionFields("time,scope")); msg.Append(mdb.TIME) < msg.Time() {
|
||||
m.RenderStatusUnauthorized() // 已过期
|
||||
|
||||
} else { // 访问
|
||||
@ -146,7 +146,7 @@ var Index = &ice.Context{Name: OAUTH, Help: "认证授权", Commands: ice.Comman
|
||||
} else if m.Warn(msg.Append(USED) == ice.TRUE, ice.ErrNotRight, CODE) {
|
||||
m.RenderStatusForbidden() // 已使用
|
||||
|
||||
} else if kit.Time(msg.Append(mdb.TIME)) < kit.Time(m.Time()) {
|
||||
} else if msg.Append(mdb.TIME) < m.Time() {
|
||||
m.RenderStatusUnauthorized() // 已过期
|
||||
|
||||
} else { // 授权
|
||||
@ -159,7 +159,7 @@ var Index = &ice.Context{Name: OAUTH, Help: "认证授权", Commands: ice.Comman
|
||||
if ls := strings.SplitN(m.R.Header.Get(web.Authorization), ice.SP, 2); m.Warn(len(ls) != 2 || ls[1] == "", ice.ErrNotFound, web.Bearer) {
|
||||
m.RenderStatusBadRequest() // 参数错误
|
||||
|
||||
} else if msg := m.Cmd(ACCESS, ls[1]); kit.Time(msg.Append(mdb.TIME)) < kit.Time(m.Time()) {
|
||||
} else if msg := m.Cmd(ACCESS, ls[1]); msg.Append(mdb.TIME) < m.Time() {
|
||||
m.RenderStatusUnauthorized() // 已过期
|
||||
|
||||
} else { // 访问
|
||||
|
@ -20,11 +20,9 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
POD: {Name: "pod", Help: "节点", Actions: ice.MergeActions(ice.Actions{
|
||||
web.SERVE_PARSE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch kit.Select("", arg, 0) {
|
||||
case CHAT:
|
||||
if kit.Select("", arg, 0) == CHAT {
|
||||
for i := 1; i < len(arg)-1; i += 2 {
|
||||
m.Logs("refer", arg[i], arg[i+1])
|
||||
m.Option(arg[i], arg[i+1])
|
||||
m.Logs("Refer", arg[i], arg[i+1]).Options(arg[i], arg[i+1])
|
||||
}
|
||||
}
|
||||
}},
|
||||
|
21
logs.go
21
logs.go
@ -190,16 +190,23 @@ func (m *Message) FormatChain() string {
|
||||
for msg := m; msg != nil; msg = msg.message {
|
||||
ms = append(ms, msg)
|
||||
}
|
||||
meta := append([]string{}, NL)
|
||||
show := func(msg *Message, meta string) string {
|
||||
if len(msg.meta[meta]) > 0 {
|
||||
return kit.Format("%s:%d %v", meta, len(msg.meta[meta]), msg.meta[meta])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
meta := []string{}
|
||||
for i := len(ms) - 1; i >= 0; i-- {
|
||||
msg := ms[i]
|
||||
meta = append(meta, kit.Format("%s %s:%d %v %s:%d %v %s:%d %v %s:%d %v %s", msg.FormatPrefix(),
|
||||
MSG_DETAIL, len(msg.meta[MSG_DETAIL]), msg.meta[MSG_DETAIL],
|
||||
MSG_OPTION, len(msg.meta[MSG_OPTION]), msg.meta[MSG_OPTION],
|
||||
MSG_APPEND, len(msg.meta[MSG_APPEND]), msg.meta[MSG_APPEND],
|
||||
MSG_RESULT, len(msg.meta[MSG_RESULT]), msg.meta[MSG_RESULT],
|
||||
meta = append(meta, kit.Join([]string{
|
||||
msg.FormatPrefix(),
|
||||
show(msg, MSG_DETAIL),
|
||||
show(msg, MSG_OPTION),
|
||||
show(msg, MSG_APPEND),
|
||||
show(msg, MSG_RESULT),
|
||||
msg._cmd.GetFileLine(),
|
||||
))
|
||||
}, " "))
|
||||
for _, k := range msg.meta[MSG_OPTION] {
|
||||
if v, ok := msg.meta[k]; ok {
|
||||
meta = append(meta, kit.Format("\t%s: %d %v", k, len(v), v))
|
||||
|
5
meta.go
5
meta.go
@ -184,7 +184,10 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
|
||||
}
|
||||
for _, k := range msg.meta[MSG_OPTION] {
|
||||
switch k {
|
||||
case MSG_CMDS, MSG_FIELDS, MSG_SESSID:
|
||||
case MSG_CMDS, MSG_FIELDS, MSG_SESSID, "event":
|
||||
continue
|
||||
}
|
||||
if strings.HasSuffix(k, ".cb") {
|
||||
continue
|
||||
}
|
||||
if kit.IndexOf(m.meta[MSG_APPEND], k) > -1 {
|
||||
|
6
misc.go
6
misc.go
@ -295,7 +295,9 @@ func (c *Context) _action(m *Message, cmd *Command, key string, sub string, h *A
|
||||
if strings.HasPrefix(arg[i], PS) {
|
||||
break
|
||||
}
|
||||
m.Option(arg[i], arg[i+1])
|
||||
if arg[i+1] != "" {
|
||||
m.Option(arg[i], arg[i+1])
|
||||
}
|
||||
}
|
||||
} else {
|
||||
order = true
|
||||
@ -306,7 +308,7 @@ func (c *Context) _action(m *Message, cmd *Command, key string, sub string, h *A
|
||||
m.Option(name, value)
|
||||
}
|
||||
}
|
||||
if m.Warn(m.OptionDefault(name, kit.Format(kit.Value(v, VALUE))) == "" && kit.Value(v, "need") == "must") {
|
||||
if m.Warn(m.OptionDefault(name, kit.Format(kit.Value(v, VALUE))) == "" && kit.Value(v, "need") == "must", ErrNotValid, name) {
|
||||
return m
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user