1
0
forked from x/icebergs
This commit is contained in:
shaoying 2020-02-29 13:36:03 +08:00
parent 48e7c676d6
commit 137a5d61a2
3 changed files with 27 additions and 21 deletions

View File

@ -14,10 +14,12 @@ import (
)
type Frame struct {
in io.ReadCloser
out io.Writer
in io.ReadCloser
out io.Writer
target *ice.Context
count int
exit bool
}
func (f *Frame) prompt(m *ice.Message) *Frame {
@ -141,7 +143,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
line := ""
bio := bufio.NewScanner(f.in)
for f.prompt(m); bio.Scan(); f.prompt(m) {
for f.prompt(m); bio.Scan() && !f.exit; f.prompt(m) {
if len(bio.Text()) == 0 {
// 空行
continue
@ -247,6 +249,11 @@ var Index = &ice.Context{Name: "ssh", Help: "终端模块",
m.Info("%v", ls)
}
}},
"return": {Name: "return", Help: "解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Option(ice.MSG_PROMPT, m.Confv("prompt", "meta.PS1"))
f := m.Target().Server().(*Frame)
f.exit = true
}},
"super": {Name: "super user remote port local", Help: "上位机", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
key := m.Rich("super", nil, kit.Dict(

View File

@ -106,6 +106,8 @@ func (web *Frame) HandleWSS(m *ice.Message, safe bool, c *websocket.Conn, name s
if len(target) == 0 {
// 本地执行
msg.Option(ice.MSG_USERROLE, msg.Cmdx(ice.AAA_ROLE, "check", msg.Option(ice.MSG_USERNAME)))
msg.Log("some", "%s: %s", msg.Option(ice.MSG_USERROLE), msg.Option(ice.MSG_USERNAME))
if msg.Optionv(ice.MSG_HANDLE, "true"); !msg.Warn(!safe, "no right") {
m.Option("_dev", name)
msg = msg.Cmd()

View File

@ -49,7 +49,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
"some", kit.Dict("simple", kit.Dict(
"inputs", kit.List(
kit.MDB_INPUT, "text", "name", "name",
kit.MDB_INPUT, "button", "value", "查看",
kit.MDB_INPUT, "button", "value", "查看", "action", "auto",
kit.MDB_INPUT, "button", "value", "返回", "cb", "Last",
),
)),
@ -240,26 +240,23 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
m.Option(kit.MDB_NAME, arg[0])
m.Option(kit.MDB_TEXT, arg[1])
if len(arg) > 2 {
if meta := m.Confv("field", kit.Keys("meta.some", arg[2])); meta != nil {
arg = arg[3:]
m.Option("meta", meta)
} else {
list := []string{}
for _, line := range kit.Split(strings.Join(arg[2:], " "), "\n") {
ls := kit.Split(line)
for i := 0; i < len(ls); i++ {
if strings.HasPrefix(ls[i], "#") {
ls = ls[:i]
break
}
if meta := m.Confv("field", kit.Keys("meta.some", kit.Select("simple", arg, 2))); meta != nil {
m.Option("meta", meta)
} else {
list := []string{}
for _, line := range kit.Split(strings.Join(arg[2:], " "), "\n") {
ls := kit.Split(line)
for i := 0; i < len(ls); i++ {
if strings.HasPrefix(ls[i], "#") {
ls = ls[:i]
break
}
list = append(list, ls...)
}
meta := kit.Parse(nil, "", list...)
m.Option("meta", meta)
list = append(list, ls...)
}
meta := kit.Parse(nil, "", list...)
m.Option("meta", meta)
}
m.Render(m.Conf(cmd, "meta.template"))