1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-12-12 11:32:37 +08:00
parent 4fd30e611d
commit 3ce839ecc9
14 changed files with 89 additions and 76 deletions

View File

@ -22,6 +22,7 @@ const (
THEME = "theme" THEME = "theme"
LANGUAGE = "language" LANGUAGE = "language"
LOCATION = "location"
LONGITUDE = "longitude" LONGITUDE = "longitude"
LATITUDE = "latitude" LATITUDE = "latitude"
PROVINCE = "province" PROVINCE = "province"

View File

@ -70,7 +70,7 @@ func init() {
m.OptionDefault(FG, BLACK, BG, WHITE) m.OptionDefault(FG, BLACK, BG, WHITE)
_qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0)) _qrcode_cli(m, kit.Select(kit.Select(ice.Info.Make.Domain, ice.Info.Domain), arg, 0))
} else { } else {
m.OptionDefault(SIZE, "320") m.OptionDefault(SIZE, kit.Select("360", "260", m.IsMobileUA()))
// m.OptionDefault(SIZE, kit.Select("320", "368", m.IsWeixinUA())) // m.OptionDefault(SIZE, kit.Select("320", "368", m.IsWeixinUA()))
m.Option(FG, kit.Select(m.Option(ice.MSG_FG), arg, 1)) m.Option(FG, kit.Select(m.Option(ice.MSG_FG), arg, 1))
m.Option(BG, kit.Select(m.Option(ice.MSG_BG), arg, 2)) m.Option(BG, kit.Select(m.Option(ice.MSG_BG), arg, 2))

View File

@ -8,6 +8,7 @@ import (
"shylinux.com/x/icebergs/base/aaa" "shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -33,8 +34,8 @@ func BasicSess(m *ice.Message) {
aaa.SessCheck(m, m.Option(ice.MSG_SESSID)) aaa.SessCheck(m, m.Option(ice.MSG_SESSID))
} }
func BasicCheck(m *ice.Message, realm string) bool { func BasicCheck(m *ice.Message, realm string) bool {
switch ls := kit.Split(m.R.Header.Get(Authorization)); kit.Select("", ls, 0) { switch ls := kit.Split(m.R.Header.Get(html.Authorization)); kit.Select("", ls, 0) {
case Basic: case html.Basic:
if buf, err := base64.StdEncoding.DecodeString(kit.Select("", ls, 1)); !m.Warn(err) { if buf, err := base64.StdEncoding.DecodeString(kit.Select("", ls, 1)); !m.Warn(err) {
if ls := strings.SplitN(string(buf), ":", 2); !m.Warn(len(ls) < 2) { if ls := strings.SplitN(string(buf), ":", 2); !m.Warn(len(ls) < 2) {
if msg := m.Cmd(TOKEN, ls[1]); !m.Warn(msg.Time() > msg.Append(mdb.TIME)) { if msg := m.Cmd(TOKEN, ls[1]); !m.Warn(msg.Time() > msg.Append(mdb.TIME)) {

View File

@ -18,7 +18,7 @@ import (
func _cache_name(m *ice.Message, h string) string { return path.Join(ice.VAR_FILE, h[:2], h) } func _cache_name(m *ice.Message, h string) string { return path.Join(ice.VAR_FILE, h[:2], h) }
func _cache_mime(m *ice.Message, mime, name string) string { func _cache_mime(m *ice.Message, mime, name string) string {
if mime == ApplicationOctet { if mime == html.ApplicationOctet {
if kit.ExtIsImage(name) { if kit.ExtIsImage(name) {
mime = IMAGE + nfs.PS + kit.Ext(name) mime = IMAGE + nfs.PS + kit.Ext(name)
} else if kit.ExtIsVideo(name) { } else if kit.ExtIsVideo(name) {
@ -64,7 +64,7 @@ func _cache_upload(m *ice.Message, r *http.Request) (mime, name, file, size stri
b.Seek(0, os.SEEK_SET) b.Seek(0, os.SEEK_SET)
if n, e := io.Copy(f, b); !m.Warn(e, ice.ErrNotValid, UPLOAD) { if n, e := io.Copy(f, b); !m.Warn(e, ice.ErrNotValid, UPLOAD) {
m.Logs(nfs.SAVE, nfs.FILE, p, nfs.SIZE, kit.FmtSize(int64(n))) m.Logs(nfs.SAVE, nfs.FILE, p, nfs.SIZE, kit.FmtSize(int64(n)))
return h.Header.Get(ContentType), h.Filename, p, kit.Format(n) return h.Header.Get(html.ContentType), h.Filename, p, kit.Format(n)
} }
} }
} }
@ -79,7 +79,7 @@ func _cache_download(m *ice.Message, r *http.Response, file string, cb ice.Any)
}() }()
defer f.Close() defer f.Close()
last, base := 0, 10 last, base := 0, 10
nfs.CopyStream(m, f, r.Body, base*ice.MOD_BUFS, kit.Int(kit.Select("100", r.Header.Get(ContentLength))), func(count, total, value int) { nfs.CopyStream(m, f, r.Body, base*ice.MOD_BUFS, kit.Int(kit.Select("100", r.Header.Get(html.ContentLength))), func(count, total, value int) {
if value/base == last { if value/base == last {
return return
} }

View File

@ -4,7 +4,9 @@ import (
"strings" "strings"
ice "shylinux.com/x/icebergs" ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -49,9 +51,9 @@ func init() {
mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) { mdb.CREATE: {Name: "create type name text", Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelectUpdate(m, mdb.HashCreate(m), func(value ice.Map) { value[mdb.COUNT] = kit.Int(value[mdb.COUNT]) + 1 }) mdb.HashSelectUpdate(m, mdb.HashCreate(m), func(value ice.Map) { value[mdb.COUNT] = kit.Int(value[mdb.COUNT]) + 1 })
}}, }},
"valid": {Hand: func(m *ice.Message, arg ...string) { mdb.VALID: {Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelect(m.Spawn(), arg...).Table(func(value ice.Maps) { mdb.HashSelect(m.Spawn(), arg...).Table(func(value ice.Maps) {
if !strings.HasPrefix(value[mdb.TEXT], "Mozilla/") { if !strings.HasPrefix(value[mdb.TEXT], html.Mozilla) {
return return
} else if count := kit.Int(value[mdb.COUNT]); count < 3 { } else if count := kit.Int(value[mdb.COUNT]); count < 3 {
return return
@ -61,23 +63,26 @@ func init() {
}) })
m.StatusTimeCount(_count_stat(m)) m.StatusTimeCount(_count_stat(m))
}}, }},
"location": {Hand: func(m *ice.Message, arg ...string) { aaa.LOCATION: {Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelects(m).Sort(mdb.COUNT, ice.INT_R) GoToast(mdb.HashSelects(m).Sort(mdb.COUNT, ice.INT_R), "", func(toast func(string, int, int)) []string {
GoToast(m, "", func(toast func(string, int, int)) []string {
m.Table(func(index int, value ice.Maps) { m.Table(func(index int, value ice.Maps) {
if value["location"] == "" { if value[aaa.LOCATION] == "" {
location := kit.Format(kit.Value(SpideGet(m, "http://opendata.baidu.com/api.php?co=&resource_id=6006&oe=utf8", "query", value[mdb.NAME]), "data.0.location")) location := kit.Format(kit.Value(SpideGet(m, "http://opendata.baidu.com/api.php?co=&resource_id=6006&oe=utf8", "query", value[mdb.NAME]), "data.0.location"))
mdb.HashModify(m, mdb.HASH, value[mdb.HASH], "location", location) mdb.HashModify(m, mdb.HASH, value[mdb.HASH], aaa.LOCATION, location)
toast(location, index, m.Length()) toast(kit.Select(value[mdb.NAME], location), index, m.Length())
m.Sleep300ms() m.Sleep300ms()
} }
}) })
return nil return nil
}) })
}}, }},
}, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, "type,name", mdb.FIELD, "time,hash,count,location,type,name,text", mdb.SORT, "type,name,text,location")), Hand: func(m *ice.Message, arg ...string) { }, mdb.HashAction(mdb.LIMIT, 1000, mdb.LEAST, 500, mdb.SHORT, "type,name", mdb.FIELD, "time,hash,count,location,type,name,text")), Hand: func(m *ice.Message, arg ...string) {
mdb.HashSelect(m, arg...) mdb.HashSelect(m, arg...).Sort(mdb.TIME, ice.STR_R).StatusTimeCount(_count_stat(m))
m.StatusTimeCount(_count_stat(m))
}}, }},
}) })
} }
func Count(m *ice.Message, arg ...string) *ice.Message {
m.Cmd(COUNT, mdb.CREATE, arg, kit.Dict(ice.LOG_DISABLE, ice.TRUE))
return m
}

View File

@ -6,11 +6,30 @@ import (
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
const (
Mozilla = "Mozilla"
UserAgent = "User-Agent"
Referer = "Referer"
Authorization = "Authorization"
Bearer = "Bearer"
Basic = "Basic"
Accept = "Accept"
AcceptLanguage = "Accept-Language"
ContentLength = "Content-Length"
ContentType = "Content-Type"
XForwardedFor = "X-Forwarded-For"
XHost = "X-Host"
ApplicationForm = "application/x-www-form-urlencoded"
ApplicationOctet = "application/octet-stream"
ApplicationJSON = "application/json"
)
const ( const (
H1 = "h1" H1 = "h1"
H2 = "h2" H2 = "h2"
H3 = "h3" H3 = "h3"
SPAN = "span" SPAN = "span"
CHECKBOX = "checkbox"
STYLE = "style" STYLE = "style"
WIDTH = "width" WIDTH = "width"
@ -77,8 +96,3 @@ func FormatDanger(value string) string {
COLOR, "var(--danger-fg-color)", COLOR, "var(--danger-fg-color)",
)) ))
} }
const (
AcceptLanguage = "Accept-Language"
CHECKBOX = "checkbox"
)

View File

@ -14,6 +14,7 @@ import (
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -98,7 +99,7 @@ func RenderType(w http.ResponseWriter, name, mime string) {
mime = "application/" + kit.Ext(name) mime = "application/" + kit.Ext(name)
} }
} }
RenderHeader(w, ContentType, mime) RenderHeader(w, html.ContentType, mime)
} }
func RenderOrigin(w http.ResponseWriter, origin string) { func RenderOrigin(w http.ResponseWriter, origin string) {
RenderHeader(w, "Access-Control-Allow-Origin", origin) RenderHeader(w, "Access-Control-Allow-Origin", origin)

View File

@ -19,6 +19,7 @@ import (
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/ssh" "shylinux.com/x/icebergs/base/ssh"
"shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
"shylinux.com/x/toolkits/logs" "shylinux.com/x/toolkits/logs"
) )
@ -40,7 +41,6 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
const ( const (
X_REAL_IP = "X-Real-Ip" X_REAL_IP = "X-Real-Ip"
X_REAL_PORT = "X-Real-Port" X_REAL_PORT = "X-Real-Port"
X_FORWARDED_FOR = "X-Forwarded-For"
INDEX_MODULE = "Index-Module" INDEX_MODULE = "Index-Module"
) )
if r.Header.Get(INDEX_MODULE) == "" { if r.Header.Get(INDEX_MODULE) == "" {
@ -52,7 +52,7 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
if r.Header.Set(ice.MSG_USERIP, ip); r.Header.Get(X_REAL_PORT) != "" { if r.Header.Set(ice.MSG_USERIP, ip); r.Header.Get(X_REAL_PORT) != "" {
r.Header.Set(ice.MSG_USERADDR, ip+nfs.DF+r.Header.Get(X_REAL_PORT)) r.Header.Set(ice.MSG_USERADDR, ip+nfs.DF+r.Header.Get(X_REAL_PORT))
} }
} else if ip := r.Header.Get(X_FORWARDED_FOR); ip != "" { } else if ip := r.Header.Get(html.XForwardedFor); ip != "" {
r.Header.Set(ice.MSG_USERIP, kit.Split(ip)[0]) r.Header.Set(ice.MSG_USERIP, kit.Split(ip)[0])
} else if strings.HasPrefix(r.RemoteAddr, "[") { } else if strings.HasPrefix(r.RemoteAddr, "[") {
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, "]")[0][1:]) r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, "]")[0][1:])
@ -63,7 +63,7 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
r.Header.Set(ice.LOG_TRACEID, log.Traceid()) r.Header.Set(ice.LOG_TRACEID, log.Traceid())
m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String(), logs.TraceidMeta(r.Header.Get(ice.LOG_TRACEID))) m.Logs(r.Header.Get(ice.MSG_USERIP), r.Method, r.URL.String(), logs.TraceidMeta(r.Header.Get(ice.LOG_TRACEID)))
} }
if path.Join(r.URL.Path) == nfs.PS && strings.HasPrefix(r.UserAgent(), Mozilla) { if path.Join(r.URL.Path) == nfs.PS && strings.HasPrefix(r.UserAgent(), html.Mozilla) {
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 { if r.Method == http.MethodGet {
@ -85,7 +85,7 @@ func _serve_static(msg *ice.Message, w http.ResponseWriter, r *http.Request) boo
} else if p = path.Join(nfs.USR, r.URL.Path); kit.HasPrefix(r.URL.Path, nfs.VOLCANOS, nfs.INTSHELL) && nfs.Exists(msg, 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) 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) { } 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=") ispod := kit.Contains(r.URL.String(), CHAT_POD, "pod=") || kit.Contains(r.Header.Get(html.Referer), CHAT_POD, "pod=")
return !ispod && Render(msg, ice.RENDER_DOWNLOAD, p) 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) { } 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) return Render(msg, ice.RENDER_DOWNLOAD, p)
@ -94,7 +94,7 @@ func _serve_static(msg *ice.Message, w http.ResponseWriter, r *http.Request) boo
} }
} }
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(html.Referer), "debug=true")
m.Options(ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID), ice.MSG_LANGUAGE, "") m.Options(ice.LOG_TRACEID, r.Header.Get(ice.LOG_TRACEID), ice.MSG_LANGUAGE, "")
_log := func(level string, arg ...ice.Any) *ice.Message { _log := func(level string, arg ...ice.Any) *ice.Message {
if debug || arg[0] == ice.MSG_CMDS { if debug || arg[0] == ice.MSG_CMDS {
@ -102,8 +102,8 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
} }
return m return m
} }
kit.If(r.Header.Get(Referer), func(p string) { _log("page", Referer, p) }) kit.If(r.Header.Get(html.Referer), func(p string) { _log("page", html.Referer, p) })
if u, e := url.Parse(r.Header.Get(Referer)); e == nil { if u, e := url.Parse(r.Header.Get(html.Referer)); e == nil {
add := func(k, v string) { _log(nfs.PATH, k, m.Option(k, v)) } add := func(k, v string) { _log(nfs.PATH, k, m.Option(k, v)) }
switch arg := strings.Split(strings.TrimPrefix(u.Path, nfs.PS), nfs.PS); arg[0] { switch arg := strings.Split(strings.TrimPrefix(u.Path, nfs.PS), nfs.PS); arg[0] {
case CHAT: case CHAT:
@ -117,18 +117,18 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
if r.Method == http.MethodGet && m.Option(ice.MSG_CMDS) != "" { if r.Method == http.MethodGet && m.Option(ice.MSG_CMDS) != "" {
_log(ctx.ARGS, ice.MSG_CMDS, m.Optionv(ice.MSG_CMDS)) _log(ctx.ARGS, ice.MSG_CMDS, m.Optionv(ice.MSG_CMDS))
} }
switch kit.Select("", kit.Split(r.Header.Get(ContentType)), 0) { switch kit.Select("", kit.Split(r.Header.Get(html.ContentType)), 0) {
case ApplicationJSON: case html.ApplicationJSON:
kit.For(kit.UnMarshal(r.Body), func(k string, v ice.Any) { m.Optionv(k, v) }) kit.For(kit.UnMarshal(r.Body), func(k string, v ice.Any) { m.Optionv(k, v) })
default: default:
r.ParseMultipartForm(kit.Int64(kit.Select("4096", r.Header.Get(ContentLength)))) r.ParseMultipartForm(kit.Int64(kit.Select("4096", r.Header.Get(html.ContentLength))))
kit.For(r.PostForm, func(k string, v []string) { _log(FORM, k, kit.Join(v, lex.SP)).Optionv(k, v) }) kit.For(r.PostForm, func(k string, v []string) { _log(FORM, k, kit.Join(v, lex.SP)).Optionv(k, v) })
} }
kit.For(r.Cookies(), func(k, v string) { m.Optionv(k, v) }) kit.For(r.Cookies(), func(k, v string) { m.Optionv(k, v) })
m.Options(ice.MSG_METHOD, r.Method, ice.MSG_COUNT, "0") m.Options(ice.MSG_METHOD, r.Method, ice.MSG_COUNT, "0")
m.Options(ice.MSG_REFERER, r.Header.Get(Referer)) m.Options(ice.MSG_REFERER, r.Header.Get(html.Referer))
m.Options(ice.MSG_USERWEB, _serve_domain(m), ice.MSG_USERPOD, m.Option(ice.POD)) m.Options(ice.MSG_USERWEB, _serve_domain(m), ice.MSG_USERPOD, m.Option(ice.POD))
m.Options(ice.MSG_USERUA, r.Header.Get(UserAgent), ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP)) m.Options(ice.MSG_USERUA, r.Header.Get(html.UserAgent), ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
m.Options(ice.MSG_SESSID, kit.Select(m.Option(ice.MSG_SESSID), m.Option(CookieName(m.Option(ice.MSG_USERWEB))))) m.Options(ice.MSG_SESSID, kit.Select(m.Option(ice.MSG_SESSID), m.Option(CookieName(m.Option(ice.MSG_USERWEB)))))
kit.If(m.Optionv(ice.MSG_CMDS) == nil, func() { kit.If(m.Optionv(ice.MSG_CMDS) == nil, func() {
kit.If(strings.TrimPrefix(r.URL.Path, key), func(p string) { m.Optionv(ice.MSG_CMDS, strings.Split(p, nfs.PS)) }) kit.If(strings.TrimPrefix(r.URL.Path, key), func(p string) { m.Optionv(ice.MSG_CMDS, strings.Split(p, nfs.PS)) })
@ -154,8 +154,8 @@ func _serve_handle(key string, cmd *ice.Command, m *ice.Message, w http.Response
} }
func _serve_domain(m *ice.Message) string { func _serve_domain(m *ice.Message) string {
return kit.GetValid( return kit.GetValid(
func() string { return kit.Select("", m.R.Header.Get(Referer), m.R.Method == http.MethodPost) }, func() string { return kit.Select("", m.R.Header.Get(html.Referer), m.R.Method == http.MethodPost) },
func() string { return m.R.Header.Get("X-Host") }, func() string { return m.R.Header.Get(html.XHost) },
func() string { return ice.Info.Domain }, func() string { return ice.Info.Domain },
func() string { func() string {
if b, e := regexp.MatchString("^[0-9.]+$", m.R.Host); b && e == nil { if b, e := regexp.MatchString("^[0-9.]+$", m.R.Host); b && e == nil {
@ -183,7 +183,7 @@ func _serve_auth(m *ice.Message, key string, cmds []string, w http.ResponseWrite
aaa.SessAuth(m, kit.Dict(aaa.USERNICK, ls[1], aaa.USERNAME, ls[2], aaa.USERROLE, ls[3]), CACHE, ls[0]) aaa.SessAuth(m, kit.Dict(aaa.USERNICK, ls[1], aaa.USERNAME, ls[2], aaa.USERROLE, ls[3]), CACHE, ls[0])
} }
} }
m.Cmd(COUNT, mdb.CREATE, aaa.IP, m.Option(ice.MSG_USERIP), m.Option(ice.MSG_USERUA), kit.Dict(ice.LOG_DISABLE, ice.TRUE)) Count(m, aaa.IP, m.Option(ice.MSG_USERIP), m.Option(ice.MSG_USERUA))
return cmds, aaa.Right(m, key, cmds) return cmds, aaa.Right(m, key, cmds)
} }
@ -275,5 +275,5 @@ func RequireFile(m *ice.Message, file string) string {
return "" return ""
} }
func IsLocalHost(m *ice.Message) bool { func IsLocalHost(m *ice.Message) bool {
return (m.R == nil || m.R.Header.Get("X-Forwarded-For") == "") && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP)) return (m.R == nil || m.R.Header.Get(html.XForwardedFor) == "") && tcp.IsLocalHost(m, m.Option(ice.MSG_USERIP))
} }

View File

@ -19,6 +19,7 @@ import (
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -61,7 +62,7 @@ func _spide_show(m *ice.Message, name string, arg ...string) {
return return
} }
defer res.Body.Close() defer res.Body.Close()
m.Cost(cli.STATUS, res.Status, nfs.SIZE, kit.FmtSize(kit.Int64(res.Header.Get(ContentLength))), mdb.TYPE, res.Header.Get(ContentType)) m.Cost(cli.STATUS, res.Status, nfs.SIZE, kit.FmtSize(kit.Int64(res.Header.Get(html.ContentLength))), mdb.TYPE, res.Header.Get(html.ContentType))
m.Push(mdb.TYPE, STATUS).Push(mdb.NAME, res.StatusCode).Push(mdb.VALUE, res.Status) m.Push(mdb.TYPE, STATUS).Push(mdb.NAME, res.StatusCode).Push(mdb.VALUE, res.Status)
m.Options(STATUS, res.Status) m.Options(STATUS, res.Status)
kit.For(res.Header, func(k string, v []string) { kit.For(res.Header, func(k string, v []string) {
@ -104,16 +105,16 @@ func _spide_body(m *ice.Message, method string, arg ...string) (io.Reader, ice.M
case SPIDE_FORM: case SPIDE_FORM:
arg = kit.Simple(arg, func(v string) string { return url.QueryEscape(v) }) arg = kit.Simple(arg, func(v string) string { return url.QueryEscape(v) })
_data := kit.JoinKV("=", "&", arg[1:]...) _data := kit.JoinKV("=", "&", arg[1:]...)
head[ContentType], body = ApplicationForm, bytes.NewBufferString(_data) head[html.ContentType], body = html.ApplicationForm, bytes.NewBufferString(_data)
case SPIDE_PART: case SPIDE_PART:
head[ContentType], body = _spide_part(m, arg...) head[html.ContentType], body = _spide_part(m, arg...)
case SPIDE_FILE: case SPIDE_FILE:
if f, e := nfs.OpenFile(m, arg[1]); m.Assert(e) { if f, e := nfs.OpenFile(m, arg[1]); m.Assert(e) {
m.Logs(nfs.LOAD, nfs.FILE, arg[1]) m.Logs(nfs.LOAD, nfs.FILE, arg[1])
body = f body = f
} }
case SPIDE_DATA: case SPIDE_DATA:
head[ContentType], body = ApplicationJSON, bytes.NewBufferString(kit.Select("{}", arg, 1)) head[html.ContentType], body = html.ApplicationJSON, bytes.NewBufferString(kit.Select("{}", arg, 1))
case SPIDE_JSON: case SPIDE_JSON:
arg = arg[1:] arg = arg[1:]
fallthrough fallthrough
@ -121,7 +122,7 @@ func _spide_body(m *ice.Message, method string, arg ...string) (io.Reader, ice.M
data := ice.Map{} data := ice.Map{}
kit.For(arg, func(k, v string) { kit.Value(data, k, v) }) kit.For(arg, func(k, v string) { kit.Value(data, k, v) })
_data := kit.Format(data) _data := kit.Format(data)
head[ContentType], body = ApplicationJSON, bytes.NewBufferString(_data) head[html.ContentType], body = html.ApplicationJSON, bytes.NewBufferString(_data)
} }
return body, head, arg[:0] return body, head, arg[:0]
} }
@ -170,7 +171,9 @@ func _spide_head(m *ice.Message, req *http.Request, head ice.Maps, value ice.Map
kit.For(value[SPIDE_COOKIE], func(k string, v string) { req.AddCookie(&http.Cookie{Name: k, Value: v}) }) kit.For(value[SPIDE_COOKIE], func(k string, v string) { req.AddCookie(&http.Cookie{Name: k, Value: v}) })
kit.For(kit.Simple(m.Optionv(SPIDE_COOKIE)), func(k, v string) { req.AddCookie(&http.Cookie{Name: k, Value: v}) }) kit.For(kit.Simple(m.Optionv(SPIDE_COOKIE)), func(k, v string) { req.AddCookie(&http.Cookie{Name: k, Value: v}) })
kit.For(kit.Simple(m.Optionv(SPIDE_HEADER)), func(k, v string) { req.Header.Set(k, v) }) kit.For(kit.Simple(m.Optionv(SPIDE_HEADER)), func(k, v string) { req.Header.Set(k, v) })
kit.If(req.Method == http.MethodPost, func() { m.Logs(kit.Select(ice.AUTO, req.Header.Get(ContentLength)), req.Header.Get(ContentType)) }) kit.If(req.Method == http.MethodPost, func() {
m.Logs(kit.Select(ice.AUTO, req.Header.Get(html.ContentLength)), req.Header.Get(html.ContentType))
})
} }
func _spide_send(m *ice.Message, name string, req *http.Request, timeout string) (*http.Response, error) { func _spide_send(m *ice.Message, name string, req *http.Request, timeout string) (*http.Response, error) {
client := mdb.HashSelectTarget(m, name, func() ice.Any { return &http.Client{Timeout: kit.Duration(timeout)} }).(*http.Client) client := mdb.HashSelectTarget(m, name, func() ice.Any { return &http.Client{Timeout: kit.Duration(timeout)} }).(*http.Client)
@ -184,7 +187,7 @@ func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) {
} }
switch action { switch action {
case SPIDE_RAW: case SPIDE_RAW:
if b, _ := ioutil.ReadAll(res.Body); strings.HasPrefix(res.Header.Get(ContentType), ApplicationJSON) { if b, _ := ioutil.ReadAll(res.Body); strings.HasPrefix(res.Header.Get(html.ContentType), html.ApplicationJSON) {
// m.Echo(kit.Formats(kit.UnMarshal(string(b)))) // m.Echo(kit.Formats(kit.UnMarshal(string(b))))
m.Echo(string(b)) m.Echo(string(b))
} else { } else {
@ -198,7 +201,7 @@ func _spide_save(m *ice.Message, action, file, uri string, res *http.Response) {
case SPIDE_SAVE: case SPIDE_SAVE:
_cache_download(m, res, file, m.OptionCB(SPIDE)) _cache_download(m, res, file, m.OptionCB(SPIDE))
case SPIDE_CACHE: case SPIDE_CACHE:
m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(ContentType), uri, kit.Dict(RESPONSE, res), m.OptionCB(SPIDE)) m.Cmdy(CACHE, DOWNLOAD, res.Header.Get(html.ContentType), uri, kit.Dict(RESPONSE, res), m.OptionCB(SPIDE))
m.Echo(m.Append(mdb.HASH)) m.Echo(m.Append(mdb.HASH))
default: default:
var data ice.Any var data ice.Any
@ -226,21 +229,6 @@ const (
SPIDE_JSON = "json" SPIDE_JSON = "json"
SPIDE_RES = "content_data" SPIDE_RES = "content_data"
Basic = "Basic"
Bearer = "Bearer"
Authorization = "Authorization"
AcceptLanguage = "Accept-Language"
ContentLength = "Content-Length"
ContentType = "Content-Type"
UserAgent = "User-Agent"
Referer = "Referer"
Accept = "Accept"
Mozilla = "Mozilla"
ApplicationForm = "application/x-www-form-urlencoded"
ApplicationOctet = "application/octet-stream"
ApplicationJSON = "application/json"
IMAGE_JPEG = "image/jpeg" IMAGE_JPEG = "image/jpeg"
IMAGE_PNG = "image/png" IMAGE_PNG = "image/png"
TEXT_HTML = "text/html" TEXT_HTML = "text/html"
@ -332,7 +320,7 @@ func init() {
case HEADER: case HEADER:
switch arg[0] { switch arg[0] {
case mdb.KEY: case mdb.KEY:
m.Push(arg[0], Authorization) m.Push(arg[0], html.Authorization)
} }
default: default:
mdb.HashSelectValue(m.Spawn(), func(value ice.Map) { m.Push(kit.Select(ORIGIN, arg, 0), kit.Value(value, CLIENT_ORIGIN)) }) mdb.HashSelectValue(m.Spawn(), func(value ice.Map) { m.Push(kit.Select(ORIGIN, arg, 0), kit.Value(value, CLIENT_ORIGIN)) })

View File

@ -10,6 +10,7 @@ import (
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/tcp" "shylinux.com/x/icebergs/base/tcp"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -32,7 +33,7 @@ func init() {
if m.Warn(m.R.Method != http.MethodPost, ice.ErrNotAllow) { if m.Warn(m.R.Method != http.MethodPost, ice.ErrNotAllow) {
return return
} }
msg := m.Cmd("", mdb.CREATE, mdb.TYPE, Basic, mdb.NAME, m.Option(ice.MSG_USERNAME), mdb.TEXT, m.Option(tcp.HOST)) msg := m.Cmd("", mdb.CREATE, mdb.TYPE, html.Basic, mdb.NAME, m.Option(ice.MSG_USERNAME), mdb.TEXT, m.Option(tcp.HOST))
m.ProcessReplace(kit.MergeURL2(m.Option(tcp.HOST), ChatCmdPath(m, m.PrefixKey(), SET), m.ProcessReplace(kit.MergeURL2(m.Option(tcp.HOST), ChatCmdPath(m, m.PrefixKey(), SET),
TOKEN, strings.Replace(UserHost(m), "://", kit.Format("://%s:%s@", m.Option(ice.MSG_USERNAME), msg.Result()), 1))) TOKEN, strings.Replace(UserHost(m), "://", kit.Format("://%s:%s@", m.Option(ice.MSG_USERNAME), msg.Result()), 1)))
}}, }},

View File

@ -10,6 +10,7 @@ import (
"shylinux.com/x/icebergs/base/lex" "shylinux.com/x/icebergs/base/lex"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -177,7 +178,7 @@ func (s Client) request(m *ice.Message, hash, api string, arg ...string) []strin
m.Option(ACCESS_TOKEN, msg.Append(ACCESS_TOKEN)) m.Option(ACCESS_TOKEN, msg.Append(ACCESS_TOKEN))
}) })
kit.If(m.Option(ACCESS_TOKEN), func(p string) { kit.If(m.Option(ACCESS_TOKEN), func(p string) {
m.Options(web.SPIDE_HEADER, ice.Maps{web.Authorization: msg.Append(TOKEN_PREFIX) + lex.SP + p}) m.Options(web.SPIDE_HEADER, ice.Maps{html.Authorization: msg.Append(TOKEN_PREFIX) + lex.SP + p})
arg = append(arg, ACCESS_TOKEN, p) arg = append(arg, ACCESS_TOKEN, p)
}) })
kit.If(api == "", func() { api = path.Join(msg.Append(API_PREFIX), m.ActionKey()) }) kit.If(api == "", func() { api = path.Join(msg.Append(API_PREFIX), m.ActionKey()) })

View File

@ -9,6 +9,7 @@ import (
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/base/web/html"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
) )
@ -33,5 +34,5 @@ func GetSSO(m *ice.Message) string {
return "" return ""
} }
ls := strings.Split(kit.ParseURL(link).Path, nfs.PS) ls := strings.Split(kit.ParseURL(link).Path, nfs.PS)
return kit.MergeURL2(link, web.PP(CHAT, SSO), web.SPACE, kit.Select("", ls, 3), cli.BACK, m.R.Header.Get(web.Referer)) return kit.MergeURL2(link, web.PP(CHAT, SSO), web.SPACE, kit.Select("", ls, 3), cli.BACK, m.R.Header.Get(html.Referer))
} }

View File

@ -11,7 +11,7 @@ import (
"shylinux.com/x/icebergs/base/gdb" "shylinux.com/x/icebergs/base/gdb"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs" "shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web/html"
"shylinux.com/x/icebergs/core/chat" "shylinux.com/x/icebergs/core/chat"
"shylinux.com/x/icebergs/core/chat/location" "shylinux.com/x/icebergs/core/chat/location"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
@ -20,7 +20,7 @@ import (
func _wx_sign(m *ice.Message, nonce, stamp string) string { func _wx_sign(m *ice.Message, nonce, stamp string) string {
return kit.Format(sha1.Sum([]byte(kit.Join(kit.Sort(kit.Simple( return kit.Format(sha1.Sum([]byte(kit.Join(kit.Sort(kit.Simple(
kit.Format("jsapi_ticket=%s", m.Cmdx(ACCESS, TICKET)), kit.Format("jsapi_ticket=%s", m.Cmdx(ACCESS, TICKET)),
kit.Format("url=%s", m.R.Header.Get(web.Referer)), kit.Format("url=%s", m.R.Header.Get(html.Referer)),
kit.Format("timestamp=%s", stamp), kit.Format("timestamp=%s", stamp),
kit.Format("noncestr=%s", nonce), kit.Format("noncestr=%s", nonce),
)), "&")))) )), "&"))))

View File

@ -62,7 +62,7 @@ func init() {
msg := spidePost(m, WXACODE_UNLIMIT, web.SPIDE_DATA, kit.Format(kit.Dict( msg := spidePost(m, WXACODE_UNLIMIT, web.SPIDE_DATA, kit.Format(kit.Dict(
"env_version", m.Option(ENV), "page", info.Append(PAGES), SCENE, meta, IS_HYALINE, m.Option(IS_HYALINE) == ice.TRUE, html.WIDTH, 320, "env_version", m.Option(ENV), "page", info.Append(PAGES), SCENE, meta, IS_HYALINE, m.Option(IS_HYALINE) == ice.TRUE, html.WIDTH, 320,
))) )))
switch kit.Select("", kit.Split(msg.Option(web.ContentType), "; "), 0) { switch kit.Select("", kit.Split(msg.Option(html.ContentType), "; "), 0) {
case web.IMAGE_JPEG: case web.IMAGE_JPEG:
image := m.Cmd(web.CACHE, web.WRITE, mdb.TYPE, web.IMAGE_JPEG, mdb.NAME, scene, kit.Dict(mdb.TEXT, msg.Result())).Append(mdb.HASH) image := m.Cmd(web.CACHE, web.WRITE, mdb.TYPE, web.IMAGE_JPEG, mdb.NAME, scene, kit.Dict(mdb.TEXT, msg.Result())).Append(mdb.HASH)
mdb.HashSelects(m, mdb.HashCreate(m.Spawn(), m.OptionSimple(mdb.NAME), mdb.TEXT, meta, nfs.IMAGE, image, ctx.INDEX, m.Prefix(IDE), ctx.ARGS, scene, mdb.TYPE, m.Option(ENV))) mdb.HashSelects(m, mdb.HashCreate(m.Spawn(), m.OptionSimple(mdb.NAME), mdb.TEXT, meta, nfs.IMAGE, image, ctx.INDEX, m.Prefix(IDE), ctx.ARGS, scene, mdb.TYPE, m.Option(ENV)))