forked from x/icebergs
add some
This commit is contained in:
parent
8360cae3c9
commit
7deacdb671
@ -21,8 +21,8 @@ func _command_list(m *ice.Message, name string) *ice.Message {
|
|||||||
m.Push(mdb.INDEX, kit.Keys(s.Prefix(), key))
|
m.Push(mdb.INDEX, kit.Keys(s.Prefix(), key))
|
||||||
m.Push(mdb.NAME, kit.Format(cmd.Name))
|
m.Push(mdb.NAME, kit.Format(cmd.Name))
|
||||||
m.Push(mdb.HELP, kit.Format(cmd.Help))
|
m.Push(mdb.HELP, kit.Format(cmd.Help))
|
||||||
m.Push(mdb.META, FormatPretty(cmd.Meta, 0, 2))
|
m.Push(mdb.META, kit.Format(cmd.Meta))
|
||||||
m.Push(mdb.LIST, FormatPretty(cmd.List, 0, 2))
|
m.Push(mdb.LIST, kit.Format(cmd.List))
|
||||||
})
|
})
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -87,12 +87,17 @@ func PushImages(m *ice.Message, name string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func PushNotice(m *ice.Message, arg ...ice.Any) {
|
func PushNotice(m *ice.Message, arg ...ice.Any) {
|
||||||
|
opts := ice.Map{ice.MSG_OPTION: []string{}, ice.MSG_OPTS: []string{}}
|
||||||
|
kit.For([]string{ice.LOG_DEBUG, ice.LOG_TRACEID}, func(key string) {
|
||||||
|
opts[ice.MSG_OPTION] = kit.Simple(opts[ice.MSG_OPTION], key)
|
||||||
|
opts[key] = m.Option(key)
|
||||||
|
})
|
||||||
if m.Option(ice.MSG_DAEMON) == "" {
|
if m.Option(ice.MSG_DAEMON) == "" {
|
||||||
return
|
return
|
||||||
} else if m.Option(ice.MSG_USERPOD) == "" {
|
} else if m.Option(ice.MSG_USERPOD) == "" {
|
||||||
m.Cmd(SPACE, m.Option(ice.MSG_DAEMON), arg, ice.Maps{ice.MSG_OPTION: "", ice.MSG_OPTS: ""})
|
m.Cmd(SPACE, m.Option(ice.MSG_DAEMON), arg, opts)
|
||||||
} else {
|
} else {
|
||||||
m.Cmd(SPACE, kit.Keys(m.Option("__target"), m.Option(ice.MSG_DAEMON)), arg, ice.Maps{ice.MSG_OPTION: "", ice.MSG_OPTS: ""})
|
m.Cmd(SPACE, kit.Keys(m.Option("__target"), m.Option(ice.MSG_DAEMON)), arg, opts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func PushNoticeToast(m *ice.Message, arg ...ice.Any) { PushNotice(m, kit.List("toast", arg)...) }
|
func PushNoticeToast(m *ice.Message, arg ...ice.Any) { PushNotice(m, kit.List("toast", arg)...) }
|
||||||
|
@ -152,9 +152,14 @@ func RenderVersion(m *ice.Message) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CHAT = "chat"
|
CHAT = "chat"
|
||||||
CHAT_POD = "/chat/pod/"
|
CHAT_POD = "/chat/pod/"
|
||||||
CHAT_CMD = "/chat/cmd/"
|
CHAT_CMD = "/chat/cmd/"
|
||||||
|
REQUIRE_SRC = "/require/src/"
|
||||||
|
REQUIRE_USR = "/require/usr/"
|
||||||
|
REQUIRE_MODULES = "/require/modules/"
|
||||||
|
VOLCANOS = "/volcanos/"
|
||||||
|
INTSHELL = "/intshell/"
|
||||||
|
|
||||||
CODE_GIT_SERVICE = "web.code.git.service"
|
CODE_GIT_SERVICE = "web.code.git.service"
|
||||||
CODE_GIT_SEARCH = "web.code.git.search"
|
CODE_GIT_SEARCH = "web.code.git.search"
|
||||||
|
@ -58,33 +58,39 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
|||||||
} else {
|
} else {
|
||||||
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, nfs.DF)[0])
|
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, nfs.DF)[0])
|
||||||
}
|
}
|
||||||
traceid := log.Traceid()
|
if !kit.HasPrefix(r.URL.String(), VOLCANOS, REQUIRE_SRC, REQUIRE_MODULES, INTSHELL) {
|
||||||
r.Header.Set(ice.LOG_TRACEID, traceid)
|
r.Header.Set(ice.LOG_TRACEID, log.Traceid())
|
||||||
if m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String(), logs.TraceidMeta(traceid)); r.Method == http.MethodGet {
|
m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String(), logs.TraceidMeta(r.Header.Get(ice.LOG_TRACEID)))
|
||||||
ispod := kit.Contains(r.URL.String(), CHAT_POD, "pod=") || kit.Contains(r.Header.Get(Referer), CHAT_POD, "pod=")
|
}
|
||||||
if msg := m.Spawn(w, r).Options(ice.MSG_USERUA, r.UserAgent()); path.Join(r.URL.Path) == nfs.PS {
|
if path.Join(r.URL.Path) == nfs.PS && strings.HasPrefix(r.UserAgent(), Mozilla) {
|
||||||
if !msg.IsCliUA() {
|
|
||||||
if r.URL.Path = kit.Select(nfs.PS, mdb.Config(m, ice.MAIN)); path.Join(r.URL.Path) != nfs.PS {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !Render(RenderMain(msg), msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...)
|
|
||||||
} else if p := path.Join(kit.Select(ice.USR_VOLCANOS, ice.USR_INTSHELL, msg.IsCliUA()), r.URL.Path); nfs.Exists(msg, p) {
|
|
||||||
return !Render(msg, ice.RENDER_DOWNLOAD, p)
|
|
||||||
} else if p = path.Join(nfs.USR, r.URL.Path); kit.HasPrefix(r.URL.Path, nfs.VOLCANOS, nfs.INTSHELL) && nfs.Exists(msg, p) {
|
|
||||||
return !Render(msg, ice.RENDER_DOWNLOAD, p)
|
|
||||||
} else if p = strings.TrimPrefix(r.URL.Path, nfs.REQUIRE); kit.HasPrefix(r.URL.Path, ice.REQUIRE_SRC, nfs.REQUIRE+ice.USR_ICONS, nfs.REQUIRE+ice.USR_ICEBERGS) && nfs.Exists(msg, p) {
|
|
||||||
if !ispod {
|
|
||||||
return !Render(msg, ice.RENDER_DOWNLOAD, p)
|
|
||||||
}
|
|
||||||
} else if p = path.Join(ice.USR_MODULES, strings.TrimPrefix(r.URL.Path, ice.REQUIRE_MODULES)); kit.HasPrefix(r.URL.Path, ice.REQUIRE_MODULES) && nfs.Exists(msg, p) {
|
|
||||||
return !Render(msg, ice.RENDER_DOWNLOAD, p)
|
|
||||||
}
|
|
||||||
} else if path.Join(r.URL.Path) == nfs.PS {
|
|
||||||
r.URL.Path = kit.Select(nfs.PS, mdb.Config(m, ice.MAIN))
|
r.URL.Path = kit.Select(nfs.PS, mdb.Config(m, ice.MAIN))
|
||||||
}
|
}
|
||||||
|
if r.Method == http.MethodGet {
|
||||||
|
msg := m.Spawn(w, r).Options(ice.MSG_USERUA, r.UserAgent(), ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID))
|
||||||
|
if path.Join(r.URL.Path) == nfs.PS {
|
||||||
|
if Render(RenderMain(msg), msg.Option(ice.MSG_OUTPUT), kit.List(msg.Optionv(ice.MSG_ARGS))...) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else if _serve_static(msg, w, r) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
func _serve_static(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||||
|
if p := path.Join(kit.Select(ice.USR_VOLCANOS, ice.USR_INTSHELL, msg.IsCliUA()), r.URL.Path); nfs.Exists(msg, p) {
|
||||||
|
return Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||||
|
} else if p = path.Join(nfs.USR, r.URL.Path); kit.HasPrefix(r.URL.Path, nfs.VOLCANOS, nfs.INTSHELL) && nfs.Exists(msg, p) {
|
||||||
|
return Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||||
|
} else if p = strings.TrimPrefix(r.URL.Path, nfs.REQUIRE); kit.HasPrefix(r.URL.Path, ice.REQUIRE_SRC, nfs.REQUIRE+ice.USR_ICONS, nfs.REQUIRE+ice.USR_ICEBERGS) && nfs.Exists(msg, p) {
|
||||||
|
ispod := kit.Contains(r.URL.String(), CHAT_POD, "pod=") || kit.Contains(r.Header.Get(Referer), CHAT_POD, "pod=")
|
||||||
|
return !ispod && Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||||
|
} else if p = path.Join(ice.USR_MODULES, strings.TrimPrefix(r.URL.Path, ice.REQUIRE_MODULES)); kit.HasPrefix(r.URL.Path, ice.REQUIRE_MODULES) && nfs.Exists(msg, p) {
|
||||||
|
return Render(msg, ice.RENDER_DOWNLOAD, p)
|
||||||
|
} else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.ResponseWriter, r *http.Request) {
|
func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||||
debug := strings.Contains(r.URL.String(), "debug=true") || strings.Contains(r.Header.Get(Referer), "debug=true")
|
debug := strings.Contains(r.URL.String(), "debug=true") || strings.Contains(r.Header.Get(Referer), "debug=true")
|
||||||
m.Option(ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID))
|
m.Option(ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID))
|
||||||
@ -130,7 +136,7 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
|
|||||||
if cmds, ok := _serve_auth(m, key, kit.Simple(m.Optionv(ice.MSG_CMDS)), w, r); ok {
|
if cmds, ok := _serve_auth(m, key, kit.Simple(m.Optionv(ice.MSG_CMDS)), w, r); ok {
|
||||||
defer func() {
|
defer func() {
|
||||||
kit.If(m.Option(ice.MSG_STATUS) == "", func() { m.StatusTimeCount() })
|
kit.If(m.Option(ice.MSG_STATUS) == "", func() { m.StatusTimeCount() })
|
||||||
m.Cost(kit.Format("%s: /chat/cmd/%s/%s %v", r.Method, m.Option(ice.MSG_INDEX), path.Join(cmds...), m.FormatSize()))
|
m.Cost(kit.Format("%s: %s %v", r.Method, r.URL.String(), m.FormatSize()))
|
||||||
}()
|
}()
|
||||||
m.Option(ice.MSG_OPTS, kit.Simple(m.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) }))
|
m.Option(ice.MSG_OPTS, kit.Simple(m.Optionv(ice.MSG_OPTION), func(k string) bool { return !strings.HasPrefix(k, ice.MSG_SESSID) }))
|
||||||
if m.Detailv(m.PrefixKey(), cmds); len(cmds) > 1 && cmds[0] == ctx.ACTION {
|
if m.Detailv(m.PrefixKey(), cmds); len(cmds) > 1 && cmds[0] == ctx.ACTION {
|
||||||
|
@ -232,6 +232,7 @@ const (
|
|||||||
UserAgent = "User-Agent"
|
UserAgent = "User-Agent"
|
||||||
Referer = "Referer"
|
Referer = "Referer"
|
||||||
Accept = "Accept"
|
Accept = "Accept"
|
||||||
|
Mozilla = "Mozilla"
|
||||||
|
|
||||||
ApplicationForm = "application/x-www-form-urlencoded"
|
ApplicationForm = "application/x-www-form-urlencoded"
|
||||||
ApplicationOctet = "application/octet-stream"
|
ApplicationOctet = "application/octet-stream"
|
||||||
|
@ -67,6 +67,7 @@ func init() {
|
|||||||
SPARK: {Name: "spark type=inner,shell,redis,mysql text", Help: "段落", Actions: ice.MergeActions(ice.Actions{
|
SPARK: {Name: "spark type=inner,shell,redis,mysql text", Help: "段落", Actions: ice.MergeActions(ice.Actions{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||||
ice.AddRender(ice.RENDER_SCRIPT, func(msg *ice.Message, args ...ice.Any) string {
|
ice.AddRender(ice.RENDER_SCRIPT, func(msg *ice.Message, args ...ice.Any) string {
|
||||||
|
return msg.Cmdx(SPARK, SHELL, args)
|
||||||
return m.Options(ice.MSG_COUNT, "0").Cmdx(SPARK, SHELL, args)
|
return m.Options(ice.MSG_COUNT, "0").Cmdx(SPARK, SHELL, args)
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
|
@ -178,7 +178,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
ctx.LOAD: {Name: "load authkey=.ssh/authorized_keys", Hand: func(m *ice.Message, arg ...string) {
|
ctx.LOAD: {Name: "load authkey=.ssh/authorized_keys", Hand: func(m *ice.Message, arg ...string) {
|
||||||
m.Cmd(nfs.CAT, kit.HomePath(m.Option(AUTHKEY)), func(pub string) { m.Cmd(SERVICE, mdb.INSERT, mdb.TEXT, pub) })
|
m.Cmd(nfs.CAT, kit.HomePath(m.Option(AUTHKEY)), func(pub string) { m.Cmd(SERVICE, mdb.INSERT, pub) })
|
||||||
}},
|
}},
|
||||||
ctx.SAVE: {Name: "save authkey=.ssh/authorized_keys", Hand: func(m *ice.Message, arg ...string) {
|
ctx.SAVE: {Name: "save authkey=.ssh/authorized_keys", Hand: func(m *ice.Message, arg ...string) {
|
||||||
list := []string{}
|
list := []string{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user