forked from x/icebergs
opt header
This commit is contained in:
parent
ae3b093570
commit
e52cd73a31
@ -1,23 +1,23 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
if r.Header.Get("index.module") == "" {
|
||||
r.Header.Set("index.module", m.Target().Name)
|
||||
r.Header.Set("index.module", m.Prefix())
|
||||
} else { // 模块接口
|
||||
return true
|
||||
}
|
||||
@ -34,18 +34,18 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
}
|
||||
m.Info("").Info("%s %s %s", r.Header.Get(ice.MSG_USERIP), r.Method, r.URL)
|
||||
|
||||
// 输出日志
|
||||
// 参数日志
|
||||
if m.Conf(SERVE, kit.Keym("logheaders")) == "true" {
|
||||
for k, v := range r.Header {
|
||||
m.Info("%s: %v", k, kit.Format(v))
|
||||
}
|
||||
m.Info(" ")
|
||||
m.Info("")
|
||||
|
||||
defer func() {
|
||||
for k, v := range w.Header() {
|
||||
m.Info("%s: %v", k, kit.Format(v))
|
||||
}
|
||||
m.Info(" ")
|
||||
m.Info("")
|
||||
}()
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
}
|
||||
|
||||
// 请求地址
|
||||
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SHARE, kit.Keym("domain")), r.Header.Get("Referer")))
|
||||
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SHARE, kit.Keym(kit.MDB_DOMAIN)), r.Header.Get("Referer")))
|
||||
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
|
||||
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
|
||||
if msg.R, msg.W = r, w; r.Header.Get("X-Real-Port") != "" {
|
||||
@ -127,7 +127,7 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
v[i], _ = url.QueryUnescape(p)
|
||||
}
|
||||
if msg.Optionv(k, v); k == ice.MSG_SESSID {
|
||||
msg.Render(COOKIE, v[0])
|
||||
RenderCookie(msg, v[0])
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,15 +238,15 @@ func init() {
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option(mdb.FIELDS, kit.Select("time,status,name,port,dev", mdb.DETAIL, len(arg) > 0))
|
||||
m.Fields(len(arg) == 0, "time,status,name,port,dev")
|
||||
m.Cmdy(mdb.SELECT, SERVE, "", mdb.HASH, kit.MDB_NAME, arg)
|
||||
}},
|
||||
|
||||
"/volcanos/": {Name: "/volcanos/", Help: "浏览器", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Render(ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, kit.Keym("volcanos.path")), path.Join(arg...)))
|
||||
m.Render(ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, kit.Keym(ice.VOLCANOS, kit.MDB_PATH)), path.Join(arg...)))
|
||||
}},
|
||||
"/intshell/": {Name: "/intshell/", Help: "命令行", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Render(ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, kit.Keym("intshell.path")), path.Join(arg...)))
|
||||
m.Render(ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, kit.Keym(ice.INTSHELL, kit.MDB_PATH)), path.Join(arg...)))
|
||||
}},
|
||||
"/publish/": {Name: "/publish/", Help: "私有云", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_share_local(m, m.Conf(SERVE, kit.Keym(ice.PUBLISH)), path.Join(arg...))
|
||||
|
@ -27,9 +27,10 @@ func _header_grant(m *ice.Message, arg ...string) {
|
||||
if pod := m.Option(kit.SSH_POD); pod != "" {
|
||||
m.Option(kit.SSH_POD, "")
|
||||
m.Cmd(web.SPACE, pod, m.Prefix(P_HEADER), kit.MDB_ACTION, GRANT, arg)
|
||||
return
|
||||
return // 下发命令
|
||||
}
|
||||
|
||||
// 授权登录
|
||||
m.Cmd(aaa.ROLE, kit.Select(aaa.TECH, aaa.VOID, m.Option(ice.MSG_USERROLE) == aaa.VOID), m.Option(ice.MSG_USERNAME))
|
||||
m.Cmd(web.SPACE, m.Option(web.SPACE), ice.MSG_SESSID, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME)))
|
||||
}
|
||||
@ -40,9 +41,10 @@ func _header_users(m *ice.Message, key string, arg ...string) {
|
||||
|
||||
const (
|
||||
TITLE = "title"
|
||||
LOGIN = "login"
|
||||
CHECK = "check"
|
||||
LOGIN = "login"
|
||||
GRANT = "grant"
|
||||
SHARE = "share"
|
||||
AGENT = "agent"
|
||||
)
|
||||
const P_HEADER = "/header"
|
||||
@ -55,19 +57,22 @@ func init() {
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
P_HEADER: {Name: "/header", Help: "标题栏", Action: map[string]*ice.Action{
|
||||
LOGIN: {Name: "login", Help: "用户登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
CHECK: {Name: "check", Help: "登录检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
_header_check(m)
|
||||
m.Echo(m.Option(ice.MSG_USERNAME))
|
||||
}},
|
||||
LOGIN: {Name: "login", Help: "密码登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
if aaa.UserLogin(m, arg[0], arg[1]) {
|
||||
web.RenderCookie(m, aaa.SessCreate(m, arg[0]))
|
||||
}
|
||||
m.Echo(m.Option(ice.MSG_USERNAME))
|
||||
}},
|
||||
CHECK: {Name: "check", Help: "登录检查", Hand: func(m *ice.Message, arg ...string) {
|
||||
_header_check(m)
|
||||
m.Echo(m.Option(ice.MSG_USERNAME))
|
||||
}},
|
||||
GRANT: {Name: "grant space", Help: "用户授权", Hand: func(m *ice.Message, arg ...string) {
|
||||
GRANT: {Name: "grant space", Help: "扫码授权", Hand: func(m *ice.Message, arg ...string) {
|
||||
_header_grant(m, arg...)
|
||||
}},
|
||||
SHARE: {Name: "share type", Help: "扫码登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(web.SHARE, mdb.CREATE, kit.MDB_TYPE, web.LOGIN, arg)
|
||||
}},
|
||||
AGENT: {Name: "agent", Help: "应用宿主", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy("web.chat.wx.access", "config")
|
||||
}},
|
||||
@ -75,24 +80,18 @@ func init() {
|
||||
code.WEBPACK: {Name: "webpack", Help: "网页打包", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.WEBPACK, mdb.CREATE)
|
||||
}},
|
||||
web.SHARE: {Name: "share type", Help: "用户共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(web.SHARE, mdb.CREATE, kit.MDB_TYPE, LOGIN, arg)
|
||||
}},
|
||||
aaa.AVATAR: {Name: "avatar", Help: "头像图片", Hand: func(m *ice.Message, arg ...string) {
|
||||
_header_users(m, aaa.AVATAR, arg...)
|
||||
}},
|
||||
aaa.BACKGROUND: {Name: "background", Help: "背景图片", Hand: func(m *ice.Message, arg ...string) {
|
||||
_header_users(m, aaa.BACKGROUND, arg...)
|
||||
}},
|
||||
aaa.USERNICK: {Name: "usernick", Help: "用户昵称", Hand: func(m *ice.Message, arg ...string) {
|
||||
_header_users(m, aaa.USERNICK, arg...)
|
||||
}},
|
||||
aaa.USERROLE: {Name: "userrole", Help: "用户角色", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Echo(aaa.UserRole(m, m.Option("who")))
|
||||
aaa.AVATAR: {Name: "avatar", Help: "头像图片", Hand: func(m *ice.Message, arg ...string) {
|
||||
_header_users(m, aaa.AVATAR, arg...)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
user := m.Cmd("aaa.user", m.Option(ice.MSG_USERNAME))
|
||||
for _, k := range []string{aaa.AVATAR, aaa.BACKGROUND} {
|
||||
for _, k := range []string{aaa.BACKGROUND, aaa.AVATAR} {
|
||||
m.Option(k, user.Append(k))
|
||||
}
|
||||
m.Echo(m.Conf(HEADER, kit.Keym(TITLE)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user