1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 08:48:06 +08:00

add pwd.js

This commit is contained in:
shaoying 2019-09-23 20:50:39 +08:00
parent d9a40b1c82
commit 5bafb5d9d0
11 changed files with 175 additions and 88 deletions

View File

@ -627,7 +627,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
m.Echo("%s%02x", short, len(v)-1)
}
} else {
} else if len(arg[0]) > 0 {
if i, e := strconv.ParseInt(arg[0][length:], 16, 64); e == nil {
m.Echo(m.Conf("aaa.short", []interface{}{short, int(i)}))
} else {
@ -779,8 +779,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

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-09-23 11:05:14", "centos", 565,
"2019-09-23 20:04:21", "centos", 596,
}

View File

@ -25,7 +25,7 @@ func (ctx *CTX) Spawn(m *Message, c *Context, arg ...string) Server {
func (ctx *CTX) Begin(m *Message, arg ...string) Server {
m.Option("ctx.routine", 0)
m.Option("log.disable", true)
m.Option("ctx.chain", "aaa", "ssh", "cli", "nfs")
m.Option("ctx.chain", "aaa", "ssh", "nfs", "cli", "web")
m.Option("table.limit", 30)
m.Option("table.offset", 0)
@ -58,7 +58,7 @@ func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Optionv("bio.ctx", m.Target())
m.Optionv("bio.msg", m)
m.Cap("stream", "stdio")
m.Cmd("aaa.role", "root", "user", m.Option("username", m.Conf("runtime", "boot.username")))
m.Cmd("aaa.role", m.Option("userrole", "root"), "user", m.Option("username", m.Conf("runtime", "boot.username")))
m.Option("sessid", m.Cmdx("aaa.user", "session", "select"))
m.Cmd("nfs.source", m.Conf("cli.system", "script.init")).Cmd("nfs.source", "stdio").Cmd("nfs.source", m.Conf("cli.system", "script.exit"))
@ -814,8 +814,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
}
}
// 默认参数
args := make([]string, 0, len(arg))
for i, j := 0, 1; i < len(arg); i++ {
args, j := make([]string, 0, len(arg)), 1
for i := 0; i < len(arg); i++ {
if strings.HasPrefix(arg[i], "__") {
if j < len(msg.Meta["detail"]) {
args = append(args, msg.Meta["detail"][j:]...)
@ -828,6 +828,9 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
args = append(args, arg[i])
}
}
if j < len(msg.Meta["detail"]) {
args = append(args, msg.Meta["detail"][j:]...)
}
msg.Cmdy(args)
return
}},

View File

@ -361,10 +361,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
args = append(args, msg.Parse(v))
}
}
msg.Log("time", "check: %v", m.Format("cost"))
if msg.Cmd(tool["cmd"], args, arg).CopyTo(m); !msg.Hand {
msg.Log("warn", "not found %v:%v", tool["ctx"], tool["cmd"])
}
msg.Cmd(tool["cmd"], args, arg).CopyTo(m)
default:
m.Confm("componet", arg[0:], func(value map[string]interface{}) {
@ -756,6 +753,19 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
rest, ps = old, append(ps, m.Cap("stream"))
}
if len(ps) == 0 {
// 发送前端
if m.Option("userrole") == "root" {
if !strings.Contains(old, ".") {
old = m.Option("username") + "." + old
}
m.CallBack(true, func(msg *ctx.Message) *ctx.Message {
m.Copy(msg, "append")
return nil
}, "web.wss", old, "sync", arg)
m.Table()
return
}
// 查找失败
m.Echo("error: not found %s", names[0]).Back(m)
return

View File

@ -1096,31 +1096,37 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
"/wss": &ctx.Command{Name: "/wss", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
r := m.Optionv("request").(*http.Request)
w := m.Optionv("response").(http.ResponseWriter)
agent := r.Header.Get("User-Agent")
if s, e := websocket.Upgrade(w, r, nil, 4096, 4096); m.Assert(e) {
h := kit.Hashs("uniq")
h := m.Option("wssid")
if h == "" || m.Confs("wss", h) {
h = kit.Hashs("uniq")
}
p := make(chan *ctx.Message, 10)
meta := map[string]interface{}{
"create_time": m.Time(),
"create_user": m.Option("username"),
"agent": r.Header.Get("User-Agent"),
"agent": agent,
"sessid": m.Option("sessid"),
"socket": s,
"channel": p,
}
m.Conf("wss", []string{m.Option("username"), h}, meta)
m.Conf("wss", h, meta)
p <- m.Spawn().Add("detail", "wss", h)
what := m
m.Log("info", "wss conn %v", h)
m.Log("wss", "conn %v %s", h, agent)
m.Gos(m.Spawn(), func(msg *ctx.Message) {
for {
if t, b, e := s.ReadMessage(); e == nil {
var data interface{}
if e := json.Unmarshal(b, &data); e == nil {
m.Log("info", "wss recv %s %d msg %v", h, t, data)
m.Log("wss", "recv %s %d msg %v", h, t, data)
} else {
m.Log("warn", "wss recv %s %d msg %v", h, t, e)
m.Log("wss", "recv %s %d msg %v", h, t, b)
data = b
}
what.Optionv("data", data)
@ -1137,15 +1143,15 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
s.WriteJSON(what.Meta)
}
s.Close()
m.Conf("wss", h, "")
m.Log("wss", "close %s %s", h, agent)
m.Conf("wss", []string{m.Option("username"), h}, "")
m.Log("warn", "wss close %s", h)
m.Conf("wss", h, "")
s.Close()
}
return
}},
"wss": &ctx.Command{Name: "wss", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
if len(arg) == 0 || arg[0] == "" {
m.Confm("wss", func(key string, value map[string]interface{}) {
if value["agent"] == nil {
return
@ -1164,7 +1170,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
if strings.Contains(arg[0], ".") {
vs := strings.SplitN(arg[0], ".", 2)
m.Confm("wss", vs[0], func(key string, value map[string]interface{}) {
if vs[1] == "*" || strings.Contains(kit.Format(value["agent"]), vs[1]) {
if len(vs) == 1 || vs[1] == "*" || strings.Contains(kit.Format(value["agent"]), vs[1]) {
list = append(list, key)
}
})
@ -1187,19 +1193,28 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
p <- m
m.CallBack(true, func(msg *ctx.Message) *ctx.Message {
if data, ok := m.Optionv("data").(map[string]interface{}); ok {
res := kit.Trans(data["result"])
m.Log("info", "result: %v", res)
if len(res) > 0 {
m.Result(res)
}
}
if len(list) == 1 && data["append"] != nil {
for _, k := range kit.Trans(data["append"]) {
m.Push(k, kit.Trans(data[k]))
}
} else {
m.Push("time", m.Time())
m.Push("key", m.Cmdx("aaa.short", v))
m.Push("action", kit.Format(arg[2:]))
m.Push("time", m.Time())
m.Push("key", m.Cmdx("aaa.short", v))
m.Push("action", kit.Format(arg[2:]))
m.Push("result", kit.Format(m.Meta["result"]))
return nil
res := kit.Trans(data["result"])
m.Push("return", kit.Format(res))
m.Log("wss", "result: %v", res)
}
} else {
m.Push("time", m.Time())
m.Push("key", m.Cmdx("aaa.short", v))
m.Push("action", kit.Format(arg[2:]))
}
return m
}, "skip")
m.Table()
} else {
m.Meta["detail"] = arg[1:]
p <- m

View File

@ -215,11 +215,10 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
if !m.Options("sessid") || !m.Options("username") {
return
}
m.Short("river")
// 自动入群
if m.Options("river") {
if m.Confs("flow", m.Option("river")) && !m.Confs("flow", []string{m.Option("river"), "user", m.Option("username")}) {
if m.Short("river"); m.Confs("flow", m.Option("river")) && !m.Confs("flow", []string{m.Option("river"), "user", m.Option("username")}) {
u := m.Cmdx("ssh._route", m.Conf("runtime", "work.route"), "_check", "work", m.Option("username"))
m.Conf("flow", []string{m.Option("river"), "user", m.Option("username"), "user"}, u)
}

View File

@ -48,13 +48,20 @@ fun media "娱乐" private \
end
end
kit wss "推送" private "web.wss" \
fun wss "推送" private \
text "" name wss imports plugin_wss \
text "" name cmd \
text "" name cmd view long \
button "推送" \
button "返回" click Last \
exports wss key
if $2 == ""
copy web.wss
else
copy web.wss _ sync
end
end
kit pos "位置" private \
button "查看" click getLocation \
button "显示" click openLocation \

View File

@ -288,6 +288,7 @@ var page = Page({check: true,
], 0)
},
Core: function(event, line, args, cbs) {
var msg = (event.msg = line || {})
var plugin = event.Plugin || page.plugin && page.plugin.Plugin || {}, engine = {
share: function(args) {
typeof cbs == "function" && cbs(ctx.Share({"group": option.dataset.group, "name": option.dataset.name, "cmds": [
@ -295,6 +296,39 @@ var page = Page({check: true,
]}))
return true
},
wss: function(id) {
return page.wssid = id
},
pwd: function(args) {
return [river, storm, page.plugin && page.plugin.Meta.name, page.input && page.input.name, page.input && page.input.value]
},
dir: function(rid, sid, pid, uid) {
if (!rid) {
return kit.Selector(page.river, "div.output>div.item>div.text>span", function(item) {
return item.innerText
})
}
if (!sid) {
return kit.Selector(page.storm, "div.output>div.item>div.text>span", function(item) {
return item.innerText
})
}
if (!pid) {
return kit.Selector(page.action, "fieldset.item>legend", function(item) {
return item.innerText
})
}
if (!uid) {
msg.append = ["name", "value"]
msg.name = [], msg.value = []
return kit.Selector(page.plugin, "input", function(item) {
msg.name.push(item.name)
msg.value.push(item.value)
return item.name+":"+item.value
})
}
return [river, storm, page.plugin && page.plugin.Meta.name, page.input && page.input.name]
},
echo: function(one, two) {
kit.Log(one, two)
},
@ -328,21 +362,28 @@ var page = Page({check: true,
_split: function(str) {return str.trim().split(" ")},
_cmd: function(arg) {
var args = typeof arg[1] == "string"? engine._split(arg[1]): arg[1];
var res = null
page.script("record", args)
function result(res) {
res != null && res != undefined && !msg.result && (msg.result = [res])
return true
}
if (typeof engine[args[0]] == "function") {
return kit._call(engine[args[0]], args.slice(1))
return result(kit._call(engine[args[0]], args.slice(1)))
}
if (page.plugin && typeof page.plugin.Plugin[args[0]] == "function") {
return kit._call(page.plugin.Plugin[args[0]], args.slice(1))
return result(kit._call(page.plugin.Plugin[args[0]], args.slice(1)))
}
if (page.dialog && page.dialog.Pane.Jshy(event, args)) {return true}
if (page.pane && page.pane.Pane.Jshy(event, args)) {return true}
if (page.storm && page.storm.Pane.Jshy(event, args)) {return true}
if (page.river && page.river.Pane.Jshy(event, args)) {return true}
if (page.dialog && (res = page.dialog.Pane.Jshy(event, args))) {return result(res)}
if (page.pane && (res = page.pane.Pane.Jshy(event, args))) {return result(res)}
if (page.storm && (res = page.storm.Pane.Jshy(event, args))) {return result(res)}
if (page.river && (res = page.river.Pane.Jshy(event, args))) {return result(res)}
if (page && page.Jshy(event, args)) {return true}
if (page.plugin && page.plugin.Plugin.Jshy(event, args)) {return true}
if (page && (res = page.Jshy(event, args))) {return result(res)}
if (page.plugin && (res = page.plugin.Plugin.Jshy(event, args))) {return result(res)}
kit.Log("not find", arg[1])
return true
},

View File

@ -1,4 +1,4 @@
ctx = context = {
ctx = context = {__proto__: kit,
Run: function(dataset, cmd, cb) {
var option = {"cmds": cmd}
for (var k in dataset) {
@ -85,6 +85,32 @@ ctx = context = {
}
return ret
},
Upload: function(file, cb, detail) {
var data = new FormData()
data.append("upload", file)
var xhr = new XMLHttpRequest()
xhr.onload = function(event) {
var msg = JSON.parse(xhr.responseText||'{"result":[]}')
typeof cb == "function" && cb(event, msg)
}
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) {
return
}
if (xhr.status != 200) {
return
}
}
xhr.upload.onprogress = function(event) {
typeof detail == "function" && detail(event)
}
xhr.open("POST", "/upload", true)
xhr.send(data)
},
Share: function(objs) {
var args = this.Search()
for (var k in objs) {
@ -152,7 +178,7 @@ ctx = context = {
for (var k in key) {
document.cookie = k+"="+key[k];
}
return this.Cookie()
return arguments.callee()
}
if (value == undefined) {
var pattern = new RegExp(key+"=([^;]*);?")
@ -160,7 +186,7 @@ ctx = context = {
return result && result.length > 0? result[1]: ""
}
document.cookie = key+"="+value+";path=/"
return this.Cookie(key)
return arguments.callee(key)
},
POST: function(url, form, cb) {
var args = []
@ -205,9 +231,10 @@ ctx = context = {
xhr.send(args.join("&"))
},
WSS: function(cb, onerror, onclose) {
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/wss")
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/wss?wssid="+(page.wssid||""))
s.onopen = function(event) {
kit.Log(event)
kit.Log("wss", "open")
page.ontoast("wss open")
}
s.onmessage = function(event) {
var msg = JSON.parse(event.data)
@ -218,9 +245,14 @@ ctx = context = {
var msg = {"result": [event.data]}
}
msg.event = event, msg.reply = function(sub) {
s.send(JSON.stringify(sub||msg))
msg.event = event, msg.reply = function(res) {
res = res || msg, res.event = undefined
kit.Log(["wss", "detail"].concat(msg.detail))
kit.Log(["wss", "result"].concat(res.result))
s.send(JSON.stringify(res))
}
kit.Log(msg)
typeof cb == "function" && cb(msg)
}
s.onerror = function(event) {
@ -228,35 +260,10 @@ ctx = context = {
typeof onerror == "function" && onerror(event)
}
s.onclose = function(event) {
kit.Log(event)
kit.Log("wss", "close")
page.ontoast("wss close")
typeof onclose == "function" && onclose(event)
}
return s
},
Upload: function(file, cb, detail) {
var data = new FormData()
data.append("upload", file)
var xhr = new XMLHttpRequest()
xhr.onload = function(event) {
var msg = JSON.parse(xhr.responseText||'{"result":[]}')
typeof cb == "function" && cb(event, msg)
}
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) {
return
}
if (xhr.status != 200) {
return
}
}
xhr.upload.onprogress = function(event) {
typeof detail == "function" && detail(event)
}
xhr.open("POST", "/upload", true)
xhr.send(data)
},
}

View File

@ -128,7 +128,7 @@ function Meta(target, obj) {
}
function Page(page) {
var script = {}, record = ""
page = Meta(document.body, page, {
page = Meta(document.body, page, {__proto__: ctx,
onload: function() {
var sessid = ctx.Cookie("sessid")
if (page.check && !sessid) {
@ -425,20 +425,22 @@ function Page(page) {
return []
},
Jshy: function(event, args) {
var msg = event.msg || {}
if (page[args[0]] && page[args[0]].type == "fieldset") {
if (args.length > 1) {
return page[args[0]].Pane.Jshy(event, args.slice(1))
} else {
msg.result = ["pane", args[0]]
return page[args[0]].Pane.Show()
}
}
if (script[args[0]]) {
return page.script("replay", args[0])
}
if (script[args[0]]) {return page.script("replay", args[0])}
return typeof page[args[0]] == "function" && kit._call(page[args[0]], args.slice(1))
},
WSS: function(cb, onerror, onclose) {
return page.socket || (page.socket = ctx.WSS(cb || (function(m) {
if (m.detail) {
page.action.Pane.Core(event, m, ["_cmd", m.detail], function(msg) {
m.reply(msg)
@ -451,7 +453,7 @@ function Page(page) {
page.socket.close()
}), onclose || (function() {
setTimeout(function() {
page.socket = undefined, setTimeout(function() {
page.WSS(cb, onerror, onclose)
}, 1000)
})))
@ -633,14 +635,18 @@ function Pane(page, field) {
return text
},
Jshy: function(event, args) {
var msg = event.msg || {}
if (pane[args[0]] && pane[args[0]].type == "fieldset") {
msg.result = ["plugin", args[0]]
pane[args[0]].scrollIntoView(), pane[args[0]].Plugin.Select(true)
return pane[args[0]].Plugin.Jshy(event, args.slice(1))
}
if (typeof pane.Action[args[0]] == "function") {
msg.result = ["action", args[0]]
return kit._call(pane.Action[args[0]], [event, args[0]])
}
if (member[args[0]] != undefined) {
msg.result = ["item", args[0]]
pane.Select(member[args[0]].index, member[args[0]].key)
return true
}
@ -1010,11 +1016,10 @@ function Plugin(page, pane, field, runs) {
},
onaction: {
onfocus: function(event, action, type, name, item) {
page.input = event.target
plugin.Select(true)
page.input = event.target, plugin.Select(true)
},
onblur: function(event, action, type, name, item) {
page.input = undefined
// page.input = undefined
},
onclick: function(event, action, type, name, item) {
switch (type) {

View File

@ -1,4 +1,4 @@
kit = toolkit = {
kit = toolkit = {__proto__: document,
// 用户终端
device: {
isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1,