mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
vpn pro context 修改了一些小东西
This commit is contained in:
parent
8fe0d03eda
commit
9cdea710d9
@ -77,7 +77,11 @@ func (cli *CLI) parse() bool { // {{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(line) == 1 {
|
if len(line) == 1 {
|
||||||
return true
|
if len(cli.ins) == 1 {
|
||||||
|
line = cli.history[len(cli.history)-1]["cli"]
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
line = cli.next
|
line = cli.next
|
||||||
@ -89,6 +93,7 @@ func (cli *CLI) parse() bool { // {{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
back:
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if line[0] == '#' {
|
if line[0] == '#' {
|
||||||
return true
|
return true
|
||||||
@ -118,6 +123,7 @@ func (cli *CLI) parse() bool { // {{{
|
|||||||
|
|
||||||
for i := 0; i < len(ls); i++ {
|
for i := 0; i < len(ls); i++ {
|
||||||
ls[i] = strings.TrimSpace(ls[i])
|
ls[i] = strings.TrimSpace(ls[i])
|
||||||
|
|
||||||
if ls[i][0] == '#' {
|
if ls[i][0] == '#' {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -126,6 +132,13 @@ func (cli *CLI) parse() bool { // {{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ls = msg.Meta["detail"]
|
||||||
|
if n, e := strconv.Atoi(ls[0]); e == nil && 0 <= n && n < len(cli.history) && ls[0] != cli.history[n]["cli"] {
|
||||||
|
line = cli.history[n]["cli"]
|
||||||
|
msg.Meta["detail"] = nil
|
||||||
|
goto back
|
||||||
|
}
|
||||||
|
|
||||||
msg.Post(cli.Context)
|
msg.Post(cli.Context)
|
||||||
|
|
||||||
for _, v := range msg.Meta["result"] {
|
for _, v := range msg.Meta["result"] {
|
||||||
@ -426,6 +439,9 @@ var Index = &ctx.Context{Name: "cli", Help: "管理终端",
|
|||||||
cli.alias[arg[0]] = arg[1]
|
cli.alias[arg[0]] = arg[1]
|
||||||
m.Echo("%s: %s\n", arg[0], cli.alias[arg[0]])
|
m.Echo("%s: %s\n", arg[0], cli.alias[arg[0]])
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
cli.alias[arg[0]] = strings.Join(arg[1:], " ")
|
||||||
|
m.Echo("%s: %s\n", arg[0], cli.alias[arg[0]])
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
// }}}
|
// }}}
|
||||||
@ -441,7 +457,12 @@ var Index = &ctx.Context{Name: "cli", Help: "管理终端",
|
|||||||
n, e := strconv.Atoi(arg[0])
|
n, e := strconv.Atoi(arg[0])
|
||||||
if e == nil && 0 <= n && n < len(cli.history) {
|
if e == nil && 0 <= n && n < len(cli.history) {
|
||||||
log.Println("shy log why:", cli.history[n]["cli"])
|
log.Println("shy log why:", cli.history[n]["cli"])
|
||||||
return cli.history[n]["cli"]
|
cli.next = cli.history[n]["cli"]
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
n, e := strconv.Atoi(arg[0])
|
||||||
|
if e == nil && 0 <= n && n < len(cli.history) {
|
||||||
|
cli.history[n]["cli"] = strings.Join(arg[1:], " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
@ -482,6 +503,8 @@ var Index = &ctx.Context{Name: "cli", Help: "管理终端",
|
|||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
|
case "void":
|
||||||
|
m.Target.Conf(arg[1], "")
|
||||||
case "delete":
|
case "delete":
|
||||||
if _, ok := m.Target.Configs[arg[1]]; ok {
|
if _, ok := m.Target.Configs[arg[1]]; ok {
|
||||||
delete(m.Target.Configs, arg[1])
|
delete(m.Target.Configs, arg[1])
|
||||||
@ -569,7 +592,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理终端",
|
|||||||
Messages: make(chan *ctx.Message, 10),
|
Messages: make(chan *ctx.Message, 10),
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { // {{{
|
func init() {
|
||||||
cli := &CLI{alias: map[string]string{
|
cli := &CLI{alias: map[string]string{
|
||||||
"~": "context",
|
"~": "context",
|
||||||
"!": "history",
|
"!": "history",
|
||||||
@ -581,5 +604,3 @@ func init() { // {{{
|
|||||||
cli.Context = Index
|
cli.Context = Index
|
||||||
ctx.Index.Register(Index, cli)
|
ctx.Index.Register(Index, cli)
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
|
@ -354,7 +354,11 @@ func (c *Context) Start(m *Message) bool { // {{{
|
|||||||
func (c *Context) Spawn(m *Message, arg ...string) *Context { // {{{
|
func (c *Context) Spawn(m *Message, arg ...string) *Context { // {{{
|
||||||
s := &Context{Name: arg[0], Help: c.Help}
|
s := &Context{Name: arg[0], Help: c.Help}
|
||||||
m.Target = s
|
m.Target = s
|
||||||
c.Register(s, c.Server.Spawn(s, m, arg...)).Begin(m)
|
if c.Server != nil {
|
||||||
|
c.Register(s, c.Server.Spawn(s, m, arg...)).Begin(m)
|
||||||
|
} else {
|
||||||
|
c.Register(s, nil).Begin(m)
|
||||||
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,7 +656,7 @@ func (c *Context) Del(arg ...string) { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
func (c *Context) Create(s *Context) *Message { // {{{
|
func (c *Context) Storm(s *Context) *Message { // {{{
|
||||||
|
|
||||||
msg := &Message{
|
msg := &Message{
|
||||||
Time: time.Now(),
|
Time: time.Now(),
|
||||||
@ -716,6 +720,9 @@ func (c *Context) Conf(key string, arg ...string) string { // {{{
|
|||||||
if s == c {
|
if s == c {
|
||||||
panic(errors.New(x.Name + "配置项已存在"))
|
panic(errors.New(x.Name + "配置项已存在"))
|
||||||
}
|
}
|
||||||
|
if c.Configs == nil {
|
||||||
|
c.Configs = make(map[string]*Config)
|
||||||
|
}
|
||||||
c.Configs[key] = &Config{Name: arg[0], Value: arg[1], Help: arg[2], Hand: x.Hand}
|
c.Configs[key] = &Config{Name: arg[0], Value: arg[1], Help: arg[2], Hand: x.Hand}
|
||||||
return arg[1]
|
return arg[1]
|
||||||
default:
|
default:
|
||||||
@ -752,7 +759,7 @@ func (c *Context) Cap(key string, arg ...string) string { // {{{
|
|||||||
return x.Value
|
return x.Value
|
||||||
case 1:
|
case 1:
|
||||||
if x.Hand != nil {
|
if x.Hand != nil {
|
||||||
x.Value = x.Hand(c, x, x.Value)
|
x.Value = x.Hand(c, x, arg[0])
|
||||||
} else {
|
} else {
|
||||||
x.Value = arg[0]
|
x.Value = arg[0]
|
||||||
}
|
}
|
||||||
@ -761,6 +768,9 @@ func (c *Context) Cap(key string, arg ...string) string { // {{{
|
|||||||
if s == c {
|
if s == c {
|
||||||
panic(errors.New(key + "缓存项已存在"))
|
panic(errors.New(key + "缓存项已存在"))
|
||||||
}
|
}
|
||||||
|
if c.Caches == nil {
|
||||||
|
c.Caches = make(map[string]*Cache)
|
||||||
|
}
|
||||||
c.Caches[key] = &Cache{arg[0], arg[1], arg[2], x.Hand}
|
c.Caches[key] = &Cache{arg[0], arg[1], arg[2], x.Hand}
|
||||||
return arg[1]
|
return arg[1]
|
||||||
default:
|
default:
|
||||||
|
@ -32,13 +32,28 @@ func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) { // {{{
|
|||||||
log.Println(web.Name, r.RemoteAddr, r.Method, r.URL)
|
log.Println(web.Name, r.RemoteAddr, r.Method, r.URL)
|
||||||
defer log.Println()
|
defer log.Println()
|
||||||
|
|
||||||
r.ParseForm()
|
if web.Conf("logheaders") == "yes" {
|
||||||
for k, v := range r.PostForm {
|
for k, v := range r.Header {
|
||||||
log.Printf("%s: %s", k, v[0])
|
log.Println(k+":", v[0])
|
||||||
|
}
|
||||||
|
log.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
r.ParseForm()
|
||||||
|
if len(r.PostForm) > 0 {
|
||||||
|
for k, v := range r.PostForm {
|
||||||
|
log.Printf("%s: %s", k, v[0])
|
||||||
|
}
|
||||||
|
log.Println()
|
||||||
}
|
}
|
||||||
log.Println()
|
|
||||||
|
|
||||||
web.ServeMux.ServeHTTP(w, r)
|
web.ServeMux.ServeHTTP(w, r)
|
||||||
|
|
||||||
|
if web.Conf("logheaders") == "yes" {
|
||||||
|
for k, v := range w.Header() {
|
||||||
|
log.Println(k+":", v[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
@ -108,11 +123,12 @@ var Index = &ctx.Context{Name: "web", Help: "网页服务",
|
|||||||
"status": &ctx.Cache{Name: "status", Value: "stop", Help: "服务状态"},
|
"status": &ctx.Cache{Name: "status", Value: "stop", Help: "服务状态"},
|
||||||
},
|
},
|
||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
"directory": &ctx.Config{Name: "directory", Value: "./", Help: "服务目录"},
|
"logheaders": &ctx.Config{Name: "logheaders", Value: "yes", Help: "日志输出请求头"},
|
||||||
"protocol": &ctx.Config{Name: "protocol", Value: "https", Help: "服务协议"},
|
"directory": &ctx.Config{Name: "directory", Value: "./", Help: "服务目录"},
|
||||||
"address": &ctx.Config{Name: "address", Value: ":443", Help: "监听地址"},
|
"protocol": &ctx.Config{Name: "protocol", Value: "https", Help: "服务协议"},
|
||||||
"route": &ctx.Config{Name: "route", Value: "/", Help: "请求路径"},
|
"address": &ctx.Config{Name: "address", Value: ":443", Help: "监听地址"},
|
||||||
"default": &ctx.Config{Name: "default", Value: "hello web world", Help: "默认响应体"},
|
"route": &ctx.Config{Name: "route", Value: "/", Help: "请求路径"},
|
||||||
|
"default": &ctx.Config{Name: "default", Value: "hello web world", Help: "默认响应体"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"listen": &ctx.Command{Name: "listen [route [address protocol [directory]]]", Help: "开启网页服务", Hand: func(c *ctx.Context, m *ctx.Message, key string, arg ...string) string {
|
"listen": &ctx.Command{Name: "listen [route [address protocol [directory]]]", Help: "开启网页服务", Hand: func(c *ctx.Context, m *ctx.Message, key string, arg ...string) string {
|
||||||
|
@ -24,6 +24,22 @@ func FmtSize(size int64) string {
|
|||||||
return fmt.Sprintf("%dB", size)
|
return fmt.Sprintf("%dB", size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FmtNano(nano int64) string {
|
||||||
|
if nano > 1000000000 {
|
||||||
|
return fmt.Sprintf("%d.%ds", nano/1000000000, nano/100000000%100)
|
||||||
|
}
|
||||||
|
|
||||||
|
if nano > 1000000 {
|
||||||
|
return fmt.Sprintf("%d.%dms", nano/100000, nano/100000%100)
|
||||||
|
}
|
||||||
|
|
||||||
|
if nano > 1000 {
|
||||||
|
return fmt.Sprintf("%d.%dus", nano/1000, nano/100%100)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%dns", nano)
|
||||||
|
}
|
||||||
|
|
||||||
func Check(e error) bool {
|
func Check(e error) bool {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
panic(e)
|
panic(e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user