From c78d114767422026a164baf62a16662566c2c1e6 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sun, 6 Oct 2024 01:20:34 +0800 Subject: [PATCH] fix --- auth/blacklist.go | 43 ++++++++++++++++++++++++++++++++++++++++++- proxy/proxy.go | 2 +- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/auth/blacklist.go b/auth/blacklist.go index a008a42..6025de4 100644 --- a/auth/blacklist.go +++ b/auth/blacklist.go @@ -1,6 +1,47 @@ 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 { if blocked == fullrepo { return true diff --git a/proxy/proxy.go b/proxy/proxy.go index fdd06ec..32dc370 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -60,7 +60,7 @@ func NoRouteHandler(cfg *config.Config, blist *config.Blist) gin.HandlerFunc { fullrepo := fmt.Sprintf("%s/%s", username, repo) // 黑名单检查 - blacklistpass := auth.CheckBlacklist(fullrepo, blist.Blacklist) + blacklistpass := auth.CheckBlacklist(fullrepo) if blacklistpass { c.AbortWithStatusJSON(404, gin.H{"error": "Not found"}) logw("Blacklisted repo: %s", fullrepo)