diff --git a/base/web/matrix.go b/base/web/matrix.go index ea9c132e..ea23be97 100644 --- a/base/web/matrix.go +++ b/base/web/matrix.go @@ -17,7 +17,7 @@ import ( func _matrix_list(m *ice.Message, domain string, fields ...string) (server []string) { value := kit.Dict(cli.ParseMake(m.Cmdx(Space(m, domain), cli.RUNTIME))) value[DOMAIN], value[mdb.TYPE], value[mdb.ICONS] = domain, SERVER, kit.Select(nfs.USR_ICONS_ICEBERGS, ice.SRC_MAIN_ICO, domain == "") - button := []ice.Any{PORTAL, ADMIN, DESKTOP, XTERM, UPGRADE, cli.RUNTIME, WORD, STATUS, VIMER, OPEN} + button := []ice.Any{PORTAL, ADMIN, DESKTOP, OPEN, UPGRADE, cli.RUNTIME, WORD, STATUS, VIMER, XTERM} if domain == "" { button = []ice.Any{PORTAL, WORD, STATUS, VIMER, COMPILE, cli.RUNTIME, XTERM, ADMIN, DESKTOP, OPEN} } diff --git a/base/web/process.go b/base/web/process.go index 40ba5f8d..aabb0128 100644 --- a/base/web/process.go +++ b/base/web/process.go @@ -1,6 +1,8 @@ package web import ( + "strings" + ice "shylinux.com/x/icebergs" "shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/mdb" @@ -38,5 +40,5 @@ func ProcessHashPodCmd(m *ice.Message, arg ...string) (msg *ice.Message) { func processSpace(m *ice.Message, pod string, arg ...string) { m.ProcessField(ctx.ACTION, m.ActionKey(), ctx.RUN, arg) m.RewriteAppend(func(value, key string, index int) string { return kit.Select("", value, key != SPACE) }) - m.Push(ice.MSG_SPACE, pod) + m.Push(ice.MSG_SPACE, strings.TrimPrefix(pod, "ops.")) } diff --git a/base/web/render.go b/base/web/render.go index 2e18f97b..ddaff84b 100644 --- a/base/web/render.go +++ b/base/web/render.go @@ -80,6 +80,8 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool { 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, + "task.id", "work.id", "space.timeout", + ice.MSG_USERWEB0, ice.MSG_USERPOD0, ) } m.Render(ice.RENDER_VOID) diff --git a/base/web/space.go b/base/web/space.go index b08a2325..a69e1c43 100644 --- a/base/web/space.go +++ b/base/web/space.go @@ -141,8 +141,7 @@ func _space_handle(m *ice.Message, safe bool, name string, c *websocket.Conn) { 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:])) + msg.Options(ice.MSG_USERWEB, value[mdb.TEXT], ice.MSG_USERPOD, kit.Keys(target[1:])) }) _space_echo(msg, source, target, c) case ice.Handler: // 接收响应 @@ -212,14 +211,15 @@ func _space_send(m *ice.Message, name string, arg ...string) (h string) { } if target := kit.Split(name, nfs.PT, nfs.PT); !mdb.HashSelectDetail(m, target[0], func(value ice.Map) { if c, ok := value[mdb.TARGET].(*websocket.Conn); !m.WarnNotValid(!ok, mdb.TARGET) { - kit.If(kit.Format(value[mdb.TYPE]) == MASTER, func() { - m.Options( - ice.MSG_USERWEB0, m.Option(ice.MSG_USERWEB), ice.MSG_USERPOD0, name, - ice.MSG_USERWEB, value[mdb.TEXT], ice.MSG_USERPOD, "", ice.MSG_USERHOST, "", - ) + kit.If(kit.Format(value[mdb.TYPE]) == MASTER && value[mdb.NAME] != ice.OPS, func() { + m.Options(ice.MSG_USERWEB, value[mdb.TEXT], ice.MSG_USERPOD, "", ice.MSG_USERHOST, "", ice.MSG_USERWEB0, m.Option(ice.MSG_USERWEB), ice.MSG_USERPOD0, name) }) kit.For([]string{ice.MSG_USERROLE, ice.LOG_TRACEID}, func(k string) { m.Optionv(k, m.Optionv(k)) }) - kit.For(m.Optionv(ice.MSG_OPTS), func(k string) { m.Optionv(k, m.Optionv(k)) }) + kit.For(m.Optionv(ice.MSG_OPTS), func(k string) { + kit.If(!kit.IsIn(k, "task.id", "work.id"), func() { + m.Optionv(k, m.Optionv(k)) + }) + }) if withecho { _space_echo(m.Set(ice.MSG_DETAIL, arg...), []string{h}, target, c) } else { @@ -339,7 +339,7 @@ func init() { }) m.Sort("", kit.Simple(aaa.LOGIN, WEIXIN, PORTAL, WORKER, SERVER, MASTER)) } else { - m.OptionDefault(ice.MSG_USERPOD, arg[0]) + // m.OptionDefault(ice.MSG_USERPOD, arg[0]) for i := 0; i < 5; i++ { if _space_send(m, arg[0], kit.Simple(kit.Split(arg[1]), arg[2:])...); !m.IsErrNotFound() { break diff --git a/misc/ssh/relay/matrix.go b/misc/ssh/relay/matrix.go index 65d649fa..377c2892 100644 --- a/misc/ssh/relay/matrix.go +++ b/misc/ssh/relay/matrix.go @@ -21,23 +21,25 @@ type matrix struct { 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 { + if value[web.SPACE] == ice.CONTEXTS { + m.PushButton(s.Portal, s.Desktop, s.Admin, s.Open, s.Word, s.Status, s.Vimer, s.Compile, s.Runtime, s.Xterm) + } else if value[MACHINE] == tcp.LOCALHOST { 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.Xterm, s.Vimer, s.Runtime, s.Desktop, s.Admin, s.Open) + m.PushButton(s.Portal, s.Vimer, s.Runtime, s.Xterm, s.Desktop, s.Admin, s.Open) } }).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) 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) Open(m *ice.Message, arg ...string) { s.open(m, arg...) } func (s matrix) Word(m *ice.Message, arg ...string) { s.plug(m, arg...) } 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) { 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) Open(m *ice.Message, arg ...string) { s.open(m, arg...) } func init() { ice.Cmd("ssh.matrix", matrix{}) } @@ -45,21 +47,17 @@ 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), - ), m.ActionKey(), arg, arg...) + m.ProcessPodCmd(kit.Keys(kit.Select("", ice.OPS, ice.Info.NodeType == web.WORKER), m.Option(MACHINE), m.Option(web.SPACE)), 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 { + if m.Option(MACHINE) == "" { 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)) }) + kit.If(m.Option(web.SPACE), 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)) }) @@ -68,22 +66,18 @@ func (s matrix) iframe(m *ice.Message, arg ...string) { m.ProcessIframe(s.title(m), s.link(m), arg...) } func (s matrix) open(m *ice.Message, arg ...string) { - if kit.HasPrefixList(arg, ctx.RUN) || m.Option(MACHINE) == tcp.LOCALHOST { + if kit.HasPrefixList(arg, ctx.RUN) || m.Option(MACHINE) == "" { 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) { - 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.Option(MACHINE), func(p string) { res = m.Cmd(SSH_RELAY, p).Append(mdb.LINK) }) + kit.If(m.Option(web.SPACE), func(p string) { res += web.S(p) }) 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), - )) + return kit.Select(ice.CONTEXTS, kit.Keys(m.Option(MACHINE), m.Option(web.SPACE), kit.Select("", m.ActionKey(), m.ActionKey() != web.OPEN))) } diff --git a/misc/ssh/relay/matrix.js b/misc/ssh/relay/matrix.js index dc5a5a3d..fbb3dd2e 100644 --- a/misc/ssh/relay/matrix.js +++ b/misc/ssh/relay/matrix.js @@ -1,27 +1,24 @@ Volcanos(chat.ONIMPORT, { - _init: function(can, msg) { var list = {"contexts": {}}, machine = ["localhost"] - msg.Table(function(value) { var space = value.space, _machine = value.machine; + _init: function(can, msg) { var list = {"": {}}, machine = [""] + msg.Table(function(value) { + if (value.space == ice.CONTEXTS) { value.space = "" } + if (value.machine == tcp.LOCALHOST) { value.machine = "" } + var space = value.space, _machine = value.machine; machine.indexOf(_machine) == -1 && (machine.push(_machine)) - list[space] = list[space]||{}, list[space][_machine] = value }) + list[space] = list[space]||{}, list[space][_machine] = value + }) can.ui = can.page.Appends(can, can._output, [{view: [wiki.CONTENT, html.TABLE], list: [ {type: html.THEAD, list: [{type: html.TR, list: can.core.List(machine, function(machine) { - return {type: html.TH, list: [can.onimport.item(can, list["contexts"][machine], list)]} + return {type: html.TH, list: [can.onimport.item(can, list[""][machine], list)]} }) }]}, - {type: html.TBODY, list: can.core.Item(list, function(space, value) { if (space == "contexts") { return } + {type: html.TBODY, list: can.core.Item(list, function(space, value) { if (space == "") { return } return {type: html.TR, list: can.core.List(machine, function(machine) { var item = value[machine] return {type: html.TD, list: [item? can.onimport.item(can, item, list): can.onimport.void(can, space, machine, list)]} })} })}, ] }]), can.onmotion.delay(can, function() { can.Status(mdb.COUNT, can.core.Item(list).length+"x"+can.core.Item(machine).length) }) }, - void: function(can, space, machine, list) { - return - return {view: html.ACTION, _init: function(target) { var worker = list[space]["localhost"], server = list["contexts"][machine] - worker && can.onappend.input(can, {type: html.BUTTON, name: code.INSTALL, onclick: function(event) { - can.Update(can.request(event, {space: space, machine: machine}, worker), [ctx.ACTION, code.INSTALL]) - }}, "", target) - }} - }, + void: function(can, space, machine, list) {}, item: function(can, item, list) { function cb(action) { return function(event) { can.Update(can.request(event, item), [ctx.ACTION, action]) } } return {view: [[html.ITEM, item.type, item.status, can.onimport.style(can, item, list)]], list: [ @@ -32,7 +29,7 @@ Volcanos(chat.ONIMPORT, { ]}, ]} }, - style: function(can, item, list) { var space = item.space, machine = item.machine, worker = list[space]["localhost"] + style: function(can, item, list) { var space = item.space, machine = item.machine, worker = list[space][""] return !worker? html.NOTICE: (worker.status != cli.STOP && item.status != cli.STOP && (item.version != worker.version || item.time < worker.time))? html.DANGER: "" }, }, [""]) diff --git a/misc/websocket/websocket.go b/misc/websocket/websocket.go index 09ee359b..0d6a1a62 100644 --- a/misc/websocket/websocket.go +++ b/misc/websocket/websocket.go @@ -10,6 +10,8 @@ import ( "shylinux.com/x/websocket" ) +const bufs = 10 * ice.MOD_BUFS + type Conn struct { *websocket.Conn lock task.Lock @@ -20,10 +22,10 @@ func (c *Conn) WriteMessage(messageType int, data []byte) error { return c.Conn.WriteMessage(messageType, data) } func Upgrade(w http.ResponseWriter, r *http.Request) (*Conn, error) { - conn, e := websocket.Upgrade(w, r, nil, ice.MOD_BUFS, ice.MOD_BUFS) + conn, e := websocket.Upgrade(w, r, nil, bufs, bufs) return &Conn{Conn: conn}, e } func NewClient(c net.Conn, u *url.URL) (*Conn, error) { - conn, _, e := websocket.NewClient(c, u, nil, ice.MOD_BUFS, ice.MOD_BUFS) + conn, _, e := websocket.NewClient(c, u, nil, bufs, bufs) return &Conn{Conn: conn}, e }