From 644e80d040eaffcb88e164bc986a29edabaca9ce Mon Sep 17 00:00:00 2001 From: shy Date: Sun, 25 Feb 2024 17:56:11 +0800 Subject: [PATCH] add some --- base/web/render.go | 5 ++- base/web/space.go | 7 ++- conf.go | 1 + core/chat/macos/desktop.go | 3 +- misc/ssh/relay/matrix.go | 92 ++++++++++++++++---------------------- misc/ssh/relay/relay.go | 33 +++++++------- 6 files changed, 66 insertions(+), 75 deletions(-) diff --git a/base/web/render.go b/base/web/render.go index d3b56d0d..2e18f97b 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -26,6 +26,7 @@ const ( RESPONSE = "response" CONTENT = "content" TITLE = "title" + STYLE = "style" ) func Render(m *ice.Message, cmd string, args ...ice.Any) bool { @@ -74,8 +75,8 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool { default: kit.If(cmd != "" && cmd != ice.RENDER_RAW, func() { m.Echo(kit.Format(cmd, args...)) }) RenderType(m.W, nfs.JSON, "") - m.FormatsMeta(m.W, ice.MSG_USERIP, ice.MSG_USERUA, ice.MSG_METHOD, - ice.MSG_USERWEB, ice.MSG_REFERER, ice.MSG_DAEMON, ice.MSG_USERPOD, + 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, diff --git a/base/web/space.go b/base/web/space.go index 12173cf8..b08a2325 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -140,6 +140,10 @@ func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) { m.WarnNotFound(!mdb.HashSelectDetail(m, next, func(value ice.Map) { switch c := value[mdb.TARGET].(type) { case (*websocket.Conn): // 转发报文 + kit.If(value[mdb.TYPE] == MASTER, func() { + msg.Option(ice.MSG_USERWEB, value[mdb.TEXT]) + msg.Option(ice.MSG_USERPOD, kit.Keys(target[1:])) + }) _space_echo(msg, source, target, c) case ice.Handler: // 接收响应 msg.Go(func() { c(msg) }) @@ -185,7 +189,8 @@ func _space_exec(m *ice.Message, name string, source, target []string, c *websoc kit.If(m.Optionv(ice.MSG_ARGS) != nil, func() { m.Options(ice.MSG_ARGS, kit.Simple(m.Optionv(ice.MSG_ARGS))) }) } defer m.Cost(kit.Format("%v->%v %v %v", source, target, m.Detailv(), m.FormatSize())) - _space_echo(m.Set(ice.MSG_OPTS).Options(m.OptionSimple(ice.LOG_DEBUG, ice.LOG_TRACEID)), []string{}, kit.Reverse(kit.Simple(source)), c) + _space_echo(m.Set(ice.MSG_OPTS).Options(m.OptionSimple(ice.MSG_USERWEB, ice.MSG_USERPOD, ice.LOG_DEBUG, ice.LOG_DISABLE, ice.LOG_TRACEID)), []string{}, kit.Reverse(kit.Simple(source)), c) + m.Option(ice.MSG_HANDLE, ice.TRUE) } func _space_echo(m *ice.Message, source, target []string, c *websocket.Conn) { defer func() { m.WarnNotValid(recover()) }() diff --git a/conf.go b/conf.go index 1f4c51d0..6cf01869 100644 --- a/conf.go +++ b/conf.go @@ -193,6 +193,7 @@ const ( // MSG MSG_UPLOAD = "_upload" MSG_SOURCE = "_source" MSG_TARGET = "_target" + MSG_HANDLE = "_handle" MSG_ACTION = "_action" MSG_STATUS = "_status" diff --git a/core/chat/macos/desktop.go b/core/chat/macos/desktop.go index 4a785bef..48139b41 100644 --- a/core/chat/macos/desktop.go +++ b/core/chat/macos/desktop.go @@ -45,7 +45,8 @@ func init() { Notify(m, "usr/icons/Infomation.png", cli.RUNTIME, "系统启动成功", ctx.INDEX, cli.RUNTIME) }}, DESKTOP: {Help: "桌面", Role: aaa.VOID, Actions: ice.MergeActions(ice.Actions{ - web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { web.DreamProcessIframe(m, arg...) }}, + // web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { web.DreamProcessIframe(m, arg...) }}, + // web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { web.DreamProcess(m, "", arg, arg...) }}, }, web.DreamTablesAction(), PodCmdAction(), CmdHashAction(), mdb.ExportHashAction())}, }) } diff --git a/misc/ssh/relay/matrix.go b/misc/ssh/relay/matrix.go index 1f0246dc..65d649fa 100644 --- a/misc/ssh/relay/matrix.go +++ b/misc/ssh/relay/matrix.go @@ -19,18 +19,14 @@ type matrix struct { list string `name:"list refresh" help:"矩阵"` } -func (s matrix) List(m *ice.Message, arg ...string) *ice.Message { - m.Cmdy(SSH_RELAY, web.DREAM) - m.Table(func(value ice.Maps) { +func (s matrix) List(m *ice.Message, arg ...string) { + m.Cmdy(SSH_RELAY, web.DREAM).Table(func(value ice.Maps) { if value[MACHINE] == tcp.LOCALHOST { - m.PushButton(s.Portal, s.Word, s.Status, s.Vimer, s.Compile, s.Runtime, s.Xterm, s.Admin, s.Desktop, s.Open) + m.PushButton(s.Portal, s.Word, s.Status, s.Vimer, s.Compile, s.Runtime, s.Xterm, s.Desktop, s.Admin, s.Open) } else { - m.PushButton(s.Portal, s.Admin, s.Desktop, s.Xterm, s.Runtime, s.Vimer, s.Open) + m.PushButton(s.Portal, s.Xterm, s.Vimer, s.Runtime, s.Desktop, s.Admin, s.Open) } - }) - m.Action(html.FILTER).Display("") - m.Sort("type,status,space,machine", []string{web.SERVER, web.WORKER, ""}, []string{cli.START, cli.STOP, ""}, "str_r", "str") - return m + }).Action(html.FILTER).Display("").Sort("type,status,space,machine", []string{web.SERVER, web.WORKER, ""}, []string{cli.START, cli.STOP, ""}, "str_r", "str") } func (s matrix) Portal(m *ice.Message, arg ...string) { s.iframe(m, arg...) } func (s matrix) Word(m *ice.Message, arg ...string) { s.plug(m, arg...) } @@ -38,48 +34,39 @@ func (s matrix) Status(m *ice.Message, arg ...string) { s.plug(m, arg...) } func (s matrix) Vimer(m *ice.Message, arg ...string) { s.plug(m, arg...) } func (s matrix) Compile(m *ice.Message, arg ...string) { s.plug(m, arg...) } func (s matrix) Runtime(m *ice.Message, arg ...string) { s.plug(m, arg...) } -func (s matrix) Xterm(m *ice.Message, arg ...string) { - m.ProcessXterm(func() []string { - if m.Option(MACHINE) == tcp.LOCALHOST { - p := kit.Select(ice.CONTEXTS) - kit.If(m.Option(web.SPACE) != ice.CONTEXTS, func() { p = path.Join(p, nfs.USR_LOCAL_WORK+m.Option(web.SPACE)) }) - return []string{cli.Shell(m.Message), "", kit.Format("cd ~/%s", p)} - } - msg := m.Cmd(SSH_RELAY, m.Option(MACHINE)) - p := kit.Select(ice.CONTEXTS, msg.Append(web.DREAM)) - kit.If(m.Option(web.SPACE) != ice.CONTEXTS, func() { p = path.Join(p, nfs.USR_LOCAL_WORK+m.Option(web.SPACE)) }) - return []string{m.Option(MACHINE), "", kit.Format("cd ~/%s", p)} - }, arg...) - kit.If(!kit.HasPrefixList(arg, ice.RUN), func() { - m.Push(ctx.STYLE, html.FLOAT) - m.Push(web.TITLE, s.title(m)) - }) -} +func (s matrix) Xterm(m *ice.Message, arg ...string) { s.xterm(m, arg...) } +func (s matrix) Desktop(m *ice.Message, arg ...string) { s.plug(m, arg...) } func (s matrix) Admin(m *ice.Message, arg ...string) { s.open(m, arg...) } -func (s matrix) Desktop(m *ice.Message, arg ...string) { s.open(m, arg...) } func (s matrix) Open(m *ice.Message, arg ...string) { s.open(m, arg...) } func init() { ice.Cmd("ssh.matrix", matrix{}) } -func (s matrix) title(m *ice.Message) string { - return kit.Select("contexts", kit.Keys(kit.Select("", m.Option(MACHINE), m.Option(MACHINE) != tcp.LOCALHOST), +func (s matrix) plug(m *ice.Message, arg ...string) { + if !kit.HasPrefixList(arg, ctx.RUN) { + defer m.Push(web.TITLE, s.title(m)) + } + m.ProcessPodCmd(kit.Keys( + kit.Select("", ice.OPS, ice.Info.NodeType == web.WORKER), + kit.Select("", m.Option(MACHINE), m.Option(MACHINE) != tcp.LOCALHOST), kit.Select("", m.Option(web.SPACE), m.Option(web.SPACE) != ice.CONTEXTS), - kit.Select("", m.ActionKey(), m.ActionKey() != web.OPEN), - )) + ), m.ActionKey(), arg, arg...) +} +func (s matrix) xterm(m *ice.Message, arg ...string) { + m.ProcessXterm(func() []string { + cmd, dir := cli.SH, ice.CONTEXTS + if m.Option(MACHINE) == tcp.LOCALHOST { + cmd = cli.Shell(m.Message) + } else { + cmd, dir = m.Option(MACHINE), kit.Select(dir, m.Cmd(SSH_RELAY, m.Option(MACHINE)).Append(web.DREAM)) + } + kit.If(m.Option(web.SPACE) != ice.CONTEXTS, func() { dir = path.Join(dir, nfs.USR_LOCAL_WORK+m.Option(web.SPACE)) }) + return []string{cmd, "", kit.Format("cd ~/%s", dir)} + }, arg...) + kit.If(!kit.HasPrefixList(arg, ctx.RUN), func() { m.Push(web.STYLE, html.FLOAT).Push(web.TITLE, s.title(m)) }) } func (s matrix) iframe(m *ice.Message, arg ...string) { m.ProcessIframe(s.title(m), s.link(m), arg...) } -func (s matrix) plug(m *ice.Message, arg ...string) { - if kit.HasPrefixList(arg, ctx.RUN) || m.Option(MACHINE) == tcp.LOCALHOST { - m.ProcessFloat(m.ActionKey(), arg, arg...) - if !kit.HasPrefixList(arg, ctx.RUN) { - m.Push(web.TITLE, s.title(m)) - } - } else { - m.ProcessOpen(s.link(m)) - } -} func (s matrix) open(m *ice.Message, arg ...string) { if kit.HasPrefixList(arg, ctx.RUN) || m.Option(MACHINE) == tcp.LOCALHOST { m.ProcessIframe(s.title(m), s.link(m), arg...) @@ -88,16 +75,15 @@ func (s matrix) open(m *ice.Message, arg ...string) { } } func (s matrix) link(m *ice.Message, arg ...string) (res string) { - if m.Option(MACHINE) == tcp.LOCALHOST { - res = m.UserHost() - } else { - res = m.Cmd(SSH_RELAY, m.Option(MACHINE)).Append(mdb.LINK) - } - if m.Option(web.SPACE) != ice.CONTEXTS { - res += web.S(m.Option(web.SPACE)) - } - if m.ActionKey() != web.OPEN { - res += web.C(m.ActionKey()) - } - return + kit.If(m.Option(MACHINE) != tcp.LOCALHOST, func() { res = m.Cmd(SSH_RELAY, m.Option(MACHINE)).Append(mdb.LINK) }) + kit.If(m.Option(web.SPACE) != ice.CONTEXTS, func() { res += web.S(m.Option(web.SPACE)) }) + kit.If(m.ActionKey() != web.OPEN, func() { res += web.C(m.ActionKey()) }) + return kit.Select(nfs.PS, res) +} +func (s matrix) title(m *ice.Message) string { + return kit.Select(ice.CONTEXTS, kit.Keys( + kit.Select("", m.Option(MACHINE), m.Option(MACHINE) != tcp.LOCALHOST), + kit.Select("", m.Option(web.SPACE), m.Option(web.SPACE) != ice.CONTEXTS), + kit.Select("", m.ActionKey(), m.ActionKey() != web.OPEN), + )) } diff --git a/misc/ssh/relay/relay.go b/misc/ssh/relay/relay.go index 1e6ef4f3..01c26e98 100644 --- a/misc/ssh/relay/relay.go +++ b/misc/ssh/relay/relay.go @@ -164,6 +164,7 @@ func (s relay) Dream(m *ice.Message) { } }) }) + fields := "time,machine,host,space,type,status,module,version,commitTime,compileTime,bootTime,link,icons" s.foreach(m, func(msg *ice.Message, cmd []string) { m.Push("", kit.Dict(msg.OptionSimple(fields), mdb.TYPE, web.SERVER, mdb.STATUS, web.ONLINE, web.SPACE, ice.CONTEXTS, web.LINK, web.HostPort(m.Message, msg.Option(tcp.HOST), msg.Option(web.PORTAL))), kit.Split(fields)) @@ -179,33 +180,29 @@ func (s relay) Dream(m *ice.Message) { }).Cut(fields)) }) }) - m.Options(ice.MSG_PROCESS, "") - if m.Action(s.Dream, "filter:text"); tcp.IsLocalHost(m.Message, m.Option(ice.MSG_USERIP)) { - if _msg := m.Cmd(cli.SYSTEM, ice.BIN_ICE_BIN, web.ADMIN, cli.RUNTIME); len(_msg.Result()) > 0 { - m.Push(MACHINE, tcp.LOCALHOST).Push(tcp.HOST, tcp.PublishLocalhost(m.Message, tcp.LOCALHOST)) - m.Push("", kit.Dict(cli.ParseMake(_msg.Result()), ice.SPACE, ice.CONTEXTS), kit.Split("time,space,module,version,commitTime,compileTime,bootTime")) - m.Push(mdb.TYPE, web.SERVER).Push(mdb.STATUS, web.ONLINE).Push(web.LINK, web.UserHost(m.Message)) - m.Push(mdb.ICONS, ice.SRC_MAIN_ICO) - } - if _msg := m.Spawn().SplitIndex(m.Cmdx(cli.SYSTEM, kit.Split(s.admin(m, web.ROUTE)))); _msg.Length() > 0 { - m.Message.Copy(_msg.Table(func(value ice.Maps) { - _msg.Push(MACHINE, tcp.LOCALHOST).Push(tcp.HOST, tcp.PublishLocalhost(m.Message, tcp.LOCALHOST)) - _msg.Push(web.LINK, web.UserHost(m.Message)+web.S(value[web.SPACE])) - }).Cut(fields)) - } - } + + m.Push(MACHINE, tcp.LOCALHOST).Push(tcp.HOST, tcp.PublishLocalhost(m.Message, tcp.LOCALHOST)) + m.Push("", kit.Dict(cli.ParseMake(m.AdminCmd(cli.RUNTIME).Result()), ice.SPACE, ice.CONTEXTS), kit.Split("time,space,module,version,commitTime,compileTime,bootTime")) + m.Push(mdb.TYPE, web.SERVER).Push(mdb.STATUS, web.ONLINE).Push(web.LINK, web.UserHost(m.Message)) + m.Push(mdb.ICONS, ice.SRC_MAIN_ICO) + _msg := m.AdminCmd(web.ROUTE) + m.Message.Copy(_msg.Table(func(value ice.Maps) { + _msg.Push(MACHINE, tcp.LOCALHOST).Push(tcp.HOST, tcp.PublishLocalhost(m.Message, tcp.LOCALHOST)) + _msg.Push(web.LINK, web.UserHost(m.Message)+web.S(value[web.SPACE])) + }).Cut(fields)) + m.RewriteAppend(func(value, key string, index int) string { if key == mdb.ICONS { if value == "" { - value = kit.MergeURL2(m.Appendv(web.LINK)[index], "/require/"+nfs.USR_ICONS_ICEBERGS) + value = kit.MergeURL2(m.Appendv(web.LINK)[index], nfs.REQUIRE+nfs.USR_ICONS_ICEBERGS) } else if strings.HasPrefix(value, nfs.REQUIRE) && m.Appendv(MACHINE)[index] != tcp.LOCALHOST { value = kit.MergeURL2(m.Appendv(web.LINK)[index], value) } else if kit.HasPrefix(value, nfs.USR, nfs.SRC) { - value = m.Option(ice.MSG_USERHOST) + "/require/" + value + value = m.Option(ice.MSG_USERHOST) + nfs.REQUIRE + value } } return value - }) + }).Action(s.Dream, "filter:text").Options(ice.MSG_PROCESS, "") } func (s relay) ForEach(m *ice.Message, arg ...string) *ice.Message { s.foreach(m, func(msg *ice.Message, cmd []string) {