From 46f57dbbb5db2b1ccab3f20e093ceef070a3b8b1 Mon Sep 17 00:00:00 2001 From: shy Date: Wed, 20 Mar 2024 11:55:42 +0800 Subject: [PATCH] add some --- misc/ssh/auth.go | 28 ++++++++++++ misc/ssh/relay/matrix.css | 25 ----------- misc/ssh/relay/matrix.go | 90 --------------------------------------- misc/ssh/relay/matrix.js | 35 --------------- misc/ssh/relay/relay.shy | 2 - 5 files changed, 28 insertions(+), 152 deletions(-) create mode 100644 misc/ssh/auth.go delete mode 100644 misc/ssh/relay/matrix.css delete mode 100644 misc/ssh/relay/matrix.go delete mode 100644 misc/ssh/relay/matrix.js delete mode 100644 misc/ssh/relay/relay.shy diff --git a/misc/ssh/auth.go b/misc/ssh/auth.go new file mode 100644 index 00000000..27629192 --- /dev/null +++ b/misc/ssh/auth.go @@ -0,0 +1,28 @@ +package ssh + +import ( + "strings" + + ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/mdb" + "shylinux.com/x/icebergs/base/nfs" + psh "shylinux.com/x/icebergs/base/ssh" + kit "shylinux.com/x/toolkits" +) + +func init() { + const ( + AUTH = "auth" + ) + psh.Index.MergeCommands(ice.Commands{ + AUTH: {Name: "auth list", Help: "连接", Hand: func(m *ice.Message, arg ...string) { + m.Cmd(nfs.CAT, kit.HomePath(m.Option(AUTHKEY)), func(pub string) { + if ls := kit.Split(pub); len(ls) > 2 { + m.Push(mdb.TYPE, ls[0]) + m.Push(mdb.NAME, ls[len(ls)-1]) + m.Push(mdb.TEXT, strings.Join(ls[1:len(ls)-1], "+")) + } + }) + }}, + }) +} diff --git a/misc/ssh/relay/matrix.css b/misc/ssh/relay/matrix.css deleted file mode 100644 index be232485..00000000 --- a/misc/ssh/relay/matrix.css +++ /dev/null @@ -1,25 +0,0 @@ -fieldset.ssh.matrix>div.output>table.content th { padding:var(--input-padding); } -fieldset.ssh.matrix>div.output>table.content th i { padding:var(--input-padding); } -fieldset.ssh.matrix>div.output>table.content th i:hover { background-color:var(--hover-bg-color); color:var(--hover-fg-color); } -fieldset.ssh.matrix>div.output>table.content td { padding:var(--input-padding); } -fieldset.ssh.matrix>div.output>table.content td:hover { color:unset; } -fieldset.ssh.matrix>div.output>table.content div.item { display:flex; align-items:center; cursor:default; } -fieldset.ssh.matrix>div.output>table.content div.item img { height:var(--header-height); width:var(--header-height); margin:var(--input-margin); cursor:pointer; } -fieldset.ssh.matrix>div.output>table.content div.item div.title { text-align:left; padding:var(--input-padding); } -fieldset.ssh.matrix>div.output>table.content div.item div.title>span { cursor:pointer; } -fieldset.ssh.matrix>div.output>table.content div.item div.status i { font-size:var(--status-font-size); padding:0; } -fieldset.ssh.matrix>div.output>table.content div.item div.action { margin-top:var(--input-margin); overflow:hidden; } -fieldset.ssh.matrix>div.output>table.content div.item div.action input.icons { display:none; } -fieldset.ssh.matrix>div.output>table.content div.item div.title:hover { background-color:unset; } -fieldset.ssh.matrix>div.output>table.content div.item div.title span:hover { background-color:var(--hover-bg-color); } -fieldset.ssh.matrix>div.output>table.content div.item div.status div.item:hover { background-color:var(--hover-bg-color); } -fieldset.ssh.matrix>div.output>table.content div.item:hover { background-color:unset; color:unset; } -fieldset.ssh.matrix>div.output>table.content div.item.notice { background-color:var(--notice-bg-color); color:var(--notice-fg-color); } -fieldset.ssh.matrix>div.output>table.content div.item.danger { background-color:var(--danger-bg-color); color:var(--danger-fg-color); } -fieldset.ssh.matrix>div.output>table.content div.item.danger div.status div.item { color:var(--danger-fg-color); } -fieldset.ssh.matrix>div.output>table.content div.item.notice div.status div.item { color:var(--notice-fg-color); } -fieldset.ssh.matrix>div.output>table.content div.item.stop div.title>span { color:var(--disable-fg-color); } -fieldset.ssh.matrix>div.output>table.content tr:not(:hover) div.action { visibility:hidden; } -body:not(.mobile) fieldset.ssh.matrix>div.output>table.content th:first-child { position:sticky; left:2px; z-index:2; } -body:not(.mobile) fieldset.ssh.matrix>div.output>table.content td:first-child { background-color:var(--plugin-bg-color); position:sticky; left:2px; z-index:1; } -body:not(.mobile) fieldset.ssh.matrix>div.output>table.content tr.danger td:first-child { background-color:transparent; } diff --git a/misc/ssh/relay/matrix.go b/misc/ssh/relay/matrix.go deleted file mode 100644 index 1969026d..00000000 --- a/misc/ssh/relay/matrix.go +++ /dev/null @@ -1,90 +0,0 @@ -package relay - -import ( - "path" - - "shylinux.com/x/ice" - "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/html" - kit "shylinux.com/x/toolkits" -) - -type matrix struct { - status string `name:"status" help:"源码" icon:"bi bi-git"` - list string `name:"list refresh" help:"矩阵"` -} - -func (s matrix) List(m *ice.Message, arg ...string) { - m.Cmdy(SSH_RELAY, web.DREAM).Table(func(value ice.Maps) { - if value[web.SPACE] == ice.CONTEXTS { - m.PushButton(s.Portal, s.Desktop, s.Dream, s.Admin, s.Open, s.Word, s.Status, s.Vimer, s.Compile, s.Runtime, s.Xterm) - } else if value[mdb.STATUS] == cli.STOP { - m.PushButton() - } 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.Desktop, s.Admin, s.Open, s.Vimer, s.Runtime, s.Xterm) - } - }).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) Dream(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 init() { ice.Cmd("ssh.matrix", matrix{}) } - -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), 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) == "" { - 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), 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) open(m *ice.Message, arg ...string) { - if m.ActionKey() == web.OPEN { - m.ProcessOpen(s.link(m)) - return - } - 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), 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(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 deleted file mode 100644 index 5aae34c4..00000000 --- a/misc/ssh/relay/matrix.js +++ /dev/null @@ -1,35 +0,0 @@ -Volcanos(chat.ONIMPORT, { - _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 - }) - 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[""][machine], list)]} - }) }]}, - {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) {}, - 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: [ - {img: can.misc.Resource(can, item.icons||nfs.USR_ICONS_ICEBERGS, item.machine), onclick: cb(web.DESKTOP)}, {view: wiki.TITLE, list: [ - {text: (item.type == web.SERVER? item.machine: item.space)||location.host, onclick: cb(web.OPEN)}, - item.status != cli.STOP && can.onappend.label(can, item, {version: icon.version, time: icon.compile}), - can.onappend.buttons(can, item), - ]}, - ]} - }, - 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/ssh/relay/relay.shy b/misc/ssh/relay/relay.shy deleted file mode 100644 index f912ea67..00000000 --- a/misc/ssh/relay/relay.shy +++ /dev/null @@ -1,2 +0,0 @@ -chapter "relay" -field ssh.relay