mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
fix
This commit is contained in:
parent
b87a8de3c4
commit
c78d114767
2 changed files with 43 additions and 2 deletions
|
|
@ -1,6 +1,47 @@
|
||||||
package auth
|
package auth
|
||||||
|
|
||||||
func CheckBlacklist(fullrepo string, blist []string) bool {
|
import (
|
||||||
|
"fmt"
|
||||||
|
"ghproxy/config"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
cfg *config.Config
|
||||||
|
configfile = "/data/ghproxy/config/config.yaml"
|
||||||
|
blacklist *config.Blist
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
loadBlacklistConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadConfig() {
|
||||||
|
var err error
|
||||||
|
// 初始化配置
|
||||||
|
cfg, err = config.LoadConfig(configfile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to load config: %v", err)
|
||||||
|
}
|
||||||
|
fmt.Printf("Loaded config: %v\n", cfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadBlacklistConfig() {
|
||||||
|
var err error
|
||||||
|
// 初始化黑名单配置
|
||||||
|
blacklist, err = config.LoadBlacklistConfig(cfg.Blacklist.BlacklistFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to load blacklist: %v", err)
|
||||||
|
}
|
||||||
|
logw("Loaded blacklist: %v", blacklist)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckBlacklist(fullrepo string) bool {
|
||||||
|
forRangeCheck(blacklist.Blacklist, fullrepo)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func forRangeCheck(blist []string, fullrepo string) bool {
|
||||||
for _, blocked := range blist {
|
for _, blocked := range blist {
|
||||||
if blocked == fullrepo {
|
if blocked == fullrepo {
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func NoRouteHandler(cfg *config.Config, blist *config.Blist) gin.HandlerFunc {
|
||||||
fullrepo := fmt.Sprintf("%s/%s", username, repo)
|
fullrepo := fmt.Sprintf("%s/%s", username, repo)
|
||||||
|
|
||||||
// 黑名单检查
|
// 黑名单检查
|
||||||
blacklistpass := auth.CheckBlacklist(fullrepo, blist.Blacklist)
|
blacklistpass := auth.CheckBlacklist(fullrepo)
|
||||||
if blacklistpass {
|
if blacklistpass {
|
||||||
c.AbortWithStatusJSON(404, gin.H{"error": "Not found"})
|
c.AbortWithStatusJSON(404, gin.H{"error": "Not found"})
|
||||||
logw("Blacklisted repo: %s", fullrepo)
|
logw("Blacklisted repo: %s", fullrepo)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue