forked from x/icebergs
opt aaa
This commit is contained in:
parent
ffe18771a1
commit
ad0a0e95df
@ -2,7 +2,7 @@ package aaa
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/mdb"
|
"shylinux.com/x/icebergs/base/mdb"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
@ -15,13 +15,13 @@ const EMAIL = "email"
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
const (
|
const (
|
||||||
TO = "to"
|
TO = "to"
|
||||||
ADMIN = "admin"
|
ADMIN = "admin"
|
||||||
SUBJECT = "subject"
|
SUBJECT = "subject"
|
||||||
CONTENT = "content"
|
CONTENT = "content"
|
||||||
SERVICE = "service"
|
SERVICE = "service"
|
||||||
NL = "\r\n"
|
NL = "\r\n"
|
||||||
DF = ": "
|
DF = ": "
|
||||||
)
|
)
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
EMAIL: {Name: "email name auto create", Help: "邮件", Actions: ice.MergeActions(ice.Actions{
|
EMAIL: {Name: "email name auto create", Help: "邮件", Actions: ice.MergeActions(ice.Actions{
|
||||||
@ -29,13 +29,13 @@ func init() {
|
|||||||
if m.Option(SERVICE) == "" {
|
if m.Option(SERVICE) == "" {
|
||||||
m.Options(m.Cmd("", ADMIN).AppendSimple(SERVICE, USERNAME, PASSWORD))
|
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))
|
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])
|
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.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))
|
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.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)
|
mdb.HashSelect(m, arg...).PushAction(SEND, mdb.REMOVE)
|
||||||
}},
|
}},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ const OFFER = "offer"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
OFFER: {Name: "offer hash auto", Actions: ice.MergeActions(ice.Actions{
|
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))
|
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)),
|
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))
|
kit.Dict(ice.MSG_USERNAME, m.Option(EMAIL), ice.MSG_USERNICK, VOID, ice.MSG_USERROLE, VOID))
|
||||||
|
@ -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,
|
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)))
|
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 {
|
func RoleAction(key ...string) ice.Actions {
|
||||||
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
if c, ok := ice.Info.Index[m.CommandKey()].(*ice.Context); ok && c == m.Target() {
|
if c, ok := ice.Info.Index[m.CommandKey()].(*ice.Context); ok && c == m.Target() {
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
"shylinux.com/x/icebergs/base/aaa"
|
|
||||||
"shylinux.com/x/icebergs/base/gdb"
|
"shylinux.com/x/icebergs/base/gdb"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
@ -33,18 +32,15 @@ func init() {
|
|||||||
env = append(env, ls[0], ls[1])
|
env = append(env, ls[0], ls[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Optionv(CMD_ENV, env)
|
m.Options(CMD_ENV, env, CMD_INPUT, os.Stdin, CMD_OUTPUT, os.Stdout, CMD_ERRPUT, os.Stderr)
|
||||||
m.Optionv(CMD_INPUT, os.Stdin)
|
|
||||||
m.Optionv(CMD_OUTPUT, os.Stdout)
|
|
||||||
m.Optionv(CMD_ERRPUT, os.Stderr)
|
|
||||||
if p := kit.Env(CTX_LOG); p != "" {
|
if p := kit.Env(CTX_LOG); p != "" {
|
||||||
m.Optionv(CMD_ERRPUT, p)
|
m.Optionv(CMD_ERRPUT, p)
|
||||||
}
|
}
|
||||||
m.Cmd(FOREVER, STOP)
|
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 {
|
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 {
|
} 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) }},
|
RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(gdb.SIGNAL, gdb.RESTART) }},
|
||||||
|
@ -25,8 +25,8 @@ const MIRRORS = "mirrors"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.MergeCommands(ice.Commands{
|
Index.MergeCommands(ice.Commands{
|
||||||
MIRRORS: {Name: "mirrors cli auto", Help: "软件镜像", Actions: ice.MergeActions(ice.Actions{
|
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), "") }},
|
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) {
|
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))
|
osid := kit.Select(m.Conf(RUNTIME, kit.Keys(HOST, OSID)), m.Option(OSID))
|
||||||
mdb.ZoneSelectCB(m, m.Option(CLI), func(value ice.Map) {
|
mdb.ZoneSelectCB(m, m.Option(CLI), func(value ice.Map) {
|
||||||
|
@ -131,7 +131,6 @@ func init() {
|
|||||||
_qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0))
|
_qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0))
|
||||||
} else {
|
} 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.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))
|
_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))
|
m.StatusTime(mdb.LINK, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))
|
||||||
}
|
}
|
||||||
|
@ -66,9 +66,10 @@ func _runtime_init(m *ice.Message) {
|
|||||||
func _runtime_hostinfo(m *ice.Message) {
|
func _runtime_hostinfo(m *ice.Message) {
|
||||||
m.Push("nCPU", strings.Count(m.Cmdx(nfs.CAT, "/proc/cpuinfo"), "processor"))
|
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) {
|
for i, ls := range strings.Split(m.Cmdx(nfs.CAT, "/proc/meminfo"), ice.NL) {
|
||||||
vs := kit.Split(ls, ": ")
|
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 {
|
if m.Push(strings.TrimSpace(vs[0]), kit.FmtSize(kit.Int64(strings.TrimSpace(vs[1]))*1024)); i > 1 {
|
||||||
break
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), ice.FS)[0])
|
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)))
|
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 {
|
if len(arg) > 0 && arg[0] == BOOTINFO {
|
||||||
arg = arg[1:]
|
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())
|
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), kit.Select(ice.Info.NodeName, arg, 0))
|
||||||
ice.Info.NodeName = m.Conf(RUNTIME, kit.Keys(NODE, mdb.NAME), strings.ReplaceAll(name, ice.PT, "_"))
|
ice.Info.NodeType = m.Conf(RUNTIME, kit.Keys(NODE, mdb.TYPE), kit.Select(ice.Info.NodeType, arg, 1))
|
||||||
}
|
}
|
||||||
|
@ -170,9 +170,6 @@ type Message interface {
|
|||||||
Optionv(key string, arg ...ice.Any) ice.Any
|
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 {
|
func SystemFind(m Message, bin string, dir ...string) string {
|
||||||
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
|
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
|
||||||
dir = append(dir, strings.Split(text, ice.NL)...)
|
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)...)
|
dir = append(dir, strings.Split(kit.Env(PATH), ice.DF)...)
|
||||||
return _system_find(m, bin, dir...)
|
return _system_find(m, bin, dir...)
|
||||||
}
|
}
|
||||||
func SystemExec(m *ice.Message, arg ...string) string {
|
func IsSuccess(m Message) bool { return m.Append(CODE) == "" || m.Append(CODE) == "0" }
|
||||||
return strings.TrimSpace(m.Cmdx(SYSTEM, arg))
|
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 {
|
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)
|
return strings.TrimRight(m.Cmdx(SYSTEM, "sh", "-c", kit.Format(cmds, args...), ice.Option{CMD_OUTPUT, ""}), ice.NL)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func _serve_spide(m *ice.Message, prefix string, c *ice.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func _serve_start(m *ice.Message) {
|
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))
|
m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT))
|
||||||
}
|
}
|
||||||
aaa.UserRoot(m, m.Option(aaa.USERNAME), m.Option(aaa.USERNICK))
|
aaa.UserRoot(m, m.Option(aaa.USERNAME), m.Option(aaa.USERNICK))
|
||||||
@ -335,7 +335,7 @@ func init() {
|
|||||||
}, Commands: ice.Commands{
|
}, Commands: ice.Commands{
|
||||||
SERVE: {Name: "serve name auto start spide", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
SERVE: {Name: "serve name auto start spide", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
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} {
|
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)
|
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, p)
|
||||||
}
|
}
|
||||||
|
4
exec.go
4
exec.go
@ -18,8 +18,8 @@ func (m *Message) TryCatch(msg *Message, catch bool, cb ...func(msg *Message)) *
|
|||||||
default:
|
default:
|
||||||
fileline := m.FormatStack(2, 1)
|
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("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).Log("stack", m.FormatStack(1, 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).Result(ErrWarn, e, SP, m.FormatStack(1, 5))
|
||||||
if len(cb) > 1 {
|
if len(cb) > 1 {
|
||||||
m.TryCatch(msg, catch, cb[1:]...)
|
m.TryCatch(msg, catch, cb[1:]...)
|
||||||
} else if !catch {
|
} else if !catch {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user