From b35ef05a43ba9e5214cf5a3b38d7f6295f7f07c4 Mon Sep 17 00:00:00 2001 From: harveyshao Date: Sat, 26 Nov 2022 19:35:27 +0800 Subject: [PATCH] opt ssh --- base/mdb/hash.go | 10 +++++--- base/ssh/render.go | 2 -- base/ssh/script.go | 57 ++++++++++++++++++++------------------------ base/ssh/ssh.go | 2 +- base/web/serve.go | 35 ++++++++++++++------------- base/web/share.go | 3 +-- base/web/space.go | 3 +++ base/web/web.go | 4 +--- core/chat/favor.go | 4 ++-- core/code/autogen.go | 3 +-- misc/wx/access.go | 6 ++--- 11 files changed, 63 insertions(+), 66 deletions(-) diff --git a/base/mdb/hash.go b/base/mdb/hash.go index bec12284..d7d66b79 100644 --- a/base/mdb/hash.go +++ b/base/mdb/hash.go @@ -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 { diff --git a/base/ssh/render.go b/base/ssh/render.go index 6fe6f8c0..439ccc57 100644 --- a/base/ssh/render.go +++ b/base/ssh/render.go @@ -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() diff --git a/base/ssh/script.go b/base/ssh/script.go index c65df385..c609b4e1 100644 --- a/base/ssh/script.go +++ b/base/ssh/script.go @@ -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 ( - FRAME = "frame" - STDIO = "stdio" - PS1 = "PS1" - PS2 = "PS2" - - SOURCE_STDIO = "source.stdio" + MESSAGE = "message" + FRAME = "frame" + STDIO = "stdio" + PS1 = "PS1" + PS2 = "PS2" ) 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...) } }}, - TARGET: {Name: "target name run", Help: "当前模块", Hand: func(m *ice.Message, arg ...string) { - f := m.Target().Server().(*Frame) - m.Search(arg[0]+ice.PT, func(p *ice.Context, s *ice.Context) { f.target = s }) - f.prompt(m) + RETURN: {Name: "return run", Help: "结束脚本", Hand: func(m *ice.Message, arg ...string) { + if f, ok := m.Optionv(FRAME).(*Frame); ok { + f.Close(m, arg...) + } }}, - PROMPT: {Name: "prompt arg run", Help: "命令提示", Actions: mdb.AutoConfig( + TARGET: {Name: "target name run", Help: "当前模块", Hand: func(m *ice.Message, arg ...string) { + 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: 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...) - } - }}, }) } diff --git a/base/ssh/ssh.go b/base/ssh/ssh.go index a24cfd94..95ba711c 100644 --- a/base/ssh/ssh.go +++ b/base/ssh/ssh.go @@ -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) } diff --git a/base/web/serve.go b/base/web/serve.go index 19bd6676..74d783ca 100644 --- a/base/web/serve.go +++ b/base/web/serve.go @@ -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 { diff --git a/base/web/share.go b/base/web/share.go index 088ed449..f41e66f9 100644 --- a/base/web/share.go +++ b/base/web/share.go @@ -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) diff --git a/base/web/space.go b/base/web/space.go index d9e5456b..2d7a5e68 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -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), "")) diff --git a/base/web/web.go b/base/web/web.go index 49295e1e..1250c49b 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -109,9 +109,7 @@ func (frame *Frame) Close(m *ice.Message, arg ...string) bool { } const ( - SERVE_START = "serve.start" - SERVE_STOP = "serve.stop" - WEBSITE = "website" + WEBSITE = "website" CODE_INNER = "web.code.inner" WIKI_WORD = "web.wiki.word" diff --git a/core/chat/favor.go b/core/chat/favor.go index cf625082..b12248f9 100644 --- a/core/chat/favor.go +++ b/core/chat/favor.go @@ -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) { diff --git a/core/code/autogen.go b/core/code/autogen.go index 4d24d054..3cb2adb7 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -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) diff --git a/misc/wx/access.go b/misc/wx/access.go index 64417568..f491f408 100644 --- a/misc/wx/access.go +++ b/misc/wx/access.go @@ -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)) }}, })