forked from x/icebergs
add aaa.auth
This commit is contained in:
parent
762c9becb2
commit
ee6adfdbf9
@ -5,9 +5,10 @@ import (
|
||||
)
|
||||
|
||||
var share_template = kit.Dict(
|
||||
"share", `<a href="/share/%s" target="_blank">%s</a>`,
|
||||
"qrcode", `<img src="/share/%s/qrcode">`,
|
||||
"value", `<img src="/share/%s/value">`,
|
||||
"share", `<img src="/share/%s/share">`,
|
||||
|
||||
"link", `<a href="/share/%s" target="_blank">%s</a>`,
|
||||
"simple", `<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
|
@ -467,7 +467,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
m.Cmd(ice.WEB_SPIDE, "add", "self", kit.Select("http://:9020", m.Conf(ice.CLI_RUNTIME, "conf.ctx_self")))
|
||||
}
|
||||
if m.Richs(ice.WEB_SPIDE, nil, "dev", nil) == nil {
|
||||
m.Cmd(ice.WEB_SPIDE, "add", "dev", kit.Select("http://mac.local:9020", m.Conf(ice.CLI_RUNTIME, "conf.ctx_dev")))
|
||||
m.Cmd(ice.WEB_SPIDE, "add", "dev", kit.Select("http://:9020", m.Conf(ice.CLI_RUNTIME, "conf.ctx_dev")))
|
||||
}
|
||||
if m.Richs(ice.WEB_SPIDE, nil, "shy", nil) == nil {
|
||||
m.Cmd(ice.WEB_SPIDE, "add", "shy", kit.Select("https://shylinux.com:443", m.Conf(ice.CLI_RUNTIME, "conf.ctx_shy")))
|
||||
@ -865,12 +865,14 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
t := time.AfterFunc(kit.Duration(m.Conf(ice.WEB_SPACE, "meta.timeout.c")), func() {
|
||||
m.TryCatch(m, true, func(m *ice.Message) {
|
||||
m.Log(ice.LOG_WARN, "timeout")
|
||||
m.Back(nil)
|
||||
})
|
||||
})
|
||||
m.Call(true, func(msg *ice.Message) *ice.Message {
|
||||
if msg != nil {
|
||||
m.Copy(msg)
|
||||
}
|
||||
// 返回结果
|
||||
m.Copy(msg).Log("cost", "%s: %s %v", m.Format("cost"), arg[0], arg[1:])
|
||||
m.Log("cost", "%s: %s %v", m.Format("cost"), arg[0], arg[1:])
|
||||
t.Stop()
|
||||
return nil
|
||||
})
|
||||
@ -878,7 +880,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
}) == nil, "not found %s", arg[0])
|
||||
}
|
||||
}},
|
||||
ice.WEB_DREAM: {Name: "dream", Help: "梦想家", Meta: kit.Dict("exports", []string{"you", "name"},
|
||||
ice.WEB_DREAM: {Name: "dream", Help: "梦想家", Meta: kit.Dict(
|
||||
"remote", "pod", "exports", []string{"you", "name"},
|
||||
"detail", []interface{}{"启动", "停止"},
|
||||
), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "value", "", "name", "name",
|
||||
@ -915,7 +918,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
m.Option("cmd_type", "daemon")
|
||||
m.Optionv("cmd_env",
|
||||
"ctx_log", "boot.log",
|
||||
"ctx_mod", "ctx log gdb ssh",
|
||||
"ctx_mod", "ctx,log,gdb,ssh",
|
||||
"ctx_dev", m.Conf(ice.CLI_RUNTIME, "conf.ctx_dev"),
|
||||
"PATH", kit.Path(path.Join(p, "bin"))+":"+os.Getenv("PATH"),
|
||||
)
|
||||
m.Cmd(m.Confv(ice.WEB_DREAM, "meta.cmd"), "self", arg[0])
|
||||
@ -942,7 +946,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
}},
|
||||
|
||||
ice.WEB_FAVOR: {Name: "favor [path [type name [text [key value]....]]", Help: "收藏夹", Meta: kit.Dict(
|
||||
"remote", "you", "exports", []string{"hot", "favor"},
|
||||
"remote", "pod", "exports", []string{"hot", "favor"},
|
||||
"detail", []string{"编辑", "收录", "导出", "删除"},
|
||||
), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "favor", "action", "auto",
|
||||
@ -1157,7 +1161,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
m.Push("data", h)
|
||||
}
|
||||
}},
|
||||
ice.WEB_STORY: {Name: "story", Help: "故事会", Meta: kit.Dict("remote", "you", "exports", []string{"top", "story"},
|
||||
ice.WEB_STORY: {Name: "story", Help: "故事会", Meta: kit.Dict("remote", "pod", "exports", []string{"top", "story"},
|
||||
"detail", []string{"共享", "更新", "推送"}), List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "story", "action", "auto",
|
||||
kit.MDB_INPUT, "text", "name", "list", "action", "auto",
|
||||
@ -1536,9 +1540,11 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
m.Richs(ice.WEB_SHARE, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
m.Push("detail", value)
|
||||
m.Push("key", "link")
|
||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.share"), key, key))
|
||||
m.Push("key", "qrcode")
|
||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.qrcode"), key))
|
||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.link"), key, key))
|
||||
m.Push("key", "share")
|
||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.share"), key))
|
||||
m.Push("key", "value")
|
||||
m.Push("value", fmt.Sprintf(m.Conf(ice.WEB_SHARE, "meta.template.value"), key))
|
||||
})
|
||||
return
|
||||
}
|
||||
@ -1609,10 +1615,14 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
m.Append("_output", "result")
|
||||
m.Echo(kit.Formats(value))
|
||||
return
|
||||
case "qrcode", "共享码":
|
||||
case "share", "共享码":
|
||||
m.Append("_output", "qrcode")
|
||||
m.Echo("%s/%s/", m.Conf(ice.WEB_SHARE, "meta.domain"), key)
|
||||
return
|
||||
case "value", "数据值":
|
||||
m.Append("_output", "qrcode")
|
||||
m.Echo("%s", value["text"])
|
||||
return
|
||||
}
|
||||
|
||||
switch value["type"] {
|
||||
@ -1709,6 +1719,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
break
|
||||
}
|
||||
}
|
||||
m.Log(ice.LOG_EXPORT, "%s %s", m.Option("begin"), m.Format("append"))
|
||||
|
||||
case ice.STORY_PUSH:
|
||||
// 上传节点
|
||||
|
108
misc/auth/auth.go
Normal file
108
misc/auth/auth.go
Normal file
@ -0,0 +1,108 @@
|
||||
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) }
|
9
misc/auth/auth.js
Normal file
9
misc/auth/auth.js
Normal file
@ -0,0 +1,9 @@
|
||||
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: []})
|
1
misc/auth/auth.shy
Normal file
1
misc/auth/auth.shy
Normal file
@ -0,0 +1 @@
|
||||
title "auth"
|
1
misc/tmux/auto.tmux
Normal file
1
misc/tmux/auto.tmux
Normal file
@ -0,0 +1 @@
|
||||
bind C-F command-prompt -p "send favor:" -I "tmux.auto" 'run-shell -b "curl $ctx_dev/code/tmux/favor?cmds=%%"'
|
@ -2,6 +2,7 @@ package tmux
|
||||
|
||||
import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
@ -14,26 +15,30 @@ import (
|
||||
var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
Caches: map[string]*ice.Cache{},
|
||||
Configs: map[string]*ice.Config{
|
||||
"prefix": {Name: "buffer", Help: "缓存", Value: kit.Data("cmd", []interface{}{ice.CLI_SYSTEM, "tmux"})},
|
||||
"buffer": {Name: "buffer", Help: "缓存", Value: kit.Data()},
|
||||
"session": {Name: "session", Help: "会话", Value: kit.Data(
|
||||
"format", "#{session_id},#{session_attached},#{session_name},#{session_windows},#{session_height},#{session_width}",
|
||||
"fields", "id,tag,session,windows,height,width",
|
||||
"cmd", []interface{}{"cli.system", "tmux", "list-session"},
|
||||
)},
|
||||
"windows": {Name: "window", Help: "窗口", Value: kit.Data(
|
||||
"format", "#{window_id},#{window_active},#{window_name},#{window_panes},#{window_height},#{window_width}",
|
||||
"fields", "id,tag,window,panes,height,width",
|
||||
"cmd", []interface{}{"cli.system", "tmux", "list-windows"},
|
||||
)},
|
||||
"panes": {Name: "pane", Help: "终端", Value: kit.Data(
|
||||
"format", "#{pane_id},#{pane_active},#{pane_index},#{pane_tty},#{pane_height},#{pane_width}",
|
||||
"fields", "id,tag,pane,tty,height,width",
|
||||
"cmd", []interface{}{"cli.system", "tmux", "list-panes"},
|
||||
)},
|
||||
"view": {Name: "pane", Help: "终端", Value: kit.Data(
|
||||
"format", "#{pane_id},#{pane_active},#{pane_index},#{pane_tty},#{pane_height},#{pane_width}",
|
||||
"fields", "id,tag,pane,tty,height,width",
|
||||
"cmd", []interface{}{"cli.system", "tmux", "list-panes"},
|
||||
)},
|
||||
"relay": {Name: "relay", Help: "跳板", Value: kit.Data(
|
||||
"tail", kit.Dict(
|
||||
"verify", "Verification code:",
|
||||
"password", "Password:",
|
||||
"login", "[relay ~]$",
|
||||
),
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
@ -42,6 +47,8 @@ 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`)
|
||||
}
|
||||
|
||||
for _, v := range []string{"auto.sh", "auto.vim"} {
|
||||
@ -54,8 +61,8 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
}
|
||||
}
|
||||
}},
|
||||
"auto": {Name: "auto", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
prefix := []string{ice.CLI_SYSTEM, "tmux"}
|
||||
"auto": {Name: "auto", Help: "自动化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
|
||||
// 共享空间
|
||||
share, dev := "", kit.Select(m.Conf(ice.CLI_RUNTIME, "conf.ctx_dev"), m.Conf(ice.CLI_RUNTIME, "host.ctx_self"))
|
||||
@ -72,6 +79,11 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
m.Cmd(prefix, "new-session", "-ds", arg[0])
|
||||
}
|
||||
|
||||
if m.Option("relay") != "" {
|
||||
// 自动认证
|
||||
m.Cmd("relay", arg[0], m.Option("relay"))
|
||||
}
|
||||
|
||||
// 连接参数
|
||||
m.Cmdy(prefix, "send-keys", "-t", arg[0], "export ctx_dev=", dev, "Enter")
|
||||
m.Cmdy(prefix, "send-keys", "-t", arg[0], "export ctx_share=", share, "Enter")
|
||||
@ -83,6 +95,9 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
m.Cmdy(prefix, "send-keys", "-t", arg[0], value["text"], "Enter")
|
||||
}
|
||||
})
|
||||
for _, v := range kit.Simple(m.Optionv("after")) {
|
||||
m.Cmdy(prefix, "send-keys", "-t", arg[0], v, "Enter")
|
||||
}
|
||||
}},
|
||||
|
||||
"text": {Name: "text", Help: "文本", List: kit.List(
|
||||
@ -90,20 +105,19 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
kit.MDB_INPUT, "button", "value", "保存",
|
||||
kit.MDB_INPUT, "textarea", "name", "text",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
prefix := []string{ice.CLI_SYSTEM, "tmux"}
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
if len(arg) > 1 && arg[1] != "" {
|
||||
m.Cmd(prefix, "set-buffer", arg[1])
|
||||
}
|
||||
m.Cmdy(prefix, "show-buffer").Set("append")
|
||||
}},
|
||||
|
||||
"buffer": {Name: "buffer", Help: "缓存", List: kit.List(
|
||||
kit.MDB_INPUT, "text", "name", "buffer", "action", "auto",
|
||||
kit.MDB_INPUT, "text", "name", "value",
|
||||
kit.MDB_INPUT, "button", "value", "查看", "action", "auto",
|
||||
kit.MDB_INPUT, "button", "value", "返回", "cb", "Last",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
prefix := []string{ice.CLI_SYSTEM, "tmux"}
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
if len(arg) > 1 {
|
||||
// 设置缓存
|
||||
m.Cmd(prefix, "set-buffer", "-b", arg[0], arg[1])
|
||||
@ -134,7 +148,8 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
kit.MDB_INPUT, "button", "value", "查看", "action", "auto",
|
||||
kit.MDB_INPUT, "button", "value", "返回", "cb", "Last",
|
||||
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
prefix := []string{"cli.system", "tmux"}
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
|
||||
if len(arg) > 1 && arg[0] == "action" {
|
||||
switch arg[1] {
|
||||
case "运行":
|
||||
@ -197,7 +212,7 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
|
||||
if len(arg) == 0 {
|
||||
// 会话列表
|
||||
m.Split(m.Cmdx(m.Confv(cmd, "meta.cmd"),
|
||||
m.Split(m.Cmdx(prefix, "list-session",
|
||||
"-F", m.Conf(cmd, "meta.format")), m.Conf(cmd, "meta.fields"), ",", "\n")
|
||||
return
|
||||
}
|
||||
@ -240,17 +255,68 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台",
|
||||
m.Echo(strings.TrimSpace(m.Cmdx("view", target)))
|
||||
}},
|
||||
"windows": {Name: "window", Help: "窗口", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Split(m.Cmdx(m.Confv(cmd, "meta.cmd"), "-t", kit.Select("", arg, 0),
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
m.Split(m.Cmdx(prefix, "list-windows", "-t", kit.Select("", arg, 0),
|
||||
"-F", m.Conf(cmd, "meta.format")), m.Conf(cmd, "meta.fields"), ",", "\n")
|
||||
}},
|
||||
"panes": {Name: "pane", Help: "终端", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Split(m.Cmdx(m.Confv(cmd, "meta.cmd"), "-t", kit.Select("", arg, 0),
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
m.Split(m.Cmdx(prefix, "list-panes", "-t", kit.Select("", arg, 0),
|
||||
"-F", m.Conf(cmd, "meta.format")), m.Conf(cmd, "meta.fields"), ",", "\n")
|
||||
}},
|
||||
"view": {Name: "view", Help: "终端", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy("cli.system", "tmux", "capture-pane", "-pt", kit.Select("", arg, 0)).Set("append")
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
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) {
|
||||
prefix := kit.Simple(m.Confv("prefix", "meta.cmd"))
|
||||
|
||||
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")
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
})
|
||||
}},
|
||||
"/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")
|
||||
}
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
func init() { code.Index.Register(Index, nil) }
|
||||
func init() { code.Index.Register(Index, &web.Frame{}) }
|
||||
|
@ -190,7 +190,8 @@ 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! CmdlineLeave * call ShySync("exec")
|
||||
autocmd! CmdWinLeave * call ShySync("exec")
|
||||
" autocmd! QuickFixCmdPost * call ShyCheck("fixs")
|
||||
autocmd! InsertLeave * call ShySync("insert")
|
||||
|
||||
|
@ -47,9 +47,11 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
|
||||
"/sync": {Name: "/sync", Help: "同步", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
switch arg[0] {
|
||||
case "read", "write", "exec", "insert":
|
||||
m.Cmd(ice.WEB_FAVOR, m.Conf("vim", "meta.history"), "vimrc", arg[0], kit.Select(m.Option("arg"), m.Option("sub")),
|
||||
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"))
|
||||
|
||||
cmds := []string{ice.WEB_FAVOR, m.Conf("vim", "meta.history"), "vimrc", arg[0], kit.Select(m.Option("arg"), m.Option("sub")),
|
||||
"sid", m.Option("sid"), "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")}
|
||||
if m.Cmd(cmds); m.Option("you") != "" {
|
||||
m.Cmd(ice.WEB_SPACE, m.Option("you"), cmds)
|
||||
}
|
||||
default:
|
||||
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, kit.Keys("sync", arg[0]), kit.Dict(
|
||||
@ -86,14 +88,16 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器",
|
||||
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Options("arg") {
|
||||
// 添加收藏
|
||||
m.Cmd(ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"),
|
||||
"pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col"),
|
||||
)
|
||||
cmds := []string{ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"),
|
||||
"pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")}
|
||||
if m.Cmdy(cmds); m.Option("you") != "" {
|
||||
m.Cmdy(ice.WEB_SPACE, m.Option("you"), cmds)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 查看收藏
|
||||
m.Cmd(ice.WEB_FAVOR, m.Option("tab"), "extra", "extra.pwd", "extra.buf", "extra.row", "extra.col").Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(ice.WEB_SPACE, m.Option("you"), ice.WEB_FAVOR, m.Option("tab"), "extra", "extra.pwd", "extra.buf", "extra.row", "extra.col").Table(func(index int, value map[string]string, head []string) {
|
||||
switch value["type"] {
|
||||
case ice.TYPE_VIMRC:
|
||||
m.Echo("%v\n", m.Option("tab")).Echo("%v:%v:%v:(%v): %v\n",
|
||||
|
@ -92,6 +92,14 @@ 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`
|
||||
done
|
||||
${ctx_curl} -s "$ctx_dev/code/tmux/favor?relay=$which&cmds=tmux.auto&$arg" &
|
||||
}
|
||||
|
||||
# 同步数据
|
||||
ShySync() {
|
||||
case "$1" in
|
||||
@ -108,7 +116,7 @@ ShySync() {
|
||||
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
|
||||
ShyPost history "$line"
|
||||
ShyPost sync history arg "$line" >/dev/null
|
||||
done
|
||||
ctx_begin=$ctx_end
|
||||
;;
|
||||
@ -129,7 +137,7 @@ ShyFavor() {
|
||||
# 查看收藏
|
||||
ctx_word="sh"
|
||||
shift && [ "$1" != "" ] && ctx_tab="$1"
|
||||
shift && [ "$1" != "" ] && ctx_note="$1"
|
||||
shift && ctx_note="$1"
|
||||
else
|
||||
# 添加收藏
|
||||
[ "$1" != "" ] && ctx_word="$*" || ctx_word=`history|tail -n1|head -n1|sed -e 's/^[\ 0-9]*//g'`
|
||||
@ -151,6 +159,9 @@ ShyInit() {
|
||||
|
||||
if bind &>/dev/null; then
|
||||
# bash
|
||||
bind -x '"\C-G\C-R":ShySync base'
|
||||
bind -x '"\C-G\C-G":ShySync history'
|
||||
|
||||
# bind 'TAB:complete'
|
||||
bind 'TAB:menu-complete'
|
||||
complete -F ShyInput word
|
||||
@ -158,13 +169,12 @@ ShyInit() {
|
||||
bind -x '"\C-G\C-F":ShyFavor'
|
||||
bind -x '"\C-GF":ShyFavor sh'
|
||||
bind -x '"\C-Gf":ShyFavor sh'
|
||||
bind -x '"\C-G\C-G":ShySync history'
|
||||
|
||||
elif bindkey &>/dev/null; then
|
||||
# zsh
|
||||
setopt nosharehistory
|
||||
bindkey -s '\C-G\C-R' 'ShySync base\n'
|
||||
bindkey -s '\C-G\C-G' 'ShySync history\n'
|
||||
setopt nosharehistory
|
||||
fi
|
||||
|
||||
echo "url: ${ctx_url}"
|
||||
|
@ -45,45 +45,16 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
||||
m.Cmdy("login", "exit")
|
||||
}},
|
||||
|
||||
"/download": {Name: "/download", Help: "下载", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
you := m.Option("you")
|
||||
m.Option("you", "")
|
||||
|
||||
if len(arg) == 0 || arg[0] == "" {
|
||||
// 文件列表
|
||||
m.Cmdy(ice.WEB_SPACE, you, ice.WEB_STORY)
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
// 查找文件
|
||||
if m.Cmdy(ice.WEB_STORY, "index", arg[0]).Append("text") == "" && you != "" {
|
||||
// 上发文件
|
||||
m.Cmdy(ice.WEB_SPACE, you, ice.WEB_STORY, "index", arg[0])
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
m.Append("_output", kit.Select("file", "result", m.Append("file") == ""))
|
||||
}},
|
||||
"/upload": {Name: "/upload", Help: "上传", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
you := m.Option("you")
|
||||
m.Option("you", "")
|
||||
|
||||
// 缓存文件
|
||||
msg := m.Cmd(ice.WEB_STORY, "upload")
|
||||
m.Echo("data: %s\n", msg.Append("data"))
|
||||
m.Echo("time: %s\n", msg.Append("time"))
|
||||
m.Echo("type: %s\n", msg.Append("type"))
|
||||
m.Echo("name: %s\n", msg.Append("name"))
|
||||
m.Echo("size: %s\n", msg.Append("size"))
|
||||
|
||||
if you != "" {
|
||||
// 下发文件
|
||||
m.Cmd(ice.WEB_SPACE, you, ice.WEB_STORY, ice.STORY_PULL, "dev", msg.Append("name"))
|
||||
}
|
||||
}},
|
||||
"/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")}
|
||||
|
||||
if m.Cmd(cmds); m.Option("you") != "" {
|
||||
m.Cmd(ice.WEB_SPACE, m.Option("you"), cmds)
|
||||
}
|
||||
default:
|
||||
m.Richs("login", nil, m.Option("sid"), func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, kit.Keys("sync", arg[0]), kit.Dict(
|
||||
@ -181,19 +152,17 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
||||
m.Info("trans: %v", m.Result())
|
||||
}},
|
||||
"/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
you := m.Option("you")
|
||||
m.Option("you", "")
|
||||
|
||||
if len(arg) > 0 && arg[0] != "sh" {
|
||||
// 添加收藏
|
||||
if m.Cmdy(ice.WEB_FAVOR, m.Option("tab"), ice.TYPE_SHELL, m.Option("note"), arg[0]); you != "" {
|
||||
m.Cmdy(ice.WEB_SPACE, you, ice.WEB_FAVOR, m.Option("tab"), ice.TYPE_SHELL, m.Option("note"), arg[0])
|
||||
cmds := []string{ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab")), ice.TYPE_SHELL, m.Option("note"), arg[0]}
|
||||
if m.Cmdy(cmds); m.Option("you") != "" {
|
||||
m.Cmdy(ice.WEB_SPACE, m.Option("you"), cmds)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m.Echo("#/bin/sh\n\n")
|
||||
m.Cmd(ice.WEB_SPACE, you, ice.WEB_FAVOR, m.Option("tab")).Table(func(index int, value map[string]string, head []string) {
|
||||
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) {
|
||||
switch value["type"] {
|
||||
case ice.TYPE_SHELL:
|
||||
// 查看收藏
|
||||
@ -203,10 +172,38 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行",
|
||||
}
|
||||
})
|
||||
}},
|
||||
"/history": {Name: "/history", Help: "历史", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
vs := strings.SplitN(strings.TrimSpace(arg[0]), " ", 2)
|
||||
m.Cmd(ice.WEB_SPACE, m.Option("you"), 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"))
|
||||
|
||||
"/download": {Name: "/download", Help: "下载", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 || arg[0] == "" {
|
||||
// 文件列表
|
||||
m.Cmdy(ice.WEB_SPACE, m.Option("you"), ice.WEB_STORY)
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
// 查找文件
|
||||
if m.Cmdy(ice.WEB_STORY, "index", arg[0]).Append("text") == "" && m.Option("you") != "" {
|
||||
// 上发文件
|
||||
m.Cmd(ice.WEB_SPACE, m.Option("you"), ice.WEB_STORY, "push", arg[0], "dev", arg[0])
|
||||
m.Cmdy(ice.WEB_STORY, "index", arg[0])
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
m.Append("_output", kit.Select("file", "result", m.Append("file") == ""))
|
||||
}},
|
||||
"/upload": {Name: "/upload", Help: "上传", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
// 缓存文件
|
||||
msg := m.Cmd(ice.WEB_STORY, "upload")
|
||||
m.Echo("data: %s\n", msg.Append("data"))
|
||||
m.Echo("time: %s\n", msg.Append("time"))
|
||||
m.Echo("type: %s\n", msg.Append("type"))
|
||||
m.Echo("name: %s\n", msg.Append("name"))
|
||||
m.Echo("size: %s\n", msg.Append("size"))
|
||||
|
||||
if m.Option("you") != "" {
|
||||
// 下发文件
|
||||
m.Cmd(ice.WEB_SPACE, m.Option("you"), ice.WEB_STORY, ice.STORY_PULL, msg.Append("name"), "dev", msg.Append("name"))
|
||||
}
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
@ -35,10 +35,7 @@ END
|
||||
[ -f Makefile ] || cat >> Makefile <<END
|
||||
all:
|
||||
@echo && date
|
||||
export CGO_ENABLED=0
|
||||
export GOPRIVATE=github.com
|
||||
export GOPROXY=https://goproxy.cn
|
||||
go build -o ${ice_bin} ${main_go} && chmod u+x ${ice_bin} && ./${ice_sh} restart
|
||||
GOPRIVATE=github.com GOPROXY=https://goproxy.cn CGO_ENABLED=0 go build -o ${ice_bin} ${main_go} && chmod u+x ${ice_bin} && ./${ice_sh} restart
|
||||
END
|
||||
|
||||
[ -d etc ] || mkdir etc
|
||||
|
Loading…
x
Reference in New Issue
Block a user