1
0
forked from x/ContextOS

opt ssh.componet

This commit is contained in:
shaoying 2019-07-31 23:14:13 +08:00
parent bff17facfb
commit e2b8d0a9cf
14 changed files with 294 additions and 309 deletions

6
bin/user.sh Normal file
View File

@ -0,0 +1,6 @@
#! /bin/bash
export ctx_type=user
[ -f bin/boot.sh ] && source bin/boot.sh || source boot.sh

9
bin/zone.sh Normal file
View File

@ -0,0 +1,9 @@
#! /bin/bash
export ctx_ups=-
export ctx_dev=-
export ctx_type=work
[ -f bin/boot.sh ] && source bin/boot.sh || source boot.sh

View File

@ -0,0 +1,4 @@
highlight shyNumber ctermfg=magenta
syn match shyNumber "-\=\<\d\+\>#\="

View File

@ -103,66 +103,18 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
"github.com/PuerkitoBio/goquery",
"github.com/go-cas/cas",
}, "plugin": map[string]interface{}{
"path": "src/plugin", "list": []interface{}{
map[string]interface{}{"name": "index.go", "text": `package main
import (
"contexts/cli"
"contexts/ctx"
"toolkit"
"fmt"
"os"
)
var Index = &ctx.Context{Name: "test", Help: "测试工具",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{
"_index": &ctx.Config{Name: "index", Value: []interface{}{
map[string]interface{}{"name": "demo", "help": "demo",
"tmpl": "componet", "view": "componet", "init": "",
"type": "public", "ctx": "demo", "cmd": "demo",
"args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "value": "hello world"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
}},
},
Commands: map[string]*ctx.Command{
"demo": {Name: "demo", Help: "demo", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Echo(kit.Select("hello world", arg, 0))
return
}},
},
}
func main() {
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
}
`}, map[string]interface{}{"name": "index.js", "text": `
{init: function(page, pane, field, option, output) {
kit.Log("hello world")
}}
`}, map[string]interface{}{"name": "index.shy", "text": `
fun hello world "" "" \
public \
text "" \
button "执行"
copy pwd
end
`}, map[string]interface{}{"name": "local.shy", "text": ` `},
},
"path": "src/plugin", "list": Template,
}, "script": map[string]interface{}{
"path": "usr/script",
},
}, Help: "项目管理"},
"compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{
"bench": "src/extend/bench.go", "list": []interface{}{
map[string]interface{}{"os": "linux", "cpu": "amd64"},
map[string]interface{}{"os": "linux", "cpu": "386"},
map[string]interface{}{"os": "linux", "cpu": "arm"},
map[string]interface{}{"os": "windows", "cpu": "amd64"},
map[string]interface{}{"os": "linux", "cpu": "386"},
map[string]interface{}{"os": "linux", "cpu": "amd64"},
map[string]interface{}{"os": "windows", "cpu": "386"},
map[string]interface{}{"os": "windows", "cpu": "amd64"},
map[string]interface{}{"os": "darwin", "cpu": "amd64"},
},
"env": []interface{}{"GOBIN", "GOPATH", "PATH"},
@ -191,7 +143,8 @@ end
"portal": []interface{}{"template.tar.gz", "librarys.tar.gz"},
"script": []interface{}{"test.php"},
"list": map[string]interface{}{
"bench": "bin/bench.new",
"bench": "bin/bench.new",
"boot_sh": "bin/boot.sh",
"zone_sh": "bin/zone.sh",
"user_sh": "bin/user.sh",
@ -897,7 +850,7 @@ end
})
if q == "" {
q = path.Join(m.Conf("publish", "path"), strings.Join([]string{"bench", goos, arch}, "_"))
q = path.Join(m.Conf("publish", "path"), strings.Join([]string{"bench", goos, arch}, "."))
p = m.Cmdx("nfs.path", m.Conf("compile", "bench"))
}
@ -910,21 +863,17 @@ end
}
return
}},
"publish": &ctx.Command{Name: "publish", Help: "版本发布", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
dir := m.Conf("publish", "path")
m.Assert(os.MkdirAll(dir, 0777))
"publish": &ctx.Command{Name: "publish [item...]", Help: "版本发布", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
// 发布系统
if len(arg) == 0 {
list := [][]string{}
m.Confm("publish", "list", func(key string, value string) {
list = append(list, []string{key})
arg = append(arg, strings.Replace(key, "_", ".", -1))
})
m.Cmdp(0, []string{"copy"}, []string{"cli.publish"}, list)
return
}
p := path.Join(m.Conf("project", "plugin.path"), arg[0])
q := path.Join(m.Conf("publish", "path"), arg[0])
// 发布模块
if _, e := os.Stat(p); e == nil && m.Assert(os.MkdirAll(q, 0777)) {
m.Confm("project", "plugin.list", func(index int, value map[string]interface{}) {
m.Cmd("nfs.copy", path.Join(q, kit.Format(value["name"])), path.Join(p, kit.Format(value["name"])))
@ -936,21 +885,21 @@ end
return e
}
// 发布文件
for _, key := range arg {
key = kit.Key(key)
value := m.Conf("publish", []string{"list", key})
p := m.Cmdx("nfs.path", value)
q := path.Join(dir, key)
p := m.Cmdx("nfs.path", m.Conf("publish", []string{"list", kit.Key(key)}))
q := path.Join(m.Conf("publish", "path"), key)
if s, e := os.Stat(p); e == nil {
if s.IsDir() {
m.Cmd("cli.system", "tar", "-zcf", q, "-C", path.Dir(p), path.Base(value))
m.Cmd("cli.system", "tar", "-zcf", q, "-C", path.Dir(p), path.Base(p))
} else {
m.Cmd("nfs.copy", q, p)
}
m.Add("append", "time", s.ModTime())
m.Add("append", "size", s.Size())
m.Add("append", "hash", kit.Hashs(p)[:8])
m.Add("append", "file", q)
m.Push("time", s.ModTime())
m.Push("size", s.Size())
m.Push("hash", kit.Hashs(p)[:8])
m.Push("file", q)
}
}
m.Table()
@ -990,40 +939,38 @@ end
break
}
// 加载模块
if p, e := plugin.Open(path.Join(m.Conf("publish", "path"), arg[0], "index.so")); e == nil {
if s, e := p.Lookup("Index"); false && m.Assert(e) {
msg := m.Spawn(c.Register(*(s.(**ctx.Context)), nil, arg[0])).Cmd("_init", arg[1:])
msg.Cap("stream", arg[0])
msg.Confm("_index", func(index int, value map[string]interface{}) {
value["componet_ctx"] = "cli." + arg[0]
m.Conf("ssh.componet", []interface{}{arg[0], index}, value)
m.Add("append", "componet", arg[0])
m.Add("append", "index", index)
m.Add("append", "name", value["componet_name"])
m.Add("append", "help", value["componet_help"])
})
m.Table()
if s, e := p.Lookup("Index"); m.Assert(e) {
m.Spawn(c.Register(*(s.(**ctx.Context)), nil, arg[0])).Cmd("_init", arg[1:])
}
}
// 查找模块
msg := m.Find(arg[0], false)
if msg == nil {
m.Start(arg[0], "shy")
msg = m
} else {
msg.Target().Configs["_index"].Value = []interface{}{}
}
msg.Optionv("bio.ctx", msg.Target())
// 查找脚本
p := msg.Cmdx("nfs.path", path.Join(msg.Conf("project", "plugin.path"), arg[0], "index.shy"))
if p == "" {
p = msg.Cmdx("nfs.path", path.Join(msg.Conf("publish", "path"), arg[0], "index.shy"))
p = m.Cmdx("nfs.hash", m.Cmdx("web.get", "dev", fmt.Sprintf("publish/%s", arg[0]),
"GOARCH", m.Conf("runtime", "host.GOARCH"),
"GOOS", m.Conf("runtime", "host.GOOS"),
"upgrade", "plugin"))
}
// 加载脚本
if p != "" {
msg.Target().Configs["_index"].Value = []interface{}{}
msg.Optionv("bio.ctx", msg.Target())
msg.Cmdy("nfs.source", p)
msg.Confv("ssh.componet", arg[0], msg.Confv("_index"))
}
// 组件列表
m.Confm("ssh.componet", arg[0], func(index int, value map[string]interface{}) {
m.Push("index", index)
m.Push("name", value["componet_name"])

View File

@ -0,0 +1,52 @@
package cli
var Template = []interface{}{
map[string]interface{}{"name": "index.go", "text": `package main
import (
"contexts/cli"
"contexts/ctx"
"toolkit"
"fmt"
"os"
)
var Index = &ctx.Context{Name: "test", Help: "测试工具",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{
"_index": &ctx.Config{Name: "index", Value: []interface{}{
map[string]interface{}{"name": "demo", "help": "demo",
"tmpl": "componet", "view": "componet", "init": "",
"type": "public", "ctx": "demo", "cmd": "demo",
"args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "value": "hello world"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
}},
},
Commands: map[string]*ctx.Command{
"demo": {Name: "demo", Help: "demo", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Echo(kit.Select("hello world", arg, 0))
return
}},
},
}
func main() {
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
}
`}, map[string]interface{}{"name": "index.shy", "text": `
fun hello world "" "" \
public \
text "" \
button "执行"
copy pwd
end
`}, map[string]interface{}{"name": "index.js", "text": `
{init: function(page, pane, field, option, output) {
kit.Log("hello world")
}}
`}, map[string]interface{}{"name": "local.shy", "text": ` `},
}

View File

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-07-30 15:55:14", "ZYB-20190522USI", 316,
"2019-07-31 21:50:19", "ZYB-20190522USI", 329,
}

View File

@ -99,6 +99,7 @@ func (c *Context) Begin(m *Message, arg ...string) *Context {
if c.Server != nil {
c.Server.Begin(m, m.Meta["detail"]...)
}
m.root.Capi("ncontext", 1)
return c
}
func (c *Context) Start(m *Message, arg ...string) bool {
@ -146,7 +147,6 @@ func (c *Context) Close(m *Message, arg ...string) bool {
for i := len(c.requests) - 1; i >= 0; i-- {
if msg := c.requests[i]; msg.code == m.code {
if c.Server == nil || c.Server.Close(m, arg...) {
m.Log("close", "request %d/%d", i, len(c.requests)-1)
msg.Free()
for j := i; j < len(c.requests)-1; j++ {
c.requests[j] = c.requests[j+1]

View File

@ -774,6 +774,12 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
h := md.Sum(nil)
m.Echo(hex.EncodeToString(h[:]))
}
} else if f, p, e := kit.Create(path.Join(m.Conf("dir", "temp"), kit.Hashs(arg[0]))); m.Assert(e) {
defer f.Close()
if n, e := f.WriteString(arg[0]); m.Assert(e) {
m.Log("info", "save %v %v", n, p)
m.Echo(p)
}
}
return
}},

View File

@ -34,144 +34,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
},
Configs: map[string]*ctx.Config{
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
"company": []interface{}{
map[string]interface{}{"componet_name": "status", "componet_help": "状态",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "protected", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "cli", "system", "gg"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"status", ""}},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
map[string]interface{}{"componet_name": "deploy", "componet_help": "部署",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "protected", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "cli", "system", "gg"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "select", "name": "sub", "values": []interface{}{"deploygo", "deploy", "status"}},
map[string]interface{}{"type": "text", "name": "sub", "imports": "plugin_dir"},
map[string]interface{}{"type": "text", "name": "sub", "imports": "plugin_branch", "view": "long"},
map[string]interface{}{"type": "button", "value": "执行"},
},
"options": map[string]interface{}{"call_timeout": "180s"},
},
map[string]interface{}{"componet_name": "script", "componet_help": "脚本",
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
"componet_type": "protected", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "cli", "upgrade", "script"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "text", "name": "you", "imports": "plugin_you", "view": "long"},
map[string]interface{}{"type": "text", "name": "txt", "view": "long", "value": "test.php"},
map[string]interface{}{"type": "button", "value": "上传"},
},
"display": map[string]interface{}{"show_result": true},
},
map[string]interface{}{"componet_name": "php", "componet_help": "测试",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "protected", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "cli", "system", "php", "cmd_parse", "format"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "text", "name": "cmd", "value": "usr/script/test.php", "view": "long"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
map[string]interface{}{"componet_name": "grep", "componet_help": "日志",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "protected", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "nfs", "grep"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "value": "", "imports": "plugin_pod"},
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"", "hold", "tail", "head"}},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
map[string]interface{}{"componet_name": "redis", "componet_help": "缓存",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "protected", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "mdb", "redis"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"GET", "SET", "DEL", "HGETALL", "HGET", "HSET"}},
map[string]interface{}{"type": "text", "name": "cmd", "value": "test", "view": "long"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
map[string]interface{}{"componet_name": "mysql", "componet_help": "存储",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "protected", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "$$", "show"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "text", "name": "ctx", "value": "db1"},
map[string]interface{}{"type": "text", "name": "cmd", "value": "tblStudentLesson0", "imports": "plugin_db_table", "action": "auto"},
map[string]interface{}{"type": "button", "value": "查看 "},
},
"exports": []interface{}{"db_table", "Tables"},
},
},
"context": []interface{}{
map[string]interface{}{"componet_name": "runtime", "componet_help": "系统",
"componet_tmpl": "componet", "componet_view": "Runtime", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "runtime",
"componet_args": []interface{}{"system"}, "inputs": []interface{}{
map[string]interface{}{"type": "button", "value": "运行"},
},
},
map[string]interface{}{"componet_name": "project", "componet_help": "项目",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "project",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"plugin", "stat", "init"}},
map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "执行"},
},
"exports": []interface{}{"see", "name", "see"},
},
map[string]interface{}{"componet_name": "compile", "componet_help": "编译",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "compile",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "select", "name": "cmd", "values": []interface{}{"plugin", "windows", "darwin", "linux", "self", "all"}},
map[string]interface{}{"type": "text", "name": "who", "imports": "plugin_see"},
map[string]interface{}{"type": "button", "value": "编译"},
},
},
map[string]interface{}{"componet_name": "publish", "componet_help": "发布",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "publish",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "who", "imports": "plugin_see"},
map[string]interface{}{"type": "button", "value": "发布"},
},
},
map[string]interface{}{"componet_name": "upgrade", "componet_help": "升级",
"componet_tmpl": "componet", "componet_view": "componet", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "cli", "upgrade"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "select", "name": "action", "values": []interface{}{"script", "restart", "plugin", "portal", "system", "bench"}},
map[string]interface{}{"type": "text", "name": "who"},
map[string]interface{}{"type": "button", "value": "升级"},
},
"options": map[string]interface{}{"call_timeout": "180s"},
},
map[string]interface{}{"componet_name": "missyou", "componet_help": "任务",
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "missyou",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "action", "view": "long"},
map[string]interface{}{"type": "button", "value": "行动", "action": "auto"},
},
"exports": []interface{}{"you", "", "you"},
},
map[string]interface{}{"componet_name": "ktv", "componet_help": "存储",
"componet_tmpl": "componet", "componet_view": "Compile", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "mdb", "ktv"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "you", "imports": "plugin_you", "action": "auto"},
map[string]interface{}{"type": "button", "value": "存储", "action": "auto"},
},
"exports": []interface{}{"you", "", "you"},
},
},
"favor": []interface{}{
map[string]interface{}{"componet_name": "clip", "componet_help": "粘贴板",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
@ -201,35 +63,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
},
},
"index": []interface{}{
map[string]interface{}{"componet_name": "pod", "componet_help": "设备",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "ssh", "remote"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "view": "long"},
map[string]interface{}{"type": "button", "value": "执行", "action": "auto"},
},
"exports": []interface{}{"pod", "", "pod"},
},
map[string]interface{}{"componet_name": "ctx", "componet_help": "模块",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "$$", "context"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod", "action": "auto"},
map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs", "imports": "plugin_ctx", "action": "auto"},
map[string]interface{}{"type": "button", "value": "查看"},
},
"exports": []interface{}{"ctx", "names"},
},
map[string]interface{}{"componet_name": "cmd", "componet_help": "命令",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "$$", "command"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs", "imports": "plugin_ctx"},
map[string]interface{}{"type": "text", "name": "cmd", "value": "pwd"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
map[string]interface{}{"componet_name": "dir", "componet_help": "目录",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
@ -295,8 +128,13 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
map[string]interface{}{"type": "button", "value": "执行"},
},
},
},
"other": []interface{}{
map[string]interface{}{"componet_name": "ifconfig", "componet_help": "ifconfig",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "private", "componet_ctx": "tcp", "componet_cmd": "ifconfig",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "button", "value": "网卡"},
},
},
map[string]interface{}{"componet_name": "proc", "componet_help": "proc",
"componet_tmpl": "componet", "componet_view": "Company", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
@ -307,13 +145,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
map[string]interface{}{"type": "button", "value": "执行"},
},
},
map[string]interface{}{"componet_name": "ifconfig", "componet_help": "ifconfig",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "private", "componet_ctx": "tcp", "componet_cmd": "ifconfig",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "button", "value": "网卡"},
},
},
},
}, Help: "组件列表"},
@ -498,13 +329,17 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
switch arg[0] {
case "run":
tool := m.Confm("componet", []string{arg[1], arg[2]})
if kit.Format(tool["componet_type"]) == "private" && m.Option("userrole") != "root" {
m.Echo("private componet of %s", m.Conf("runtime", "work.name"))
break
}
if kit.Format(tool["componet_type"]) == "protected" && !m.Confs("flow", []string{arg[3], "user", m.Option("username")}) {
m.Echo("protected componet of %s", m.Conf("runtime", "work.name"))
break
if m.Option("userrole") != "root" {
switch kit.Format(tool["componet_type"]) {
case "private":
m.Echo("private componet of %s", m.Conf("runtime", "work.name"))
return
case "protected":
if !m.Confs("flow", []string{arg[3], "user", m.Option("username")}) {
m.Echo("protected componet of %s", m.Conf("runtime", "work.name"))
return
}
}
}
msg := m.Find(kit.Format(tool["componet_ctx"]))
@ -566,14 +401,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
switch arg[0] {
// 自动连接
case "auto":
if m.Confs("runtime", "boot.ctx_ups") {
m.Cmd("ssh.remote", "dial", m.Conf("runtime", "boot.ctx_ups"))
} else if m.Cmd("ssh.remote", "dial", "dev", "/shadow"); !m.Confs("runtime", "boot.ctx_box") {
m.Cmd("ssh.remote", "listen", m.Conf("runtime", "boot.ssh_port"))
m.Cmd("web.serve", "usr", m.Conf("runtime", "boot.web_port"))
}
switch m.Conf("runtime", "boot.ctx_type") {
case "work":
m.Cmd("ssh.work", "serve")
@ -582,6 +409,14 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
case "node":
}
if m.Confs("runtime", "boot.ctx_ups") {
m.Cmd("ssh.remote", "dial", m.Conf("runtime", "boot.ctx_ups"))
} else if m.Cmd("ssh.remote", "dial", "dev", "/shadow"); !m.Confs("runtime", "boot.ctx_box") {
m.Cmd("ssh.remote", "listen", m.Conf("runtime", "boot.ssh_port"))
m.Cmd("web.serve", "usr", m.Conf("runtime", "boot.web_port"))
}
// 监听连接
case "listen":
m.Cmd("ssh._node", "init")
@ -595,7 +430,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
// 添加节点
case "_add":
name := m.Cmdx("ssh._node", "create", arg[1], arg[2], m.Format("source"), arg[3:])
name := m.Cmdx("ssh._node", "create", arg[1], arg[2], m.Format("source"), arg[4:])
m.Sess("ms_source", false).Free(func(msg *ctx.Message) bool {
m.Cmd("ssh._node", "delete", name)
return true
@ -608,7 +443,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
m.Append("node.route", m.Conf("runtime", "node.route"))
m.Append("user.route", m.Conf("runtime", "user.route"))
m.Append("work.route", m.Conf("runtime", "work.route"))
m.Append("work.script", m.Cmdx("nfs.load", path.Join(m.Conf("cli.publish", "script."+arg[2]))))
m.Append("work.script", m.Cmdx("nfs.load", path.Join(m.Conf("cli.publish", "path"), kit.Select("hello", arg[3]), "local.shy")))
m.Echo(name).Back(m)
// 断线重连
@ -664,11 +499,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}
// 注册脚本
m.Log("info", "script %v", m.Append("work.script"))
m.Set("option", "local.shy", m.Append("work.script")).Cmd("nfs.source")
m.Cmd("nfs.source", m.Cmdx("nfs.hash", m.Append("work.script")))
return nil
}, "send", "", "_add", m.Conf("runtime", "node.name"), m.Conf("runtime", "node.type"))
}, "send", "", "_add", m.Conf("runtime", "node.name"), m.Conf("runtime", "node.type"), m.Conf("runtime", "boot.ctx_type"))
return nil
}, "nfs.socket", arg)

