1
0
forked from x/ContextOS

fix ctx.option

This commit is contained in:
shaoying 2019-08-01 22:50:20 +08:00
parent 831ead99e0
commit a1332f9eee
11 changed files with 77 additions and 64 deletions

View File

@ -456,20 +456,17 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
// 检查权限
case "check":
if role == "root" {
// 超级权限
m.Echo("true")
} else if len(arg) == 1 {
} else if m.Cmds("aaa.auth", "userrole", role, "check", "componet", arg[1]) {
// 组件权限
m.Echo("true")
} else if len(arg) == 2 {
} else if m.Cmds("aaa.auth", "userrole", role, "componet", arg[1], "check", "command", arg[2]) {
// 命令权限
m.Echo("true")
switch len(arg) {
case 1: // 超级权限
m.Echo("%t", role == "root")
case 2: // 组件权限
m.Echo("%t", role == "root" || m.Cmds("aaa.auth", "userrole", role, "check", "componet", arg[1]))
case 3: // 命令权限
m.Echo("%t", role == "root" || m.Cmds("aaa.auth", "userrole", role, "componet", arg[1], "check", "command", arg[2]))
default: // 参数权限
m.Echo("%t", role == "root" || m.Cmds("aaa.auth", "userrole", role, "componet", arg[1], "check", "command", arg[2]))
}
m.Log("right", "%v %v: %v %v %v", m.Result(0), m.Option("sessid"), m.Option("username"), role, arg[1:])
// 用户管理
case "user":
@ -746,8 +743,8 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
// 生成证书
template := x509.Certificate{
SerialNumber: big.NewInt(1),
IsCA: true,
SerialNumber: big.NewInt(1),
IsCA: true,
BasicConstraintsValid: true,
KeyUsage: x509.KeyUsageCertSign,
Subject: pkix.Name{CommonName: kit.Format(common)},

View File

@ -856,7 +856,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
if m.Cmdy("cli.system", env, "go", "build", o, "-o", q, p); m.Result(0) == "" {
m.Append("time", m.Time())
m.Append("hash", kit.Hashs(q)[:8])
m.Append("hash", m.Cmdx("nfs.hash", q)[:8])
m.Append("bin", q)
m.Table()
}
@ -1048,7 +1048,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
p := path.Join(m.Conf("missyou", "path"), arg[0])
if _, e := os.Stat(p); e != nil {
m.Cmd("nfs.copy", path.Join(p, "etc/local.shy"), path.Join(m.Conf("publish", "path"), kit.Select("hello", arg, 1), "local.shy"))
m.Confm("missyou", "local", func(index string, local string) {
m.Cmd("nfs.git", "clone", local, path.Join(p, m.Conf("missyou", "local"), index))
})
@ -1057,6 +1056,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
args := []string{
"daemon", "cmd_dir", p,
"cmd_env", "PATH", os.Getenv("PATH"),
"cmd_env", "ctx_type", kit.Select("hello", arg, 1),
"cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"),
"cmd_env", "ctx_ups", fmt.Sprintf("127.0.0.1%s", m.Conf("runtime", "boot.ssh_port")),
"cmd_env", "ctx_box", fmt.Sprintf("http://127.0.0.1%s", m.Conf("runtime", "boot.web_port")),

View File

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-08-01 09:34:16", "com.mac", 245,
"2019-08-01 17:49:56", "ZYB-20190522USI", 350,
}

View File

@ -729,9 +729,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
"message": &Command{Name: "message [code] [cmd...]", Help: "查看消息", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
msg := m
if len(arg) > 0 {
msg = msg.root
if code, e := strconv.Atoi(arg[0]); e == nil {
ms := []*Message{m}
ms := []*Message{m.root}
for i := 0; i < len(ms); i++ {
if ms[i].Code() == code {
msg = ms[i]
@ -742,6 +741,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
}
}
}
m.Optionv("bio.msg", msg)
if len(arg) == 0 {
// m.Format("summary", msg, "deep")
@ -809,7 +809,40 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
return
}},
"option": &Command{Name: "option", Help: "查看或添加选项", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
all := false
if len(arg) > 0 && arg[0] == "all" {
all, arg = true, arg[1:]
}
msg := m.Optionv("bio.msg").(*Message)
if len(arg) == 0 {
vals := map[string]interface{}{}
list := []string{}
for back := msg; back != nil; back = back.message {
for _, k := range back.Meta["option"] {
if _, ok := vals[k]; !ok {
if _, ok := back.Data[k]; ok {
vals[k] = back.Data[k]
} else {
vals[k] = back.Meta[k]
}
list = append(list, k)
}
}
if !all {
break
}
}
sort.Strings(list)
for _, k := range list {
m.Push("key", k)
m.Push("val", kit.Format(vals[k]))
}
m.Table()
return
}
switch v := msg.Optionv(arg[0]).(type) {
case []string:
m.Echo(strings.Join(v, ""))

View File

@ -34,34 +34,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
},
Configs: map[string]*ctx.Config{
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
"favor": []interface{}{
map[string]interface{}{"componet_name": "clip", "componet_help": "粘贴板",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "public", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "aaa", "clip"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "you", "imports": "plugin_you", "action": "auto"},
map[string]interface{}{"type": "text", "name": "txt", "view": "long"},
map[string]interface{}{"type": "button", "value": "存储", "action": "auto"},
},
},
map[string]interface{}{"componet_name": "qrcode", "componet_help": "二维码",
"componet_tmpl": "componet", "componet_view": "QRCode", "componet_init": "initQRCode.js",
"componet_type": "public", "componet_ctx": "web.chat", "componet_cmd": "login",
"componet_args": []interface{}{"qrcode"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "txt", "view": "long"},
map[string]interface{}{"type": "button", "value": "生成"},
},
},
map[string]interface{}{"componet_name": "salary", "componet_help": "工资单",
"componet_tmpl": "componet", "componet_view": "Salary", "componet_init": "",
"componet_type": "public", "componet_ctx": "web.chat", "componet_cmd": "salary",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"label": "total", "type": "text", "name": "text"},
map[string]interface{}{"label": "base", "type": "text", "name": "total", "value": "9000"},
map[string]interface{}{"type": "button", "value": "计算"},
},
},
},
"index": []interface{}{
map[string]interface{}{"componet_name": "dir", "componet_help": "目录",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
@ -973,7 +945,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}
// 权限检查
if !m.Cmds("aaa.role", m.Option("userrole"), "check", "remote", arg[0]) {
if !m.Cmds("aaa.role", m.Option("userrole"), "check", arg) {
m.Echo("no right %s %s", "remote", arg[0])
return
}

View File

@ -297,6 +297,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
default:
// 命令列表
m.Set("option", "name")
m.Set("option", "init")
if len(arg) == 1 {
m.Confm("flow", []string{rid, "tool", arg[0], "list"}, func(index int, tool map[string]interface{}) {
m.Push("river", rid)

View File

@ -30,7 +30,7 @@ fun upgrade "升级" "" "" \
private \
text "" name pod imports plugin_pod \
select "" values script values restart values plugin values bench values portal values system \
text "" \
text "" name see imports plugin_see \
button "升级"
copy ssh._route $1 cli.upgrade $2 $3
@ -67,7 +67,7 @@ end
fun cmd "命令" "" "" \
private \
text "" name pod imports plugin_pod view long \
text "" name ctx imports plugin_ctx \
text "nfs" name ctx imports plugin_ctx \
text "pwd" \
button "执行"

View File

@ -1,4 +1,9 @@
{init: function(page, pane, field, option, output) {
{init: function(page, pane, plugin, field, option, output) {
kit.Log("hello world")
plugin.Run = function(event, args, cb) {
field.Run(event, ["share", args[0]], function(url) {
kit.AppendChild(output, [{img: [url]}])
})
}
}}

View File

@ -8,12 +8,13 @@ fun clip "粘贴板" "" "" \
copy ssh._route $1 aaa.clip $2
end
fun qrcode "二维码" "" "" \
fun qrcode "二维码" "" "index.js" \
public \
text "" view long \
button "生成"
table qrcode $1
let url = $1 || $referer
append qrcode $url
end
fun salary "工资单" "" "" \

View File

@ -265,6 +265,13 @@ page = Page({
}
this.Update([river, storm], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) {
if (args.length > 0 && args[0] == "share") {
typeof cbs == "function" && cbs(ctx.Share({"group": option.dataset.group, "name": option.dataset.name, "cmds": [
line.group, line.index, args[1]||"",
]}))
return
}
var plugin = event.Plugin || {}
var meta = plugin && plugin.Field && plugin.Field.Meta || {}
event.shiftKey? page.target.Pane.Send("field", plugin.Format()):

View File

@ -723,6 +723,12 @@ function Plugin(page, pane, field) {
})
return pane.View(field.parentNode, "plugin", field.Meta, [], field.Run).field.Plugin
},
Share: function() {
location.href
option
return
},
Check: function(target, cb) {
option.querySelectorAll(".args").forEach(function(item, index, list) {
@ -838,15 +844,6 @@ function Plugin(page, pane, field) {
display.deal = arg
plugin.ondaemon[display.deal||"table"](plugin.msg)
},
Location: function(event) {
output.className = "output long"
page.getLocation(function(res) {
field.Run(event, [parseInt(res.latitude*1000000+1400)/1000000.0, parseInt(res.longitude*1000000+6250)/1000000.0].concat(
kit.Selector(option, ".args", function(item) {return item.value}))
, plugin.ondaemon)
})
},
init: function() {},
}
@ -856,7 +853,7 @@ function Plugin(page, pane, field) {
var exports = JSON.parse(meta.exports||'["",""]')
JSON.parse(meta.inputs || "[]").map(plugin.Append)
plugin.init(page, pane, field, option, output)
plugin.init(page, pane, plugin, field, option, output)
return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
}
function Editor(plugin, option, output, width, height, space, msg) {