From 50f7e564498b280476528aa7f7bc77a7d086db1b Mon Sep 17 00:00:00 2001 From: harveyshao Date: Sat, 13 Nov 2021 21:44:28 +0800 Subject: [PATCH] opt bash.grant --- base/mdb/zone.go | 2 +- base/nfs/dir.go | 4 +- core/code/autogen.go | 4 +- core/code/js.go | 10 +++-- core/code/vimer.go | 10 ++--- core/wiki/spark.go | 6 +++ misc/bash/run.go | 97 +++++++++++++++++++++++++++----------------- misc/bash/sess.go | 3 ++ 8 files changed, 86 insertions(+), 50 deletions(-) diff --git a/base/mdb/zone.go b/base/mdb/zone.go index e32b2195..54f26bf7 100644 --- a/base/mdb/zone.go +++ b/base/mdb/zone.go @@ -22,7 +22,7 @@ func _zone_select(m *ice.Message, prefix, chain, zone string, id string) { cb := m.Optionv(kit.Keycb(SELECT)) m.Richs(prefix, chain, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) { if val = kit.GetMeta(val); zone == "" { - if m.Option(FIELDS) == DETAIL { + if m.OptionFields() == DETAIL { m.Push(DETAIL, val) } else { m.Push(key, val, fields) diff --git a/base/nfs/dir.go b/base/nfs/dir.go index 8a4c67ea..a1b48296 100644 --- a/base/nfs/dir.go +++ b/base/nfs/dir.go @@ -207,7 +207,9 @@ func init() { m.Cmdy(TRASH, m.Option(kit.MDB_PATH)) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Info("dir_root: %v", m.Option(DIR_ROOT)) + if m.Option(DIR_ROOT) != "" { + m.Info("dir_root: %v", m.Option(DIR_ROOT)) + } _dir_list(m, kit.Select("./", m.Option(DIR_ROOT)), kit.Select("./", arg, 0), 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)), kit.Split(kit.Select(kit.Select("time,path,size,action", m.OptionFields()), kit.Join(kit.Slice(arg, 1))))) diff --git a/core/code/autogen.go b/core/code/autogen.go index 7a5a420a..17bf9508 100644 --- a/core/code/autogen.go +++ b/core/code/autogen.go @@ -31,7 +31,7 @@ import ( type {{.Option "name"}} struct { ice.{{.Option "type"}} - list string {{.Option "tag"}} + list string {{.Option "tags"}} } func (h {{.Option "name"}}) List(m *ice.Message, arg ...string) { @@ -163,7 +163,7 @@ func init() { case "Data": _defs(m, "list", m.Option(kit.MDB_NAME)+" path auto upload") } - m.Option("tag", kit.Format("`name:\"%s\" help:\"%s\"`", m.Option("list"), m.Option("help"))) + m.Option("tags", kit.Format("`name:\"%s\" help:\"%s\"`", m.Option("list"), m.Option("help"))) if p := path.Join(ice.SRC, m.Option(kit.MDB_ZONE), kit.Keys(m.Option(kit.MDB_NAME), GO)); !kit.FileExists(p) { _autogen_module(m, p) diff --git a/core/code/js.go b/core/code/js.go index 037668e4..9c6715b6 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -76,6 +76,12 @@ func init() { "throw", "catch", "finally", + + "can", + "sub", + "msg", + "res", + "target", ), FUNCTION, kit.Simple( "window", @@ -101,10 +107,6 @@ func init() { "cb", "cbs", "shy", - "can", - "sub", - "msg", - "res", "pane", "plugin", ), diff --git a/core/code/vimer.go b/core/code/vimer.go index d07b9d2e..9142d649 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -37,11 +37,6 @@ func init() { AUTOGEN: {Name: "create main=src/main.go@key key zone type=Zone,Hash,Data name=hi list help", Help: "模块", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(AUTOGEN, mdb.CREATE, arg) }}, - BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(AUTOGEN, BINPACK) - m.Cmd(nfs.COPY, ice.GO_MOD, path.Join(ice.SRC_RELEASE, ice.GO_MOD)) - m.ProcessInner() - }}, COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) { if m.Cmdy(COMPILE, ice.SRC_MAIN_GO); cli.IsSuccess(m) { m.Cmd(COMPILE, ice.SRC_MAIN_GO, ice.BIN_ICE_BIN) @@ -49,6 +44,11 @@ func init() { } m.ProcessInner() }}, + BINPACK: {Name: "binpack", Help: "打包", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(AUTOGEN, BINPACK) + m.Cmd(nfs.COPY, ice.GO_MOD, path.Join(ice.SRC_RELEASE, ice.GO_MOD)) + m.ProcessInner() + }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmdy(INNER, arg) }}, diff --git a/core/wiki/spark.go b/core/wiki/spark.go index e2bc9ffb..50f56660 100644 --- a/core/wiki/spark.go +++ b/core/wiki/spark.go @@ -43,6 +43,12 @@ func init() { ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { ice.AddRender(ice.RENDER_SCRIPT, func(m *ice.Message, cmd string, args ...interface{}) string { arg := kit.Simple(args...) + if m.IsCliUA() { + if len(arg) > 1 { + arg = arg[1:] + } + return strings.Join(arg, ice.NL) + } if len(arg) == 1 && arg[0] != BREAK { arg = []string{SHELL, arg[0]} } diff --git a/misc/bash/run.go b/misc/bash/run.go index e253cb1c..cd93621f 100644 --- a/misc/bash/run.go +++ b/misc/bash/run.go @@ -11,38 +11,35 @@ import ( kit "shylinux.com/x/toolkits" ) -const RUN = "run" +func _run_action(m *ice.Message, cmd *ice.Command, code string, arg ...string) { + m.Set(ice.MSG_RESULT) + m.Echo("#/bin/bash\n") -func init() { - Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ - "/run/": {Name: "/run/", Help: "执行", Action: ice.MergeAction(map[string]*ice.Action{ - ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { - m.Search(arg[0], func(_ *ice.Context, s *ice.Context, key string, cmd *ice.Command) { - p := strings.ReplaceAll(kit.Select("/app/cat.sh", cmd.Meta["display"]), ".js", ".sh") - if strings.HasPrefix(p, ice.PS+ice.REQUIRE) { - m.Cmdy(web.SPIDE, ice.DEV, web.SPIDE_RAW, p) - } else { - m.Cmdy(nfs.CAT, path.Join(ice.USR_INTSHELL, p)) - } - m.Debug(kit.Formats(cmd.Meta)) - if m.Result() == "" || m.Result(1) == ice.ErrNotFound { - m.Set(ice.MSG_RESULT) - m.Echo("#/bin/bash\n") - list := []string{} - args := []string{} - kit.Fetch(cmd.Meta["_trans"], func(k string, v string) { - list = append(list, k) - args = append(args, kit.Format(` %s)`, k)) - kit.Fetch(cmd.Meta[k], func(index int, value map[string]interface{}) { - args = append(args, kit.Format(` read -p "read %s: " v; url="$url/%s/$v" `, value[kit.MDB_NAME], value[kit.MDB_NAME])) - }) - args = append(args, kit.Format(` ;;`)) - }) - list = append(list, "quit") - m.Echo(` + list := []string{} + args := []string{} + kit.Fetch(cmd.Meta["_trans"], func(k string, v string) { + list = append(list, k) + args = append(args, kit.Format(` %s)`, k)) + kit.Fetch(cmd.Meta[k], func(index int, value map[string]interface{}) { + args = append(args, kit.Format(` read -p "input %s: " v; url="$url/%s/$v" `, value[kit.MDB_NAME], value[kit.MDB_NAME])) + }) + args = append(args, kit.Format(` ;;`)) + }) + + m.Echo(` +ish_sys_dev_run_source() { + select action in %s; do + local url="run/action/run/%s/action/$action" + case $action in +%s + esac + ish_sys_dev_source $url + done +} +`, kit.Join(list, ice.SP), arg[0], kit.Join(args, ice.NL)) + m.Echo(` ish_sys_dev_run_action() { select action in %s; do - if [ "$action" = "quit" ]; then break; fi local url="run/action/run/%s/action/$action" case $action in %s @@ -52,9 +49,39 @@ ish_sys_dev_run_action() { done } `, kit.Join(list, ice.SP), arg[0], kit.Join(args, ice.NL)) - m.Echo("cat $1\n") - m.Debug("what %v", m.Result()) + + m.Echo(ice.NL) + m.Echo(`ish_sys_dev_run_command() { + ish_sys_dev_run %s "$@" +} +`, arg[0]) + m.Echo(ice.NL) + + if code == "" { + m.Echo("cat $1") + } else { + m.Echo(code) + } + m.Echo(ice.NL) + m.Debug(m.Result()) +} + +const RUN = "run" + +func init() { + Index.Merge(&ice.Context{Commands: map[string]*ice.Command{ + "/run/": {Name: "/run/", Help: "执行", Action: ice.MergeAction(map[string]*ice.Action{ + ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) { + m.Search(arg[0], func(_ *ice.Context, s *ice.Context, key string, cmd *ice.Command) { + if p := strings.ReplaceAll(kit.Select("/app/cat.sh", cmd.Meta["display"]), ".js", ".sh"); strings.HasPrefix(p, ice.PS+ice.REQUIRE) { + m.Cmdy(web.SPIDE, ice.DEV, web.SPIDE_RAW, p) + } else { + m.Cmdy(nfs.CAT, path.Join(ice.USR_INTSHELL, p)) } + if m.Result() == "" || m.Result(1) == ice.ErrNotFound { + m.Set(ice.MSG_RESULT) + } + _run_action(m, cmd, m.Result(), arg...) }) }}, ice.RUN: {Name: "run", Help: "执行", Hand: func(m *ice.Message, arg ...string) { @@ -65,10 +92,6 @@ ish_sys_dev_run_action() { m.Table() } }}, - }, ctx.CmdAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if m.Right(arg) { - m.Cmdy(arg) - } - }}}, - }) + }, ctx.CmdAction())}, + }}) } diff --git a/misc/bash/sess.go b/misc/bash/sess.go index 6775c7d8..a80fee0b 100644 --- a/misc/bash/sess.go +++ b/misc/bash/sess.go @@ -47,6 +47,9 @@ func init() { m.Option(ice.MSG_USERNAME, msg.Append(GRANT)) m.Option(ice.MSG_USERROLE, aaa.UserRole(m, msg.Append(GRANT))) m.Option(tcp.HOSTNAME, msg.Append(tcp.HOSTNAME)) + if arg[0] == "/run/" { + return + } m.Warn(m.Option(ice.MSG_USERNAME) == "", ice.ErrNotLogin, arg) }}, "/qrcode": {Name: "/qrcode", Help: "二维码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {