forked from x/ContextOS
add aaa.auth.delete
This commit is contained in:
parent
842404a3d3
commit
8cd8222b3f
@ -159,9 +159,32 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
m.Confv("hash", hs, meta)
|
||||
m.Echo(hs)
|
||||
}},
|
||||
"auth": &ctx.Command{Name: "auth [create type meta] [id] [[ship] type [meta]] [[node] key [val]] [[data] key [val]]", Help: "权限区块链", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
"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) {
|
||||
if len(arg) == 0 { // 节点列表
|
||||
m.Spawn().Cmd("config", "auth").Cmd("select", "parse", "value", "", "fields", "key type meta ship").CopyTo(m)
|
||||
m.Confm("auth", func(key string, node map[string]interface{}) {
|
||||
up := false
|
||||
if ship, ok := node["ship"].(map[string]interface{}); ok {
|
||||
for k, v := range ship {
|
||||
val := v.(map[string]interface{})
|
||||
switch val["ship"].(string) {
|
||||
case "0":
|
||||
if !up {
|
||||
up = true
|
||||
m.Add("append", "up_key", k)
|
||||
m.Add("append", "up_type", val["type"])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !up {
|
||||
m.Add("append", "up_key", "")
|
||||
m.Add("append", "up_type", "")
|
||||
}
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "type", node["type"])
|
||||
m.Add("append", "meta", node["meta"])
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
@ -170,6 +193,59 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
s, t, arg = arg[0], v["type"].(string), 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, 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, 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, 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, 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, peer[s])
|
||||
delete(peer, s)
|
||||
}
|
||||
}
|
||||
m.Log("info", "delete node %s %v", s, m.Confm("auth", s))
|
||||
delete(m.Confm("auth"), s)
|
||||
m.Table()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if len(arg) == 0 { // 查看节点
|
||||
m.Echo(t)
|
||||
return
|
||||
@ -434,55 +510,73 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
return
|
||||
}
|
||||
|
||||
sid, bid := "", ""
|
||||
switch m.Cmdx("aaa.auth", arg[0]) {
|
||||
bid := ""
|
||||
switch m.Conf("auth", []string{arg[0], "type"}) {
|
||||
case "session":
|
||||
sid, bid, arg = arg[0], m.Spawn().Cmd("auth", arg[0], "ship", "bench").Append("key"), arg[1:]
|
||||
defer func() { m.Set("result").Echo(bid) }()
|
||||
if len(arg) == 1 {
|
||||
m.Confm("auth", []string{arg[0], "ship"}, func(key string, ship map[string]interface{}) {
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "type", ship["type"])
|
||||
m.Add("append", "meta", ship["meta"])
|
||||
m.Add("append", "create_time", ship["create_time"])
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
switch arg[1] {
|
||||
case "create":
|
||||
bid, arg = m.Cmdx("aaa.auth", arg[0], "ship", "bench", arg[2]), arg[3:]
|
||||
m.Cmdx("aaa.auth", bid, "data", "name", "web")
|
||||
case "select":
|
||||
m.Cmd("aaa.auth", arg[0], "ship", "bench").Table(func(maps map[string]string, list []string, line int) bool {
|
||||
if strings.Contains(maps["meta"], arg[2]) || strings.HasPrefix(maps["key"], arg[2]) || strings.HasSuffix(maps["key"], arg[2]) {
|
||||
bid = maps["key"]
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
arg = arg[3:]
|
||||
case "delete":
|
||||
}
|
||||
case "bench":
|
||||
bid, arg = arg[0], arg[1:]
|
||||
}
|
||||
|
||||
if bid == "" { // 创建空间
|
||||
bid = m.Spawn().Cmd("auth", sid, "ship", "bench", "web").Result(0)
|
||||
m.Spawn().Cmd("auth", bid, "data", "create_time", m.Time(), "share", "protected")
|
||||
defer func() { m.Set("result").Echo(bid) }()
|
||||
}
|
||||
|
||||
if len(arg) == 0 {
|
||||
m.Echo(bid)
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "export":
|
||||
m.Echo(m.Cmd("ctx.config", "auth", bid).Cmd("select", "key", "data").Append("value"))
|
||||
case "delete":
|
||||
m.Cmd("aaa.auth", bid, "delete", "node")
|
||||
case "rename":
|
||||
m.Cmd("aaa.auth", bid, "data", "name", arg[1])
|
||||
case "right":
|
||||
if len(arg) >= 6 {
|
||||
com := m.Cmd("aaa.auth", bid, "ship", "command")
|
||||
for i, v := range com.Meta["meta"] {
|
||||
if v == arg[5] {
|
||||
m.Echo(com.Meta["key"][i])
|
||||
return
|
||||
m.Cmd("aaa.auth", bid, "ship", "command").Table(func(maps map[string]string, list []string, line int) bool {
|
||||
if maps["meta"] == arg[5] {
|
||||
m.Echo(maps["key"])
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
} else if len(arg) >= 4 {
|
||||
com := m.Cmd("aaa.auth", bid, "ship", "componet")
|
||||
for i, v := range com.Meta["meta"] {
|
||||
if v == arg[3] {
|
||||
m.Echo(com.Meta["key"][i])
|
||||
return
|
||||
m.Cmd("aaa.auth", bid, "ship", "componet").Table(func(maps map[string]string, list []string, line int) bool {
|
||||
if maps["meta"] == arg[3] {
|
||||
m.Echo(maps["key"])
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
cid := m.Cmdx("aaa.auth", "ship", "userrole", arg[1:])
|
||||
if cid != "" {
|
||||
if cid := m.Cmdx("aaa.auth", "ship", "userrole", arg[1:]); cid != "" {
|
||||
m.Cmd("aaa.auth", bid, cid)
|
||||
m.Echo(cid)
|
||||
}
|
||||
m.Echo(cid)
|
||||
case "share":
|
||||
default:
|
||||
m.Cmdx("aaa.auth", bid, "data", arg)
|
||||
}
|
||||
}},
|
||||
|
||||
|
@ -1468,7 +1468,8 @@ func (m *Message) Cmdx(args ...interface{}) string {
|
||||
return m.Cmd(args...).Result(0)
|
||||
}
|
||||
func (m *Message) Cmdy(args ...interface{}) *Message {
|
||||
return m.Cmd(args...).CopyTo(m)
|
||||
m.Cmd(args...).CopyTo(m)
|
||||
return m
|
||||
}
|
||||
func (m *Message) Cmds(args ...interface{}) bool {
|
||||
return m.Cmd(args...).Results(0)
|
||||
@ -2346,6 +2347,22 @@ var CGI = template.FuncMap{
|
||||
return ""
|
||||
},
|
||||
|
||||
"work": func(m *Message, arg ...interface{}) interface{} {
|
||||
switch len(arg) {
|
||||
case 0:
|
||||
list := map[string]map[string]interface{}{}
|
||||
m.Confm("auth", []string{m.Option("sessid"), "ship"}, func(key string, ship map[string]interface{}) {
|
||||
if ship["type"] == "bench" {
|
||||
if work := m.Confm("auth", key); work != nil {
|
||||
list[key] = work
|
||||
}
|
||||
}
|
||||
})
|
||||
return list
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
||||
"unescape": func(str string) interface{} {
|
||||
return template.HTML(str)
|
||||
},
|
||||
|
@ -44,6 +44,46 @@ func proxy(m *ctx.Message, url string) string {
|
||||
|
||||
return "proxy/" + url
|
||||
}
|
||||
func merge(m *ctx.Message, uri string, arg ...string) string {
|
||||
add, e := url.Parse(uri)
|
||||
m.Assert(e)
|
||||
|
||||
if add.Scheme == "" {
|
||||
add.Scheme = m.Conf("protocol")
|
||||
}
|
||||
if add.Host == "" {
|
||||
add.Host = m.Conf("hostname")
|
||||
}
|
||||
if add.Path == "" {
|
||||
add.Path = path.Join(m.Conf("path"), m.Conf("file"))
|
||||
} else if !path.IsAbs(add.Path) {
|
||||
add.Path = path.Join(m.Conf("path"), add.Path)
|
||||
}
|
||||
if add.RawQuery == "" {
|
||||
add.RawQuery = m.Conf("query")
|
||||
}
|
||||
|
||||
query := add.Query()
|
||||
for i := 0; i < len(arg)-1; i += 2 {
|
||||
value := arg[i+1]
|
||||
if len(arg[i+1]) > 1 {
|
||||
switch arg[i+1][0] {
|
||||
case '$':
|
||||
value = m.Cap(arg[i+1][1:])
|
||||
case '@':
|
||||
value = m.Conf(arg[i+1][1:])
|
||||
}
|
||||
}
|
||||
|
||||
if value == "" {
|
||||
query.Del(arg[i])
|
||||
} else {
|
||||
query.Set(arg[i], value)
|
||||
}
|
||||
}
|
||||
add.RawQuery = query.Encode()
|
||||
return add.String()
|
||||
}
|
||||
func Merge(m *ctx.Message, uri string, arg ...string) string {
|
||||
uri = strings.Replace(uri, ":/", "://", -1)
|
||||
uri = strings.Replace(uri, ":///", "://", -1)
|
||||
@ -397,6 +437,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}, Help: "工作流"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"merge": &ctx.Command{Name: "merge", Help: "添加浏览器配置, address: 默认地址, output: 输出路径, editor: 编辑器", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
m.Echo(merge(m, arg[0], arg[1:]...))
|
||||
}},
|
||||
"client": &ctx.Command{Name: "client address [output [editor]]", Help: "添加浏览器配置, address: 默认地址, output: 输出路径, editor: 编辑器", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
uri, e := url.Parse(arg[0])
|
||||
m.Assert(e)
|
||||
@ -1055,25 +1098,26 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
|
||||
// 响应模板
|
||||
group, order := m.Option("componet_group", m.Confx("componet_group")), m.Option("componet_name")
|
||||
userrole := m.Option("userrole", m.Cmd("web.session").Append("userrole"))
|
||||
|
||||
// 会话检查
|
||||
if userrole == "" { // 用户登录
|
||||
if m.Options("right", !m.Confs("login_right") || !m.Confs("componet", "login")) {
|
||||
// 禁用权限
|
||||
} else if userrole := m.Option("userrole", m.Cmd("web.session").Append("userrole")); userrole == "" { // 用户登录
|
||||
group, order = m.Option("componet_group", "login"), m.Option("componet_name", "")
|
||||
} else if group == "login" { // 登录成功
|
||||
return
|
||||
} else if !m.Options("bench") || !m.Cmds("aaa.work", m.Option("bench")) { // 创建空间
|
||||
m.Append("redirect", fmt.Sprintf("%s?bench=%s", m.Option("index_path"), m.Cmdx("aaa.work", m.Option("sessid"))))
|
||||
m.Append("redirect", merge(m, m.Option("index_url"), "bench", m.Cmdx("aaa.work", m.Option("sessid"), "create", "web")))
|
||||
return
|
||||
} else if !m.Options("right", !m.Confs("login_right") || group == "login" ||
|
||||
m.Cmds("aaa.work", m.Option("bench"), "right", userrole, "componet", m.Option("componet_group"))) { // 没有权限
|
||||
} else if !m.Options("right", m.Cmds("aaa.work", m.Option("bench"), "right", m.Option("userrole"), "componet", m.Option("componet_group"))) { // 没有权限
|
||||
group, order = m.Option("componet_group", "login"), m.Option("componet_name", "")
|
||||
} else { //n访问成功
|
||||
m.Cmd("aaa.auth", m.Option("bench"), "data", "access_time", m.Time())
|
||||
m.Optionv("session", m.Confv("auth", []string{m.Option("sessid")}))
|
||||
m.Optionv("bench_data", m.Confv("auth", []string{m.Option("bench"), "data"}))
|
||||
}
|
||||
|
||||
m.Log("info", "json: %v group: %v order: %v userrole: %v right: %v", accept_json, group, order, userrole, m.Option("right"))
|
||||
m.Log("info", "json: %v group: %v order: %v userrole: %v right: %v", accept_json, group, order, m.Option("userrole"), m.Option("right"))
|
||||
|
||||
for _, v := range m.Confv("componet", group).([]interface{}) {
|
||||
val := v.(map[string]interface{})
|
||||
@ -1143,17 +1187,19 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}
|
||||
|
||||
// 执行命令
|
||||
if pre_run || m.Cmds("aaa.work", m.Option("bench"), "right", userrole, "componet", m.Option("componet_group"), "command", args[0]) {
|
||||
if pre_run || !m.Options("bench") || m.Cmds("aaa.work", m.Option("bench"), "right", m.Option("userrole"), "componet", m.Option("componet_group"), "command", args[0]) {
|
||||
msg.Cmd(args)
|
||||
|
||||
name_alias := "action." + msg.Option("componet_name")
|
||||
if msg.Options("componet_name_alias") {
|
||||
name_alias = "action." + msg.Option("componet_name_alias")
|
||||
}
|
||||
if m.Options("bench") {
|
||||
name_alias := "action." + msg.Option("componet_name")
|
||||
if msg.Options("componet_name_alias") {
|
||||
name_alias = "action." + msg.Option("componet_name_alias")
|
||||
}
|
||||
|
||||
msg.Put("option", name_alias, map[string]interface{}{
|
||||
"action_time": msg.Time(), "order": m.Option("componet_name_order"), "cmd": args,
|
||||
}).Cmd("aaa.auth", m.Option("bench"), "data", "option", name_alias, "modify_time", msg.Time())
|
||||
msg.Put("option", name_alias, map[string]interface{}{
|
||||
"action_time": msg.Time(), "order": m.Option("componet_name_order"), "cmd": args,
|
||||
}).Cmd("aaa.auth", m.Option("bench"), "data", "option", name_alias, "modify_time", msg.Time())
|
||||
}
|
||||
}
|
||||
|
||||
// 添加响应
|
||||
|
@ -28,6 +28,7 @@ var Index = &ctx.Context{Name: "wiki", Help: "文档中心",
|
||||
}, Help: "路由数量"},
|
||||
|
||||
"bench_disable": &ctx.Config{Name: "bench_disable", Value: "true", Help: "工作流"},
|
||||
"login_right": &ctx.Config{Name: "login_right", Value: "1", Help: "默认组件"},
|
||||
"componet_group": &ctx.Config{Name: "component_group", Value: "index", Help: "默认组件"},
|
||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||
"index": []interface{}{
|
||||
|
@ -30,7 +30,7 @@ function save_clipboard(item) {
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"cmd": "bench "+context.Search("bench")+".clipstack"+" '"+JSON.stringify(txt)+"'"
|
||||
"cmd": "aaa.work "+context.Search("bench")+" clipstack '"+JSON.stringify(txt)+"'"
|
||||
}, function(msg) {
|
||||
alert("保存成功")
|
||||
})
|
||||
@ -819,7 +819,7 @@ function init_docker() {
|
||||
// 事件
|
||||
docker.querySelectorAll("li>ul>li").forEach(function(item) {
|
||||
if (bench_data.board["key"] == item.dataset["key"]) {
|
||||
item.className = "stick"
|
||||
// item.className = "stick"
|
||||
}
|
||||
|
||||
item.onclick = function(event) {
|
||||
@ -867,7 +867,7 @@ function init_docker() {
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"cmd": "bench "+context.Search("bench")+".comment"+" "+prompt("name"),
|
||||
"cmd": "aaa.work "+context.Search("bench")+" rename "+prompt("name"),
|
||||
})
|
||||
location.reload()
|
||||
return
|
||||
@ -875,7 +875,7 @@ function init_docker() {
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "command",
|
||||
"cmd": "~code bench delete "+context.Search("bench"),
|
||||
"cmd": "aaa.work "+context.Search("bench")+" delete",
|
||||
})
|
||||
var b = ""
|
||||
document.querySelectorAll("div.workflow>ul.docker>li>ul.fly>li[data-key]").forEach(function(item){
|
||||
|
@ -128,6 +128,9 @@
|
||||
table.append td.clip {
|
||||
background-color:red;
|
||||
}
|
||||
table.append td:hover {
|
||||
background-color:red;
|
||||
}
|
||||
code.result pre {
|
||||
color:white;
|
||||
font-size:14px;
|
||||
@ -145,6 +148,7 @@
|
||||
</head>
|
||||
<body onkeydown="return onaction(event, 'scroll')" onkeyup="return onaction(event, 'keymap')">
|
||||
<script>
|
||||
var session ={{option . "session"}}
|
||||
var bench_data ={{option . "bench_data"}}
|
||||
</script>
|
||||
{{end}}
|
||||
@ -197,8 +201,8 @@
|
||||
<ul class="fly">
|
||||
<li data-action="refresh_fly">+ 刷新工作流(Ctrl+R)</li>
|
||||
<li data-action="create_fly">+ 添加工作流(Ctrl+T)</li>
|
||||
{{range $key, $item := conf . "bench"}}
|
||||
<li data-key="{{$key}}">{{index $item "modify_time"}} {{index $item "comment"}}({{slice $key 0 6}})</li>
|
||||
{{range $key, $item := work .}}
|
||||
<li data-key="{{$key}}">{{index $item "create_time"}} {{index $item "data" "name"}}({{slice $key 0 6}})</li>
|
||||
{{end}}
|
||||
<li data-action="rename_fly">+ 命名工作流</li>
|
||||
<li data-action="remove_fly">+ 删除工作流</li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user