View File

@ -557,14 +557,14 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
var data interface{}
for k, v := range uuu.Query() {
if len(v) == 1 {
if i, e := strconv.Atoi(v[0]); e == nil && false {
if i, e := strconv.Atoi(v[0]); e == nil {
data = kit.Chain(data, k, i)
} else {
data = kit.Chain(data, k, v[0])
}
} else {
for _, val := range v {
if i, e := strconv.Atoi(v[0]); e == nil && false {
if i, e := strconv.Atoi(v[0]); e == nil {
data = kit.Chain(data, []string{k, "-2"}, i)
} else {
data = kit.Chain(data, []string{k, "-2"}, val)
@ -956,38 +956,38 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
return
}},
"/publish/": &ctx.Command{Name: "/publish/", Help: "下载文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
"/publish/": &ctx.Command{Name: "/publish/filename [upgrade script|plugin]", Help: "下载项目", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
// 下载程序
key = strings.TrimPrefix(key, "/publish/")
if strings.HasSuffix(key, "bench") {
key = key + "." + m.Option("GOOS") + "." + m.Option("GOARCH")
key = key + "." + kit.Select(m.Conf("runtime", "host.GOOS"), m.Option("GOOS")) +
"." + kit.Select(m.Conf("runtime", "host.GOARCH"), m.Option("GOARCH"))
}
p := ""
if m.Option("upgrade") == "plugin" {
if !strings.HasSuffix(key, ".so") {
key += ".so"
}
p = m.Cmdx("nfs.path", path.Join("src/plugin", key))
}
if m.Option("upgrade") == "script" {
// 下载脚本
if m.Options("missyou") {
p = m.Cmdx("nfs.path", path.Join(m.Conf("missyou", "path"), m.Option("missyou"), "usr/script", key))
} else {
p = m.Cmdx("nfs.path", path.Join("usr/script", key))
}
}
key = strings.Replace(key, ".", "_", -1)
if p == "" {
p = m.Cmdx("nfs.path", path.Join(m.Conf("publish", "path"), key))
}
if p == "" {
p = m.Cmdx("nfs.path", m.Conf("publish", []string{"list", key}))
}
if s, e := os.Stat(p); e != nil || s.IsDir() {
return e
} else if m.Option("upgrade") == "plugin" {
// 下载插件
p = m.Cmdx("nfs.path", path.Join(m.Conf("publish", "path"), key, kit.Select("index.shy", m.Option("index"))))
} else {
// 下载系统
if p = m.Cmdx("nfs.path", path.Join(m.Conf("publish", "path"), key)); p == "" {
p = m.Cmdx("nfs.path", m.Conf("publish", []string{"list", kit.Key(key)}))
}
}
m.Log("info", "publish %s %s", kit.Hashs(p), p)
http.ServeFile(m.Optionv("response").(http.ResponseWriter), m.Optionv("request").(*http.Request), p)
// 下载文件
if s, e := os.Stat(p); e == nil && !s.IsDir() {
m.Log("info", "publish %s %s", kit.Hashs(p), p)
http.ServeFile(m.Optionv("response").(http.ResponseWriter), m.Optionv("request").(*http.Request), p)
}
return
}},
"/shadow": &ctx.Command{Name: "/shadow", Help: "暗网", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {

View File

@ -0,0 +1,36 @@
package main
import (
"contexts/cli"
"contexts/ctx"
"toolkit"
"fmt"
"os"
)
var Index = &ctx.Context{Name: "test", Help: "测试工具",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{
"_index": &ctx.Config{Name: "index", Value: []interface{}{
map[string]interface{}{"name": "demo", "help": "demo",
"tmpl": "componet", "view": "componet", "init": "",
"type": "public", "ctx": "demo", "cmd": "demo",
"args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "value": "hello world"},
map[string]interface{}{"type": "button", "value": "执行"},
},
},
}},
},
Commands: map[string]*ctx.Command{
"demo": {Name: "demo", Help: "demo", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Echo(kit.Select("hello world", arg, 0))
return
}},
},
}
func main() {
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
}

View File

@ -0,0 +1,4 @@
{init: function(page, pane, field, option, output) {
kit.Log("hello world")
}}

View File

@ -0,0 +1,87 @@
fun project "项目" "" "" \
private \
select "" values plugin values stat values init \
text "" \
button "执行" \
exports see name see
copy cli.project $1 $2
end
fun compile "编译" "" "" \
private \
select "" values plugin values windows values darwin values linux values self values all \
text "" name see imports plugin_see \
button "编译"
copy cli.compile $1 $2
end
fun publish "发布" "" "" \
private \
text "" name see imports plugin_see \
button "发布"
copy cli.publish $1
end
fun upgrade "升级" "" "" \
private \
text "" name pod imports plugin_pod \
select "" values script values restart values plugin values bench values portal values system \
text "" \
button "升级"
copy ssh._route $1 cli.upgrade $2 $3
end
fun missyou "任务" "" "" \
private \
text "" view long \
button "行动" action auto \
exports you "" you
copy cli.missyou $1
end
fun pod "设备" "" "" \
private \
text "" view long \
button "行动" action auto \
exports pod pod
copy ssh._route $1 ssh.remote $1
end
fun ctx "模块" "" "" \
private \
text "" name pod imports plugin_pod action auto view long \
text "nfs" name ctx imports plugin_ctx action auto \
button "行动" \
exports ctx names
copy ssh._route $1 context $2 list
end
fun cmd "命令" "" "" \
private \
text "" name pod imports plugin_pod view long \
text "" name ctx imports plugin_ctx \
text "pwd" \
button "执行"
copy ssh._route $1 context $2 command $3
end
fun dir "目录" "" "" \
private \
text "" name pod imports plugin_pod action auto view long \
text "usr/script" name dir imports plugin_dir action auto view long \
button "查看" action auto \
button "回退" click Back \
exports dir "" dir
copy ssh._route $1 nfs.dir $2 time size line path
end

View File

@ -0,0 +1 @@