1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-02-24 23:28:03 +08:00
parent 47d01ecea9
commit dec30e9ad7
3 changed files with 89 additions and 6 deletions

View File

@ -1,18 +1,86 @@
package relay package relay
import ( import (
"path"
"shylinux.com/x/ice" "shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits"
) )
type matrix struct { type matrix struct {
list string `data:"list refresh"` list string `name:"list refresh" help:"矩阵"`
} }
func (s matrix) List(m *ice.Message, arg ...string) *ice.Message { func (s matrix) List(m *ice.Message, arg ...string) *ice.Message {
m.Cmdy("ssh.relay", "dream").Display("") m.Cmdy(SSH_RELAY, web.DREAM).PushAction(s.Portal, s.Admin, s.Desktop, s.Xterm, s.Runtime).Action(html.FILTER).Display("")
m.Sort("type,status,space,machine", []string{web.SERVER, web.WORKER, ""}, []string{cli.START, cli.STOP, ""}, "str_r", "str_r") m.Sort("type,status,space,machine", []string{web.SERVER, web.WORKER, ""}, []string{cli.START, cli.STOP, ""}, "str_r", "str")
return m return m
} }
func (s matrix) Portal(m *ice.Message, arg ...string) { s.iframe(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) 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 init() { ice.Cmd("ssh.matrix", matrix{}) } func init() { ice.Cmd("ssh.matrix", matrix{}) }
func (s matrix) title(m *ice.Message) string {
return kit.Keys(kit.Select("", m.Option(MACHINE), m.Option(MACHINE) != tcp.LOCALHOST), m.Option(web.SPACE), m.ActionKey())
}
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...)
} else {
m.ProcessOpen(s.link(m))
}
}
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
}

View File

@ -1,5 +1,5 @@
Volcanos(chat.ONIMPORT, { Volcanos(chat.ONIMPORT, {
_init: function(can, msg) { var list = {"contexts": {}}, machine = [] _init: function(can, msg) { var list = {"contexts": {}}, machine = ["localhost"]
msg.Table(function(value) { var space = value.space, _machine = value.machine; msg.Table(function(value) { var space = value.space, _machine = value.machine;
machine.indexOf(_machine) == -1 && (machine.push(_machine)) machine.indexOf(_machine) == -1 && (machine.push(_machine))
list[space] = list[space]||{}, list[space][_machine] = value }) list[space] = list[space]||{}, list[space][_machine] = value })

View File

@ -61,9 +61,10 @@ type relay struct {
ice.Code ice.Code
checkbox string `data:"true"` checkbox string `data:"true"`
short string `data:"machine"` short string `data:"machine"`
field string `data:"time,machine,username,host,port,portal,dream,module,version,commitTime,compileTime,bootTime,go,git,package,shell,kernel,arch,ncpu,vcpu,mhz,mem,disk,network,listen,socket,proc,vendor"` tools string `data:"ssh.matrix"`
field string `data:"time,icons,machine,username,host,port,portal,dream,module,version,commitTime,compileTime,bootTime,go,git,package,shell,kernel,arch,ncpu,vcpu,mhz,mem,disk,network,listen,socket,proc,vendor"`
statsTables string `name:"statsTables" event:"stats.tables"` statsTables string `name:"statsTables" event:"stats.tables"`
create string `name:"create machine* username* host* port*=22"` create string `name:"create machine* username* host* port*=22" icons`
stats string `name:"stats machine" help:"采集" icon:"bi bi-card-list"` stats string `name:"stats machine" help:"采集" icon:"bi bi-card-list"`
dream string `name:"dream" help:"空间" icon:"bi bi-grid-3x3-gap"` dream string `name:"dream" help:"空间" icon:"bi bi-grid-3x3-gap"`
forEach string `name:"forEach machine cmd*:textarea=pwd"` forEach string `name:"forEach machine cmd*:textarea=pwd"`
@ -184,6 +185,7 @@ func (s relay) Dream(m *ice.Message) {
m.Push(MACHINE, tcp.LOCALHOST).Push(tcp.HOST, tcp.PublishLocalhost(m.Message, tcp.LOCALHOST)) 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("", 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.TYPE, web.SERVER).Push(mdb.STATUS, web.ONLINE).Push(web.LINK, web.UserHost(m.Message))
m.Push(mdb.ICONS, "src/main.ico")
} }
if _msg := m.Spawn().SplitIndex(m.Cmdx(cli.SYSTEM, kit.Split(s.admin(m, web.ROUTE)))); _msg.Length() > 0 { 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) { m.Message.Copy(_msg.Table(func(value ice.Maps) {
@ -192,6 +194,19 @@ func (s relay) Dream(m *ice.Message) {
}).Cut(fields)) }).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)
} 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
}
}
return value
})
} }
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) {