mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
mac opt web.share
This commit is contained in:
parent
717209f14c
commit
419c5487f5
@ -211,6 +211,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
if int64(msg.Capi("expire")) > time.Now().Unix() {
|
||||
m.Echo(msg.Cap("username"))
|
||||
m.Copy(msg, "target")
|
||||
m.Appendv("aaa", msg)
|
||||
m.Sess("aaa", msg)
|
||||
} else {
|
||||
delete(aaa.sessions, arg[0])
|
||||
@ -243,6 +244,8 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
if m.Cap("password") == aaa.Password(arg[1]) {
|
||||
m.Sess("aaa", m.Target())
|
||||
m.Echo(m.Cap("sessid"))
|
||||
m.Appendv("aaa", m)
|
||||
m.Sess("aaa", m)
|
||||
} else {
|
||||
m.Sess("aaa", c)
|
||||
}
|
||||
@ -255,8 +258,9 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
if !find {
|
||||
m.Start(m.Confx("aaa_name"), m.Confx("aaa_help"), arg[0], aaa.Password(arg[1]), aaa.Session(arg[0]))
|
||||
m.Cap("stream", arg[0])
|
||||
m.Sess("aaa", m)
|
||||
m.Echo(m.Cap("sessid"))
|
||||
m.Appendv("aaa", m)
|
||||
m.Sess("aaa", m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ func Trans(arg ...interface{}) []string { // {{{
|
||||
for _, v := range val {
|
||||
ls = append(ls, fmt.Sprintf("%d", v))
|
||||
}
|
||||
case nil:
|
||||
default:
|
||||
ls = append(ls, fmt.Sprintf("%v", val))
|
||||
}
|
||||
@ -574,6 +575,9 @@ func (m *Message) Assert(e interface{}, msg ...string) bool { // {{{
|
||||
}
|
||||
|
||||
m.Log("error", "%s", fmt.Sprintln(e))
|
||||
if m.Confs("debug") {
|
||||
debug.PrintStack()
|
||||
}
|
||||
panic(m.Set("result", "error: ", fmt.Sprintln(e), "\n"))
|
||||
}
|
||||
|
||||
@ -1344,7 +1348,10 @@ func (m *Message) Optionv(key string, arg ...interface{}) interface{} { // {{{
|
||||
}
|
||||
for _, k := range msg.Meta["option"] {
|
||||
if k == key {
|
||||
return msg.Data[key]
|
||||
if v, ok := msg.Data[key]; ok {
|
||||
return v
|
||||
}
|
||||
return msg.Meta[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1409,7 +1416,10 @@ func (m *Message) Appendv(key string, arg ...interface{}) interface{} { // {{{
|
||||
}
|
||||
for _, k := range ms[i].Meta["append"] {
|
||||
if k == key {
|
||||
return ms[i].Data[key]
|
||||
if v, ok := ms[i].Data[key]; ok {
|
||||
return v
|
||||
}
|
||||
return ms[i].Meta[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2097,7 +2107,7 @@ var CGI = template.FuncMap{
|
||||
}
|
||||
case string:
|
||||
if len(arg) == 2 {
|
||||
return m.Meta[value]
|
||||
return m.Optionv(value)
|
||||
}
|
||||
|
||||
switch val := arg[2].(type) {
|
||||
@ -2215,7 +2225,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
"chain": &Config{Name: "chain", Value: map[string]interface{}{}, Help: "调试模式,on:打印,off:不打印)"},
|
||||
"compact_log": &Config{Name: "compact_log(true/false)", Value: "true", Help: "调试模式,on:打印,off:不打印)"},
|
||||
"auto_make": &Config{Name: "auto_make(true/false)", Value: "true", Help: "调试模式,on:打印,off:不打印)"},
|
||||
"debug": &Config{Name: "debug(on/off)", Value: "off", Help: "调试模式,on:打印,off:不打印)"},
|
||||
"debug": &Config{Name: "debug(on/off)", Value: "on", Help: "调试模式,on:打印,off:不打印)"},
|
||||
|
||||
"search_method": &Config{Name: "search_method(find/search)", Value: "search", Help: "搜索方法, find: 模块名精确匹配, search: 模块名或帮助信息模糊匹配"},
|
||||
"search_choice": &Config{Name: "search_choice(first/last/rand/magic)", Value: "magic", Help: "搜索匹配, first: 匹配第一个模块, last: 匹配最后一个模块, rand: 随机选择, magic: 加权选择"},
|
||||
@ -3358,10 +3368,36 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||
delete(cs[i].Commands, arg[2])
|
||||
} else if len(arg) == 4 {
|
||||
delete(cs[i].Commands[arg[2]].Shares, arg[3])
|
||||
} else if len(arg) == 5 {
|
||||
delete(cs[i].Commands[arg[2]].Shares, arg[3])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
case "show":
|
||||
switch arg[1] {
|
||||
case "cache":
|
||||
case "config":
|
||||
case "command":
|
||||
case "context":
|
||||
for friend, x := range share.Index {
|
||||
for command, c := range x.Commands {
|
||||
m.Add("append", "friend", friend)
|
||||
m.Add("append", "key", command)
|
||||
m.Add("append", "arg", "")
|
||||
m.Add("append", "value", "")
|
||||
for a, s := range c.Shares {
|
||||
for _, v := range s {
|
||||
m.Log("fuck", "fuck %v %v %v %v", friend, command, a, v)
|
||||
m.Add("append", "friend", friend)
|
||||
m.Add("append", "key", command)
|
||||
m.Add("append", "arg", a)
|
||||
m.Add("append", "value", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // }}}
|
||||
}},
|
||||
},
|
||||
|
@ -59,7 +59,7 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
||||
"nlog": &ctx.Cache{Name: "nlog", Value: "0", Help: "日志屏蔽类型"},
|
||||
},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"silent": &ctx.Config{Name: "silent", Value: map[string]interface{}{"cb": true}, Help: "日志屏蔽类型"},
|
||||
"silent": &ctx.Config{Name: "silent", Value: map[string]interface{}{"cb": true, "find": true}, Help: "日志屏蔽类型"},
|
||||
"module": &ctx.Config{Name: "module", Value: map[string]interface{}{
|
||||
"log": map[string]interface{}{"cmd": true},
|
||||
"lex": map[string]interface{}{"cmd": true, "debug": true},
|
||||
|
@ -1234,6 +1234,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
continue
|
||||
case "csv":
|
||||
cmd := exec.Command("git", "log", "--shortstat", "--pretty=commit: %ad", "--date=format:%Y-%m-%d")
|
||||
m.Log("fuck", "wh%v", cmd)
|
||||
if out, e := cmd.CombinedOutput(); e != nil {
|
||||
m.Echo("error: ")
|
||||
m.Echo("%s\n", e)
|
||||
|
@ -123,8 +123,7 @@ func (web *WEB) Trans(m *ctx.Message, key string, hand func(*ctx.Message, *ctx.C
|
||||
|
||||
// }}}
|
||||
func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) { // {{{
|
||||
m := web.Message()
|
||||
m.Log("cmd", "%v %s %s", r.RemoteAddr, r.Method, r.URL)
|
||||
m := web.Message().Log("info", "").Log("info", "%v %s %s", r.RemoteAddr, r.Method, r.URL)
|
||||
|
||||
if m.Confs("logheaders") {
|
||||
for k, v := range r.Header {
|
||||
@ -303,6 +302,14 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
}, Help: "执行条件"},
|
||||
"index": &ctx.Config{Name: "index", Value: map[string]interface{}{
|
||||
"shy": []interface{}{
|
||||
map[string]interface{}{
|
||||
"template": "userinfo", "title": "userinfo",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"module": "web", "command": "/share",
|
||||
"argument": []interface{}{},
|
||||
"template": "share", "title": "share",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"module": "cli", "command": "system",
|
||||
"argument": []interface{}{"tmux", "list-clients"},
|
||||
@ -630,6 +637,13 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
r := m.Optionv("request").(*http.Request) // {{{
|
||||
w := m.Optionv("response").(http.ResponseWriter)
|
||||
|
||||
//权限检查
|
||||
dir := path.Join(m.Cap("directory"), m.Option("dir", strings.TrimPrefix(m.Option("path"), "/index")))
|
||||
if check := m.Spawn(c).Cmd("/check", "command", "/index/", "dir", dir); !check.Results(0) {
|
||||
m.Copy(check, "append")
|
||||
return
|
||||
}
|
||||
|
||||
//执行命令
|
||||
if m.Has("details") {
|
||||
if check := m.Spawn().Cmd("/check", "target", m.Option("module"), "command", m.Option("details")); !check.Results(0) {
|
||||
@ -642,25 +656,19 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
return
|
||||
}
|
||||
|
||||
//权限检查
|
||||
dir := path.Join(m.Cap("directory"), m.Option("dir", strings.TrimPrefix(m.Option("path"), "/index")))
|
||||
check := m.Spawn(c).Cmd("/check", "command", "/index/", "dir", dir)
|
||||
if !check.Results(0) {
|
||||
m.Copy(check, "append")
|
||||
return
|
||||
}
|
||||
|
||||
//下载文件
|
||||
if s, e := os.Stat(dir); e == nil && m.Option("dir") != "" && !s.IsDir() {
|
||||
if s, e := os.Stat(dir); e == nil && !s.IsDir() {
|
||||
http.ServeFile(w, r, dir)
|
||||
return
|
||||
}
|
||||
|
||||
if !m.Options("module") {
|
||||
m.Option("module", "web")
|
||||
}
|
||||
//浏览目录
|
||||
aaa := check.Appendv("aaa").(*ctx.Message)
|
||||
m.Append("template", aaa.Cap("username"))
|
||||
m.Append("template", m.Append("username"))
|
||||
m.Option("title", "index")
|
||||
m.Option("dir", dir)
|
||||
m.Option("username", m.Append("username"))
|
||||
// }}}
|
||||
}},
|
||||
"/travel": &ctx.Command{Name: "/travel", Help: "文件上传", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
@ -932,56 +940,52 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
m.Append("redirect", m.Option("referer"))
|
||||
// }}}
|
||||
}},
|
||||
"/share": &ctx.Command{Name: "/share", Help: "资源共享", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
check := m.Spawn().Cmd("/check", "command", arg[0], arg[1], arg[2]) // {{{
|
||||
if !check.Results(0) {
|
||||
"/share": &ctx.Command{Name: "/share arg...", Help: "资源共享", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if check := m.Spawn().Cmd("/check", "target", m.Option("module"), m.Optionv("share")); !check.Results(0) {
|
||||
m.Copy(check, "append")
|
||||
return
|
||||
}
|
||||
|
||||
msg := check.Appendv("aaa").(*ctx.Message).Spawn(m.Target())
|
||||
if m.Options("shareto") {
|
||||
msg.Cmd("right", m.Option("shareto"), "add", "command", arg[0], arg[1], arg[2])
|
||||
if m.Options("friend") && m.Options("module") {
|
||||
m.Copy(m.Appendv("aaa").(*ctx.Message).Find(m.Option("module")).Cmd("right", m.Option("friend"), m.Option("action"), m.Optionv("share")), "result")
|
||||
if m.Confv("index", m.Option("friend")) == nil {
|
||||
m.Confv("index", m.Option("friend"), m.Confv("index", m.Append("username")))
|
||||
}
|
||||
return
|
||||
}
|
||||
if m.Options("notshareto") {
|
||||
msg.Cmd("right", m.Option("notshareto"), "del", "command", arg[0], arg[1], arg[2])
|
||||
|
||||
msg := m.Spawn().Cmd("right", "target", m.Option("module"), m.Append("username"), "show", "context")
|
||||
m.Copy(msg, "append")
|
||||
}},
|
||||
"/check": &ctx.Command{Name: "/check arg...", Help: "权限检查, cache|config|command: 接口类型, name: 接口名称, args: 其它参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
if login := m.Spawn().Cmd("/login"); login.Has("template") { // {{{
|
||||
m.Echo("no").Copy(login, "append")
|
||||
return
|
||||
}
|
||||
|
||||
if msg := m.Spawn().Cmd("right", m.Append("username"), "check", arg); !msg.Results(0) {
|
||||
m.Echo("no").Append("message", "no right, please contact manager")
|
||||
return
|
||||
}
|
||||
|
||||
m.Echo("ok")
|
||||
// }}}
|
||||
}},
|
||||
"/check": &ctx.Command{Name: "/check check", Help: "权限检查, cache|config|command: 接口类型, name: 接口名称, args: 其它参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
// w := m.Optionv("response").(http.ResponseWriter) //{{{
|
||||
if login := m.Spawn().Cmd("/login"); login.Has("redirect") {
|
||||
aaa := m.Appendv("aaa").(*ctx.Message)
|
||||
if msg := m.Spawn().Cmd("right", aaa.Cap("username"), "check", arg); msg.Results(0) {
|
||||
m.Copy(login, "append").Echo(msg.Result(0))
|
||||
return
|
||||
}
|
||||
// w.WriteHeader(http.StatusForbidden)
|
||||
m.Append("message", "no right, please contact manager")
|
||||
m.Echo("no")
|
||||
return
|
||||
} else {
|
||||
m.Copy(login, "append").Echo("no")
|
||||
}
|
||||
// }}}
|
||||
}},
|
||||
"/login": &ctx.Command{Name: "/login", Help: "用户登录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
w := m.Optionv("response").(http.ResponseWriter) // {{{
|
||||
|
||||
if m.Options("sessid") {
|
||||
if aaa := m.Find("aaa").Cmd("login", m.Option("sessid")); aaa.Results(0) {
|
||||
if m.Options("sessid") { // {{{
|
||||
if aaa := m.Sess("aaa").Cmd("login", m.Option("sessid")); aaa.Results(0) {
|
||||
m.Append("redirect", m.Option("referer"))
|
||||
m.Appendv("aaa", aaa)
|
||||
m.Append("username", aaa.Cap("username"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
w := m.Optionv("response").(http.ResponseWriter)
|
||||
if m.Options("username") && m.Options("password") {
|
||||
if aaa := m.Find("aaa").Cmd("login", m.Option("username"), m.Option("password")); aaa.Results(0) {
|
||||
if aaa := m.Sess("aaa").Cmd("login", m.Option("username"), m.Option("password")); aaa.Results(0) {
|
||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: aaa.Result(0)})
|
||||
m.Append("redirect", m.Option("referer"))
|
||||
m.Appendv("aaa", aaa)
|
||||
m.Append("username", m.Option("username"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +73,11 @@ ctx = {
|
||||
|
||||
var args = [];
|
||||
for (k in form) {
|
||||
if (form[k] != undefined) {
|
||||
if (form[k] instanceof Array) {
|
||||
for (i in form[k]) {
|
||||
args.push(k+"="+encodeURIComponent(form[k][i]));
|
||||
}
|
||||
} else if (form[k] != undefined) {
|
||||
args.push(k+"="+encodeURIComponent(form[k]));
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
{{define "userinfo"}}
|
||||
<fieldset><legend>userinfo</legend>
|
||||
welcome <span class="username">{{append . "username"}}</span> to context world
|
||||
welcome <span class="username">{{option . "username"}}</span> to context world
|
||||
<button onclick="return logout(event)">logout</button>
|
||||
</fieldset>
|
||||
<style>
|
||||
@ -21,7 +21,7 @@
|
||||
</style>
|
||||
<script>
|
||||
function logout(event) {
|
||||
ctx.Cookie("sessid", "");
|
||||
ctx.Cookie("sessid", ";path=/");
|
||||
ctx.Refresh();
|
||||
return false;
|
||||
}
|
||||
@ -30,49 +30,57 @@
|
||||
|
||||
{{define "share"}}
|
||||
<fieldset><legend>share</legend>
|
||||
<form method="POST">
|
||||
<label>share to:</label><input type="text" name="shareto" value="{{msg . "option" "dir"}}" required>
|
||||
<form method="POST" onsubmit="return share(event, '{{cap . "directory"}}{{option . "dir"|meta}}')">
|
||||
<label>share to:</label><input type="text" name="shareto" required>
|
||||
<input type="submit">
|
||||
</form>
|
||||
<table>
|
||||
<colgroup>{{range .Meta.append}}<col class="{{.}}">{{end}}</colgroup>
|
||||
<tr>{{range .Meta.append}}<th class="{{.}}">{{.}}</th>{{end}}</tr>
|
||||
|
||||
{{if .Meta.append}}
|
||||
{{$meta := .Meta}}
|
||||
{{$first := index .Meta.append 0}}
|
||||
{{range $i, $k := index $meta $first}}
|
||||
{{$msg := .}}
|
||||
{{$ncol := append . |len}}
|
||||
{{$nrow := append . 0|append .|len}}
|
||||
<tr>{{range append .}}<th><code onclick="sort_table('{{.}}')">{{.}}</code></th>{{end}}</tr>
|
||||
{{range $row, $val := append . 0|append .}}
|
||||
<tr>
|
||||
{{range $key := index $meta "append"}}
|
||||
<td class="{{$key}}">
|
||||
{{if eq $key "delete"}}
|
||||
<button onclick="return deleteshare(event, '{{index $meta "value" $i}}', '{{index $meta "group" $i}}')">delete</button>
|
||||
{{else}}
|
||||
<code>{{index $meta $key $i}}</code>
|
||||
{{end}}
|
||||
</td>
|
||||
{{range append $msg}}
|
||||
{{$value := append $msg . $row}}
|
||||
<td><code>
|
||||
{{if eq . "value"}}
|
||||
<code><a title="点击删除" href="/" onclick="deleteshare(event, '{{append $msg "friend" $row}}', '{{$value}}')">{{$value}}</a></code>
|
||||
{{else}}
|
||||
{{$value}}
|
||||
{{end}}
|
||||
</code></td>
|
||||
{{end}}
|
||||
</tr>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</table>
|
||||
</fieldset>
|
||||
<script>
|
||||
function share(event, dir) {
|
||||
if (dir.endsWith("/")) {
|
||||
dir = dir.substr(0, dir.length-1)
|
||||
}
|
||||
var fields = event.target.elements;
|
||||
var shareto = fields["shareto"].value
|
||||
ctx.POST("/upload", {
|
||||
shareto: shareto,
|
||||
sharedir: dir,
|
||||
ctx.POST("/share", {
|
||||
module: "web",
|
||||
friend: shareto,
|
||||
action: "add",
|
||||
share: ["command", "/index/", "dir", dir],
|
||||
}, function(msg) {
|
||||
ctx.Refresh();
|
||||
})
|
||||
return false;
|
||||
}
|
||||
function deleteshare(event, dir, group) {
|
||||
function deleteshare(event, group, dir) {
|
||||
if (!window.confirm("cancel share?")) {
|
||||
return
|
||||
}
|
||||
ctx.POST("/share", {
|
||||
notshareto: group,
|
||||
sharedir: dir,
|
||||
module: "web",
|
||||
friend: group,
|
||||
action: "del",
|
||||
share: ["command", "/index/", "dir"],
|
||||
}, function(msg) {
|
||||
ctx.Refresh();
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user