mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
24w06b
This commit is contained in:
parent
0899397d2e
commit
45246e124e
1 changed files with 21 additions and 2 deletions
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"ghproxy/auth"
|
|
||||||
"ghproxy/config"
|
"ghproxy/config"
|
||||||
"ghproxy/logger"
|
"ghproxy/logger"
|
||||||
|
|
||||||
|
|
@ -47,7 +46,7 @@ func NoRouteHandler(config *config.Config) gin.HandlerFunc {
|
||||||
rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
|
rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !auth.AuthHandler(c) {
|
if !AuthHandler(c) {
|
||||||
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
||||||
logw("Unauthorized request: %s", rawPath)
|
logw("Unauthorized request: %s", rawPath)
|
||||||
return
|
return
|
||||||
|
|
@ -190,3 +189,23 @@ func checkURL(u string) []string {
|
||||||
logw("Invalid URL: %s", u)
|
logw("Invalid URL: %s", u)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AuthHandler(c *gin.Context) bool {
|
||||||
|
// 如果身份验证未启用,直接返回 true
|
||||||
|
if !cfg.Auth {
|
||||||
|
logw("auth PASS")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取 auth_token 参数
|
||||||
|
authToken := c.Query("auth_token")
|
||||||
|
logw("auth_token: ", authToken)
|
||||||
|
|
||||||
|
// 验证 token
|
||||||
|
isValid := authToken == cfg.AuthToken
|
||||||
|
if !isValid {
|
||||||
|
logw("auth FAIL")
|
||||||
|
}
|
||||||
|
|
||||||
|
return isValid
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue