forked from x/ContextOS
mac add aaa.userinfo web.upload context.Cookie context.Search context.Cache
This commit is contained in:
parent
1bd5acc897
commit
4fe19b1818
@ -216,6 +216,19 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
|
"userinfo": &ctx.Command{Name: "userinfo sessid", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
m.Travel(func(m *ctx.Message, n int) bool {
|
||||||
|
if m.Cap("sessid") == arg[0] {
|
||||||
|
m.Append("method", m.Cap("method"))
|
||||||
|
m.Append("stream", m.Cap("stream"))
|
||||||
|
m.Append("sessid", m.Cap("sessid"))
|
||||||
|
m.Append("login_time", m.Cap("login_time"))
|
||||||
|
m.Append("expire_time", m.Cap("expire_time"))
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
m.Table()
|
||||||
|
}},
|
||||||
"right": &ctx.Command{Name: "right [user [check|owner|share group [order] [add|del]]]", Form: map[string]int{"from": 1}, Help: "权限管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"right": &ctx.Command{Name: "right [user [check|owner|share group [order] [add|del]]]", Form: map[string]int{"from": 1}, Help: "权限管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
m.Travel(func(m *ctx.Message, n int) bool {
|
m.Travel(func(m *ctx.Message, n int) bool {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
|
@ -1332,6 +1332,15 @@ func (m *Message) Appendv(key string, arg ...interface{}) interface{} {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Message) Parse(arg string) string {
|
||||||
|
if len(arg) > 1 && arg[0] == '$' {
|
||||||
|
return m.Cap(arg[1:])
|
||||||
|
}
|
||||||
|
if len(arg) > 1 && arg[0] == '@' {
|
||||||
|
return m.Confx(arg[1:])
|
||||||
|
}
|
||||||
|
return arg
|
||||||
|
}
|
||||||
func (m *Message) Wait() bool {
|
func (m *Message) Wait() bool {
|
||||||
if m.target.exit != nil {
|
if m.target.exit != nil {
|
||||||
return <-m.target.exit
|
return <-m.target.exit
|
||||||
|
@ -84,6 +84,7 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
|||||||
msg.Option("referer", r.Header.Get("Referer"))
|
msg.Option("referer", r.Header.Get("Referer"))
|
||||||
msg.Option("accept", r.Header.Get("Accept"))
|
msg.Option("accept", r.Header.Get("Accept"))
|
||||||
|
|
||||||
|
r.ParseMultipartForm(int64(m.Confi("multipart_bsize")))
|
||||||
if r.ParseForm(); len(r.PostForm) > 0 {
|
if r.ParseForm(); len(r.PostForm) > 0 {
|
||||||
for k, v := range r.PostForm {
|
for k, v := range r.PostForm {
|
||||||
m.Log("info", "%s: %v", k, v)
|
m.Log("info", "%s: %v", k, v)
|
||||||
@ -147,11 +148,11 @@ func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if r.URL.Path == "/" && m.Confs("root_index") {
|
if r.URL.Path == "/" && m.Confs("root_index") {
|
||||||
http.Redirect(w, r, m.Conf("root_index"), http.StatusFound)
|
r.URL.Path = m.Conf("root_index")
|
||||||
} else {
|
|
||||||
web.ServeMux.ServeHTTP(w, r)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
web.ServeMux.ServeHTTP(w, r)
|
||||||
|
|
||||||
if m.Confs("logheaders") {
|
if m.Confs("logheaders") {
|
||||||
for k, v := range w.Header() {
|
for k, v := range w.Header() {
|
||||||
m.Log("info", "%s: %v", k, v)
|
m.Log("info", "%s: %v", k, v)
|
||||||
@ -169,7 +170,7 @@ func (web *WEB) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
func (web *WEB) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
func (web *WEB) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
||||||
web.Configs["root_index"] = &ctx.Config{Name: "root_index", Value: "", Help: "默认路由"}
|
web.Configs["root_index"] = &ctx.Config{Name: "root_index", Value: "/render", Help: "默认路由"}
|
||||||
web.Configs["logheaders"] = &ctx.Config{Name: "logheaders(yes/no)", Value: "no", Help: "日志输出报文头"}
|
web.Configs["logheaders"] = &ctx.Config{Name: "logheaders(yes/no)", Value: "no", Help: "日志输出报文头"}
|
||||||
web.Caches["directory"] = &ctx.Cache{Name: "directory", Value: m.Confx("directory", arg, 0), Help: "服务目录"}
|
web.Caches["directory"] = &ctx.Cache{Name: "directory", Value: m.Confx("directory", arg, 0), Help: "服务目录"}
|
||||||
web.Caches["route"] = &ctx.Cache{Name: "route", Value: "/" + web.Context.Name + "/", Help: "模块路由"}
|
web.Caches["route"] = &ctx.Cache{Name: "route", Value: "/" + web.Context.Name + "/", Help: "模块路由"}
|
||||||
@ -237,14 +238,15 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"nroute": &ctx.Cache{Name: "nroute", Value: "0", Help: "路由数量"},
|
"nroute": &ctx.Cache{Name: "nroute", Value: "0", Help: "路由数量"},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
"body_response": &ctx.Config{Name: "body_response", Value: "response", Help: "响应缓存"},
|
"multipart_bsize": &ctx.Config{Name: "multipart_bsize", Value: "102400", Help: "缓存大小"},
|
||||||
"method": &ctx.Config{Name: "method", Value: "GET", Help: "请求方法"},
|
"body_response": &ctx.Config{Name: "body_response", Value: "response", Help: "响应缓存"},
|
||||||
"brow_home": &ctx.Config{Name: "brow_home", Value: "http://localhost:9094", Help: "服务"},
|
"method": &ctx.Config{Name: "method", Value: "GET", Help: "请求方法"},
|
||||||
"directory": &ctx.Config{Name: "directory", Value: "usr", Help: "服务目录"},
|
"brow_home": &ctx.Config{Name: "brow_home", Value: "http://localhost:9094", Help: "服务"},
|
||||||
"address": &ctx.Config{Name: "address", Value: ":9094", Help: "服务地址"},
|
"directory": &ctx.Config{Name: "directory", Value: "usr", Help: "服务目录"},
|
||||||
"protocol": &ctx.Config{Name: "protocol", Value: "http", Help: "服务协议"},
|
"address": &ctx.Config{Name: "address", Value: ":9094", Help: "服务地址"},
|
||||||
"cert": &ctx.Config{Name: "cert", Value: "etc/cert.pem", Help: "路由数量"},
|
"protocol": &ctx.Config{Name: "protocol", Value: "http", Help: "服务协议"},
|
||||||
"key": &ctx.Config{Name: "key", Value: "etc/key.pem", Help: "路由数量"},
|
"cert": &ctx.Config{Name: "cert", Value: "etc/cert.pem", Help: "路由数量"},
|
||||||
|
"key": &ctx.Config{Name: "key", Value: "etc/key.pem", Help: "路由数量"},
|
||||||
|
|
||||||
"web_site": &ctx.Config{Name: "web_site", Value: []interface{}{
|
"web_site": &ctx.Config{Name: "web_site", Value: []interface{}{
|
||||||
map[string]interface{}{"_name": "MDN", "site": "https://developer.mozilla.org"},
|
map[string]interface{}{"_name": "MDN", "site": "https://developer.mozilla.org"},
|
||||||
@ -258,11 +260,14 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||||
"login": []interface{}{
|
"login": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "head", "name": "head", "help": "head",
|
"name": "head", "help": "head", "template": "head",
|
||||||
"context": "", "command": "", "arguments": []interface{}{},
|
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "componet", "name": "login", "help": "login",
|
"name": "userinfo", "help": "userinfo",
|
||||||
|
"context": "aaa", "command": "userinfo", "arguments": []interface{}{"@sessid"},
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "login", "help": "login", "template": "componet",
|
||||||
"context": "aaa", "command": "login", "arguments": []interface{}{"@username", "@password"},
|
"context": "aaa", "command": "login", "arguments": []interface{}{"@username", "@password"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
@ -283,21 +288,20 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"result_reload": "10",
|
"result_reload": "10",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "tail", "name": "tail", "help": "tail",
|
"name": "tail", "help": "tail", "template": "tail",
|
||||||
"context": "", "command": "", "arguments": []interface{}{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"index": []interface{}{
|
"index": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "head", "name": "head", "help": "head",
|
"name": "head", "help": "head", "template": "head",
|
||||||
"context": "", "command": "", "arguments": []interface{}{},
|
"context": "", "command": "", "arguments": []interface{}{},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "clipboard", "name": "clipbaord", "help": "clipbaord",
|
"name": "clipbaord", "help": "clipbaord", "template": "clipboard",
|
||||||
"context": "", "command": "", "arguments": []interface{}{},
|
"context": "", "command": "", "arguments": []interface{}{},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "componet", "name": "message", "help": "message",
|
"name": "message", "help": "message", "template": "componet",
|
||||||
"context": "cli", "command": "buffer", "arguments": []interface{}{},
|
"context": "cli", "command": "buffer", "arguments": []interface{}{},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
@ -311,9 +315,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "componet", "name": "time", "help": "time",
|
"name": "time", "help": "time", "template": "componet",
|
||||||
"context": "cli", "command": "time",
|
"context": "cli", "command": "time", "arguments": []interface{}{"@string"},
|
||||||
"arguments": []interface{}{"@string"},
|
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"type": "text", "name": "time_format",
|
"type": "text", "name": "time_format",
|
||||||
@ -330,7 +333,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "componet", "name": "json", "help": "json",
|
"name": "json", "help": "json", "template": "componet",
|
||||||
"context": "nfs", "command": "json",
|
"context": "nfs", "command": "json",
|
||||||
"arguments": []interface{}{"@string"},
|
"arguments": []interface{}{"@string"},
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
@ -345,7 +348,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "componet", "name": "dir", "help": "dir",
|
"name": "dir", "help": "dir", "template": "componet",
|
||||||
"context": "nfs", "command": "dir",
|
"context": "nfs", "command": "dir",
|
||||||
"arguments": []interface{}{"@dir",
|
"arguments": []interface{}{"@dir",
|
||||||
"dir_deep", "no",
|
"dir_deep", "no",
|
||||||
@ -353,6 +356,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"dir_link", "<a class='download' data-type='%s'>%s<a>",
|
"dir_link", "<a class='download' data-type='%s'>%s<a>",
|
||||||
"dir_info", "",
|
"dir_info", "",
|
||||||
},
|
},
|
||||||
|
"form_type": "upload",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"type": "text", "name": "dir",
|
"type": "text", "name": "dir",
|
||||||
@ -380,6 +384,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"name": "filename", "value": "filename",
|
"name": "filename", "value": "filename",
|
||||||
},
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "is_dir", "value": "is_dir",
|
||||||
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"name": "line", "value": "line",
|
"name": "line", "value": "line",
|
||||||
},
|
},
|
||||||
@ -415,10 +422,18 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"type": "file", "name": "upload",
|
||||||
|
"label": "upload", "value": "upload",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"type": "submit", "name": "submit",
|
||||||
|
"label": "submit", "value": "submit",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "componet", "name": "web_site", "help": "web_site",
|
"name": "web_site", "help": "web_site", "template": "componet",
|
||||||
"context": "web", "command": "config",
|
"context": "web", "command": "config",
|
||||||
"arguments": []interface{}{
|
"arguments": []interface{}{
|
||||||
"web_site",
|
"web_site",
|
||||||
@ -427,7 +442,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
"display_result": "",
|
"display_result": "",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"template": "tail", "name": "tail", "help": "tail",
|
"name": "tail", "help": "tail", "template": "tail",
|
||||||
"context": "", "command": "", "arguments": []interface{}{},
|
"context": "", "command": "", "arguments": []interface{}{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -787,6 +802,22 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
m.Appendv("login", login)
|
m.Appendv("login", login)
|
||||||
m.Echo(sessid)
|
m.Echo(sessid)
|
||||||
}},
|
}},
|
||||||
|
"/upload": &ctx.Command{Name: "/upload", Help: "上传文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
r := m.Optionv("request").(*http.Request)
|
||||||
|
f, h, e := r.FormFile("upload")
|
||||||
|
m.Assert(e)
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
p := path.Join(m.Conf("directory"), m.Option("dir"), h.Filename)
|
||||||
|
o, e := os.Create(p)
|
||||||
|
m.Assert(e)
|
||||||
|
defer o.Close()
|
||||||
|
|
||||||
|
io.Copy(o, f)
|
||||||
|
m.Log("upload", "file(%d): %s", h.Size, p)
|
||||||
|
m.Append("redirect", m.Option("referer"))
|
||||||
|
}},
|
||||||
|
|
||||||
"/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 _, ok := m.Target().Server.(*WEB); m.Assert(ok) {
|
if _, ok := m.Target().Server.(*WEB); m.Assert(ok) {
|
||||||
accept_json := strings.HasPrefix(m.Option("accept"), "application/json")
|
accept_json := strings.HasPrefix(m.Option("accept"), "application/json")
|
||||||
@ -796,9 +827,8 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
// m.Assert(e)
|
// m.Assert(e)
|
||||||
// tmpl.Funcs(ctx.CGI)
|
// tmpl.Funcs(ctx.CGI)
|
||||||
//
|
//
|
||||||
|
|
||||||
tmpl := template.New("render").Funcs(ctx.CGI)
|
tmpl := template.New("render").Funcs(ctx.CGI)
|
||||||
tmpl.ParseGlob("/home/shaoying/context/usr/template/common/base.tmpl")
|
tmpl.ParseGlob(fmt.Sprintf("%s/context/usr/template/common/base.tmpl", os.Getenv("HOME")))
|
||||||
|
|
||||||
w := m.Optionv("response").(http.ResponseWriter)
|
w := m.Optionv("response").(http.ResponseWriter)
|
||||||
if accept_json {
|
if accept_json {
|
||||||
@ -810,43 +840,34 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
if m.Option("componet_group") == "" {
|
if m.Option("componet_group") == "" {
|
||||||
m.Option("componet_group", m.Conf("componet_group"))
|
m.Option("componet_group", m.Conf("componet_group"))
|
||||||
}
|
}
|
||||||
|
|
||||||
group := m.Option("componet_group")
|
group := m.Option("componet_group")
|
||||||
|
order := m.Option("componet_order")
|
||||||
right := false
|
right := group == "login"
|
||||||
if group == "login" {
|
|
||||||
right = true
|
|
||||||
}
|
|
||||||
|
|
||||||
login := m
|
login := m
|
||||||
login = nil
|
login = nil
|
||||||
|
|
||||||
for count := 0; count == 0; {
|
if !right {
|
||||||
order := -1
|
login = m.Spawn().Cmd("session").Appendv("login").(*ctx.Message)
|
||||||
if m.Option("componet_order") != "" {
|
}
|
||||||
order = m.Optioni("componet_order")
|
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 !right {
|
for count := 0; count == 0; group, order, right = "login", "", true {
|
||||||
login = m.Spawn().Cmd("session").Appendv("login").(*ctx.Message)
|
for _, v := range m.Confv("componet", group).([]interface{}) {
|
||||||
}
|
val := v.(map[string]interface{})
|
||||||
if !right && login != nil {
|
if order != "" && val["name"].(string) != order {
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, v := range m.Confv("componet", group).([]interface{}) {
|
|
||||||
if order != -1 && i != order {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val := v.(map[string]interface{})
|
|
||||||
|
|
||||||
order_right := right
|
order_right := right
|
||||||
if !order_right && login != nil {
|
if !order_right && login != nil {
|
||||||
if role := login.Confv("right", []interface{}{group, val["name"], "right", "role"}); role != nil && role.(string) == "share" {
|
if role := login.Confv("right", []interface{}{group, val["name"], "right", "role"}); role != nil && role.(string) == "share" {
|
||||||
@ -857,16 +878,21 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := m.Find(val["context"].(string))
|
context := m.Cap("module")
|
||||||
|
if val["context"] != nil {
|
||||||
|
context = val["context"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := m.Find(context)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
if !accept_json {
|
if !accept_json && val["template"] != nil {
|
||||||
m.Assert(tmpl.ExecuteTemplate(w, val["template"].(string), m))
|
m.Assert(tmpl.ExecuteTemplate(w, val["template"].(string), m))
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
|
||||||
msg.Option("componet_order", i)
|
msg.Option("componet_order", val["name"].(string))
|
||||||
|
|
||||||
for k, v := range val {
|
for k, v := range val {
|
||||||
if msg.Option(k) != "" {
|
if msg.Option(k) != "" {
|
||||||
@ -887,13 +913,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
for _, v := range val["arguments"].([]interface{}) {
|
for _, v := range val["arguments"].([]interface{}) {
|
||||||
switch value := v.(type) {
|
switch value := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
if len(value) > 1 && value[0] == '$' {
|
args = append(args, m.Parse(value))
|
||||||
args = append(args, msg.Cap(value[1:]))
|
|
||||||
} else if len(value) > 1 && value[0] == '@' {
|
|
||||||
args = append(args, msg.Confx(value[1:]))
|
|
||||||
} else {
|
|
||||||
args = append(args, value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -906,30 +926,22 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Cmd(val["command"], args); accept_json {
|
if val["command"] != nil {
|
||||||
|
msg.Cmd(val["command"], args)
|
||||||
|
}
|
||||||
|
|
||||||
|
if accept_json {
|
||||||
list = append(list, msg.Meta)
|
list = append(list, msg.Meta)
|
||||||
} else {
|
} else if val["template"] != nil {
|
||||||
m.Assert(tmpl.ExecuteTemplate(w, val["template"].(string), msg))
|
m.Assert(tmpl.ExecuteTemplate(w, val["template"].(string), msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Appends("sessid") {
|
if msg.Detail(0) == "login" && msg.Appends("sessid") {
|
||||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Append("sessid")})
|
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Append("sessid")})
|
||||||
m.Append("page_redirect", fmt.Sprintf("/render?componet_group=%s&componet_order=%s",
|
m.Append("page_refresh", "10")
|
||||||
m.Option("componet_group", m.Option("last_componet_group")),
|
|
||||||
m.Option("componet_order", m.Option("last_componet_order"))))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if count == 0 {
|
|
||||||
m.Option("last_componet_group", m.Option("componet_group"))
|
|
||||||
m.Option("last_componet_order", m.Option("componet_order"))
|
|
||||||
m.Option("componet_group", "login")
|
|
||||||
m.Option("componet_order", "-1")
|
|
||||||
group = m.Option("componet_group")
|
|
||||||
order = -1
|
|
||||||
right = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if accept_json {
|
if accept_json {
|
||||||
|
@ -65,6 +65,20 @@ function send_command(form, cb) {
|
|||||||
}
|
}
|
||||||
function onaction(event, action) {
|
function onaction(event, action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "click":
|
||||||
|
if (event.target.nodeName == "INPUT") {
|
||||||
|
if (event.altKey) {
|
||||||
|
event.target.focus()
|
||||||
|
event.target.select()
|
||||||
|
console.log("fuck")
|
||||||
|
console.log(document.execCommand("paste"))
|
||||||
|
// var clipboard = document.querySelector("#clipboard")
|
||||||
|
// clipboard.value = text
|
||||||
|
// clipboard.select()
|
||||||
|
// document.execCommand("copy")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
case "command":
|
case "command":
|
||||||
send_command(event.target.form)
|
send_command(event.target.form)
|
||||||
break
|
break
|
||||||
@ -148,10 +162,15 @@ function init_download(event) {
|
|||||||
if (!option) {
|
if (!option) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.querySelector("form.option.dir input[name=dir]").value = context.Search("download_dir")
|
||||||
|
|
||||||
option["dir"].value && send_command(option)
|
option["dir"].value && send_command(option)
|
||||||
|
|
||||||
var append = document.querySelector("table.append.dir")
|
var append = document.querySelector("table.append.dir")
|
||||||
|
append.onchange =
|
||||||
append.onclick = function(event) {
|
append.onclick = function(event) {
|
||||||
|
console.log(event)
|
||||||
if (event.target.tagName == "A") {
|
if (event.target.tagName == "A") {
|
||||||
if (event.target.dataset.type != "true") {
|
if (event.target.dataset.type != "true") {
|
||||||
location.href = option["dir"].value+"/"+event.target.innerText
|
location.href = option["dir"].value+"/"+event.target.innerText
|
||||||
@ -170,6 +189,7 @@ function init_download(event) {
|
|||||||
var sort_order = option["sort_order"]
|
var sort_order = option["sort_order"]
|
||||||
switch (event.target.innerText) {
|
switch (event.target.innerText) {
|
||||||
case "filename":
|
case "filename":
|
||||||
|
case "is_dir":
|
||||||
sort_order.value = (sort_order.value == "str")? "str_r": "str"
|
sort_order.value = (sort_order.value == "str")? "str_r": "str"
|
||||||
break
|
break
|
||||||
case "line":
|
case "line":
|
||||||
|
@ -1,4 +1,83 @@
|
|||||||
context = {
|
context = {
|
||||||
|
Search: function(key, value) {
|
||||||
|
var args = {};
|
||||||
|
var search = location.search.split("?");
|
||||||
|
if (search.length > 1) {
|
||||||
|
var searchs = search[1].split("&");
|
||||||
|
for (var i = 0; i < searchs.length; i++) {
|
||||||
|
var keys = searchs[i].split("=");
|
||||||
|
args[keys[0]] = decodeURIComponent(keys[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == undefined) {
|
||||||
|
return args
|
||||||
|
} else if (typeof key == "object") {
|
||||||
|
for (var k in key) {
|
||||||
|
if (key[k] != undefined) {
|
||||||
|
args[k] = key[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (value == undefined) {
|
||||||
|
return args[key] || this.Cookie(key);
|
||||||
|
} else {
|
||||||
|
args[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var arg = [];
|
||||||
|
for (var k in args) {
|
||||||
|
arg.push(k+"="+encodeURIComponent(args[k]));
|
||||||
|
}
|
||||||
|
location.search = arg.join("&");
|
||||||
|
},
|
||||||
|
Cookie: function(key, value) {
|
||||||
|
if (key == undefined) {
|
||||||
|
cs = {}
|
||||||
|
cookies = document.cookie.split("; ")
|
||||||
|
for (var i = 0; i < cookies.length; i++) {
|
||||||
|
cookie = cookies[i].split("=")
|
||||||
|
cs[cookie[0]] = cookie[1]
|
||||||
|
}
|
||||||
|
return cs
|
||||||
|
}
|
||||||
|
if (typeof key == "object") {
|
||||||
|
for (var k in key) {
|
||||||
|
document.cookie = k+"="+key[k];
|
||||||
|
}
|
||||||
|
return this.Cookie()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == undefined) {
|
||||||
|
var pattern = new RegExp(key+"=([^;]*);?");
|
||||||
|
var result = pattern.exec(document.cookie);
|
||||||
|
if (result && result.length > 0) {
|
||||||
|
return result[1];
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
document.cookie = key+"="+value;
|
||||||
|
return this.Cookie(key);
|
||||||
|
},
|
||||||
|
Cache: function(key, cb, sync) {
|
||||||
|
if (key == undefined) {
|
||||||
|
return this.cache
|
||||||
|
}
|
||||||
|
if (this.cache && !sync) {
|
||||||
|
typeof cb == "function" && cb(this.cache[key])
|
||||||
|
return this.cache[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
var that = this
|
||||||
|
this.GET("", {"componet_group": "login", "componet_order": "userinfo"}, function(msg) {
|
||||||
|
msg = msg[0]
|
||||||
|
that.cache = {}
|
||||||
|
for (var i = 0; i < msg.append.length; i++) {
|
||||||
|
that.cache[msg.append[i]] = msg[msg.append[i]].join("")
|
||||||
|
}
|
||||||
|
typeof cb == "function" && cb(that.cache[key])
|
||||||
|
})
|
||||||
|
},
|
||||||
GET: function(url, form, cb) {
|
GET: function(url, form, cb) {
|
||||||
form = form || {}
|
form = form || {}
|
||||||
|
|
||||||
@ -39,6 +118,8 @@ context = {
|
|||||||
msg.result && console.log(msg.result.join(""));
|
msg.result && console.log(msg.result.join(""));
|
||||||
if (msg.page_redirect) {
|
if (msg.page_redirect) {
|
||||||
location.href = msg.page_redirect.join("")
|
location.href = msg.page_redirect.join("")
|
||||||
|
} else if (msg.page_refresh) {
|
||||||
|
location.reload()
|
||||||
}
|
}
|
||||||
typeof cb == "function" && cb(msg)
|
typeof cb == "function" && cb(msg)
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,8 @@
|
|||||||
<body onkeyup="return onaction(event, 'keymap')">
|
<body onkeyup="return onaction(event, 'keymap')">
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{define "void"}}{{end}}
|
||||||
|
|
||||||
{{define "detail"}}{{detail .}}{{end}}
|
{{define "detail"}}{{detail .}}{{end}}
|
||||||
{{define "option"}}{{option .}}{{end}}
|
{{define "option"}}{{option .}}{{end}}
|
||||||
{{define "append"}}{{append .}}{{end}}
|
{{define "append"}}{{append .}}{{end}}
|
||||||
@ -73,8 +75,18 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{define "upload"}}
|
||||||
|
<fieldset><legend>clipboard</legend>
|
||||||
|
<form
|
||||||
|
>
|
||||||
|
<file></file>
|
||||||
|
</form>
|
||||||
|
</fieldset>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{define "componet"}}
|
{{define "componet"}}
|
||||||
<fieldset><legend title="{{option .Meta "help"}}">{{option .Meta "help"}}({{option .Meta "command"}}.{{option .Meta "context"}})</legend>
|
<fieldset><legend title="{{option .Meta "help"}}">{{option .Meta "help"}}({{option .Meta "command"}}.{{option .Meta "context"}})</legend>
|
||||||
|
{{$form_type := option . "form_type"|meta}}
|
||||||
<form class="option {{option .Meta "name"}}"
|
<form class="option {{option .Meta "name"}}"
|
||||||
data-last_componet_group="{{option . "last_componet_group"|meta}}"
|
data-last_componet_group="{{option . "last_componet_group"|meta}}"
|
||||||
data-last_componet_order="{{option . "last_componet_order"|meta}}"
|
data-last_componet_order="{{option . "last_componet_order"|meta}}"
|
||||||
@ -82,6 +94,9 @@
|
|||||||
data-componet_order="{{option . "componet_order"|meta}}"
|
data-componet_order="{{option . "componet_order"|meta}}"
|
||||||
data-componet_name="{{option . "name"|meta}}"
|
data-componet_name="{{option . "name"|meta}}"
|
||||||
data-componet_help="{{option . "help"|meta}}"
|
data-componet_help="{{option . "help"|meta}}"
|
||||||
|
{{if eq $form_type "upload"}}
|
||||||
|
method="POST" action="/upload" enctype="multipart/form-data"
|
||||||
|
{{end}}
|
||||||
>
|
>
|
||||||
<input style="display:none"></input>
|
<input style="display:none"></input>
|
||||||
{{range $index, $input := option . "inputs"}}
|
{{range $index, $input := option . "inputs"}}
|
||||||
@ -89,6 +104,10 @@
|
|||||||
{{$type := index $input "type"}}
|
{{$type := index $input "type"}}
|
||||||
{{if eq $type "button"}}
|
{{if eq $type "button"}}
|
||||||
<input type="button" name="{{index $input "name"}}" value="{{index $input "value"}}" onclick="return onaction(event, 'command')">
|
<input type="button" name="{{index $input "name"}}" value="{{index $input "value"}}" onclick="return onaction(event, 'command')">
|
||||||
|
{{else if eq $type "submit"}}
|
||||||
|
<input type="submit" value="{{index $input "value"}}">
|
||||||
|
{{else if eq $type "file"}}
|
||||||
|
<input type="file" name="{{index $input "name"}}">
|
||||||
{{else if eq $type "choice"}}
|
{{else if eq $type "choice"}}
|
||||||
{{$default_value := index $input "value"}}
|
{{$default_value := index $input "value"}}
|
||||||
<label>{{index $input "label"}} : </label>
|
<label>{{index $input "label"}} : </label>
|
||||||
@ -104,7 +123,12 @@
|
|||||||
</select>
|
</select>
|
||||||
{{else}}
|
{{else}}
|
||||||
<label>{{index $input "label"}} : </label>
|
<label>{{index $input "label"}} : </label>
|
||||||
<input name="{{index $input "name"}}" value="{{index $input "value"}}" onkeyup="return onaction(event, 'input')" list="clipstack">
|
<input
|
||||||
|
name="{{index $input "name"}}"
|
||||||
|
value="{{index $input "value"}}"
|
||||||
|
list="clipstack"
|
||||||
|
onclick="return onaction(event, 'click')"
|
||||||
|
onkeyup="return onaction(event, 'input')">
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user