From b122d1021c187bbd31f51073b5117b5cee5e0d57 Mon Sep 17 00:00:00 2001 From: shy Date: Mon, 25 Dec 2023 11:21:32 +0800 Subject: [PATCH] opt relay --- base/web/route.go | 12 +++++++++--- misc/ssh/relay/relay.go | 24 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/base/web/route.go b/base/web/route.go index fd872fdd..28973aeb 100644 --- a/base/web/route.go +++ b/base/web/route.go @@ -105,10 +105,18 @@ func init() { 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 "commit": + m.Push(key, ice.Info.Make.When) + case "compile": + m.Push(key, ice.Info.Make.Time) + case "boot": + m.Push(key, m.Cmdx(cli.RUNTIME, "boot.time")) case "md5": m.Push(key, ice.Info.Hash) case nfs.SIZE: @@ -118,8 +126,6 @@ func init() { var stats runtime.MemStats runtime.ReadMemStats(&stats) m.Push(key, kit.Format("%s/%s/%s", kit.FmtSize(int64(stats.Sys)), ice.Info.Size, m.Cmdx(nfs.DIR, nfs.SIZE))) - case mdb.TYPE: - m.Push(key, ice.Info.NodeType) case nfs.PATH: m.Push(key, kit.Path("")) case tcp.HOSTNAME: @@ -137,7 +143,7 @@ func init() { kit.If(value[mdb.STATUS] == OFFLINE, func() { mdb.HashRemove(m, SPACE, value[SPACE]) }) }) }}, - }, mdb.HashAction(mdb.SHORT, SPACE, mdb.FIELD, "time,space,type,module,version,md5,size,path,hostname", mdb.SORT, "type,space", html.CHECKBOX, ice.TRUE, mdb.ACTION, ice.MAIN)), Hand: func(m *ice.Message, arg ...string) { + }, mdb.HashAction(mdb.SHORT, SPACE, mdb.FIELD, "time,space,type,module,version,commit,compile,boot,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:])) diff --git a/misc/ssh/relay/relay.go b/misc/ssh/relay/relay.go index 34c99ebf..37c1fae3 100644 --- a/misc/ssh/relay/relay.go +++ b/misc/ssh/relay/relay.go @@ -65,6 +65,7 @@ type relay struct { pubkey string `name:"pubkey" help:"公钥"` version string `name:"version" help:"版本"` stats string `name:"stats machine" help:"采集"` + dream string `name:"dream" help:"空间"` forEach string `name:"forEach machine cmd*:textarea=pwd" help:"遍历"` forFlow string `name:"forFlow machine cmd*:textarea=pwd" help:"流程"` list string `name:"list machine auto" help:"代理"` @@ -164,6 +165,27 @@ func (s relay) Stats(m *ice.Message) { ))...) }) } +func (s relay) Dream(m *ice.Message) { + s.foreach(m, func(msg *ice.Message, cmd []string) { + ssh.CombinedOutput(msg.Message, "contexts/bin/ice.bin web.admin web.route", func(res string) { + _msg := m.Spawn().SplitIndex(res) + _msg.Table(func(value ice.Maps) { + _msg.Push(MACHINE, msg.Option(MACHINE)).Push(tcp.HOST, msg.Option(tcp.HOST)) + switch msg.Option(web.PORTAL) { + case "": + _msg.Push(web.LINK, "") + case tcp.PORT_443: + _msg.Push(web.LINK, kit.Format("https://%s/chat/pod/%s", msg.Option(tcp.HOST), value[web.SPACE])) + case tcp.PORT_80: + _msg.Push(web.LINK, kit.Format("http://%s/chat/pod/%s", msg.Option(tcp.HOST), value[web.SPACE])) + default: + _msg.Push(web.LINK, kit.Format("http://%s:%s/chat/pod/%s", msg.Option(tcp.HOST), msg.Option(web.PORTAL), value[web.SPACE])) + } + }) + m.Copy(_msg.Cut("time,machine,host,space,type,status,module,version,link")) + }) + }) +} func (s relay) ForEach(m *ice.Message, arg ...string) *ice.Message { s.foreach(m, func(msg *ice.Message, cmd []string) { kit.For(cmd, func(cmd string) { @@ -188,7 +210,7 @@ func (s relay) List(m *ice.Message, arg ...string) *ice.Message { if m.Length() == 0 { m.Action(s.Create, s.Compile, s.Publish, s.Pubkey) } else { - m.Action(s.Create, s.Upgrade, s.Version, s.Stats, s.ForEach, s.ForFlow, s.Compile, s.Publish, s.Pubkey) + m.Action(s.Create, s.Upgrade, s.Version, s.Stats, s.Dream, s.ForEach, s.ForFlow, s.Compile, s.Publish, s.Pubkey) } } stats := map[string]int{}