mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
tce add add_componet
This commit is contained in:
parent
e0a9b58b0c
commit
231ef878e6
29
Makefile
29
Makefile
@ -24,6 +24,31 @@ build:
|
||||
run:
|
||||
etc/run.sh 2>var/error.log
|
||||
|
||||
tar:
|
||||
[ -e tar ] || mkdir tar
|
||||
[ -e tar/bin ] || mkdir tar/bin
|
||||
[ -e tar/etc ] || mkdir tar/etc
|
||||
cp etc/bootstrap.sh tar/
|
||||
cp etc/init.shy tar/etc/
|
||||
cp etc/exit.shy tar/etc/
|
||||
touch tar/etc/local.shy
|
||||
touch tar/etc/exit_local.shy
|
||||
[ -e tar/usr ] || mkdir tar/usr
|
||||
cp -r usr/template tar/usr
|
||||
cp -r usr/librarys tar/usr
|
||||
[ -e tar/var ] || mkdir tar/var
|
||||
|
||||
tar_all: tar darwin linux64
|
||||
cp etc/local.shy tar/etc/
|
||||
cp etc/exit_local.shy tar/etc/
|
||||
mv bench.darwin tar/bin/
|
||||
mv bench.linux64 tar/bin/
|
||||
tar zcvf tar.tgz tar
|
||||
|
||||
darwin:
|
||||
GOARCH=amd64 GOOS=darwin go build $(BENCH)
|
||||
mv bench bench.darwin
|
||||
|
||||
win64:
|
||||
GOARCH=amd64 GOOS=windows go build $(BENCH)
|
||||
mv bench.exe bench_1.0_win64.exe
|
||||
@ -33,7 +58,7 @@ win32:
|
||||
|
||||
linux64:
|
||||
GOARCH=amd64 GOOS=linux go build $(BENCH)
|
||||
mv bench bench_1.0_linux64
|
||||
mv bench bench.linux64
|
||||
linux32:
|
||||
GOARCH=386 GOOS=linux go build $(BENCH)
|
||||
mv bench bench_1.0_linux32
|
||||
@ -68,3 +93,5 @@ load_dotsfile:\
|
||||
~/.vim/syntax/shy.vim: $(DOTS)/shy.vim
|
||||
cp $< $@
|
||||
|
||||
.PHONY: tar
|
||||
|
||||
|
13
etc/bootstrap.sh
Executable file
13
etc/bootstrap.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
bench=bench
|
||||
[ `uname` = "Darwin" ] && bench=bin/bench.darwin
|
||||
[ `uname` = "Linux" ] && bench=bin/bench.linux64
|
||||
[ -e "$bench" ] || bench=bench
|
||||
|
||||
while true; do
|
||||
$bench stdio && break
|
||||
echo "bench run error"
|
||||
echo "restarting..."
|
||||
sleep 3
|
||||
done
|
@ -1,8 +1,8 @@
|
||||
source etc/exit_local.shy
|
||||
|
||||
~code
|
||||
config save var/counter.json counter
|
||||
config save counter.json counter
|
||||
~stdio
|
||||
config save var/history.json history
|
||||
config save history.json history
|
||||
return hello
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
~stdio
|
||||
config load var/history.json history
|
||||
config load history.json history
|
||||
~code
|
||||
config load var/counter.json counter
|
||||
config load counter.json counter
|
||||
|
||||
source etc/local.shy
|
||||
~shy
|
||||
|
@ -1,8 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
while true; do
|
||||
bench stdio && break
|
||||
echo "bench run error"
|
||||
echo "restarting..."
|
||||
sleep 3
|
||||
done
|
@ -16,7 +16,6 @@ import (
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -58,16 +57,8 @@ func (aaa *AAA) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
|
||||
c.Caches = map[string]*ctx.Cache{
|
||||
"method": &ctx.Cache{Name: "method", Value: arg[0], Help: "登录方式"},
|
||||
"sessid": &ctx.Cache{Name: "sessid", Value: aaa.Session(arg[1]), Help: "会话令牌"},
|
||||
"login_time": &ctx.Cache{Name: "login_time", Value: fmt.Sprintf("%d", now), Help: "登录时间"},
|
||||
"expire_time": &ctx.Cache{Name: "expire_time", Value: fmt.Sprintf("%d", int64(m.Confi("expire"))+now), Help: "会话超时"},
|
||||
"login_time": &ctx.Cache{Name: "login_time", Value: fmt.Sprintf("%d", now), Help: "登录时间", Hand: func(m *ctx.Message, x *ctx.Cache, arg ...string) string {
|
||||
if len(arg) > 0 {
|
||||
return arg[0]
|
||||
}
|
||||
|
||||
n, e := strconv.Atoi(x.Value)
|
||||
m.Assert(e)
|
||||
return time.Unix(int64(n), 0).Format("15:03:04")
|
||||
}},
|
||||
}
|
||||
c.Configs = map[string]*ctx.Config{
|
||||
"right": &ctx.Config{Name: "right", Value: map[string]interface{}{}, Help: "用户权限"},
|
||||
@ -122,11 +113,10 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
"key": &ctx.Config{Name: "key", Value: "etc/pem/key.pem", Help: "私钥文件"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"login": &ctx.Command{
|
||||
Name: "login [sessid]|[username password]",
|
||||
Form: map[string]int{"ip": 1, "openid": 1, "cert": 1, "pub": 1, "key": 1, "load": 1, "save": 1},
|
||||
"login": &ctx.Command{Name: "login [sessid]|[username password]",
|
||||
Form: map[string]int{"ip": 1, "openid": 1, "cert": 1, "pub": 1, "key": 1},
|
||||
Help: []string{"会话管理", "sessid: 令牌", "username: 账号", "password: 密码",
|
||||
"ip: 主机地址", "openid: 微信登录", "cert: 证书", "pub: 公钥", "key: 私钥", "load: 加载会话", "save: 保存会话"},
|
||||
"ip: 主机地址", "openid: 微信登录", "cert: 证书", "pub: 公钥", "key: 私钥"},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if aaa, ok := c.Server.(*AAA); m.Assert(ok) {
|
||||
method := ""
|
||||
@ -185,7 +175,15 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
return
|
||||
}
|
||||
|
||||
m.Start(fmt.Sprintf("user%d", m.Capi("nuser", 1)), "密码登录", "password", arg[0])
|
||||
name := ""
|
||||
switch arg[0] {
|
||||
case "root", "void":
|
||||
name = arg[0]
|
||||
default:
|
||||
name = fmt.Sprintf("user%d", m.Capi("nuser", 1))
|
||||
}
|
||||
|
||||
m.Start(name, "密码登录", "password", arg[0])
|
||||
m.Cap("password", "password", aaa.Password(arg[1]), "密码登录")
|
||||
m.Append("sessid", m.Cap("sessid"))
|
||||
m.Echo(m.Cap("sessid"))
|
||||
@ -196,6 +194,8 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
if n > 0 && m.Cap("sessid") == arg[0] {
|
||||
if int64(m.Capi("expire_time")) > time.Now().Unix() {
|
||||
m.Sess("login", m.Target().Message())
|
||||
m.Append("login_time", time.Unix(int64(m.Capi("login_time")), 0).Format(m.Conf("time_format")))
|
||||
m.Append("expire_time", time.Unix(int64(m.Capi("expire_time")), 0).Format(m.Conf("time_format")))
|
||||
m.Echo(m.Cap("stream"))
|
||||
} else {
|
||||
m.Target().Close(m)
|
||||
@ -242,8 +242,11 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
if m.Cap("stream") == arg[0] {
|
||||
if len(arg) == 1 { //查看所有权
|
||||
for k, v := range m.Confv("right").(map[string]interface{}) {
|
||||
for order, right := range v.(map[string]interface{}) {
|
||||
m.Add("append", "group", k)
|
||||
m.Add("append", "right", v)
|
||||
m.Add("append", "order", order)
|
||||
m.Add("append", "right", right)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -280,8 +283,11 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
}
|
||||
if len(arg) == 3 { //查看使用权
|
||||
for k, v := range m.Confv("right", arg[2]).(map[string]interface{}) {
|
||||
for order, right := range v.(map[string]interface{}) {
|
||||
m.Add("append", "order", k)
|
||||
m.Add("append", "right", v)
|
||||
m.Add("append", "right", order)
|
||||
m.Add("append", "detail", right)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -716,6 +716,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
}
|
||||
}
|
||||
|
||||
m.Append("datetime", t.Format(m.Confx("time_format")))
|
||||
m.Append("timestamp", t.Unix()*int64(m.Confi("time_unit")))
|
||||
|
||||
if stamp {
|
||||
m.Echo("%d", t.Unix()*int64(m.Confi("time_unit")))
|
||||
} else {
|
||||
|
@ -2997,14 +2997,16 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
if len(arg) == 0 || action != "" {
|
||||
save := map[string]interface{}{}
|
||||
if action == "load" {
|
||||
f, e := os.Open(which)
|
||||
f, e := os.Open(m.Sess("nfs").Cmd("path", which).Result(0))
|
||||
if e != nil {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
de := json.NewDecoder(f)
|
||||
de.Decode(&save)
|
||||
if e = de.Decode(&save); e != nil {
|
||||
m.Log("info", "e: %v", e)
|
||||
}
|
||||
}
|
||||
|
||||
m.BackTrace(func(m *Message) bool {
|
||||
@ -3163,7 +3165,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
}},
|
||||
|
||||
"trans": &Command{Name: "trans key index", Help: "数据转换", Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||
value := m.Data[(arg[0])]
|
||||
value := m.Data[arg[0]]
|
||||
if arg[1] != "" {
|
||||
v := Chain(m, value, arg[1])
|
||||
value = v
|
||||
@ -3173,7 +3175,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
case map[string]interface{}:
|
||||
for k, v := range val {
|
||||
m.Add("append", "key", k)
|
||||
m.Add("append", "value", v)
|
||||
switch value := v.(type) {
|
||||
case float64:
|
||||
m.Add("append", "value", fmt.Sprintf("%d", int(value)))
|
||||
default:
|
||||
m.Add("append", "value", fmt.Sprintf("%v", value))
|
||||
}
|
||||
}
|
||||
m.Sort("key", "str").Table()
|
||||
case map[string]string:
|
||||
@ -3187,11 +3194,11 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
switch value := v.(type) {
|
||||
case map[string]interface{}:
|
||||
for k, v := range value {
|
||||
m.Add("append", k, v)
|
||||
m.Add("append", k, fmt.Sprintf("%v", v))
|
||||
}
|
||||
default:
|
||||
m.Add("append", "index", i)
|
||||
m.Add("append", "value", v)
|
||||
m.Add("append", "value", fmt.Sprintf("%v", v))
|
||||
}
|
||||
}
|
||||
m.Table()
|
||||
|
@ -1041,7 +1041,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
defer f.Close()
|
||||
|
||||
switch {
|
||||
case strings.HasSuffix(arg[0], ".json"):
|
||||
case strings.HasSuffix(arg[0], ".json") && len(m.Meta["append"]) > 0:
|
||||
data := []interface{}{}
|
||||
|
||||
nrow := len(m.Meta[m.Meta["append"][0]])
|
||||
@ -1056,7 +1056,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
en.SetIndent("", " ")
|
||||
en.Encode(data)
|
||||
|
||||
case strings.HasSuffix(arg[0], ".csv"):
|
||||
case strings.HasSuffix(arg[0], ".csv") && len(m.Meta["append"]) > 0:
|
||||
w := csv.NewWriter(f)
|
||||
|
||||
line := []string{}
|
||||
@ -1075,10 +1075,12 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
}
|
||||
w.Flush()
|
||||
default:
|
||||
m.Log("fuck", "what ---%v", m.Meta)
|
||||
for _, v := range m.Meta["result"] {
|
||||
f.WriteString(v)
|
||||
}
|
||||
}
|
||||
m.Log("fuck", "what ---%v", m.Meta)
|
||||
m.Set("append").Set("result").Echo(name)
|
||||
}},
|
||||
|
||||
|
@ -346,7 +346,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}},
|
||||
"get": &ctx.Command{Name: "get [method GET|POST] url arg...",
|
||||
Help: "访问服务, method: 请求方法, url: 请求地址, arg: 请求参数",
|
||||
Form: map[string]int{"method": 1, "headers": 2, "content_type": 1, "body": 1, "path_value": 1, "body_response": 1, "trans": 1, "parse": 1},
|
||||
Form: map[string]int{"method": 1, "headers": 2, "content_type": 1, "body": 1, "path_value": 1, "body_response": 1, "parse": 1},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if web, ok := m.Target().Server.(*WEB); m.Assert(ok) {
|
||||
if m.Has("path_value") {
|
||||
@ -417,10 +417,10 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
switch {
|
||||
case strings.HasPrefix(ct, "application/json"):
|
||||
json.Unmarshal(buf, &result)
|
||||
if m.Has("trans") {
|
||||
if m.Has("parse") {
|
||||
msg := m.Spawn()
|
||||
msg.Put("option", "response", result)
|
||||
msg.Cmd("trans", "response", m.Option("trans"))
|
||||
msg.Cmd("trans", "response", m.Option("parse"))
|
||||
m.Copy(msg, "append")
|
||||
m.Copy(msg, "result")
|
||||
return
|
||||
@ -657,7 +657,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}},
|
||||
"session": &ctx.Command{Name: "session", Help: "用户登录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
sessid := m.Option("sessid")
|
||||
if sessid == "" && m.Options("username") && m.Options("password") {
|
||||
if m.Options("username") && m.Options("password") {
|
||||
sessid = m.Sess("aaa").Cmd("login", m.Option("username"), m.Option("password")).Result(0)
|
||||
}
|
||||
if sessid == "" && m.Options("remote_addr") {
|
||||
@ -717,7 +717,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}
|
||||
|
||||
group := m.Option("componet_group")
|
||||
order := m.Option("componet_order")
|
||||
order := m.Option("componet_name")
|
||||
right := group == "login"
|
||||
if !right {
|
||||
right = !m.Confs("login_right")
|
||||
@ -728,17 +728,18 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
if !right {
|
||||
login = m.Spawn().Cmd("session").Appendv("login").(*ctx.Message)
|
||||
}
|
||||
if !right && login != nil {
|
||||
if role := login.Confv("right", []interface{}{"right", "role"}); role != nil && role.(string) == "root" {
|
||||
right = true
|
||||
}
|
||||
}
|
||||
if !right && login != nil {
|
||||
if role := login.Confv("right", []interface{}{group, "right", "role"}); role != nil && role.(string) == "owner" {
|
||||
right = true
|
||||
}
|
||||
if login != nil {
|
||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: login.Cap("sessid")})
|
||||
}
|
||||
|
||||
if !right && login != nil {
|
||||
right = m.Sess("aaa").Cmd("right", login.Cap("stream"), "check", group).Results(0)
|
||||
}
|
||||
if !right && login != nil {
|
||||
right = m.Sess("aaa").Cmd("right", "void", "check", group).Results(0)
|
||||
}
|
||||
|
||||
m.Log("info", "group: %v, name: %v, right: %v", group, order, right)
|
||||
for count := 0; count == 0; group, order, right = "login", "", true {
|
||||
for _, v := range m.Confv("componet", group).([]interface{}) {
|
||||
val := v.(map[string]interface{})
|
||||
@ -748,9 +749,10 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
|
||||
order_right := right
|
||||
if !order_right && login != nil {
|
||||
if role := login.Confv("right", []interface{}{group, val["componet_name"], "right", "role"}); role != nil && role.(string) == "share" {
|
||||
order_right = true
|
||||
order_right = m.Sess("aaa").Cmd("right", login.Cap("stream"), "check", group, val["componet_name"]).Results(0)
|
||||
}
|
||||
if !order_right && login != nil {
|
||||
order_right = m.Sess("aaa").Cmd("right", "void", "check", group, val["componet_name"]).Results(0)
|
||||
}
|
||||
if !order_right {
|
||||
continue
|
||||
@ -770,7 +772,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}
|
||||
count++
|
||||
|
||||
msg.Option("componet_order", val["componet_name"].(string))
|
||||
msg.Option("componet_name", val["componet_name"].(string))
|
||||
|
||||
for k, v := range val {
|
||||
if msg.Option(k) != "" {
|
||||
@ -808,9 +810,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
if order != "" || (val["pre_run"] != nil && val["pre_run"].(bool)) {
|
||||
if val["componet_cmd"] != nil {
|
||||
msg.Cmd(val["componet_cmd"], args)
|
||||
if msg.Options("file_name") {
|
||||
if msg.Options("download_file") {
|
||||
m.Append("page_redirect", fmt.Sprintf("/download/%s",
|
||||
msg.Sess("nfs").Copy(msg, "append").Copy(msg, "result").Cmd("export", msg.Option("file_name")).Result(0)))
|
||||
msg.Sess("nfs").Copy(msg, "append").Copy(msg, "result").Cmd("export", msg.Option("download_file")).Result(0)))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -23,28 +23,38 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||
"login": []interface{}{
|
||||
map[string]interface{}{"componet_name": "head", "template": "head"},
|
||||
map[string]interface{}{"componet_name": "userinfo", "componet_help": "userinfo",
|
||||
"context": "aaa", "componet_cmd": "userinfo", "arguments": []interface{}{"@sessid"},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "login", "componet_help": "login", "template": "componet",
|
||||
"context": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@username", "@password"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "username", "label": "username"},
|
||||
map[string]interface{}{"type": "password", "name": "password", "label": "password"},
|
||||
map[string]interface{}{"type": "button", "label": "login"},
|
||||
map[string]interface{}{"type": "button", "value": "login"},
|
||||
},
|
||||
"display_append": "", "display_result": "", "result_reload": "10",
|
||||
"display_append": "", "display_result": "",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "tail", "template": "tail"},
|
||||
},
|
||||
"index": []interface{}{
|
||||
map[string]interface{}{"componet_name": "head", "template": "head"},
|
||||
map[string]interface{}{"componet_name": "clipbaord", "componet_help": "clipbaord", "template": "clipboard"},
|
||||
map[string]interface{}{"componet_name": "login", "componet_help": "login", "template": "componet",
|
||||
"context": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@username", "@password"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "username", "label": "username"},
|
||||
map[string]interface{}{"type": "password", "name": "password", "label": "password"},
|
||||
map[string]interface{}{"type": "button", "value": "login"},
|
||||
},
|
||||
"display_append": "", "display_result": "",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "userinfo", "componet_help": "userinfo", "template": "componet",
|
||||
"context": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@sessid"},
|
||||
"pre_run": true,
|
||||
},
|
||||
map[string]interface{}{"componet_name": "clipboard", "componet_help": "clipboard", "template": "clipboard"},
|
||||
map[string]interface{}{"componet_name": "buffer", "componet_help": "buffer", "template": "componet",
|
||||
"context": "cli", "componet_cmd": "tmux", "arguments": []interface{}{"buffer"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "limit", "label": "limit", "value": "3"},
|
||||
map[string]interface{}{"type": "text", "name": "index", "label": "index"},
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
"pre_run": true,
|
||||
},
|
||||
@ -55,14 +65,14 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"label": "format", "value": "2006-01-02 15:04:05",
|
||||
},
|
||||
map[string]interface{}{"type": "text", "name": "string", "label": "string"},
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "json", "componet_help": "json", "template": "componet",
|
||||
"context": "nfs", "componet_cmd": "json", "arguments": []interface{}{"@string"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "string", "label": "string"},
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "dir", "componet_help": "dir", "template": "componet",
|
||||
@ -106,21 +116,11 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
},
|
||||
"display_result": "",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "contract", "componet_help": "contract", "template": "componet",
|
||||
"context": "cli.shy", "componet_cmd": "run", "arguments": []interface{}{"python/get_teacher_contract.py", "@fmt", "@begin", "@end", "cmd_env", "IS_PROD_RUNTIME", 1, "cmd_error"},
|
||||
"display_result": "", "file_name": "",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "file_name", "value": "data_2006_0102_1504.txt", "class": "file_name"},
|
||||
map[string]interface{}{"type": "text", "name": "fmt", "value": "%Y-%m-%d %H:%M"},
|
||||
map[string]interface{}{"type": "text", "name": "begin", "value": "2018-10-26 12:00"},
|
||||
map[string]interface{}{"type": "text", "name": "end", "value": "2018-10-29 12:00"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "download", "componet_help": "download", "template": "componet",
|
||||
"context": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
|
||||
"display_result": "", "file_name": "",
|
||||
"display_result": "", "download_file": "",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "file_name", "value": "data_2006_0102_1504.txt", "class": "file_name"},
|
||||
map[string]interface{}{"type": "text", "name": "download_file", "value": "data_2006_0102_1504.txt", "class": "file_name"},
|
||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
||||
"class": "file_cmd", "clipstack": "clistack",
|
||||
},
|
||||
@ -130,7 +130,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"context": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
||||
"class": "cmd", "clipstack": "clistack",
|
||||
"class": "cmd", "clipstack": "void",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -138,7 +138,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"context": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
||||
"class": "cmd", "clipstack": "clistack",
|
||||
"class": "cmd", "clipstack": "void",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -146,7 +146,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"context": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "cmd", "value": "",
|
||||
"class": "cmd", "clipstack": "clistack",
|
||||
"class": "cmd", "clipstack": "void",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -155,7 +155,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"display_result": "",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "ctx", "value": "shy"},
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "ccc", "componet_help": "ccc", "template": "componet",
|
||||
@ -169,27 +169,27 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
map[string]interface{}{"name": "cache", "value": "cache"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "cmd", "componet_help": "cmd", "template": "componet",
|
||||
"context": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@current_ctx", "command", "list"},
|
||||
"pre_run": true, "display_result": "",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "history", "componet_help": "history", "template": "componet",
|
||||
"context": "cli", "componet_cmd": "config", "arguments": []interface{}{"source_list"},
|
||||
"pre_run": true, "display_result": "",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "develop", "componet_help": "develop", "template": "componet",
|
||||
"context": "web.code", "componet_cmd": "config", "arguments": []interface{}{"counter"},
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
"pre_run": true,
|
||||
"display_result": "",
|
||||
@ -197,7 +197,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
map[string]interface{}{"componet_name": "windows", "componet_help": "windows", "template": "componet",
|
||||
"context": "cli", "componet_cmd": "windows",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
"pre_run": true,
|
||||
"display_result": "",
|
||||
@ -205,7 +205,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
map[string]interface{}{"componet_name": "runtime", "componet_help": "runtime", "template": "componet",
|
||||
"context": "cli", "componet_cmd": "runtime",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
"pre_run": true,
|
||||
"display_result": "",
|
||||
@ -213,7 +213,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
map[string]interface{}{"componet_name": "sysinfo", "componet_help": "sysinfo", "template": "componet",
|
||||
"context": "cli", "componet_cmd": "sysinfo",
|
||||
"inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "label": "refresh"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
"pre_run": true,
|
||||
"display_result": "",
|
||||
|
@ -21,8 +21,10 @@ function send_command(form, cb) {
|
||||
context.GET("", data, function(msg) {
|
||||
msg = msg[0]
|
||||
|
||||
var result = document.querySelector("code.result."+data["componet_name"]+" pre")
|
||||
var append = document.querySelector("table.append."+data["componet_name"])
|
||||
var name = data["componet_name_alias"] || data["componet_name"]
|
||||
|
||||
var result = document.querySelector("code.result."+name+" pre")
|
||||
var append = document.querySelector("table.append."+name)
|
||||
if (msg && (msg.append || msg.result)) {
|
||||
result && (result.innerHTML = (msg.result || []).join(""))
|
||||
append && (append.innerHTML = "")
|
||||
@ -74,15 +76,22 @@ function onaction(event, action) {
|
||||
}
|
||||
break
|
||||
case "command":
|
||||
send_command(event.target.form)
|
||||
send_command(event.target.form, function() {
|
||||
if (event.target.value == "login") {
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
break
|
||||
case "input":
|
||||
switch (event.key) {
|
||||
case "Enter":
|
||||
var clistack = document.querySelector("#clistack")
|
||||
if (!clistack) {
|
||||
break
|
||||
}
|
||||
var history = JSON.parse(event.target.dataset["history"] || "[]")
|
||||
if (history.length == 0 || event.target.value != history[history.length-1]) {
|
||||
history.push(event.target.value)
|
||||
var clistack = document.querySelector("#clistack")
|
||||
insert_child(clistack, "option").value = event.target.value
|
||||
}
|
||||
check_argument(event.target.form, event.target)
|
||||
@ -153,6 +162,10 @@ function onaction(event, action) {
|
||||
event.target.dataset["history_last"] = history.length-1
|
||||
break
|
||||
}
|
||||
case "b":
|
||||
if (event.ctrlKey && event.key == "b") {
|
||||
add_fieldset()
|
||||
}
|
||||
default:
|
||||
console.log(event)
|
||||
if (event.target.dataset["last_char"] == "j" && event.key == "k") {
|
||||
@ -238,6 +251,9 @@ function init_result(event) {
|
||||
}
|
||||
function init_download(event) {
|
||||
var append = document.querySelector("table.append.dir")
|
||||
if (!append) {
|
||||
return
|
||||
}
|
||||
insert_before(append, "input", {
|
||||
"type": "button",
|
||||
"value": "root",
|
||||
@ -339,6 +355,9 @@ function init_download(event) {
|
||||
|
||||
function init_context() {
|
||||
var append = document.querySelector("table.append.ctx")
|
||||
if (!append) {
|
||||
return
|
||||
}
|
||||
var option = document.querySelector("form.option.ctx")
|
||||
insert_before(append, "input", {
|
||||
"type": "button",
|
||||
@ -360,6 +379,26 @@ function init_context() {
|
||||
return true
|
||||
}
|
||||
})
|
||||
insert_before(append, "input", {
|
||||
"type": "button",
|
||||
"value": "aaa",
|
||||
"onclick": function(event) {
|
||||
option["ctx"].value = "aaa"
|
||||
send_command(option)
|
||||
context.Cookie("current_ctx", option["ctx"].value)
|
||||
return true
|
||||
}
|
||||
})
|
||||
insert_before(append, "input", {
|
||||
"type": "button",
|
||||
"value": "web",
|
||||
"onclick": function(event) {
|
||||
option["ctx"].value = "web"
|
||||
send_command(option)
|
||||
context.Cookie("current_ctx", option["ctx"].value)
|
||||
return true
|
||||
}
|
||||
})
|
||||
insert_before(append, "input", {
|
||||
"type": "button",
|
||||
"value": "mdb",
|
||||
@ -389,6 +428,9 @@ function init_context() {
|
||||
}
|
||||
function init_command() {
|
||||
var append = document.querySelector("table.append.command")
|
||||
if (!append) {
|
||||
return
|
||||
}
|
||||
var option = document.querySelector("form.option.command")
|
||||
insert_before(append, "input", {
|
||||
"type": "button",
|
||||
@ -418,6 +460,44 @@ function init_command() {
|
||||
})
|
||||
}
|
||||
|
||||
function init_userinfo() {
|
||||
var append = document.querySelector("table.append.userinfo")
|
||||
if (!append) {
|
||||
return
|
||||
}
|
||||
var option = document.querySelector("form.option.userinfo")
|
||||
return
|
||||
insert_before(append, "input", {
|
||||
"type": "button",
|
||||
"value": "logout",
|
||||
"onclick": function(event) {
|
||||
context.Cookie("sessid", "")
|
||||
location.reload()
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var ncommand = 3
|
||||
function add_fieldset() {
|
||||
var name = "command"+ncommand++
|
||||
|
||||
var fieldset = append_child(document.querySelector("body"), "fieldset")
|
||||
append_child(fieldset, "legend", {"innerText": name})
|
||||
|
||||
var option = append_child(fieldset, "form", {"className": "option "+name})
|
||||
option.dataset["componet_group"] = "index"
|
||||
option.dataset["componet_name"] = "command"
|
||||
option.dataset["componet_name_alias"] = name
|
||||
append_child(option, "input").style["display"] = "none"
|
||||
append_child(option, "input", {"name": "cmd", "className": "cmd", "onkeyup": function(event){
|
||||
onaction(event, "input")
|
||||
}}).focus()
|
||||
|
||||
var append = append_child(fieldset, "table", {"className": "append "+name})
|
||||
append_child(append_child(fieldset, "code", {"className": "result "+name}), "pre")
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
init_option()
|
||||
init_append()
|
||||
@ -425,4 +505,6 @@ window.onload = function() {
|
||||
init_download()
|
||||
init_context()
|
||||
init_command()
|
||||
init_userinfo()
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,6 @@
|
||||
{{end}}
|
||||
<form class="option {{option .Meta "componet_name"}}"
|
||||
data-componet_group="{{option . "componet_group"|meta}}"
|
||||
data-componet_order="{{option . "componet_order"|meta}}"
|
||||
data-componet_name="{{option . "componet_name"|meta}}"
|
||||
{{if eq $form_type "upload"}}
|
||||
method="POST" action="/upload" enctype="multipart/form-data"
|
||||
@ -140,7 +139,7 @@
|
||||
<label>{{index $input "label"}} : </label>
|
||||
{{end}}
|
||||
{{if eq $type "button"}}
|
||||
<input type="button" onclick="return onaction(event, 'command')" value="{{index $input "label"}}">
|
||||
<input type="button" onclick="return onaction(event, 'command')" value="{{index $input "value"}}">
|
||||
{{else if eq $type "submit"}}
|
||||
<input type="submit" value="{{index $input "value"}}">
|
||||
{{else if eq $type "file"}}
|
||||
@ -157,6 +156,14 @@
|
||||
{{end}}
|
||||
{{end}}
|
||||
</select>
|
||||
{{else if eq $type "password"}}
|
||||
<input
|
||||
type="password"
|
||||
name="{{index $input "name"}}"
|
||||
value="{{index $input "value"}}"
|
||||
class="{{index $input "class"}}"
|
||||
onclick="return onaction(event, 'click')"
|
||||
onkeyup="return onaction(event, 'input')">
|
||||
{{else}}
|
||||
<input
|
||||
name="{{index $input "name"}}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user