From c95da31e37bee0cecd6df506c57afb7344fedf8b Mon Sep 17 00:00:00 2001 From: shy Date: Thu, 28 Dec 2023 10:00:40 +0800 Subject: [PATCH] opt portal --- base/cli/system.go | 1 + base/nfs/template.go | 3 ++- base/tcp/port.go | 2 +- base/web/spide.go | 2 +- core/chat/macos/desktop.css | 2 +- core/code/publish.go | 6 ++++-- misc/ssh/connect.go | 3 ++- misc/ssh/relay/relay.go | 3 +-- misc/xterm/xterm.go | 34 +++++++++++++++++++++++++++++++++- 9 files changed, 46 insertions(+), 10 deletions(-) diff --git a/base/cli/system.go b/base/cli/system.go index ca27a00e..950f12a5 100644 --- a/base/cli/system.go +++ b/base/cli/system.go @@ -142,6 +142,7 @@ const ( KILL = "kill" FIND = "find" GREP = "grep" + SUDO = "sudo" EXEC = "exec" EXIT = "exit" ECHO = "echo" diff --git a/base/nfs/template.go b/base/nfs/template.go index a7a7aef4..e1c91949 100644 --- a/base/nfs/template.go +++ b/base/nfs/template.go @@ -37,7 +37,8 @@ func Template(m *ice.Message, p string, data ...ice.Any) string { } var TemplateText = func(m *ice.Message, p string) string { - return m.Cmdx(CAT, TemplatePath(m, path.Base(p))) + m.Debug("what %v", m.Option("_template")) + return m.Cmdx(CAT, kit.Select(TemplatePath(m, path.Base(p)), m.Option("_template"))) } var TemplatePath = func(m *ice.Message, arg ...string) string { if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); Exists(m, p) { diff --git a/base/tcp/port.go b/base/tcp/port.go index 9e315b88..fcdbcd3e 100644 --- a/base/tcp/port.go +++ b/base/tcp/port.go @@ -52,7 +52,7 @@ func init() { PORT: {Name: "port port path auto socket", Help: "端口", Actions: ice.MergeActions(ice.Actions{ mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) { switch arg[0] { - case SERVER: + case HOST, SERVER: m.Cmd(PORT, SOCKET, func(value ice.Maps) { switch value[mdb.STATUS] { case "LISTEN": diff --git a/base/web/spide.go b/base/web/spide.go index 4514e011..2cd4203a 100644 --- a/base/web/spide.go +++ b/base/web/spide.go @@ -269,7 +269,7 @@ func init() { } } nfs.TemplateText = func(m *ice.Message, p string) string { - if p := nfs.TemplatePath(m, path.Base(p)); kit.HasPrefix(p, "/require/", ice.HTTP) { + if p := kit.Select(nfs.TemplatePath(m, path.Base(p)), m.Option("_template")); kit.HasPrefix(p, "/require/", ice.HTTP) { return m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodGet, p) } else { return m.Cmdx(nfs.CAT, p) diff --git a/core/chat/macos/desktop.css b/core/chat/macos/desktop.css index a0387eee..74fcd553 100644 --- a/core/chat/macos/desktop.css +++ b/core/chat/macos/desktop.css @@ -83,6 +83,6 @@ body:not(.mobile) fieldset.macos.dock>div.output>div.item:hover { background-col body:not(.mobile) fieldset.macos.dock>div.output>div.item img:hover { width:160px; transition:width 0.3s; } body:not(.mobile) fieldset.macos.desktop>div.output>fieldset.macos.dock:hover { margin-left:-40px; transition:margin-left 0.3s; } body:not(.mobile) fieldset.macos.desktop>div.output>div.desktop>fieldset:not(:hover)>form.option>div.icon { visibility:hidden; } -body:not(.mobile) fieldset.macos.desktop>div.output>div.desktop>div.item { margin:10px; } +body:not(.mobile) fieldset.macos.desktop>div.output>div.desktop>div.item { margin:var(--desktop-icon-margin); } body.mobile fieldset.macos.desktop>div.output>div.desktop>fieldset>form.option>div.item.text>input { width:60px; } body.mobile fieldset.macos.dock>div.output { overflow-y:hidden; } diff --git a/core/code/publish.go b/core/code/publish.go index 9996b43a..c40f6edb 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -63,10 +63,12 @@ func _publish_contexts(m *ice.Message, arg ...string) { case "manual": m.Options(nfs.BINARY, "ice.linux.amd64") } + m.Debug("what %v", m.Option("_template")) + template := strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH))) if m.Option("format") == "raw" { - m.Echo(strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH)))) + m.Echo(template) } else { - m.EchoScript(strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH)))) + m.EchoScript(template) } } } diff --git a/misc/ssh/connect.go b/misc/ssh/connect.go index d05bcb9d..5aa93fea 100644 --- a/misc/ssh/connect.go +++ b/misc/ssh/connect.go @@ -270,12 +270,13 @@ func PushShell(m *ice.Message, cmds []string, cb func(string)) { s.RequestPty(kit.Env(cli.TERM), height, width, ssh.TerminalModes{ssh.ECHO: 1, ssh.TTY_OP_ISPEED: 14400, ssh.TTY_OP_OSPEED: 14400}) defer s.Wait() s.Shell() - lock := task.Lock{} + list := [][]string{} cmd := kit.Format("%s@%s[%s]%s$ ssh %s@%s\r\n", m.Option(aaa.USERNAME), ice.Info.Hostname, kit.Split(time.Now().Format(ice.MOD_TIME))[1], path.Base(kit.Path("")), m.Option(aaa.USERNAME), m.Option(tcp.HOST)) list = append(list, []string{cmd}) + lock := task.Lock{} m.Debug("cmd %v", cmd) cb(cmd) defer cb("\r\n\r\n") diff --git a/misc/ssh/relay/relay.go b/misc/ssh/relay/relay.go index d7868b1a..787377be 100644 --- a/misc/ssh/relay/relay.go +++ b/misc/ssh/relay/relay.go @@ -80,8 +80,7 @@ func (s relay) Init(m *ice.Message, arg ...string) { NCPU, "处理器", VCPU, "虚拟核", MHZ, "频率", MEM, "内存", DISK, "磁盘", NETWORK, "流量", LISTEN, "服务", SOCKET, "连接", PROC, "进程", - nfs.COMMIT, "发布时间", code.COMPILE, "编译时间", - "boot", "启动时间", + nfs.COMMIT, "发布时间", code.COMPILE, "编译时间", "boot", "启动时间", ) msg := m.Spawn(ice.Maps{ice.MSG_FIELDS: ""}) m.GoSleep3s(func() { s.Hash.List(msg).Table(func(value ice.Maps) { s.xterm(m.Spawn(value)) }) }) diff --git a/misc/xterm/xterm.go b/misc/xterm/xterm.go index b143897f..95de8228 100644 --- a/misc/xterm/xterm.go +++ b/misc/xterm/xterm.go @@ -1,14 +1,17 @@ package xterm import ( + "fmt" "os" "os/exec" "path" ice "shylinux.com/x/icebergs" + "shylinux.com/x/icebergs/base/cli" "shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/nfs" kit "shylinux.com/x/toolkits" + "shylinux.com/x/toolkits/task" ) type Winsize struct { @@ -35,7 +38,7 @@ func (s xterm) Setsize(rows, cols string) error { func (s xterm) Writeln(str string, arg ...ice.Any) { s.Write([]byte(kit.Format(str, arg...) + lex.NL)) } func (s xterm) Write(buf []byte) (int, error) { return s.File.Write(buf) } func (s xterm) Read(buf []byte) (int, error) { return s.File.Read(buf) } -func (s xterm) Close() error { return s.Cmd.Process.Kill() } +func (s xterm) Close() error { s.Cmd.Process.Kill(); return s.File.Close() } type handler func(m *ice.Message, arg ...string) (XTerm, error) @@ -59,3 +62,32 @@ func Command(m *ice.Message, dir string, cli string, arg ...string) (XTerm, erro return &xterm{cmd, pty}, cmd.Start() } } +func PushShell(m *ice.Message, xterm XTerm, cmds []string, cb func(string)) { + list := [][]string{} + list = append(list, []string{""}) + lock := task.Lock{} + m.Go(func() { + kit.For(cmds, func(cmd string) { + for { + m.Sleep300ms() + if func() bool { defer lock.Lock()(); return len(list[len(list)-1]) > 1 }() { + break + } + } + m.Debug("cmd %v", cmd) + fmt.Fprintln(xterm, cmd) + defer lock.Lock()() + list = append(list, []string{cmd}) + }) + defer fmt.Fprintln(xterm, cli.EXIT) + m.Sleep(m.OptionDefault("interval", "3s")) + }) + kit.For(xterm, func(res []byte) { + m.Debug("res %v", string(res)) + m.Debug("res %v", res) + cb(string(res)) + defer lock.Lock()() + list[len(list)-1] = append(list[len(list)-1], string(res)) + }) + m.Debug("res %v", 123) +}