mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
mac mod web.travel
This commit is contained in:
parent
1d9bc356cf
commit
f0bd6d0f0e
@ -713,167 +713,126 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
||||
// }}}
|
||||
}},
|
||||
"/travel": &ctx.Command{Name: "/travel", Help: "文件上传", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||
r := m.Data["request"].(*http.Request) // {{{
|
||||
w := m.Data["response"].(http.ResponseWriter)
|
||||
w := m.Data["response"].(http.ResponseWriter) // {{{
|
||||
|
||||
dir := "ctx"
|
||||
if m.Options("dir") {
|
||||
dir = m.Option("dir")
|
||||
module := "ctx"
|
||||
if m.Options("module") {
|
||||
module = m.Option("module")
|
||||
}
|
||||
if m.Options("domain") {
|
||||
module = "ssh"
|
||||
}
|
||||
|
||||
if msg := m.Find(dir, true); msg != nil {
|
||||
if m.Option("method") == "POST" {
|
||||
switch m.Option("ccc") {
|
||||
case "config":
|
||||
m.Echo(msg.Conf(m.Option("name"), m.Option("value")))
|
||||
case "command":
|
||||
msg = msg.Spawn(msg.Target())
|
||||
msg.Cmd(m.Option("name"))
|
||||
m.Copy(msg, "result").Copy(msg, "append")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "head", m.Meta))
|
||||
|
||||
for k, v := range msg.Target().Caches {
|
||||
msg.Add("append", "key", k)
|
||||
msg.Add("append", "name", v.Name)
|
||||
msg.Add("append", "help", v.Help)
|
||||
msg.Add("append", "value", v.Value)
|
||||
}
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "cache", msg.Meta))
|
||||
}
|
||||
|
||||
msg = msg.Spawn(msg.Target())
|
||||
for k, v := range msg.Target().Configs {
|
||||
msg.Add("append", "key", k)
|
||||
msg.Add("append", "name", v.Name)
|
||||
msg.Add("append", "help", v.Help)
|
||||
msg.Add("append", "value", v.Value)
|
||||
msg.Add("append", "input", "")
|
||||
}
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "config", msg.Meta))
|
||||
}
|
||||
|
||||
msg = msg.Spawn(msg.Target())
|
||||
for k, v := range msg.Target().Commands {
|
||||
msg.Add("append", "key", k)
|
||||
msg.Add("append", "name", v.Name)
|
||||
msg.Add("append", "help", v.Help)
|
||||
msg.Add("append", "input", "")
|
||||
}
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "command", msg.Meta))
|
||||
}
|
||||
|
||||
msg = msg.Spawn(msg.Target())
|
||||
msg.Copy(m, "option")
|
||||
msg.Travel(msg.Target(), func(m *ctx.Message) bool {
|
||||
m.Add("append", "name", m.Target().Name)
|
||||
m.Add("append", "help", m.Target().Help)
|
||||
m.Add("append", "module", m.Cap("module"))
|
||||
m.Add("append", "status", m.Cap("status"))
|
||||
m.Add("append", "stream", m.Cap("stream"))
|
||||
return true
|
||||
})
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "context", msg.Meta))
|
||||
}
|
||||
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "tail", m.Meta))
|
||||
delete(m.Meta, "result")
|
||||
delete(m.Meta, "append")
|
||||
}
|
||||
|
||||
return
|
||||
if !m.Options("file") {
|
||||
m.Option("file", m.Cap("directory"))
|
||||
}
|
||||
|
||||
if m.Option("method") == "POST" {
|
||||
file, header, e := r.FormFile("file")
|
||||
m.Assert(e)
|
||||
|
||||
name := path.Join(dir, header.Filename)
|
||||
|
||||
if _, e := os.Stat(name); e != nil {
|
||||
f, e := os.Create(name)
|
||||
m.Assert(e)
|
||||
|
||||
_, e = io.Copy(f, file)
|
||||
m.Assert(e)
|
||||
m.Option("message", "", "\n", name)
|
||||
} else {
|
||||
m.Option("message", "", "\n", name, "already exist!")
|
||||
}
|
||||
}
|
||||
|
||||
branch := m.Find("nfs").Cmd("git", "-C", dir, "branch")
|
||||
m.Option("branch", branch.Result(0))
|
||||
status := m.Find("nfs").Cmd("git", "-C", dir, "status")
|
||||
m.Option("status", status.Result(0))
|
||||
|
||||
file := m.Option("file")
|
||||
|
||||
s, e := os.Stat(file)
|
||||
if m.Assert(e); !s.IsDir() {
|
||||
http.ServeFile(w, r, file)
|
||||
msg := m.Find(module, true)
|
||||
if msg == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fs, e := ioutil.ReadDir(file)
|
||||
m.Assert(e)
|
||||
if m.Option("method") == "POST" {
|
||||
switch m.Option("ccc") {
|
||||
case "cache":
|
||||
m.Echo(msg.Cap(m.Option("name")))
|
||||
case "config":
|
||||
if m.Options("value") {
|
||||
m.Echo(msg.Conf(m.Option("name"), m.Option("value")))
|
||||
} else {
|
||||
m.Echo(msg.Conf(m.Option("name")))
|
||||
}
|
||||
case "command":
|
||||
msg = msg.Spawn(msg.Target())
|
||||
if m.Options("domain") {
|
||||
module := "ssh"
|
||||
if m.Options("module") {
|
||||
module = m.Option("module")
|
||||
}
|
||||
if m.Options("value") {
|
||||
msg.Detail(0, "send", "context", module, m.Option("name"), m.Option("value"))
|
||||
} else {
|
||||
msg.Detail(0, "send", "context", module, m.Option("name"))
|
||||
}
|
||||
msg.Log("fuck", nil, "why %d ", len(msg.Meta["detail"]))
|
||||
|
||||
max := true
|
||||
if i, e := strconv.Atoi(m.Option("order")); e == nil {
|
||||
max = i%2 == 1
|
||||
}
|
||||
msg.Option("domain", m.Option("domain"))
|
||||
msg.CallBack(true, func(sub *ctx.Message) *ctx.Message {
|
||||
m.Copy(sub, "result").Copy(sub, "append")
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
if m.Options("value") {
|
||||
msg.Detail(0, m.Option("name"), m.Option("value"))
|
||||
} else {
|
||||
msg.Detail(0, m.Option("name"))
|
||||
}
|
||||
|
||||
switch m.Option("list") {
|
||||
case "time":
|
||||
if max {
|
||||
m.Option("message", "sort by time")
|
||||
sort.Sort(listtime(fs))
|
||||
} else {
|
||||
m.Option("message", "sort by time reverse")
|
||||
sort.Sort(sort.Reverse(listtime(fs)))
|
||||
msg.Cmd()
|
||||
m.Copy(msg, "result").Copy(msg, "append")
|
||||
}
|
||||
}
|
||||
case "size":
|
||||
if max {
|
||||
m.Option("message", "sort by size")
|
||||
sort.Sort(listsize(fs))
|
||||
} else {
|
||||
m.Option("message", "sort by size reverse")
|
||||
sort.Sort(sort.Reverse(listsize(fs)))
|
||||
}
|
||||
case "name":
|
||||
if max {
|
||||
m.Option("message", "sort by name")
|
||||
sort.Sort(listname(fs))
|
||||
} else {
|
||||
m.Option("message", "sort by name reverse")
|
||||
sort.Sort(sort.Reverse(listname(fs)))
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range fs {
|
||||
m.Add("append", "time", v.ModTime().Format("2006-01-02 15:04:05"))
|
||||
m.Add("append", "size", kit.FmtSize(v.Size()))
|
||||
|
||||
name := v.Name()
|
||||
if v.IsDir() {
|
||||
name += "/"
|
||||
}
|
||||
|
||||
m.Add("append", "name", name)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("upload_tpl"))).Execute(w, m.Meta))
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "head", m.Meta))
|
||||
|
||||
for k, v := range msg.Target().Caches {
|
||||
msg.Add("append", "key", k)
|
||||
msg.Add("append", "name", v.Name)
|
||||
msg.Add("append", "help", v.Help)
|
||||
msg.Add("append", "value", v.Value)
|
||||
}
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "cache", msg.Meta))
|
||||
}
|
||||
|
||||
msg = msg.Spawn(msg.Target())
|
||||
for k, v := range msg.Target().Configs {
|
||||
msg.Add("append", "key", k)
|
||||
msg.Add("append", "name", v.Name)
|
||||
msg.Add("append", "help", v.Help)
|
||||
msg.Add("append", "value", v.Value)
|
||||
msg.Add("append", "input", "")
|
||||
}
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "config", msg.Meta))
|
||||
}
|
||||
|
||||
msg = msg.Spawn(msg.Target())
|
||||
for k, v := range msg.Target().Commands {
|
||||
msg.Add("append", "key", k)
|
||||
msg.Add("append", "name", v.Name)
|
||||
msg.Add("append", "help", v.Help)
|
||||
msg.Add("append", "input", "")
|
||||
}
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "command", msg.Meta))
|
||||
}
|
||||
|
||||
msg = msg.Spawn(msg.Target())
|
||||
msg.Travel(msg.Target(), func(m *ctx.Message) bool {
|
||||
m.Add("append", "name", m.Target().Name)
|
||||
m.Add("append", "help", m.Target().Help)
|
||||
m.Add("append", "module", m.Cap("module"))
|
||||
m.Add("append", "status", m.Cap("status"))
|
||||
m.Add("append", "stream", m.Cap("stream"))
|
||||
return true
|
||||
})
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "context", msg.Meta))
|
||||
}
|
||||
|
||||
msg = msg.Find("ssh", true)
|
||||
msg.Option("domains", m.Option("domain"))
|
||||
msg.Travel(msg.Target(), func(m *ctx.Message) bool {
|
||||
m.Add("append", "name", m.Target().Name)
|
||||
m.Add("append", "help", m.Target().Help)
|
||||
m.Add("append", "domain", m.Conf("domains"))
|
||||
return true
|
||||
})
|
||||
if len(msg.Meta["append"]) > 0 {
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "domain", msg.Meta))
|
||||
}
|
||||
|
||||
m.Assert(template.Must(template.ParseGlob(m.Conf("travel_tpl"))).ExecuteTemplate(w, "tail", m.Meta))
|
||||
delete(m.Meta, "result")
|
||||
delete(m.Meta, "append")
|
||||
// }}}
|
||||
|
@ -13,15 +13,6 @@ ctx = {
|
||||
return this.Cookie(name);
|
||||
},
|
||||
Search: function(name, value) {
|
||||
if (value == undefined) {
|
||||
var pattern = new RegExp(name+"=([^&#]*)");
|
||||
var result = pattern.exec(location.search);
|
||||
if (result && result.length > 0) {
|
||||
return result[1];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
var args = {};
|
||||
var search = location.search.split("?");
|
||||
if (search.length > 1) {
|
||||
@ -31,7 +22,18 @@ ctx = {
|
||||
args[keys[0]] = decodeURIComponent(keys[1]);
|
||||
}
|
||||
}
|
||||
args[name] = value;
|
||||
|
||||
if (typeof name == "object") {
|
||||
for (var k in name) {
|
||||
if (name[k] != undefined) {
|
||||
args[k] = name[k];
|
||||
}
|
||||
}
|
||||
} else if (value == undefined) {
|
||||
return args[name];
|
||||
} else {
|
||||
args[name] = value;
|
||||
}
|
||||
|
||||
var arg = [];
|
||||
for (var k in args) {
|
||||
@ -46,8 +48,8 @@ ctx = {
|
||||
case 4:
|
||||
switch (xhr.status) {
|
||||
case 200:
|
||||
var msg = JSON.parse(xhr.responseText);
|
||||
console.log(msg)
|
||||
var msg = JSON.parse(xhr.responseText||'{"result":[]}');
|
||||
msg && console.log(msg)
|
||||
typeof cb == "function" && cb(msg)
|
||||
}
|
||||
break;
|
||||
@ -61,6 +63,10 @@ ctx = {
|
||||
form = form || {}
|
||||
form["dir"] = this.Search("dir")
|
||||
}
|
||||
if (!("module" in form)) {
|
||||
form = form || {}
|
||||
form["module"] = this.Search("module")
|
||||
}
|
||||
|
||||
var args = [];
|
||||
for (k in form) {
|
||||
@ -68,9 +74,44 @@ ctx = {
|
||||
}
|
||||
|
||||
var arg = args.join("&");
|
||||
console.log(url)
|
||||
console.log(arg)
|
||||
console.log("POST: "+url+"?"+arg);
|
||||
xhr.send(arg);
|
||||
},
|
||||
Cap: function(cap, cb) {
|
||||
this.POST("", {ccc:"cache", name:cap}, function(msg) {
|
||||
typeof cb == "function" && cb(msg.result.join(""));
|
||||
});
|
||||
},
|
||||
Conf: function(conf, value, cb) {
|
||||
if (typeof value == "function") {
|
||||
cb = value;
|
||||
value = undefined;
|
||||
}
|
||||
|
||||
var args = {ccc:"config", name:conf};
|
||||
if (value != undefined) {
|
||||
args.value = value
|
||||
}
|
||||
|
||||
this.POST("", args, function(msg) {
|
||||
typeof cb == "function" && cb(msg.result.join(""));
|
||||
});
|
||||
},
|
||||
Cmd: function(cmd, value, cb) {
|
||||
if (typeof value == "function") {
|
||||
cb = value;
|
||||
value = undefined;
|
||||
}
|
||||
|
||||
var args = {ccc:"command", name:cmd};
|
||||
if (value != undefined) {
|
||||
args.value = value
|
||||
}
|
||||
|
||||
this.POST("", args, cb);
|
||||
},
|
||||
Module: function(module, domain) {
|
||||
this.Search({module:module, domain:domain})
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@
|
||||
{{end}}
|
||||
|
||||
{{define "context"}}
|
||||
<fieldset><legend><input type="text" id="dir" value="{{index .dir 0}}" onkeydown="return Change(event)"></legend>
|
||||
<fieldset><legend><input type="text" id="module" value="{{index .module 0}}" onkeydown="return Change(event)"></legend>
|
||||
<table>
|
||||
<colgroup>{{range .append}}<col class="{{.}}">{{end}}</colgroup>
|
||||
<tr>{{range .append}}<th class="{{.}}" onclick="list('{{.}}')">{{.}}</th>{{end}}</tr>
|
||||
@ -138,7 +138,35 @@
|
||||
{{range $key := index $meta "append"}}
|
||||
{{if eq $key "name"}}
|
||||
<td class="{{$key}}">
|
||||
<code><a href="/travel?dir={{index $meta "module" $i}}">{{index $meta $key $i}}</a></code>
|
||||
<code><a href="/travel?module={{index $meta "module" $i}}">{{index $meta $key $i}}</a></code>
|
||||
</td>
|
||||
{{else}}
|
||||
<td class="{{$key}}">
|
||||
<code>{{index $meta $key $i}}</code>
|
||||
</td>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</tr>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</table>
|
||||
</fieldset>
|
||||
{{end}}
|
||||
|
||||
{{define "domain"}}
|
||||
<fieldset><legend><input type="text" id="domain" value="{{index . "domains" 0}}" onkeydown="return Change(event)"></legend>
|
||||
<table>
|
||||
<colgroup>{{range .append}}<col class="{{.}}">{{end}}</colgroup>
|
||||
<tr>{{range .append}}<th class="{{.}}" onclick="list('{{.}}')">{{.}}</th>{{end}}</tr>
|
||||
{{$l := index .append|len}}
|
||||
{{if gt $l 0}}
|
||||
{{$meta := .}} {{$first := index .append 0}}
|
||||
{{range $i, $k := index . $first}}
|
||||
<tr>
|
||||
{{range $key := index $meta "append"}}
|
||||
{{if eq $key "name"}}
|
||||
<td class="{{$key}}">
|
||||
<code><a href="/travel?domain={{index $meta "domain" $i}}">{{index $meta $key $i}}</a></code>
|
||||
</td>
|
||||
{{else}}
|
||||
<td class="{{$key}}">
|
||||
@ -162,7 +190,7 @@
|
||||
|
||||
function Config(event, name) {
|
||||
if (event.keyCode == 13) {
|
||||
ctx.POST("", {ccc:"config", name:name, value:event.currentTarget.value}, function(msg) {Refresh()})
|
||||
ctx.Conf(name, event.currentTarget.value, function(msg) {Refresh()});
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,9 +204,9 @@
|
||||
var direct = document.getElementById("direct");
|
||||
if (name) {
|
||||
direct.value = name;
|
||||
ctx.POST("", {ccc:"command", name:name, value:event.currentTarget.value}, Result)
|
||||
ctx.Cmd(name, event.currentTarget.value, Result);
|
||||
} else {
|
||||
ctx.POST("", {ccc:"command", name:event.currentTarget.value}, Result)
|
||||
ctx.Cmd(event.currentTarget.value, "", Result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,13 +219,13 @@
|
||||
|
||||
var direct = document.getElementById("direct");
|
||||
direct.value = name;
|
||||
ctx.POST("", {ccc:"command", name:name, value:value||""}, Result)
|
||||
ctx.Cmd(name, value, Result);
|
||||
return false;
|
||||
}
|
||||
|
||||
function Change(event) {
|
||||
if (event.keyCode == 13) {
|
||||
ctx.Search("dir", event.target.value);
|
||||
ctx.Search("module", event.target.value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,7 +234,9 @@
|
||||
ctx.Cookie("order", ctx.Cookie("order")*1 + 1);
|
||||
location.assign(location.href);
|
||||
}
|
||||
|
||||
function show(name) {
|
||||
ctx.Cap(name, function(msg) {console.log(msg)});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
{{end}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user