diff --git a/base/aaa/email.go b/base/aaa/email.go index 9ee3120c..069e497c 100644 --- a/base/aaa/email.go +++ b/base/aaa/email.go @@ -2,7 +2,7 @@ package aaa import ( "net/smtp" - + ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/mdb" kit "shylinux.com/x/toolkits" @@ -15,13 +15,13 @@ const EMAIL = "email" func init() { const ( - TO = "to" - ADMIN = "admin" + TO = "to" + ADMIN = "admin" SUBJECT = "subject" CONTENT = "content" SERVICE = "service" - NL = "\r\n" - DF = ": " + NL = "\r\n" + DF = ": " ) Index.MergeCommands(ice.Commands{ EMAIL: {Name: "email name auto create", Help: "邮件", Actions: ice.MergeActions(ice.Actions{ @@ -29,13 +29,13 @@ func init() { 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]) + 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,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 b2259c9a..64b6b2b1 100644 --- a/base/aaa/offer.go +++ b/base/aaa/offer.go @@ -15,7 +15,7 @@ const OFFER = "offer" func init() { Index.MergeCommands(ice.Commands{ OFFER: {Name: "offer hash auto", Actions: ice.MergeActions(ice.Actions{ - INVITE: {Name: "invite email content", Help: "邀请", Hand: func(m *ice.Message, arg ...string) { + 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)) 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)) diff --git a/base/aaa/role.go b/base/aaa/role.go index bdba451d..a6822200 100644 --- a/base/aaa/role.go +++ b/base/aaa/role.go @@ -102,7 +102,9 @@ 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, role string, key ...string) bool { return m.Cmdx(ROLE, RIGHT, role, key) == ice.OK } +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() { diff --git a/base/cli/forever.go b/base/cli/forever.go index 06c64713..2bb027bc 100644 --- a/base/cli/forever.go +++ b/base/cli/forever.go @@ -5,7 +5,6 @@ import ( "path" ice "shylinux.com/x/icebergs" - "shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/gdb" "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" @@ -33,18 +32,15 @@ func init() { env = append(env, ls[0], ls[1]) } } - m.Optionv(CMD_ENV, env) - m.Optionv(CMD_INPUT, os.Stdin) - m.Optionv(CMD_OUTPUT, os.Stdout) - m.Optionv(CMD_ERRPUT, os.Stderr) + m.Options(CMD_ENV, env, CMD_INPUT, os.Stdin, CMD_OUTPUT, os.Stdout, CMD_ERRPUT, os.Stderr) if p := kit.Env(CTX_LOG); p != "" { m.Optionv(CMD_ERRPUT, p) } m.Cmd(FOREVER, STOP) if bin := kit.Select(os.Args[0], ice.BIN_ICE_BIN, nfs.ExistsFile(m, ice.BIN_ICE_BIN)); len(arg) > 0 && arg[0] == ice.SPACE { - m.Cmdy(FOREVER, bin, ice.SPACE, "dial", ice.DEV, ice.OPS, arg[2:]) + m.Cmdy(FOREVER, bin, ice.SPACE, "dial", ice.DEV, ice.OPS, arg[1:]) } else { - m.Cmdy(FOREVER, bin, ice.SERVE, START, ice.DEV, "", aaa.USERNAME, aaa.ROOT, aaa.PASSWORD, aaa.ROOT, arg) + m.Cmdy(FOREVER, bin, ice.SERVE, START, ice.DEV, "", arg) } }}, RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.RESTART) }}, diff --git a/base/cli/mirrors.go b/base/cli/mirrors.go index c40697e8..68372f15 100644 --- a/base/cli/mirrors.go +++ b/base/cli/mirrors.go @@ -25,8 +25,8 @@ 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(m.PrefixKey(), kit.Keys(mdb.HASH), "") }}, - mdb.INSERT: {Name: "insert cli osid cmd"}, + ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { m.Conf("", kit.Keys(mdb.HASH), "") }}, + 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) { diff --git a/base/cli/qrcode.go b/base/cli/qrcode.go index 7a3d904b..cdf8f530 100644 --- a/base/cli/qrcode.go +++ b/base/cli/qrcode.go @@ -131,7 +131,6 @@ func init() { _qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0)) } else { m.Option(SIZE, kit.Select(kit.Format(kit.Min(480, kit.Int(m.Option(ice.HEIGHT)), kit.Int(m.Option(ice.WIDTH)))), arg, 3)) - m.Debug("what %v", m.Option(SIZE)) _qrcode_web(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0)) m.StatusTime(mdb.LINK, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0)) } diff --git a/base/cli/runtime.go b/base/cli/runtime.go index 17f442dc..a0b5fbdc 100644 --- a/base/cli/runtime.go +++ b/base/cli/runtime.go @@ -66,9 +66,10 @@ func _runtime_init(m *ice.Message) { func _runtime_hostinfo(m *ice.Message) { m.Push("nCPU", strings.Count(m.Cmdx(nfs.CAT, "/proc/cpuinfo"), "processor")) for i, ls := range strings.Split(m.Cmdx(nfs.CAT, "/proc/meminfo"), ice.NL) { - vs := kit.Split(ls, ": ") - if m.Push(strings.TrimSpace(vs[0]), kit.FmtSize(kit.Int64(strings.TrimSpace(vs[1]))*1024)); i > 1 { - break + if vs := kit.Split(ls, ": "); len(vs) > 1 { + if m.Push(strings.TrimSpace(vs[0]), kit.FmtSize(kit.Int64(strings.TrimSpace(vs[1]))*1024)); i > 1 { + break + } } } m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), ice.FS)[0]) @@ -207,7 +208,7 @@ func init() { m.Echo(kit.MergePOD(os.Getenv(CTX_DEV), os.Getenv(CTX_POD))) } }}, - }, ctx.ConfAction("hi")), Hand: func(m *ice.Message, arg ...string) { + }, ctx.ConfAction("")), Hand: func(m *ice.Message, arg ...string) { if len(arg) > 0 && arg[0] == BOOTINFO { arg = arg[1:] } @@ -216,8 +217,8 @@ func init() { }}, }) } -func NodeInfo(m *ice.Message, kind, name string) { +func NodeInfo(m *ice.Message, arg ...string) { m.Conf(RUNTIME, kit.Keys(NODE, mdb.TIME), m.Time()) - ice.Info.NodeType = m.Conf(RUNTIME, kit.Keys(NODE, mdb.TYPE), kind) - ice.Info.NodeName = m.Conf(RUNTIME, kit.Keys(NODE, mdb.NAME), strings.ReplaceAll(name, ice.PT, "_")) + ice.Info.NodeName = m.Conf(RUNTIME, kit.Keys(NODE, mdb.NAME), kit.Select(ice.Info.NodeName, arg, 0)) + ice.Info.NodeType = m.Conf(RUNTIME, kit.Keys(NODE, mdb.TYPE), kit.Select(ice.Info.NodeType, arg, 1)) } diff --git a/base/cli/system.go b/base/cli/system.go index 2a97ce8e..83d8987a 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -170,9 +170,6 @@ type Message interface { Optionv(key string, arg ...ice.Any) ice.Any } -func IsSuccess(m Message) bool { - return m.Append(CODE) == "0" || m.Append(CODE) == "" -} func SystemFind(m Message, bin string, dir ...string) string { if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 { dir = append(dir, strings.Split(text, ice.NL)...) @@ -180,9 +177,8 @@ func SystemFind(m Message, bin string, dir ...string) string { dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...) return _system_find(m, bin, dir...) } -func SystemExec(m *ice.Message, arg ...string) string { - return strings.TrimSpace(m.Cmdx(SYSTEM, arg)) -} +func IsSuccess(m Message) bool { return m.Append(CODE) == "" || m.Append(CODE) == "0" } +func SystemExec(m *ice.Message, arg ...string) string { return strings.TrimSpace(m.Cmdx(SYSTEM, arg)) } func SystemCmds(m *ice.Message, cmds string, args ...ice.Any) string { return strings.TrimRight(m.Cmdx(SYSTEM, "sh", "-c", kit.Format(cmds, args...), ice.Option{CMD_OUTPUT, ""}), ice.NL) } diff --git a/base/web/serve.go b/base/web/serve.go index 7c3b59bd..19bd6676 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -86,7 +86,7 @@ func _serve_spide(m *ice.Message, prefix string, c *ice.Context) { } } 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 { + 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)) } aaa.UserRoot(m, m.Option(aaa.USERNAME), m.Option(aaa.USERNICK)) @@ -335,7 +335,7 @@ func init() { }, Commands: ice.Commands{ SERVE: {Name: "serve name auto start spide", Help: "服务器", Actions: ice.MergeActions(ice.Actions{ ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { - cli.NodeInfo(m, WORKER, ice.Info.PathName) + cli.NodeInfo(m, ice.Info.PathName, WORKER) for _, p := range []string{LOGIN, SHARE, SPACE, ice.VOLCANOS, ice.INTSHELL, ice.PUBLISH, ice.REQUIRE, ice.HELP, ice.CMD} { m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, p) } diff --git a/exec.go b/exec.go index 8f7b4457..400c0792 100644 --- a/exec.go +++ b/exec.go @@ -18,8 +18,8 @@ func (m *Message) TryCatch(msg *Message, catch bool, cb ...func(msg *Message)) * default: fileline := m.FormatStack(2, 1) m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("chain", msg.FormatChain()) - m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("stack", m.FormatStack(2, 100)) - m.Log(LOG_WARN, "catch: %s %s", e, fileline).Result(ErrWarn, e, SP, m.FormatStack(2, 5)) + m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("stack", m.FormatStack(1, 100)) + m.Log(LOG_WARN, "catch: %s %s", e, fileline).Result(ErrWarn, e, SP, m.FormatStack(1, 5)) if len(cb) > 1 { m.TryCatch(msg, catch, cb[1:]...) } else if !catch {