forked from x/icebergs
opt lock
This commit is contained in:
parent
735ba5c7c2
commit
2473f3cf3e
@ -61,8 +61,8 @@ func SessCheck(m *ice.Message, sessid string) bool {
|
||||
}
|
||||
func SessAuth(m *ice.Message, value ice.Any, arg ...string) *ice.Message {
|
||||
return m.Auth(
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, kit.Value(value, USERNAME)),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, kit.Value(value, USERNICK)),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, kit.Value(value, USERNAME)),
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, kit.Value(value, USERROLE)),
|
||||
arg, logs.FileLineMeta(kit.Select(logs.FileLine(-1), m.Option("aaa.checker"))),
|
||||
)
|
||||
|
@ -19,7 +19,7 @@ func BinPath(arg ...string) string {
|
||||
push := func(p string) { kit.If(kit.IndexOf(list, p) == -1, func() { list = append(list, p) }) }
|
||||
kit.For(arg, func(p string) {
|
||||
list = append(list, kit.Path(p, ice.BIN), kit.Path(p, ice.USR_PUBLISH), kit.Path(p, ice.USR_LOCAL_BIN), kit.Path(p, ice.USR_LOCAL_GO_BIN))
|
||||
for _, l := range kit.Revert(strings.Split(ice.Pulse.Cmdx(nfs.CAT, kit.Path(p, ice.ETC_PATH)), ice.NL)) {
|
||||
for _, l := range kit.Reverse(strings.Split(ice.Pulse.Cmdx(nfs.CAT, kit.Path(p, ice.ETC_PATH)), ice.NL)) {
|
||||
kit.If(strings.TrimSpace(l) != "" && !strings.HasPrefix(strings.TrimSpace(l), "#"), func() { push(kit.Path(p, l)) })
|
||||
}
|
||||
})
|
||||
|
@ -222,6 +222,6 @@ func init() {
|
||||
}
|
||||
func NodeInfo(m *ice.Message, arg ...string) {
|
||||
m.Conf(RUNTIME, kit.Keys(NODE, mdb.TIME), m.Time())
|
||||
ice.Info.NodeName = m.Conf(RUNTIME, kit.Keys(NODE, mdb.NAME), kit.Select(ice.Info.NodeName, arg, 0))
|
||||
ice.Info.NodeType = m.Conf(RUNTIME, kit.Keys(NODE, mdb.TYPE), kit.Select(ice.Info.NodeType, arg, 1))
|
||||
ice.Info.NodeName = mdb.Conf(m, RUNTIME, kit.Keys(NODE, mdb.NAME), kit.Select(ice.Info.NodeName, arg, 0))
|
||||
ice.Info.NodeType = mdb.Conf(m, RUNTIME, kit.Keys(NODE, mdb.TYPE), kit.Select(ice.Info.NodeType, arg, 1))
|
||||
}
|
||||
|
@ -4,14 +4,12 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
@ -20,66 +18,49 @@ import (
|
||||
)
|
||||
|
||||
func _path_split(ps string) []string {
|
||||
ps = strings.ReplaceAll(ps, "\\", "/")
|
||||
return kit.Split(ps, "\n"+kit.Select(":", ";", strings.Contains(ps, ";")), "\n")
|
||||
ps = strings.ReplaceAll(ps, "\\", ice.PS)
|
||||
return kit.Split(ps, ice.NL+kit.Select(ice.DF, ";", strings.Contains(ps, ";")), ice.NL)
|
||||
}
|
||||
func _system_cmd(m *ice.Message, arg ...string) *exec.Cmd {
|
||||
bin, env := "", kit.Simple(m.Optionv(CMD_ENV))
|
||||
for i := 0; i < len(env)-1; i += 2 {
|
||||
if env[i] == PATH {
|
||||
if bin = _system_find(m, arg[0], _path_split(env[i+1])...); bin != "" {
|
||||
m.Logs(mdb.SELECT, "envpath cmd", bin)
|
||||
kit.For(env, func(k, v string) {
|
||||
if k == PATH {
|
||||
if bin = _system_find(m, arg[0], _path_split(v)...); bin != "" {
|
||||
m.Logs(FIND, "envpath cmd", bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
if bin == "" {
|
||||
if text := kit.ReadFile(ice.ETC_PATH); len(text) > 0 {
|
||||
if bin = _system_find(m, arg[0], strings.Split(text, ice.NL)...); bin != "" {
|
||||
m.Logs(mdb.SELECT, "etcpath cmd", bin)
|
||||
m.Logs(FIND, "etcpath cmd", bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
if bin == "" {
|
||||
if bin = _system_find(m, arg[0], ice.BIN, m.Option(CMD_DIR)); bin != "" {
|
||||
m.Logs(mdb.SELECT, "contexts cmd", bin)
|
||||
}
|
||||
}
|
||||
if bin == "" {
|
||||
if bin = _system_find(m, arg[0], ice.BIN, nfs.PWD); bin != "" {
|
||||
m.Logs(mdb.SELECT, "contexts cmd", bin)
|
||||
if bin = _system_find(m, arg[0], m.Option(CMD_DIR), ice.BIN, nfs.PWD); bin != "" {
|
||||
m.Logs(FIND, "contexts cmd", bin)
|
||||
}
|
||||
}
|
||||
if bin == "" && !strings.Contains(arg[0], ice.PS) {
|
||||
if bin = _system_find(m, arg[0]); bin != "" {
|
||||
m.Logs(mdb.SELECT, "systems cmd", bin)
|
||||
m.Logs(FIND, "systems cmd", bin)
|
||||
}
|
||||
}
|
||||
if bin == "" && !strings.Contains(arg[0], ice.PS) {
|
||||
m.Cmd(MIRRORS, CMD, arg[0])
|
||||
if bin = _system_find(m, arg[0]); bin != "" {
|
||||
m.Logs(mdb.SELECT, "mirrors cmd", bin)
|
||||
m.Logs(FIND, "mirrors cmd", bin)
|
||||
}
|
||||
}
|
||||
if bin == "" && runtime.GOOS == WINDOWS {
|
||||
if bin = _system_find(m, arg[0], path.Join(os.Getenv("ProgramFiles"), "Git/bin"), path.Join(os.Getenv("ProgramFiles"), "Go/bin")); bin != "" {
|
||||
m.Logs(mdb.SELECT, "systems cmd", bin)
|
||||
}
|
||||
}
|
||||
if bin == "" {
|
||||
bin = arg[0]
|
||||
}
|
||||
cmd := exec.Command(bin, arg[1:]...)
|
||||
cmd := exec.Command(kit.Select(arg[0], bin), arg[1:]...)
|
||||
if cmd.Dir = kit.TrimPath(m.Option(CMD_DIR)); len(cmd.Dir) > 0 {
|
||||
if m.Logs(mdb.PARAMS, CMD_DIR, cmd.Dir); !nfs.ExistsFile(m, cmd.Dir) {
|
||||
if m.Logs(EXEC, CMD_DIR, cmd.Dir); !nfs.ExistsFile(m, cmd.Dir) {
|
||||
file.MkdirAll(cmd.Dir, ice.MOD_DIR)
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(env)-1; i += 2 {
|
||||
cmd.Env = append(cmd.Env, kit.Format("%s=%s", env[i], env[i+1]))
|
||||
}
|
||||
if len(cmd.Env) > 0 {
|
||||
m.Logs(mdb.PARAMS, CMD_ENV, kit.Format(cmd.Env))
|
||||
}
|
||||
kit.For(env, func(k, v string) { cmd.Env = append(cmd.Env, kit.Format("%s=%s", k, v)) })
|
||||
kit.If(len(cmd.Env) > 0, func() { m.Logs(EXEC, CMD_ENV, kit.Format(cmd.Env)) })
|
||||
return cmd
|
||||
}
|
||||
func _system_out(m *ice.Message, out string) io.Writer {
|
||||
@ -88,7 +69,7 @@ func _system_out(m *ice.Message, out string) io.Writer {
|
||||
} else if m.Option(out) == "" {
|
||||
return nil
|
||||
} else if f, p, e := file.CreateFile(m.Option(out)); m.Assert(e) {
|
||||
m.Logs(mdb.EXPORT, out, p)
|
||||
m.Logs(nfs.SAVE, out, p)
|
||||
m.Optionv(out, f)
|
||||
return f
|
||||
}
|
||||
@ -113,11 +94,12 @@ func _system_exec(m *ice.Message, cmd *exec.Cmd) {
|
||||
if m.IsErr() {
|
||||
m.Option(ice.MSG_ARGS, kit.Simple(http.StatusBadRequest, cmd.Args, err.String()))
|
||||
m.Echo(strings.TrimRight(err.String(), ice.NL))
|
||||
// m.Debug("%s %s", err, out)
|
||||
}
|
||||
}()
|
||||
}
|
||||
if e := cmd.Run(); !m.Warn(e, ice.ErrNotValid, cmd.Args) {
|
||||
m.Cost(CODE, _system_code(cmd), ctx.ARGS, cmd.Args)
|
||||
m.Cost(CODE, _system_code(cmd), EXEC, cmd.Args)
|
||||
}
|
||||
m.Push(mdb.TIME, m.Time()).Push(CODE, _system_code(cmd))
|
||||
}
|
||||
@ -165,6 +147,9 @@ const (
|
||||
MAN = "man"
|
||||
GREP = "grep"
|
||||
OPENS = "opens"
|
||||
REST = "rest"
|
||||
FIND = "find"
|
||||
EXEC = "exec"
|
||||
)
|
||||
|
||||
const SYSTEM = "system"
|
||||
@ -198,7 +183,7 @@ func init() {
|
||||
}
|
||||
m.Cmdy(nfs.CAT, ice.ETC_PATH)
|
||||
}},
|
||||
"find": {Hand: func(m *ice.Message, arg ...string) {
|
||||
FIND: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(_system_find(m, arg[0], arg[1:]...))
|
||||
}},
|
||||
MAN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -32,7 +32,7 @@ func _config_only(v ice.Any, arg ...string) bool {
|
||||
func _config_save(m *ice.Message, name string, arg ...string) {
|
||||
data, msg := ice.Map{}, m.Spawn(m.Source())
|
||||
for _, k := range arg {
|
||||
if v := msg.Confv(k); _config_only(v, mdb.META) {
|
||||
if v := mdb.Confv(msg, k); _config_only(v, mdb.META) {
|
||||
continue
|
||||
} else {
|
||||
data[k] = v
|
||||
|
@ -59,5 +59,5 @@ func DisplayBase(m Message, file string, arg ...ice.Any) Message {
|
||||
return m
|
||||
}
|
||||
func Toolkit(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_TOOLKIT, kit.Select(m.Config(mdb.TOOLS), kit.Fields(arg)))
|
||||
m.Option(ice.MSG_TOOLKIT, kit.Select(mdb.Config(m, mdb.TOOLS), kit.Fields(arg)))
|
||||
}
|
||||
|
@ -11,14 +11,27 @@ const PROCESS = "process"
|
||||
var _process = map[string]ice.Any{}
|
||||
|
||||
func AddProcess(key string, val ice.Any) { _process[key] = val }
|
||||
func Process(m *ice.Message, key string, args []string, arg ...string) {
|
||||
switch cb := _process[key].(type) {
|
||||
case func(*ice.Message, []string, ...string):
|
||||
cb(m, args, arg...)
|
||||
func _process_args(m *ice.Message, args ice.Any) []string {
|
||||
switch cb := args.(type) {
|
||||
case func() string:
|
||||
return []string{cb()}
|
||||
case func() []string:
|
||||
return cb()
|
||||
case []string:
|
||||
return cb
|
||||
case string:
|
||||
if len(arg) == 0 || arg[0] != PROCESS {
|
||||
m.Cmdy(cb, PROCESS, args)
|
||||
m.Optionv(ice.FIELD_PREFIX, kit.Simple(m.ActionKey(), m.Optionv(ice.FIELD_PREFIX)))
|
||||
return []string{cb}
|
||||
case nil:
|
||||
default:
|
||||
m.ErrorNotImplement(args)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func Process(m *ice.Message, key string, args ice.Any, arg ...string) {
|
||||
switch cb := _process[kit.Select(m.ActionKey(), key)].(type) {
|
||||
case string:
|
||||
if !kit.HasPrefixList(arg, ACTION, PROCESS) {
|
||||
m.Cmdy(cb, PROCESS, _process_args(m, args)).Optionv(ice.FIELD_PREFIX, kit.Simple(m.ActionKey(), m.Optionv(ice.FIELD_PREFIX)))
|
||||
} else {
|
||||
m.Cmdy(cb, arg)
|
||||
}
|
||||
@ -26,47 +39,22 @@ func Process(m *ice.Message, key string, args []string, arg ...string) {
|
||||
ProcessField(m, key, args, arg...)
|
||||
}
|
||||
}
|
||||
func ProcessCommand(m *ice.Message, cmd string, val []string, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == ice.RUN {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) *ice.Message {
|
||||
if cmd = kit.Select(m.ActionKey(), cmd); !kit.HasPrefixList(arg, ice.RUN) {
|
||||
m.Cmdy(COMMAND, cmd).Push(ARGS, _process_args(m, args)).ProcessField(ACTION, m.ActionKey(), ice.RUN).Option("_index", m.PrefixKey())
|
||||
} else {
|
||||
m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(val))
|
||||
m.ProcessField(cmd, ice.RUN)
|
||||
kit.If(aaa.Right(m, cmd, arg[1:]), func() { m.Cmdy(cmd, arg[1:]) })
|
||||
}
|
||||
}
|
||||
func ProcessCommandOpt(m *ice.Message, arg []string, args ...string) {
|
||||
if len(arg) > 0 && arg[0] == ice.RUN {
|
||||
return
|
||||
}
|
||||
m.Push("opt", kit.Format(m.OptionSimple(args...)))
|
||||
return m
|
||||
}
|
||||
func ProcessFloat(m *ice.Message, arg ...string) {
|
||||
m.Option(ice.MSG_PROCESS, ice.PROCESS_FLOAT)
|
||||
m.Option(ice.PROCESS_ARG, arg)
|
||||
m.Cmdy(COMMAND, arg[0])
|
||||
m.Cmdy(COMMAND, arg[0]).Options(ice.MSG_PROCESS, ice.PROCESS_FLOAT, ice.PROCESS_ARG, arg)
|
||||
}
|
||||
|
||||
func ProcessField(m *ice.Message, cmd string, args ice.Any, arg ...string) {
|
||||
if cmd = kit.Select(m.ActionKey(), cmd); len(arg) == 0 || arg[0] != ice.RUN {
|
||||
m.Option("_index", m.PrefixKey())
|
||||
m.Cmdy(COMMAND, cmd).ProcessField(ACTION, m.ActionKey(), ice.RUN)
|
||||
switch cb := args.(type) {
|
||||
case func() string:
|
||||
m.Push(ARGS, kit.Format([]string{cb()}))
|
||||
case func() []string:
|
||||
m.Push(ARGS, kit.Format(cb()))
|
||||
case []string:
|
||||
m.Push(ARGS, kit.Format(cb))
|
||||
case string:
|
||||
m.Push(ARGS, kit.Format([]string{cb}))
|
||||
case nil:
|
||||
default:
|
||||
m.ErrorNotImplement(args)
|
||||
}
|
||||
func ProcessCommand(m *ice.Message, cmd string, args []string, arg ...string) {
|
||||
if !kit.HasPrefixList(arg, ice.RUN) {
|
||||
m.Cmdy(COMMAND, cmd).Push(ice.ARG, kit.Format(args)).ProcessField(cmd, ice.RUN)
|
||||
} else {
|
||||
if aaa.Right(m, cmd, arg[1:]) {
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
}
|
||||
m.Cmdy(cmd, arg[1:])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ func init() {
|
||||
HAPPEN: {Name: "happen event*", Help: "触发", Hand: func(m *ice.Message, arg ...string) {
|
||||
defer m.Cost()
|
||||
m.OptionCB(mdb.SELECT, "")
|
||||
mdb.ZoneSelect(m.Spawn(ice.OptionFields("")), m.Option(EVENT)).Tables(func(value ice.Maps) {
|
||||
m.Cmdy(kit.Split(value[ice.CMD]), m.Option(EVENT), arg[2:], ice.OptionFields(""))
|
||||
mdb.ZoneSelect(m.Spawn(ice.OptionFields("")), arg[1]).Tables(func(value ice.Maps) {
|
||||
m.Cmdy(kit.Split(value[ice.CMD]), arg[1], arg[2:], ice.OptionFields(""))
|
||||
})
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.SHORT, EVENT, mdb.FIELD, "time,id,cmd"))},
|
||||
|
@ -32,6 +32,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
continue
|
||||
for _, file := range []string{m.Conf(SHOW, kit.Keys(l.l, FILE)), BENCH} {
|
||||
if file == "" {
|
||||
continue
|
||||
|
@ -177,16 +177,14 @@ func HashKey(m *ice.Message) string {
|
||||
return HashShort(m)
|
||||
}
|
||||
func HashShort(m *ice.Message) string {
|
||||
return kit.Select(HASH, m.Config(SHORT), m.Config(SHORT) != UNIQ)
|
||||
return kit.Select(HASH, Config(m, SHORT), Config(m, SHORT) != UNIQ)
|
||||
}
|
||||
func HashField(m *ice.Message) string { return kit.Select(HASH_FIELD, m.Config(FIELD)) }
|
||||
func HashField(m *ice.Message) string { return kit.Select(HASH_FIELD, Config(m, FIELD)) }
|
||||
func HashInputs(m *ice.Message, arg ...Any) *ice.Message {
|
||||
return m.Cmdy(INPUTS, m.PrefixKey(), "", HASH, arg)
|
||||
}
|
||||
func HashCreate(m *ice.Message, arg ...Any) string {
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, m.OptionSimple(strings.Replace(HashField(m), "hash,", "", 1)))
|
||||
}
|
||||
kit.If(len(arg) == 0 || len(kit.Simple(arg)) == 0, func() { arg = append(arg, m.OptionSimple(strings.Replace(HashField(m), "hash,", "", 1))) })
|
||||
return m.Echo(m.Cmdx(append(kit.List(INSERT, m.PrefixKey(), "", HASH, logs.FileLineMeta(-1)), arg...)...)).Result()
|
||||
}
|
||||
func HashRemove(m *ice.Message, arg ...Any) *ice.Message {
|
||||
@ -210,7 +208,7 @@ func HashSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
m.Fields(len(kit.Slice(arg, 0, 1)), HashField(m))
|
||||
}
|
||||
m.Cmdy(SELECT, m.PrefixKey(), "", HASH, HashShort(m), arg, logs.FileLineMeta(-1))
|
||||
if m.PushAction(m.Config(ACTION), REMOVE); !m.FieldsIsDetail() {
|
||||
if m.PushAction(Config(m, ACTION), REMOVE); !m.FieldsIsDetail() {
|
||||
return m.StatusTimeCount()
|
||||
}
|
||||
return m.StatusTime()
|
||||
@ -258,11 +256,7 @@ func HashSelectDetail(m *ice.Message, key string, cb Any) (has bool) {
|
||||
func HashSelectDetails(m *ice.Message, key string, cb func(ice.Map) bool) ice.Map {
|
||||
val := kit.Dict()
|
||||
HashSelectDetail(m, key, func(value ice.Map) {
|
||||
if cb(value) {
|
||||
for k, v := range value {
|
||||
val[k] = v
|
||||
}
|
||||
}
|
||||
kit.If(cb(value), func() { kit.For(value, func(k string, v ice.Any) { val[k] = v }) })
|
||||
})
|
||||
return val
|
||||
}
|
||||
|
@ -295,9 +295,6 @@ var _lock = task.Lock{}
|
||||
var _locks = map[string]*task.Lock{}
|
||||
|
||||
func getLock(m *ice.Message, key string) *task.Lock {
|
||||
if key == "" {
|
||||
key = m.PrefixKey()
|
||||
}
|
||||
defer _lock.Lock()()
|
||||
l, ok := _locks[key]
|
||||
if !ok {
|
||||
@ -306,16 +303,40 @@ func getLock(m *ice.Message, key string) *task.Lock {
|
||||
}
|
||||
return l
|
||||
}
|
||||
func Lock(m *ice.Message, arg ...ice.Any) func() { return getLock(m, kit.Keys(arg...)).Lock() }
|
||||
func RLock(m *ice.Message, arg ...ice.Any) func() { return getLock(m, kit.Keys(arg...)).RLock() }
|
||||
func Lock(m *ice.Message, arg ...ice.Any) func() {
|
||||
key := kit.Select(m.PrefixKey(), kit.Keys(arg...))
|
||||
m.Option("_lock", key)
|
||||
return getLock(m, key).Lock()
|
||||
}
|
||||
func RLock(m *ice.Message, arg ...ice.Any) func() {
|
||||
key := kit.Select(m.PrefixKey(), kit.Keys(arg...))
|
||||
m.Option("_lock", key)
|
||||
return getLock(m, key).RLock()
|
||||
}
|
||||
|
||||
func Config(m *ice.Message, key string, arg ...ice.Any) string {
|
||||
return kit.Format(Configv(m, key, arg...))
|
||||
}
|
||||
func Configv(m *ice.Message, key string, arg ...ice.Any) ice.Any {
|
||||
if len(arg) > 0 {
|
||||
defer Lock(m, m.PrefixKey(), key)()
|
||||
} else {
|
||||
defer RLock(m, m.PrefixKey(), key)()
|
||||
Confv(m, m.PrefixKey(), kit.Keym(key), arg[0])
|
||||
}
|
||||
return m.Config(key, arg...)
|
||||
return Confv(m, m.PrefixKey(), kit.Keym(key))
|
||||
}
|
||||
func Confv(m *ice.Message, arg ...ice.Any) ice.Any {
|
||||
key := kit.Format(arg[0])
|
||||
if ctx, ok := ice.Info.Index[key].(*ice.Context); ok {
|
||||
key = ctx.PrefixKey(key)
|
||||
}
|
||||
if len(arg) > 1 {
|
||||
defer Lock(m, key)()
|
||||
} else {
|
||||
defer RLock(m, key)()
|
||||
}
|
||||
return m.Confv(arg...)
|
||||
}
|
||||
func Conf(m *ice.Message, arg ...ice.Any) string {
|
||||
return kit.Format(Confv(m, arg...))
|
||||
}
|
||||
|
||||
var cache = sync.Map{}
|
||||
|
@ -158,9 +158,9 @@ func ZoneKey(m *ice.Message) string {
|
||||
return ZoneShort(m)
|
||||
}
|
||||
func ZoneShort(m *ice.Message) string {
|
||||
return kit.Select(ZONE, m.Config(SHORT), m.Config(SHORT) != UNIQ)
|
||||
return kit.Select(ZONE, Config(m, SHORT), Config(m, SHORT) != UNIQ)
|
||||
}
|
||||
func ZoneField(m *ice.Message) string { return kit.Select(ZONE_FIELD, m.Config(FIELD)) }
|
||||
func ZoneField(m *ice.Message) string { return kit.Select(ZONE_FIELD, Config(m, FIELD)) }
|
||||
func ZoneInputs(m *ice.Message, arg ...Any) {
|
||||
m.Cmdy(INPUTS, m.PrefixKey(), "", ZONE, m.Option(ZoneKey(m)), arg)
|
||||
}
|
||||
@ -193,9 +193,9 @@ func ZoneModify(m *ice.Message, arg ...Any) {
|
||||
}
|
||||
func ZoneSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
arg = kit.Slice(arg, 0, 2)
|
||||
m.Fields(len(arg), kit.Select(kit.Fields(TIME, m.Config(SHORT), COUNT), m.Config(FIELDS)), ZoneField(m))
|
||||
m.Fields(len(arg), kit.Select(kit.Fields(TIME, Config(m, SHORT), COUNT), Config(m, FIELDS)), ZoneField(m))
|
||||
if m.Cmdy(SELECT, m.PrefixKey(), "", ZONE, arg, logs.FileLineMeta(-1)); len(arg) == 0 {
|
||||
m.PushAction(m.Config(ACTION), REMOVE).StatusTimeCount().Sort(ZoneShort(m))
|
||||
m.PushAction(Config(m, ACTION), REMOVE).StatusTimeCount().Sort(ZoneShort(m))
|
||||
} else if len(arg) == 1 {
|
||||
// m.StatusTimeCountTotal(_mdb_getmeta(m, m.PrefixKey(), kit.Keys(HASH, HashSelectField(m, arg[0], HASH)), COUNT))
|
||||
m.StatusTimeCount()
|
||||
@ -204,7 +204,7 @@ func ZoneSelect(m *ice.Message, arg ...string) *ice.Message {
|
||||
}
|
||||
func ZoneExport(m *ice.Message, arg ...Any) {
|
||||
if m.OptionFields() == "" {
|
||||
m.OptionFields(m.Config(SHORT), ZoneField(m))
|
||||
m.OptionFields(Config(m, SHORT), ZoneField(m))
|
||||
}
|
||||
m.Cmdy(EXPORT, m.PrefixKey(), "", ZONE, arg)
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ func init() {
|
||||
})
|
||||
}
|
||||
func IsSourceFile(m *ice.Message, ext string) bool {
|
||||
return m.Conf(CAT, kit.Keym(SOURCE, ext)) == ice.TRUE
|
||||
return mdb.Conf(m, Prefix(CAT), kit.Keym(SOURCE, ext)) == ice.TRUE
|
||||
}
|
||||
func OptionLoad(m *ice.Message, file string) *ice.Message {
|
||||
if f, e := OpenFile(m, file); e == nil {
|
||||
|
@ -168,6 +168,7 @@ const (
|
||||
LINE = "line"
|
||||
|
||||
OPENS = "opens"
|
||||
FIND = "find"
|
||||
)
|
||||
const DIR = "dir"
|
||||
|
||||
@ -195,21 +196,14 @@ func init() {
|
||||
TRASH: {Hand: func(m *ice.Message, arg ...string) { m.Cmd(TRASH, mdb.CREATE, m.Option(PATH)) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
root, dir := kit.Select(PWD, m.Option(DIR_ROOT)), kit.Select(PWD, arg, 0)
|
||||
if strings.HasPrefix(dir, ice.PS) {
|
||||
root, dir = ice.PS, strings.TrimPrefix(dir, ice.PS)
|
||||
}
|
||||
if root == ice.PS && dir == ice.PS {
|
||||
root, dir = PWD, PWD
|
||||
}
|
||||
kit.If(strings.HasPrefix(dir, ice.PS), func() { root, dir = ice.PS, strings.TrimPrefix(dir, ice.PS) })
|
||||
kit.If(root == ice.PS && dir == ice.PS, func() { root, dir = PWD, PWD })
|
||||
if !aaa.Right(m, path.Join(root, dir)) {
|
||||
return
|
||||
}
|
||||
m.Logs(FIND, DIR_ROOT, root, PATH, dir, DIR_TYPE, m.Option(DIR_TYPE))
|
||||
fields := kit.Split(kit.Select(kit.Select(DIR_DEF_FIELDS, m.OptionFields()), kit.Join(kit.Slice(arg, 1))))
|
||||
if root != "" {
|
||||
m.Logs(mdb.SELECT, DIR_ROOT, root, dir)
|
||||
}
|
||||
_dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)), fields)
|
||||
m.StatusTimeCount()
|
||||
_dir_list(m, root, dir, 0, m.Option(DIR_DEEP) == ice.TRUE, kit.Select(TYPE_BOTH, m.Option(DIR_TYPE)), kit.Regexp(m.Option(DIR_REG)), fields).StatusTimeCount()
|
||||
}},
|
||||
})
|
||||
}
|
||||
@ -227,7 +221,7 @@ func Relative(m *ice.Message, p string) string {
|
||||
return p
|
||||
}
|
||||
func SplitPath(m *ice.Message, p string) []string {
|
||||
if ls := kit.Split(p, ice.PS); len(ls) == 1 {
|
||||
if ls := kit.Split(kit.Select(ice.SRC_MAIN_GO, p), ice.PS); len(ls) == 1 {
|
||||
return []string{PWD, ls[0]}
|
||||
} else if ls[0] == ice.USR {
|
||||
return []string{strings.Join(ls[:2], ice.PS) + ice.PS, strings.Join(ls[2:], ice.PS)}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package nfs
|
||||
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
const NFS = "nfs"
|
||||
|
||||
@ -9,3 +12,4 @@ var Index = &ice.Context{Name: NFS, Help: "存储模块"}
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil, TAR, CAT, DIR, PACK, DEFS, SAVE, PUSH, COPY, LINK, GREP, TRASH)
|
||||
}
|
||||
func Prefix(arg ...string) string { return kit.Keys(NFS, arg) }
|
||||
|
@ -118,9 +118,9 @@ func (f *Frame) parse(m *ice.Message, h, line string) string {
|
||||
return ""
|
||||
}
|
||||
func (f *Frame) scan(m *ice.Message, h, line string) *Frame {
|
||||
f.ps1 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS1)))
|
||||
f.ps2 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS2)))
|
||||
m.Options(MESSAGE, m, ice.LOG_DISABLE, ice.TRUE)
|
||||
f.ps1 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS1)))
|
||||
f.ps2 = kit.Simple(mdb.Confv(m, PROMPT, kit.Keym(PS2)))
|
||||
// m.Options(MESSAGE, m, ice.LOG_DISABLE, ice.TRUE)
|
||||
m.I, m.O = f.stdin, f.stdout
|
||||
ps, bio := f.ps1, bufio.NewScanner(f.stdin)
|
||||
for f.prompt(m, ps...); f.stdin != nil && bio.Scan(); f.prompt(m, ps...) {
|
||||
|
@ -53,6 +53,7 @@ const (
|
||||
PROTOCOL = "protocol"
|
||||
HOSTPORT = "hostport"
|
||||
HOSTNAME = "hostname"
|
||||
NODENAME = "nodename"
|
||||
)
|
||||
const (
|
||||
LISTEN = "listen"
|
||||
|
@ -114,7 +114,7 @@ func init() {
|
||||
case mdb.NAME, nfs.TEMPLATE:
|
||||
_dream_list(m).Cut("name,status,time")
|
||||
case nfs.REPOS:
|
||||
if msg := m.Cmd(SPIDE, ice.OPS, SPIDE_MSG, m.Option(ice.MSG_USERHOST)+"/x/list"); !msg.IsErr() {
|
||||
if msg := m.Cmd(SPIDE, ice.OPS, SPIDE_MSG, UserHost(m)+"/x/list"); !msg.IsErr() {
|
||||
m.Copy(msg)
|
||||
}
|
||||
for _, dev := range []string{ice.OPS, ice.DEV} {
|
||||
@ -160,7 +160,6 @@ func init() {
|
||||
if len(arg) == 0 {
|
||||
_dream_list(m)
|
||||
} else if arg[0] == ctx.ACTION {
|
||||
m.Option(ice.POD, m.Option(nfs.NAME))
|
||||
gdb.Event(m, DREAM_ACTION, arg)
|
||||
} else {
|
||||
m.Cmdy(nfs.CAT, arg[1:], kit.Dict(nfs.DIR_ROOT, path.Join(ice.USR_LOCAL_WORK, arg[0])))
|
||||
@ -170,5 +169,18 @@ func init() {
|
||||
}
|
||||
|
||||
func DreamAction() ice.Actions {
|
||||
return gdb.EventsAction(DREAM_OPEN, DREAM_CLOSE, DREAM_INPUTS, DREAM_TABLES, DREAM_ACTION)
|
||||
return ice.MergeActions(ice.Actions{
|
||||
DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) { DreamProcess(m, []string{}, arg...) }},
|
||||
}, gdb.EventsAction(DREAM_OPEN, DREAM_CLOSE, DREAM_INPUTS, DREAM_TABLES, DREAM_ACTION))
|
||||
}
|
||||
func DreamProcess(m *ice.Message, args ice.Any, arg ...string) {
|
||||
if kit.HasPrefixList(arg, ice.RUN) {
|
||||
ctx.ProcessField(m, m.PrefixKey(), args, kit.Slice(arg, 1)...)
|
||||
} else if kit.HasPrefixList(arg, ctx.ACTION, m.CommandKey()) {
|
||||
if arg = kit.Slice(arg, 2); kit.HasPrefixList(arg, DREAM) {
|
||||
m.Cmdy(SPACE, m.Option(ice.MSG_USERPOD, arg[1]), m.PrefixKey(), ctx.ACTION, DREAM_ACTION, ice.RUN, arg[2:])
|
||||
} else if dream := m.Option(mdb.NAME); dream != "" {
|
||||
m.Cmdy(SPACE, dream, m.PrefixKey(), ctx.ACTION, DREAM_ACTION, ice.RUN, arg).Optionv(ice.FIELD_PREFIX, kit.Simple(ctx.ACTION, m.CommandKey(), DREAM, dream, ice.RUN))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func PushNotice(m *ice.Message, arg ...ice.Any) {
|
||||
msg.Optionv(ice.MSG_OPTS, msg.Optionv(ice.MSG_OPTION, []string{}))
|
||||
msg.Cmd(SPACE, m.Option(ice.MSG_DAEMON), arg)
|
||||
} else {
|
||||
m.Cmd("web.spide", ice.OPS, MergeURL2(m, SHARE_TOAST+m.Option(ice.MSG_DAEMON)), "arg", kit.Format(arg))
|
||||
m.Cmd(Prefix(SPIDE), ice.OPS, MergeURL2(m, SHARE_TOAST+m.Option(ice.MSG_DAEMON)), ice.ARG, kit.Format(arg))
|
||||
}
|
||||
}
|
||||
func PushNoticeGrow(m *ice.Message, arg ...ice.Any) {
|
||||
@ -167,3 +167,11 @@ func ProcessIframe(m *ice.Message, name, link string, arg ...string) {
|
||||
}
|
||||
ctx.ProcessField(m, "web.chat.iframe", arg, arg...)
|
||||
}
|
||||
|
||||
func UserHost(m *ice.Message) string {
|
||||
if u := OptionUserWeb(m); strings.Contains(u.Host, tcp.LOCALHOST) {
|
||||
return m.Option(ice.MSG_USERHOST, tcp.PublishLocalhost(m, u.Scheme+"://"+u.Host))
|
||||
} else {
|
||||
return m.Option(ice.MSG_USERHOST, u.Scheme+"://"+u.Host)
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -21,41 +20,23 @@ const (
|
||||
COOKIE = "cookie"
|
||||
STATUS = "status"
|
||||
)
|
||||
const (
|
||||
WEBSITE = "website"
|
||||
RESIZE = "resize"
|
||||
OUTPUT = "output"
|
||||
INPUT = "input"
|
||||
VIEW = "view"
|
||||
|
||||
CODE_VIMER = "web.code.vimer"
|
||||
CODE_INNER = "web.code.inner"
|
||||
CODE_XTERM = "web.code.xterm"
|
||||
WIKI_WORD = "web.wiki.word"
|
||||
CHAT_FAVOR = "web.chat.favor"
|
||||
)
|
||||
|
||||
func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
if cmd == ice.RENDER_VOID {
|
||||
return true
|
||||
}
|
||||
arg := kit.Simple(args...)
|
||||
if len(arg) == 0 {
|
||||
args = nil
|
||||
}
|
||||
if cmd != "" && cmd != ice.RENDER_DOWNLOAD {
|
||||
kit.If(len(arg) == 0, func() { args = nil })
|
||||
if cmd != "" && (cmd != ice.RENDER_DOWNLOAD || m.R.Method != http.MethodGet) {
|
||||
defer func() { m.Logs("Render", cmd, args) }()
|
||||
}
|
||||
switch cmd {
|
||||
case COOKIE: // value [name [path [expire]]]
|
||||
RenderCookie(m, arg[0], arg[1:]...)
|
||||
|
||||
case STATUS, ice.RENDER_STATUS: // [code [text]]
|
||||
RenderStatus(m.W, kit.Int(kit.Select("200", arg, 0)), strings.Join(kit.Slice(arg, 1), " "))
|
||||
|
||||
case ice.RENDER_REDIRECT: // url [arg...]
|
||||
http.Redirect(m.W, m.R, kit.MergeURL(arg[0], arg[1:]), http.StatusTemporaryRedirect)
|
||||
|
||||
case ice.RENDER_DOWNLOAD: // file [type [name]]
|
||||
if strings.HasPrefix(arg[0], ice.HTTP) {
|
||||
RenderRedirect(m, arg[0])
|
||||
@ -69,7 +50,6 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
defer f.Close()
|
||||
io.Copy(m.W, f)
|
||||
}
|
||||
|
||||
case ice.RENDER_RESULT:
|
||||
if len(arg) > 0 { // [str [arg...]]
|
||||
m.W.Write([]byte(kit.Format(arg[0], args[1:]...)))
|
||||
@ -79,11 +59,9 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
}
|
||||
m.W.Write([]byte(m.Result()))
|
||||
}
|
||||
|
||||
case ice.RENDER_JSON:
|
||||
RenderType(m.W, nfs.JSON, "")
|
||||
m.W.Write([]byte(arg[0]))
|
||||
|
||||
default:
|
||||
if cmd != "" && cmd != ice.RENDER_RAW {
|
||||
m.Echo(kit.Format(cmd, args...))
|
||||
@ -91,9 +69,15 @@ func Render(m *ice.Message, cmd string, args ...ice.Any) bool {
|
||||
RenderType(m.W, nfs.JSON, "")
|
||||
m.DumpMeta(m.W)
|
||||
}
|
||||
m.Render(ice.RENDER_VOID)
|
||||
return true
|
||||
}
|
||||
|
||||
func CookieName(url string) string { return ice.MSG_SESSID + "_" + kit.ParseURLMap(url)[tcp.PORT] }
|
||||
func RenderCookie(m *ice.Message, value string, arg ...string) { // name path expire
|
||||
http.SetCookie(m.W, &http.Cookie{Value: value, Name: kit.Select(CookieName(m.Option(ice.MSG_USERWEB)), arg, 0),
|
||||
Path: kit.Select(ice.PS, arg, 1), Expires: time.Now().Add(kit.Duration(kit.Select(mdb.MONTH, arg, 2)))})
|
||||
}
|
||||
func RenderType(w http.ResponseWriter, name, mime string) {
|
||||
if mime == "" {
|
||||
switch kit.Ext(name) {
|
||||
@ -107,93 +91,73 @@ func RenderType(w http.ResponseWriter, name, mime string) {
|
||||
}
|
||||
RenderHeader(w, ContentType, mime)
|
||||
}
|
||||
func RenderOrigin(w http.ResponseWriter, origin string) {
|
||||
RenderHeader(w, "Access-Control-Allow-Origin", origin)
|
||||
}
|
||||
func RenderHeader(w http.ResponseWriter, key, value string) {
|
||||
w.Header().Set(key, value)
|
||||
}
|
||||
func RenderCookie(m *ice.Message, value string, arg ...string) { // name path expire
|
||||
expire := time.Now().Add(kit.Duration(kit.Select(m.Conf(aaa.SESS, kit.Keym(mdb.EXPIRE)), arg, 2)))
|
||||
http.SetCookie(m.W, &http.Cookie{Value: value,
|
||||
Name: kit.Select(CookieName(m.Option(ice.MSG_USERWEB)), arg, 0), Path: kit.Select(ice.PS, arg, 1), Expires: expire})
|
||||
}
|
||||
func RenderStatus(w http.ResponseWriter, code int, text string) {
|
||||
w.WriteHeader(code)
|
||||
w.Write([]byte(text))
|
||||
}
|
||||
func RenderRefresh(m *ice.Message, arg ...string) { // url text delay
|
||||
Render(m, ice.RENDER_RESULT, kit.Format(`
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="%s; url='%s'">
|
||||
</head>
|
||||
<body>
|
||||
%s
|
||||
</body>
|
||||
</html>
|
||||
`, kit.Select("3", arg, 2), kit.Select(m.Option(ice.MSG_USERWEB), arg, 0), kit.Select("loading...", arg, 1)))
|
||||
m.Render(ice.RENDER_VOID)
|
||||
}
|
||||
func RenderRedirect(m *ice.Message, arg ...ice.Any) {
|
||||
Render(m, ice.RENDER_REDIRECT, arg...)
|
||||
m.Render(ice.RENDER_VOID)
|
||||
}
|
||||
func RenderDownload(m *ice.Message, arg ...ice.Any) {
|
||||
Render(m, ice.RENDER_DOWNLOAD, arg...)
|
||||
m.Render(ice.RENDER_VOID)
|
||||
}
|
||||
func RenderResult(m *ice.Message, arg ...ice.Any) {
|
||||
Render(m, ice.RENDER_RESULT, arg...)
|
||||
m.Render(ice.RENDER_VOID)
|
||||
}
|
||||
func RenderTemplate(m *ice.Message, file string, arg ...ice.Any) {
|
||||
m.RenderResult(kit.Renders(kit.Format(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, WEB, file)), arg...), m))
|
||||
func RenderTemplate(m *ice.Message, file string, arg ...ice.Any) *ice.Message {
|
||||
return m.RenderResult(kit.Renders(kit.Format(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, WEB, file)), arg...), m))
|
||||
}
|
||||
|
||||
func AllowOrigin(m *ice.Message, origin string) {
|
||||
m.W.Header().Set("Access-Control-Allow-Origin", origin)
|
||||
func RenderRefresh(m *ice.Message, arg ...string) { // url text delay
|
||||
RenderTemplate(m, "refresh.html", kit.Select("3", arg, 2), kit.Select(m.Option(ice.MSG_USERWEB), arg, 0), kit.Select("loading...", arg, 1))
|
||||
}
|
||||
func CookieName(url string) string {
|
||||
return ice.MSG_SESSID + "_" + kit.ReplaceAll(kit.ParseURLMap(url)[tcp.PORT], ".", "_", ":", "_")
|
||||
return ice.MSG_SESSID + "_" + kit.ReplaceAll(kit.ParseURLMap(url)[tcp.HOST], ".", "_", ":", "_")
|
||||
}
|
||||
|
||||
func RenderIndex(m *ice.Message, repos string, file ...string) *ice.Message {
|
||||
func RenderIndex(m *ice.Message, file ...string) *ice.Message {
|
||||
if m.IsCliUA() {
|
||||
return m.RenderDownload(path.Join(ice.USR_INTSHELL, kit.Select(ice.INDEX_SH, path.Join(file...))))
|
||||
}
|
||||
return m.RenderDownload(path.Join(ice.USR_VOLCANOS, kit.Select("page/"+ice.INDEX_HTML, path.Join(file...))))
|
||||
|
||||
if repos == "" {
|
||||
repos = kit.Select(ice.VOLCANOS, ice.INTSHELL, m.IsCliUA())
|
||||
}
|
||||
p := func() string {
|
||||
defer mdb.RLock(m, "web.serve")()
|
||||
return path.Join(m.Conf(SERVE, kit.Keym(repos, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(repos, INDEX)), path.Join(file...)))
|
||||
}
|
||||
return m.RenderDownload(p())
|
||||
}
|
||||
func RenderMain(m *ice.Message, pod, index string, arg ...ice.Any) *ice.Message {
|
||||
if script := m.Cmdx(Space(m, pod), nfs.CAT, kit.Select(ice.SRC_MAIN_JS, index)); script != "" {
|
||||
return m.Echo(kit.Renders(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "web/main.html")), ice.Maps{nfs.VERSION: renderVersion(m), nfs.SCRIPT: script})).RenderResult()
|
||||
func RenderMain(m *ice.Message) *ice.Message {
|
||||
if m.IsCliUA() {
|
||||
return m.RenderDownload(path.Join(ice.USR_INTSHELL, ice.INDEX_SH))
|
||||
}
|
||||
return RenderIndex(m, ice.VOLCANOS)
|
||||
}
|
||||
func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) {
|
||||
RenderPodCmd(m, "", cmd, arg...)
|
||||
return RenderTemplate(m.Options(nfs.VERSION, renderVersion(m)), "main.html")
|
||||
}
|
||||
func RenderCmds(m *ice.Message, list ...ice.Any) {
|
||||
m.Echo(kit.Renders(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "web/cmd.html")), ice.Maps{nfs.VERSION: renderVersion(m), ice.LIST: kit.Format(list)})).RenderResult()
|
||||
RenderTemplate(m.Options(nfs.VERSION, renderVersion(m), mdb.LIST, kit.Format(list)), "cmds.html")
|
||||
}
|
||||
func RenderPodCmd(m *ice.Message, pod, cmd string, arg ...ice.Any) {
|
||||
msg := m.Cmd(Space(m, pod), ctx.COMMAND, kit.Select("web.wiki.word", cmd))
|
||||
list := kit.Format(kit.List(kit.Dict(msg.AppendSimple(mdb.NAME, mdb.HELP),
|
||||
RenderCmds(m, kit.Dict(msg.AppendSimple(mdb.NAME, mdb.HELP),
|
||||
ctx.INDEX, cmd, ctx.ARGS, kit.Simple(arg), ctx.DISPLAY, m.Option(ice.MSG_DISPLAY),
|
||||
mdb.LIST, kit.UnMarshal(msg.Append(mdb.LIST)), mdb.META, kit.UnMarshal(msg.Append(mdb.META)),
|
||||
)))
|
||||
m.Echo(kit.Renders(m.Cmdx(nfs.CAT, path.Join(ice.SRC_TEMPLATE, "web/cmd.html")), ice.Maps{nfs.VERSION: renderVersion(m), ice.LIST: list})).RenderResult()
|
||||
))
|
||||
}
|
||||
func RenderCmd(m *ice.Message, cmd string, arg ...ice.Any) { RenderPodCmd(m, "", cmd, arg...) }
|
||||
func renderVersion(m *ice.Message) string {
|
||||
if strings.Contains(m.R.URL.RawQuery, "debug=true") {
|
||||
return kit.Format("?_v=%v&_t=%d", ice.Info.Make.Version, time.Now().Unix())
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
const (
|
||||
WEBSITE = "website"
|
||||
RESIZE = "resize"
|
||||
LAYOUT = "layout"
|
||||
OUTPUT = "output"
|
||||
INPUT = "input"
|
||||
VIEW = "view"
|
||||
CHAT = "chat"
|
||||
|
||||
CODE_VIMER = "web.code.vimer"
|
||||
CODE_INNER = "web.code.inner"
|
||||
CODE_XTERM = "web.code.xterm"
|
||||
CHAT_FAVOR = "web.chat.favor"
|
||||
WIKI_WORD = "web.wiki.word"
|
||||
)
|
||||
|
@ -7,6 +7,8 @@ import (
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
@ -20,21 +22,17 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _serve_address(m *ice.Message) string {
|
||||
return kit.Format("http://localhost:%s", m.Option(tcp.PORT))
|
||||
}
|
||||
func _serve_start(m *ice.Message) {
|
||||
if m.Option(aaa.USERNAME) != "" {
|
||||
aaa.UserRoot(m, m.Option(aaa.USERNAME), m.Option(aaa.USERNICK))
|
||||
}
|
||||
if cli.NodeInfo(m, kit.Select(ice.Info.Hostname, m.Option("nodename")), SERVER); m.Option(tcp.PORT) == tcp.RANDOM {
|
||||
m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT))
|
||||
}
|
||||
if runtime.GOOS == cli.WINDOWS {
|
||||
m.Cmd(SPIDE, ice.OPS, kit.Format("http://localhost:%s/exit", m.Option(tcp.PORT))).Sleep("100ms")
|
||||
}
|
||||
defer kit.For(kit.Split(m.Option(ice.DEV)), func(v string) { m.Cmd(SPACE, tcp.DIAL, ice.DEV, v, mdb.NAME, ice.Info.NodeName) })
|
||||
kit.If(m.Option(aaa.USERNAME), func() { aaa.UserRoot(m, m.Option(aaa.USERNAME), m.Option(aaa.USERNICK)) })
|
||||
kit.If(m.Option(tcp.PORT) == tcp.RANDOM, func() { m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT)) })
|
||||
kit.If(runtime.GOOS == cli.WINDOWS, func() { m.Cmd(SPIDE, ice.OPS, _serve_address(m)+"/exit").Sleep("300ms") })
|
||||
cli.NodeInfo(m, kit.Select(ice.Info.Hostname, m.Option(tcp.NODENAME)), SERVER)
|
||||
m.Target().Start(m, m.OptionSimple(tcp.HOST, tcp.PORT)...)
|
||||
m.Sleep("300ms")
|
||||
for _, v := range kit.Split(m.Option(ice.DEV)) {
|
||||
m.Cmd(SPACE, tcp.DIAL, ice.DEV, v, mdb.NAME, ice.Info.NodeName)
|
||||
}
|
||||
}
|
||||
func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
const (
|
||||
@ -42,7 +40,6 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
X_REAL_PORT = "X-Real-Port"
|
||||
X_FORWARDED_FOR = "X-Forwarded-For"
|
||||
INDEX_MODULE = "Index-Module"
|
||||
MOZILLA = "Mozilla/5.0"
|
||||
)
|
||||
if r.Header.Get(INDEX_MODULE) == "" {
|
||||
r.Header.Set(INDEX_MODULE, m.Prefix())
|
||||
@ -60,37 +57,28 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
} else {
|
||||
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, ice.DF)[0])
|
||||
}
|
||||
if m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String()); m.Config(LOGHEADERS) == ice.TRUE {
|
||||
kit.Fetch(r.Header, func(k string, v []string) { m.Logs("Header", k, v) })
|
||||
}
|
||||
if r.Method == http.MethodGet && r.URL.Path != PP(SPACE) && !strings.HasPrefix(r.URL.Path, "/code/bash") {
|
||||
repos := kit.Select(ice.INTSHELL, ice.VOLCANOS, strings.Contains(r.Header.Get(UserAgent), MOZILLA))
|
||||
dir := kit.Select(ice.USR_INTSHELL, ice.USR_VOLCANOS, strings.Contains(r.Header.Get(UserAgent), MOZILLA))
|
||||
if p := path.Join(ice.USR, repos, r.URL.Path); r.URL.Path != ice.PS && nfs.ExistsFile(m, p) {
|
||||
Render(m.Spawn(w, r), ice.RENDER_DOWNLOAD, p)
|
||||
return false
|
||||
} else if msg := gdb.Event(m.Spawn(w, r), SERVE_REWRITE, r.Method, r.URL.Path, path.Join(dir, r.URL.Path), repos); msg.Option(ice.MSG_OUTPUT) != "" {
|
||||
Render(msg, msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...)
|
||||
return false
|
||||
if m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String()); r.Method == http.MethodGet {
|
||||
if msg := m.Spawn(w, r).Options(ice.MSG_USERUA, r.UserAgent()); path.Join(r.URL.Path) == ice.PS {
|
||||
return !Render(RenderMain(msg), msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...)
|
||||
} else if p := path.Join(kit.Select(ice.USR_VOLCANOS, ice.USR_INTSHELL, msg.IsCliUA()), r.URL.Path); nfs.ExistsFile(msg, p) {
|
||||
return !Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||
if u, e := url.Parse(r.Header.Get(Referer)); e == nil && r.URL.Path != PP(SPACE) {
|
||||
add := func(k, v string) { m.Logs("path", k, m.Option(k, v)) }
|
||||
_log := func(level string, arg ...ice.Any) *ice.Message { return m.Logs(level, arg...) }
|
||||
if u, e := url.Parse(r.Header.Get(Referer)); e == nil {
|
||||
add := func(k, v string) { _log("Path", k, m.Option(k, v)) }
|
||||
switch arg := strings.Split(strings.TrimPrefix(u.Path, ice.PS), ice.PS); arg[0] {
|
||||
case "share":
|
||||
case CHAT:
|
||||
kit.For(arg[1:], func(k, v string) { add(k, v) })
|
||||
case SHARE:
|
||||
add(arg[0], arg[1])
|
||||
case "chat":
|
||||
for i := 1; i < len(arg)-1; i += 2 {
|
||||
add(arg[i], arg[i+1])
|
||||
}
|
||||
}
|
||||
// gdb.Event(m, SERVE_PARSE, strings.Split(strings.TrimPrefix(u.Path, ice.PS), ice.PS))
|
||||
kit.Fetch(u.Query(), func(k string, v []string) { m.Logs("Refer", k, v).Optionv(k, v) })
|
||||
kit.For(u.Query(), func(k string, v []string) { _log("Refer", k, v).Optionv(k, v) })
|
||||
}
|
||||
m.Option(ice.MSG_USERUA, r.Header.Get(UserAgent))
|
||||
m.Options(ice.MSG_USERUA, r.Header.Get(UserAgent), ice.MSG_HEIGHT, "480", ice.MSG_WIDTH, "320")
|
||||
for k, v := range kit.ParseQuery(r.URL.RawQuery) {
|
||||
kit.If(m.IsCliUA(), func() { v = kit.Simple(v, func(v string) (string, error) { return url.QueryUnescape(v) }) })
|
||||
m.Optionv(k, v)
|
||||
@ -98,36 +86,26 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
||||
switch r.Header.Get(ContentType) {
|
||||
case ContentJSON:
|
||||
data := kit.UnMarshal(r.Body)
|
||||
m.Logs(mdb.IMPORT, mdb.VALUE, kit.Format(data)).Optionv(ice.MSG_USERDATA, data)
|
||||
kit.Fetch(data, func(k string, v ice.Any) { m.Optionv(k, v) })
|
||||
_log("Body", mdb.VALUE, kit.Format(data)).Optionv(ice.MSG_USERDATA, data)
|
||||
kit.For(data, func(k string, v ice.Any) { m.Optionv(k, v) })
|
||||
default:
|
||||
r.ParseMultipartForm(kit.Int64(kit.Select("4096", r.Header.Get(ContentLength))))
|
||||
kit.Fetch(r.PostForm, func(k string, v []string) {
|
||||
kit.For(r.PostForm, func(k string, v []string) {
|
||||
kit.If(m.IsCliUA(), func() { v = kit.Simple(v, func(v string) (string, error) { return url.QueryUnescape(v) }) })
|
||||
m.Logs("Form", k, kit.Join(v, ice.SP)).Optionv(k, v)
|
||||
_log("Form", k, kit.Join(v, ice.SP)).Optionv(k, v)
|
||||
})
|
||||
}
|
||||
kit.Fetch(r.Cookies(), func(k, v string) { m.Optionv(k, v) })
|
||||
m.OptionDefault(ice.MSG_HEIGHT, "480", ice.MSG_WIDTH, "320")
|
||||
m.Option(ice.MSG_USERUA, r.Header.Get(UserAgent))
|
||||
m.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
|
||||
m.Option(ice.MSG_USERADDR, kit.Select(r.RemoteAddr, r.Header.Get(ice.MSG_USERADDR)))
|
||||
if m.Option(ice.MSG_USERWEB, _serve_domain(m)); m.Option(ice.POD) != "" {
|
||||
m.Option(ice.MSG_USERPOD, m.Option(ice.POD))
|
||||
}
|
||||
if u := OptionUserWeb(m); strings.Contains(u.Host, tcp.LOCALHOST) {
|
||||
m.Option(ice.MSG_USERHOST, tcp.PublishLocalhost(m, u.Scheme+"://"+u.Host))
|
||||
} else {
|
||||
m.Option(ice.MSG_USERHOST, u.Scheme+"://"+u.Host)
|
||||
}
|
||||
m.Option(ice.MSG_SESSID, kit.Select(m.Option(ice.MSG_SESSID), m.Option(CookieName(m.Option(ice.MSG_USERWEB)))))
|
||||
kit.For(r.Cookies(), func(k, v string) { m.Optionv(k, v) })
|
||||
m.Options(ice.MSG_USERWEB, _serve_domain(m), ice.MSG_USERPOD, m.Option(ice.POD))
|
||||
m.Options(ice.MSG_SESSID, kit.Select(m.Option(ice.MSG_SESSID), m.Option(CookieName(m.Option(ice.MSG_USERWEB)))))
|
||||
m.Options(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP), ice.MSG_USERADDR, kit.Select(r.RemoteAddr, r.Header.Get(ice.MSG_USERADDR)))
|
||||
if m.Optionv(ice.MSG_CMDS) == nil {
|
||||
if p := strings.TrimPrefix(r.URL.Path, key); p != "" {
|
||||
m.Optionv(ice.MSG_CMDS, strings.Split(p, ice.PS))
|
||||
}
|
||||
}
|
||||
if cmds, ok := _serve_login(m, key, kit.Simple(m.Optionv(ice.MSG_CMDS)), w, r); ok {
|
||||
defer func() { m.Cost(kit.Format("%s %v %v", r.URL.Path, cmds, m.FormatSize())) }()
|
||||
defer func() { m.Cost(kit.Format("%s: %s %v", r.Method, m.PrefixPath()+path.Join(cmds...), m.FormatSize())) }()
|
||||
m.Option(ice.MSG_OPTS, kit.Simple(m.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) }))
|
||||
if m.Detailv(m.PrefixKey(), cmds); len(cmds) > 1 && cmds[0] == ctx.ACTION {
|
||||
m.ActionHand(cmd, key, cmds[1], cmds[2:]...)
|
||||
@ -135,7 +113,7 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
||||
m.CmdHand(cmd, key, cmds...)
|
||||
}
|
||||
}
|
||||
Render(m, m.Option(ice.MSG_OUTPUT), m.Optionv(ice.MSG_ARGS))
|
||||
Render(m, m.Option(ice.MSG_OUTPUT), kit.List(m.Optionv(ice.MSG_ARGS))...)
|
||||
}
|
||||
func _serve_domain(m *ice.Message) string {
|
||||
return kit.GetValid(
|
||||
@ -150,13 +128,30 @@ func _serve_domain(m *ice.Message) string {
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
var localhost = sync.Map{}
|
||||
|
||||
func _serve_login(m *ice.Message, key string, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
|
||||
if aaa.SessCheck(m, m.Option(ice.MSG_SESSID)); m.Option(ice.MSG_USERNAME) == "" && r.URL.Path != PP(SPACE) && !strings.HasPrefix(r.URL.Path, "/sync") {
|
||||
if m.Conf(SERVE, kit.Keym(tcp.LOCALHOST)) == ice.TRUE && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
|
||||
if r.URL.Path == PP(SPACE) {
|
||||
return cmds, true
|
||||
}
|
||||
if aaa.SessCheck(m, m.Option(ice.MSG_SESSID)); m.Option(ice.MSG_USERNAME) == "" {
|
||||
last, ok := localhost.Load(m.Option(ice.MSG_USERIP))
|
||||
if ls := kit.Simple(last); ok && len(ls) > 0 && kit.Time(m.Time())-kit.Time(ls[0]) < int64(time.Hour) {
|
||||
m.Auth(
|
||||
aaa.USERNICK, m.Option(ice.MSG_USERNICK, ls[1]),
|
||||
aaa.USERNAME, m.Option(ice.MSG_USERNAME, ls[2]),
|
||||
aaa.USERROLE, m.Option(ice.MSG_USERROLE, ls[3]),
|
||||
"last", ls[0],
|
||||
)
|
||||
} else if ice.Info.Localhost && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) {
|
||||
aaa.UserRoot(m)
|
||||
} else {
|
||||
gdb.Event(m, SERVE_LOGIN)
|
||||
}
|
||||
if ice.Info.Localhost {
|
||||
localhost.Store(m.Option(ice.MSG_USERIP), kit.Simple(m.Time(), m.OptionSplit(ice.MSG_USERNICK, ice.MSG_USERNAME, ice.MSG_USERROLE)))
|
||||
}
|
||||
}
|
||||
if _, ok := m.Target().Commands[WEB_LOGIN]; ok {
|
||||
return cmds, !m.Target().Cmd(m, WEB_LOGIN, kit.Simple(key, cmds)...).IsErr()
|
||||
@ -168,21 +163,15 @@ func _serve_login(m *ice.Message, key string, cmds []string, w http.ResponseWrit
|
||||
return cmds, aaa.Right(m, key, cmds)
|
||||
}
|
||||
}
|
||||
func _serve_address(m *ice.Message) string {
|
||||
return kit.Format("http://localhost:%s", m.Option(tcp.PORT))
|
||||
}
|
||||
|
||||
const (
|
||||
SERVE_START = "serve.start"
|
||||
SERVE_REWRITE = "serve.rewrite"
|
||||
SERVE_PARSE = "serve.parse"
|
||||
SERVE_LOGIN = "serve.login"
|
||||
SERVE_CHECK = "serve.check"
|
||||
SERVE_STOP = "serve.stop"
|
||||
SERVE_START = "serve.start"
|
||||
SERVE_LOGIN = "serve.login"
|
||||
SERVE_CHECK = "serve.check"
|
||||
|
||||
REQUIRE_MODULES = "require/modules/"
|
||||
REQUIRE_USR = "require/usr/"
|
||||
REQUIRE_SRC = "require/src/"
|
||||
REQUIRE_USR = "require/usr/"
|
||||
REQUIRE_MODULES = "require/modules/"
|
||||
|
||||
WEB_LOGIN = "_login"
|
||||
DOMAIN = "domain"
|
||||
@ -192,13 +181,11 @@ const (
|
||||
const SERVE = "serve"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
"/exit": {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(ice.EXIT) }},
|
||||
Index.MergeCommands(ice.Commands{"/exit": {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(ice.EXIT) }},
|
||||
SERVE: {Name: "serve name auto start", Help: "服务器", Actions: ice.MergeActions(ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ice.Info.Localhost = m.Config(tcp.LOCALHOST) == ice.TRUE
|
||||
cli.NodeInfo(m, ice.Info.Pathname, WORKER)
|
||||
ice.Info.Intshell = path.Join(m.Conf(SERVE, kit.Keym(ice.INTSHELL, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(ice.INTSHELL, INDEX))))
|
||||
ice.Info.Volcanos = path.Join(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, nfs.PATH)), kit.Select(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, INDEX))))
|
||||
}},
|
||||
cli.START: {Name: "start dev proto host port=9020 nodename username usernick", Hand: func(m *ice.Message, arg ...string) {
|
||||
_serve_start(m)
|
||||
@ -220,58 +207,29 @@ func init() {
|
||||
cli.Opens(m, _serve_address(m))
|
||||
}()
|
||||
}},
|
||||
SERVE_REWRITE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] != http.MethodGet {
|
||||
return
|
||||
}
|
||||
switch arg[1] {
|
||||
case ice.PS:
|
||||
if arg[3] == ice.INTSHELL {
|
||||
RenderIndex(m, arg[3])
|
||||
} else {
|
||||
RenderMain(m, "", "")
|
||||
}
|
||||
default:
|
||||
if nfs.ExistsFile(m, arg[2]) {
|
||||
m.RenderDownload(arg[2])
|
||||
}
|
||||
}
|
||||
}},
|
||||
DOMAIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
m.Config(tcp.LOCALHOST, ice.FALSE)
|
||||
ice.Info.Domain = arg[0]
|
||||
}
|
||||
kit.If(len(arg) > 0, func() { ice.Info.Domain, ice.Info.Localhost = arg[0], false })
|
||||
m.Echo(ice.Info.Domain)
|
||||
}},
|
||||
}, mdb.HashAction(
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,proto,host,port", tcp.LOCALHOST, ice.TRUE, LOGHEADERS, ice.FALSE,
|
||||
ice.INTSHELL, kit.Dict(nfs.PATH, ice.USR_INTSHELL, INDEX, ice.INDEX_SH, nfs.REPOS, "https://shylinux.com/x/intshell", nfs.BRANCH, nfs.MASTER),
|
||||
ice.VOLCANOS, kit.Dict(nfs.PATH, ice.USR_VOLCANOS, INDEX, "page/index.html", nfs.REPOS, "https://shylinux.com/x/volcanos", nfs.BRANCH, nfs.MASTER),
|
||||
), mdb.ClearHashOnExitAction(), ServeAction())},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,proto,host,port", tcp.LOCALHOST, ice.TRUE), mdb.ClearHashOnExitAction(), ServeAction())},
|
||||
PP(ice.INTSHELL): {Name: "/intshell/", Help: "命令行", Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
RenderIndex(m, ice.INTSHELL, arg...)
|
||||
RenderIndex(m, arg...)
|
||||
}},
|
||||
PP(ice.VOLCANOS): {Name: "/volcanos/", Help: "浏览器", Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
RenderIndex(m, ice.VOLCANOS, arg...)
|
||||
RenderIndex(m, arg...)
|
||||
}},
|
||||
PP(ice.PUBLISH): {Name: "/publish/", Help: "定制化", Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_local(m, ice.USR_PUBLISH, path.Join(arg...))
|
||||
}},
|
||||
PP(ice.PUBLISH, "demo"): {Name: "/publish/demo", Help: "定制化", Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.RenderRedirect("/")
|
||||
}},
|
||||
PP(ice.REQUIRE): {Name: "/require/shylinux.com/x/volcanos/proto.js", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 4 {
|
||||
m.RenderStatusBadRequest()
|
||||
return
|
||||
}
|
||||
if path.Join(arg[:3]...) == ice.Info.Make.Module && nfs.ExistsFile(m, path.Join(arg[3:]...)) {
|
||||
} else if path.Join(arg[:3]...) == ice.Info.Make.Module && nfs.ExistsFile(m, path.Join(arg[3:]...)) {
|
||||
m.RenderDownload(path.Join(arg[3:]...))
|
||||
return
|
||||
}
|
||||
cache := kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, "go", "env", "GOMODCACHE"))
|
||||
p := path.Join(cache, path.Join(arg...))
|
||||
p := path.Join(kit.Select(ice.USR_REQUIRE, m.Cmdx(cli.SYSTEM, "go", "env", "GOMODCACHE")), path.Join(arg...))
|
||||
if !nfs.ExistsFile(m, p) {
|
||||
if p = path.Join(ice.USR_REQUIRE, path.Join(arg...)); !nfs.ExistsFile(m, p) {
|
||||
ls := strings.SplitN(path.Join(arg[:3]...), ice.AT, 2)
|
||||
@ -284,6 +242,12 @@ func init() {
|
||||
}
|
||||
m.RenderDownload(p)
|
||||
}},
|
||||
PP(REQUIRE_SRC): {Name: "/require/src/", Help: "源代码", Actions: ice.MergeActions(ctx.CmdAction(), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_local(m, ice.SRC, path.Join(arg...))
|
||||
}},
|
||||
PP(REQUIRE_USR): {Name: "/require/usr/", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_local(m, ice.USR, path.Join(arg...))
|
||||
}},
|
||||
PP(REQUIRE_MODULES): {Name: "/require/modules/", Help: "依赖库", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := path.Join(ice.USR_NODE_MODULES, path.Join(arg...))
|
||||
if !nfs.ExistsFile(m, p) {
|
||||
@ -291,12 +255,6 @@ func init() {
|
||||
}
|
||||
m.RenderDownload(p)
|
||||
}},
|
||||
PP(REQUIRE_USR): {Name: "/require/usr/", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_local(m, ice.USR, path.Join(arg...))
|
||||
}},
|
||||
PP(REQUIRE_SRC): {Name: "/require/src/", Help: "源代码", Actions: ice.MergeActions(ice.Actions{}, ctx.CmdAction(), aaa.RoleAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
_share_local(m, ice.SRC, path.Join(arg...))
|
||||
}},
|
||||
PP(ice.HELP): {Name: "/help/", Help: "帮助", Actions: ice.MergeActions(ctx.CmdAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, "tutor.shy")
|
||||
@ -324,6 +282,4 @@ func init() {
|
||||
return nil, nil
|
||||
})
|
||||
}
|
||||
func ServeAction() ice.Actions {
|
||||
return gdb.EventsAction(SERVE_START, SERVE_REWRITE, SERVE_PARSE, SERVE_LOGIN, SERVE_CHECK, SERVE_STOP)
|
||||
}
|
||||
func ServeAction() ice.Actions { return gdb.EventsAction(SERVE_START, SERVE_LOGIN, SERVE_CHECK) }
|
||||
|
@ -107,11 +107,6 @@ func init() {
|
||||
LOGIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoQRCode(m.Cmd(SHARE, mdb.CREATE, mdb.TYPE, LOGIN).Option(mdb.LINK)).ProcessInner()
|
||||
}},
|
||||
SERVE_PARSE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.Select("", arg, 0) == SHARE {
|
||||
m.Logs("Refer", arg[0], arg[1]).Option(arg[0], arg[1])
|
||||
}
|
||||
}},
|
||||
SERVE_LOGIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(ice.MSG_USERNAME) == "" && m.Option(SHARE) != "" {
|
||||
switch msg := m.Cmd(SHARE, m.Option(SHARE)); msg.Append(mdb.TYPE) {
|
||||
@ -134,7 +129,7 @@ func init() {
|
||||
case LOGIN:
|
||||
m.RenderRedirect(ice.PS, ice.MSG_SESSID, aaa.SessCreate(m, msg.Append(aaa.USERNAME)))
|
||||
default:
|
||||
RenderMain(m, "", "")
|
||||
RenderMain(m)
|
||||
}
|
||||
}},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,username,usernick,userrole,river,storm,type,name,text", mdb.EXPIRE, "72h"), ServeAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -46,19 +46,20 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
})
|
||||
}
|
||||
func _space_fork(m *ice.Message) {
|
||||
buffer := kit.Dict(m.Configv(BUFFER))
|
||||
if conn, e := websocket.Upgrade(m.W, m.R, nil, kit.Int(buffer["r"]), kit.Int(buffer["w"])); m.Assert(e) {
|
||||
if conn, e := websocket.Upgrade(m.W, m.R, nil, ice.MOD_BUFS, ice.MOD_BUFS); m.Assert(e) {
|
||||
text := kit.Select(m.Option(ice.MSG_USERADDR), m.Option(mdb.TEXT))
|
||||
name := strings.ToLower(kit.ReplaceAll(kit.Select(m.Option(ice.MSG_USERADDR), m.Option(mdb.NAME)), ice.PT, "_", ice.DF, "_"))
|
||||
args := kit.Simple(mdb.TYPE, kit.Select(WORKER, m.Option(mdb.TYPE)), mdb.NAME, name, mdb.TEXT, text, m.OptionSimple(SHARE, RIVER, ice.MSG_USERUA, cli.DAEMON))
|
||||
m.Go(func() {
|
||||
defer mdb.HashCreateDeferRemove(m, args, kit.Dict(mdb.TARGET, conn))()
|
||||
defer gdb.EventDeferEvent(m, SPACE_OPEN, args)(SPACE_CLOSE, args)
|
||||
// defer gdb.EventDeferEvent(m, SPACE_OPEN, args)(SPACE_CLOSE, args)
|
||||
switch m.Option(mdb.TYPE) {
|
||||
case WORKER:
|
||||
defer gdb.EventDeferEvent(m, DREAM_OPEN, args)(DREAM_CLOSE, args)
|
||||
case CHROME:
|
||||
m.Go(func() { m.Sleep30ms().Cmd(SPACE, name, cli.PWD, name) })
|
||||
case aaa.LOGIN:
|
||||
gdb.EventDeferEvent(m, SPACE_LOGIN, args)
|
||||
}
|
||||
_space_handle(m, false, name, conn)
|
||||
})
|
||||
@ -73,7 +74,7 @@ func _space_handle(m *ice.Message, safe bool, name string, conn *websocket.Conn)
|
||||
}
|
||||
msg := m.Spawn(b)
|
||||
source, target := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name), kit.Simple(msg.Optionv(ice.MSG_TARGET))
|
||||
// msg.Log("recv", "%v->%v %v %v", source, target, msg.Detailv(), msg.FormatMeta())
|
||||
msg.Log("recv", "%v->%v %v %v", source, target, msg.Detailv(), msg.DumpMeta(nil))
|
||||
if next := msg.Option(ice.MSG_TARGET); next == "" || len(target) == 0 {
|
||||
if msg.Optionv(ice.MSG_HANDLE, ice.TRUE); safe { // 下行命令
|
||||
gdb.Event(msg, SPACE_LOGIN)
|
||||
@ -111,16 +112,17 @@ func _space_exec(msg *ice.Message, source, target []string, conn *websocket.Conn
|
||||
default:
|
||||
if aaa.Right(msg, msg.Detailv()) {
|
||||
msg = msg.Cmd()
|
||||
msg.Option("debug", msg.Option("debug"))
|
||||
}
|
||||
}
|
||||
defer msg.Cost(kit.Format("%v->%v %v %v", source, target, msg.Detailv(), msg.FormatSize()))
|
||||
_space_echo(msg.Set(ice.MSG_OPTS), []string{}, kit.Revert(kit.Simple(source)), conn)
|
||||
_space_echo(msg.Set(ice.MSG_OPTS), []string{}, kit.Reverse(kit.Simple(source)), conn)
|
||||
}
|
||||
func _space_echo(m *ice.Message, source, target []string, conn *websocket.Conn) {
|
||||
if m.Options(ice.MSG_SOURCE, source, ice.MSG_TARGET, target[1:]); m.Warn(conn.WriteMessage(1, []byte(m.FormatMeta()))) {
|
||||
mdb.HashRemove(m, mdb.NAME, target[0])
|
||||
} else {
|
||||
m.Log("send", "%v->%v %v %v", source, target, m.Detailv(), m.FormatMeta())
|
||||
m.Log("send", "%v->%v %v %v", source, target, m.Detailv(), m.DumpMeta(nil))
|
||||
}
|
||||
}
|
||||
func _space_send(m *ice.Message, space string, arg ...string) {
|
||||
@ -142,7 +144,7 @@ func _space_send(m *ice.Message, space string, arg ...string) {
|
||||
_space_echo(m, []string{addSend(m, m)}, target, conn)
|
||||
}
|
||||
}) {
|
||||
call(m, m.Config(kit.Keys(TIMEOUT, "c")), func(res *ice.Message) { m.Copy(res) })
|
||||
call(m, "30s", func(res *ice.Message) { m.Copy(res) })
|
||||
} else if kit.IndexOf([]string{ice.OPS, ice.DEV, ice.SHY}, target[0]) > -1 {
|
||||
return
|
||||
} else {
|
||||
@ -159,9 +161,7 @@ const (
|
||||
WORKER = "worker"
|
||||
)
|
||||
const (
|
||||
BUFFER = "buffer"
|
||||
REDIAL = "redial"
|
||||
TIMEOUT = "timeout"
|
||||
REDIAL = "redial"
|
||||
|
||||
SPACE_START = "space.start"
|
||||
SPACE_OPEN = "space.open"
|
||||
@ -222,8 +222,7 @@ func init() {
|
||||
}},
|
||||
ice.PS: {Hand: func(m *ice.Message, arg ...string) { _space_fork(m) }},
|
||||
}, mdb.HashAction(mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text", ctx.ACTION, OPEN,
|
||||
REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000), TIMEOUT, kit.Dict("c", "10s"),
|
||||
BUFFER, kit.Dict("r", ice.MOD_BUFS, "w", ice.MOD_BUFS),
|
||||
REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000),
|
||||
), mdb.ClearHashOnExitAction(), SpaceAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) < 2 {
|
||||
mdb.HashSelect(m, arg...).Sort("type,name,text")
|
||||
|
@ -56,7 +56,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
}(key, cmd)
|
||||
}
|
||||
})
|
||||
defer gdb.EventDeferEvent(m, SERVE_START, arg)(SERVE_STOP, arg)
|
||||
gdb.EventDeferEvent(m, SERVE_START, arg)
|
||||
switch cb := m.OptionCB("").(type) {
|
||||
case func(http.Handler):
|
||||
cb(f)
|
||||
|
4
conf.go
4
conf.go
@ -177,6 +177,7 @@ const ( // MSG
|
||||
MSG_ACTION = "_action"
|
||||
MSG_STATUS = "_status"
|
||||
|
||||
MSG_INDEX = "_index"
|
||||
MSG_ALIAS = "_alias"
|
||||
MSG_SCRIPT = "_script"
|
||||
MSG_OUTPUT = "_output"
|
||||
@ -318,6 +319,9 @@ const ( // web
|
||||
THEME = "theme"
|
||||
TITLE = "title"
|
||||
)
|
||||
const ( // gdb
|
||||
DEBUG = "debug"
|
||||
)
|
||||
const ( // nfs
|
||||
SOURCE = "source"
|
||||
SCRIPT = "script"
|
||||
|
@ -36,8 +36,12 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FAVOR: {Name: "favor hash auto create getClipboardData getLocation scanQRCode record1 record2 upload", Help: "收藏夹", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.FOREACH && arg[1] == "" {
|
||||
m.Cmd("", ice.OptionFields("")).Tables(func(value ice.Maps) { m.PushSearch(value) })
|
||||
if arg[0] == mdb.FOREACH {
|
||||
m.Cmd("", ice.OptionFields("")).Tables(func(value ice.Maps) {
|
||||
if arg[1] == "" || arg[1] == value[mdb.TYPE] || strings.Contains(value[mdb.TEXT], arg[1]) {
|
||||
m.PushSearch(value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -86,17 +90,17 @@ func init() {
|
||||
ctx.ProcessField(m, ls[0], ls[1:], arg...)
|
||||
}},
|
||||
"vimer": {Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessField(m, web.CODE_VIMER, []string{m.Option(mdb.TEXT)}, arg...)
|
||||
ctx.Process(m, "", nfs.SplitPath(m, m.Option(mdb.TEXT)), arg...)
|
||||
}},
|
||||
"xterm": {Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessField(m, web.CODE_XTERM, []string{m.Option(mdb.TEXT)}, arg...)
|
||||
ctx.Process(m, "", []string{mdb.TYPE, m.Option(mdb.TEXT), mdb.NAME, m.Option(mdb.NAME), mdb.TEXT, ""}, arg...)
|
||||
}},
|
||||
cli.OPENS: {Hand: func(m *ice.Message, arg ...string) { cli.Opens(m, m.Option(mdb.TEXT)) }},
|
||||
ice.RUN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.TYPE, mdb.HashSelects(m.Spawn(), m.Option(mdb.HASH)).Append(mdb.TYPE))
|
||||
ctx.Run(m, arg...)
|
||||
}},
|
||||
}, mdb.HashAction(), ctx.CmdAction(), KeyboardAction(), mdb.ImportantDataAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, ctx.CmdAction(), mdb.HashAction(), mdb.ImportantDataAction(), KeyboardAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) > 0 && arg[0] == ctx.ACTION {
|
||||
m.Option(mdb.TYPE, mdb.HashSelects(m.Spawn(), m.Option(mdb.HASH)).Append(mdb.TYPE))
|
||||
gdb.Event(m, FAVOR_ACTION, arg)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"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/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -37,7 +38,7 @@ func init() {
|
||||
ctx.ProcessField(m, ctx.CONFIG, arg, arg...)
|
||||
}},
|
||||
}, ctx.CmdAction(), aaa.WhiteAction(ctx.COMMAND, ice.RUN)), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Result(kit.Select(m.Config(TITLE), ice.Info.Make.Email))
|
||||
m.Result(kit.Select(mdb.Config(m, TITLE), ice.Info.Make.Email))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -16,10 +16,7 @@ func init() {
|
||||
const CONFIRM = "confirm"
|
||||
Index.MergeCommands(ice.Commands{
|
||||
GRANT: {Name: "grant space auto", Help: "授权", Actions: ice.MergeActions(ice.Actions{
|
||||
web.SPACE_OPEN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(mdb.TYPE) != aaa.LOGIN {
|
||||
return
|
||||
}
|
||||
web.SPACE_LOGIN: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Go(func(msg *ice.Message) {
|
||||
link := tcp.PublishLocalhost(m, web.MergePodCmd(m, "", "", web.SPACE, m.Option(mdb.NAME)))
|
||||
msg.Sleep300ms(web.SPACE, m.Option(mdb.NAME), cli.PWD, m.Option(mdb.NAME), link, msg.Cmdx(cli.QRCODE, link))
|
||||
@ -37,7 +34,7 @@ func init() {
|
||||
m.Cmd(web.SPACE, m.Option(web.SPACE), ice.MSG_SESSID, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME)))
|
||||
m.ProcessLocation(web.MergeURL2(m, ice.PS))
|
||||
}},
|
||||
}, gdb.EventAction(web.SPACE_OPEN), aaa.RoleAction(CONFIRM)), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, gdb.EventAction(web.SPACE_LOGIN), aaa.RoleAction(CONFIRM)), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo("请授权: %s 访问设备: %s", arg[0], ice.Info.Hostname).Echo(ice.NL).EchoButton(CONFIRM)
|
||||
}},
|
||||
})
|
||||
|
@ -94,7 +94,7 @@ func init() {
|
||||
m.Option(k, web.SHARE_LOCAL+k)
|
||||
}
|
||||
}
|
||||
m.Echo(kit.Select(kit.Select("", strings.SplitN(ice.Info.Make.Remote, "://", 2), 1), m.Config(TITLE))).OptionFromConfig(MENUS)
|
||||
m.Echo(kit.Select(kit.Select("", strings.SplitN(ice.Info.Make.Remote, "://", 2), 1), mdb.Config(m, TITLE))).Option(MENUS, mdb.Config(m, MENUS))
|
||||
}},
|
||||
})
|
||||
}
|
||||
|
@ -17,13 +17,7 @@ const POD = "pod"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
POD: {Name: "pod", Help: "节点", Actions: ice.MergeActions(ice.Actions{
|
||||
web.SERVE_PARSE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if kit.Select("", arg, 0) == CHAT {
|
||||
kit.Fetch(arg[1:], func(k, v string) { m.Logs("Refer", k, v).Options(k, v) })
|
||||
}
|
||||
}},
|
||||
}, ctx.CmdAction(), web.ServeAction(), web.ApiAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
POD: {Name: "pod", Help: "节点", Actions: ice.MergeActions(ctx.CmdAction(), web.ServeAction(), web.ApiAction(), aaa.WhiteAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
if web.OptionAgentIs(m, "curl", "wget") {
|
||||
m.Cmdy(web.SHARE_LOCAL, ice.BIN_ICE_BIN, kit.Dict(ice.POD, kit.Select("", arg, 0), ice.MSG_USERROLE, aaa.TECH))
|
||||
return
|
||||
@ -34,7 +28,7 @@ func init() {
|
||||
if m.Cmd(web.SPACE, arg[0]).Length() == 0 && nfs.ExistsFile(m, path.Join(ice.USR_LOCAL_WORK, arg[0])) {
|
||||
m.Cmd(web.DREAM, cli.START, kit.Dict(mdb.NAME, arg[0]))
|
||||
}
|
||||
web.RenderMain(aaa.UserRoot(m), arg[0], "")
|
||||
web.RenderMain(m)
|
||||
} else if arg[1] == CMD {
|
||||
web.RenderPodCmd(m, arg[0], arg[2], arg[3:])
|
||||
} else if arg[1] == WEBSITE {
|
||||
|
@ -17,7 +17,7 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
web.P(SSO): {Name: "/sso", Help: "授权", Actions: aaa.WhiteAction(), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Warn(m.Option(ice.MSG_USERNAME) == "", ice.ErrNotLogin) || m.Warn(m.Option(cli.BACK) == "", ice.ErrNotValid) {
|
||||
web.RenderIndex(m, ice.VOLCANOS)
|
||||
web.RenderIndex(m)
|
||||
return
|
||||
}
|
||||
m.RenderRedirect(kit.MergeURL(m.Option(cli.BACK), ice.MSG_SESSID, m.Cmdx(web.SPACE, m.Option(web.SPACE), aaa.SESS, mdb.CREATE,
|
||||
|
@ -71,15 +71,14 @@ func _autogen_gits(m *ice.Message, arg ...string) string {
|
||||
return kit.Join(res, ice.NL)
|
||||
}
|
||||
func _autogen_git(m *ice.Message, arg ...string) ice.Map {
|
||||
return kit.Dict(
|
||||
mdb.TIME, m.Time(), nfs.PATH, kit.Path(""), arg,
|
||||
return kit.Dict(arg,
|
||||
mdb.TIME, m.Time(), nfs.PATH, kit.Path(""), web.DOMAIN, web.UserHost(m),
|
||||
mdb.HASH, m.Cmdx(cli.SYSTEM, GIT, "log", "-n1", `--pretty=%H`),
|
||||
nfs.REMOTE, m.Cmdx(cli.SYSTEM, GIT, "config", "remote.origin.url"),
|
||||
nfs.BRANCH, m.Cmdx(cli.SYSTEM, GIT, "rev-parse", "--abbrev-ref", "HEAD"),
|
||||
nfs.VERSION, m.Cmdx(cli.SYSTEM, GIT, "describe", "--tags"),
|
||||
aaa.EMAIL, m.Cmdx(cli.SYSTEM, GIT, "config", "user.email"),
|
||||
aaa.USERNAME, kit.Select(ice.Info.Username, m.Cmdx(cli.SYSTEM, GIT, "config", "user.name")),
|
||||
web.DOMAIN, tcp.PublishLocalhost(m, kit.Split(m.Option(ice.MSG_USERWEB), ice.QS)[0]),
|
||||
)
|
||||
}
|
||||
func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
@ -102,10 +101,6 @@ func init() {
|
||||
const (
|
||||
VERSION = "version"
|
||||
)
|
||||
const (
|
||||
USR_RELEASE_CONF_GO = "usr/release/conf.go"
|
||||
USR_RELEASE_BINPACK_GO = "usr/release/binpack.go"
|
||||
)
|
||||
Index.MergeCommands(ice.Commands{
|
||||
AUTOGEN: {Name: "autogen path auto script module version", Help: "生成", Actions: ice.Actions{
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -140,6 +135,10 @@ func init() {
|
||||
DEVPACK: {Help: "开发", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.REMOVE) }},
|
||||
WEBPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(WEBPACK, mdb.CREATE) }},
|
||||
BINPACK: {Help: "打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
const (
|
||||
USR_RELEASE_CONF_GO = "usr/release/conf.go"
|
||||
USR_RELEASE_BINPACK_GO = "usr/release/binpack.go"
|
||||
)
|
||||
if m.Cmd(BINPACK, mdb.CREATE); nfs.ExistsFile(m, ice.USR_RELEASE) && m.Option(ice.MSG_USERPOD) == "" {
|
||||
nfs.Copy(m, func(buf []byte, offset int) []byte {
|
||||
kit.If(offset == 0, func() { buf = bytes.Replace(buf, []byte("package main"), []byte("package ice"), 1) })
|
||||
|
@ -15,7 +15,7 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
CASE: {Name: "case dev zone id auto insert", Help: "用例", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INSERT: {Name: "insert zone*=demo name=hi cmd=GET,POST api*=/chat/cmd/web.chat.favor arg:textarea res:textarea"},
|
||||
cli.CHECK: {Name: "check", Help: "检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.CHECK: {Help: "检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.ProcessInner(); len(arg) > 1 {
|
||||
success := 0
|
||||
m.Cmd("", arg[0], arg[1], func(value ice.Maps) {
|
||||
|
@ -45,7 +45,7 @@ func init() {
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case SERVICE:
|
||||
m.Push(arg[0], m.Cmd(web.SPIDE, ice.DEV).Append(web.CLIENT_ORIGIN)+"/publish/")
|
||||
m.Push(arg[0], kit.MergeURL2(m.Cmd(web.SPIDE, ice.DEV).Append(web.CLIENT_ORIGIN), "/publish/"))
|
||||
case VERSION:
|
||||
m.Push(arg[0], "1.15.5", "1.17.3")
|
||||
default:
|
||||
|
@ -59,7 +59,7 @@ func _css_exec(m *ice.Message, arg ...string) {
|
||||
}
|
||||
} else {
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple())
|
||||
m.Push(ctx.STYLE, path.Join("/require", path.Join(arg[2], arg[1])))
|
||||
m.Push(ctx.STYLE, require(arg[2], arg[1]))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
package code
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
@ -17,19 +14,15 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FAVOR: {Name: "favor zone id auto insert page", Help: "收藏夹", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.INSERT: {Name: "insert zone*=数据结构 type=go name*=hi text*=hello path file line"},
|
||||
XTERM: {Help: "终端", Hand: func(m *ice.Message, arg ...string) {
|
||||
if msg := mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID)); strings.HasPrefix(msg.Option(mdb.TYPE), cli.OPEN) {
|
||||
m.Cmdy(cli.SYSTEM, m.Option(mdb.TYPE)).ProcessHold()
|
||||
} else {
|
||||
ctx.Process(m, m.ActionKey(), msg.OptionSimple(mdb.TYPE, mdb.NAME, mdb.TEXT), arg...)
|
||||
}
|
||||
XTERM: {Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID))
|
||||
ctx.Process(m, "", msg.OptionSplit(mdb.TYPE, mdb.NAME, mdb.TEXT), arg...)
|
||||
}},
|
||||
INNER: {Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
msg := mdb.ZoneSelects(m, m.Option(mdb.ZONE), m.Option(mdb.ID))
|
||||
ctx.Process(m, m.ActionKey(), msg.OptionSplit(nfs.PATH, nfs.FILE, nfs.LINE), arg...)
|
||||
msg := mdb.ZoneSelects(m.Spawn(), m.Option(mdb.ZONE), m.Option(mdb.ID))
|
||||
ctx.Process(m, "", msg.OptionSplit(nfs.PATH, nfs.FILE, nfs.LINE), arg...)
|
||||
}},
|
||||
}, mdb.PageZoneAction(mdb.FIELD, "time,id,type,name,text,path,file,line"), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.CACHE_LIMIT, "30")
|
||||
}, mdb.PageZoneAction(mdb.FIELD, "time,id,type,name,text,path,file,line")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.PageZoneSelect(m, arg...); len(arg) > 0 && arg[0] != "" {
|
||||
m.Tables(func(value ice.Maps) { m.PushButton(kit.Select(INNER, XTERM, value[nfs.FILE] == "")) }).Option(ctx.STYLE, arg[0])
|
||||
}
|
||||
|
@ -121,7 +121,18 @@ func init() {
|
||||
m.Echo(nfs.Template(m, "demo.go"), path.Base(path.Dir(path.Join(arg[2], arg[1]))))
|
||||
}},
|
||||
COMPLETE: {Hand: func(m *ice.Message, arg ...string) { _go_complete(m, arg...) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) { _c_tags(m, "gotags", "-f", nfs.TAGS, "-R", nfs.PWD) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, cmd := range []string{"guru", "gopls"} {
|
||||
if ls := kit.Split(m.Cmdx(cli.SYSTEM, cmd, "definition", m.Option(nfs.PATH)+m.Option(nfs.FILE)+ice.DF+"#"+m.Option("offset")), ice.DF); len(ls) > 0 {
|
||||
if strings.HasPrefix(ls[0], kit.Path("")) {
|
||||
_ls := nfs.SplitPath(m, strings.TrimPrefix(ls[0], kit.Path("")+ice.PS))
|
||||
m.Push(nfs.PATH, _ls[0]).Push(nfs.FILE, _ls[1]).Push(nfs.LINE, ls[1])
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
_c_tags(m, "gotags", "-f", nfs.TAGS, "-R", nfs.PWD)
|
||||
}},
|
||||
}, PlugAction())},
|
||||
MOD: {Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _mod_show(m, path.Join(arg[2], arg[1])) }},
|
||||
|
@ -10,16 +10,18 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func require(arg ...string) string { return path.Join(ice.PS, ice.REQUIRE, path.Join(arg...)) }
|
||||
|
||||
const HTML = "html"
|
||||
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
HTML: {Name: "html path auto", Help: "网页", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoIFrame(kit.MergeURL(path.Join(ice.PS, ice.REQUIRE, arg[2], arg[1]), "_v", kit.Hashs(mdb.UNIQ)))
|
||||
m.EchoIFrame(kit.MergeURL(require(arg[2], arg[1]), "_v", kit.Hashs(mdb.UNIQ)))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoIFrame(kit.MergeURL(path.Join(ice.PS, ice.REQUIRE, arg[2], arg[1]), "_v", kit.Hashs(mdb.UNIQ)))
|
||||
m.EchoIFrame(kit.MergeURL(require(arg[2], arg[1]), "_v", kit.Hashs(mdb.UNIQ)))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(kit.Renders(nfs.TemplateText(m, "demo.html"), ice.Maps{ice.LIST: kit.Format(kit.List(kit.Dict(ctx.INDEX, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO)))))})).RenderResult()
|
||||
|
@ -37,11 +37,9 @@ func _inner_tags(m *ice.Message, dir string, value string) {
|
||||
}
|
||||
file, ls := ls[1], strings.SplitN(ls[2], ";\"", 2)
|
||||
text := strings.TrimSuffix(strings.TrimPrefix(ls[0], "/^"), "$/")
|
||||
if text, line := _inner_line(m, kit.Path(dir, file), text); dir == "" {
|
||||
m.PushRecord(kit.Dict(nfs.PATH, path.Dir(file)+ice.PS, nfs.FILE, path.Base(file), nfs.LINE, kit.Format(line), mdb.TEXT, text))
|
||||
} else {
|
||||
m.PushRecord(kit.Dict(nfs.PATH, dir, nfs.FILE, strings.TrimPrefix(file, nfs.PWD), nfs.LINE, kit.Format(line), mdb.TEXT, text))
|
||||
}
|
||||
text, line := _inner_line(m, kit.Path(dir, file), text)
|
||||
_ls := nfs.SplitPath(m, path.Join(dir, file))
|
||||
m.PushRecord(kit.Dict(nfs.PATH, _ls[0], nfs.FILE, _ls[1], nfs.LINE, kit.Format(line), mdb.TEXT, text))
|
||||
}
|
||||
}
|
||||
func _inner_line(m *ice.Message, file, text string) (string, int) {
|
||||
@ -95,9 +93,7 @@ func init() {
|
||||
case ctx.INDEX:
|
||||
m.Cmdy(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, ice.OptionFields(ctx.INDEX))
|
||||
case ctx.ARGS:
|
||||
if m.Option(ctx.INDEX) != "" {
|
||||
m.Cmdy(m.Option(ctx.INDEX))
|
||||
}
|
||||
kit.If(m.Option(ctx.INDEX) != "", func() { m.Cmdy(m.Option(ctx.INDEX)) })
|
||||
case nfs.PATH:
|
||||
m.Cmdy(nfs.DIR, p, nfs.DIR_CLI_FIELDS)
|
||||
kit.If(strings.HasPrefix(p, bind[0]), func() { m.Cmdy(nfs.DIR, strings.Replace(p, bind[0], bind[1], 1), nfs.DIR_CLI_FIELDS) })
|
||||
@ -113,7 +109,7 @@ func init() {
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { _inner_show(m, arg[0], arg[1], arg[2]) }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _inner_exec(m, arg[0], arg[1], arg[2]) }},
|
||||
nfs.GREP: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.GREP, arg) }},
|
||||
nfs.TAGS: {Hand: func(m *ice.Message, arg ...string) { _inner_tags(m, m.Option(nfs.PATH), arg[0]) }}, FAVOR: {},
|
||||
nfs.TAGS: {Hand: func(m *ice.Message, arg ...string) { _inner_tags(m, m.Option(nfs.PATH), arg[0]) }},
|
||||
NAVIGATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(NAVIGATE, kit.Ext(m.Option(mdb.FILE)), m.Option(nfs.FILE), m.Option(nfs.PATH))
|
||||
}},
|
||||
@ -132,16 +128,6 @@ func init() {
|
||||
}},
|
||||
})
|
||||
}
|
||||
func InnerPath(arg ...string) (dir, file string) {
|
||||
p := strings.TrimPrefix(path.Join(arg...), kit.Path("")+ice.PS)
|
||||
if list := strings.Split(p, ice.PS); strings.HasPrefix(p, nfs.USR) {
|
||||
return path.Join(list[:2]...) + ice.PS, path.Join(list[2:]...)
|
||||
} else if strings.HasPrefix(p, ice.ISH_PLUGED) {
|
||||
return path.Join(list[:5]...) + ice.PS, path.Join(list[5:]...)
|
||||
} else {
|
||||
return list[0] + ice.PS, path.Join(list[1:]...)
|
||||
}
|
||||
}
|
||||
func PlugAction() ice.Actions {
|
||||
return ice.Actions{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -18,31 +18,31 @@ import (
|
||||
)
|
||||
|
||||
func _install_path(m *ice.Message, link string) string {
|
||||
link = strings.Split(kit.Select(m.Option(mdb.LINK), link), ice.QS)[0]
|
||||
if p := path.Join(ice.USR_INSTALL, kit.TrimExt(link)); nfs.ExistsFile(m, p) {
|
||||
u := kit.ParseURL(kit.Select(m.Option(web.LINK), link))
|
||||
if p := path.Join(ice.USR_INSTALL, kit.TrimExt(u.Path)); nfs.ExistsFile(m, p) {
|
||||
return p
|
||||
} else if pp := path.Join(ice.USR_INSTALL, path.Base(link)); nfs.ExistsFile(m, pp) {
|
||||
} else if pp := path.Join(ice.USR_INSTALL, path.Base(u.Path)); nfs.ExistsFile(m, pp) {
|
||||
return path.Join(ice.USR_INSTALL, strings.Split(m.Cmd(nfs.TAR, pp, "", "1").Append(nfs.FILE), ice.PS)[0])
|
||||
} else {
|
||||
return p
|
||||
}
|
||||
}
|
||||
func _install_download(m *ice.Message) {
|
||||
link := m.Option(mdb.LINK)
|
||||
name := path.Base(strings.Split(link, ice.QS)[0])
|
||||
link := m.Option(web.LINK)
|
||||
name := path.Base(kit.ParseURL(link).Path)
|
||||
file := path.Join(kit.Select(ice.USR_INSTALL, m.Option(nfs.PATH)), name)
|
||||
if nfs.ExistsFile(m, file) {
|
||||
m.Cmdy(nfs.DIR, file)
|
||||
return
|
||||
}
|
||||
mdb.HashCreate(m.Cmd(nfs.SAVE, file, ""), mdb.NAME, name, nfs.PATH, file, mdb.LINK, link)
|
||||
mdb.HashCreate(m.Cmd(nfs.SAVE, file, ""), mdb.NAME, name, nfs.PATH, file, web.LINK, link)
|
||||
web.GoToast(m, name, func(toast func(string, int, int)) {
|
||||
defer nfs.TarExport(m, file)
|
||||
begin := time.Now()
|
||||
web.SpideSave(m, file, link, func(count, total, step int) {
|
||||
web.SpideSave(m, file, link, func(count, total, value int) {
|
||||
cost := time.Now().Sub(begin)
|
||||
mdb.HashSelectUpdate(m, name, func(value ice.Map) { value[mdb.COUNT], value[mdb.TOTAL], value[mdb.VALUE] = count, total, step })
|
||||
toast(kit.FormatShow(nfs.FROM, begin.Format("15:04:05"), "cost", kit.FmtDuration(cost), "rest", kit.FmtDuration(cost*time.Duration(101)/time.Duration(step+1)-cost)), count, total)
|
||||
mdb.HashSelectUpdate(m, name, func(value ice.Map) { value[mdb.COUNT], value[mdb.TOTAL], value[mdb.VALUE] = count, total, value })
|
||||
toast(kit.FormatShow(nfs.FROM, begin.Format("15:04:05"), cli.COST, kit.FmtDuration(cost), cli.REST, kit.FmtDuration(cost*time.Duration(101)/time.Duration(value+1)-cost)), count, total)
|
||||
})
|
||||
})
|
||||
if s, e := nfs.StatFile(m, file); e == nil && s.Size() > 0 {
|
||||
@ -77,9 +77,9 @@ func _install_build(m *ice.Message, arg ...string) string {
|
||||
func _install_order(m *ice.Message, arg ...string) {
|
||||
p := _install_path(m, "")
|
||||
if m.Option(nfs.PATH) == "" {
|
||||
for _, v := range []string{"", "sbin", "bin", "_install/bin"} {
|
||||
kit.For([]string{"", "sbin", "bin", "_install/bin"}, func(v string) {
|
||||
kit.If(nfs.ExistsFile(m, path.Join(p, v)), func() { m.Option(nfs.PATH, v) })
|
||||
}
|
||||
})
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, nfs.PUSH, path.Join(p, m.Option(nfs.PATH)))
|
||||
}
|
||||
@ -120,21 +120,16 @@ func _install_start(m *ice.Message, arg ...string) {
|
||||
}
|
||||
func _install_stop(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, func(value ice.Maps) {
|
||||
if value[cli.PID] == m.Option(cli.PID) {
|
||||
m.Cmd(cli.DAEMON, cli.STOP, kit.Dict(mdb.HASH, value[mdb.HASH]))
|
||||
}
|
||||
kit.If(value[cli.PID] == m.Option(cli.PID), func() { m.Cmd(cli.DAEMON, cli.STOP, kit.Dict(mdb.HASH, value[mdb.HASH])) })
|
||||
})
|
||||
m.Cmd(gdb.SIGNAL, gdb.KILL, m.Option(cli.PID))
|
||||
}
|
||||
func _install_end(m *ice.Message, arg ...string) {
|
||||
func _install_clear(m *ice.Message, arg ...string) {
|
||||
m.Cmd(cli.DAEMON, func(value ice.Maps) {
|
||||
if value[cli.PID] == m.Option(cli.PID) {
|
||||
m.Cmd(cli.DAEMON, mdb.REMOVE, kit.Dict(mdb.HASH, value[mdb.HASH]))
|
||||
}
|
||||
kit.If(value[cli.PID] == m.Option(cli.PID), func() { m.Cmd(cli.DAEMON, mdb.REMOVE, kit.Dict(mdb.HASH, value[mdb.HASH])) })
|
||||
})
|
||||
}
|
||||
func _install_trash(m *ice.Message, arg ...string) {
|
||||
_install_trash(m, arg...)
|
||||
nfs.Trash(m, kit.Path(ice.USR_LOCAL_DAEMON, m.Option(tcp.PORT), m.Option(nfs.PATH)))
|
||||
}
|
||||
func _install_service(m *ice.Message, arg ...string) {
|
||||
@ -178,7 +173,7 @@ func init() {
|
||||
cli.SPAWN: {Name: "spawn link*", Hand: func(m *ice.Message, arg ...string) { _install_spawn(m, arg...) }},
|
||||
cli.START: {Name: "start link* cmd", Hand: func(m *ice.Message, arg ...string) { _install_start(m, arg...) }},
|
||||
cli.STOP: {Hand: func(m *ice.Message, arg ...string) { _install_stop(m, arg...) }},
|
||||
cli.END: {Help: "清理", Hand: func(m *ice.Message, arg ...string) { _install_end(m, arg...) }},
|
||||
cli.CLEAR: {Hand: func(m *ice.Message, arg ...string) { _install_clear(m, arg...) }},
|
||||
gdb.DEBUG: {Hand: func(m *ice.Message, arg ...string) { ctx.Process(m, XTERM, []string{mdb.TYPE, "gdb"}, arg...) }},
|
||||
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) { _install_trash(m, arg...) }},
|
||||
nfs.PATH: {Hand: func(m *ice.Message, arg ...string) { m.Echo(_install_path(m, kit.Select("", arg, 0))) }},
|
||||
|
@ -17,17 +17,16 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
JS: {Name: "js path auto", Help: "前端", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cmds, text := "node", kit.Format(`require("./usr/volcanos/proto.js"), require("./usr/volcanos/publish/client/nodejs/proto.js"), Volcanos.meta._main("%s")`, path.Join(ice.PS, arg[2], arg[1]))
|
||||
ProcessXterm(m, cmds, text)
|
||||
ProcessXterm(m, "node", kit.Format(`require("./usr/volcanos/proto.js"), require("./usr/volcanos/publish/client/nodejs/proto.js"), Volcanos.meta._main("%s")`, path.Join(ice.PS, arg[2], arg[1])))
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[2] == ice.USR_VOLCANOS {
|
||||
if strings.HasPrefix(arg[1], "plugin/local/") {
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(kit.TrimExt(strings.TrimPrefix(arg[1], "plugin/local/"), JS), ice.PS, ice.PT, -1)), kit.Simple())
|
||||
if strings.HasPrefix(arg[1], ice.PLUGIN_LOCAL) {
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, "web."+strings.Replace(kit.TrimExt(strings.TrimPrefix(arg[1], ice.PLUGIN_LOCAL), JS), ice.PS, ice.PT, -1)), kit.Simple())
|
||||
}
|
||||
} else {
|
||||
ctx.DisplayBase(m, path.Join("/require", path.Join(arg[2], arg[1])))
|
||||
ctx.ProcessCommand(m, kit.Select("can._plugin", ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple())
|
||||
ctx.DisplayBase(m, require(arg[2], arg[1]))
|
||||
ctx.ProcessCommand(m, kit.Select(ice.CAN_PLUGIN, ctx.GetFileCmd(kit.ExtChange(path.Join(arg[2], arg[1]), GO))), kit.Simple())
|
||||
}
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.js")) }},
|
||||
|
@ -26,7 +26,6 @@ func init() {
|
||||
m.Option(web.SPIDE_HEADER, web.Accept, web.ContentJSON, web.Authorization, "token "+kit.Select(m.Option(ACCESS_TOKEN), arg, 0))
|
||||
return m
|
||||
}
|
||||
|
||||
Index.MergeCommands(ice.Commands{
|
||||
OAUTH: {Name: "oauth hash auto", Help: "授权", Actions: ice.MergeActions(ice.Actions{
|
||||
ctx.CONFIG: {Name: "config client_id client_secret redirect_uri", Help: "配置", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
@ -52,12 +52,12 @@ func init() {
|
||||
u := web.OptionUserWeb(m)
|
||||
p := u.Hostname() + ice.DF + m.Cmdx(tcp.PORT, aaa.RIGHT)
|
||||
m.Cmd(cli.DAEMON, m.Configv(PPROF), "-http="+p, m.Option(BINNARY), m.Option(nfs.FILE))
|
||||
m.Echo("http://%s/ui/top", p).ProcessInner()
|
||||
m.Sleep("3s").ProcessOpen(kit.Format("http://%s/ui/top", p))
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.FIELDS, "time,zone,count,binnary,service,seconds", mdb.FIELD, "time,id,text,file", PPROF, kit.List(GO, "tool", PPROF))), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
m.EchoAnchor(web.MergeLink(m, "/debug/pprof/"))
|
||||
m.PushAction(cli.START, mdb.REMOVE).Action(mdb.CREATE)
|
||||
m.EchoAnchor(web.MergeLink(m, "/debug/pprof/"))
|
||||
} else {
|
||||
m.Tables(func(value ice.Maps) { m.PushDownload(mdb.LINK, "pprof.pd.gz", value[nfs.FILE]).PushButton(web.SERVE) })
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func _publish_file(m *ice.Message, file string, arg ...string) string {
|
||||
func _publish_contexts(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.DIR_ROOT, "")
|
||||
for _, k := range kit.Default(arg, ice.MISC) {
|
||||
m.Options(web.DOMAIN, m.Option(ice.MSG_USERHOST), cli.CTX_ENV, kit.Select("", ice.SP+kit.JoinKV(ice.EQ, ice.SP, cli.CTX_POD, m.Option(ice.MSG_USERPOD)), m.Option(ice.MSG_USERPOD) != ""))
|
||||
m.Options(web.DOMAIN, web.UserHost(m), cli.CTX_ENV, kit.Select("", ice.SP+kit.JoinKV(ice.EQ, ice.SP, cli.CTX_POD, m.Option(ice.MSG_USERPOD)), m.Option(ice.MSG_USERPOD) != ""))
|
||||
switch k {
|
||||
case INSTALL:
|
||||
m.Echo(strings.TrimSpace(nfs.Template(m, kit.Keys(ice.MISC, SH))))
|
||||
|
@ -29,14 +29,9 @@ func init() {
|
||||
cli.IsAlpine(m, "python2")
|
||||
cli.IsAlpine(m, "python3")
|
||||
}},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
cmds, text := "python -i "+path.Join(arg[2], arg[1]), ""
|
||||
ProcessXterm(m, cmds, text)
|
||||
}},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_py_exec(m, path.Join(arg[2], arg[1]))
|
||||
}},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(`print "hello world"`) }},
|
||||
mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { ProcessXterm(m, "python -i "+path.Join(arg[2], arg[1]), "") }},
|
||||
mdb.ENGINE: {Hand: func(m *ice.Message, arg ...string) { _py_exec(m, path.Join(arg[2], arg[1])) }},
|
||||
TEMPLATE: {Hand: func(m *ice.Message, arg ...string) { m.Echo(nfs.Template(m, "demo.py")) }},
|
||||
}, PlugAction())},
|
||||
})
|
||||
}
|
||||
|
@ -11,8 +11,7 @@ const (
|
||||
const REPOS = nfs.REPOS
|
||||
|
||||
func init() {
|
||||
const GIT_REPOS = "web.code.git.repos"
|
||||
Index.MergeCommands(ice.Commands{
|
||||
REPOS: {Name: "repos name auto", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(GIT_REPOS, arg) }},
|
||||
})
|
||||
Index.MergeCommands(ice.Commands{REPOS: {Name: "repos name auto", Actions: ice.Actions{
|
||||
"status": {Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.code.git.status", arg) }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) { m.Cmdy("web.code.git.repos", arg) }}})
|
||||
}
|
||||
|
@ -9,11 +9,12 @@ import (
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/ssh"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _sh_cmds(m *ice.Message, p string) (string, string) {
|
||||
cmds, text := kit.Select(SH, m.Config(ssh.SHELL)), kit.Format(strings.TrimSpace(nfs.Template(m, "cmd.sh")), m.Option(ice.MSG_USERHOST), m.Option(ice.MSG_USERPOD), p)
|
||||
cmds, text := kit.Select(SH, m.Config(ssh.SHELL)), kit.Format(strings.TrimSpace(nfs.Template(m, "cmd.sh")), web.UserHost(m), m.Option(ice.MSG_USERPOD), p)
|
||||
if head := kit.Select("", strings.Split(m.Cmdx(nfs.CAT, p), ice.NL), 0); strings.HasPrefix(head, "#!") {
|
||||
cmds = strings.TrimSpace(strings.TrimPrefix(head, "#!"))
|
||||
}
|
||||
@ -22,8 +23,8 @@ func _sh_cmds(m *ice.Message, p string) (string, string) {
|
||||
|
||||
const (
|
||||
BASH = "bash"
|
||||
VIM = "vim"
|
||||
CONF = "conf"
|
||||
VIM = "vim"
|
||||
)
|
||||
const SH = nfs.SH
|
||||
|
||||
|
@ -21,7 +21,7 @@ func init() {
|
||||
nfs.TARGET, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, ice.BIN, nfs.FILE, ice.ICE_BIN)),
|
||||
nfs.BINARY, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, nfs.TAR, nfs.FILE, "contexts.bin.tar.gz")),
|
||||
nfs.SOURCE, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, nfs.TAR, nfs.FILE, "contexts.src.tar.gz")),
|
||||
COMPILE, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, nfs.TAR, nfs.FILE, "go1.15.15", nfs.PATH, "usr/local/")),
|
||||
COMPILE, kit.Dict(mdb.LIST, kit.List(mdb.TYPE, nfs.TAR, nfs.FILE, "go1.15.5", nfs.PATH, ice.USR_LOCAL)),
|
||||
), mdb.META, kit.Dict(mdb.FIELD, "type,file,path"))},
|
||||
}, Commands: ice.Commands{
|
||||
UPGRADE: {Name: "upgrade item=target,binary,source,compile run restart", Help: "升级", Actions: ice.MergeActions(ice.Actions{
|
||||
|
@ -55,8 +55,8 @@ func init() {
|
||||
m.PushSearch(mdb.TYPE, nfs.FILE, mdb.NAME, "main", mdb.TEXT, ice.SRC_MAIN_GO)
|
||||
m.PushSearch(mdb.TYPE, nfs.FILE, mdb.NAME, "main", mdb.TEXT, ice.SRC_MAIN_SH)
|
||||
m.PushSearch(mdb.TYPE, nfs.FILE, mdb.NAME, "main", mdb.TEXT, ice.SRC_MAIN_JS)
|
||||
m.PushSearch(mdb.TYPE, web.LINK, mdb.NAME, "admin", mdb.TEXT, kit.MergeURL(m.Option(ice.MSG_USERHOST)+ice.PS, log.DEBUG, ice.TRUE))
|
||||
m.PushSearch(mdb.TYPE, web.LINK, mdb.NAME, VIMER, mdb.TEXT, web.MergePodCmds(m, "", web.CODE_VIMER, log.DEBUG, ice.TRUE))
|
||||
m.PushSearch(mdb.TYPE, web.LINK, mdb.NAME, "admin", mdb.TEXT, kit.MergeURL(web.UserHost(m)+ice.PS, log.DEBUG, ice.TRUE))
|
||||
m.PushSearch(mdb.TYPE, web.LINK, mdb.NAME, m.CommandKey(), mdb.TEXT, web.MergePodCmds(m, "", "", log.DEBUG, ice.TRUE))
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
@ -162,9 +162,6 @@ func init() {
|
||||
web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.Switch(m.Option(mdb.TYPE), kit.Simple(web.SERVER, web.WORKER), func() { m.PushButton(kit.Dict(m.CommandKey(), "源码")) })
|
||||
}},
|
||||
web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(arg[1] == m.CommandKey(), func() { ctx.ProcessField(m, m.PrefixKey(), []string{}, arg...) })
|
||||
}},
|
||||
}, mdb.HashAction(mdb.SHORT, nfs.PATH, mdb.FIELD, "time,path"), web.DreamAction(), aaa.RoleAction(ctx.COMMAND)), Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Cmdy(INNER, arg); arg[0] != ctx.ACTION {
|
||||
kit.If(len(arg) > 1, func() { mdb.HashCreate(m.Spawn(), nfs.PATH, path.Join(kit.Slice(arg, 0, 2)...)) })
|
||||
@ -186,7 +183,10 @@ func init() {
|
||||
ice.AddMerges(func(c *ice.Context, key string, cmd *ice.Command, sub string, action *ice.Action) (ice.Handler, ice.Handler) {
|
||||
switch sub {
|
||||
case TEMPLATE, COMPLETE, NAVIGATE:
|
||||
return func(m *ice.Message, arg ...string) { m.Cmd(sub, mdb.CREATE, key, m.PrefixKey()) }, nil
|
||||
return func(m *ice.Message, arg ...string) {
|
||||
m.Option(mdb.SHORT, mdb.TYPE)
|
||||
m.Cmd(sub, mdb.CREATE, key, m.PrefixKey())
|
||||
}, nil
|
||||
}
|
||||
return nil, nil
|
||||
})
|
||||
|
@ -117,7 +117,7 @@ func init() {
|
||||
_webpack_can(m)
|
||||
m.Cmdy("")
|
||||
}},
|
||||
mdb.REMOVE: {Help: "调试", Hand: func(m *ice.Message, arg ...string) {
|
||||
mdb.REMOVE: {Help: "开发", Hand: func(m *ice.Message, arg ...string) {
|
||||
_webpack_cache(m.Spawn(), _volcanos(m), false)
|
||||
m.Cmdy(nfs.DIR, _volcanos(m, PAGE))
|
||||
}},
|
||||
|
@ -37,13 +37,12 @@ func (s _xterm) Close() error {
|
||||
return s.Cmd.Process.Kill()
|
||||
}
|
||||
func _xterm_get(m *ice.Message, h string) _xterm {
|
||||
if h = kit.Select(m.Option(mdb.HASH), h); m.Assert(h != "") && mdb.HashSelectField(m, m.Option(mdb.HASH, h), mdb.TYPE) == "" {
|
||||
mdb.HashCreate(m, m.OptionSimple(mdb.HashField(m)))
|
||||
}
|
||||
h = kit.Select(m.Option(mdb.HASH), h)
|
||||
m.Assert(h != "")
|
||||
mdb.HashModify(m, mdb.TIME, m.Time(), web.VIEW, m.Option(ice.MSG_DAEMON))
|
||||
return mdb.HashSelectTarget(m, h, func(value ice.Maps) ice.Any {
|
||||
text := strings.Split(value[mdb.TEXT], ice.NL)
|
||||
ls := kit.Split(kit.Select(nfs.SH, strings.Split(value[mdb.TYPE], " # ")[0]))
|
||||
ls := kit.Split(strings.Split(kit.Select(nfs.SH, value[mdb.TYPE]), " # ")[0])
|
||||
cmd := exec.Command(cli.SystemFind(m, ls[0]), ls[1:]...)
|
||||
cmd.Dir = nfs.MkdirAll(m, kit.Path(value[nfs.PATH]))
|
||||
cmd.Env = append(cmd.Env, os.Environ()...)
|
||||
@ -54,7 +53,6 @@ func _xterm_get(m *ice.Message, h string) _xterm {
|
||||
defer tty.Close()
|
||||
defer mdb.HashRemove(m, mdb.HASH, h)
|
||||
m.Log(cli.START, strings.Join(cmd.Args, ice.SP))
|
||||
m.Option(ice.LOG_DISABLE, ice.TRUE)
|
||||
buf := make([]byte, ice.MOD_BUFS)
|
||||
for {
|
||||
if n, e := tty.Read(buf); !m.Warn(e) && e == nil {
|
||||
@ -81,9 +79,7 @@ func _xterm_echo(m *ice.Message, h string, str string) {
|
||||
web.PushNoticeGrow(m, h, str)
|
||||
}
|
||||
func _xterm_cmds(m *ice.Message, h string, cmd string, arg ...ice.Any) {
|
||||
if cmd != "" {
|
||||
_xterm_get(m, h).Writeln(cmd, arg...)
|
||||
}
|
||||
kit.If(cmd != "", func() { _xterm_get(m, h).Writeln(cmd, arg...) })
|
||||
ctx.ProcessHold(m)
|
||||
}
|
||||
|
||||
@ -92,6 +88,11 @@ const XTERM = "xterm"
|
||||
func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
XTERM: {Name: "xterm hash auto", Help: "命令行", Actions: ice.MergeActions(ice.Actions{
|
||||
mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) {
|
||||
if arg[0] == mdb.FOREACH && arg[1] == "" {
|
||||
m.PushSearch(mdb.TYPE, web.LINK, mdb.NAME, m.CommandKey(), mdb.TEXT, web.MergePodCmds(m, "", "", log.DEBUG, ice.TRUE))
|
||||
}
|
||||
}},
|
||||
mdb.INPUTS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
switch mdb.HashInputs(m, arg); arg[0] {
|
||||
case mdb.TYPE:
|
||||
@ -105,12 +106,17 @@ func init() {
|
||||
m.Cmdy(nfs.DIR, ice.USR_LOCAL_WORK, nfs.PATH)
|
||||
m.Cmdy(nfs.DIR, ice.USR_LOCAL_REPOS, nfs.PATH)
|
||||
m.Cmdy(nfs.DIR, ice.USR_LOCAL_DAEMON, nfs.PATH)
|
||||
case nfs.FILE:
|
||||
push := func(arg ...string) { m.Push(nfs.FILE, strings.Join(arg, ice.DF)) }
|
||||
m.Cmd("", func(value ice.Maps) {
|
||||
kit.If(value[mdb.TYPE] == web.LAYOUT, func() { push(web.LAYOUT, value[mdb.HASH], value[mdb.NAME]) })
|
||||
})
|
||||
m.Cmd("", mdb.INPUTS, mdb.TYPE, func(value ice.Maps) { push(ssh.SHELL, value[mdb.TYPE]) })
|
||||
m.Cmd(nfs.CAT, kit.HomePath(".bash_history"), func(text string) { push(text) })
|
||||
m.Cmd(nfs.CAT, kit.HomePath(".zsh_history"), func(text string) { push(text) })
|
||||
m.Cmd(ctx.COMMAND, mdb.SEARCH, ctx.COMMAND, "", "", ice.OptionFields(ctx.INDEX), func(value ice.Maps) { push(ctx.INDEX, value[ctx.INDEX]) })
|
||||
}
|
||||
}},
|
||||
web.DREAM_CREATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd("", mdb.CREATE, mdb.TYPE, BASH, m.OptionSimple(mdb.NAME), nfs.PATH, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME)))
|
||||
}},
|
||||
mdb.CREATE: {Name: "create type*=sh name text path theme:textarea", Hand: func(m *ice.Message, arg ...string) { mdb.HashCreate(m) }},
|
||||
web.RESIZE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_xterm_get(m, "").Setsize(m.OptionDefault("rows", "24"), m.OptionDefault("cols", "80"))
|
||||
}},
|
||||
@ -119,25 +125,19 @@ func init() {
|
||||
_xterm_get(m, "").Write(string(b))
|
||||
}
|
||||
}},
|
||||
INSTALL: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_xterm_cmds(m, kit.Select("", arg, 0), m.Cmdx(PUBLISH, ice.CONTEXTS, INSTALL))
|
||||
}},
|
||||
log.DEBUG: {Hand: func(m *ice.Message, arg ...string) {
|
||||
_xterm_cmds(m, kit.Select("", arg, 0), "cd ~/contexts; tail -f var/log/bench.log")
|
||||
}},
|
||||
web.OUTPUT: {Help: "全屏", Hand: func(m *ice.Message, arg ...string) {
|
||||
web.ProcessWebsite(m, "", "", m.OptionSimple(mdb.HASH), ctx.STYLE, web.OUTPUT)
|
||||
}},
|
||||
web.DREAM_CREATE: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd("", mdb.CREATE, mdb.TYPE, BASH, m.OptionSimple(mdb.NAME), nfs.PATH, path.Join(ice.USR_LOCAL_WORK, m.Option(mdb.NAME)))
|
||||
}},
|
||||
web.DREAM_TABLES: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.Switch(m.Option(mdb.TYPE), kit.Simple(web.SERVER, web.WORKER), func() { m.PushButton(kit.Dict(m.CommandKey(), "命令")) })
|
||||
}},
|
||||
web.DREAM_ACTION: {Hand: func(m *ice.Message, arg ...string) {
|
||||
kit.If(arg[1] == m.CommandKey(), func() { ctx.ProcessField(m, m.PrefixKey(), []string{}, arg...) })
|
||||
}},
|
||||
ctx.PROCESS: {Hand: func(m *ice.Message, arg ...string) {
|
||||
ctx.ProcessField(m, m.PrefixKey(), func() string { return m.Cmdx("", mdb.CREATE, arg) }, arg...)
|
||||
}},
|
||||
}, mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,path,view,theme"), web.DreamAction(), ctx.ProcessAction(), ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
|
||||
}, ctx.CmdAction(), ctx.ProcessAction(), web.DreamAction(), mdb.HashAction(mdb.FIELD, "time,hash,type,name,text,path,view,theme")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 {
|
||||
m.PushAction(web.OUTPUT, mdb.REMOVE).Action(mdb.CREATE, mdb.PRUNES)
|
||||
} else {
|
||||
@ -153,6 +153,5 @@ func init() {
|
||||
}
|
||||
|
||||
func ProcessXterm(m *ice.Message, cmds, text string, arg ...string) {
|
||||
m.Option(nfs.PATH, "")
|
||||
m.Cmdy(ctx.COMMAND, XTERM).Push(ctx.ARGS, kit.Format([]string{m.Cmdx(XTERM, mdb.CREATE, mdb.TYPE, cmds, mdb.NAME, kit.Select("", arg, 0), mdb.TEXT, text)})).ProcessField(XTERM)
|
||||
ctx.Process(m, XTERM, []string{mdb.TYPE, cmds, mdb.NAME, kit.Select("", arg, 0), mdb.TEXT, text}, arg...)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func _option(m *ice.Message, kind, name, text string, arg ...string) *ice.Messag
|
||||
}
|
||||
|
||||
func _wiki_path(m *ice.Message, arg ...string) string {
|
||||
return path.Join(m.Config(nfs.PATH), path.Join(arg...))
|
||||
return path.Join(mdb.Config(m, nfs.PATH), path.Join(arg...))
|
||||
}
|
||||
func _wiki_link(m *ice.Message, text string) string {
|
||||
if !kit.HasPrefix(text, ice.PS, ice.HTTP) {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func _word_show(m *ice.Message, name string, arg ...string) {
|
||||
m.Options(ice.MSG_ALIAS, m.Configv(mdb.ALIAS), TITLE, map[string]int{}, MENU, kit.Dict(mdb.LIST, kit.List()))
|
||||
m.Options(ice.MSG_ALIAS, mdb.Configv(m, mdb.ALIAS), TITLE, map[string]int{}, MENU, kit.Dict(mdb.LIST, kit.List()))
|
||||
m.Cmdy(ssh.SOURCE, name, kit.Dict(nfs.DIR_ROOT, _wiki_path(m)))
|
||||
}
|
||||
|
||||
|
11
data.go
11
data.go
@ -3,6 +3,7 @@ package ice
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -14,15 +15,19 @@ func (m *Message) ActionKey() string {
|
||||
func (m *Message) CommandKey() string {
|
||||
return strings.TrimPrefix(strings.TrimSuffix(m._key, PS), PS)
|
||||
}
|
||||
func (m *Message) PrefixRawKey(arg ...Any) string {
|
||||
return kit.Keys(m.Prefix(m._key), kit.Keys(arg...))
|
||||
}
|
||||
func (m *Message) PrefixKey(arg ...Any) string {
|
||||
return kit.Keys(m.Prefix(m.CommandKey()), kit.Keys(arg...))
|
||||
}
|
||||
func (m *Message) PrefixPath(arg ...Any) string {
|
||||
return strings.TrimPrefix(strings.ReplaceAll(kit.Keys(m.Prefix(m.CommandKey()), kit.Keys(arg...)), PT, PS), "web") + PS
|
||||
}
|
||||
func (m *Message) Prefix(arg ...string) string {
|
||||
return m.Target().PrefixKey(arg...)
|
||||
}
|
||||
func (m *Message) PrefixPath(arg ...Any) string {
|
||||
return strings.TrimPrefix(path.Join(strings.ReplaceAll(m.PrefixRawKey(arg...), PT, PS)), "web") + PS
|
||||
}
|
||||
|
||||
func (m *Message) Config(key string, arg ...Any) string {
|
||||
return kit.Format(m.Configv(key, arg...))
|
||||
}
|
||||
|
3
info.go
3
info.go
@ -39,6 +39,7 @@ var Info = struct {
|
||||
Index Map
|
||||
|
||||
Important bool
|
||||
Localhost bool
|
||||
|
||||
merges []MergeHandler
|
||||
render map[string]func(*Message, ...Any) string
|
||||
@ -55,8 +56,8 @@ server: https://shylinux.com
|
||||
source: https://shylinux.com/x/contexts
|
||||
`,
|
||||
File: Maps{},
|
||||
Gomod: Maps{},
|
||||
Route: Maps{},
|
||||
Gomod: Maps{},
|
||||
Index: Map{},
|
||||
|
||||
render: map[string]func(*Message, ...Any) string{},
|
||||
|
34
logs.go
34
logs.go
@ -2,6 +2,7 @@ package ice
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -183,31 +184,34 @@ func (m *Message) FormatCost() string {
|
||||
func (m *Message) FormatSize() string {
|
||||
return kit.Format("%dx%d %v", m.Length(), len(m.meta[MSG_APPEND]), kit.Simple(m.meta[MSG_APPEND]))
|
||||
}
|
||||
func (m *Message) DumpMeta(w io.Writer) {
|
||||
m.meta[MSG_OPTION] = kit.Filters(m.meta[MSG_OPTION], "sessid", "cmds", "fields", "_option", "_handle", "_output", "", "_name", "_index", "log.caller", "aaa.checker")
|
||||
func (m *Message) DumpMeta(w io.Writer, arg ...string) (res string) {
|
||||
kit.If(len(arg) == 0 && m.Option(DEBUG) == TRUE, func() { arg = []string{SP, SP, NL} })
|
||||
if w == nil {
|
||||
buf := bytes.NewBuffer(make([]byte, 1024))
|
||||
defer func() { res = buf.String() }()
|
||||
w = buf
|
||||
}
|
||||
kit.For(m.meta[MSG_OPTION], func(i int, k string) {
|
||||
kit.If(len(m.meta[k]) == 0 || len(m.meta[k]) == 1 && m.meta[k][0] == "", func() { m.meta[MSG_OPTION][i] = "" })
|
||||
})
|
||||
bio := bufio.NewWriter(w)
|
||||
m.meta[MSG_OPTION] = kit.Filters(m.meta[MSG_OPTION], MSG_CMDS, MSG_FIELDS, MSG_SESSID, MSG_OPTS, MSG_HANDLE, MSG_OUTPUT, MSG_INDEX, "", "aaa.checker")
|
||||
bio, count, NL := bufio.NewWriter(w), 0, kit.Select("", arg, 2)
|
||||
defer bio.Flush()
|
||||
echo := func(k string) {
|
||||
echo := func(arg ...Any) { fmt.Fprint(bio, arg...) }
|
||||
push := func(k string) {
|
||||
if len(m.meta[k]) == 0 {
|
||||
return
|
||||
}
|
||||
kit.If(k != MSG_DETAIL, func() { fmt.Fprintln(bio, FS) })
|
||||
fmt.Fprint(bio, kit.Format(" %q: ", k))
|
||||
kit.If(count > 0, func() { echo(FS, NL) })
|
||||
echo(kit.Format("%s%q:%s", kit.Select("", arg, 0), k, kit.Select("", arg, 1)))
|
||||
b, _ := json.Marshal(m.meta[k])
|
||||
bio.Write(b)
|
||||
count++
|
||||
}
|
||||
fmt.Fprintln(bio, "{")
|
||||
defer fmt.Fprintln(bio, "}")
|
||||
echo(MSG_DETAIL)
|
||||
echo(MSG_OPTION)
|
||||
kit.For(m.meta[MSG_OPTION], func(k string) { echo(k) })
|
||||
kit.For(m.meta[MSG_APPEND], func(k string) { echo(k) })
|
||||
echo(MSG_APPEND)
|
||||
echo(MSG_RESULT)
|
||||
fmt.Fprintln(bio)
|
||||
echo("{", NL)
|
||||
defer echo("}", NL)
|
||||
kit.For(kit.Simple(MSG_DETAIL, MSG_OPTION, m.meta[MSG_OPTION], m.meta[MSG_APPEND], MSG_APPEND, MSG_RESULT), push)
|
||||
return
|
||||
}
|
||||
func (m *Message) FormatMeta() string {
|
||||
return kit.Format(m.meta)
|
||||
|
4
meta.go
4
meta.go
@ -420,7 +420,7 @@ func (m *Message) Detailv(arg ...Any) []string {
|
||||
}
|
||||
return m.meta[MSG_DETAIL]
|
||||
}
|
||||
func (m *Message) Options(arg ...Any) Any {
|
||||
func (m *Message) Options(arg ...Any) *Message {
|
||||
for i := 0; i < len(arg); i += 2 {
|
||||
switch val := arg[i].(type) {
|
||||
case Maps:
|
||||
@ -440,7 +440,7 @@ func (m *Message) Options(arg ...Any) Any {
|
||||
m.Optionv(kit.Format(arg[i]), arg[i+1])
|
||||
}
|
||||
}
|
||||
return m.Optionv(kit.Format(arg[0]))
|
||||
return m
|
||||
}
|
||||
func (m *Message) Optionv(key string, arg ...Any) Any {
|
||||
if len(arg) > 0 {
|
||||
|
14
misc.go
14
misc.go
@ -300,17 +300,21 @@ func (c *Context) _action(m *Message, cmd *Command, key string, sub string, h *A
|
||||
if strings.HasPrefix(arg[i], PS) {
|
||||
break
|
||||
}
|
||||
if arg[i+1] != "" {
|
||||
m.Option(arg[i], arg[i+1])
|
||||
}
|
||||
// if arg[i+1] != "" {
|
||||
// m.Option(arg[i], arg[i+1])
|
||||
// }
|
||||
m.Option(arg[i], arg[i+1])
|
||||
}
|
||||
} else {
|
||||
order = true
|
||||
}
|
||||
}
|
||||
if order {
|
||||
if value := kit.Select("", arg, i); value != "" {
|
||||
m.Option(name, value)
|
||||
// if value := kit.Select("", arg, i); value != "" {
|
||||
// m.Option(name, value)
|
||||
// }
|
||||
if i < len(arg) {
|
||||
m.Option(name, arg[i])
|
||||
}
|
||||
}
|
||||
if m.Warn(m.OptionDefault(name, kit.Format(kit.Value(v, VALUE))) == "" && kit.Value(v, "need") == "must", ErrNotValid, name) {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -17,7 +18,7 @@ func init() {
|
||||
mdb.REVERT: {Help: "撤销", Hand: func(m *ice.Message, arg ...string) { m.Cmd(SESS, mdb.MODIFY, GRANT, "") }},
|
||||
}, Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Cmdy(SESS, arg); len(arg) > 0 && m.Append(GRANT) == "" {
|
||||
m.Echo("请授权 %s@%s 访问 %s", m.Append(aaa.USERNAME), m.Append(tcp.HOSTNAME), m.Option(ice.MSG_USERHOST))
|
||||
m.Echo("请授权 %s@%s 访问 %s", m.Append(aaa.USERNAME), m.Append(tcp.HOSTNAME), web.UserHost(m))
|
||||
}
|
||||
m.Tables(func(value ice.Maps) { m.PushButton(kit.Select(mdb.REVERT, mdb.MODIFY, value[GRANT] == "")) })
|
||||
}},
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func _git_url(m *ice.Message, repos string) string {
|
||||
return kit.MergeURL2(m.Option(ice.MSG_USERHOST), "/x/"+path.Join(repos)+".git")
|
||||
return kit.MergeURL2(web.UserHost(m), "/x/"+path.Join(repos)+".git")
|
||||
}
|
||||
func _git_dir(arg ...string) string { return path.Join(path.Join(arg...), ".git") }
|
||||
func _git_cmd(m *ice.Message, arg ...string) *ice.Message { return m.Cmd(cli.SYSTEM, GIT, arg) }
|
||||
|
@ -280,7 +280,7 @@ func init() {
|
||||
}},
|
||||
"oauth": {Help: "授权", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.ProcessOpen(kit.MergeURL2(kit.Select(ice.Info.Make.Remote, m.Cmdx(cli.SYSTEM, "git", "remote", "get-url", "origin")), "/chat/cmd/web.code.git.token",
|
||||
aaa.USERNAME, m.Option(ice.MSG_USERNAME), tcp.HOST, m.Option(ice.MSG_USERHOST)))
|
||||
aaa.USERNAME, m.Option(ice.MSG_USERNAME), tcp.HOST, web.UserHost(m)))
|
||||
}},
|
||||
"token": {Name: "token token", Help: "令牌", Hand: func(m *ice.Message, arg ...string) {
|
||||
list := []string{m.Option(TOKEN)}
|
||||
|
@ -39,12 +39,12 @@ func init() {
|
||||
m.Cmd(nfs.SAVE, kit.HomePath(FILE), strings.Join(list, ice.NL)+ice.NL)
|
||||
}},
|
||||
web.PP(GET): {Hand: func(m *ice.Message, arg ...string) {
|
||||
web.AllowOrigin(m, "*")
|
||||
web.RenderOrigin(m.W, "*")
|
||||
m.Cmd(nfs.CAT, kit.HomePath(FILE), func(text string) {
|
||||
if u := kit.ParseURL(text); u.Host == arg[0] {
|
||||
if p, ok := u.User.Password(); ok {
|
||||
m.Echo(u.User.Username()).Echo(p)
|
||||
web.AllowOrigin(m, u.Scheme+"://"+u.Host)
|
||||
web.RenderOrigin(m.W, u.Scheme+"://"+u.Host)
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -56,7 +56,7 @@ func init() {
|
||||
}},
|
||||
}, mdb.HashAction(mdb.EXPIRE, mdb.MONTH, mdb.SHORT, aaa.USERNAME, mdb.FIELD, "time,username,token")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.HashSelect(m, arg...); len(arg) > 0 && m.Length() > 0 {
|
||||
p := strings.Replace(m.Option(ice.MSG_USERHOST), "://", kit.Format("://%s:%s@", m.Option(ice.MSG_USERNAME), m.Append(TOKEN)), 1)
|
||||
p := strings.Replace(web.UserHost(m), "://", kit.Format("://%s:%s@", m.Option(ice.MSG_USERNAME), m.Append(TOKEN)), 1)
|
||||
m.OptionDefault(tcp.HOST, LOCAL)
|
||||
if m.Push("url", p).EchoScript(p).EchoScript(nfs.Template(m, "echo.sh", p)); m.Option(ice.CMD) == m.PrefixKey() {
|
||||
m.ProcessReplace(kit.MergeURL2(m.Option(tcp.HOST), m.PrefixPath(SET), TOKEN, p))
|
||||
|
@ -15,7 +15,7 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
web.P(SSO): {Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(ice.MSG_USERNAME) != "" {
|
||||
web.RenderIndex(m, ice.VOLCANOS)
|
||||
web.RenderIndex(m)
|
||||
return
|
||||
}
|
||||
appid := m.Cmd(APP).Append(APPID)
|
||||
|
@ -19,8 +19,8 @@ func init() {
|
||||
Index.MergeCommands(ice.Commands{
|
||||
FAVOR: {Name: "favor zone id auto insert", Help: "收藏夹", Actions: ice.MergeActions(ice.Actions{
|
||||
code.INNER: {Hand: func(m *ice.Message, arg ...string) {
|
||||
dir, file := code.InnerPath(kit.Select("", m.Option(cli.PWD), !path.IsAbs(m.Option(nfs.FILE))), m.Option(nfs.FILE))
|
||||
ctx.ProcessField(m, "", []string{dir, file, m.Option(nfs.LINE)}, arg...)
|
||||
ls := nfs.SplitPath(m, path.Join(kit.Select("", m.Option(cli.PWD), !path.IsAbs(m.Option(nfs.FILE))), m.Option(nfs.FILE)))
|
||||
ctx.ProcessField(m, "", []string{ls[0], ls[1], m.Option(nfs.LINE)}, arg...)
|
||||
}},
|
||||
}, mdb.ZoneAction(mdb.FIELD, "time,id,type,name,text,file,line,pwd")), Hand: func(m *ice.Message, arg ...string) {
|
||||
if mdb.ZoneSelect(m, arg...); len(arg) == 0 {
|
||||
|
@ -141,10 +141,10 @@ func (m *Message) ProcessDisplay(arg ...Any) {
|
||||
m.Process(PROCESS_DISPLAY)
|
||||
m.Option(MSG_DISPLAY, arg...)
|
||||
}
|
||||
|
||||
func (m *Message) ProcessField(arg ...Any) {
|
||||
func (m *Message) ProcessField(arg ...Any) *Message {
|
||||
m.Process(PROCESS_FIELD)
|
||||
m.Option(FIELD_PREFIX, arg...)
|
||||
return m
|
||||
}
|
||||
func (m *Message) ProcessInner() { m.Process(PROCESS_INNER) }
|
||||
func (m *Message) ProcessAgain() { m.Process(PROCESS_AGAIN) }
|
||||
|
@ -81,8 +81,7 @@ func (m *Message) Render(cmd string, arg ...Any) *Message {
|
||||
}
|
||||
return m
|
||||
}
|
||||
m.Options(MSG_OUTPUT, cmd, MSG_ARGS, arg)
|
||||
return m
|
||||
return m.Options(MSG_OUTPUT, cmd, MSG_ARGS, arg)
|
||||
}
|
||||
func (m *Message) RenderTemplate(arg ...Any) *Message {
|
||||
return m.Render(RENDER_TEMPLATE, arg...)
|
||||
|
3
type.go
3
type.go
@ -526,6 +526,9 @@ func (m *Message) Confi(key string, sub string) int {
|
||||
return kit.Int(m.Conf(key, sub))
|
||||
}
|
||||
func (m *Message) Confv(arg ...Any) (val Any) {
|
||||
if m.Spawn().Warn(Info.Important && m.Option("_lock") == "") {
|
||||
m.Debug("what lock %s %s", m.PrefixKey(), m.FormatStack(1, 100))
|
||||
}
|
||||
run := func(conf *Config) {
|
||||
if len(arg) == 1 {
|
||||
val = conf.Value
|
||||
|
Loading…
x
Reference in New Issue
Block a user