mirror of
https://shylinux.com/x/icebergs
synced 2025-05-12 23:40:15 +08:00
Compare commits
No commits in common. "master" and "v1.5.10" have entirely different histories.
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2025 shylinux
|
||||
Copyright (c) 2020 shylinux
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,3 +1,3 @@
|
||||
# icebergs
|
||||
|
||||
icebergs 是一个后端框架,通过集群化、模块化、自动化方式,在各种设备上,即可一键启动完整的云计算服务与云研发环境。
|
||||
icebergs 是一个应用框架,通过群化、模块化、集自动化方式,在各种设备上,一键部署完整的个人云计算与云研发平台。
|
||||
|
@ -1,16 +1,21 @@
|
||||
package aaa
|
||||
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
)
|
||||
|
||||
const (
|
||||
RSA = "rsa"
|
||||
SIGN = "sign"
|
||||
CERT = "cert"
|
||||
VERIFY = "verify"
|
||||
BASE64 = "base64"
|
||||
)
|
||||
const AAA = "aaa"
|
||||
|
||||
var Index = &ice.Context{Name: AAA, Help: "认证模块"}
|
||||
var Index = &ice.Context{Name: AAA, Help: "认证模块", Commands: ice.Commands{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.Info.Load(m).Cmd(ROLE, ice.CTX_INIT).Cmd(ROLE, mdb.CREATE, TECH, VOID)
|
||||
}},
|
||||
}}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, APPLY, OFFER, EMAIL, USER, TOTP, SESS, ROLE, CERT, RSA) }
|
||||
func init() { ice.Index.Register(Index, nil, OFFER, EMAIL, USER, TOTP, SESS, ROLE, RSA) }
|
||||
|
@ -2,22 +2,14 @@ package aaa
|
||||
|
||||
import (
|
||||
"net/smtp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
ADMIN = "admin"
|
||||
SEND = "send"
|
||||
DATE = "date"
|
||||
FROM = "from"
|
||||
TO = "to"
|
||||
CC = "cc"
|
||||
SUBJECT = "subject"
|
||||
CONTENT = "content"
|
||||
)
|
||||
@ -25,53 +17,23 @@ const EMAIL = "email"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
TO = "to"
|
||||
ADMIN = "admin"
|
||||
SERVICE = "service"
|
||||
NL = "\r\n"
|
||||
DF = ": "
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
EMAIL: {Help: "邮件", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name*=admin service*='smtp.163.com:25' username* password*"},
|
||||
SEND: {Name: "send from=admin to*='shy@shylinux.com' cc subject*=hi content*:textarea=hello", Help: "发送", Icon: "bi bi-send-plus", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := mdb.HashSelects(m.Spawn(), m.OptionDefault(FROM, ADMIN))
|
||||
if m.WarnNotFound(msg.Append(SERVICE) == "", m.Option(FROM)) {
|
||||
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) {
|
||||
kit.If(m.Option(SERVICE) == "", func() { m.Options(m.Cmd("", ADMIN).AppendSimple(SERVICE, USERNAME, PASSWORD)) })
|
||||
if m.Warn(m.Option(SERVICE) == "", ice.ErrNotValid, SERVICE) {
|
||||
return
|
||||
}
|
||||
m.ToastProcess()
|
||||
content := []byte(kit.JoinKV(DF, NL, kit.Simple(FROM, msg.Append(USERNAME), m.OptionSimple(TO, CC, SUBJECT), DATE, time.Now().Format(time.RFC1123Z), html.ContentType, "text/html; charset=UTF-8")...) + NL + NL + m.Option(CONTENT))
|
||||
auth := smtp.PlainAuth("", msg.Append(USERNAME), msg.Append(PASSWORD), kit.Split(msg.Append(SERVICE), ice.DF)[0])
|
||||
m.Logs(EMAIL, SEND, string(content))
|
||||
if !m.WarnNotValid(smtp.SendMail(msg.Append(SERVICE), auth, msg.Append(USERNAME), kit.Split(m.Option(TO)), content)) {
|
||||
m.ToastSuccess()
|
||||
}
|
||||
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.Logs(EMAIL, SEND, string(content)).Warn(smtp.SendMail(m.Option(SERVICE), auth, m.Option(USERNAME), kit.Split(m.Option(TO)), content))
|
||||
}},
|
||||
}, mdb.DevDataAction("name,service,username,password"), mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,service,username", ice.ACTION, SEND)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 && m.Length() == 0 {
|
||||
m.EchoInfoButton(m.Trans("please add admin email", "请配置管理员邮箱"), mdb.CREATE, mdb.DEV_REQUEST)
|
||||
} else if len(arg) == 0 {
|
||||
m.Action(mdb.CREATE, mdb.DEV_REQUEST)
|
||||
}
|
||||
}},
|
||||
})
|
||||
ice.Info.Inputs = append(ice.Info.Inputs, func(m *ice.Message, arg ...string) {
|
||||
switch kit.TrimPrefix(arg[0], "extra.") {
|
||||
case TO:
|
||||
if m.Option(ice.ACTION) != EMAIL {
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
case EMAIL:
|
||||
m.Push(arg[0], "shy@shylinux.com", "shylinux@163.com")
|
||||
case PASSWORD:
|
||||
m.SetAppend()
|
||||
}
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,service,username,password", ice.ACTION, SEND))},
|
||||
})
|
||||
}
|
||||
func SendEmail(m *ice.Message, from, to, cc string, arg ...string) {
|
||||
m.Option(ice.MSG_USERHOST, strings.Split(m.Option(ice.MSG_USERHOST), "://")[1])
|
||||
m.Cmdy(EMAIL, SEND, kit.Select(mdb.Config(m, EMAIL), from), kit.Select(m.Option(EMAIL), to), cc,
|
||||
strings.TrimSpace(kit.Select(ice.Render(m, ice.RENDER_TEMPLATE, SUBJECT_HTML), arg, 0)),
|
||||
kit.Select(ice.Render(m, ice.RENDER_TEMPLATE, CONTENT_HTML), arg, 1),
|
||||
)
|
||||
}
|
||||
|
@ -1,71 +1,41 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _offer_create(m *ice.Message, arg ...string) {
|
||||
h := mdb.HashCreate(m.Spawn(), FROM, m.Option(ice.MSG_USERNAME), mdb.STATUS, INVITE, m.OptionSimple(EMAIL, SUBJECT, CONTENT))
|
||||
SendEmail(m.Options("link", m.Cmdx("host", "publish", m.MergePodCmd("", "", mdb.HASH, h))), m.Option(FROM), "", "")
|
||||
gdb.Event(m, OFFER_CREATE, mdb.HASH, h, EMAIL, m.Option(EMAIL))
|
||||
}
|
||||
func _offer_accept(m *ice.Message, arg ...string) {
|
||||
msg := mdb.HashSelect(m.Spawn(), m.Option(mdb.HASH))
|
||||
if ls := kit.Split(msg.Append(EMAIL), mdb.AT); !m.WarnNotFound(msg.Length() == 0 || len(ls) < 2, m.Option(mdb.HASH)) {
|
||||
m.Spawn().AdminCmd(USER, mdb.CREATE, USERROLE, VOID, USERNAME, msg.Append(EMAIL), USERNICK, ls[0], USERZONE, ls[1])
|
||||
mdb.HashModify(m, m.OptionSimple(mdb.HASH), mdb.STATUS, ACCEPT)
|
||||
gdb.Event(m, OFFER_ACCEPT, mdb.HASH, m.Option(mdb.HASH), EMAIL, msg.Append(EMAIL))
|
||||
m.ProcessLocation(m.MergePod("", ice.MSG_SESSID, SessValid(m.Options(ice.MSG_USERNAME, msg.Append(EMAIL)))))
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
INVITE = "invite"
|
||||
ACCEPT = "accept"
|
||||
SUBJECT_HTML = "subject.html"
|
||||
CONTENT_HTML = "content.html"
|
||||
|
||||
OFFER_CREATE = "offer.create"
|
||||
OFFER_ACCEPT = "offer.accept"
|
||||
INVITE = "invite"
|
||||
ACCEPT = "accept"
|
||||
)
|
||||
const APPLY = "apply"
|
||||
const OFFER = "offer"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
OFFER: {Help: "邀请", Role: VOID, Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict("from", "发自")),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create from*=admin email*='shy@shylinux.com' subject content", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
|
||||
_offer_create(m, arg...)
|
||||
OFFER: {Name: "offer hash auto", Help: "邀请", Actions: ice.MergeActions(ice.Actions{
|
||||
INVITE: {Name: "invite email*='shylinux@163.com' subject content", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
|
||||
h := mdb.HashCreate(m.Spawn(), m.OptionSimple(EMAIL, SUBJECT, CONTENT), INVITE, m.Option(ice.MSG_USERNAME), mdb.STATUS, INVITE)
|
||||
m.Cmd(EMAIL, SEND, m.Option(EMAIL), m.OptionDefault(SUBJECT, "welcome to contents, please continue"),
|
||||
m.OptionDefault(CONTENT, ice.Render(m, ice.RENDER_ANCHOR, m.Cmdx("host", "publish", m.MergePodCmd("", "", mdb.HASH, h)))),
|
||||
)
|
||||
}},
|
||||
ACCEPT: {Help: "接受", Role: VOID, Hand: func(m *ice.Message, arg ...string) {
|
||||
if !m.WarnNotValid(m.Option(mdb.HASH), mdb.HASH) {
|
||||
_offer_accept(m, arg...)
|
||||
ACCEPT: {Help: "接受", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Warn(m.Option(mdb.HASH) == "", ice.ErrNotValid, mdb.HASH) {
|
||||
return
|
||||
}
|
||||
msg := m.Cmd("", m.Option(mdb.HASH))
|
||||
if ls := kit.Split(msg.Append(EMAIL), mdb.AT); !m.Warn(msg.Length() == 0 || len(ls) < 2, ice.ErrNotValid, m.Option(mdb.HASH)) {
|
||||
m.Cmd(USER, mdb.CREATE, USERNICK, ls[0], USERNAME, msg.Append(EMAIL), USERZONE, ls[1])
|
||||
m.ProcessOpen(kit.MergeURL2(m.Option(ice.MSG_USERWEB), ice.PS, ice.MSG_SESSID, SessCreate(m, msg.Append(EMAIL)), mdb.HASH, ""))
|
||||
mdb.HashModify(m, m.OptionSimple(mdb.HASH), mdb.STATUS, ACCEPT)
|
||||
}
|
||||
}},
|
||||
}, mdb.ImportantHashAction(
|
||||
mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,from,status,email,subject,content"), EMAIL, ADMIN,
|
||||
), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.WarnNotRight(len(arg) == 0 && !IsTechOrRoot(m)) {
|
||||
return
|
||||
} else if mdb.HashSelect(m, arg...).FieldsIsDetail() {
|
||||
if m.Option(ice.MSG_USERNAME) == "" {
|
||||
m.Option(ice.MSG_USERHOST, strings.Split(m.Option(ice.MSG_USERHOST), "://")[1])
|
||||
m.SetAppend().EchoInfoButton(m.Template(SUBJECT_HTML), ACCEPT)
|
||||
} else if strings.Contains(m.Option(ice.MSG_USERWEB), "/c/offer") {
|
||||
m.ProcessLocation(m.MergePod(""))
|
||||
}
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,status,invite,email,title,content"), RoleAction(ACCEPT)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if !m.Warn(len(arg) == 0 && m.Option(ice.MSG_USERROLE) == VOID, ice.ErrNotRight) {
|
||||
kit.If(mdb.HashSelect(m, arg...).FieldsIsDetail(), func() { m.PushAction(ACCEPT) }, func() { m.Action(INVITE) })
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
func OfferAction() ice.Actions {
|
||||
return gdb.EventsAction(OFFER_CREATE, OFFER_ACCEPT, USER_CREATE, USER_REMOVE)
|
||||
}
|
||||
|
@ -1,124 +0,0 @@
|
||||
package portal
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
type apply struct {
|
||||
ice.Hash
|
||||
email string `data:"admin"`
|
||||
checkbox string `data:"true"`
|
||||
online string `data:"true"`
|
||||
field string `data:"time,hash,status,email,userrole,username,usernick,icons,agent,system,ip,ua"`
|
||||
apply string `name:"apply" help:"申请" role:"void"`
|
||||
agree string `name:"agree userrole=tech,void" help:"同意" icon:"bi bi-check2-square"`
|
||||
login string `name:"login" help:"登录" role:"void"`
|
||||
list string `name:"list hash auto sso" help:"注册"`
|
||||
}
|
||||
|
||||
func (s apply) Sso(m *ice.Message, arg ...string) {
|
||||
m.AddHeaderLogin(cli.QRCODE, cli.QRCODE, "扫码登录", "10")
|
||||
m.AddHeaderLogin(mdb.PLUGIN, aaa.EMAIL, "邮箱登录", "20", ctx.INDEX, m.ShortKey(), ctx.ARGS, kit.FuncName(s.Login))
|
||||
m.AddHeaderLogin(mdb.PLUGIN, aaa.APPLY, "注册用户", "30", ctx.INDEX, m.ShortKey(), ctx.ARGS, kit.FuncName(s.Apply))
|
||||
}
|
||||
func (s apply) Apply(m *ice.Message, arg ...string) {
|
||||
if m.IsGetMethod() {
|
||||
if k := _cookie_key(m); m.Option(k) == "" || s.List(m, m.Option(k)).Length() == 0 && m.Result() == "" {
|
||||
m.DisplayForm(m, "email*", aaa.USERNICK, s.Apply)
|
||||
}
|
||||
} else if !m.WarnAlreadyExists(m.Options(arg).Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() > 0, m.Option(aaa.EMAIL)) {
|
||||
m.Options(ice.MSG_USERNAME, m.Option(aaa.EMAIL), ice.MSG_USERNICK, kit.Split(m.Option(aaa.EMAIL), "@")[0])
|
||||
h := s.Hash.Create(m, kit.Simple(arg, mdb.STATUS, kit.FuncName(s.Apply), web.ParseUA(m.Message))...)
|
||||
m.ProcessCookie(_cookie_key(m), h)
|
||||
m.StreamPushRefreshConfirm()
|
||||
m.ChatMessageInsertPlug(aaa.APPLY, "user.signup", "", m.PrefixKey(), h)
|
||||
}
|
||||
}
|
||||
func (s apply) Agree(m *ice.Message, arg ...string) {
|
||||
if m.WarnNotValid(m.Option(mdb.HASH) == "", mdb.HASH) {
|
||||
return
|
||||
}
|
||||
msg := s.Hash.List(m.Spawn(), m.Option(mdb.HASH))
|
||||
if m.WarnNotFound(msg.Length() == 0, m.Option(mdb.HASH)) {
|
||||
return
|
||||
}
|
||||
s.Hash.Modify(m, kit.Simple(m.OptionSimple(mdb.HASH, aaa.USERROLE), mdb.STATUS, s.Agree)...)
|
||||
// m.UserCreate(m.Option(aaa.USERROLE), msg.Append(aaa.USERNAME), msg.Append(aaa.USERNICK))
|
||||
m.PushRefresh(msg.Append(cli.DAEMON))
|
||||
}
|
||||
func (s apply) Login(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(mdb.HASH) == kit.FuncName(s.Apply), func() { m.Options(mdb.HASH, "") })
|
||||
if m.IsGetMethod() {
|
||||
m.DisplayForm("email*", s.Login)
|
||||
} else if m.Options(arg).Option(aaa.EMAIL) == "" {
|
||||
if m.WarnNotValid(m.OptionDefault(mdb.HASH, m.Option(_cookie_key(m))) == "", mdb.HASH) {
|
||||
m.ProcessCookie(_cookie_key(m), "")
|
||||
return
|
||||
}
|
||||
msg := s.Hash.List(m.Spawn(), m.Option(mdb.HASH))
|
||||
if m.WarnNotFound(msg.Length() == 0, m.Option(mdb.HASH)) {
|
||||
m.ProcessCookie(_cookie_key(m), "")
|
||||
return
|
||||
}
|
||||
m.UserCreate(m.Option(aaa.USERROLE), msg.Append(aaa.USERNAME), msg.Append(aaa.USERNICK))
|
||||
web.RenderCookie(m.Message, m.Cmdx(aaa.SESS, mdb.CREATE, msg.Append(aaa.USERNAME)))
|
||||
s.Hash.Modify(m, kit.Simple(m.OptionSimple(mdb.HASH), mdb.STATUS, s.Login)...)
|
||||
m.ProcessLocation(nfs.PS)
|
||||
m.StreamPushRefreshConfirm()
|
||||
} else {
|
||||
if m.WarnNotFound(m.Cmd(aaa.USER, m.Option(aaa.EMAIL)).Length() == 0, m.Option(aaa.EMAIL)) {
|
||||
return
|
||||
}
|
||||
m.Options(ice.MSG_USERNAME, m.Option(aaa.EMAIL))
|
||||
space := kit.Keys(kit.Slice(kit.Split(m.Option(ice.MSG_DAEMON), nfs.PT), 0, -1))
|
||||
share := m.Cmd(web.SHARE, mdb.CREATE, mdb.TYPE, web.FIELD, mdb.NAME, web.CHAT_GRANT, mdb.TEXT, space, web.SPACE, ice.OPS).Append(mdb.LINK)
|
||||
m.Options(web.LINK, share).SendEmail("", "", "")
|
||||
// m.ProcessHold(m.Trans("please auth login in mailbox", "请注意查收邮件"))
|
||||
m.Echo(m.Trans("please auth login in mailbox", "请注意查收邮件"))
|
||||
m.ProcessInner()
|
||||
}
|
||||
}
|
||||
func (s apply) List(m *ice.Message, arg ...string) *ice.Message {
|
||||
kit.If(m.Option(_cookie_key(m)), func(p string) { arg = []string{p} })
|
||||
kit.If(!m.IsTech(), func() { m.Option(ice.MSG_ONLINE, ice.FALSE) })
|
||||
if m.IsTech() || (len(arg) > 0 && arg[0] != "") {
|
||||
s.Hash.List(m, arg...).Table(func(value ice.Maps) {
|
||||
switch value[mdb.STATUS] {
|
||||
case kit.FuncName(s.Apply):
|
||||
m.PushButton(s.Agree, s.Remove)
|
||||
case kit.FuncName(s.Agree):
|
||||
m.PushButton(s.Login, s.Remove)
|
||||
default:
|
||||
m.PushButton(s.Remove)
|
||||
}
|
||||
})
|
||||
}
|
||||
if m.Option(_cookie_key(m)) != "" || m.ActionKey() != "" {
|
||||
switch m.Append(mdb.STATUS) {
|
||||
case kit.FuncName(s.Login):
|
||||
if m.ActionKey() == kit.FuncName(s.Apply) {
|
||||
m.ProcessCookie(_cookie_key(m), "")
|
||||
} else {
|
||||
m.SetAppend().ProcessLocation(nfs.PS)
|
||||
}
|
||||
case kit.FuncName(s.Agree):
|
||||
m.SetAppend().EchoInfoButton(m.Trans("please login", "请登录"), s.Login)
|
||||
case kit.FuncName(s.Apply):
|
||||
m.SetAppend().EchoInfoButton(m.Trans("please wait admin agree", "请等待管理员同意"), nil)
|
||||
}
|
||||
} else if len(arg) == 0 {
|
||||
m.EchoQRCode(m.MergePodCmd("", "", ctx.ACTION, s.Apply))
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func init() { ice.Cmd("aaa.apply", apply{}) }
|
||||
|
||||
func _cookie_key(m *ice.Message) string { return kit.Keys(m.PrefixKey(), mdb.HASH) }
|
@ -1,77 +0,0 @@
|
||||
package portal
|
||||
|
||||
import (
|
||||
"shylinux.com/x/ice"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
type asign struct {
|
||||
ice.Hash
|
||||
export string `data:"true"`
|
||||
short string `data:"role"`
|
||||
field string `data:"time,role"`
|
||||
shorts string `data:"index"`
|
||||
fields string `data:"time,index,operate"`
|
||||
insert string `name:"insert index"`
|
||||
deploy string `name:"deploy" help:"部署"`
|
||||
list string `name:"list role auto" help:"分配"`
|
||||
confer string `name:"confer username" help:"授权"`
|
||||
}
|
||||
|
||||
func (s asign) Inputs(m *ice.Message, arg ...string) {
|
||||
if arg[0] == "operate" {
|
||||
m.Search(m.Option(ctx.INDEX), func(key string, cmd *ice.Command) {
|
||||
for sub, action := range cmd.Actions {
|
||||
if kit.HasPrefix(sub, "_", "/") {
|
||||
continue
|
||||
}
|
||||
m.Push(arg[0], sub)
|
||||
m.Push(mdb.NAME, action.Name)
|
||||
m.Push(mdb.HELP, action.Help)
|
||||
}
|
||||
m.Sort(arg[0])
|
||||
m.Option(ice.TABLE_CHECKBOX, ice.TRUE)
|
||||
})
|
||||
} else if arg[0] == aaa.USERNAME {
|
||||
m.Cmdy(aaa.USER).Cut(aaa.USERNAME, aaa.USERNICK, aaa.USERROLE)
|
||||
} else {
|
||||
s.Hash.Inputs(m, arg...)
|
||||
}
|
||||
}
|
||||
func (s asign) Modify(m *ice.Message, arg ...string) {
|
||||
if m.Option(ctx.INDEX) != "" {
|
||||
s.Update(m, arg...)
|
||||
} else {
|
||||
s.Modify(m, arg...)
|
||||
}
|
||||
}
|
||||
func (s asign) Deploy(m *ice.Message, arg ...string) {
|
||||
defer m.ToastProcess()()
|
||||
s.List(m.Spawn()).Table(func(val ice.Maps) {
|
||||
m.Cmd(aaa.ROLE, mdb.REMOVE, val[aaa.ROLE])
|
||||
m.Cmd(aaa.ROLE, mdb.CREATE, val[aaa.ROLE])
|
||||
s.List(m.Spawn(), val[aaa.ROLE]).Table(func(value ice.Maps) {
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, val[aaa.ROLE], value[ctx.INDEX])
|
||||
m.Cmd(aaa.ROLE, aaa.BLACK, val[aaa.ROLE], value[ctx.INDEX], ctx.ACTION)
|
||||
kit.For(kit.Split(value["operate"]), func(p string) {
|
||||
m.Cmd(aaa.ROLE, aaa.WHITE, val[aaa.ROLE], value[ctx.INDEX], ctx.ACTION, p)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
func (s asign) List(m *ice.Message, arg ...string) *ice.Message {
|
||||
if len(arg) == 0 {
|
||||
s.Hash.List(m, arg...).Action(s.Create, s.Deploy).PushAction(s.Confer, s.Remove)
|
||||
} else {
|
||||
s.Hash.SubList(m, arg[0], arg[1:]...).Action(s.Insert, s.Deploy).PushAction(s.Delete)
|
||||
}
|
||||
return m
|
||||
}
|
||||
func (s asign) Confer(m *ice.Message, arg ...string) {
|
||||
m.Cmd(aaa.USER, mdb.MODIFY, aaa.USERNAME, m.Option(aaa.USERNAME), aaa.USERROLE, m.Option(aaa.ROLE))
|
||||
}
|
||||
|
||||
func init() { ice.Cmd("aaa.asign", asign{}) }
|
115
base/aaa/role.go
115
base/aaa/role.go
@ -16,7 +16,7 @@ func _role_keys(key ...string) string {
|
||||
key[0] = _key
|
||||
}
|
||||
}
|
||||
return strings.TrimPrefix(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), "web.")
|
||||
return strings.TrimPrefix(strings.TrimPrefix(strings.TrimSuffix(strings.Replace(path.Join(strings.Replace(kit.Keys(key), ice.PT, ice.PS, -1)), ice.PS, ice.PT, -1), ice.PT), ice.PT), "web.")
|
||||
}
|
||||
func _role_set(m *ice.Message, role, zone, key string, status bool) {
|
||||
m.Logs(mdb.INSERT, mdb.KEY, ROLE, ROLE, role, zone, key)
|
||||
@ -35,20 +35,16 @@ func _role_check(value ice.Map, key []string, ok bool) bool {
|
||||
func _role_right(m *ice.Message, role string, key ...string) (ok bool) {
|
||||
return role == ROOT || len(mdb.HashSelectDetails(m, kit.Select(VOID, role), func(value ice.Map) bool { return _role_check(value, key, role == TECH) })) > 0
|
||||
}
|
||||
func _role_list(m *ice.Message, role string, arg ...string) *ice.Message {
|
||||
func _role_list(m *ice.Message, role string) *ice.Message {
|
||||
mdb.HashSelectDetail(m, kit.Select(VOID, role), func(value ice.Map) {
|
||||
kit.For(value[WHITE], func(k string, v ice.Any) {
|
||||
if len(arg) == 0 || k == arg[0] {
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME)).Push(mdb.ZONE, WHITE).Push(mdb.KEY, k).Push(mdb.STATUS, v)
|
||||
}
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME)).Push(mdb.ZONE, WHITE).Push(mdb.KEY, k).Push(mdb.STATUS, v)
|
||||
})
|
||||
kit.For(value[BLACK], func(k string, v ice.Any) {
|
||||
if len(arg) == 0 || k == arg[0] {
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME)).Push(mdb.ZONE, BLACK).Push(mdb.KEY, k).Push(mdb.STATUS, v)
|
||||
}
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME)).Push(mdb.ZONE, BLACK).Push(mdb.KEY, k).Push(mdb.STATUS, v)
|
||||
})
|
||||
})
|
||||
return m.Sort(mdb.KEY)
|
||||
return m.Sort(mdb.KEY).StatusTimeCount()
|
||||
}
|
||||
|
||||
const (
|
||||
@ -61,45 +57,17 @@ const (
|
||||
BLACK = "black"
|
||||
RIGHT = "right"
|
||||
)
|
||||
const (
|
||||
AUTH = "auth"
|
||||
ACCESS = "access"
|
||||
PUBLIC = "public"
|
||||
PRIVATE = "private"
|
||||
CONFIRM = "confirm"
|
||||
)
|
||||
const ROLE = "role"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ROLE: {Name: "role name key auto", Help: "角色", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(ROLE, mdb.CREATE, VOID, TECH)
|
||||
has := map[string]bool{VOID: true, TECH: true}
|
||||
m.Travel(func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
role := map[string][]string{}
|
||||
kit.For(kit.Split(cmd.Role), func(k string) { role[k] = []string{} })
|
||||
for sub, action := range cmd.Actions {
|
||||
kit.For(kit.Split(action.Role), func(k string) { role[k] = append(role[k], sub) })
|
||||
}
|
||||
kit.For(role, func(role string, list []string) {
|
||||
kit.If(!has[role], func() { m.Cmd(ROLE, mdb.CREATE, role); has[role] = true })
|
||||
roleHandle(m, role, list...)
|
||||
})
|
||||
})
|
||||
m.Cmd(ROLE, WHITE, VOID, ROLE, "action", RIGHT)
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.KEY {
|
||||
mdb.HashInputs(m, ice.INDEX).CutTo(ice.INDEX, arg[0])
|
||||
}
|
||||
}},
|
||||
ROLE: {Name: "role role auto insert", Help: "角色", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(arg, func(role string) {
|
||||
mdb.Rich(m, ROLE, nil, kit.Dict(mdb.NAME, role, BLACK, kit.Dict(), WHITE, kit.Dict()))
|
||||
})
|
||||
}},
|
||||
mdb.INSERT: {Name: "insert role*=void 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) {
|
||||
@ -108,65 +76,38 @@ func init() {
|
||||
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 len(arg) > 2 {
|
||||
m.Search(arg[1], func(key string, cmd *ice.Command) {
|
||||
if _, ok := cmd.Actions[arg[2]]; ok {
|
||||
arg = kit.Simple(arg[0], arg[1], ice.ACTION, arg[2:])
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, role := range kit.AddUniq(kit.Split(arg[0]), VOID) {
|
||||
if _role_right(m, role, kit.Split(_role_keys(arg[1:]...), ice.PT)...) {
|
||||
m.Echo(ice.OK)
|
||||
break
|
||||
}
|
||||
}
|
||||
kit.If(_role_right(m, arg[0], kit.Split(_role_keys(arg[1:]...), ice.PT)...), func() { m.Echo(ice.OK) })
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
mdb.HashSelect(m, arg...)
|
||||
} else {
|
||||
_role_list(m, kit.Select("", arg, 0), kit.Slice(arg, 1)...)
|
||||
}
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME)), Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_list(m, kit.Select("", arg, 0)).PushAction(mdb.DELETE)
|
||||
}},
|
||||
})
|
||||
}
|
||||
func roleHandle(m *ice.Message, role string, key ...string) {
|
||||
cmd := m.ShortKey()
|
||||
role = kit.Select(VOID, role)
|
||||
m.Cmd(ROLE, WHITE, role, cmd)
|
||||
if cmd == "header" {
|
||||
return
|
||||
}
|
||||
m.Cmd(ROLE, BLACK, role, cmd, ice.ACTION)
|
||||
kit.For(key, func(key string) { m.Cmd(ROLE, WHITE, role, cmd, ice.ACTION, key) })
|
||||
}
|
||||
func WhiteAction(role string, key ...string) ice.Actions {
|
||||
role = kit.Select(VOID, role)
|
||||
func RoleAction(key ...string) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cmd := m.CommandKey()
|
||||
m.Cmd(ROLE, WHITE, role, cmd)
|
||||
if cmd == "header" {
|
||||
return
|
||||
cmd := m.PrefixKey()
|
||||
if c, ok := ice.Info.Index[m.CommandKey()].(*ice.Context); ok && c == m.Target() {
|
||||
cmd = m.CommandKey()
|
||||
}
|
||||
m.Cmd(ROLE, BLACK, role, cmd, ice.ACTION)
|
||||
kit.For(key, func(key string) { m.Cmd(ROLE, WHITE, role, cmd, ice.ACTION, key) })
|
||||
m.Cmd(ROLE, WHITE, VOID, cmd)
|
||||
m.Cmd(ROLE, BLACK, VOID, cmd, ice.ACTION)
|
||||
kit.For(key, func(key string) { m.Cmd(ROLE, WHITE, VOID, cmd, ice.ACTION, key) })
|
||||
}}}
|
||||
}
|
||||
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)
|
||||
kit.For(key, func(key string) { m.Cmd(ROLE, WHITE, VOID, m.CommandKey(), ice.ACTION, key) })
|
||||
}}}
|
||||
}
|
||||
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, logs.FileLineMeta(-1)) != ice.OK,
|
||||
ice.ErrNotRight, kit.Keys(key...), USERROLE, m.Option(ice.MSG_USERROLE), logs.FileLineMeta(-1))
|
||||
}
|
||||
func White(m *ice.Message, key ...string) {
|
||||
kit.For(key, func(key string) { m.Cmd(ROLE, WHITE, VOID, key) })
|
||||
}
|
||||
func Black(m *ice.Message, key ...string) {
|
||||
kit.For(key, func(key string) { m.Cmd(ROLE, BLACK, VOID, key) })
|
||||
}
|
||||
func Right(m *ice.Message, key ...ice.Any) bool {
|
||||
if key := kit.Simple(key); len(key) > 2 && key[1] == ice.ACTION && kit.IsIn(kit.Format(key[2]), ice.RUN, ice.COMMAND) {
|
||||
return true
|
||||
} else if len(key) > 0 && key[0] == ice.ETC_PATH {
|
||||
return true
|
||||
}
|
||||
// m.Option(ice.MSG_TITLE, kit.Keys(m.Option(ice.MSG_USERPOD), m.CommandKey(), m.ActionKey())+" "+logs.FileLine(-2))
|
||||
return !ice.Info.Important || m.Option(ice.MSG_USERROLE) == ROOT || !m.WarnNotRight(m.Cmdx(ROLE, RIGHT, m.Option(ice.MSG_USERROLE), key, logs.FileLineMeta(-1)) != ice.OK,
|
||||
kit.Keys(key...), USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
}
|
||||
func IsTechOrRoot(m *ice.Message) bool { return kit.IsIn(m.Option(ice.MSG_USERROLE), TECH, ROOT) }
|
||||
|
@ -9,22 +9,20 @@ import (
|
||||
|
||||
func _sess_create(m *ice.Message, username string, arg ...string) {
|
||||
if msg := m.Cmd(USER, username); msg.Length() > 0 {
|
||||
mdb.HashCreate(m, msg.AppendSimple(USERROLE, USERNAME, USERNICK, AVATAR), arg)
|
||||
mdb.HashCreate(m, msg.AppendSimple(USERNICK, USERNAME, USERROLE), arg)
|
||||
} else {
|
||||
mdb.HashCreate(m, m.OptionSimple(USERROLE, USERNAME, USERNICK, AVATAR), arg)
|
||||
mdb.HashCreate(m, m.OptionSimple(USERNICK, USERNAME, USERROLE), arg)
|
||||
}
|
||||
}
|
||||
func _sess_check(m *ice.Message, sessid string) {
|
||||
if val := mdb.HashSelectDetails(m, sessid, func(value ice.Map) bool {
|
||||
return kit.Format(value[mdb.TIME]) > m.Time()
|
||||
}); 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)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
IP = "ip"
|
||||
UA = "ua"
|
||||
IP = "ip"
|
||||
)
|
||||
const (
|
||||
CHECK = "check"
|
||||
@ -35,12 +33,12 @@ const SESS = "sess"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SESS: {Name: "sess hash auto", Help: "会话", Actions: ice.MergeActions(ice.Actions{
|
||||
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), 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(ice.MSG_SESSID)) }},
|
||||
}, mdb.ImportantHashAction("checkbox", ice.TRUE, mdb.EXPIRE, mdb.MONTH, mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,userrole,username,usernick,avatar,ip,ua"))},
|
||||
}, mdb.ImportantHashAction(mdb.EXPIRE, mdb.MONTH, mdb.SHORT, mdb.UNIQ, mdb.FIELD, "time,hash,usernick,username,userrole,ua,ip"))},
|
||||
})
|
||||
}
|
||||
|
||||
@ -48,25 +46,21 @@ func SessCreate(m *ice.Message, username string) string {
|
||||
return m.Option(ice.MSG_SESSID, m.Cmdx(SESS, mdb.CREATE, username))
|
||||
}
|
||||
func SessCheck(m *ice.Message, sessid string) bool {
|
||||
m.Options(ice.MSG_USERNICK, "", ice.MSG_USERNAME, "", ice.MSG_USERROLE, VOID, ice.MSG_CHECKER, logs.FileLine(-1))
|
||||
m.Options(ice.MSG_USERNICK, "", ice.MSG_USERNAME, "", ice.MSG_USERROLE, VOID, "aaa.checker", logs.FileLine(-1))
|
||||
return sessid != "" && m.Cmdy(SESS, CHECK, sessid, logs.FileLineMeta(-1)).Option(ice.MSG_USERNAME) != ""
|
||||
}
|
||||
func SessValid(m *ice.Message) string {
|
||||
if m.Option(ice.MSG_SESSID) == "" || m.Spawn().AdminCmd(SESS, m.Option(ice.MSG_SESSID)).Length() == 0 {
|
||||
return m.Option(ice.MSG_SESSID, m.Spawn().AdminCmd(SESS, mdb.CREATE, m.Option(ice.MSG_USERNAME)).Result())
|
||||
}
|
||||
return m.Option(ice.MSG_SESSID)
|
||||
}
|
||||
func SessAuth(m *ice.Message, value ice.Any, arg ...string) *ice.Message {
|
||||
switch val := value.(type) {
|
||||
case []string:
|
||||
value = kit.Dict(USERNICK, kit.Select("", val, 0), USERNAME, kit.Select("", val, 1), USERROLE, kit.Select("", val, 2))
|
||||
}
|
||||
return m.Auth(
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, kit.Format(kit.Value(value, USERROLE))),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, kit.Format(kit.Value(value, USERNAME))),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, kit.Format(kit.Value(value, USERNICK))),
|
||||
LANGUAGE, m.OptionDefault(ice.MSG_LANGUAGE, kit.Format(kit.Value(value, LANGUAGE))),
|
||||
AVATAR, m.Option(ice.MSG_AVATAR, kit.Format(kit.Value(value, AVATAR))),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, kit.Value(value, USERNICK)),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, kit.Value(value, USERNAME)),
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, kit.Value(value, USERROLE)),
|
||||
arg, logs.FileLineMeta(kit.Select(logs.FileLine(-1), m.Option("aaa.checker"))),
|
||||
)
|
||||
}
|
||||
func SessLogout(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(ice.MSG_SESSID), func(sessid string) { m.Cmd(SESS, mdb.REMOVE, mdb.HASH, sessid) })
|
||||
kit.If(m.Option(ice.MSG_SESSID) != "", func() { m.Cmd(SESS, mdb.REMOVE, mdb.HASH, m.Option(ice.MSG_SESSID)) })
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ func _totp_get(key string, per int64, num int) string {
|
||||
return kit.Format(kit.Format("%%0%dd", num), res%int64(math.Pow10(num)))
|
||||
}
|
||||
|
||||
const (
|
||||
TOKEN = "token"
|
||||
)
|
||||
const TOTP = "totp"
|
||||
|
||||
func init() {
|
||||
@ -43,7 +46,7 @@ func init() {
|
||||
SECRET = "secret"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TOTP: {Help: "令牌", Actions: ice.MergeActions(ice.Actions{
|
||||
TOTP: {Name: "totp name auto create", Help: "令牌", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name*=hi number*=6 period*=30 secret", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(SECRET) == "", func() { m.Option(SECRET, _totp_gen(kit.Int64(m.Option(PERIOD)))) })
|
||||
mdb.HashCreate(m, m.OptionSimple(mdb.NAME, NUMBER, PERIOD, SECRET))
|
||||
@ -58,9 +61,10 @@ func init() {
|
||||
if len(arg) > 0 {
|
||||
m.PushQRCode(mdb.SCAN, kit.Format(mdb.Config(m, mdb.LINK), value[mdb.NAME], value[SECRET]))
|
||||
m.Echo(m.Append(mdb.VALUE))
|
||||
} else {
|
||||
m.PushAction(mdb.REMOVE).StatusTimeCount()
|
||||
}
|
||||
})
|
||||
kit.If(len(arg) == 0, func() { m.PushAction(mdb.REMOVE).Action(mdb.CREATE, mdb.PRUNES) })
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -12,29 +11,17 @@ func _user_create(m *ice.Message, name string, arg ...string) {
|
||||
mdb.HashCreate(m, USERNAME, name, arg)
|
||||
gdb.Event(m, USER_CREATE, USER, name)
|
||||
}
|
||||
func _user_remove(m *ice.Message, name string, arg ...string) {
|
||||
gdb.Event(m, USER_REMOVE, m.OptionSimple(USERNAME, USERNICK))
|
||||
mdb.HashRemove(m, m.OptionSimple(USERNAME))
|
||||
}
|
||||
|
||||
const (
|
||||
BACKGROUND = "background"
|
||||
AVATAR_URL = "avatar_url"
|
||||
AVATAR = "avatar"
|
||||
GENDER = "gender"
|
||||
MOBILE = "mobile"
|
||||
PHONE = "phone"
|
||||
SECRET = "secret"
|
||||
THEME = "theme"
|
||||
|
||||
LANGUAGE = "language"
|
||||
LOCATION = "location"
|
||||
LONGITUDE = "longitude"
|
||||
LATITUDE = "latitude"
|
||||
COMPANY = "company"
|
||||
PROVINCE = "province"
|
||||
COUNTRY = "country"
|
||||
CITY = "city"
|
||||
CITY = "city"
|
||||
COUNTRY = "country"
|
||||
PROVINCE = "province"
|
||||
LANGUAGE = "language"
|
||||
)
|
||||
const (
|
||||
USERNICK = "usernick"
|
||||
@ -44,13 +31,12 @@ const (
|
||||
USERZONE = "userzone"
|
||||
|
||||
USER_CREATE = "user.create"
|
||||
USER_REMOVE = "user.remove"
|
||||
)
|
||||
const USER = "user"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
USER: {Help: "用户", Icon: "Contacts.png", Actions: ice.MergeActions(ice.Actions{
|
||||
USER: {Name: "user username auto create", Help: "用户", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case USERNICK:
|
||||
@ -58,55 +44,44 @@ func init() {
|
||||
case USERNAME:
|
||||
m.Push(arg[0], m.Option(ice.MSG_USERNAME))
|
||||
}
|
||||
if arg[0] == USERROLE {
|
||||
m.Option(ice.TABLE_CHECKBOX, ice.TRUE)
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create userrole=void,tech username* usernick language userzone email avatar", Hand: func(m *ice.Message, arg ...string) {
|
||||
_user_create(m, m.Option(USERNAME), m.OptionSimple(USERROLE, USERNICK, LANGUAGE, AVATAR, BACKGROUND, USERZONE, EMAIL)...)
|
||||
mdb.CREATE: {Name: "create usernick username* userrole=void,tech userzone background", Hand: func(m *ice.Message, arg ...string) {
|
||||
_user_create(m, m.Option(USERNAME), m.OptionSimple(USERNICK, USERROLE, USERZONE, BACKGROUND)...)
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { _user_remove(m, m.Option(USERNAME)) }},
|
||||
}, mdb.ImportantHashAction(mdb.SHORT, USERNAME, mdb.FIELD, "time,userrole,username,usernick,language,avatar,background,userzone", html.CHECKBOX, ice.TRUE))},
|
||||
}, mdb.ImportantHashAction(mdb.SHORT, USERNAME, mdb.FIELD, "time,usernick,username,userrole,userzone"))},
|
||||
})
|
||||
}
|
||||
|
||||
func UserInfo(m *ice.Message, name ice.Any, key, meta string) (value string) {
|
||||
if m.Cmd(USER, kit.Select(m.Option(ice.MSG_USERNAME), name), func(val ice.Maps) { value = val[key] }).Length() == 0 || value == "" {
|
||||
if m.Cmd(USER, name, func(val ice.Maps) { value = val[key] }).Length() == 0 && kit.Format(name) == m.Option(ice.MSG_USERNAME) {
|
||||
return m.Option(meta)
|
||||
}
|
||||
return
|
||||
}
|
||||
func UserRole(m *ice.Message, username ice.Any) (role string) {
|
||||
if username == "" {
|
||||
return VOID
|
||||
} else if role = VOID; username == ice.Info.Username {
|
||||
return ROOT
|
||||
} else {
|
||||
return UserInfo(m, username, USERROLE, ice.MSG_USERROLE)
|
||||
}
|
||||
}
|
||||
func UserNick(m *ice.Message, username ice.Any) (nick string) {
|
||||
return UserInfo(m, username, USERNICK, ice.MSG_USERNICK)
|
||||
}
|
||||
func UserLang(m *ice.Message, username ice.Any) (nick string) {
|
||||
return UserInfo(m, username, LANGUAGE, ice.MSG_LANGUAGE)
|
||||
func UserRole(m *ice.Message, username ice.Any) (role string) {
|
||||
if username == "" {
|
||||
return VOID
|
||||
}
|
||||
if role = VOID; username == ice.Info.Username {
|
||||
return ROOT
|
||||
}
|
||||
return UserInfo(m, username, USERROLE, ice.MSG_USERROLE)
|
||||
}
|
||||
func UserZone(m *ice.Message, username ice.Any) (zone string) {
|
||||
return UserInfo(m, username, USERZONE, ice.MSG_USERZONE)
|
||||
}
|
||||
func UserEmail(m *ice.Message, username ice.Any) (nick string) {
|
||||
return UserInfo(m, username, EMAIL, EMAIL)
|
||||
}
|
||||
func UserRoot(m *ice.Message, arg ...string) *ice.Message {
|
||||
userrole := kit.Select(TECH, arg, 0)
|
||||
userzone := kit.Select("", arg, 3)
|
||||
userrole := kit.Select(ROOT, arg, 2)
|
||||
username := kit.Select(ice.Info.Username, arg, 1)
|
||||
usernick := kit.Select(UserNick(m, username), arg, 2)
|
||||
language := kit.Select(UserLang(m, username), arg, 3)
|
||||
userzone := kit.Select(ice.OPS, arg, 4)
|
||||
email := kit.Select(UserEmail(m, username), arg, 5)
|
||||
usernick := kit.Select(UserNick(m, username), arg, 0)
|
||||
background := kit.Select("usr/icons/background.jpg", UserInfo(m, username, BACKGROUND, ""))
|
||||
if len(arg) > 0 {
|
||||
kit.If(username != ROOT, func() { ice.Info.Username = username })
|
||||
m.Cmd(USER, mdb.CREATE, userrole, username, usernick, language, userzone, email)
|
||||
ice.Info.Username = username
|
||||
m.Cmd(USER, mdb.CREATE, usernick, username, userrole, userzone, background)
|
||||
}
|
||||
return SessAuth(m, kit.Dict(USERROLE, userrole, USERNAME, username, USERNICK, usernick))
|
||||
return SessAuth(m, kit.Dict(USERNICK, usernick, USERNAME, username, USERROLE, userrole))
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package base
|
||||
package shy
|
||||
|
||||
import (
|
||||
_ "shylinux.com/x/icebergs/base/aaa"
|
||||
|
5
base/base.shy
Normal file
5
base/base.shy
Normal file
@ -0,0 +1,5 @@
|
||||
label `
|
||||
ctx mdb web aaa
|
||||
lex yac ssh gdb
|
||||
tcp nfs cli log
|
||||
`
|
@ -1,14 +1,9 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const CLI = "cli"
|
||||
|
||||
var Index = &ice.Context{Name: CLI, Help: "命令模块"}
|
||||
|
||||
func Prefix(arg ...string) string { return kit.Keys(CLI, arg) }
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, FOREVER, MIRRORS, QRCODE, SUDO) }
|
||||
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, FOREVER, MIRRORS, QRCODE) }
|
||||
|
@ -28,28 +28,18 @@ var _color_map = map[string]color.Color{
|
||||
SILVER: color.RGBA{0xC0, 0xC0, 0xC0, _DARK},
|
||||
}
|
||||
|
||||
var _color_list = map[string]string{
|
||||
"navy": "#000080",
|
||||
"aliceblue": "#f0f8ff",
|
||||
"firebrick": "#b22222",
|
||||
}
|
||||
|
||||
func _parse_color(str string) color.Color {
|
||||
if str == RANDOM {
|
||||
list := kit.SortedKey(_color_map)
|
||||
str = list[rand.Intn(len(list))]
|
||||
}
|
||||
str = kit.Select(str, _color_list[str])
|
||||
if strings.HasPrefix(str, "#") {
|
||||
kit.If(len(str) == 7, func() { str += "ff" })
|
||||
if u, e := strconv.ParseUint(str[1:], 16, 64); e == nil {
|
||||
return color.RGBA{uint8((u & 0xFF000000) >> 24), uint8((u & 0x00FF0000) >> 16), uint8((u & 0x0000FF00) >> 8), uint8((u & 0x000000FF) >> 0)}
|
||||
}
|
||||
}
|
||||
if color, ok := _color_map[str]; ok {
|
||||
return color
|
||||
}
|
||||
return _color_map[WHITE]
|
||||
return _color_map[str]
|
||||
}
|
||||
func _parse_cli_color(str string) string {
|
||||
res := 0
|
||||
@ -75,9 +65,7 @@ const (
|
||||
PURPLE = "purple"
|
||||
YELLOW = "yellow"
|
||||
RANDOM = "random"
|
||||
TRANS = "#0000"
|
||||
LIGHT = "light"
|
||||
DARK = "dark"
|
||||
GLASS = "#0000"
|
||||
)
|
||||
|
||||
func Color(m *ice.Message, c string, str ice.Any) string {
|
||||
|
@ -1,11 +1,9 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
@ -13,7 +11,6 @@ import (
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -21,8 +18,6 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok {
|
||||
cmd.Stdin = r
|
||||
}
|
||||
err := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
|
||||
cmd.Stderr = err
|
||||
if w := _system_out(m, CMD_OUTPUT); w != nil {
|
||||
cmd.Stdout, cmd.Stderr = w, w
|
||||
}
|
||||
@ -30,20 +25,21 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
cmd.Stderr = w
|
||||
}
|
||||
h := mdb.HashCreate(m.Spawn(), STATUS, START,
|
||||
ice.CMD, strings.TrimPrefix(strings.TrimPrefix(kit.JoinWord(cmd.Args...), kit.Path("")+nfs.PS), cmd.Dir+nfs.PS), DIR, cmd.Dir, ENV, kit.Select("", cmd.Env),
|
||||
ice.CMD, kit.Join(cmd.Args, lex.SP), DIR, cmd.Dir, ENV, kit.Select("", cmd.Env),
|
||||
m.OptionSimple(CMD_INPUT, CMD_OUTPUT, CMD_ERRPUT, mdb.CACHE_CLEAR_ONEXIT),
|
||||
)
|
||||
if e := cmd.Start(); m.WarnNotValid(e, cmd.Args, err.String()) {
|
||||
if e := cmd.Start(); m.Warn(e, ice.ErrNotStart, cmd.Args) {
|
||||
mdb.HashModify(m, h, STATUS, ERROR, ERROR, e)
|
||||
return
|
||||
}
|
||||
mdb.HashSelectUpdate(m, h, func(value ice.Map) { value[PID] = cmd.Process.Pid })
|
||||
m.Echo("%d", cmd.Process.Pid).Go(func() {
|
||||
if e := cmd.Wait(); !m.WarnNotValid(e, cmd.Args, err.String()) && cmd.ProcessState != nil && cmd.ProcessState.Success() {
|
||||
m.Echo("%d", cmd.Process.Pid)
|
||||
m.Go(func() {
|
||||
if e := cmd.Wait(); !m.Warn(e, ice.ErrNotStart, cmd.Args) && cmd.ProcessState != nil && cmd.ProcessState.Success() {
|
||||
mdb.HashModify(m, mdb.HASH, h, STATUS, STOP)
|
||||
m.Cost(CODE, "0", ctx.ARGS, cmd.Args)
|
||||
} else {
|
||||
mdb.HashSelectUpdate(m, h, func(value ice.Map) { value[STATUS], value[ERROR] = ERROR, e })
|
||||
mdb.HashSelectUpdate(m, h, func(value ice.Map) { kit.If(value[STATUS] == START, func() { value[STATUS], value[ERROR] = ERROR, e }) })
|
||||
}
|
||||
switch status := mdb.HashSelectField(m.Sleep300ms(), h, STATUS); cb := m.OptionCB("").(type) {
|
||||
case func(string) bool:
|
||||
@ -56,18 +52,18 @@ func _daemon_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
kit.For(kit.Simple(CMD_INPUT, CMD_OUTPUT, CMD_ERRPUT), func(p string) { nfs.Close(m, m.Optionv(p)) })
|
||||
for _, p := range kit.Simple(CMD_INPUT, CMD_OUTPUT, CMD_ERRPUT) {
|
||||
nfs.Close(m, m.Optionv(p))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const (
|
||||
DIR = "dir"
|
||||
ENV = "env"
|
||||
API = "api"
|
||||
MOD = "mod"
|
||||
PWD = "pwd"
|
||||
PID = "pid"
|
||||
PPID = "ppid"
|
||||
DIR = "dir"
|
||||
ENV = "env"
|
||||
API = "api"
|
||||
PID = "pid"
|
||||
PWD = "pwd"
|
||||
)
|
||||
const (
|
||||
BUILD = "build"
|
||||
@ -77,34 +73,26 @@ const (
|
||||
BENCH = "bench"
|
||||
PPROF = "pprof"
|
||||
|
||||
TIMEOUT = "timeout"
|
||||
STATUS = "status"
|
||||
ERROR = "error"
|
||||
CLEAR = "clear"
|
||||
STASH = "stash"
|
||||
DELAY = "delay"
|
||||
RECORD = "record"
|
||||
RELOAD = "reload"
|
||||
REBOOT = "reboot"
|
||||
RESTART = "restart"
|
||||
INTERVAL = "interval"
|
||||
OPTS = "opts"
|
||||
ARGS = "args"
|
||||
LOGS = "logs"
|
||||
TIMEOUT = "timeout"
|
||||
STATUS = "status"
|
||||
ERROR = "error"
|
||||
CLEAR = "clear"
|
||||
RELOAD = "reload"
|
||||
RESTART = "restart"
|
||||
|
||||
DELAY = "delay"
|
||||
BEGIN = "begin"
|
||||
END = "end"
|
||||
START = "start"
|
||||
STOP = "stop"
|
||||
OPEN = "open"
|
||||
CLOSE = "close"
|
||||
STOP = "stop"
|
||||
END = "end"
|
||||
|
||||
PLAY = "play"
|
||||
MAIN = "main"
|
||||
CODE = "code"
|
||||
COST = "cost"
|
||||
FROM = "from"
|
||||
BACK = "back"
|
||||
FROM = "from"
|
||||
)
|
||||
|
||||
const DAEMON = "daemon"
|
||||
@ -112,29 +100,25 @@ const DAEMON = "daemon"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DAEMON: {Name: "daemon hash auto", Help: "守护进程", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashPrunesValue(m, mdb.CACHE_CLEAR_ONEXIT, ice.TRUE)
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { mdb.HashPrunesValue(m, mdb.CACHE_CLEAR_ONEXIT, ice.TRUE) }},
|
||||
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))...))
|
||||
}},
|
||||
RESTART: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("", STOP).Sleep3s().Cmdy("", START)
|
||||
}},
|
||||
RESTART: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("", STOP).Sleep3s().Cmdy("", START) }},
|
||||
STOP: {Hand: func(m *ice.Message, arg ...string) {
|
||||
h, pid := m.Option(mdb.HASH), m.Option(PID)
|
||||
mdb.HashSelects(m.Spawn(), h).Table(func(value ice.Maps) {
|
||||
mdb.HashSelects(m, h).Table(func(value ice.Maps) {
|
||||
if h == "" && value[PID] != pid {
|
||||
return
|
||||
}
|
||||
mdb.HashModify(m, mdb.HASH, kit.Select(h, value[mdb.HASH]), STATUS, STOP)
|
||||
kit.If(value[PID], func() { m.Cmd(gdb.SIGNAL, gdb.KILL, value[PID]) })
|
||||
m.Cmd(gdb.SIGNAL, gdb.KILL, value[PID])
|
||||
})
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
h, pid := m.Option(mdb.HASH), m.Option(PID)
|
||||
mdb.HashSelects(m.Spawn(), h).Table(func(value ice.Maps) {
|
||||
mdb.HashSelects(m, h).Table(func(value ice.Maps) {
|
||||
if h == "" && value[PID] != pid {
|
||||
return
|
||||
}
|
||||
@ -152,53 +136,25 @@ func init() {
|
||||
})
|
||||
kit.If(len(arg) == 0, func() { m.Action(START, mdb.PRUNES) })
|
||||
if len(arg) > 0 && m.Length() == 0 {
|
||||
if runtime.GOOS == WINDOWS {
|
||||
_daemon_exec(m, _system_cmd(m, arg...))
|
||||
} else {
|
||||
_daemon_exec(m, _system_cmd(m, arg...))
|
||||
// _daemon_exec(m, _system_cmd(m, kit.Simple(kit.Split(arg[0]), arg[1:])...))
|
||||
}
|
||||
_daemon_exec(m, _system_cmd(m, kit.Simple(kit.Split(arg[0]), arg[1:])...))
|
||||
kit.If(IsSuccess(m) && m.Append(CMD_ERR) == "", func() { m.SetAppend() })
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func Opens(m *ice.Message, arg ...string) {
|
||||
if !tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
|
||||
// return
|
||||
} else if len(arg) == 0 || arg[0] == "" {
|
||||
// return
|
||||
}
|
||||
switch runtime.GOOS {
|
||||
case DARWIN:
|
||||
if kit.Ext(arg[0]) == "app" {
|
||||
m.Cmdy(SYSTEM, OPEN, "-a", arg[0])
|
||||
m.Cmd(SYSTEM, OPEN, "-a", arg[0])
|
||||
} else {
|
||||
m.Cmdy(SYSTEM, OPEN, arg[0])
|
||||
m.Cmd(SYSTEM, OPEN, arg[0])
|
||||
}
|
||||
case WINDOWS:
|
||||
if kit.Ext(arg[0]) == "exe" {
|
||||
m.Cmdy(SYSTEM, arg[0])
|
||||
m.Cmd(SYSTEM, arg[0])
|
||||
} else {
|
||||
m.Cmdy(SYSTEM, "explorer", arg[0])
|
||||
m.Cmd(SYSTEM, "explorer", arg[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
func OpenCmds(m *ice.Message, arg ...string) *ice.Message {
|
||||
if !tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
|
||||
return m
|
||||
} else if len(arg) == 0 || arg[0] == "" {
|
||||
return m
|
||||
}
|
||||
TellApp(m, "Terminal", kit.Format(`do script %q`, strings.Join(arg, "; ")), "activate")
|
||||
return m
|
||||
}
|
||||
func TellApp(m *ice.Message, app string, arg ...string) {
|
||||
OSAScript(m, kit.Format(`
|
||||
tell application "%s"
|
||||
%s
|
||||
end tell
|
||||
`, app, strings.Join(arg, lex.NL)))
|
||||
}
|
||||
func OSAScript(m *ice.Message, arg ...string) { m.Cmd(SYSTEM, "osascript", "-e", arg) }
|
||||
|
@ -14,12 +14,26 @@ import (
|
||||
)
|
||||
|
||||
func _path_sep() string { return kit.Select(nfs.DF, ";", strings.Contains(os.Getenv(PATH), ";")) }
|
||||
func BinPath(arg ...string) string {
|
||||
list := []string{}
|
||||
push := func(p string) {
|
||||
kit.If(kit.IndexOf(list, p) == -1, func() { list = append(list, kit.ReplaceAll(p, "\\", nfs.PS)) })
|
||||
}
|
||||
kit.For(arg, func(p string) {
|
||||
list = append(list, kit.Path(p, ice.BIN), kit.Path(p, ice.USR_PUBLISH), kit.Path(p, ice.USR_LOCAL_BIN), kit.Path(p, ice.USR_LOCAL_GO_BIN))
|
||||
kit.For(kit.Reverse(strings.Split(ice.Pulse.Cmdx(nfs.CAT, kit.Path(p, ice.ETC_PATH)), lex.NL)), func(l string) {
|
||||
kit.If(strings.TrimSpace(l) != "" && !strings.HasPrefix(strings.TrimSpace(l), "#"), func() { push(kit.Path(p, l)) })
|
||||
})
|
||||
})
|
||||
kit.For(strings.Split(kit.Env(PATH), _path_sep()), func(p string) { push(p) })
|
||||
return kit.Join(list, _path_sep())
|
||||
}
|
||||
|
||||
const FOREVER = "forever"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FOREVER: {Help: "启动", Actions: ice.Actions{
|
||||
FOREVER: {Name: "forever auto", Help: "启动", Actions: ice.Actions{
|
||||
START: {Hand: func(m *ice.Message, arg ...string) {
|
||||
env := []string{PATH, BinPath(""), HOME, kit.Select(kit.Path(""), os.Getenv(HOME))}
|
||||
kit.For(ENV_LIST, func(k string) { kit.If(kit.Env(k) != "", func() { env = append(env, k, kit.Env(k)) }) })
|
||||
@ -29,7 +43,7 @@ func init() {
|
||||
}
|
||||
})
|
||||
m.Options(CMD_ENV, env, CMD_INPUT, os.Stdin, CMD_OUTPUT, os.Stdout, CMD_ERRPUT, os.Stderr)
|
||||
kit.If(kit.Select("/dev/null", kit.Env(CTX_LOG)), func(p string) { m.Optionv(CMD_ERRPUT, p) })
|
||||
kit.If(kit.Env(CTX_LOG), func(p string) { m.Optionv(CMD_ERRPUT, p) })
|
||||
m.Cmd(FOREVER, STOP)
|
||||
if bin := kit.Select(os.Args[0], ice.BIN_ICE_BIN, nfs.Exists(m, ice.BIN_ICE_BIN)); len(arg) > 0 && arg[0] == ice.SPACE {
|
||||
m.Cmdy(FOREVER, bin, ice.SPACE, START, ice.DEV, ice.OPS, arg[1:])
|
||||
@ -56,18 +70,3 @@ func init() {
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func BinPath(arg ...string) string {
|
||||
list := []string{}
|
||||
push := func(p string) {
|
||||
kit.If(kit.IndexOf(list, p) == -1, func() { list = append(list, kit.ReplaceAll(p, "\\", nfs.PS)) })
|
||||
}
|
||||
kit.For(arg, func(p string) {
|
||||
list = append(list, kit.Path(p, ice.BIN), kit.Path(p, ice.USR_PUBLISH), kit.Path(p, ice.USR_LOCAL_BIN), kit.Path(p, ice.USR_LOCAL_GO_BIN))
|
||||
kit.For(kit.Reverse(EtcPath(ice.Pulse)), func(l string) {
|
||||
kit.If(strings.TrimSpace(l) != "" && !strings.HasPrefix(strings.TrimSpace(l), "#"), func() { push(kit.Path(p, l)) })
|
||||
})
|
||||
})
|
||||
kit.For(strings.Split(kit.Env(PATH), _path_sep()), func(p string) { push(p) })
|
||||
return kit.Join(list, _path_sep())
|
||||
}
|
||||
|
@ -14,109 +14,65 @@ import (
|
||||
|
||||
const (
|
||||
CMD = "cmd"
|
||||
ADD = "add"
|
||||
OSID = "osid"
|
||||
REPOS = "repos"
|
||||
UBUNTU = "ubuntu"
|
||||
CENTOS = "centos"
|
||||
ALPINE = "alpine"
|
||||
BUSYBOX = "busybox"
|
||||
RELEASE = "release"
|
||||
RHEL = "rhel"
|
||||
|
||||
ETC_OS_RELEASE = "/etc/os-release"
|
||||
ETC_APK_REPOS = "/etc/apk/repositories"
|
||||
)
|
||||
|
||||
const MIRRORS = "mirrors"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
MIRRORS: {Help: "软件镜像", Actions: ice.MergeActions(ice.Actions{
|
||||
MIRRORS: {Name: "mirrors cli auto", Help: "软件镜像", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INSERT: {Name: "insert cli* osid cmd*"},
|
||||
CMD: {Name: "cmd cli osid", Hand: func(m *ice.Message, arg ...string) {
|
||||
osid := kit.Select(mdb.Conf(m, RUNTIME, kit.Keys(HOST, OSID)), m.Option(OSID))
|
||||
mdb.ZoneSelectCB(m, m.Option(CLI), func(value ice.Map) {
|
||||
kit.If(strings.Contains(osid, kit.Format(value[OSID])), func() {
|
||||
m.Cmdy(kit.Split(kit.Format(value[CMD])))
|
||||
})
|
||||
kit.If(strings.Contains(osid, kit.Format(value[OSID])), func() { m.Cmdy(kit.Split(kit.Format(value[CMD]))) })
|
||||
})
|
||||
}},
|
||||
ADD: {Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.Info.PushStream(m)
|
||||
mdb.ZoneSelect(m, m.Option(CLI)).Table(func(value ice.Maps) {
|
||||
m.ToastProcess()
|
||||
if msg := m.Cmd(kit.Split(value[CMD])); IsSuccess(msg) {
|
||||
m.ToastSuccess()
|
||||
} else {
|
||||
m.ToastFailure()
|
||||
}
|
||||
})
|
||||
}},
|
||||
REPOS: {Name: "repos proxy=mirrors.tencent.com", Help: "镜像", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch {
|
||||
case strings.Contains(_release, ALPINE):
|
||||
defer m.PushStream().ToastProcess()()
|
||||
kit.If(m.Option("proxy"), func(p string) {
|
||||
m.Cmd(nfs.SAVE, ETC_APK_REPOS, strings.ReplaceAll(m.Cmdx(nfs.CAT, ETC_APK_REPOS), "dl-cdn.alpinelinux.org", p))
|
||||
})
|
||||
m.Cmdy(SYSTEM, "apk", "update")
|
||||
}
|
||||
}},
|
||||
ALPINE: {Name: "alpine cli cmd", Hand: func(m *ice.Message, arg ...string) { IsAlpine(m, arg...) }},
|
||||
}, mdb.ZoneAction(mdb.SHORT, CLI, mdb.FIELDS, "time,id,osid,cmd"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.Table(func(value ice.Maps) {
|
||||
p := SystemFind(m, value[CLI])
|
||||
if m.Push(nfs.PATH, p); p == "" {
|
||||
m.PushButton(ADD)
|
||||
} else {
|
||||
m.PushButton("")
|
||||
}
|
||||
}).Action(REPOS).StatusTimeCount("release", _release)
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(_release, ALPINE):
|
||||
m.Cmdy(nfs.CAT, ETC_APK_REPOS)
|
||||
}
|
||||
// m.EchoScript(kit.Format("cd %s; %s", kit.Path(""), kit.JoinCmds(kit.Simple(kit.Path(os.Args[0]), os.Args[1:])...)))
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, CLI, mdb.FIELD, "time,id,osid,cmd"), mdb.ClearOnExitHashAction())},
|
||||
})
|
||||
}
|
||||
|
||||
var _release = ""
|
||||
|
||||
func release(m *ice.Message) string {
|
||||
list := []string{runtime.GOOS}
|
||||
if list[0] != LINUX || !nfs.Exists(m, ETC_OS_RELEASE) {
|
||||
return list[0]
|
||||
osid := runtime.GOOS
|
||||
if osid != LINUX {
|
||||
return osid
|
||||
}
|
||||
m.Cmd(nfs.CAT, ETC_OS_RELEASE, kit.Dict(ice.MSG_USERROLE, aaa.ROOT), func(text string, _ int) string {
|
||||
m.Option(nfs.CAT_CONTENT, _release)
|
||||
_release = m.Cmdx(nfs.CAT, "/etc/os-release", kit.Dict(ice.MSG_USERROLE, aaa.ROOT), func(text string, _ int) string {
|
||||
if ls := kit.Split(text, mdb.EQ); len(ls) > 1 {
|
||||
kit.Switch(ls[0], []string{"ID", "ID_LIKE"}, func() { list = append(list, strings.TrimSpace(ls[1])) })
|
||||
kit.Switch(ls[0], []string{"ID", "ID_LIKE"}, func() { osid = strings.TrimSpace(ls[1] + lex.SP + osid) })
|
||||
}
|
||||
return text
|
||||
})
|
||||
_release = kit.JoinWord(list...)
|
||||
return _release
|
||||
return osid
|
||||
}
|
||||
func insert(m *ice.Message, sys, cmd string, arg ...string) bool {
|
||||
if !strings.Contains(_release, sys) {
|
||||
if !strings.Contains(release(m), sys) {
|
||||
return false
|
||||
}
|
||||
if len(arg) > 0 {
|
||||
m.GoSleep300ms(func() {
|
||||
m.Cmd(mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, sys, CMD, cmd+lex.SP+kit.Select(arg[0], arg, 1))
|
||||
})
|
||||
m.GoSleep("300ms", mdb.INSERT, kit.Keys(CLI, MIRRORS), "", mdb.ZONE, arg[0], OSID, sys, CMD, cmd+lex.SP+kit.Select(arg[0], arg, 1))
|
||||
}
|
||||
return true
|
||||
}
|
||||
func IsAlpine(m *ice.Message, arg ...string) bool {
|
||||
return insert(m, ALPINE, "system apk add", arg...)
|
||||
}
|
||||
func IsRedhat(m *ice.Message, arg ...string) bool {
|
||||
return insert(m, RHEL, "system yum install -y", arg...)
|
||||
func IsCentos(m *ice.Message, arg ...string) bool {
|
||||
return insert(m, CENTOS, "system yum install -y", arg...)
|
||||
}
|
||||
func IsUbuntu(m *ice.Message, arg ...string) bool {
|
||||
return insert(m, UBUNTU, "system apt get -y", arg...)
|
||||
}
|
||||
func IsSystem(m *ice.Message, arg ...string) bool {
|
||||
return IsAlpine(m, arg...) || IsRedhat(m, arg...)
|
||||
return IsAlpine(m, arg...) || IsCentos(m, arg...) || IsUbuntu(m, arg...)
|
||||
}
|
||||
|
@ -4,11 +4,9 @@ import (
|
||||
"encoding/base64"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
"shylinux.com/x/icebergs/misc/qrcode"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -37,7 +35,7 @@ func _qrcode_web(m *ice.Message, text string) string {
|
||||
sc.ForegroundColor = ParseColor(m.Option(FG))
|
||||
sc.BackgroundColor = ParseColor(m.Option(BG))
|
||||
if data, err := sc.PNG(kit.Int(m.Option(SIZE))); m.Assert(err) {
|
||||
m.Echo(`<img class="qrcode" src="data:image/png;base64,%s" title='%s'>`, base64.StdEncoding.EncodeToString(data), text)
|
||||
m.Echo(`<img src="data:image/png;base64,%s" title='%s'>`, base64.StdEncoding.EncodeToString(data), text)
|
||||
}
|
||||
return text
|
||||
}
|
||||
@ -49,38 +47,26 @@ const QRCODE = "qrcode"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
QRCODE: {Name: "qrcode text fg@key bg@key size auto", Help: "二维码", Icon: "Chess.png", Role: aaa.VOID, Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(mdb.TEXT, "文本", BG, "背景色", FG, "字体色")),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
QRCODE: {Name: "qrcode text fg@key bg@key size auto", Help: "二维码", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_QRCODE, func(m *ice.Message, args ...ice.Any) string {
|
||||
if m.IsMobileUA() {
|
||||
m.Option(SIZE, "280")
|
||||
}
|
||||
return m.Cmd(Prefix(QRCODE), kit.Simple(args...)).Result()
|
||||
return m.Cmd(QRCODE, kit.Simple(args...)).Result()
|
||||
})
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case FG, BG:
|
||||
m.Push(arg[0], kit.SortedKey(_color_map))
|
||||
m.Push(arg[0], BLACK, WHITE)
|
||||
}
|
||||
}},
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
dark := kit.IndexOf([]string{BLACK, "dark"}, m.Option(ice.MSG_THEME)) > -1
|
||||
m.Option(FG, kit.Select(kit.Select(BLACK, SILVER, dark), arg, 1))
|
||||
m.Option(BG, kit.Select(kit.Select(WHITE, BLACK, dark), arg, 2))
|
||||
if m.IsCliUA() {
|
||||
m.OptionDefault(FG, BLACK, BG, WHITE)
|
||||
_qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0))
|
||||
} else {
|
||||
// m.OptionDefault(SIZE, kit.Select("360", "280", m.IsMobileUA()))
|
||||
m.Option(FG, kit.Select(m.Option(ice.MSG_FG), arg, 1))
|
||||
m.Option(BG, kit.Select(m.Option(ice.MSG_BG), arg, 2))
|
||||
m.Option(SIZE, kit.Select(m.OptionDefault(SIZE, "320"), arg, 3))
|
||||
switch m.Option(ice.MSG_THEME) {
|
||||
case LIGHT, WHITE:
|
||||
m.OptionDefault(FG, BLACK, BG, WHITE)
|
||||
default:
|
||||
m.OptionDefault(FG, WHITE, BG, BLACK)
|
||||
}
|
||||
m.Option(SIZE, kit.Select(kit.Format(kit.Max(240, kit.Min(480, kit.Int(m.Option(ice.MSG_HEIGHT)), kit.Int(m.Option(ice.MSG_WIDTH))))), arg, 3))
|
||||
m.StatusTime(mdb.LINK, _qrcode_web(m, tcp.PublishLocalhost(m, kit.Select(m.Option(ice.MSG_USERWEB), arg, 0))))
|
||||
}
|
||||
}},
|
||||
|
39
base/cli/readelf.go
Normal file
39
base/cli/readelf.go
Normal file
@ -0,0 +1,39 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"debug/elf"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
"readelf": {Name: "readelf path=usr/publish/ice.linux.amd64 auto", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], nfs.PS) {
|
||||
m.Cmdy(nfs.DIR, arg)
|
||||
return
|
||||
}
|
||||
if f, e := nfs.OpenFile(m, arg[0]); !m.Warn(e) {
|
||||
defer f.Close()
|
||||
buf := make([]byte, 1024)
|
||||
n, e := f.Read(buf)
|
||||
if m.Warn(e) {
|
||||
return
|
||||
}
|
||||
kit.If(bytes.Equal(buf[:4], []byte{0x7f, 0x45, 0x4c, 0x46}), func() {
|
||||
f, _ := elf.Open(arg[0])
|
||||
m.Echo("%v", kit.Formats(f))
|
||||
})
|
||||
for i := 0; i < n; i++ {
|
||||
kit.If(i%16 == 0, func() { m.Push("addr", kit.Format("%04x", i)) })
|
||||
m.Push(kit.Format("%02x", i%16), kit.Format("%02x", buf[i]))
|
||||
}
|
||||
m.StatusTimeCount()
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
@ -10,16 +11,15 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _runtime_init(m *ice.Message) {
|
||||
count := kit.Int(m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT)))
|
||||
defer m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), count+1)
|
||||
kit.For(kit.UnMarshal(kit.Format(ice.Info.Make)), func(k string, v ice.Any) { m.Conf(RUNTIME, kit.Keys(MAKE, strings.ToLower(k)), v) })
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOARCH), runtime.GOARCH)
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, GOOS), runtime.GOOS)
|
||||
@ -28,80 +28,54 @@ func _runtime_init(m *ice.Message) {
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, PWD), kit.Path(""))
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, HOME), kit.HomePath(""))
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, MAXPROCS), runtime.GOMAXPROCS(0))
|
||||
ice.Info.System = m.Conf(RUNTIME, kit.Keys(HOST, OSID))
|
||||
kit.For(ENV_LIST, func(k string) { m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k)) })
|
||||
ice.Info.Lang = m.Conf(RUNTIME, kit.Keys(CONF, LANG))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME), kit.UserName())
|
||||
kit.For(ENV_LIST, func(k string) {
|
||||
m.Conf(RUNTIME, kit.Keys(CONF, k), kit.Env(k))
|
||||
kit.If(k == CTX_PID, func() { ice.Info.PidPath = kit.Env(k) })
|
||||
})
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), kit.Env("HOSTNAME"))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME), path.Base(kit.Path("")))
|
||||
if name, e := os.Hostname(); e == nil && name != "" {
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME), name)
|
||||
}
|
||||
ice.Info.Username = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME), path.Base(kit.Path("")))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME), kit.UserName())
|
||||
ice.Info.Hostname = m.Conf(RUNTIME, kit.Keys(BOOT, HOSTNAME))
|
||||
ice.Info.Pathname = m.Conf(RUNTIME, kit.Keys(BOOT, PATHNAME))
|
||||
kit.HashSeed = append(kit.HashSeed, ice.Info.Username)
|
||||
kit.HashSeed = append(kit.HashSeed, ice.Info.Hostname)
|
||||
kit.HashSeed = append(kit.HashSeed, ice.Info.Pathname)
|
||||
aaa.UserRoot(ice.Pulse, aaa.TECH, ice.Info.Make.Author, "", "", ice.DEV, ice.Info.Make.Email)
|
||||
aaa.UserRoot(ice.Pulse, aaa.TECH, ice.Info.Make.Username, "", "", ice.DEV, ice.Info.Make.Email)
|
||||
aaa.UserRoot(ice.Pulse, aaa.ROOT, ice.Info.Username)
|
||||
aaa.UserRoot(ice.Pulse, aaa.ROOT, aaa.ROOT)
|
||||
ice.Info.Time = m.Time()
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.TIME), ice.Info.Time)
|
||||
ice.Info.Username = m.Conf(RUNTIME, kit.Keys(BOOT, USERNAME))
|
||||
aaa.UserRoot(ice.Pulse, "", ice.Info.Username, aaa.ROOT, ice.OPS)
|
||||
aaa.UserRoot(ice.Pulse, "", ice.Info.Make.Username, aaa.TECH, ice.DEV)
|
||||
if runtime.GOARCH != MIPSLE {
|
||||
msg := m.Cmd(nfs.DIR, _system_find(m, os.Args[0]), "time,path,size,hash")
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.TIME), msg.Append(mdb.TIME))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.HASH), msg.Append(mdb.HASH))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, nfs.SIZE), msg.Append(nfs.SIZE))
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, ice.BIN), msg.Append(nfs.PATH))
|
||||
ice.Info.Hash = msg.Append(mdb.HASH)
|
||||
ice.Info.Size = msg.Append(nfs.SIZE)
|
||||
}
|
||||
nfs.Exists(m, "/proc/meminfo", func(p string) {
|
||||
kit.For(kit.SplitLine(m.Cmdx(nfs.CAT, p)), func(p string) {
|
||||
switch ls := kit.Split(p, ": "); kit.Select("", ls, 0) {
|
||||
case "MemTotal", "MemFree", "MemAvailable":
|
||||
m.Conf(RUNTIME, kit.Keys(HOST, ls[0]), kit.FmtSize(kit.Int(ls[1])*1024))
|
||||
}
|
||||
})
|
||||
})
|
||||
m.Conf(m.PrefixKey(), mdb.META, "")
|
||||
m.Conf(RUNTIME, kit.Keys(BOOT, mdb.COUNT), count+1)
|
||||
m.Conf(RUNTIME, mdb.META, "")
|
||||
m.Conf(RUNTIME, mdb.HASH, "")
|
||||
}
|
||||
func _runtime_hostinfo(m *ice.Message) {
|
||||
m.Push("time", ice.Info.Make.Time)
|
||||
m.Push("nCPU", runtime.NumCPU())
|
||||
for i, ls := range strings.Split(m.Cmdx(nfs.CAT, "/proc/meminfo"), lex.NL) {
|
||||
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"), mdb.FS)[0])
|
||||
m.Push("GOMAXPROCS", runtime.GOMAXPROCS(0))
|
||||
m.Push("NumGoroutine", runtime.NumGoroutine())
|
||||
var stats runtime.MemStats
|
||||
runtime.ReadMemStats(&stats)
|
||||
m.Push("Sys", kit.FmtSize(stats.Sys))
|
||||
m.Push("Alloc", kit.FmtSize(stats.Alloc))
|
||||
m.Push("TotalAlloc", kit.FmtSize(stats.TotalAlloc))
|
||||
m.Push("StackSys", kit.FmtSize(stats.StackSys))
|
||||
m.Push("StackInuse", kit.FmtSize(stats.StackInuse))
|
||||
m.Push("HeapSys", kit.FmtSize(stats.HeapSys))
|
||||
m.Push("HeapInuse", kit.FmtSize(stats.HeapInuse))
|
||||
m.Push("HeapIdle", kit.FmtSize(stats.HeapIdle))
|
||||
m.Push("HeapReleased", kit.FmtSize(stats.HeapReleased))
|
||||
m.Push("Sys", kit.FmtSize(int64(stats.Sys)))
|
||||
m.Push("Alloc", kit.FmtSize(int64(stats.Alloc)))
|
||||
m.Push("Objects", stats.HeapObjects)
|
||||
m.Push("NumGC", stats.NumGC)
|
||||
m.Push("LastGC", time.Unix(int64(stats.LastGC)/int64(time.Second), int64(stats.LastGC)%int64(time.Second)))
|
||||
m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), mdb.FS)[0])
|
||||
if runtime.GOOS == LINUX {
|
||||
for i, ls := range strings.Split(m.Cmdx(nfs.CAT, "/proc/meminfo"), lex.NL) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m.Push("MemAvailable", "")
|
||||
m.Push("MemTotal", "")
|
||||
m.Push("MemFree", "")
|
||||
}
|
||||
}
|
||||
func _runtime_diskinfo(m *ice.Message) {
|
||||
m.Spawn().Split(kit.Replace(m.Cmdx(SYSTEM, "df", "-h"), "Mounted on", "Mountedon"), "", lex.SP, lex.NL).Table(func(value ice.Maps, index int, head []string) {
|
||||
m.Spawn().Split(kit.Replace(m.Cmdx(SYSTEM, "df", "-h"), "Mounted on", "Mountedon"), "", lex.SP, lex.NL).Table(func(index int, value ice.Maps, head []string) {
|
||||
kit.If(strings.HasPrefix(value["Filesystem"], "/dev"), func() { m.Push("", value, head) })
|
||||
})
|
||||
m.RenameAppend("%iused", "piused", "Use%", "Usep")
|
||||
@ -125,18 +99,8 @@ const (
|
||||
MIPSLE = "mipsle"
|
||||
GOOS = "GOOS"
|
||||
LINUX = "linux"
|
||||
MACOS = "macos"
|
||||
DARWIN = "darwin"
|
||||
WINDOWS = "windows"
|
||||
|
||||
COMMIT_TIME = "commitTime"
|
||||
COMPILE_TIME = "compileTime"
|
||||
BOOT_TIME = "bootTime"
|
||||
|
||||
KERNEL = "kernel"
|
||||
ARCH = "arch"
|
||||
CPU = "cpu"
|
||||
OS = "os"
|
||||
)
|
||||
const (
|
||||
PATH = "PATH"
|
||||
@ -144,41 +108,35 @@ const (
|
||||
USER = "USER"
|
||||
TERM = "TERM"
|
||||
SHELL = "SHELL"
|
||||
LANG = "LANG"
|
||||
TZ = "TZ"
|
||||
)
|
||||
const (
|
||||
CTX_SHY = "ctx_shy"
|
||||
CTX_DEV = "ctx_dev"
|
||||
CTX_DEV_IP = "ctx_dev_ip"
|
||||
CTX_OPS = "ctx_ops"
|
||||
CTX_REPOS = "ctx_repos"
|
||||
CTX_NAME = "ctx_name"
|
||||
CTX_DEMO = "ctx_demo"
|
||||
CTX_MAIL = "ctx_mail"
|
||||
CTX_ROOT = "ctx_root"
|
||||
CTX_DOMAIN = "ctx_domain"
|
||||
|
||||
CTX_SHY = "ctx_shy"
|
||||
CTX_COM = "ctx_com"
|
||||
CTX_DEV = "ctx_dev"
|
||||
CTX_OPS = "ctx_ops"
|
||||
CTX_ARG = "ctx_arg"
|
||||
CTX_PID = "ctx_pid"
|
||||
CTX_LOG = "ctx_log"
|
||||
CTX_POD = "ctx_pod"
|
||||
CTX_ENV = "ctx_env"
|
||||
CTX_CLI = "ctx_cli"
|
||||
CTX_ARG = "ctx_arg"
|
||||
|
||||
CTX_DAEMON = "ctx_daemon"
|
||||
)
|
||||
|
||||
var ENV_LIST = []string{TZ, LANG, TERM, SHELL, CTX_SHY, CTX_DEV, CTX_OPS, CTX_DEMO, CTX_MAIL, CTX_ROOT, CTX_PID}
|
||||
var ENV_LIST = []string{TERM, SHELL, CTX_SHY, CTX_COM, CTX_DEV, CTX_OPS, CTX_ARG, CTX_PID, CTX_DAEMON}
|
||||
|
||||
const (
|
||||
USERNAME = "username"
|
||||
HOSTNAME = "hostname"
|
||||
PATHNAME = "pathname"
|
||||
USERNAME = "username"
|
||||
)
|
||||
const (
|
||||
IFCONFIG = "ifconfig"
|
||||
DISKINFO = "diskinfo"
|
||||
HOSTINFO = "hostinfo"
|
||||
USERINFO = "userinfo"
|
||||
PROCINFO = "procinfo"
|
||||
PROCKILL = "prockill"
|
||||
BOOTINFO = "bootinfo"
|
||||
MAXPROCS = "maxprocs"
|
||||
)
|
||||
@ -186,9 +144,9 @@ const RUNTIME = "runtime"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,bootinfo,role,api,cli,cmd,mod,env,path,chain auto upgrade reboot lock", Icon: "Infomation.png", Help: "环境", Actions: ice.MergeActions(ice.Actions{
|
||||
RUNTIME: {Name: "runtime info=bootinfo,ifconfig,diskinfo,hostinfo,userinfo,procinfo,bootinfo,api,cli,cmd,mod,env,path,chain,routine auto", Help: "运行环境", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _runtime_init(m) }},
|
||||
IFCONFIG: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(tcp.HOST) }},
|
||||
IFCONFIG: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("tcp.host") }},
|
||||
DISKINFO: {Hand: func(m *ice.Message, arg ...string) { _runtime_diskinfo(m) }},
|
||||
HOSTINFO: {Hand: func(m *ice.Message, arg ...string) { _runtime_hostinfo(m) }},
|
||||
HOSTNAME: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -197,72 +155,81 @@ func init() {
|
||||
}
|
||||
m.Echo(ice.Info.Hostname)
|
||||
}},
|
||||
USERINFO: {Hand: func(m *ice.Message, arg ...string) { m.Split(m.Cmdx(SYSTEM, "who"), "user term time") }},
|
||||
PROCINFO: {Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd("", HOSTINFO)
|
||||
m.Split(m.Cmdx(SYSTEM, "ps", "u")).PushAction(PROCKILL).Sort("COMMAND")
|
||||
m.StatusTimeCount("nCPU", msg.Append("nCPU"), "MemTotal", msg.Append("MemTotal"), "MemFree", msg.Append("MemFree"))
|
||||
}},
|
||||
PROCKILL: {Help: "结束进程", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(gdb.SIGNAL, gdb.STOP, m.Option("PID")).ProcessRefresh() }},
|
||||
MAXPROCS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) > 0, func() { runtime.GOMAXPROCS(kit.Int(mdb.Conf(m, RUNTIME, kit.Keys(HOST, MAXPROCS), arg[0]))) })
|
||||
m.Echo("%d", runtime.GOMAXPROCS(0))
|
||||
}},
|
||||
USERINFO: {Hand: func(m *ice.Message, arg ...string) { m.Split(m.Cmdx(SYSTEM, "who"), "user term time") }},
|
||||
aaa.ROLE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(aaa.ROLE, func(value ice.Maps) { m.Push(mdb.KEY, kit.Keys(value[aaa.ROLE], value[mdb.ZONE], value[mdb.KEY])) })
|
||||
ctx.DisplayStorySpide(m.Options(nfs.DIR_ROOT, "ice."), mdb.FIELD, mdb.KEY, lex.SPLIT, nfs.PT)
|
||||
}},
|
||||
API: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 1 {
|
||||
m.Cmdy(ctx.COMMAND, "inner").Push(ctx.ARGS, kit.Format(nfs.SplitPath(m, m.Option(nfs.FILE))))
|
||||
m.Cmdy(ctx.COMMAND, "web.code.inner").Push(ctx.ARGS, kit.Format(nfs.SplitPath(m, m.Option(nfs.FILE))))
|
||||
return
|
||||
}
|
||||
ctx.DisplayStorySpide(m.Options(nfs.DIR_ROOT, nfs.PS), lex.PREFIX, kit.Fields(ctx.ACTION, m.ActionKey()))
|
||||
kit.For(ice.Info.Route, func(k, v string) { m.Push(nfs.PATH, k).Push(nfs.FILE, v) })
|
||||
m.Sort(nfs.PATH)
|
||||
m.Sort(nfs.PATH).StatusTimeCount()
|
||||
}},
|
||||
CLI: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 1 {
|
||||
m.Cmdy(ctx.COMMAND, "inner").Push(ctx.ARGS, kit.Format(nfs.SplitPath(m, m.Option(nfs.FILE))))
|
||||
m.Cmdy(ctx.COMMAND, "web.code.inner").Push(ctx.ARGS, kit.Format(nfs.SplitPath(m, m.Option(nfs.FILE))))
|
||||
return
|
||||
}
|
||||
ctx.DisplayStorySpide(m.Options(nfs.DIR_ROOT, "ice."), lex.PREFIX, kit.Fields(ctx.ACTION, m.ActionKey()), mdb.FIELD, mdb.NAME, lex.SPLIT, nfs.PT)
|
||||
kit.For(ice.Info.File, func(k, v string) { m.Push(nfs.FILE, k).Push(mdb.NAME, v) })
|
||||
m.Sort(mdb.NAME)
|
||||
m.Sort(mdb.NAME).StatusTimeCount()
|
||||
}},
|
||||
CMD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionFields(ctx.INDEX, mdb.NAME, mdb.HELP, nfs.FILE)
|
||||
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND)
|
||||
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND).StatusTimeCount()
|
||||
}},
|
||||
MOD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
"mod": {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(ice.Info.Gomod, func(k string, v string) { m.Push(nfs.MODULE, k).Push(nfs.VERSION, v) })
|
||||
m.StatusTimeCount()
|
||||
}},
|
||||
"routine": {Hand: func(m *ice.Message, arg ...string) {
|
||||
buf := make([]byte, 4096*4096)
|
||||
runtime.Stack(buf, true)
|
||||
status := map[string]int{}
|
||||
outer:
|
||||
for _, v := range bytes.Split(buf, []byte(lex.NL+lex.NL)) {
|
||||
ls := bytes.Split(v, []byte(lex.NL))
|
||||
if ls := strings.SplitN(string(ls[0]), " ", 3); len(ls) > 0 {
|
||||
m.Push(mdb.ID, ls[1]).Push("status", ls[2])
|
||||
status[kit.Split(string(ls[2]), " []:")[0]]++
|
||||
}
|
||||
for i := 1; i < len(ls); i += 2 {
|
||||
if bytes.HasPrefix(ls[i], []byte("shylinux.com/x/")) {
|
||||
m.Push(nfs.PATH, kit.TrimPath(string(ls[i+1]))).Push("func", string(ls[i]))
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
m.Push(nfs.PATH, kit.TrimPath(string(ls[2]))).Push("func", string(ls[1]))
|
||||
}
|
||||
var stats runtime.MemStats
|
||||
runtime.ReadMemStats(&stats)
|
||||
m.StatusTimeCount(status, "GOMAXPROCS", runtime.GOMAXPROCS(0), "NumGC", stats.NumGC, "Alloc", kit.FmtSize(int64(stats.Alloc)), "Sys", kit.FmtSize(int64(stats.Sys)))
|
||||
m.Echo("%v", string(buf))
|
||||
}},
|
||||
ENV: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(os.Environ(), func(v string) { ls := strings.SplitN(v, mdb.EQ, 2); m.Push(mdb.NAME, ls[0]).Push(mdb.VALUE, ls[1]) })
|
||||
m.Sort(mdb.NAME)
|
||||
kit.For(os.Environ(), func(v string) {
|
||||
ls := strings.SplitN(v, mdb.EQ, 2)
|
||||
m.Push(mdb.NAME, ls[0]).Push(mdb.VALUE, ls[1])
|
||||
})
|
||||
m.StatusTimeCount().Sort(mdb.NAME)
|
||||
}},
|
||||
nfs.PATH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(_path_split(os.Getenv(PATH)), func(p string) { m.Push(nfs.PATH, p) })
|
||||
}},
|
||||
"chain": {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.FormatChain()) }},
|
||||
"upgrade": {Help: "升级", Hand: func(m *ice.Message, arg ...string) {
|
||||
if nfs.Exists(m, ice.SRC_MAIN_GO) && nfs.Exists(m, ".git") && SystemFind(m, "go") != "" {
|
||||
m.Cmdy("vimer", "compile")
|
||||
} else if nfs.Exists(m, ice.BIN_ICE_BIN) {
|
||||
m.Cmdy("upgrade")
|
||||
} else {
|
||||
m.Cmdy("", REBOOT)
|
||||
}
|
||||
}},
|
||||
REBOOT: {Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Go(func() { m.Sleep30ms(ice.EXIT, 1) })
|
||||
}},
|
||||
"lock": {Help: "锁屏", Icon: "bi bi-file-lock", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch runtime.GOOS {
|
||||
case DARWIN:
|
||||
TellApp(m, "System Events", `keystroke "q" using {control down, command down}`)
|
||||
}
|
||||
}},
|
||||
}, ctx.ConfAction("")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, ctx.CmdAction(), ctx.ConfAction("")), Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) > 0 && arg[0] == BOOTINFO, func() { arg = arg[1:] })
|
||||
m.Cmdy(ctx.CONFIG, RUNTIME, arg).StatusTime(mdb.TIME, ice.Info.Make.Time,
|
||||
mdb.HASH, kit.Cut(ice.Info.Hash, 6), nfs.SIZE, ice.Info.Size,
|
||||
mdb.NAME, ice.Info.NodeName, nfs.VERSION, ice.Info.Make.Versions(),
|
||||
).Action()
|
||||
m.Cmdy(ctx.CONFIG, RUNTIME, arg)
|
||||
ctx.DisplayStoryJSON(m)
|
||||
}},
|
||||
})
|
||||
@ -271,37 +238,5 @@ func NodeInfo(m *ice.Message, arg ...string) {
|
||||
mdb.Conf(m, RUNTIME, kit.Keys(NODE, mdb.TIME), m.Time())
|
||||
ice.Info.NodeName = mdb.Conf(m, RUNTIME, kit.Keys(NODE, mdb.NAME), kit.Select(ice.Info.NodeName, arg, 0))
|
||||
ice.Info.NodeType = mdb.Conf(m, RUNTIME, kit.Keys(NODE, mdb.TYPE), kit.Select(ice.Info.NodeType, arg, 1))
|
||||
ice.Info.NodeIcon = mdb.Conf(m, RUNTIME, kit.Keys(NODE, mdb.ICON), kit.Select(ice.Info.NodeIcon, arg, 2))
|
||||
}
|
||||
func IsWindows() bool { return runtime.GOOS == WINDOWS }
|
||||
func ParseMake(str string) []string {
|
||||
res := kit.UnMarshal(str)
|
||||
data := kit.Value(res, MAKE)
|
||||
version := kit.Format(kit.Value(data, nfs.VERSION))
|
||||
if kit.Format(kit.Value(data, "forword")) != "0" {
|
||||
version = kit.Join(kit.TrimArg(kit.Simple(
|
||||
kit.Select("v0.0.0", kit.Format(kit.Value(data, nfs.VERSION))),
|
||||
kit.Select("0", kit.Format(kit.Value(data, "forword"))),
|
||||
kit.Cut(kit.Format(kit.Value(data, mdb.HASH)), 6),
|
||||
)...), "-")
|
||||
}
|
||||
return kit.Simple(
|
||||
mdb.TIME, kit.Format(kit.Value(data, mdb.TIME)),
|
||||
ice.SPACE, kit.Format(kit.Value(res, kit.Keys(NODE, mdb.NAME))),
|
||||
nfs.MODULE, kit.Format(kit.Value(data, nfs.MODULE)),
|
||||
nfs.VERSION, version,
|
||||
COMMIT_TIME, kit.Format(kit.Value(data, "when")),
|
||||
COMPILE_TIME, kit.Format(kit.Value(data, mdb.TIME)),
|
||||
BOOT_TIME, kit.Format(kit.Value(res, kit.Keys(BOOT, mdb.TIME))),
|
||||
SHELL, kit.Format(kit.Value(res, kit.Keys(CONF, SHELL))),
|
||||
KERNEL, kit.Format(kit.Value(res, kit.Keys(HOST, GOOS))),
|
||||
ARCH, kit.Format(kit.Value(res, kit.Keys(HOST, GOARCH))),
|
||||
)
|
||||
}
|
||||
func SimpleMake() []string {
|
||||
return []string{
|
||||
nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(),
|
||||
COMMIT_TIME, ice.Info.Make.When, COMPILE_TIME, ice.Info.Make.Time, BOOT_TIME, ice.Info.Time,
|
||||
KERNEL, runtime.GOOS, ARCH, runtime.GOARCH,
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SUDO: {Actions: mdb.HashAction(mdb.SHORT, "cmd", mdb.FIELD, "time,cmd")},
|
||||
})
|
||||
}
|
@ -4,16 +4,16 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/file"
|
||||
)
|
||||
@ -31,9 +31,11 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
}
|
||||
}
|
||||
})
|
||||
if bin == "" {
|
||||
if bin = _system_find(m, arg[0], EtcPath(m)...); bin != "" {
|
||||
m.Logs(FIND, "etcpath cmd", bin)
|
||||
if bin == "" && nfs.Exists(m, ice.ETC_PATH) {
|
||||
if text := m.Cmdx(nfs.CAT, ice.ETC_PATH); len(text) > 0 {
|
||||
if bin = _system_find(m, arg[0], strings.Split(text, lex.NL)...); bin != "" {
|
||||
m.Logs(FIND, "etcpath cmd", bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
if bin == "" {
|
||||
@ -52,21 +54,14 @@ func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
m.Logs(FIND, "mirrors cmd", bin)
|
||||
}
|
||||
}
|
||||
arg[0] = kit.Select(arg[0], bin)
|
||||
if m.Cmd(SUDO, arg[0]).Length() > 0 {
|
||||
m.Logs(FIND, "sudo cmd", arg[0])
|
||||
arg = kit.Simple(SUDO, arg)
|
||||
}
|
||||
cmd := exec.Command(arg[0], arg[1:]...)
|
||||
cmd := exec.Command(kit.Select(arg[0], bin), arg[1:]...)
|
||||
if cmd.Dir = kit.TrimPath(m.Option(CMD_DIR)); len(cmd.Dir) > 0 {
|
||||
if m.Logs(EXEC, CMD_DIR, cmd.Dir); !nfs.Exists(m, cmd.Dir) {
|
||||
file.MkdirAll(cmd.Dir, ice.MOD_DIR)
|
||||
}
|
||||
}
|
||||
kit.For(env, func(k, v string) { cmd.Env = append(cmd.Env, kit.Format("%s=%s", k, v)) })
|
||||
kit.If(len(cmd.Env) > 0 && m.IsDebug(), func() { m.Logs(EXEC, CMD_ENV, kit.Format(cmd.Env)) })
|
||||
kit.If(len(cmd.Env) > 0, func() { m.Logs(EXEC, CMD_ENV, kit.Format(cmd.Env)) })
|
||||
_system_cmds(m, cmd, arg...)
|
||||
return cmd
|
||||
}
|
||||
func _system_out(m *ice.Message, out string) io.Writer {
|
||||
@ -95,18 +90,19 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
cmd.Stdout, cmd.Stderr = out, err
|
||||
defer func() {
|
||||
m.Push(CMD_OUT, out.String()).Push(CMD_ERR, err.String())
|
||||
if m.Echo(out.String()).Echo(err.String()); m.IsErr() {
|
||||
// m.Echo(strings.TrimRight(out.String(), lex.NL))
|
||||
m.Echo(out.String())
|
||||
if m.IsErr() {
|
||||
m.Option(ice.MSG_ARGS, kit.Simple(http.StatusBadRequest, cmd.Args, err.String()))
|
||||
m.Echo(strings.TrimRight(err.String(), lex.NL))
|
||||
m.Info("err: %v", err.String())
|
||||
m.Info("out: %v", out.String())
|
||||
m.Debug("%s %s", err, out)
|
||||
}
|
||||
}()
|
||||
}
|
||||
if e := cmd.Run(); !m.WarnNotValid(e, cmd.Args) {
|
||||
if e := cmd.Run(); !m.Warn(e, ice.ErrNotValid, cmd.Args) {
|
||||
m.Cost(CODE, _system_code(cmd), EXEC, cmd.Args)
|
||||
}
|
||||
m.Push(mdb.TIME, m.Time()).Push(CODE, _system_code(cmd)).StatusTime()
|
||||
m.Push(mdb.TIME, m.Time()).Push(CODE, _system_code(cmd))
|
||||
}
|
||||
func _system_code(cmd *exec.Cmd) string {
|
||||
return kit.Select("1", "0", cmd.ProcessState != nil && cmd.ProcessState.Success())
|
||||
@ -114,16 +110,19 @@ func _system_code(cmd *exec.Cmd) string {
|
||||
func _system_find(m *ice.Message, bin string, dir ...string) string {
|
||||
if strings.Contains(bin, nfs.DF) {
|
||||
return bin
|
||||
} else if strings.HasPrefix(bin, nfs.PS) {
|
||||
}
|
||||
if strings.HasPrefix(bin, nfs.PS) {
|
||||
return bin
|
||||
} else if strings.HasPrefix(bin, nfs.PWD) {
|
||||
}
|
||||
if strings.HasPrefix(bin, nfs.PWD) {
|
||||
return bin
|
||||
}
|
||||
kit.If(len(dir) == 0, func() { dir = append(dir, _path_split(kit.Env(PATH))...) })
|
||||
for _, p := range dir {
|
||||
if nfs.Exists(m, path.Join(p, bin)) {
|
||||
return kit.Path(p, bin)
|
||||
} else if IsWindows() && nfs.Exists(m, path.Join(p, bin)+".exe") {
|
||||
}
|
||||
if IsWindows() && nfs.Exists(m, path.Join(p, bin)+".exe") {
|
||||
return kit.Path(p, bin) + ".exe"
|
||||
}
|
||||
}
|
||||
@ -134,12 +133,6 @@ func _system_find(m *ice.Message, bin string, dir ...string) string {
|
||||
}
|
||||
|
||||
const (
|
||||
TIME_300ms = "300ms"
|
||||
TIME_30ms = "30ms"
|
||||
TIME_30s = "30s"
|
||||
TIME_3s = "3s"
|
||||
TIME_1s = "1s"
|
||||
|
||||
CMD_DIR = "cmd_dir"
|
||||
CMD_ENV = "cmd_env"
|
||||
|
||||
@ -150,39 +143,12 @@ const (
|
||||
CMD_ERR = "cmd_err"
|
||||
CMD_OUT = "cmd_out"
|
||||
|
||||
RUN = "run"
|
||||
MAN = "man"
|
||||
FIND = "find"
|
||||
GREP = "grep"
|
||||
EXEC = "exec"
|
||||
REST = "rest"
|
||||
PARAM = "param"
|
||||
OPENS = "opens"
|
||||
RELAY = "relay"
|
||||
)
|
||||
|
||||
const (
|
||||
SH = "sh"
|
||||
LN = "ln"
|
||||
CP = "cp"
|
||||
MV = "mv"
|
||||
RM = "rm"
|
||||
CD = "cd"
|
||||
CAT = "cat"
|
||||
|
||||
FIND = "find"
|
||||
GREP = "grep"
|
||||
TAIL = "tail"
|
||||
WGET = "wget"
|
||||
CURL = "curl"
|
||||
|
||||
SUDO = "sudo"
|
||||
EXEC = "exec"
|
||||
EXIT = "exit"
|
||||
ECHO = "echo"
|
||||
KILL = "kill"
|
||||
|
||||
GO = "go"
|
||||
GOTAGS = "gotags"
|
||||
GIT = "git"
|
||||
MAN = "man"
|
||||
YUM = "yum"
|
||||
)
|
||||
|
||||
const SYSTEM = "system"
|
||||
@ -190,60 +156,63 @@ const SYSTEM = "system"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SYSTEM: {Name: "system cmd", Help: "系统命令", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if runtime.GOOS == DARWIN && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
|
||||
if mdb.IsSearchForEach(m, arg, nil) {
|
||||
return
|
||||
list := map[string]bool{"Terminal.app": true, "Docker.app": true, "Google Chrome.app": true}
|
||||
for _, p := range strings.Split(m.Cmdx("", nfs.SH, "-c", `ps aux|grep /Applications/|grep -v Cache|grep -v Helper|grep -v Widget|grep -v Extension|grep -v Chrome|grep -v com.app|grep -v grep|grep -o "[^/]*.app"|sort|uniq`), lex.NL) {
|
||||
list[p] = true
|
||||
}
|
||||
for p := range list {
|
||||
m.PushSearch(mdb.TYPE, OPENS, mdb.TEXT, p)
|
||||
}
|
||||
}
|
||||
if arg[0] == m.CommandKey() && arg[1] == OPENS {
|
||||
for _, p := range []string{"/Applications", "/System/Applications", "/System/Applications/Utilities"} {
|
||||
m.Cmd(nfs.DIR, p, mdb.NAME, func(value ice.Maps) { m.PushSearch(mdb.TEXT, path.Join(p, value[mdb.NAME]), value) })
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
nfs.PUSH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(arg, func(p string) {
|
||||
kit.If(!kit.IsIn(p, EtcPath(m)...), func() {
|
||||
for _, p := range arg {
|
||||
if !strings.Contains(m.Cmdx(nfs.CAT, ice.ETC_PATH), p) {
|
||||
m.Cmd(nfs.PUSH, ice.ETC_PATH, strings.TrimSpace(p)+lex.NL)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
m.Cmdy(nfs.CAT, ice.ETC_PATH)
|
||||
}},
|
||||
FIND: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_system_find(m, arg[0], arg[1:]...)) }},
|
||||
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) {
|
||||
kit.If(len(arg) == 1, func() { arg = append(arg, "") })
|
||||
if len(arg) == 1 {
|
||||
arg = append(arg, "")
|
||||
}
|
||||
m.Option(CMD_ENV, "COLUMNS", kit.Int(kit.Select("1920", m.Option(ice.MSG_WIDTH)))/12)
|
||||
m.Echo(SystemCmds(m, "man %s %s|col -b", kit.Select("", arg[1], arg[1] != "1"), arg[0]))
|
||||
}},
|
||||
OPENS: {Hand: func(m *ice.Message, arg ...string) { Opens(m, arg...) }},
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, "cmd", mdb.FIELD, "time,cmd,arg")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
mdb.HashSelect(m)
|
||||
return
|
||||
}
|
||||
if _system_exec(m, _system_cmd(m, arg...)); IsSuccess(m) && m.Append(CMD_ERR) == "" {
|
||||
m.SetAppend()
|
||||
}
|
||||
}},
|
||||
})
|
||||
ice.Info.SystemCmd = func(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
msg := m.Cmd(append([]ice.Any{SYSTEM}, arg...)...)
|
||||
if m.Warn(!IsSuccess(msg), msg.Append(CMD_ERR)) {
|
||||
}
|
||||
return msg
|
||||
}
|
||||
}
|
||||
|
||||
func SystemFindGit(m *ice.Message) bool { return SystemFind(m, GIT) != "" }
|
||||
func SystemFindGo(m *ice.Message) bool { return SystemFind(m, GO) != "" }
|
||||
func SystemFind(m *ice.Message, bin string, dir ...string) string {
|
||||
dir = append(dir, EtcPath(m)...)
|
||||
if text := m.Cmdx(nfs.CAT, ice.ETC_PATH); len(text) > 0 {
|
||||
dir = append(dir, strings.Split(text, lex.NL)...)
|
||||
}
|
||||
return _system_find(m, bin, append(dir, _path_split(kit.Env(PATH))...)...)
|
||||
}
|
||||
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, ""}), lex.NL)
|
||||
return strings.TrimRight(m.Cmdx(SYSTEM, "sh", "-c", kit.Format(cmds, args...), ice.Option{CMD_OUTPUT, ""}), lex.NL)
|
||||
}
|
||||
func IsSuccess(m *ice.Message) bool { return m.Append(CODE) == "" || m.Append(CODE) == "0" }
|
||||
|
||||
var _cache_path []string
|
||||
|
||||
func Shell(m *ice.Message) string { return kit.Select(SH, os.Getenv(SHELL)) }
|
||||
func EtcPath(m *ice.Message) (res []string) {
|
||||
if len(_cache_path) > 0 {
|
||||
return _cache_path
|
||||
}
|
||||
nfs.Exists(m, ice.ETC_PATH, func(p string) {
|
||||
kit.For(strings.Split(m.Cmdx(nfs.CAT, p, kit.Dict(aaa.UserRole, aaa.ROOT)), lex.NL), func(p string) {
|
||||
kit.If(p != "" && !strings.HasPrefix(p, "# "), func() {
|
||||
res = append(res, p)
|
||||
})
|
||||
})
|
||||
})
|
||||
_cache_path = res
|
||||
return
|
||||
}
|
||||
|
@ -1,11 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
|
||||
func _system_cmds(m *ice.Message, cmd *exec.Cmd, arg ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
|
||||
func _system_cmds(m *ice.Message, cmd *exec.Cmd, arg ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
|
||||
func _system_cmds(m *ice.Message, cmd *exec.Cmd, arg ...string) *exec.Cmd {
|
||||
return cmd
|
||||
}
|
@ -2,41 +2,37 @@ package ctx
|
||||
|
||||
import (
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
func _command_list(m *ice.Message, name string) *ice.Message {
|
||||
if name == "" {
|
||||
for k, v := range m.Source().Commands {
|
||||
if IsOrderCmd(k) {
|
||||
continue
|
||||
}
|
||||
m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.HELP, v.Help)
|
||||
}
|
||||
return m.Sort(mdb.KEY)
|
||||
}
|
||||
if strings.HasPrefix(name, "can.") {
|
||||
return m.Push(mdb.INDEX, name).Push(mdb.NAME, name).Push(mdb.HELP, "").Push(mdb.META, "").Push(mdb.LIST, "")
|
||||
}
|
||||
m.Option(ice.MSG_NODENAME, ice.Info.Titles)
|
||||
m.Option(ice.MSG_NODEICON, m.Resource(ice.Info.NodeIcon))
|
||||
|
||||
m.Spawn(m.Source()).Search(name, func(p *ice.Context, s *ice.Context, key string, cmd *ice.Command) {
|
||||
icon := kit.Format(kit.Value(cmd.Meta, kit.Keys(ice.CTX_ICONS, key)))
|
||||
icons := kit.Select(cmd.Icon, icon, !kit.HasPrefix(icon, "bi ", "{"))
|
||||
if icons != "" {
|
||||
icons = m.Resource(icons)
|
||||
}
|
||||
m.Push(mdb.INDEX, kit.Keys(s.Prefix(), key))
|
||||
m.Push(mdb.ICONS, icons)
|
||||
m.Push(mdb.NAME, kit.Format(cmd.Name)).Push(mdb.HELP, kit.Format(cmd.Help))
|
||||
m.Push(mdb.LIST, kit.Format(cmd.List)).Push(mdb.META, kit.Format(cmd.Meta))
|
||||
m.Push("_command", ShortCmd(kit.Keys(s.Prefix(), key)))
|
||||
if !nfs.Exists(m, kit.Split(cmd.FileLine(), nfs.DF)[0], func(p string) {
|
||||
m.Push("_fileline", m.FileURI(p))
|
||||
}) {
|
||||
m.Push("_fileline", "")
|
||||
}
|
||||
m.Push("_role", kit.Select("", ice.OK, aaa.Right(m.Spawn(), name)))
|
||||
m.Push("_help", GetCmdHelp(m, name))
|
||||
m.Push(mdb.NAME, kit.Format(cmd.Name))
|
||||
m.Push(mdb.HELP, kit.Format(cmd.Help))
|
||||
m.Push(mdb.META, FormatPretty(cmd.Meta, 0, 2))
|
||||
m.Push(mdb.LIST, FormatPretty(cmd.List, 0, 2))
|
||||
})
|
||||
return m
|
||||
}
|
||||
@ -45,125 +41,116 @@ func _command_search(m *ice.Message, kind, name, text string) {
|
||||
if IsOrderCmd(key) || !strings.Contains(s.Prefix(key), name) {
|
||||
return
|
||||
}
|
||||
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1),
|
||||
kit.SimpleKV("", s.Prefix(), kit.Select(key, cmd.Name), cmd.Help),
|
||||
INDEX, kit.Keys(s.Prefix(), key))
|
||||
}).Sort(m.OptionFields())
|
||||
m.PushSearch(ice.CTX, kit.PathName(1), ice.CMD, kit.FileName(1), kit.SimpleKV("", s.Prefix(), cmd.Name, cmd.Help),
|
||||
CONTEXT, s.Prefix(), COMMAND, key, INDEX, kit.Keys(s.Prefix(), key), mdb.HELP, cmd.Help, nfs.FILE, FileURI(cmd.FileLine()),
|
||||
)
|
||||
})
|
||||
m.Sort(m.OptionFields())
|
||||
}
|
||||
|
||||
const (
|
||||
INDEX = "index"
|
||||
CMDS = "cmds"
|
||||
ARGS = "args"
|
||||
OPTS = "opts"
|
||||
STYLE = "style"
|
||||
DISPLAY = "display"
|
||||
PREVIEW = "preview"
|
||||
ACTION = "action"
|
||||
TOOLS = "tools"
|
||||
RUN = "run"
|
||||
SHIP = "ship"
|
||||
|
||||
ICONS = ice.CTX_ICONS
|
||||
TRANS = ice.CTX_TRANS
|
||||
TITLE = ice.CTX_TITLE
|
||||
INPUT = html.INPUT
|
||||
)
|
||||
const COMMAND = "command"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
COMMAND: {Name: "command key auto", Help: "命令", Role: aaa.VOID, Actions: ice.MergeActions(ice.Actions{
|
||||
COMMAND: {Name: "command key auto", Help: "命令", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
TravelCmd(m, func(key, file, line string) { AddFileCmd(file, key) })
|
||||
m.Travel(func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
kit.If(cmd.Actions == nil, func() { cmd.Actions = ice.Actions{} })
|
||||
if _, ok := cmd.Actions[COMMAND]; !ok {
|
||||
cmd.Actions[COMMAND] = &ice.Action{Hand: Command}
|
||||
}
|
||||
if _, ok := cmd.Actions[RUN]; !ok {
|
||||
cmd.Actions[RUN] = &ice.Action{Hand: Run}
|
||||
}
|
||||
if _, ok := cmd.Actions[mdb.INPUTS]; !ok {
|
||||
cmd.Actions[mdb.INPUTS] = &ice.Action{Hand: func(m *ice.Message, arg ...string) { mdb.HashInputs(m, arg) }}
|
||||
}
|
||||
})
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == m.CommandKey() || len(arg) > 1 && arg[1] != "" {
|
||||
_command_search(m, arg[0], kit.Select("", arg, 1), kit.Select("", arg, 2))
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] != "" && arg[0] != ice.EXIT {
|
||||
m.Search(arg[0], func(key string, cmd *ice.Command) {
|
||||
field := kit.Format(kit.Value(cmd.List, kit.Format("%d.name", len(arg)-1)))
|
||||
if m.Cmdy(arg[0], mdb.INPUTS, field); m.Length() == 0 {
|
||||
m.Cmdy(arg).Cut(field)
|
||||
}
|
||||
})
|
||||
}
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
TravelCmd(m, func(key, file, line string) { m.Push(mdb.NAME, key).Push(nfs.FILE, file).Push(nfs.LINE, line) }).Sort(mdb.NAME).Table(func(value ice.Maps) {
|
||||
m.Echo(`%s %s %s;" f`+lex.NL, value[mdb.NAME], value[nfs.FILE], value[nfs.LINE])
|
||||
}).Cmd(nfs.SAVE, nfs.TAGS, m.Result())
|
||||
}},
|
||||
"default": {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Spawn(m.Source()).Search(arg[0], func(key string, cmd *ice.Command) {
|
||||
if arg[1] == ACTION {
|
||||
list := kit.Value(cmd.Meta, arg[2])
|
||||
kit.For(arg[3:], func(k, v string) {
|
||||
kit.For(list, func(value ice.Map) {
|
||||
kit.If(value[mdb.NAME] == k, func() {
|
||||
value[mdb.VALUE] = v
|
||||
})
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
for i, v := range arg[1:] {
|
||||
kit.Value(cmd.List, kit.Keys(i, mdb.VALUE), v)
|
||||
}
|
||||
})
|
||||
}},
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, CmdAction(), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.OptionFields(INDEX)
|
||||
m.Cmdy("", mdb.SEARCH, COMMAND)
|
||||
} else {
|
||||
kit.For(arg, func(k string) { _command_list(m, k) })
|
||||
m.Cmdy("", mdb.SEARCH, COMMAND, ice.OptionFields(INDEX))
|
||||
DisplayStory(m.Options(nfs.DIR_ROOT, "ice."), "spide.js?split=.")
|
||||
return
|
||||
}
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, "") })
|
||||
kit.For(arg, func(k string) { _command_list(m, k) })
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
var PodCmd = func(m *ice.Message, arg ...ice.Any) bool { return false }
|
||||
var Upload = func(*ice.Message) []string { return nil }
|
||||
|
||||
func CmdInputs(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case INDEX:
|
||||
m.Cmdy(COMMAND, mdb.SEARCH, COMMAND, ice.OptionFields(INDEX))
|
||||
case ARGS:
|
||||
m.Cmdy(m.Option(INDEX))
|
||||
}
|
||||
}
|
||||
func PodCmd(m *ice.Message, arg ...ice.Any) bool {
|
||||
Upload(m)
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
m.Options(ice.POD, "").Cmdy(append(kit.List(ice.SPACE, pod), arg...)...)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
func Run(m *ice.Message, arg ...string) {
|
||||
kit.If(!PodCmd(m, arg) && aaa.Right(m, arg), func() { m.Cmdy(arg) })
|
||||
}
|
||||
func Command(m *ice.Message, arg ...string) {
|
||||
kit.If(!PodCmd(m, COMMAND, arg), func() { m.Cmdy(COMMAND, arg) })
|
||||
func CmdHandler(args ...ice.Any) ice.Handler {
|
||||
return func(m *ice.Message, arg ...string) { m.Cmdy(args...) }
|
||||
}
|
||||
func CmdAction(args ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(args...), ice.RUN: {Hand: Run},
|
||||
COMMAND: {Hand: func(m *ice.Message, arg ...string) { kit.If(!PodCmd(m, COMMAND, arg), func() { m.Cmdy(COMMAND, arg) }) }},
|
||||
}
|
||||
}
|
||||
func CmdList(m *ice.Message) *ice.Message {
|
||||
return m.Cmdy(COMMAND, mdb.SEARCH, COMMAND, ice.OptionFields(INDEX))
|
||||
}
|
||||
|
||||
func FileCmd(dir string) string {
|
||||
if strings.Index(dir, ":") == 1 {
|
||||
return ice.Pulse.FileURI(kit.ExtChange(strings.Join(kit.Slice(strings.Split(dir, ":"), 0, 2), ":"), nfs.GO))
|
||||
func IsOrderCmd(key string) bool { return key[0] == '/' || key[0] == '_' }
|
||||
func FileURI(dir string) string {
|
||||
logs.Println("%v %v %v", dir, ice.Info.Make.Path, kit.Path(""))
|
||||
if dir == "" {
|
||||
return ""
|
||||
} else if strings.Contains(dir, "/pkg/mod/") {
|
||||
dir = strings.Split(dir, "/pkg/mod/")[1]
|
||||
} else if path.IsAbs(dir) {
|
||||
if ice.Info.Make.Path != "" && strings.HasPrefix(dir, ice.Info.Make.Path) {
|
||||
dir = strings.TrimPrefix(dir, ice.Info.Make.Path)
|
||||
} else if strings.HasPrefix(dir, kit.Path("")+nfs.PS) {
|
||||
dir = strings.TrimPrefix(dir, kit.Path("")+nfs.PS)
|
||||
}
|
||||
} else if nfs.Exists(ice.Pulse, path.Join(ice.SRC, dir)) {
|
||||
dir = path.Join(ice.SRC, dir)
|
||||
}
|
||||
return ice.Pulse.FileURI(kit.ExtChange(strings.Split(dir, nfs.DF)[0], nfs.GO))
|
||||
return path.Join(nfs.PS, ice.REQUIRE, dir)
|
||||
}
|
||||
func FileCmd(dir string) string { return FileURI(kit.ExtChange(strings.Split(dir, nfs.DF)[0], nfs.GO)) }
|
||||
func AddFileCmd(dir, key string) {
|
||||
ice.Info.File[FileCmd(dir)] = key
|
||||
if ls := strings.SplitN(path.Join(kit.Slice(kit.Split(FileCmd(dir), nfs.PS), 1, 4)...), mdb.AT, 2); len(ls) > 1 {
|
||||
_ls := strings.Split(FileCmd(dir), mdb.AT+ls[1]+nfs.PS)
|
||||
ice.Info.File[path.Join(nfs.P, nfs.USR, path.Base(_ls[0]), _ls[1])] = key
|
||||
ice.Info.Gomod[ls[0]] = ls[1]
|
||||
} else {
|
||||
ice.Info.File[FileCmd(dir)] = key
|
||||
}
|
||||
}
|
||||
func GetFileCmd(dir string) string {
|
||||
if strings.HasPrefix(dir, ice.REQUIRE+nfs.PS) {
|
||||
dir = nfs.PS + dir
|
||||
} else if strings.HasPrefix(dir, ice.ISH_PLUGED) {
|
||||
dir = path.Join(nfs.P, strings.TrimPrefix(dir, ice.ISH_PLUGED))
|
||||
dir = path.Join(nfs.PS, ice.REQUIRE, strings.TrimPrefix(dir, ice.ISH_PLUGED))
|
||||
}
|
||||
for _, dir := range []string{dir, path.Join(nfs.P, ice.Info.Make.Module, dir), path.Join(nfs.P, ice.Info.Make.Module, ice.SRC, dir)} {
|
||||
for _, dir := range []string{dir, path.Join(nfs.PS, ice.REQUIRE, ice.Info.Make.Module, dir), path.Join(nfs.PS, ice.REQUIRE, ice.Info.Make.Module, ice.SRC, dir)} {
|
||||
if cmd, ok := ice.Info.File[FileCmd(dir)]; ok {
|
||||
return cmd
|
||||
}
|
||||
@ -174,17 +161,10 @@ func GetFileCmd(dir string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func GetCmdHelp(m *ice.Message, cmds string) (file string) {
|
||||
file = kit.TrimPrefix(m.FileURI(kit.ExtChange(GetCmdFile(m, cmds), nfs.SHY)), nfs.P, nfs.REQUIRE)
|
||||
if !nfs.Exists(m, path.Join(nfs.USR_LEARNING_PORTAL, "commands", strings.TrimPrefix(file, nfs.USR_ICEBERGS)), func(p string) { file = p }) {
|
||||
kit.If(!nfs.Exists(m, file), func() { file = "" })
|
||||
}
|
||||
return
|
||||
}
|
||||
func GetCmdFile(m *ice.Message, cmds string) (file string) {
|
||||
m.Search(kit.Select(m.PrefixKey(), cmds), func(key string, cmd *ice.Command) {
|
||||
if file = kit.TrimPrefix(m.FileURI(kit.Split(cmd.FileLine(), nfs.DF)[0]), nfs.P); !nfs.Exists(m, file) {
|
||||
file = path.Join(nfs.P, file)
|
||||
m.Search(cmds, func(key string, cmd *ice.Command) {
|
||||
if file = strings.TrimPrefix(FileURI(kit.Split(cmd.FileLine(), nfs.DF)[0]), "/require/"); !nfs.Exists(m, file) {
|
||||
file = path.Join(ice.ISH_PLUGED, file)
|
||||
}
|
||||
})
|
||||
return
|
||||
@ -194,34 +174,9 @@ func TravelCmd(m *ice.Message, cb func(key, file, line string)) *ice.Message {
|
||||
if IsOrderCmd(key) {
|
||||
return
|
||||
}
|
||||
if runtime.GOOS == ice.WINDOWS {
|
||||
if ls := kit.Split(cmd.FileLine(), nfs.DF); len(ls) > 2 {
|
||||
cb(kit.Keys(s.Prefix(), key), strings.TrimPrefix(strings.Join(kit.Slice(ls, 0, -1), nfs.DF), kit.Path("")+nfs.PS), kit.Select("1", ls, -1))
|
||||
return
|
||||
}
|
||||
}
|
||||
if ls := kit.Split(cmd.FileLine(), nfs.DF); len(ls) > 0 {
|
||||
if ls := kit.Split(cmd.FileLine(), nfs.DF); len(ls) > 0 && cmd.Name != "" {
|
||||
cb(kit.Keys(s.Prefix(), key), strings.TrimPrefix(ls[0], kit.Path("")+nfs.PS), kit.Select("1", ls, 1))
|
||||
}
|
||||
})
|
||||
return m
|
||||
}
|
||||
func IsOrderCmd(key string) bool {
|
||||
return key[0] == '/' || key[0] == '_'
|
||||
}
|
||||
func ShortCmd(key string) string {
|
||||
_key := kit.Select("", kit.Split(key, nfs.PT), -1)
|
||||
if _p, ok := ice.Info.Index[_key].(*ice.Context); ok && _p.Prefix(_key) == key {
|
||||
return _key
|
||||
}
|
||||
return key
|
||||
}
|
||||
func ResourceFile(m *ice.Message, file string, arg ...string) string {
|
||||
if kit.HasPrefix(file, nfs.PS, ice.HTTP) {
|
||||
return file
|
||||
} else if nfs.Exists(m, file) {
|
||||
return file
|
||||
} else {
|
||||
return path.Join(path.Dir(GetCmdFile(m, m.PrefixKey())), file)
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,80 @@ import (
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
)
|
||||
|
||||
func FormatPretty(v ice.Any, i, n int) string {
|
||||
return kit.Formats(v)
|
||||
switch v := v.(type) {
|
||||
case map[string]ice.Any:
|
||||
if n == 0 {
|
||||
list := []string{"{"}
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
list = append(list, kit.Format("%q", k), nfs.DF, FormatPretty(v, 0, 0), mdb.FS)
|
||||
})
|
||||
list = list[:len(list)-1]
|
||||
list = append(list, "}")
|
||||
return strings.Join(list, "")
|
||||
}
|
||||
list := []string{"{", lex.NL}
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
list = append(list, strings.Repeat(lex.TB, i+1), kit.Format("%q", k), nfs.DF)
|
||||
if i < n && !kit.IsIn(k, mdb.META) && !strings.HasPrefix(k, "_") {
|
||||
list = append(list, FormatPretty(v, i+1, n))
|
||||
} else {
|
||||
list = append(list, FormatPretty(v, 0, 0))
|
||||
}
|
||||
list = append(list, mdb.FS, lex.NL)
|
||||
})
|
||||
list = append(list[:len(list)-2], lex.NL)
|
||||
list = append(list, strings.Repeat(lex.TB, i), "}")
|
||||
return strings.Join(list, "")
|
||||
case []ice.Any:
|
||||
if n == 0 {
|
||||
list := []string{"["}
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
list = append(list, FormatPretty(v, 0, 0), mdb.FS)
|
||||
})
|
||||
list = list[:len(list)-1]
|
||||
list = append(list, "]")
|
||||
return strings.Join(list, "")
|
||||
}
|
||||
list := []string{"[", lex.NL}
|
||||
kit.For(v, func(v ice.Any) {
|
||||
list = append(list, strings.Repeat(lex.TB, i+1))
|
||||
if i < n {
|
||||
list = append(list, FormatPretty(v, i+1, n))
|
||||
} else {
|
||||
list = append(list, FormatPretty(v, 0, 0))
|
||||
}
|
||||
list = append(list, mdb.FS, lex.NL)
|
||||
})
|
||||
list = append(list[:len(list)-2], lex.NL)
|
||||
list = append(list, strings.Repeat(lex.TB, i), "]")
|
||||
return strings.Join(list, "")
|
||||
case string:
|
||||
return kit.Format(v)
|
||||
return kit.Format("%q", v)
|
||||
default:
|
||||
return kit.Format(v)
|
||||
}
|
||||
}
|
||||
func _config_format_list(m *ice.Message, v ice.Any) string {
|
||||
list := []string{"{", lex.NL}
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
if k == mdb.HASH {
|
||||
list = append(list, lex.TB, kit.Format("%q", k), nfs.DF, "{", lex.NL)
|
||||
kit.For(v, func(k string, v ice.Any) {
|
||||
list = append(list, lex.TB, lex.TB, kit.Format("%q", k), nfs.DF, kit.Format(v), mdb.FS, lex.NL)
|
||||
})
|
||||
list = list[:len(list)-2]
|
||||
list = append(list, lex.TB, lex.NL, lex.TB, "}", mdb.FS, lex.NL)
|
||||
} else {
|
||||
list = append(list, lex.TB, kit.Format("%q", k), nfs.DF, kit.Format(v), mdb.FS, lex.NL)
|
||||
}
|
||||
})
|
||||
list = list[:len(list)-2]
|
||||
list = append(list, lex.NL, "}")
|
||||
return strings.Join(list, "")
|
||||
}
|
||||
func _config_only(v ice.Any, arg ...string) bool {
|
||||
switch v := v.(type) {
|
||||
case nil:
|
||||
@ -24,7 +98,14 @@ func _config_only(v ice.Any, arg ...string) bool {
|
||||
for k, v := range v {
|
||||
if v, ok := v.(ice.Map); ok && len(v) == 0 {
|
||||
continue
|
||||
} else if kit.IndexOf(arg, k) == -1 {
|
||||
} else {
|
||||
for k := range v {
|
||||
if kit.IsIn(k, "important") && len(v) > 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
if kit.IndexOf(arg, k) == -1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -33,17 +114,9 @@ func _config_only(v ice.Any, arg ...string) bool {
|
||||
return false
|
||||
}
|
||||
func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
if !ice.HasVar() {
|
||||
return
|
||||
}
|
||||
data, msg := ice.Map{}, m.Spawn(m.Source())
|
||||
for _, k := range arg {
|
||||
if v := mdb.Confv(msg, k); _config_only(v, mdb.META) && _config_only(kit.Value(v, mdb.META),
|
||||
mdb.IMPORTANT, mdb.EXPIRE, mdb.VENDOR, nfs.SOURCE, nfs.SCRIPT, nfs.PATH, lex.REGEXP,
|
||||
mdb.SHORT, mdb.FIELD, mdb.SHORTS, mdb.FIELDS,
|
||||
mdb.ACTION, mdb.SORT, mdb.TOOLS,
|
||||
"link", "linux", "darwin", "windows",
|
||||
) {
|
||||
if v := mdb.Confv(msg, k); _config_only(v, mdb.META) {
|
||||
continue
|
||||
} else {
|
||||
data[k] = v
|
||||
@ -54,16 +127,13 @@ func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
}
|
||||
if f, _, e := miss.CreateFile(path.Join(ice.VAR_CONF, name)); m.Assert(e) {
|
||||
defer f.Close()
|
||||
if s, e := json.MarshalIndent(data, "", " "); !m.WarnNotValid(e) {
|
||||
if _, e := f.Write(s); !m.WarnNotValid(e) {
|
||||
if s, e := json.MarshalIndent(data, "", " "); !m.Warn(e) {
|
||||
if _, e := f.Write(s); !m.Warn(e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func _config_load(m *ice.Message, name string, arg ...string) {
|
||||
if !ice.HasVar() {
|
||||
return
|
||||
}
|
||||
if f, e := miss.OpenFile(path.Join(ice.VAR_CONF, name)); e == nil {
|
||||
defer f.Close()
|
||||
data, msg := ice.Map{}, m.Spawn(m.Source())
|
||||
@ -79,84 +149,77 @@ func _config_load(m *ice.Message, name string, arg ...string) {
|
||||
func _config_make(m *ice.Message, key string, arg ...string) {
|
||||
msg := m.Spawn(m.Source())
|
||||
if len(arg) > 1 {
|
||||
kit.If(!kit.IsIn(strings.Split(arg[0], nfs.PT)[0], mdb.META, mdb.HASH, mdb.LIST), func() { arg[0] = kit.Keys(mdb.META, arg[0]) })
|
||||
kit.If(strings.HasPrefix(arg[1], mdb.AT), func() { arg[1] = msg.Cmdx(nfs.CAT, arg[1][1:]) })
|
||||
mdb.Confv(msg, key, arg[0], kit.Parse(nil, "", arg[1:]...))
|
||||
}
|
||||
if len(arg) > 0 {
|
||||
m.Echo(kit.Formats(mdb.Confv(msg, key, arg[0])))
|
||||
m.Echo(FormatPretty(mdb.Confv(msg, key, arg[0]), 0, 1))
|
||||
} else {
|
||||
m.Echo(kit.Formats(mdb.Confv(msg, key))).StatusTime(mdb.COUNT, kit.Length(mdb.Confv(msg, key, mdb.HASH)))
|
||||
m.Echo(FormatPretty(mdb.Confv(msg, key), 0, 1))
|
||||
}
|
||||
}
|
||||
func _config_list(m *ice.Message) {
|
||||
for k, v := range m.Source().Configs {
|
||||
if !IsOrderCmd(k) {
|
||||
m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.VALUE, kit.Format(v.Value))
|
||||
if IsOrderCmd(k) {
|
||||
continue
|
||||
}
|
||||
m.Push(mdb.KEY, k).Push(mdb.NAME, v.Name).Push(mdb.VALUE, kit.Format(v.Value))
|
||||
}
|
||||
m.Sort(mdb.KEY)
|
||||
}
|
||||
|
||||
const (
|
||||
SAVE = "save"
|
||||
LOAD = "load"
|
||||
)
|
||||
const CONFIG = "config"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CONFIG: {Name: "config key auto", Help: "配置", Actions: ice.Actions{
|
||||
nfs.SAVE: {Hand: func(m *ice.Message, arg ...string) { _config_save(m, arg[0], arg[1:]...) }},
|
||||
nfs.LOAD: {Hand: func(m *ice.Message, arg ...string) { _config_load(m, arg[0], arg[1:]...) }},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], mdb.EXPORT) }},
|
||||
mdb.IMPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(arg[0], mdb.IMPORT) }},
|
||||
CONFIG: {Name: "config key auto export import trash", Help: "配置", Actions: ice.Actions{
|
||||
SAVE: {Hand: func(m *ice.Message, arg ...string) { _config_save(m, arg[0], arg[1:]...) }},
|
||||
LOAD: {Hand: func(m *ice.Message, arg ...string) { _config_load(m, arg[0], arg[1:]...) }},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.EXPORT, arg[0], "", mdb.HASH) }},
|
||||
mdb.IMPORT: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.IMPORT, arg[0], "", mdb.HASH) }},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(mdb.EXPORT, arg[0], "", mdb.HASH, path.Join(ice.VAR_TRASH, kit.Keys(arg[0])))
|
||||
nfs.Trash(m, path.Join(ice.VAR_DATA, arg[0]))
|
||||
nfs.Trash(m, m.Cmdx(arg[0], mdb.EXPORT))
|
||||
mdb.Conf(m, arg[0], mdb.HASH, "")
|
||||
m.Go(func() { m.Cmd(ice.EXIT, 1) })
|
||||
}},
|
||||
mdb.CREATE: {Name: "create name value", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Confv(m.Option(mdb.KEY), kit.Keys(mdb.META, m.Option(mdb.NAME)), m.Option(mdb.VALUE))
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Confv(m.Option(mdb.KEY), kit.Keys(mdb.META, m.Option(mdb.NAME)), "")
|
||||
}},
|
||||
mdb.MODIFY: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.VALUE {
|
||||
m.Confv(m.Option(mdb.KEY), kit.Keys(mdb.META, m.Option(mdb.NAME)), arg[1])
|
||||
}
|
||||
mdb.LIST: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list := []ice.Any{}
|
||||
kit.For(arg[2:], func(v string) { list = append(list, v) })
|
||||
mdb.Confv(m, arg[0], arg[1], list)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
_config_list(m)
|
||||
} else {
|
||||
_config_make(m, arg[0], arg[1:]...)
|
||||
m.Action(mdb.CREATE, mdb.IMPORT, mdb.EXPORT, nfs.TRASH)
|
||||
kit.For(mdb.Confv(m, arg[0], mdb.META), func(k, v string) {
|
||||
m.Push(mdb.NAME, k).Push(mdb.VALUE, v).PushButton(mdb.REMOVE)
|
||||
})
|
||||
DisplayStoryJSON(m)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
func init() { ice.Info.Save = Save; ice.Info.Load = Load }
|
||||
func init() {
|
||||
ice.Info.Save = Save
|
||||
ice.Info.Load = Load
|
||||
}
|
||||
func Save(m *ice.Message, arg ...string) *ice.Message {
|
||||
kit.If(len(arg) == 0, func() { arg = kit.SortedKey(m.Target().Configs) })
|
||||
kit.For(arg, func(i int, k string) { arg[i] = strings.Replace(m.Prefix(k), nfs.PS, "", 1) })
|
||||
return m.Cmd(prefix(CONFIG), nfs.SAVE, m.Prefix(nfs.JSON), arg)
|
||||
kit.For(arg, func(i int, k string) { arg[i] = m.Prefix(k) })
|
||||
return m.Cmd(CONFIG, SAVE, m.Prefix(nfs.JSON), arg)
|
||||
}
|
||||
func Load(m *ice.Message, arg ...string) *ice.Message {
|
||||
kit.If(len(arg) == 0, func() { arg = kit.SortedKey(m.Target().Configs) })
|
||||
kit.For(arg, func(i int, k string) { arg[i] = strings.Replace(m.Prefix(k), nfs.PS, "", 1) })
|
||||
return m.Cmd(prefix(CONFIG), nfs.LOAD, m.Prefix(nfs.JSON), arg)
|
||||
kit.For(arg, func(i int, k string) { arg[i] = m.Prefix(k) })
|
||||
return m.Cmd(CONFIG, LOAD, m.Prefix(nfs.JSON), arg)
|
||||
}
|
||||
func ConfAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(arg...)}
|
||||
func ConfAction(arg ...ice.Any) ice.Actions { return ice.Actions{ice.CTX_INIT: mdb.AutoConfig(arg...)} }
|
||||
func ConfigSimple(m *ice.Message, key ...string) (res []string) {
|
||||
kit.For(kit.Split(kit.Join(key)), func(k string) { res = append(res, k, mdb.Config(m, k)) })
|
||||
return
|
||||
}
|
||||
func ConfigFromOption(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
kit.For(m.Target().Commands[m.CommandKey()].Actions[m.ActionKey()].List, func(value ice.Any) {
|
||||
arg = append(arg, kit.Format(kit.Value(value, mdb.NAME)))
|
||||
})
|
||||
}
|
||||
kit.For(arg, func(k string) { mdb.Config(m, k, kit.Select(mdb.Config(m, k), m.Option(k))) })
|
||||
}
|
||||
func OptionFromConfig(m *ice.Message, arg ...string) string {
|
||||
|
@ -22,7 +22,7 @@ const CONTEXT = "context"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CONTEXT: {Name: "context name=ice action=context,command,config key auto", Help: "模块", 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) {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, m.Source().Prefix()) })
|
||||
m.Search(arg[0]+nfs.PT, func(p *ice.Context, s *ice.Context) {
|
||||
msg := m.Spawn(s)
|
||||
|
@ -11,4 +11,4 @@ var Index = &ice.Context{Name: CTX, Help: "标准模块"}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, CONTEXT, COMMAND, CONFIG) }
|
||||
|
||||
func prefix(arg ...string) string { return kit.Keys(CTX, arg) }
|
||||
func Prefix(arg ...string) string { return kit.Keys(CTX, arg) }
|
||||
|
@ -2,93 +2,54 @@ package ctx
|
||||
|
||||
import (
|
||||
"path"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
type displayMessage interface {
|
||||
Option(key string, arg ...ice.Any) string
|
||||
Action(arg ...ice.Any) *ice.Message
|
||||
}
|
||||
|
||||
func isLocalFile(p string) bool {
|
||||
return !strings.HasPrefix(p, nfs.PS) && !strings.HasPrefix(p, ice.HTTP)
|
||||
}
|
||||
func DisplayTable(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayBase(m, ice.PLUGIN_TABLE_JS, arg...)
|
||||
func Display(m displayMessage, file string, arg ...ice.Any) displayMessage {
|
||||
kit.If(file == "", func() { file = kit.Keys(kit.FileName(5), nfs.JS) })
|
||||
kit.If(isLocalFile(file), func() { file = path.Join(nfs.PS, path.Join(path.Dir(FileURI(logs.FileLines(2))), file)) })
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayTableCard(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayTable(m, STYLE, "card")
|
||||
func DisplayTable(m displayMessage, arg ...ice.Any) displayMessage {
|
||||
return DisplayBase(m, "/plugin/table.js", arg...)
|
||||
}
|
||||
func DisplayStory(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
kit.If(file == "", func() { file = kit.Keys(m.CommandKey(), nfs.JS) })
|
||||
func DisplayTableCard(m displayMessage, arg ...ice.Any) displayMessage {
|
||||
return DisplayTable(m, "style", "card")
|
||||
}
|
||||
func DisplayStory(m displayMessage, file string, arg ...ice.Any) displayMessage {
|
||||
kit.If(file == "", func() { file = kit.Keys(kit.FileName(5), nfs.JS) })
|
||||
kit.If(isLocalFile(file), func() { file = path.Join(ice.PLUGIN_STORY, file) })
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayInput(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
kit.If(file == "", func() { file = kit.Keys(m.CommandKey(), nfs.JS) })
|
||||
kit.If(isLocalFile(file), func() { file = path.Join(ice.PLUGIN_INPUT, file) })
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayStoryForm(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
args := kit.List()
|
||||
for i := range arg {
|
||||
switch v := arg[i].(type) {
|
||||
case string:
|
||||
args = append(args, ice.SplitCmd("list "+v, nil)...)
|
||||
default:
|
||||
trans := kit.Value(m.Commands(m.CommandKey()).Meta, ice.CTX_TRANS)
|
||||
if t := reflect.TypeOf(v); t.Kind() == reflect.Func {
|
||||
name := kit.FuncName(arg[i])
|
||||
args = append(args, kit.Dict(mdb.TYPE, html.BUTTON, mdb.NAME, name, mdb.VALUE, kit.Select(name, kit.Value(trans, name), !m.IsEnglish())))
|
||||
}
|
||||
}
|
||||
}
|
||||
kit.For(args, func(v ice.Map) { m.Push("", v, kit.Split("type,name,value,values,need,action")) })
|
||||
return DisplayStory(m, "form")
|
||||
}
|
||||
func DisplayInputKey(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayInput(m, "key", arg...)
|
||||
}
|
||||
func DisplayStoryWeight(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayStory(m, "weight", arg...)
|
||||
}
|
||||
func DisplayStoryPie(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayStory(m, "pie", arg...)
|
||||
}
|
||||
func DisplayStoryJSON(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
func DisplayStoryJSON(m displayMessage, arg ...ice.Any) displayMessage {
|
||||
return DisplayStory(m, "json", arg...)
|
||||
}
|
||||
func DisplayStorySpide(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
func DisplayStorySpide(m displayMessage, arg ...ice.Any) displayMessage {
|
||||
return DisplayStory(m, "spide", arg...)
|
||||
}
|
||||
func DisplayStoryChina(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayStory(m, "china", arg...)
|
||||
}
|
||||
func DisplayStudio(m *ice.Message, cmd ...string) *ice.Message {
|
||||
for i, k := range cmd {
|
||||
kit.If(!strings.Contains(cmd[i], nfs.PT), func() { cmd[i] = m.Prefix(k) })
|
||||
}
|
||||
return DisplayStory(m.Cmdy(COMMAND, cmd), "studio")
|
||||
}
|
||||
func DisplayLocal(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
kit.If(file == "", func() { file = strings.ReplaceAll(strings.TrimPrefix(m.PrefixKey(), "web."), nfs.PT, nfs.PS) })
|
||||
func DisplayLocal(m displayMessage, file string, arg ...ice.Any) displayMessage {
|
||||
kit.If(file == "", func() { file = path.Join(kit.PathName(5), kit.Keys(kit.FileName(5), nfs.JS)) })
|
||||
kit.If(isLocalFile(file), func() { file = path.Join(ice.PLUGIN_LOCAL, file) })
|
||||
return DisplayBase(m, file, arg...)
|
||||
}
|
||||
func DisplayLocalInner(m *ice.Message, arg ...ice.Any) *ice.Message {
|
||||
return DisplayLocal(m, "code/inner", arg...)
|
||||
}
|
||||
func DisplayBase(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
func DisplayBase(m displayMessage, file string, arg ...ice.Any) displayMessage {
|
||||
m.Option(ice.MSG_DISPLAY, kit.MergeURL(kit.Select(kit.ExtChange(file, nfs.JS), file, strings.Contains(file, mdb.QS)), arg...))
|
||||
return Toolkit(m, "")
|
||||
}
|
||||
func DisplayBaseCSS(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
m.Option(ice.MSG_DISPLAY_CSS, kit.MergeURL(kit.Select(kit.ExtChange(file, nfs.CSS), file, strings.Contains(file, mdb.QS)), arg...))
|
||||
return m
|
||||
}
|
||||
func Toolkit(m *ice.Message, arg ...string) *ice.Message {
|
||||
m.OptionDefault(ice.MSG_ONLINE, mdb.Config(m, "online"))
|
||||
return m.Options(ice.MSG_TOOLKIT, kit.Select(mdb.Config(m, mdb.TOOLS), kit.Fields(arg)))
|
||||
func Toolkit(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_TOOLKIT, kit.Select(mdb.Config(m, mdb.TOOLS), kit.Fields(arg)))
|
||||
}
|
||||
|
@ -1,61 +1,78 @@
|
||||
package ctx
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const PROCESS = "process"
|
||||
|
||||
var _process = map[string]ice.Any{}
|
||||
|
||||
func AddProcess(key string, val ice.Any) { _process[key] = val }
|
||||
func _process_args(m *ice.Message, args ice.Any) []string {
|
||||
switch cb := args.(type) {
|
||||
case []string:
|
||||
return cb
|
||||
case string:
|
||||
return []string{cb}
|
||||
case func() string:
|
||||
return []string{cb()}
|
||||
case func() []string:
|
||||
return cb()
|
||||
case func():
|
||||
cb()
|
||||
case []string:
|
||||
return cb
|
||||
case string:
|
||||
return []string{cb}
|
||||
case nil:
|
||||
default:
|
||||
m.ErrorNotImplement(args)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.Message {
|
||||
if cmd = kit.Select(m.ActionKey(), cmd); kit.HasPrefixList(arg, RUN) {
|
||||
if !PodCmd(m, cmd, arg[1:]) && aaa.Right(m, cmd, arg[1:]) {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
func Process(m *ice.Message, key string, args ice.Any, arg ...string) {
|
||||
switch cb := _process[kit.Select(m.ActionKey(), key)].(type) {
|
||||
case string:
|
||||
if !kit.HasPrefixList(arg, ACTION, PROCESS) {
|
||||
m.Cmdy(cb, PROCESS, _process_args(m, args)).Optionv(ice.FIELD_PREFIX, kit.Simple(m.ActionKey(), m.Optionv(ice.FIELD_PREFIX)))
|
||||
} else {
|
||||
m.Cmdy(cb, arg)
|
||||
}
|
||||
return m
|
||||
default:
|
||||
ProcessField(m, key, args, arg...)
|
||||
}
|
||||
args = kit.Format(_process_args(m, args))
|
||||
if PodCmd(m, COMMAND, cmd) {
|
||||
m.Push(ice.SPACE, m.Option(ice.MSG_USERPOD))
|
||||
}
|
||||
func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.Message {
|
||||
if cmd = kit.Select(m.ActionKey(), cmd); !kit.HasPrefixList(arg, ice.RUN) {
|
||||
m.Cmdy(COMMAND, cmd).Push(ARGS, kit.Format(_process_args(m, args))).Options(ice.MSG_INDEX, m.PrefixKey()).ProcessField(ACTION, m.ActionKey(), ice.RUN)
|
||||
} else {
|
||||
m.Cmdy(COMMAND, cmd)
|
||||
}
|
||||
if m.Push(ARGS, args); m.IsMetaKey() {
|
||||
m.Push(STYLE, html.FLOAT)
|
||||
}
|
||||
if m.ActionKey() == "" {
|
||||
m.ProcessField(ACTION, RUN, cmd)
|
||||
} else {
|
||||
m.ProcessField(ACTION, m.ActionKey(), RUN)
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
m.Options(ice.POD, "").Cmdy("web.space", pod, cmd, arg[1:])
|
||||
} else {
|
||||
kit.If(aaa.Right(m, cmd, arg[1:]), func() { m.Cmdy(cmd, arg[1:]) })
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
func ProcessFloat(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.Message {
|
||||
if m.IsMetaKey() {
|
||||
m.ProcessOpen(path.Join("/c/", cmd, path.Join(_process_args(m, args)...)))
|
||||
return m
|
||||
} else if !kit.HasPrefixList(arg, RUN) {
|
||||
defer m.Push(STYLE, html.FLOAT)
|
||||
}
|
||||
return ProcessField(m, cmd, args, arg...)
|
||||
func ProcessFloat(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(COMMAND, arg[0]).Options(ice.MSG_PROCESS, ice.PROCESS_FLOAT, ice.PROCESS_ARG, arg)
|
||||
}
|
||||
func ProcessCommand(m *ice.Message, cmd string, args []string, arg ...string) {
|
||||
if !kit.HasPrefixList(arg, ice.RUN) {
|
||||
m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(args)).ProcessField(cmd, ice.RUN)
|
||||
} else {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
}
|
||||
}
|
||||
func ProcessCmds(m *ice.Message, cmd string, arg ...string) {
|
||||
m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(arg)).ProcessField(ACTION, ice.RUN, cmd)
|
||||
}
|
||||
|
||||
func ProcessRefresh(m *ice.Message, arg ...string) { m.ProcessRefresh(arg...) }
|
||||
func ProcessRewrite(m *ice.Message, arg ...ice.Any) { m.ProcessRewrite(arg...) }
|
||||
func ProcessHold(m *ice.Message, text ...ice.Any) { m.Process(ice.PROCESS_HOLD, text...) }
|
||||
func ProcessOpen(m *ice.Message, url string) { m.Process(ice.PROCESS_OPEN, url) }
|
||||
|
||||
func ProcessAction() ice.Actions {
|
||||
return ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { AddProcess(m.CommandKey(), m.PrefixKey()) }},
|
||||
PROCESS: {Hand: func(m *ice.Message, arg ...string) { ProcessField(m, m.PrefixKey(), arg, arg...) }},
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package gdb
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -15,6 +13,8 @@ const (
|
||||
)
|
||||
const EVENT = "event"
|
||||
|
||||
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{
|
||||
@ -25,15 +25,16 @@ func init() {
|
||||
HAPPEN: {Name: "happen event*", Help: "触发", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer m.Cost()
|
||||
m.OptionCB(mdb.SELECT, "")
|
||||
mdb.ZoneSelectAll(m.Spawn(ice.OptionFields("")), arg[1]).Table(func(value ice.Maps) {
|
||||
mdb.ZoneSelect(m.Spawn(ice.OptionFields("")), arg[1]).Table(func(value ice.Maps) {
|
||||
m.Cmdy(kit.Split(value[ice.CMD]), arg[1], arg[2:], ice.OptionFields(""))
|
||||
})
|
||||
_waitMap.Range(func(key, cb ice.Any) bool { cb.(func(*ice.Message, ...string))(m, arg...); return true })
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, EVENT, mdb.FIELDS, "time,id,cmd"), mdb.ClearOnExitHashAction())},
|
||||
}, mdb.ZoneAction(mdb.SHORT, EVENT, mdb.FIELD, "time,id,cmd"), mdb.ClearOnExitHashAction())},
|
||||
})
|
||||
}
|
||||
|
||||
func EventAction(arg ...string) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, _ ...string) { kit.For(arg, func(k string) { Watch(m, k) }) }}}
|
||||
}
|
||||
func EventsAction(arg ...string) ice.Actions {
|
||||
list := kit.DictList(arg...)
|
||||
return ice.Actions{ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -42,34 +43,17 @@ func EventsAction(arg ...string) ice.Actions {
|
||||
}
|
||||
}}}
|
||||
}
|
||||
|
||||
var list map[string]int = map[string]int{}
|
||||
|
||||
func Watch(m *ice.Message, key string, arg ...string) *ice.Message {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, m.ShortKey()) })
|
||||
return m.Cmd(Prefix(EVENT), LISTEN, EVENT, key, ice.CMD, kit.Join(arg, ice.SP))
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, m.PrefixKey()) })
|
||||
return m.Cmd(EVENT, LISTEN, EVENT, key, ice.CMD, kit.Join(arg, ice.SP))
|
||||
}
|
||||
func Event(m *ice.Message, key string, arg ...ice.Any) *ice.Message {
|
||||
if key = kit.Select(kit.Keys(m.CommandKey(), m.ActionKey()), key); list[key] == 0 {
|
||||
if list[key] == 0 {
|
||||
return m
|
||||
}
|
||||
return m.Cmdy(Prefix(EVENT), HAPPEN, EVENT, key, arg, logs.FileLineMeta(-1))
|
||||
return m.Cmdy(EVENT, HAPPEN, EVENT, kit.Select(kit.Keys(m.CommandKey(), m.ActionKey()), key), arg, logs.FileLineMeta(-1))
|
||||
}
|
||||
func EventDeferEvent(m *ice.Message, key string, arg ...ice.Any) func(string, ...ice.Any) {
|
||||
Event(m, key, arg...)
|
||||
return func(key string, args ...ice.Any) { Event(m, key, args...) }
|
||||
}
|
||||
|
||||
var _waitMap = sync.Map{}
|
||||
|
||||
func WaitEvent(m *ice.Message, key string, cb func(*ice.Message, ...string) bool) {
|
||||
wg := sync.WaitGroup{}
|
||||
h := kit.HashsUniq()
|
||||
defer _waitMap.Delete(h)
|
||||
_waitMap.Store(h, func(m *ice.Message, arg ...string) {
|
||||
m.Info("WaitEvent %v %v", key, kit.FileLine(cb, 3))
|
||||
kit.If((key == "" || m.Option(EVENT) == key) && cb(m, arg...), func() { wg.Done() })
|
||||
})
|
||||
wg.Add(1)
|
||||
defer wg.Wait()
|
||||
}
|
||||
|
@ -15,22 +15,20 @@ import (
|
||||
|
||||
type Frame struct{ s chan os.Signal }
|
||||
|
||||
func (f *Frame) Begin(m *ice.Message, arg ...string) {
|
||||
f.s = make(chan os.Signal, 10)
|
||||
}
|
||||
func (f *Frame) Begin(m *ice.Message, arg ...string) { f.s = make(chan os.Signal, 10) }
|
||||
func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
if ice.HasVar() {
|
||||
if f, p, e := logs.CreateFile(ice.VAR_LOG_ICE_PID); e == nil {
|
||||
kit.If(ice.Info.PidPath, func(p string) {
|
||||
if f, p, e := logs.CreateFile(p); e == nil {
|
||||
defer f.Close()
|
||||
m.Logs("save", "file", p, PID, os.Getpid())
|
||||
fmt.Fprint(f, os.Getpid())
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
t := time.NewTicker(kit.Duration(mdb.Conf(m, TIMER, kit.Keym(TICK))))
|
||||
})
|
||||
t := kit.Duration(mdb.Conf(m, TIMER, kit.Keym(TICK)))
|
||||
for {
|
||||
select {
|
||||
case <-t.C:
|
||||
m.Options(ice.LOG_DISABLE, ice.TRUE).Cmd(TIMER, HAPPEN)
|
||||
case <-time.Tick(t):
|
||||
m.Cmd(TIMER, HAPPEN, kit.Dict(ice.LOG_DISABLE, ice.TRUE))
|
||||
case s, ok := <-f.s:
|
||||
if !ok {
|
||||
return
|
||||
@ -39,9 +37,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func (f *Frame) Close(m *ice.Message, arg ...string) {
|
||||
close(f.s)
|
||||
}
|
||||
func (f *Frame) Close(m *ice.Message, arg ...string) { close(f.s) }
|
||||
func (f *Frame) listen(m *ice.Message, s int, arg ...string) {
|
||||
signal.Notify(f.s, syscall.Signal(s))
|
||||
mdb.HashCreate(m, SIGNAL, s, arg)
|
||||
@ -51,6 +47,4 @@ const GDB = "gdb"
|
||||
|
||||
var Index = &ice.Context{Name: GDB, Help: "事件模块"}
|
||||
|
||||
func Prefix(arg ...string) string { return kit.Keys(GDB, arg) }
|
||||
|
||||
func init() { ice.Index.Register(Index, &Frame{}, SIGNAL, EVENT, TIMER, ROUTINE) }
|
||||
|
@ -11,7 +11,7 @@ const ROUTINE = "routine"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ROUTINE: {Help: "协程池", Actions: ice.MergeActions(ice.Actions{
|
||||
ROUTINE: {Name: "routine hash auto prunes", Help: "协程池", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create name cmd", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Go(func() {
|
||||
cb := m.OptionCB("")
|
||||
@ -19,7 +19,7 @@ func init() {
|
||||
h := mdb.HashCreate(m, m.OptionSimple(mdb.NAME, ice.CMD), mdb.STATUS, START)
|
||||
defer func() {
|
||||
if e := recover(); e == nil {
|
||||
mdb.HashRemove(m, mdb.HASH, h)
|
||||
mdb.HashModify(m, mdb.HASH, h, mdb.STATUS, STOP)
|
||||
} else {
|
||||
mdb.HashModify(m, mdb.HASH, h, mdb.STATUS, ERROR, ERROR, e)
|
||||
}
|
||||
@ -38,9 +38,9 @@ func init() {
|
||||
}
|
||||
}, m.Option(mdb.NAME))
|
||||
}},
|
||||
}, mdb.StatusHashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.FIELD, "time,hash,status,name,cmd"), mdb.ClearOnExitHashAction())},
|
||||
}, mdb.StatusHashAction(mdb.FIELD, "time,hash,status,name,cmd"), mdb.ClearOnExitHashAction())},
|
||||
})
|
||||
}
|
||||
func Go(m *ice.Message, cb ice.Any, arg ...string) {
|
||||
m.Cmd(ROUTINE, mdb.CREATE, kit.Select(m.ShortKey(), arg, 0), logs.FileLine(cb), cb)
|
||||
m.Cmd(ROUTINE, mdb.CREATE, kit.Select(m.PrefixKey(), arg, 0), logs.FileLine(cb), cb)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package gdb
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"syscall"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
@ -20,7 +21,13 @@ func _signal_action(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m.Spawn(), arg...).Table(func(value ice.Maps) { m.Cmdy(kit.Split(value[ice.CMD])) })
|
||||
}
|
||||
func _signal_process(m *ice.Message, p string, s os.Signal) {
|
||||
kit.If(p == "", func() { b, _ := file.ReadFile(ice.VAR_LOG_ICE_PID); p = string(b) })
|
||||
if p == "" {
|
||||
b, _ := file.ReadFile(ice.Info.PidPath)
|
||||
p = string(b)
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
}
|
||||
}
|
||||
if p, e := os.FindProcess(kit.Int(kit.Select(kit.Format(os.Getpid()), p))); e == nil {
|
||||
p.Signal(s)
|
||||
}
|
||||
@ -41,26 +48,31 @@ const SIGNAL = "signal"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SIGNAL: {Help: "信号量", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { _signal_init(m, arg...) }},
|
||||
SIGNAL: {Name: "signal signal auto listen", Help: "信号量", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
}
|
||||
_signal_listen(m, 2, mdb.NAME, "重启", ice.CMD, "exit 1")
|
||||
_signal_listen(m, 3, mdb.NAME, "退出", ice.CMD, "exit 0")
|
||||
}},
|
||||
LISTEN: {Name: "listen signal name cmd", Help: "监听", Hand: func(m *ice.Message, arg ...string) {
|
||||
_signal_listen(m, kit.Int(m.Option(SIGNAL)), arg...)
|
||||
}},
|
||||
HAPPEN: {Name: "happen signal", Help: "触发", Hand: func(m *ice.Message, arg ...string) {
|
||||
_signal_action(m, m.Option(SIGNAL))
|
||||
}},
|
||||
RESTART: {Name: "restart pid", Hand: func(m *ice.Message, arg ...string) {
|
||||
RESTART: {Name: "restart pid", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||
_signal_process(m, m.Option(PID), syscall.SIGINT)
|
||||
}},
|
||||
STOP: {Name: "stop pid", Hand: func(m *ice.Message, arg ...string) {
|
||||
STOP: {Name: "stop pid", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
||||
_signal_process(m, m.Option(PID), syscall.SIGQUIT)
|
||||
}},
|
||||
KILL: {Name: "kill pid signal", Hand: func(m *ice.Message, arg ...string) {
|
||||
KILL: {Name: "kill pid signal", Help: "结束", Hand: func(m *ice.Message, arg ...string) {
|
||||
_signal_process(m, m.Option(PID), syscall.Signal(kit.Int(kit.Select("9", m.Option(SIGNAL)))))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, SIGNAL, mdb.FIELD, "time,signal,name,cmd", mdb.ACTION, HAPPEN), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
defer kit.If(len(arg) == 0, func() { m.Action(LISTEN) })
|
||||
mdb.HashSelect(m, arg...)
|
||||
mdb.HashSelect(m, arg...).Sort(SIGNAL)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package gdb
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _signal_init(m *ice.Message, arg ...string) {
|
||||
_signal_listen(m, 1, mdb.NAME, START, ice.CMD, "runtime")
|
||||
_signal_listen(m, 2, mdb.NAME, RESTART, ice.CMD, "exit 1")
|
||||
_signal_listen(m, 3, mdb.NAME, STOP, ice.CMD, "exit 0")
|
||||
_signal_listen(m, int(syscall.SIGUSR1), mdb.NAME, "info", ice.CMD, "runtime")
|
||||
}
|
||||
func SignalProcess(m *ice.Message, pid string) bool {
|
||||
if proc, err := os.FindProcess(kit.Int(pid)); err == nil && proc.Signal(syscall.SIGUSR1) == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
package gdb
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _signal_init(m *ice.Message, arg ...string) {
|
||||
_signal_listen(m, 1, mdb.NAME, START, ice.CMD, "runtime")
|
||||
_signal_listen(m, 2, mdb.NAME, RESTART, ice.CMD, "exit 1")
|
||||
_signal_listen(m, 3, mdb.NAME, STOP, ice.CMD, "exit 0")
|
||||
_signal_listen(m, int(syscall.SIGUSR1), mdb.NAME, "info", ice.CMD, "runtime")
|
||||
}
|
||||
func SignalProcess(m *ice.Message, pid string) bool {
|
||||
if proc, err := os.FindProcess(kit.Int(pid)); err == nil && proc.Signal(syscall.SIGUSR1) == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package gdb
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
)
|
||||
|
||||
func _signal_init(m *ice.Message, arg ...string) {
|
||||
_signal_listen(m, 1, mdb.NAME, START, ice.CMD, "runtime")
|
||||
_signal_listen(m, 2, mdb.NAME, RESTART, ice.CMD, "exit 1")
|
||||
_signal_listen(m, 3, mdb.NAME, STOP, ice.CMD, "exit 0")
|
||||
}
|
||||
func SignalProcess(m *ice.Message, pid string) bool {
|
||||
return false
|
||||
}
|
@ -5,20 +5,17 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _timer_action(m *ice.Message, now time.Time, arg ...string) {
|
||||
mdb.HashSelects(m).Table(func(value ice.Maps) {
|
||||
count := kit.Int(value[mdb.COUNT])
|
||||
if count == 0 || value[mdb.TIME] > now.Format(ice.MOD_TIME) {
|
||||
if value[mdb.COUNT] == "0" || value[mdb.TIME] > now.Format(ice.MOD_TIME) {
|
||||
return
|
||||
}
|
||||
m.Options(ice.LOG_DISABLE, ice.FALSE)
|
||||
m.Cmd(kit.Split(value[ice.CMD])).Cost()
|
||||
kit.If(count < 0, func() { count++ })
|
||||
mdb.HashModify(m, mdb.NAME, value[mdb.NAME], mdb.COUNT, count-1, mdb.TIME, m.Time(value[INTERVAL]))
|
||||
m.Option(ice.LOG_DISABLE, ice.FALSE)
|
||||
m.Cmd(ROUTINE, mdb.CREATE, mdb.NAME, value[mdb.NAME], kit.Keycb(ROUTINE), value[ice.CMD])
|
||||
mdb.HashModify(m, mdb.HASH, value[mdb.HASH], mdb.COUNT, kit.Int(value[mdb.COUNT])-1, mdb.TIME, m.Time(value[INTERVAL]))
|
||||
})
|
||||
}
|
||||
|
||||
@ -31,22 +28,11 @@ const TIMER = "timer"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TIMER: {Help: "定时器", Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(DELAY, "延时", INTERVAL, "间隔", TICK, "周期")),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case mdb.COUNT:
|
||||
m.Push(arg[0], "-1")
|
||||
case ice.CMD:
|
||||
m.Push(arg[0], "cli.procstat insert")
|
||||
}
|
||||
}},
|
||||
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.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...) }},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,delay,interval,count,cmd", TICK, "10s")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).StatusTimeCount(mdb.ConfigSimple(m, TICK))
|
||||
}},
|
||||
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, "1s"))},
|
||||
})
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package lex
|
||||
|
||||
const (
|
||||
PATTERN = "pattern"
|
||||
EXTREG = "extreg"
|
||||
REGEXP = "regexp"
|
||||
PREFIX = "prefix"
|
||||
SUFFIX = "suffix"
|
||||
|
@ -17,7 +17,7 @@ func _split_tab(text string) (tab int) {
|
||||
case ' ':
|
||||
tab++
|
||||
default:
|
||||
return
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
@ -34,7 +34,6 @@ func _split_list(m *ice.Message, file string, arg ...string) ice.Map {
|
||||
const INDENT = "_indent"
|
||||
stack, indent := []int{}, 0
|
||||
list, line := kit.List(kit.Data(INDENT, -1)), ""
|
||||
err := false
|
||||
m.Cmd(nfs.CAT, file, func(text string) {
|
||||
if strings.TrimSpace(text) == "" {
|
||||
return
|
||||
@ -48,9 +47,6 @@ func _split_list(m *ice.Message, file string, arg ...string) ice.Map {
|
||||
stack, indent = _split_deep(stack, text)
|
||||
data := kit.Data(INDENT, indent)
|
||||
ls := kit.Split(text, m.Option(SPLIT_SPACE), m.Option(SPLIT_BLOCK), m.Option(SPLIT_QUOTE), m.Option(SPLIT_TRANS))
|
||||
if err {
|
||||
return
|
||||
}
|
||||
switch cb := m.OptionCB(SPLIT).(type) {
|
||||
case func(int, []string):
|
||||
cb(indent, ls)
|
||||
@ -67,13 +63,8 @@ func _split_list(m *ice.Message, file string, arg ...string) ice.Map {
|
||||
ls = cb(ls)
|
||||
case func([]string):
|
||||
cb(ls)
|
||||
case func(string, []string):
|
||||
cb(text, ls)
|
||||
case func(int, string, []string):
|
||||
cb(indent, text, ls)
|
||||
case nil:
|
||||
default:
|
||||
err = true
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
kit.For(arg, func(k string) {
|
||||
@ -105,7 +96,6 @@ const (
|
||||
SPLIT_QUOTE = "split.quote"
|
||||
SPLIT_TRANS = "split.trans"
|
||||
)
|
||||
const PARSE = "parse"
|
||||
const SPLIT = "split"
|
||||
|
||||
func init() {
|
||||
@ -113,9 +103,9 @@ func init() {
|
||||
SPLIT: {Name: "split path key auto", Help: "分词", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], nfs.PS) {
|
||||
m.Cmdy(nfs.DIR, arg)
|
||||
} else {
|
||||
m.Echo(kit.Format(_split_list(m, arg[0], kit.Split(kit.Join(arg[1:]))...)))
|
||||
return
|
||||
}
|
||||
m.Echo(kit.Format(_split_list(m, arg[0], kit.Split(kit.Join(arg[1:]))...)))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
|
||||
const BENCH = "bench"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
BENCH: {Help: "记录", Hand: func(m *ice.Message, arg ...string) {}},
|
||||
})
|
||||
}
|
@ -1,13 +1,11 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -15,80 +13,74 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _debug_file(k string) string { return ice.VAR_LOG + k + ".log" }
|
||||
|
||||
const DEBUG = "debug"
|
||||
|
||||
func _debug_file(k string) string { return ice.VAR_LOG + k + ".log" }
|
||||
|
||||
func init() {
|
||||
const (
|
||||
LEVEL = "level"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DEBUG: {Name: "debug level=error,bench,debug,error,watch offset limit auto reset app doc", Help: "日志", Actions: ice.Actions{
|
||||
DEBUG: {Name: "debug level=error,bench,debug,error,watch offset limit filter auto reset doc", Help: "后台日志", Actions: ice.Actions{
|
||||
"doc": {Help: "文档", Hand: func(m *ice.Message, arg ...string) { m.ProcessOpen("https://pkg.go.dev/std") }},
|
||||
"reset": {Help: "重置", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(nfs.CAT, _debug_file(arg[0]), func(line string, index int) { m.ProcessRewrite(mdb.OFFSET, index+2, mdb.LIMIT, 1000) })
|
||||
}},
|
||||
"app": {Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.OpenCmds(m, kit.Format("cd %s", kit.Path("")), "tail -f var/log/bench.log")
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
r := regexp.MustCompile("{.*}")
|
||||
offset, limit := kit.Int(kit.Select("0", arg, 1)), kit.Int(kit.Select("100", arg, 2))
|
||||
offset, limit, stats := kit.Int(kit.Select("0", arg, 1)), kit.Int(kit.Select("1000", arg, 2)), map[string]int{}
|
||||
switch arg[0] {
|
||||
case BENCH, ERROR, DEBUG:
|
||||
m.Cmd(nfs.CAT, _debug_file(arg[0]), func(text string, index int) {
|
||||
if index < offset || index >= offset+limit || !strings.Contains(text, kit.Select("", arg, 3)) {
|
||||
m.Cmd(nfs.CAT, _debug_file(arg[0]), func(line string, index int) {
|
||||
if index < offset || index >= offset+limit || !strings.Contains(line, kit.Select("", arg, 3)) {
|
||||
return
|
||||
}
|
||||
ls := strings.SplitN(strings.ReplaceAll(strings.ReplaceAll(text, " ", " "), " ", " "), lex.SP, 8)
|
||||
if _, e := time.Parse(kit.Split(ice.MOD_TIMES)[0], ls[0]); e != nil || len(ls) < 8 {
|
||||
m.Push(mdb.TIME, "").Push(ice.LOG_TRACEID, "").Push(mdb.ID, "")
|
||||
ls := strings.SplitN(line, lex.SP, 6)
|
||||
if _, e := time.Parse(kit.Split(ice.MOD_TIMES)[0], ls[0]); e != nil || len(ls) < 6 {
|
||||
m.Push(mdb.TIME, "").Push(mdb.ID, "")
|
||||
m.Push(nfs.PATH, "").Push(nfs.FILE, "").Push(nfs.LINE, "")
|
||||
m.Push(ctx.SHIP, "").Push(LEVEL, "").Push(nfs.CONTENT, text)
|
||||
m.Push(ctx.SHIP, "").Push(LEVEL, "").Push(nfs.CONTENT, line)
|
||||
return
|
||||
}
|
||||
m.Push(mdb.TIME, ls[0]+lex.SP+ls[1]).Push(ice.LOG_TRACEID, ls[3]).Push(mdb.ID, ls[4])
|
||||
m.Push(mdb.TIME, ls[0]+lex.SP+ls[1]).Push(mdb.ID, ls[2])
|
||||
m.Push(nfs.PATH, ice.USR_ICEBERGS)
|
||||
if i := strings.LastIndex(ls[7], lex.SP); strings.HasPrefix(ls[7][i+1:], ice.BASE) || strings.HasPrefix(ls[7][i+1:], ice.CORE) || strings.HasPrefix(ls[7][i+1:], ice.MISC) {
|
||||
m.Push(nfs.FILE, strings.TrimSpace(strings.Split(ls[7][i:], nfs.DF)[0]))
|
||||
m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[7][i:], nfs.DF)[1]))
|
||||
ls[7] = ls[7][:i]
|
||||
} else if strings.HasPrefix(ls[7][i+1:], ice.USR_ICEBERGS) {
|
||||
m.Push(nfs.FILE, strings.TrimPrefix(strings.TrimSpace(strings.Split(ls[7][i:], nfs.DF)[0]), ice.USR_ICEBERGS))
|
||||
m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[7][i:], nfs.DF)[1]))
|
||||
ls[7] = ls[7][:i]
|
||||
if i := strings.LastIndex(ls[5], lex.SP); strings.HasPrefix(ls[5][i+1:], ice.BASE) || strings.HasPrefix(ls[5][i+1:], ice.CORE) || strings.HasPrefix(ls[5][i+1:], ice.MISC) {
|
||||
m.Push(nfs.FILE, strings.TrimSpace(strings.Split(ls[5][i:], nfs.DF)[0]))
|
||||
m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[5][i:], nfs.DF)[1]))
|
||||
ls[5] = ls[5][:i]
|
||||
} else if strings.HasPrefix(ls[5][i+1:], ice.USR_ICEBERGS) {
|
||||
m.Push(nfs.FILE, strings.TrimPrefix(strings.TrimSpace(strings.Split(ls[5][i:], nfs.DF)[0]), ice.USR_ICEBERGS))
|
||||
m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[5][i:], nfs.DF)[1]))
|
||||
ls[5] = ls[5][:i]
|
||||
} else {
|
||||
m.Push(nfs.FILE, "base/web/serve.go").Push(nfs.LINE, "62")
|
||||
}
|
||||
if ls[6] == ice.LOG_CMDS {
|
||||
if ls[4] == ice.LOG_CMDS {
|
||||
_ls := strings.SplitN(ls[5], lex.SP, 2)
|
||||
if ls[6], ls[7] = _ls[0], _ls[1]; !unicode.IsDigit(rune(ls[7][0])) {
|
||||
_ls := strings.SplitN(ls[7], lex.SP, 2)
|
||||
ls[6], ls[7] = ls[6]+lex.SP+_ls[0], _ls[1]
|
||||
if ls[4], ls[5] = _ls[0], _ls[1]; !unicode.IsDigit(rune(ls[5][0])) {
|
||||
_ls := strings.SplitN(ls[5], lex.SP, 2)
|
||||
ls[4], ls[5] = ls[4]+lex.SP+_ls[0], _ls[1]
|
||||
}
|
||||
}
|
||||
switch ls[6] {
|
||||
case "recv", "done", "send", "echo":
|
||||
ls[7] += "\n" + kit.Formats(kit.UnMarshal(r.FindString(ls[7])))
|
||||
}
|
||||
m.Push(ctx.SHIP, ls[5]).Push(LEVEL, ls[6]).Push(nfs.CONTENT, ls[7])
|
||||
m.Push(ctx.SHIP, ls[3]).Push(LEVEL, ls[4]).Push(nfs.CONTENT, ls[5])
|
||||
stats[ls[4]]++
|
||||
})
|
||||
case WATCH:
|
||||
m.Cmd(nfs.CAT, ice.VAR_LOG+arg[0]+".log", func(text string, index int) {
|
||||
if index < offset || index >= offset+limit || !strings.Contains(text, kit.Select("", arg, 3)) {
|
||||
m.Cmd(nfs.CAT, ice.VAR_LOG+arg[0]+".log", func(line string, index int) {
|
||||
if len(arg) > 2 && !strings.Contains(line, arg[2]) || index < offset {
|
||||
return
|
||||
}
|
||||
ls := strings.SplitN(strings.ReplaceAll(strings.ReplaceAll(text, " ", " "), " ", " "), lex.SP, 8)
|
||||
m.Push(mdb.TIME, ls[0]+lex.SP+ls[1]).Push(ice.LOG_TRACEID, ls[3]).Push(mdb.ID, ls[4])
|
||||
i := strings.LastIndex(ls[7], lex.SP)
|
||||
ls := strings.SplitN(line, lex.SP, 6)
|
||||
m.Push(mdb.TIME, ls[0]+lex.SP+ls[1]).Push(mdb.ID, ls[2])
|
||||
i := strings.LastIndex(ls[5], lex.SP)
|
||||
m.Push(nfs.PATH, ice.USR_ICEBERGS)
|
||||
m.Push(nfs.FILE, strings.TrimSpace(strings.Split(ls[7][i:], nfs.DF)[0]))
|
||||
m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[7][i:], nfs.DF)[1]))
|
||||
m.Push(ctx.SHIP, ls[5]).Push(LEVEL, ls[6]).Push(nfs.CONTENT, ls[7][:i])
|
||||
m.Push(nfs.FILE, strings.TrimSpace(strings.Split(ls[5][i:], nfs.DF)[0]))
|
||||
m.Push(nfs.LINE, strings.TrimSpace(strings.Split(ls[5][i:], nfs.DF)[1]))
|
||||
m.Push(ctx.SHIP, ls[3]).Push(LEVEL, ls[4]).Push(nfs.CONTENT, ls[5][:i])
|
||||
stats[ls[4]]++
|
||||
})
|
||||
}
|
||||
m.StatusTimeCountStats(LEVEL)
|
||||
m.StatusTimeCountTotal(offset+m.Length(), stats)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ const ERROR = "error"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ERROR: {Help: "错误", Hand: func(m *ice.Message, arg ...string) {
|
||||
ERROR: {Name: "error auto", Help: "错误", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(nfs.CAT, path.Join(ice.VAR_LOG, "error.log"))
|
||||
}},
|
||||
})
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
@ -16,30 +14,24 @@ import (
|
||||
)
|
||||
|
||||
type Log struct {
|
||||
c bool
|
||||
p, l, s string
|
||||
p string
|
||||
l string
|
||||
s string
|
||||
}
|
||||
|
||||
type Frame struct{ p chan *Log }
|
||||
|
||||
func (f *Frame) Begin(m *ice.Message, arg ...string) {
|
||||
f.p = make(chan *Log, ice.MOD_BUFS)
|
||||
ice.Info.Log = func(m *ice.Message, p, l, s string) { f.p <- &Log{p: p, l: l, s: s} }
|
||||
}
|
||||
func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
if !ice.HasVar() {
|
||||
return
|
||||
}
|
||||
mdb.Confm(m, FILE, nil, func(k string, v ice.Map) {
|
||||
if mdb.Conf(m, k, kit.Keym(mdb.DISABLE)) == ice.TRUE {
|
||||
return
|
||||
}
|
||||
if f, p, e := logs.CreateFile(kit.Format(v[nfs.PATH])); e == nil {
|
||||
m.Logs(nfs.SAVE, nfs.FILE, p)
|
||||
v[FILE] = bufio.NewWriter(f)
|
||||
}
|
||||
})
|
||||
f.p = make(chan *Log, ice.MOD_BUFS)
|
||||
ice.Info.Log = func(m *ice.Message, p, l, s string) {
|
||||
f.p <- &Log{c: m.Option(ice.LOG_DEBUG) == ice.TRUE, p: p, l: l, s: s}
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case l, ok := <-f.p:
|
||||
@ -50,8 +42,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
if file == "" {
|
||||
return
|
||||
}
|
||||
conf := m.Confv(FILE, file)
|
||||
bio := kit.Value(conf, FILE).(*bufio.Writer)
|
||||
bio := m.Confv(FILE, kit.Keys(file, FILE)).(*bufio.Writer)
|
||||
if bio == nil {
|
||||
return
|
||||
}
|
||||
@ -59,44 +50,43 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
defer fmt.Fprintln(bio)
|
||||
fmt.Fprint(bio, l.p, lex.SP)
|
||||
view := mdb.Confm(m, VIEW, m.Conf(SHOW, kit.Keys(l.l, VIEW)))
|
||||
kit.If(ice.Info.Colors || l.c, func() { bio.WriteString(kit.Format(view[PREFIX])) })
|
||||
defer kit.If(ice.Info.Colors || l.c, func() { bio.WriteString(kit.Format(view[SUFFIX])) })
|
||||
kit.If(ice.Info.Colors, func() { bio.WriteString(kit.Format(view[PREFIX])) })
|
||||
defer kit.If(ice.Info.Colors, func() { bio.WriteString(kit.Format(view[SUFFIX])) })
|
||||
fmt.Fprint(bio, l.l, lex.SP, l.s)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
func (f *Frame) Close(m *ice.Message, arg ...string) { ice.Info.Log = nil; close(f.p) }
|
||||
func (f *Frame) Close(m *ice.Message, arg ...string) {
|
||||
ice.Info.Log = nil
|
||||
close(f.p)
|
||||
}
|
||||
|
||||
const (
|
||||
PREFIX = "prefix"
|
||||
SUFFIX = "suffix"
|
||||
TRACEID = "traceid"
|
||||
PREFIX = "prefix"
|
||||
SUFFIX = "suffix"
|
||||
)
|
||||
const (
|
||||
GREEN = "green"
|
||||
YELLOW = "yellow"
|
||||
RED = "red"
|
||||
)
|
||||
const (
|
||||
BENCH = "bench"
|
||||
)
|
||||
const (
|
||||
FILE = "file"
|
||||
VIEW = "view"
|
||||
SHOW = "show"
|
||||
)
|
||||
const (
|
||||
BENCH_LOG = "bench.log"
|
||||
DEBUG_LOG = "debug.log"
|
||||
ERROR_LOG = "error.log"
|
||||
WATCH_LOG = "watch.log"
|
||||
)
|
||||
const LOG = "log"
|
||||
|
||||
var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
||||
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
|
||||
BENCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, BENCH_LOG), mdb.LIST, []string{}),
|
||||
DEBUG, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, DEBUG_LOG), mdb.LIST, []string{ice.LOG_DEBUG}),
|
||||
ERROR, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, ERROR_LOG), mdb.LIST, []string{ice.LOG_WARN, ice.LOG_ERROR}),
|
||||
WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, WATCH_LOG), mdb.LIST, []string{mdb.CREATE, mdb.REMOVE, mdb.INSERT, mdb.DELETE, mdb.MODIFY, mdb.EXPORT, mdb.IMPORT}),
|
||||
BENCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "bench.log"), mdb.LIST, []string{}),
|
||||
DEBUG, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "debug.log"), mdb.LIST, []string{ice.LOG_DEBUG}),
|
||||
ERROR, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "error.log"), mdb.LIST, []string{ice.LOG_WARN, ice.LOG_ERROR}),
|
||||
WATCH, kit.Dict(nfs.PATH, path.Join(ice.VAR_LOG, "watch.log"), mdb.LIST, []string{mdb.CREATE, mdb.REMOVE, mdb.INSERT, mdb.DELETE, mdb.MODIFY, mdb.EXPORT, mdb.IMPORT}),
|
||||
)},
|
||||
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
||||
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", mdb.LIST, []string{ice.CTX_START, ice.LOG_CMDS}),
|
||||
@ -106,7 +96,7 @@ var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
||||
SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()},
|
||||
}, Commands: ice.Commands{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.Info.Load(m)
|
||||
ice.Info.Load(m, TAIL)
|
||||
mdb.Confm(m, FILE, nil, func(key string, value ice.Map) {
|
||||
kit.For(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, FILE), key) })
|
||||
})
|
||||
@ -114,40 +104,7 @@ var Index = &ice.Context{Name: LOG, Help: "日志模块", Configs: ice.Configs{
|
||||
kit.For(value[mdb.LIST], func(index int, k string) { m.Conf(SHOW, kit.Keys(k, VIEW), key) })
|
||||
})
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.Info.Save(m)
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { ice.Info.Save(m, TAIL) }},
|
||||
}}
|
||||
|
||||
func init() { ice.Index.Register(Index, &Frame{}, TAIL) }
|
||||
|
||||
func init() {
|
||||
ice.Info.Traceid = "short"
|
||||
ice.Pulse.Option("work.id", "0")
|
||||
ice.Pulse.Option("task.id", "0")
|
||||
ice.Pulse.Option(ice.LOG_TRACEID, Traceid(ice.Pulse))
|
||||
}
|
||||
|
||||
var _trace_count int64
|
||||
|
||||
func Traceid(m *ice.Message) (traceid string) {
|
||||
ls := []string{}
|
||||
kit.For(kit.Split(ice.Info.Traceid), func(key string) {
|
||||
switch key {
|
||||
case "short":
|
||||
if len(ls) == 0 {
|
||||
ls = append(ls, kit.Hashs(mdb.UNIQ)[:6])
|
||||
}
|
||||
case "long":
|
||||
if len(ls) == 0 {
|
||||
ls = append(ls, kit.Hashs(mdb.UNIQ))
|
||||
}
|
||||
case "node":
|
||||
ls = append(ls, ice.Info.NodeName)
|
||||
case "hide":
|
||||
ls = ls[:0]
|
||||
}
|
||||
})
|
||||
kit.If(len(ls) > 0, func() { ls = append(ls, kit.Format(atomic.AddInt64(&_trace_count, 1))) })
|
||||
return strings.Join(ls, "-")
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ const TAIL = "tail"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TAIL: {Name: "tail name id auto page", Help: "日志流", Actions: ice.MergeActions(ice.Actions{
|
||||
TAIL: {Name: "tail name id auto page create", Help: "日志流", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m.Spawn(ice.OptionFields("name,file"))).Table(func(value ice.Maps) {
|
||||
m.Cmd("", mdb.CREATE, kit.SimpleKV("name,file", value))
|
||||
@ -35,6 +35,6 @@ func init() {
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) { _tail_create(m, arg...) }},
|
||||
}, mdb.PageZoneAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,file,count", mdb.FIELDS, "time,id,file,size,text"))},
|
||||
}, mdb.PageZoneAction(mdb.SHORT, mdb.NAME, mdb.FIELDS, "time,name,file,count", mdb.FIELD, "time,id,file,size,text"))},
|
||||
})
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ const WATCH = "watch"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
WATCH: {Help: "记录", Hand: func(m *ice.Message, arg ...string) {
|
||||
WATCH: {Name: "watch auto", Help: "记录", Hand: func(m *ice.Message, arg ...string) {
|
||||
stats := map[string]int{}
|
||||
m.Cmd(nfs.CAT, path.Join(ice.VAR_LOG, "watch.log"), func(text string) {
|
||||
ls := kit.Split(text)
|
||||
m.Push(mdb.TIME, ls[0]+lex.SP+ls[1]).Push(mdb.ID, ls[2]).Push(nfs.SOURCE, kit.Slice(ls, -1)[0])
|
||||
m.Push(ctx.SHIP, ls[3]).Push("operate", ls[4]).Push(nfs.CONTENT, kit.Join(kit.Slice(ls, 5, -1), lex.SP))
|
||||
m.Push(ctx.SHIP, ls[3]).Push(ctx.ACTION, ls[4]).Push(nfs.CONTENT, kit.Join(kit.Slice(ls, 5, -1), lex.SP))
|
||||
stats[ls[4]]++
|
||||
})
|
||||
m.StatusTimeCount(stats)
|
||||
|
217
base/mdb/hash.go
217
base/mdb/hash.go
@ -3,12 +3,10 @@ package mdb
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
@ -24,7 +22,7 @@ func _hash_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
kit.For(list, func(k string, i int) { m.Push(field, k).Push(COUNT, i) })
|
||||
m.SortIntR(COUNT)
|
||||
}()
|
||||
defer RLock(m, prefix)()
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, FOREACH, func(key string, value Map) {
|
||||
value = kit.GetMeta(value)
|
||||
list[kit.Format(value[field])] += kit.Int(kit.Select("1", value[COUNT]))
|
||||
@ -32,63 +30,52 @@ func _hash_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
}
|
||||
func _hash_insert(m *ice.Message, prefix, chain string, arg ...string) string {
|
||||
m.Logs(INSERT, KEY, path.Join(prefix, chain), arg)
|
||||
defer Lock(m, prefix)()
|
||||
if expire := m.Conf(prefix, kit.Keys(chain, kit.Keym(EXPIRE))); expire != "" && arg[0] != HASH {
|
||||
defer Lock(m, prefix, chain)()
|
||||
if expire := m.Conf(prefix, kit.Keys(chain, kit.Keym(EXPIRE))); expire != "" {
|
||||
arg = kit.Simple(TIME, m.Time(expire), arg)
|
||||
}
|
||||
if arg[0] == HASH {
|
||||
m.Echo(arg[1]).Conf(prefix, kit.Keys(chain, HASH, arg[1]), kit.Data(arg[2:]))
|
||||
} else {
|
||||
if target, ok := m.Optionv(TARGET).([]string); ok && len(target) == 0 {
|
||||
m.Echo(Rich(m, prefix, chain, kit.Data(arg)))
|
||||
} else {
|
||||
m.Echo(Rich(m, prefix, chain, kit.Data(arg, TARGET, m.Optionv(TARGET))))
|
||||
}
|
||||
m.Echo(Rich(m, prefix, chain, kit.Data(arg, TARGET, m.Optionv(TARGET))))
|
||||
}
|
||||
saveImportant(m, prefix, chain, kit.Simple(INSERT, prefix, chain, HASH, HASH, m.Result(), TIME, m.Time(), arg)...)
|
||||
return m.Result()
|
||||
}
|
||||
func _hash_delete(m *ice.Message, prefix, chain, field, value string) {
|
||||
defer Lock(m, prefix)()
|
||||
defer Lock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, value, func(key string, val Map) {
|
||||
if target, ok := kit.GetMeta(val)[TARGET].(io.Closer); ok {
|
||||
target.Close()
|
||||
}
|
||||
saveImportant(m, prefix, chain, kit.Simple(DELETE, prefix, chain, HASH, HASH, key)...)
|
||||
m.Logs(DELETE, KEY, path.Join(prefix, chain), field, value, VALUE, kit.Format(val))
|
||||
m.Conf(prefix, kit.Keys(chain, HASH, key), "")
|
||||
saveImportant(m, prefix, chain, kit.Simple(DELETE, prefix, chain, HASH, HASH, key)...)
|
||||
})
|
||||
}
|
||||
func _hash_modify(m *ice.Message, prefix, chain string, field, value string, arg ...string) {
|
||||
m.Logs(MODIFY, KEY, path.Join(prefix, chain), field, value, arg)
|
||||
defer Lock(m, prefix)()
|
||||
defer Lock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, value, func(key string, val Map) {
|
||||
_mdb_modify(m, val, field, arg...)
|
||||
saveImportant(m, prefix, chain, kit.Simple(MODIFY, prefix, chain, HASH, HASH, key, arg)...)
|
||||
_mdb_modify(m, val, field, arg...)
|
||||
})
|
||||
}
|
||||
func _hash_select(m *ice.Message, prefix, chain, field, value string) {
|
||||
kit.If(field == HASH && value == RANDOM, func() { value = RANDOMS })
|
||||
defer m.SortStrR(TIME)
|
||||
fields := _hash_fields(m)
|
||||
defer RLock(m, prefix)()
|
||||
if strings.Contains(value, ",") {
|
||||
kit.For(kit.Split(value), func(value string) {
|
||||
Richs(m, prefix, chain, value, func(key string, value Map) { _mdb_select(m, m.OptionCB(""), key, value, fields, nil) })
|
||||
})
|
||||
} else {
|
||||
Richs(m, prefix, chain, value, func(key string, value Map) { _mdb_select(m, m.OptionCB(""), key, value, fields, nil) })
|
||||
}
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, value, func(key string, value Map) { _mdb_select(m, m.OptionCB(""), key, value, fields, nil) })
|
||||
}
|
||||
func _hash_select_field(m *ice.Message, prefix, chain string, key string, field string) (value string) {
|
||||
defer RLock(m, prefix)()
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, key, func(key string, val Map) { value = kit.Select(kit.Format(val[field]), key, field == HASH) })
|
||||
return
|
||||
}
|
||||
func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
fields := _hash_fields(m)
|
||||
kit.If(kit.IndexOf(fields, HASH) == -1, func() { fields = append(fields, HASH) })
|
||||
defer RLock(m, prefix)()
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, FOREACH, func(key string, value Map) {
|
||||
switch value = kit.GetMeta(value); cb := m.OptionCB("").(type) {
|
||||
case func(string, Map) bool:
|
||||
@ -101,41 +88,33 @@ func _hash_prunes(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
})
|
||||
}
|
||||
func _hash_export(m *ice.Message, prefix, chain, file string) {
|
||||
if !ice.HasUsr() {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix)()
|
||||
if len(Confm(m, prefix, kit.Keys(chain, HASH))) == 0 {
|
||||
defer Lock(m, prefix, chain)()
|
||||
count := len(Confm(m, prefix, kit.Keys(chain, HASH)))
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
f, p, e := miss.CreateFile(kit.Keys(file, JSON))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p)
|
||||
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count)
|
||||
en := json.NewEncoder(f)
|
||||
if en.SetIndent("", " "); !m.WarnNotValid(en.Encode(m.Confv(prefix, kit.Keys(chain, HASH))), EXPORT, prefix) {
|
||||
// m.Conf(prefix, kit.Keys(chain, HASH), "")
|
||||
if en.SetIndent("", " "); !m.Warn(en.Encode(m.Confv(prefix, kit.Keys(chain, HASH))), EXPORT, prefix) {
|
||||
m.Conf(prefix, kit.Keys(chain, HASH), "")
|
||||
}
|
||||
}
|
||||
func _hash_import(m *ice.Message, prefix, chain, file string) {
|
||||
if !ice.HasUsr() {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix)()
|
||||
defer Lock(m, prefix, chain)()
|
||||
f, e := miss.OpenFile(kit.Keys(file, JSON))
|
||||
if e != nil && !ice.Info.Important {
|
||||
return
|
||||
} else if m.WarnNotFound(e) {
|
||||
if m.Warn(e) {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
data := Map{}
|
||||
m.Warn(json.NewDecoder(f).Decode(&data))
|
||||
m.Assert(json.NewDecoder(f).Decode(&data))
|
||||
m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, kit.Keys(file, JSON), COUNT, len(data))
|
||||
kit.If(m.Confv(prefix, kit.Keys(chain, HASH)) == nil, func() { m.Confv(prefix, kit.Keys(chain, HASH), ice.Map{}) })
|
||||
defer m.Echo("%d", len(data))
|
||||
kit.For(data, func(k string, v Any) { m.Confv(prefix, kit.Keys(chain, HASH, k), v) })
|
||||
m.Echo("%d", len(data))
|
||||
}
|
||||
|
||||
const (
|
||||
@ -151,15 +130,14 @@ const (
|
||||
const HASH = "hash"
|
||||
|
||||
func HashAction(arg ...Any) ice.Actions {
|
||||
return ice.Actions{
|
||||
ice.CTX_INIT: AutoConfig(append(kit.List(FIELD, HASH_FIELD), arg...)...),
|
||||
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) }},
|
||||
MODIFY: {Hand: func(m *ice.Message, arg ...string) { HashModify(m, arg) }},
|
||||
SELECT: {Hand: func(m *ice.Message, arg ...string) { HashSelect(m, arg...) }},
|
||||
SELECT: {Name: "select hash auto create", Hand: func(m *ice.Message, arg ...string) { HashSelect(m, arg...) }},
|
||||
PRUNES: {Name: "prunes before@date", Hand: func(m *ice.Message, arg ...string) { HashPrunes(m, nil) }},
|
||||
EXPORT: {Hand: func(m *ice.Message, arg ...string) { HashExport(m, arg) }},
|
||||
IMPORT: {Hand: func(m *ice.Message, arg ...string) { HashImport(m, arg) }},
|
||||
@ -167,60 +145,13 @@ func HashAction(arg ...Any) ice.Actions {
|
||||
}
|
||||
func StatusHashAction(arg ...Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
PRUNES: &ice.Action{Name: "prunes status", Hand: func(m *ice.Message, arg ...string) {
|
||||
args := []string{}
|
||||
kit.For(kit.Split(m.OptionDefault(STATUS, "error,close,stop,end")), func(s string) { args = append(args, STATUS, s) })
|
||||
m.Cmdy(PRUNES, m.PrefixKey(), m.Option(SUBKEY), HASH, args, ice.OptionFields(HashField(m)))
|
||||
PRUNES: &ice.Action{Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, STATUS, "error", STATUS, "close", STATUS, "stop", STATUS, "end", ice.OptionFields(HashField(m)))
|
||||
}},
|
||||
}, HashAction(arg...))
|
||||
}
|
||||
func ClearOnExitHashAction() ice.Actions {
|
||||
return ice.Actions{ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { Conf(m, m.PrefixKey(), HASH, "") }}}
|
||||
}
|
||||
func ExportHashAction(arg ...Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { Config(m, IMPORTANT, ice.TRUE); HashImport(m, arg) }},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { HashExport(m, arg) }},
|
||||
}, HashAction(arg...))
|
||||
}
|
||||
|
||||
const (
|
||||
DEV_REQUEST = "devRequest"
|
||||
DEV_CHOOSE = "devChoose"
|
||||
DEV_RESPONSE = "devResponse"
|
||||
DEV_CONFIRM = "devConfirm"
|
||||
DEV_CREATE = "devCreate"
|
||||
)
|
||||
|
||||
func DevDataAction(fields ...string) ice.Actions {
|
||||
const (
|
||||
DAEMON = "daemon"
|
||||
ORIGIN = "origin"
|
||||
BACK = "back"
|
||||
)
|
||||
return ice.Actions{
|
||||
DEV_REQUEST: {Name: "request origin*", Help: "请求", Icon: "bi bi-cloud-download", Hand: func(m *ice.Message, arg ...string) {
|
||||
back := m.Options(ice.MSG_USERWEB, m.Option(ice.MSG_USERHOST)).MergePod("")
|
||||
m.ProcessOpen(m.Options(ice.MSG_USERWEB, m.Option(ORIGIN), ice.MSG_USERPOD, "").MergePodCmd("", m.PrefixKey(), ACTION, DEV_CHOOSE, BACK, back, DAEMON, m.Option(ice.MSG_DAEMON)))
|
||||
}},
|
||||
DEV_CHOOSE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
HashSelect(m.Options(ice.MSG_FIELDS, kit.Join(fields))).PushAction(DEV_RESPONSE).Options(ice.MSG_ACTION, "")
|
||||
}},
|
||||
DEV_RESPONSE: {Help: "选择", Hand: func(m *ice.Message, arg ...string) {
|
||||
if !m.WarnNotAllow(m.Option(ice.MSG_METHOD) != http.MethodPost) {
|
||||
m.ProcessReplace(m.ParseLink(m.Option(BACK)).MergePodCmd("", m.PrefixKey(), ACTION, DEV_CONFIRM, m.OptionSimple(DAEMON), m.OptionSimple(fields...)))
|
||||
}
|
||||
}},
|
||||
DEV_CONFIRM: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoInfoButton(kit.JoinWord(m.PrefixKey(), m.Cmdx("nfs.cat", "src/template/mdb.hash/savefrom.html"), m.Option(kit.Split(fields[0])[0])), DEV_CREATE)
|
||||
}},
|
||||
DEV_CREATE: {Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if !m.WarnNotAllow(m.Option(ice.MSG_METHOD) != http.MethodPost) {
|
||||
defer kit.If(m.Option(DAEMON), func(p string) { m.Cmd("space", p, "refresh") })
|
||||
HashCreate(m.ProcessClose(), m.OptionSimple(fields...))
|
||||
}
|
||||
}},
|
||||
}
|
||||
return ice.MergeActions(ice.Actions{ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { Conf(m, m.PrefixKey(), HASH, "") }}})
|
||||
}
|
||||
|
||||
func HashKey(m *ice.Message) string {
|
||||
@ -230,42 +161,15 @@ func HashKey(m *ice.Message) string {
|
||||
return HashShort(m)
|
||||
}
|
||||
func HashShort(m *ice.Message) string {
|
||||
if m.Option(SHORT) != "" {
|
||||
return m.Option(SHORT)
|
||||
}
|
||||
short := ""
|
||||
if m.Option(SUBKEY) != "" {
|
||||
if short = Conf(m, m.PrefixKey(), kit.Keys(m.Option(SUBKEY), META, SHORT)); short == "" {
|
||||
short = Config(m, SHORTS)
|
||||
}
|
||||
} else {
|
||||
short = Config(m, SHORT)
|
||||
}
|
||||
return kit.Select(HASH, short, short != UNIQ)
|
||||
}
|
||||
func HashField(m *ice.Message) string {
|
||||
if m.Option(FIELD) != "" {
|
||||
return m.Option(FIELD)
|
||||
}
|
||||
field := ""
|
||||
if m.Option(SUBKEY) != "" {
|
||||
if field = Conf(m, m.PrefixKey(), kit.Keys(m.Option(SUBKEY), META, FIELDS)); field == "" {
|
||||
field = Config(m, FIELDS)
|
||||
}
|
||||
} else {
|
||||
field = Config(m, FIELD)
|
||||
}
|
||||
return kit.Select(HASH_FIELD, field)
|
||||
return kit.Select(HASH, Config(m, SHORT), Config(m, SHORT) != UNIQ)
|
||||
}
|
||||
func HashField(m *ice.Message) string { return kit.Select(HASH_FIELD, Config(m, FIELD)) }
|
||||
func HashInputs(m *ice.Message, arg ...Any) *ice.Message {
|
||||
return m.Cmdy(INPUTS, m.PrefixKey(), m.Option(SUBKEY), HASH, arg)
|
||||
return m.Cmdy(INPUTS, m.PrefixKey(), "", HASH, arg)
|
||||
}
|
||||
func HashCreate(m *ice.Message, arg ...Any) string {
|
||||
kit.If(len(arg) == 0 || len(kit.Simple(arg...)) == 0, func() {
|
||||
arg = append(arg, m.OptionSimple(kit.Filters(kit.Split(HashField(m)), TIME, HASH)...))
|
||||
})
|
||||
kit.If(m.Option(SUBKEY) == "", func() { kit.If(Config(m, SHORTS), func(p string) { arg = append([]ice.Any{SHORT, p}, arg) }) })
|
||||
return m.Echo(m.Cmdx(append(kit.List(INSERT, m.PrefixKey(), m.Option(SUBKEY), HASH, logs.FileLineMeta(-1)), arg...)...)).Result()
|
||||
kit.If(len(arg) == 0 || len(kit.Simple(arg...)) == 0, func() { arg = append(arg, m.OptionSimple(strings.Replace(HashField(m), "hash,", "", 1))) })
|
||||
return m.Echo(m.Cmdx(append(kit.List(INSERT, m.PrefixKey(), "", HASH, logs.FileLineMeta(-1)), arg...)...)).Result()
|
||||
}
|
||||
func HashRemove(m *ice.Message, arg ...Any) *ice.Message {
|
||||
if args := kit.Simple(arg...); len(args) == 0 {
|
||||
@ -273,32 +177,30 @@ func HashRemove(m *ice.Message, arg ...Any) *ice.Message {
|
||||
} else if len(args) == 1 {
|
||||
arg = kit.List(HashKey(m), args[0])
|
||||
}
|
||||
return m.Cmdy(DELETE, m.PrefixKey(), m.Option(SUBKEY), HASH, arg)
|
||||
return m.Cmdy(DELETE, m.PrefixKey(), "", HASH, arg)
|
||||
}
|
||||
func HashModify(m *ice.Message, arg ...Any) *ice.Message {
|
||||
if args := kit.Simple(arg...); args[0] != HASH && args[0] != HashShort(m) {
|
||||
arg = append(kit.List(m.OptionSimple(HashKey(m))), arg...)
|
||||
}
|
||||
return m.Cmd(MODIFY, m.PrefixKey(), m.Option(SUBKEY), HASH, arg)
|
||||
return m.Cmd(MODIFY, m.PrefixKey(), "", HASH, arg)
|
||||
}
|
||||
func HashSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
if len(arg) > 0 && (arg[0] == FOREACH || strings.Contains(arg[0], ",")) {
|
||||
if len(arg) > 0 && arg[0] == FOREACH {
|
||||
m.Fields(0, HashField(m))
|
||||
} else {
|
||||
m.Fields(len(kit.Slice(arg, 0, 1)), HashField(m))
|
||||
}
|
||||
m.Cmdy(SELECT, m.PrefixKey(), m.Option(SUBKEY), HASH, HashShort(m), arg, logs.FileLineMeta(-1))
|
||||
kit.If(kit.Select(Config(m, SHORT), Config(m, SORT)), func(sort string) { kit.If(sort != UNIQ, func() { m.Sort(sort) }) })
|
||||
m.Cmdy(SELECT, m.PrefixKey(), "", HASH, HashShort(m), arg, logs.FileLineMeta(-1))
|
||||
if m.PushAction(Config(m, ACTION), REMOVE); !m.FieldsIsDetail() {
|
||||
m.Options(ice.TABLE_CHECKBOX, Config(m, html.CHECKBOX))
|
||||
return m.Action(CREATE)
|
||||
return m.StatusTimeCount()
|
||||
}
|
||||
return sortByField(m, HashField(m), arg...)
|
||||
return m.StatusTime()
|
||||
}
|
||||
func HashPrunes(m *ice.Message, cb func(Map) bool) *ice.Message {
|
||||
expire := kit.Select(m.Time("-"+kit.Select(DAYS, Config(m, EXPIRE))), m.Option("before"))
|
||||
m.OptionCB(PRUNES, func(key string, value Map) bool { return kit.Format(value[TIME]) < expire && (cb == nil || cb(value)) })
|
||||
return m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, ice.OptionFields(HashField(m)))
|
||||
return m.Cmdy(PRUNES, m.PrefixKey(), "", HASH, ice.OptionFields(HashField(m))).StatusTimeCount()
|
||||
}
|
||||
func HashExport(m *ice.Message, arg ...Any) *ice.Message {
|
||||
return m.Cmdy(EXPORT, m.PrefixKey(), "", HASH, arg)
|
||||
@ -319,17 +221,22 @@ func HashSelectValue(m *ice.Message, cb Any) *ice.Message {
|
||||
}
|
||||
func HashSelectUpdate(m *ice.Message, key string, cb Any) *ice.Message {
|
||||
defer Lock(m, m.PrefixKey())()
|
||||
Richs(m, m.PrefixKey(), nil, kit.Select(FOREACH, key), func(key string, value Map) { _mdb_select(m, cb, key, value, nil, nil) })
|
||||
Richs(m, m.PrefixKey(), nil, key, func(key string, value Map) { _mdb_select(m, cb, key, value, nil, nil) })
|
||||
return m
|
||||
}
|
||||
func HashSelectDetail(m *ice.Message, key string, cb Any) (has bool) {
|
||||
defer RLock(m, m.PrefixKey())()
|
||||
Richs(m, m.PrefixKey(), nil, key, func(key string, value Map) { _mdb_select(m, cb, key, value, nil, nil); has = true })
|
||||
Richs(m, m.PrefixKey(), nil, key, func(key string, value Map) {
|
||||
_mdb_select(m, cb, key, value, nil, nil)
|
||||
has = true
|
||||
})
|
||||
return
|
||||
}
|
||||
func HashSelectDetails(m *ice.Message, key string, cb func(Map) bool) Map {
|
||||
val := kit.Dict()
|
||||
HashSelectDetail(m, key, func(value Map) { kit.If(cb(value), func() { kit.For(value, func(k string, v Any) { val[k] = v }) }) })
|
||||
HashSelectDetail(m, key, func(value Map) {
|
||||
kit.If(cb(value), func() { kit.For(value, func(k string, v Any) { val[k] = v }) })
|
||||
})
|
||||
return val
|
||||
}
|
||||
func HashSelectField(m *ice.Message, key string, field string) (value string) {
|
||||
@ -353,7 +260,7 @@ func HashSelectTarget(m *ice.Message, key string, create Any) (target Any) {
|
||||
}
|
||||
switch create := create.(type) {
|
||||
case func(Maps) Any:
|
||||
target = create(kit.ToMaps(value))
|
||||
target = create(ToMaps(value))
|
||||
case func(Map) Any:
|
||||
target = create(value)
|
||||
case func() Any:
|
||||
@ -368,7 +275,7 @@ func HashSelectTarget(m *ice.Message, key string, create Any) (target Any) {
|
||||
func HashSelectClose(m *ice.Message) *ice.Message {
|
||||
HashSelectValue(m, func(value Map) {
|
||||
if c, ok := value[TARGET].(io.Closer); ok {
|
||||
m.WarnNotValid(c.Close())
|
||||
m.Warn(c.Close())
|
||||
}
|
||||
delete(value, TARGET)
|
||||
})
|
||||
@ -391,32 +298,14 @@ func Richs(m *ice.Message, prefix string, chain Any, raw Any, cb Any) (res Map)
|
||||
if cache == nil {
|
||||
return nil
|
||||
}
|
||||
if value := kit.Format(raw); strings.Contains(value, ",") {
|
||||
kit.For(kit.Split(value), func(value string) {
|
||||
res = miss.Richs(path.Join(prefix, kit.Keys(chain)), cache, value, cb)
|
||||
})
|
||||
return
|
||||
}
|
||||
return miss.Richs(path.Join(prefix, kit.Keys(chain)), cache, raw, cb)
|
||||
|
||||
}
|
||||
func Rich(m *ice.Message, prefix string, chain Any, data Any) string {
|
||||
cache := Confm(m, prefix, chain)
|
||||
kit.If(cache == nil, func() { cache = kit.Data(); m.Confv(prefix, chain, cache) })
|
||||
if cache == nil {
|
||||
cache = kit.Data()
|
||||
m.Confv(prefix, chain, cache)
|
||||
}
|
||||
return miss.Rich(path.Join(prefix, kit.Keys(chain)), cache, data)
|
||||
}
|
||||
func sortByField(m *ice.Message, fields string, arg ...string) *ice.Message {
|
||||
return m.Table(func(value ice.Maps) {
|
||||
m.SetAppend().FieldsSetDetail()
|
||||
kit.For(kit.Split(fields), func(key string) {
|
||||
key = strings.TrimSuffix(key, "*")
|
||||
if key == HASH {
|
||||
m.Push(key, kit.Select(value[key], arg, 0))
|
||||
} else {
|
||||
m.Push(key, value[key])
|
||||
}
|
||||
delete(value, key)
|
||||
})
|
||||
kit.For(kit.SortedKey(value), func(k string) { m.Push(k, value[k]) })
|
||||
})
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package mdb
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
@ -21,7 +20,7 @@ func _list_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
kit.For(list, func(k string, i int) { m.Push(field, k).Push(COUNT, i) })
|
||||
m.SortIntR(COUNT)
|
||||
}()
|
||||
defer RLock(m, prefix)()
|
||||
defer RLock(m, prefix, chain)()
|
||||
Grows(m, prefix, chain, "", "", func(value ice.Map) {
|
||||
value = kit.GetMeta(value)
|
||||
list[kit.Format(value[field])] += kit.Int(kit.Select("1", value[COUNT]))
|
||||
@ -29,60 +28,49 @@ func _list_inputs(m *ice.Message, prefix, chain string, field, value string) {
|
||||
}
|
||||
func _list_insert(m *ice.Message, prefix, chain string, arg ...string) {
|
||||
m.Logs(INSERT, KEY, path.Join(prefix, chain), arg)
|
||||
defer Lock(m, prefix)()
|
||||
m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg, TARGET, m.Optionv(TARGET))))
|
||||
defer Lock(m, prefix, chain)()
|
||||
saveImportant(m, prefix, chain, kit.Simple(INSERT, prefix, chain, LIST, TIME, m.Time(), arg)...)
|
||||
m.Echo("%d", Grow(m, prefix, chain, kit.Dict(arg, TARGET, m.Optionv(TARGET))))
|
||||
}
|
||||
func _list_modify(m *ice.Message, prefix, chain string, field, value string, arg ...string) {
|
||||
m.Logs(MODIFY, KEY, path.Join(prefix, chain), field, value, arg)
|
||||
defer Lock(m, prefix)()
|
||||
Grows(m, prefix, chain, field, value, func(index int, val ice.Map) { _mdb_modify(m, val, field, arg...) })
|
||||
defer Lock(m, prefix, chain)()
|
||||
saveImportant(m, prefix, chain, kit.Simple(MODIFY, prefix, chain, LIST, field, value, arg)...)
|
||||
Grows(m, prefix, chain, field, value, func(index int, val ice.Map) { _mdb_modify(m, val, field, arg...) })
|
||||
}
|
||||
func _list_select(m *ice.Message, prefix, chain, field, value string) {
|
||||
defer m.SortIntR(ID)
|
||||
fields := _list_fields(m)
|
||||
defer RLock(m, prefix)()
|
||||
defer RLock(m, prefix, chain)()
|
||||
Grows(m, prefix, chain, kit.Select(m.Option(CACHE_FIELD), field), kit.Select(m.Option(CACHE_VALUE), value), func(value ice.Map) {
|
||||
_mdb_select(m, m.OptionCB(""), "", value, fields, nil)
|
||||
})
|
||||
}
|
||||
func _list_export(m *ice.Message, prefix, chain, file string) {
|
||||
defer Lock(m, prefix)()
|
||||
p := kit.Keys(file, CSV)
|
||||
count := kit.Int(Conf(m, prefix, kit.Keys(chain, META, COUNT)))
|
||||
if count == 0 {
|
||||
if s, e := os.Stat(p); e == nil && !s.IsDir() {
|
||||
os.Remove(p)
|
||||
}
|
||||
return
|
||||
}
|
||||
f, p, e := miss.CreateFile(p)
|
||||
defer Lock(m, prefix, chain)()
|
||||
f, p, e := miss.CreateFile(kit.Keys(file, CSV))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
defer m.Echo(p)
|
||||
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count)
|
||||
w := csv.NewWriter(f)
|
||||
defer w.Flush()
|
||||
head := kit.Split(ListField(m))
|
||||
count, head := 0, kit.Split(ListField(m))
|
||||
Grows(m, prefix, chain, "", "", func(index int, value ice.Map) {
|
||||
if value = kit.GetMeta(value); index == 0 {
|
||||
kit.If(len(head) == 0 || head[0] == ice.FIELDS_DETAIL, func() { head = kit.SortedKey(value) })
|
||||
w.Write(head)
|
||||
}
|
||||
w.Write(kit.Simple(head, func(k string) string { return kit.Format(value[k]) }))
|
||||
count++
|
||||
})
|
||||
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count)
|
||||
m.Conf(prefix, kit.Keys(chain, kit.Keym(COUNT)), 0)
|
||||
m.Conf(prefix, kit.Keys(chain, LIST), "")
|
||||
}
|
||||
func _list_import(m *ice.Message, prefix, chain, file string) {
|
||||
defer Lock(m, prefix)()
|
||||
defer Lock(m, prefix, chain)()
|
||||
f, e := miss.OpenFile(kit.Keys(file, CSV))
|
||||
if e != nil && !ice.Info.Important {
|
||||
return
|
||||
} else if m.WarnNotFound(e) {
|
||||
return
|
||||
}
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
r := csv.NewReader(f)
|
||||
head, _ := r.Read()
|
||||
@ -186,8 +174,8 @@ func OptionPages(m *ice.Message, arg ...string) (page int, size int) {
|
||||
m.Option(CACHE_OFFEND, kit.Select(m.Option(CACHE_OFFEND), arg, 0))
|
||||
m.Option(CACHE_LIMIT, kit.Select(m.Option(CACHE_LIMIT), arg, 1))
|
||||
m.Option(CACHE_FILTER, kit.Select(m.Option(CACHE_FILTER), arg, 2))
|
||||
m.Option(OFFEND, kit.Select(m.Option(OFFEND), arg, 0))
|
||||
m.Option(LIMIT, kit.Select(m.Option(LIMIT), arg, 1))
|
||||
m.Option(LIMIT, kit.Select(m.Option(LIMIT), arg, 0))
|
||||
m.Option(OFFEND, kit.Select(m.Option(OFFEND), arg, 1))
|
||||
size = kit.Int(kit.Select("10", m.Option(LIMIT)))
|
||||
page = kit.Int(m.Option(OFFEND))/size + 1
|
||||
return
|
||||
@ -207,23 +195,31 @@ const (
|
||||
CACHE_FIELD = "cache.field"
|
||||
)
|
||||
|
||||
func Grows(m *ice.Message, prefix string, chain Any, match string, value string, cb Any) Map {
|
||||
type Message interface {
|
||||
Confv(arg ...Any) (val Any)
|
||||
Option(key string, arg ...Any) string
|
||||
}
|
||||
|
||||
func Grows(m Message, prefix string, chain Any, match string, value string, cb Any) Map {
|
||||
cache, ok := m.Confv(prefix, chain).(ice.Map)
|
||||
if cache == nil || !ok {
|
||||
return nil
|
||||
} else if begin, limit := kit.Int(m.Option(CACHE_BEGIN)), kit.Int(m.Option(CACHE_LIMIT)); begin != 0 && limit > 0 {
|
||||
if count := kit.Int(m.Option(CACHE_COUNT, kit.Int(kit.Value(cache, kit.Keym(COUNT))))); count-begin < limit {
|
||||
m.Option(CACHE_OFFEND, 0)
|
||||
m.Option(CACHE_LIMIT, count-begin+1)
|
||||
}
|
||||
limit := kit.Int(m.Option(CACHE_LIMIT))
|
||||
if begin := kit.Int(m.Option(CACHE_BEGIN)); begin != 0 && limit > 0 {
|
||||
count := kit.Int(m.Option(CACHE_COUNT, kit.Int(kit.Value(cache, kit.Keym("count")))))
|
||||
if begin > 0 {
|
||||
m.Option(CACHE_OFFEND, count-begin-limit)
|
||||
} else {
|
||||
m.Option(CACHE_OFFEND, count-begin-limit+1)
|
||||
m.Option(CACHE_OFFEND, -begin-limit)
|
||||
}
|
||||
}
|
||||
return miss.Grows(path.Join(prefix, kit.Keys(chain)), cache,
|
||||
kit.Int(kit.Select("0", strings.TrimPrefix(m.Option(CACHE_OFFEND), "-"))),
|
||||
kit.Int(kit.Select("10", m.Option(CACHE_LIMIT))), match, value, cb)
|
||||
kit.Int(kit.Select("10", m.Option(CACHE_LIMIT))),
|
||||
match, value, cb)
|
||||
}
|
||||
func Grow(m *ice.Message, prefix string, chain Any, data Any) int {
|
||||
func Grow(m Message, prefix string, chain Any, data Any) int {
|
||||
cache, ok := m.Confv(prefix, chain).(ice.Map)
|
||||
if cache == nil || !ok {
|
||||
cache = kit.Data()
|
||||
|
@ -8,37 +8,38 @@ import (
|
||||
"shylinux.com/x/toolkits/task"
|
||||
)
|
||||
|
||||
type configMessage interface {
|
||||
Option(key string, arg ...Any) string
|
||||
PrefixKey(...string) string
|
||||
Confv(...Any) Any
|
||||
}
|
||||
|
||||
var _lock = task.Lock{}
|
||||
var _locks = map[string]*task.Lock{}
|
||||
|
||||
func getLock(m *ice.Message, arg ...string) *task.Lock {
|
||||
func getLock(m configMessage, arg ...string) *task.Lock {
|
||||
key := kit.Select(m.PrefixKey(), kit.Keys(arg))
|
||||
defer _lock.Lock()()
|
||||
l, ok := _locks[key]
|
||||
kit.If(!ok, func() { l = &task.Lock{}; _locks[key] = l })
|
||||
if !ok {
|
||||
l = &task.Lock{}
|
||||
_locks[key] = l
|
||||
}
|
||||
return l
|
||||
}
|
||||
func Lock(m *ice.Message, arg ...string) func() {
|
||||
return getLock(m, arg...).Lock()
|
||||
}
|
||||
func RLock(m *ice.Message, arg ...string) func() {
|
||||
return getLock(m, arg...).RLock()
|
||||
}
|
||||
func Lock(m configMessage, arg ...string) func() { return getLock(m, arg...).Lock() }
|
||||
func RLock(m configMessage, arg ...string) func() { return getLock(m, arg...).RLock() }
|
||||
|
||||
func ConfigSimple(m *ice.Message, key ...string) (res []string) {
|
||||
for _, key := range key {
|
||||
res = append(res, key, kit.Format(Configv(m, key)))
|
||||
}
|
||||
return
|
||||
}
|
||||
func Config(m *ice.Message, key string, arg ...Any) string {
|
||||
func Config(m configMessage, key string, arg ...Any) string {
|
||||
return kit.Format(Configv(m, key, arg...))
|
||||
}
|
||||
func Configv(m *ice.Message, key string, arg ...Any) Any {
|
||||
kit.If(len(arg) > 0, func() { Confv(m, m.PrefixKey(), kit.Keym(key), arg[0]) })
|
||||
func Configv(m configMessage, key string, arg ...Any) Any {
|
||||
if len(arg) > 0 {
|
||||
Confv(m, m.PrefixKey(), kit.Keym(key), arg[0])
|
||||
}
|
||||
return Confv(m, m.PrefixKey(), kit.Keym(key))
|
||||
}
|
||||
func Confv(m *ice.Message, arg ...Any) Any {
|
||||
func Confv(m configMessage, arg ...Any) Any {
|
||||
key := kit.Select(m.PrefixKey(), kit.Format(arg[0]))
|
||||
if ctx, ok := ice.Info.Index[key].(*ice.Context); ok {
|
||||
key = ctx.Prefix(key)
|
||||
@ -50,10 +51,14 @@ func Confv(m *ice.Message, arg ...Any) Any {
|
||||
}
|
||||
return m.Confv(arg...)
|
||||
}
|
||||
func Conf(m *ice.Message, arg ...Any) string { return kit.Format(Confv(m, arg...)) }
|
||||
func Confm(m *ice.Message, key string, sub Any, cbs ...Any) Map {
|
||||
func Conf(m configMessage, arg ...Any) string {
|
||||
return kit.Format(Confv(m, arg...))
|
||||
}
|
||||
func Confm(m configMessage, key string, sub Any, cbs ...Any) Map {
|
||||
val := m.Confv(key, sub)
|
||||
kit.If(len(cbs) > 0, func() { kit.For(val, cbs[0]) })
|
||||
if len(cbs) > 0 {
|
||||
kit.For(val, cbs[0])
|
||||
}
|
||||
value, _ := val.(Map)
|
||||
return value
|
||||
}
|
||||
@ -61,15 +66,16 @@ func Confm(m *ice.Message, key string, sub Any, cbs ...Any) Map {
|
||||
var cache = sync.Map{}
|
||||
|
||||
func Cache(m *ice.Message, key string, add func() Any) Any {
|
||||
if key = kit.Keys(m.PrefixKey(), key); add == nil {
|
||||
if key = m.PrefixKey(key); add == nil {
|
||||
cache.Delete(key)
|
||||
return nil
|
||||
} else if val, ok := cache.Load(key); ok {
|
||||
}
|
||||
if val, ok := cache.Load(key); ok {
|
||||
return val
|
||||
} else if val := add(); val != nil {
|
||||
}
|
||||
if val := add(); val != nil {
|
||||
cache.Store(key, val)
|
||||
return val
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
193
base/mdb/mdb.go
193
base/mdb/mdb.go
@ -32,10 +32,9 @@ func _mdb_select(m *ice.Message, cb Any, key string, value Map, fields []string,
|
||||
case func(Any):
|
||||
cb(value[TARGET])
|
||||
case func(Maps):
|
||||
cb(kit.ToMaps(value))
|
||||
cb(ToMaps(value))
|
||||
case string, []string, []Any, nil:
|
||||
if m.FieldsIsDetail() {
|
||||
// m.Push(ice.FIELDS_DETAIL, value, nil, kit.Dict(HASH, key))
|
||||
m.Push(ice.FIELDS_DETAIL, value)
|
||||
} else {
|
||||
m.Push(key, value, fields, val)
|
||||
@ -55,66 +54,51 @@ const (
|
||||
DICT = kit.MDB_DICT
|
||||
META = kit.MDB_META
|
||||
|
||||
SHORT = kit.MDB_SHORT
|
||||
FIELD = kit.MDB_FIELD
|
||||
COUNT = kit.MDB_COUNT
|
||||
TOTAL = kit.MDB_TOTAL
|
||||
LIMIT = kit.MDB_LIMIT
|
||||
LEAST = kit.MDB_LEAST
|
||||
STORE = kit.MDB_STORE
|
||||
FSIZE = kit.MDB_FSIZE
|
||||
|
||||
UNIQ = kit.MDB_UNIQ
|
||||
FOREACH = kit.MDB_FOREACH
|
||||
RANDOMS = kit.MDB_RANDOMS
|
||||
)
|
||||
const (
|
||||
ID = kit.MDB_ID
|
||||
KEY = kit.MDB_KEY
|
||||
TIME = kit.MDB_TIME
|
||||
TYPE = kit.MDB_TYPE
|
||||
NAME = kit.MDB_NAME
|
||||
TEXT = kit.MDB_TEXT
|
||||
|
||||
ICON = kit.MDB_ICON
|
||||
SCAN = kit.MDB_SCAN
|
||||
LINK = kit.MDB_LINK
|
||||
HELP = kit.MDB_HELP
|
||||
FILE = kit.MDB_FILE
|
||||
DATA = kit.MDB_DATA
|
||||
VIEW = kit.MDB_VIEW
|
||||
SHOW = kit.MDB_SHOW
|
||||
|
||||
KEY = kit.MDB_KEY
|
||||
VALUE = kit.MDB_VALUE
|
||||
LINK = kit.MDB_LINK
|
||||
FILE = kit.MDB_FILE
|
||||
SCAN = kit.MDB_SCAN
|
||||
SHOW = kit.MDB_SHOW
|
||||
HELP = kit.MDB_HELP
|
||||
|
||||
INDEX = kit.MDB_INDEX
|
||||
VALUE = kit.MDB_VALUE
|
||||
EXTRA = kit.MDB_EXTRA
|
||||
ALIAS = kit.MDB_ALIAS
|
||||
EXPIRE = kit.MDB_EXPIRE
|
||||
STATUS = kit.MDB_STATUS
|
||||
STREAM = kit.MDB_STREAM
|
||||
|
||||
TOOLS = "tools"
|
||||
ICONS = "icons"
|
||||
UNITS = "units"
|
||||
ORDER = "order"
|
||||
SCORE = "score"
|
||||
GROUP = "group"
|
||||
VALID = "valid"
|
||||
ENABLE = "enable"
|
||||
MEMBER = "member"
|
||||
DISABLE = "disable"
|
||||
EXPIRED = "expired"
|
||||
INVALID = "invalid"
|
||||
SHORT = kit.MDB_SHORT
|
||||
FIELD = kit.MDB_FIELD
|
||||
TOTAL = kit.MDB_TOTAL
|
||||
COUNT = kit.MDB_COUNT
|
||||
LIMIT = kit.MDB_LIMIT
|
||||
LEAST = kit.MDB_LEAST
|
||||
STORE = kit.MDB_STORE
|
||||
FSIZE = kit.MDB_FSIZE
|
||||
TOOLS = "tools"
|
||||
|
||||
SOURCE = "_source"
|
||||
TARGET = "_target"
|
||||
IMPORTANT = "important"
|
||||
SOURCE = "_source"
|
||||
TARGET = "_target"
|
||||
)
|
||||
const (
|
||||
INPUTS = "inputs"
|
||||
CREATE = "create"
|
||||
REMOVE = "remove"
|
||||
UPDATE = "update"
|
||||
INSERT = "insert"
|
||||
DELETE = "delete"
|
||||
MODIFY = "modify"
|
||||
@ -125,32 +109,22 @@ const (
|
||||
|
||||
DETAIL = "detail"
|
||||
FIELDS = "fields"
|
||||
SHORTS = "shorts"
|
||||
PARAMS = "params"
|
||||
|
||||
ACTION = "action"
|
||||
UPLOAD = "upload"
|
||||
RECENT = "recent"
|
||||
REPEAT = "repeat"
|
||||
REVERT = "revert"
|
||||
RANDOM = "random"
|
||||
OFFEND = "offend"
|
||||
OFFSET = "offset"
|
||||
RANDOM = "random"
|
||||
WEIGHT = "weight"
|
||||
SUBKEY = "mdb.sub"
|
||||
|
||||
ACTION = "action"
|
||||
UPLOAD = "upload"
|
||||
RECENT = "recent"
|
||||
REPEAT = "repeat"
|
||||
REVERT = "revert"
|
||||
RENAME = "rename"
|
||||
VENDOR = "vendor"
|
||||
PRUNE = "prune"
|
||||
TABLE = "table"
|
||||
CLASS = "class"
|
||||
DATABASE = "database"
|
||||
|
||||
ICON = "icon"
|
||||
PAGE = "page"
|
||||
NEXT = "next"
|
||||
PREV = "prev"
|
||||
PLAY = "play"
|
||||
|
||||
SORT = "sort"
|
||||
JSON = "json"
|
||||
CSV = "csv"
|
||||
SUB = "sub"
|
||||
@ -167,18 +141,16 @@ var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: ice.Commands
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
INPUTS: {Name: "inputs key sub type field value", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[3] {
|
||||
case "index":
|
||||
m.Cmdy("command", SEARCH, "command", "", "", ice.OptionFields("index"))
|
||||
return
|
||||
}
|
||||
kit.Switch(arg[2],
|
||||
HASH, func() { _hash_inputs(m, arg[0], arg[1], kit.Select(NAME, arg, 3), kit.Select("", arg, 4)) },
|
||||
ZONE, func() { _zone_inputs(m, arg[0], arg[1], arg[3], kit.Select(NAME, arg, 4), kit.Select("", arg, 5)) },
|
||||
LIST, func() { _list_inputs(m, arg[0], arg[1], kit.Select(NAME, arg, 3), kit.Select("", arg, 4)) },
|
||||
)
|
||||
for _, inputs := range ice.Info.Inputs {
|
||||
if arg[2] == ZONE {
|
||||
inputs(m, arg[4])
|
||||
} else {
|
||||
inputs(m, arg[3])
|
||||
}
|
||||
}
|
||||
}},
|
||||
INSERT: {Name: "insert key sub type arg...", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.Switch(arg[2],
|
||||
@ -224,31 +196,12 @@ var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: ice.Commands
|
||||
// LIST, func() { _list_prunes(m, arg[0], arg[1], arg[3:]...) },
|
||||
)
|
||||
}},
|
||||
EXPORT: {Name: "export index auto", Help: "导出数据", Actions: ice.MergeActions(ice.Actions{
|
||||
IMPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
HashSelect(m).Table(func(value ice.Maps) {
|
||||
if value[ENABLE] != ice.FALSE {
|
||||
m.Cmd(IMPORT, value[INDEX], "", value[TYPE])
|
||||
}
|
||||
})
|
||||
}},
|
||||
EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
HashSelect(m).Table(func(value ice.Maps) {
|
||||
if value[ENABLE] != ice.FALSE {
|
||||
m.Cmd(EXPORT, value[INDEX], "", value[TYPE])
|
||||
}
|
||||
})
|
||||
}},
|
||||
}, ExportHashAction(SHORT, INDEX, FIELD, "time,index,type,enable")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
HashSelect(m, arg...).PushAction(REMOVE)
|
||||
return
|
||||
}
|
||||
EXPORT: {Name: "export key sub type file", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionDefault(CACHE_LIMIT, "-1")
|
||||
file := _mdb_export_file(m, arg...)
|
||||
kit.Switch(arg[2],
|
||||
HASH, func() { _hash_export(m, arg[0], arg[1], file) },
|
||||
ZONE, func() { _zone_export(m, arg[0], arg[1], file); _hash_export(m, arg[0], arg[1], file) },
|
||||
ZONE, func() { _zone_export(m, arg[0], arg[1], file) },
|
||||
LIST, func() { _list_export(m, arg[0], arg[1], file) },
|
||||
)
|
||||
}},
|
||||
@ -256,7 +209,7 @@ var Index = &ice.Context{Name: MDB, Help: "数据模块", Commands: ice.Commands
|
||||
file := _mdb_export_file(m, arg...)
|
||||
kit.Switch(arg[2],
|
||||
HASH, func() { _hash_import(m, arg[0], arg[1], file) },
|
||||
ZONE, func() { _hash_import(m, arg[0], arg[1], file); _zone_import(m, arg[0], arg[1], file) },
|
||||
ZONE, func() { _zone_import(m, arg[0], arg[1], file) },
|
||||
LIST, func() { _list_import(m, arg[0], arg[1], file) },
|
||||
)
|
||||
}},
|
||||
@ -274,52 +227,60 @@ func init() {
|
||||
|
||||
func AutoConfig(arg ...Any) *ice.Action {
|
||||
return &ice.Action{Hand: func(m *ice.Message, args ...string) {
|
||||
if cs := m.Target().Configs; cs[m.CommandKey()] == nil {
|
||||
cs[m.CommandKey()] = &ice.Config{Value: kit.Data(arg...)}
|
||||
} else {
|
||||
kit.For(kit.Dict(arg...), func(k string, v Any) { Config(m, k, v) })
|
||||
if cs := m.Target().Configs; len(arg) > 0 {
|
||||
if cs[m.CommandKey()] == nil {
|
||||
cs[m.CommandKey()] = &ice.Config{Value: kit.Data(arg...)}
|
||||
} else {
|
||||
kit.For(kit.Dict(arg...), func(k string, v Any) { Config(m, k, v) })
|
||||
}
|
||||
}
|
||||
if cmd := m.Target().Commands[m.CommandKey()]; cmd == nil {
|
||||
return
|
||||
} else {
|
||||
s := Config(m, SHORT)
|
||||
kit.If(s == "" || s == UNIQ || strings.Contains(s, ","), func() { s = HASH })
|
||||
if cmd.Name == "" {
|
||||
cmd.Name = kit.Format("%s %s auto", m.CommandKey(), s)
|
||||
cmd.List = ice.SplitCmd(cmd.Name, cmd.Actions)
|
||||
} else if cmd.Actions[INSERT] != nil {
|
||||
if inputs := []Any{}; cmd.Meta[INSERT] == nil {
|
||||
kit.For(kit.Filters(kit.Simple(Config(m, SHORT), kit.Split(ListField(m))), "", TIME, ID), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(INSERT, "添加", inputs...)
|
||||
}
|
||||
add := func(list []string) (inputs []Any) {
|
||||
kit.For(list, func(k string) {
|
||||
kit.If(!kit.IsIn(k, TIME, HASH, COUNT, ID, ENABLE, DISABLE), func() {
|
||||
inputs = append(inputs, k+kit.Select("", FOREACH, strings.Contains(s, k)))
|
||||
})
|
||||
})
|
||||
return
|
||||
if inputs := []Any{}; cmd.Meta[CREATE] == nil {
|
||||
kit.For(kit.Filters(kit.Split(kit.Select(Config(m, SHORT), Config(m, FIELDS))), TIME, HASH, COUNT), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(CREATE, "创建", inputs...)
|
||||
}
|
||||
kit.If(cmd.Meta[CREATE] == nil, func() { m.Design(CREATE, "", add(kit.Split(HashField(m)))...) })
|
||||
return
|
||||
if cmd.Actions[INSERT] != nil {
|
||||
kit.If(cmd.Meta[INSERT] == nil, func() { m.Design(INSERT, "", add(kit.Simple(Config(m, SHORT), kit.Split(ListField(m))))...) })
|
||||
kit.If(cmd.Meta[CREATE] == nil, func() { m.Design(CREATE, "", add(kit.Split(Config(m, SHORT)))...) })
|
||||
} else if cmd.Actions[CREATE] != nil {
|
||||
kit.If(cmd.Meta[CREATE] == nil, func() { m.Design(CREATE, "", add(kit.Split(HashField(m)))...) })
|
||||
} else if cmd.Actions[CREATE] != nil {
|
||||
if inputs := []Any{}; cmd.Meta[CREATE] == nil {
|
||||
kit.For(kit.Filters(kit.Split(HashField(m)), TIME, HASH), func(k string) { inputs = append(inputs, k) })
|
||||
m.Design(CREATE, "创建", inputs...)
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
func ImportantZoneAction(arg ...Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { Config(m, IMPORTANT, ice.TRUE) }},
|
||||
}, ZoneAction(arg...))
|
||||
func ImportantZoneAction() ice.Actions {
|
||||
return ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
Config(m, "important", ice.TRUE)
|
||||
ZoneImport(m)
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionFields("")
|
||||
ZoneExport(m)
|
||||
}},
|
||||
}
|
||||
}
|
||||
func ImportantHashAction(arg ...Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { Config(m, IMPORTANT, ice.TRUE) }},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
Config(m, "important", ice.TRUE)
|
||||
HashImport(m)
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
HashExport(m)
|
||||
}},
|
||||
}, HashAction(arg...))
|
||||
}
|
||||
func saveImportant(m *ice.Message, key, sub string, arg ...string) {
|
||||
if m.Option("skip.important") == ice.TRUE {
|
||||
return
|
||||
}
|
||||
kit.If(m.Conf(key, kit.Keys(META, IMPORTANT)) == ice.TRUE, func() { ice.SaveImportant(m, arg...) })
|
||||
kit.If(m.Conf(key, kit.Keys(META, "important")) == ice.TRUE, func() { ice.SaveImportant(m, arg...) })
|
||||
}
|
||||
func ToMaps(value Map) Maps {
|
||||
res := Maps{}
|
||||
kit.For(value, func(k, v string) { res[k] = v })
|
||||
return res
|
||||
}
|
||||
|
@ -11,13 +11,16 @@ func init() { Index.MergeCommands(ice.Commands{RENDER: {Help: "渲染", Actions:
|
||||
|
||||
func RenderAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{ice.CTX_INIT: AutoConfig(SHORT, TYPE, FIELD, "time,type,name,text", arg),
|
||||
CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) { Config(m, SHORT, TYPE); HashCreate(m) }},
|
||||
CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
Config(m, SHORT, TYPE)
|
||||
HashCreate(m)
|
||||
}},
|
||||
SELECT: {Name: "select type name text auto create", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 2 || arg[0] == "" {
|
||||
HashSelect(m, arg...)
|
||||
return
|
||||
}
|
||||
m.OptionDefault(ice.MSG_FIELDS, kit.Select("type,name,text", arg, 2))
|
||||
m.OptionDefault(ice.MSG_FIELDS, kit.Select("", arg, 2))
|
||||
kit.For(kit.Split(arg[0]), func(k string) {
|
||||
HashSelects(m.Spawn(), k).Table(func(value ice.Maps) {
|
||||
m.Cmdy(kit.Keys(value[TEXT], value[NAME]), m.CommandKey(), k, arg[1], kit.Select("", arg, 2), kit.Slice(arg, 3))
|
||||
|
@ -16,14 +16,11 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
func IsSearchPreview(m *ice.Message, arg []string, cb ...func() []string) bool {
|
||||
func IsSearchForEach(m *ice.Message, arg []string, cb func() []string) bool {
|
||||
if arg[0] == FOREACH && arg[1] == "" {
|
||||
for _, cb := range cb {
|
||||
if cb != nil {
|
||||
if args := cb(); len(args) > 0 {
|
||||
m.PushSearch(TYPE, kit.Select("", args, 0), NAME, kit.Select("", args, 1), TEXT, kit.Select("", args, 2))
|
||||
}
|
||||
}
|
||||
if cb != nil {
|
||||
args := cb()
|
||||
m.PushSearch(TYPE, kit.Select("", args, 0), NAME, kit.Select("", args, 1), TEXT, kit.Select("", args, 2))
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
113
base/mdb/zone.go
113
base/mdb/zone.go
@ -4,7 +4,6 @@ import (
|
||||
"encoding/csv"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -13,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func _zone_meta(m *ice.Message, prefix, chain, key string) string {
|
||||
defer RLock(m, prefix)()
|
||||
defer RLock(m, prefix, chain)()
|
||||
return m.Conf(prefix, kit.Keys(chain, kit.Keym(key)))
|
||||
}
|
||||
func _zone_fields(m *ice.Message) []string {
|
||||
@ -25,6 +24,7 @@ func _zone_inputs(m *ice.Message, prefix, chain, zone string, field, value strin
|
||||
return
|
||||
}
|
||||
h := _hash_select_field(m, prefix, chain, zone, HASH)
|
||||
defer RLock(m, prefix, chain)()
|
||||
_list_inputs(m, prefix, kit.Keys(chain, HASH, h), field, value)
|
||||
}
|
||||
func _zone_insert(m *ice.Message, prefix, chain, zone string, arg ...string) {
|
||||
@ -33,11 +33,13 @@ func _zone_insert(m *ice.Message, prefix, chain, zone string, arg ...string) {
|
||||
h = _hash_insert(m, prefix, chain, kit.Select(ZONE, _zone_meta(m, prefix, chain, SHORT)), zone)
|
||||
}
|
||||
m.Assert(h != "")
|
||||
defer Lock(m, prefix, chain)()
|
||||
_list_insert(m, prefix, kit.Keys(chain, HASH, h), arg...)
|
||||
}
|
||||
func _zone_modify(m *ice.Message, prefix, chain, zone, id string, arg ...string) {
|
||||
h := _hash_select_field(m, prefix, chain, zone, HASH)
|
||||
m.Assert(h != "")
|
||||
defer Lock(m, prefix, chain)()
|
||||
_list_modify(m, prefix, kit.Keys(chain, HASH, h), ID, id, arg...)
|
||||
}
|
||||
func _zone_select(m *ice.Message, prefix, chain, zone string, id string) {
|
||||
@ -49,23 +51,17 @@ func _zone_select(m *ice.Message, prefix, chain, zone string, id string) {
|
||||
}
|
||||
defer m.SortIntR(ID)
|
||||
fields := _zone_fields(m)
|
||||
defer RLock(m, prefix)()
|
||||
defer RLock(m, prefix, chain)()
|
||||
Richs(m, prefix, chain, kit.Select(FOREACH, zone), func(key string, val Map) {
|
||||
chain := kit.Keys(chain, HASH, key)
|
||||
defer RLock(m, prefix, chain)()
|
||||
Grows(m, prefix, chain, ID, id, func(value ice.Map) {
|
||||
_mdb_select(m, m.OptionCB(""), key, value, fields, val)
|
||||
})
|
||||
m.StatusTimeCountTotal(kit.Value(val, "meta.count"), "step", "0")
|
||||
})
|
||||
}
|
||||
func _zone_export(m *ice.Message, prefix, chain, file string) {
|
||||
if !ice.HasUsr() {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix)()
|
||||
if len(Confm(m, prefix, kit.Keys(chain, HASH))) == 0 {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix, chain)()
|
||||
f, p, e := miss.CreateFile(kit.Keys(file, CSV))
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
@ -79,6 +75,7 @@ func _zone_export(m *ice.Message, prefix, chain, file string) {
|
||||
Richs(m, prefix, chain, key, func(key string, val ice.Map) {
|
||||
val = kit.GetMeta(val)
|
||||
chain := kit.Keys(chain, HASH, key)
|
||||
defer Lock(m, prefix, chain)()
|
||||
Grows(m, prefix, chain, "", "", func(value ice.Map) {
|
||||
value = kit.GetMeta(value)
|
||||
w.Write(kit.Simple(head, func(k string) string {
|
||||
@ -87,21 +84,18 @@ func _zone_export(m *ice.Message, prefix, chain, file string) {
|
||||
count++
|
||||
})
|
||||
})
|
||||
m.Conf(prefix, kit.Keys(chain, HASH, key, LIST), "")
|
||||
m.Conf(prefix, kit.Keys(chain, HASH, key, META, COUNT), "")
|
||||
}
|
||||
kit.If(count == 0, func() { os.Remove(p) })
|
||||
if count == 0 {
|
||||
os.Remove(p)
|
||||
return
|
||||
}
|
||||
m.Logs(EXPORT, KEY, path.Join(prefix, chain), FILE, p, COUNT, count)
|
||||
m.Conf(prefix, kit.Keys(chain, HASH), "")
|
||||
}
|
||||
func _zone_import(m *ice.Message, prefix, chain, file string) {
|
||||
if !ice.HasUsr() {
|
||||
return
|
||||
}
|
||||
defer Lock(m, prefix)()
|
||||
defer Lock(m, prefix, chain)()
|
||||
f, e := miss.OpenFile(kit.Keys(file, CSV))
|
||||
if e != nil && !ice.Info.Important {
|
||||
return
|
||||
} else if m.WarnNotFound(e) {
|
||||
if m.Warn(e) {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
@ -109,10 +103,6 @@ func _zone_import(m *ice.Message, prefix, chain, file string) {
|
||||
head, _ := r.Read()
|
||||
zkey := kit.Select(head[0], m.OptionFields())
|
||||
list := ice.Maps{}
|
||||
times := ice.Maps{}
|
||||
kit.For(m.Confv(prefix, kit.Keys(chain, HASH)), func(key string, value ice.Any) {
|
||||
times[key] = kit.Format(kit.Value(value, kit.Keys(META, TIME)))
|
||||
})
|
||||
count := 0
|
||||
for {
|
||||
line, e := r.Read()
|
||||
@ -136,9 +126,12 @@ func _zone_import(m *ice.Message, prefix, chain, file string) {
|
||||
}
|
||||
if list[zone] == "" {
|
||||
list[zone] = Rich(m, prefix, chain, kit.Data(zkey, zone))
|
||||
kit.If(times[list[zone]], func(t string) { m.Confv(prefix, kit.Keys(chain, HASH, list[zone], META, TIME), t) })
|
||||
}
|
||||
func() { chain := kit.Keys(chain, HASH, list[zone]); Grow(m, prefix, chain, data) }()
|
||||
func() {
|
||||
chain := kit.Keys(chain, HASH, list[zone])
|
||||
defer Lock(m, prefix, chain)()
|
||||
Grow(m, prefix, chain, data)
|
||||
}()
|
||||
count++
|
||||
}
|
||||
m.Logs(IMPORT, KEY, path.Join(prefix, chain), FILE, kit.Keys(file, CSV), COUNT, count)
|
||||
@ -150,56 +143,21 @@ const (
|
||||
)
|
||||
const ZONE = "zone"
|
||||
|
||||
func ZoneConfig(arg ...Any) *ice.Action {
|
||||
return &ice.Action{Hand: func(m *ice.Message, args ...string) {
|
||||
if cs := m.Target().Configs; cs[m.CommandKey()] == nil {
|
||||
cs[m.CommandKey()] = &ice.Config{Value: kit.Data(arg...)}
|
||||
} else {
|
||||
kit.For(kit.Dict(arg...), func(k string, v Any) { Config(m, k, v) })
|
||||
}
|
||||
if cmd := m.Target().Commands[m.CommandKey()]; cmd == nil {
|
||||
return
|
||||
} else {
|
||||
s := kit.Select(ZONE, Config(m, SHORT))
|
||||
kit.If(s == UNIQ || strings.Contains(s, ","), func() { s = HASH })
|
||||
if cmd.Name == "" {
|
||||
cmd.Name = kit.Format("%s %s id auto", m.CommandKey(), s)
|
||||
cmd.List = ice.SplitCmd(cmd.Name, cmd.Actions)
|
||||
}
|
||||
add := func(list []string) (inputs []Any) {
|
||||
kit.For(list, func(k string) {
|
||||
kit.If(!kit.IsIn(k, TIME, HASH, COUNT, ID), func() {
|
||||
inputs = append(inputs, k+kit.Select("", FOREACH, strings.Contains(s, k)))
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
kit.If(cmd.Meta[INSERT] == nil, func() { m.Design(INSERT, "", add(kit.Simple(kit.Split(s), kit.Split(ZoneField(m))))...) })
|
||||
kit.If(cmd.Meta[CREATE] == nil, func() { m.Design(CREATE, "", add(kit.Split(kit.Select(s, Config(m, FIELD))))...) })
|
||||
}
|
||||
}}
|
||||
}
|
||||
func ZoneAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: ZoneConfig(append(kit.List(SHORT, ZONE, FIELDS, ZONE_FIELD), arg...)...),
|
||||
return ice.Actions{ice.CTX_INIT: AutoConfig(append(kit.List(SHORT, ZONE, FIELD, ZONE_FIELD), arg...)...),
|
||||
INPUTS: {Hand: func(m *ice.Message, arg ...string) { ZoneInputs(m, arg) }},
|
||||
CREATE: {Hand: func(m *ice.Message, arg ...string) { ZoneCreate(m, arg) }},
|
||||
REMOVE: {Hand: func(m *ice.Message, arg ...string) { ZoneRemove(m, arg) }},
|
||||
INSERT: {Hand: func(m *ice.Message, arg ...string) { ZoneInsert(m, arg) }},
|
||||
MODIFY: {Hand: func(m *ice.Message, arg ...string) { ZoneModify(m, arg) }},
|
||||
SELECT: {Hand: func(m *ice.Message, arg ...string) { ZoneSelect(m, arg...) }},
|
||||
SELECT: {Name: "select zone id auto insert", Hand: func(m *ice.Message, arg ...string) { ZoneSelect(m, arg...) }},
|
||||
EXPORT: {Hand: func(m *ice.Message, arg ...string) { ZoneExport(m, arg) }},
|
||||
IMPORT: {Hand: func(m *ice.Message, arg ...string) { ZoneImport(m, arg) }},
|
||||
}
|
||||
}
|
||||
func ExportZoneAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { Config(m, IMPORTANT, ice.TRUE); ZoneImport(m, arg) }},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) { m.OptionFields(""); ZoneExport(m, arg) }},
|
||||
}, ZoneAction(arg...))
|
||||
}
|
||||
func PageZoneAction(arg ...ice.Any) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
SELECT: {Hand: func(m *ice.Message, arg ...string) { PageZoneSelect(m, arg...) }},
|
||||
SELECT: {Name: "select zone id auto insert page", Hand: func(m *ice.Message, arg ...string) { PageZoneSelect(m, arg...) }},
|
||||
PREV: {Hand: func(m *ice.Message, arg ...string) { PrevPageLimit(m, arg[0], arg[1:]...) }},
|
||||
NEXT: {Hand: func(m *ice.Message, arg ...string) { NextPage(m, arg[0], arg[1:]...) }},
|
||||
}, ZoneAction(arg...))
|
||||
@ -213,7 +171,7 @@ func ZoneKey(m *ice.Message) string {
|
||||
func ZoneShort(m *ice.Message) string {
|
||||
return kit.Select(ZONE, Config(m, SHORT), Config(m, SHORT) != UNIQ)
|
||||
}
|
||||
func ZoneField(m *ice.Message) string { return kit.Select(ZONE_FIELD, Config(m, FIELDS)) }
|
||||
func ZoneField(m *ice.Message) string { return kit.Select(ZONE_FIELD, Config(m, FIELD)) }
|
||||
func ZoneInputs(m *ice.Message, arg ...Any) {
|
||||
m.Cmdy(INPUTS, m.PrefixKey(), "", ZONE, m.Option(ZoneKey(m)), arg)
|
||||
}
|
||||
@ -236,24 +194,19 @@ func ZoneInsert(m *ice.Message, arg ...Any) {
|
||||
}
|
||||
}
|
||||
func ZoneModify(m *ice.Message, arg ...Any) {
|
||||
if args := kit.Simple(arg...); m.Option(ID) == "" {
|
||||
HashModify(m, arg...)
|
||||
} else if args[0] == HASH || args[0] == ZoneShort(m) {
|
||||
m.Cmdy(MODIFY, m.PrefixKey(), "", ZONE, args[1], args[3], args[4:])
|
||||
if args := kit.Simple(arg...); args[0] == HASH || args[0] == ZoneShort(m) {
|
||||
m.Cmdy(MODIFY, m.PrefixKey(), "", ZONE, args[1], args[3], arg[4:])
|
||||
} else {
|
||||
m.Cmdy(MODIFY, m.PrefixKey(), "", ZONE, m.Option(ZoneKey(m)), m.Option(ID), arg)
|
||||
}
|
||||
}
|
||||
func ZoneSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
arg = kit.Slice(arg, 0, 2)
|
||||
short, field, fields := Config(m, SHORT), Config(m, FIELD), ZoneField(m)
|
||||
m.Fields(len(arg), kit.Select(kit.Fields(TIME, short, COUNT), field), fields)
|
||||
m.Fields(len(arg), kit.Select(kit.Fields(TIME, Config(m, SHORT), COUNT), Config(m, FIELDS)), ZoneField(m))
|
||||
if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg, logs.FileLineMeta(-1)); len(arg) == 0 {
|
||||
m.Sort(short).PushAction(REMOVE).Action(CREATE)
|
||||
m.PushAction(Config(m, ACTION), REMOVE).StatusTimeCount().Sort(ZoneShort(m))
|
||||
} else if len(arg) == 1 {
|
||||
m.Action(INSERT)
|
||||
} else {
|
||||
sortByField(m, fields)
|
||||
m.StatusTimeCountTotal(_zone_meta(m, m.PrefixKey(), kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT))
|
||||
}
|
||||
return m
|
||||
}
|
||||
@ -279,11 +232,5 @@ func ZoneSelectCB(m *ice.Message, zone string, cb Any) *ice.Message {
|
||||
}
|
||||
func PageZoneSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
OptionPages(m, kit.Slice(arg, 2)...)
|
||||
arg = kit.Slice(arg, 0, 2)
|
||||
if ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.Action(CREATE)
|
||||
} else if len(arg) == 1 {
|
||||
m.Action(INSERT, PAGE)
|
||||
}
|
||||
return m
|
||||
return ZoneSelect(m, arg...)
|
||||
}
|
||||
|
103
base/nfs/cat.go
103
base/nfs/cat.go
@ -2,7 +2,6 @@ package nfs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -31,11 +30,11 @@ func _cat_line(m *ice.Message, p string) (n int) {
|
||||
return
|
||||
}
|
||||
func _cat_list(m *ice.Message, p string) {
|
||||
if m.Option(CAT_CONTENT) == "" && !kit.IsIn(kit.Ext(p), "css", "js") && !aaa.Right(m, path.Join(m.Option(DIR_ROOT), p)) {
|
||||
if m.Option(CAT_CONTENT) == "" && !aaa.Right(m, p) {
|
||||
return
|
||||
}
|
||||
f, e := _cat_find(m, p)
|
||||
if m.WarnNotFound(e, FILE, p) {
|
||||
if m.Warn(e, ice.ErrNotFound, p) {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
@ -44,20 +43,14 @@ func _cat_list(m *ice.Message, p string) {
|
||||
list := []string{}
|
||||
kit.For(f, func(s string, i int) { list = append(list, cb(s, i)) })
|
||||
m.Echo(strings.Join(list, ice.NL) + ice.NL)
|
||||
case func([]string, string) string:
|
||||
list := []string{}
|
||||
kit.For(f, func(s string, i int) { list = append(list, cb(kit.Split(s), s)) })
|
||||
m.Echo(strings.Join(list, ice.NL) + ice.NL)
|
||||
case func(string, int):
|
||||
kit.For(f, cb)
|
||||
case func(string):
|
||||
kit.For(f, cb)
|
||||
case func([]string, string):
|
||||
kit.For(f, cb)
|
||||
case func([]string):
|
||||
kit.For(f, cb)
|
||||
case nil:
|
||||
if b, e := ioutil.ReadAll(f); !m.WarnNotFound(e) {
|
||||
if b, e := ioutil.ReadAll(f); !m.Warn(e) {
|
||||
m.Echo(string(b)).StatusTime(FILE, p, SIZE, len(b))
|
||||
}
|
||||
default:
|
||||
@ -68,6 +61,7 @@ func _cat_list(m *ice.Message, p string) {
|
||||
const (
|
||||
CAT_CONTENT = "cat_content"
|
||||
CONFIGURE = "configure"
|
||||
TEMPLATE = "template"
|
||||
STDIO = "stdio"
|
||||
|
||||
TAGS = "tags"
|
||||
@ -76,18 +70,13 @@ const (
|
||||
TARGET = "target"
|
||||
BINARY = "binary"
|
||||
SCRIPT = "script"
|
||||
FORMAT = "format"
|
||||
TRANS = "trans"
|
||||
|
||||
CLONE = "clone"
|
||||
REPOS = "repos"
|
||||
REMOTE = "remote"
|
||||
ORIGIN = "origin"
|
||||
COMMIT = "commit"
|
||||
BRANCH = "branch"
|
||||
MASTER = "master"
|
||||
VERSION = "version"
|
||||
COMPILE = "compile"
|
||||
)
|
||||
const (
|
||||
HTML = ice.HTML
|
||||
@ -99,7 +88,6 @@ const (
|
||||
SHY = ice.SHY
|
||||
CSV = ice.CSV
|
||||
JSON = ice.JSON
|
||||
MOD = "mod"
|
||||
|
||||
PROTO = "proto"
|
||||
YAML = "yaml"
|
||||
@ -110,13 +98,10 @@ const (
|
||||
MD = "md"
|
||||
PY = "py"
|
||||
|
||||
IMAGE = "image"
|
||||
JPEG = "jpeg"
|
||||
JPG = "jpg"
|
||||
PNG = "png"
|
||||
MP4 = "mp4"
|
||||
MOV = "mov"
|
||||
PDF = "pdf"
|
||||
PNG = "png"
|
||||
JPG = "jpg"
|
||||
MP4 = "mp4"
|
||||
PDF = "pdf"
|
||||
|
||||
DF = ice.DF
|
||||
PS = ice.PS
|
||||
@ -127,30 +112,29 @@ const CAT = "cat"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CAT: {Name: "cat path auto", Help: "文件", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: mdb.AutoConfig(SOURCE, kit.DictList(
|
||||
HTML, CSS, JS, GO, SH, PY, SHY, CSV, JSON, CONFIGURE, PROTO, YAML, CONF, XML, YML, TXT, MD, strings.ToLower(ice.LICENSE), strings.ToLower(ice.MAKEFILE),
|
||||
)),
|
||||
}, DIR), Hand: func(m *ice.Message, arg ...string) {
|
||||
if !DirList(m, arg...) {
|
||||
if arg[0] != "" {
|
||||
m.Logs(FIND, m.OptionSimple(DIR_ROOT), FILE, arg[0])
|
||||
}
|
||||
_cat_list(m, arg[0])
|
||||
CAT: {Name: "cat path auto", Help: "文件", Actions: ice.MergeActions(ice.Actions{ice.CTX_INIT: mdb.AutoConfig(SOURCE, kit.DictList(
|
||||
HTML, CSS, JS, GO, SH, PY, SHY, CSV, JSON, CONFIGURE, PROTO, YAML, CONF, XML, YML, TXT, MD, strings.ToLower(ice.LICENSE), strings.ToLower(ice.MAKEFILE),
|
||||
))}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], PS) {
|
||||
m.Cmdy(DIR, arg)
|
||||
} else {
|
||||
_cat_list(m.Logs(FIND, m.OptionSimple(DIR_ROOT), FILE, arg[0]), arg[0])
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func DirList(m *ice.Message, arg ...string) bool {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], PS) {
|
||||
m.Cmdy(DIR, kit.Slice(arg, 0, 1))
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
type templateMessage interface {
|
||||
PrefixKey(...string) string
|
||||
Cmdx(...ice.Any) string
|
||||
}
|
||||
|
||||
func Template(m templateMessage, p string, arg ...ice.Any) string {
|
||||
return kit.Renders(kit.Format(TemplateText(m, p), arg...), m)
|
||||
}
|
||||
func TemplateText(m templateMessage, p string) string {
|
||||
return m.Cmdx(CAT, path.Join(m.PrefixKey(), path.Base(p)), kit.Dict(DIR_ROOT, ice.SRC_TEMPLATE))
|
||||
}
|
||||
func IsSourceFile(m *ice.Message, ext string) bool {
|
||||
return mdb.Conf(m, Prefix(CAT), kit.Keym(SOURCE, ext)) == ice.TRUE
|
||||
}
|
||||
@ -166,20 +150,24 @@ func Open(m *ice.Message, p string, cb ice.Any) {
|
||||
if p == "" {
|
||||
return
|
||||
} else if strings.HasSuffix(p, PS) {
|
||||
kit.If(p == PS, func() { p = "" })
|
||||
if ls, e := ReadDir(m, p); !m.WarnNotFound(e) {
|
||||
if p == PS {
|
||||
p = ""
|
||||
}
|
||||
if ls, e := ReadDir(m, p); !m.Warn(e) {
|
||||
switch cb := cb.(type) {
|
||||
case func([]os.FileInfo):
|
||||
cb(ls)
|
||||
case func(os.FileInfo):
|
||||
kit.For(ls, cb)
|
||||
case func(io.Reader, string):
|
||||
kit.For(ls, func(s os.FileInfo) { kit.If(!s.IsDir(), func() { Open(m, path.Join(p, s.Name()), cb) }) })
|
||||
kit.For(ls, func(s os.FileInfo) {
|
||||
kit.If(!s.IsDir(), func() { Open(m, path.Join(p, s.Name()), cb) })
|
||||
})
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
}
|
||||
} else if f, e := OpenFile(m, p); !m.WarnNotFound(e, p) {
|
||||
} else if f, e := OpenFile(m, p); !m.Warn(e, ice.ErrNotFound, p) {
|
||||
defer f.Close()
|
||||
switch cb := cb.(type) {
|
||||
case func(io.Reader, os.FileInfo):
|
||||
@ -190,7 +178,7 @@ func Open(m *ice.Message, p string, cb ice.Any) {
|
||||
case func(io.Reader):
|
||||
cb(f)
|
||||
case func(string):
|
||||
if b, e := ioutil.ReadAll(f); !m.WarnNotFound(e) {
|
||||
if b, e := ioutil.ReadAll(f); !m.Warn(e) {
|
||||
cb(string(b))
|
||||
}
|
||||
default:
|
||||
@ -199,7 +187,7 @@ func Open(m *ice.Message, p string, cb ice.Any) {
|
||||
}
|
||||
}
|
||||
func ReadAll(m *ice.Message, r io.Reader) []byte {
|
||||
if b, e := ioutil.ReadAll(r); !m.WarnNotFound(e) {
|
||||
if b, e := ioutil.ReadAll(r); !m.Warn(e) {
|
||||
return b
|
||||
}
|
||||
return nil
|
||||
@ -211,26 +199,3 @@ func ReadFile(m *ice.Message, p string) (b []byte, e error) {
|
||||
func Rewrite(m *ice.Message, p string, cb func(string) string) {
|
||||
m.Cmd(SAVE, p, m.Cmdx(CAT, p, func(s string, i int) string { return cb(s) }))
|
||||
}
|
||||
func ScanCSV(m *ice.Message, file string, cb func([]string), arg ...string) {
|
||||
f, e := OpenFile(m, file)
|
||||
if m.Warn(e) {
|
||||
return
|
||||
}
|
||||
r := csv.NewReader(f)
|
||||
head, err := r.Read()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
index := []int{}
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, head...) })
|
||||
kit.For(arg, func(h string) { index = append(index, kit.IndexOf(head, h)) })
|
||||
for {
|
||||
data, err := r.Read()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
res := []string{}
|
||||
kit.For(index, func(i int) { res = append(res, data[i]) })
|
||||
cb(res)
|
||||
}
|
||||
}
|
||||
|
169
base/nfs/dir.go
169
base/nfs/dir.go
@ -4,9 +4,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
@ -24,7 +22,7 @@ func _dir_hash(m *ice.Message, p string) (h string) {
|
||||
kit.If(len(list) > 0, func() { h = kit.Hashs(list) })
|
||||
return ""
|
||||
}
|
||||
func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) (total int64, last time.Time) {
|
||||
func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, dir_type string, dir_reg *regexp.Regexp, fields []string) *ice.Message {
|
||||
ls, _ := ReadDir(m, path.Join(root, dir))
|
||||
if len(ls) == 0 {
|
||||
if s, e := StatFile(m, path.Join(root, dir)); e == nil && !s.IsDir() {
|
||||
@ -51,7 +49,6 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
kit.If(s.ModTime().After(last), func() { last = s.ModTime() })
|
||||
for _, field := range fields {
|
||||
switch field {
|
||||
case mdb.TIME:
|
||||
@ -77,7 +74,6 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di
|
||||
m.Push(field, _dir_size(m, p))
|
||||
} else {
|
||||
m.Push(field, kit.FmtSize(s.Size()))
|
||||
total += s.Size()
|
||||
}
|
||||
case LINE:
|
||||
if isDir {
|
||||
@ -96,15 +92,13 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di
|
||||
case mdb.LINK:
|
||||
if isDir {
|
||||
m.Push(mdb.LINK, "")
|
||||
} else if strings.Contains(p, "ice.windows.") {
|
||||
m.PushDownload(mdb.LINK, "ice.exe", p)
|
||||
} else {
|
||||
if strings.Contains(p, "ice.windows") {
|
||||
m.PushDownload(mdb.LINK, "ice.exe", p)
|
||||
} else {
|
||||
m.PushDownload(mdb.LINK, p)
|
||||
}
|
||||
m.PushDownload(mdb.LINK, p)
|
||||
}
|
||||
case mdb.SHOW:
|
||||
switch p := m.MergeLink(SHARE_LOCAL+p, ice.POD, m.Option(ice.MSG_USERPOD)); kit.Ext(s.Name()) {
|
||||
switch p := kit.MergeURL("/share/local/"+p, ice.POD, m.Option(ice.MSG_USERPOD)); kit.Ext(s.Name()) {
|
||||
case PNG, JPG:
|
||||
m.PushImages(field, p)
|
||||
case MP4:
|
||||
@ -116,7 +110,7 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di
|
||||
if m.IsCliUA() || m.Option(ice.MSG_USERROLE) == aaa.VOID {
|
||||
break
|
||||
}
|
||||
m.PushButton(mdb.SHOW, "rename", TRASH)
|
||||
m.PushButton(TRASH)
|
||||
default:
|
||||
m.Push(field, "")
|
||||
}
|
||||
@ -124,77 +118,20 @@ func _dir_list(m *ice.Message, root string, dir string, level int, deep bool, di
|
||||
}
|
||||
if deep && isDir {
|
||||
switch s.Name() {
|
||||
case "pluged", "node_modules":
|
||||
case "node_modules", "pluged", "target", "trash":
|
||||
continue
|
||||
}
|
||||
_total, _last := _dir_list(m, root, pp, level+1, deep, dir_type, dir_reg, fields)
|
||||
if total += _total; _last.After(last) {
|
||||
last = _last
|
||||
}
|
||||
_dir_list(m, root, pp, level+1, deep, dir_type, dir_reg, fields)
|
||||
}
|
||||
}
|
||||
return
|
||||
return m
|
||||
}
|
||||
|
||||
const (
|
||||
PWD = "./"
|
||||
SRC = "src/"
|
||||
ETC = "etc/"
|
||||
BIN = "bin/"
|
||||
VAR = "var/"
|
||||
USR = "usr/"
|
||||
|
||||
SCAN = "scan"
|
||||
GOWORK = "gowork"
|
||||
|
||||
PORTAL_GO = "portal.go"
|
||||
PORTAL_JSON = "portal.json"
|
||||
ETC_LOCAL_SH = "etc/local.sh"
|
||||
ETC_CERT_KEY = "etc/cert/cert.key"
|
||||
ETC_CERT_PEM = "etc/cert/cert.pem"
|
||||
SRC_DOCUMENT = "src/document/"
|
||||
SRC_PRIVATE = "src/private/"
|
||||
SRC_MAIN_PNG = "src/main.png"
|
||||
SRC_OPTION_GO = "src/option.go"
|
||||
SRC_TEMPLATE = ice.SRC_TEMPLATE
|
||||
USR_TOOLKITS = ice.USR_TOOLKITS
|
||||
USR_ICEBERGS = ice.USR_ICEBERGS
|
||||
USR_RELEASE = ice.USR_RELEASE
|
||||
USR_PUBLISH = ice.USR_PUBLISH
|
||||
USR_LOCAL = ice.USR_LOCAL
|
||||
USR_LOCAL_WORK = ice.USR_LOCAL_WORK
|
||||
USR_IMAGE = "usr/image/"
|
||||
USR_MATERIAL = "usr/material/"
|
||||
USR_LOCAL_IMAGE = "usr/local/image/"
|
||||
USR_LEARNING_PORTAL = "usr/learning/portal/"
|
||||
USR_MODULES = "usr/node_modules/"
|
||||
USR_PACKAGE = "usr/package.json"
|
||||
|
||||
VAR_LOG_BENCH_LOG = "var/log/bench.log"
|
||||
USR_ICONS_AVATAR = "usr/icons/avatar.jpg"
|
||||
USR_ICONS_CONTEXTS = "usr/icons/contexts.jpg"
|
||||
USR_ICONS_ICEBERGS = "usr/icons/icebergs.png"
|
||||
USR_ICONS_VOLCANOS = "usr/icons/volcanos.png"
|
||||
USR_ICONS = "usr/icons/"
|
||||
|
||||
V = "/v/"
|
||||
M = "/m/"
|
||||
P = "/p/"
|
||||
X = "/x/"
|
||||
S = "/s/"
|
||||
C = "/c/"
|
||||
INTSHELL = "/intshell/"
|
||||
VOLCANOS = "/volcanos/"
|
||||
VOLCANOS_PLUGIN = "/volcanos/plugin/"
|
||||
REQUIRE_MODULES = "/require/modules/"
|
||||
REQUIRE_USR = "/require/usr/"
|
||||
REQUIRE_SRC = "/require/src/"
|
||||
REQUIRE = "/require/"
|
||||
PLUGIN = "/plugin/"
|
||||
SHARE_LOCAL = "/share/local/"
|
||||
PATHNAME = "pathname"
|
||||
FILENAME = "filename"
|
||||
CONTEXTS = "contexts"
|
||||
PWD = "./"
|
||||
SRC = "src/"
|
||||
USR = "usr/"
|
||||
REQUIRE = "/require/"
|
||||
|
||||
TYPE_ALL = "all"
|
||||
TYPE_BIN = "bin"
|
||||
@ -203,8 +140,8 @@ const (
|
||||
TYPE_BOTH = "both"
|
||||
|
||||
DIR_ROOT = "dir_root"
|
||||
DIR_DEEP = "dir_deep"
|
||||
DIR_TYPE = "dir_type"
|
||||
DIR_DEEP = "dir_deep"
|
||||
DIR_REG = "dir_reg"
|
||||
|
||||
DIR_DEF_FIELDS = "time,path,size,action"
|
||||
@ -224,67 +161,61 @@ const DIR = "dir"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DIR: {Name: "dir path auto upload app", Icon: "dir.png", Help: "文件夹", Actions: ice.Actions{
|
||||
DIR: {Name: "dir path auto upload", Help: "目录", Actions: ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
aaa.White(m, ice.MAKEFILE, ice.README_MD, ice.LICENSE)
|
||||
aaa.White(m, ice.SRC, ice.BIN, ice.USR)
|
||||
aaa.Black(m, ice.SRC_PRIVATE)
|
||||
aaa.Black(m, ice.USR_LOCAL)
|
||||
}},
|
||||
ice.APP: {Help: "本机", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
m.System("open", kit.Path(m.Option(PATH)))
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchForEach(m, arg, nil) && m.Cmdx("host", "islocal", m.Option(ice.MSG_USERIP)) == ice.OK {
|
||||
return
|
||||
kit.For([]string{"Desktop", "Documents", "Downloads", "Pictures"}, func(p string) {
|
||||
p = kit.HomePath(p)
|
||||
m.Cmd(DIR, PWD, mdb.NAME, mdb.TIME, kit.Dict(DIR_ROOT, p)).SortStrR(mdb.TIME).TablesLimit(5, func(value ice.Maps) {
|
||||
name := value[mdb.NAME]
|
||||
kit.If(len(kit.TrimExt(name)) > 30, func() { name = name[:10] + ".." + name[len(name)-10:] })
|
||||
m.PushSearch(mdb.TYPE, OPENS, mdb.NAME, name, mdb.TEXT, path.Join(p, value[mdb.NAME]))
|
||||
})
|
||||
})
|
||||
}
|
||||
}},
|
||||
mdb.SHOW: {Help: "预览", Hand: func(m *ice.Message, arg ...string) {
|
||||
Show(m.ProcessInner(), path.Join(m.Option(DIR_ROOT), m.Option(PATH)))
|
||||
}}, mdb.UPLOAD: {},
|
||||
SIZE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Select("", kit.Split(m.System("du", "-sh").Result()), 0))
|
||||
}},
|
||||
"rename": {Name: "rename to", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(MOVE, path.Join(path.Dir(m.Option(PATH)), m.Option(TO)), m.Option(PATH))
|
||||
}},
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(TRASH, mdb.CREATE, m.Option(PATH))
|
||||
}},
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(TRASH, mdb.CREATE, m.Option(PATH)) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
root, dir := kit.Select(PWD, m.Option(DIR_ROOT)), kit.Select(PWD, arg, 0)
|
||||
kit.If(strings.HasPrefix(dir, PS), func() { root = "" })
|
||||
if !aaa.Right(m, path.Join(root, dir)) {
|
||||
return
|
||||
}
|
||||
m.Logs(FIND, DIR_ROOT, root, PATH, dir, m.OptionSimple(DIR_TYPE, DIR_REG))
|
||||
m.Logs(FIND, DIR_ROOT, root, PATH, dir, DIR_TYPE, m.Option(DIR_TYPE))
|
||||
fields := kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1))))
|
||||
size, last := _dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), regexp.MustCompile(m.Option(DIR_REG)), fields)
|
||||
kit.If(m.Option(DIR_ROOT), func() { m.Option(DIR_ROOT, path.Join(m.Option(DIR_ROOT))+PS) })
|
||||
m.StatusTimeCount(mdb.TIME, last, SIZE, kit.FmtSize(size), m.OptionSimple(DIR_ROOT))
|
||||
_dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), regexp.MustCompile(m.Option(DIR_REG)), fields).StatusTimeCount()
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
var bind = []string{
|
||||
"usr/icebergs/core/chat/", "usr/volcanos/panel/",
|
||||
"usr/icebergs/core/", "usr/volcanos/plugin/local/",
|
||||
}
|
||||
|
||||
func Relative(m *ice.Message, p string) string {
|
||||
if _p := kit.ExtChange(p, JS); Exists(m, _p) {
|
||||
return _p
|
||||
} else if _p := kit.ExtChange(path.Join(ice.USR_VOLCANOS, ice.PLUGIN_LOCAL, path.Join(kit.Slice(kit.Split(p, PS), -2)...)), JS); Exists(m, kit.Split(_p, "?")[0]) {
|
||||
return _p
|
||||
} else {
|
||||
return p
|
||||
for i := 0; i < len(bind); i += 2 {
|
||||
if strings.HasPrefix(p, bind[i]) {
|
||||
return strings.Replace(p, bind[i], bind[i+1], 1)
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
func SplitPath(m *ice.Message, p string) []string {
|
||||
if kit.HasPrefix(p, REQUIRE_SRC, REQUIRE_USR) {
|
||||
if kit.HasPrefix(p, ice.REQUIRE_SRC, ice.REQUIRE_USR) {
|
||||
p = strings.TrimPrefix(p, REQUIRE)
|
||||
} else if kit.HasPrefix(p, REQUIRE) {
|
||||
ls := kit.Split(p, PS)
|
||||
return []string{ice.USR_REQUIRE + path.Join(ls[1:4]...) + PS, path.Join(ls[4:]...)}
|
||||
} else if kit.HasPrefix(p, P) {
|
||||
p = strings.TrimPrefix(p, P)
|
||||
}
|
||||
line := kit.Select("1", strings.Split(p, DF), 1)
|
||||
p = strings.TrimPrefix(p, kit.Path("")+PS)
|
||||
p = strings.Split(p, DF)[0]
|
||||
p = strings.Split(p, "?")[0]
|
||||
if ls := kit.Split(kit.Select(ice.SRC_MAIN_GO, p), PS); len(ls) == 1 {
|
||||
return []string{PWD, ls[0], line}
|
||||
} else if ls[0] == ice.USR {
|
||||
@ -307,21 +238,3 @@ func DirDeepAll(m *ice.Message, root, dir string, cb func(ice.Maps), arg ...stri
|
||||
return msg.Table(cb)
|
||||
}
|
||||
}
|
||||
func Show(m *ice.Message, file string) bool {
|
||||
p := SHARE_LOCAL + file
|
||||
kit.If(m.Option(ice.MSG_USERPOD), func(pod string) { p = kit.MergeURL(p, ice.POD, pod) })
|
||||
switch strings.ToLower(kit.Ext(file)) {
|
||||
case PNG, JPG, JPEG, "gif":
|
||||
m.EchoImages(p)
|
||||
case MP4, MOV:
|
||||
m.EchoVideos(p)
|
||||
default:
|
||||
if IsSourceFile(m, kit.Ext(file)) {
|
||||
m.Cmdy(CAT, file)
|
||||
} else {
|
||||
m.ProcessOpen(p)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const DOCUMENT = "document"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DOCUMENT: {Name: "document index path auto", Help: "文档", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(ice.COMMAND).Option(ice.MSG_DISPLAY, "")
|
||||
return
|
||||
}
|
||||
m.Search(arg[0], func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
if p := DocumentPath(m); p != "" {
|
||||
if len(kit.Slice(arg, 0, 2)) == 1 {
|
||||
m.Cmdy(DIR, p)
|
||||
} else {
|
||||
m.Cmdy(CAT, arg[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
}},
|
||||
})
|
||||
}
|
||||
func Document(m *ice.Message, p string, arg ...ice.Any) string {
|
||||
return kit.Renders(kit.Format(DocumentText(m, p), arg...), m)
|
||||
}
|
||||
|
||||
var DocumentText = func(m *ice.Message, p string) string {
|
||||
return m.Cmdx(CAT, DocumentPath(m, path.Base(p)))
|
||||
}
|
||||
var DocumentPath = func(m *ice.Message, arg ...string) string {
|
||||
return path.Join(USR_LEARNING_PORTAL, m.PrefixKey(), path.Join(arg...))
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const FIND = "find"
|
||||
|
||||
func init() {
|
||||
const CMD_DIR = "cmd_dir"
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FIND: {Name: "find word file auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, "main.go") })
|
||||
m.Options(mdb.VALUE, arg[0], CMD_DIR, kit.Select("", arg, 2))
|
||||
msg := m.System(FIND, kit.Select(SRC, arg, 1), "-name", arg[0])
|
||||
m.Echo(msg.FormatsMeta(nil))
|
||||
kit.For(strings.Split(msg.Result(), ice.NL), func(s string) { m.Push(FILE, s) })
|
||||
m.StatusTimeCount(kit.Dict(PATH, m.Option(CMD_DIR)))
|
||||
}},
|
||||
})
|
||||
}
|
@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
FIND = "find"
|
||||
OPENS = "opens"
|
||||
)
|
||||
|
||||
@ -17,17 +18,14 @@ const GREP = "grep"
|
||||
func init() {
|
||||
const CMD_DIR = "cmd_dir"
|
||||
Index.MergeCommands(ice.Commands{
|
||||
GREP: {Name: "grep word file auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, ice.MAIN) })
|
||||
kit.If(len(arg) == 1, func() { arg = append(arg, ice.SRC) })
|
||||
m.Options(mdb.VALUE, arg[0])
|
||||
kit.For(kit.SplitLine(m.System(GREP, "--exclude=.[a-z]*", "--exclude-dir=.[a-z]*", "-rni", arg[0], kit.AddUniq([]string{}, arg[1:]...)).Result()), func(s string) {
|
||||
GREP: {Name: "grep word file path auto", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Options(mdb.VALUE, arg[0], CMD_DIR, kit.Select("", arg, 2))
|
||||
kit.For(strings.Split(m.Cmdx("cli.system", GREP, "--exclude=.[a-z]*", "--exclude-dir=.[a-z]*", "-rni", arg[0], kit.Select(PT, arg, 1)), ice.NL), func(s string) {
|
||||
if ls := strings.SplitN(s, DF, 3); len(ls) > 2 {
|
||||
_ls := SplitPath(m, ls[0])
|
||||
m.Push(PATH, _ls[0]).Push(FILE, _ls[1]).Push(LINE, ls[1]).Push(mdb.TEXT, ls[2])
|
||||
m.Push(FILE, strings.TrimPrefix(ls[0], PWD)).Push(LINE, ls[1]).Push(mdb.TEXT, ls[2])
|
||||
}
|
||||
})
|
||||
m.Sort("path,file,line")
|
||||
m.StatusTimeCount(PATH, m.Option(CMD_DIR))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -16,17 +17,18 @@ const HEX = "hex"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{HEX: {Name: "hex path compress=raw,gzip,zlib size auto", Help: "二进制", Hand: func(m *ice.Message, arg ...string) {
|
||||
if DirList(m, arg...) {
|
||||
if len(arg) == 0 || arg[0] == "" || strings.HasSuffix(arg[0], PS) {
|
||||
m.Cmdy(DIR, kit.Slice(arg, 0, 1))
|
||||
return
|
||||
}
|
||||
Open(m, arg[0], func(r io.Reader, s os.FileInfo) {
|
||||
switch arg[1] {
|
||||
case "gzip":
|
||||
if g, e := gzip.NewReader(r); !m.WarnNotFound(e) {
|
||||
if g, e := gzip.NewReader(r); !m.Warn(e) {
|
||||
r = g
|
||||
}
|
||||
case "zlib":
|
||||
if z, e := zlib.NewReader(r); !m.WarnNotFound(e) {
|
||||
if z, e := zlib.NewReader(r); !m.Warn(e) {
|
||||
r = z
|
||||
}
|
||||
}
|
||||
@ -37,7 +39,7 @@ func init() {
|
||||
m.Push(kit.Format(i%8), hex.EncodeToString(buf[i:i+1]))
|
||||
kit.If(i%8 == 7, func() { m.Push(mdb.TEXT, string(buf[i-7:i+1])) })
|
||||
})
|
||||
m.StatusTime(mdb.TIME, s.ModTime().Format(ice.MOD_TIME), FILE, arg[0], SIZE, kit.FmtSize(s.Size()))
|
||||
m.Status(mdb.TIME, s.ModTime().Format(ice.MOD_TIME), FILE, arg[0], SIZE, kit.FmtSize(s.Size()))
|
||||
})
|
||||
}}})
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ const NFS = "nfs"
|
||||
var Index = &ice.Context{Name: NFS, Help: "存储模块"}
|
||||
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil, ZIP, TAR, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, GREP, FIND, MOVE, MOVETO, TRASH)
|
||||
ice.Index.Register(Index, nil, TAR, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, GREP, TRASH)
|
||||
}
|
||||
func Prefix(arg ...string) string { return kit.Keys(NFS, arg) }
|
||||
|
@ -16,7 +16,7 @@ const PACK = "pack"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PACK: {Name: "pack path auto create upload", Help: "文件系统", Actions: ice.Actions{
|
||||
PACK: {Name: "pack path auto upload create", Help: "文件系统", Actions: ice.Actions{
|
||||
mdb.CREATE: {Name: "create path*=src/hi/hi.txt text*=hello", Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, PackFile)
|
||||
Create(m, m.Option(PATH), func(w io.Writer, p string) {
|
||||
@ -24,13 +24,6 @@ func init() {
|
||||
})
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { PackFile.Remove(path.Clean(m.Option(PATH))) }},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, PackFile)
|
||||
Open(m, path.Join(m.Option(PATH), m.Option(FILE)), func(r io.Reader, p string) {
|
||||
OptionFiles(m, DiskFile)
|
||||
Create(m, p, func(w io.Writer) { Copy(m, w, r, func(n int) { m.Logs(LOAD, FILE, p, SIZE, n) }) })
|
||||
})
|
||||
}},
|
||||
mdb.IMPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, DiskFile)
|
||||
Open(m, path.Join(m.Option(PATH), m.Option(FILE)), func(r io.Reader, p string) {
|
||||
@ -38,6 +31,13 @@ func init() {
|
||||
Create(m, p, func(w io.Writer) { Copy(m, w, r, func(n int) { m.Logs(LOAD, FILE, p, SIZE, n) }) })
|
||||
})
|
||||
}},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, PackFile)
|
||||
Open(m, path.Join(m.Option(PATH), m.Option(FILE)), func(r io.Reader, p string) {
|
||||
OptionFiles(m, DiskFile)
|
||||
Create(m, p, func(w io.Writer) { Copy(m, w, r, func(n int) { m.Logs(LOAD, FILE, p, SIZE, n) }) })
|
||||
})
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
OptionFiles(m, PackFile)
|
||||
if p := kit.Select("", arg, 0); p != "" && !strings.HasSuffix(p, PS) {
|
||||
@ -48,18 +48,22 @@ func init() {
|
||||
m.Push(PATH, path.Join(p, s.Name())+kit.Select("", PS, s.IsDir()))
|
||||
m.Push(SIZE, kit.FmtSize(s.Size()))
|
||||
})
|
||||
m.PushAction(mdb.REMOVE)
|
||||
m.PushAction(mdb.REMOVE).StatusTimeCount()
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
var DiskFile = file.NewDiskFile()
|
||||
var PackFile = file.NewPackFile()
|
||||
var DiskFile = file.NewDiskFile()
|
||||
|
||||
func init() { file.Init(OptionFiles(ice.Pulse, DiskFile, PackFile)) }
|
||||
|
||||
func OptionFiles(m *ice.Message, f ...file.File) file.File {
|
||||
type optionMessage interface {
|
||||
Optionv(key string, arg ...ice.Any) ice.Any
|
||||
}
|
||||
|
||||
func OptionFiles(m optionMessage, f ...file.File) file.File {
|
||||
if len(f) > 1 {
|
||||
m.Optionv(ice.MSG_FILES, file.NewMultiFile(f...))
|
||||
} else if len(f) > 0 {
|
||||
@ -67,18 +71,18 @@ func OptionFiles(m *ice.Message, f ...file.File) file.File {
|
||||
}
|
||||
return m.Optionv(ice.MSG_FILES).(file.File)
|
||||
}
|
||||
func StatFile(m *ice.Message, p string) (os.FileInfo, error) { return OptionFiles(m).StatFile(p) }
|
||||
func OpenFile(m *ice.Message, p string) (io.ReadCloser, error) { return OptionFiles(m).OpenFile(p) }
|
||||
func CreateFile(m *ice.Message, p string) (io.WriteCloser, string, error) {
|
||||
func StatFile(m optionMessage, p string) (os.FileInfo, error) { return OptionFiles(m).StatFile(p) }
|
||||
func OpenFile(m optionMessage, p string) (io.ReadCloser, error) { return OptionFiles(m).OpenFile(p) }
|
||||
func CreateFile(m optionMessage, p string) (io.WriteCloser, string, error) {
|
||||
return OptionFiles(m).CreateFile(p)
|
||||
}
|
||||
func AppendFile(m *ice.Message, p string) (io.ReadWriteCloser, string, error) {
|
||||
func AppendFile(m optionMessage, p string) (io.ReadWriteCloser, string, error) {
|
||||
w, e := OptionFiles(m).AppendFile(p)
|
||||
return w, p, e
|
||||
}
|
||||
func WriteFile(m *ice.Message, p string, b []byte) error { return OptionFiles(m).WriteFile(p, b) }
|
||||
func WriteFile(m optionMessage, p string, b []byte) error { return OptionFiles(m).WriteFile(p, b) }
|
||||
|
||||
func ReadDir(m *ice.Message, p string) ([]os.FileInfo, error) {
|
||||
func ReadDir(m optionMessage, p string) ([]os.FileInfo, error) {
|
||||
list, e := OptionFiles(m).ReadDir(p)
|
||||
for i := 0; i < len(list)-1; i++ {
|
||||
for j := i + 1; j < len(list); j++ {
|
||||
@ -91,34 +95,25 @@ func ReadDir(m *ice.Message, p string) ([]os.FileInfo, error) {
|
||||
}
|
||||
return list, e
|
||||
}
|
||||
func MkdirAll(m *ice.Message, p string) string {
|
||||
func MkdirAll(m optionMessage, p string) string {
|
||||
OptionFiles(m).MkdirAll(p, ice.MOD_DIR)
|
||||
return p
|
||||
}
|
||||
func RemoveAll(m *ice.Message, p string) error { return OptionFiles(m).RemoveAll(p) }
|
||||
func Remove(m *ice.Message, p string) error { return OptionFiles(m).Remove(p) }
|
||||
func Rename(m *ice.Message, oldname string, newname string) error {
|
||||
func RemoveAll(m optionMessage, p string) error { return OptionFiles(m).RemoveAll(p) }
|
||||
func Remove(m optionMessage, p string) error { return OptionFiles(m).Remove(p) }
|
||||
func Rename(m optionMessage, oldname string, newname string) error {
|
||||
MkdirAll(m, path.Dir(newname))
|
||||
return OptionFiles(m).Rename(oldname, newname)
|
||||
}
|
||||
func Symlink(m *ice.Message, oldname string, newname string) error {
|
||||
func Symlink(m optionMessage, oldname string, newname string) error {
|
||||
return OptionFiles(m).Symlink(oldname, newname)
|
||||
}
|
||||
func Link(m *ice.Message, oldname string, newname string) error {
|
||||
func Link(m optionMessage, oldname string, newname string) error {
|
||||
return OptionFiles(m).Link(oldname, newname)
|
||||
}
|
||||
|
||||
func Exists(m *ice.Message, p string, cb ...func(string)) bool {
|
||||
func Exists(m optionMessage, p string) bool {
|
||||
if _, e := OptionFiles(m).StatFile(p); e == nil {
|
||||
for _, cb := range cb {
|
||||
cb(p)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
func ExistsFile(m *ice.Message, p string) bool {
|
||||
if s, e := OptionFiles(m).StatFile(p); e == nil && !s.IsDir() {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@ -127,7 +122,7 @@ func NewReadCloser(r io.Reader) io.ReadCloser { return file.NewReadCloser(r) }
|
||||
func NewWriteCloser(w func([]byte) (int, error), c func() error) io.WriteCloser {
|
||||
return file.NewWriteCloser(w, c)
|
||||
}
|
||||
func Close(m *ice.Message, p ice.Any) {
|
||||
func Close(m optionMessage, p ice.Any) {
|
||||
if w, ok := p.(io.Closer); ok {
|
||||
w.Close()
|
||||
}
|
||||
|
@ -3,20 +3,18 @@ package nfs
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _defs_file(m *ice.Message, name string, text ...string) {
|
||||
if s, e := os.Stat(path.Join(m.Option(DIR_ROOT), name)); e == nil && s.Size() > 0 {
|
||||
if Exists(m, path.Join(m.Option(DIR_ROOT), name)) {
|
||||
return
|
||||
}
|
||||
for i, v := range text {
|
||||
if b, e := kit.Render(v, m); !m.WarnNotValid(e) {
|
||||
if b, e := kit.Render(v, m); !m.Warn(e) {
|
||||
text[i] = string(b)
|
||||
}
|
||||
}
|
||||
@ -45,16 +43,16 @@ func _copy_file(m *ice.Message, name string, from ...string) {
|
||||
})
|
||||
}
|
||||
func _link_file(m *ice.Message, name string, from string) {
|
||||
if m.WarnNotValid(from == "", FROM) {
|
||||
if m.Warn(from == "", ice.ErrNotValid, FROM) {
|
||||
return
|
||||
}
|
||||
name = path.Join(m.Option(DIR_ROOT), name)
|
||||
from = path.Join(m.Option(DIR_ROOT), from)
|
||||
if m.WarnNotFound(!Exists(m, from), from) {
|
||||
if m.Warn(!Exists(m, from), ice.ErrNotFound, from) {
|
||||
return
|
||||
}
|
||||
Remove(m, name)
|
||||
if MkdirAll(m, path.Dir(name)); m.WarnNotValid(Link(m, from, name)) && m.WarnNotValid(Symlink(m, from, name), from) {
|
||||
if MkdirAll(m, path.Dir(name)); m.Warn(Link(m, from, name)) && m.Warn(Symlink(m, from, name), ice.ErrWarn, from) {
|
||||
return
|
||||
}
|
||||
m.Logs(SAVE, FILE, name, FROM, from).Echo(name)
|
||||
@ -73,8 +71,6 @@ const PUSH = "push"
|
||||
const COPY = "copy"
|
||||
const LINK = "link"
|
||||
const LOAD = "load"
|
||||
const MOVE = "move"
|
||||
const MOVETO = "moveto"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
@ -96,18 +92,10 @@ func init() {
|
||||
LINK: {Name: "link file from run", Help: "链接", Hand: func(m *ice.Message, arg ...string) {
|
||||
_link_file(m, arg[0], arg[1])
|
||||
}},
|
||||
MOVE: {Name: "move file from run", Help: "移动", Hand: func(m *ice.Message, arg ...string) {
|
||||
arg[1] = path.Join(m.Option(DIR_ROOT), arg[1])
|
||||
arg[0] = path.Join(m.Option(DIR_ROOT), arg[0])
|
||||
Rename(m, arg[1], arg[0])
|
||||
}},
|
||||
MOVETO: {Name: "moveto path from run", Help: "移动到", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(arg[1:], func(from string) { m.Cmd(MOVE, path.Join(arg[0], path.Base(from)), from) })
|
||||
}},
|
||||
})
|
||||
}
|
||||
func Create(m *ice.Message, p string, cb ice.Any) string {
|
||||
if f, p, e := CreateFile(m, p); !m.WarnNotValid(e) {
|
||||
func Create(m *ice.Message, p string, cb ice.Any) {
|
||||
if f, p, e := CreateFile(m, p); !m.Warn(e) {
|
||||
defer f.Close()
|
||||
switch cb := cb.(type) {
|
||||
case func(io.Writer, string):
|
||||
@ -118,10 +106,9 @@ func Create(m *ice.Message, p string, cb ice.Any) string {
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
func Append(m *ice.Message, p string, cb ice.Any) {
|
||||
if f, p, e := AppendFile(m, p); !m.WarnNotValid(e) {
|
||||
if f, p, e := AppendFile(m, p); !m.Warn(e) {
|
||||
defer f.Close()
|
||||
switch cb := cb.(type) {
|
||||
case func(io.Writer, string):
|
||||
@ -134,12 +121,7 @@ func Append(m *ice.Message, p string, cb ice.Any) {
|
||||
}
|
||||
}
|
||||
func Save(m *ice.Message, w io.Writer, s string, cb ice.Any) {
|
||||
switch content := m.Optionv(CONTENT).(type) {
|
||||
case io.Reader:
|
||||
io.Copy(w, content)
|
||||
return
|
||||
}
|
||||
if n, e := fmt.Fprint(w, s); !m.WarnNotValid(e) {
|
||||
if n, e := fmt.Fprint(w, s); !m.Warn(e) {
|
||||
switch cb := cb.(type) {
|
||||
case func(int):
|
||||
cb(n)
|
||||
@ -149,7 +131,7 @@ func Save(m *ice.Message, w io.Writer, s string, cb ice.Any) {
|
||||
}
|
||||
}
|
||||
func Copy(m *ice.Message, w io.Writer, r io.Reader, cb ice.Any) {
|
||||
if n, e := io.Copy(w, r); !m.WarnNotValid(e) {
|
||||
if n, e := io.Copy(w, r); !m.Warn(e) {
|
||||
switch cb := cb.(type) {
|
||||
case func(int):
|
||||
cb(int(n))
|
||||
@ -158,7 +140,7 @@ func Copy(m *ice.Message, w io.Writer, r io.Reader, cb ice.Any) {
|
||||
}
|
||||
}
|
||||
}
|
||||
func CopyStream(m *ice.Message, to io.Writer, from io.Reader, cache, total int, cb ice.Any) {
|
||||
func CopyStream(m *ice.Message, to io.WriteCloser, from io.ReadCloser, cache, total int, cb ice.Any) {
|
||||
kit.If(total == 0, func() { total = 1 })
|
||||
count, buf := 0, make([]byte, cache)
|
||||
for {
|
||||
@ -176,7 +158,7 @@ func CopyStream(m *ice.Message, to io.Writer, from io.Reader, cache, total int,
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
if e == io.EOF || m.WarnNotValid(e) {
|
||||
if e == io.EOF || m.Warn(e) {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -215,14 +197,3 @@ func Pipe(m *ice.Message, cb ice.Any) io.WriteCloser {
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
||||
func TempName(m *ice.Message) string {
|
||||
return m.Cmdx(SAVE, path.Join(ice.VAR_TMP, kit.Hashs(mdb.UNIQ)), "")
|
||||
}
|
||||
func Temp(m *ice.Message, cb func(p string)) {
|
||||
p := TempName(m)
|
||||
defer os.Remove(p)
|
||||
cb(p)
|
||||
}
|
||||
|
||||
var ImageResize = func(m *ice.Message, p string, height, width uint) bool { return false }
|
||||
|
@ -2,6 +2,7 @@ package nfs
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"archive/zip"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"os"
|
||||
@ -13,14 +14,25 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _zip_list(m *ice.Message, p string, cb func(zip.FileHeader, io.Reader, int)) {
|
||||
if f, e := zip.OpenReader(p); m.Warn(e, ice.ErrNotValid, p) {
|
||||
return
|
||||
} else {
|
||||
defer f.Close()
|
||||
for i, f := range f.File {
|
||||
if r, e := f.Open(); e == nil {
|
||||
defer r.Close()
|
||||
cb(f.FileHeader, r, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func _tar_list(m *ice.Message, p string, cb func(*tar.Header, io.Reader, int)) {
|
||||
Open(m, p, func(r io.Reader) {
|
||||
for {
|
||||
switch kit.Ext(p) {
|
||||
case TGZ:
|
||||
p = kit.Keys(kit.TrimExt(p, kit.Ext(p)), TAR, GZ)
|
||||
case GZ:
|
||||
if f, e := gzip.NewReader(r); m.WarnNotValid(e, p) {
|
||||
if f, e := gzip.NewReader(r); m.Warn(e, ice.ErrNotValid, p) {
|
||||
return
|
||||
} else {
|
||||
defer f.Close()
|
||||
@ -30,7 +42,7 @@ func _tar_list(m *ice.Message, p string, cb func(*tar.Header, io.Reader, int)) {
|
||||
i := 0
|
||||
for r := tar.NewReader(r); ; i++ {
|
||||
h, e := r.Next()
|
||||
if m.WarnNotValid(e) || e == io.EOF {
|
||||
if m.Warn(e) || e == io.EOF {
|
||||
break
|
||||
}
|
||||
if h.Size == 0 {
|
||||
@ -49,9 +61,8 @@ func _tar_list(m *ice.Message, p string, cb func(*tar.Header, io.Reader, int)) {
|
||||
}
|
||||
|
||||
const (
|
||||
XZ = "xz"
|
||||
GZ = "gz"
|
||||
TGZ = "tgz"
|
||||
ZIP = "zip"
|
||||
)
|
||||
const TAR = "tar"
|
||||
|
||||
@ -61,11 +72,23 @@ func init() {
|
||||
mdb.NEXT: {Hand: func(m *ice.Message, arg ...string) { mdb.PrevPage(m, arg[0], kit.Slice(arg, 1)...) }},
|
||||
mdb.PREV: {Hand: func(m *ice.Message, arg ...string) { mdb.NextPageLimit(m, arg[0], kit.Slice(arg, 1)...) }},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list, size := kit.Dict(), 0
|
||||
if kit.Ext(m.Option(PATH)) == ZIP {
|
||||
m.Cmdy(ZIP, mdb.EXPORT, arg)
|
||||
_zip_list(m, m.Option(PATH), func(h zip.FileHeader, r io.Reader, i int) {
|
||||
p := path.Join(path.Dir(m.Option(PATH)), kit.Split(path.Base(m.Option(PATH)), "-.")[0], h.Name)
|
||||
if strings.HasSuffix(h.Name, PS) {
|
||||
MkdirAll(m, p)
|
||||
return
|
||||
}
|
||||
kit.IfNoKey(list, path.Dir(p), func(p string) { MkdirAll(m, p) })
|
||||
Create(m, p, func(w io.Writer) {
|
||||
os.Chmod(p, os.FileMode(h.Mode()))
|
||||
Copy(m, w, r, func(n int) { size += n })
|
||||
kit.If(m.Option(FILE), func() { m.Cmdy(DIR, p).Cmdy(CAT, p) })
|
||||
})
|
||||
})
|
||||
return
|
||||
}
|
||||
list, size := kit.Dict(), 0
|
||||
_tar_list(m, m.Option(PATH), func(h *tar.Header, r io.Reader, i int) {
|
||||
if h.Name == m.Option(FILE) || m.Option(FILE) == "" {
|
||||
p := path.Join(path.Dir(m.Option(PATH)), h.Name)
|
||||
@ -87,10 +110,6 @@ func init() {
|
||||
m.Cmdy(DIR, arg)
|
||||
return
|
||||
}
|
||||
if kit.Ext(arg[0]) == ZIP {
|
||||
m.Cmdy(ZIP, arg)
|
||||
return
|
||||
}
|
||||
page, size := mdb.OptionPages(m, kit.Slice(arg, 2)...)
|
||||
_tar_list(m, arg[0], func(h *tar.Header, r io.Reader, i int) {
|
||||
if len(kit.Slice(arg, 0, 2)) > 1 {
|
||||
|
@ -1,55 +0,0 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const TEMPLATE = "template"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TEMPLATE: {Name: "template index path auto", Help: "模板", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.AddRender(ice.RENDER_TEMPLATE, func(m *ice.Message, args ...ice.Any) string {
|
||||
return Template(m, kit.Format(args[0]), args[1:]...)
|
||||
})
|
||||
}},
|
||||
}), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy(ice.COMMAND).Option(ice.MSG_DISPLAY, "")
|
||||
return
|
||||
}
|
||||
m.Search(arg[0], func(p *ice.Context, c *ice.Context, key string, cmd *ice.Command) {
|
||||
if p := TemplatePath(m); p != "" {
|
||||
if len(kit.Slice(arg, 0, 2)) == 1 {
|
||||
m.Cmdy(DIR, p)
|
||||
} else {
|
||||
m.Cmdy(CAT, arg[1])
|
||||
}
|
||||
}
|
||||
})
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func init() { ice.Info.Template = Template }
|
||||
|
||||
func Template(m *ice.Message, p string, data ...ice.Any) string {
|
||||
if text := TemplateText(m, p); text == "" {
|
||||
return ""
|
||||
} else if len(data) == 0 {
|
||||
return kit.Renders(text, m)
|
||||
} else {
|
||||
return kit.Renders(text, data[0])
|
||||
}
|
||||
}
|
||||
|
||||
var TemplateText = func(m *ice.Message, p string) string {
|
||||
return m.Cmdx(CAT, kit.Select(TemplatePath(m, path.Base(p)), m.Option("_template")))
|
||||
}
|
||||
var TemplatePath = func(m *ice.Message, arg ...string) string {
|
||||
return path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...))
|
||||
}
|
@ -2,6 +2,7 @@ package nfs
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
@ -10,25 +11,29 @@ import (
|
||||
)
|
||||
|
||||
func _trash_create(m *ice.Message, from string) {
|
||||
if m.WarnNotValid(from == "", FROM) {
|
||||
if m.Warn(from == "", ice.ErrNotValid, FROM) {
|
||||
return
|
||||
}
|
||||
s, e := StatFile(m, from)
|
||||
if m.WarnNotFound(e, from) {
|
||||
defer os.Remove(from)
|
||||
if m.Warn(e, ice.ErrNotFound, from) {
|
||||
return
|
||||
}
|
||||
defer Remove(m, from)
|
||||
p := path.Join(ice.VAR_TRASH, path.Base(from))
|
||||
kit.If(!s.IsDir(), func() { Open(m, from, func(r io.Reader) { p = path.Join(ice.VAR_TRASH, kit.HashsPath(r)) }) })
|
||||
RemoveAll(m, p)
|
||||
kit.If(!m.WarnNotValid(Rename(m, from, p)), func() { mdb.HashCreate(m, FROM, kit.Paths(from), FILE, p) })
|
||||
kit.If(!m.Warn(Rename(m, from, p)), func() { mdb.HashCreate(m, FROM, kit.Paths(from), FILE, p) })
|
||||
}
|
||||
|
||||
const TRASH = "trash"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
TRASH: {Name: "trash hash auto", Help: "回收站", Actions: ice.MergeActions(ice.Actions{
|
||||
TRASH: {Name: "trash hash auto prunes", Help: "回收站", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.REVERT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
Rename(m, m.Option(FILE), m.Option(FROM))
|
||||
mdb.HashRemove(m, m.OptionSimple(mdb.HASH))
|
||||
}},
|
||||
mdb.CREATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_trash_create(m, kit.Paths(m.Option(FROM)))
|
||||
}},
|
||||
@ -36,11 +41,6 @@ func init() {
|
||||
Remove(m, m.Option(FILE))
|
||||
mdb.HashRemove(m, m.OptionSimple(mdb.HASH))
|
||||
}},
|
||||
mdb.REVERT: {Help: "恢复", Icon: "bi bi-folder-symlink", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := mdb.HashSelect(m.Spawn(), m.Option(mdb.HASH))
|
||||
Rename(m, msg.Append(FILE), msg.Append(FROM))
|
||||
mdb.HashRemove(m, m.OptionSimple(mdb.HASH))
|
||||
}},
|
||||
mdb.PRUNES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashPrunes(m, nil).Table(func(value ice.Maps) { Remove(m, value[FILE]) })
|
||||
}},
|
||||
|
@ -1,72 +0,0 @@
|
||||
package nfs
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _zip_list(m *ice.Message, p string, cb func(zip.FileHeader, io.Reader, int)) {
|
||||
if f, e := zip.OpenReader(p); m.WarnNotFound(e, p) {
|
||||
return
|
||||
} else {
|
||||
defer f.Close()
|
||||
for i, f := range f.File {
|
||||
if r, e := f.Open(); e == nil {
|
||||
defer r.Close()
|
||||
cb(f.FileHeader, r, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const ZIP = "zip"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ZIP: {Name: "zip path file auto page", Help: "打包", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.NEXT: {Hand: func(m *ice.Message, arg ...string) { mdb.PrevPage(m, arg[0], kit.Slice(arg, 1)...) }},
|
||||
mdb.PREV: {Hand: func(m *ice.Message, arg ...string) { mdb.NextPageLimit(m, arg[0], kit.Slice(arg, 1)...) }},
|
||||
mdb.EXPORT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list, size := kit.Dict(), 0
|
||||
_zip_list(m, m.Option(PATH), func(h zip.FileHeader, r io.Reader, i int) {
|
||||
p := path.Join(path.Dir(m.Option(PATH)), kit.Split(path.Base(m.Option(PATH)), "_-.")[0], h.Name)
|
||||
if strings.HasSuffix(h.Name, PS) {
|
||||
MkdirAll(m, p)
|
||||
return
|
||||
}
|
||||
kit.IfNoKey(list, path.Dir(p), func(p string) { MkdirAll(m, p) })
|
||||
Create(m, p, func(w io.Writer) {
|
||||
os.Chmod(p, os.FileMode(h.Mode()))
|
||||
Copy(m, w, r, func(n int) { size += n })
|
||||
kit.If(m.Option(FILE), func() { m.Cmdy(DIR, p).Cmdy(CAT, p) })
|
||||
})
|
||||
})
|
||||
}},
|
||||
}, mdb.PageListAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 || strings.HasSuffix(arg[0], PS) {
|
||||
m.Cmdy(DIR, arg)
|
||||
return
|
||||
}
|
||||
page, size := mdb.OptionPages(m, kit.Slice(arg, 2)...)
|
||||
_zip_list(m, arg[0], func(h zip.FileHeader, r io.Reader, i int) {
|
||||
if len(kit.Slice(arg, 0, 2)) > 1 {
|
||||
if h.Name != arg[1] {
|
||||
return
|
||||
}
|
||||
m.Echo(string(ReadAll(m, r)[:]))
|
||||
}
|
||||
if i >= (page-1)*size && i < page*size {
|
||||
m.Push(mdb.TIME, h.ModTime().Format(ice.MOD_TIME)).Push(FILE, h.Name).Push(SIZE, kit.FmtSize(int64(h.UncompressedSize)))
|
||||
}
|
||||
})
|
||||
m.PushAction(mdb.EXPORT)
|
||||
}},
|
||||
})
|
||||
}
|
@ -9,24 +9,20 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func Render(m *ice.Message, cmd string, arg ...ice.Any) (res string) {
|
||||
func Render(msg *ice.Message, cmd string, arg ...ice.Any) (res string) {
|
||||
switch args := kit.Simple(arg...); cmd {
|
||||
case ice.RENDER_RESULT:
|
||||
kit.If(len(args) > 0, func() { m.Resultv(args) })
|
||||
res = m.Result()
|
||||
kit.If(len(args) > 0, func() { msg.Resultv(args) })
|
||||
res = msg.Result()
|
||||
case ice.RENDER_VOID:
|
||||
return res
|
||||
default:
|
||||
if res = m.Result(); res == "" {
|
||||
if m.IsCliUA() {
|
||||
res = m.TableEchoWithStatus().Result()
|
||||
} else {
|
||||
res = m.TableEcho().Result()
|
||||
}
|
||||
if res = msg.Result(); res == "" {
|
||||
res = msg.TableEcho().Result()
|
||||
}
|
||||
}
|
||||
if fmt.Fprint(m.O, res); !strings.HasSuffix(res, lex.NL) {
|
||||
fmt.Fprint(m.O, lex.NL)
|
||||
if fmt.Fprint(msg.O, res); !strings.HasSuffix(res, lex.NL) {
|
||||
fmt.Fprint(msg.O, lex.NL)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/log"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
@ -45,7 +44,7 @@ func (f *Frame) prompt(m *ice.Message, arg ...string) *Frame {
|
||||
case mdb.COUNT:
|
||||
fmt.Fprintf(f.stdout, "%d", f.count)
|
||||
case tcp.HOSTNAME:
|
||||
fmt.Fprintf(f.stdout, ice.Info.NodeName)
|
||||
fmt.Fprintf(f.stdout, "%s", kit.Slice(kit.Split(ice.Info.Hostname, " -/."), -1)[0])
|
||||
case mdb.TIME:
|
||||
fmt.Fprintf(f.stdout, kit.Slice(kit.Split(time.Now().Format(ice.MOD_TIME)), -1)[0])
|
||||
case TARGET:
|
||||
@ -79,7 +78,7 @@ func (f *Frame) change(m *ice.Message, ls []string) []string {
|
||||
func (f *Frame) alias(m *ice.Message, ls []string) []string {
|
||||
if len(ls) == 0 {
|
||||
return ls
|
||||
} else if alias := kit.Simple(kit.Value(m.Optionv(ice.SSH_ALIAS), ls[0])); len(alias) > 0 {
|
||||
} else if alias := kit.Simple(kit.Value(m.Optionv(ice.MSG_ALIAS), ls[0])); len(alias) > 0 {
|
||||
ls = append(alias, ls[1:]...)
|
||||
}
|
||||
return ls
|
||||
@ -96,39 +95,40 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
|
||||
return ""
|
||||
}
|
||||
msg := m.Spawn(f.target)
|
||||
kit.If(h == STDIO, func() { msg.Option(ice.LOG_TRACEID, log.Traceid(m)) })
|
||||
if msg.Cmdy(ls); h == STDIO && msg.IsErrNotFoundIndex() {
|
||||
if msg.Cmdy(ls); h == STDIO && msg.IsErrNotFound() {
|
||||
msg.SetResult().Cmdy(cli.SYSTEM, ls)
|
||||
}
|
||||
kit.If(m.Option(ice.MSG_STATUS) == "", func() { m.StatusTimeCount() })
|
||||
f.res = Render(msg, msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...)
|
||||
return ""
|
||||
}
|
||||
func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
||||
kit.If(f.source == STDIO, func() { m.Option(ice.LOG_DISABLE, ice.TRUE) })
|
||||
// kit.If(f.source == STDIO, func() { m.Options(MESSAGE, m, ice.LOG_DISABLE, ice.TRUE) })
|
||||
f.ps1 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS1)))
|
||||
f.ps2 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS2)))
|
||||
ps, bio := f.ps1, bufio.NewScanner(f.stdin)
|
||||
m.I, m.O = f.stdin, f.stdout
|
||||
for f.prompt(m.Sleep300ms(), ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) {
|
||||
ps, bio := f.ps1, bufio.NewScanner(f.stdin)
|
||||
for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) {
|
||||
if len(bio.Text()) == 0 && h == STDIO {
|
||||
continue
|
||||
}
|
||||
f.count++
|
||||
if f.count++; len(bio.Text()) == 0 {
|
||||
continue
|
||||
}
|
||||
if strings.HasSuffix(bio.Text(), "\\") {
|
||||
line += bio.Text()[:len(bio.Text())-1]
|
||||
ps = f.ps2
|
||||
continue
|
||||
}
|
||||
if line += bio.Text(); strings.Count(line, "`")%2 == 1 {
|
||||
line += lex.NL
|
||||
ps = f.ps2
|
||||
continue
|
||||
} else if len(bio.Text()) == 0 {
|
||||
continue
|
||||
} else if strings.HasSuffix(bio.Text(), "\\") {
|
||||
line += bio.Text()[:len(bio.Text())-1]
|
||||
ps = f.ps2
|
||||
continue
|
||||
} else if strings.HasPrefix(strings.TrimSpace(line), "#") {
|
||||
}
|
||||
if strings.HasPrefix(strings.TrimSpace(line), "#") {
|
||||
line = ""
|
||||
continue
|
||||
} else if ps = f.ps1; f.stdout == os.Stdout && ice.Info.Colors {
|
||||
}
|
||||
if ps = f.ps1; f.stdout == os.Stdout && ice.Info.Colors {
|
||||
f.printf(m, "\033[0m")
|
||||
}
|
||||
line = f.parse(m, h, line)
|
||||
@ -137,7 +137,12 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
||||
}
|
||||
|
||||
func (f *Frame) Begin(m *ice.Message, arg ...string) {
|
||||
ice.Info.Colors = kit.IsIn(strings.Split(os.Getenv(cli.TERM), "-")[0], "xterm", "screen")
|
||||
switch strings.Split(os.Getenv(cli.TERM), "-")[0] {
|
||||
case "xterm", "screen":
|
||||
ice.Info.Colors = true
|
||||
default:
|
||||
ice.Info.Colors = false
|
||||
}
|
||||
}
|
||||
func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
m.Optionv(FRAME, f)
|
||||
@ -148,7 +153,6 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
f.pipe, f.stdin, f.stdout = w, r, os.Stdout
|
||||
kit.If(f.target == nil, func() { f.target = m.Target() })
|
||||
m.Optionv(ice.MSG_OPTS, ice.MSG_USERNAME, ice.MSG_USERROLE)
|
||||
m.Option(ice.MSG_USERWEB, "http://localhost:9020")
|
||||
f.scan(m, STDIO, "")
|
||||
default:
|
||||
if m.Option(ice.MSG_SCRIPT) != "" {
|
||||
@ -162,16 +166,11 @@ func (f *Frame) Start(m *ice.Message, arg ...string) {
|
||||
if msg := m.Cmd(nfs.CAT, m.Option(ice.MSG_SCRIPT, f.source)); msg.IsErr() {
|
||||
return
|
||||
} else {
|
||||
kit.If(m.Option(nfs.CAT_CONTENT), func() { m.Option(nfs.CAT_CONTENT, "") })
|
||||
buf := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
|
||||
f.stdin, f.stdout = bytes.NewBufferString(msg.Result()), buf
|
||||
defer func() { m.Echo(buf.String()) }()
|
||||
}
|
||||
if target, ok := m.Optionv(ice.SSH_TARGET).(*ice.Context); ok {
|
||||
f.target = target
|
||||
} else {
|
||||
f.target = m.Source()
|
||||
}
|
||||
f.target = m.Source()
|
||||
f.scan(m, "", "")
|
||||
}
|
||||
}
|
||||
@ -184,6 +183,7 @@ func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server
|
||||
const (
|
||||
FRAME = "frame"
|
||||
SHELL = "shell"
|
||||
WEBIO = "webio"
|
||||
STDIO = "stdio"
|
||||
PS1 = "PS1"
|
||||
PS2 = "PS2"
|
||||
@ -194,6 +194,7 @@ const (
|
||||
TARGET = "target"
|
||||
PROMPT = "prompt"
|
||||
PRINTF = "printf"
|
||||
SCREEN = "screen"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -227,6 +228,16 @@ func init() {
|
||||
f.printf(m, kit.Select(m.Option(nfs.CONTENT), arg, 0))
|
||||
}
|
||||
}},
|
||||
SCREEN: {Name: "screen run text", Help: "输出命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
if f, ok := m.Target().Server().(*Frame); ok {
|
||||
for _, line := range kit.Split(arg[0], lex.NL, lex.NL) {
|
||||
fmt.Fprintf(f.pipe, line+lex.NL)
|
||||
f.printf(m, line+lex.NL)
|
||||
m.Sleep300ms()
|
||||
}
|
||||
m.Echo(f.res)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -6,4 +6,4 @@ const SSH = "ssh"
|
||||
|
||||
var Index = &ice.Context{Name: SSH, Help: "终端模块"}
|
||||
|
||||
func init() { ice.Index.Register(Index, &Frame{}, SOURCE, RETURN, TARGET, PROMPT, PRINTF) }
|
||||
func init() { ice.Index.Register(Index, &Frame{}, SOURCE, RETURN, TARGET, PROMPT, PRINTF, SCREEN) }
|
||||
|
@ -19,7 +19,7 @@ func _server_udp(m *ice.Message, arg ...string) {
|
||||
m.Assert(e)
|
||||
buf := make([]byte, 2*ice.MOD_BUFS)
|
||||
for {
|
||||
if n, from, e := l.ReadFromUDP(buf[:]); !m.WarnNotValid(e) {
|
||||
if n, from, e := l.ReadFromUDP(buf[:]); !m.Warn(e) {
|
||||
cb(from, buf[:n])
|
||||
} else {
|
||||
break
|
||||
@ -34,23 +34,20 @@ func _client_dial_udp4(m *ice.Message, arg ...string) {
|
||||
defer kit.If(e == nil, func() { c.Close() })
|
||||
switch cb := m.OptionCB("").(type) {
|
||||
case func(*net.UDPConn):
|
||||
kit.If(!m.WarnNotValid(e), func() { cb(c) })
|
||||
kit.If(!m.Warn(e), func() { cb(c) })
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
UDP4 = "udp4"
|
||||
SEND = "send"
|
||||
RECV = "recv"
|
||||
ECHO = "echo"
|
||||
DONE = "done"
|
||||
DIRECT = "direct"
|
||||
UDP4 = "udp4"
|
||||
SEND = "send"
|
||||
RECV = "recv"
|
||||
)
|
||||
|
||||
func UDPAddr(m *ice.Message, host, port string) *net.UDPAddr {
|
||||
if addr, e := net.ResolveUDPAddr(UDP4, host+nfs.DF+port); !m.WarnNotValid(e, host, port, logs.FileLineMeta(2)) {
|
||||
if addr, e := net.ResolveUDPAddr(UDP4, host+nfs.DF+port); !m.Warn(e, ice.ErrNotValid, host, port, logs.FileLineMeta(2)) {
|
||||
return addr
|
||||
}
|
||||
return nil
|
||||
|
@ -2,7 +2,6 @@ package tcp
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
@ -30,12 +29,12 @@ func (c *Conn) Write(b []byte) (int, error) {
|
||||
func (c *Conn) Close() error { return c.Conn.Close() }
|
||||
|
||||
func _client_dial(m *ice.Message, arg ...string) {
|
||||
c, e := net.DialTimeout(TCP, m.Option(HOST)+nfs.DF+m.Option(PORT), 3*time.Second)
|
||||
c, e := net.Dial(TCP, m.Option(HOST)+nfs.DF+m.Option(PORT))
|
||||
c = &Conn{Conn: c, m: m, s: &Stat{}}
|
||||
defer kit.If(e == nil, func() { c.Close() })
|
||||
switch cb := m.OptionCB("").(type) {
|
||||
case func(net.Conn):
|
||||
kit.If(!m.WarnNotValid(e), func() { cb(c) })
|
||||
kit.If(!m.Warn(e), func() { cb(c) })
|
||||
default:
|
||||
m.ErrorNotImplement(cb)
|
||||
}
|
||||
@ -48,7 +47,7 @@ const CLIENT = "client"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CLIENT: {Help: "客户端", Actions: ice.MergeActions(ice.Actions{
|
||||
CLIENT: {Name: "client hash auto prunes", Help: "客户端", Actions: ice.MergeActions(ice.Actions{
|
||||
DIAL: {Name: "dial type name port=9010 host=", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case UDP4:
|
||||
|
@ -2,34 +2,16 @@ package tcp
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _host_domain(m *ice.Message) string {
|
||||
return kit.GetValid(
|
||||
func() string { return m.Option(ice.TCP_DOMAIN) },
|
||||
func() string { return mdb.Config(m, DOMAIN) },
|
||||
func() string { return os.Getenv(ice.TCP_DOMAIN) },
|
||||
func() string {
|
||||
if !kit.IsIn(m.ActionKey(), "", ice.LIST) {
|
||||
return m.Cmdv(HOST, mdb.Config(m, ice.MAIN), aaa.IP)
|
||||
}
|
||||
return ""
|
||||
},
|
||||
func() string {
|
||||
return LOCALHOST
|
||||
},
|
||||
)
|
||||
}
|
||||
func _host_list(m *ice.Message, name string) *ice.Message {
|
||||
func _host_list(m *ice.Message, name string) {
|
||||
if ifs, e := net.Interfaces(); m.Assert(e) {
|
||||
for _, v := range ifs {
|
||||
if !strings.Contains(v.Name, name) || len(v.HardwareAddr.String()) == 0 {
|
||||
@ -41,43 +23,31 @@ func _host_list(m *ice.Message, name string) *ice.Message {
|
||||
if strings.Contains(ip[0], nfs.DF) || len(ip) == 0 {
|
||||
continue
|
||||
}
|
||||
m.Push(mdb.INDEX, v.Index).Push(mdb.NAME, v.Name).Push(aaa.IP, ip[0]).Push(MASK, ip[1]).Push(MAC_ADDRESS, v.HardwareAddr.String())
|
||||
m.Push(mdb.INDEX, v.Index).Push(mdb.NAME, v.Name).Push(aaa.IP, ip[0]).Push("mask", ip[1]).Push("hard", v.HardwareAddr.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m.SortInt(mdb.INDEX).StatusTimeCount(DOMAIN, _host_domain(m))
|
||||
if len(m.Appendv(aaa.IP)) == 0 {
|
||||
m.Push(mdb.INDEX, -1).Push(mdb.NAME, LOCALHOST).Push(aaa.IP, "127.0.0.1").Push("mask", "255.0.0.0").Push("hard", "")
|
||||
}
|
||||
m.SortInt(mdb.INDEX).StatusTimeCount()
|
||||
}
|
||||
|
||||
const (
|
||||
LOCALHOST = "localhost"
|
||||
MAC_ADDRESS = "mac-address"
|
||||
MASK = "mask"
|
||||
LOCALHOST = "localhost"
|
||||
|
||||
DOMAIN = "domain"
|
||||
GATEWAY = "gateway"
|
||||
MACHINE = "machine"
|
||||
ISLOCAL = "islocal"
|
||||
PUBLISH = "publish"
|
||||
GATEWAY = "gateway"
|
||||
)
|
||||
const HOST = "host"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
HOST: {Name: "host name auto domain", Help: "主机", Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(
|
||||
aaa.IP, "网络地址", MASK, "子网掩码", MAC_ADDRESS, "物理地址",
|
||||
)),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
HOST: {Name: "host name auto", Help: "主机", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd("", func(value ice.Maps) { m.Cmd("", aaa.WHITE, LOCALHOST, value[aaa.IP]) })
|
||||
ice.Info.Host = mdb.Config(m, DOMAIN)
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) && m.Cmd(HOST).Length() > 0 {
|
||||
ip := m.Cmdv(HOST, GATEWAY, aaa.IP)
|
||||
m.PushSearch(mdb.TYPE, GATEWAY, mdb.NAME, ip, mdb.TEXT, "http://"+ip)
|
||||
}
|
||||
}},
|
||||
aaa.WHITE: {Name: "white name text", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, mdb.TYPE, m.ActionKey(), m.OptionSimple(mdb.NAME, mdb.TEXT))
|
||||
@ -85,37 +55,32 @@ func init() {
|
||||
aaa.BLACK: {Name: "black name text", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, mdb.TYPE, m.ActionKey(), m.OptionSimple(mdb.NAME, mdb.TEXT))
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchForEach(m, arg, nil) {
|
||||
ip := m.Cmdv(HOST, GATEWAY, aaa.IP)
|
||||
m.PushSearch(mdb.TYPE, GATEWAY, mdb.NAME, ip, mdb.TEXT, "http://"+ip)
|
||||
}
|
||||
}},
|
||||
ISLOCAL: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] = strings.Split(strings.TrimPrefix(arg[0], "["), "]")[0]; arg[0] == "::1" || strings.HasPrefix(arg[0], "127.") || arg[0] == LOCALHOST {
|
||||
if arg[0] = strings.Split(strings.TrimPrefix(arg[0], "["), "]")[0]; arg[0] == "::1" || strings.HasPrefix(arg[0], "127.") {
|
||||
m.Echo(ice.OK)
|
||||
} else if mdb.HashSelectField(m, strings.Split(arg[0], nfs.DF)[0], mdb.TYPE) == aaa.WHITE {
|
||||
m.Echo(ice.OK)
|
||||
}
|
||||
}},
|
||||
PUBLISH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, p := range []string{LOCALHOST, "127.0.0.1", m.Option("tcp_localhost")} {
|
||||
if p != "" && strings.Contains(arg[0], p) {
|
||||
arg[0] = strings.Replace(arg[0], p, _host_domain(m), 1)
|
||||
break
|
||||
}
|
||||
if strings.Contains(arg[0], LOCALHOST) {
|
||||
arg[0] = strings.Replace(arg[0], LOCALHOST, m.Cmdv(HOST, aaa.IP), 1)
|
||||
} else if strings.Contains(arg[0], "127.0.0.1") {
|
||||
arg[0] = strings.Replace(arg[0], "127.0.0.1", m.Cmdv(HOST, aaa.IP), 1)
|
||||
}
|
||||
m.Echo(arg[0])
|
||||
}},
|
||||
GATEWAY: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Push(aaa.IP, kit.Keys(kit.Slice(strings.Split(m.Cmdv(HOST, aaa.IP), nfs.PT), 0, 3), "1"))
|
||||
}},
|
||||
DOMAIN: {Name: "domain ip", Help: "主机", Icon: "bi bi-house-check", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(aaa.IP), func(p string) { ice.Info.Host = p; mdb.Config(m, DOMAIN, p) })
|
||||
m.Echo(mdb.Config(m, DOMAIN))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.TEXT)), Hand: func(m *ice.Message, arg ...string) {
|
||||
_host_list(m, kit.Select("", arg, 0)).Table(func(value ice.Maps) {
|
||||
if value[aaa.IP] == mdb.Config(m, DOMAIN) {
|
||||
m.Push(mdb.STATUS, "current").PushButton("")
|
||||
} else {
|
||||
m.Push(mdb.STATUS, "").PushButton(DOMAIN)
|
||||
}
|
||||
})
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.TEXT), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
_host_list(m, kit.Select("", arg, 0))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
130
base/tcp/port.go
130
base/tcp/port.go
@ -3,8 +3,6 @@ package tcp
|
||||
import (
|
||||
"net"
|
||||
"path"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
@ -15,8 +13,9 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _port_right(m *ice.Message, current, begin, end int) string {
|
||||
kit.If(current >= end, func() { current = begin })
|
||||
func _port_right(m *ice.Message, arg ...string) string {
|
||||
current, end := kit.Int(kit.Select(mdb.Config(m, CURRENT), arg, 0)), kit.Int(mdb.Config(m, END))
|
||||
kit.If(current >= end, func() { current = kit.Int(mdb.Config(m, BEGIN)) })
|
||||
for i := current; i < end; i++ {
|
||||
if p := path.Join(ice.USR_LOCAL_DAEMON, kit.Format(i)); nfs.Exists(m, p) {
|
||||
|
||||
@ -33,138 +32,37 @@ func _port_right(m *ice.Message, current, begin, end int) string {
|
||||
}
|
||||
|
||||
const (
|
||||
PORT_22 = "22"
|
||||
PORT_80 = "80"
|
||||
PORT_443 = "443"
|
||||
PORT_9020 = "9020"
|
||||
PORT_9022 = "9022"
|
||||
|
||||
SOCKET = "socket"
|
||||
BEGIN = "begin"
|
||||
CURRENT = "current"
|
||||
RANDOM = "random"
|
||||
END = "end"
|
||||
PID = "pid"
|
||||
SPACE = "space"
|
||||
)
|
||||
const PORT = "port"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PORT: {Name: "port port path auto socket", Help: "端口", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case HOST, SERVER:
|
||||
m.Cmd(PORT, SOCKET, func(value ice.Maps) {
|
||||
switch value[mdb.STATUS] {
|
||||
case "LISTEN":
|
||||
m.Push(arg[0], strings.Replace(value["local"], "0.0.0.0", "127.0.0.1", 1))
|
||||
}
|
||||
})
|
||||
case PORT:
|
||||
if runtime.GOOS == "darwin" {
|
||||
ls := kit.SplitLine(m.Cmd("system", "sh", "-c", `lsof -nP -i4TCP | grep LISTEN | awk '{print $1 " " $9 }'`).Result())
|
||||
kit.For(ls, func(p string) {
|
||||
ls := kit.SplitWord(p)
|
||||
m.Push(arg[0], kit.Split(ls[1], ":")[1]).Push(SERVER, ls[0])
|
||||
})
|
||||
m.Sort(arg[0], ice.INT)
|
||||
return
|
||||
}
|
||||
m.Cmd(PORT, SOCKET, func(value ice.Maps) {
|
||||
switch value[mdb.STATUS] {
|
||||
case "LISTEN":
|
||||
m.Push(arg[0], strings.TrimPrefix(value["local"], "0.0.0.0:"))
|
||||
m.Push(mdb.NAME, "listen")
|
||||
}
|
||||
})
|
||||
}
|
||||
}},
|
||||
SOCKET: {Help: "端口", Hand: func(m *ice.Message, arg ...string) {
|
||||
parse := func(str string) int64 { port, _ := strconv.ParseInt(str, 16, 32); return port }
|
||||
trans := func(str string) string {
|
||||
switch str {
|
||||
case "01":
|
||||
return "ESTABLISHED"
|
||||
case "02":
|
||||
return "TCP_SYNC_SEND"
|
||||
case "03":
|
||||
return "TCP_SYNC_RECV"
|
||||
case "04":
|
||||
return "TCP_FIN_WAIT1"
|
||||
case "05":
|
||||
return "TCP_FIN_WAIT2"
|
||||
case "06":
|
||||
return "TIME_WAIT"
|
||||
case "07":
|
||||
return "TCP_CLOSE"
|
||||
case "08":
|
||||
return "TCP_CLOSE_WAIT"
|
||||
case "0A":
|
||||
return "LISTEN"
|
||||
default:
|
||||
return str
|
||||
}
|
||||
}
|
||||
stats := map[string]int{}
|
||||
m.Spawn().Split(m.Cmdx(nfs.CAT, "/proc/net/tcp")).Table(func(value ice.Maps) {
|
||||
stats[trans(value["st"])]++
|
||||
m.Push(mdb.STATUS, trans(value["st"]))
|
||||
ls := kit.Split(value["local_address"], ":")
|
||||
m.Push("local", kit.Format("%d.%d.%d.%d:%d", parse(ls[0][6:8]), parse(ls[0][4:6]), parse(ls[0][2:4]), parse(ls[0][:2]), parse(ls[1])))
|
||||
ls = kit.Split(value["rem_address"], ":")
|
||||
m.Push("remote", kit.Format("%d.%d.%d.%d:%d", parse(ls[0][6:8]), parse(ls[0][4:6]), parse(ls[0][2:4]), parse(ls[0][:2]), parse(ls[1])))
|
||||
})
|
||||
m.Spawn().Split(m.Cmdx(nfs.CAT, "/proc/net/tcp6")).Table(func(value ice.Maps) {
|
||||
stats[trans(value["st"])]++
|
||||
m.Push(mdb.STATUS, trans(value["st"]))
|
||||
ls := kit.Split(value["local_address"], ":")
|
||||
m.Push("local", kit.Format("%d.%d.%d.%d:%d", parse(ls[0][30:32]), parse(ls[0][28:30]), parse(ls[0][26:28]), parse(ls[0][24:26]), parse(ls[1])))
|
||||
ls = kit.Split(value["remote_address"], ":")
|
||||
m.Push("remote", kit.Format("%d.%d.%d.%d:%d", parse(ls[0][30:32]), parse(ls[0][28:30]), parse(ls[0][26:28]), parse(ls[0][24:26]), parse(ls[1])))
|
||||
})
|
||||
m.Sort("status,local", []string{"LISTEN", "ESTABLISHED", "TIME_WAIT"}).StatusTimeCount(stats)
|
||||
}},
|
||||
PORT: {Name: "port port path auto", Help: "端口", Actions: ice.MergeActions(ice.Actions{
|
||||
CURRENT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(mdb.Config(m, CURRENT)) }},
|
||||
aaa.RIGHT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_port_right(m, arg...)) }},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Assert(m.Option(PORT) != "")
|
||||
nfs.Trash(m, path.Join(ice.USR_LOCAL_DAEMON, m.Option(PORT)))
|
||||
mdb.HashRemove(m)
|
||||
}},
|
||||
aaa.RIGHT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(PortRight(m, arg...)) }},
|
||||
CURRENT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(mdb.Config(m, CURRENT)) }},
|
||||
STOP: {Hand: func(m *ice.Message, arg ...string) { PortCmds(m, arg...); mdb.HashModify(m, PID, "") }},
|
||||
START: {Hand: func(m *ice.Message, arg ...string) { PortCmds(m, arg...); mdb.HashModify(m, PID, m.Append(PID)) }},
|
||||
}, mdb.HashAction(BEGIN, 10000, END, 20000,
|
||||
mdb.SHORT, PORT, mdb.FIELD, "time,port,pid,cmd,name,text,icon,space,index",
|
||||
)), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(BEGIN, 10000, CURRENT, 10000, END, 20000)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
m.Cmdy(nfs.DIR, arg[1:], kit.Dict(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL_DAEMON, arg[0])))
|
||||
return
|
||||
}
|
||||
current := kit.Int(mdb.Config(m, BEGIN))
|
||||
mdb.HashSelect(m, arg...).Table(func(value ice.Maps) {
|
||||
current = kit.Max(current, kit.Int(value[PORT]))
|
||||
if value[PID] == "" {
|
||||
m.PushButton(START, nfs.TRASH)
|
||||
} else {
|
||||
m.PushButton(STOP)
|
||||
}
|
||||
m.Options(nfs.DIR_ROOT, ice.USR_LOCAL_DAEMON).Cmd(nfs.DIR, nfs.PWD, func(value ice.Maps) {
|
||||
bin := m.Cmdv(nfs.DIR, path.Join(value[nfs.PATH], ice.BIN), nfs.PATH)
|
||||
kit.If(bin == "", func() { bin = m.Cmdv(nfs.DIR, path.Join(value[nfs.PATH], "sbin"), nfs.PATH) })
|
||||
port := kit.Int(path.Base(value[nfs.PATH]))
|
||||
m.Push(mdb.TIME, value[mdb.TIME]).Push(PORT, port).Push(nfs.SIZE, value[nfs.SIZE]).Push(ice.BIN, strings.TrimPrefix(bin, value[nfs.PATH]))
|
||||
current = kit.Max(current, port)
|
||||
})
|
||||
m.PushAction(nfs.TRASH).StatusTimeCount(ctx.ConfigSimple(m, BEGIN, CURRENT, END)).SortInt(PORT)
|
||||
mdb.Config(m, CURRENT, current)
|
||||
m.StatusTimeCount(mdb.ConfigSimple(m, BEGIN, CURRENT, END)).SortInt(PORT)
|
||||
}},
|
||||
})
|
||||
ice.Info.Inputs = append(ice.Info.Inputs, func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case PORT:
|
||||
m.SetAppend().Cmdy(PORT, mdb.INPUTS, arg)
|
||||
}
|
||||
})
|
||||
}
|
||||
func PortRight(m *ice.Message, arg ...string) string {
|
||||
current, begin, end := kit.Select("20000", mdb.Config(m, CURRENT)), kit.Select("20000", mdb.Config(m, BEGIN)), kit.Select("30000", mdb.Config(m, END))
|
||||
return _port_right(m, kit.Int(kit.Select(kit.Select(begin, current), arg, 0)), kit.Int(kit.Select(begin, arg, 1)), kit.Int(kit.Select(end, arg, 2)))
|
||||
}
|
||||
func PortCmds(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SPACE, m.Option(SPACE), m.Option(ctx.INDEX), m.ActionKey())
|
||||
}
|
||||
|
@ -30,17 +30,16 @@ func (l Listener) Close() error {
|
||||
|
||||
func _server_listen(m *ice.Message, arg ...string) {
|
||||
l, e := net.Listen(TCP, m.Option(HOST)+nfs.DF+m.Option(PORT))
|
||||
if m.WarnNotValid(e) {
|
||||
return
|
||||
}
|
||||
l = &Listener{Listener: l, m: m, h: mdb.HashCreate(m, arg, kit.Dict(mdb.TARGET, l), STATUS, kit.Select(ERROR, OPEN, e == nil), ERROR, kit.Format(e)), s: &Stat{}}
|
||||
defer kit.If(e == nil, func() { l.Close() })
|
||||
switch cb := m.OptionCB("").(type) {
|
||||
case func(net.Listener):
|
||||
m.Assert(e)
|
||||
cb(l)
|
||||
case func(net.Conn):
|
||||
m.Assert(e)
|
||||
for {
|
||||
if c, e := l.Accept(); !m.WarnNotValid(e) {
|
||||
if c, e := l.Accept(); !m.Warn(e) {
|
||||
cb(c)
|
||||
} else {
|
||||
break
|
||||
@ -52,13 +51,10 @@ func _server_listen(m *ice.Message, arg ...string) {
|
||||
}
|
||||
|
||||
const (
|
||||
PROTOCOL = "protocol"
|
||||
HOSTPORT = "hostport"
|
||||
HOSTNAME = "hostname"
|
||||
NODENAME = "nodename"
|
||||
NODETYPE = "nodetype"
|
||||
BANDWIDTH = "bandwidth"
|
||||
ADDRESS = "address"
|
||||
PROTOCOL = "protocol"
|
||||
HOSTPORT = "hostport"
|
||||
HOSTNAME = "hostname"
|
||||
NODENAME = "nodename"
|
||||
)
|
||||
const (
|
||||
PROTO = "proto"
|
||||
@ -71,13 +67,12 @@ const (
|
||||
)
|
||||
const (
|
||||
LISTEN = "listen"
|
||||
UNIX = "unix"
|
||||
)
|
||||
const SERVER = "server"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SERVER: {Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
SERVER: {Name: "server hash auto prunes", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
LISTEN: {Name: "listen type name port=9030 host=", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case UDP4:
|
||||
|
@ -9,6 +9,6 @@ const TCP = "tcp"
|
||||
|
||||
var Index = &ice.Context{Name: TCP, Help: "通信模块"}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, WIFI, HOST, PORT, CLIENT, SERVER) }
|
||||
func init() { ice.Index.Register(Index, nil, HOST, PORT, CLIENT, SERVER) }
|
||||
|
||||
func Prefix(arg ...ice.Any) string { return kit.Keys(TCP, kit.Keys(arg...)) }
|
||||
|
@ -1,47 +0,0 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
SSID = "ssid"
|
||||
)
|
||||
const WIFI = "wifi"
|
||||
|
||||
func init() {
|
||||
const (
|
||||
NETWORKSETUP = "networksetup"
|
||||
CONNECT = "connect"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
WIFI: {Help: "无线", Icon: "AirPort Utility.png", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case SSID:
|
||||
kit.For(kit.Slice(kit.SplitLine(m.System(NETWORKSETUP, "-listpreferredwirelessnetworks", "en0").Result()), 1), func(name string) {
|
||||
m.Push(arg[0], strings.TrimSpace(name))
|
||||
})
|
||||
}
|
||||
}},
|
||||
CONNECT: {Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.ToastProcess()
|
||||
msg := mdb.HashSelect(m.Spawn(), m.Option(SSID, strings.TrimSpace(m.Option(SSID))))
|
||||
if res := m.System(NETWORKSETUP, "-setairportnetwork", "en0", kit.Select(m.Option(SSID), msg.Append(SSID)), msg.Append(aaa.PASSWORD)); res.Result() != "" {
|
||||
m.Echo(res.Result()).ToastFailure(res.Result())
|
||||
} else {
|
||||
m.ProcessHold()
|
||||
}
|
||||
}},
|
||||
}, mdb.ExportHashAction(mdb.SHORT, SSID, mdb.FIELD, "time,ssid,password")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...).PushAction(CONNECT, mdb.REMOVE); len(arg) > 0 {
|
||||
m.EchoQRCode(kit.Format("WIFI:T:WPA;S:%s;P:%s;H:false;;", m.Append(SSID), m.Append(aaa.PASSWORD)))
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const ADMIN = "admin"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ADMIN: {Name: "admin index list", Help: "后台", Role: aaa.VOID, Actions: ice.MergeActions(ice.Actions{
|
||||
DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { DreamProcessIframe(m, arg...) }},
|
||||
}, DreamTablesAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(ice.MSG_SOURCE) != "" {
|
||||
RenderMain(m)
|
||||
} else {
|
||||
kit.If(len(arg) == 0, func() { arg = append(arg, SPACE, DOMAIN) })
|
||||
m.Cmd(SPIDE, mdb.CREATE, HostPort(m, tcp.LOCALHOST, kit.GetValid(
|
||||
func() string { return m.Cmdx(nfs.CAT, ice.VAR_LOG_ICE_PORT) },
|
||||
func() string { return m.Cmdx(nfs.CAT, kit.Path(os.Args[0], "../", ice.VAR_LOG_ICE_PORT)) },
|
||||
func() string { return m.Cmdx(nfs.CAT, kit.Path(os.Args[0], "../../", ice.VAR_LOG_ICE_PORT)) },
|
||||
func() string { return tcp.PORT_9020 },
|
||||
)), ice.OPS)
|
||||
args := []string{}
|
||||
for i := range arg {
|
||||
if arg[i] == "--" {
|
||||
arg, args = arg[:i], arg[i+1:]
|
||||
break
|
||||
}
|
||||
}
|
||||
kit.If(os.Getenv(cli.CTX_OPS), func(p string) { m.Optionv(SPIDE_HEADER, html.XHost, p) })
|
||||
m.Cmdy(SPIDE, ice.OPS, SPIDE_RAW, http.MethodPost, C(arg...), cli.PWD, kit.Path(""), args)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
func AdminCmd(m *ice.Message, cmd string, arg ...ice.Any) *ice.Message {
|
||||
if ice.Info.NodeType == WORKER {
|
||||
return m.Cmd(append([]ice.Any{SPACE, ice.OPS, cmd}, arg...)...)
|
||||
} else {
|
||||
return m.Cmd(append([]ice.Any{cmd}, arg...)...)
|
||||
}
|
||||
}
|
||||
func OpsCmd(m *ice.Message, cmd string, arg ...ice.Any) *ice.Message {
|
||||
if ice.Info.NodeType == WORKER {
|
||||
return m.Cmd(append([]ice.Any{SPACE, ice.OPS, cmd}, arg...)...)
|
||||
} else {
|
||||
return m.Cmd(append([]ice.Any{cmd}, arg...)...)
|
||||
}
|
||||
}
|
||||
func DevCmd(m *ice.Message, cmd string, arg ...ice.Any) *ice.Message {
|
||||
if ice.Info.NodeType == WORKER {
|
||||
return m.Cmd(append([]ice.Any{SPACE, ice.OPS, SPACE, ice.DEV, cmd}, arg...)...)
|
||||
} else {
|
||||
return m.Cmd(append([]ice.Any{SPACE, ice.DEV, cmd}, arg...)...)
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { aaa.White(m, "basic") }},
|
||||
"/basic/check": {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(m.R.Header, func(key string, value []string) { m.Debug("what %v %v", key, value) })
|
||||
if BasicSess(m); m.Option(ice.MSG_USERNAME) == "" {
|
||||
BasicCheck(m, "请输入账号密码")
|
||||
}
|
||||
}},
|
||||
"/basic/login": {Hand: func(m *ice.Message, arg ...string) { RenderMain(m) }},
|
||||
"/basic/auths": {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.R.URL.Query().Get(ice.MSG_SESSID), func(p string) { RenderCookie(m, m.Option(ice.MSG_SESSID, p)) })
|
||||
RenderRedirect(m, kit.Select(nfs.PS, m.R.URL.Query().Get("redirect_uri")))
|
||||
}},
|
||||
})
|
||||
}
|
||||
func BasicSess(m *ice.Message) {
|
||||
m.Options(ice.MSG_USERWEB, _serve_domain(m))
|
||||
m.Options(ice.MSG_SESSID, kit.Select(m.Option(ice.MSG_SESSID), m.Option(CookieName(m.Option(ice.MSG_USERWEB)))))
|
||||
aaa.SessCheck(m, m.Option(ice.MSG_SESSID))
|
||||
}
|
||||
func BasicCheck(m *ice.Message, realm string, check ...func(*ice.Message) bool) bool {
|
||||
switch ls := kit.Split(m.R.Header.Get(html.Authorization)); kit.Select("", ls, 0) {
|
||||
case html.Basic:
|
||||
if buf, err := base64.StdEncoding.DecodeString(kit.Select("", ls, 1)); !m.WarnNotValid(err) {
|
||||
if ls := strings.SplitN(string(buf), ":", 2); !m.WarnNotValid(len(ls) < 2 || ls[1] == "", html.Basic) {
|
||||
if msg := m.Cmd(TOKEN, ls[1]); !m.WarnNotValid(msg.Time() > msg.Append(mdb.TIME)) {
|
||||
if len(check) == 0 || check[0](msg) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m.W.Header().Add("WWW-Authenticate", kit.Format(`Basic realm="%s"`, realm))
|
||||
m.RenderStatusUnauthorized()
|
||||
return false
|
||||
}
|
@ -2,11 +2,10 @@ package web
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -16,31 +15,20 @@ import (
|
||||
)
|
||||
|
||||
func _broad_send(m *ice.Message, to_host, to_port string, host, port string, arg ...string) {
|
||||
m.Cmd(tcp.CLIENT, tcp.DIAL, mdb.TYPE, tcp.UDP4, tcp.HOST, to_host, tcp.PORT, kit.Select(tcp.PORT_9020, to_port), func(s *net.UDPConn) {
|
||||
m.Cmd(tcp.CLIENT, tcp.DIAL, mdb.TYPE, tcp.UDP4, tcp.HOST, to_host, tcp.PORT, kit.Select("9020", to_port), func(s *net.UDPConn) {
|
||||
msg := m.Spawn(kit.Dict(tcp.HOST, host, tcp.PORT, port, arg))
|
||||
msg.Logs(tcp.SEND, BROAD, msg.FormatsMeta(nil), nfs.TO, tcp.HostPort(to_host, to_port)).FormatsMeta(s)
|
||||
})
|
||||
}
|
||||
func _broad_serve(m *ice.Message) {
|
||||
if m.Cmd(tcp.HOST).Length() == 0 {
|
||||
return
|
||||
}
|
||||
m.GoSleep300ms(func() {
|
||||
m.Cmd(tcp.HOST, func(value ice.Maps) {
|
||||
_broad_send(m, "", "", value[aaa.IP], m.Option(tcp.PORT), kit.Simple(gdb.EVENT, tcp.LISTEN, mdb.NAME, ice.Info.NodeName, mdb.TYPE, ice.Info.NodeType, mdb.TIME, m.Time(), cli.SimpleMake())...)
|
||||
})
|
||||
m.GoSleep("10ms", tcp.HOST, func(value ice.Maps) {
|
||||
_broad_send(m, "", "", value[aaa.IP], m.Option(tcp.PORT), gdb.EVENT, tcp.LISTEN, mdb.NAME, ice.Info.NodeName, mdb.TYPE, ice.Info.NodeType)
|
||||
})
|
||||
m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, tcp.UDP4, mdb.NAME, logs.FileLine(1), m.OptionSimple(tcp.HOST, tcp.PORT), func(from *net.UDPAddr, buf []byte) {
|
||||
if m.WarnNotValid(len(buf) > 1024, "broad recv buf size too large") {
|
||||
return
|
||||
}
|
||||
msg := m.Spawn(buf).Logs(tcp.RECV, BROAD, string(buf), nfs.FROM, from)
|
||||
if strings.HasPrefix(msg.Option(tcp.HOST), "169.254") {
|
||||
return
|
||||
}
|
||||
if m.Cmd(BROAD, mdb.CREATE, msg.OptionSimple(kit.Simple(msg.Optionv(ice.MSG_OPTION))...)); msg.Option(gdb.EVENT) == tcp.LISTEN {
|
||||
m.Cmds(BROAD, func(value ice.Maps) {
|
||||
_broad_send(m, msg.Option(tcp.HOST), msg.Option(tcp.PORT), value[tcp.HOST], value[tcp.PORT], kit.Simple(value)...)
|
||||
if mdb.HashCreate(m, msg.OptionSimple(kit.Simple(msg.Optionv(ice.MSG_OPTION))...)); msg.Option(gdb.EVENT) == tcp.LISTEN {
|
||||
m.Cmds("", func(value ice.Maps) {
|
||||
_broad_send(m, msg.Option(tcp.HOST), msg.Option(tcp.PORT), value[tcp.HOST], value[tcp.PORT], mdb.TYPE, value[mdb.TYPE], mdb.NAME, value[mdb.NAME])
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -50,40 +38,28 @@ const BROAD = "broad"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
BROAD: {Help: "广播台", Icon: "Podcasts.png", Actions: ice.MergeActions(ice.Actions{
|
||||
SERVE_START: {Hand: func(m *ice.Message, arg ...string) { gdb.Go(m, _broad_serve) }},
|
||||
BROAD: {Name: "broad hash auto", Help: "广播", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) {
|
||||
if mdb.IsSearchForEach(m, arg, nil) {
|
||||
host, domain := m.Cmdv(tcp.HOST, aaa.IP), UserWeb(m).Hostname()
|
||||
m.Cmds("", func(value ice.Maps) {
|
||||
switch kit.If(value[tcp.HOST] == host, func() { value[tcp.HOST] = domain }); value[mdb.TYPE] {
|
||||
case "sshd":
|
||||
m.PushSearch(mdb.NAME, Script(m, "ssh -p %s %s@%s", value[tcp.PORT], m.Option(ice.MSG_USERNAME), value[tcp.HOST]), mdb.TEXT, HostPort(m, value[tcp.HOST], value[tcp.PORT]), value)
|
||||
m.PushSearch(mdb.NAME, Script(m, "ssh -p %s %s@%s", value[tcp.PORT], m.Option(ice.MSG_USERNAME), value[tcp.HOST]), mdb.TEXT, Domain(value[tcp.HOST], value[tcp.PORT]), value)
|
||||
default:
|
||||
m.PushSearch(mdb.TEXT, HostPort(m, value[tcp.HOST], value[tcp.PORT]), value)
|
||||
m.PushSearch(mdb.TEXT, Domain(value[tcp.HOST], value[tcp.PORT]), value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}},
|
||||
SERVE: {Name: "serve port=9020 host", Hand: func(m *ice.Message, arg ...string) { gdb.Go(m, _broad_serve) }},
|
||||
ADMIN: {Hand: func(m *ice.Message, arg ...string) { broadOpen(m) }},
|
||||
DREAM: {Hand: func(m *ice.Message, arg ...string) { broadOpen(m) }},
|
||||
VIMER: {Hand: func(m *ice.Message, arg ...string) { broadOpen(m) }},
|
||||
SPIDE: {Name: "spide name type=repos", Icon: "bi bi-house-add", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPIDE, mdb.CREATE, HostPort(m, m.Option(tcp.HOST), m.Option(tcp.PORT)), m.Option(mdb.NAME))
|
||||
SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
|
||||
gdb.Go(m, _broad_serve)
|
||||
}},
|
||||
SERVE: {Name: "serve port=9020 host", Hand: func(m *ice.Message, arg ...string) { gdb.Go(m, _broad_serve) }},
|
||||
OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.ProcessOpen(HostPort(m, m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
||||
ctx.ProcessOpen(m, Domain(m.Option(tcp.HOST), m.Option(tcp.PORT)))
|
||||
}},
|
||||
tcp.SEND: {Hand: func(m *ice.Message, arg ...string) { _broad_send(m, "", "", "", "", arg...) }},
|
||||
}, gdb.EventsAction(SERVE_START), mdb.HashAction(mdb.SHORT, "host,port",
|
||||
mdb.FIELD, "time,hash,type,name,host,port,module,version,commitTime,compileTime,bootTime,kernel,arch",
|
||||
mdb.ACTION, "admin,dream,vimer,spide,open", mdb.SORT, "type,name,host,port"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...)
|
||||
m.StatusTimeCount("nodename", ice.Info.NodeName)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, "host,port", mdb.FIELD, "time,hash,type,name,host,port", mdb.ACTION, OPEN), mdb.ClearOnExitHashAction())},
|
||||
})
|
||||
}
|
||||
func broadOpen(m *ice.Message) {
|
||||
m.ProcessOpen(HostPort(m, m.Option(mdb.NAME), m.Option(tcp.PORT)) + C(m.ActionKey()))
|
||||
}
|
||||
|
@ -8,18 +8,17 @@ import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/miss"
|
||||
)
|
||||
|
||||
func _cache_name(m *ice.Message, h string) string { return path.Join(ice.VAR_FILE, h[:2], h) }
|
||||
func _cache_mime(m *ice.Message, mime, name string) string {
|
||||
if mime == html.ApplicationOctet {
|
||||
if mime == ApplicationOctet {
|
||||
if kit.ExtIsImage(name) {
|
||||
mime = IMAGE + nfs.PS + kit.Ext(name)
|
||||
} else if kit.ExtIsVideo(name) {
|
||||
@ -31,10 +30,10 @@ func _cache_mime(m *ice.Message, mime, name string) string {
|
||||
return mime
|
||||
}
|
||||
func _cache_save(m *ice.Message, mime, name, text string, arg ...string) {
|
||||
if m.WarnNotValid(name == "", mdb.NAME) {
|
||||
if m.Warn(name == "", ice.ErrNotValid, mdb.NAME) {
|
||||
return
|
||||
} else if len(text) > 512 {
|
||||
p := m.Cmdx(nfs.SAVE, _cache_name(m, kit.Hashs(text)), kit.Dict(nfs.CONTENT, text))
|
||||
p := m.Cmdx(nfs.SAVE, _cache_name(m, kit.Hashs(text)), text)
|
||||
text, arg = p, kit.Simple(p, len(text))
|
||||
}
|
||||
file, size := kit.Select("", arg, 0), kit.Int(kit.Select(kit.Format(len(text)), arg, 1))
|
||||
@ -58,22 +57,21 @@ func _cache_catch(m *ice.Message, path string) (file string, size string) {
|
||||
return "", "0"
|
||||
}
|
||||
func _cache_upload(m *ice.Message, r *http.Request) (mime, name, file, size string) {
|
||||
if b, h, e := r.FormFile(UPLOAD); !m.WarnNotValid(e, UPLOAD) {
|
||||
if b, h, e := r.FormFile(UPLOAD); !m.Warn(e, ice.ErrNotValid, UPLOAD) {
|
||||
defer b.Close()
|
||||
if f, p, e := miss.CreateFile(_cache_name(m, kit.Hashs(b))); !m.WarnNotValid(e, UPLOAD) {
|
||||
if f, p, e := miss.CreateFile(_cache_name(m, kit.Hashs(b))); !m.Warn(e, ice.ErrNotValid, UPLOAD) {
|
||||
defer f.Close()
|
||||
b.Seek(0, os.SEEK_SET)
|
||||
if n, e := io.Copy(f, b); !m.WarnNotValid(e, UPLOAD) {
|
||||
if n, e := io.Copy(f, b); !m.Warn(e, ice.ErrNotValid, UPLOAD) {
|
||||
m.Logs(nfs.SAVE, nfs.FILE, p, nfs.SIZE, kit.FmtSize(int64(n)))
|
||||
return h.Header.Get(html.ContentType), h.Filename, p, kit.Format(n)
|
||||
return h.Header.Get(ContentType), h.Filename, p, kit.Format(n)
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", "", "", "0"
|
||||
}
|
||||
func _cache_download(m *ice.Message, r *http.Response, file string, cb ice.Any) string {
|
||||
m.Option(ice.MSG_USERROLE, aaa.TECH)
|
||||
if f, p, e := miss.CreateFile(file); !m.WarnNotValid(e, DOWNLOAD) {
|
||||
if f, p, e := miss.CreateFile(file); !m.Warn(e, ice.ErrNotValid, DOWNLOAD) {
|
||||
defer func() {
|
||||
if s, e := os.Stat(file); e == nil && s.Size() == 0 {
|
||||
nfs.Remove(m, file)
|
||||
@ -81,12 +79,12 @@ func _cache_download(m *ice.Message, r *http.Response, file string, cb ice.Any)
|
||||
}()
|
||||
defer f.Close()
|
||||
last, base := 0, 10
|
||||
nfs.CopyStream(m, f, r.Body, base*ice.MOD_BUFS, kit.Int(kit.Select("100", r.Header.Get(html.ContentLength))), func(count, total, value int) {
|
||||
nfs.CopyStream(m, f, r.Body, base*ice.MOD_BUFS, kit.Int(kit.Select("100", r.Header.Get(ContentLength))), func(count, total, value int) {
|
||||
if value/base == last {
|
||||
return
|
||||
}
|
||||
last = value / base
|
||||
switch m.Logs(nfs.SAVE, nfs.FILE, p, mdb.COUNT, kit.FmtSize(int64(count)), mdb.TOTAL, kit.FmtSize(int64(total)), mdb.VALUE, value); cb := cb.(type) {
|
||||
switch m.Logs(nfs.SAVE, nfs.FILE, p, mdb.COUNT, count, mdb.TOTAL, total, mdb.VALUE, value); cb := cb.(type) {
|
||||
case func(int, int, int):
|
||||
kit.If(cb != nil, func() { cb(count, total, value) })
|
||||
case nil:
|
||||
@ -105,8 +103,6 @@ const (
|
||||
WRITE = "write"
|
||||
UPLOAD = "upload"
|
||||
DOWNLOAD = "download"
|
||||
PREVIEW = "preview"
|
||||
PAGES = "pages"
|
||||
|
||||
IMAGE = "image"
|
||||
VIDEO = "video"
|
||||
@ -115,97 +111,69 @@ const CACHE = "cache"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CACHE: {Name: "cache hash auto upload", Help: "缓存池", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.RENDER_DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_share_link(m, kit.Select(arg[0], arg, 1), ice.POD, m.Option(ice.MSG_USERPOD), nfs.FILENAME, kit.Select("", arg[0], len(arg) > 1)))
|
||||
CACHE: {Name: "cache hash auto write catch upload download", Help: "缓存池", Actions: ice.MergeActions(ice.Actions{
|
||||
WATCH: {Name: "watch hash* path*", Help: "释放", Hand: func(m *ice.Message, arg ...string) {
|
||||
_cache_watch(m, m.Option(mdb.HASH), m.Option(nfs.PATH))
|
||||
}},
|
||||
WRITE: {Name: "write type name* text*", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
WRITE: {Name: "write type name* text*", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
_cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), m.Option(mdb.TEXT))
|
||||
}},
|
||||
CATCH: {Name: "catch path* type", Help: "导入", Hand: func(m *ice.Message, arg ...string) {
|
||||
CATCH: {Name: "catch path* type", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
file, size := _cache_catch(m, m.Option(nfs.PATH))
|
||||
_cache_save(m, m.Option(mdb.TYPE), m.Option(nfs.PATH), "", file, size)
|
||||
}},
|
||||
WATCH: {Name: "watch hash* path*", Help: "导出", Hand: func(m *ice.Message, arg ...string) {
|
||||
_cache_watch(m, m.Option(mdb.HASH), m.Option(nfs.PATH))
|
||||
}},
|
||||
UPLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mime, name, file, size := _cache_upload(m, m.R)
|
||||
_cache_save(m, mime, name, "", file, size)
|
||||
}},
|
||||
DOWNLOAD: {Name: "download type name*", Hand: func(m *ice.Message, arg ...string) {
|
||||
if res, ok := m.Optionv(RESPONSE).(*http.Response); !m.WarnNotValid(!ok, RESPONSE) {
|
||||
nfs.Temp(m, func(p string) {
|
||||
file, size := _cache_catch(m, _cache_download(m, res, p, m.OptionCB("")))
|
||||
_cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), "", file, size)
|
||||
})
|
||||
if res, ok := m.Optionv(RESPONSE).(*http.Response); !m.Warn(!ok, ice.ErrNotValid, RESPONSE) {
|
||||
file, size := _cache_catch(m, _cache_download(m, res, path.Join(ice.VAR_TMP, kit.Hashs(mdb.UNIQ)), m.OptionCB("")))
|
||||
_cache_save(m, m.Option(mdb.TYPE), m.Option(mdb.NAME), "", file, size)
|
||||
}
|
||||
}},
|
||||
ice.RENDER_DOWNLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_share_link(m, kit.Select(arg[0], arg, 1), ice.POD, m.Option(ice.MSG_USERPOD), "filename", kit.Select("", arg[0], len(arg) > 1)))
|
||||
}},
|
||||
nfs.PS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelectDetail(m, arg[0], func(value ice.Map) {
|
||||
mdb.HashSelectDetail(m, arg[0], func(value ice.Map) {
|
||||
kit.If(kit.Format(value[nfs.FILE]), func() { m.RenderDownload(value[nfs.FILE]) }, func() { m.RenderResult(value[mdb.TEXT]) })
|
||||
}) {
|
||||
return
|
||||
}
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
msg := m.Options(ice.POD, "").Cmd(SPACE, pod, CACHE, arg[0])
|
||||
kit.If(kit.Format(msg.Append(nfs.FILE)), func() {
|
||||
m.RenderDownload(path.Join(ice.USR_LOCAL_WORK, pod, msg.Append(nfs.FILE)))
|
||||
}, func() { m.RenderResult(msg.Append(mdb.TEXT)) })
|
||||
}
|
||||
})
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,size,type,name,text,file"), ice.RenderAction(ice.RENDER_DOWNLOAD)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 {
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.TEXT, mdb.FIELD, "time,hash,size,type,name,text,file", ctx.ACTION, WATCH), ice.RenderAction(ice.RENDER_DOWNLOAD)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 || m.R != nil && m.R.Method == http.MethodGet {
|
||||
return
|
||||
}
|
||||
if m.Length() == 0 {
|
||||
return
|
||||
} else if m.Append(nfs.FILE) == "" {
|
||||
if m.Append(nfs.FILE) == "" {
|
||||
m.PushScript(mdb.TEXT, m.Append(mdb.TEXT))
|
||||
} else {
|
||||
PushDisplay(m, m.Append(mdb.TYPE), m.Append(mdb.NAME), m.MergeLink(P(SHARE, CACHE, arg[0])))
|
||||
PushDisplay(m, m.Append(mdb.TYPE), m.Append(mdb.NAME), MergeURL2(m, P(SHARE, CACHE, arg[0])))
|
||||
}
|
||||
}},
|
||||
})
|
||||
ice.AddMergeAction(func(c *ice.Context, key string, cmd *ice.Command, sub string, action *ice.Action) {
|
||||
switch sub {
|
||||
case UPLOAD:
|
||||
if kit.FileLines(action.Hand) == kit.FileLines(1) {
|
||||
if c.Name == WEB && key == CACHE {
|
||||
break
|
||||
}
|
||||
watch := action.Hand == nil
|
||||
action.Hand = ice.MergeHand(func(m *ice.Message, arg ...string) {
|
||||
up := Upload(m)
|
||||
m.Assert(len(up) > 1)
|
||||
msg := m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD))
|
||||
// if m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD)).Table(func(value ice.Maps) { m.Options(value) }).Length() == 0 {
|
||||
if msg.Length() == 0 {
|
||||
SpideCache(m.Spawn(), m.MergeLink(SHARE_CACHE+up[0]))
|
||||
}
|
||||
// if m.Options(mdb.HASH, up[0], mdb.NAME, up[1]); watch {
|
||||
if watch {
|
||||
m.Cmdy(CACHE, WATCH, up[0], path.Join(msg.Append(nfs.PATH), up[1]))
|
||||
m.Cmd(CACHE, m.Option(ice.MSG_UPLOAD)).Table(func(value ice.Maps) { m.Options(value) })
|
||||
if m.Options(mdb.HASH, up[0], mdb.NAME, up[1]); watch {
|
||||
m.Cmdy(CACHE, WATCH, m.Option(mdb.HASH), path.Join(m.Option(nfs.PATH), up[1]))
|
||||
}
|
||||
}, action.Hand)
|
||||
}
|
||||
})
|
||||
}
|
||||
func UploadSave(m *ice.Message, p string) string {
|
||||
up := kit.Simple(m.Optionv(ice.MSG_UPLOAD))
|
||||
kit.If(strings.HasSuffix(p, nfs.PS), func() { p = path.Join(p, up[1]) })
|
||||
m.Cmd(CACHE, WATCH, up[0], p)
|
||||
return p
|
||||
ctx.Upload = Upload
|
||||
}
|
||||
func Upload(m *ice.Message) []string {
|
||||
if up := kit.Simple(m.Optionv(ice.MSG_UPLOAD)); len(up) == 1 {
|
||||
msg := m.Cmd(CACHE, UPLOAD)
|
||||
if m.Optionv(ice.MSG_UPLOAD, kit.Simple(msg.Append(mdb.HASH), msg.Append(mdb.NAME), msg.Append(nfs.SIZE))); m.Option(ice.MSG_USERPOD) != "" {
|
||||
if nfs.Exists(m, nfs.USR_LOCAL_WORK+m.Option(ice.MSG_USERPOD)) {
|
||||
m.Cmd(nfs.LINK, path.Join(nfs.USR_LOCAL_WORK+m.Option(ice.MSG_USERPOD), msg.Append(nfs.FILE)), msg.Append(nfs.FILE))
|
||||
m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), CACHE, mdb.CREATE, msg.AppendSimple(mdb.NAME, mdb.TEXT, nfs.FILE, nfs.SIZE))
|
||||
} else {
|
||||
m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), SPIDE, ice.DEV, SPIDE_CACHE, http.MethodGet, tcp.PublishLocalhost(m, m.MergeLink(PP(SHARE, CACHE, msg.Append(mdb.HASH)))))
|
||||
}
|
||||
if m.Cmdy(CACHE, UPLOAD).Optionv(ice.MSG_UPLOAD, kit.Simple(m.Append(mdb.HASH), m.Append(mdb.NAME), m.Append(nfs.SIZE))); m.Option(ice.MSG_USERPOD) != "" {
|
||||
m.Cmd(SPACE, m.Option(ice.MSG_USERPOD), SPIDE, ice.DEV, SPIDE_CACHE, http.MethodGet, tcp.PublishLocalhost(m, MergeURL2(m, PP(SHARE, CACHE, m.Append(mdb.HASH)))))
|
||||
}
|
||||
return kit.Simple(m.Optionv(ice.MSG_UPLOAD))
|
||||
} else {
|
||||
@ -216,12 +184,10 @@ func Download(m *ice.Message, link string, cb func(count, total, value int)) *ic
|
||||
return m.Cmdy(Prefix(SPIDE), ice.DEV, SPIDE_CACHE, http.MethodGet, link, cb)
|
||||
}
|
||||
func PushDisplay(m *ice.Message, mime, name, link string) {
|
||||
if html.IsImage(name, mime) {
|
||||
if strings.HasPrefix(mime, IMAGE+nfs.PS) || kit.ExtIsImage(name) {
|
||||
m.PushImages(nfs.FILE, link)
|
||||
} else if html.IsVideo(name, mime) {
|
||||
} else if strings.HasPrefix(mime, VIDEO+nfs.PS) || kit.ExtIsImage(name) {
|
||||
m.PushVideos(nfs.FILE, link)
|
||||
} else if html.IsAudio(name, mime) {
|
||||
m.PushAudios(nfs.FILE, link)
|
||||
} else {
|
||||
m.PushDownload(nfs.FILE, name, link)
|
||||
}
|
||||
@ -233,32 +199,3 @@ func RenderCache(m *ice.Message, h string) {
|
||||
m.RenderDownload(msg.Append(mdb.FILE), msg.Append(mdb.TYPE), msg.Append(mdb.NAME))
|
||||
}
|
||||
}
|
||||
func ExportCacheAction(field string) ice.Actions {
|
||||
return ice.Actions{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m.Spawn(kit.Dict(ice.MSG_FIELDS, field))).Table(func(value ice.Maps) {
|
||||
kit.For(kit.Split(value[field]), func(h string) {
|
||||
msg := m.Cmd(CACHE, h)
|
||||
m.Cmd(nfs.LINK, kit.Keys(path.Join(ice.USR_LOCAL_EXPORT, m.PrefixKey(), field, h), kit.Select("", kit.Split(msg.Append(mdb.TYPE), nfs.PS), -1)), msg.Append(nfs.FILE))
|
||||
})
|
||||
})
|
||||
}},
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list := map[string]string{}
|
||||
m.Cmd(nfs.DIR, path.Join(ice.USR_LOCAL_EXPORT, m.PrefixKey(), field), func(value ice.Maps) {
|
||||
list[kit.TrimExt(value[nfs.PATH])] = m.Cmd(CACHE, CATCH, value[nfs.PATH]).Append(mdb.HASH)
|
||||
})
|
||||
mdb.HashSelectUpdate(m, "", func(value ice.Map) {
|
||||
value[field] = kit.Join(kit.Simple(kit.For(kit.Split(kit.Format(value[field])), func(p string) string { return kit.Select(p, list[p]) })))
|
||||
})
|
||||
}},
|
||||
UPLOAD: {Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.Temp(m, func(p string) {
|
||||
msg := m.Cmd(CACHE, Upload(m)[0])
|
||||
if os.Link(msg.Append(nfs.FILE), p); nfs.ImageResize(m, p, 390, 390) {
|
||||
m.Echo(m.Cmd(CACHE, CATCH, p, msg.Append(mdb.TYPE)).Append(mdb.HASH))
|
||||
}
|
||||
})
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
@ -1,114 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _count_stat(m *ice.Message, arg ...string) map[string]int {
|
||||
stat := map[string]int{}
|
||||
m.Table(func(value ice.Maps) {
|
||||
count := kit.Int(value[mdb.COUNT])
|
||||
stat[mdb.TOTAL] += count
|
||||
for _, agent := range []string{"美国", "电信", "联通", "移动", "阿里云", "腾讯云"} {
|
||||
if strings.Contains(value[aaa.LOCATION], agent) {
|
||||
stat[agent] += count
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, agent := range []string{"GoModuleMirror", "Go-http-client", "git", "compatible"} {
|
||||
if strings.Contains(value[mdb.TEXT], agent) {
|
||||
stat[agent] += count
|
||||
return
|
||||
}
|
||||
}
|
||||
for _, agent := range html.AgentList {
|
||||
if strings.Contains(value[mdb.TEXT], agent) {
|
||||
stat[agent] += count
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, agent := range html.SystemList {
|
||||
if strings.Contains(value[mdb.TEXT], agent) {
|
||||
stat[agent] += count
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
return stat
|
||||
}
|
||||
|
||||
const COUNT = "count"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
COUNT: &ice.Command{Name: "count hash auto group valid location", Help: "计数器", Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(aaa.LOCATION, "地理位置")),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelectUpdate(m, mdb.HashCreate(m), func(value ice.Map) { value[mdb.COUNT] = kit.Int(value[mdb.COUNT]) + 1 })
|
||||
// m.Cmd("count", mdb.CREATE, OFFER, m.Option(FROM), kit.Dict(ice.LOG_DISABLE, ice.TRUE))
|
||||
}},
|
||||
mdb.VALID: {Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m.Spawn(), arg...).Table(func(value ice.Maps) {
|
||||
if !strings.HasPrefix(value[mdb.TEXT], html.Mozilla) {
|
||||
return
|
||||
} else if count := kit.Int(value[mdb.COUNT]); count < 1 {
|
||||
return
|
||||
} else {
|
||||
m.Push("", value, kit.Split(mdb.Config(m, mdb.FIELD)))
|
||||
}
|
||||
})
|
||||
m.StatusTimeCount(_count_stat(m))
|
||||
}},
|
||||
mdb.GROUP: {Hand: func(m *ice.Message, arg ...string) {
|
||||
count := map[string]int{}
|
||||
list := map[string]map[string]string{}
|
||||
m.Cmd("", mdb.VALID).Table(func(value ice.Maps) {
|
||||
count[value[aaa.LOCATION]] += kit.Int(value[mdb.COUNT])
|
||||
list[value[aaa.LOCATION]] = value
|
||||
})
|
||||
stat := map[string]int{}
|
||||
for _, v := range list {
|
||||
func() {
|
||||
for _, agent := range []string{"美国", "电信", "联通", "移动", "阿里云", "腾讯云", "北京市", "香港"} {
|
||||
if strings.Contains(v[aaa.LOCATION], agent) {
|
||||
stat[agent] += kit.Int(v[mdb.COUNT])
|
||||
return
|
||||
}
|
||||
}
|
||||
m.Push("", v, kit.Split(mdb.Config(m, mdb.FIELD)))
|
||||
}()
|
||||
}
|
||||
m.StatusTimeCount(stat)
|
||||
}},
|
||||
aaa.LOCATION: {Hand: func(m *ice.Message, arg ...string) {
|
||||
GoToast(mdb.HashSelects(m).Sort(mdb.COUNT, ice.INT_R), func(toast func(string, int, int)) []string {
|
||||
m.Table(func(value ice.Maps, index, total int) {
|
||||
if value[aaa.LOCATION] == "" {
|
||||
location := kit.Format(kit.Value(SpideGet(m, "http://opendata.baidu.com/api.php?co=&resource_id=6006&oe=utf8", "query", value[mdb.NAME]), "data.0.location"))
|
||||
mdb.HashModify(m, mdb.HASH, value[mdb.HASH], aaa.LOCATION, location)
|
||||
toast(kit.Select(value[mdb.NAME], location), index, total)
|
||||
m.Sleep300ms()
|
||||
}
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}},
|
||||
}, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, "type,name", mdb.FIELD, "time,hash,count,location,type,name,text")), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Sort(mdb.TIME, ice.STR_R).StatusTimeCount(_count_stat(m))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func Count(m *ice.Message, arg ...string) *ice.Message {
|
||||
kit.If(len(arg) > 0 && arg[0] == "", func() { arg[0] = m.ShortKey() })
|
||||
kit.If(len(arg) > 1 && arg[1] == "", func() { arg[1] = m.ActionKey() })
|
||||
m.Cmd(COUNT, mdb.CREATE, arg, kit.Dict(ice.LOG_DISABLE, ice.TRUE))
|
||||
return m
|
||||
}
|
@ -3,10 +3,8 @@ package web
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
@ -17,172 +15,75 @@ import (
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _dream_list(m *ice.Message) *ice.Message {
|
||||
list := m.CmdMap(SPACE, mdb.NAME)
|
||||
mdb.HashSelects(m.Spawn()).Table(func(value ice.Maps, index int, head []string) {
|
||||
if value[aaa.ACCESS] == aaa.PRIVATE && (m.Option(ice.FROM_SPACE) != "" || !aaa.IsTechOrRoot(m)) {
|
||||
return
|
||||
}
|
||||
stats := map[string]int{}
|
||||
mdb.HashSelect(m).Table(func(value ice.Maps) {
|
||||
if space, ok := list[value[mdb.NAME]]; ok {
|
||||
value[ice.MAIN] = space[ice.MAIN]
|
||||
value[mdb.ICONS] = space[mdb.ICONS]
|
||||
m.Push("", value, kit.Slice(head, 0, -1))
|
||||
m.Push(mdb.TYPE, space[mdb.TYPE]).Push(cli.STATUS, cli.START)
|
||||
m.Push(nfs.MODULE, space[nfs.MODULE]).Push(nfs.VERSION, space[nfs.VERSION])
|
||||
button := []ice.Any{PORTAL, DESKTOP, ADMIN, WORD}
|
||||
text := space[nfs.MODULE]
|
||||
kit.If(m.Option(ice.DREAM_SIMPLE) != ice.TRUE && aaa.IsTechOrRoot(m), func() {
|
||||
kit.If(m.IsDebug(), func() {
|
||||
button = append(button, VIMER, STATUS, COMPILE, cli.RUNTIME, XTERM)
|
||||
text += "\n" + DreamStat(m, value[mdb.NAME])
|
||||
})
|
||||
button = append(button, "settings", cli.STOP)
|
||||
})
|
||||
m.Push(mdb.TEXT, text)
|
||||
m.PushButton(append(button, OPEN)...)
|
||||
} else if aaa.IsTechOrRoot(m) {
|
||||
m.Push("", value, kit.Slice(head, 0, -1))
|
||||
m.Push(nfs.MODULE, "").Push(nfs.VERSION, "").Push(mdb.TEXT, "")
|
||||
if m.Push(mdb.TYPE, WORKER); nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, value[mdb.NAME])) {
|
||||
m.Push(cli.STATUS, cli.STOP).PushButton(cli.START, nfs.TRASH)
|
||||
} else {
|
||||
m.Push(cli.STATUS, cli.BEGIN).PushButton(cli.START, mdb.REMOVE)
|
||||
}
|
||||
msg := gdb.Event(m.Spawn(value, space), DREAM_TABLES).Copy(m.Spawn().PushButton(cli.STOP))
|
||||
m.Push(mdb.TYPE, space[mdb.TYPE])
|
||||
m.Push(cli.STATUS, cli.START)
|
||||
m.Push(mdb.TEXT, msg.Append(mdb.TEXT))
|
||||
m.PushButton(strings.Join(msg.Appendv(ctx.ACTION), ""))
|
||||
stats[cli.START]++
|
||||
} else if nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, value[mdb.NAME])) {
|
||||
m.Push(mdb.TYPE, WORKER)
|
||||
m.Push(cli.STATUS, cli.STOP)
|
||||
m.Push(mdb.TEXT, "")
|
||||
m.PushButton(cli.START, nfs.TRASH)
|
||||
stats[cli.STOP]++
|
||||
} else {
|
||||
m.Push(mdb.TYPE, WORKER)
|
||||
m.Push(cli.STATUS, cli.STOP)
|
||||
m.Push(mdb.TEXT, "")
|
||||
m.PushButton(cli.START, mdb.REMOVE)
|
||||
stats[ice.INIT]++
|
||||
}
|
||||
})
|
||||
m.RewriteAppend(func(value, key string, index int) string {
|
||||
if key == mdb.TIME {
|
||||
if space, ok := list[m.Appendv(mdb.NAME)[index]]; ok {
|
||||
return space[mdb.TIME]
|
||||
}
|
||||
} else if key == mdb.ICONS {
|
||||
if kit.HasPrefix(value, HTTP, nfs.PS) {
|
||||
return value
|
||||
} else if nfs.ExistsFile(m, path.Join(ice.USR_LOCAL_WORK, m.Appendv(mdb.NAME)[index], value)) {
|
||||
return m.Spawn(kit.Dict(ice.MSG_USERPOD, m.Appendv(mdb.NAME)[index])).FileURI(value)
|
||||
} else if nfs.ExistsFile(m, value) {
|
||||
return m.FileURI(value)
|
||||
}
|
||||
}
|
||||
return value
|
||||
})
|
||||
return m
|
||||
}
|
||||
func _dream_list_more(m *ice.Message) *ice.Message {
|
||||
field := kit.Split(mdb.Config(m, mdb.FIELD) + ",type,status,module,version,text")
|
||||
m.Cmds(SPACE).Table(func(value ice.Maps) {
|
||||
value[nfs.REPOS] = "https://" + value[nfs.MODULE]
|
||||
value[aaa.ACCESS] = kit.Select("", value[aaa.USERROLE], value[aaa.USERROLE] != aaa.VOID)
|
||||
value[mdb.STATUS] = cli.START
|
||||
button := []ice.Any{PORTAL, DESKTOP, ADMIN, WORD}
|
||||
kit.If(m.IsDebug(), func() { button = append(button, VIMER, STATUS, COMPILE, cli.RUNTIME, XTERM) })
|
||||
switch value[mdb.TYPE] {
|
||||
case ORIGIN:
|
||||
if m.IsCliUA() {
|
||||
return
|
||||
}
|
||||
value[mdb.TEXT] = kit.JoinLine(value[nfs.MODULE], value[mdb.TEXT])
|
||||
button = append(button, GETTOKEN, OPEN)
|
||||
kit.If(value[aaa.ACCESS] == "", func() { button = []ice.Any{PORTAL, OPEN} })
|
||||
case SERVER:
|
||||
if !m.IsCliUA() {
|
||||
value[mdb.TEXT] = kit.JoinLine(value[nfs.MODULE], value[mdb.TEXT])
|
||||
} else if !strings.HasPrefix(value[mdb.TEXT], ice.HTTP) {
|
||||
return
|
||||
}
|
||||
button = append(button, SETTOKEN, OPEN)
|
||||
case aaa.LOGIN:
|
||||
if m.IsCliUA() {
|
||||
return
|
||||
}
|
||||
value[mdb.TEXT] = kit.JoinWord(value[AGENT], value[cli.SYSTEM], value[aaa.IP], kit.Format(PublicIP(m, value[aaa.IP])))
|
||||
button = []ice.Any{GRANT}
|
||||
default:
|
||||
return
|
||||
}
|
||||
m.Push("", value, field)
|
||||
m.PushButton(button...)
|
||||
})
|
||||
return m
|
||||
return m.Sort("status,type,name", ice.STR, ice.STR, ice.STR_R).StatusTimeCount(stats)
|
||||
}
|
||||
func _dream_start(m *ice.Message, name string) {
|
||||
if m.WarnNotValid(name == "", mdb.NAME) {
|
||||
if m.Warn(name == "", ice.ErrNotValid, mdb.NAME) {
|
||||
return
|
||||
}
|
||||
if !m.IsCliUA() {
|
||||
defer m.ProcessRefresh()
|
||||
}
|
||||
defer mdb.Lock(m, m.PrefixKey(), cli.START, name)()
|
||||
p := _dream_check(m, name)
|
||||
if p == "" {
|
||||
defer m.ProcessOpen(m.MergePod(m.Option(mdb.NAME, name)))
|
||||
p := path.Join(ice.USR_LOCAL_WORK, name)
|
||||
if pid := m.Cmdx(nfs.CAT, path.Join(p, ice.Info.PidPath), kit.Dict(ice.MSG_USERROLE, aaa.TECH)); pid != "" && nfs.Exists(m, "/proc/"+pid) {
|
||||
m.Info("already exists %v", pid)
|
||||
return
|
||||
} else if m.Cmd(SPACE, name).Length() > 0 {
|
||||
m.Info("already exists %v", name)
|
||||
return
|
||||
}
|
||||
if !nfs.Exists(m, p) {
|
||||
gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME))
|
||||
}
|
||||
defer ToastProcess(m)()
|
||||
defer m.Sleep("1s")
|
||||
m.Options(cli.CMD_DIR, kit.Path(p), cli.CMD_ENV, kit.Simple(
|
||||
cli.CTX_OPS, Domain(tcp.LOCALHOST, m.Cmdv(SERVE, tcp.PORT)), cli.CTX_LOG, ice.VAR_LOG_BOOT_LOG, cli.CTX_PID, ice.VAR_LOG_ICE_PID,
|
||||
cli.PATH, cli.BinPath(p, ""), cli.USER, ice.Info.Username, kit.EnvSimple(cli.HOME, cli.TERM, cli.SHELL, "USERPROFILE"), mdb.Configv(m, cli.ENV),
|
||||
), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG), mdb.CACHE_CLEAR_ONEXIT, ice.TRUE)
|
||||
defer m.Options(cli.CMD_DIR, "", cli.CMD_ENV, "", cli.CMD_OUTPUT, "")
|
||||
m.Options(cli.CMD_DIR, kit.Path(p), cli.CMD_ENV, kit.EnvList(kit.Simple(m.OptionSimple(ice.TCP_DOMAIN),
|
||||
cli.CTX_OPS, HostPort(m, tcp.LOCALHOST, m.Cmdv(SERVE, tcp.PORT)), cli.CTX_LOG, ice.VAR_LOG_BOOT_LOG,
|
||||
cli.CTX_ROOT, kit.Path(""), cli.PATH, cli.BinPath(p, ""), cli.USER, ice.Info.Username,
|
||||
)...), cli.CMD_OUTPUT, path.Join(p, ice.VAR_LOG_BOOT_LOG), mdb.CACHE_CLEAR_ONEXIT, ice.TRUE)
|
||||
kit.If(m.Option(nfs.BINARY) == "" && !cli.SystemFindGo(m), func(p string) { m.Option(nfs.BINARY, S(name)) })
|
||||
gdb.Event(m, DREAM_CREATE, m.OptionSimple(mdb.NAME, mdb.TYPE))
|
||||
kit.If(m.Option(nfs.BINARY), func(p string) { _dream_binary(m, p) })
|
||||
kit.If(m.Option(nfs.TEMPLATE), func(p string) { _dream_template(m, p) })
|
||||
bin := kit.Select(kit.Path(os.Args[0]), cli.SystemFind(m, ice.ICE_BIN, nfs.PWD+path.Join(p, ice.BIN), nfs.PWD+ice.BIN))
|
||||
if cli.IsSuccess(m.Cmd(cli.DAEMON, bin, SPACE, tcp.DIAL, ice.DEV, ice.OPS, cli.DAEMON, ice.OPS)) {
|
||||
gdb.WaitEvent(m, DREAM_OPEN, func(m *ice.Message, arg ...string) bool { return m.Option(mdb.NAME) == name })
|
||||
m.Sleep300ms()
|
||||
}
|
||||
}
|
||||
func _dream_check(m *ice.Message, name string) string {
|
||||
p := path.Join(ice.USR_LOCAL_WORK, name)
|
||||
msg := m.Spawn(kit.Dict(ice.MSG_USERROLE, aaa.ROOT))
|
||||
if pp := path.Join(p, ice.VAR_LOG_ICE_PID); nfs.Exists(m, pp) {
|
||||
for i := 0; i < 5; i++ {
|
||||
pid := msg.Cmdx(nfs.CAT, pp)
|
||||
if pid == "" {
|
||||
return p
|
||||
}
|
||||
m.Sleep("1s")
|
||||
if m.Cmd(SPACE, name).Length() > 0 {
|
||||
m.Info("already exists %v", name)
|
||||
return ""
|
||||
}
|
||||
if runtime.GOOS == cli.LINUX && !nfs.Exists(m, "/proc/"+pid) {
|
||||
return p
|
||||
}
|
||||
if nfs.Exists(m, "/proc/"+pid) && runtime.GOOS == cli.LINUX {
|
||||
if !kit.HasPrefix(msg.Cmdx(nfs.CAT, "/proc/"+pid+"/cmdline"), kit.Path(ice.BIN_ICE_BIN), kit.Path(p, ice.BIN_ICE_BIN)) {
|
||||
return p
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
if gdb.SignalProcess(m, pid) {
|
||||
m.Info("already exists %v", pid)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
return p
|
||||
m.Cmd(cli.DAEMON, kit.Select(kit.Path(os.Args[0]), cli.SystemFind(m, ice.ICE_BIN, nfs.PWD+path.Join(p, ice.BIN), nfs.PWD+ice.BIN)),
|
||||
SPACE, tcp.DIAL, ice.DEV, ice.OPS, mdb.TYPE, WORKER, m.OptionSimple(mdb.NAME), cli.DAEMON, ice.OPS)
|
||||
}
|
||||
func _dream_binary(m *ice.Message, p string) {
|
||||
if bin := path.Join(m.Option(cli.CMD_DIR), ice.BIN_ICE_BIN); nfs.Exists(m, bin) {
|
||||
return
|
||||
} else if kit.IsUrl(p) || strings.HasPrefix(p, S()) {
|
||||
// m.Cmd(DREAM, DOWNLOAD, bin, kit.MergeURL2(p, kit.Format("/publish/ice.%s.%s", runtime.GOOS, runtime.GOARCH), ice.POD, m.Option(mdb.NAME)))
|
||||
m.Cmd(DREAM, DOWNLOAD, bin, kit.MergeURL(p, cli.GOOS, runtime.GOOS, cli.GOARCH, runtime.GOARCH))
|
||||
|
||||
} else if kit.IsUrl(p) {
|
||||
SpideSave(m, bin, kit.MergeURL(p, cli.GOOS, runtime.GOOS, cli.GOARCH, runtime.GOARCH), nil)
|
||||
os.Chmod(bin, ice.MOD_DIR)
|
||||
} else {
|
||||
m.Cmd(nfs.LINK, bin, kit.Path(p))
|
||||
}
|
||||
}
|
||||
func _dream_template(m *ice.Message, p string) {
|
||||
kit.For([]string{
|
||||
ice.LICENSE, ice.README_MD, ice.MAKEFILE, ice.GO_MOD, ice.GO_SUM,
|
||||
ice.LICENSE, ice.MAKEFILE, ice.README_MD, ice.GO_MOD, ice.GO_SUM,
|
||||
ice.SRC_MAIN_SH, ice.SRC_MAIN_SHY, ice.SRC_MAIN_GO, ice.SRC_MAIN_JS,
|
||||
ice.ETC_MISS_SH, ice.ETC_INIT_SHY, ice.ETC_EXIT_SHY,
|
||||
}, func(file string) {
|
||||
@ -199,403 +100,86 @@ func _dream_template(m *ice.Message, p string) {
|
||||
}
|
||||
|
||||
const (
|
||||
ALWAYS = "always"
|
||||
STARTALL = "startall"
|
||||
STOPALL = "stopall"
|
||||
FOR_EACH = "forEach"
|
||||
FOR_FLOW = "forFlow"
|
||||
GETTOKEN = "gettoken"
|
||||
SETTOKEN = "settoken"
|
||||
|
||||
DREAM_INPUTS = "dream.inputs"
|
||||
DREAM_CREATE = "dream.create"
|
||||
DREAM_REMOVE = "dream.remove"
|
||||
DREAM_TRASH = "dream.trash"
|
||||
DREAM_START = "dream.start"
|
||||
DREAM_STOP = "dream.stop"
|
||||
DREAM_OPEN = "dream.open"
|
||||
DREAM_CLOSE = "dream.close"
|
||||
|
||||
DREAM_INPUTS = "dream.inputs"
|
||||
DREAM_TABLES = "dream.tables"
|
||||
DREAM_ACTION = "dream.action"
|
||||
|
||||
OPS_DREAM_CREATE = "ops.dream.create"
|
||||
OPS_DREAM_REMOVE = "ops.dream.remove"
|
||||
)
|
||||
const DREAM = "dream"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
DREAM: {Name: "dream refresh", Help: "梦想家", Icon: "Launchpad.png", Role: aaa.VOID, Meta: kit.Dict(
|
||||
ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(WORKER, "空间", SERVER, "门户", ORIGIN, "主机")),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
ice.AFTER_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
AddPortalProduct(m, "云空间", `
|
||||
比虚拟机和容器,更加轻量,每个空间都是一个完整的系统,拥有各种软件与独立的环境。
|
||||
空间内所有的软件、配置、数据以源码库形式保存,每个空间都可以随时启动、停止、上传、下载、分享。
|
||||
每个空间都自带软件开发工具,也可以随时编程添加新的功能。
|
||||
`, 200.0)
|
||||
}},
|
||||
DREAM: {Name: "dream name auto create", Help: "梦想家", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) {
|
||||
mdb.HashSelects(m.Spawn()).Table(func(value ice.Maps) { m.PushSearch(mdb.TYPE, WORKER, mdb.TEXT, m.MergePod(value[mdb.NAME]), value) })
|
||||
if mdb.IsSearchForEach(m, arg, nil) {
|
||||
m.Cmds("", func(value ice.Maps) { m.PushSearch(mdb.TEXT, m.MergePod(value[mdb.NAME]), value) })
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case mdb.NAME:
|
||||
DreamEach(m, "", kit.Select(cli.START, cli.STOP, m.Option(ctx.ACTION) == STARTALL), func(name string) { m.Push(arg[0], name) })
|
||||
case tcp.NODENAME:
|
||||
m.Cmdy(SPACE, m.Option(mdb.NAME), SPACE, ice.INFO).CutTo(mdb.NAME, arg[0])
|
||||
case aaa.USERNAME:
|
||||
if aaa.IsTechOrRoot(m) && m.Option(ctx.ACTION) == GRANT {
|
||||
m.Cmdy(aaa.USER).Cut(aaa.USERNAME, aaa.USERNICK).Option(ice.TABLE_CHECKBOX, ice.FALSE)
|
||||
} else {
|
||||
m.Push(arg[0], m.Option(tcp.NODENAME))
|
||||
m.Push(arg[0], m.Option(ice.MSG_USERNAME))
|
||||
}
|
||||
case nfs.REPOS:
|
||||
case mdb.NAME, nfs.TEMPLATE:
|
||||
_dream_list(m).Cut("name,status,time")
|
||||
case nfs.BINARY:
|
||||
m.Cmdy(nfs.DIR, ice.BIN, "path,size,hashs,time", kit.Dict(nfs.DIR_TYPE, nfs.TYPE_BIN))
|
||||
m.Cmd(nfs.DIR, ice.USR_LOCAL_WORK, kit.Dict(nfs.DIR_TYPE, nfs.TYPE_BOTH), func(value ice.Maps) {
|
||||
m.Cmdy(nfs.DIR, path.Join(value[nfs.PATH], ice.BIN), "path,size,hashs,time", kit.Dict(nfs.DIR_TYPE, nfs.TYPE_BIN))
|
||||
})
|
||||
default:
|
||||
gdb.Event(m, DREAM_INPUTS, arg)
|
||||
}
|
||||
}},
|
||||
nfs.SCAN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
list := m.CmdMap(CODE_GIT_REPOS, nfs.REPOS)
|
||||
GoToastTable(m.Cmd(nfs.DIR, nfs.USR_LOCAL_WORK, mdb.NAME), mdb.NAME, func(value ice.Maps) {
|
||||
if repos, ok := list[value[mdb.NAME]]; ok {
|
||||
m.Cmd("", mdb.CREATE, value[mdb.NAME], repos[ORIGIN])
|
||||
}
|
||||
})
|
||||
}},
|
||||
mdb.CREATE: {Name: "create name*=hi repos binary", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.CREATE: {Name: "create name*=hi repos binary template", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.REPOS, kit.Select("", kit.Slice(kit.Split(m.Option(nfs.REPOS)), -1), 0))
|
||||
kit.If(!strings.Contains(m.Option(mdb.NAME), "-") || !strings.HasPrefix(m.Option(mdb.NAME), "20"), func() { m.Option(mdb.NAME, m.Time("20060102-")+m.Option(mdb.NAME)) })
|
||||
m.Option(nfs.REPOS, kit.Select("", kit.Split(m.Option(nfs.REPOS)), -1))
|
||||
if mdb.HashCreate(m); ice.Info.Important == true {
|
||||
_dream_start(m, m.Option(mdb.NAME))
|
||||
SpaceEvent(m, OPS_DREAM_CREATE, m.Option(mdb.NAME), m.OptionSimple(mdb.NAME, nfs.REPOS, nfs.BINARY)...)
|
||||
if mdb.HashCreate(m); !m.IsCliUA() {
|
||||
_dream_start(m, m.OptionDefault(mdb.NAME, path.Base(m.Option(nfs.REPOS))))
|
||||
}
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
gdb.Event(m, DREAM_REMOVE, m.OptionSimple(mdb.NAME))
|
||||
mdb.HashRemove(m)
|
||||
}},
|
||||
STARTALL: {Name: "startall name", Help: "启动", Icon: "bi bi-play-circle", Hand: func(m *ice.Message, arg ...string) {
|
||||
DreamEach(m, m.Option(mdb.NAME), cli.STOP, func(name string) {
|
||||
m.Cmd("", cli.START, ice.Maps{mdb.NAME: name, ice.MSG_DAEMON: ""})
|
||||
})
|
||||
}},
|
||||
STOPALL: {Name: "stopall name", Help: "停止", Icon: "bi bi-stop-circle", Hand: func(m *ice.Message, arg ...string) {
|
||||
DreamEach(m, m.Option(mdb.NAME), cli.START, func(name string) {
|
||||
m.Cmd("", cli.STOP, ice.Maps{mdb.NAME: name, ice.MSG_DAEMON: ""})
|
||||
})
|
||||
}},
|
||||
cli.BUILD: {Name: "build name", Hand: func(m *ice.Message, arg ...string) {
|
||||
compile := cli.SystemFindGo(m)
|
||||
m.Option(ice.MSG_TITLE, kit.Keys(m.Option(ice.MSG_USERPOD0), m.Option(ice.MSG_USERPOD), m.CommandKey(), m.ActionKey()))
|
||||
m.Cmd("", FOR_FLOW, m.Option(mdb.NAME), kit.JoinWord(cli.SH, ice.ETC_MISS_SH), func(p string) bool {
|
||||
if compile && nfs.Exists(m, path.Join(p, ice.SRC_MAIN_GO)) {
|
||||
return false
|
||||
} else {
|
||||
m.Cmd(SPACE, path.Base(p), cli.RUNTIME, UPGRADE)
|
||||
return true
|
||||
}
|
||||
}).Sleep3s()
|
||||
m.ProcessHold()
|
||||
}},
|
||||
PUBLISH: {Name: "publish name", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_TITLE, kit.Keys(m.Option(ice.MSG_USERPOD0), m.Option(ice.MSG_USERPOD), m.CommandKey(), m.ActionKey()))
|
||||
list := []string{cli.LINUX, cli.DARWIN, cli.WINDOWS}
|
||||
msg := m.Spawn(ice.Maps{ice.MSG_DAEMON: ""})
|
||||
func() {
|
||||
if m.Option(mdb.NAME) != "" {
|
||||
return
|
||||
}
|
||||
defer ToastProcess(m, PUBLISH, ice.Info.Pathname)()
|
||||
m.Cmd(AUTOGEN, BINPACK)
|
||||
kit.For(list, func(goos string) {
|
||||
list := []string{cli.AMD64}
|
||||
kit.If(goos == cli.DARWIN, func() { list = append(list, cli.ARM64) })
|
||||
kit.For(list, func(arch string) {
|
||||
PushNoticeRich(m, mdb.NAME, ice.Info.NodeName, msg.Cmd(COMPILE, goos, arch).AppendSimple())
|
||||
})
|
||||
})
|
||||
}()
|
||||
DreamEach(m, m.Option(mdb.NAME), "", func(name string) {
|
||||
m.Cmd(SPACE, name, AUTOGEN, BINPACK)
|
||||
kit.For(list, func(goos string) {
|
||||
list := []string{cli.AMD64}
|
||||
kit.If(goos == cli.DARWIN, func() { list = append(list, cli.ARM64) })
|
||||
kit.For(list, func(arch string) {
|
||||
PushNoticeRich(m.Options(ice.MSG_COUNT, "0", ice.LOG_DISABLE, ice.TRUE), mdb.NAME, name, msg.Cmd(SPACE, name, COMPILE, goos, arch, kit.Dict(ice.MSG_USERPOD, name)).AppendSimple())
|
||||
})
|
||||
})
|
||||
})
|
||||
m.ProcessHold()
|
||||
}},
|
||||
FOR_FLOW: {Name: "forFlow name cmd*='sh etc/miss.sh'", Help: "流程", Icon: "bi bi-terminal", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Options(ctx.DISPLAY, html.PLUGIN_XTERM, cli.CMD_OUTPUT, nfs.NewWriteCloser(func(buf []byte) (int, error) {
|
||||
PushNoticeGrow(m.Options(ice.MSG_COUNT, "0", ice.LOG_DEBUG, ice.FALSE, ice.LOG_DISABLE, ice.TRUE), strings.ReplaceAll(string(buf), lex.NL, "\r\n"))
|
||||
return len(buf), nil
|
||||
}, nil))
|
||||
msg := m.Spawn(ice.Maps{ice.MSG_DEBUG: ice.FALSE})
|
||||
DreamEach(m, m.Option(mdb.NAME), "", func(name string) {
|
||||
p := path.Join(ice.USR_LOCAL_WORK, name)
|
||||
if cb, ok := m.OptionCB("").(func(string) bool); ok && cb(p) {
|
||||
return
|
||||
}
|
||||
defer PushNoticeGrow(msg, "\r\n\r\n")
|
||||
PushNoticeGrow(msg, kit.Format("\033[33m[%s]%s$\033[0m %s\r\n", time.Now().Format(ice.MOD_TIME_ONLY), name, m.Option(ice.CMD)))
|
||||
m.Cmd(cli.SYSTEM, kit.Split(m.Option(ice.CMD)), kit.Dict(cli.CMD_DIR, p)).Sleep300ms()
|
||||
})
|
||||
}},
|
||||
cli.START: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_dream_start(m, m.Option(mdb.NAME))
|
||||
gdb.Event(m, DREAM_START, arg)
|
||||
}},
|
||||
cli.START: {Hand: func(m *ice.Message, arg ...string) { _dream_start(m, m.Option(mdb.NAME)) }},
|
||||
cli.STOP: {Hand: func(m *ice.Message, arg ...string) {
|
||||
gdb.Event(m, DREAM_STOP, arg)
|
||||
m.Cmd(SPACE, mdb.MODIFY, m.OptionSimple(mdb.NAME), mdb.STATUS, cli.STOP)
|
||||
m.Cmd(SPACE, m.Option(mdb.NAME), ice.EXIT).Sleep3s()
|
||||
m.Go(func() { m.Cmd(SPACE, m.Option(mdb.NAME), ice.EXIT) })
|
||||
m.Sleep30ms()
|
||||
}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
gdb.Event(m, DREAM_TRASH, arg)
|
||||
nfs.Trash(m, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME)))
|
||||
}},
|
||||
cli.RUNTIME: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ProcessPodCmd(m, m.Option(mdb.NAME), "", nil, arg...)
|
||||
}},
|
||||
"settings": {Name: "settings restart=manual,always access=public,private", Help: "设置", Style: html.DANGER, Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(cli.RESTART) == "manual", func() { m.Option(cli.RESTART, "") })
|
||||
kit.If(m.Option(aaa.ACCESS) == aaa.PUBLIC, func() { m.Option(aaa.ACCESS, "") })
|
||||
mdb.HashModify(m, m.OptionSimple(mdb.NAME, cli.RESTART, aaa.ACCESS))
|
||||
}},
|
||||
SETTOKEN: {Name: "settoken nodename* username*", Help: "令牌", Style: html.DANGER, Hand: func(m *ice.Message, arg ...string) {
|
||||
token := m.Cmdx(TOKEN, mdb.CREATE, mdb.TYPE, SERVER, mdb.NAME, m.Option(aaa.USERNAME), mdb.TEXT, m.Option(tcp.NODENAME))
|
||||
m.Cmd(SPACE, m.Option(mdb.NAME), SPIDE, DEV_CREATE_TOKEN, ice.Maps{TOKEN: token})
|
||||
}},
|
||||
GETTOKEN: {Help: "令牌", Style: html.DANGER, Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Options(m.Cmd(SPIDE, m.Option(mdb.NAME)).AppendSimple()).Cmdy(SPIDE, mdb.DEV_REQUEST)
|
||||
}},
|
||||
GRANT: {Name: "grant username", Role: aaa.VOID, Hand: func(m *ice.Message, arg ...string) {
|
||||
if aaa.IsTechOrRoot(m) && m.Option(aaa.USERNAME) != "" {
|
||||
m.Option(ice.MSG_USERNAME, m.Option(aaa.USERNAME))
|
||||
}
|
||||
m.Cmd(CHAT_GRANT, aaa.CONFIRM, kit.Dict(SPACE, m.Option(mdb.NAME)))
|
||||
}},
|
||||
OPEN: {Style: html.NOTICE, Role: aaa.VOID, Hand: func(m *ice.Message, arg ...string) {
|
||||
if strings.HasSuffix(m.Option(ice.MAIN), ".portal") || kit.HasPrefixList(arg, ctx.RUN) {
|
||||
if !kit.HasPrefixList(arg, ctx.RUN) {
|
||||
defer m.Push(TITLE, m.Option(mdb.NAME))
|
||||
defer m.Push("_icon", m.Option(mdb.ICON))
|
||||
defer m.Push("_style", "portal")
|
||||
defer m.Push("_height", "844")
|
||||
defer m.Push("_width", "390")
|
||||
}
|
||||
ctx.ProcessFloat(m, CHAT_IFRAME, S(m.Option(mdb.NAME)), arg...)
|
||||
} else if m.Option(mdb.TYPE) == ORIGIN {
|
||||
m.ProcessOpen(SpideOrigin(m, m.Option(mdb.NAME)))
|
||||
} else if p := ProxyDomain(m, m.Option(mdb.NAME)); p != "" {
|
||||
m.ProcessOpen(p)
|
||||
} else {
|
||||
m.ProcessOpen(S(kit.Keys(m.Option(ice.MSG_USERPOD), m.Option(mdb.NAME))))
|
||||
}
|
||||
}},
|
||||
DREAM_OPEN: {Hand: func(m *ice.Message, arg ...string) {}},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { nfs.Trash(m, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME))) }},
|
||||
DREAM_CLOSE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(arg, func(k, v string) {
|
||||
if k == cli.DAEMON && v == ice.OPS && m.Cmdv(SPACE, m.Option(mdb.NAME), mdb.STATUS) != cli.STOP {
|
||||
m.GoSleep300ms(func() { m.Cmd(DREAM, cli.START, m.OptionSimple(mdb.NAME)) })
|
||||
}
|
||||
})
|
||||
if m.Option(cli.DAEMON) == ice.OPS && m.Cmdv(SPACE, m.Option(mdb.NAME), mdb.STATUS) != cli.STOP {
|
||||
m.Go(func() { m.Sleep300ms(DREAM, cli.START, m.OptionSimple(mdb.NAME)) })
|
||||
}
|
||||
}},
|
||||
DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
button := []ice.Any{}
|
||||
if aaa.IsTechOrRoot(m) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case ORIGIN:
|
||||
button = append(button, DREAM, GETTOKEN)
|
||||
case SERVER:
|
||||
button = append(button, DREAM, SETTOKEN)
|
||||
case WORKER:
|
||||
button = append(button, "settings")
|
||||
}
|
||||
}
|
||||
m.PushButton(append(button, OPEN)...)
|
||||
kit.Switch(m.Option(mdb.TYPE), []string{SERVER, WORKER}, func() { m.PushButton(OPEN) })
|
||||
}},
|
||||
SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, cmd := range kit.Reverse(kit.Split(mdb.Config(m, html.BUTTON))) {
|
||||
m.Cmd(gdb.EVENT, gdb.LISTEN, gdb.EVENT, DREAM_TABLES, ice.CMD, cmd)
|
||||
m.Cmd(gdb.EVENT, gdb.LISTEN, gdb.EVENT, DREAM_ACTION, ice.CMD, cmd)
|
||||
aaa.White(m, kit.Keys(m.ShortKey(), ctx.ACTION, cmd))
|
||||
}
|
||||
mdb.HashSelects(m.Spawn()).SortStrR(mdb.NAME).Table(func(value ice.Maps) {
|
||||
if value[cli.RESTART] == ALWAYS && nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK+value[mdb.NAME])) {
|
||||
m.Cmd(DREAM, cli.START, kit.Dict(mdb.NAME, value[mdb.NAME]))
|
||||
}
|
||||
})
|
||||
}},
|
||||
STATS_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if msg := _dream_list(m.Spawn()); msg.Length() > 0 {
|
||||
stat := map[string]int{}
|
||||
msg.Table(func(value ice.Maps) { stat[value[mdb.TYPE]]++; stat[value[mdb.STATUS]]++ })
|
||||
PushStats(m, kit.Keys(m.CommandKey(), cli.START), stat[cli.START], "", "已启动空间")
|
||||
PushStats(m, kit.Keys(m.CommandKey(), SERVER), stat[SERVER], "", "已连接机器")
|
||||
PushStats(m, kit.Keys(m.CommandKey(), ORIGIN), stat[ORIGIN], "", "已连接主机")
|
||||
}
|
||||
}},
|
||||
ORIGIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPACE).Table(func(value ice.Maps, index int, head []string) {
|
||||
kit.If(value[mdb.TYPE] == m.ActionKey(), func() { m.PushRecord(value, head...) })
|
||||
})
|
||||
m.SortStrR(mdb.NAME)
|
||||
kit.If(len(arg) > 0, func() { m.Cut(arg...) })
|
||||
}},
|
||||
SERVER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPACE).Table(func(value ice.Maps, index int, head []string) {
|
||||
kit.If(value[mdb.TYPE] == m.ActionKey(), func() { m.PushRecord(value, head...) })
|
||||
})
|
||||
m.SortStrR(mdb.NAME)
|
||||
kit.If(len(arg) > 0, func() { m.Cut(arg...) })
|
||||
}},
|
||||
WORKER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPACE).Table(func(value ice.Maps, index int, head []string) {
|
||||
kit.If(value[mdb.TYPE] == m.ActionKey(), func() { m.PushRecord(value, head...) })
|
||||
})
|
||||
m.SortStrR(mdb.NAME)
|
||||
kit.If(len(arg) > 0, func() { m.Cut(arg...) })
|
||||
}},
|
||||
DOWNLOAD: {Name: "download path link", Hand: func(m *ice.Message, arg ...string) {
|
||||
GoToast(m, func(toast func(string, int, int)) []string {
|
||||
SpideSave(m, m.Option(nfs.PATH), kit.MergeURL(m.Option(mdb.LINK), cli.GOOS, runtime.GOOS, cli.GOARCH, runtime.GOARCH), func(count, total, value int) {
|
||||
toast(m.Option(mdb.NAME), count, total)
|
||||
})
|
||||
return nil
|
||||
})
|
||||
os.Chmod(m.Option(nfs.PATH), ice.MOD_DIR)
|
||||
}},
|
||||
VERSION: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("web.code.version")
|
||||
}},
|
||||
nfs.GOWORK: {Name: "gowork name", Help: "工作区", Icon: "bi bi-exclude", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.SYSTEM, cli.GO, "work", "init")
|
||||
kit.For([]string{".", nfs.USR_RELEASE, nfs.USR_ICEBERGS, nfs.USR_TOOLKITS}, func(p string) { m.Cmd(cli.SYSTEM, cli.GO, "work", "use", p) })
|
||||
DreamEach(m, m.Option(mdb.NAME), "", func(name string) { m.Cmd(cli.SYSTEM, cli.GO, "work", "use", path.Join(ice.USR_LOCAL_WORK, name)) })
|
||||
m.Cmdy(nfs.CAT, "go.work")
|
||||
}},
|
||||
}, StatsAction(), DreamAction(), DreamTablesAction(), mdb.ImportantHashAction(
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,main,icons,repos,binary,template,restart,access",
|
||||
html.BUTTON, kit.JoinWord(PORTAL, DESKTOP, ADMIN, WORD, VIMER, STATUS, COMPILE, XTERM, DREAM),
|
||||
)), Hand: func(m *ice.Message, arg ...string) {
|
||||
OPEN: {Hand: func(m *ice.Message, arg ...string) { ctx.ProcessOpen(m, m.MergePod(m.Option(mdb.NAME))) }},
|
||||
}, ctx.CmdAction(), DreamAction(), mdb.ImportantHashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,repos,binary,template")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
if ice.Info.NodeType == WORKER {
|
||||
return
|
||||
}
|
||||
_dream_list(m)
|
||||
if _dream_list_more(m); !aaa.IsTechOrRoot(m) || m.IsCliUA() {
|
||||
m.Action()
|
||||
} else if m.IsDebug() && cli.SystemFindGo(m) {
|
||||
m.Action(mdb.CREATE, STARTALL, STOPALL, cli.BUILD, PUBLISH)
|
||||
} else {
|
||||
m.Action(mdb.CREATE, STARTALL, STOPALL)
|
||||
}
|
||||
if m.Length() == 0 {
|
||||
m.EchoInfoButton(m.Trans("please scan or create new dream", "请扫描或创建新空间"), mdb.CREATE, nfs.SCAN)
|
||||
return
|
||||
}
|
||||
ctx.DisplayTableCard(m)
|
||||
m.Options(ice.MSG_TOOLKIT, "web.code.compose.insight")
|
||||
m.Sort("type,status,name", []string{aaa.LOGIN, WORKER, SERVER, ORIGIN}, []string{cli.START, cli.STOP, cli.BEGIN}, ice.STR_R)
|
||||
m.StatusTimeCountStats(mdb.TYPE, mdb.STATUS)
|
||||
} else if arg[0] == ctx.ACTION {
|
||||
m.Cmdy(arg[1], DREAM_ACTION, arg)
|
||||
// gdb.Event(m, DREAM_ACTION, arg)
|
||||
gdb.Event(m, DREAM_ACTION, arg)
|
||||
} else {
|
||||
m.Cmdy(nfs.CAT, arg[1:], kit.Dict(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL_WORK, arg[0])))
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func DreamTablesAction(arg ...string) ice.Actions {
|
||||
return ice.Actions{ice.CTX_INIT: {Hand: DreamWhiteHandle},
|
||||
DREAM_TABLES: {Hand: func(m *ice.Message, _ ...string) {
|
||||
m.PushButton(kit.Dict(m.CommandKey(), kit.Select(m.Commands("").Help, arg, 0)))
|
||||
}},
|
||||
DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { DreamProcess(m, "", nil, arg...) }},
|
||||
}
|
||||
}
|
||||
func DreamAction() ice.Actions {
|
||||
return gdb.EventsAction(
|
||||
DREAM_INPUTS, DREAM_CREATE, DREAM_REMOVE, DREAM_TRASH, DREAM_OPEN, DREAM_CLOSE,
|
||||
OPS_ORIGIN_OPEN, OPS_SERVER_OPEN, OPS_DREAM_CREATE, OPS_DREAM_REMOVE,
|
||||
SERVE_START, SPACE_LOGIN,
|
||||
)
|
||||
return ice.MergeActions(ice.Actions{
|
||||
DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { DreamProcess(m, []string{}, arg...) }},
|
||||
}, gdb.EventsAction(DREAM_OPEN, DREAM_CLOSE, DREAM_INPUTS, DREAM_TABLES, DREAM_ACTION))
|
||||
}
|
||||
func DreamWhiteHandle(m *ice.Message, arg ...string) {
|
||||
aaa.White(m, kit.Keys(DREAM, ctx.ACTION, m.ShortKey()))
|
||||
aaa.White(m, kit.Keys(m.ShortKey(), ctx.ACTION, DREAM_ACTION))
|
||||
}
|
||||
func DreamProcessIframe(m *ice.Message, arg ...string) {
|
||||
if !kit.HasPrefixList(arg, ctx.ACTION, m.ShortKey()) && !kit.HasPrefixList(arg, ctx.ACTION, m.CommandKey()) {
|
||||
return
|
||||
}
|
||||
if len(arg) == 2 {
|
||||
defer m.Push(TITLE, kit.Keys(m.Option(mdb.NAME), m.ShortKey())+kit.Format("(%s)", m.Command().Help))
|
||||
defer m.Push("_icon", m.Option(mdb.ICON))
|
||||
}
|
||||
DreamProcess(m, CHAT_IFRAME, func() string {
|
||||
p := S(kit.Keys(m.Option(ice.MSG_USERPOD), m.Option(mdb.NAME)))
|
||||
kit.If(m.Option(mdb.TYPE) == ORIGIN && m.CommandKey() == PORTAL, func() { p = SpideOrigin(m, m.Option(mdb.NAME)) })
|
||||
return kit.MergeURL(p+C(m.ShortKey()), ice.MSG_DEBUG, m.Option(ice.MSG_DEBUG))
|
||||
}, arg...)
|
||||
}
|
||||
func DreamProcess(m *ice.Message, cmd string, args ice.Any, arg ...string) {
|
||||
if !kit.HasPrefixList(arg, ctx.ACTION, m.ShortKey()) && !kit.HasPrefixList(arg, ctx.ACTION, m.CommandKey()) {
|
||||
return
|
||||
} else if arg = arg[2:]; len(arg) == 0 {
|
||||
arg = append(arg, m.Option(mdb.NAME))
|
||||
defer m.ProcessField(ctx.ACTION, m.ShortKey(), arg[0], ctx.RUN)
|
||||
defer processSpace(m, arg[0], arg[0], m.ShortKey())
|
||||
}
|
||||
ctx.ProcessFloat(m.Options(ice.POD, arg[0]), kit.Select(m.ShortKey(), cmd), args, arg[1:]...)
|
||||
}
|
||||
func DreamEach(m *ice.Message, name string, status string, cb func(string)) *ice.Message {
|
||||
reg, err := regexp.Compile(name)
|
||||
if m.WarnNotValid(err) {
|
||||
return m
|
||||
}
|
||||
msg := m.Spawn()
|
||||
m.Cmds(DREAM, kit.Dict(ice.DREAM_SIMPLE, ice.TRUE)).Table(func(value ice.Maps) {
|
||||
if value[mdb.STATUS] == kit.Select(cli.START, status) && value[mdb.TYPE] == WORKER && (value[mdb.NAME] == name || reg.MatchString(kit.Format("%s:%s=%s@%d", value[mdb.NAME], value[mdb.TYPE], value[nfs.MODULE], value[nfs.VERSION]))) {
|
||||
msg.Push(mdb.NAME, value[mdb.NAME])
|
||||
func DreamProcess(m *ice.Message, args ice.Any, arg ...string) {
|
||||
if kit.HasPrefixList(arg, ice.RUN) {
|
||||
ctx.ProcessField(m, m.PrefixKey(), args, kit.Slice(arg, 1)...)
|
||||
} else if kit.HasPrefixList(arg, ctx.ACTION, m.CommandKey()) {
|
||||
if arg = kit.Slice(arg, 2); kit.HasPrefixList(arg, DREAM) {
|
||||
m.Cmdy(SPACE, m.Option(ice.MSG_USERPOD, arg[1]), m.PrefixKey(), ctx.ACTION, DREAM_ACTION, ice.RUN, arg[2:])
|
||||
} else if dream := m.Option(mdb.NAME); dream != "" {
|
||||
m.Cmdy(SPACE, dream, m.PrefixKey(), ctx.ACTION, DREAM_ACTION, ice.RUN, arg).Optionv(ice.FIELD_PREFIX, kit.Simple(ctx.ACTION, m.CommandKey(), DREAM, dream, ice.RUN))
|
||||
}
|
||||
})
|
||||
return GoToastTable(msg, mdb.NAME, func(value ice.Maps) { cb(value[mdb.NAME]) })
|
||||
}
|
||||
func DreamListSpide(m *ice.Message, list []string, types string, cb func(dev, origin string)) {
|
||||
msg := m.Spawn()
|
||||
kit.For(list, func(name string) { msg.Push(mdb.NAME, name) })
|
||||
m.Cmds(SPACE).Table(func(value ice.Maps) { kit.If(value[mdb.TYPE] == types, func() { msg.Push(mdb.NAME, value[mdb.NAME]) }) })
|
||||
has := map[string]bool{}
|
||||
GoToastTable(msg, mdb.NAME, func(value ice.Maps) {
|
||||
origin := SpideOrigin(m, value[mdb.NAME])
|
||||
kit.If(!has[origin], func() { has[origin] = true; cb(value[mdb.NAME], origin) })
|
||||
})
|
||||
}
|
||||
func DreamList(m *ice.Message) *ice.Message {
|
||||
return AdminCmd(m.Options(ice.DREAM_SIMPLE, ice.TRUE), DREAM)
|
||||
}
|
||||
func DreamStat(m *ice.Message, name string) (res string) {
|
||||
if cli.SystemFindGit(m) {
|
||||
text := []string{}
|
||||
for _, line := range kit.Split(m.Cmdx(cli.SYSTEM, cli.GIT, "diff", "--shortstat", kit.Dict(cli.CMD_DIR, path.Join(ice.USR_LOCAL_WORK, name))), mdb.FS, mdb.FS) {
|
||||
if list := kit.Split(line); strings.Contains(line, nfs.FILE) {
|
||||
text = append(text, kit.Format("<span class='files'>%s file</span>", list[0]))
|
||||
} else if strings.Contains(line, "ins") {
|
||||
text = append(text, kit.Format("<span class='add'>%s+++</span>", list[0]))
|
||||
} else if strings.Contains(line, "del") {
|
||||
text = append(text, kit.Format("<span class='del'>%s---</span>", list[0]))
|
||||
}
|
||||
}
|
||||
res = strings.Join(text, "")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -1,153 +0,0 @@
|
||||
package html
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
FAVICON = "favicon"
|
||||
Mozilla = "Mozilla"
|
||||
Firefox = "Firefox"
|
||||
Safari = "Safari"
|
||||
Chrome = "Chrome"
|
||||
Edg = "Edg"
|
||||
Mobile = "Mobile"
|
||||
Alipay = "Alipay"
|
||||
MicroMessenger = "MicroMessenger"
|
||||
Android = "Android"
|
||||
IPhone = "iPhone"
|
||||
Mac = "Mac"
|
||||
Linux = "Linux"
|
||||
Windows = "Windows"
|
||||
|
||||
UserAgent = "User-Agent"
|
||||
XForwardedFor = "X-Forwarded-For"
|
||||
XHost = "X-Host"
|
||||
Referer = "Referer"
|
||||
Authorization = "Authorization"
|
||||
Bearer = "Bearer"
|
||||
Basic = "Basic"
|
||||
Accept = "Accept"
|
||||
AcceptLanguage = "Accept-Language"
|
||||
ContentEncoding = "Content-Encoding"
|
||||
ContentLength = "Content-Length"
|
||||
ContentType = "Content-Type"
|
||||
|
||||
ApplicationForm = "application/x-www-form-urlencoded"
|
||||
ApplicationOctet = "application/octet-stream"
|
||||
ApplicationJSON = "application/json"
|
||||
TEXT_PLAIN = "text/plain"
|
||||
)
|
||||
const (
|
||||
LABEL = "label"
|
||||
TABLE = "table"
|
||||
TR = "tr"
|
||||
TH = "th"
|
||||
TD = "td"
|
||||
H1 = "h1"
|
||||
H2 = "h2"
|
||||
H3 = "h3"
|
||||
SPAN = "span"
|
||||
TEXT = "text"
|
||||
PLUG = "plug"
|
||||
FORM = "form"
|
||||
TEXTAREA = "textarea"
|
||||
PASSWORD = "password"
|
||||
CHECKBOX = "checkbox"
|
||||
SELECT = "select"
|
||||
BUTTON = "button"
|
||||
IMAGE = "image"
|
||||
SUBMIT = "submit"
|
||||
CHROME = "chrome"
|
||||
NEED = "need"
|
||||
MUST = "must"
|
||||
|
||||
STYLE = "style"
|
||||
FLOAT = "float"
|
||||
WIDTH = "width"
|
||||
HEIGHT = "height"
|
||||
|
||||
BG_COLOR = "background-color"
|
||||
FG_COLOR = "color"
|
||||
)
|
||||
const (
|
||||
DARK = "dark"
|
||||
LIGHT = "light"
|
||||
WHITE = "white"
|
||||
BLACK = "black"
|
||||
SILVER = "silver"
|
||||
DANGER = "danger"
|
||||
NOTICE = "notice"
|
||||
|
||||
PROJECT = "project"
|
||||
CONTENT = "content"
|
||||
PROFILE = "profile"
|
||||
DISPLAY = "display"
|
||||
|
||||
VIEW = "view"
|
||||
VALUE = "value"
|
||||
INPUT = "input"
|
||||
ICON = "icon"
|
||||
ICONS = "icons"
|
||||
OUTPUT = "output"
|
||||
LAYOUT = "layout"
|
||||
RESIZE = "resize"
|
||||
// FILTER = "filter"
|
||||
REFRESH = "refresh"
|
||||
CONFIRM = "confirm"
|
||||
|
||||
PLUGIN_JSON = "/plugin/story/json.js"
|
||||
PLUGIN_INNER = "/plugin/local/code/inner.js"
|
||||
PLUGIN_XTERM = "/plugin/local/code/xterm.js"
|
||||
ICONS_SSH = "usr/icons/ssh.png"
|
||||
ICONS_MAIL = "usr/icons/Mail.png"
|
||||
ICONS_DREAM = "usr/icons/Launchpad.png"
|
||||
ICONS_SETTINGS = "usr/icons/System Settings.png"
|
||||
|
||||
GetLocation = "getLocation"
|
||||
ConnectWifi = "ConnectWifi"
|
||||
GetClipboardData = "getClipboardData"
|
||||
ScanQRCode = "scanQRCode"
|
||||
ChooseImage = "chooseImage"
|
||||
Record1 = "record1"
|
||||
Record2 = "record2"
|
||||
)
|
||||
|
||||
func IsImage(name, mime string) bool {
|
||||
return strings.HasPrefix(mime, "image/") || kit.ExtIsImage(name)
|
||||
}
|
||||
func IsVideo(name, mime string) bool {
|
||||
return strings.HasPrefix(mime, "video/") || kit.ExtIsVideo(name)
|
||||
}
|
||||
func IsAudio(name, mime string) bool {
|
||||
return strings.HasPrefix(mime, "audio/")
|
||||
}
|
||||
|
||||
func Format(tag string, inner string, arg ...string) string {
|
||||
return kit.Format("<%s %s>%s</%s>", tag, kit.JoinProperty(arg...), inner, tag)
|
||||
}
|
||||
func FormatA(inner string, arg ...string) string {
|
||||
return kit.Format(`<a href="%s">%s</a>`, kit.Select(inner, arg, 0), inner)
|
||||
}
|
||||
func FormatDanger(value string) string {
|
||||
return Format(SPAN, value, STYLE, kit.JoinCSS(BG_COLOR, "var(--danger-bg-color)", FG_COLOR, "var(--danger-fg-color)"))
|
||||
}
|
||||
|
||||
var AgentList = []string{
|
||||
MicroMessenger,
|
||||
Alipay,
|
||||
Edg,
|
||||
Chrome,
|
||||
Safari,
|
||||
Firefox,
|
||||
"Go-http-client",
|
||||
}
|
||||
var SystemList = []string{
|
||||
Android,
|
||||
IPhone,
|
||||
Mac,
|
||||
Linux,
|
||||
Windows,
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
fieldset.web.matrix>div.output>table.content th { padding:var(--input-padding); }
|
||||
fieldset.web.matrix>div.output>table.content th i { padding:var(--input-padding); }
|
||||
fieldset.web.matrix>div.output>table.content th i:hover { background-color:var(--hover-bg-color); color:var(--hover-fg-color); }
|
||||
fieldset.web.matrix>div.output>table.content td { padding:var(--input-padding); }
|
||||
fieldset.web.matrix>div.output>table.content td:hover { color:unset; }
|
||||
fieldset.web.matrix>div.output>table.content div.item { display:flex; align-items:center; cursor:default; }
|
||||
fieldset.web.matrix>div.output>table.content div.item img { height:var(--header-height); width:var(--header-height); cursor:pointer; }
|
||||
fieldset.web.matrix>div.output>table.content div.item img.jpg { padding:var(--input-padding); }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title { text-align:left; padding:var(--input-padding); }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title>span { cursor:pointer; }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title>span.status { font-size:var(--status-font-size); }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title>span.status>span { padding:0 var(--input-padding); }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title>span.status>span.files { background-color:purple; color:var(--notice-fg-color);}
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title>span.status>span.add { background-color:var(--notice-bg-color); color:var(--notice-fg-color);}
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title>span.status>span.del { background-color:var(--danger-bg-color); color:var(--danger-fg-color);}
|
||||
fieldset.web.matrix>div.output>table.content div.item div.status i { font-size:var(--status-font-size); padding:0; }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.action { margin-top:var(--input-margin); overflow:hidden; }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.action input.icons { display:none; }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title:hover { background-color:unset; }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.title span:hover { background-color:var(--hover-bg-color); }
|
||||
fieldset.web.matrix>div.output>table.content div.item div.status div.item:hover { background-color:var(--hover-bg-color); }
|
||||
fieldset.web.matrix>div.output>table.content div.item:hover { background-color:unset; color:unset; }
|
||||
fieldset.web.matrix>div.output:not(.process)>table.content div.item.notice { background-color:var(--notice-bg-color); color:var(--notice-fg-color); }
|
||||
fieldset.web.matrix>div.output:not(.process)>table.content div.item.danger { background-color:var(--danger-bg-color); color:var(--danger-fg-color); }
|
||||
fieldset.web.matrix>div.output:not(.process)>table.content div.item.server { border:var(--box-notice); }
|
||||
fieldset.web.matrix>div.output:not(.process)>table.content div.item.origin { border:var(--box-danger); }
|
||||
fieldset.web.matrix>div.output:not(.process)>table.content div.item.danger div.status div.item { color:var(--danger-fg-color); }
|
||||
fieldset.web.matrix>div.output:not(.process)>table.content div.item.notice div.status div.item { color:var(--notice-fg-color); }
|
||||
fieldset.web.matrix>div.output:not(.process)>table.content div.item.stop div.title>span { color:var(--disable-fg-color); }
|
||||
fieldset.web.matrix>div.output.process>table.content div.item.process { background-color:blue; color:var(--notice-fg-color); }
|
||||
fieldset.web.matrix>div.output>table.content tr:not(:hover) div.action { visibility:hidden; }
|
||||
body:not(.mobile) fieldset.web.matrix>div.output>table.content th:first-child { position:sticky; left:2px; z-index:2; }
|
||||
body:not(.mobile) fieldset.web.matrix>div.output>table.content td:first-child { box-shadow:var(--th-box-shadow); background-color:var(--plugin-bg-color); position:sticky; left:2px; z-index:1; }
|
||||
body:not(.mobile) fieldset.web.matrix>div.output>table.content td:hover { box-shadow:var(--notice-box-shadow); }
|
||||
body:not(.mobile) fieldset.web.matrix>div.output>table.content th:hover { box-shadow:var(--notice-box-shadow); }
|
||||
body:not(.mobile) fieldset.web.matrix>div.output>table.content tr.danger td:first-child { background-color:transparent; }
|
@ -1,168 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _matrix_list(m *ice.Message, domain, typ string, value ice.Maps, fields ...string) (server, icons, types []string) {
|
||||
value[DOMAIN], value[mdb.TYPE] = domain, typ
|
||||
// istech, isdebug := typ == SERVER || kit.IsIn(value[aaa.ACCESS], aaa.TECH, aaa.ROOT), m.IsDebug()
|
||||
istech := typ == SERVER || kit.IsIn(value[aaa.ACCESS], aaa.TECH, aaa.ROOT)
|
||||
compile := kit.Select("", kit.Select(COMPILE, UPGRADE, typ == SERVER), istech)
|
||||
|
||||
button := []ice.Any{PORTAL, DESKTOP, ADMIN, WORD, OPEN, compile, DREAM}
|
||||
kit.If(istech, func() { button = append(button, STATUS) })
|
||||
kit.If(istech, func() { button = append(button, VIMER, COMPILE, cli.RUNTIME, XTERM) })
|
||||
m.PushRecord(value, fields...).PushButton(button...)
|
||||
|
||||
button = []ice.Any{PORTAL, DESKTOP, ADMIN, WORD, OPEN, compile}
|
||||
kit.If(istech, func() { button = append(button, STATUS) })
|
||||
kit.If(istech, func() { button = append(button, VIMER, COMPILE, cli.RUNTIME, XTERM, cli.STOP) })
|
||||
m.Cmd(Space(m, domain), DREAM).Table(func(value ice.Maps) {
|
||||
switch value[mdb.TYPE] {
|
||||
case WORKER:
|
||||
if value[aaa.ACCESS] == aaa.PRIVATE {
|
||||
break
|
||||
}
|
||||
value[DOMAIN] = domain
|
||||
kit.If(value[mdb.STATUS] == cli.STOP, func() { value[mdb.ICONS] = nfs.P + nfs.USR_ICONS_ICEBERGS })
|
||||
kit.If(value[mdb.STATUS] == cli.STOP && istech, func() { button = []ice.Any{cli.START, mdb.REMOVE} })
|
||||
m.PushRecord(value, fields...).PushButton(button...)
|
||||
case SERVER, ORIGIN:
|
||||
server = append(server, kit.Keys(domain, value[mdb.NAME]))
|
||||
icons = append(icons, value[mdb.ICONS])
|
||||
types = append(types, value[mdb.TYPE])
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
func _matrix_action(m *ice.Message, action string, arg ...string) {
|
||||
switch domain := kit.Keys(m.Option(DOMAIN), m.Option(mdb.NAME)); action {
|
||||
case PORTAL, ADMIN:
|
||||
if kit.HasPrefixList(arg, ctx.RUN) {
|
||||
ProcessIframe(m, "", "", arg...)
|
||||
} else {
|
||||
title, link := kit.Keys(domain, action), kit.Select("", S(domain), domain != "")+C(action)
|
||||
if m.Option(mdb.TYPE) == ORIGIN {
|
||||
link = kit.MergeURL2(SpideOrigin(m, m.Option(DOMAIN)), C(action))
|
||||
if kit.IsIn(action, ADMIN) {
|
||||
m.ProcessOpen(link)
|
||||
break
|
||||
}
|
||||
}
|
||||
ProcessIframe(m, title, kit.Select(nfs.PS, link), arg...).ProcessField(ctx.ACTION, action, ctx.RUN)
|
||||
}
|
||||
case OPEN:
|
||||
link := kit.Select(nfs.PS, S(domain), domain != "")
|
||||
if m.Option(mdb.TYPE) == ORIGIN {
|
||||
link = SpideOrigin(m, m.Option(DOMAIN))
|
||||
} else if m.Option("server.type") == ORIGIN {
|
||||
link = kit.MergeURL2(SpideOrigin(m, m.Option(DOMAIN)), S(m.Option(mdb.NAME)))
|
||||
}
|
||||
m.ProcessOpen(link)
|
||||
default:
|
||||
if !kit.HasPrefixList(arg, ctx.RUN) {
|
||||
kit.If(action == XTERM, func() { arg = []string{cli.SH} })
|
||||
defer m.ProcessField(ctx.ACTION, action, ctx.RUN, domain, action)
|
||||
}
|
||||
ProcessPodCmd(m, domain, action, arg, arg...)
|
||||
}
|
||||
}
|
||||
func _matrix_dream(m *ice.Message, action string, arg ...string) {
|
||||
m.Cmd(Space(m, m.Option(DOMAIN)), DREAM, kit.Select(m.ActionKey(), action), m.OptionSimple(mdb.NAME), arg)
|
||||
}
|
||||
|
||||
func _matrix_cmd(m *ice.Message, cmd string, arg ...string) *ice.Message {
|
||||
return m.Cmdy(Space(m, kit.Keys(m.Option(DOMAIN), m.Option(mdb.NAME))), kit.Select(m.ActionKey(), cmd), arg)
|
||||
}
|
||||
|
||||
const (
|
||||
TARGET = "target"
|
||||
)
|
||||
const MATRIX = "matrix"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
MATRIX: {Name: "matrix refresh", Help: "矩阵", Icon: "Mission Control.png", Meta: kit.Dict(
|
||||
ice.CTX_ICONS, kit.Dict(STATUS, "bi bi-git"), ice.CTX_TRANS, kit.Dict(
|
||||
STATUS, "源码", html.INPUT, kit.Dict(MYSELF, "本机", ORIGIN, "主机"),
|
||||
),
|
||||
), Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(SPIDE, mdb.INPUTS, arg) }},
|
||||
mdb.CREATE: {Name: "create origin* name icons", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPIDE, mdb.CREATE, m.OptionSimple("origin,name,icons,token"), mdb.TYPE, nfs.REPOS)
|
||||
m.Cmd(SPIDE, DEV_CREATE_TOKEN, ice.Maps{CLIENT_NAME: m.Option(mdb.NAME)})
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) { _matrix_dream(m, nfs.TRASH); _matrix_dream(m, "") }},
|
||||
cli.START: {Hand: func(m *ice.Message, arg ...string) { _matrix_dream(m, "") }},
|
||||
cli.STOP: {Hand: func(m *ice.Message, arg ...string) { _matrix_dream(m, "") }},
|
||||
UPGRADE: {Hand: func(m *ice.Message, arg ...string) { _matrix_cmd(m, "").Sleep3s(); m.ProcessRefresh() }},
|
||||
INSTALL: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.IsIn(m.Cmdv(Space(m, m.Option(DOMAIN)), SPIDE, ice.DEV_IP, CLIENT_HOSTNAME), m.Cmd(tcp.HOST).Appendv(aaa.IP)...) {
|
||||
m.Option(nfs.BINARY, S(m.Option(mdb.NAME)))
|
||||
} else {
|
||||
m.OptionDefault(nfs.BINARY, UserHost(m)+S(m.Option(mdb.NAME)))
|
||||
}
|
||||
_matrix_dream(m, mdb.CREATE, kit.Simple(m.OptionSimple(mdb.ICONS, nfs.REPOS, nfs.BINARY))...)
|
||||
m.Cmd(SPACE, kit.Keys(m.Option(DOMAIN), m.Option(mdb.NAME)), MESSAGE, mdb.CREATE, mdb.TYPE, ORIGIN, mdb.ICONS, m.Option(mdb.ICONS), TARGET, kit.Keys(nfs.FROM, m.Option(mdb.NAME)))
|
||||
m.Cmd(SPACE, m.Option(mdb.NAME), MESSAGE, mdb.CREATE, mdb.TYPE, SERVER, mdb.ICONS, m.Option(mdb.ICONS), TARGET, kit.Keys(ice.OPS, m.Option(DOMAIN), m.Option(mdb.NAME)))
|
||||
StreamPushRefreshConfirm(m, m.Trans("refresh for new space ", "刷新列表查看新空间 ")+kit.Keys(m.Option(DOMAIN), m.Option(mdb.NAME)))
|
||||
SpaceEvent(m, OPS_DREAM_SPAWN, "", m.OptionSimple(mdb.NAME, DOMAIN)...)
|
||||
}},
|
||||
}, ctx.ConfAction(
|
||||
mdb.FIELD, "time,domain,status,type,name,text,icons,repos,binary,module,version,access",
|
||||
ctx.TOOLS, kit.Simple("web.code.compose.insight", VERSION), ONLINE, ice.TRUE, cli.TIMEOUT, "10s",
|
||||
)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.HasPrefixList(arg, ctx.ACTION) {
|
||||
_matrix_action(m, arg[1], arg[2:]...)
|
||||
return
|
||||
}
|
||||
GoToast(m, func(toast func(name string, count, total int)) []string {
|
||||
field := kit.Split(mdb.Config(m, mdb.FIELD))
|
||||
space := m.CmdMap(SPACE, mdb.NAME)
|
||||
m.Options("space.timeout", mdb.Config(m, cli.TIMEOUT), "dream.simple", ice.TRUE)
|
||||
list, icons, types := _matrix_list(m, "", MYSELF, ice.Maps{
|
||||
mdb.TIME: ice.Info.Make.Time,
|
||||
mdb.ICONS: nfs.P + ice.SRC_MAIN_ICO,
|
||||
nfs.MODULE: ice.Info.Make.Module,
|
||||
nfs.VERSION: ice.Info.Make.Versions(),
|
||||
aaa.ACCESS: m.Option(ice.MSG_USERROLE),
|
||||
}, field...)
|
||||
kit.For(list, func(domain string, index int, total int) {
|
||||
toast(domain, index, total)
|
||||
_matrix_list(m, domain, types[index], ice.Maps{
|
||||
mdb.TIME: space[domain][mdb.TIME],
|
||||
mdb.ICONS: icons[index],
|
||||
nfs.MODULE: space[domain][nfs.MODULE],
|
||||
nfs.VERSION: space[domain][nfs.VERSION],
|
||||
aaa.ACCESS: kit.Format(kit.Value(space[domain], aaa.USERROLE)),
|
||||
}, field...)
|
||||
})
|
||||
m.RewriteAppend(func(value, key string, index int) string {
|
||||
if key == mdb.ICONS && kit.HasPrefix(value, nfs.P, nfs.REQUIRE) {
|
||||
if domain := m.Appendv(DOMAIN)[index]; domain != "" && space[domain][mdb.TYPE] == ORIGIN {
|
||||
value = kit.MergeURL2(space[domain][mdb.TEXT], value, m.Appendv(mdb.NAME)[index])
|
||||
} else if m.Appendv(mdb.TYPE)[index] == SERVER {
|
||||
value = kit.MergeURL(value, ice.POD, m.Appendv(DOMAIN)[index])
|
||||
} else if m.Appendv(mdb.TYPE)[index] == WORKER {
|
||||
value = kit.MergeURL(value, ice.POD, kit.Keys(m.Appendv(DOMAIN)[index], m.Appendv(mdb.NAME)[index]))
|
||||
}
|
||||
}
|
||||
return value
|
||||
})
|
||||
m.Action(mdb.CREATE, UPGRADE).StatusTimeCountStats(mdb.TYPE, mdb.STATUS).Display("")
|
||||
m.Sort("type,status,name,domain", []string{MYSELF, SERVER, ORIGIN, WORKER, ""}, []string{cli.START, cli.STOP, ""}, ice.STR_R, ice.STR_R)
|
||||
ctx.Toolkit(m)
|
||||
return nil
|
||||
})
|
||||
}},
|
||||
})
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
Volcanos(chat.ONIMPORT, {
|
||||
_init: function(can, msg) { var list = {}, domain = [""], server = []
|
||||
msg.Table(function(value) { var name = value.name, _domain = value.domain
|
||||
list[name] = list[name]||{}, list[name][_domain] = value, domain.indexOf(_domain) == -1 && domain.push(_domain)
|
||||
value.type == web.SERVER && server.push(value.domain)
|
||||
}), can.db.list = list, can.db.domain = domain, can.db.server = server
|
||||
if (domain.length > can.core.Item(list).length) {
|
||||
can.ui = can.page.Appends(can, can._output, [{view: [wiki.CONTENT, html.TABLE], list: [
|
||||
{type: html.THEAD, list: [{type: html.TR, list: can.core.Item(list, function(name, value) {
|
||||
return {type: html.TH, list: [value[""]? can.onimport.item(can, value[""], list): can.onimport.void(can, name, domain, list)]}
|
||||
}) }]},
|
||||
{type: html.TBODY, list: can.core.List(domain, function(domain) { if (!domain) { return }
|
||||
return {type: html.TR, list: can.core.Item(list, function(name, value) { var item = value[domain]
|
||||
return {type: html.TD, list: [item? can.onimport.item(can, item, list): can.onimport.void(can, name, domain, list)]}
|
||||
})}
|
||||
})},
|
||||
] }]), can.onmotion.delay(can, function() { can.Status(mdb.COUNT, can.core.List(domain).length+"x"+can.core.Item(list).length) })
|
||||
} else {
|
||||
can.ui = can.page.Appends(can, can._output, [{view: [wiki.CONTENT, html.TABLE], list: [
|
||||
{type: html.THEAD, list: [{type: html.TR, list: can.core.List(domain, function(domain) {
|
||||
return {type: html.TH, list: [can.onimport.item(can, list[""][domain], list)]}
|
||||
}) }]},
|
||||
{type: html.TBODY, list: can.core.Item(list, function(name, value) { if (!name) { return }
|
||||
return {type: html.TR, list: can.core.List(domain, function(domain) { var item = value[domain]
|
||||
return {type: html.TD, list: [item? can.onimport.item(can, item, list): can.onimport.void(can, name, domain, list)]}
|
||||
})}
|
||||
})},
|
||||
] }]), can.onmotion.delay(can, function() { can.Status(mdb.COUNT, can.core.Item(list).length+"x"+can.core.List(domain).length) })
|
||||
}
|
||||
},
|
||||
void: function(can, name, domain, list) { var worker = list[name][""], server = list[""][domain]
|
||||
return {view: html.ACTION, _init: function(target) {
|
||||
worker && server.type != web.ORIGIN && can.onappend.input(can, {type: html.BUTTON, name: code.INSTALL, onclick: function(event) {
|
||||
can.Update(can.request(event, {name: name, domain: domain}, worker), [ctx.ACTION, code.INSTALL])
|
||||
}}, "", target)
|
||||
}}
|
||||
},
|
||||
item: function(can, item, list) { var name = item.name, domain = item.domain, worker = list[name][""], server = list[""][domain]; item["server.type"] = server.type
|
||||
function cb(action) { return function(event) { can.Update(can.request(event, item), [ctx.ACTION, action]) } }
|
||||
return {view: [[html.ITEM, item.type, item.status, can.onimport.style(can, item, list)]], list: [
|
||||
{img: item.icons, onclick: cb(web.DESKTOP)},
|
||||
{view: wiki.TITLE, list: [
|
||||
{text: item.name||item.domain||location.host, onclick: cb(web.OPEN)},
|
||||
item.status != cli.STOP && can.onappend.label(can, item, {version: icon.version, time: icon.compile, access: "bi bi-file-lock"}),
|
||||
{text: [item.text, "", mdb.STATUS]}, can.onappend.buttons(can, item),
|
||||
]},
|
||||
], _init: function(target) { item._target = target }}
|
||||
},
|
||||
style: function(can, item, list) { var name = item.name, domain = item.domain, worker = list[name][""]
|
||||
if (worker && worker.module != item.module) { return
|
||||
can.core.Item(list, function(key, value) { value = value[""]
|
||||
if (value.module == item.module) { worker = value }
|
||||
})
|
||||
}
|
||||
return !worker? html.NOTICE: (worker.status != cli.STOP && item.status != cli.STOP && (item.version != worker.version ||
|
||||
(item["server.type"] == "origin"? item.time > worker.time: item.time < worker.time)
|
||||
))? html.DANGER: ""
|
||||
},
|
||||
}, [""])
|
||||
Volcanos(chat.ONACTION, {
|
||||
upgrade: function(event, can) { var msg = can.request(event)
|
||||
if (msg.Option(mdb.NAME) || msg.Option(web.DOMAIN)) { return can.Update(event, [ctx.ACTION, code.UPGRADE]) }
|
||||
can.page.ClassList.add(can, can._output, ice.PROCESS)
|
||||
can.core.Next(can.db.server, function(server, next, index) {
|
||||
can.core.Next(can.core.Item(can.db.list, function(key, value) { return value }), function(list, next, i) {
|
||||
var item = list[server]; if (!item) { return next() } if (!item.name || item.status != cli.START) { return next() }
|
||||
can.page.ClassList.add(can, item._target, ice.PROCESS)
|
||||
can.Update(can.request({}, item, {_handle: ice.TRUE}), [ctx.ACTION, code.UPGRADE], function(msg) { next() })
|
||||
}, next)
|
||||
}, function() {
|
||||
can.core.Next(can.db.server, function(server, next, index) {
|
||||
var item = can.db.list[""][server]; can.page.ClassList.add(can, item._target, ice.PROCESS)
|
||||
can.Update(can.request({}, item, {_handle: ice.TRUE}), [ctx.ACTION, code.UPGRADE], function(msg) { next() })
|
||||
}, function() { can.onmotion.delay(can, function() {can.Update() }, 3000) })
|
||||
})
|
||||
},
|
||||
})
|
@ -3,33 +3,33 @@ package web
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/log"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/file"
|
||||
)
|
||||
|
||||
func UserWeb(m *ice.Message) *url.URL {
|
||||
return kit.ParseURL(m.OptionDefault(ice.MSG_USERWEB, "http://localhost:9020"))
|
||||
type Message interface {
|
||||
Option(key string, arg ...ice.Any) string
|
||||
PrefixKey(...string) string
|
||||
}
|
||||
|
||||
func UserWeb(m Message) *url.URL { return kit.ParseURL(m.Option(ice.MSG_USERWEB)) }
|
||||
func UserHost(m *ice.Message) string {
|
||||
if p := m.Option(ice.MSG_USERHOST); p != "" {
|
||||
return p
|
||||
} else if u := UserWeb(m); u.Hostname() == tcp.LOCALHOST {
|
||||
if ice.Info.Host != "" {
|
||||
return m.Option(ice.MSG_USERHOST, strings.ReplaceAll(u.Scheme+"://"+u.Host, tcp.LOCALHOST, ice.Info.Host))
|
||||
}
|
||||
if u := UserWeb(m); strings.Contains(u.Host, tcp.LOCALHOST) {
|
||||
return m.Option(ice.MSG_USERHOST, tcp.PublishLocalhost(m, u.Scheme+"://"+u.Host))
|
||||
} else {
|
||||
return m.Option(ice.MSG_USERHOST, u.Scheme+"://"+u.Host)
|
||||
}
|
||||
}
|
||||
func AgentIs(m *ice.Message, arg ...string) bool {
|
||||
func AgentIs(m Message, arg ...string) bool {
|
||||
for _, k := range arg {
|
||||
if strings.HasPrefix(strings.ToLower(m.Option(ice.MSG_USERUA)), k) {
|
||||
return true
|
||||
@ -37,35 +37,36 @@ func AgentIs(m *ice.Message, arg ...string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
func ParseLink(m *ice.Message, url string) ice.Maps {
|
||||
list := ice.Maps{}
|
||||
u := kit.ParseURL(url)
|
||||
switch arg := strings.Split(strings.TrimPrefix(u.Path, nfs.PS), nfs.PS); arg[0] {
|
||||
case CHAT:
|
||||
kit.For(arg[1:], func(k, v string) { list[k] = v })
|
||||
case SHARE:
|
||||
list[arg[0]] = arg[1]
|
||||
func MergeURL2(m Message, url string, arg ...ice.Any) string {
|
||||
if m.Option(log.DEBUG) == ice.TRUE {
|
||||
arg = append([]ice.Any{log.DEBUG, ice.TRUE}, arg)
|
||||
}
|
||||
kit.For(u.Query(), func(k string, v []string) { list[k] = v[0] })
|
||||
return list
|
||||
if m.Option(ice.MSG_USERWEB) == "" {
|
||||
return kit.MergeURL2(Domain(ice.Pulse.Cmdv(tcp.HOST, aaa.IP), ice.Pulse.Cmdv(SERVE, tcp.PORT)), url, arg...)
|
||||
}
|
||||
return kit.MergeURL2(m.Option(ice.MSG_USERWEB), url, arg...)
|
||||
}
|
||||
func PushPodCmd(m *ice.Message, cmd string, arg ...string) *ice.Message {
|
||||
if m.IsWorker() {
|
||||
return m
|
||||
}
|
||||
msg := m.Spawn()
|
||||
func MergeLink(m Message, url string, arg ...ice.Any) string {
|
||||
return kit.MergeURL(strings.Split(MergeURL2(m, url), mdb.QS)[0], arg...)
|
||||
}
|
||||
func ProcessPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) {
|
||||
m.ProcessOpen(m.MergePodCmd(pod, cmd, arg...))
|
||||
}
|
||||
func ProcessIframe(m *ice.Message, name, link string, arg ...string) {
|
||||
ctx.ProcessField(m, CHAT_IFRAME, func() []string {
|
||||
return []string{m.Cmdx(CHAT_IFRAME, mdb.CREATE, mdb.TYPE, LINK, mdb.NAME, name, LINK, link)}
|
||||
}, arg...)
|
||||
}
|
||||
func PushPodCmd(m *ice.Message, cmd string, arg ...string) {
|
||||
kit.If(m.Length() > 0 && len(m.Appendv(ice.POD)) == 0, func() { m.Table(func(value ice.Maps) { m.Push(ice.POD, m.Option(ice.MSG_USERPOD)) }) })
|
||||
m.Cmds(SPACE, func(value ice.Maps) {
|
||||
kit.If(kit.IsIn(value[mdb.TYPE], WORKER), func() { msg.Push(SPACE, value[mdb.NAME]) })
|
||||
})
|
||||
kit.If(m.Length() > 0 && len(m.Appendv(SPACE)) == 0, func() { m.Table(func(value ice.Maps) { m.Push(SPACE, "") }) })
|
||||
GoToastTable(msg, SPACE, func(value ice.Maps) {
|
||||
m.Cmd(SPACE, value[SPACE], kit.Dict(ice.MSG_USERPOD, value[SPACE]), kit.Select(m.ShortKey(), cmd), arg).Table(func(val ice.Maps, index int, head []string) {
|
||||
kit.If(!kit.IsIn(SPACE, head...), func() { head = append(head, SPACE) })
|
||||
val[SPACE] = kit.Keys(m.Option(ice.MSG_USERPOD), value[SPACE], val[SPACE])
|
||||
m.Push("", val, head)
|
||||
kit.Switch(value[mdb.TYPE], []string{SERVER, WORKER}, func() {
|
||||
m.Cmd(SPACE, value[mdb.NAME], kit.Select(m.PrefixKey(), cmd), arg).Table(func(index int, val ice.Maps, head []string) {
|
||||
val[ice.POD] = kit.Keys(value[mdb.NAME], val[ice.POD])
|
||||
m.Push("", val, head)
|
||||
})
|
||||
})
|
||||
})
|
||||
return m
|
||||
}
|
||||
func PushImages(m *ice.Message, name string) {
|
||||
if kit.ExtIsImage(name) {
|
||||
@ -77,29 +78,43 @@ func PushImages(m *ice.Message, name string) {
|
||||
func PushNotice(m *ice.Message, arg ...ice.Any) {
|
||||
if m.Option(ice.MSG_DAEMON) == "" {
|
||||
return
|
||||
} else if m.Option(ice.MSG_USERPOD) == "" {
|
||||
m.Cmd(SPACE, m.Option(ice.MSG_DAEMON), arg, ice.Maps{ice.MSG_OPTION: "", ice.MSG_OPTS: ""})
|
||||
} else {
|
||||
m.Cmd(SPACE, kit.Keys(m.Option("__target"), m.Option(ice.MSG_DAEMON)), arg, ice.Maps{ice.MSG_OPTION: "", ice.MSG_OPTS: ""})
|
||||
}
|
||||
opts := ice.Map{ice.MSG_OPTION: []string{}, ice.MSG_OPTS: []string{}}
|
||||
kit.For([]string{ctx.DISPLAY, ctx.STYLE, cli.DELAY, ice.MSG_TITLE, ice.MSG_STATUS, ice.LOG_DEBUG, ice.LOG_TRACEID, ice.LOG_DISABLE}, func(key string) {
|
||||
opts[ice.MSG_OPTION], opts[key] = kit.Simple(opts[ice.MSG_OPTION], key), m.Option(key)
|
||||
}
|
||||
func PushNoticeToast(m *ice.Message, arg ...ice.Any) { PushNotice(m, kit.List("toast", arg)...) }
|
||||
func PushNoticeGrow(m *ice.Message, arg ...ice.Any) { PushNotice(m, kit.List("grow", arg)...) }
|
||||
func PushStream(m *ice.Message) {
|
||||
m.Options(cli.CMD_OUTPUT, file.NewWriteCloser(func(buf []byte) { PushNoticeGrow(m, string(buf)) }, func() { PushNoticeToast(m, "done") })).ProcessHold()
|
||||
}
|
||||
|
||||
func Toast(m *ice.Message, text string, arg ...ice.Any) { // [title [duration [progress]]]
|
||||
if len(arg) > 1 {
|
||||
switch val := arg[1].(type) {
|
||||
case string:
|
||||
if value, err := time.ParseDuration(val); err == nil {
|
||||
arg[1] = int(value / time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
PushNoticeToast(m, text, arg)
|
||||
}
|
||||
func ToastFailure(m *ice.Message, arg ...ice.Any) { Toast(m, ice.FAILURE, arg...) }
|
||||
func ToastSuccess(m *ice.Message, arg ...ice.Any) { Toast(m, ice.SUCCESS, arg...) }
|
||||
func ToastProcess(m *ice.Message, arg ...ice.Any) func() {
|
||||
kit.If(len(arg) == 0, func() { arg = kit.List("", "-1") })
|
||||
kit.If(len(arg) == 1, func() { arg = append(arg, "-1") })
|
||||
Toast(m, ice.PROCESS, arg...)
|
||||
return func() { Toast(m, ice.SUCCESS) }
|
||||
}
|
||||
func GoToast(m *ice.Message, title string, cb func(toast func(string, int, int))) {
|
||||
cb(func(name string, count, total int) {
|
||||
kit.If(total == 0, func() { total = 1 })
|
||||
Toast(m,
|
||||
kit.Format("%s %s/%s", name, strings.TrimSuffix(kit.FmtSize(int64(count)), "B"), strings.TrimSuffix(kit.FmtSize(int64(total)), "B")),
|
||||
kit.Format("%s %d%%", title, count*100/total), kit.Select("1000", "30000", count < total), count*100/total,
|
||||
)
|
||||
})
|
||||
m.Cmd(SPACE, m.Option(ice.MSG_DAEMON), arg, opts)
|
||||
}
|
||||
func PushNoticeToast(m *ice.Message, arg ...ice.Any) {
|
||||
PushNotice(m, kit.List(TOAST, arg)...)
|
||||
}
|
||||
func PushNoticeRefresh(m *ice.Message, arg ...ice.Any) {
|
||||
PushNotice(m, kit.List("refresh", arg)...)
|
||||
}
|
||||
func PushNoticeGrow(m *ice.Message, arg ...ice.Any) {
|
||||
PushNotice(m.StatusTimeCount(), kit.List("grow", arg)...)
|
||||
}
|
||||
func PushNoticeRich(m *ice.Message, arg ...ice.Any) {
|
||||
PushNotice(m.StatusTimeCount(), kit.Simple("rich", arg))
|
||||
}
|
||||
func PushStream(m *ice.Message) *ice.Message {
|
||||
msg := m.SpawnSilent()
|
||||
m.Options(cli.CMD_OUTPUT, file.NewWriteCloser(func(buf []byte) { PushNoticeGrow(msg, string(buf)) }, nil)).ProcessHold(toastContent(m, ice.SUCCESS))
|
||||
return m
|
||||
}
|
||||
func init() { ice.Info.PushNotice = PushNotice }
|
||||
func init() { ice.Info.PushStream = PushStream }
|
||||
|
@ -1,44 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func ProcessIframe(m *ice.Message, title, link string, arg ...string) *ice.Message {
|
||||
if m.IsMetaKey() {
|
||||
m.ProcessOpen(link)
|
||||
return m
|
||||
} else if !kit.HasPrefixList(arg, ctx.RUN) {
|
||||
defer m.Push(TITLE, title)
|
||||
}
|
||||
return ctx.ProcessFloat(m, CHAT_IFRAME, link, arg...)
|
||||
}
|
||||
func ProcessPodCmd(m *ice.Message, pod, cmd string, args ice.Any, arg ...string) *ice.Message {
|
||||
if kit.HasPrefixList(arg, ctx.RUN) {
|
||||
pod, cmd, arg = arg[1], arg[2], kit.Simple(arg[0], arg[3:])
|
||||
} else {
|
||||
cmd = kit.Select(m.ActionKey(), cmd)
|
||||
defer processSpace(m, pod, pod, cmd)
|
||||
}
|
||||
return ctx.ProcessFloat(m.Options(ice.POD, pod), cmd, args, arg...)
|
||||
}
|
||||
func ProcessHashPodCmd(m *ice.Message, arg ...string) (msg *ice.Message) {
|
||||
if kit.HasPrefixList(arg, ctx.RUN) {
|
||||
msg = mdb.HashSelects(m.Spawn(), arg[1])
|
||||
arg = kit.Simple(arg[0], arg[2:])
|
||||
} else {
|
||||
msg = mdb.HashSelects(m.Spawn(), m.Option(mdb.HASH))
|
||||
defer processSpace(m, msg.Append(SPACE), m.Option(mdb.HASH))
|
||||
}
|
||||
return ctx.ProcessFloat(m.Options(ice.POD, msg.Append(SPACE)), msg.Append(ctx.INDEX), kit.Split(msg.Append(ctx.ARGS)), arg...)
|
||||
}
|
||||
func processSpace(m *ice.Message, pod string, arg ...string) {
|
||||
m.ProcessField(kit.TransArgs(kit.Simple(ctx.ACTION, m.ActionKey(), ctx.RUN, arg))...)
|
||||
m.RewriteAppend(func(value, key string, index int) string { return kit.Select("", value, key != SPACE) })
|
||||
m.Push(ice.MSG_SPACE, strings.TrimPrefix(pod, "ops."))
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const PRODUCT = "product"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
PRODUCT: {Name: "product refresh", Help: "产品展示", Actions: mdb.HashAction(mdb.SHORT, "index", mdb.FIELD, "time,name,text,order,disable,index,args"), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).SortInt(mdb.ORDER)
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
||||
func AddPortalProduct(m *ice.Message, name, text string, order float64, arg ...string) {
|
||||
m.Cmd("web.product", mdb.CREATE, mdb.NAME, name, mdb.TEXT, strings.TrimSpace(text), mdb.ORDER, order, ctx.INDEX, m.PrefixKey(), ctx.ARGS, kit.Format(arg))
|
||||
}
|
@ -14,31 +14,14 @@ import (
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
STATUS = "status"
|
||||
HEADER = "header"
|
||||
COOKIE = "cookie"
|
||||
REQUEST = "request"
|
||||
RESPONSE = "response"
|
||||
CONTENT = "content"
|
||||
TITLE = "title"
|
||||
STYLE = "style"
|
||||
COOKIE = "cookie"
|
||||
STATUS = "status"
|
||||
)
|
||||
|
||||
func renderMsg(m *ice.Message) {
|
||||
m.FormatsMeta(m.W,
|
||||
ice.MSG_USERIP, ice.MSG_USERUA, ice.MSG_METHOD, ice.MSG_REFERER, ice.MSG_DAEMON,
|
||||
ice.MSG_LANGUAGE, ice.MSG_THEME, ice.MSG_BG, ice.MSG_FG,
|
||||
ice.MSG_RIVER, ice.MSG_STORM, ice.MSG_INDEX, ice.MSG_FIELDS,
|
||||
ice.MSG_SOURCE, ice.MSG_TARGET,
|
||||
"task.id", "work.id", "space.timeout",
|
||||
ice.MSG_USERWEB0, ice.MSG_USERPOD0,
|
||||
)
|
||||
}
|
||||
func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
if cmd == ice.RENDER_VOID {
|
||||
return true
|
||||
@ -46,24 +29,17 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
arg := kit.Simple(args...)
|
||||
kit.If(len(arg) == 0, func() { args = nil })
|
||||
if cmd != "" {
|
||||
if cmd != ice.RENDER_DOWNLOAD || !kit.HasPrefix(arg[0], nfs.SRC, nfs.USR, ice.SRC_TEMPLATE, ice.USR_INTSHELL, ice.USR_VOLCANOS) {
|
||||
if !(cmd == ice.RENDER_RESULT && len(args) == 0) {
|
||||
defer func() { m.Logs("Render", cmd, args) }()
|
||||
}
|
||||
if cmd != ice.RENDER_DOWNLOAD || !kit.HasPrefix(arg[0], ice.USR_VOLCANOS, ice.USR_INTSHELL) {
|
||||
defer func() { m.Logs("Render", cmd, args) }()
|
||||
}
|
||||
}
|
||||
switch cmd {
|
||||
case COOKIE: // value [name [path [expire]]]
|
||||
RenderCookie(m, arg[0], arg[1:]...)
|
||||
case STATUS, ice.RENDER_STATUS: // [code [text]]
|
||||
if m.IsCliUA() {
|
||||
RenderStatus(m.W, kit.Int(kit.Select("200", arg, 0)), kit.Select(m.Result(), strings.Join(kit.Slice(arg, 1), " ")))
|
||||
} else {
|
||||
m.W.WriteHeader(kit.Int(kit.Select("200", arg, 0)))
|
||||
renderMsg(m)
|
||||
}
|
||||
RenderStatus(m.W, kit.Int(kit.Select("200", arg, 0)), strings.Join(kit.Slice(arg, 1), " "))
|
||||
case ice.RENDER_REDIRECT: // url [arg...]
|
||||
http.Redirect(m.W, m.R, m.MergeLink(arg[0], arg[1:]), http.StatusTemporaryRedirect)
|
||||
http.Redirect(m.W, m.R, kit.MergeURL(arg[0], arg[1:]), http.StatusTemporaryRedirect)
|
||||
case ice.RENDER_DOWNLOAD: // file [type [name]]
|
||||
if strings.HasPrefix(arg[0], HTTP) {
|
||||
RenderRedirect(m, arg[0])
|
||||
@ -71,57 +47,39 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
}
|
||||
RenderType(m.W, arg[0], kit.Select("", arg, 1))
|
||||
RenderHeader(m.W, "Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(path.Base(kit.Select(arg[0], m.Option("filename"))), arg, 2)))
|
||||
if m.Option("render") == "replace" {
|
||||
res := m.Cmdx(nfs.CAT, arg[0])
|
||||
fieldset := "fieldset." + m.Option(ctx.INDEX)
|
||||
m.W.Write([]byte(kit.ReplaceAll(res,
|
||||
"$content", fieldset+">div.output>div.layout>div.layout>div.content",
|
||||
"$profile", fieldset+">div.output>div.layout>div.layout>div.profile",
|
||||
"$display", fieldset+">div.output>div.layout>div.display",
|
||||
"$project", fieldset+">div.output>div.project",
|
||||
"$option", fieldset+">form.option",
|
||||
"$action", fieldset+">div.action",
|
||||
"$output", fieldset+">div.output",
|
||||
"$status", fieldset+">div.status",
|
||||
"$fieldset", fieldset,
|
||||
"$body", "body.cmd."+m.Option(ctx.INDEX),
|
||||
"$index", m.Option(ctx.INDEX),
|
||||
"$input", "body>div.input.float."+m.Option(ctx.INDEX),
|
||||
)))
|
||||
break
|
||||
}
|
||||
if _, e := nfs.DiskFile.StatFile(arg[0]); e == nil {
|
||||
http.ServeFile(m.W, m.R, kit.Path(arg[0]))
|
||||
} else if f, e := nfs.PackFile.OpenFile(arg[0]); e == nil {
|
||||
defer f.Close()
|
||||
t, _ := time.ParseInLocation("2006-01-02 15:04:05", ice.Info.Make.When, time.Local)
|
||||
RenderHeader(m.W, "Last-Modified", t.UTC().Format(time.RFC1123))
|
||||
io.Copy(m.W, f)
|
||||
}
|
||||
case ice.RENDER_RESULT:
|
||||
if len(arg) > 0 { // [str [arg...]]
|
||||
m.W.Write([]byte(kit.Format(arg[0], args[1:]...)))
|
||||
} else {
|
||||
kit.If(m.Result() == "" && m.Length() > 0, func() { m.TableEcho() })
|
||||
if m.Result() == "" && m.Length() > 0 {
|
||||
m.TableEcho()
|
||||
}
|
||||
m.W.Write([]byte(m.Result()))
|
||||
}
|
||||
case ice.RENDER_JSON:
|
||||
RenderType(m.W, nfs.JSON, "")
|
||||
m.W.Write([]byte(arg[0]))
|
||||
default:
|
||||
kit.If(cmd != "" && cmd != ice.RENDER_RAW, func() { m.Echo(kit.Format(cmd, args...)) })
|
||||
if cmd != "" && cmd != ice.RENDER_RAW {
|
||||
m.Echo(kit.Format(cmd, args...))
|
||||
}
|
||||
RenderType(m.W, nfs.JSON, "")
|
||||
renderMsg(m)
|
||||
m.FormatsMeta(m.W)
|
||||
}
|
||||
m.Render(ice.RENDER_VOID)
|
||||
return true
|
||||
}
|
||||
|
||||
func CookieName(url string) string { return ice.MSG_SESSID + "_" + kit.ParseURLMap(url)[tcp.PORT] }
|
||||
func RenderCookie(m *ice.Message, value string, arg ...string) string { // name path expire
|
||||
func RenderCookie(m *ice.Message, value string, arg ...string) { // name path expire
|
||||
http.SetCookie(m.W, &http.Cookie{Value: value, Name: kit.Select(CookieName(m.Option(ice.MSG_USERWEB)), arg, 0),
|
||||
Path: kit.Select(nfs.PS, arg, 1), Expires: time.Now().Add(kit.Duration(kit.Select(mdb.MONTH, arg, 2)))})
|
||||
return value
|
||||
}
|
||||
func RenderType(w http.ResponseWriter, name, mime string) {
|
||||
if mime == "" {
|
||||
@ -134,124 +92,78 @@ func RenderType(w http.ResponseWriter, name, mime string) {
|
||||
mime = "application/" + kit.Ext(name)
|
||||
}
|
||||
}
|
||||
RenderHeader(w, html.ContentType, mime)
|
||||
RenderHeader(w, ContentType, mime)
|
||||
}
|
||||
func RenderOrigin(w http.ResponseWriter, origin string) {
|
||||
RenderHeader(w, "Access-Control-Allow-Origin", origin)
|
||||
}
|
||||
func RenderHeader(w http.ResponseWriter, key, value string) { w.Header().Set(key, value) }
|
||||
func RenderHeader(w http.ResponseWriter, key, value string) {
|
||||
w.Header().Set(key, value)
|
||||
}
|
||||
func RenderStatus(w http.ResponseWriter, code int, text string) {
|
||||
w.WriteHeader(code)
|
||||
w.Write([]byte(text))
|
||||
}
|
||||
func RenderRedirect(m *ice.Message, arg ...ice.Any) { Render(m, ice.RENDER_REDIRECT, arg...) }
|
||||
func RenderDownload(m *ice.Message, arg ...ice.Any) { Render(m, ice.RENDER_DOWNLOAD, arg...) }
|
||||
func RenderResult(m *ice.Message, arg ...ice.Any) { Render(m, ice.RENDER_RESULT, arg...) }
|
||||
func RenderRedirect(m *ice.Message, arg ...ice.Any) {
|
||||
Render(m, ice.RENDER_REDIRECT, arg...)
|
||||
}
|
||||
func RenderDownload(m *ice.Message, arg ...ice.Any) {
|
||||
Render(m, ice.RENDER_DOWNLOAD, arg...)
|
||||
}
|
||||
func RenderResult(m *ice.Message, arg ...ice.Any) {
|
||||
Render(m, ice.RENDER_RESULT, arg...)
|
||||
}
|
||||
func RenderTemplate(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
return m.RenderResult(kit.Renders(kit.Format(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, WEB, file)), arg...), m))
|
||||
}
|
||||
func RenderRefresh(m *ice.Message, arg ...string) { // url text delay
|
||||
RenderTemplate(m, "refresh.html", kit.Select("3", arg, 2), kit.Select(m.Option(ice.MSG_USERWEB), arg, 0), kit.Select("loading...", arg, 1))
|
||||
}
|
||||
func RenderMain(m *ice.Message) *ice.Message {
|
||||
if m.IsCliUA() {
|
||||
return m.RenderDownload(path.Join(ice.USR_INTSHELL, ice.INDEX_SH))
|
||||
}
|
||||
m.Options(nfs.SCRIPT, ice.SRC_MAIN_JS, nfs.VERSION, RenderVersion(m))
|
||||
m.OptionDefault(mdb.ICONS, strings.Split(m.Resource(ice.Info.NodeIcon), "?")[0]+m.Option(nfs.VERSION))
|
||||
m.OptionDefault(TITLE, kit.Select("", ice.Info.Titles, ice.Info.Titles != "ContextOS"))
|
||||
kit.If(ice.Info.NodeType == WORKER, func() { m.OptionDefault(TITLE, m.Option(ice.MSG_USERPOD)) })
|
||||
m.OptionDefault(TITLE, kit.Select("ContextOS", UserWeb(m).Host))
|
||||
return m.RenderResult(kit.Renders(m.Cmdx(nfs.CAT, ice.SRC_MAIN_HTML), m))
|
||||
return RenderTemplate(m.Options(nfs.VERSION, renderVersion(m)), "main.html")
|
||||
}
|
||||
func RenderCmds(m *ice.Message, cmds ...ice.Any) {
|
||||
RenderMain(m.Options(ctx.CMDS, kit.Format(cmds)))
|
||||
func RenderCmds(m *ice.Message, list ...ice.Any) {
|
||||
RenderTemplate(m.Options(nfs.VERSION, renderVersion(m), mdb.LIST, kit.Format(list)), "cmds.html")
|
||||
}
|
||||
func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) {
|
||||
if msg := m.Cmd(Space(m, pod), ctx.COMMAND, kit.Select(m.ShortKey(), cmd)); msg.Length() == 0 {
|
||||
RenderResult(m, kit.Format("not found command %s", cmd))
|
||||
} else {
|
||||
if kit.IsIn(msg.Append(ctx.INDEX), "word", "vimer", "web.wiki.word", "web.code.vimer") {
|
||||
m.Option(mdb.ICONS, msg.Option(ice.MSG_NODEICON))
|
||||
}
|
||||
m.OptionDefault(mdb.ICONS, m.Resource(kit.Select(ice.Info.NodeIcon, msg.Option(ice.MSG_NODEICON), msg.Append(mdb.ICONS))))
|
||||
serve := strings.Split(UserHost(m), "://")[1]
|
||||
pod = kit.Select(pod, msg.Option(ice.MSG_NODENAME), m.Option(ice.MSG_USERPOD) != "")
|
||||
m.OptionDefault(TITLE, kit.Select(cmd, msg.Append(mdb.HELP), !m.IsEnglish())+" "+kit.Select(serve, pod))
|
||||
RenderCmds(m, kit.Dict(msg.AppendSimple(), ctx.ARGS, kit.Simple(arg), ctx.DISPLAY, m.Option(ice.MSG_DISPLAY)))
|
||||
}
|
||||
msg := m.Cmd(Space(m, pod), ctx.COMMAND, kit.Select("web.wiki.word", cmd))
|
||||
RenderCmds(m, kit.Dict(msg.AppendSimple(mdb.NAME, mdb.HELP),
|
||||
ctx.INDEX, msg.Append(ctx.INDEX), ctx.ARGS, kit.Simple(arg), ctx.DISPLAY, m.Option(ice.MSG_DISPLAY),
|
||||
mdb.LIST, kit.UnMarshal(msg.Append(mdb.LIST)), mdb.META, kit.UnMarshal(msg.Append(mdb.META)),
|
||||
))
|
||||
}
|
||||
func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { RenderPodCmd(m, "", cmd, arg...) }
|
||||
|
||||
func RenderVersion(m *ice.Message) string {
|
||||
ls := []string{ice.Info.Make.Versions()}
|
||||
if strings.Contains(ice.Info.Make.Domain, "debug=true") {
|
||||
if m.Option(log.DEBUG) == ice.TRUE || m.R != nil && strings.Contains(m.R.URL.RawQuery, "debug=true") {
|
||||
ls = append(ls, kit.Format("%d", time.Now().Unix()-kit.Time(ice.Info.Make.When)/int64(time.Second)))
|
||||
}
|
||||
func renderVersion(m *ice.Message) string {
|
||||
if m.R != nil && strings.Contains(m.R.URL.RawQuery, "debug=true") || m.Option(log.DEBUG) == ice.TRUE {
|
||||
return kit.Format("?_v=%v&_t=%d", ice.Info.Make.Version, time.Now().Unix())
|
||||
}
|
||||
return "?" + kit.JoinQuery(kit.Simple(kit.Dict("_v", strings.Join(ls, "-"), ice.POD, m.Option(ice.MSG_USERPOD)))...)
|
||||
return ""
|
||||
}
|
||||
|
||||
const (
|
||||
PLAY = "play"
|
||||
SHOW = "show"
|
||||
|
||||
BLACK = "black"
|
||||
DISPLAY = "display"
|
||||
RESIZE = "resize"
|
||||
LAYOUT = "layout"
|
||||
OUTPUT = "output"
|
||||
INPUT = "input"
|
||||
VIEW = "view"
|
||||
CHAT = "chat"
|
||||
WORD = "word"
|
||||
VIMER = "vimer"
|
||||
XTERM = "xterm"
|
||||
GRANT = "grant"
|
||||
OAUTH = "oauth"
|
||||
DESKTOP = "desktop"
|
||||
MESSAGE = "message"
|
||||
|
||||
AUTOGEN = "autogen"
|
||||
BINPACK = "binpack"
|
||||
COMPILE = "compile"
|
||||
PUBLISH = "publish"
|
||||
VERSION = "version"
|
||||
UPGRADE = "upgrade"
|
||||
INSTALL = "install"
|
||||
|
||||
CODE_MYSQL_CLIENT = "web.code.mysql.client"
|
||||
CODE_MYSQL_QUERY = "web.code.mysql.query"
|
||||
CODE_GIT_SERVICE = "web.code.git.service"
|
||||
CODE_GIT_SEARCH = "web.code.git.search"
|
||||
CODE_GIT_STATUS = "web.code.git.status"
|
||||
CODE_GIT_REPOS = "web.code.git.repos"
|
||||
CODE_AUTOGEN = "web.code.autogen"
|
||||
CODE_COMPILE = "web.code.compile"
|
||||
CODE_PUBLISH = "web.code.publish"
|
||||
CODE_UPGRADE = "web.code.upgrade"
|
||||
CODE_VIMER = "web.code.vimer"
|
||||
CODE_INNER = "web.code.inner"
|
||||
CODE_XTERM = "web.code.xterm"
|
||||
CODE_MOD = "web.code.mod"
|
||||
WIKI_FEEL = "web.wiki.feel"
|
||||
WIKI_DRAW = "web.wiki.draw"
|
||||
WIKI_WORD = "web.wiki.word"
|
||||
WIKI_PORTAL = "web.wiki.portal"
|
||||
CHAT_OAUTH_CLIENT = "web.chat.oauth.client"
|
||||
CHAT_WX_ACCESS = "web.chat.wx.access"
|
||||
CHAT_WX_AGENT = "web.chat.wx.agent"
|
||||
CHAT_WX_TEMPLATE = "web.chat.wx.template"
|
||||
CHAT_WX_OCR = "web.chat.wx.ocr"
|
||||
CHAT_MESSAGE = "web.chat.message"
|
||||
CHAT_HEADER = "web.chat.header"
|
||||
CHAT_IFRAME = "web.chat.iframe"
|
||||
CHAT_FAVOR = "web.chat.favor"
|
||||
CHAT_FLOWS = "web.chat.flows"
|
||||
CHAT_GRANT = "web.chat.grant"
|
||||
CHAT_POD = "web.chat.pod"
|
||||
CHAT_CMD = "web.chat.cmd"
|
||||
TEAM_PLAN = "web.team.plan"
|
||||
TEAM_GONGANXITONG_USER = "web.team.gonganxitong.user"
|
||||
TEAM_GONGANXITONG_CITY = "web.team.gonganxitong.city"
|
||||
TEAM_GONGANXITONG_DOMAIN = "web.team.gonganxitong.domain"
|
||||
TEAM_PLAN = "web.team.plan"
|
||||
WIKI_WORD = "web.wiki.word"
|
||||
WIKI_DRAW = "web.wiki.draw"
|
||||
WIKI_FEEL = "web.wiki.feel"
|
||||
CODE_INNER = "web.code.inner"
|
||||
CODE_VIMER = "web.code.vimer"
|
||||
CODE_XTERM = "web.code.xterm"
|
||||
CODE_COMPILE = "web.code.compile"
|
||||
CODE_GIT_SERVICE = "web.code.git.service"
|
||||
CODE_GIT_STATUS = "web.code.git.status"
|
||||
CODE_GIT_REPOS = "web.code.git.repos"
|
||||
CHAT_FAVOR = "web.chat.favor"
|
||||
CHAT_IFRAME = "web.chat.iframe"
|
||||
)
|
||||
|
||||
func MessageInsertJSON(m *ice.Message, zone, name, text string, arg ...string) {
|
||||
MessageInsert(m, zone, kit.Simple(mdb.TYPE, html.TEXT, mdb.NAME, kit.Select(m.CommandKey(), name),
|
||||
mdb.TEXT, text, ctx.DISPLAY, html.PLUGIN_JSON, arg)...)
|
||||
}
|
||||
func MessageInsert(m *ice.Message, zone string, arg ...string) {
|
||||
m.Cmd(MESSAGE, mdb.INSERT, zone, tcp.DIRECT, tcp.RECV, arg)
|
||||
}
|
||||
|
@ -1,166 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _route_push(m *ice.Message, space string, msg *ice.Message) *ice.Message {
|
||||
return msg.Table(func(value ice.Maps, index int, head []string) {
|
||||
value[SPACE], head = space, append(head, SPACE)
|
||||
m.Push("", value, head)
|
||||
})
|
||||
}
|
||||
func _route_match(m *ice.Message, space string, cb func(ice.Maps, int, []ice.Maps)) {
|
||||
reg, err := regexp.Compile(space)
|
||||
if m.WarnNotValid(err) {
|
||||
return
|
||||
}
|
||||
res := []ice.Maps{}
|
||||
list := kit.Split(space)
|
||||
m.Cmd("").Table(func(value ice.Maps) {
|
||||
if value[mdb.STATUS] == OFFLINE {
|
||||
|
||||
} else if value[SPACE] == space {
|
||||
res = append(res, value)
|
||||
} else if kit.IsIn(value[SPACE], list...) {
|
||||
res = append(res, value)
|
||||
} else if reg.MatchString(kit.Format("%s:%s=%s@%s", value[SPACE], value[mdb.TYPE], value[nfs.MODULE], value[nfs.VERSION])) {
|
||||
res = append(res, value)
|
||||
}
|
||||
})
|
||||
for i, item := range res {
|
||||
cb(item, i, res)
|
||||
}
|
||||
}
|
||||
func _route_toast(m *ice.Message, space string, args ...string) {
|
||||
GoToast(m, func(toast func(string, int, int)) (list []string) {
|
||||
count, total := 0, 1
|
||||
_route_match(m, space, func(value ice.Maps, i int, _list []ice.Maps) {
|
||||
count, total = i, len(_list)
|
||||
toast(value[SPACE], count, total)
|
||||
if msg := _route_push(m, value[SPACE], m.Cmd(SPACE, value[SPACE], args, ice.Maps{ice.MSG_DAEMON: ""})); msg.IsErr() || !cli.IsSuccess(msg) {
|
||||
list = append(list, value[SPACE]+": "+msg.Result())
|
||||
} else {
|
||||
kit.If(msg.Result() == "", func() { msg.TableEcho() })
|
||||
m.Push(SPACE, value[SPACE]).Push(ice.RES, msg.Result())
|
||||
}
|
||||
})
|
||||
m.StatusTimeCount(ice.CMD, kit.Join(args, lex.SP), ice.SUCCESS, kit.Format("%d/%d", total-len(list), total))
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
const (
|
||||
ONLINE = "online"
|
||||
OFFLINE = "offline"
|
||||
)
|
||||
const ROUTE = "route"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
ROUTE: {Name: "route space:text cmds:text auto build travel diagram prunes", Help: "路由表", Icon: "Shortcuts.png", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.MAIN: {Help: "首页", Hand: func(m *ice.Message, arg ...string) { ctx.ProcessField(m, CHAT_IFRAME, m.MergePod(""), arg...) }},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case SPACE:
|
||||
list := map[string]bool{}
|
||||
push := func(key string) { kit.If(!list[key], func() { m.Push(arg[0], key); list[key] = true }) }
|
||||
mdb.HashSelect(m.Spawn()).Table(func(value ice.Maps) { push(kit.Format("=%s@", value[nfs.MODULE])) })
|
||||
kit.For([]string{WORKER, SERVER}, func(key string) { push(kit.Format(":%s=", key)) })
|
||||
}
|
||||
}},
|
||||
ctx.CMDS: {Name: "cmds space index* args", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
_route_toast(m, m.Option(SPACE), append([]string{m.Option(ctx.INDEX)}, kit.Split(m.Option(ctx.ARGS))...)...)
|
||||
}},
|
||||
cli.BUILD: {Name: "build space", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_TITLE, kit.Keys(m.Option(ice.MSG_USERPOD0), m.Option(ice.MSG_USERPOD), m.CommandKey()))
|
||||
_route_toast(m, m.Option(SPACE), cli.RUNTIME, UPGRADE)
|
||||
m.SetAppend().Cmdy("", "travel")
|
||||
}},
|
||||
"travel": {Help: "遍历", Icon: "bi bi-card-list", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.For(kit.Split(m.OptionDefault(ice.MSG_FIELDS, mdb.Config(m, mdb.FIELD))), func(key string) {
|
||||
switch key {
|
||||
case mdb.TIME:
|
||||
m.Push(key, ice.Info.Make.Time)
|
||||
case mdb.TYPE:
|
||||
m.Push(key, ice.Info.NodeType)
|
||||
case nfs.MODULE:
|
||||
m.Push(key, ice.Info.Make.Module)
|
||||
case nfs.VERSION:
|
||||
m.Push(key, ice.Info.Make.Versions())
|
||||
case cli.COMMIT_TIME:
|
||||
m.Push(key, ice.Info.Make.When)
|
||||
case cli.COMPILE_TIME:
|
||||
m.Push(key, ice.Info.Make.Time)
|
||||
case cli.BOOT_TIME:
|
||||
m.Push(key, m.Cmdx(cli.RUNTIME, "boot.time"))
|
||||
case "md5":
|
||||
m.Push(key, ice.Info.Hash)
|
||||
case nfs.SIZE:
|
||||
var stats runtime.MemStats
|
||||
runtime.ReadMemStats(&stats)
|
||||
m.Push(key, kit.Format("%s/%s/%s", ice.Info.Size, kit.FmtSize(int64(stats.Sys)), m.Cmdx(nfs.DIR, nfs.SIZE)))
|
||||
case nfs.PATH:
|
||||
m.Push(key, kit.Path(""))
|
||||
case tcp.HOSTNAME:
|
||||
m.Push(key, ice.Info.Hostname)
|
||||
default:
|
||||
m.Push(key, "")
|
||||
}
|
||||
})
|
||||
defer m.ProcessRefresh()
|
||||
PushPodCmd(m, "", m.ActionKey())
|
||||
m.Table(func(value ice.Maps) { kit.If(value[SPACE], func() { mdb.HashCreate(m.Spawn(), kit.Simple(value)) }) })
|
||||
}},
|
||||
"diagram": {Help: "导图", Icon: "bi bi-diagram-3", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.DisplayStorySpide(m.Cmdy(""), nfs.DIR_ROOT, ice.Info.NodeName, mdb.FIELD, SPACE, lex.SPLIT, nfs.PT, ctx.ACTION, ice.MAIN)
|
||||
}},
|
||||
mdb.PRUNES: &ice.Action{Name: "prunes status=offline", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd("", func(value ice.Maps) {
|
||||
kit.If(value[mdb.STATUS] == OFFLINE, func() { mdb.HashRemove(m, SPACE, value[SPACE]) })
|
||||
})
|
||||
m.ProcessRefresh()
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, SPACE, mdb.FIELD, "time,space,type,module,version,commitTime,compileTime,bootTime,md5,size,path,hostname", mdb.SORT, "type,space", html.CHECKBOX, ice.TRUE, mdb.ACTION, ice.MAIN)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 1 {
|
||||
_route_match(m, arg[0], func(value ice.Maps, i int, list []ice.Maps) {
|
||||
_route_push(m, value[SPACE], m.Cmd(SPACE, value[SPACE], arg[1:]))
|
||||
})
|
||||
} else if mdb.HashSelect(m, arg...); len(arg) > 0 {
|
||||
m.EchoIFrame(m.MergePod(arg[0]))
|
||||
} else {
|
||||
m.OptionFields("")
|
||||
list := m.CmdMap(SPACE, mdb.NAME)
|
||||
lists := m.CmdMap(DREAM, mdb.NAME)
|
||||
mem, disk, stat := 0, 0, map[string]int{}
|
||||
m.Table(func(value ice.Maps) {
|
||||
disk += kit.Int(kit.Select("", kit.Split(value[nfs.SIZE], nfs.PS), 2))
|
||||
mem += kit.Int(kit.Select("", kit.Split(value[nfs.SIZE], nfs.PS), 0))
|
||||
if _, ok := list[value[SPACE]]; ok {
|
||||
m.Push(mdb.STATUS, ONLINE)
|
||||
stat[ONLINE]++
|
||||
} else {
|
||||
m.Push(mdb.STATUS, OFFLINE)
|
||||
stat[OFFLINE]++
|
||||
}
|
||||
if v, ok := lists[value[SPACE]]; ok {
|
||||
m.Push(mdb.ICONS, v[mdb.ICONS])
|
||||
} else {
|
||||
m.Push(mdb.ICONS, "")
|
||||
}
|
||||
}).Sort("status,space", ice.STR_R, ice.STR).StatusTimeCount(stat, nfs.SIZE, kit.Format("%s/%s", kit.FmtSize(mem), kit.FmtSize(disk))).Options(ice.MSG_ACTION, "")
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
@ -1,243 +1,111 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/log"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/logs"
|
||||
)
|
||||
|
||||
func _serve_address(m *ice.Message) string { return HostPort(m, tcp.LOCALHOST, m.Option(tcp.PORT)) }
|
||||
func _serve_address(m *ice.Message) string { return Domain(tcp.LOCALHOST, m.Option(tcp.PORT)) }
|
||||
func _serve_start(m *ice.Message) {
|
||||
kit.If(m.Option(aaa.USERNAME), func() { aaa.UserRoot(m, "", m.Option(aaa.USERNAME), m.Option(aaa.USERNICK), m.Option(aaa.LANGUAGE)) })
|
||||
kit.If(m.Option(tcp.PORT) == tcp.RANDOM, func() { m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT)) })
|
||||
m.Go(func() {
|
||||
m.Cmd(SPIDE, ice.OPS, _serve_address(m)+nfs.PS+ice.EXIT, ice.Maps{CLIENT_TIMEOUT: cli.TIME_30ms, ice.LOG_DISABLE: ice.TRUE})
|
||||
}).Sleep(cli.TIME_1s)
|
||||
cli.NodeInfo(m, kit.Select(kit.Split(ice.Info.Hostname, nfs.PT)[0], m.Option(tcp.NODENAME)), SERVER, mdb.Config(m, mdb.ICONS))
|
||||
kit.If(ice.HasVar(), func() { m.Cmd(nfs.SAVE, ice.VAR_LOG_ICE_PORT, m.Option(tcp.PORT)) })
|
||||
kit.For(kit.Split(m.Option(ice.DEV)), func(dev string) {
|
||||
if strings.HasPrefix(dev, HTTP) {
|
||||
m.Cmd(SPIDE, mdb.CREATE, dev, ice.DEV, "", nfs.REPOS)
|
||||
m.Cmd(SPIDE, mdb.CREATE, dev, "dev_ip", "", "dev_ip")
|
||||
dev = ice.DEV
|
||||
}
|
||||
if msg := m.Cmd(SPIDE, dev); msg.Append(TOKEN) == "" {
|
||||
if m.Option(TOKEN) != "" {
|
||||
m.Cmd(SPACE, tcp.DIAL, ice.DEV, dev, TOKEN, m.Option(TOKEN))
|
||||
} else {
|
||||
m.Cmd(SPACE, tcp.DIAL, ice.DEV, dev)
|
||||
}
|
||||
}
|
||||
defer kit.For(kit.Split(m.Option(ice.DEV)), func(v string) {
|
||||
m.Sleep("10ms").Cmd(SPACE, tcp.DIAL, ice.DEV, v, mdb.NAME, ice.Info.NodeName, TOKEN, m.Option(TOKEN))
|
||||
})
|
||||
m.Spawn(ice.Maps{TOKEN: ""}).Start("", m.OptionSimple(tcp.HOST, tcp.PORT)...)
|
||||
if m.Cmd(tcp.HOST).Length() == 0 {
|
||||
return
|
||||
}
|
||||
kit.If(m.Option(aaa.USERNAME), func() { aaa.UserRoot(m, m.Option(aaa.USERNICK), m.Option(aaa.USERNAME)) })
|
||||
kit.If(m.Option(tcp.PORT) == tcp.RANDOM, func() { m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT)) })
|
||||
kit.If(cli.IsWindows(), func() { m.Cmd(SPIDE, ice.OPS, _serve_address(m)+"/exit").Sleep30ms() })
|
||||
cli.NodeInfo(m, kit.Select(ice.Info.Hostname, m.Option(tcp.NODENAME)), SERVER)
|
||||
m.Start("", m.OptionSimple(tcp.HOST, tcp.PORT)...)
|
||||
}
|
||||
func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
const (
|
||||
X_REAL_IP = "X-Real-Ip"
|
||||
X_REAL_PORT = "X-Real-Port"
|
||||
INDEX_MODULE = "Index-Module"
|
||||
X_REAL_IP = "X-Real-Ip"
|
||||
X_REAL_PORT = "X-Real-Port"
|
||||
X_FORWARDED_FOR = "X-Forwarded-For"
|
||||
INDEX_MODULE = "Index-Module"
|
||||
)
|
||||
if r.Header.Get(INDEX_MODULE) == "" {
|
||||
r.Header.Set(INDEX_MODULE, m.Prefix())
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
func() {
|
||||
defer InfoLock.Lock()()
|
||||
Info.ServeMainCount++
|
||||
}()
|
||||
if ip := r.Header.Get(X_REAL_IP); ip != "" {
|
||||
if r.Header.Set(ice.MSG_USERIP, ip); r.Header.Get(X_REAL_PORT) != "" {
|
||||
r.Header.Set(ice.MSG_USERADDR, ip+nfs.DF+r.Header.Get(X_REAL_PORT))
|
||||
}
|
||||
} else if ip := r.Header.Get(html.XForwardedFor); ip != "" {
|
||||
} else if ip := r.Header.Get(X_FORWARDED_FOR); ip != "" {
|
||||
r.Header.Set(ice.MSG_USERIP, kit.Split(ip)[0])
|
||||
} else if strings.HasPrefix(r.RemoteAddr, "[") {
|
||||
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, "]")[0][1:])
|
||||
} else {
|
||||
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, nfs.DF)[0])
|
||||
}
|
||||
if !kit.HasPrefix(r.URL.String(), nfs.VOLCANOS, nfs.REQUIRE_MODULES, nfs.INTSHELL) {
|
||||
r.Header.Set(ice.LOG_TRACEID, log.Traceid(m))
|
||||
m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String(), logs.TraceidMeta(r.Header.Get(ice.LOG_TRACEID)))
|
||||
}
|
||||
if path.Join(r.URL.Path) == nfs.PS && strings.HasPrefix(r.UserAgent(), html.Mozilla) {
|
||||
r.URL.Path = kit.Select(nfs.PS, mdb.Config(m, ice.MAIN))
|
||||
}
|
||||
if r.Method == http.MethodGet {
|
||||
msg := m.Spawn(w, r).Options(ice.MSG_USERUA, r.UserAgent(), ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID), ParseLink(m, kit.Select(r.URL.String(), r.Referer())))
|
||||
if path.Join(r.URL.Path) == nfs.PS {
|
||||
msg.Options(ice.MSG_USERWEB, _serve_domain(msg))
|
||||
if Render(RenderMain(msg), msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...) {
|
||||
return false
|
||||
}
|
||||
} else if _serve_static(msg, w, r) {
|
||||
return false
|
||||
kit.If(path.Join(r.URL.Path) == nfs.PS, func() { r.URL.Path = kit.Select(nfs.PS, mdb.Config(m, "main")) })
|
||||
if m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String()); r.Method == http.MethodGet {
|
||||
if msg := m.Spawn(w, r).Options(ice.MSG_USERUA, r.UserAgent()); path.Join(r.URL.Path) == nfs.PS {
|
||||
return !Render(RenderMain(msg), msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...)
|
||||
} else if p := path.Join(kit.Select(ice.USR_VOLCANOS, ice.USR_INTSHELL, msg.IsCliUA()), r.URL.Path); nfs.Exists(msg, p) {
|
||||
return !Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
func _serve_static(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
// _serve_params(msg, r.Header.Get(html.Referer))
|
||||
if strings.HasPrefix(r.URL.Path, "/.git/") {
|
||||
return false
|
||||
}
|
||||
_serve_params(msg, r.URL.String())
|
||||
ispod := msg.Option(ice.POD) != ""
|
||||
if strings.HasPrefix(r.URL.Path, nfs.V) {
|
||||
return Render(msg, ice.RENDER_DOWNLOAD, path.Join(ice.USR_VOLCANOS, strings.TrimPrefix(r.URL.Path, nfs.V)))
|
||||
} else if kit.HasPrefix(r.URL.Path, nfs.P) {
|
||||
if kit.Contains(r.URL.String(), "render=replace") {
|
||||
return false
|
||||
}
|
||||
p := path.Join(strings.TrimPrefix(r.URL.Path, nfs.P))
|
||||
if pp := path.Join(nfs.USR_LOCAL_WORK, msg.Option(ice.POD)); ispod && nfs.Exists(msg, pp) && !strings.HasPrefix(p, "require/") {
|
||||
if kit.HasPrefix(p, "var/", "usr/local/") {
|
||||
return false
|
||||
}
|
||||
if pp = path.Join(pp, p); nfs.Exists(msg, pp) {
|
||||
return Render(msg, ice.RENDER_DOWNLOAD, pp)
|
||||
} else if nfs.Exists(msg, p) {
|
||||
return Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
}
|
||||
}
|
||||
if kit.HasPrefix(p, ice.USR_ICEBERGS, ice.USR_ICONS) && nfs.Exists(msg, p) {
|
||||
return Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
}
|
||||
if !ispod {
|
||||
return (kit.HasPrefix(p, nfs.SRC) && nfs.Exists(msg, p)) && Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
}
|
||||
} else if kit.HasPrefix(r.URL.Path, nfs.M) {
|
||||
p := nfs.USR_MODULES + strings.TrimPrefix(r.URL.Path, nfs.M)
|
||||
return nfs.Exists(msg, p) && Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
} else if kit.HasPrefix(path.Base(r.URL.Path), "MP_verify_") {
|
||||
return Render(msg, ice.RENDER_DOWNLOAD, nfs.ETC+path.Base(r.URL.Path))
|
||||
} else if p := path.Join(kit.Select(ice.USR_VOLCANOS, ice.USR_INTSHELL, msg.IsCliUA()), r.URL.Path); nfs.Exists(msg, p) {
|
||||
return Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
} else if p = path.Join(nfs.USR, r.URL.Path); kit.HasPrefix(r.URL.Path, nfs.VOLCANOS, nfs.INTSHELL) && nfs.Exists(msg, p) {
|
||||
return Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
}
|
||||
return false
|
||||
p := ""
|
||||
if p = strings.TrimPrefix(r.URL.Path, nfs.REQUIRE); kit.HasPrefix(r.URL.Path, nfs.REQUIRE_SRC, nfs.REQUIRE+ice.USR_ICONS, nfs.REQUIRE+ice.USR_ICEBERGS) && nfs.Exists(msg, p) {
|
||||
return !ispod && Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
} else if p = path.Join(nfs.USR_MODULES, strings.TrimPrefix(r.URL.Path, nfs.REQUIRE_MODULES)); kit.HasPrefix(r.URL.Path, nfs.REQUIRE_MODULES) && nfs.Exists(msg, p) {
|
||||
return Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
func _serve_params(m *ice.Message, p string) {
|
||||
if u, e := url.Parse(p); e == nil {
|
||||
func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||
_log := func(level string, arg ...ice.Any) *ice.Message { return m.Logs(strings.Title(level), arg...) }
|
||||
if u, e := url.Parse(r.Header.Get(Referer)); e == nil {
|
||||
add := func(k, v string) { _log(nfs.PATH, k, m.Option(k, v)) }
|
||||
switch arg := strings.Split(strings.TrimPrefix(u.Path, nfs.PS), nfs.PS); arg[0] {
|
||||
case CHAT:
|
||||
kit.For(arg[1:], func(k, v string) { m.Option(k, v) })
|
||||
kit.For(arg[1:], func(k, v string) { add(k, v) })
|
||||
case SHARE:
|
||||
m.Option(arg[0], arg[1])
|
||||
case "s":
|
||||
m.Option(ice.POD, kit.Select("", arg, 1))
|
||||
add(arg[0], arg[1])
|
||||
}
|
||||
kit.For(u.Query(), func(k string, v []string) { m.Optionv(k, v) })
|
||||
kit.For(u.Query(), func(k string, v []string) { _log(ctx.ARGS, k, v).Optionv(k, v) })
|
||||
}
|
||||
}
|
||||
func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||
debug := strings.Contains(r.URL.String(), "debug=true") || strings.Contains(r.Header.Get(html.Referer), "debug=true")
|
||||
m.Options(ice.LOG_DEBUG, ice.FALSE, ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID))
|
||||
_log := func(level string, arg ...ice.Any) *ice.Message {
|
||||
if debug || arg[0] == ice.MSG_CMDS {
|
||||
return m.Logs(strings.Title(level), arg...)
|
||||
}
|
||||
return m
|
||||
}
|
||||
kit.If(r.Header.Get(html.Referer), func(p string) { _log("page", html.Referer, p) })
|
||||
_serve_params(m, r.Header.Get(html.Referer))
|
||||
_serve_params(m, r.URL.String())
|
||||
if r.Method == http.MethodGet && m.Option(ice.MSG_CMDS) != "" {
|
||||
_log(ctx.ARGS, ice.MSG_CMDS, m.Optionv(ice.MSG_CMDS))
|
||||
}
|
||||
switch kit.Select("", kit.Split(r.Header.Get(html.ContentType)), 0) {
|
||||
case html.ApplicationJSON:
|
||||
buf, _ := ioutil.ReadAll(r.Body)
|
||||
m.Option("request.data", string(buf))
|
||||
kit.For(kit.UnMarshal(string(buf)), func(k string, v ice.Any) { m.Optionv(k, v) })
|
||||
kit.For(kit.ParseQuery(r.URL.RawQuery), func(k string, v []string) { m.Optionv(k, v) })
|
||||
switch r.Header.Get(ContentType) {
|
||||
case ApplicationJSON:
|
||||
kit.For(kit.UnMarshal(r.Body), func(k string, v ice.Any) { m.Optionv(k, v) })
|
||||
default:
|
||||
r.ParseMultipartForm(kit.Int64(kit.Select("4096", r.Header.Get(html.ContentLength))))
|
||||
r.ParseMultipartForm(kit.Int64(kit.Select("4096", r.Header.Get(ContentLength))))
|
||||
kit.For(r.PostForm, func(k string, v []string) { _log(FORM, k, kit.Join(v, lex.SP)).Optionv(k, v) })
|
||||
}
|
||||
kit.For(r.Cookies(), func(k, v string) { m.Optionv(k, v) })
|
||||
m.Options(ice.MSG_METHOD, r.Method, ice.MSG_COUNT, "0")
|
||||
m.Options(ice.MSG_REFERER, r.Header.Get(html.Referer))
|
||||
m.OptionDefault(ice.MSG_HEIGHT, "480", ice.MSG_WIDTH, "320")
|
||||
m.Options(ice.MSG_USERWEB, _serve_domain(m), ice.MSG_USERPOD, m.Option(ice.POD))
|
||||
m.Options(ice.MSG_USERUA, r.Header.Get(html.UserAgent), ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
|
||||
m.Options(ice.MSG_USERUA, r.Header.Get(UserAgent), ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
|
||||
m.Options(ice.MSG_SESSID, kit.Select(m.Option(ice.MSG_SESSID), m.Option(CookieName(m.Option(ice.MSG_USERWEB)))))
|
||||
kit.If(m.Optionv(ice.MSG_CMDS) == nil, func() {
|
||||
kit.If(strings.TrimPrefix(r.URL.Path, key), func(p string) { m.Optionv(ice.MSG_CMDS, strings.Split(p, nfs.PS)) })
|
||||
})
|
||||
UserHost(m)
|
||||
for k, v := range m.R.Header {
|
||||
// m.Info("what %v %v", k, v)
|
||||
kit.If(strings.HasPrefix(k, "Wechatpay"), func() { m.Option(k, v) })
|
||||
}
|
||||
m.W.Header().Add(strings.ReplaceAll(ice.LOG_TRACEID, ".", "-"), m.Option(ice.LOG_TRACEID))
|
||||
defer func() { Render(m, m.Option(ice.MSG_OUTPUT), kit.List(m.Optionv(ice.MSG_ARGS))...) }()
|
||||
if cmds, ok := _serve_auth(m, key, kit.Simple(m.Optionv(ice.MSG_CMDS)), w, r); ok {
|
||||
m.Option(ice.MSG_COST, "")
|
||||
defer func() {
|
||||
kit.If(m.Option(ice.MSG_STATUS) == "", func() { m.StatusTimeCount() })
|
||||
m.Cost(kit.Format("%s: %s %v", r.Method, r.URL.String(), m.FormatSize())).Options(ice.MSG_COST, m.FormatCost())
|
||||
}()
|
||||
defer func() { m.Cost(kit.Format("%s: %s %v", r.Method, m.PrefixPath()+path.Join(cmds...), m.FormatSize())) }()
|
||||
m.Option(ice.MSG_OPTS, kit.Simple(m.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) }))
|
||||
if m.Detailv(m.ShortKey(), cmds); len(cmds) > 1 && cmds[0] == ctx.ACTION && cmds[1] != ctx.ACTION {
|
||||
if !kit.IsIn(cmds[1], aaa.LOGIN, ctx.RUN, ctx.COMMAND) && m.WarnNotAllow(r.Method == http.MethodGet) {
|
||||
return
|
||||
}
|
||||
if m.Detailv(m.PrefixKey(), cmds); len(cmds) > 1 && cmds[0] == ctx.ACTION {
|
||||
m.ActionHand(cmd, key, cmds[1], cmds[2:]...)
|
||||
} else {
|
||||
m.CmdHand(cmd, key, cmds...)
|
||||
}
|
||||
func() {
|
||||
defer InfoLock.Lock()()
|
||||
Info.Commands[kit.Select(kit.Select("", cmds, 0), m.Option(ice.MSG_INDEX))]++
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
Info.ServeGetCount++
|
||||
case http.MethodPut:
|
||||
Info.ServePutCount++
|
||||
case http.MethodPost:
|
||||
Info.ServePostCount++
|
||||
case http.MethodDelete:
|
||||
Info.ServeDeleteCount++
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
func _serve_domain(m *ice.Message) string {
|
||||
return kit.GetValid(
|
||||
func() string { return kit.Select("", m.R.Header.Get(html.Referer), m.R.Method == http.MethodPost) },
|
||||
func() string { return m.R.Header.Get(html.XHost) },
|
||||
func() string { return kit.Select("", m.R.Header.Get(Referer), m.R.Method == http.MethodPost) },
|
||||
func() string { return m.R.Header.Get("X-Host") },
|
||||
func() string { return ice.Info.Domain },
|
||||
func() string {
|
||||
if b, e := regexp.MatchString("^[0-9.]+$", m.R.Host); b && e == nil {
|
||||
@ -248,189 +116,84 @@ func _serve_domain(m *ice.Message) string {
|
||||
)
|
||||
}
|
||||
func _serve_auth(m *ice.Message, key string, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
|
||||
kit.If(len(cmds) > 0, func() { cmds = append(kit.Split(cmds[0], ","), cmds[1:]...) })
|
||||
kit.If(!aaa.IsTechOrRoot(m), func() { m.Option("user_uid", "") })
|
||||
if r.URL.Path == PP(SPACE) {
|
||||
aaa.SessCheck(m, m.Option(ice.MSG_SESSID))
|
||||
return cmds, true
|
||||
}
|
||||
defer func() { m.Options(ice.MSG_CMDS, "") }()
|
||||
if strings.Contains(m.Option(ice.MSG_SESSID), " ") {
|
||||
m.Cmdy(kit.Split(m.Option(ice.MSG_SESSID)))
|
||||
} else if aaa.SessCheck(m, m.Option(ice.MSG_SESSID)); m.Option(ice.MSG_USERNAME) == "" {
|
||||
if ls := kit.Simple(mdb.Cache(m, m.Option(ice.MSG_USERIP), func() ice.Any {
|
||||
if !IsLocalHost(m) {
|
||||
return nil
|
||||
}
|
||||
aaa.UserRoot(m)
|
||||
return kit.Simple(m.Time(), m.OptionSplit(ice.MSG_USERNICK, ice.MSG_USERNAME, ice.MSG_USERROLE))
|
||||
})); len(ls) > 0 {
|
||||
aaa.SessAuth(m, kit.Dict(aaa.USERNICK, ls[1], aaa.USERNAME, ls[2], aaa.USERROLE, ls[3]), CACHE, ls[0])
|
||||
defer func() { m.Options(ice.MSG_CMDS, "", ice.MSG_SESSID, "") }()
|
||||
if aaa.SessCheck(m, m.Option(ice.MSG_SESSID)); m.Option(SHARE) != "" {
|
||||
switch msg := m.Cmd(SHARE, m.Option(SHARE)); msg.Append(mdb.TYPE) {
|
||||
case FIELD, STORM:
|
||||
msg.Table(func(value ice.Maps) { aaa.SessAuth(m, value) })
|
||||
}
|
||||
}
|
||||
if m.Option(ice.MSG_USERNAME) == "" && ice.Info.Localhost {
|
||||
ls := kit.Simple(mdb.Cache(m, m.Option(ice.MSG_USERIP), func() ice.Any {
|
||||
if tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
|
||||
aaa.UserRoot(m)
|
||||
return kit.Simple(m.Time(), m.OptionSplit(ice.MSG_USERNICK, ice.MSG_USERNAME, ice.MSG_USERROLE))
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
if len(ls) > 0 {
|
||||
m.Auth(aaa.USERNICK, m.Option(ice.MSG_USERNICK, ls[1]), aaa.USERNAME, m.Option(ice.MSG_USERNAME, ls[2]), aaa.USERROLE, m.Option(ice.MSG_USERROLE, ls[3]), CACHE, ls[0])
|
||||
}
|
||||
}
|
||||
Count(m, aaa.IP, m.Option(ice.MSG_USERIP), m.Option(ice.MSG_USERUA))
|
||||
return cmds, aaa.Right(m, key, cmds)
|
||||
}
|
||||
|
||||
const (
|
||||
SSO = "sso"
|
||||
URL = "url"
|
||||
SERVE_START = "serve.start"
|
||||
|
||||
HTTP = "http"
|
||||
HTTPS = "https"
|
||||
DOMAIN = "domain"
|
||||
ORIGIN = "origin"
|
||||
FORM = "form"
|
||||
BODY = "body"
|
||||
HOME = "home"
|
||||
|
||||
SERVE_START = "serve.start"
|
||||
PROXY_CONF = "proxyConf"
|
||||
PROXY_PATH = "usr/local/daemon/10000/"
|
||||
PROXY_CMDS = "./sbin/nginx"
|
||||
ApplicationJSON = "application/json"
|
||||
ApplicationOctet = "application/octet-stream"
|
||||
)
|
||||
const SERVE = "serve"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{P(ice.EXIT): {Hand: func(m *ice.Message, arg ...string) { m.Cmd(ice.EXIT) }},
|
||||
SERVE: {Name: "serve port auto main host system", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.MAIN: {Name: "main index space", Help: "首页", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(ctx.INDEX) == "" {
|
||||
mdb.Config(m, ice.MAIN, "")
|
||||
} else if m.Option(SPACE) == "" {
|
||||
mdb.Config(m, ice.MAIN, C(m.Option(ctx.INDEX)))
|
||||
} else {
|
||||
mdb.Config(m, ice.MAIN, S(m.Option(SPACE))+C(m.Option(ctx.INDEX)))
|
||||
}
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SERVE: {Name: "serve name auto start", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) { cli.NodeInfo(m, ice.Info.Pathname, WORKER) }},
|
||||
DOMAIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(len(arg) > 0, func() { ice.Info.Domain, ice.Info.Localhost = arg[0], false })
|
||||
m.Echo(ice.Info.Domain)
|
||||
}},
|
||||
mdb.ICONS: {Hand: func(m *ice.Message, arg ...string) { mdb.Config(m, mdb.ICONS, arg[0]) }},
|
||||
tcp.HOST: {Help: "公网", Hand: func(m *ice.Message, arg ...string) { m.Echo(kit.Formats(PublicIP(m))) }},
|
||||
cli.SYSTEM: {Help: "系统", Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, "System Settings.app") }},
|
||||
cli.START: {Name: "start dev proto host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) {
|
||||
if runtime.GOOS == cli.LINUX {
|
||||
m.Cmd(nfs.SAVE, nfs.ETC_LOCAL_SH, m.Spawn(ice.Maps{cli.PWD: kit.Path(""), aaa.USER: kit.UserName(), ctx.ARGS: kit.JoinCmds(arg...)}).Template("local.sh")+lex.NL)
|
||||
m.GoSleep("3s", func() { m.Cmd("", PROXY_CONF, kit.Select(ice.Info.NodeName, m.Option("nodename"))) })
|
||||
} else if runtime.GOOS == cli.WINDOWS {
|
||||
m.Cmd(cli.SYSTEM, cli.ECHO, "-ne", kit.Format("\033]0;%s %s serve start %s\007",
|
||||
path.Base(kit.Path("")), strings.TrimPrefix(kit.Path(os.Args[0]), kit.Path("")+nfs.PS), kit.JoinCmdArgs(arg...)))
|
||||
}
|
||||
_serve_start(m)
|
||||
}},
|
||||
SERVE_START: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(ice.DEMO) == ice.TRUE, func() { m.Cmd(CHAT_HEADER, ice.DEMO) })
|
||||
kit.If(os.Getenv(cli.TERM), func() { m.Go(func() { ssh.PrintQRCode(m, tcp.PublishLocalhost(m, _serve_address(m))) }) })
|
||||
m.Cmd(SPIDE, mdb.CREATE, HostPort(m, tcp.LOCALHOST, m.Option(tcp.PORT)), ice.OPS, ice.SRC_MAIN_ICO, nfs.REPOS, "")
|
||||
m.Cmds(SPIDE).Table(func(value ice.Maps) {
|
||||
kit.If(value[CLIENT_NAME] != ice.OPS && value[TOKEN] != "", func() {
|
||||
m.Cmd(SPACE, tcp.DIAL, ice.DEV, value[CLIENT_NAME], TOKEN, value[TOKEN], mdb.TYPE, SERVER)
|
||||
})
|
||||
m.Go(func() {
|
||||
ssh.PrintQRCode(m, tcp.PublishLocalhost(m, _serve_address(m)))
|
||||
return
|
||||
opened := false
|
||||
for i := 0; i < 3 && !opened; i++ {
|
||||
m.Sleep("1s").Cmd(SPACE, func(value ice.Maps) { kit.If(value[mdb.TYPE] == CHROME, func() { opened = true }) })
|
||||
}
|
||||
kit.If(!opened, func() { cli.Opens(m, _serve_address(m)) })
|
||||
})
|
||||
Count(m, m.ActionKey(), m.Option(tcp.PORT))
|
||||
if cb, ok := m.Optionv(SERVE_START).(func()); ok {
|
||||
cb()
|
||||
}
|
||||
ice.Info.Important = ice.HasVar()
|
||||
}},
|
||||
PROXY_CONF: {Name: "proxyConf name* port host path", Hand: func(m *ice.Message, arg ...string) {
|
||||
if dir := m.OptionDefault(nfs.PATH, PROXY_PATH, tcp.HOST, "127.0.0.1", tcp.PORT, tcp.PORT_9020); nfs.Exists(m, dir) {
|
||||
for _, p := range []string{"upstream.conf"} {
|
||||
m.Cmd(nfs.SAVE, kit.Format("%s/conf/portal/%s/%s", dir, m.Option(mdb.NAME), p), m.Template(p)+lex.NL)
|
||||
}
|
||||
for _, p := range []string{"server.conf", "location.conf"} {
|
||||
m.Cmd(nfs.DEFS, kit.Format("%s/conf/portal/%s/%s", dir, m.Option(mdb.NAME), p), m.Template(p)+lex.NL)
|
||||
}
|
||||
m.Cmd(cli.SYSTEM, cli.SUDO, kit.Path(dir, "sbin/nginx"), "-p", kit.Path(dir), "-s", "reload")
|
||||
}
|
||||
}},
|
||||
}, gdb.EventsAction(SERVE_START), mdb.HashAction(
|
||||
mdb.SHORT, tcp.PORT, mdb.FIELD, "time,status,port,host,proto"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Action().StatusTimeCount(kit.Dict(ice.MAIN, mdb.Config(m, ice.MAIN)))
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,proto,host,port"), mdb.ClearOnExitHashAction())},
|
||||
})
|
||||
ice.AddMergeAction(func(c *ice.Context, key string, cmd *ice.Command, sub string, action *ice.Action) {
|
||||
if strings.HasPrefix(sub, nfs.PS) {
|
||||
actions := ice.Actions{}
|
||||
for k, v := range cmd.Actions {
|
||||
kit.If(!kit.IsIn(k, ice.CTX_INIT, ice.CTX_EXIT), func() { actions[k] = v })
|
||||
}
|
||||
kit.If(action.Hand == nil, func() { action.Hand = cmd.Hand })
|
||||
sub = kit.Select(P(key, sub), PP(key, sub), strings.HasSuffix(sub, nfs.PS))
|
||||
c.Commands[sub] = &ice.Command{Name: kit.Select(cmd.Name, action.Name), Actions: actions, Hand: func(m *ice.Message, arg ...string) {
|
||||
c.Commands[sub] = &ice.Command{Name: kit.Select(cmd.Name, action.Name), Actions: ctx.CmdAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Spawn(c, key, cmd)
|
||||
defer m.Copy(msg)
|
||||
action.Hand(msg, arg...)
|
||||
m.Copy(msg)
|
||||
}, RawHand: action.Hand}
|
||||
}}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func ServeCmdAction() ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
nfs.PS: {Hand: func(m *ice.Message, arg ...string) { RenderCmd(m, "", arg) }},
|
||||
})
|
||||
}
|
||||
func IsLocalHost(m *ice.Message) bool {
|
||||
return (m.R == nil || m.R.Header.Get(html.XForwardedFor) == "") && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP))
|
||||
}
|
||||
func ParseURL(m *ice.Message, p string) []string {
|
||||
if u, e := url.Parse(p); e == nil {
|
||||
arg := strings.Split(strings.TrimPrefix(u.Path, nfs.PS), nfs.PS)
|
||||
for i := 0; i < len(arg); i += 2 {
|
||||
switch arg[i] {
|
||||
case "s":
|
||||
m.Option(ice.POD, kit.Select("", arg, i+1))
|
||||
case "c":
|
||||
m.Option(ice.CMD, kit.Select("", arg, i+1))
|
||||
}
|
||||
}
|
||||
kit.For(u.Query(), func(k string, v []string) { m.Optionv(k, v) })
|
||||
return kit.Split(u.Fragment, ":")
|
||||
}
|
||||
return []string{}
|
||||
}
|
||||
func ParseUA(m *ice.Message) (res []string) {
|
||||
res = append(res, aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
res = append(res, aaa.USERNAME, m.Option(ice.MSG_USERNAME))
|
||||
res = append(res, aaa.USERNICK, m.Option(ice.MSG_USERNICK))
|
||||
res = append(res, aaa.AVATAR, m.Option(ice.MSG_AVATAR))
|
||||
res = append(res, cli.DAEMON, m.Option(ice.MSG_DAEMON))
|
||||
for _, p := range html.AgentList {
|
||||
if strings.Contains(m.Option(ice.MSG_USERUA), p) {
|
||||
res = append(res, mdb.ICONS, kit.Select(agentIcons[p], m.Option(mdb.ICONS)), AGENT, p)
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, p := range html.SystemList {
|
||||
if strings.Contains(m.Option(ice.MSG_USERUA), p) {
|
||||
res = append(res, cli.SYSTEM, p)
|
||||
break
|
||||
}
|
||||
}
|
||||
return append(res, aaa.IP, m.Option(ice.MSG_USERIP), aaa.UA, m.Option(ice.MSG_USERUA))
|
||||
}
|
||||
func ProxyDomain(m *ice.Message, name string) (domain string) {
|
||||
p := path.Join(PROXY_PATH, "conf/portal", name, "server.conf")
|
||||
if !nfs.Exists(m, p) {
|
||||
domain := UserWeb(m).Hostname()
|
||||
if domain == "localhost" {
|
||||
return ""
|
||||
}
|
||||
if p = path.Join(PROXY_PATH, "conf/server", kit.Keys(name, kit.Slice(kit.Split(UserWeb(m).Hostname(), "."), -2))) + ".conf"; !nfs.Exists(m, p) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
m.Cmd(nfs.CAT, p, func(ls []string) { kit.If(ls[0] == "server_name", func() { domain = ls[1] }) })
|
||||
return kit.Select("", "https://"+domain, domain != "")
|
||||
}
|
||||
func Domain(host, port string) string { return kit.Format("%s://%s:%s", HTTP, host, port) }
|
||||
func Script(m *ice.Message, str string, arg ...ice.Any) string {
|
||||
return ice.Render(m, ice.RENDER_SCRIPT, kit.Format(str, arg...))
|
||||
}
|
||||
func ChatCmdPath(m *ice.Message, arg ...string) string {
|
||||
return m.MergePodCmd("", kit.Select(m.ShortKey(), path.Join(arg...)))
|
||||
}
|
||||
func RequireFile(m *ice.Message, file string) string {
|
||||
if strings.HasPrefix(file, nfs.PS) || strings.HasPrefix(file, ice.HTTP) || strings.Contains(file, "://") {
|
||||
return file
|
||||
} else if file != "" {
|
||||
return nfs.P + file
|
||||
}
|
||||
return ""
|
||||
}
|
||||
func ChatCmdPath(arg ...string) string { return path.Join("/chat/cmd/", path.Join(arg...)) }
|
||||
|
@ -1,12 +1,14 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -18,40 +20,35 @@ import (
|
||||
|
||||
func _share_link(m *ice.Message, p string, arg ...ice.Any) string {
|
||||
if strings.HasPrefix(p, ice.USR_PUBLISH) {
|
||||
return kit.MergeURL2(UserHost(m), strings.TrimPrefix(p, ice.USR), arg...)
|
||||
return tcp.PublishLocalhost(m, MergeLink(m, strings.TrimPrefix(p, ice.USR), arg...))
|
||||
}
|
||||
return kit.MergeURL2(UserHost(m), kit.Select("", PP(SHARE, LOCAL), !strings.HasPrefix(p, nfs.PS) && !strings.HasPrefix(p, HTTP))+p, arg...)
|
||||
return tcp.PublishLocalhost(m, MergeLink(m, kit.Select("", PP(SHARE, LOCAL), !strings.HasPrefix(p, nfs.PS) && !strings.HasPrefix(p, HTTP))+p, arg...))
|
||||
}
|
||||
func _share_cache(m *ice.Message, arg ...string) {
|
||||
if m.Cmdy(CACHE, arg[0]); m.Length() == 0 {
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
msg := m.Options(ice.POD, "", ice.MSG_USERROLE, aaa.TECH).Cmd(SPACE, pod, CACHE, arg[0])
|
||||
kit.If(kit.Format(msg.Append(nfs.FILE)), func() {
|
||||
m.RenderDownload(path.Join(ice.USR_LOCAL_WORK, pod, msg.Append(nfs.FILE)))
|
||||
}, func() {
|
||||
m.RenderResult(msg.Append(mdb.TEXT))
|
||||
})
|
||||
if pod := m.Option(ice.POD); ctx.PodCmd(m, CACHE, arg[0]) {
|
||||
if m.Append(nfs.FILE) == "" {
|
||||
m.RenderResult(m.Append(mdb.TEXT))
|
||||
} else {
|
||||
ShareLocalFile(m.Options(ice.POD, pod), m.Append(nfs.FILE))
|
||||
}
|
||||
} else if m.Append(nfs.FILE) != "" {
|
||||
m.RenderDownload(m.Append(nfs.FILE), m.Append(mdb.TYPE), m.Append(mdb.NAME))
|
||||
} else {
|
||||
m.RenderResult(m.Append(mdb.TEXT))
|
||||
if m.Cmdy(CACHE, arg[0]); m.Append(nfs.FILE) == "" {
|
||||
m.RenderResult(m.Append(mdb.TEXT))
|
||||
} else {
|
||||
m.RenderDownload(m.Append(nfs.FILE), m.Append(mdb.TYPE), m.Append(mdb.NAME))
|
||||
}
|
||||
}
|
||||
}
|
||||
func _share_proxy(m *ice.Message) {
|
||||
if m.WarnNotValid(m.Option(SHARE) == "") {
|
||||
return
|
||||
switch p := path.Join(ice.VAR_PROXY, m.Option(ice.POD), m.Option(nfs.PATH)); m.R.Method {
|
||||
case http.MethodGet:
|
||||
m.RenderDownload(p, m.Option(mdb.TYPE), m.Option(mdb.NAME))
|
||||
case http.MethodPost:
|
||||
if _, _, e := m.R.FormFile(UPLOAD); e == nil {
|
||||
m.Cmdy(CACHE, UPLOAD).Cmdy(CACHE, WATCH, m.Option(mdb.HASH), p)
|
||||
}
|
||||
m.RenderResult(m.Option(nfs.PATH))
|
||||
}
|
||||
msg := m.Cmd(SHARE, m.Option(SHARE))
|
||||
defer m.Cmd(SHARE, mdb.REMOVE, mdb.HASH, m.Option(SHARE))
|
||||
if m.WarnNotValid(msg.Append(mdb.TEXT) == "") {
|
||||
return
|
||||
}
|
||||
p := path.Join(ice.VAR_PROXY, msg.Append(mdb.TEXT), msg.Append(mdb.NAME))
|
||||
if _, _, e := m.R.FormFile(UPLOAD); e == nil {
|
||||
m.Cmdy(CACHE, UPLOAD).Cmdy(CACHE, WATCH, m.Option(mdb.HASH), p)
|
||||
}
|
||||
m.RenderResult(m.Option(nfs.PATH))
|
||||
}
|
||||
|
||||
const (
|
||||
@ -60,43 +57,26 @@ const (
|
||||
STORM = "storm"
|
||||
FIELD = "field"
|
||||
|
||||
PROXY = "proxy"
|
||||
LOCAL = "local"
|
||||
PROXY = "proxy"
|
||||
TOAST = "toast"
|
||||
|
||||
SHARE_CACHE = "/share/cache/"
|
||||
SHARE_LOCAL = "/share/local/"
|
||||
)
|
||||
const SHARE = "share"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
SHARE: {Name: "share hash auto login", Help: "共享链", Icon: "Freeform.png", Role: aaa.VOID, Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create type name text space", Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(mdb.TYPE) == LOGIN && m.Option(mdb.TEXT) == "", func() { arg = append(arg, mdb.TEXT, tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB))) })
|
||||
mdb.HashCreate(m, m.OptionSimple("type,name,text,space"), arg, aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
m.Option(mdb.LINK, tcp.PublishLocalhost(m, m.MergeLink(P(SHARE, m.Result()))))
|
||||
Count(m, "", m.Option(mdb.TYPE))
|
||||
SHARE: {Name: "share hash auto login prunes", Help: "共享链", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashCreate(m, arg, m.OptionSimple(ice.CMD), aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
m.Option(mdb.LINK, _share_link(m, P(SHARE, m.Result())))
|
||||
}},
|
||||
LOGIN: {Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
LOGIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoQRCode(m.Cmd(SHARE, mdb.CREATE, mdb.TYPE, LOGIN).Option(mdb.LINK)).ProcessInner()
|
||||
}},
|
||||
OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.ProcessOpen(m.MergeLink(P(SHARE, m.Option(mdb.HASH))))
|
||||
}},
|
||||
ctx.COMMAND: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if msg := mdb.HashSelects(m.Spawn(), m.Option(SHARE)); !IsNotValidFieldShare(m, msg) {
|
||||
m.Cmdy(Space(m, msg.Append(SPACE)), ctx.COMMAND, msg.Append(mdb.NAME), kit.Dict(ice.MSG_USERPOD, msg.Append(SPACE)))
|
||||
}
|
||||
}},
|
||||
ctx.RUN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if msg := mdb.HashSelects(m.Spawn(), m.Option(SHARE)); !IsNotValidFieldShare(m, msg) {
|
||||
aaa.SessAuth(m, kit.Dict(msg.AppendSimple(aaa.USERNICK, aaa.USERNAME, aaa.USERROLE)))
|
||||
// m.Cmdy(Space(m, msg.Append(SPACE)), msg.Append(mdb.NAME), kit.UnMarshal(msg.Append(mdb.TEXT)), arg[1:], kit.Dict(ice.MSG_USERPOD, msg.Append(SPACE)))
|
||||
m.Cmdy(Space(m, msg.Append(SPACE)), msg.Append(mdb.NAME), arg[1:], kit.Dict(ice.MSG_USERPOD, msg.Append(SPACE)))
|
||||
}
|
||||
}},
|
||||
nfs.PS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.WarnNotValid(len(arg) == 0 || arg[0] == "", SHARE) {
|
||||
if m.Warn(len(arg) == 0 || arg[0] == "", ice.ErrNotValid, SHARE) {
|
||||
return
|
||||
}
|
||||
msg := m.Cmd(SHARE, m.Option(SHARE, arg[0]))
|
||||
@ -106,130 +86,66 @@ func init() {
|
||||
}
|
||||
switch msg.Append(mdb.TYPE) {
|
||||
case LOGIN:
|
||||
u := kit.ParseURL(m.Option(ice.MSG_USERHOST))
|
||||
m.RenderRedirect(kit.MergeURL(msg.Append(mdb.TEXT), ice.MSG_SESSID, aaa.SessCreate(m, msg.Append(aaa.USERNAME))))
|
||||
break
|
||||
if u.Scheme == ice.HTTP {
|
||||
m.RenderRedirect(kit.MergeURL(msg.Append(mdb.TEXT), ice.MSG_SESSID, aaa.SessCreate(m, msg.Append(aaa.USERNAME))))
|
||||
if msg.Append(ice.CMD) != "" {
|
||||
m.RenderRedirect(m.MergePodCmd("", msg.Append(ice.CMD)), ice.MSG_SESSID, aaa.SessCreate(m, msg.Append(aaa.USERNAME)))
|
||||
} else {
|
||||
RenderCookie(m, aaa.SessCreate(m, msg.Append(aaa.USERNAME)))
|
||||
m.RenderRedirect(msg.Append(mdb.TEXT))
|
||||
m.RenderRedirect(nfs.PS, ice.MSG_SESSID, aaa.SessCreate(m, msg.Append(aaa.USERNAME)))
|
||||
}
|
||||
case STORM:
|
||||
RenderCookie(m, aaa.SessCreate(m, msg.Append(aaa.USERNAME)))
|
||||
m.RenderRedirect(m.MergeLink(kit.Select(nfs.PS, msg.Append(mdb.TEXT)), msg.AppendSimple(RIVER, STORM)))
|
||||
case FIELD:
|
||||
if msg.Append(mdb.NAME) == "web.chat.grant" {
|
||||
RenderPodCmd(m, "", msg.Append(mdb.NAME), kit.UnMarshal(msg.Append(mdb.TEXT)))
|
||||
} else {
|
||||
RenderPodCmd(m, msg.Append(SPACE), msg.Append(mdb.NAME), kit.UnMarshal(msg.Append(mdb.TEXT)))
|
||||
}
|
||||
case DOWNLOAD:
|
||||
m.RenderDownload(msg.Append(mdb.TEXT))
|
||||
default:
|
||||
RenderMain(m)
|
||||
if msg.Append(ice.CMD) != "" {
|
||||
RenderCmd(m, msg.Append(ice.CMD))
|
||||
} else {
|
||||
RenderMain(m)
|
||||
}
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,space,usernick,username,userrole", mdb.EXPIRE, mdb.DAYS)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if aaa.IsTechOrRoot(m) || len(arg) > 0 && arg[0] != "" {
|
||||
mdb.HashSelect(m, arg...).PushAction(OPEN, mdb.REMOVE)
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,river,storm,usernick,username,userrole", mdb.EXPIRE, mdb.DAYS), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if ctx.PodCmd(m, SHARE, arg) {
|
||||
return
|
||||
}
|
||||
if mdb.HashSelect(m, arg...); len(arg) > 0 {
|
||||
link := _share_link(m, P(SHARE, arg[0]))
|
||||
m.PushQRCode(cli.QRCODE, link)
|
||||
m.PushScript(nfs.SCRIPT, link)
|
||||
m.PushAnchor(link)
|
||||
}
|
||||
}},
|
||||
PP(SHARE, PROXY): {Hand: func(m *ice.Message, arg ...string) { _share_proxy(m) }},
|
||||
PP(SHARE, CACHE): {Hand: func(m *ice.Message, arg ...string) { _share_cache(m, arg...) }},
|
||||
PP(SHARE, LOCAL): {Hand: func(m *ice.Message, arg ...string) { ShareLocalFile(m, arg...) }},
|
||||
PP(SHARE, PROXY): {Hand: func(m *ice.Message, arg ...string) { _share_proxy(m) }},
|
||||
PP(SHARE, TOAST): {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Options(ice.LOG_DISABLE, ice.TRUE).Cmdy(SPACE, arg[0], kit.UnMarshal(m.Option(ice.ARG)))
|
||||
}},
|
||||
})
|
||||
}
|
||||
func IsNotValidShare(m *ice.Message, time string) bool {
|
||||
return m.WarnNotValid(time < m.Time(), ice.ErrNotValid, m.Option(SHARE), time, m.Time(), logs.FileLineMeta(2))
|
||||
}
|
||||
func IsNotValidFieldShare(m *ice.Message, msg *ice.Message) bool {
|
||||
if m.Warn(IsNotValidShare(m, msg.Append(mdb.TIME)), kit.Format("共享超时, 请联系 %s(%s), 重新分享 %s %s %s", msg.Append(aaa.USERNICK), msg.Append(aaa.USERNAME), msg.Append(mdb.TYPE), msg.Append(mdb.NAME), msg.Append(mdb.TEXT))) {
|
||||
return true
|
||||
}
|
||||
if m.WarnNotValid(msg.Append(mdb.NAME) == "") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
func SharePath(m *ice.Message, p string) string {
|
||||
kit.If(!kit.HasPrefix(p, nfs.PS, ice.HTTP), func() {
|
||||
if kit.HasPrefix(p, nfs.SRC, nfs.USR) && !kit.HasPrefix(p, nfs.USR_LOCAL) {
|
||||
p = m.MergeLink(path.Join(nfs.P, p), ice.POD, m.Option(ice.MSG_USERPOD))
|
||||
} else {
|
||||
p = m.MergeLink(path.Join(SHARE_LOCAL, p), ice.POD, m.Option(ice.MSG_USERPOD))
|
||||
}
|
||||
})
|
||||
return p
|
||||
return m.Warn(time < m.Time(), ice.ErrNotValid, m.Option(SHARE), time, m.Time(), logs.FileLineMeta(2))
|
||||
}
|
||||
func ShareLocalFile(m *ice.Message, arg ...string) {
|
||||
p := path.Join(arg...)
|
||||
switch ls := strings.Split(p, nfs.PS); ls[0] {
|
||||
case ice.ETC, ice.VAR:
|
||||
if m.WarnNotRight(m.Option(ice.MSG_USERROLE) == aaa.VOID, p) {
|
||||
if m.Warn(m.Option(ice.MSG_USERROLE) == aaa.VOID, ice.ErrNotRight, p) {
|
||||
return
|
||||
}
|
||||
default:
|
||||
if m.Option(ice.MSG_USERNAME) != "" && strings.HasPrefix(p, nfs.USR_LOCAL_IMAGE+m.Option(ice.MSG_USERNAME)) {
|
||||
|
||||
} else if m.Option(ice.POD) == "" && !aaa.Right(m, ls) {
|
||||
return
|
||||
} else {
|
||||
if m.Option(ice.POD) != "" && !strings.Contains(p, "/src/") && !strings.HasPrefix(p, "src/") {
|
||||
if strings.HasPrefix(p, "usr/local/storage/") {
|
||||
if m.Cmd(SPACE, "20240903-operation", "web.team.storage.file", aaa.RIGHT, ls[3:]).IsErr() {
|
||||
return
|
||||
}
|
||||
} else if m.WarnNotRight(m.Cmdx(SPACE, m.Option(ice.POD), aaa.ROLE, aaa.RIGHT, aaa.VOID, p) != ice.OK) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.Option(ice.POD) != "" && nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, m.Option(ice.POD))) {
|
||||
if pp := kit.Path(ice.USR_LOCAL_WORK, m.Option(ice.POD), p); nfs.Exists(m, pp) {
|
||||
m.RenderDownload(pp)
|
||||
return
|
||||
} else if nfs.Exists(m, p) {
|
||||
m.RenderDownload(p)
|
||||
if m.Option(ice.POD) == "" && !aaa.Right(m, ls) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if m.Option(ice.POD) == "" || (kit.HasPrefix(p, ice.USR_ICONS, ice.USR_VOLCANOS, ice.USR_ICEBERGS, ice.USR_INTSHELL) && nfs.Exists(m, p)) {
|
||||
if m.Option(ice.POD) == "" {
|
||||
m.RenderDownload(p)
|
||||
} else if pp := kit.Path(ice.USR_LOCAL_WORK, m.Option(ice.POD), p); nfs.Exists(m, pp) {
|
||||
m.RenderDownload(pp)
|
||||
} else if pp := ProxyUpload(m, m.Option(ice.POD), p); nfs.Exists(m, pp) {
|
||||
m.RenderDownload(pp)
|
||||
} else {
|
||||
return
|
||||
} else if p := kit.Path(ice.USR_LOCAL_WORK, m.Option(ice.POD), p); nfs.Exists(m, p) {
|
||||
m.RenderDownload(p)
|
||||
return
|
||||
}
|
||||
}
|
||||
func ShareLocal(m *ice.Message, p string) string {
|
||||
if kit.HasPrefix(p, nfs.PS, HTTP) {
|
||||
return p
|
||||
}
|
||||
return m.MergeLink(PP(SHARE, LOCAL, p))
|
||||
}
|
||||
func ShareField(m *ice.Message, cmd string, arg ...ice.Any) *ice.Message {
|
||||
return m.EchoQRCode(tcp.PublishLocalhost(m, m.MergeLink(P(SHARE, AdminCmd(m, SHARE, mdb.CREATE, mdb.TYPE, FIELD, mdb.NAME, kit.Select(m.ShortKey(), cmd), mdb.TEXT, kit.Format(kit.Simple(arg...)), SPACE, m.Option(ice.MSG_USERPOD)).Result()))))
|
||||
}
|
||||
func ProxyUpload(m *ice.Message, pod string, p string) string {
|
||||
pp := path.Join(ice.VAR_PROXY, pod, p)
|
||||
size, cache := int64(0), time.Now().Add(-time.Hour*24)
|
||||
pp := path.Join(ice.VAR_PROXY, m.Option(ice.POD), p)
|
||||
cache, size := time.Now().Add(-time.Hour*24), int64(0)
|
||||
if s, e := file.StatFile(pp); e == nil {
|
||||
size, cache = s.Size(), s.ModTime()
|
||||
} else if s, e := file.StatFile(p); e == nil {
|
||||
size, cache = s.Size(), s.ModTime()
|
||||
cache, size = s.ModTime(), s.Size()
|
||||
}
|
||||
if m.Cmdv(SPACE, pod, mdb.TYPE) == ORIGIN {
|
||||
m.Cmd(SPIDE, pod, SPIDE_SAVE, pp, "/p/"+p)
|
||||
} else {
|
||||
kit.If(p == ice.BIN_ICE_BIN, func() { m.Option(ice.MSG_USERROLE, aaa.TECH) })
|
||||
share := m.Cmdx(SHARE, mdb.CREATE, mdb.TYPE, PROXY, mdb.NAME, p, mdb.TEXT, pod)
|
||||
defer m.Cmd(SHARE, mdb.REMOVE, mdb.HASH, share)
|
||||
url := tcp.PublishLocalhost(m, m.MergeLink(PP(SHARE, PROXY), SHARE, share))
|
||||
m.Cmd(SPACE, pod, SPIDE, PROXY, URL, url, nfs.SIZE, size, CACHE, cache.Format(ice.MOD_TIME), UPLOAD, mdb.AT+p, kit.Dict(ice.MSG_USERROLE, aaa.TECH))
|
||||
}
|
||||
return kit.Select(p, pp, file.ExistsFile(pp))
|
||||
kit.If(p == ice.BIN_ICE_BIN, func() { m.Option(ice.MSG_USERROLE, aaa.TECH) })
|
||||
m.Cmd(SPACE, m.Option(ice.POD), SPIDE, ice.DEV, SPIDE_RAW, MergeLink(m, PP(SHARE, PROXY)), SPIDE_PART, m.OptionSimple(ice.POD), nfs.PATH, p, nfs.SIZE, size, CACHE, cache.Format(ice.MOD_TIME), UPLOAD, mdb.AT+p)
|
||||
m.RenderDownload(kit.Select(p, pp, file.ExistsFile(pp)))
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"io"
|
||||
"math/rand"
|
||||
"net"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -16,185 +13,98 @@ import (
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/log"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
"shylinux.com/x/icebergs/misc/websocket"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
"shylinux.com/x/toolkits/task"
|
||||
)
|
||||
|
||||
var Info = struct {
|
||||
ServeMainCount int
|
||||
ServeGetCount int
|
||||
ServePutCount int
|
||||
ServePostCount int
|
||||
ServeDeleteCount int
|
||||
SpaceCmdCount int
|
||||
SpaceReadCount int
|
||||
SpaceReadByte int
|
||||
SpaceWriteCount int
|
||||
SpaceWriteByte int
|
||||
Commands map[string]int
|
||||
}{
|
||||
Commands: map[string]int{},
|
||||
}
|
||||
var InfoLock = &task.Lock{}
|
||||
|
||||
func _space_qrcode(m *ice.Message, dev string) {
|
||||
ssh.PrintQRCode(m, m.Cmdv(SPACE, dev, cli.PWD, mdb.LINK))
|
||||
}
|
||||
func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
msg := m.Cmd(SPIDE, dev)
|
||||
origin := msg.Append(CLIENT_ORIGIN)
|
||||
u := kit.ParseURL(kit.MergeURL2(strings.Replace(origin, HTTP, "ws", 1), PP(SPACE), mdb.TYPE, ice.Info.NodeType, mdb.NAME, name, TOKEN, msg.Append(TOKEN), mdb.ICONS, ice.Info.NodeIcon,
|
||||
ice.MAIN, ice.Info.NodeMain, mdb.TIME, ice.Info.Make.Time, nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(), cli.GOOS, runtime.GOOS, cli.GOARCH, runtime.GOARCH, arg))
|
||||
args := kit.SimpleKV("type,name,host,port", u.Scheme, dev, u.Hostname(), kit.Select(kit.Select(tcp.PORT_443, tcp.PORT_80, u.Scheme == "ws"), u.Port()))
|
||||
u := kit.ParseURL(kit.MergeURL2(strings.Replace(m.Cmdv(SPIDE, dev, CLIENT_ORIGIN), HTTP, "ws", 1), PP(SPACE), mdb.TYPE, ice.Info.NodeType, mdb.NAME, name, arg))
|
||||
args := kit.SimpleKV("type,name,host,port", u.Scheme, dev, u.Hostname(), u.Port())
|
||||
gdb.Go(m, func() {
|
||||
once := sync.Once{}
|
||||
redial := kit.Dict(mdb.Configv(m, REDIAL))
|
||||
a, b, _c := kit.Int(redial["a"]), kit.Int(redial["b"]), kit.Int(redial["c"])
|
||||
for i := 1; i < _c; i++ {
|
||||
next := time.Duration(rand.Intn(a*i*i)+b*(i+1)) * time.Millisecond
|
||||
a, b, c := kit.Int(redial["a"]), kit.Int(redial["b"]), kit.Int(redial["c"])
|
||||
for i := 1; i < c; i++ {
|
||||
next := time.Duration(rand.Intn(a*(i+1))+b*i) * time.Millisecond
|
||||
m.Cmd(tcp.CLIENT, tcp.DIAL, args, func(c net.Conn) {
|
||||
if c, e := websocket.NewClient(c, u); !m.WarnNotValid(e, tcp.DIAL, dev, SPACE, u.String()) {
|
||||
mdb.HashCreate(m, kit.SimpleKV("", ORIGIN, dev, origin), kit.Dict(mdb.TARGET, c))
|
||||
defer mdb.HashRemove(m, mdb.HASH, dev)
|
||||
if c, e := websocket.NewClient(c, u); !m.Warn(e, tcp.DIAL, dev, SPACE, u.String()) {
|
||||
defer mdb.HashCreateDeferRemove(m, kit.SimpleKV("", MASTER, dev, u.Hostname()), kit.Dict(mdb.TARGET, c))()
|
||||
kit.If(ice.Info.Colors, func() { once.Do(func() { m.Go(func() { _space_qrcode(m, dev) }) }) })
|
||||
_space_handle(m.Spawn(), true, dev, c)
|
||||
i = 0
|
||||
}
|
||||
}).Cost(mdb.COUNT, i, mdb.NEXT, next, tcp.DIAL, dev, LINK, u.String()).Sleep(next)
|
||||
if mdb.HashSelect(m.Spawn(), name).Append(mdb.STATUS) == cli.STOP {
|
||||
break
|
||||
}
|
||||
}
|
||||
}, kit.JoinWord(SPACE, dev))
|
||||
}, kit.Join(kit.Simple(SPACE, name), lex.SP))
|
||||
}
|
||||
func _space_fork(m *ice.Message) {
|
||||
addr := kit.Select(m.R.RemoteAddr, m.R.Header.Get(ice.MSG_USERADDR))
|
||||
text := strings.ReplaceAll(kit.Select(addr, m.Option(mdb.TEXT)), "%2F", nfs.PS)
|
||||
name := SpaceName(kit.Select(addr, m.Option(mdb.NAME)))
|
||||
if m.OptionDefault(mdb.TYPE, SERVER) == WORKER && (!nfs.Exists(m, path.Join(ice.USR_LOCAL_WORK, name)) || !tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP))) {
|
||||
m.Option(mdb.TYPE, SERVER)
|
||||
name := kit.ReplaceAll(kit.Select(addr, m.Option(mdb.NAME)), "[", "_", "]", "_", nfs.DF, "_", nfs.PT, "_")
|
||||
text := kit.Select(addr, m.Option(mdb.TEXT))
|
||||
if kit.IsIn(m.Option(mdb.TYPE), CHROME) || !(ice.Info.Localhost && tcp.IsLocalHost(m, m.R.RemoteAddr) ||
|
||||
m.Option(TOKEN) != "" && m.Cmdv(TOKEN, m.Option(TOKEN), mdb.TIME) > m.Time()) {
|
||||
name = kit.ReplaceAll(addr, "[", "_", "]", "_", nfs.DF, "_", nfs.PT, "_")
|
||||
text = kit.Select(addr, m.Option(mdb.NAME), m.Option(mdb.TEXT))
|
||||
}
|
||||
if kit.IsIn(m.Option(mdb.TYPE), PORTAL, aaa.LOGIN) && len(name) == 32 && kit.IsIn(mdb.HashSelects(m.Spawn(), name).Append(aaa.IP), "", m.Option(ice.MSG_USERIP)) {
|
||||
|
||||
} else if kit.IsIn(m.Option(mdb.TYPE), SERVER) && IsLocalHost(m) {
|
||||
|
||||
} else if kit.IsIn(m.Option(mdb.TYPE), WORKER) && IsLocalHost(m) {
|
||||
text = nfs.USR_LOCAL_WORK + name
|
||||
} else {
|
||||
name, text = kit.Hashs(name), kit.Select(addr, m.Option(mdb.TEXT))
|
||||
}
|
||||
safe := false
|
||||
if m.Option(ice.MSG_USERNAME, ""); kit.IsIn(m.Option(mdb.TYPE), WORKER, PORTAL) {
|
||||
if tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
|
||||
aaa.SessAuth(m, kit.Dict(m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME, ice.Info.Username)).AppendSimple()))
|
||||
}
|
||||
} else if m.Option(TOKEN) != "" {
|
||||
if msg := m.Cmd(TOKEN, m.Option(TOKEN)); msg.Append(mdb.TIME) > m.Time() && kit.IsIn(msg.Append(mdb.TYPE), SERVER, SPIDE) {
|
||||
aaa.SessAuth(m, kit.Dict(m.Cmd(aaa.USER, m.Option(ice.MSG_USERNAME, msg.Append(mdb.NAME))).AppendSimple()))
|
||||
name = SpaceName(kit.Select(name, msg.Append(mdb.TEXT)))
|
||||
// kit.If(ProxyDomain(m.Spawn(kit.Dict(ice.MSG_USERROLE, aaa.TECH)), name), func(p string) { text = p })
|
||||
kit.If(ProxyDomain(m, name), func(p string) { text = p })
|
||||
safe = aaa.IsTechOrRoot(m)
|
||||
}
|
||||
}
|
||||
args := kit.Simple(mdb.TYPE, m.Option(mdb.TYPE), mdb.NAME, name, mdb.TEXT, text, m.OptionSimple(mdb.ICONS, mdb.TIME, nfs.MODULE, nfs.VERSION, cli.DAEMON, "main"))
|
||||
args = append(args, aaa.USERNICK, m.Option(ice.MSG_USERNICK), aaa.USERNAME, m.Option(ice.MSG_USERNAME), aaa.USERROLE, m.Option(ice.MSG_USERROLE))
|
||||
args = append(args, cli.SYSTEM, m.Option(cli.GOOS))
|
||||
args = append(args, ParseUA(m)...)
|
||||
if c, e := websocket.Upgrade(m.W, m.R); !m.WarnNotValid(e) {
|
||||
args := kit.Simple(mdb.TYPE, kit.Select(WORKER, m.Option(mdb.TYPE)), mdb.NAME, name, mdb.TEXT, text, m.OptionSimple(cli.DAEMON, ice.MSG_USERUA))
|
||||
if c, e := websocket.Upgrade(m.W, m.R); !m.Warn(e) {
|
||||
gdb.Go(m, func() {
|
||||
defer mdb.HashCreateDeferRemove(m, args, kit.Dict(mdb.TARGET, c))()
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case LOGIN:
|
||||
if m.Option(ice.MSG_SESSID) != "" && m.Option(ice.MSG_USERNAME) != "" {
|
||||
m.Cmd(SPACE, name, ice.MSG_SESSID, m.Option(ice.MSG_SESSID))
|
||||
}
|
||||
gdb.Event(m, SPACE_LOGIN, args)
|
||||
defer gdb.Event(m, SPACE_LOGIN_CLOSE, args)
|
||||
case PORTAL:
|
||||
gdb.EventDeferEvent(m, PORTAL_OPEN, args)
|
||||
m.Go(func() { m.Cmd(SPACE, name, cli.PWD, name) })
|
||||
case SERVER:
|
||||
case WORKER:
|
||||
defer gdb.EventDeferEvent(m, DREAM_OPEN, args)(DREAM_CLOSE, args)
|
||||
safe = true
|
||||
m.Go(func() {
|
||||
SpacePwd(m, name, kit.Path(""))
|
||||
// SpaceEvent(m, OPS_DREAM_OPEN, name, args...)
|
||||
})
|
||||
case SERVER:
|
||||
defer gdb.EventDeferEvent(m, SPACE_OPEN, args)(SPACE_CLOSE, args)
|
||||
m.Go(func() {
|
||||
SpacePwd(m, name, "")
|
||||
SpaceEvent(m.Spawn(ice.MSG_USERROLE, aaa.TECH), OPS_SERVER_OPEN, name, args...)
|
||||
})
|
||||
case CHROME:
|
||||
m.Go(func() { m.Cmd(SPACE, name, cli.PWD, name) })
|
||||
case LOGIN:
|
||||
gdb.Event(m, SPACE_LOGIN, args)
|
||||
}
|
||||
_space_handle(m.Spawn(), safe, name, c)
|
||||
}, kit.JoinWord(SPACE, name))
|
||||
_space_handle(m, false, name, c)
|
||||
}, kit.Join(kit.Simple(SPACE, name), lex.SP))
|
||||
}
|
||||
}
|
||||
func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) {
|
||||
defer m.Cost(SPACE, name)
|
||||
m.Options(ice.MSG_USERROLE, "", mdb.TYPE, "", mdb.NAME, "", cli.DAEMON, "")
|
||||
for {
|
||||
_, b, e := c.ReadMessage()
|
||||
if e != nil {
|
||||
break
|
||||
}
|
||||
func() {
|
||||
defer InfoLock.Lock()()
|
||||
Info.SpaceReadCount++
|
||||
Info.SpaceReadByte += len(b)
|
||||
}()
|
||||
msg := m.Spawn(b)
|
||||
if safe && msg.Option(ice.MSG_UNSAFE) != ice.TRUE { // 下行权限
|
||||
if !aaa.IsTechOrRoot(msg) && msg.Option(ice.MSG_HANDLE) != ice.TRUE {
|
||||
msg.Option(ice.MSG_USERROLE, kit.Select(msg.Option(ice.MSG_USERROLE), aaa.UserRole(msg, msg.Option(ice.MSG_USERNAME))))
|
||||
}
|
||||
// kit.If(kit.IsIn(msg.Option(ice.MSG_USERROLE), "", aaa.VOID), func() { msg.Option(ice.MSG_USERROLE, aaa.UserRole(msg, msg.Option(ice.MSG_USERNAME))) })
|
||||
} else { // 上行权限
|
||||
msg.Option(ice.MSG_UNSAFE, ice.TRUE)
|
||||
kit.If(msg.Option(ice.MSG_USERROLE), func() { msg.Option(ice.MSG_USERROLE, aaa.VOID) })
|
||||
}
|
||||
source, target := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name), kit.Simple(msg.Optionv(ice.MSG_TARGET))
|
||||
msg.Log(kit.Select(tcp.RECV, tcp.ECHO, msg.Option(ice.MSG_HANDLE) == ice.TRUE), "%d %v->%v %v %v", len(b), source, target, msg.Detailv(), msg.FormatMeta())
|
||||
msg.Log(tcp.RECV, "%v->%v %v %v", source, target, msg.Detailv(), msg.FormatsMeta(nil))
|
||||
if next := msg.Option(ice.MSG_TARGET); next == "" || len(target) == 0 {
|
||||
msg.Go(func() {
|
||||
if k := kit.Keys(msg.Option(ice.MSG_USERPOD), "_token"); msg.Option(k) != "" {
|
||||
aaa.SessCheck(msg, msg.Option(k))
|
||||
}
|
||||
msg.Option(ice.MSG_OPTS, kit.Simple(msg.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) }))
|
||||
_space_exec(msg, name, source, target, c)
|
||||
}, strings.Join(kit.Simple(SPACE, name, msg.Detailv()), lex.SP))
|
||||
} else {
|
||||
for i := 0; i < 5; i++ {
|
||||
if !m.WarnNotFoundSpace(!mdb.HashSelectDetail(m, next, func(value ice.Map) {
|
||||
switch c := value[mdb.TARGET].(type) {
|
||||
case (*websocket.Conn): // 转发报文
|
||||
kit.If(value[mdb.TYPE] == ORIGIN && msg.Option(ice.MSG_HANDLE) == ice.FALSE, func() {
|
||||
msg.Optionv(ice.MSG_USERWEB, kit.Simple(value[mdb.TEXT], msg.Optionv(ice.MSG_USERWEB)))
|
||||
msg.Optionv(ice.MSG_USERPOD, kit.Simple(kit.Keys(target[1:]), msg.Optionv(ice.MSG_USERPOD)))
|
||||
})
|
||||
_space_echo(msg, source, target, c)
|
||||
case ice.Handler: // 接收响应
|
||||
msg.Go(func() { c(msg) })
|
||||
}
|
||||
}), SPACE, next) {
|
||||
break
|
||||
}
|
||||
if kit.HasPrefixList(msg.Detailv(), "toast") {
|
||||
break
|
||||
}
|
||||
if msg.Option("space.noecho") == "true" {
|
||||
break
|
||||
}
|
||||
m.Sleep3s()
|
||||
if safe { // 下行命令
|
||||
msg.Option(ice.MSG_USERROLE, aaa.UserRole(msg, msg.Option(ice.MSG_USERNAME)))
|
||||
} else { // 上行请求
|
||||
msg.Option(ice.MSG_USERROLE, aaa.VOID)
|
||||
}
|
||||
m.Go(func() { _space_exec(msg, source, target, c) }, strings.Join(kit.Simple(SPACE, name, msg.Detailv()), lex.SP))
|
||||
// if msg.Option("_exec") == "go" {
|
||||
// m.Go(func() { _space_exec(msg, source, target, c) }, strings.Join(kit.Simple(SPACE, name, msg.Detailv()), lex.SP))
|
||||
// } else {
|
||||
// _space_exec(msg, source, target, c)
|
||||
// }
|
||||
} else {
|
||||
done := false
|
||||
m.Warn(!mdb.HashSelectDetail(m, next, func(value ice.Map) {
|
||||
switch c := value[mdb.TARGET].(type) {
|
||||
case (*websocket.Conn): // 转发报文
|
||||
_space_echo(msg, source, target, c)
|
||||
case ice.Handler: // 接收响应
|
||||
done = true
|
||||
c(msg)
|
||||
}
|
||||
}), ice.ErrNotFound, next)
|
||||
kit.If(done, func() { mdb.HashRemove(m, mdb.HASH, next) })
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -209,383 +119,118 @@ func _space_domain(m *ice.Message) (link string) {
|
||||
return ""
|
||||
},
|
||||
func() string { return tcp.PublishLocalhost(m, m.Option(ice.MSG_USERWEB)) },
|
||||
func() string { return HostPort(m, m.Cmdv(tcp.HOST, aaa.IP), m.Cmdv(SERVE, tcp.PORT)) },
|
||||
)
|
||||
func() string { return Domain(m.Cmdv(tcp.HOST, aaa.IP), m.Cmdv(SERVE, tcp.PORT)) })
|
||||
}
|
||||
func _space_exec(m *ice.Message, name string, source, target []string, c *websocket.Conn) {
|
||||
m.Option(ice.MSG_HANDLE, ice.TRUE)
|
||||
switch kit.Select("", m.Detailv(), 0) {
|
||||
case "":
|
||||
m.Warn(true, ice.ErrNotValid)
|
||||
return
|
||||
func _space_exec(m *ice.Message, source, target []string, c *websocket.Conn) {
|
||||
switch kit.Select(cli.PWD, m.Detailv(), 0) {
|
||||
case cli.PWD:
|
||||
m.Push(mdb.LINK, m.MergePod(kit.Select("", source, -1)))
|
||||
if m.Option(cli.SYSTEM) == "" {
|
||||
m.Optionv(ice.MSG_OPTION, []string{})
|
||||
break
|
||||
}
|
||||
args := m.OptionSimple(mdb.ICONS, mdb.TIME, nfs.MODULE, nfs.VERSION, AGENT, cli.SYSTEM)
|
||||
kit.If(name == ice.OPS, func() { args = append(args, m.OptionSimple(mdb.TEXT)...) })
|
||||
mdb.HashModify(m, mdb.HASH, name, ParseUA(m), args)
|
||||
// SpaceEvent(m, OPS_ORIGIN_OPEN, name, kit.Simple(mdb.NAME, name, args)...)
|
||||
default:
|
||||
if m.IsErr() {
|
||||
return
|
||||
}
|
||||
func() {
|
||||
defer InfoLock.Lock()()
|
||||
Info.SpaceCmdCount++
|
||||
Info.Commands[kit.Select(kit.Select("", m.Detailv(), 0), m.Option(ice.MSG_INDEX))]++
|
||||
}()
|
||||
m.Options(ice.MSG_ARGS, "", ice.MSG_COUNT, "0")
|
||||
kit.If(m.Option(ice.MSG_DAEMON), func(p string) {
|
||||
m.Option(ice.MSG_DAEMON0, m.Option(ice.MSG_DAEMON))
|
||||
m.Option(ice.MSG_DAEMON, kit.Keys(kit.Slice(kit.Reverse(kit.Simple(source)), 0, -1), p))
|
||||
})
|
||||
m.Option(ice.FROM_SPACE, kit.Keys(kit.Reverse(kit.Simple(source[1:]))))
|
||||
kit.If(aaa.Right(m, m.Detailv()), func() { m.TryCatch(true, func(_ *ice.Message) { m = m.Cmd() }) })
|
||||
kit.If(m.Optionv(ice.MSG_ARGS) != nil, func() { m.Options(ice.MSG_ARGS, kit.Simple(m.Optionv(ice.MSG_ARGS))) })
|
||||
m.Option("__target", kit.Reverse(kit.Simple(source)))
|
||||
kit.If(aaa.Right(m, m.Detailv()), func() { m.TryCatch(m, true, func(_ *ice.Message) { m = m.Cmd() }) })
|
||||
}
|
||||
defer m.Cost(kit.Format("%v->%v %v %v", source, target, m.Detailv(), m.FormatSize()))
|
||||
if m.Option(ice.SPACE_NOECHO) == ice.TRUE {
|
||||
return
|
||||
}
|
||||
m.Options(ice.MSG_USERWEB, m.Optionv(ice.MSG_USERWEB), ice.MSG_USERPOD, m.Optionv(ice.MSG_USERPOD))
|
||||
_space_echo(m.Set(ice.MSG_OPTS).Options(m.OptionSimple(ice.MSG_HANDLE, ice.LOG_DEBUG, ice.LOG_DISABLE, ice.LOG_TRACEID)), []string{}, kit.Reverse(kit.Simple(source)), c)
|
||||
_space_echo(m.Set(ice.MSG_OPTS).Options(log.DEBUG, m.Option(log.DEBUG)), []string{}, kit.Reverse(kit.Simple(source)), c)
|
||||
}
|
||||
func _space_echo(m *ice.Message, source, target []string, c *websocket.Conn) {
|
||||
defer func() { m.WarnNotValid(recover()) }()
|
||||
m.Options(ice.MSG_SOURCE, source, ice.MSG_TARGET, target[1:])
|
||||
data := m.FormatMeta()
|
||||
if !m.WarnNotValid(c.WriteMessage(1, []byte(data))) {
|
||||
func() {
|
||||
defer InfoLock.Lock()()
|
||||
Info.SpaceWriteCount++
|
||||
Info.SpaceWriteByte += len(data)
|
||||
}()
|
||||
if source != nil {
|
||||
m.Log(kit.Select(tcp.SEND, tcp.DONE, m.Option(ice.MSG_HANDLE) == ice.TRUE), "%d %v->%v %v %v", len(data), source, target,
|
||||
kit.ReplaceAll(kit.Format("%v", m.Detailv()), "\r\n", "\\r\\n", "\t", "\\t", "\n", "\\n"), data)
|
||||
}
|
||||
if m.Options(ice.MSG_SOURCE, source, ice.MSG_TARGET, target[1:]); !m.Warn(c.WriteMessage(1, []byte(m.FormatMeta()))) {
|
||||
m.Log(tcp.SEND, "%v->%v %v %v", source, target, m.Detailv(), m.FormatsMeta(nil))
|
||||
}
|
||||
}
|
||||
func _space_send(m *ice.Message, name string, arg ...string) (h string) {
|
||||
withecho := m.Option(ice.SPACE_NOECHO) != ice.TRUE
|
||||
kit.If(len(arg) > 0 && arg[0] == TOAST, func() { withecho = false; m.Option(ice.MSG_DEBUG, ice.FALSE) })
|
||||
wait, done := m.Wait(kit.Select("", m.OptionDefault(ice.SPACE_TIMEOUT, "180s"), withecho), func(msg *ice.Message, arg ...string) {
|
||||
wait, done := m.Wait(func(msg *ice.Message, arg ...string) {
|
||||
m.Cost(kit.Format("%v->[%v] %v %v", m.Optionv(ice.MSG_SOURCE), name, m.Detailv(), msg.FormatSize())).Copy(msg)
|
||||
})
|
||||
if withecho {
|
||||
h = mdb.HashCreate(m.SpawnSilent(), mdb.TYPE, tcp.SEND, mdb.NAME, kit.Keys(name, m.Target().ID()), mdb.TEXT, kit.Join(arg, lex.SP), kit.Dict(mdb.TARGET, done))
|
||||
defer mdb.HashRemove(m.SpawnSilent(), mdb.HASH, h)
|
||||
}
|
||||
if target := kit.Split(name, nfs.PT, nfs.PT); !mdb.HashSelectDetail(m, target[0], func(value ice.Map) {
|
||||
if c, ok := value[mdb.TARGET].(*websocket.Conn); !m.WarnNotValid(!ok, mdb.TARGET) {
|
||||
kit.If(kit.Format(value[mdb.TYPE]) == ORIGIN && target[0] != ice.OPS, func() {
|
||||
m.Optionv(ice.MSG_USERWEB, kit.Simple(value[mdb.TEXT], m.Optionv(ice.MSG_USERWEB)))
|
||||
m.Optionv(ice.MSG_USERPOD, kit.Simple(kit.Keys(target[1:]), m.Optionv(ice.MSG_USERPOD)))
|
||||
m.Options(ice.MSG_USERHOST, "", ice.MSG_USERWEB0, m.Option(ice.MSG_USERWEB), ice.MSG_USERPOD0, name)
|
||||
})
|
||||
m.Option(ice.MSG_HANDLE, ice.FALSE)
|
||||
kit.For([]string{ice.MSG_USERROLE, ice.LOG_TRACEID, ice.SPACE_NOECHO}, func(k string) { m.Optionv(k, m.Optionv(k)) })
|
||||
kit.For(kit.Filters(kit.Simple(m.Optionv(ice.MSG_OPTS)), "task.id", "work.id"), func(k string) { m.Optionv(k, m.Optionv(k)) })
|
||||
if withecho {
|
||||
_space_echo(m.Set(ice.MSG_DETAIL, arg...), []string{h}, target, c)
|
||||
} else {
|
||||
_space_echo(m.Set(ice.MSG_DETAIL, arg...), nil, target, c)
|
||||
}
|
||||
h = mdb.HashCreate(m.Spawn(), mdb.TYPE, tcp.SEND, mdb.NAME, kit.Keys(name, m.Target().ID()), mdb.TEXT, kit.Join(arg, lex.SP), kit.Dict(mdb.TARGET, done))
|
||||
if target := kit.Split(name, nfs.PT, nfs.PT); mdb.HashSelectDetail(m, target[0], func(value ice.Map) {
|
||||
if c, ok := value[mdb.TARGET].(*websocket.Conn); !m.Warn(!ok, ice.ErrNotValid, mdb.TARGET) {
|
||||
kit.For(m.Optionv(ice.MSG_OPTS), func(k string) { m.Optionv(k, m.Optionv(k)) })
|
||||
_space_echo(m.Set(ice.MSG_DETAIL, arg...), []string{h}, target, c)
|
||||
}
|
||||
}) {
|
||||
if name == ice.OPS && ice.Info.NodeType == SERVER {
|
||||
m.Cmdy(arg)
|
||||
return
|
||||
}
|
||||
kit.If(m.IsDebug(), func() {
|
||||
m.WarnNotFoundSpace(kit.IndexOf([]string{ice.OPS, ice.DEV}, target[0]) == -1, SPACE, name)
|
||||
})
|
||||
} else if withecho {
|
||||
m.Warn(!wait(), kit.Format("space %v %v time out", name, arg))
|
||||
wait()
|
||||
} else {
|
||||
m.Warn(kit.IndexOf([]string{ice.OPS, ice.DEV}, target[0]) == -1, ice.ErrNotFound, name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const (
|
||||
WEIXIN = "weixin"
|
||||
PORTAL = "portal"
|
||||
WORKER = "worker"
|
||||
CHROME = "chrome"
|
||||
MASTER = "master"
|
||||
SERVER = "server"
|
||||
MYSELF = "myself"
|
||||
ORIGIN = "origin"
|
||||
WORKER = "worker"
|
||||
|
||||
REDIAL = "redial"
|
||||
AGENT = "agent"
|
||||
)
|
||||
const (
|
||||
OPS_ORIGIN_OPEN = "ops.origin.open"
|
||||
OPS_SERVER_OPEN = "ops.server.open"
|
||||
OPS_DREAM_SPAWN = "ops.dream.spawn"
|
||||
OPS_DREAM_OPEN = "ops.dream.open"
|
||||
|
||||
SPACE_LOGIN = "space.login"
|
||||
SPACE_LOGIN_CLOSE = "space.login.close"
|
||||
SPACE_GRANT = "space.grant"
|
||||
SPACE_OPEN = "space.open"
|
||||
SPACE_CLOSE = "space.close"
|
||||
PORTAL_OPEN = "portal.open"
|
||||
PORTAL_CLOSE = "portal.close"
|
||||
SPACE_LOGIN = "space.login"
|
||||
)
|
||||
const SPACE = "space"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
"p": {Help: "资源", Actions: ApiWhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == "require" {
|
||||
m.Cmdy("/require/", arg[1:])
|
||||
return
|
||||
}
|
||||
if kit.IsIn(arg[0], ice.SRC, ice.USR) {
|
||||
ShareLocalFile(m, arg...)
|
||||
} else {
|
||||
m.Cmdy(PP(ice.REQUIRE), arg)
|
||||
}
|
||||
}},
|
||||
"m": {Help: "模块", Actions: ApiWhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
p := path.Join(nfs.USR_MODULES, path.Join(arg...))
|
||||
kit.If(!nfs.Exists(m, p), func() {
|
||||
if kit.IsIn(m.Option(ice.MSG_USERROLE), aaa.TECH, aaa.ROOT) {
|
||||
kit.If(!nfs.Exists(m, nfs.USR_PACKAGE), func() {
|
||||
m.Cmd(nfs.SAVE, nfs.USR_PACKAGE, kit.Formats(kit.Dict(mdb.NAME, "usr", nfs.VERSION, "0.0.1")))
|
||||
})
|
||||
m.Cmd(cli.SYSTEM, "npm", "install", arg[0], kit.Dict(cli.CMD_DIR, ice.USR))
|
||||
}
|
||||
})
|
||||
m.RenderDownload(p)
|
||||
}},
|
||||
"c": {Help: "命令", Actions: ApiWhiteAction(), Hand: func(m *ice.Message, arg ...string) { m.Cmdy(CHAT_CMD, arg) }},
|
||||
"s": {Help: "空间", Actions: ApiWhiteAction(), Hand: func(m *ice.Message, arg ...string) { m.Cmdy(CHAT_POD, arg) }},
|
||||
SPACE: {Name: "space name cmds auto", Help: "空间站", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.NodeInfo(m, ice.Info.Pathname, WORKER)
|
||||
aaa.White(m, SPACE, ice.MAIN)
|
||||
if kit.IsIn(ice.Info.NodeIcon, "src/main.ico", "") {
|
||||
nfs.Exists(m, "src/main.ico", func(p string) { ice.Info.NodeIcon = p })
|
||||
nfs.Exists(m, "src/main.jpg", func(p string) { ice.Info.NodeIcon = p })
|
||||
nfs.Exists(m, "src/main.png", func(p string) { ice.Info.NodeIcon = p })
|
||||
tcp.DIAL: {Name: "dial dev=ops name", Hand: func(m *ice.Message, arg ...string) {
|
||||
if strings.HasPrefix(m.Option(ice.DEV), HTTP) {
|
||||
m.Cmd(SPIDE, mdb.CREATE, m.OptionSimple(ice.DEV))
|
||||
m.Option(ice.DEV, ice.DEV)
|
||||
}
|
||||
_space_dial(m, m.Option(ice.DEV), kit.Select(ice.Info.NodeName, m.Option(mdb.NAME)), arg...)
|
||||
}},
|
||||
mdb.ICONS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.NodeInfo(m, ice.Info.Pathname, WORKER, arg[0])
|
||||
m.Cmd(SERVE, m.ActionKey(), arg)
|
||||
}},
|
||||
ice.MAIN: {Name: "main index", Role: aaa.VOID, Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
ice.Info.NodeMain = m.Option(ctx.INDEX)
|
||||
m.Cmd(SERVE, m.ActionKey(), arg)
|
||||
return
|
||||
}
|
||||
m.Options(mdb.ICONS, "")
|
||||
kit.If(ice.Info.NodeMain, func(cmd string) { RenderPodCmd(m, "", cmd) }, func() { RenderMain(m) })
|
||||
}},
|
||||
ice.INFO: {Role: aaa.VOID, Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Push(mdb.TIME, ice.Info.Make.Time)
|
||||
m.Push(mdb.NAME, ice.Info.NodeName)
|
||||
m.Push(mdb.ICONS, ice.Info.NodeIcon)
|
||||
m.Push(nfs.MODULE, ice.Info.Make.Module)
|
||||
m.Push(nfs.VERSION, ice.Info.Make.Versions())
|
||||
m.Push(nfs.PATHNAME, ice.Info.Pathname)
|
||||
m.Push(tcp.HOSTPORT, HostPort(m, m.Cmd(tcp.HOST).Append(aaa.IP), m.Cmd(SERVER).Append(tcp.PORT)))
|
||||
m.Push(ORIGIN, m.Option(ice.MSG_USERHOST))
|
||||
cli.START: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("", tcp.DIAL, arg) }},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
defer mdb.HashModifyDeferRemove(m, m.OptionSimple(mdb.NAME), mdb.STATUS, cli.STOP)()
|
||||
m.Cmd("", m.Option(mdb.NAME), ice.EXIT)
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) {
|
||||
if mdb.IsSearchForEach(m, arg, nil) {
|
||||
m.Cmds("", func(value ice.Maps) {
|
||||
switch value[mdb.TYPE] {
|
||||
case MASTER:
|
||||
m.PushSearch(mdb.TEXT, m.Cmdv(SPIDE, value[mdb.NAME], CLIENT_ORIGIN), value)
|
||||
case SERVER:
|
||||
m.PushSearch(mdb.TEXT, m.MergePod(value[mdb.NAME]), value)
|
||||
case ORIGIN:
|
||||
m.PushSearch(mdb.TEXT, m.Cmdv(SPIDE, value[mdb.NAME], CLIENT_ORIGIN), value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}},
|
||||
cli.START: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("", tcp.DIAL, arg) }},
|
||||
tcp.DIAL: {Name: "dial dev=ops name", Hand: func(m *ice.Message, arg ...string) {
|
||||
_space_dial(m, m.Option(ice.DEV), kit.Select(ice.Info.NodeName, m.Option(mdb.NAME)), arg...)
|
||||
ice.Info.Important = ice.HasVar()
|
||||
}},
|
||||
cli.CLOSE: {Hand: func(m *ice.Message, arg ...string) { mdb.HashRemove(m, m.OptionSimple(mdb.NAME)) }},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
defer ToastProcess(m)()
|
||||
mdb.HashModify(m, m.OptionSimple(mdb.NAME), mdb.STATUS, cli.STOP)
|
||||
msg := mdb.HashSelect(m.Spawn(), m.Option(mdb.NAME))
|
||||
if msg.Append(mdb.TYPE) == ORIGIN {
|
||||
if target, ok := mdb.HashSelectTarget(m, m.Option(mdb.NAME), nil).(io.Closer); ok {
|
||||
target.Close()
|
||||
}
|
||||
} else {
|
||||
m.Cmd("", m.Option(mdb.NAME), ice.EXIT).Sleep3s()
|
||||
}
|
||||
}},
|
||||
DOMAIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_space_domain(m)) }},
|
||||
LOGIN: {Help: "授权", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := m.Cmd("", kit.Select(m.Option(mdb.NAME), arg, 0))
|
||||
m.Options(ice.MSG_USERIP, msg.Append(aaa.IP), ice.MSG_USERUA, msg.Append(aaa.UA))
|
||||
LOGIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_USERUA, m.Cmdv("", kit.Select(m.Option(mdb.NAME), arg, 0), ice.MSG_USERUA))
|
||||
m.Cmd("", kit.Select(m.Option(mdb.NAME), arg, 0), ice.MSG_SESSID, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME)))
|
||||
}},
|
||||
SPACE_LOGIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(m.Option(ice.FROM_DAEMON), func(p string) { m.Cmd("", p, GRANT, m.Option(mdb.NAME), -1) })
|
||||
}},
|
||||
OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case ORIGIN:
|
||||
ProcessIframe(m, m.Option(mdb.NAME), SpideOrigin(m, m.Option(mdb.NAME)), arg...)
|
||||
case MASTER:
|
||||
ctx.ProcessOpen(m, m.Cmdv(SPIDE, m.Option(mdb.NAME), CLIENT_ORIGIN))
|
||||
default:
|
||||
ProcessIframe(m, m.Option(mdb.NAME), m.MergePod(m.Option(mdb.NAME)), arg...)
|
||||
ctx.ProcessOpen(m, m.MergePod(m.Option(mdb.NAME), arg))
|
||||
}
|
||||
}},
|
||||
"main": {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(mdb.Config(m, "main"), func(cmd string) { RenderPodCmd(m, "", cmd) }, func() {
|
||||
m.RenderResult(nfs.Template(m.Options(nfs.VERSION, renderVersion(m)), "main.html"))
|
||||
})
|
||||
m.Optionv(ice.MSG_ARGS, kit.Simple(m.Optionv(ice.MSG_ARGS)))
|
||||
}},
|
||||
nfs.PS: {Hand: func(m *ice.Message, arg ...string) { _space_fork(m) }},
|
||||
}, gdb.EventsAction(SPACE_LOGIN), mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500,
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text,main,icons,module,version,agent,system,ip,usernick,username,userrole",
|
||||
ctx.ACTION, OPEN, REDIAL, kit.Dict("a", 1000, "b", 100, "c", 1000),
|
||||
), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text", ctx.ACTION, OPEN, REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000)), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
if len(arg) == 1 && strings.Contains(arg[0], nfs.PT) {
|
||||
ls := kit.Split(arg[0], nfs.PT)
|
||||
m.Cmdy(SPACE, ls[0], SPACE, kit.Keys(ls[1:]))
|
||||
return
|
||||
}
|
||||
defer m.StatusTimeCount(kit.Dict(ice.MAIN, mdb.Config(m, ice.MAIN)))
|
||||
kit.If(len(arg) > 0 && arg[0] != "", func() { m.OptionFields(ice.MSG_DETAIL) })
|
||||
mdb.HashSelect(m.Spawn(), arg...).Table(func(value ice.Maps) {
|
||||
if m.Push("", value, kit.Split(mdb.Config(m, mdb.FIELD))); len(arg) > 0 && arg[0] != "" {
|
||||
m.Push(mdb.STATUS, value[mdb.STATUS]).Push(aaa.UA, value[aaa.UA])
|
||||
}
|
||||
if kit.IsIn(value[mdb.TYPE], WEIXIN, PORTAL) && value[mdb.NAME] != html.CHROME {
|
||||
m.Push(mdb.LINK, m.MergeLink(value[mdb.TEXT]))
|
||||
} else if kit.IsIn(value[mdb.TYPE], WORKER, SERVER) {
|
||||
m.Push(mdb.LINK, m.MergePod(value[mdb.NAME]))
|
||||
} else if kit.IsIn(value[mdb.TYPE], ORIGIN) {
|
||||
m.Push(mdb.LINK, value[mdb.TEXT])
|
||||
mdb.HashSelect(m, arg...).Sort("").Table(func(value ice.Maps) {
|
||||
if kit.IsIn(value[mdb.TYPE], SERVER, WORKER) {
|
||||
m.Push(mdb.LINK, tcp.PublishLocalhost(m, m.MergePod(value[mdb.NAME])))
|
||||
} else {
|
||||
m.Push(mdb.LINK, "")
|
||||
}
|
||||
m.PushButton(kit.Select(OPEN, LOGIN, value[mdb.TYPE] == LOGIN), mdb.REMOVE)
|
||||
})
|
||||
m.RewriteAppend(func(value, key string, index int) string {
|
||||
if key == mdb.ICONS && !kit.HasPrefix(value, HTTP) {
|
||||
if m.Appendv(mdb.TYPE)[index] == ORIGIN {
|
||||
if !kit.HasPrefix(value, nfs.PS) {
|
||||
value = kit.MergeURL(nfs.P + value)
|
||||
}
|
||||
if m.Appendv(mdb.NAME)[index] == ice.OPS {
|
||||
value = kit.MergeURL2(m.Option(ice.MSG_USERWEB), value)
|
||||
} else {
|
||||
value = kit.MergeURL2(m.Appendv(mdb.TEXT)[index], value)
|
||||
}
|
||||
} else {
|
||||
if !kit.HasPrefix(value, nfs.PS) {
|
||||
value = kit.MergeURL(nfs.P+value, ice.POD, kit.Keys(m.Option(ice.MSG_USERPOD), m.Appendv(mdb.NAME)[index]))
|
||||
}
|
||||
}
|
||||
}
|
||||
return value
|
||||
})
|
||||
m.Sort("", kit.Simple(aaa.LOGIN, WEIXIN, PORTAL, WORKER, SERVER, ORIGIN))
|
||||
kit.If(len(arg) == 1, func() { m.EchoIFrame(m.MergePod(arg[0])) })
|
||||
} else {
|
||||
if ice.Info.NodeType != WORKER && arg[0] == ice.OPS {
|
||||
m.Cmdy(arg[1:])
|
||||
return
|
||||
}
|
||||
if kit.IsIn(arg[0], "", ice.Info.NodeName) {
|
||||
m.Cmdy(arg[1:])
|
||||
return
|
||||
}
|
||||
if ice.Info.NodeType == WORKER && !strings.HasPrefix(arg[0], ice.OPS) {
|
||||
arg[0] = kit.Keys(ice.OPS, arg[0])
|
||||
}
|
||||
for i := 0; i < 5; i++ {
|
||||
if _space_send(m, arg[0], kit.Simple(kit.Split(arg[1]), arg[2:])...); !m.IsErrNotFoundSpace() {
|
||||
break
|
||||
} else if i < 4 {
|
||||
m.SetAppend().SetResult().Sleep3s()
|
||||
}
|
||||
}
|
||||
_space_send(m, arg[0], kit.Simple(kit.Split(arg[1]), arg[2:])...)
|
||||
}
|
||||
}},
|
||||
})
|
||||
ice.Info.Inputs = append(ice.Info.Inputs, func(m *ice.Message, arg ...string) {
|
||||
switch kit.TrimPrefix(arg[0], "extra.") {
|
||||
case DREAM:
|
||||
m.SetAppend()
|
||||
AdminCmd(m, DREAM).Table(func(value ice.Maps) {
|
||||
kit.If(kit.IsIn(value[mdb.TYPE], WORKER), func() {
|
||||
m.Push(arg[0], value[mdb.NAME])
|
||||
m.PushRecord(value, nfs.VERSION, mdb.TIME, nfs.MODULE, mdb.ICONS)
|
||||
})
|
||||
})
|
||||
case SPACE:
|
||||
AdminCmd(m, SPACE).Table(func(value ice.Maps) {
|
||||
kit.If(kit.IsIn(value[mdb.TYPE], WORKER, SERVER), func() { m.Push(arg[0], value[mdb.NAME]) })
|
||||
})
|
||||
case SERVER:
|
||||
AdminCmd(m, SPACE).Table(func(value ice.Maps) {
|
||||
kit.If(kit.IsIn(value[mdb.TYPE], SERVER), func() { m.Push(arg[0], value[mdb.NAME]) })
|
||||
})
|
||||
case ORIGIN:
|
||||
m.SetAppend().Push(arg[0], SpideOrigin(m, ice.DEV))
|
||||
m.Copy(m.Cmd(SPIDE, kit.Dict(ice.MSG_FIELDS, CLIENT_ORIGIN)).CutTo(CLIENT_ORIGIN, arg[0]).Sort(arg[0]))
|
||||
case mdb.ICONS:
|
||||
m.Options(nfs.DIR_DEEP, ice.TRUE, nfs.DIR_REG, kit.ExtReg(nfs.PNG, nfs.JPG, nfs.JPEG))
|
||||
m.Cmdy(nfs.DIR, nfs.SRC, nfs.PATH)
|
||||
if aaa.IsTechOrRoot(m) {
|
||||
m.Cmdy(nfs.DIR, nfs.USR_LOCAL_IMAGE, nfs.PATH)
|
||||
}
|
||||
m.Cmdy(nfs.DIR, nfs.USR_IMAGE, nfs.PATH)
|
||||
m.Cmdy(nfs.DIR, nfs.USR_ICONS, nfs.PATH)
|
||||
m.CutTo(nfs.PATH, arg[0])
|
||||
case ctx.INDEX, ice.CMD:
|
||||
m.OptionFields(ctx.INDEX)
|
||||
if space := m.Option(SPACE); space != "" {
|
||||
if ice.Info.NodeType == WORKER {
|
||||
m.Options(SPACE, []string{}).Cmdy(SPACE, kit.Keys(ice.OPS, space), ctx.COMMAND)
|
||||
} else {
|
||||
m.Options(SPACE, []string{}).Cmdy(SPACE, space, ctx.COMMAND)
|
||||
}
|
||||
} else {
|
||||
m.Cmdy(ctx.COMMAND)
|
||||
}
|
||||
m.CutTo(ctx.INDEX, arg[0])
|
||||
case ctx.ARGS:
|
||||
m.OptionDefault(ctx.INDEX, m.Option("extra.index"))
|
||||
if space := m.Option(SPACE); space != "" {
|
||||
m.Options(SPACE, []string{}).Cmdy(SPACE, space, ctx.COMMAND, mdb.INPUTS, m.Option(ctx.INDEX))
|
||||
} else {
|
||||
m.Cmdy(ctx.COMMAND, mdb.INPUTS, m.Option(ctx.INDEX))
|
||||
}
|
||||
case tcp.WIFI:
|
||||
m.Cmdy(tcp.WIFI).CutTo(tcp.SSID, arg[0])
|
||||
case MESSAGE:
|
||||
m.Cmdy(MESSAGE).Cut(mdb.HASH, mdb.ZONE, mdb.ICONS)
|
||||
case TARGET:
|
||||
m.AdminCmd(MATRIX).Table(func(value ice.Maps) {
|
||||
m.Push(arg[0], kit.Keys(kit.Select("", ice.OPS, ice.Info.NodeType == WORKER), value[DOMAIN], value[mdb.NAME]))
|
||||
m.Push(mdb.TYPE, value[mdb.TYPE])
|
||||
})
|
||||
m.Sort("type,target", []string{MYSELF, SERVER, ORIGIN, WORKER}, ice.STR_R)
|
||||
}
|
||||
})
|
||||
ice.Info.AdminCmd = AdminCmd
|
||||
ctx.PodCmd = func(m *ice.Message, arg ...ice.Any) bool {
|
||||
Upload(m)
|
||||
if pod := m.Option(ice.POD); pod != "" {
|
||||
if ls := kit.Simple(m.Optionv(ice.MSG_UPLOAD)); len(ls) > 1 {
|
||||
// m.Cmd(SPACE, pod, SPIDE, ice.DEV, CACHE, SHARE_CACHE+ls[0])
|
||||
}
|
||||
m.Options(ice.POD, []string{}, ice.MSG_USERPOD, strings.TrimPrefix(pod, "ops.")).Cmdy(append(kit.List(ice.SPACE, pod), arg...)...)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
func Space(m *ice.Message, arg ice.Any) []string {
|
||||
if arg == nil || arg == "" {
|
||||
@ -593,32 +238,3 @@ func Space(m *ice.Message, arg ice.Any) []string {
|
||||
}
|
||||
return []string{SPACE, kit.Format(arg)}
|
||||
}
|
||||
func PodCmd(m *ice.Message, key string, arg ...string) bool {
|
||||
if pod := m.Option(key); pod != "" {
|
||||
m.Options(key, "", ice.MSG_USERPOD, strings.TrimPrefix(pod, "ops.")).Cmdy(SPACE, pod, m.ShortKey(), arg)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
func SpaceName(name string) string {
|
||||
return kit.ReplaceAll(name, nfs.DF, "_", nfs.PS, "_", nfs.PT, "_", "[", "_", "]", "_")
|
||||
}
|
||||
func SpacePwd(m *ice.Message, name, text string) {
|
||||
m.Optionv(ice.MSG_OPTS, m.OptionSimple(ice.MSG_USERROLE, ice.MSG_USERNAME))
|
||||
m.Cmd(SPACE, name, cli.PWD, name, kit.Dict(ice.SPACE_NOECHO, ice.TRUE,
|
||||
mdb.ICONS, ice.Info.NodeIcon, mdb.TEXT, text, AGENT, "Go-http-client", cli.SYSTEM, runtime.GOOS,
|
||||
mdb.TIME, ice.Info.Make.Time, nfs.MODULE, ice.Info.Make.Module, nfs.VERSION, ice.Info.Make.Versions(),
|
||||
))
|
||||
}
|
||||
func SpaceEvent(m *ice.Message, event, skip string, arg ...string) {
|
||||
m.Optionv(ice.MSG_OPTS, m.OptionSimple(ice.MSG_USERROLE, ice.MSG_USERNAME))
|
||||
m.Cmds(SPACE).Table(func(value ice.Maps) {
|
||||
if kit.IsIn(value[mdb.TYPE], WORKER) && value[mdb.NAME] != skip {
|
||||
m.Cmd(SPACE, value[mdb.NAME], gdb.EVENT, gdb.HAPPEN, gdb.EVENT, event, arg, kit.Dict(
|
||||
ice.MSG_USERROLE, aaa.TECH, ice.SPACE_NOECHO, ice.TRUE,
|
||||
))
|
||||
}
|
||||
})
|
||||
m.Cmd(gdb.EVENT, gdb.HAPPEN, gdb.EVENT, event, arg, kit.Dict(ice.MSG_USERROLE, aaa.TECH))
|
||||
}
|
||||
|
@ -2,96 +2,66 @@ package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/log"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web/html"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _spide_create(m *ice.Message, link, types, name, icons, token string) {
|
||||
if u, e := url.Parse(link); !m.WarnNotValid(e != nil || link == "", link) {
|
||||
func _spide_create(m *ice.Message, name, link string) {
|
||||
if u, e := url.Parse(link); !m.Warn(e != nil || link == "", ice.ErrNotValid, link) {
|
||||
dir, file := path.Split(u.EscapedPath())
|
||||
m.Logs(mdb.INSERT, SPIDE, name, LINK, link)
|
||||
mdb.HashSelectUpdate(m, mdb.HashCreate(m, CLIENT_NAME, name), func(value ice.Map) {
|
||||
value[mdb.ICONS], value[TOKEN] = icons, kit.Select(kit.Format(value[TOKEN]), token)
|
||||
value[SPIDE_CLIENT] = kit.Dict(mdb.NAME, name, mdb.TYPE, types,
|
||||
SPIDE_METHOD, http.MethodGet, URL, link, ORIGIN, u.Scheme+"://"+u.Host,
|
||||
tcp.PROTOCOL, u.Scheme, tcp.HOSTNAME, u.Hostname(), tcp.HOST, u.Host, nfs.PATH, dir, nfs.FILE, file, cli.TIMEOUT, "300s",
|
||||
value[SPIDE_CLIENT] = kit.Dict(mdb.NAME, name, SPIDE_METHOD, http.MethodPost, "url", link, ORIGIN, u.Scheme+"://"+u.Host,
|
||||
tcp.PROTOCOL, u.Scheme, tcp.HOSTNAME, u.Hostname(), tcp.HOST, u.Host, nfs.PATH, dir, nfs.FILE, file, cli.TIMEOUT, "30s",
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
func _spide_show(m *ice.Message, name string, arg ...string) {
|
||||
file := ""
|
||||
action, arg := _spide_args(m, arg, SPIDE_RAW, SPIDE_DETAIL, SPIDE_MSG, SPIDE_SAVE, SPIDE_CACHE, SPIDE_STREAM)
|
||||
action, arg := _spide_args(m, arg, SPIDE_RAW, SPIDE_MSG, SPIDE_CACHE, SPIDE_SAVE)
|
||||
kit.If(action == SPIDE_SAVE, func() { file, arg = arg[0], arg[1:] })
|
||||
msg := mdb.HashSelects(m.Spawn(), name)
|
||||
method, arg := _spide_args(m, arg, http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete)
|
||||
method = kit.Select(http.MethodGet, msg.Append(CLIENT_METHOD), method)
|
||||
method = kit.Select(http.MethodPost, msg.Append(CLIENT_METHOD), method)
|
||||
uri, arg := arg[0], arg[1:]
|
||||
body, head, arg := _spide_body(m, method, arg...)
|
||||
if m.Option("spide.break") == ice.TRUE {
|
||||
return
|
||||
}
|
||||
if c, ok := body.(io.Closer); ok {
|
||||
defer c.Close()
|
||||
}
|
||||
_uri := kit.MergeURL2(msg.Append(CLIENT_URL), uri, arg)
|
||||
req, e := http.NewRequest(method, _uri, body)
|
||||
if m.WarnNotValid(e, uri) {
|
||||
req, e := http.NewRequest(method, kit.MergeURL2(msg.Append(CLIENT_URL), uri, arg), body)
|
||||
if m.Warn(e, ice.ErrNotValid, uri) {
|
||||
return
|
||||
}
|
||||
mdb.HashSelectDetail(m, name, func(value ice.Map) { _spide_head(m, req, head, value) })
|
||||
if m.Option(log.DEBUG) == ice.TRUE {
|
||||
kit.For(req.Header, func(k string, v []string) { m.Logs(REQUEST, k, v) })
|
||||
}
|
||||
res, e := _spide_send(m, name, req, kit.Format(m.OptionDefault(CLIENT_TIMEOUT, msg.Append(CLIENT_TIMEOUT))))
|
||||
if m.WarnNotFound(e, SPIDE, uri) {
|
||||
res, e := _spide_send(m, name, req, kit.Format(msg.Append(CLIENT_TIMEOUT)))
|
||||
if m.Warn(e, ice.ErrNotFound, uri) {
|
||||
return
|
||||
}
|
||||
defer res.Body.Close()
|
||||
m.Cost(cli.STATUS, res.Status, nfs.SIZE, kit.FmtSize(kit.Int64(res.Header.Get(html.ContentLength))), mdb.TYPE, res.Header.Get(html.ContentType))
|
||||
if action == SPIDE_DETAIL {
|
||||
m.Push(mdb.TYPE, STATUS).Push(mdb.NAME, res.StatusCode).Push(mdb.VALUE, res.Status)
|
||||
}
|
||||
m.Options(STATUS, res.Status)
|
||||
kit.For(res.Header, func(k string, v []string) {
|
||||
if m.Option(log.DEBUG) == ice.TRUE {
|
||||
m.Logs(RESPONSE, k, v)
|
||||
}
|
||||
if m.Options(k, v); action == SPIDE_DETAIL {
|
||||
m.Push(mdb.TYPE, SPIDE_HEADER).Push(mdb.NAME, k).Push(mdb.VALUE, v[0])
|
||||
}
|
||||
})
|
||||
m.Cost(cli.STATUS, res.Status, nfs.SIZE, res.Header.Get(ContentLength), mdb.TYPE, res.Header.Get(ContentType))
|
||||
kit.For(res.Header, func(k string, v []string) { m.Logs("response", k, v) })
|
||||
mdb.HashSelectUpdate(m, name, func(value ice.Map) {
|
||||
kit.For(res.Cookies(), func(v *http.Cookie) {
|
||||
kit.Value(value, kit.Keys(SPIDE_COOKIE, v.Name), v.Value)
|
||||
if m.Option(log.DEBUG) == ice.TRUE {
|
||||
m.Logs(RESPONSE, v.Name, v.Value)
|
||||
}
|
||||
if action == SPIDE_DETAIL {
|
||||
m.Push(mdb.TYPE, COOKIE).Push(mdb.NAME, v.Name).Push(mdb.VALUE, v.Value)
|
||||
}
|
||||
m.Logs("response", v.Name, v.Value)
|
||||
})
|
||||
})
|
||||
if m.WarnNotValid(res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated && res.StatusCode != http.StatusNoContent, uri, cli.STATUS, res.Status) {
|
||||
if m.Warn(res.StatusCode != http.StatusOK, ice.ErrNotValid, uri, cli.STATUS, res.Status) {
|
||||
switch res.StatusCode {
|
||||
case http.StatusNotFound, http.StatusUnauthorized:
|
||||
return
|
||||
@ -113,25 +83,24 @@ func _spide_body(m *ice.Message, method string, arg ...string) (io.Reader, ice.M
|
||||
head := ice.Maps{}
|
||||
switch kit.If(len(arg) == 1, func() { arg = []string{SPIDE_DATA, arg[0]} }); arg[0] {
|
||||
case SPIDE_FORM:
|
||||
// arg = kit.Simple(arg, func(v string) string { return url.QueryEscape(v) })
|
||||
head[html.ContentType], body = html.ApplicationForm, bytes.NewBufferString(kit.JoinQuery(arg[1:]...))
|
||||
m.Info("debug what %v", kit.JoinQuery(arg[1:]...))
|
||||
arg = kit.Simple(arg, func(v string) string { return url.QueryEscape(v) })
|
||||
head[ContentType], body = ContentFORM, bytes.NewBufferString(kit.JoinKV("=", "&", arg[1:]...))
|
||||
case SPIDE_PART:
|
||||
head[html.ContentType], body = _spide_part(m, arg...)
|
||||
head[ContentType], body = _spide_part(m, arg...)
|
||||
case SPIDE_FILE:
|
||||
if f, e := nfs.OpenFile(m, arg[1]); m.Assert(e) {
|
||||
m.Logs(nfs.LOAD, nfs.FILE, arg[1])
|
||||
body = f
|
||||
}
|
||||
case SPIDE_DATA:
|
||||
head[html.ContentType], body = html.ApplicationJSON, bytes.NewBufferString(kit.Select("{}", arg, 1))
|
||||
head[ContentType], body = ApplicationJSON, bytes.NewBufferString(kit.Select("{}", arg, 1))
|
||||
case SPIDE_JSON:
|
||||
arg = arg[1:]
|
||||
fallthrough
|
||||
default:
|
||||
data := ice.Map{}
|
||||
kit.For(arg, func(k, v string) { kit.Value(data, k, v) })
|
||||
head[html.ContentType], body = html.ApplicationJSON, bytes.NewBufferString(kit.Format(data))
|
||||
head[ContentType], body = ApplicationJSON, bytes.NewBufferString(kit.Format(data))
|
||||
}
|
||||
return body, head, arg[:0]
|
||||
}
|
||||
@ -144,25 +113,20 @@ func _spide_part(m *ice.Message, arg ...string) (string, io.Reader) {
|
||||
if arg[i] == nfs.SIZE {
|
||||
size = kit.Int64(arg[i+1])
|
||||
} else if arg[i] == SPIDE_CACHE {
|
||||
if t, e := time.ParseInLocation(ice.MOD_TIME, arg[i+1], time.Local); !m.WarnNotValid(e) {
|
||||
if t, e := time.ParseInLocation(ice.MOD_TIME, arg[i+1], time.Local); !m.Warn(e, ice.ErrNotValid) {
|
||||
cache = t
|
||||
}
|
||||
} else if strings.HasPrefix(arg[i+1], mdb.AT) {
|
||||
p := arg[i+1][1:]
|
||||
if s, e := nfs.StatFile(m, p); !m.WarnNotValid(e) {
|
||||
if s, e := nfs.StatFile(m, arg[i+1][1:]); !m.Warn(e, ice.ErrNotValid) {
|
||||
if s.Size() == size && s.ModTime().Before(cache) {
|
||||
m.Option("spide.break", ice.TRUE)
|
||||
continue
|
||||
} else if s.Size() == size && !nfs.Exists(m.Spawn(kit.Dict(ice.MSG_FILES, nfs.DiskFile)), p) {
|
||||
m.Option("spide.break", ice.TRUE)
|
||||
continue
|
||||
}
|
||||
m.Logs(nfs.FIND, LOCAL, s.ModTime(), nfs.SIZE, s.Size(), CACHE, cache, nfs.SIZE, size)
|
||||
}
|
||||
if f, e := nfs.OpenFile(m, p); !m.WarnNotValid(e, arg[i+1]) {
|
||||
if f, e := nfs.OpenFile(m, arg[i+1][1:]); !m.Warn(e, ice.ErrNotValid, arg[i+1]) {
|
||||
defer f.Close()
|
||||
if p, e := mp.CreateFormFile(arg[i], path.Base(p)); !m.WarnNotValid(e, arg[i+1]) {
|
||||
if n, e := io.Copy(p, f); !m.WarnNotValid(e, arg[i+1]) {
|
||||
if p, e := mp.CreateFormFile(arg[i], path.Base(arg[i+1][1:])); !m.Warn(e, ice.ErrNotValid, arg[i+1]) {
|
||||
if n, e := io.Copy(p, f); !m.Warn(e, ice.ErrNotValid, arg[i+1]) {
|
||||
m.Logs(nfs.LOAD, nfs.FILE, arg[i+1], nfs.SIZE, n)
|
||||
}
|
||||
}
|
||||
@ -175,61 +139,53 @@ func _spide_part(m *ice.Message, arg ...string) (string, io.Reader) {
|
||||
}
|
||||
func _spide_head(m *ice.Message, req *http.Request, head ice.Maps, value ice.Map) {
|
||||
m.Logs(req.Method, req.URL.String())
|
||||
kit.For(head, func(k, v string) { req.Header.Set(k, v) })
|
||||
kit.For(value[SPIDE_HEADER], func(k string, v string) { req.Header.Set(k, v) })
|
||||
kit.For(value[SPIDE_COOKIE], func(k string, v string) { req.AddCookie(&http.Cookie{Name: k, Value: v}) })
|
||||
kit.For(kit.Simple(m.Optionv(SPIDE_COOKIE)), func(k, v string) { req.AddCookie(&http.Cookie{Name: k, Value: v}) })
|
||||
kit.For(kit.Simple(m.Optionv(SPIDE_HEADER)), func(k, v string) { req.Header.Set(k, v) })
|
||||
kit.If(req.Method == http.MethodPost, func() {
|
||||
m.Logs(kit.Select(ice.AUTO, req.Header.Get(html.ContentLength)), req.Header.Get(html.ContentType))
|
||||
kit.For(value[SPIDE_COOKIE], func(k string, v string) {
|
||||
req.AddCookie(&http.Cookie{Name: k, Value: v})
|
||||
m.Logs("Cookie", k, v)
|
||||
})
|
||||
kit.For(kit.Simple(m.Optionv(SPIDE_COOKIE)), func(k, v string) {
|
||||
req.AddCookie(&http.Cookie{Name: k, Value: v})
|
||||
m.Logs("Cookie", k, v)
|
||||
})
|
||||
kit.For(value[SPIDE_HEADER], func(k string, v string) {
|
||||
req.Header.Set(k, v)
|
||||
m.Logs("Header", k, v)
|
||||
})
|
||||
kit.For(kit.Simple(m.Optionv(SPIDE_HEADER)), func(k, v string) {
|
||||
req.Header.Set(k, v)
|
||||
m.Logs("Header", k, v)
|
||||
})
|
||||
kit.For(head, func(k, v string) {
|
||||
req.Header.Set(k, v)
|
||||
m.Logs("Header", k, v)
|
||||
})
|
||||
kit.If(req.Method == http.MethodPost, func() { m.Logs(kit.Select(ice.AUTO, req.Header.Get(ContentLength)), req.Header.Get(ContentType)) })
|
||||
}
|
||||
func _spide_send(m *ice.Message, name string, req *http.Request, timeout string) (*http.Response, error) {
|
||||
client := mdb.HashSelectTarget(m, name, func() ice.Any {
|
||||
if name == ice.OPS {
|
||||
return &http.Client{Timeout: kit.Duration(timeout), Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}}
|
||||
}
|
||||
return &http.Client{Timeout: kit.Duration(timeout)}
|
||||
}).(*http.Client)
|
||||
client := mdb.HashSelectTarget(m, name, func() ice.Any { return &http.Client{Timeout: kit.Duration(timeout)} }).(*http.Client)
|
||||
return client.Do(req)
|
||||
}
|
||||
func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) {
|
||||
m.SetResult()
|
||||
switch action {
|
||||
case SPIDE_RAW, SPIDE_DETAIL:
|
||||
b, _ := ioutil.ReadAll(res.Body)
|
||||
m.Echo(string(b))
|
||||
case SPIDE_RAW:
|
||||
if b, _ := ioutil.ReadAll(res.Body); strings.HasPrefix(res.Header.Get(ContentType), ApplicationJSON) {
|
||||
m.Echo(kit.Formats(kit.UnMarshal(string(b))))
|
||||
} else {
|
||||
m.Echo(string(b))
|
||||
}
|
||||
case SPIDE_MSG:
|
||||
var data map[string][]string
|
||||
m.Assert(json.NewDecoder(res.Body).Decode(&data))
|
||||
kit.For(data[ice.MSG_OPTION], func(k string) { m.Options(k, data[k]) })
|
||||
kit.For(data[ice.MSG_APPEND], func(k string) { kit.For(data[k], func(v string) { m.Push(k, v) }) })
|
||||
m.Resultv(data[ice.MSG_RESULT])
|
||||
case SPIDE_SAVE:
|
||||
if strings.HasSuffix(file, "/") {
|
||||
file += kit.Select("", kit.Split(m.Option("Content-Disposition"), ";="), -1)
|
||||
m.Info("save file %v", file)
|
||||
}
|
||||
m.Echo(_cache_download(m, res, file, m.OptionCB(SPIDE)))
|
||||
_cache_download(m, res, file, m.OptionCB(SPIDE))
|
||||
case SPIDE_CACHE:
|
||||
m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(html.ContentType), uri, kit.Dict(RESPONSE, res), m.OptionCB(SPIDE))
|
||||
m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(ContentType), uri, kit.Dict(RESPONSE, res), m.OptionCB(SPIDE))
|
||||
m.Echo(m.Append(mdb.HASH))
|
||||
case SPIDE_STREAM:
|
||||
cb, ok := m.Optionv(SPIDE_STREAM).(func(string))
|
||||
if !ok {
|
||||
cb = func(text string) { PushNoticeGrow(m, m.Option("which"), text) }
|
||||
}
|
||||
b := make([]byte, 1024)
|
||||
for {
|
||||
if n, e := res.Body.Read(b); e != nil {
|
||||
break
|
||||
} else {
|
||||
cb(string(b[:n]))
|
||||
}
|
||||
}
|
||||
default:
|
||||
var data ice.Any
|
||||
if b, e := ioutil.ReadAll(res.Body); !m.WarnNotFound(e) {
|
||||
if b, e := ioutil.ReadAll(res.Body); !m.Warn(e) {
|
||||
if json.Unmarshal(b, &data) == nil {
|
||||
m.Push("", kit.KeyValue(ice.Map{}, "", m.Optionv(SPIDE_RES, data)))
|
||||
} else {
|
||||
@ -240,12 +196,10 @@ func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) {
|
||||
}
|
||||
|
||||
const (
|
||||
SPIDE_RAW = "raw"
|
||||
SPIDE_DETAIL = "detail"
|
||||
SPIDE_MSG = "msg"
|
||||
SPIDE_SAVE = "save"
|
||||
SPIDE_CACHE = "cache"
|
||||
SPIDE_STREAM = "stream"
|
||||
SPIDE_RAW = "raw"
|
||||
SPIDE_MSG = "msg"
|
||||
SPIDE_CACHE = "cache"
|
||||
SPIDE_SAVE = "save"
|
||||
|
||||
SPIDE_BODY = "body"
|
||||
SPIDE_FORM = "form"
|
||||
@ -255,10 +209,18 @@ const (
|
||||
SPIDE_JSON = "json"
|
||||
SPIDE_RES = "content_data"
|
||||
|
||||
IMAGE_JPEG = "image/jpeg"
|
||||
IMAGE_PNG = "image/png"
|
||||
TEXT_HTML = "text/html"
|
||||
TEXT_CSS = "text/css"
|
||||
Bearer = "Bearer"
|
||||
Authorization = "Authorization"
|
||||
ContentType = "Content-Type"
|
||||
ContentLength = "Content-Length"
|
||||
UserAgent = "User-Agent"
|
||||
Referer = "Referer"
|
||||
Accept = "Accept"
|
||||
|
||||
ContentFORM = "application/x-www-form-urlencoded"
|
||||
ContentPNG = "image/png"
|
||||
ContentHTML = "text/html"
|
||||
ContentCSS = "text/css"
|
||||
)
|
||||
const (
|
||||
SPIDE_CLIENT = "client"
|
||||
@ -266,212 +228,64 @@ const (
|
||||
SPIDE_COOKIE = "cookie"
|
||||
SPIDE_HEADER = "header"
|
||||
|
||||
CLIENT_URL = "client.url"
|
||||
CLIENT_NAME = "client.name"
|
||||
CLIENT_TYPE = "client.type"
|
||||
CLIENT_METHOD = "client.method"
|
||||
CLIENT_ORIGIN = "client.origin"
|
||||
CLIENT_TIMEOUT = "client.timeout"
|
||||
CLIENT_PROTOCOL = "client.protocol"
|
||||
CLIENT_HOSTNAME = "client.hostname"
|
||||
CLIENT_HOST = "client.host"
|
||||
CLIENT_ORIGIN = "client.origin"
|
||||
CLIENT_URL = "client.url"
|
||||
|
||||
OPEN = "open"
|
||||
MAIN = "main"
|
||||
FULL = "full"
|
||||
LINK = "link"
|
||||
MERGE = "merge"
|
||||
VENDOR = "vendor"
|
||||
|
||||
QS = "?"
|
||||
OPEN = "open"
|
||||
FULL = "full"
|
||||
LINK = "link"
|
||||
MERGE = "merge"
|
||||
REQUEST = "request"
|
||||
RESPONSE = "response"
|
||||
)
|
||||
|
||||
var agentIcons = map[string]string{
|
||||
html.Safari: "usr/icons/Safari.png",
|
||||
html.Chrome: "usr/icons/Chrome.png",
|
||||
html.Edg: "usr/icons/Edg.png",
|
||||
html.MicroMessenger: "usr/icons/wechat.png",
|
||||
"Go-http-client": "usr/icons/go.png",
|
||||
}
|
||||
|
||||
const SPIDE = "spide"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
// SPIDE: {Name: "spide client.name action=raw,msg,save,cache method=GET,PUT,POST,DELETE url format=form,part,json,data,file arg run create", Help: "蜘蛛侠", Actions: ice.MergeActions(ice.Actions{
|
||||
SPIDE: {Help: "蜘蛛侠", Icon: "Find My.png", Meta: kit.Dict(ice.CTX_TRANS, kit.Dict(html.INPUT, kit.Dict(
|
||||
CLIENT_TYPE, "类型", CLIENT_NAME, "名称", CLIENT_URL, "地址",
|
||||
CLIENT_METHOD, "方法", CLIENT_ORIGIN, "服务", CLIENT_TIMEOUT, "超时",
|
||||
CLIENT_PROTOCOL, "协议", CLIENT_HOST, "主机", CLIENT_HOSTNAME, "机器",
|
||||
))), Actions: ice.MergeActions(ice.Actions{
|
||||
SPIDE: {Name: "spide client.name action=raw,msg,save,cache method=GET,PUT,POST,DELETE url format=form,part,json,data,file arg run create", Help: "蜘蛛侠", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
conf := mdb.Confm(m, cli.RUNTIME, cli.CONF)
|
||||
dev := kit.Select("https://dev.shylinux.com", ice.Info.Make.Domain, conf[cli.CTX_DEV])
|
||||
m.Cmd("", mdb.CREATE, dev, ice.DEV, ice.SRC_MAIN_ICO, nfs.REPOS)
|
||||
m.Cmd("", mdb.CREATE, kit.Select(dev, os.Getenv("ctx_dev_ip")), ice.DEV_IP, ice.SRC_MAIN_ICO, "dev_ip")
|
||||
m.Cmd("", mdb.CREATE, kit.Select("http://localhost:9020", conf[cli.CTX_OPS]), ice.OPS, ice.SRC_MAIN_ICO, nfs.REPOS)
|
||||
m.Cmd("", mdb.CREATE, kit.Select("https://shylinux.com", conf[cli.CTX_SHY]), ice.SHY, ice.SRC_MAIN_ICO, nfs.REPOS)
|
||||
m.Cmd("", mdb.CREATE, kit.Select("https://mail.shylinux.com", conf[cli.CTX_MAIL]), ice.MAIL, "usr/icons/Mail.png", "mail")
|
||||
m.Cmd("", mdb.CREATE, kit.Select("https://demo.shylinux.com", conf[cli.CTX_DEMO]), ice.DEMO, ice.SRC_MAIN_ICO, "demo")
|
||||
m.Cmd("", mdb.CREATE, "https://2023.shylinux.com", "2023-ContextOS", ice.SRC_MAIN_ICO, nfs.REPOS)
|
||||
m.Cmd("", mdb.CREATE, "https://2024.shylinux.com", "2024-ContextOS", ice.SRC_MAIN_ICO, nfs.REPOS)
|
||||
m.Cmd("", mdb.CREATE, "https://2025.shylinux.com", "2025-ContextOS", ice.SRC_MAIN_ICO, nfs.REPOS)
|
||||
m.Cmd("", mdb.CREATE, ice.OPS, kit.Select("http://127.0.0.1:9020", conf[cli.CTX_OPS]))
|
||||
m.Cmd("", mdb.CREATE, ice.DEV, kit.Select(kit.Select("https://contexts.com.cn", ice.Info.Make.Domain), conf[cli.CTX_DEV]))
|
||||
m.Cmd("", mdb.CREATE, ice.COM, kit.Select("https://contexts.com.cn", conf[cli.CTX_COM]))
|
||||
m.Cmd("", mdb.CREATE, ice.SHY, kit.Select(kit.Select("https://shylinux.com", ice.Info.Make.Remote), conf[cli.CTX_SHY]))
|
||||
}},
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.IsSearchPreview(m, arg) {
|
||||
mdb.HashSelectValue(m.Spawn(), func(value ice.Map) {
|
||||
m.PushSearch(mdb.TYPE, LINK, mdb.NAME, kit.Value(value, CLIENT_NAME), mdb.TEXT, kit.Value(value, CLIENT_ORIGIN), value)
|
||||
})
|
||||
if mdb.IsSearchForEach(m, arg, nil) {
|
||||
m.PushSearch(mdb.TYPE, LINK, mdb.NAME, ice.DEV, mdb.TEXT, mdb.HashSelectField(m, ice.DEV, CLIENT_ORIGIN))
|
||||
m.PushSearch(mdb.TYPE, LINK, mdb.NAME, ice.COM, mdb.TEXT, mdb.HashSelectField(m, ice.COM, CLIENT_ORIGIN))
|
||||
m.PushSearch(mdb.TYPE, LINK, mdb.NAME, ice.SHY, mdb.TEXT, mdb.HashSelectField(m, ice.SHY, CLIENT_ORIGIN))
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(ctx.ACTION) {
|
||||
case COOKIE:
|
||||
switch arg[0] {
|
||||
case mdb.KEY:
|
||||
m.Push(arg[0], ice.MSG_SESSID)
|
||||
}
|
||||
case HEADER:
|
||||
switch arg[0] {
|
||||
case mdb.KEY:
|
||||
m.Push(arg[0], html.Authorization)
|
||||
}
|
||||
case CLIENT_NAME:
|
||||
mdb.HashSelectValue(m.Spawn(), func(value ice.Map) {
|
||||
m.Push(arg[0], kit.Value(value, CLIENT_NAME))
|
||||
m.Push(mdb.TYPE, kit.Value(value, CLIENT_TYPE))
|
||||
})
|
||||
m.Sort(arg[0])
|
||||
default:
|
||||
switch arg[0] {
|
||||
case mdb.NAME, mdb.ICONS:
|
||||
m.SplitIndex(m.Cmdx(SPIDE, ice.DEV, kit.MergeURL2(m.Option(ORIGIN), C(SPACE, ice.INFO)))).Cut(arg[0])
|
||||
mdb.HashInputs(m, arg)
|
||||
default:
|
||||
mdb.HashSelectValue(m.Spawn(), func(value ice.Map) {
|
||||
m.Push(kit.Select(ORIGIN, arg, 0), kit.Value(value, kit.Keys("client", arg[0])))
|
||||
})
|
||||
kit.If(arg[0] == mdb.TYPE, func() { m.Push(arg[0], nfs.REPOS) })
|
||||
m.Sort(arg[0])
|
||||
}
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create origin* name icons type token", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(mdb.TYPE) == nfs.REPOS && (m.Option(mdb.NAME) == "" || m.Option(mdb.ICONS) == "") {
|
||||
msg := m.Spawn().SplitIndex(m.Cmdx(SPIDE, ice.DEV, kit.MergeURL2(m.Option(ORIGIN), C(SPACE, ice.INFO))))
|
||||
if m.OptionDefault(mdb.NAME, msg.Append(mdb.NAME)); msg.Append(mdb.ICONS) != "" {
|
||||
m.OptionDefault(mdb.ICONS, m.Resource(msg.Append(mdb.ICONS), msg.Append(ORIGIN)))
|
||||
}
|
||||
}
|
||||
if u, e := url.Parse(m.Option(ORIGIN)); m.WarnNotValid(e != nil || u.Host == "", m.Option(ORIGIN)) {
|
||||
return
|
||||
} else {
|
||||
m.OptionDefault(mdb.NAME, kit.Split(u.Host, ".:")[0])
|
||||
kit.If(u.Query().Get(TOKEN), func(p string) { m.OptionDefault(TOKEN, p) })
|
||||
_spide_create(m, m.Option(ORIGIN), m.Option(mdb.TYPE), m.Option(mdb.NAME), m.Option(mdb.ICONS), m.Option(TOKEN))
|
||||
}
|
||||
}},
|
||||
COOKIE: {Name: "cookie key* value", Help: "状态量", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashModify(m, m.OptionSimple(CLIENT_NAME), kit.Keys(COOKIE, m.Option(mdb.KEY)), m.Option(mdb.VALUE))
|
||||
}},
|
||||
HEADER: {Name: "header key* value", Help: "请求头", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.HashModify(m, m.OptionSimple(CLIENT_NAME), kit.Keys(HEADER, m.Option(mdb.KEY)), m.Option(mdb.VALUE))
|
||||
}},
|
||||
mdb.CREATE: {Name: "create name link", Hand: func(m *ice.Message, arg ...string) { _spide_create(m, m.Option(mdb.NAME), m.Option(LINK)) }},
|
||||
MERGE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.MergeURL2(m.Cmdv("", arg[0], CLIENT_URL), arg[1], arg[2:]))
|
||||
}},
|
||||
PROXY: {Name: "proxy url size cache upload", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SPIDE, ice.DEV, SPIDE_RAW, http.MethodPost, m.Option(URL), SPIDE_PART, arg[2:])
|
||||
}},
|
||||
"disconn": {Help: "断连", Icon: "bi bi-person-x", Style: "danger", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPACE, cli.CLOSE, kit.Dict(mdb.NAME, m.Option(CLIENT_NAME)))
|
||||
mdb.HashModify(m, mdb.NAME, m.Option(CLIENT_NAME), TOKEN, "")
|
||||
}},
|
||||
DEV_CREATE_TOKEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.OptionDefault(CLIENT_NAME, m.Option(ice.FROM_SPACE))
|
||||
mdb.HashModify(m, m.OptionSimple(CLIENT_NAME, TOKEN))
|
||||
m.Cmd(SPACE, tcp.DIAL, m.Option(CLIENT_NAME)).Sleep300ms()
|
||||
}},
|
||||
DEV_REQUEST_TEXT: {Hand: func(m *ice.Message, arg ...string) { m.Echo(SpaceName(ice.Info.NodeName)) }},
|
||||
}, DevTokenAction(CLIENT_NAME, CLIENT_URL), mdb.ImportantHashAction(mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,icons,client.name,client.url,client.type,token")), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, mdb.HashAction(mdb.SHORT, CLIENT_NAME, mdb.FIELD, "time,client.name,client.url")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 2 || arg[0] == "" || (len(arg) > 3 && arg[3] == "") {
|
||||
list := m.CmdMap(SPACE, mdb.NAME)
|
||||
mdb.HashSelect(m, kit.Slice(arg, 0, 1)...).Table(func(value ice.Maps) {
|
||||
if value[CLIENT_TYPE] == nfs.REPOS {
|
||||
if _, ok := list[value[CLIENT_NAME]]; ok {
|
||||
m.Push(mdb.STATUS, ONLINE).PushButton(mdb.DEV_REQUEST, "disconn", mdb.REMOVE)
|
||||
} else {
|
||||
m.Push(mdb.STATUS, "").PushButton(mdb.DEV_REQUEST, mdb.REMOVE)
|
||||
}
|
||||
} else {
|
||||
m.Push(mdb.STATUS, "").PushButton(mdb.REMOVE)
|
||||
}
|
||||
})
|
||||
kit.If(len(arg) > 0 && arg[0] != "", func() { m.Action(COOKIE, HEADER) })
|
||||
m.Sort("client.type,client.name", []string{nfs.REPOS, "dev_ip", "demo", "mail"})
|
||||
mdb.HashSelect(m, kit.Slice(arg, 0, 1)...).Sort(CLIENT_NAME)
|
||||
} else {
|
||||
_spide_show(m, arg[0], arg[1:]...)
|
||||
}
|
||||
}},
|
||||
http.MethodGet: {Name: "GET url key value run", Hand: func(m *ice.Message, arg ...string) {
|
||||
http.MethodGet: {Name: "GET url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodGet, arg[0], arg[1:]))))
|
||||
}},
|
||||
http.MethodPut: {Name: "PUT url key value run", Hand: func(m *ice.Message, arg ...string) {
|
||||
http.MethodPut: {Name: "PUT url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodPut, arg[0], arg[1:]))))
|
||||
}},
|
||||
http.MethodPost: {Name: "POST url key value run", Hand: func(m *ice.Message, arg ...string) {
|
||||
http.MethodPost: {Name: "POST url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodPost, arg[0], arg[1:]))))
|
||||
}},
|
||||
http.MethodDelete: {Name: "DELETE url key value run", Hand: func(m *ice.Message, arg ...string) {
|
||||
http.MethodDelete: {Name: "DELETE url key value run", Help: "蜘蛛侠", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Formats(kit.UnMarshal(m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodDelete, arg[0], arg[1:]))))
|
||||
}},
|
||||
})
|
||||
nfs.TemplateText = func(m *ice.Message, p string) string {
|
||||
if p := kit.Select(nfs.TemplatePath(m, p), m.Option("_template")); kit.HasPrefix(p, nfs.P, nfs.REQUIRE, ice.HTTP) {
|
||||
return kit.Format(mdb.Cache(ice.Pulse, p, func() ice.Any { return m.Cmdx(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, p) }))
|
||||
} else if p == "" {
|
||||
return ""
|
||||
} else if nfs.Exists(m, p) {
|
||||
return m.Cmdx(nfs.CAT, p)
|
||||
} else if strings.Contains(p, "/pkg/mod/") {
|
||||
ls := strings.Split(p, "/pkg/mod/")
|
||||
return kit.Format(mdb.Cache(ice.Pulse, p, func() ice.Any { return m.Cmdx(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, nfs.REQUIRE+ls[1]) }))
|
||||
} else if strings.Contains(p, "/usr/local/work/") {
|
||||
ls := strings.Split(strings.Split(p, "/usr/local/work/")[1], "/src/")
|
||||
pp := kit.MergeURL2(ice.Info.Make.Domain, "/p/src/"+ls[1]+"?pod="+ls[0])
|
||||
return kit.Format(mdb.Cache(ice.Pulse, p, func() ice.Any { return m.Cmdx(SPIDE, ice.OPS, SPIDE_RAW, http.MethodGet, pp) }))
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
nfs.TemplatePath = func(m *ice.Message, arg ...string) string {
|
||||
if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); nfs.Exists(m, p) {
|
||||
return p + kit.Select("", nfs.PS, len(arg) == 0)
|
||||
} else {
|
||||
p := m.FileURI(ctx.GetCmdFile(m, m.PrefixKey()))
|
||||
if pp := kit.TrimPrefix(path.Join(path.Dir(p), path.Join(arg...)), nfs.P, nfs.REQUIRE); nfs.Exists(m, pp) {
|
||||
return pp
|
||||
}
|
||||
if ice.Info.Important {
|
||||
return kit.MergeURL2(SpideOrigin(m, ice.OPS)+p, path.Join(arg...))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
||||
nfs.DocumentPath = func(m *ice.Message, arg ...string) string {
|
||||
if p := path.Join(nfs.USR_LEARNING_PORTAL, m.PrefixKey(), path.Join(arg...)); nfs.Exists(m, p) {
|
||||
return p + kit.Select("", nfs.PS, len(arg) == 0)
|
||||
} else {
|
||||
return kit.MergeURL2(UserHost(m)+ctx.GetCmdFile(m, m.PrefixKey()), path.Join(arg...))
|
||||
}
|
||||
}
|
||||
nfs.DocumentText = func(m *ice.Message, p string) string {
|
||||
if p := nfs.DocumentPath(m, path.Base(p)); kit.HasPrefix(p, nfs.P, nfs.REQUIRE, ice.HTTP) {
|
||||
return m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodGet, p)
|
||||
} else {
|
||||
return m.Cmdx(nfs.CAT, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func SpideGet(m *ice.Message, arg ...ice.Any) ice.Any {
|
||||
@ -486,59 +300,6 @@ func SpidePost(m *ice.Message, arg ...ice.Any) ice.Any {
|
||||
func SpideDelete(m *ice.Message, arg ...ice.Any) ice.Any {
|
||||
return kit.UnMarshal(m.Cmdx(http.MethodDelete, arg))
|
||||
}
|
||||
func SpideCache(m *ice.Message, link string) *ice.Message {
|
||||
return m.Cmd(Prefix(SPIDE), ice.DEV_IP, SPIDE_CACHE, http.MethodGet, link)
|
||||
}
|
||||
func SpideSave(m *ice.Message, file, link string, cb func(count, total, value int)) *ice.Message {
|
||||
for _, p := range []string{ice.DEV_IP, ice.DEV} {
|
||||
msg := m.Cmd(Prefix(SPIDE), p, SPIDE_SAVE, file, http.MethodGet, link, cb)
|
||||
if !msg.IsErr() {
|
||||
return msg
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
func SpideOrigin(m *ice.Message, name string) string { return m.Cmdv(SPIDE, name, CLIENT_ORIGIN) }
|
||||
func SpideURL(m *ice.Message, name string) string { return m.Cmdv(SPIDE, name, CLIENT_URL) }
|
||||
func SpideList(m *ice.Message) *ice.Message { return m.Copy(AdminCmd(m, SPIDE)) }
|
||||
func SpideReposList(m *ice.Message) *ice.Message {
|
||||
AdminCmd(m, SPIDE).Table(func(value ice.Maps) {
|
||||
if value[CLIENT_TYPE] == nfs.REPOS {
|
||||
m.Push(mdb.NAME, value[CLIENT_NAME])
|
||||
m.Push(mdb.ICONS, value[mdb.ICONS])
|
||||
}
|
||||
})
|
||||
ctx.DisplayInputKey(m, "style", "_nameicon")
|
||||
return m
|
||||
}
|
||||
func PublicIP(m *ice.Message, arg ...string) ice.Any {
|
||||
if len(arg) == 0 {
|
||||
return SpideGet(m, "http://ip-api.com/json")
|
||||
}
|
||||
return mdb.Cache(m, "web.spide.location."+arg[0], func() ice.Any {
|
||||
return kit.Format(kit.Value(SpideGet(m, "http://opendata.baidu.com/api.php?co=&resource_id=6006&oe=utf8", "query", arg[0]), "data.0.location"))
|
||||
})
|
||||
}
|
||||
func HostPort(m *ice.Message, host, port string, arg ...string) string {
|
||||
p := ""
|
||||
if len(arg) > 0 {
|
||||
kit.If(kit.Select("", arg, 0), func(pod string) { p += S(pod) })
|
||||
kit.If(kit.Select("", arg, 1), func(cmd string) { p += C(cmd) })
|
||||
}
|
||||
kit.If(m.Option(ice.LOG_DEBUG) == ice.TRUE, func() { p += "?debug=true" })
|
||||
kit.If(host == "", func() {
|
||||
if u := kit.ParseURL(UserHost(m)); u != nil {
|
||||
host = u.Hostname()
|
||||
}
|
||||
})
|
||||
host = kit.Select("localhost", host)
|
||||
if port == tcp.PORT_443 {
|
||||
return kit.Format("https://%s", host) + p
|
||||
} else if port == tcp.PORT_80 {
|
||||
return kit.Format("http://%s", host) + p
|
||||
} else if port == "" {
|
||||
return kit.Format("%s://%s", UserWeb(m).Scheme, host) + p
|
||||
} else {
|
||||
return kit.Format("http://%s:%s", host, port) + p
|
||||
}
|
||||
func SpideSave(m *ice.Message, file, link string, cb func(int, int, int)) *ice.Message {
|
||||
return m.Cmd(Prefix(SPIDE), ice.DEV, SPIDE_SAVE, file, http.MethodGet, link, cb)
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/gdb"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const (
|
||||
STATS_TABLES = "stats.tables"
|
||||
)
|
||||
const STATS = "stats"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
STATS: {Help: "汇总量", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer ctx.DisplayStory(m, "")
|
||||
if m.Option(ice.MSG_USERPOD) == "" {
|
||||
PushStats(m, "", "", "", "共享总数", SHARE)
|
||||
PushStats(m, "", "", "", "令牌总数", TOKEN)
|
||||
PushStats(m, "", "", "", "注册总数", aaa.APPLY)
|
||||
PushStats(m, "", "", "", "邀请总数", aaa.OFFER)
|
||||
if ice.Info.Username == ice.Info.Make.Username {
|
||||
PushStats(m, "", m.Cmd(aaa.USER).Length()-1, "", "用户总数", aaa.USER)
|
||||
} else {
|
||||
PushStats(m, "", m.Cmd(aaa.USER).Length()-2, "", "用户总数", aaa.USER)
|
||||
}
|
||||
PushStats(m, "", "", "", "会话总数", aaa.SESS)
|
||||
PushStats(m, "", m.Cmd(mdb.SELECT, aaa.ROLE, "", mdb.HASH).Length(), "", "角色总数", aaa.ROLE)
|
||||
PushStats(m, "", "", "", "命令总数", ctx.COMMAND)
|
||||
}
|
||||
gdb.Event(m, STATS_TABLES)
|
||||
PushPodCmd(m, "", arg...)
|
||||
}},
|
||||
})
|
||||
}
|
||||
func StatsAction(arg ...string) ice.Actions {
|
||||
return ice.MergeActions(ice.Actions{
|
||||
STATS_TABLES: {Hand: func(m *ice.Message, _ ...string) {
|
||||
if msg := mdb.HashSelects(m.Spawn()); msg.Length() > 0 {
|
||||
PushStats(m, kit.Keys(m.CommandKey(), mdb.TOTAL), msg.Length(), arg...)
|
||||
}
|
||||
}},
|
||||
}, gdb.EventsAction(STATS_TABLES))
|
||||
}
|
||||
func PushStats(m *ice.Message, name string, value ice.Any, arg ...string) {
|
||||
index := kit.Select(m.ShortKey(), arg, 2)
|
||||
kit.If(name == "", func() { name = kit.Keys(kit.Select("", kit.Split(index, nfs.PT), -1), mdb.TOTAL) })
|
||||
kit.If(value == "", func() { value = m.Cmd(index).Length() })
|
||||
kit.If(value != 0, func() {
|
||||
m.Push(mdb.NAME, name).Push(mdb.VALUE, value).Push(mdb.UNITS, kit.Select("", arg, 0)).Push(ctx.TRANS, kit.Select("", arg, 1)).Push(ctx.INDEX, index)
|
||||
})
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
$project div.list { margin-left:25px; }
|
||||
$project div.item span.exists { color:var(--notice-bg-color); padding:0 var(--input-padding); }
|
||||
$content>div.item { box-shadow:var(--th-box-shadow); border:var(--plugin-border); border-radius:var(--plugin-radius); }
|
||||
$content>div.item:hover { box-shadow:var(--notice-box-shadow); }
|
||||
$content>div.item div.title div.label { font-size:var(--status-font-size); font-weight:normal; margin-top:var(--input-margin); }
|
||||
$content>div.item div.title div.label span { padding:var(--input-padding); padding-right:var(--input-margin); }
|
||||
$content>div.item div.content { height:70px; }
|
@ -1,131 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const STORE = "store"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
STORE: {Name: "store refresh", Help: "商店", Icon: "App Store.png", Role: aaa.VOID, Actions: ice.MergeActions(ice.Actions{
|
||||
ice.AFTER_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
AddPortalProduct(m, "云商店", `
|
||||
每个用户都可以将自己的空间列表,以系统商店的方式分享给其它用户。
|
||||
同样的每个用户,也可以添加任意多个商店,直接将空间下载到本机使用。
|
||||
`, 300.0)
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case ORIGIN:
|
||||
m.Cmd(BROAD).Table(func(value ice.Maps) {
|
||||
m.Push(arg[0], HostPort(m, value[tcp.HOST], value[tcp.PORT]))
|
||||
})
|
||||
}
|
||||
m.Cmdy(SPIDE, mdb.INPUTS, arg)
|
||||
}},
|
||||
mdb.CREATE: {Name: "create origin* name icons", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPIDE, mdb.CREATE, m.OptionSimple("origin,name,icons"), mdb.TYPE, nfs.REPOS)
|
||||
}},
|
||||
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SPIDE, mdb.REMOVE, CLIENT_NAME, m.Option(mdb.NAME))
|
||||
}},
|
||||
tcp.DIAL: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Options(m.Cmd(SPIDE, m.Option(mdb.NAME)).AppendSimple())
|
||||
m.Cmdy(SPIDE, mdb.DEV_REQUEST)
|
||||
}},
|
||||
INSTALL: {Name: "install name*", Hand: func(m *ice.Message, arg ...string) {
|
||||
if !kit.HasPrefixList(arg, ctx.RUN) {
|
||||
m.Cmdy(DREAM, mdb.CREATE, m.OptionSimple(mdb.NAME, nfs.REPOS, nfs.BINARY))
|
||||
m.Cmdy(DREAM, cli.START, m.OptionSimple(mdb.NAME))
|
||||
}
|
||||
ProcessIframe(m, m.Option(mdb.NAME), S(m.Option(mdb.NAME)), arg...)
|
||||
}},
|
||||
PORTAL: {Role: aaa.VOID, Hand: func(m *ice.Message, arg ...string) {
|
||||
ProcessIframe(m, m.Option(mdb.NAME), m.Option(ORIGIN)+S(m.Option(mdb.NAME))+C(m.ActionKey()), arg...)
|
||||
}},
|
||||
OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(mdb.TYPE) == ORIGIN {
|
||||
m.ProcessOpen(m.Option(ORIGIN))
|
||||
} else {
|
||||
m.ProcessOpen(S(m.Option(mdb.NAME)))
|
||||
}
|
||||
}},
|
||||
}, ctx.ConfAction(CLIENT_TIMEOUT, cli.TIME_3s), DREAM), Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.HasPrefixList(arg, ctx.ACTION) {
|
||||
m.Cmdy(DREAM, arg)
|
||||
} else if m.Display("").DisplayCSS(""); len(arg) == 0 {
|
||||
list := m.Spawn(ice.Maps{ice.MSG_FIELDS: ""}).CmdMap(SPACE, mdb.NAME)
|
||||
m.Cmd(SPIDE, arg, kit.Dict(ice.MSG_FIELDS, "time,icons,client.type,client.name,client.origin")).Table(func(value ice.Maps) {
|
||||
kit.If(value[CLIENT_TYPE] == nfs.REPOS && value[CLIENT_NAME] != ice.SHY, func() {
|
||||
kit.If(value[CLIENT_NAME] == ice.OPS, func() { value[CLIENT_ORIGIN] = UserHost(m) })
|
||||
m.Push(mdb.TYPE, ORIGIN).Push(mdb.NAME, value[CLIENT_NAME]).Push(mdb.ICONS, value[mdb.ICONS]).Push(ORIGIN, value[CLIENT_ORIGIN])
|
||||
if _, ok := list[value[CLIENT_NAME]]; ok || kit.IsIn(value[CLIENT_NAME], ice.OPS, ice.DEV) {
|
||||
m.Push(mdb.STATUS, ice.TRUE)
|
||||
} else {
|
||||
m.Push(mdb.STATUS, ice.FALSE)
|
||||
}
|
||||
})
|
||||
})
|
||||
if m.SortStrR(mdb.NAME); ice.Info.NodeType == WORKER || !aaa.IsTechOrRoot(m) {
|
||||
m.Action()
|
||||
} else {
|
||||
m.PushAction(OPEN, tcp.DIAL, mdb.REMOVE).Action(mdb.CREATE)
|
||||
}
|
||||
} else {
|
||||
defer ToastProcess(m, ice.LIST, arg[0])()
|
||||
if arg[0] == ice.OPS && ice.Info.NodeType == SERVER {
|
||||
m.Cmdy(DREAM)
|
||||
return
|
||||
}
|
||||
dream := C(DREAM)
|
||||
origin := SpideOrigin(m, arg[0])
|
||||
kit.If(origin == "", func() { arg[0], origin, dream = ice.DEV, arg[0], arg[0]+dream })
|
||||
// if kit.IsIn(kit.ParseURL(origin).Hostname(), append(m.Cmds(tcp.HOST).Appendv(aaa.IP), tcp.LOCALHOST)...) {
|
||||
// if kit.IsIn(kit.ParseURL(origin).Hostname(), tcp.LOCALHOST) {
|
||||
// origin = m.Option(ice.MSG_USERHOST)
|
||||
// } else {
|
||||
// origin = tcp.PublishLocalhost(m, origin)
|
||||
// }
|
||||
// origin = tcp.PublishLocalhost(m, origin)
|
||||
stat := map[string]int{}
|
||||
list := m.Spawn(ice.Maps{ice.MSG_FIELDS: ""}).CmdMap(SPACE, mdb.NAME)
|
||||
m.SetAppend().Spawn().SplitIndex(m.Cmdx(SPIDE, arg[0], dream, kit.Dict(mdb.ConfigSimple(m, CLIENT_TIMEOUT)))).Table(func(value ice.Maps) {
|
||||
if value[mdb.TYPE] == ORIGIN {
|
||||
return
|
||||
}
|
||||
stat[value[mdb.TYPE]]++
|
||||
if value[nfs.BINARY] == "" {
|
||||
value[nfs.BINARY] = origin + S(value[mdb.NAME])
|
||||
}
|
||||
m.Push("", value, kit.Split("time,type,name,icons,repos,binary,module,version"))
|
||||
if _, ok := list[value[mdb.NAME]]; ok {
|
||||
m.Push(mdb.STATUS, ice.TRUE)
|
||||
} else {
|
||||
m.Push(mdb.STATUS, ice.FALSE)
|
||||
}
|
||||
if value[mdb.TYPE] == SERVER {
|
||||
m.Push(mdb.TEXT, value[mdb.TEXT]).Push(ORIGIN, value[mdb.TEXT]).PushButton()
|
||||
return
|
||||
}
|
||||
m.Push(mdb.TEXT, value[nfs.REPOS]).Push(ORIGIN, origin)
|
||||
button := []ice.Any{PORTAL}
|
||||
if _, ok := list[value[mdb.NAME]]; ok {
|
||||
button = append(button, OPEN)
|
||||
} else if aaa.IsTechOrRoot(m) {
|
||||
button = append(button, INSTALL)
|
||||
}
|
||||
m.PushButton(button...)
|
||||
})
|
||||
m.StatusTimeCount(ORIGIN, origin, stat)
|
||||
}
|
||||
}},
|
||||
})
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user