mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 00:01:10 +08:00
24w15c
This commit is contained in:
parent
e3d56ae9b7
commit
824656f9d0
10 changed files with 191 additions and 75 deletions
27
auth/auth.go
27
auth/auth.go
|
|
@ -7,7 +7,24 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var logw = logger.Logw
|
||||
// 日志模块
|
||||
var (
|
||||
logw = logger.Logw
|
||||
logInfo = logger.LogInfo
|
||||
LogWarning = logger.LogWarning
|
||||
logError = logger.LogError
|
||||
)
|
||||
|
||||
// Auth Init
|
||||
func Init(cfg *config.Config) {
|
||||
if cfg.Blacklist.Enabled {
|
||||
LoadBlacklist(cfg)
|
||||
}
|
||||
if cfg.Whitelist.Enabled {
|
||||
LoadWhitelist(cfg)
|
||||
}
|
||||
logInfo("Auth Init")
|
||||
}
|
||||
|
||||
func AuthHandler(c *gin.Context, cfg *config.Config) bool {
|
||||
// 如果身份验证未启用,直接返回 true
|
||||
|
|
@ -17,19 +34,19 @@ func AuthHandler(c *gin.Context, cfg *config.Config) bool {
|
|||
|
||||
// 获取 auth_token 参数
|
||||
authToken := c.Query("auth_token")
|
||||
logw("auth_token received: %s", authToken)
|
||||
logInfo("auth_token received: %s", authToken)
|
||||
|
||||
// 验证 token
|
||||
if authToken == "" {
|
||||
logw("auth FAILED: no auth_token provided")
|
||||
LogWarning("auth FAILED: no auth_token provided")
|
||||
return false
|
||||
}
|
||||
|
||||
isValid := authToken == cfg.Auth.AuthToken
|
||||
if !isValid {
|
||||
logw("auth FAILED: invalid auth_token: %s", authToken)
|
||||
LogWarning("auth FAILED: invalid auth_token: %s", authToken)
|
||||
}
|
||||
|
||||
logw("auth SUCCESS: %t", isValid)
|
||||
logInfo("auth SUCCESS: %t", isValid)
|
||||
return isValid
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue