From 5ac08bba56f312648d1c3fae9f7fd744c0cf54e2 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sun, 6 Oct 2024 04:32:55 +0800 Subject: [PATCH] 1.3.0 --- CHANGELOG.md | 10 ++++++++++ README.md | 24 +++++++++++++++++++----- VERSION | 2 +- auth/auth.go | 2 +- docker/dockerfile/release/Dockerfile | 1 + proxy/proxy.go | 9 ++++----- 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3333b56..1ebf1a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # 更新日志 +v1.3.0 +--- +- CHANGE: 优化代码结构,提升性能 +- CHANGE: 优化黑名单功能,提升稳定性 +- CHANGE: 剃刀计划,减少调试用日志输出 +- ADD: 新增auth子模块blacklist.go,支持黑名单功能 +- ADD: 新增blacklist.json文件,用于配置黑名单 +- CHANGE: config.yaml文件格式修改,使其具备更好的可读性 +- WARNING: 此版本为大版本更新,配置文件重构,此版本不再向前兼容,请注意备份文件并重新部署 + 24w09b --- - CHANGE: 优化代码结构,提升性能 diff --git a/README.md b/README.md index 547fad2..3dec4bb 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ - 支持Docker部署 - 支持速率限制 - 支持用户鉴权 +- 支持自定义黑名单 - 符合[RFC 7234](https://httpwg.org/specs/rfc7234.html)的HTTP Cache - 使用Caddy作为Web Server - 基于[WJQSERVER-STUDIO/golang-temp](https://github.com/WJQSERVER-STUDIO/golang-temp)模板构建,具有标准化的日志记录与构建流程 @@ -62,7 +63,7 @@ docker run -p 7210:80 -v ./ghproxy/log/run:/data/ghproxy/log -v ./ghproxy/log/ca 本项目采用config.yaml作为外部配置,默认配置如下 使用Docker部署时,慎重修改config.yaml,以免造成不必要的麻烦 -``` +```yaml # 核心配置 server: port: 8080 # 监听端口(小白请勿修改) @@ -86,13 +87,27 @@ auth: # 黑名单配置 blacklist: enabled: true - blacklistfile: "/data/ghproxy/config/blacklist.yaml" + blacklistfile: "/data/ghproxy/config/blacklist.json" ``` +### 黑名单配置 + +黑名单配置位于config/blacklist.json,格式如下: + +```json +{ + "blacklist": [ + "test/test1", + "example/repo2", + "another/repo3" + ] + } +``` + ### Caddy反代配置 -``` +```Caddyfile example.com { reverse_proxy { to 127.0.0.1:7210 @@ -112,9 +127,8 @@ example.com { - [x] 允许更多参数通过config结构传入 - [x] 改进程序效率 - [x] 用户鉴权 -- [ ] 仓库黑名单 +- [x] 仓库黑名单 ### DEV - [x] Docker Pull 代理 -- [x] 仓库黑名单 diff --git a/VERSION b/VERSION index 867e524..589268e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.0 \ No newline at end of file +1.3.0 \ No newline at end of file diff --git a/auth/auth.go b/auth/auth.go index 2e3c680..4a8a7b0 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -12,7 +12,6 @@ var logw = logger.Logw func AuthHandler(c *gin.Context, cfg *config.Config) bool { // 如果身份验证未启用,直接返回 true if !cfg.Auth.Enabled { - logw("auth PASSED") return true } @@ -31,5 +30,6 @@ func AuthHandler(c *gin.Context, cfg *config.Config) bool { logw("auth FAILED: invalid auth_token: %s", authToken) } + logw("auth SUCCESS: %t", isValid) return isValid } diff --git a/docker/dockerfile/release/Dockerfile b/docker/dockerfile/release/Dockerfile index 8424d6b..8f944d9 100644 --- a/docker/dockerfile/release/Dockerfile +++ b/docker/dockerfile/release/Dockerfile @@ -13,6 +13,7 @@ RUN wget -O /data/caddy/Caddyfile https://raw.githubusercontent.com/${USER}/${RE RUN VERSION=$(curl -s https://raw.githubusercontent.com/${USER}/${REPO}/main/VERSION) && \ wget -O /data/${APPLICATION}/${APPLICATION} https://github.com/${USER}/${REPO}/releases/download/$VERSION/${APPLICATION} RUN wget -O /data/${APPLICATION}/config.yaml https://raw.githubusercontent.com/${USER}/${REPO}/main/config/config.yaml +RUN wget -O /data/${APPLICATION}/blacklist.json https://raw.githubusercontent.com/${USER}/${REPO}/main/config/blacklist.json RUN wget -O /usr/local/bin/init.sh https://raw.githubusercontent.com/${USER}/${REPO}/main/init.sh RUN chmod +x /data/${APPLICATION}/${APPLICATION} RUN chmod +x /usr/local/bin/init.sh diff --git a/proxy/proxy.go b/proxy/proxy.go index 2fb0930..a9fa6ed 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -32,7 +32,6 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/") re := regexp.MustCompile(`^(http:|https:)?/?/?(.*)`) matches := re.FindStringSubmatch(rawPath) - logw("Matches: %v", matches[2]) if len(matches) < 3 { logw("Invalid URL: %s", rawPath) @@ -59,8 +58,9 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { // 黑名单检查 blacklistpass := auth.CheckBlacklist(fullrepo) if blacklistpass { - c.AbortWithStatus(http.StatusForbidden) - logw("Blacklisted repo: %s", fullrepo) + errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", fullrepo) + c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) + logw(errMsg) return } @@ -80,7 +80,6 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { return } - logw("Request: %s %s", c.Request.Method, rawPath) logw("Matches: %v", matches) switch { @@ -99,7 +98,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { method := c.Request.Method - logw("%s Method: %s", u, method) + logw("%s %s", method, u) client := req.C()