mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 09:34:05 +08:00
mix github
This commit is contained in:
commit
ead1f551cd
@ -131,12 +131,13 @@ func init() {
|
|||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) < 2 {
|
if len(arg) < 2 { // 角色列表
|
||||||
_role_list(m, kit.Select("", arg, 0))
|
_role_list(m, kit.Select("", arg, 0))
|
||||||
m.PushAction(mdb.REMOVE)
|
m.PushAction(mdb.REMOVE)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置角色
|
||||||
_role_user(m, arg[0], arg[1:]...)
|
_role_user(m, arg[0], arg[1:]...)
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
@ -53,8 +53,6 @@ func SessIsCli(m *ice.Message) bool {
|
|||||||
const (
|
const (
|
||||||
IP = "ip"
|
IP = "ip"
|
||||||
UA = "ua"
|
UA = "ua"
|
||||||
|
|
||||||
SESSID = "sessid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -33,8 +33,7 @@ func _user_remove(m *ice.Message, name string) {
|
|||||||
}
|
}
|
||||||
func _user_search(m *ice.Message, kind, name, text string) {
|
func _user_search(m *ice.Message, kind, name, text string) {
|
||||||
m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||||
value = kit.GetMeta(value)
|
if value = kit.GetMeta(value); name != "" && name != value[USERNAME] {
|
||||||
if name != "" && name != value[USERNAME] {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.PushSearch(kit.SSH_CMD, USER, kit.MDB_TYPE, kit.Format(UserRole(m, value[USERNAME])),
|
m.PushSearch(kit.SSH_CMD, USER, kit.MDB_TYPE, kit.Format(UserRole(m, value[USERNAME])),
|
||||||
@ -144,7 +143,7 @@ func init() {
|
|||||||
m.Table(func(index int, value map[string]string, head []string) {
|
m.Table(func(index int, value map[string]string, head []string) {
|
||||||
m.Push(USERROLE, UserRole(m, value[USERNAME]))
|
m.Push(USERROLE, UserRole(m, value[USERNAME]))
|
||||||
})
|
})
|
||||||
m.PushAction(ROLE, mdb.REMOVE)
|
m.PushAction(mdb.REMOVE)
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NodeInfo(m *ice.Message, kind, name string) {
|
func NodeInfo(m *ice.Message, kind, name string) {
|
||||||
@ -26,13 +25,9 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
|||||||
m.Load()
|
m.Load()
|
||||||
|
|
||||||
// 启动配置
|
// 启动配置
|
||||||
m.Conf(RUNTIME, "conf.ctx_self", os.Getenv("ctx_self"))
|
for _, k := range []string{"ctx_self", "ctx_dev", "ctx_shy", "ctx_pid", "ctx_user", "ctx_share", "ctx_river"} {
|
||||||
m.Conf(RUNTIME, "conf.ctx_dev", os.Getenv("ctx_dev"))
|
m.Conf(RUNTIME, kit.Keys("conf", k), os.Getenv(k))
|
||||||
m.Conf(RUNTIME, "conf.ctx_shy", os.Getenv("ctx_shy"))
|
}
|
||||||
m.Conf(RUNTIME, "conf.ctx_pid", os.Getenv("ctx_pid"))
|
|
||||||
m.Conf(RUNTIME, "conf.ctx_user", os.Getenv("ctx_user"))
|
|
||||||
m.Conf(RUNTIME, "conf.ctx_share", os.Getenv("ctx_share"))
|
|
||||||
m.Conf(RUNTIME, "conf.ctx_river", os.Getenv("ctx_river"))
|
|
||||||
|
|
||||||
// 主机信息
|
// 主机信息
|
||||||
m.Conf(RUNTIME, "host.GOARCH", runtime.GOARCH)
|
m.Conf(RUNTIME, "host.GOARCH", runtime.GOARCH)
|
||||||
@ -63,7 +58,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
|||||||
ice.Info.CtxShare = m.Conf(RUNTIME, "conf.ctx_share")
|
ice.Info.CtxShare = m.Conf(RUNTIME, "conf.ctx_share")
|
||||||
ice.Info.CtxRiver = m.Conf(RUNTIME, "conf.ctx_river")
|
ice.Info.CtxRiver = m.Conf(RUNTIME, "conf.ctx_river")
|
||||||
|
|
||||||
// 启动记录
|
// 启动次数
|
||||||
count := kit.Int(m.Conf(RUNTIME, "boot.count")) + 1
|
count := kit.Int(m.Conf(RUNTIME, "boot.count")) + 1
|
||||||
m.Conf(RUNTIME, "boot.count", count)
|
m.Conf(RUNTIME, "boot.count", count)
|
||||||
|
|
||||||
@ -78,24 +73,13 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
|||||||
|
|
||||||
// 版本信息
|
// 版本信息
|
||||||
kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Build)), func(key string, value interface{}) {
|
kit.Fetch(kit.UnMarshal(kit.Format(ice.Info.Build)), func(key string, value interface{}) {
|
||||||
m.Conf(RUNTIME, kit.Keys("build", strings.ToLower(key)), value)
|
m.Conf(RUNTIME, kit.Keys("make", strings.ToLower(key)), value)
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
list := []string{}
|
|
||||||
m.Richs(DAEMON, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
|
||||||
if value = kit.GetMeta(value); kit.Value(value, mdb.CACHE_CLEAR_ON_EXIT) == "true" {
|
|
||||||
list = append(list, key)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
for _, k := range list {
|
|
||||||
m.Conf(DAEMON, kit.Keys(kit.MDB_HASH, k), "")
|
|
||||||
}
|
|
||||||
m.Save()
|
m.Save()
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE) }
|
||||||
ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE, PYTHON, OUTPUT, PROGRESS)
|
|
||||||
}
|
|
||||||
|
@ -1,16 +1,7 @@
|
|||||||
chapter "cli"
|
chapter "cli"
|
||||||
|
|
||||||
field "脚本" python
|
field "扫码" qrcode
|
||||||
field "守护" daemon
|
field "守护" daemon
|
||||||
field "命令" system
|
field "命令" system
|
||||||
field "输出" output
|
|
||||||
field "环境" runtime
|
field "环境" runtime
|
||||||
field "进程" cli.proc
|
|
||||||
|
|
||||||
section "python"
|
|
||||||
refer `
|
|
||||||
官网 https://www.python.org/
|
|
||||||
源码 https://www.python.org/downloads/source/
|
|
||||||
文档 https://docs.python.org/3/reference/index.html
|
|
||||||
`
|
|
||||||
|
|
||||||
|
@ -2,47 +2,49 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
|
func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
|
||||||
if w, ok := m.Optionv(CMD_STDOUT).(io.Writer); ok {
|
if w, ok := m.Optionv(CMD_OUTPUT).(io.Writer); ok {
|
||||||
cmd.Stdout = w
|
cmd.Stdout = w
|
||||||
cmd.Stderr = w
|
cmd.Stderr = w
|
||||||
} else if f, p, e := kit.Create(out); m.Assert(e) {
|
} else if f, p, e := kit.Create(out); m.Assert(e) {
|
||||||
m.Log_EXPORT(kit.MDB_META, DAEMON, CMD_STDOUT, p)
|
m.Log_EXPORT(kit.MDB_META, DAEMON, CMD_OUTPUT, p)
|
||||||
m.Optionv(CMD_STDOUT, f)
|
m.Optionv(CMD_OUTPUT, f)
|
||||||
cmd.Stdout = f
|
cmd.Stdout = f
|
||||||
cmd.Stderr = f
|
cmd.Stderr = f
|
||||||
}
|
}
|
||||||
if w, ok := m.Optionv(CMD_STDERR).(io.Writer); ok {
|
if w, ok := m.Optionv(CMD_ERRPUT).(io.Writer); ok {
|
||||||
cmd.Stderr = w
|
cmd.Stderr = w
|
||||||
} else if f, p, e := kit.Create(err); m.Assert(e) {
|
} else if f, p, e := kit.Create(err); m.Assert(e) {
|
||||||
m.Log_EXPORT(kit.MDB_META, DAEMON, CMD_STDERR, p)
|
m.Log_EXPORT(kit.MDB_META, DAEMON, CMD_ERRPUT, p)
|
||||||
m.Optionv(CMD_STDERR, f)
|
m.Optionv(CMD_ERRPUT, f)
|
||||||
cmd.Stderr = f
|
cmd.Stderr = f
|
||||||
}
|
}
|
||||||
|
|
||||||
if e := cmd.Start(); m.Warn(e != nil, ErrStart, cmd.Args, " ", e) {
|
// 启动进程
|
||||||
|
if e := cmd.Start(); m.Warn(e != nil, cmd.Args, " ", e) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
h := m.Cmdx(mdb.INSERT, DAEMON, "", mdb.HASH,
|
|
||||||
mdb.CACHE_CLEAR_ON_EXIT, m.Option(mdb.CACHE_CLEAR_ON_EXIT),
|
|
||||||
kit.MDB_STATUS, Status.Start, kit.SSH_CMD, strings.Join(cmd.Args, " "),
|
|
||||||
kit.SSH_DIR, cmd.Dir, kit.SSH_ENV, kit.Select("", cmd.Env), kit.SSH_PID, cmd.Process.Pid,
|
|
||||||
CMD_STDOUT, out, CMD_STDERR, err,
|
|
||||||
)
|
|
||||||
m.Echo("%d", cmd.Process.Pid)
|
m.Echo("%d", cmd.Process.Pid)
|
||||||
|
|
||||||
m.Go(func() {
|
m.Go(func() {
|
||||||
if e := cmd.Wait(); m.Warn(e != nil, ErrStart, cmd.Args, " ", e) {
|
h := m.Cmdx(mdb.INSERT, DAEMON, "", mdb.HASH,
|
||||||
|
kit.MDB_STATUS, Status.Start, kit.SSH_PID, cmd.Process.Pid,
|
||||||
|
kit.SSH_CMD, strings.Join(cmd.Args, " "),
|
||||||
|
kit.SSH_DIR, cmd.Dir, kit.SSH_ENV, kit.Select("", cmd.Env),
|
||||||
|
mdb.CACHE_CLEAR_ON_EXIT, m.Option(mdb.CACHE_CLEAR_ON_EXIT),
|
||||||
|
CMD_OUTPUT, out, CMD_ERRPUT, err,
|
||||||
|
)
|
||||||
|
|
||||||
|
if e := cmd.Wait(); m.Warn(e != nil, cmd.Args, " ", e) {
|
||||||
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, kit.MDB_HASH, h,
|
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, kit.MDB_HASH, h,
|
||||||
kit.MDB_STATUS, Status.Error, kit.MDB_ERROR, e)
|
kit.MDB_STATUS, Status.Error, kit.MDB_ERROR, e)
|
||||||
} else {
|
} else {
|
||||||
@ -50,17 +52,16 @@ func _daemon_show(m *ice.Message, cmd *exec.Cmd, out, err string) {
|
|||||||
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, kit.MDB_HASH, h,
|
m.Cmd(mdb.MODIFY, DAEMON, "", mdb.HASH, kit.MDB_HASH, h,
|
||||||
kit.MDB_STATUS, Status.Stop)
|
kit.MDB_STATUS, Status.Stop)
|
||||||
}
|
}
|
||||||
if w, ok := m.Optionv(CMD_STDOUT).(io.Closer); ok {
|
|
||||||
|
if w, ok := m.Optionv(CMD_OUTPUT).(io.Closer); ok {
|
||||||
w.Close()
|
w.Close()
|
||||||
}
|
}
|
||||||
if w, ok := m.Optionv(CMD_STDERR).(io.Closer); ok {
|
if w, ok := m.Optionv(CMD_ERRPUT).(io.Closer); ok {
|
||||||
w.Close()
|
w.Close()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const ErrStart = "daemon start: "
|
|
||||||
|
|
||||||
var Status = struct{ Error, Start, Stop string }{
|
var Status = struct{ Error, Start, Stop string }{
|
||||||
Error: "error",
|
Error: "error",
|
||||||
Start: "start",
|
Start: "start",
|
||||||
@ -68,10 +69,10 @@ var Status = struct{ Error, Start, Stop string }{
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
DIR = "dir"
|
||||||
ENV = "env"
|
ENV = "env"
|
||||||
CMD = "cmd"
|
CMD = "cmd"
|
||||||
ARG = "arg"
|
ARG = "arg"
|
||||||
DIR = "dir"
|
|
||||||
RUN = "run"
|
RUN = "run"
|
||||||
RES = "res"
|
RES = "res"
|
||||||
ERR = "err"
|
ERR = "err"
|
||||||
@ -87,9 +88,23 @@ const DAEMON = "daemon"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
DAEMON: {Name: DAEMON, Help: "守护进程", Value: kit.Data(kit.MDB_PATH, "usr/local/daemon")},
|
DAEMON: {Name: DAEMON, Help: "守护进程", Value: kit.Data(kit.MDB_PATH, path.Join(ice.USR_LOCAL, DAEMON))},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
}},
|
||||||
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
list := []string{}
|
||||||
|
m.Richs(DAEMON, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||||
|
if value = kit.GetMeta(value); kit.Value(value, mdb.CACHE_CLEAR_ON_EXIT) == ice.TRUE {
|
||||||
|
list = append(list, key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
for _, k := range list {
|
||||||
|
m.Conf(DAEMON, kit.Keys(kit.MDB_HASH, k), "")
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
|
||||||
DAEMON: {Name: "daemon hash auto start prunes", Help: "守护进程", Action: map[string]*ice.Action{
|
DAEMON: {Name: "daemon hash auto start prunes", Help: "守护进程", Action: map[string]*ice.Action{
|
||||||
RESTART: {Name: "restart", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
RESTART: {Name: "restart", Help: "重启", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(DAEMON, STOP)
|
m.Cmd(DAEMON, STOP)
|
||||||
@ -98,9 +113,9 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
START: {Name: "start cmd env dir", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
START: {Name: "start cmd env dir", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Option(CMD_TYPE, DAEMON)
|
m.Option(CMD_TYPE, DAEMON)
|
||||||
m.Option(CMD_DIR, m.Option("dir"))
|
m.Option(CMD_DIR, m.Option(DIR))
|
||||||
m.Option(CMD_ENV, kit.Split(m.Option("env"), " ="))
|
m.Option(CMD_ENV, kit.Split(m.Option(ENV), " ="))
|
||||||
m.Cmdy(SYSTEM, kit.Split(m.Option("cmd")))
|
m.Cmdy(SYSTEM, kit.Split(m.Option(CMD)))
|
||||||
}},
|
}},
|
||||||
STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Option(mdb.FIELDS, "time,hash,status,pid,cmd,dir,env")
|
m.Option(mdb.FIELDS, "time,hash,status,pid,cmd,dir,env")
|
||||||
@ -118,8 +133,8 @@ func init() {
|
|||||||
m.Cmdy(mdb.PRUNES, DAEMON, "", mdb.HASH, kit.MDB_STATUS, Status.Stop)
|
m.Cmdy(mdb.PRUNES, DAEMON, "", mdb.HASH, kit.MDB_STATUS, Status.Stop)
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 { // 进程列表
|
||||||
m.Option(mdb.FIELDS, "time,hash,status,pid,cmd,dir,env")
|
m.Fields(len(arg) == 0, "time,hash,status,pid,cmd,dir,env")
|
||||||
m.Cmdy(mdb.SELECT, DAEMON, "", mdb.HASH)
|
m.Cmdy(mdb.SELECT, DAEMON, "", mdb.HASH)
|
||||||
m.Table(func(index int, value map[string]string, head []string) {
|
m.Table(func(index int, value map[string]string, head []string) {
|
||||||
switch value[kit.MDB_STATUS] {
|
switch value[kit.MDB_STATUS] {
|
||||||
@ -130,11 +145,11 @@ func init() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
} else if m.Richs(DAEMON, "", arg[0], nil) != nil {
|
} else if m.Richs(DAEMON, "", arg[0], nil) != nil { // 进程详情
|
||||||
m.Option(mdb.FIELDS, mdb.DETAIL)
|
m.Option(mdb.FIELDS, mdb.DETAIL)
|
||||||
m.Cmdy(mdb.SELECT, DAEMON, "", mdb.HASH, kit.MDB_HASH, arg)
|
m.Cmdy(mdb.SELECT, DAEMON, "", mdb.HASH, kit.MDB_HASH, arg)
|
||||||
|
|
||||||
} else {
|
} else { // 启动进程
|
||||||
m.Option(CMD_TYPE, DAEMON)
|
m.Option(CMD_TYPE, DAEMON)
|
||||||
m.Cmdy(SYSTEM, arg)
|
m.Cmdy(SYSTEM, arg)
|
||||||
}
|
}
|
||||||
|
@ -1,125 +0,0 @@
|
|||||||
package cli
|
|
||||||
|
|
||||||
import (
|
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"io"
|
|
||||||
)
|
|
||||||
|
|
||||||
func _cli_progress(m *ice.Message, cb interface{}) {
|
|
||||||
m.Option(mdb.FIELDS, "time,name,step,count,total")
|
|
||||||
if m.Option(ice.MSG_PROCESS, "_progress"); m.Option("_progress") != "" {
|
|
||||||
m.Cmdy(mdb.SELECT, PROGRESS, "", mdb.HASH, kit.MDB_HASH, m.Option("_progress"))
|
|
||||||
if len(m.Appendv(kit.MDB_TIME)) > 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
h := m.Cmdx(mdb.INSERT, PROGRESS, "", mdb.HASH, "step", 0, "count", 0, "total", 1)
|
|
||||||
m.Cmdy(mdb.SELECT, PROGRESS, "", mdb.HASH, kit.MDB_HASH, m.Option("_progress", h))
|
|
||||||
|
|
||||||
m.Go(func() {
|
|
||||||
switch cb := cb.(type) {
|
|
||||||
case func(cb func(name string, count, total int)):
|
|
||||||
cb(func(name string, count, total int) {
|
|
||||||
m.Debug("what %v", name)
|
|
||||||
m.Cmd(mdb.MODIFY, PROGRESS, "", mdb.HASH, kit.MDB_HASH, h, "name", name,
|
|
||||||
"step", count*100/total, "count", count, "total", total)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
func Follow(m *ice.Message, action string, cb func()) bool {
|
|
||||||
m.Option(ice.MSG_PROCESS, "_follow")
|
|
||||||
if m.Option(mdb.CACHE_ACTION, action); m.Option(mdb.CACHE_HASH) != "" {
|
|
||||||
m.Cmdy(OUTPUT, m.Option(mdb.CACHE_HASH))
|
|
||||||
m.Sort(kit.MDB_ID).Table(func(index int, value map[string]string, head []string) {
|
|
||||||
m.Option(mdb.CACHE_BEGIN, value[kit.MDB_ID])
|
|
||||||
m.Echo(value[kit.SSH_RES])
|
|
||||||
})
|
|
||||||
|
|
||||||
if len(m.Resultv()) == 0 && m.Conf(OUTPUT, kit.Keys(kit.MDB_HASH, m.Option(mdb.CACHE_HASH), kit.MDB_META, kit.MDB_STATUS)) == STOP {
|
|
||||||
m.Option(mdb.CACHE_STATUS, STOP)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
m.Cmdy(OUTPUT, mdb.CREATE, kit.MDB_NAME, m.Option(kit.MDB_LINK))
|
|
||||||
m.Option(mdb.CACHE_HASH, m.Result())
|
|
||||||
m.Option(mdb.CACHE_BEGIN, 1)
|
|
||||||
m.Set(ice.MSG_RESULT)
|
|
||||||
m.Go(cb)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
PROGRESS_CB = "progress.cb"
|
|
||||||
)
|
|
||||||
|
|
||||||
const PROGRESS = "progress"
|
|
||||||
|
|
||||||
const OUTPUT = "output"
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
Index.Merge(&ice.Context{
|
|
||||||
Configs: map[string]*ice.Config{
|
|
||||||
OUTPUT: {Name: OUTPUT, Help: "输出", Value: kit.Data()},
|
|
||||||
PROGRESS: {Name: PROGRESS, Help: "进度", Value: kit.Data()},
|
|
||||||
},
|
|
||||||
Commands: map[string]*ice.Command{
|
|
||||||
PROGRESS: {Name: "progress hash auto", Help: "进度", Action: map[string]*ice.Action{
|
|
||||||
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
_cli_progress(m, m.Optionv(PROGRESS_CB))
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
m.Option(mdb.FIELDS, kit.Select("time,name,step,count,total", mdb.DETAIL, len(arg) > 0))
|
|
||||||
m.Cmdy(mdb.SELECT, PROGRESS, "", mdb.HASH, kit.MDB_HASH, arg)
|
|
||||||
m.SortInt("step")
|
|
||||||
}},
|
|
||||||
|
|
||||||
OUTPUT: {Name: "output hash id auto", Help: "输出", Action: map[string]*ice.Action{
|
|
||||||
mdb.CREATE: {Name: "create cmd", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
h := m.Cmdx(mdb.INSERT, OUTPUT, "", mdb.HASH, kit.MDB_STATUS, Status.Start, arg)
|
|
||||||
r, w := io.Pipe()
|
|
||||||
m.Go(func() {
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
for {
|
|
||||||
if n, e := r.Read(buf); e != nil || n == 0 {
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
m.Grow(OUTPUT, kit.Keys(kit.MDB_HASH, h), kit.Dict(
|
|
||||||
kit.SSH_RES, string(buf[:n]),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.Cmd(mdb.MODIFY, OUTPUT, "", mdb.HASH, kit.MDB_HASH, h, kit.MDB_STATUS, Status.Stop)
|
|
||||||
})
|
|
||||||
m.Option(OUTPUT, w)
|
|
||||||
m.Echo(h)
|
|
||||||
}},
|
|
||||||
mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmdy(mdb.MODIFY, OUTPUT, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH), arg)
|
|
||||||
}},
|
|
||||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmdy(mdb.DELETE, OUTPUT, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
|
||||||
}},
|
|
||||||
mdb.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmdy(mdb.PRUNES, OUTPUT, "", mdb.HASH, kit.MDB_STATUS, Status.Stop)
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
if len(arg) == 0 {
|
|
||||||
m.Option(mdb.FIELDS, "time,hash,status,name")
|
|
||||||
m.Cmdy(mdb.SELECT, OUTPUT, "", mdb.HASH)
|
|
||||||
m.PushAction(mdb.REMOVE)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Option(ice.MSG_CONTROL, "_page")
|
|
||||||
m.Option(mdb.FIELDS, kit.Select("time,id,res", mdb.DETAIL, len(arg) > 1))
|
|
||||||
m.Cmdy(mdb.SELECT, OUTPUT, kit.Keys(kit.MDB_HASH, arg[0]), mdb.LIST, kit.MDB_ID, arg[1:])
|
|
||||||
m.Sort(kit.MDB_ID)
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package cli
|
|
||||||
|
|
||||||
import (
|
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
Index.Merge(&ice.Context{
|
|
||||||
Commands: map[string]*ice.Command{
|
|
||||||
"proc": {Name: "proc name=ice.bin PID auto", Help: "进程管理", Action: map[string]*ice.Action{
|
|
||||||
"kill": {Name: "kill", Help: "结束", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
if p, e := os.FindProcess(kit.Int(m.Option("PID"))); m.Assert(e) {
|
|
||||||
m.Assert(p.Kill())
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
msg := m.Spawn()
|
|
||||||
msg.Split(m.Cmdx(SYSTEM, "ps", "ux"), "", " ", "\n")
|
|
||||||
msg.Table(func(index int, value map[string]string, head []string) {
|
|
||||||
if m.Appendv(ice.MSG_APPEND, "action", head); len(arg) > 1 && value["PID"] != arg[1] {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(arg) > 0 && !strings.Contains(value["COMMAND"], arg[0]) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.PushButton("kill")
|
|
||||||
m.Push("", value)
|
|
||||||
})
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,48 +1,95 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go"
|
|
||||||
"github.com/skip2/go-qrcode"
|
"github.com/skip2/go-qrcode"
|
||||||
|
"image/color"
|
||||||
|
"math/rand"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/aaa"
|
"github.com/shylinux/icebergs/base/aaa"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _qrcode_cli(m *ice.Message, arg ...string) {
|
var _trans_web = map[string]color.Color{
|
||||||
fg := qrcodeTerminal.ConsoleColors.BrightBlue
|
"black": color.RGBA{0, 0, 0, 255},
|
||||||
bg := qrcodeTerminal.ConsoleColors.BrightWhite
|
"red": color.RGBA{255, 0, 0, 255},
|
||||||
switch m.Option("fg") {
|
"green": color.RGBA{0, 255, 0, 255},
|
||||||
case "black":
|
"yellow": color.RGBA{255, 255, 0, 255},
|
||||||
fg = qrcodeTerminal.ConsoleColors.BrightBlack
|
"blue": color.RGBA{0, 0, 255, 255},
|
||||||
case "red":
|
"magenta": color.RGBA{255, 0, 255, 255},
|
||||||
fg = qrcodeTerminal.ConsoleColors.BrightRed
|
"cyan": color.RGBA{0, 255, 255, 255},
|
||||||
case "green":
|
"white": color.RGBA{255, 255, 255, 255},
|
||||||
fg = qrcodeTerminal.ConsoleColors.BrightGreen
|
|
||||||
case "yellow":
|
|
||||||
fg = qrcodeTerminal.ConsoleColors.BrightYellow
|
|
||||||
case "blue":
|
|
||||||
fg = qrcodeTerminal.ConsoleColors.BrightBlue
|
|
||||||
case "cyan":
|
|
||||||
fg = qrcodeTerminal.ConsoleColors.BrightCyan
|
|
||||||
case "magenta":
|
|
||||||
fg = qrcodeTerminal.ConsoleColors.BrightMagenta
|
|
||||||
case "white":
|
|
||||||
fg = qrcodeTerminal.ConsoleColors.BrightWhite
|
|
||||||
}
|
|
||||||
obj := qrcodeTerminal.New2(fg, bg, qrcodeTerminal.QRCodeRecoveryLevels.Medium)
|
|
||||||
m.Echo("%s", *obj.Get(arg[0]))
|
|
||||||
}
|
}
|
||||||
func _qrcode_web(m *ice.Message, arg ...string) {
|
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
|
func _parse_color(str string) color.Color {
|
||||||
if qr, e := qrcode.New(arg[0], qrcode.Medium); m.Assert(e) {
|
if str == "random" {
|
||||||
m.Assert(qr.Write(kit.Int(kit.Select("240", arg, 1)), buf))
|
list := []string{}
|
||||||
|
for k := range _trans_web {
|
||||||
|
list = append(list, k)
|
||||||
|
}
|
||||||
|
str = list[rand.Intn(len(list))]
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(str, "#") {
|
||||||
|
if len(str) == 7 {
|
||||||
|
str += "ff"
|
||||||
|
}
|
||||||
|
if u, e := strconv.ParseUint(str[1:], 16, 64); e == nil {
|
||||||
|
return color.RGBA{
|
||||||
|
uint8((u & 0xFF000000) >> 24),
|
||||||
|
uint8((u & 0x00FF0000) >> 16),
|
||||||
|
uint8((u & 0x0000FF00) >> 8),
|
||||||
|
uint8((u & 0x000000FF) >> 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _trans_web[str]
|
||||||
|
}
|
||||||
|
func _trans_cli(str string) string {
|
||||||
|
res := 0
|
||||||
|
r, g, b, _ := _parse_color(str).RGBA()
|
||||||
|
if r > 128 {
|
||||||
|
res += 1
|
||||||
|
}
|
||||||
|
if g > 128 {
|
||||||
|
res += 2
|
||||||
|
}
|
||||||
|
if b > 128 {
|
||||||
|
res += 4
|
||||||
|
}
|
||||||
|
return kit.Format(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _qrcode_cli(m *ice.Message, text string, arg ...string) {
|
||||||
|
qr, _ := qrcode.New(text, qrcode.Medium)
|
||||||
|
fg := _trans_cli(m.Option("fg"))
|
||||||
|
bg := _trans_cli(m.Option("bg"))
|
||||||
|
|
||||||
|
data := qr.Bitmap()
|
||||||
|
for i, row := range data {
|
||||||
|
if n := len(data); i < 3 || i >= n-3 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for i, col := range row {
|
||||||
|
if n := len(row); i < 3 || i >= n-3 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Echo("\033[4%sm \033[0m", kit.Select(bg, fg, col))
|
||||||
|
}
|
||||||
|
m.Echo("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func _qrcode_web(m *ice.Message, text string, arg ...string) {
|
||||||
|
qr, _ := qrcode.New(text, qrcode.Medium)
|
||||||
|
qr.ForegroundColor = _parse_color(m.Option("fg"))
|
||||||
|
qr.BackgroundColor = _parse_color(m.Option("bg"))
|
||||||
|
|
||||||
|
if data, err := qr.PNG(kit.Int(m.Option("size"))); m.Assert(err) {
|
||||||
|
m.Echo(`<img src="data:image/png;base64,%s" title='%s'>`, base64.StdEncoding.EncodeToString(data), text)
|
||||||
}
|
}
|
||||||
m.Option("byte", buf.Bytes())
|
|
||||||
data := base64.StdEncoding.EncodeToString(buf.Bytes())
|
|
||||||
m.Echo(`<img src="data:image/png;base64,%s" title='%s' height=%s>`, data, arg[0], kit.Select("240", arg, 1))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QRCODE = "qrcode"
|
const QRCODE = "qrcode"
|
||||||
@ -53,12 +100,16 @@ func init() {
|
|||||||
QRCODE: {Name: "qrcode", Help: "二维码", Value: kit.Data()},
|
QRCODE: {Name: "qrcode", Help: "二维码", Value: kit.Data()},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
QRCODE: {Name: "qrcode text auto", Help: "二维码", Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
QRCODE: {Name: "qrcode text fg bg size auto", Help: "二维码", Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
m.Option("fg", kit.Select("blue", arg, 1))
|
||||||
|
m.Option("bg", kit.Select("white", arg, 2))
|
||||||
|
m.Option("size", kit.Select("240", arg, 3))
|
||||||
|
|
||||||
if aaa.SessIsCli(m) {
|
if aaa.SessIsCli(m) {
|
||||||
_qrcode_cli(m, arg...)
|
_qrcode_cli(m, arg[0])
|
||||||
return
|
} else {
|
||||||
|
_qrcode_web(m, arg[0])
|
||||||
}
|
}
|
||||||
_qrcode_web(m, arg...)
|
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
"github.com/shylinux/icebergs/base/ctx"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/ctx"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DISKINFO = "diskinfo"
|
||||||
|
IFCONFIG = "ifconfig"
|
||||||
|
HOSTNAME = "hostname"
|
||||||
|
HOSTINFO = "hostinfo"
|
||||||
|
USERINFO = "userinfo"
|
||||||
|
PROCINFO = "procinfo"
|
||||||
|
BOOTINFO = "bootinfo"
|
||||||
|
)
|
||||||
const RUNTIME = "runtime"
|
const RUNTIME = "runtime"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -19,11 +28,26 @@ func init() {
|
|||||||
RUNTIME: {Name: RUNTIME, Help: "运行环境", Value: kit.Dict()},
|
RUNTIME: {Name: RUNTIME, Help: "运行环境", Value: kit.Dict()},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
RUNTIME: {Name: "runtime info=procinfo,hostinfo,diskinfo,ifconfig,hostname,userinfo,bootinfo auto", Help: "运行环境", Action: map[string]*ice.Action{
|
RUNTIME: {Name: "runtime info=diskinfo,ifconfig,hostname,hostinfo,userinfo,procinfo,bootinfo auto", Help: "运行环境", Action: map[string]*ice.Action{
|
||||||
"procinfo": {Name: "procinfo", Help: "procinfo", Hand: func(m *ice.Message, arg ...string) {
|
DISKINFO: {Name: "diskinfo", Help: "磁盘信息", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Split(m.Cmdx(SYSTEM, "ps", "u"), "", " ", "\n")
|
m.Spawn().Split(m.Cmdx(SYSTEM, "df", "-h"), "", " ", "\n").Table(func(index int, value map[string]string, head []string) {
|
||||||
|
if strings.HasPrefix(value["Filesystem"], "/dev") {
|
||||||
|
m.Push("", value, head)
|
||||||
|
}
|
||||||
|
})
|
||||||
}},
|
}},
|
||||||
"hostinfo": {Name: "hostinfo", Help: "hostinfo", Hand: func(m *ice.Message, arg ...string) {
|
IFCONFIG: {Name: "ifconfig", Help: "网卡配置", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmdy("tcp.host")
|
||||||
|
}},
|
||||||
|
HOSTNAME: {Name: "hostname", Help: "主机域名", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
if len(arg) > 0 {
|
||||||
|
m.Conf(RUNTIME, "boot.hostname", arg[0])
|
||||||
|
m.Conf(RUNTIME, "node.name", arg[0])
|
||||||
|
ice.Info.HostName = arg[0]
|
||||||
|
}
|
||||||
|
m.Echo(ice.Info.HostName)
|
||||||
|
}},
|
||||||
|
HOSTINFO: {Name: "hostinfo", Help: "主机信息", Hand: func(m *ice.Message, arg ...string) {
|
||||||
if f, e := os.Open("/proc/cpuinfo"); e == nil {
|
if f, e := os.Open("/proc/cpuinfo"); e == nil {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
if b, e := ioutil.ReadAll(f); e == nil {
|
if b, e := ioutil.ReadAll(f); e == nil {
|
||||||
@ -44,29 +68,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), ",")[0])
|
m.Push("uptime", kit.Split(m.Cmdx(SYSTEM, "uptime"), ",")[0])
|
||||||
}},
|
}},
|
||||||
"diskinfo": {Name: "diskinfo", Help: "diskinfo", Hand: func(m *ice.Message, arg ...string) {
|
USERINFO: {Name: "userinfo", Help: "用户信息", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Spawn().Split(m.Cmdx(SYSTEM, "df", "-h"), "", " ", "\n").Table(func(index int, value map[string]string, head []string) {
|
|
||||||
if strings.HasPrefix(value["Filesystem"], "/dev") {
|
|
||||||
m.Push("", value, head)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}},
|
|
||||||
"ifconfig": {Name: "ifconfig", Help: "ifconfig", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Cmdy("tcp.host")
|
|
||||||
}},
|
|
||||||
"hostname": {Name: "hostname", Help: "hostname", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
if len(arg) > 0 {
|
|
||||||
m.Conf(RUNTIME, "boot.hostname", arg[0])
|
|
||||||
m.Conf(RUNTIME, "node.name", arg[0])
|
|
||||||
ice.Info.HostName = arg[0]
|
|
||||||
}
|
|
||||||
m.Echo(ice.Info.HostName)
|
|
||||||
}},
|
|
||||||
"userinfo": {Name: "userinfo", Help: "userinfo", Hand: func(m *ice.Message, arg ...string) {
|
|
||||||
m.Split(m.Cmdx(SYSTEM, "who"), "user term time", " ", "\n")
|
m.Split(m.Cmdx(SYSTEM, "who"), "user term time", " ", "\n")
|
||||||
}},
|
}},
|
||||||
|
PROCINFO: {Name: "procinfo", Help: "进程信息", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Split(m.Cmdx(SYSTEM, "ps", "u"), "", " ", "\n")
|
||||||
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) > 0 && arg[0] == "bootinfo" {
|
if len(arg) > 0 && arg[0] == BOOTINFO {
|
||||||
arg = arg[1:]
|
arg = arg[1:]
|
||||||
}
|
}
|
||||||
m.Cmdy(ctx.CONFIG, RUNTIME, arg)
|
m.Cmdy(ctx.CONFIG, RUNTIME, arg)
|
||||||
|
@ -1 +0,0 @@
|
|||||||
package cli
|
|
@ -6,72 +6,59 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _system_show(m *ice.Message, cmd *exec.Cmd) {
|
func _system_show(m *ice.Message, cmd *exec.Cmd) {
|
||||||
|
// 输入流
|
||||||
if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok {
|
if r, ok := m.Optionv(CMD_INPUT).(io.Reader); ok {
|
||||||
cmd.Stdin = r
|
cmd.Stdin = r
|
||||||
}
|
}
|
||||||
|
|
||||||
if w, ok := m.Optionv(CMD_OUTPUT).(io.WriteCloser); ok {
|
// 输出流
|
||||||
cmd.Stdout = w
|
if w, ok := m.Optionv(CMD_OUTPUT).(io.Writer); ok {
|
||||||
cmd.Stderr = w
|
cmd.Stdout, cmd.Stderr = w, w
|
||||||
if w, ok := m.Optionv(CMD_ERRPUT).(io.WriteCloser); ok {
|
if w, ok := m.Optionv(CMD_ERRPUT).(io.Writer); ok {
|
||||||
cmd.Stderr = w
|
cmd.Stderr = w
|
||||||
}
|
}
|
||||||
|
|
||||||
if e := cmd.Run(); e != nil {
|
|
||||||
m.Warn(e != nil, ErrRun, strings.Join(cmd.Args, " "), "\n", e.Error())
|
|
||||||
m.Push(CMD_ERR, e.Error())
|
|
||||||
} else {
|
|
||||||
m.Cost("args", cmd.Args, "code", cmd.ProcessState.ExitCode())
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
out := bytes.NewBuffer(make([]byte, 0, 1024))
|
out := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
err := bytes.NewBuffer(make([]byte, 0, 1024))
|
err := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||||
defer func() {
|
defer func() {
|
||||||
m.Push(CMD_ERR, err.String())
|
m.Push(CMD_ERR, err.String())
|
||||||
m.Push(CMD_OUT, out.String())
|
m.Push(CMD_OUT, out.String())
|
||||||
m.Echo(kit.Select(err.String(), out.String()))
|
m.Echo(kit.Select(out.String(), err.String()))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
cmd.Stdout = out
|
cmd.Stdout, cmd.Stderr = out, err
|
||||||
cmd.Stderr = err
|
}
|
||||||
|
|
||||||
if e := cmd.Run(); e != nil {
|
// 执行命令
|
||||||
m.Warn(e != nil, ErrRun, strings.Join(cmd.Args, " "), "\n", kit.Select(e.Error(), err.String()))
|
if e := cmd.Run(); e != nil {
|
||||||
fmt.Fprintf(err, e.Error())
|
m.Warn(e != nil, cmd.Args, " ", e.Error())
|
||||||
} else {
|
} else {
|
||||||
m.Cost("args", cmd.Args, "code", cmd.ProcessState.ExitCode(), "err", err.Len(), "out", out.Len())
|
m.Cost("code", cmd.ProcessState.ExitCode(), "args", cmd.Args)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Push(kit.MDB_TIME, m.Time())
|
m.Push(kit.MDB_TIME, m.Time())
|
||||||
m.Push(CMD_CODE, int(cmd.ProcessState.ExitCode()))
|
m.Push(CMD_CODE, int(cmd.ProcessState.ExitCode()))
|
||||||
}
|
}
|
||||||
|
|
||||||
const ErrRun = "cli run err: "
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
CMD_DIR = "cmd_dir"
|
||||||
|
CMD_ENV = "cmd_env"
|
||||||
|
CMD_TYPE = "cmd_type"
|
||||||
|
|
||||||
CMD_INPUT = "cmd_input"
|
CMD_INPUT = "cmd_input"
|
||||||
CMD_OUTPUT = "cmd_output"
|
CMD_OUTPUT = "cmd_output"
|
||||||
CMD_ERRPUT = "cmd_errput"
|
CMD_ERRPUT = "cmd_errput"
|
||||||
|
|
||||||
CMD_STDERR = "cmd_stderr"
|
|
||||||
CMD_STDOUT = "cmd_stdout"
|
|
||||||
|
|
||||||
CMD_TYPE = "cmd_type"
|
|
||||||
CMD_DIR = "cmd_dir"
|
|
||||||
CMD_ENV = "cmd_env"
|
|
||||||
|
|
||||||
CMD_OUT = "cmd_out"
|
|
||||||
CMD_ERR = "cmd_err"
|
|
||||||
CMD_CODE = "cmd_code"
|
CMD_CODE = "cmd_code"
|
||||||
|
CMD_ERR = "cmd_err"
|
||||||
|
CMD_OUT = "cmd_out"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -90,15 +77,7 @@ func init() {
|
|||||||
SYSTEM: {Name: SYSTEM, Help: "系统命令", Value: kit.Data()},
|
SYSTEM: {Name: SYSTEM, Help: "系统命令", Value: kit.Data()},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
SYSTEM: {Name: "system id auto", Help: "系统命令", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
SYSTEM: {Name: "system cmd= 执行:button", Help: "系统命令", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||||
|
|
||||||
if len(arg) == 0 || kit.Int(arg[0]) > 0 {
|
|
||||||
m.Option("_control", "_page")
|
|
||||||
m.Option(mdb.FIELDS, kit.Select("time,id,cmd,dir,env", mdb.DETAIL, len(arg) > 0))
|
|
||||||
m.Cmdy(mdb.SELECT, SYSTEM, "", mdb.LIST, kit.MDB_ID, arg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) == 1 {
|
if len(arg) == 1 {
|
||||||
arg = kit.Split(arg[0])
|
arg = kit.Split(arg[0])
|
||||||
}
|
}
|
||||||
@ -123,7 +102,7 @@ func init() {
|
|||||||
|
|
||||||
switch m.Option(CMD_TYPE) {
|
switch m.Option(CMD_TYPE) {
|
||||||
case DAEMON:
|
case DAEMON:
|
||||||
_daemon_show(m, cmd, m.Option(CMD_STDOUT), m.Option(CMD_STDERR))
|
_daemon_show(m, cmd, m.Option(CMD_OUTPUT), m.Option(CMD_ERRPUT))
|
||||||
default:
|
default:
|
||||||
_system_show(m, cmd)
|
_system_show(m, cmd)
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ func _command_search(m *ice.Message, kind, name, text string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m.PushSearch(kit.SSH_CMD, COMMAND, CONTEXT, s.Cap(ice.CTX_FOLLOW), COMMAND, key,
|
m.PushSearch(kit.SSH_CMD, COMMAND, CONTEXT, m.Prefix(), COMMAND, key,
|
||||||
kit.MDB_TYPE, kind, kit.MDB_NAME, key, kit.MDB_TEXT, s.Cap(ice.CTX_FOLLOW),
|
kit.MDB_TYPE, kind, kit.MDB_NAME, key, kit.MDB_TEXT, m.Prefix(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Log struct {
|
type Log struct {
|
||||||
@ -35,19 +35,19 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
file := kit.Select("bench", m.Conf("show", kit.Keys(l.l, "file")))
|
file := kit.Select(BENCH, m.Conf(SHOW, kit.Keys(l.l, FILE)))
|
||||||
view := m.Confm("view", m.Conf("show", kit.Keys(l.l, "view")))
|
view := m.Confm(VIEW, m.Conf(SHOW, kit.Keys(l.l, VIEW)))
|
||||||
bio := m.Confv("file", file+".file").(*bufio.Writer)
|
bio := m.Confv(FILE, kit.Keys(file, FILE)).(*bufio.Writer)
|
||||||
|
|
||||||
bio.WriteString(l.p)
|
bio.WriteString(l.p)
|
||||||
bio.WriteString(" ")
|
bio.WriteString(" ")
|
||||||
if p, ok := view["prefix"].(string); ok {
|
if p, ok := view[PREFIX].(string); ok {
|
||||||
bio.WriteString(p)
|
bio.WriteString(p)
|
||||||
}
|
}
|
||||||
bio.WriteString(l.l)
|
bio.WriteString(l.l)
|
||||||
bio.WriteString(" ")
|
bio.WriteString(" ")
|
||||||
bio.WriteString(l.s)
|
bio.WriteString(l.s)
|
||||||
if p, ok := view["suffix"].(string); ok {
|
if p, ok := view[SUFFIX].(string); ok {
|
||||||
bio.WriteString(p)
|
bio.WriteString(p)
|
||||||
}
|
}
|
||||||
bio.WriteString("\n")
|
bio.WriteString("\n")
|
||||||
@ -60,50 +60,71 @@ func (f *Frame) Close(m *ice.Message, arg ...string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
PREFIX = "prefix"
|
||||||
|
SUFFIX = "suffix"
|
||||||
|
)
|
||||||
|
const (
|
||||||
|
GREEN = "green"
|
||||||
|
YELLOW = "yellow"
|
||||||
|
RED = "red"
|
||||||
|
)
|
||||||
|
const (
|
||||||
|
WATCH = "watch"
|
||||||
|
BENCH = "bench"
|
||||||
|
ERROR = "error"
|
||||||
|
TRACE = "trace"
|
||||||
|
)
|
||||||
|
const (
|
||||||
|
FILE = "file"
|
||||||
|
VIEW = "view"
|
||||||
|
SHOW = "show"
|
||||||
|
)
|
||||||
|
|
||||||
var Index = &ice.Context{Name: "log", Help: "日志模块",
|
var Index = &ice.Context{Name: "log", Help: "日志模块",
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
"file": {Name: "file", Help: "日志文件", Value: kit.Dict(
|
FILE: {Name: FILE, Help: "日志文件", Value: kit.Dict(
|
||||||
"watch", kit.Dict("path", "var/log/watch.log", "list", []string{
|
WATCH, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "watch.log"), kit.MDB_LIST, []string{
|
||||||
ice.LOG_CREATE, ice.LOG_REMOVE,
|
ice.LOG_CREATE, ice.LOG_REMOVE,
|
||||||
ice.LOG_INSERT, ice.LOG_DELETE,
|
ice.LOG_INSERT, ice.LOG_DELETE,
|
||||||
ice.LOG_SELECT, ice.LOG_MODIFY,
|
ice.LOG_SELECT, ice.LOG_MODIFY,
|
||||||
ice.LOG_EXPORT, ice.LOG_IMPORT,
|
ice.LOG_EXPORT, ice.LOG_IMPORT,
|
||||||
}),
|
}),
|
||||||
"bench", kit.Dict("path", "var/log/bench.log", "list", []string{}),
|
BENCH, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "bench.log"), kit.MDB_LIST, []string{}),
|
||||||
"error", kit.Dict("path", "var/log/error.log", "list", []string{
|
ERROR, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "error.log"), kit.MDB_LIST, []string{
|
||||||
ice.LOG_WARN, ice.LOG_ERROR,
|
ice.LOG_WARN, ice.LOG_ERROR,
|
||||||
}),
|
}),
|
||||||
"trace", kit.Dict("path", "var/log/trace.log", "list", []string{}),
|
TRACE, kit.Dict(kit.MDB_PATH, path.Join(ice.VAR_LOG, "trace.log"), kit.MDB_LIST, []string{}),
|
||||||
)},
|
)},
|
||||||
"view": {Name: "view", Help: "日志格式", Value: kit.Dict(
|
VIEW: {Name: VIEW, Help: "日志格式", Value: kit.Dict(
|
||||||
"green", kit.Dict("prefix", "\033[32m", "suffix", "\033[0m", "list", []string{
|
GREEN, kit.Dict(PREFIX, "\033[32m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||||
ice.LOG_START, ice.LOG_SERVE,
|
ice.LOG_START, ice.LOG_SERVE,
|
||||||
ice.LOG_CMDS,
|
ice.LOG_CMDS,
|
||||||
}),
|
}),
|
||||||
"yellow", kit.Dict("prefix", "\033[33m", "suffix", "\033[0m", "list", []string{
|
YELLOW, kit.Dict(PREFIX, "\033[33m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||||
ice.LOG_AUTH, ice.LOG_COST,
|
ice.LOG_AUTH, ice.LOG_COST,
|
||||||
}),
|
}),
|
||||||
"red", kit.Dict("prefix", "\033[31m", "suffix", "\033[0m", "list", []string{
|
RED, kit.Dict(PREFIX, "\033[31m", SUFFIX, "\033[0m", kit.MDB_LIST, []string{
|
||||||
ice.LOG_WARN, ice.LOG_CLOSE,
|
ice.LOG_WARN, ice.LOG_CLOSE,
|
||||||
}),
|
}),
|
||||||
)},
|
)},
|
||||||
"show": {Name: "show", Help: "日志分流", Value: kit.Dict()},
|
SHOW: {Name: SHOW, Help: "日志分流", Value: kit.Dict()},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Confm("view", nil, func(key string, value map[string]interface{}) {
|
m.Confm(VIEW, nil, func(key string, value map[string]interface{}) {
|
||||||
kit.Fetch(value["list"], func(index int, k string) {
|
kit.Fetch(value[kit.MDB_LIST], func(index int, k string) {
|
||||||
m.Conf("show", kit.Keys(k, "view"), key)
|
m.Conf(SHOW, kit.Keys(k, VIEW), key)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
m.Confm("file", nil, func(key string, value map[string]interface{}) {
|
m.Confm(FILE, nil, func(key string, value map[string]interface{}) {
|
||||||
kit.Fetch(value["list"], func(index int, k string) {
|
kit.Fetch(value[kit.MDB_LIST], func(index int, k string) {
|
||||||
m.Conf("show", kit.Keys(k, "file"), key)
|
m.Conf(SHOW, kit.Keys(k, FILE), key)
|
||||||
})
|
})
|
||||||
// 日志文件
|
// 日志文件
|
||||||
if f, p, e := kit.Create(kit.Format(value["path"])); m.Assert(e) {
|
if f, p, e := kit.Create(kit.Format(value[kit.MDB_PATH])); m.Assert(e) {
|
||||||
m.Cap(ice.CTX_STREAM, path.Base(p))
|
m.Cap(ice.CTX_STREAM, path.Base(p))
|
||||||
value["file"] = bufio.NewWriter(f)
|
value[FILE] = bufio.NewWriter(f)
|
||||||
m.Log_CREATE(kit.MDB_FILE, p)
|
m.Log_CREATE(kit.MDB_FILE, p)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package nfs
|
package nfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
"github.com/shylinux/icebergs/base/aaa"
|
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/aaa"
|
||||||
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _cat_ext(name string) string {
|
func _cat_ext(name string) string {
|
||||||
|
@ -155,8 +155,8 @@ func Dir(m *ice.Message, sort string) {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
TYPE_ALL = "all"
|
TYPE_ALL = "all"
|
||||||
TYPE_DIR = "dir"
|
|
||||||
TYPE_CAT = "cat"
|
TYPE_CAT = "cat"
|
||||||
|
TYPE_DIR = "dir"
|
||||||
TYPE_BOTH = "both"
|
TYPE_BOTH = "both"
|
||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
@ -185,9 +185,9 @@ func init() {
|
|||||||
mdb.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
mdb.UPLOAD: {Name: "upload", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||||
up := kit.Simple(m.Optionv(ice.MSG_UPLOAD))
|
up := kit.Simple(m.Optionv(ice.MSG_UPLOAD))
|
||||||
if p := path.Join(m.Option(kit.MDB_PATH), up[1]); m.Option(ice.MSG_USERPOD) == "" {
|
if p := path.Join(m.Option(kit.MDB_PATH), up[1]); m.Option(ice.MSG_USERPOD) == "" {
|
||||||
m.Cmdy("cache", "watch", up[0], p)
|
m.Cmdy("web.cache", "watch", up[0], p)
|
||||||
} else {
|
} else {
|
||||||
m.Cmdy("spide", "dev", "save", p, "GET", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+up[0]))
|
m.Cmdy("web.spide", "dev", "save", p, "GET", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/cache/"+up[0]))
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package nfs
|
package nfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _save_file(m *ice.Message, name string, text ...string) {
|
func _save_file(m *ice.Message, name string, text ...string) {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package nfs
|
package nfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/cli"
|
"github.com/shylinux/icebergs/base/cli"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"bufio"
|
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func _tail_create(m *ice.Message, arg ...string) {
|
func _tail_create(m *ice.Message, arg ...string) {
|
||||||
@ -26,8 +26,8 @@ func _tail_create(m *ice.Message, arg ...string) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
m.Option(cli.CMD_STDOUT, w)
|
m.Option(cli.CMD_OUTPUT, w)
|
||||||
m.Option(cli.CMD_STDERR, w)
|
m.Option(cli.CMD_ERRPUT, w)
|
||||||
m.Option(mdb.CACHE_CLEAR_ON_EXIT, "true")
|
m.Option(mdb.CACHE_CLEAR_ON_EXIT, "true")
|
||||||
m.Cmd(cli.DAEMON, TAIL, "-n", "0", "-f", file)
|
m.Cmd(cli.DAEMON, TAIL, "-n", "0", "-f", file)
|
||||||
})
|
})
|
||||||
@ -38,23 +38,41 @@ const TAIL = "tail"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
TAIL: {Name: TAIL, Help: "跟踪", Value: kit.Data()},
|
TAIL: {Name: TAIL, Help: "日志流", Value: kit.Data()},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
TAIL: {Name: "tail hash id auto create", Help: "跟踪", Action: map[string]*ice.Action{
|
TAIL: {Name: "tail hash id limit offend auto prev next create", Help: "日志流", Action: map[string]*ice.Action{
|
||||||
mdb.CREATE: {Name: "create file name", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
mdb.CREATE: {Name: "create file name", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||||
_tail_create(m, arg...)
|
_tail_create(m, arg...)
|
||||||
}},
|
}},
|
||||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(mdb.DELETE, TAIL, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
m.Cmdy(mdb.DELETE, TAIL, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||||
}},
|
}},
|
||||||
|
"prev": {Name: "prev", Help: "上一页", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
offend := kit.Int(kit.Select("0", arg, 3)) + kit.Int(kit.Select("10", arg, 2))
|
||||||
|
total := kit.Int(m.Conf(TAIL, kit.Keys(kit.MDB_HASH, arg[0], kit.MDB_META, kit.MDB_COUNT)))
|
||||||
|
if offend >= total {
|
||||||
|
offend = total - kit.Int(kit.Select("10", arg, 2))
|
||||||
|
m.Toast("已经是最后一页啦!")
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Process("_rewrite", "offend", offend)
|
||||||
|
}},
|
||||||
|
"next": {Name: "next", Help: "下一页", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
offend := kit.Int(kit.Select("0", arg, 3)) - kit.Int(kit.Select("10", arg, 2))
|
||||||
|
if offend < 0 {
|
||||||
|
offend = 0
|
||||||
|
m.Toast("已经是第一页啦!")
|
||||||
|
}
|
||||||
|
m.Process("_rewrite", "offend", offend)
|
||||||
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Option(mdb.FIELDS, kit.Select("time,hash,count,name,file", kit.Select("time,id,file,text", mdb.DETAIL, len(arg) > 1), len(arg) > 0))
|
m.Option(mdb.FIELDS, kit.Select("time,hash,count,name,file", kit.Select("time,id,file,text", mdb.DETAIL, len(arg) > 1 && arg[1] != ""), len(arg) > 0))
|
||||||
|
m.Option("cache.limit", kit.Select("10", arg, 2))
|
||||||
|
m.Option("cache.offend", kit.Select("0", arg, 3))
|
||||||
|
|
||||||
if m.Cmdy(mdb.SELECT, TAIL, "", mdb.ZONE, arg); len(arg) == 0 {
|
if m.Cmdy(mdb.SELECT, TAIL, "", mdb.ZONE, arg); len(arg) == 0 {
|
||||||
m.PushAction(mdb.REMOVE)
|
m.PushAction(mdb.REMOVE)
|
||||||
} else if len(arg) == 1 {
|
|
||||||
m.Option(ice.MSG_CONTROL, ice.CONTROL_PAGE)
|
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package nfs
|
package nfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/cli"
|
"github.com/shylinux/icebergs/base/cli"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func _trash_create(m *ice.Message, name string) {
|
func _trash_create(m *ice.Message, name string) {
|
||||||
@ -25,7 +25,7 @@ func _trash_create(m *ice.Message, name string) {
|
|||||||
p := path.Join(m.Conf(TRASH, kit.META_PATH), h[:2], h)
|
p := path.Join(m.Conf(TRASH, kit.META_PATH), h[:2], h)
|
||||||
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
os.MkdirAll(path.Dir(p), ice.MOD_DIR)
|
||||||
os.Rename(name, p)
|
os.Rename(name, p)
|
||||||
m.Cmdy(mdb.INSERT, TRASH, "", mdb.LIST, kit.MDB_FILE, p, kit.MDB_FROM, name)
|
m.Cmdy(mdb.INSERT, TRASH, "", mdb.HASH, kit.MDB_FILE, p, kit.MDB_FROM, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,17 +35,20 @@ const TRASH = "trash"
|
|||||||
func init() {
|
func init() {
|
||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
TRASH: {Name: TRASH, Help: "删除", Value: kit.Data(kit.MDB_PATH, "var/trash")},
|
TRASH: {Name: TRASH, Help: "回收站", Value: kit.Data(
|
||||||
|
kit.MDB_SHORT, kit.MDB_FROM, kit.MDB_PATH, ice.VAR_TRASH,
|
||||||
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
TRASH: {Name: "trash file auto", Help: "删除", Action: map[string]*ice.Action{
|
TRASH: {Name: "trash file auto", Help: "回收站", Action: map[string]*ice.Action{
|
||||||
"recover": {Name: "recover", Help: "恢复", Hand: func(m *ice.Message, arg ...string) {
|
"recover": {Name: "recover", Help: "恢复", Hand: func(m *ice.Message, arg ...string) {
|
||||||
os.Rename(m.Option(kit.MDB_FILE), m.Option(kit.MDB_FROM))
|
os.Rename(m.Option(kit.MDB_FILE), m.Option(kit.MDB_FROM))
|
||||||
|
m.Cmd(mdb.DELETE, TRASH, "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Option(mdb.FIELDS, "time,id,file,from")
|
m.Option(mdb.FIELDS, "time,hash,file,from")
|
||||||
m.Cmdy(mdb.SELECT, TRASH, "", mdb.LIST)
|
m.Cmdy(mdb.SELECT, TRASH, "", mdb.HASH)
|
||||||
m.PushAction("recover")
|
m.PushAction("recover")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
package ssh
|
package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/aaa"
|
"github.com/shylinux/icebergs/base/aaa"
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
"github.com/shylinux/icebergs/base/tcp"
|
"github.com/shylinux/icebergs/base/tcp"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Winsize struct{ Height, Width, x, y uint16 }
|
type Winsize struct{ Height, Width, x, y uint16 }
|
||||||
|
@ -1,16 +1,6 @@
|
|||||||
package ssh
|
package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
"github.com/shylinux/icebergs/base/aaa"
|
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
|
||||||
"github.com/shylinux/icebergs/base/nfs"
|
|
||||||
"github.com/shylinux/icebergs/base/tcp"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh"
|
|
||||||
"golang.org/x/crypto/ssh/terminal"
|
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -19,6 +9,15 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/aaa"
|
||||||
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
|
"github.com/shylinux/icebergs/base/nfs"
|
||||||
|
"github.com/shylinux/icebergs/base/tcp"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _ssh_tick(m *ice.Message, pw io.Writer) {
|
func _ssh_tick(m *ice.Message, pw io.Writer) {
|
||||||
|
@ -1,14 +1,6 @@
|
|||||||
package ssh
|
package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
"github.com/shylinux/icebergs/base/aaa"
|
|
||||||
"github.com/shylinux/icebergs/base/mdb"
|
|
||||||
"github.com/shylinux/icebergs/base/nfs"
|
|
||||||
"github.com/shylinux/icebergs/base/tcp"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
"golang.org/x/crypto/ssh"
|
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
@ -17,6 +9,14 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/aaa"
|
||||||
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
|
"github.com/shylinux/icebergs/base/nfs"
|
||||||
|
"github.com/shylinux/icebergs/base/tcp"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func _ssh_meta(conn ssh.ConnMetadata) map[string]string {
|
func _ssh_meta(conn ssh.ConnMetadata) map[string]string {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package ssh
|
package ssh
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
@ -8,10 +10,6 @@ import (
|
|||||||
"github.com/shylinux/icebergs/base/mdb"
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
"github.com/shylinux/icebergs/base/tcp"
|
"github.com/shylinux/icebergs/base/tcp"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func _ssh_sess(m *ice.Message, h string, client *ssh.Client) (*ssh.Session, error) {
|
func _ssh_sess(m *ice.Message, h string, client *ssh.Client) (*ssh.Session, error) {
|
||||||
@ -87,8 +85,7 @@ func init() {
|
|||||||
m.Debug("%v %v", n, e)
|
m.Debug("%v %v", n, e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
m.Sleep("300ms")
|
m.ProcessRefresh("300ms")
|
||||||
m.Cmdy(SESSION, m.Option(kit.MDB_HASH))
|
|
||||||
}},
|
}},
|
||||||
"bind": {Name: "bind", Help: "绑定", Hand: func(m *ice.Message, arg ...string) {
|
"bind": {Name: "bind", Help: "绑定", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Richs(SESSION, "", m.Option(kit.MDB_HASH), func(key string, value map[string]interface{}) {
|
m.Richs(SESSION, "", m.Option(kit.MDB_HASH), func(key string, value map[string]interface{}) {
|
||||||
|
@ -13,14 +13,16 @@ var Index = &ice.Context{Name: SSH, Help: "终端模块", Commands: map[string]*
|
|||||||
m.Load()
|
m.Load()
|
||||||
m.Conf(SOURCE, kit.Keys(kit.MDB_HASH, STDIO, kit.MDB_META, kit.MDB_NAME), STDIO)
|
m.Conf(SOURCE, kit.Keys(kit.MDB_HASH, STDIO, kit.MDB_META, kit.MDB_NAME), STDIO)
|
||||||
m.Conf(SOURCE, kit.Keys(kit.MDB_HASH, STDIO, kit.MDB_META, kit.MDB_TIME), m.Time())
|
m.Conf(SOURCE, kit.Keys(kit.MDB_HASH, STDIO, kit.MDB_META, kit.MDB_TIME), m.Time())
|
||||||
|
|
||||||
|
m.Richs(SERVICE, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||||
|
value = kit.GetMeta(value)
|
||||||
|
m.Cmd(SERVICE, tcp.LISTEN, tcp.PORT, value[tcp.PORT], value)
|
||||||
|
})
|
||||||
}},
|
}},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
if _, ok := m.Target().Server().(*Frame); ok {
|
if _, ok := m.Target().Server().(*Frame); ok {
|
||||||
m.Done(true)
|
m.Done(true)
|
||||||
}
|
}
|
||||||
m.Richs(SERVICE, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
|
||||||
kit.Value(value, "meta.status", tcp.CLOSE)
|
|
||||||
})
|
|
||||||
m.Richs(CHANNEL, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
m.Richs(CHANNEL, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||||
kit.Value(value, "meta.status", tcp.CLOSE)
|
kit.Value(value, "meta.status", tcp.CLOSE)
|
||||||
})
|
})
|
||||||
|
@ -5,9 +5,10 @@ refer `
|
|||||||
源码 https://github.com/openssh/openssh-portable
|
源码 https://github.com/openssh/openssh-portable
|
||||||
`
|
`
|
||||||
|
|
||||||
field "脚本" ssh.source
|
|
||||||
|
|
||||||
field "服务" ssh.service
|
field "服务" ssh.service
|
||||||
field "通道" ssh.channel
|
field "通道" ssh.channel
|
||||||
|
|
||||||
field "连接" ssh.connect
|
field "连接" ssh.connect
|
||||||
field "会话" ssh.session
|
field "会话" ssh.session
|
||||||
|
field "脚本" ssh.source
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ func _dream_show(m *ice.Message, name string) {
|
|||||||
// 启动任务
|
// 启动任务
|
||||||
kit.Path(os.Args[0])
|
kit.Path(os.Args[0])
|
||||||
|
|
||||||
m.Optionv(cli.CMD_STDERR, path.Join(p, m.Conf(DREAM, kit.Keym(kit.SSH_ENV, "ctx_log"))))
|
m.Optionv(cli.CMD_ERRPUT, path.Join(p, m.Conf(DREAM, kit.Keym(kit.SSH_ENV, "ctx_log"))))
|
||||||
m.Cmd(cli.DAEMON, m.Confv(DREAM, kit.Keym(kit.SSH_CMD)), SPIDE_DEV, SPIDE_DEV, kit.MDB_NAME, name)
|
m.Cmd(cli.DAEMON, m.Confv(DREAM, kit.Keym(kit.SSH_CMD)), SPIDE_DEV, SPIDE_DEV, kit.MDB_NAME, name)
|
||||||
m.Event(DREAM_CREATE, kit.MDB_TYPE, m.Option(kit.MDB_TYPE), kit.MDB_NAME, name)
|
m.Event(DREAM_CREATE, kit.MDB_TYPE, m.Option(kit.MDB_TYPE), kit.MDB_NAME, name)
|
||||||
m.Sleep(ice.MOD_TICK)
|
m.Sleep(ice.MOD_TICK)
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/aaa"
|
"github.com/shylinux/icebergs/base/aaa"
|
||||||
"github.com/shylinux/icebergs/base/cli"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,12 +45,6 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
|||||||
http.ServeFile(msg.W, msg.R, kit.Path(arg[0]))
|
http.ServeFile(msg.W, msg.R, kit.Path(arg[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
case ice.RENDER_QRCODE: // text [size]
|
|
||||||
if data, ok := msg.Cmd(cli.QRCODE, arg).Optionv("byte").([]byte); ok {
|
|
||||||
msg.W.Header().Set(ContentType, ContentPNG)
|
|
||||||
msg.W.Write(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
case ice.RENDER_RESULT:
|
case ice.RENDER_RESULT:
|
||||||
if len(arg) > 0 { // [str [arg...]]
|
if len(arg) > 0 { // [str [arg...]]
|
||||||
msg.W.Write([]byte(kit.Format(arg[0], args[1:]...)))
|
msg.W.Write([]byte(kit.Format(arg[0], args[1:]...)))
|
||||||
|
@ -158,20 +158,10 @@ func init() {
|
|||||||
|
|
||||||
switch msg.Append(kit.MDB_TYPE) {
|
switch msg.Append(kit.MDB_TYPE) {
|
||||||
case LOGIN, RIVER:
|
case LOGIN, RIVER:
|
||||||
switch kit.Select("", arg, 1) {
|
m.Render(REDIRECT, "/", list)
|
||||||
case SHARE:
|
|
||||||
m.Render(ice.RENDER_QRCODE, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/", list))
|
|
||||||
default:
|
|
||||||
m.Render(REDIRECT, "/", list)
|
|
||||||
}
|
|
||||||
|
|
||||||
case STORM:
|
case STORM:
|
||||||
switch kit.Select("", arg, 1) {
|
m.Render(REDIRECT, "/page/share.html", SHARE, m.Option(SHARE))
|
||||||
case SHARE:
|
|
||||||
m.Render(ice.RENDER_QRCODE, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/page/share.html", list))
|
|
||||||
default:
|
|
||||||
m.Render(REDIRECT, "/page/share.html", SHARE, m.Option(SHARE))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
3
conf.go
3
conf.go
@ -22,6 +22,7 @@ const ( // REPOS
|
|||||||
|
|
||||||
SUCCESS = "success"
|
SUCCESS = "success"
|
||||||
FAILURE = "failure"
|
FAILURE = "failure"
|
||||||
|
TRUE = "true"
|
||||||
)
|
)
|
||||||
const ( // DIR
|
const ( // DIR
|
||||||
USR_VOLCANOS = "usr/volcanos"
|
USR_VOLCANOS = "usr/volcanos"
|
||||||
@ -33,7 +34,9 @@ const ( // DIR
|
|||||||
PROTO_JS = "proto.js"
|
PROTO_JS = "proto.js"
|
||||||
FRAME_JS = "frame.js"
|
FRAME_JS = "frame.js"
|
||||||
|
|
||||||
|
VAR_LOG = "var/log"
|
||||||
VAR_CONF = "var/conf"
|
VAR_CONF = "var/conf"
|
||||||
|
VAR_TRASH = "var/trash"
|
||||||
ETC_MISS = "etc/miss.sh"
|
ETC_MISS = "etc/miss.sh"
|
||||||
ETC_INIT = "etc/init.shy"
|
ETC_INIT = "etc/init.shy"
|
||||||
ETC_EXIT = "etc/exit.shy"
|
ETC_EXIT = "etc/exit.shy"
|
||||||
|
@ -102,10 +102,10 @@ func init() {
|
|||||||
|
|
||||||
"test": {Name: "test path func auto run case", Help: "测试用例", Action: map[string]*ice.Action{
|
"test": {Name: "test path func auto run case", Help: "测试用例", Action: map[string]*ice.Action{
|
||||||
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||||
cli.Follow(m, "run", func() {
|
// cli.Follow(m, "run", func() {
|
||||||
m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/")))
|
m.Option(cli.CMD_DIR, kit.Select(path.Dir(arg[0]), arg[0], strings.HasSuffix(arg[0], "/")))
|
||||||
m.Cmdy(cli.SYSTEM, "go", "test", "./", "-v", "-run="+arg[1])
|
m.Cmdy(cli.SYSTEM, "go", "test", "./", "-v", "-run="+arg[1])
|
||||||
})
|
// })
|
||||||
}},
|
}},
|
||||||
"case": {Name: "case", Help: "用例", Hand: func(m *ice.Message, arg ...string) {
|
"case": {Name: "case", Help: "用例", Hand: func(m *ice.Message, arg ...string) {
|
||||||
msg := m.Spawn()
|
msg := m.Spawn()
|
||||||
|
@ -47,3 +47,11 @@ code.go
|
|||||||
code.shy
|
code.shy
|
||||||
csdn.go
|
csdn.go
|
||||||
github.go
|
github.go
|
||||||
|
|
||||||
|
section "python"
|
||||||
|
refer `
|
||||||
|
官网 https://www.python.org/
|
||||||
|
源码 https://www.python.org/downloads/source/
|
||||||
|
文档 https://docs.python.org/3/reference/index.html
|
||||||
|
`
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package cli
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ice "github.com/shylinux/icebergs"
|
|
||||||
kit "github.com/shylinux/toolkits"
|
|
||||||
|
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
ice "github.com/shylinux/icebergs"
|
||||||
|
"github.com/shylinux/icebergs/base/cli"
|
||||||
|
kit "github.com/shylinux/toolkits"
|
||||||
)
|
)
|
||||||
|
|
||||||
const PYTHON = "python"
|
const PYTHON = "python"
|
||||||
@ -13,8 +14,7 @@ func init() {
|
|||||||
Index.Merge(&ice.Context{
|
Index.Merge(&ice.Context{
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
PYTHON: {Name: "python", Help: "脚本命令", Value: kit.Data(
|
PYTHON: {Name: "python", Help: "脚本命令", Value: kit.Data(
|
||||||
"python", "python",
|
PYTHON, "python", cli.SOURCE, "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
|
||||||
"source", "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
|
|
||||||
)},
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
@ -30,10 +30,10 @@ func init() {
|
|||||||
}},
|
}},
|
||||||
|
|
||||||
"pip": {Name: "pip", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
"pip": {Name: "pip", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(SYSTEM, m.Conf(PYTHON, "meta.pip"), "install", arg)
|
m.Cmdy(cli.SYSTEM, m.Conf(PYTHON, "meta.pip"), "install", arg)
|
||||||
}},
|
}},
|
||||||
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmdy(SYSTEM, m.Conf(PYTHON, "meta.python"), arg)
|
m.Cmdy(cli.SYSTEM, m.Conf(PYTHON, "meta.python"), arg)
|
||||||
}},
|
}},
|
||||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Cmdy("web.code.install", path.Base(m.Conf(PYTHON, kit.META_SOURCE)), arg)
|
m.Cmdy("web.code.install", path.Base(m.Conf(PYTHON, kit.META_SOURCE)), arg)
|
Loading…
x
Reference in New Issue
Block a user