mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 09:14:06 +08:00
add some
Change-Id: I258fc3409e027aa70a2a95ecebe87978ef1e38df
This commit is contained in:
parent
a10cfd46cb
commit
1e911d2cc6
@ -14,4 +14,4 @@
|
|||||||
|
|
||||||
source etc/local.shy
|
source etc/local.shy
|
||||||
|
|
||||||
~shy
|
~lark
|
||||||
|
@ -187,6 +187,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
m.Log("info", "import %s", arg[1])
|
m.Log("info", "import %s", arg[1])
|
||||||
module := msg.Cap("module")
|
module := msg.Cap("module")
|
||||||
for k, _ := range msg.Target().Commands {
|
for k, _ := range msg.Target().Commands {
|
||||||
|
if len(k) > 0 && k[0] == '/' {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if len(arg) == 2 {
|
if len(arg) == 2 {
|
||||||
cli.alias[k] = []string{module + "." + k}
|
cli.alias[k] = []string{module + "." + k}
|
||||||
continue
|
continue
|
||||||
@ -649,13 +652,13 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
"run": &ctx.Command{Name: "run", Help: "脚本参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"run": &ctx.Command{Name: "run", Help: "脚本参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
name := path.Join(m.Option("dir_root"), m.Option("download_dir"))
|
name := path.Join(m.Option("dir_root"), m.Option("download_dir"))
|
||||||
msg := m.Sess("nfs").Add("option", "dir_reg", ".*\\.(sh|shy|py)$").Add("option", "dir_root", "").Cmd("dir", name)
|
msg := m.Sess("nfs").Add("option", "dir_reg", ".*\\.(sh|shy|py)$").Add("option", "dir_root", "").Cmd("dir", name, "dir_deep")
|
||||||
m.Copy(msg, "append").Copy(msg, "result")
|
m.Copy(msg, "append").Copy(msg, "result")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
name := path.Join(m.Option("dir_root"), m.Option("download_dir"), arg[0])
|
// name := path.Join(m.Option("dir_root"), m.Option("download_dir"), arg[0])
|
||||||
msg := m.Spawn(c).Cmd("cmd", name, arg[1:])
|
msg := m.Spawn(c).Cmd("cmd", arg[0], arg[1:])
|
||||||
m.Copy(msg, "append").Copy(msg, "result")
|
m.Copy(msg, "append").Copy(msg, "result")
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
@ -2968,9 +2968,27 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"config": &Command{Name: "config [all] [export key..] [save|load file key...] [create map|list|string key name help] [delete key]",
|
"config": &Command{Name: "config [all] [export key..] [save|load file key...] [list|map arg...] [create map|list|string key name help] [delete key]",
|
||||||
Help: "配置管理, export: 导出配置, save: 保存配置到文件, load: 从文件加载配置, create: 创建配置, delete: 删除配置",
|
Help: "配置管理, export: 导出配置, save: 保存配置到文件, load: 从文件加载配置, create: 创建配置, delete: 删除配置",
|
||||||
Hand: func(m *Message, c *Context, key string, arg ...string) {
|
Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||||
|
if len(arg) > 2 && arg[2] == "list" {
|
||||||
|
chain := strings.Split(arg[1], ".")
|
||||||
|
chain = append(chain, "-2")
|
||||||
|
|
||||||
|
for _, val := range arg[3:] {
|
||||||
|
m.Confv(arg[0], chain, val)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(arg) > 2 && arg[2] == "map" {
|
||||||
|
chain := strings.Split(arg[1], ".")
|
||||||
|
|
||||||
|
for i := 3; i < len(arg)-1; i += 2 {
|
||||||
|
m.Confv(arg[0], append(chain, arg[i]), arg[i+1])
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
all := false
|
all := false
|
||||||
if len(arg) > 0 && arg[0] == "all" {
|
if len(arg) > 0 && arg[0] == "all" {
|
||||||
arg, all = arg[1:], true
|
arg, all = arg[1:], true
|
||||||
@ -3053,15 +3071,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case "save":
|
case "save":
|
||||||
// f, e := os.Create(which)
|
|
||||||
// m.Assert(e)
|
|
||||||
// defer f.Close()
|
|
||||||
//
|
|
||||||
buf, e := json.MarshalIndent(save, "", " ")
|
buf, e := json.MarshalIndent(save, "", " ")
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
m.Sess("nfs").Add("option", "data", string(buf)).Cmd("save", which)
|
m.Sess("nfs").Add("option", "data", string(buf)).Cmd("save", which)
|
||||||
|
|
||||||
// f.Write(buf)
|
|
||||||
case "export":
|
case "export":
|
||||||
buf, e := json.MarshalIndent(save, "", " ")
|
buf, e := json.MarshalIndent(save, "", " ")
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
@ -3079,68 +3091,10 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
value = m.Confv(arg[0])
|
value = m.Confv(arg[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
switch val := value.(type) {
|
msg := m.Spawn()
|
||||||
case map[string]interface{}:
|
msg.Put("option", "_cache", value)
|
||||||
if true {
|
msg.Cmd("trans", "_cache", "")
|
||||||
for k, v := range val {
|
m.Copy(msg, "append").Copy(msg, "result")
|
||||||
m.Add("append", k, v)
|
|
||||||
}
|
|
||||||
sort.Strings(m.Meta["append"])
|
|
||||||
m.Table()
|
|
||||||
} else {
|
|
||||||
for k, v := range val {
|
|
||||||
m.Add("append", "key", k)
|
|
||||||
m.Add("append", "value", v)
|
|
||||||
}
|
|
||||||
m.Sort("key", "str").Table()
|
|
||||||
}
|
|
||||||
case map[string]string:
|
|
||||||
for k, v := range val {
|
|
||||||
m.Add("append", k, v)
|
|
||||||
}
|
|
||||||
sort.Strings(m.Meta["append"])
|
|
||||||
m.Table()
|
|
||||||
// for k, v := range val {
|
|
||||||
// m.Add("append", "key", k)
|
|
||||||
// m.Add("append", "value", v)
|
|
||||||
// }
|
|
||||||
// m.Sort("key", "str").Table()
|
|
||||||
case []interface{}:
|
|
||||||
for i, v := range val {
|
|
||||||
switch value := v.(type) {
|
|
||||||
case map[string]interface{}:
|
|
||||||
for k, v := range value {
|
|
||||||
switch val := v.(type) {
|
|
||||||
case string:
|
|
||||||
m.Add("append", k, val)
|
|
||||||
case float64:
|
|
||||||
m.Add("append", k, int(val))
|
|
||||||
default:
|
|
||||||
b, _ := json.Marshal(val)
|
|
||||||
m.Add("append", k, string(b))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Strings(m.Meta["append"])
|
|
||||||
case map[string]string:
|
|
||||||
for k, v := range value {
|
|
||||||
m.Add("append", k, v)
|
|
||||||
}
|
|
||||||
sort.Strings(m.Meta["append"])
|
|
||||||
default:
|
|
||||||
m.Add("append", "index", i)
|
|
||||||
m.Add("append", "value", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.Table()
|
|
||||||
case []string:
|
|
||||||
for i, v := range val {
|
|
||||||
m.Add("append", "index", i)
|
|
||||||
m.Add("append", "value", v)
|
|
||||||
}
|
|
||||||
m.Table()
|
|
||||||
default:
|
|
||||||
m.Echo("%v", value)
|
|
||||||
}
|
|
||||||
}},
|
}},
|
||||||
"cache": &Command{Name: "cache [all] |key [value]|key = value|key name value help|delete key]",
|
"cache": &Command{Name: "cache [all] |key [value]|key = value|key name value help|delete key]",
|
||||||
Help: "查看、读写、赋值、新建、删除缓存变量",
|
Help: "查看、读写、赋值、新建、删除缓存变量",
|
||||||
@ -3257,26 +3211,58 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
|
|
||||||
// 解析
|
// 解析
|
||||||
nrow := len(m.Meta[m.Meta["append"][0]])
|
nrow := len(m.Meta[m.Meta["append"][0]])
|
||||||
|
keys := []string{}
|
||||||
for i := 0; i < nrow; i++ {
|
for i := 0; i < nrow; i++ {
|
||||||
for j := 0; j < len(m.Meta["parse"]); j += 2 {
|
for j := 0; j < len(m.Meta["parse"]); j += 2 {
|
||||||
var value interface{}
|
var value interface{}
|
||||||
e := json.Unmarshal([]byte(m.Meta[m.Meta["parse"][j]][i]), &value)
|
json.Unmarshal([]byte(m.Meta[m.Meta["parse"][j]][i]), &value)
|
||||||
|
if m.Meta["parse"][j+1] != "" {
|
||||||
|
value = Chain(m, value, m.Meta["parse"][j+1])
|
||||||
|
}
|
||||||
|
|
||||||
|
switch val := value.(type) {
|
||||||
|
case map[string]interface{}:
|
||||||
|
for k, _ := range val {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
keys = append(keys, m.Meta["parse"][j+1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := 0; i < nrow; i++ {
|
||||||
|
for _, k := range keys {
|
||||||
|
m.Add("append", k, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := 0; i < nrow; i++ {
|
||||||
|
for j := 0; j < len(m.Meta["parse"]); j += 2 {
|
||||||
|
var value interface{}
|
||||||
|
json.Unmarshal([]byte(m.Meta[m.Meta["parse"][j]][i]), &value)
|
||||||
if m.Meta["parse"][j+1] != "" {
|
if m.Meta["parse"][j+1] != "" {
|
||||||
value = Chain(m, value, m.Meta["parse"][j+1])
|
value = Chain(m, value, m.Meta["parse"][j+1])
|
||||||
}
|
}
|
||||||
m.Log("fuck", "info %v %v %v %v %T", e, m.Meta["parse"][j], m.Meta["parse"][j+1], value, value)
|
|
||||||
|
|
||||||
switch val := value.(type) {
|
switch val := value.(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
for k, v := range val {
|
for k, v := range val {
|
||||||
m.Add("append", k, v)
|
switch val := v.(type) {
|
||||||
|
case string:
|
||||||
|
m.Meta[k][i] = val
|
||||||
|
case float64:
|
||||||
|
m.Meta[k][i] = fmt.Sprintf("%d", int(val))
|
||||||
|
default:
|
||||||
|
b, _ := json.Marshal(val)
|
||||||
|
m.Meta[k][i] = string(b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
case string:
|
||||||
|
m.Meta[m.Meta["parse"][j+1]][i] = val
|
||||||
case float64:
|
case float64:
|
||||||
m.Add("append", m.Meta["parse"][j+1], fmt.Sprintf("%d", int(val)))
|
m.Meta[m.Meta["parse"][j+1]][i] = fmt.Sprintf("%d", int(val))
|
||||||
case nil:
|
|
||||||
m.Add("append", m.Meta["parse"][j+1], "")
|
|
||||||
default:
|
default:
|
||||||
m.Add("append", m.Meta["parse"][j+1], fmt.Sprintf("%v", val))
|
b, _ := json.Marshal(val)
|
||||||
|
m.Meta[m.Meta["parse"][j+1]][i] = string(b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1016,6 +1016,8 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
}
|
}
|
||||||
if p, f, e := open(m, arg[0], os.O_WRONLY|os.O_CREATE|os.O_TRUNC); m.Assert(e) {
|
if p, f, e := open(m, arg[0], os.O_WRONLY|os.O_CREATE|os.O_TRUNC); m.Assert(e) {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
m.Append("directory", p)
|
||||||
|
m.Echo(p)
|
||||||
|
|
||||||
for _, v := range arg[1:] {
|
for _, v := range arg[1:] {
|
||||||
n, e := fmt.Fprint(f, v)
|
n, e := fmt.Fprint(f, v)
|
||||||
|
@ -121,6 +121,8 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
|||||||
if msg.Confs("cas_url") {
|
if msg.Confs("cas_url") {
|
||||||
if !cas.IsAuthenticated(r) && !msg.Confs("skip_cas") {
|
if !cas.IsAuthenticated(r) && !msg.Confs("skip_cas") {
|
||||||
r.URL.Path = r.Header.Get("index_path")
|
r.URL.Path = r.Header.Get("index_path")
|
||||||
|
w.Header().Add("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Add("Vary", "*")
|
||||||
cas.RedirectToLogin(w, r)
|
cas.RedirectToLogin(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -395,7 +397,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}},
|
}},
|
||||||
"get": &ctx.Command{Name: "get [method GET|POST] url arg...",
|
"get": &ctx.Command{Name: "get [method GET|POST] url arg...",
|
||||||
Help: "访问服务, method: 请求方法, 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, "parse": 1},
|
Form: map[string]int{"method": 1, "headers": 2, "content_type": 1, "body": 1, "path_value": 1, "body_response": 1, "parse": 1, "save": 1},
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if web, ok := m.Target().Server.(*WEB); m.Assert(ok) {
|
if web, ok := m.Target().Server.(*WEB); m.Assert(ok) {
|
||||||
if m.Has("path_value") {
|
if m.Has("path_value") {
|
||||||
@ -472,12 +474,18 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if m.Has("save") {
|
if m.Has("save") {
|
||||||
p := path.Join(m.Sess("nfs").Cmd("pwd").Result(0), m.Option("save"))
|
|
||||||
|
p := m.Option("save")
|
||||||
|
if !strings.Contains(m.Option("save"), "/") {
|
||||||
|
p = path.Join(m.Sess("nfs").Cmd("pwd").Result(0), m.Option("save"))
|
||||||
|
}
|
||||||
|
|
||||||
f, e := os.Create(p)
|
f, e := os.Create(p)
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
io.Copy(f, res.Body)
|
io.Copy(f, res.Body)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
m.Log("info", "save file %s", p)
|
m.Log("info", "save file %s %s", p, m.Sess("aaa").Cmd("md5", p).Result(0))
|
||||||
|
m.Echo(p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,7 +500,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
m.Copy(msg, "append").Copy(msg, "result")
|
m.Copy(msg, "append").Copy(msg, "result")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
b, _ := json.Marshal(result)
|
b, _ := json.MarshalIndent(result, "", " ")
|
||||||
result = string(b)
|
result = string(b)
|
||||||
case strings.HasPrefix(ct, "text/html"):
|
case strings.HasPrefix(ct, "text/html"):
|
||||||
html, e := goquery.NewDocumentFromReader(res.Body)
|
html, e := goquery.NewDocumentFromReader(res.Body)
|
||||||
@ -848,7 +856,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"/download/": &ctx.Command{Name: "/download/", Help: "上传文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"/download/": &ctx.Command{Name: "/download/", Help: "上传文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
r := m.Optionv("request").(*http.Request)
|
r := m.Optionv("request").(*http.Request)
|
||||||
w := m.Optionv("response").(http.ResponseWriter)
|
w := m.Optionv("response").(http.ResponseWriter)
|
||||||
http.ServeFile(w, r, m.Sess("nfs").Cmd("path", strings.TrimPrefix(m.Option("path"), "/download/")).Result(0))
|
p := m.Sess("nfs").Cmd("path", strings.TrimPrefix(m.Option("path"), "/download/")).Result(0)
|
||||||
|
m.Log("info", "download %s %s", p, m.Sess("aaa").Cmd("md5", p).Result(0))
|
||||||
|
http.ServeFile(w, r, p)
|
||||||
}},
|
}},
|
||||||
"/render": &ctx.Command{Name: "/render template", Help: "渲染模板, template: 模板名称", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"/render": &ctx.Command{Name: "/render template", Help: "渲染模板, template: 模板名称", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if web, ok := m.Target().Server.(*WEB); m.Assert(ok) {
|
if web, ok := m.Target().Server.(*WEB); m.Assert(ok) {
|
||||||
@ -897,7 +907,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !right {
|
if !right {
|
||||||
if lark := m.Find("web.lark"); lark != nil && m.Confs("login_lark") {
|
lark := m.Find("web.lark")
|
||||||
|
if lark != nil && m.Confs("login_lark") {
|
||||||
right = ctx.Right(lark.Cmd("auth", m.Option("username"), "check", m.Option("cmd")).Result(0))
|
right = ctx.Right(lark.Cmd("auth", m.Option("username"), "check", m.Option("cmd")).Result(0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,10 +93,12 @@ context = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var arg = args.join("&");
|
var arg = args.join("&");
|
||||||
arg && (url += ((url.indexOf("?")>-1)? "&": "?") + arg)
|
// arg && (url += ((url.indexOf("?")>-1)? "&": "?") + arg)
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", url);
|
// xhr.open("POST", url);
|
||||||
|
xhr.open("POST", url);
|
||||||
|
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||||
xhr.setRequestHeader("Accept", "application/json")
|
xhr.setRequestHeader("Accept", "application/json")
|
||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
@ -122,7 +124,7 @@ context = {
|
|||||||
}
|
}
|
||||||
typeof cb == "function" && cb(msg)
|
typeof cb == "function" && cb(msg)
|
||||||
}
|
}
|
||||||
xhr.send();
|
xhr.send(arg);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user