forked from x/icebergs
opt portal
This commit is contained in:
parent
feb4d49d63
commit
c95da31e37
@ -142,6 +142,7 @@ const (
|
|||||||
KILL = "kill"
|
KILL = "kill"
|
||||||
FIND = "find"
|
FIND = "find"
|
||||||
GREP = "grep"
|
GREP = "grep"
|
||||||
|
SUDO = "sudo"
|
||||||
EXEC = "exec"
|
EXEC = "exec"
|
||||||
EXIT = "exit"
|
EXIT = "exit"
|
||||||
ECHO = "echo"
|
ECHO = "echo"
|
||||||
|
@ -37,7 +37,8 @@ func Template(m *ice.Message, p string, data ...ice.Any) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var TemplateText = func(m *ice.Message, p string) 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 {
|
var TemplatePath = func(m *ice.Message, arg ...string) string {
|
||||||
if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); Exists(m, p) {
|
if p := path.Join(ice.SRC_TEMPLATE, m.PrefixKey(), path.Join(arg...)); Exists(m, p) {
|
||||||
|
@ -52,7 +52,7 @@ func init() {
|
|||||||
PORT: {Name: "port port path auto socket", Help: "端口", Actions: ice.MergeActions(ice.Actions{
|
PORT: {Name: "port port path auto socket", Help: "端口", Actions: ice.MergeActions(ice.Actions{
|
||||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
case SERVER:
|
case HOST, SERVER:
|
||||||
m.Cmd(PORT, SOCKET, func(value ice.Maps) {
|
m.Cmd(PORT, SOCKET, func(value ice.Maps) {
|
||||||
switch value[mdb.STATUS] {
|
switch value[mdb.STATUS] {
|
||||||
case "LISTEN":
|
case "LISTEN":
|
||||||
|
@ -269,7 +269,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
nfs.TemplateText = func(m *ice.Message, p string) string {
|
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)
|
return m.Cmdx(SPIDE, ice.DEV, SPIDE_RAW, http.MethodGet, p)
|
||||||
} else {
|
} else {
|
||||||
return m.Cmdx(nfs.CAT, p)
|
return m.Cmdx(nfs.CAT, p)
|
||||||
|
@ -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.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>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>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.desktop>div.output>div.desktop>fieldset>form.option>div.item.text>input { width:60px; }
|
||||||
body.mobile fieldset.macos.dock>div.output { overflow-y:hidden; }
|
body.mobile fieldset.macos.dock>div.output { overflow-y:hidden; }
|
||||||
|
@ -63,10 +63,12 @@ func _publish_contexts(m *ice.Message, arg ...string) {
|
|||||||
case "manual":
|
case "manual":
|
||||||
m.Options(nfs.BINARY, "ice.linux.amd64")
|
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" {
|
if m.Option("format") == "raw" {
|
||||||
m.Echo(strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH))))
|
m.Echo(template)
|
||||||
} else {
|
} else {
|
||||||
m.EchoScript(strings.TrimSpace(nfs.Template(m, kit.Keys(k, SH))))
|
m.EchoScript(template)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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})
|
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()
|
defer s.Wait()
|
||||||
s.Shell()
|
s.Shell()
|
||||||
lock := task.Lock{}
|
|
||||||
list := [][]string{}
|
list := [][]string{}
|
||||||
cmd := kit.Format("%s@%s[%s]%s$ ssh %s@%s\r\n",
|
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), ice.Info.Hostname, kit.Split(time.Now().Format(ice.MOD_TIME))[1], path.Base(kit.Path("")),
|
||||||
m.Option(aaa.USERNAME), m.Option(tcp.HOST))
|
m.Option(aaa.USERNAME), m.Option(tcp.HOST))
|
||||||
list = append(list, []string{cmd})
|
list = append(list, []string{cmd})
|
||||||
|
lock := task.Lock{}
|
||||||
m.Debug("cmd %v", cmd)
|
m.Debug("cmd %v", cmd)
|
||||||
cb(cmd)
|
cb(cmd)
|
||||||
defer cb("\r\n\r\n")
|
defer cb("\r\n\r\n")
|
||||||
|
@ -80,8 +80,7 @@ func (s relay) Init(m *ice.Message, arg ...string) {
|
|||||||
NCPU, "处理器", VCPU, "虚拟核", MHZ, "频率",
|
NCPU, "处理器", VCPU, "虚拟核", MHZ, "频率",
|
||||||
MEM, "内存", DISK, "磁盘", NETWORK, "流量",
|
MEM, "内存", DISK, "磁盘", NETWORK, "流量",
|
||||||
LISTEN, "服务", SOCKET, "连接", PROC, "进程",
|
LISTEN, "服务", SOCKET, "连接", PROC, "进程",
|
||||||
nfs.COMMIT, "发布时间", code.COMPILE, "编译时间",
|
nfs.COMMIT, "发布时间", code.COMPILE, "编译时间", "boot", "启动时间",
|
||||||
"boot", "启动时间",
|
|
||||||
)
|
)
|
||||||
msg := m.Spawn(ice.Maps{ice.MSG_FIELDS: ""})
|
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)) }) })
|
m.GoSleep3s(func() { s.Hash.List(msg).Table(func(value ice.Maps) { s.xterm(m.Spawn(value)) }) })
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
package xterm
|
package xterm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
ice "shylinux.com/x/icebergs"
|
ice "shylinux.com/x/icebergs"
|
||||||
|
"shylinux.com/x/icebergs/base/cli"
|
||||||
"shylinux.com/x/icebergs/base/lex"
|
"shylinux.com/x/icebergs/base/lex"
|
||||||
"shylinux.com/x/icebergs/base/nfs"
|
"shylinux.com/x/icebergs/base/nfs"
|
||||||
kit "shylinux.com/x/toolkits"
|
kit "shylinux.com/x/toolkits"
|
||||||
|
"shylinux.com/x/toolkits/task"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Winsize struct {
|
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) 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) 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) 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)
|
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()
|
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)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user