1
0
forked from x/icebergs

opt relay

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-12-25 11:21:32 +08:00
parent d60b1fc1a5
commit b122d1021c
2 changed files with 32 additions and 4 deletions

View File

@ -105,10 +105,18 @@ func init() {
switch key { switch key {
case mdb.TIME: case mdb.TIME:
m.Push(key, ice.Info.Make.Time) m.Push(key, ice.Info.Make.Time)
case mdb.TYPE:
m.Push(key, ice.Info.NodeType)
case nfs.MODULE: case nfs.MODULE:
m.Push(key, ice.Info.Make.Module) m.Push(key, ice.Info.Make.Module)
case nfs.VERSION: case nfs.VERSION:
m.Push(key, ice.Info.Make.Versions()) 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": case "md5":
m.Push(key, ice.Info.Hash) m.Push(key, ice.Info.Hash)
case nfs.SIZE: case nfs.SIZE:
@ -118,8 +126,6 @@ func init() {
var stats runtime.MemStats var stats runtime.MemStats
runtime.ReadMemStats(&stats) 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))) 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: case nfs.PATH:
m.Push(key, kit.Path("")) m.Push(key, kit.Path(""))
case tcp.HOSTNAME: case tcp.HOSTNAME:
@ -137,7 +143,7 @@ func init() {
kit.If(value[mdb.STATUS] == OFFLINE, func() { mdb.HashRemove(m, SPACE, value[SPACE]) }) 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 { if len(arg) > 1 {
_route_match(m, arg[0], func(value ice.Maps, i int, list []ice.Maps) { _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:])) _route_push(m, value[SPACE], m.Cmd(SPACE, value[SPACE], arg[1:]))

View File

@ -65,6 +65,7 @@ type relay struct {
pubkey string `name:"pubkey" help:"公钥"` pubkey string `name:"pubkey" help:"公钥"`
version string `name:"version" help:"版本"` version string `name:"version" help:"版本"`
stats string `name:"stats machine" help:"采集"` stats string `name:"stats machine" help:"采集"`
dream string `name:"dream" help:"空间"`
forEach string `name:"forEach machine cmd*:textarea=pwd" help:"遍历"` forEach string `name:"forEach machine cmd*:textarea=pwd" help:"遍历"`
forFlow string `name:"forFlow machine cmd*:textarea=pwd" help:"流程"` forFlow string `name:"forFlow machine cmd*:textarea=pwd" help:"流程"`
list string `name:"list machine auto" 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 { func (s relay) ForEach(m *ice.Message, arg ...string) *ice.Message {
s.foreach(m, func(msg *ice.Message, cmd []string) { s.foreach(m, func(msg *ice.Message, cmd []string) {
kit.For(cmd, func(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 { if m.Length() == 0 {
m.Action(s.Create, s.Compile, s.Publish, s.Pubkey) m.Action(s.Create, s.Compile, s.Publish, s.Pubkey)
} else { } 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{} stats := map[string]int{}