1
0
forked from x/icebergs
This commit is contained in:
harveyshao 2022-11-26 19:35:27 +08:00
parent a14a231e8a
commit b35ef05a43
11 changed files with 63 additions and 66 deletions

View File

@ -10,7 +10,9 @@ import (
"shylinux.com/x/toolkits/miss"
)
func _hash_fields(m *ice.Message) []string { return kit.Split(kit.Select(HASH_FIELD, m.OptionFields())) }
func _hash_fields(m *ice.Message) []string {
return kit.Split(kit.Select(HASH_FIELD, m.OptionFields()))
}
func _hash_inputs(m *ice.Message, prefix, chain string, field, value string) {
list := map[string]int{}
defer func() {
@ -150,7 +152,9 @@ func HashKey(m *ice.Message) string {
}
return HashShort(m)
}
func HashShort(m *ice.Message) string { return kit.Select(HASH, m.Config(SHORT), m.Config(SHORT) != UNIQ) }
func HashShort(m *ice.Message) string {
return kit.Select(HASH, m.Config(SHORT), m.Config(SHORT) != UNIQ)
}
func HashField(m *ice.Message) string { return kit.Select(HASH_FIELD, m.Config(FIELD)) }
func HashInputs(m *ice.Message, arg ...Any) *ice.Message {
return m.Cmdy(INPUTS, m.PrefixKey(), "", HASH, arg)
@ -159,7 +163,7 @@ func HashCreate(m *ice.Message, arg ...Any) string {
if len(arg) == 0 {
arg = append(arg, m.OptionSimple(HashField(m)))
}
return m.Echo(m.Cmdx(INSERT, m.PrefixKey(), "", HASH, arg)).Result()
return m.Echo(m.Cmdx(append(kit.List(INSERT, m.PrefixKey(), "", HASH), arg...)...)).Result()
}
func HashRemove(m *ice.Message, arg ...Any) *ice.Message {
if args := kit.Simple(arg); len(args) == 0 {

View File

@ -15,10 +15,8 @@ func Render(msg *ice.Message, cmd string, arg ...ice.Any) (res string) {
msg.Resultv(args)
}
res = msg.Result()
case ice.RENDER_VOID:
return res
default:
if res = msg.Result(); res == "" {
res = msg.Table().Result()

View File

@ -13,7 +13,6 @@ import (
ice "shylinux.com/x/icebergs"
"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"
kit "shylinux.com/x/toolkits"
@ -42,7 +41,7 @@ func (f *Frame) prompt(m *ice.Message, list ...string) *Frame {
if len(list) == 0 {
list = append(list, f.ps1...)
}
fmt.Fprintf(f.stdout, "\r")
fmt.Fprintf(f.stdout, "\r\033[2K")
for _, v := range list {
switch v {
case mdb.COUNT:
@ -104,13 +103,13 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
if msg.Cmdy(ls); h == STDIO && msg.IsErrNotFound() {
msg.SetResult().Cmdy(cli.SYSTEM, ls)
}
f.res = Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]ice.Any)...)
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 {
f.ps1 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS1)))
f.ps2 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS2)))
m.Optionv("message", m)
m.Optionv(MESSAGE, m)
m.I, m.O = f.stdin, f.stdout
ps, bio := f.ps1, bufio.NewScanner(f.stdin)
for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) {
@ -161,8 +160,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
f.pipe, f.stdin, f.stdout = w, r, os.Stdout
m.Option(ice.MSG_OPTS, ice.MSG_USERNAME, ice.MSG_USERROLE)
f.scan(m, STDIO, "")
default: // 脚本文件
default:
if m.Option(ice.MSG_SCRIPT) != "" {
ls := kit.Split(m.Option(ice.MSG_SCRIPT), ice.PS)
for i := len(ls) - 1; i > 0; i-- {
@ -173,15 +171,13 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
}
m.Option(ice.MSG_SCRIPT, f.source)
f.target = m.Source()
if msg := m.Cmd(nfs.CAT, f.source); msg.IsErr() {
return true // 查找失败
return true
} else {
buf := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
f.stdin, f.stdout = bytes.NewBufferString(msg.Result()), buf
defer func() { m.Echo(buf.String()) }()
}
f.scan(m, "", "")
}
return true
@ -198,50 +194,54 @@ func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server
}
const (
MESSAGE = "message"
FRAME = "frame"
STDIO = "stdio"
PS1 = "PS1"
PS2 = "PS2"
SOURCE_STDIO = "source.stdio"
)
const (
SCRIPT = "script"
SOURCE = "source"
RETURN = "return"
TARGET = "target"
PROMPT = "prompt"
PRINTF = "printf"
SCREEN = "screen"
RETURN = "return"
)
func init() {
Index.MergeCommands(ice.Commands{
SOURCE: {Name: "source file", Help: "脚本解析", Actions: mdb.HashAction(), Hand: func(m *ice.Message, arg ...string) {
SOURCE: {Name: "source file run", Help: "脚本解析", Actions: mdb.HashAction(), Hand: func(m *ice.Message, arg ...string) {
if f, ok := m.Target().Server().(*Frame); ok {
f.Spawn(m, m.Target()).Start(m, arg...)
}
}},
RETURN: {Name: "return run", Help: "结束脚本", Hand: func(m *ice.Message, arg ...string) {
if f, ok := m.Optionv(FRAME).(*Frame); ok {
f.Close(m, arg...)
}
}},
TARGET: {Name: "target name run", Help: "当前模块", Hand: func(m *ice.Message, arg ...string) {
f := m.Target().Server().(*Frame)
if f, ok := m.Target().Server().(*Frame); ok {
m.Search(arg[0]+ice.PT, func(p *ice.Context, s *ice.Context) { f.target = s })
f.prompt(m)
}
}},
PROMPT: {Name: "prompt arg run", Help: "命令提示", Actions: mdb.AutoConfig(
PROMPT: {Name: "prompt arg run", Help: "命令提示", Actions: ctx.ConfAction(
PS1, []ice.Any{"\033[33;44m", mdb.COUNT, "[", mdb.TIME, "]", "\033[5m", TARGET, "\033[0m", "\033[44m", ">", "\033[0m ", "\033[?25h", "\033[32m"},
PS2, []ice.Any{mdb.COUNT, " ", TARGET, "> "},
), Hand: func(m *ice.Message, arg ...string) {
if f, ok := m.Optionv(FRAME).(*Frame); ok {
if f, ok := m.Target().Server().(*Frame); ok {
f.prompt(m, arg...)
}
}},
PRINTF: {Name: "printf run text", Help: "输出显示", Hand: func(m *ice.Message, arg ...string) {
if f, ok := m.Optionv(FRAME).(*Frame); ok {
if f, ok := m.Target().Server().(*Frame); ok {
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.Optionv(FRAME).(*Frame); ok {
if f, ok := m.Target().Server().(*Frame); ok {
for _, line := range kit.Split(arg[0], ice.NL, ice.NL) {
fmt.Fprintf(f.pipe, line+ice.NL)
f.printf(m, line+ice.NL)
@ -250,10 +250,5 @@ func init() {
m.Echo(f.res)
}
}},
RETURN: {Name: "return", Help: "结束脚本", Hand: func(m *ice.Message, arg ...string) {
if f, ok := m.Optionv(FRAME).(*Frame); ok {
f.Close(m, arg...)
}
}},
})
}

View File

@ -6,4 +6,4 @@ const SSH = "ssh"
var Index = &ice.Context{Name: SSH, Help: "终端模块"}
func init() { ice.Index.Register(Index, &Frame{}, SOURCE, TARGET, PROMPT, PRINTF, SCREEN, RETURN) }
func init() { ice.Index.Register(Index, &Frame{}, SOURCE, RETURN, TARGET, PROMPT, PRINTF, SCREEN) }

View File

@ -311,6 +311,9 @@ func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWr
}
const (
SERVE_START = "serve.start"
SERVE_STOP = "serve.stop"
WEB_LOGIN = "_login"
SSO = "sso"
@ -320,29 +323,17 @@ const (
const SERVE = "serve"
func init() {
Index.Merge(&ice.Context{Configs: ice.Configs{
SERVE: {Name: SERVE, Help: "服务器", Value: kit.Data(
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,proto,host,port,dev",
tcp.LOCALHOST, ice.TRUE, LOGHEADERS, ice.FALSE,
nfs.PATH, kit.Dict(ice.PS, ice.USR_VOLCANOS),
ice.VOLCANOS, kit.Dict(nfs.PATH, ice.USR_VOLCANOS, INDEX, "page/index.html",
nfs.REPOS, "https://shylinux.com/x/volcanos", nfs.BRANCH, nfs.MASTER,
),
ice.INTSHELL, kit.Dict(nfs.PATH, ice.USR_INTSHELL, INDEX, ice.INDEX_SH,
nfs.REPOS, "https://shylinux.com/x/intshell", nfs.BRANCH, nfs.MASTER,
),
)},
}, Commands: ice.Commands{
Index.MergeCommands(ice.Commands{
SERVE: {Name: "serve name auto start spide", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
cli.NodeInfo(m, ice.Info.PathName, WORKER)
for _, p := range []string{LOGIN, SHARE, SPACE, ice.VOLCANOS, ice.INTSHELL, ice.PUBLISH, ice.REQUIRE, ice.HELP, ice.CMD} {
m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, p)
}
gdb.Watch(m, SERVE_START)
_serve_rewrite(m)
gdb.Watch(m, ssh.SOURCE_STDIO)
}},
ssh.SOURCE_STDIO: {Name: "source.stdio", Help: "终端", Hand: func(m *ice.Message, arg ...string) {
SERVE_START: {Name: "source.stdio", Help: "终端", Hand: func(m *ice.Message, arg ...string) {
m.Go(func() {
m.Sleep("2s")
url := m.Cmdx(SPACE, DOMAIN)
@ -363,7 +354,17 @@ func init() {
cli.START: {Name: "start dev proto=http host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) {
_serve_start(m)
}},
}, mdb.HashAction())},
}, mdb.HashAction(
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,proto,host,port,dev",
tcp.LOCALHOST, ice.TRUE, LOGHEADERS, ice.FALSE,
nfs.PATH, kit.Dict(ice.PS, ice.USR_VOLCANOS),
ice.VOLCANOS, kit.Dict(nfs.PATH, ice.USR_VOLCANOS, INDEX, "page/index.html",
nfs.REPOS, "https://shylinux.com/x/volcanos", nfs.BRANCH, nfs.MASTER,
),
ice.INTSHELL, kit.Dict(nfs.PATH, ice.USR_INTSHELL, INDEX, ice.INDEX_SH,
nfs.REPOS, "https://shylinux.com/x/intshell", nfs.BRANCH, nfs.MASTER,
),
))},
PP(ice.INTSHELL): {Name: "/intshell/", Help: "命令行", Hand: func(m *ice.Message, arg ...string) {
RenderIndex(m, ice.INTSHELL, arg...)
@ -399,7 +400,7 @@ func init() {
}
m.Cmdy("web.chat./cmd/", arg)
}},
}})
})
ice.AddMerges(func(c *ice.Context, key string, cmd *ice.Command, sub string, action *ice.Action) (ice.Handler, ice.Handler) {
if strings.HasPrefix(sub, ice.PS) {
if sub = kit.Select(sub, PP(key), sub == ice.PS); action.Hand == nil {

View File

@ -13,7 +13,6 @@ import (
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/ssh"
"shylinux.com/x/icebergs/base/tcp"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/toolkits/file"
@ -155,7 +154,7 @@ func init() {
if mdb.HashSelect(m, arg...); len(arg) > 0 {
link := _share_link(m, P(SHARE, arg[0]))
m.PushQRCode(cli.QRCODE, link)
m.PushScript(ssh.SCRIPT, link)
m.PushScript(nfs.SCRIPT, link)
m.PushAnchor(link)
} else {
m.Action(LOGIN)

View File

@ -302,6 +302,9 @@ func init() {
if mdb.HashSelect(m, arg...); len(arg) > 0 {
m.Sort("type,name,text")
}
if m.IsCliUA() {
return
}
m.Tables(func(value ice.Maps) {
if msg := gdb.Event(m.Spawn(), DREAM_TABLES, mdb.NAME, value[mdb.NAME], mdb.TYPE, value[mdb.TYPE]); len(msg.Appendv(ctx.ACTION)) > 0 {
m.PushButton(strings.Join(msg.Appendv(ctx.ACTION), ""))

View File

@ -109,8 +109,6 @@ func (frame *Frame) Close(m *ice.Message, arg ...string) bool {
}
const (
SERVE_START = "serve.start"
SERVE_STOP = "serve.stop"
WEBSITE = "website"
CODE_INNER = "web.code.inner"

View File

@ -8,7 +8,7 @@ import (
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/gdb"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/ssh"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
@ -98,7 +98,7 @@ func init() {
text = web.MergeLink(m, text)
text = tcp.ReplaceLocalhost(m, text)
}
m.PushScript(ssh.SCRIPT, text)
m.PushScript(nfs.SCRIPT, text)
m.PushQRCode(cli.QRCODE, text)
}
m.Tables(func(value ice.Maps) {

View File

@ -8,7 +8,6 @@ import (
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/ssh"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
)
@ -189,7 +188,7 @@ func init() {
m.Option(nfs.FILE, path.Join(m.Option(mdb.ZONE), kit.Keys(m.Option(mdb.NAME), GO)))
_autogen_version(m.Spawn())
}},
ssh.SCRIPT: {Name: "script", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
nfs.SCRIPT: {Name: "script", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
m.Cmd(nfs.DEFS, ice.ETC_MISS_SH, _miss_script)
defer m.Cmdy(nfs.CAT, ice.ETC_MISS_SH)

View File

@ -9,7 +9,7 @@ import (
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/gdb"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/ssh"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/core/chat"
@ -27,7 +27,7 @@ func _wx_sign(m *ice.Message, nonce, stamp string) string {
}
func _wx_config(m *ice.Message, nonce string) {
m.Option(APPID, m.Config(APPID))
m.Option(ssh.SCRIPT, m.Config(ssh.SCRIPT))
m.Option(nfs.SCRIPT, m.Config(nfs.SCRIPT))
m.Option("signature", _wx_sign(m, m.Option("noncestr", nonce), m.Option("timestamp", kit.Format(time.Now().Unix()))))
}
func _wx_check(m *ice.Message) {
@ -102,7 +102,7 @@ func init() {
CHECK: {Name: "check", Help: "检验", Hand: func(m *ice.Message, arg ...string) {
_wx_check(m)
}},
}, mdb.HashAction(tcp.SERVER, "https://api.weixin.qq.com", ssh.SCRIPT, "/plugin/local/chat/wx.js")), Hand: func(m *ice.Message, arg ...string) {
}, mdb.HashAction(tcp.SERVER, "https://api.weixin.qq.com", nfs.SCRIPT, "/plugin/local/chat/wx.js")), Hand: func(m *ice.Message, arg ...string) {
m.Echo(m.Config(APPID))
}},
})