forked from x/ContextOS
opt aaa
Change-Id: Ice106fec6aa5077cf5a527f026c673bce2b91b7b
This commit is contained in:
parent
084d8797fb
commit
ec4540e8ee
@ -124,14 +124,10 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
"auth": &ctx.Config{Name: "auth", Value: map[string]interface{}{}, Help: "散列"},
|
"auth": &ctx.Config{Name: "auth", Value: map[string]interface{}{}, Help: "散列"},
|
||||||
"auth_expire": &ctx.Config{Name: "auth_expire", Value: "10m", Help: "权限超时"},
|
"auth_expire": &ctx.Config{Name: "auth_expire", Value: "10m", Help: "权限超时"},
|
||||||
"auth_type": &ctx.Config{Name: "auth_type", Value: map[string]interface{}{
|
"auth_type": &ctx.Config{Name: "auth_type", Value: map[string]interface{}{
|
||||||
"session": map[string]interface{}{"unique": true},
|
"unique": map[string]interface{}{"session": true, "bench": true},
|
||||||
"bench": map[string]interface{}{"unique": true},
|
"public": map[string]interface{}{"userrole": true, "username": true, "cert": true},
|
||||||
"cert": map[string]interface{}{"public": true},
|
"single": map[string]interface{}{"password": true, "token": true, "uuid": true, "ppid": true},
|
||||||
"username": map[string]interface{}{"public": true},
|
"secrete": map[string]interface{}{"password": true, "token": true, "uuid": true, "ppid": true},
|
||||||
"userrole": map[string]interface{}{"public": true},
|
|
||||||
"password": map[string]interface{}{"secrete": true, "single": true},
|
|
||||||
"uuid": map[string]interface{}{"secrete": true, "single": true},
|
|
||||||
"ppid": map[string]interface{}{"secrete": true, "single": true},
|
|
||||||
}, Help: "散列"},
|
}, Help: "散列"},
|
||||||
|
|
||||||
"secrete_key": &ctx.Config{Name: "secrete_key", Value: map[string]interface{}{"password": 1, "uuid": 1}, Help: "私钥文件"},
|
"secrete_key": &ctx.Config{Name: "secrete_key", Value: map[string]interface{}{"password": 1, "uuid": 1}, Help: "私钥文件"},
|
||||||
@ -160,472 +156,468 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
m.Echo(hs)
|
m.Echo(hs)
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"auth": &ctx.Command{Name: "auth [id] [[ship] type [meta]] [[data] key [val]] [[node] key [val]]", Help: "权限区块链", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"auth": &ctx.Command{Name: "auth [id] [delete data|ship|node] [[ship] type [meta]] [[data] key [val]] [[node] key [val]]",
|
||||||
if len(arg) == 0 { // 节点列表
|
Help: "权限区块链", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
m.Confm("auth", func(key string, node map[string]interface{}) {
|
if len(arg) == 0 { // 节点列表
|
||||||
up := false
|
m.Confm("auth", func(key string, node map[string]interface{}) {
|
||||||
if ship, ok := node["ship"].(map[string]interface{}); ok {
|
up := false
|
||||||
for k, v := range ship {
|
if ship, ok := node["ship"].(map[string]interface{}); ok {
|
||||||
val := v.(map[string]interface{})
|
for k, v := range ship {
|
||||||
switch val["ship"].(string) {
|
val := v.(map[string]interface{})
|
||||||
case "0":
|
switch val["ship"].(string) {
|
||||||
if !up {
|
case "0":
|
||||||
up = true
|
if !up {
|
||||||
m.Add("append", "up_key", k)
|
up = true
|
||||||
m.Add("append", "up_type", val["type"])
|
m.Add("append", "up_key", k)
|
||||||
|
m.Add("append", "up_type", val["type"])
|
||||||
|
m.Add("append", "up_ship", val["ship"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if !up {
|
||||||
if !up {
|
m.Add("append", "up_key", "")
|
||||||
m.Add("append", "up_key", "")
|
m.Add("append", "up_type", "")
|
||||||
m.Add("append", "up_type", "")
|
m.Add("append", "up_ship", "")
|
||||||
}
|
|
||||||
m.Add("append", "key", key)
|
|
||||||
m.Add("append", "type", node["type"])
|
|
||||||
m.Add("append", "meta", node["meta"])
|
|
||||||
})
|
|
||||||
m.Table()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s, t, a := "", "", ""
|
|
||||||
if v := m.Confm("auth", arg[0]); v != nil {
|
|
||||||
s, t, a, arg = arg[0], kit.Format(v["type"]), kit.Format(v["meta"]), arg[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) > 0 && arg[0] == "delete" {
|
|
||||||
switch arg[1] {
|
|
||||||
case "data":
|
|
||||||
if data := m.Confm("auth", []string{s, "data"}); data != nil {
|
|
||||||
for _, k := range arg[2:] {
|
|
||||||
m.Log("info", "delete data %s %s %v", s, k, kit.Formats(data[k]))
|
|
||||||
delete(data, k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "ship":
|
|
||||||
if ship := m.Confm("auth", []string{s, "ship"}); ship != nil {
|
|
||||||
for _, k := range arg[2:] {
|
|
||||||
if val, ok := ship[k].(map[string]interface{}); ok {
|
|
||||||
m.Add("append", "key", k)
|
|
||||||
m.Add("append", "ship", val["ship"])
|
|
||||||
m.Add("append", "type", val["type"])
|
|
||||||
m.Add("append", "meta", val["meta"])
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Log("info", "delete ship %s %s %v", s, k, kit.Formats(ship[k]))
|
|
||||||
delete(ship, k)
|
|
||||||
if peer := m.Confm("auth", []string{k, "ship"}); peer != nil {
|
|
||||||
m.Log("info", "delete ship %s %s %v", k, s, kit.Formats(peer[s]))
|
|
||||||
delete(peer, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.Table()
|
|
||||||
}
|
|
||||||
case "node":
|
|
||||||
if ship := m.Confm("auth", []string{s, "ship"}); ship != nil {
|
|
||||||
for k, _ := range ship {
|
|
||||||
if val, ok := ship[k].(map[string]interface{}); ok {
|
|
||||||
m.Add("append", "key", k)
|
|
||||||
m.Add("append", "ship", val["ship"])
|
|
||||||
m.Add("append", "type", val["type"])
|
|
||||||
m.Add("append", "meta", val["meta"])
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Log("info", "delete ship %s %s %v", s, k, kit.Formats(ship[k]))
|
|
||||||
delete(ship, k)
|
|
||||||
if peer := m.Confm("auth", []string{k, "ship"}); peer != nil {
|
|
||||||
m.Log("info", "delete ship %s %s %v", k, s, kit.Formats(peer[s]))
|
|
||||||
delete(peer, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m.Log("info", "delete node %s %v", s, kit.Formats(m.Confm("auth", s)))
|
|
||||||
delete(m.Confm("auth"), s)
|
|
||||||
m.Table()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) == 0 { // 查看节点
|
|
||||||
m.Echo(t)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
p, route, block, chain := s, "ship", []map[string]string{}, []map[string]string{}
|
|
||||||
for i := 0; i < len(arg); i += 2 {
|
|
||||||
if p == "" {
|
|
||||||
m.Confm("auth", func(k string, node map[string]interface{}) {
|
|
||||||
if strings.HasSuffix(k, arg[i]) || strings.HasPrefix(k, arg[i]) {
|
|
||||||
arg[i] = k
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
|
|
||||||
if strings.HasSuffix(k, arg[i]) || strings.HasPrefix(k, arg[i]) {
|
|
||||||
arg[i] = k
|
|
||||||
}
|
}
|
||||||
|
m.Add("append", "key", key)
|
||||||
|
m.Add("append", "type", node["type"])
|
||||||
|
m.Add("append", "meta", node["meta"])
|
||||||
})
|
})
|
||||||
|
m.Table()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if node := m.Confm("auth", arg[i]); node != nil {
|
s, t, a := "", "", ""
|
||||||
if i++; p != "" { // 添加链接
|
if v := m.Confm("auth", arg[0]); v != nil {
|
||||||
d, e := time.ParseDuration(m.Conf("auth_expire"))
|
s, t, a, arg = arg[0], kit.Format(v["type"]), kit.Format(v["meta"]), arg[1:]
|
||||||
m.Assert(e)
|
}
|
||||||
expire := time.Now().Add(d).Unix()
|
if len(arg) == 0 { // 查看节点
|
||||||
m.Confv("auth", []string{p, "ship", arg[i-1]}, map[string]interface{}{
|
m.Echo(t)
|
||||||
"create_time": m.Time(), "type": node["type"], "meta": node["meta"], "ship": "4", "expire_time": expire,
|
return
|
||||||
})
|
|
||||||
|
|
||||||
m.Confv("auth", []string{arg[i-1], "ship", p}, map[string]interface{}{
|
|
||||||
"create_time": m.Time(), "type": t, "meta": a, "ship": "5", "expire_time": expire,
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
p, t, a = arg[i-1], node["type"].(string), node["meta"].(string)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i < len(arg) {
|
p, route, block, chain := s, "ship", []map[string]string{}, []map[string]string{}
|
||||||
switch arg[i] { // 切换类型
|
for i := 0; i < len(arg); i += 2 {
|
||||||
case "data", "node", "ship":
|
if node := m.Confm("auth", arg[i]); node != nil {
|
||||||
route, i = arg[i], i+1
|
if i++; p != "" { // 朋友链接
|
||||||
}
|
expire := kit.Int(m.Time(m.Conf("auth_expire"), "stamp"))
|
||||||
}
|
m.Confv("auth", []string{arg[i-1], "ship", p}, map[string]interface{}{
|
||||||
|
"create_time": m.Time(), "expire_time": expire,
|
||||||
if p == "" && route != "ship" {
|
"type": t, "meta": a, "ship": "5",
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
switch route {
|
|
||||||
case "ship": // 链接操作
|
|
||||||
if i > len(arg)-1 {
|
|
||||||
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
|
|
||||||
if node := m.Confm("auth", k); node != nil {
|
|
||||||
m.Add("append", "key", k)
|
|
||||||
m.Add("append", "ship", ship["ship"])
|
|
||||||
m.Add("append", "type", node["type"])
|
|
||||||
m.Add("append", "meta", node["meta"])
|
|
||||||
m.Add("append", "create_time", node["create_time"])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
m.Set("result").Table()
|
|
||||||
break
|
|
||||||
} else if i == len(arg)-1 { // 读取链接
|
|
||||||
if p == "" {
|
|
||||||
m.Confm("auth", func(k string, node map[string]interface{}) {
|
|
||||||
if node["type"].(string) == arg[i] || strings.HasSuffix(k, arg[i]) || strings.HasPrefix(k, arg[i]) {
|
|
||||||
m.Add("append", "key", k)
|
|
||||||
m.Add("append", "type", node["type"])
|
|
||||||
m.Add("append", "meta", node["meta"])
|
|
||||||
m.Add("append", "create_time", node["create_time"])
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
} else {
|
m.Confv("auth", []string{p, "ship", arg[i-1]}, map[string]interface{}{
|
||||||
if node := m.Confm("auth", []string{arg[i]}); node != nil {
|
"create_time": m.Time(), "expire_time": expire,
|
||||||
m.Confv("auth", []string{p, "ship", arg[i]}, node)
|
"type": node["type"], "meta": node["meta"], "ship": "4",
|
||||||
}
|
|
||||||
|
|
||||||
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
|
|
||||||
if node := m.Confm("auth", k); ship["type"].(string) == arg[i] || strings.HasSuffix(k, arg[i]) || strings.HasPrefix(k, arg[i]) {
|
|
||||||
m.Add("append", "key", k)
|
|
||||||
m.Add("append", "ship", ship["ship"])
|
|
||||||
m.Add("append", "type", node["type"])
|
|
||||||
m.Add("append", "meta", node["meta"])
|
|
||||||
m.Add("append", "create_time", node["create_time"])
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
m.Set("result").Table()
|
p, t, a = arg[i-1], node["type"].(string), node["meta"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
if i < len(arg) {
|
||||||
|
switch arg[i] { // 切换类型
|
||||||
|
case "data", "node", "ship":
|
||||||
|
route, i = arg[i], i+1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if p == "" && route != "ship" {
|
||||||
return
|
return
|
||||||
} else if i == len(arg)-2 {
|
}
|
||||||
if p != "" && arg[i] == "session" {
|
|
||||||
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
|
switch route {
|
||||||
if node := m.Confm("auth", k); ship["type"].(string) == arg[i] && (ship["meta"] == arg[i+1] || strings.HasSuffix(k, arg[i+1]) || strings.HasPrefix(k, arg[i+1])) {
|
case "ship": // 链接操作
|
||||||
m.Add("append", "key", k)
|
if i >= len(arg)-1 {
|
||||||
m.Add("append", "ship", ship["ship"])
|
if p == "" { // 节点列表
|
||||||
m.Add("append", "type", node["type"])
|
m.Confm("auth", func(k string, node map[string]interface{}) {
|
||||||
m.Add("append", "meta", node["meta"])
|
if i > len(arg)-1 || node["type"].(string) == arg[i] || strings.HasSuffix(k, arg[i]) || strings.HasPrefix(k, arg[i]) {
|
||||||
m.Add("append", "create_time", node["create_time"])
|
m.Add("append", "create_time", node["create_time"])
|
||||||
|
m.Add("append", "key", k)
|
||||||
|
m.Add("append", "type", node["type"])
|
||||||
|
m.Add("append", "meta", node["meta"])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else { // 链接列表
|
||||||
|
if i == len(arg)-1 {
|
||||||
|
m.Confm("auth", []string{arg[i]}, func(node map[string]interface{}) {
|
||||||
|
m.Confv("auth", []string{p, "ship", arg[i]}, node)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
m.Set("result").Table()
|
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
|
||||||
|
if node := m.Confm("auth", k); i > len(arg)-1 || ship["type"].(string) == arg[i] || strings.HasSuffix(k, arg[i]) || strings.HasPrefix(k, arg[i]) {
|
||||||
|
m.Add("append", "create_time", node["create_time"])
|
||||||
|
m.Add("append", "key", k)
|
||||||
|
m.Add("append", "ship", ship["ship"])
|
||||||
|
m.Add("append", "type", node["type"])
|
||||||
|
m.Add("append", "meta", node["meta"])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
m.Sort("create_time", "time_r").Set("result").Table()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if arg[i] == "check" {
|
// 删除链接
|
||||||
has := "false"
|
if arg[i] == "delete" {
|
||||||
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
|
m.Confm("auth", []string{p, "ship"}, func(ship map[string]interface{}) {
|
||||||
if i == len(arg)-2 && (ship["meta"] != arg[i+1] || k != arg[i+1]) {
|
for _, k := range arg[i+1:] {
|
||||||
return
|
m.Confm("auth", []string{k, "ship"}, func(peer map[string]interface{}) {
|
||||||
}
|
m.Log("info", "delete peer %s %s %s", k, s, kit.Formats(peer[s]))
|
||||||
if i == len(arg)-3 && (ship["type"] != arg[i+1] || ship["meta"] != arg[i+2]) {
|
delete(peer, s)
|
||||||
return
|
})
|
||||||
}
|
m.Log("info", "delete ship %s %s %s", s, k, kit.Formats(ship[k]))
|
||||||
|
delete(ship, k)
|
||||||
if ship["expire_time"] == nil || int64(kit.Int(ship["expire_time"])) > time.Now().Unix() {
|
|
||||||
has = k
|
|
||||||
}
|
|
||||||
})
|
|
||||||
m.Set("result").Echo(has)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
meta := []string{arg[i]}
|
|
||||||
if m.Confs("auth_type", []string{arg[i], "secrete"}) {
|
|
||||||
meta = append(meta, Password(arg[i+1])) // 加密节点
|
|
||||||
} else {
|
|
||||||
meta = append(meta, arg[i+1])
|
|
||||||
}
|
|
||||||
if t != "session" && !m.Confs("auth_type", []string{arg[i], "public"}) {
|
|
||||||
meta = append(meta, p) // 私有节点
|
|
||||||
}
|
|
||||||
if m.Confs("auth_type", []string{arg[i], "unique"}) {
|
|
||||||
meta = append(meta, "time", "rand") // 惟一节点
|
|
||||||
}
|
|
||||||
|
|
||||||
h := m.Cmdx("aaa.hash", meta)
|
|
||||||
if !m.Confs("auth", h) {
|
|
||||||
if m.Confs("auth_type", []string{arg[i], "single"}) && m.Confs("auth", p) && m.Cmds("aaa.auth", p, arg[i]) {
|
|
||||||
m.Set("result")
|
|
||||||
return // 单点认证失败
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建节点
|
|
||||||
block = append(block, map[string]string{"hash": h, "type": arg[i], "meta": meta[1]})
|
|
||||||
}
|
|
||||||
|
|
||||||
if s != "" { // 创建根链接
|
|
||||||
chain = append(chain, map[string]string{"node": s, "ship": "3", "hash": h, "type": arg[i], "meta": meta[1]})
|
|
||||||
chain = append(chain, map[string]string{"node": h, "ship": "2", "hash": s, "type": arg[i], "meta": meta[1]})
|
|
||||||
}
|
|
||||||
if p != "" { // 创建父链接
|
|
||||||
chain = append(chain, map[string]string{"node": p, "ship": "1", "hash": h, "type": arg[i], "meta": meta[1]})
|
|
||||||
chain = append(chain, map[string]string{"node": h, "ship": "0", "hash": p, "type": t, "meta": a})
|
|
||||||
}
|
|
||||||
|
|
||||||
p, t, a = h, arg[i], meta[1]
|
|
||||||
m.Echo(h)
|
|
||||||
case "node": // 节点操作
|
|
||||||
if i > len(arg)-1 { // 查看节点
|
|
||||||
m.Cmdy("aaa.config", "auth", p)
|
|
||||||
return
|
|
||||||
} else if i == len(arg)-1 { // 查询节点
|
|
||||||
ps := []string{p}
|
|
||||||
for j := 0; j < len(ps); j++ {
|
|
||||||
if value := m.Confv("auth", []string{ps[j], arg[i]}); value != nil {
|
|
||||||
m.Put("option", "data", value).Cmdy("ctx.trans", "data")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Confm("auth", []string{ps[j], "ship"}, func(key string, ship map[string]interface{}) {
|
|
||||||
if ship["ship"] != "0" {
|
|
||||||
ps = append(ps, key)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
} else { // 修改节点
|
|
||||||
m.Confv("auth", []string{p, arg[i]}, arg[i+1])
|
|
||||||
}
|
|
||||||
case "data": // 数据操作
|
|
||||||
if i > len(arg)-1 { // 查看数据
|
|
||||||
m.Cmdy("ctx.config", "auth", strings.Join([]string{p, "data"}, "."))
|
|
||||||
return
|
|
||||||
} else if i == len(arg)-1 { // 相询数据
|
|
||||||
ps := []string{p}
|
|
||||||
for j := 0; j < len(ps); j++ {
|
|
||||||
if value := m.Confv("auth", []string{ps[j], "data", arg[i]}); value != nil {
|
|
||||||
m.Set("append").Set("result").Put("option", "data", value).Cmdy("ctx.trans", "data")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Confm("auth", []string{ps[j], "ship"}, func(key string, ship map[string]interface{}) {
|
// 检查链接
|
||||||
if ship["ship"] != "0" {
|
if arg[i] == "check" {
|
||||||
ps = append(ps, key)
|
has := "false"
|
||||||
|
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
|
||||||
|
if i == len(arg)-2 && (ship["meta"] != arg[i+1] && k != arg[i+1]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if i == len(arg)-3 && (ship["type"] != arg[i+1] || ship["meta"] != arg[i+2]) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ship["expire_time"] == nil || int64(kit.Int(ship["expire_time"])) > time.Now().Unix() {
|
||||||
|
has = k
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
m.Set("result").Echo(has)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
} else { // 修改数据
|
meta := []string{arg[i]}
|
||||||
if arg[i] == "option" {
|
|
||||||
m.Confv("auth", []string{p, "data", arg[i+1]}, m.Optionv(arg[i+1]))
|
// 加密节点
|
||||||
|
if m.Confs("auth_type", []string{"secrete", arg[i]}) {
|
||||||
|
meta = append(meta, Password(arg[i+1]))
|
||||||
} else {
|
} else {
|
||||||
m.Confv("auth", []string{p, "data", arg[i]}, arg[i+1])
|
meta = append(meta, arg[i+1])
|
||||||
}
|
}
|
||||||
|
// 私有节点
|
||||||
|
if !m.Confs("auth_type", []string{"public", arg[i]}) {
|
||||||
|
if m.Confs("auth_type", []string{"unique", arg[i]}) {
|
||||||
|
meta = append(meta, "uniq")
|
||||||
|
} else {
|
||||||
|
meta = append(meta, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// h := m.Cmdx("aaa.hash", meta)
|
||||||
|
h, _ := kit.Hash(meta)
|
||||||
|
if !m.Confs("auth", h) {
|
||||||
|
m.Set("result")
|
||||||
|
if m.Confs("auth_type", []string{"single", arg[i]}) && m.Confs("auth", p) && m.Cmds("aaa.auth", p, arg[i]) {
|
||||||
|
m.Log("fuck", "password %s", h)
|
||||||
|
return // 单点认证失败
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建节点
|
||||||
|
block = append(block, map[string]string{"hash": h, "type": arg[i], "meta": meta[1]})
|
||||||
|
m.Echo(h)
|
||||||
|
}
|
||||||
|
|
||||||
|
if s != "" { // 祖孙链接
|
||||||
|
chain = append(chain, map[string]string{"node": s, "ship": "3", "hash": h, "type": arg[i], "meta": meta[1]})
|
||||||
|
chain = append(chain, map[string]string{"node": h, "ship": "2", "hash": s, "type": arg[i], "meta": meta[1]})
|
||||||
|
}
|
||||||
|
if p != "" { // 父子链接
|
||||||
|
chain = append(chain, map[string]string{"node": p, "ship": "1", "hash": h, "type": arg[i], "meta": meta[1]})
|
||||||
|
chain = append(chain, map[string]string{"node": h, "ship": "0", "hash": p, "type": t, "meta": a})
|
||||||
|
}
|
||||||
|
|
||||||
|
p, t, a = h, arg[i], meta[1]
|
||||||
|
m.Echo(h)
|
||||||
|
case "node": // 节点操作
|
||||||
|
if i > len(arg)-1 { // 查看节点
|
||||||
|
m.Cmdy("aaa.config", "auth", p)
|
||||||
|
} else if arg[i] == "delete" { // 删除节点
|
||||||
|
m.Confm("auth", []string{p, "ship"}, func(ship map[string]interface{}) {
|
||||||
|
for k, _ := range ship {
|
||||||
|
m.Confm("auth", []string{k, "ship"}, func(peer map[string]interface{}) {
|
||||||
|
m.Log("info", "delete peer %s %s %s", k, s, kit.Formats(peer[s]))
|
||||||
|
delete(peer, s)
|
||||||
|
})
|
||||||
|
m.Log("info", "delete ship %s %s %s", s, k, kit.Formats(ship[k]))
|
||||||
|
delete(ship, k)
|
||||||
|
}
|
||||||
|
m.Log("info", "delete node %s %s", s, kit.Formats(m.Confm("auth", s)))
|
||||||
|
delete(m.Confm("auth"), s)
|
||||||
|
})
|
||||||
|
} else if i < len(arg)-1 { // 修改属性
|
||||||
|
m.Confv("auth", []string{p, arg[i]}, arg[i+1])
|
||||||
|
} else { // 搜索属性
|
||||||
|
ps := []string{p}
|
||||||
|
for j := 0; j < len(ps); j++ {
|
||||||
|
if value := m.Confv("auth", []string{ps[j], arg[i]}); value != nil {
|
||||||
|
m.Put("option", "data", value).Cmdy("ctx.trans", "data")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
m.Confm("auth", []string{ps[j], "ship"}, func(key string, ship map[string]interface{}) {
|
||||||
|
if ship["ship"] != "0" {
|
||||||
|
ps = append(ps, key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
case "data": // 数据操作
|
||||||
|
if i > len(arg)-1 { // 查看数据
|
||||||
|
m.Cmdy("ctx.config", "auth", strings.Join([]string{p, "data"}, "."))
|
||||||
|
} else if arg[i] == "delete" { // 删除数据
|
||||||
|
m.Confm("auth", []string{s, "data"}, func(data map[string]interface{}) {
|
||||||
|
for _, k := range arg[i+1:] {
|
||||||
|
m.Log("info", "delete data %s %s %s", s, k, kit.Formats(data[k]))
|
||||||
|
delete(data, k)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if i < len(arg)-1 { // 修改数据
|
||||||
|
if arg[i] == "option" {
|
||||||
|
m.Confv("auth", []string{p, "data", arg[i+1]}, m.Optionv(arg[i+1]))
|
||||||
|
} else {
|
||||||
|
m.Confv("auth", []string{p, "data", arg[i]}, arg[i+1])
|
||||||
|
}
|
||||||
|
m.Echo(arg[i+1])
|
||||||
|
} else { // 搜索数据
|
||||||
|
ps := []string{p}
|
||||||
|
for j := 0; j < len(ps); j++ {
|
||||||
|
if value := m.Confv("auth", []string{ps[j], "data", arg[i]}); value != nil {
|
||||||
|
m.Set("append").Set("result").Put("option", "data", value).Cmdy("ctx.trans", "data")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
m.Confm("auth", []string{ps[j], "ship"}, func(key string, ship map[string]interface{}) {
|
||||||
|
if ship["ship"] != "0" {
|
||||||
|
ps = append(ps, key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
m.Log("debug", "block: %v chain: %v", len(block), len(chain))
|
m.Log("debug", "block: %v chain: %v", len(block), len(chain))
|
||||||
for _, b := range block { // 添加节点
|
for _, b := range block { // 添加节点
|
||||||
m.Confv("auth", b["hash"], map[string]interface{}{"create_time": m.Time(), "type": b["type"], "meta": b["meta"]})
|
m.Confv("auth", b["hash"], map[string]interface{}{"create_time": m.Time(), "type": b["type"], "meta": b["meta"]})
|
||||||
}
|
|
||||||
for _, c := range chain { // 添加链接
|
|
||||||
m.Confv("auth", []interface{}{c["node"], "ship", c["hash"]}, map[string]interface{}{"ship": c["ship"], "type": c["type"], "meta": c["meta"]})
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
"role": &ctx.Command{Name: "role [name [[componet] name [[command] name]]]", Help: "用户角色",
|
|
||||||
Auto: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) bool {
|
|
||||||
switch len(arg) {
|
|
||||||
case 0: // 查看角色
|
|
||||||
Auto(m, "ship", "userrole")
|
|
||||||
case 1: // 查看组件
|
|
||||||
Auto(m, "ship", "userrole", arg[0], "componet")
|
|
||||||
case 2: // 查看功能
|
|
||||||
Auto(m, "ship", "userrole", arg[0], "componet", arg[1], "command")
|
|
||||||
}
|
}
|
||||||
return true
|
for _, c := range chain { // 添加链接
|
||||||
},
|
m.Confv("auth", []interface{}{c["node"], "ship", c["hash"]}, map[string]interface{}{"ship": c["ship"], "type": c["type"], "meta": c["meta"]})
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
}
|
||||||
switch len(arg) {
|
return
|
||||||
case 0: // 查看角色
|
}},
|
||||||
|
|
||||||
|
"role": &ctx.Command{Name: "role [name [componet [name [command [name]]]]|[user [name [password|uuid code]]]]",
|
||||||
|
Help: "用户角色, componet: 组件管理, user: 用户管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
if len(arg) == 0 { // 角色列表
|
||||||
m.Cmdy("aaa.auth", "ship", "userrole")
|
m.Cmdy("aaa.auth", "ship", "userrole")
|
||||||
case 1: // 查看组件
|
return
|
||||||
m.Cmdy("aaa.auth", "ship", "userrole", arg[0], "componet")
|
}
|
||||||
case 2: // 查看功能
|
|
||||||
m.Cmdy("aaa.auth", "ship", "userrole", arg[0], "componet", arg[1], "command")
|
role, arg := arg[0], arg[1:]
|
||||||
case 3: // 查看接口
|
switch arg[0] {
|
||||||
m.Cmdy("aaa.auth", "ship", "userrole", arg[0], "componet", arg[1], "command", arg[2], "componet")
|
case "componet", "command":
|
||||||
default: // 添加接口
|
componets, commands := []string{}, []string{}
|
||||||
if arg[1] == "componet" && arg[3] == "command" {
|
for i := 0; i < len(arg); i++ { // 解析参数
|
||||||
for _, v := range arg[4:] {
|
if arg[i] == "command" {
|
||||||
m.Cmdy("aaa.auth", "ship", "userrole", arg[0], "componet", arg[2], "command", v)
|
for i := i + 1; i < len(arg); i++ {
|
||||||
|
if arg[i] == "componet" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
commands = append(commands, arg[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if arg[i] == "componet" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
componets = append(componets, arg[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(componets) == 0 { // 查看组件
|
||||||
|
m.Cmdy("aaa.auth", "ship", "userrole", role, "componet")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := 0; i < len(componets); i++ {
|
||||||
|
if len(commands) == 0 { // 查看命令
|
||||||
|
m.Cmdy("aaa.auth", "ship", "userrole", role, "componet", componets[i], "command")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for j := 0; j < len(commands); j++ { // 添加命令
|
||||||
|
m.Cmd("aaa.auth", "ship", "userrole", role, "componet", componets[i], "command", commands[j])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case "user":
|
||||||
|
if len(arg) == 1 { // 查看用户
|
||||||
|
m.Cmdy("aaa.auth", "ship", "userrole", role, "username")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for i := 1; i < len(arg); i++ { // 添加用户
|
||||||
|
if m.Cmd("aaa.auth", "ship", "username", arg[i], "userrole", role); i < len(arg)-2 {
|
||||||
|
switch arg[i+1] {
|
||||||
|
case "password", "uuid":
|
||||||
|
m.Cmd("aaa.auth", "ship", "username", arg[i], arg[i+1], arg[i+2])
|
||||||
|
i += 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"user": &ctx.Command{Name: "user [role username password] [username password|uuid code] [username [sesstype]]", Help: "用户认证, 添加、认证、查询", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"user": &ctx.Command{Name: "user cookie [role]|[login [password|uuid [code]]]|[service [name [value]]]|[session [select|create]]",
|
||||||
if len(arg) > 0 && arg[0] == "session" {
|
Help: "用户认证, cookie: cookie管理, session: 会话管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
if len(arg) == 1 { // 查看会话
|
if len(arg) == 0 { // 查看用户
|
||||||
m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "session")
|
m.Cmdy("aaa.auth", "ship", "username")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch arg[1] {
|
|
||||||
case "select": // 选择会话
|
switch arg[0] {
|
||||||
defer func() { m.Log("info", "sessid: %s", m.Append("key")) }()
|
case "role": // 用户角色
|
||||||
if m.Options("sessid") && m.Cmds("aaa.auth", m.Option("sessid"), "ship", "check", "username", m.Option("username")) {
|
m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "userrole")
|
||||||
m.Add("append", "key", m.Option("sessid")).Table()
|
|
||||||
|
case "login": // 用户登录
|
||||||
|
m.Cmdy("aaa.auth", "username", m.Option("username"), arg[1], arg[2])
|
||||||
|
|
||||||
|
case "cookie":
|
||||||
|
if len(arg) > 3 { // 设置cookie
|
||||||
|
m.Cmdy("aaa.auth", "username", m.Option("username"), "data", strings.Join(arg[:3], "."), arg[3])
|
||||||
|
arg = arg[:3]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查看cookie
|
||||||
|
m.Cmdy("aaa.auth", "username", m.Option("username"), "data", strings.Join(arg, "."))
|
||||||
|
case "session":
|
||||||
|
if len(arg) == 1 { // 查看会话
|
||||||
|
m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "session")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "session"); m.Appends("key") {
|
|
||||||
return
|
switch arg[1] {
|
||||||
|
case "select": // 选择会话
|
||||||
|
defer func() { m.Log("info", "sessid: %s", m.Result(0)) }()
|
||||||
|
|
||||||
|
if m.Options("sessid") && m.Cmds("aaa.auth", "ship", "username", m.Option("username"), "check", m.Option("sessid")) {
|
||||||
|
m.Echo(m.Option("sessid"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "session"); m.Appends("key") {
|
||||||
|
m.Set("result").Echo(m.Append("key"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fallthrough
|
||||||
|
case "create": // 创建会话
|
||||||
|
m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "session", kit.Select("web", arg, 2))
|
||||||
|
m.Cmd("aaa.auth", m.Result(0), "data", "current.ctx", "mdb")
|
||||||
}
|
}
|
||||||
fallthrough
|
|
||||||
case "create": // 创建会话
|
|
||||||
m.Cmdy("aaa.auth", "ship", "session", kit.Select("web", arg, 2), "username", m.Option("username"))
|
|
||||||
m.Cmd("aaa.auth", m.Result(0), "data", "current.ctx", "mdb")
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}},
|
||||||
|
"sess": &ctx.Command{Name: "sess [sessid] [current [pod|ctx|dir|env [value]]]|[bench [select|create]]",
|
||||||
switch len(arg) {
|
Help: "会话管理, current: 指针管理, bench: 空间管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
case 0: // 查看用户
|
if len(arg) == 0 { // 会话列表
|
||||||
m.Cmdy("aaa.auth", "ship", "username")
|
m.Cmdy("aaa.auth", "ship", "session")
|
||||||
case 1: // 查看角色
|
|
||||||
m.Cmdy("aaa.auth", "ship", "username", arg[0], "userrole")
|
|
||||||
case 2: // 查看会话
|
|
||||||
m.Cmdy("aaa.auth", "ship", "username", arg[0], "session", arg[1])
|
|
||||||
case 3: // 用户认证
|
|
||||||
if (arg[1] == "password" || arg[1] == "uuid") && m.Cmds("aaa.auth", "ship", "username", arg[0]) {
|
|
||||||
m.Cmdy("aaa.auth", "username", arg[0], arg[1], arg[2])
|
|
||||||
break
|
|
||||||
}
|
|
||||||
fallthrough
|
|
||||||
default: // 添加用户
|
|
||||||
for i := 1; i < len(arg); i += 2 {
|
|
||||||
if m.Cmdy("aaa.auth", "ship", "username", arg[i], "userrole", arg[0]); i < len(arg)-1 {
|
|
||||||
m.Cmd("aaa.auth", "ship", "username", arg[i], "password", arg[i+1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
"sess": &ctx.Command{Name: "sess [sessid [meta]|[username password password]]|[type ip ip]", Help: "会话管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
if len(arg) > 0 && arg[0] == "bench" {
|
|
||||||
if len(arg) == 1 { // 查看空间
|
|
||||||
m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch arg[1] {
|
|
||||||
case "select": // 选择空间
|
sid := m.Option("sessid")
|
||||||
defer func() { m.Log("info", "bench: %s", m.Append("key")) }()
|
if m.Conf("auth", []string{arg[0], "type"}) == "session" {
|
||||||
if m.Options("bench") && m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", m.Option("sessid")) {
|
sid, arg = arg[0], arg[1:]
|
||||||
m.Add("append", "key", m.Option("bench")).Table()
|
}
|
||||||
|
if len(arg) == 0 {
|
||||||
|
m.Echo(sid)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "user": // 查看用户
|
||||||
|
m.Cmdy("aaa.auth", sid, "ship", "username")
|
||||||
|
|
||||||
|
case "current":
|
||||||
|
if len(arg) > 2 { // 设置指针
|
||||||
|
m.Cmd("aaa.auth", sid, "data", strings.Join(arg[:2], "."), arg[2])
|
||||||
|
arg = arg[:2]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查看指针
|
||||||
|
m.Cmdy("aaa.auth", sid, "data", strings.Join(arg, "."))
|
||||||
|
|
||||||
|
case "bench":
|
||||||
|
if len(arg) == 1 { // 查看空间
|
||||||
|
m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench"); m.Appends("key") {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fallthrough
|
|
||||||
case "create": // 创建空间
|
|
||||||
m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench", kit.Select("web", arg, 2))
|
|
||||||
m.Cmd("aaa.auth", m.Result(0), "data", "name", "web")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) > 0 && arg[0] == "current" {
|
switch arg[1] {
|
||||||
switch len(arg) {
|
case "select": // 选择空间
|
||||||
case 1:
|
defer func() { m.Log("info", "bench: %s", m.Result(0)) }()
|
||||||
m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current")
|
|
||||||
case 2:
|
|
||||||
m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current."+arg[1])
|
|
||||||
default:
|
|
||||||
m.Cmd("aaa.auth", m.Option("sessid"), "data", "current."+arg[1], arg[2])
|
|
||||||
m.Cmdy("aaa.auth", m.Option("sessid"), "data", "current."+arg[1])
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch len(arg) {
|
|
||||||
case 0: // 查看会话
|
|
||||||
m.Cmdy("aaa.auth", "ship", "session")
|
|
||||||
case 1: // 查看会话
|
|
||||||
m.Cmdy("aaa.auth", arg[0])
|
|
||||||
case 2: // 查询会话
|
|
||||||
m.Cmdy("aaa.auth", arg[0], "ship", arg[1])
|
|
||||||
case 3: // 创建会话
|
|
||||||
m.Cmdy("aaa.auth", "ship", "session", arg[0], arg[1], arg[2])
|
|
||||||
case 4: // 用户登录
|
|
||||||
m.Cmdy("aaa.auth", arg[0], "ship", "username", arg[1], arg[2], arg[3])
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
"work": &ctx.Command{Name: "work [sessid create|select]|[benchid] [right [username [componet name [command name [argument name]]]]]", Help: "工作任务",
|
|
||||||
Auto: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (goon bool) {
|
|
||||||
switch len(arg) {
|
|
||||||
case 0:
|
|
||||||
Auto(m, "ship", "bench")
|
|
||||||
Auto(m, "ship", "session")
|
|
||||||
default:
|
|
||||||
switch m.Conf("auth", []string{arg[0], "type"}) {
|
|
||||||
case "session":
|
|
||||||
if len(arg) == 1 {
|
|
||||||
m.Auto("create", "create", "创建空间")
|
|
||||||
m.Auto("select", "select", "查找空间")
|
|
||||||
} else {
|
|
||||||
|
|
||||||
|
if m.Options("bench") && m.Cmds("aaa.auth", m.Option("sessid"), "ship", "check", m.Option("bench")) {
|
||||||
|
m.Echo(m.Option("bench"))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
case "bench":
|
if m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench"); m.Appends("key") {
|
||||||
if len(arg) == 1 {
|
m.Set("result").Echo(m.Append("key"))
|
||||||
m.Auto("delete", "delete", "删除空间")
|
return
|
||||||
m.Auto("rename", "rename", "命名空间")
|
|
||||||
m.Auto("right", "right [username [componet [command]]]", "权限检查")
|
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
default:
|
fallthrough
|
||||||
m.Auto("invalid id")
|
case "create": // 创建空间
|
||||||
|
m.Cmdy("aaa.auth", m.Option("sessid"), "ship", "bench", kit.Select("web", arg, 2))
|
||||||
|
m.Cmd("aaa.auth", m.Result(0), "data", "name", "web")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return
|
||||||
},
|
}},
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"work": &ctx.Command{Name: "work [benchid] [sesion]|[delete]|[rename name]|[share public|protect|private][data arg...]|[right [componet [command [argument]]]]",
|
||||||
if len(arg) > 0 && arg[0] == "right" {
|
Help: []string{"工作空间",
|
||||||
// 查看权限
|
"session: 查看会话",
|
||||||
if len(arg) == 1 {
|
"delete: 删除空间",
|
||||||
|
"rename [name]: 命名空间",
|
||||||
|
"share [public|protect|private]: 共享空间",
|
||||||
|
"data arg...: 读写数据",
|
||||||
|
"right [componet [command [arguments]]]: 权限检查",
|
||||||
|
}, Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
if len(arg) == 0 { // 空间列表
|
||||||
|
m.Cmdy("aaa.auth", "ship", "bench")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bid := m.Option("bench")
|
||||||
|
if m.Conf("auth", []string{arg[0], "type"}) == "bench" {
|
||||||
|
bid, arg = arg[0], arg[1:]
|
||||||
|
}
|
||||||
|
if len(arg) == 0 {
|
||||||
|
m.Echo(bid)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "session": // 查看会话
|
||||||
|
m.Cmdy("aaa.auth", bid, "ship", "session")
|
||||||
|
|
||||||
|
case "delete": // 删除空间
|
||||||
|
m.Cmdy("aaa.auth", bid, "delete", "node")
|
||||||
|
|
||||||
|
case "rename": // 命名空间
|
||||||
|
if len(arg) > 1 {
|
||||||
|
m.Cmd("aaa.auth", bid, "data", "name", arg[1])
|
||||||
|
}
|
||||||
|
m.Cmdy("aaa.auth", bid, "data", "name")
|
||||||
|
|
||||||
|
case "share": // 共享空间
|
||||||
|
if len(arg) > 1 {
|
||||||
|
m.Cmdy("aaa.auth", bid, "data", "share", arg[1])
|
||||||
|
}
|
||||||
|
m.Cmdy("aaa.auth", bid, "data", "share")
|
||||||
|
|
||||||
|
case "data": // 读写数据
|
||||||
|
m.Cmdy("aaa.auth", bid, arg)
|
||||||
|
|
||||||
|
case "right":
|
||||||
|
if len(arg) == 1 { // 查看权限
|
||||||
m.Cmd("aaa.auth", m.Option("bench"), "ship", "componet").CopyTo(m, "append")
|
m.Cmd("aaa.auth", m.Option("bench"), "ship", "componet").CopyTo(m, "append")
|
||||||
m.Cmd("aaa.auth", m.Option("bench"), "ship", "command").CopyTo(m, "append")
|
m.Cmd("aaa.auth", m.Option("bench"), "ship", "command").CopyTo(m, "append")
|
||||||
m.Table()
|
m.Table()
|
||||||
@ -635,12 +627,13 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
// 检查权限
|
// 检查权限
|
||||||
m.Cmd("aaa.auth", "ship", "username", m.Option("username"), "userrole").Table(func(node map[string]string) {
|
m.Cmd("aaa.auth", "ship", "username", m.Option("username"), "userrole").Table(func(node map[string]string) {
|
||||||
if node["meta"] == "root" { // 超级用户
|
if node["meta"] == "root" { // 超级用户
|
||||||
m.Log("info", "root %s", m.Option("username"))
|
m.Log("info", "role: root")
|
||||||
m.Echo("true")
|
m.Echo("true")
|
||||||
} else if len(arg) > 2 { // 接口权限
|
} else if len(arg) > 2 { // 接口权限
|
||||||
if m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", arg[2]) {
|
if m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", arg[2]) {
|
||||||
m.Echo("true")
|
m.Echo("true")
|
||||||
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "componet", arg[1], "check", arg[2]); kit.Right(cid) {
|
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "componet", arg[1], "check", arg[2]); kit.Right(cid) {
|
||||||
|
m.Log("info", "role: %s", node["meta"])
|
||||||
m.Cmd("aaa.auth", m.Option("bench"), cid)
|
m.Cmd("aaa.auth", m.Option("bench"), cid)
|
||||||
m.Echo("true")
|
m.Echo("true")
|
||||||
}
|
}
|
||||||
@ -648,6 +641,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
if m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", arg[1]) {
|
if m.Cmds("aaa.auth", m.Option("bench"), "ship", "check", arg[1]) {
|
||||||
m.Echo("true")
|
m.Echo("true")
|
||||||
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "check", arg[1]); kit.Right(cid) {
|
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "check", arg[1]); kit.Right(cid) {
|
||||||
|
m.Log("info", "role: %s", node["meta"])
|
||||||
m.Cmd("aaa.auth", m.Option("bench"), cid)
|
m.Cmd("aaa.auth", m.Option("bench"), cid)
|
||||||
m.Echo("true")
|
m.Echo("true")
|
||||||
}
|
}
|
||||||
@ -656,61 +650,6 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
|
|
||||||
m.Log("right", "bench: %s sessid: %s user: %s com: %v result: %v",
|
m.Log("right", "bench: %s sessid: %s user: %s com: %v result: %v",
|
||||||
m.Option("bench"), m.Option("sessid"), m.Option("username"), arg[2:], m.Result(0))
|
m.Option("bench"), m.Option("sessid"), m.Option("username"), arg[2:], m.Result(0))
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) == 0 { // 查看空间
|
|
||||||
m.Cmdy("aaa.auth", "ship", "bench")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
bid := ""
|
|
||||||
switch m.Conf("auth", []string{arg[0], "type"}) {
|
|
||||||
case "session": // 创建空间
|
|
||||||
bid, arg = m.Cmdx("aaa.auth", arg[0], "ship", "bench", arg[1]), arg[2:]
|
|
||||||
m.Cmd("aaa.auth", bid, "data", "name", "web")
|
|
||||||
defer func() { m.Set("result").Echo(bid) }()
|
|
||||||
case "bench": // 查询空间
|
|
||||||
bid, arg = arg[0], arg[1:]
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(arg) == 0 {
|
|
||||||
m.Echo(bid)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch arg[0] {
|
|
||||||
case "delete": // 删除空间
|
|
||||||
m.Cmd("aaa.auth", bid, "delete", "node")
|
|
||||||
case "rename": // 命名空间
|
|
||||||
m.Cmd("aaa.auth", bid, "data", "name", arg[1])
|
|
||||||
case "right": // 权限检查
|
|
||||||
m.Cmd("aaa.auth", "ship", "username", arg[1], "userrole").Table(func(node map[string]string) {
|
|
||||||
if node["meta"] == "root" { // 超级用户
|
|
||||||
m.Log("info", "root %s", arg[1])
|
|
||||||
m.Echo("true")
|
|
||||||
} else if len(arg) >= 4 { // 功能权限
|
|
||||||
if m.Cmds("aaa.auth", bid, "ship", "check", arg[3]) {
|
|
||||||
m.Echo("true")
|
|
||||||
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "componet", arg[2], "check", arg[3]); kit.Right(cid) {
|
|
||||||
m.Cmd("aaa.auth", bid, cid)
|
|
||||||
m.Echo("true")
|
|
||||||
}
|
|
||||||
} else if len(arg) >= 3 { // 组件权限
|
|
||||||
if m.Cmds("aaa.auth", bid, "ship", "check", arg[2]) {
|
|
||||||
m.Echo("true")
|
|
||||||
} else if cid := m.Cmdx("aaa.auth", "ship", "userrole", node["meta"], "check", arg[2]); kit.Right(cid) {
|
|
||||||
m.Cmd("aaa.auth", bid, cid)
|
|
||||||
m.Echo("true")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
m.Log("right", "bench: %s sessid: %s user: %s com: %v result: %v",
|
|
||||||
m.Option("bench"), m.Option("sessid"), m.Option("username"), arg[2:], m.Result(0))
|
|
||||||
default: // 读写数据
|
|
||||||
m.Cmdx("aaa.auth", bid, arg)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
@ -464,11 +464,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}
|
}
|
||||||
detail = append(detail, arg...)
|
detail = append(detail, arg...)
|
||||||
|
|
||||||
if m.Options("current_ctx") && detail[0] != "context" {
|
|
||||||
detail = append([]string{"context", m.Option("current_ctx")}, detail...)
|
|
||||||
m.Option("current_ctx", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 目标切换
|
// 目标切换
|
||||||
target := m.Optionv("ps_target")
|
target := m.Optionv("ps_target")
|
||||||
if detail[0] != "context" {
|
if detail[0] != "context" {
|
||||||
|
@ -471,12 +471,8 @@ var CGI = template.FuncMap{
|
|||||||
switch len(arg) {
|
switch len(arg) {
|
||||||
case 0:
|
case 0:
|
||||||
list := map[string]map[string]interface{}{}
|
list := map[string]map[string]interface{}{}
|
||||||
m.Confm("auth", []string{m.Option("sessid"), "ship"}, func(key string, ship map[string]interface{}) {
|
m.Cmd("aaa.sess", "bench").Table(func(node map[string]string) {
|
||||||
if ship["type"] == "bench" {
|
list[node["key"]] = m.Confm("auth", node["key"])
|
||||||
if work := m.Confm("auth", key); work != nil {
|
|
||||||
list[key] = work
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
@ -485,7 +481,8 @@ var CGI = template.FuncMap{
|
|||||||
"parse": func(m *Message, arg ...interface{}) interface{} {
|
"parse": func(m *Message, arg ...interface{}) interface{} {
|
||||||
switch len(arg) {
|
switch len(arg) {
|
||||||
case 1:
|
case 1:
|
||||||
return m.Parse(kit.Format(arg[0]))
|
v := m.Parse(kit.Format(arg[0]))
|
||||||
|
return v
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@ -360,9 +360,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
}
|
}
|
||||||
|
|
||||||
if v, ok := msg.Data[k]; ok {
|
if v, ok := msg.Data[k]; ok {
|
||||||
b, e := json.MarshalIndent(v, "", " ")
|
json.MarshalIndent(v, "", " ")
|
||||||
m.Log("fuck", " %v", b)
|
|
||||||
m.Log("fuck", " %v", e)
|
|
||||||
m.Echo(kit.Formats(v))
|
m.Echo(kit.Formats(v))
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
@ -378,7 +376,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.Sort("key", "string").Table()
|
m.Sort("key", "str").Table()
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"magic": &Command{Name: "magic", Help: "随机组员", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
"magic": &Command{Name: "magic", Help: "随机组员", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||||
|
@ -832,12 +832,18 @@ func (m *Message) Optionx(key string, arg ...string) interface{} {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
func (m *Message) Magic(begin string, chain interface{}, args ...interface{}) interface{} {
|
func (m *Message) Magic(begin string, chain interface{}, args ...interface{}) interface{} {
|
||||||
auth := []string{"bench", "session", "username", "role", "componet", "command"}
|
auth := []string{"bench", "session", "user", "role", "componet", "command"}
|
||||||
key := []string{"bench", "sessid", "username", "role", "componet", "command"}
|
key := []string{"bench", "sessid", "username", "role", "componet", "command"}
|
||||||
aaa := m.Sess("aaa", false)
|
aaa := m.Sess("aaa", false)
|
||||||
for i, v := range auth {
|
for i, v := range auth {
|
||||||
if v == begin {
|
if v == begin {
|
||||||
data := aaa.Confv("auth", []string{m.Option(key[i]), "data"})
|
h := m.Option(key[i])
|
||||||
|
if v == "user" {
|
||||||
|
h, _ = kit.Hash("username", m.Option("username"))
|
||||||
|
}
|
||||||
|
|
||||||
|
data := aaa.Confv("auth", []string{h, "data"})
|
||||||
|
|
||||||
if kit.Format(chain) == "" {
|
if kit.Format(chain) == "" {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
@ -1104,7 +1110,14 @@ func (m *Message) Parse(arg interface{}) string {
|
|||||||
return m.Cap(str[1:])
|
return m.Cap(str[1:])
|
||||||
}
|
}
|
||||||
if len(str) > 1 && str[0] == '@' {
|
if len(str) > 1 && str[0] == '@' {
|
||||||
return m.Confx(str[1:])
|
if v := m.Option(str[1:]); v != "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
if v := kit.Format(m.Magic("bench", str[1:])); v != "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
v := m.Conf(str[1:])
|
||||||
|
return v
|
||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
@ -866,13 +866,13 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
|
|
||||||
if len(arg) > 0 && arg[0] == "scan" {
|
if len(arg) > 0 && arg[0] == "scan" {
|
||||||
// 终端用户
|
// 终端用户
|
||||||
m.Cmd("aaa.user", "root", m.Option("username", m.Conf("runtime", "boot.USER")), "what")
|
m.Cmd("aaa.role", "root", "user", m.Option("username", m.Conf("runtime", "boot.USER")))
|
||||||
|
|
||||||
// 创建会话
|
// 创建会话
|
||||||
m.Option("sessid", m.Cmd("aaa.user", "session", "select").Append("key"))
|
m.Option("sessid", m.Cmdx("aaa.user", "session", "select"))
|
||||||
|
|
||||||
// 创建空间
|
// 创建空间
|
||||||
m.Option("bench", m.Cmd("aaa.sess", "bench", "select").Append("key"))
|
m.Option("bench", m.Cmdx("aaa.sess", "bench", "select"))
|
||||||
|
|
||||||
// 默认配置
|
// 默认配置
|
||||||
m.Cap("stream", arg[1])
|
m.Cap("stream", arg[1])
|
||||||
@ -1167,6 +1167,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
arg = append(arg, "")
|
arg = append(arg, "")
|
||||||
}
|
}
|
||||||
|
m.Magic("session", "current.dir", arg[0])
|
||||||
|
|
||||||
wd, e := os.Getwd()
|
wd, e := os.Getwd()
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
@ -1175,7 +1176,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
rg, e := regexp.Compile(m.Option("dir_reg"))
|
rg, e := regexp.Compile(m.Option("dir_reg"))
|
||||||
|
|
||||||
m.Confm("paths", func(index int, value string) bool {
|
m.Confm("paths", func(index int, value string) bool {
|
||||||
p := path.Join(value, m.Option("dir_root"), kit.Select("", arg))
|
p := path.Join(value, m.Option("dir_root"), arg[0])
|
||||||
if s, e := os.Stat(p); e == nil {
|
if s, e := os.Stat(p); e == nil {
|
||||||
if s.IsDir() {
|
if s.IsDir() {
|
||||||
dir(m, p, 0, kit.Right(m.Has("dir_deep")), m.Confx("dir_type"), trip, rg,
|
dir(m, p, 0, kit.Right(m.Has("dir_deep")), m.Confx("dir_type"), trip, rg,
|
||||||
|
@ -128,7 +128,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
nfs.Free(func(nfs *ctx.Message) bool {
|
nfs.Free(func(nfs *ctx.Message) bool {
|
||||||
m.Conf("timer", m.Cmdx("cli.timer", "repeat", m.Conf("timer_interval"), "context", "ssh", "remote", "redial", arg[1:]))
|
m.Conf("timer", m.Cmdx("cli.timer", "repeat", m.Conf("timer_interval"), "context", "ssh", "remote", "redial", arg[1:]))
|
||||||
m.Cmd("aaa.auth", m.Cmdx("aaa.auth", "nodes", node.Append("node.name")), "delete", "node")
|
m.Cmd("aaa.auth", m.Cmdx("aaa.auth", "nodes", node.Append("node.name")), "delete", "node")
|
||||||
|
|
||||||
m.Log("info", "delete node %s", node.Append("node.name"))
|
m.Log("info", "delete node %s", node.Append("node.name"))
|
||||||
delete(m.Confm("node"), node.Append("node.name"))
|
delete(m.Confm("node"), node.Append("node.name"))
|
||||||
m.Cap("stream", "")
|
m.Cap("stream", "")
|
||||||
@ -165,6 +164,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
|
|
||||||
// 清理节点
|
// 清理节点
|
||||||
m.Sess("ms_source", false).Free(func(msg *ctx.Message) bool {
|
m.Sess("ms_source", false).Free(func(msg *ctx.Message) bool {
|
||||||
|
m.Cmd("aaa.auth", m.Cmdx("aaa.auth", "nodes", name), "delete", "node")
|
||||||
m.Log("info", "delete node %s", name)
|
m.Log("info", "delete node %s", name)
|
||||||
delete(m.Confm("node"), name)
|
delete(m.Confm("node"), name)
|
||||||
return true
|
return true
|
||||||
@ -192,20 +192,14 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
// 路由转发
|
// 路由转发
|
||||||
if rest := kit.Select("", names, 1); names[0] != "" {
|
if rest := kit.Select("", names, 1); names[0] != "" {
|
||||||
// 数字签名
|
// 数字签名
|
||||||
if !m.Options("remote_code") {
|
if !m.Options("remote_code") && arg[0] != "check" {
|
||||||
// 用户路由
|
|
||||||
m.Option("user.route", kit.Select(m.Conf("runtime", "node.route"), m.Conf("runtime", "user.route")))
|
|
||||||
m.Cmd("aaa.auth", "username", m.Option("username"), "session", "login").Table(func(line map[string]string) {
|
|
||||||
m.Option("user.route", m.Cmd("aaa.auth", line["key"], "login").Append("meta"))
|
|
||||||
})
|
|
||||||
|
|
||||||
// 数据哈希
|
// 数据哈希
|
||||||
hash, meta := kit.Hash("rand",
|
hash, meta := kit.Hash("rand",
|
||||||
m.Option("text.time", m.Time("stamp")),
|
m.Option("text.time", m.Time("stamp")),
|
||||||
m.Option("text.cmd", strings.Join(arg, " ")),
|
m.Option("text.cmd", strings.Join(arg, " ")),
|
||||||
m.Option("text.route", route),
|
m.Option("text.route", route),
|
||||||
m.Option("node.route", m.Conf("runtime", "node.route")),
|
m.Option("node.route", m.Conf("runtime", "node.route")),
|
||||||
m.Option("user.route"),
|
m.Option("user.route", kit.Select(m.Conf("runtime", "node.route"), m.Conf("runtime", "user.route"))),
|
||||||
m.Option("user.name", m.Option("username")),
|
m.Option("user.name", m.Option("username")),
|
||||||
)
|
)
|
||||||
m.Option("text.rand", meta[0])
|
m.Option("text.rand", meta[0])
|
||||||
@ -279,14 +273,13 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设备证书
|
// 设备证书
|
||||||
m.Option("node.cert", m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert").Append("meta"))
|
if m.Option("node.cert", m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert").Append("meta")); !m.Options("node.cert") {
|
||||||
if !m.Options("node.cert") {
|
|
||||||
m.Option("node.cert", m.Spawn().Cmdx("ssh.remote", m.Option("node.route"), "sync", "check", "node"))
|
m.Option("node.cert", m.Spawn().Cmdx("ssh.remote", m.Option("node.route"), "sync", "check", "node"))
|
||||||
m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert", m.Option("node.cert"))
|
m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert", m.Option("node.cert"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设备验签
|
// 设备验签
|
||||||
if !m.Cmds("aaa.rsa", "verify", m.Option("node.cert"), m.Option("node.sign"), m.Option("text.hash", hash)) {
|
if !m.Cmds("aaa.rsa", "verify", m.Option("node.cert"), m.Option("node.sign"), m.Option("text.hash", hash)) {
|
||||||
|
m.Cmd("aaa.auth", "nodes", m.Option("node.route"), "cert", m.Option("node.cert"))
|
||||||
m.Log("warning", "node error")
|
m.Log("warning", "node error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -302,8 +295,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Conf("runtime", "user.route", user.Append("user.route"))
|
m.Conf("runtime", "user.route", user.Append("user.route"))
|
||||||
m.Conf("runtime", "user.name", user.Append("user.name"))
|
m.Conf("runtime", "user.name", user.Append("user.name"))
|
||||||
m.Conf("runtime", "user.cert", user.Append("user.cert"))
|
m.Conf("runtime", "user.cert", user.Append("user.cert"))
|
||||||
|
m.Cmd("aaa.role", "root", "user", user.Append("user.name"))
|
||||||
m.Cmd("aaa.auth", "username", user.Append("user.name"), "cert", user.Append("user.cert"))
|
m.Cmd("aaa.auth", "username", user.Append("user.name"), "cert", user.Append("user.cert"))
|
||||||
m.Cmd("aaa.user", "root", user.Append("user.name"), "what")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,8 +305,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
if !m.Options("remote_code") || m.Cmds("aaa.rsa", "verify", m.Conf("runtime", "user.cert"), m.Option("user.sign"), m.Option("text.hash")) {
|
if !m.Options("remote_code") || m.Cmds("aaa.rsa", "verify", m.Conf("runtime", "user.cert"), m.Option("user.sign"), m.Option("text.hash")) {
|
||||||
for _, v := range arg[2:] {
|
for _, v := range arg[2:] {
|
||||||
user := m.Spawn().Cmd("ssh.remote", v, "sync", "check", "user")
|
user := m.Spawn().Cmd("ssh.remote", v, "sync", "check", "user")
|
||||||
|
m.Cmd("aaa.user", arg[1], "user", user.Append("user.name"))
|
||||||
m.Cmd("aaa.auth", "username", user.Append("user.name"), "cert", user.Append("user.cert"))
|
m.Cmd("aaa.auth", "username", user.Append("user.name"), "cert", user.Append("user.cert"))
|
||||||
m.Cmd("aaa.user", arg[1], user.Append("user.name"), "what")
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -354,6 +347,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
if m.Options("remote_code") {
|
if m.Options("remote_code") {
|
||||||
|
m.Log("info", "username %s", m.Option("user.name"))
|
||||||
if m.Option("username", m.Option("user.name")); !m.Confs("trust", m.Option("node.route")) {
|
if m.Option("username", m.Option("user.name")); !m.Confs("trust", m.Option("node.route")) {
|
||||||
// 用户签名
|
// 用户签名
|
||||||
hash, _ := kit.Hash("rand", m.Option("text.time", m.Time("stamp")), m.Option("node.route"))
|
hash, _ := kit.Hash("rand", m.Option("text.time", m.Time("stamp")), m.Option("node.route"))
|
||||||
@ -371,10 +365,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建会话
|
// 创建会话
|
||||||
m.Option("sessid", m.Cmd("aaa.user", "session", "select").Append("key"))
|
m.Option("sessid", m.Cmdx("aaa.user", "session", "select"))
|
||||||
|
|
||||||
// 创建空间
|
// 创建空间
|
||||||
m.Option("bench", m.Cmd("aaa.sess", "bench", "select").Append("key"))
|
m.Option("bench", m.Cmdx("aaa.sess", "bench", "select"))
|
||||||
|
|
||||||
// 权限检查
|
// 权限检查
|
||||||
if !m.Cmds("aaa.work", "right", "remote", arg[0]) {
|
if !m.Cmds("aaa.work", "right", "remote", arg[0]) {
|
||||||
|
@ -108,23 +108,24 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
msg.Log("info", "cas_login %v", msg.Option("ticket"))
|
msg.Log("info", "cas_login %v", msg.Option("ticket"))
|
||||||
if msg.Options("ticket") {
|
if msg.Options("ticket") {
|
||||||
msg.Option("uuid", msg.Option(msg.Conf("login", "cas_uuid")))
|
|
||||||
msg.Option("username", cas.Username(r))
|
msg.Option("username", cas.Username(r))
|
||||||
|
msg.Log("info", "login: %s", msg.Option("username"))
|
||||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Cmdx("web.session", "login", "uuid"), Path: "/"})
|
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Option("sessid", msg.Cmdx("aaa.user", "session", "select")), Path: "/"})
|
||||||
http.Redirect(w, r, merge(msg, r.Header.Get("index_url"), "ticket", ""), http.StatusTemporaryRedirect)
|
http.Redirect(w, r, merge(msg, r.Header.Get("index_url"), "ticket", ""), http.StatusTemporaryRedirect)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
} else if msg.Options("username") && msg.Options("password") {
|
} else if msg.Options("username") && msg.Options("password") {
|
||||||
if sessid := msg.Cmd("web.session", "login", "password").Result(0); sessid != "" {
|
if msg.Cmds("aaa.auth", "username", msg.Option("username"), "password", msg.Option("password")) {
|
||||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Option("sessid", sessid), Path: "/"})
|
msg.Log("info", "login: %s", msg.Option("username"))
|
||||||
|
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Cmdx("aaa.user", "session", "select"), Path: "/"})
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !msg.Options("current_ctx") {
|
if msg.Options("sessid") {
|
||||||
http.SetCookie(w, &http.Cookie{Name: "current_ctx", Value: msg.Option("current_ctx", "mdb"), Path: "/"})
|
msg.Log("info", "sessid: %s", msg.Option("sessid"))
|
||||||
|
msg.Log("info", "username: %s", msg.Option("username", msg.Cmd("aaa.sess", "user").Append("meta")))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -565,12 +566,14 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
if m.Options("content_length") {
|
if m.Options("content_length") {
|
||||||
req.Header.Set("Content-Length", m.Option("content_length"))
|
req.Header.Set("Content-Length", m.Option("content_length"))
|
||||||
}
|
}
|
||||||
m.Confm("spide", []string{which, "cookie"}, func(key string, value string) {
|
|
||||||
if key != "" {
|
// 请求cookie
|
||||||
req.AddCookie(&http.Cookie{Name: key, Value: value})
|
kit.Structm(m.Magic("user", []string{"cookie", which}), func(key string, value string) {
|
||||||
m.Log("info", "set-cookie %s: %v", key, value)
|
req.AddCookie(&http.Cookie{Name: key, Value: value})
|
||||||
}
|
m.Log("info", "set-cookie %s: %v", key, value)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if kit.Right(client["logheaders"]) {
|
if kit.Right(client["logheaders"]) {
|
||||||
for k, v := range req.Header {
|
for k, v := range req.Header {
|
||||||
m.Log("info", "%s: %s", k, v)
|
m.Log("info", "%s: %s", k, v)
|
||||||
@ -599,8 +602,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 响应cookie
|
||||||
for _, v := range res.Cookies() {
|
for _, v := range res.Cookies() {
|
||||||
m.Conf("spide", []string{which, "cookie", v.Name}, v.Value)
|
m.Magic("user", []string{"cookie", which, v.Name}, v.Value)
|
||||||
m.Log("info", "get-cookie %s: %v", v.Name, v.Value)
|
m.Log("info", "get-cookie %s: %v", v.Name, v.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -842,50 +846,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"session": &ctx.Command{Name: "session [login secrete] bench [check [componet [command]]]", Help: "用户登录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
|
||||||
if len(arg) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
username, sessid := m.Option("username"), m.Option("sessid")
|
|
||||||
|
|
||||||
switch arg[0] {
|
|
||||||
case "login":
|
|
||||||
if len(arg) == 1 { // 查询用户
|
|
||||||
m.Echo(m.Cmd("aaa.sess", sessid, "username").Append("meta"))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if username == "" || !m.Options(arg[1]) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if sessid == "" || !m.Cmds("aaa.sess", sessid) { // 创建会话
|
|
||||||
if sessid = m.Cmd("aaa.auth", "username", m.Option("username"), "session", "web").Append("key"); sessid == "" {
|
|
||||||
sessid = m.Cmdx("aaa.sess", "web", "ip", m.Option("remote_ip"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if m.Cmds("aaa.sess", sessid, m.Option("username"), arg[1], m.Option(arg[1])) { // 用户登录
|
|
||||||
m.Echo(sessid)
|
|
||||||
}
|
|
||||||
|
|
||||||
case "bench":
|
|
||||||
if len(arg) == 1 { // 创建空间
|
|
||||||
bench := m.Option("bench")
|
|
||||||
if bench == "" || !m.Cmds("aaa.work", bench) {
|
|
||||||
bench = m.Cmdx("aaa.work", sessid, "web")
|
|
||||||
}
|
|
||||||
m.Echo(bench)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
// 添加数据
|
|
||||||
m.Cmd("aaa.work", arg[1:])
|
|
||||||
|
|
||||||
case "check": // 检查权限
|
|
||||||
m.Echo(m.Cmdx("aaa.work", arg[1], "right", arg[2:]))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}},
|
|
||||||
|
|
||||||
"/proxy/": &ctx.Command{Name: "/proxy/which/method/url", Help: "服务代理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"/proxy/": &ctx.Command{Name: "/proxy/which/method/url", Help: "服务代理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
fields := strings.Split(key, "/")
|
fields := strings.Split(key, "/")
|
||||||
@ -900,8 +860,6 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Option("current_ctx", kit.Select(m.Option("current_ctx", kit.Format(m.Magic("session", "current.ctx")))))
|
|
||||||
|
|
||||||
if web, ok := m.Target().Server.(*WEB); m.Assert(ok) {
|
if web, 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")
|
||||||
@ -923,18 +881,11 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
|
|
||||||
// 权限检查
|
// 权限检查
|
||||||
if m.Confs("login", "check") {
|
if m.Confs("login", "check") {
|
||||||
if m.Option("username", m.Cmdx("web.session", "login")) == "" { // 没有登录
|
if m.Option("username") == "" { // 没有登录
|
||||||
m.Set("option", "componet_group", "login").Set("option", "componet_name", "").Set("option", "bench", "")
|
m.Set("option", "componet_group", "login").Set("option", "componet_name", "").Set("option", "bench", "")
|
||||||
} else {
|
} else {
|
||||||
sessid, bench := m.Option("sessid"), m.Option("bench")
|
|
||||||
|
|
||||||
// 创建会话
|
|
||||||
if m.Option("sessid", m.Cmd("aaa.user", "session", "select").Append("key")) != sessid {
|
|
||||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: m.Option("sessid"), Path: "/"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建空间
|
// 创建空间
|
||||||
if m.Option("bench", m.Cmd("aaa.sess", "bench", "select").Append("key")) != bench {
|
if bench := m.Option("bench"); m.Option("bench", m.Cmdx("aaa.sess", "bench", "select")) != bench {
|
||||||
m.Append("redirect", merge(m, m.Option("index_url"), "bench", m.Option("bench")))
|
m.Append("redirect", merge(m, m.Option("index_url"), "bench", m.Option("bench")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -955,6 +906,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arg = arg[:0]
|
||||||
if kit.Right(val["componet_pod"]) {
|
if kit.Right(val["componet_pod"]) {
|
||||||
arg = append(arg, "sh", "node", kit.Format(m.Magic("session", "current.pod")))
|
arg = append(arg, "sh", "node", kit.Format(m.Magic("session", "current.pod")))
|
||||||
}
|
}
|
||||||
@ -1003,7 +955,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
for _, v := range val["inputs"].([]interface{}) {
|
for _, v := range val["inputs"].([]interface{}) {
|
||||||
value := v.(map[string]interface{})
|
value := v.(map[string]interface{})
|
||||||
if value["name"] != nil && msg.Option(value["name"].(string)) == "" {
|
if value["name"] != nil && msg.Option(value["name"].(string)) == "" {
|
||||||
msg.Add("option", value["name"].(string), value["value"])
|
msg.Add("option", value["name"].(string), m.Parse(value["value"]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1016,7 +968,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
// 命令历史
|
// 命令历史
|
||||||
msg.Put("option", name_alias, map[string]interface{}{
|
msg.Put("option", name_alias, map[string]interface{}{
|
||||||
"cmd": arg, "order": m.Option("componet_name_order"), "action_time": msg.Time(),
|
"cmd": arg, "order": m.Option("componet_name_order"), "action_time": msg.Time(),
|
||||||
}).Cmd("web.session", "bench", m.Option("bench"), "data", "option", name_alias, "modify_time", msg.Time())
|
}).Cmd("aaa.work", m.Option("bench"), "data", "option", name_alias, "modify_time", msg.Time())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1047,21 +999,24 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
p := path.Join(m.Cmdx("nfs.path", m.Option("current_dir")), h.Filename)
|
p := path.Join(m.Cmdx("nfs.path", m.Magic("session", "current.dir")), h.Filename)
|
||||||
|
m.Log("upload", "file: %s", p)
|
||||||
|
m.Echo("%s", p)
|
||||||
|
|
||||||
o, e := os.Create(p)
|
o, e := os.Create(p)
|
||||||
m.Assert(e)
|
m.Assert(e)
|
||||||
defer o.Close()
|
defer o.Close()
|
||||||
|
|
||||||
io.Copy(o, f)
|
io.Copy(o, f)
|
||||||
m.Log("upload", "file: %s", p)
|
|
||||||
m.Append("redirect", m.Option("referer"))
|
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"/download/": &ctx.Command{Name: "/download/", Help: "下载文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"/download/": &ctx.Command{Name: "/download/", Help: "下载文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
r := m.Optionv("request").(*http.Request)
|
r := m.Optionv("request").(*http.Request)
|
||||||
w := m.Optionv("response").(http.ResponseWriter)
|
w := m.Optionv("response").(http.ResponseWriter)
|
||||||
|
|
||||||
p := m.Cmdx("nfs.path", strings.TrimPrefix(key, "/download/"))
|
p := m.Cmdx("nfs.path", strings.TrimPrefix(key, "/download/"))
|
||||||
m.Log("info", "download %s %s", p, m.Cmdx("aaa.hash", "file", p))
|
m.Log("info", "download %s %s", p, m.Cmdx("aaa.hash", "file", p))
|
||||||
|
|
||||||
http.ServeFile(w, r, p)
|
http.ServeFile(w, r, p)
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
@ -84,11 +84,12 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
map[string]interface{}{"name": "dir", "help": "dir", "template": "componet",
|
map[string]interface{}{"name": "dir", "help": "dir", "template": "componet",
|
||||||
"componet_ctx": "nfs", "componet_cmd": "dir", "arguments": []interface{}{"@dir", "dir_sort", "@sort_field", "@sort_order"},
|
"componet_ctx": "nfs", "componet_cmd": "dir", "arguments": []interface{}{"@current.dir", "dir_sort", "@sort_field", "@sort_order"},
|
||||||
"pre_run": true, "display_result": "",
|
"pre_run": true, "display_result": "",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "choice", "name": "dir_type",
|
map[string]interface{}{"type": "choice", "name": "dir_type",
|
||||||
"label": "dir_type", "value": "both", "choice": []interface{}{
|
"label": "dir_type", "value": "both", "choice": []interface{}{
|
||||||
|
map[string]interface{}{"name": "all", "value": "all"},
|
||||||
map[string]interface{}{"name": "both", "value": "both"},
|
map[string]interface{}{"name": "both", "value": "both"},
|
||||||
map[string]interface{}{"name": "file", "value": "file"},
|
map[string]interface{}{"name": "file", "value": "file"},
|
||||||
map[string]interface{}{"name": "dir", "value": "dir"},
|
map[string]interface{}{"name": "dir", "value": "dir"},
|
||||||
@ -113,7 +114,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
map[string]interface{}{"name": "time_r", "value": "time_r"},
|
map[string]interface{}{"name": "time_r", "value": "time_r"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"type": "text", "name": "dir", "label": "dir"},
|
map[string]interface{}{"type": "text", "name": "current.dir", "value": "@current.dir", "label": "dir"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"name": "upload", "help": "upload", "template": "componet",
|
map[string]interface{}{"name": "upload", "help": "upload", "template": "componet",
|
||||||
@ -145,7 +146,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
map[string]interface{}{"name": "pod", "help": "pod", "template": "componet",
|
map[string]interface{}{"name": "pod", "help": "pod", "template": "componet",
|
||||||
"componet_ctx": "ssh", "componet_cmd": "remote",
|
"componet_ctx": "ssh", "componet_cmd": "remote",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "pod", "value": ""},
|
map[string]interface{}{"type": "text", "name": "pod", "value": "@current.pod"},
|
||||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||||
},
|
},
|
||||||
"pre_run": true, "display_result": "",
|
"pre_run": true, "display_result": "",
|
||||||
@ -154,7 +155,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
|||||||
"componet_pod": "true", "componet_ctx": "ssh", "componet_cmd": "context", "arguments": []interface{}{"@ctx", "list"},
|
"componet_pod": "true", "componet_ctx": "ssh", "componet_cmd": "context", "arguments": []interface{}{"@ctx", "list"},
|
||||||
"display_result": "",
|
"display_result": "",
|
||||||
"inputs": []interface{}{
|
"inputs": []interface{}{
|
||||||
map[string]interface{}{"type": "text", "name": "ctx", "value": ""},
|
map[string]interface{}{"type": "text", "name": "ctx", "value": "@current.ctx"},
|
||||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -230,6 +230,33 @@ func Trans(arg ...interface{}) []string {
|
|||||||
}
|
}
|
||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
|
func Struct(arg ...interface{}) map[string]interface{} {
|
||||||
|
value := map[string]interface{}{}
|
||||||
|
if len(arg) == 0 {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
switch val := arg[0].(type) {
|
||||||
|
case map[string]interface{}:
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
func Structm(args ...interface{}) map[string]interface{} {
|
||||||
|
Log("error", "what %v", Format(args))
|
||||||
|
value := Struct(args...)
|
||||||
|
for _, arg := range args {
|
||||||
|
Log("error", "what %v", Format(arg))
|
||||||
|
switch val := arg.(type) {
|
||||||
|
case func(k string, v string):
|
||||||
|
Log("error", "what %v", Format(val))
|
||||||
|
for k, v := range value {
|
||||||
|
val(k, Format(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
func Array(list []string, index int, arg ...interface{}) []string {
|
func Array(list []string, index int, arg ...interface{}) []string {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
if -1 < index && index < len(list) {
|
if -1 < index && index < len(list) {
|
||||||
|
@ -650,19 +650,14 @@ function init_download(event) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
option["dir"].value = dir
|
option["current.dir"].value = dir
|
||||||
if (dir == "" || dir.endsWith("/")) {
|
|
||||||
context.Cookie("current_dir", option["dir"].value)
|
|
||||||
}
|
|
||||||
send_command(option)
|
send_command(option)
|
||||||
option["dir"].value = context.Cookie("current_dir")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
insert_button(append, "root", function(event) {
|
insert_button(append, "root", function(event) {
|
||||||
change("")
|
change("")
|
||||||
})
|
})
|
||||||
insert_button(append, "back", function(event) {
|
insert_button(append, "back", function(event) {
|
||||||
var path = option["dir"].value.split("/")
|
var path = option["current.dir"].value.split("/")
|
||||||
while (path.pop() == "") {}
|
while (path.pop() == "") {}
|
||||||
change(path.join("/")+(path.length? "/": ""))
|
change(path.join("/")+(path.length? "/": ""))
|
||||||
})
|
})
|
||||||
@ -695,14 +690,12 @@ function init_download(event) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
(option["dir"].value = context.Search("current_dir")) && send_command(option)
|
|
||||||
|
|
||||||
add_sort(append, "filename", function(event) {
|
add_sort(append, "filename", function(event) {
|
||||||
var dir = event.target.innerText
|
var dir = event.target.innerText
|
||||||
if (option["dir"].value && !option["dir"].value.endsWith("/")) {
|
if (option["current.dir"].value && !option["current.dir"].value.endsWith("/")) {
|
||||||
change(option["dir"].value+"/"+dir, event.altKey, event.shiftKey)
|
change(option["current.dir"].value+"/"+dir, event.altKey, event.shiftKey)
|
||||||
} else {
|
} else {
|
||||||
change(option["dir"].value+dir, event.altKey, event.shiftKey)
|
change(option["current.dir"].value+dir, event.altKey, event.shiftKey)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -714,7 +707,6 @@ function init_contain() {
|
|||||||
|
|
||||||
function change(pod) {
|
function change(pod) {
|
||||||
option["pod"].value = pod
|
option["pod"].value = pod
|
||||||
context.Cookie("current_pod", option["pod"].value)
|
|
||||||
context.GET("", {
|
context.GET("", {
|
||||||
"componet_group": "index",
|
"componet_group": "index",
|
||||||
"componet_name": "cmd",
|
"componet_name": "cmd",
|
||||||
@ -726,8 +718,6 @@ function init_contain() {
|
|||||||
add_sort(append, "key", function(event) {
|
add_sort(append, "key", function(event) {
|
||||||
change(event.target.innerText.trim())
|
change(event.target.innerText.trim())
|
||||||
})
|
})
|
||||||
|
|
||||||
option["pod"].value = context.Cookie("current_pod")
|
|
||||||
}
|
}
|
||||||
function init_context() {
|
function init_context() {
|
||||||
var option = document.querySelector("form.option.ctx")
|
var option = document.querySelector("form.option.ctx")
|
||||||
@ -737,7 +727,6 @@ function init_context() {
|
|||||||
function change(ctx) {
|
function change(ctx) {
|
||||||
option["ctx"].value = ctx
|
option["ctx"].value = ctx
|
||||||
send_command(option)
|
send_command(option)
|
||||||
context.Cookie("current_ctx", option["ctx"].value)
|
|
||||||
context.GET("", {
|
context.GET("", {
|
||||||
"componet_group": "index",
|
"componet_group": "index",
|
||||||
"componet_name": "cmd",
|
"componet_name": "cmd",
|
||||||
@ -756,7 +745,6 @@ function init_context() {
|
|||||||
change(event.target.innerText.trim())
|
change(event.target.innerText.trim())
|
||||||
})
|
})
|
||||||
|
|
||||||
option["ctx"].value = context.Cookie("current_ctx")
|
|
||||||
send_command(option)
|
send_command(option)
|
||||||
}
|
}
|
||||||
function init_command() {
|
function init_command() {
|
||||||
@ -891,11 +879,14 @@ function init_toolkit() {
|
|||||||
location.reload()
|
location.reload()
|
||||||
return
|
return
|
||||||
case "create_fly":
|
case "create_fly":
|
||||||
location.search = ""
|
context.Command(["sess", "bench", "create"], function(msg) {
|
||||||
|
context.Search("bench", msg.result[0])
|
||||||
|
})
|
||||||
return
|
return
|
||||||
case "rename_fly":
|
case "rename_fly":
|
||||||
context.Command(["work", context.Search("bench"), "rename", prompt("name")])
|
context.Command(["work", context.Search("bench"), "rename", prompt("name")], function() {
|
||||||
location.reload()
|
location.reload()
|
||||||
|
})
|
||||||
return
|
return
|
||||||
case "remove_fly":
|
case "remove_fly":
|
||||||
var b = ""
|
var b = ""
|
||||||
|
@ -62,7 +62,13 @@ context = {
|
|||||||
return this.Cookie(key);
|
return this.Cookie(key);
|
||||||
},
|
},
|
||||||
Command: function(cmd, option, cb) {
|
Command: function(cmd, option, cb) {
|
||||||
option = option || {}
|
if (typeof option == "function") {
|
||||||
|
cb = option
|
||||||
|
option = {}
|
||||||
|
} else {
|
||||||
|
option = option || {}
|
||||||
|
}
|
||||||
|
|
||||||
option["componet_index"] = "index"
|
option["componet_index"] = "index"
|
||||||
if (typeof cmd == "string") {
|
if (typeof cmd == "string") {
|
||||||
option["componet_name"] = "source"
|
option["componet_name"] = "source"
|
||||||
|
@ -216,14 +216,13 @@
|
|||||||
{{$form_type := option . "form_type"|meta}}
|
{{$form_type := option . "form_type"|meta}}
|
||||||
{{$msg := .}}
|
{{$msg := .}}
|
||||||
|
|
||||||
{{if eq $form_type "upload"}}
|
|
||||||
{{end}}
|
|
||||||
<form class="option {{option .Meta "componet_name"}}"
|
<form class="option {{option .Meta "componet_name"}}"
|
||||||
data-componet_group="{{option . "componet_group"|meta}}"
|
data-componet_group="{{option . "componet_group"|meta}}"
|
||||||
data-componet_name="{{option . "componet_name"|meta}}"
|
data-componet_name="{{option . "componet_name"|meta}}"
|
||||||
{{if eq $form_type "upload"}}
|
{{if eq $form_type "upload"}}
|
||||||
method="POST" action="/upload" enctype="multipart/form-data"
|
method="POST" action="/upload" enctype="multipart/form-data"
|
||||||
onsubmit="onaction(event,'upload')"
|
onsubmit="onaction(event, 'upload')"
|
||||||
|
target="_blank"
|
||||||
{{end}}
|
{{end}}
|
||||||
>
|
>
|
||||||
<input style="display:none"></input>
|
<input style="display:none"></input>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user