forked from x/ContextOS
opt aaa.session
Change-Id: Idb47c28ce118413be4004bea12d35e622410cdd0
This commit is contained in:
parent
41815ff0f5
commit
09d1de4b87
@ -43,9 +43,8 @@
|
||||
sub_parse content "" text\
|
||||
offset 0 limit 10
|
||||
|
||||
spide add 12306 "https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%s,%s&ts=%s,%s&flag=N,N,Y"\
|
||||
spide add 12306 "https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%s,%s&ts=%s,%s&date=2018-12-23&flag=N,N,Y"\
|
||||
"div.t-list table tr"\
|
||||
date $(time $(time) time_format "2006-01-02") \
|
||||
sub_parse content "" text\
|
||||
offset 0 limit 10
|
||||
|
||||
|
@ -121,37 +121,109 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
Commands: map[string]*ctx.Command{
|
||||
"session": &ctx.Command{Name: "session create", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Spawn().Cmd("config", "session").Cmd("select", "parse", "value", "", "fields", "key type meta ship").CopyTo(m)
|
||||
m.Spawn().Cmd("config", "session").Cmd("select", "parse", "value", "", "fields", "key type meta ship data").CopyTo(m)
|
||||
return
|
||||
}
|
||||
|
||||
// 会话
|
||||
s, t := "", ""
|
||||
if len(arg) > 0 && arg[0] == "create" {
|
||||
s := Session(arg[1])
|
||||
s, t = Session(arg[1]), "session"
|
||||
m.Confv("session", s, map[string]interface{}{
|
||||
"create_time": time.Now().Unix(),
|
||||
"type": "session",
|
||||
"meta": arg[1],
|
||||
})
|
||||
m.Echo(s)
|
||||
return
|
||||
|
||||
if arg = arg[2:]; len(arg) == 0 {
|
||||
m.Echo(s)
|
||||
return
|
||||
}
|
||||
}
|
||||
if v, ok := m.Confv("session", []interface{}{arg[0], "type"}).(string); ok {
|
||||
s, t, arg = arg[0], v, arg[1:]
|
||||
}
|
||||
|
||||
s, arg := arg[0], arg[1:]
|
||||
// 属性
|
||||
which := "data"
|
||||
if len(arg) > 0 {
|
||||
switch arg[0] {
|
||||
case "data", "ship", "":
|
||||
which, arg = arg[0], arg[1:]
|
||||
}
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
m.Spawn().Cmd("config", "session", s).CopyTo(m)
|
||||
args := []string{s}
|
||||
if which != "" {
|
||||
args = append(args, which)
|
||||
}
|
||||
m.Spawn().Cmd("config", "session", strings.Join(args, ".")).CopyTo(m)
|
||||
return
|
||||
}
|
||||
|
||||
if len(arg) > 0 && arg[0] == "ip" {
|
||||
h := Hash("ip: %s", arg[0])
|
||||
m.Confv("session", h, map[string]interface{}{
|
||||
"create_time": time.Now().Unix(),
|
||||
"type": "ip",
|
||||
"meta": arg[1],
|
||||
"ship": map[string]interface{}{s: true},
|
||||
})
|
||||
m.Confv("session", []interface{}{s, "ship", h}, true)
|
||||
return
|
||||
switch which {
|
||||
case "data": // 数据
|
||||
if len(arg) == 1 {
|
||||
m.Spawn().Cmd("config", "session", strings.Join([]string{s, "data", arg[0]}, ".")).CopyTo(m)
|
||||
for k, _ := range m.Confv("session", []interface{}{s, "ship"}).(map[string]interface{}) {
|
||||
if len(m.Meta["result"]) > 0 || len(m.Meta["append"]) > 0 {
|
||||
break
|
||||
}
|
||||
m.Spawn().Cmd("config", "session", strings.Join([]string{k, "data", arg[0]}, ".")).CopyTo(m)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
m.Spawn().Cmd("config", "session", strings.Join([]string{s, "data", arg[0]}, "."), arg[1]).CopyTo(m)
|
||||
break
|
||||
case "ship": // 节点
|
||||
if len(arg) == 1 {
|
||||
for k, _ := range m.Confv("session", []interface{}{s, "ship"}).(map[string]interface{}) {
|
||||
if auth, ok := m.Confv("session", k).(map[string]interface{}); ok {
|
||||
if auth["type"].(string) == arg[0] {
|
||||
m.Add("append", "key", k)
|
||||
m.Add("append", "type", auth["type"])
|
||||
m.Add("append", "meta", auth["meta"])
|
||||
}
|
||||
}
|
||||
}
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
p, condition := s, ""
|
||||
for i := 0; i < len(arg)-1; i += 2 {
|
||||
switch arg[i] {
|
||||
case "password":
|
||||
if t == "session" {
|
||||
break
|
||||
}
|
||||
fallthrough
|
||||
default:
|
||||
h := Hash("%s%s: %s", condition, arg[i], arg[i+1])
|
||||
if sess := m.Confv("session", h); sess == nil {
|
||||
m.Confv("session", h, map[string]interface{}{
|
||||
"create_time": time.Now().Unix(),
|
||||
"type": arg[i],
|
||||
"meta": arg[i+1],
|
||||
"ship": map[string]interface{}{p: map[string]interface{}{
|
||||
"level": 0,
|
||||
"type": t,
|
||||
}},
|
||||
})
|
||||
}
|
||||
m.Confv("session", []interface{}{s, "ship", h}, map[string]interface{}{
|
||||
"level": 2,
|
||||
"type": arg[i],
|
||||
})
|
||||
m.Confv("session", []interface{}{p, "ship", h}, map[string]interface{}{
|
||||
"level": 1,
|
||||
"type": arg[i],
|
||||
})
|
||||
p, t = h, arg[i]
|
||||
}
|
||||
}
|
||||
m.Echo(p)
|
||||
}
|
||||
}},
|
||||
|
||||
|
@ -3259,7 +3259,6 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
case float64:
|
||||
m.Echo("%d", int(val))
|
||||
case nil:
|
||||
m.Echo("")
|
||||
default:
|
||||
b, _ := json.Marshal(val)
|
||||
m.Echo("%s", string(b))
|
||||
|
@ -97,6 +97,7 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
||||
msg.Option("index_path", r.Header.Get("index_path"))
|
||||
msg.Option("index_url", r.Header.Get("index_url"))
|
||||
msg.Option("remote_addr", r.RemoteAddr)
|
||||
msg.Option("remote_ip", strings.Split(r.RemoteAddr, ":"))
|
||||
msg.Option("dir_root", m.Cap("directory"))
|
||||
msg.Option("referer", r.Header.Get("Referer"))
|
||||
msg.Option("accept", r.Header.Get("Accept"))
|
||||
@ -141,6 +142,12 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
||||
}
|
||||
}
|
||||
|
||||
if false {
|
||||
if !msg.Sess("aaa").Cmd("session", msg.Option("session"), "ship", "ip").Results(0) {
|
||||
msg.Sess("aaa").Cmd("session", "create", "web", "ship", "ip", m.Option("remote_ip"))
|
||||
}
|
||||
}
|
||||
|
||||
msg.Log("cmd", "%s [] %v", key, msg.Meta["option"])
|
||||
msg.Put("option", "request", r).Put("option", "response", w)
|
||||
cmd.Hand(msg, msg.Target(), msg.Option("path"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user