diff --git a/base/ssh/ssh.go b/base/ssh/ssh.go index 52ff483a..f2173f86 100644 --- a/base/ssh/ssh.go +++ b/base/ssh/ssh.go @@ -216,6 +216,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool { if m.Option(ice.MSG_PROMPT, m.Confv("prompt", "meta.PS1")); f.out == os.Stdout { f.printf(m, "\033[0m") } + m.Cmd(ice.WEB_FAVOR, "cmd.history", "cmd", kit.Select("stdio", arg, 0), line) // 解析命令 f.parse(m, line) diff --git a/base/web/web.go b/base/web/web.go index 6da017df..11f2f223 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -682,13 +682,14 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", var data map[string][]string m.Assert(json.NewDecoder(res.Body).Decode(&data)) m.Info("res: %s", kit.Formats(data)) - if len(data["append"]) > 0 { - for i := range data[data["append"][0]] { - for _, k := range data["append"] { + if len(data[ice.MSG_APPEND]) > 0 { + for i := range data[data[ice.MSG_APPEND][0]] { + for _, k := range data[ice.MSG_APPEND] { m.Push(k, data[k][i]) } } } + m.Resultv(data[ice.MSG_RESULT]) case "raw": if b, e := ioutil.ReadAll(res.Body); m.Assert(e) { @@ -790,31 +791,32 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", name := m.Conf(ice.CLI_RUNTIME, "node.name") user := m.Conf(ice.CLI_RUNTIME, "boot.username") - m.Hold(1).Gos(m, func(m *ice.Message) { - m.Richs(ice.WEB_SPIDE, nil, dev, func(key string, value map[string]interface{}) { + m.Hold(1).Gos(m, func(msg *ice.Message) { + msg.Richs(ice.WEB_SPIDE, nil, dev, func(key string, value map[string]interface{}) { proto := kit.Select("ws", "wss", kit.Format(kit.Value(value, "client.protocol")) == "https") host := kit.Format(kit.Value(value, "client.hostname")) - for i := 0; i < m.Confi(ice.WEB_SPACE, "meta.redial.c"); i++ { - if u, e := url.Parse(kit.MergeURL(proto+"://"+host+"/space/", "node", node, "name", name, "user", user, "share", value["share"])); m.Assert(e) { - if s, e := net.Dial("tcp", host); !m.Warn(e != nil, "%s", e) { - if s, _, e := websocket.NewClient(s, u, nil, m.Confi(ice.WEB_SPACE, "meta.buffer.r"), m.Confi(ice.WEB_SPACE, "meta.buffer.w")); !m.Warn(e != nil, "%s", e) { + for i := 0; i < msg.Confi(ice.WEB_SPACE, "meta.redial.c"); i++ { + if u, e := url.Parse(kit.MergeURL(proto+"://"+host+"/space/", "node", node, "name", name, "user", user, "share", value["share"])); msg.Assert(e) { + if s, e := net.Dial("tcp", host); !msg.Warn(e != nil, "%s", e) { + if s, _, e := websocket.NewClient(s, u, nil, msg.Confi(ice.WEB_SPACE, "meta.buffer.r"), msg.Confi(ice.WEB_SPACE, "meta.buffer.w")); !msg.Warn(e != nil, "%s", e) { + msg = m.Spawn() // 连接成功 - m.Rich(ice.WEB_SPACE, nil, kit.Dict( + msg.Rich(ice.WEB_SPACE, nil, kit.Dict( kit.MDB_TYPE, ice.WEB_MASTER, kit.MDB_NAME, dev, "user", kit.Value(value, "client.hostname"), "socket", s, )) - m.Log(ice.LOG_CMDS, "%d conn %s success %s", i, dev, u) - if i = 0; web.HandleWSS(m, true, s, dev) { + msg.Log(ice.LOG_CMDS, "%d conn %s success %s", i, dev, u) + if i = 0; web.HandleWSS(msg, true, s, dev) { break } } } // 断线重连 - sleep := time.Duration(rand.Intn(m.Confi(ice.WEB_SPACE, "meta.redial.a"))*i+i*m.Confi(ice.WEB_SPACE, "meta.redial.b")) * time.Millisecond - m.Info("%d sleep: %s reconnect: %s", i, sleep, u) + sleep := time.Duration(rand.Intn(msg.Confi(ice.WEB_SPACE, "meta.redial.a"))*i+i*msg.Confi(ice.WEB_SPACE, "meta.redial.b")) * time.Millisecond + msg.Info("%d sleep: %s reconnect: %s", i, sleep, u) time.Sleep(sleep) } } @@ -1053,6 +1055,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", kit.MDB_TYPE, arg[1], kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3], "extra", kit.Dict(arg[4:]), )) + m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, value map[string]interface{}) { + kit.Value(value, "meta.time", m.Time()) + }) m.Log(ice.LOG_INSERT, "favor: %s index: %d name: %s text: %s", favor, index, arg[2], arg[3]) m.Echo("%d", index) }}, @@ -1531,7 +1536,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", // 共享列表 m.Grows(ice.WEB_SHARE, nil, "", "", func(key int, value map[string]interface{}) { m.Push(kit.Format(key), value, []string{kit.MDB_TIME, "share", kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT}) - m.Push("link", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.share"), value["share"], value["share"])) + m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.link"), value["share"], value["share"])) }) return } diff --git a/conf.go b/conf.go index b8c08584..ba482c4e 100644 --- a/conf.go +++ b/conf.go @@ -166,6 +166,7 @@ const ( // CHAT CHAT_RIVER = "river" ) const ( // TYPE + TYPE_SPIDE = "spide" TYPE_SPACE = "space" TYPE_STORY = "story" diff --git a/core/chat/chat.go b/core/chat/chat.go index 71845be7..61ca6b8c 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -5,6 +5,8 @@ import ( _ "github.com/shylinux/icebergs/base" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/toolkits" + + "strings" ) var Index = &ice.Context{Name: "chat", Help: "聊天中心", @@ -484,6 +486,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", return } + m.Cmd(ice.WEB_FAVOR, "cmd.history", "cmd", m.Option(ice.MSG_SESSID)[:6], strings.Join(cmds, " ")) // 执行命令 m.Cmdy(cmds).Option("cmds", cmds) }}, diff --git a/core/code/code.go b/core/code/code.go index fb14e751..93c06284 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -99,7 +99,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", case "prune": list := []string{} m.Richs("login", nil, "*", func(key string, value map[string]interface{}) { - if value["status"] == "logout" { + if len(arg) > 1 && arg[1] == "all" || value["status"] == "logout" { list = append(list, key) } }) @@ -108,6 +108,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", m.Log(ice.LOG_DELETE, "%s: %s", value, m.Conf("login", kit.Keys("hash", value))) m.Conf("login", kit.Keys("hash", value), "") }) + m.Echo("%d", len(list)) case "exit": // 退出会话 diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index 13fefc97..81ec68a2 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -62,9 +62,9 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", "stack": {Name: "stack", Help: "结构", Value: kit.Data("template", stack)}, "chart": {Name: "chart", Help: "绘图", Value: kit.Data("template", prefix, "suffix", ``)}, - "draw": {Name: "draw", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "path", "usr/local", "regs", ".*\\.svg", "prefix", ``, "suffix", ``)}, - "data": {Name: "data", Help: "数据表格", Value: kit.Data(kit.MDB_SHORT, "name", "path", "usr/local", "regs", ".*\\.csv")}, - "word": {Name: "word", Help: "语言文字", Value: kit.Data(kit.MDB_SHORT, "name", "path", "usr/local", "regs", ".*\\.shy", + "draw": {Name: "draw", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.svg", "prefix", ``, "suffix", ``)}, + "data": {Name: "data", Help: "数据表格", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.csv")}, + "word": {Name: "word", Help: "语言文字", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.shy", "alias", map[string]interface{}{ "label": []interface{}{"chart", "label"}, "chain": []interface{}{"chart", "chain"}, @@ -75,8 +75,8 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", "premenu": []interface{}{"title", "premenu"}, }, )}, - "walk": {Name: "walk", Help: "走遍世界", Value: kit.Data(kit.MDB_SHORT, "name", "path", "usr/local", "regs", ".*\\.csv")}, - "feel": {Name: "feel", Help: "影音媒体", Value: kit.Data(kit.MDB_SHORT, "name", "path", "usr/local", "regs", ".*\\.(png|JPG|MOV|m4v)")}, + "walk": {Name: "walk", Help: "走遍世界", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.csv")}, + "feel": {Name: "feel", Help: "影音媒体", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.(png|JPG|MOV|m4v)")}, }, Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/misc/auth/auth.go b/misc/auth/auth.go deleted file mode 100644 index eeb49efc..00000000 --- a/misc/auth/auth.go +++ /dev/null @@ -1,108 +0,0 @@ -package auth - -import ( - "github.com/shylinux/icebergs" - "github.com/shylinux/icebergs/base/aaa" - "github.com/shylinux/toolkits" - - "bytes" - "crypto/hmac" - "crypto/sha1" - "encoding/base32" - "encoding/binary" - "strings" - "time" -) - -func gen() string { - buf := bytes.NewBuffer([]byte{}) - binary.Write(buf, binary.BigEndian, time.Now().Unix()/30) - b := hmac.New(sha1.New, buf.Bytes()).Sum(nil) - return strings.ToUpper(base32.StdEncoding.EncodeToString(b[:])) -} - -func get(key string) string { - buf := []byte{} - now := kit.Int64(time.Now().Unix() / 30) - for i := 0; i < 8; i++ { - buf = append(buf, byte((now >> ((7 - i) * 8)))) - } - - s, _ := base32.StdEncoding.DecodeString(strings.ToUpper(key)) - - hm := hmac.New(sha1.New, s) - hm.Write(buf) - b := hm.Sum(nil) - - o := b[len(b)-1] & 0x0F - p := b[o : o+4] - p[0] = p[0] & 0x7f - res := int64(p[0])<<24 + int64(p[1])<<16 + int64(p[2])<<8 + int64(p[3]) - return kit.Format("%06d", res%1000000) -} - -var Index = &ice.Context{Name: "auth", Help: "auth", - Caches: map[string]*ice.Cache{}, - Configs: map[string]*ice.Config{ - "auth": {Name: "auth", Help: "auth", Value: kit.Data(kit.MDB_SHORT, "name")}, - }, - Commands: map[string]*ice.Command{ - ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Load() - }}, - ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Save("auth") - }}, - - "new": {Name: "new user [secrete]", Help: "创建动态码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 0 { - m.Richs("auth", nil, "*", func(key string, value map[string]interface{}) { - m.Push(key, value, []string{"name", "username", "website"}) - }) - return - } - - m.Append("_output", "qrcode") - if len(arg) == 1 { - if m.Richs("auth", nil, arg[0], func(key string, value map[string]interface{}) { - m.Echo("otpauth://totp/%s?secret=%s", value["name"], value["secrete"]) - }) != nil { - return - } - arg = append(arg, gen()) - } - - data := kit.Dict("name", arg[0], "secrete", arg[1]) - for i := 2; i < len(arg)-1; i += 2 { - kit.Value(data, arg[i], arg[i+1]) - } - - n := m.Rich("auth", nil, data) - m.Log(ice.LOG_CREATE, "%s", n) - - m.Cmdy(ice.WEB_SHARE, "optauth", arg[0], kit.Format("otpauth://totp/%s?secret=%s", arg[0], arg[1])) - }}, - "get": {Name: "get user [secrete]", Help: "获取动态码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 0 { - m.Richs("auth", nil, "*", func(key string, value map[string]interface{}) { - m.Push("name", value["name"]) - m.Push("code", m.Cmdx("get", value["name"], value["secrete"])) - }) - return - } - - if len(arg) == 1 { - m.Richs("auth", nil, arg[0], func(key string, value map[string]interface{}) { - arg = append(arg, kit.Format(value["secrete"])) - }) - } - if len(arg) == 1 { - arg = append(arg, m.Cmdx("new", arg[0])) - } - - m.Echo(get(arg[1])) - }}, - }, -} - -func init() { aaa.Index.Register(Index, nil) } diff --git a/misc/auth/auth.js b/misc/auth/auth.js deleted file mode 100644 index 957bfb22..00000000 --- a/misc/auth/auth.js +++ /dev/null @@ -1,9 +0,0 @@ -Volcanos("onimport", {help: "导入数据", list: [], - "init": function(can, msg, cb, output, action, option) {}, -}) -Volcanos("onaction", {help: "控件菜单", list: []}) -Volcanos("onchoice", {help: "控件交互", list: ["刷新"] - "刷新": function(event, can, value, cmd, target) {}, -}) -Volcanos("ondetail", {help: "控件详情", list: []}) -Volcanos("onexport", {help: "导出数据", list: []}) diff --git a/misc/auth/auth.shy b/misc/auth/auth.shy deleted file mode 100644 index e9142d89..00000000 --- a/misc/auth/auth.shy +++ /dev/null @@ -1 +0,0 @@ -title "auth" diff --git a/misc/chrome/chrome.go b/misc/chrome/chrome.go index 459203e1..5b26c055 100644 --- a/misc/chrome/chrome.go +++ b/misc/chrome/chrome.go @@ -3,7 +3,7 @@ package crx import ( "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/web" - "github.com/shylinux/icebergs/core/chat" + "github.com/shylinux/icebergs/core/code" "github.com/shylinux/toolkits" ) @@ -13,12 +13,7 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器", "chrome": {Name: "chrome", Help: "chrome", Value: kit.Data(kit.MDB_SHORT, "name", "history", "url.history")}, }, Commands: map[string]*ice.Command{ - "/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - switch arg[0] { - case "history": - m.Cmdy(ice.WEB_FAVOR, m.Conf("chrome", "meta.history"), "spide", arg[3], arg[2]) - } - }}, + "chrome": {Name: "chrome", Help: "浏览器", List: kit.List( kit.MDB_INPUT, "text", "name", "name", "action", "auto", kit.MDB_INPUT, "text", "name", "wid", "action", "auto", @@ -81,7 +76,53 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器", // 下发命令 m.Cmdy(ice.WEB_SPACE, arg[0], "bookmark", arg[1:]) }}, + + ice.WEB_LOGIN: {Name: "_login", Help: "_login", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option("you", "") + m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) { + // 查找空间 + m.Option("you", value["you"]) + }) + + m.Info("%s %s cmd: %v sub: %v", m.Option("you"), m.Option(ice.MSG_USERURL), m.Optionv("cmds"), m.Optionv("sub")) + }}, + "/help": {Name: "/help", Help: "帮助", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmdy("help") + }}, + "/login": {Name: "/login", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmdy("login", "init", c.Name) + }}, + "/logout": {Name: "/logout", Help: "登出", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmdy("login", "exit") + }}, + + "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) > 0 { + // 添加收藏 + cmds := []string{ice.WEB_FAVOR, m.Option("tab"), ice.TYPE_SPIDE, m.Option("note"), arg[0]} + if m.Cmdy(cmds); m.Option("you") != "" { + m.Cmdy(ice.WEB_SPACE, m.Option("you"), cmds) + } + return + } + }}, + + "/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Info("what %v", m.Option("sid")) + switch arg[0] { + case "login": + m.Cmdy(ice.WEB_SPIDE, "dev", "msg", "/code/chrome/login", "sid", m.Option("sid")) + + case "bookmark": + m.Cmdy(ice.WEB_SPIDE, "dev", "/code/chrome/favor", "cmds", arg[2], "note", arg[3], + "tab", kit.Select(m.Conf("chrome", "meta.history"), arg, 4), "sid", m.Option("sid"), "type", "spide") + + case "history": + m.Cmdy(ice.WEB_SPIDE, "dev", "/code/chrome/favor", "cmds", arg[2], "note", arg[3], + "tab", m.Conf("chrome", "meta.history"), "sid", m.Option("sid")) + } + }}, }, } -func init() { chat.Index.Register(Index, &web.Frame{}) } +func init() { code.Index.Register(Index, &web.Frame{}) } diff --git a/misc/docker/docker.go b/misc/docker/docker.go index 21240797..f6514f63 100644 --- a/misc/docker/docker.go +++ b/misc/docker/docker.go @@ -25,9 +25,16 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机", }}, "auto": {Name: "auto", Help: "自动化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := []string{ice.CLI_SYSTEM, "docker"} + + if m.Cmd(prefix, "container", "start", arg[0]).Append("code") != "1" { + // 启动容器 + return + } + // 创建容器 - pid := m.Cmdx(prefix, "run", "-dt", "-w", "/root", "--name", arg[0], "--mount", kit.Format("type=bind,source=%s,target=/root", - kit.Path(m.Conf(ice.WEB_DREAM, "meta.path"), arg[0])), "alpine") + pid := m.Cmdx(prefix, "run", "-dt", "-w", "/root", "--name", arg[0], + // "--mount", kit.Format("type=bind,source=%s,target=/root", kit.Path(m.Conf(ice.WEB_DREAM, "meta.path"), arg[0])), + "alpine") m.Log(ice.LOG_CREATE, "%s: %s", arg[0], pid) m.Cmd(ice.WEB_FAVOR, kit.Select("alpine.auto", arg, 1)).Table(func(index int, value map[string]string, head []string) { diff --git a/misc/tmux/tmux.go b/misc/tmux/tmux.go index df4a2f4a..bc0f7e52 100644 --- a/misc/tmux/tmux.go +++ b/misc/tmux/tmux.go @@ -33,8 +33,8 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", "format", "#{pane_id},#{pane_active},#{pane_index},#{pane_tty},#{pane_height},#{pane_width}", "fields", "id,tag,pane,tty,height,width", )}, - "relay": {Name: "relay", Help: "跳板", Value: kit.Data( - "tail", kit.Dict( + "relay": {Name: "relay", Help: "跳板", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME, + "count", 100, "sleep", "100ms", "tail", kit.Dict( "verify", "Verification code:", "password", "Password:", "login", "[relay ~]$", @@ -48,10 +48,10 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", if m.Richs(ice.WEB_FAVOR, nil, "tmux.auto", nil) == nil { m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "脚本", `curl $ctx_dev/publish/auto.sh > auto.sh`) m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "脚本", `source auto.sh`) - m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "脚本", `ShyLogin`) + m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "脚本", `ShyInit && ShyLogin && trap ShyLogout EXIT`) } - for _, v := range []string{"auto.sh", "auto.vim"} { + for _, v := range []string{"auto.sh", "auto.vim", "auto.tmux"} { p := path.Join(m.Conf("web.code.publish", "meta.path"), v) if _, e := os.Stat(p); e != nil && os.IsNotExist(e) { // 下载脚本 @@ -61,7 +61,7 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", } } }}, - "auto": {Name: "auto", Help: "自动化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "auto": {Name: "auto dream", Help: "自动化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := kit.Simple(m.Confv("prefix", "meta.cmd")) // 共享空间 @@ -79,9 +79,18 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", m.Cmd(prefix, "new-session", "-ds", arg[0]) } + if m.Option("local") != "" { + // 自动虚拟 + m.Cmd("local", m.Option("local"), arg[0]) + } if m.Option("relay") != "" { // 自动认证 - m.Cmd("relay", arg[0], m.Option("relay")) + m.Cmd("relay", m.Option("relay"), arg[0]) + } + + for _, v := range kit.Simple(m.Optionv("before")) { + // 前置命令 + m.Cmdy(prefix, "send-keys", "-t", arg[0], v, "Enter") } // 连接参数 @@ -93,9 +102,12 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", case "shell": // 发送命令 m.Cmdy(prefix, "send-keys", "-t", arg[0], value["text"], "Enter") + time.Sleep(10 * time.Millisecond) } }) + for _, v := range kit.Simple(m.Optionv("after")) { + // 后置命令 m.Cmdy(prefix, "send-keys", "-t", arg[0], v, "Enter") } }}, @@ -269,51 +281,70 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", m.Cmdy(prefix, "capture-pane", "-pt", kit.Select("", arg, 0)).Set("append") }}, - "relay": {Name: "relay", Help: "跳板", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "local": {Name: "local which target", Help: "虚拟机", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := kit.Simple(m.Confv("prefix", "meta.cmd")) + m.Cmdy(prefix, "send-keys", "-t", arg[1], "docker exec -it ", arg[1], " bash", "Enter") + }}, + "relay": {Name: "relay which target", Help: "跳板机", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + prefix := kit.Simple(m.Confv("prefix", "meta.cmd")) + if len(arg) == 0 { + // 认证列表 + m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) { + m.Push(key, value, []string{"name", "username", "website"}) + }) + return + } + if len(arg) == 1 { + // 认证详情 + m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) { + m.Push("detail", value) + }) + return + } + if len(arg) > 4 { + // 添加认证 + m.Rich(cmd, nil, kit.Dict( + kit.MDB_NAME, arg[0], kit.MDB_TEXT, arg[1], + "username", arg[2], "website", arg[3], "password", arg[4], + )) + return + } - m.Richs("aaa.auth.auth", nil, kit.Select("relay", arg, 1), func(key string, value map[string]interface{}) { - m.Cmdy(prefix, "send-keys", "-t", arg[0], kit.Format("ssh %s@%s", value["username"], value["website"]), "Enter") + m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) { + // 登录命令 + m.Cmdy(prefix, "send-keys", "-t", arg[1], kit.Format("ssh %s@%s", value["username"], value["website"]), "Enter") - for i := 0; i < 10; i++ { - time.Sleep(100 * time.Millisecond) - tail := m.Cmdx(prefix, "capture-pane", "-p") - if strings.HasSuffix(strings.TrimSpace(tail), m.Conf("relay", "meta.tail.login")) { - for _, v := range kit.Simple(value["init"]) { - if v != "" { - m.Cmdy(prefix, "send-keys", "-t", arg[0], v, "Enter") - } - } + sleep := kit.Duration(m.Conf(cmd, "meta.sleep")) + for i := 0; i < kit.Int(m.Conf(cmd, "meta.count")); i++ { + time.Sleep(sleep) + list := strings.Split(strings.TrimSpace(m.Cmdx(prefix, "capture-pane", "-p")), "\n") + + if tail := list[len(list)-1]; tail == m.Conf(cmd, "meta.tail.login") { + // 登录成功 break - } - - if strings.HasSuffix(strings.TrimSpace(tail), m.Conf("relay", "meta.tail.verify")) { - m.Cmdy(prefix, "send-keys", "-t", arg[0], m.Cmdx("aaa.auth.get", "relay"), "Enter") - continue - } - - if strings.HasSuffix(strings.TrimSpace(tail), m.Conf("relay", "meta.tail.password")) { - m.Cmdy(prefix, "send-keys", "-t", arg[0], value["password"], "Enter") - continue + } else if tail == m.Conf(cmd, "meta.tail.password") { + // 输入密码 + m.Cmdy(prefix, "send-keys", "-t", arg[1], value["password"], "Enter") + } else if tail == m.Conf(cmd, "meta.tail.verify") { + // 输入密码 + m.Cmdy(prefix, "send-keys", "-t", arg[1], m.Cmdx("aaa.totp.get", value["text"]), "Enter") } } }) }}, "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - // prefix := kit.Simple(m.Confv("prefix", "meta.cmd")) - - // 当前会话 current := "" m.Cmd("session").Table(func(index int, value map[string]string, head []string) { if value["tag"] == "1" { + // 当前会话 current = value["session"] } }) switch arg = kit.Split(kit.Select("tmux.auto", arg, 0)); arg[0] { default: - m.Cmd("auto", current, arg) m.Append("_output", "void") + m.Cmd("auto", current, arg) } }}, }, diff --git a/misc/vim/auto.vim b/misc/vim/auto.vim index 33e98fb8..4e2b417a 100644 --- a/misc/vim/auto.vim +++ b/misc/vim/auto.vim @@ -190,8 +190,11 @@ autocmd! VimLeave * call ShyLogout() autocmd! BufReadPost * call ShySync("bufs") autocmd! BufReadPost * call ShySync("read") autocmd! BufWritePre * call ShySync("write") -" autocmd! CmdlineLeave * call ShySync("exec") -autocmd! CmdWinLeave * call ShySync("exec") +if exists("CmdlineLeave") + autocmd! CmdlineLeave * call ShySync("exec") +else + autocmd! CmdWinLeave * call ShySync("exec") +endif " autocmd! QuickFixCmdPost * call ShyCheck("fixs") autocmd! InsertLeave * call ShySync("insert") diff --git a/misc/zsh/auto.sh b/misc/zsh/auto.sh index b51ed4b4..9361c1fd 100644 --- a/misc/zsh/auto.sh +++ b/misc/zsh/auto.sh @@ -35,6 +35,9 @@ ShyLog() { } # 发送数据 +ShyWord() { + echo "$*"|sed "s/\ /%20/g"|sed "s/|/%7C/g"|sed "s/\;/%3B/g"|sed "s/\[/%5B/g"|sed "s/\]/%5D/g" +} ShyLine() { echo "$*"|sed -e 's/\"/\\\"/g' -e 's/\n/\\n/g' } @@ -68,11 +71,13 @@ ShyHelp() { ShyLogin() { HOST=`hostname` ctx_sid=`ShyPost login "" share "${ctx_share}" pid "$$" pane "${TMUX_PANE}" hostname "${HOST}" username "${USER}"` echo "${ctx_welcome}" - echo "${ctx_dev}" - echo "sid: ${ctx_sid}" - echo "begin: ${ctx_begin}" + echo "${ctx_dev} " + echo -n "sid: ${ctx_sid} " + echo "begin: ${ctx_begin} " + export ctx_sid } ShyLogout() { + ShySync history echo ${ctx_goodbye} && [ "$ctx_sid" != "" ] && ShyPost logout } @@ -92,12 +97,23 @@ ShySend() { -F "SHELL=${SHELL}" -F "pwd=${PWD}" -F "sid=${ctx_sid}" } -ShyRelay() { - which=docker && [ "$1" != "" ] && which=$1 && shift - arg="" && for cmd in "$@"; do - arg="$arg&after="`echo $cmd|sed s/\;/%3B/g|sed s/\ /%20/g` +ShyLocal() { + which=alpine && [ "$1" != "" ] && which=$1 && shift + favor=tmux.auto && [ "$1" != "" ] && favor=$1 && shift + step=before arg="" && for cmd in "$@"; do + [ "$cmd" = after ] && step=after && continue + arg="$arg&$step="`ShyWord $cmd` done - ${ctx_curl} -s "$ctx_dev/code/tmux/favor?relay=$which&cmds=tmux.auto&$arg" & + ${ctx_curl} -s "$ctx_dev/code/tmux/favor?local=$which&cmds=$favor&$arg" & +} +ShyRelay() { + which=relay && [ "$1" != "" ] && which=$1 && shift + favor=tmux.auto && [ "$1" != "" ] && favor=$1 && shift + step=before arg="" && for cmd in "$@"; do + [ "$cmd" = after ] && step=after && continue + arg="$arg&$step="`ShyWord $cmd` + done + ${ctx_curl} -s "$ctx_dev/code/tmux/favor?relay=$which&cmds=$favor&$arg" & } # 同步数据 @@ -115,7 +131,7 @@ ShySync() { ctx_begin=${ctx_begin:=$ctx_end} ctx_count=`expr $ctx_end - $ctx_begin` ShyEcho "sync $ctx_begin-$ctx_end count $ctx_count to $ctx_dev" - history|tail -n $ctx_count |while read line; do + HISTTIMEFORMAT="%F %T " history|tail -n $ctx_count |while read line; do ShyPost sync history arg "$line" >/dev/null done ctx_begin=$ctx_end @@ -178,9 +194,8 @@ ShyInit() { fi echo "url: ${ctx_url}" - echo "pid: $$" - echo "begin: ${ctx_begin}" - echo "share: ${ctx_share}" - echo "pane: $TMUX_PANE" + echo -n "pid: $$ " + echo -n "begin: ${ctx_begin} " + echo -n "share: ${ctx_share} " + echo "pane: $TMUX_PANE " } -ShyInit && trap ShyLogout EXIT diff --git a/misc/zsh/zsh.go b/misc/zsh/zsh.go index 028343be..8c5119bf 100644 --- a/misc/zsh/zsh.go +++ b/misc/zsh/zsh.go @@ -48,9 +48,9 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行", "/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[0] { case "history": - vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 2) - cmds := []string{ice.WEB_FAVOR, m.Conf("zsh", "meta.history"), ice.TYPE_SHELL, vs[0], kit.Select("", vs, 1), - "sid", m.Option("sid"), "pwd", m.Option("pwd")} + vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 4) + cmds := []string{ice.WEB_FAVOR, m.Conf("zsh", "meta.history"), ice.TYPE_SHELL, vs[0], kit.Select("", vs, 3), + "sid", m.Option("sid"), "pwd", m.Option("pwd"), "time", vs[1] + " " + vs[2]} if m.Cmd(cmds); m.Option("you") != "" { m.Cmd(ice.WEB_SPACE, m.Option("you"), cmds) @@ -154,15 +154,22 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行", "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 && arg[0] != "sh" { // 添加收藏 - cmds := []string{ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab")), ice.TYPE_SHELL, m.Option("note"), arg[0]} + cmds := []string{ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab")), kit.Select(ice.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0]} if m.Cmdy(cmds); m.Option("you") != "" { m.Cmdy(ice.WEB_SPACE, m.Option("you"), cmds) } return } + if m.Option("tab") == "" { + // 收藏列表 + m.Cmdy(ice.WEB_SPACE, m.Option("you"), ice.WEB_FAVOR) + m.Table() + return + } + m.Echo("#/bin/sh\n\n") - m.Cmd(ice.WEB_SPACE, m.Option("you"), ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab"))).Table(func(index int, value map[string]string, head []string) { + m.Cmd(ice.WEB_SPACE, m.Option("you"), ice.WEB_FAVOR, m.Option("tab")).Table(func(index int, value map[string]string, head []string) { switch value["type"] { case ice.TYPE_SHELL: // 查看收藏 diff --git a/type.go b/type.go index 079b8e3c..a73ced79 100644 --- a/type.go +++ b/type.go @@ -758,6 +758,9 @@ func (m *Message) Appendv(key string, arg ...interface{}) []string { return m.meta[key] } func (m *Message) Resultv(arg ...interface{}) []string { + if len(arg) > 0 { + m.meta[MSG_RESULT] = kit.Simple(arg...) + } return m.meta[MSG_RESULT] } func (m *Message) Result(arg ...interface{}) string { @@ -767,7 +770,7 @@ func (m *Message) Result(arg ...interface{}) string { return kit.Select("", m.meta[MSG_RESULT], v) } } - return strings.Join(m.Resultv(), "") + return strings.Join(m.Resultv(arg...), "") } func (m *Message) Log(level string, str string, arg ...interface{}) *Message {