mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-28 09:52:01 +08:00
mac add web.index
This commit is contained in:
parent
b41f0d0ff6
commit
da6859c5e0
@ -208,6 +208,11 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
"time_format": &ctx.Config{Name: "time_format", Value: "2006-01-02 15:04:05", Help: "时间格式"},
|
"time_format": &ctx.Config{Name: "time_format", Value: "2006-01-02 15:04:05", Help: "时间格式"},
|
||||||
"time_unit": &ctx.Config{Name: "time_unit", Value: "1000", Help: "时间倍数"},
|
"time_unit": &ctx.Config{Name: "time_unit", Value: "1000", Help: "时间倍数"},
|
||||||
"time_interval": &ctx.Config{Name: "time_interval(open/close)", Value: "open", Help: "时间区间"},
|
"time_interval": &ctx.Config{Name: "time_interval(open/close)", Value: "open", Help: "时间区间"},
|
||||||
|
|
||||||
|
"tmux_default": &ctx.Config{Name: "tmux_default", Value: map[string]interface{}{
|
||||||
|
"session": []interface{}{"list-sessions"},
|
||||||
|
"buffer": []interface{}{"show-buffer"},
|
||||||
|
}, Help: "时间区间"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"source": &ctx.Command{
|
"source": &ctx.Command{
|
||||||
@ -809,6 +814,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
"clear": &ctx.Command{Name: "clear", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"clear": &ctx.Command{Name: "clear", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
m.Log("fuck", strings.Repeat("\n", 20))
|
m.Log("fuck", strings.Repeat("\n", 20))
|
||||||
}},
|
}},
|
||||||
|
"tmux": &ctx.Command{Name: "tmux", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
m.Copy(m.Spawn().Cmd("system", "tmux", arg), "result")
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
Index: map[string]*ctx.Context{
|
Index: map[string]*ctx.Context{
|
||||||
"void": &ctx.Context{Caches: map[string]*ctx.Cache{"nshell": &ctx.Cache{}}},
|
"void": &ctx.Context{Caches: map[string]*ctx.Cache{"nshell": &ctx.Cache{}}},
|
||||||
|
@ -43,6 +43,17 @@ func Trans(arg ...interface{}) []string { // {{{
|
|||||||
ls = append(ls, fmt.Sprintf("%t", val))
|
ls = append(ls, fmt.Sprintf("%t", val))
|
||||||
case int, int8, int16, int32, int64:
|
case int, int8, int16, int32, int64:
|
||||||
ls = append(ls, fmt.Sprintf("%d", val))
|
ls = append(ls, fmt.Sprintf("%d", val))
|
||||||
|
case []interface{}:
|
||||||
|
for _, v := range val {
|
||||||
|
switch val := v.(type) {
|
||||||
|
case string:
|
||||||
|
ls = append(ls, val)
|
||||||
|
case bool:
|
||||||
|
ls = append(ls, fmt.Sprintf("%t", val))
|
||||||
|
case int, int8, int16, int32, int64:
|
||||||
|
ls = append(ls, fmt.Sprintf("%d", val))
|
||||||
|
}
|
||||||
|
}
|
||||||
case []string:
|
case []string:
|
||||||
ls = append(ls, val...)
|
ls = append(ls, val...)
|
||||||
case []bool:
|
case []bool:
|
||||||
@ -1572,6 +1583,73 @@ func (m *Message) Confi(key string, arg ...interface{}) int { // {{{
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
func (m *Message) Confv(key string, args ...interface{}) interface{} { // {{{
|
||||||
|
var hand func(m *Message, x *Config, arg ...string) string
|
||||||
|
arg := Trans(args...)
|
||||||
|
|
||||||
|
for _, c := range []*Context{m.target, m.source} {
|
||||||
|
for s := c; s != nil; s = s.context {
|
||||||
|
if x, ok := s.Configs[key]; ok {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return x.Value
|
||||||
|
}
|
||||||
|
if len(arg) == 3 {
|
||||||
|
hand = x.Hand
|
||||||
|
}
|
||||||
|
|
||||||
|
switch value := x.Value.(type) {
|
||||||
|
case string:
|
||||||
|
x.Value = fmt.Sprintf("%v", value)
|
||||||
|
case bool:
|
||||||
|
x.Value = Right(fmt.Sprintf("%v", value))
|
||||||
|
case int:
|
||||||
|
i, e := strconv.Atoi(fmt.Sprintf("%v", value))
|
||||||
|
m.Assert(e)
|
||||||
|
x.Value = i
|
||||||
|
case nil:
|
||||||
|
x.Value = args[0]
|
||||||
|
default:
|
||||||
|
for i := 0; i < len(args); i += 2 {
|
||||||
|
if i < len(args)-1 {
|
||||||
|
x.Value = Chain(x.Value, args[i], args[i+1])
|
||||||
|
}
|
||||||
|
if i == len(args)-2 {
|
||||||
|
return Chain(x.Value, args[len(args)-2])
|
||||||
|
}
|
||||||
|
if i == len(args)-1 {
|
||||||
|
return Chain(x.Value, args[len(args)-1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Log("conf", "%s %v", key, args)
|
||||||
|
if m.target.Configs == nil {
|
||||||
|
m.target.Configs = make(map[string]*Config)
|
||||||
|
}
|
||||||
|
if len(arg) == 3 {
|
||||||
|
m.target.Configs[key] = &Config{Name: arg[0], Value: arg[1], Help: arg[2], Hand: hand}
|
||||||
|
return m.Conf(key, arg[1])
|
||||||
|
}
|
||||||
|
if !m.Confs("auto_make") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(arg) == 1 {
|
||||||
|
m.target.Configs[key] = &Config{Name: key, Value: arg[0], Help: "auto make", Hand: hand}
|
||||||
|
return m.Conf(key, arg[0])
|
||||||
|
}
|
||||||
|
m.target.Configs[key] = &Config{Name: key, Value: Chain(nil, args), Help: "auto make", Hand: hand}
|
||||||
|
return Chain(key, args[len(args)-2+(len(args)%2)])
|
||||||
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (m *Message) Conf(key string, args ...interface{}) string { // {{{
|
func (m *Message) Conf(key string, args ...interface{}) string { // {{{
|
||||||
var hand func(m *Message, x *Config, arg ...string) string
|
var hand func(m *Message, x *Config, arg ...string) string
|
||||||
@ -1610,6 +1688,8 @@ func (m *Message) Conf(key string, args ...interface{}) string { // {{{
|
|||||||
hand = x.Hand
|
hand = x.Hand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case bool:
|
||||||
|
case int:
|
||||||
default:
|
default:
|
||||||
values := ""
|
values := ""
|
||||||
for i := 0; i < len(args); i += 2 {
|
for i := 0; i < len(args); i += 2 {
|
||||||
@ -2037,6 +2117,9 @@ var CGI = template.FuncMap{
|
|||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}, // }}}
|
}, // }}}
|
||||||
|
"unscaped": func(str string) interface{} { // {{{
|
||||||
|
return template.HTML(str)
|
||||||
|
}, // }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
var Pulse = &Message{code: 0, time: time.Now(), source: Index, target: Index, Meta: map[string][]string{}}
|
var Pulse = &Message{code: 0, time: time.Now(), source: Index, target: Index, Meta: map[string][]string{}}
|
||||||
@ -2868,8 +2951,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
save[k] = v.Value
|
save[k] = v.Value
|
||||||
}
|
}
|
||||||
case "load":
|
case "load":
|
||||||
if len(have) == 0 || have[k] {
|
if x, ok := save[k]; ok && (len(have) == 0 || have[k]) {
|
||||||
v.Value = save[k]
|
v.Value = x
|
||||||
}
|
}
|
||||||
case "pop":
|
case "pop":
|
||||||
switch val := v.Value.(type) {
|
switch val := v.Value.(type) {
|
||||||
|
@ -54,23 +54,27 @@ func (log *LOG) Close(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
|
|
||||||
var Pulse *ctx.Message
|
var Pulse *ctx.Message
|
||||||
var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
||||||
Caches: map[string]*ctx.Cache{},
|
Caches: map[string]*ctx.Cache{
|
||||||
|
"nlog": &ctx.Cache{Name: "nlog", Value: "0", Help: "日志屏蔽类型"},
|
||||||
|
},
|
||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
|
"silent": &ctx.Config{Name: "silent", Value: map[string]interface{}{}, Help: "日志屏蔽类型"},
|
||||||
"module": &ctx.Config{Name: "module", Value: map[string]interface{}{
|
"module": &ctx.Config{Name: "module", Value: map[string]interface{}{
|
||||||
"shy": map[string]interface{}{"true": true, "false": false, "one": 1, "zero": 0, "yes": "yes", "no": "no"},
|
|
||||||
"log": map[string]interface{}{"cmd": true},
|
"log": map[string]interface{}{"cmd": true},
|
||||||
"lex": map[string]interface{}{"cmd": true, "debug": true},
|
"lex": map[string]interface{}{"cmd": true, "debug": true},
|
||||||
"yac": map[string]interface{}{"cmd": true, "debug": true},
|
"yac": map[string]interface{}{"cmd": true, "debug": true},
|
||||||
}, Help: "模块日志输出的文件"},
|
}, Help: "日志屏蔽模块"},
|
||||||
"silent": &ctx.Config{Name: "silent", Value: map[string]string{}, Help: "模块日志输出的文件"},
|
"color": &ctx.Config{Name: "color", Value: map[string]interface{}{
|
||||||
"color": &ctx.Config{Name: "color", Value: map[string]string{
|
"debug": 0, "error": 31, "check": 31,
|
||||||
"debug": "0", "error": "31", "check": "31",
|
"cmd": 32, "conf": 33,
|
||||||
"cmd": "32", "conf": "33",
|
"search": 35, "find": 35, "cb": 35, "lock": 35,
|
||||||
"search": "35", "find": "35", "cb": "35", "lock": "35",
|
"begin": 36, "start": 36, "close": 36,
|
||||||
"begin": "36", "start": "36", "close": "36",
|
}, Help: "日志输出颜色"},
|
||||||
}, Help: "模块日志输出颜色"},
|
"log_name": &ctx.Config{Name: "log_name", Value: "dump", Help: "日志屏蔽类型"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
|
"open": &ctx.Command{Name: "open file", Help: "打开日志文件", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
}},
|
||||||
"log": &ctx.Command{Name: "log level string...", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"log": &ctx.Command{Name: "log level string...", Help: "输出日志, level: 日志类型, string: 日志内容", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) && log.out != nil { // {{{
|
if log, ok := m.Target().Server.(*LOG); m.Assert(ok) && log.out != nil { // {{{
|
||||||
if m.Confs("silent", arg[0]) {
|
if m.Confs("silent", arg[0]) {
|
||||||
|
@ -1269,6 +1269,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
m.Log("info", "cmd: %s %v", "git", ctx.Trans("-C", p, c, args))
|
m.Log("info", "cmd: %s %v", "git", ctx.Trans("-C", p, c, args))
|
||||||
msg := m.Sess("cli").Cmd("system", "git", "-C", p, c, args)
|
msg := m.Sess("cli").Cmd("system", "git", "-C", p, c, args)
|
||||||
m.Copy(msg, "result").Copy(msg, "append")
|
m.Copy(msg, "result").Copy(msg, "append")
|
||||||
|
m.Echo("\n")
|
||||||
}
|
}
|
||||||
} // }}}
|
} // }}}
|
||||||
}},
|
}},
|
||||||
|
@ -279,6 +279,25 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
},
|
},
|
||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
"cmd": &ctx.Config{Name: "cmd", Value: "tmux", Help: "路由数量"},
|
"cmd": &ctx.Config{Name: "cmd", Value: "tmux", Help: "路由数量"},
|
||||||
|
"index": &ctx.Config{Name: "index", Value: map[string]interface{}{
|
||||||
|
"shy": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"module": "cli", "command": "system",
|
||||||
|
"argument": []interface{}{"tmux", "list-clients"},
|
||||||
|
"template": "result", "title": "client",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"module": "cli", "command": "system",
|
||||||
|
"argument": []interface{}{"tmux", "list-sessions"},
|
||||||
|
"template": "result", "title": "session",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"module": "cli", "command": "system",
|
||||||
|
"argument": []interface{}{"tmux", "show-buffer"},
|
||||||
|
"template": "result", "title": "buffer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, Help: "资源列表"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"client": &ctx.Command{
|
"client": &ctx.Command{
|
||||||
@ -544,6 +563,35 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
m.Copy(msg, "result")
|
m.Copy(msg, "result")
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
|
"/index": &ctx.Command{Name: "/index", Help: "网页门户", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
w := m.Optionv("response").(http.ResponseWriter)
|
||||||
|
w.Header().Add("Content-Type", "text/html")
|
||||||
|
|
||||||
|
tpl := template.New("render").Funcs(ctx.CGI)
|
||||||
|
tpl = template.Must(tpl.ParseGlob(path.Join(m.Conf("template_dir"), m.Conf("common_tmpl"))))
|
||||||
|
tpl = template.Must(tpl.ParseGlob(path.Join(m.Conf("template_dir"), m.Conf("upload_tmpl"))))
|
||||||
|
|
||||||
|
replace := [][]byte{
|
||||||
|
[]byte{27, 91, 51, 50, 109}, []byte("<span style='color:red'>"),
|
||||||
|
[]byte{27, 91, 51, 49, 109}, []byte("<span style='color:green'>"),
|
||||||
|
[]byte{27, 91, 109}, []byte("</span>"),
|
||||||
|
}
|
||||||
|
|
||||||
|
list := m.Confv("index", "shy")
|
||||||
|
for _, v := range list.([]interface{}) {
|
||||||
|
val := v.(map[string]interface{})
|
||||||
|
msg := m.Find(val["module"].(string)).Cmd(val["command"], val["argument"])
|
||||||
|
for i, v := range msg.Meta["result"] {
|
||||||
|
b := []byte(v)
|
||||||
|
for i := 0; i < len(replace)-1; i += 2 {
|
||||||
|
b = bytes.Replace(b, replace[i], replace[i+1], -1)
|
||||||
|
}
|
||||||
|
msg.Meta["result"][i] = string(b)
|
||||||
|
}
|
||||||
|
msg.Option("title", val["title"])
|
||||||
|
m.Assert(tpl.ExecuteTemplate(w, val["template"].(string), msg.Meta))
|
||||||
|
}
|
||||||
|
}},
|
||||||
"/travel": &ctx.Command{Name: "/travel", Help: "文件上传", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"/travel": &ctx.Command{Name: "/travel", Help: "文件上传", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
// r := m.Optionv("request").(*http.Request) // {{{
|
// r := m.Optionv("request").(*http.Request) // {{{
|
||||||
// w := m.Optionv("response").(http.ResponseWriter)
|
// w := m.Optionv("response").(http.ResponseWriter)
|
||||||
|
@ -78,34 +78,44 @@
|
|||||||
|
|
||||||
{{define "git"}}
|
{{define "git"}}
|
||||||
<fieldset><legend>branch</legend>
|
<fieldset><legend>branch</legend>
|
||||||
<pre>{{index . "branch"}}</pre>
|
<pre>{{index . "result"}}</pre>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset><legend>status</legend>
|
<fieldset><legend>status</legend>
|
||||||
<pre>{{index . "status"}}</pre>
|
<pre>{{index . "result"}}</pre>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "tmux"}}
|
{{define "tmux"}}
|
||||||
<fieldset><legend>sessions</legend>
|
{{$meta := .}}
|
||||||
<pre>{{meta . "sessions"}}</pre>
|
{{range $index, $value := index $meta "append"}}
|
||||||
|
<fieldset><legend>{{$value}}</legend>
|
||||||
|
{{if eq $value "buffer"}}
|
||||||
|
<button onclick="copy_tmux_buffer('copy')">copy</button>
|
||||||
|
<button onclick="send_tmux_buffer('paste')">send</button>
|
||||||
|
<textarea rows="5" cols="60" name="tmux_buffer">{{meta . "buffer" 0}}</textarea>
|
||||||
|
<script>
|
||||||
|
var buffer = document.getElementsByName("tmux_buffer")[0];
|
||||||
|
function copy_tmux_buffer(action) {
|
||||||
|
buffer.select();
|
||||||
|
document.execCommand(action);
|
||||||
|
}
|
||||||
|
function send_tmux_buffer(action) {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "/paste?content="+encodeURIComponent(buffer.value));
|
||||||
|
xhr.send()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{{else}}
|
||||||
|
<pre>{{meta $meta $value}}</pre>
|
||||||
|
{{end}}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset><legend>buffer</legend>
|
{{end}}
|
||||||
<button onclick="copy_tmux_buffer('copy')">copy</button>
|
{{end}}
|
||||||
<button onclick="send_tmux_buffer('paste')">send</button>
|
|
||||||
<textarea rows="5" cols="60" name="tmux_buffer">{{meta . "buffer" 0}}</textarea>
|
{{define "result"}}
|
||||||
|
<fieldset><legend>{{meta . "title"}}</legend>
|
||||||
|
<pre><code>{{meta . "result"|unscaped}}</code></pre>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<script>
|
|
||||||
var buffer = document.getElementsByName("tmux_buffer")[0];
|
|
||||||
function copy_tmux_buffer(action) {
|
|
||||||
buffer.select();
|
|
||||||
console.log(document.execCommand(action));
|
|
||||||
}
|
|
||||||
function send_tmux_buffer(action) {
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("POST", "/paste?content="+encodeURIComponent(buffer.value));
|
|
||||||
xhr.send()
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{define "upload"}}
|
{{define "upload"}}
|
||||||
@ -132,6 +142,8 @@
|
|||||||
{{$meta := .Meta}}
|
{{$meta := .Meta}}
|
||||||
{{$sess := .Sessions}}
|
{{$sess := .Sessions}}
|
||||||
{{range .Meta.tmpl}}
|
{{range .Meta.tmpl}}
|
||||||
|
{{$tmpl := index $sess .}}
|
||||||
|
|
||||||
{{if eq . "login"}}
|
{{if eq . "login"}}
|
||||||
{{template "login" $meta}}
|
{{template "login" $meta}}
|
||||||
{{else if eq . "userinfo"}}
|
{{else if eq . "userinfo"}}
|
||||||
@ -150,6 +162,7 @@
|
|||||||
{{template "upload" $msg}}
|
{{template "upload" $msg}}
|
||||||
{{else if eq . "create"}}
|
{{else if eq . "create"}}
|
||||||
{{template "create" $msg}}
|
{{template "create" $msg}}
|
||||||
|
{{else}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user