mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-10 02:30:09 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
fc1b98e9e1
@ -94,7 +94,7 @@ func LoginAuth(c *gin.Context) {
|
|||||||
if Conf.AccessAuthCode != authCode {
|
if Conf.AccessAuthCode != authCode {
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = Conf.Language(83)
|
ret.Msg = Conf.Language(83)
|
||||||
logging.LogWarnf("invalid auth code")
|
logging.LogWarnf("invalid auth code [ip=%s]", util.GetRemoteAddr(c.Request))
|
||||||
|
|
||||||
util.WrongAuthCount++
|
util.WrongAuthCount++
|
||||||
workspaceSession.Captcha = gulu.Rand.String(7)
|
workspaceSession.Captcha = gulu.Rand.String(7)
|
||||||
@ -113,7 +113,7 @@ func LoginAuth(c *gin.Context) {
|
|||||||
workspaceSession.AccessAuthCode = authCode
|
workspaceSession.AccessAuthCode = authCode
|
||||||
util.WrongAuthCount = 0
|
util.WrongAuthCount = 0
|
||||||
workspaceSession.Captcha = gulu.Rand.String(7)
|
workspaceSession.Captcha = gulu.Rand.String(7)
|
||||||
logging.LogInfof("auth success")
|
logging.LogInfof("auth success [ip=%s]", util.GetRemoteAddr(c.Request))
|
||||||
if err := session.Save(c); nil != err {
|
if err := session.Save(c); nil != err {
|
||||||
logging.LogErrorf("save session failed: " + err.Error())
|
logging.LogErrorf("save session failed: " + err.Error())
|
||||||
c.Status(http.StatusInternalServerError)
|
c.Status(http.StatusInternalServerError)
|
||||||
|
@ -457,7 +457,7 @@ func serveWebSocket(ginServer *gin.Engine) {
|
|||||||
|
|
||||||
if !authOk {
|
if !authOk {
|
||||||
s.CloseWithMsg([]byte(" unauthenticated"))
|
s.CloseWithMsg([]byte(" unauthenticated"))
|
||||||
logging.LogWarnf("closed an unauthenticated session [%s]", util.GetRemoteAddr(s))
|
logging.LogWarnf("closed an unauthenticated session [%s]", util.GetRemoteAddr(s.Request))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/imroc/req/v3"
|
"github.com/imroc/req/v3"
|
||||||
"github.com/olahol/melody"
|
|
||||||
"github.com/siyuan-note/httpclient"
|
"github.com/siyuan-note/httpclient"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
)
|
)
|
||||||
@ -125,15 +124,15 @@ func isOnline(checkURL string, skipTlsVerify bool) (ret bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetRemoteAddr(session *melody.Session) string {
|
func GetRemoteAddr(req *http.Request) string {
|
||||||
ret := session.Request.Header.Get("X-forwarded-for")
|
ret := req.Header.Get("X-forwarded-for")
|
||||||
ret = strings.TrimSpace(ret)
|
ret = strings.TrimSpace(ret)
|
||||||
if "" == ret {
|
if "" == ret {
|
||||||
ret = session.Request.Header.Get("X-Real-IP")
|
ret = req.Header.Get("X-Real-IP")
|
||||||
}
|
}
|
||||||
ret = strings.TrimSpace(ret)
|
ret = strings.TrimSpace(ret)
|
||||||
if "" == ret {
|
if "" == ret {
|
||||||
return session.Request.RemoteAddr
|
return req.RemoteAddr
|
||||||
}
|
}
|
||||||
return strings.Split(ret, ",")[0]
|
return strings.Split(ret, ",")[0]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user