From b83c2424160a6a0f03254c6f256f3d03f97e79b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E8=A6=8B=20=E7=81=AF=E8=8A=B1?= <172008506+satomitoka@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:06:08 +0800 Subject: [PATCH 001/405] Update go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index bbfa29e..93e23f4 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module ghproxy +module github.com/satomitoka/ghproxy go 1.23.2 From 1fd1e3bc2a0bb26111eb6ae3e0ccf4391030efa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E8=A6=8B=20=E7=81=AF=E8=8A=B1?= <172008506+satomitoka@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:07:44 +0800 Subject: [PATCH 002/405] Update main.go --- main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 38bc5c6..074c44c 100644 --- a/main.go +++ b/main.go @@ -6,10 +6,10 @@ import ( "log" "net/http" - "ghproxy/auth" - "ghproxy/config" - "ghproxy/logger" - "ghproxy/proxy" + "github.com/satomitoka/ghproxy/auth" + "github.com/satomitoka/ghproxy/config" + "github.com/satomitoka/ghproxy/logger" + "github.com/satomitoka/ghproxy/proxy" "github.com/gin-gonic/gin" ) From 00538f3d91b310916a7a51251caa9b89f36650d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E8=A6=8B=20=E7=81=AF=E8=8A=B1?= <172008506+satomitoka@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:08:02 +0800 Subject: [PATCH 003/405] Update auth.go --- auth/auth.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index 4a8a7b0..f92eab7 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -1,8 +1,8 @@ package auth import ( - "ghproxy/config" - "ghproxy/logger" + "github.com/satomitoka/ghproxy/config" + "github.com/satomitoka/ghproxy/logger" "github.com/gin-gonic/gin" ) From 4155b9cf4f6c2c71fe3a7a5060e094d9ccd62527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E8=A6=8B=20=E7=81=AF=E8=8A=B1?= <172008506+satomitoka@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:08:21 +0800 Subject: [PATCH 004/405] Update blacklist.go --- auth/blacklist.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/blacklist.go b/auth/blacklist.go index 830537f..88de8eb 100644 --- a/auth/blacklist.go +++ b/auth/blacklist.go @@ -2,7 +2,7 @@ package auth import ( "encoding/json" - "ghproxy/config" + "github.com/satomitoka/ghproxy/config" "os" ) From f4cb77a72ea6f7fa808212bc229ad67b0fa8217c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E8=A6=8B=20=E7=81=AF=E8=8A=B1?= <172008506+satomitoka@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:08:33 +0800 Subject: [PATCH 005/405] Update whitelist.go --- auth/whitelist.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/whitelist.go b/auth/whitelist.go index 326b3aa..1193bfe 100644 --- a/auth/whitelist.go +++ b/auth/whitelist.go @@ -2,7 +2,7 @@ package auth import ( "encoding/json" - "ghproxy/config" + "github.com/satomitoka/ghproxy/config" "os" ) From dd9a0c8adb25cf03908a4bdd07589689da1a623a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E8=A6=8B=20=E7=81=AF=E8=8A=B1?= <172008506+satomitoka@users.noreply.github.com> Date: Thu, 10 Oct 2024 20:09:16 +0800 Subject: [PATCH 006/405] Update proxy.go --- proxy/proxy.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index d830103..00e7be5 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -9,9 +9,9 @@ import ( "strconv" "strings" - "ghproxy/auth" - "ghproxy/config" - "ghproxy/logger" + "github.com/satomitoka/ghproxy/auth" + "github.com/satomitoka/ghproxy/config" + "github.com/satomitoka/ghproxy/logger" "github.com/gin-gonic/gin" "github.com/imroc/req/v3" From 1b5b34d2656eee7a699c14445d5402255e109bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8C=E8=A6=8B=20=E7=81=AF=E8=8A=B1?= <172008506+satomitoka@users.noreply.github.com> Date: Fri, 11 Oct 2024 00:14:39 +0800 Subject: [PATCH 007/405] Update build-dev.yml --- .github/workflows/build-dev.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index 8f8de42..0dac3d8 100644 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -17,7 +17,6 @@ jobs: goarch: [amd64, arm64] env: OUTPUT_BINARY: ghproxy - #OUTPUT_ARCHIVE: ghproxy.tar.gz GO_VERSION: 1.23.2 steps: @@ -35,7 +34,7 @@ jobs: go-version: ${{ env.GO_VERSION }} - name: Build run: | - CGO_ENABLED=0 go build -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go + CGO_ENABLED=0 go build -ldflags="-s -w" -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go - name: Package run: | tar -czvf ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}}.tar.gz ./${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} From aee81ba4fdf301ec99bff50aac85e640e1313604 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sun, 20 Oct 2024 17:48:31 +0800 Subject: [PATCH 008/405] 24w18e --- config/config.go | 4 ++-- config/config.toml | 2 +- main.go | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index 59e6b1d..4d50310 100644 --- a/config/config.go +++ b/config/config.go @@ -6,7 +6,7 @@ import ( type Config struct { Server ServerConfig - Page PageConfig + Pages PagesConfig Log LogConfig CORS CORSConfig Auth AuthConfig @@ -20,7 +20,7 @@ type ServerConfig struct { SizeLimit int `toml:"sizeLimit"` } -type PageConfig struct { +type PagesConfig struct { Enabled bool `toml:"enabled"` StaticDir string `toml:"staticDir"` } diff --git a/config/config.toml b/config/config.toml index 974c8d4..f31dd3d 100644 --- a/config/config.toml +++ b/config/config.toml @@ -3,7 +3,7 @@ host = "127.0.0.1" port = 8080 sizeLimit = 131072000 # 125MB -[page] +[pages] enabled = true staticDir = "/data/www" diff --git a/main.go b/main.go index 9c4a8ca..bb6e278 100644 --- a/main.go +++ b/main.go @@ -79,14 +79,14 @@ func init() { setupApi(cfg, router) - if cfg.Page.Enabled { - indexPagePath := fmt.Sprintf("%s/index.html", cfg.Page.StaticDir) - faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Page.StaticDir) + if cfg.Pages.Enabled { + indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir) + faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir) // 静态index页 router.StaticFile("/", indexPagePath) // 静态favicon.ico router.StaticFile("/favicon.ico", faviconPath) - } else if !cfg.Page.Enabled { + } else if !cfg.Pages.Enabled { router.GET("/", func(c *gin.Context) { c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.") LogWarning("Forbidden: IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) From 91b7cfe533de2df18529967824e70ddb3827ea1a Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sun, 20 Oct 2024 18:16:30 +0800 Subject: [PATCH 009/405] 24w18e --- CHANGELOG.md | 1 + api/api.go | 2 +- auth/auth.go | 6 +++--- main.go | 10 +++++++--- proxy/proxy.go | 22 +++++++++++----------- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b06b04e..6cc6ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - ADD: 尝试在核心程序内加入静态页面支持 - CHANGE: 优化日志记录 - CHANGE: 去除部分无用/重复配置 +- CHANGE: 规范化部分函数命名 24w18d --- diff --git a/api/api.go b/api/api.go index 7b3c5f8..7dd56a0 100644 --- a/api/api.go +++ b/api/api.go @@ -17,7 +17,7 @@ var ( var ( logw = logger.Logw logInfo = logger.LogInfo - LogWarning = logger.LogWarning + logWarning = logger.LogWarning logError = logger.LogError ) diff --git a/auth/auth.go b/auth/auth.go index bdb74eb..4f5a80d 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -11,7 +11,7 @@ import ( var ( logw = logger.Logw logInfo = logger.LogInfo - LogWarning = logger.LogWarning + logWarning = logger.LogWarning logError = logger.LogError ) @@ -38,13 +38,13 @@ func AuthHandler(c *gin.Context, cfg *config.Config) bool { // 验证 token if authToken == "" { - LogWarning("auth FAILED: no auth_token provided") + logWarning("auth FAILED: no auth_token provided") return false } isValid := authToken == cfg.Auth.AuthToken if !isValid { - LogWarning("auth FAILED: invalid auth_token: %s", authToken) + logWarning("auth FAILED: invalid auth_token: %s", authToken) } logInfo("auth SUCCESS: %t", isValid) diff --git a/main.go b/main.go index bb6e278..47f63c1 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ var ( var ( logw = logger.Logw logInfo = logger.LogInfo - LogWarning = logger.LogWarning + logWarning = logger.LogWarning logError = logger.LogError ) @@ -83,13 +83,17 @@ func init() { indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir) faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir) // 静态index页 - router.StaticFile("/", indexPagePath) + //router.StaticFile("/", indexPagePath) + router.GET("/", func(c *gin.Context) { + c.File(indexPagePath) + logInfo("IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) + }) // 静态favicon.ico router.StaticFile("/favicon.ico", faviconPath) } else if !cfg.Pages.Enabled { router.GET("/", func(c *gin.Context) { c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.") - LogWarning("Forbidden: IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) + logWarning("Forbidden: IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) }) } diff --git a/proxy/proxy.go b/proxy/proxy.go index 9593dbd..4479af3 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -21,7 +21,7 @@ import ( var ( logw = logger.Logw logInfo = logger.LogInfo - LogWarning = logger.LogWarning + logWarning = logger.LogWarning logError = logger.LogError ) @@ -40,7 +40,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { matches := re.FindStringSubmatch(rawPath) if len(matches) < 3 { - LogWarning("Invalid URL: %s", rawPath) + logWarning("Invalid URL: %s", rawPath) c.String(http.StatusForbidden, "Invalid URL.") return } @@ -51,14 +51,14 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { pathmatches := regexp.MustCompile(`^([^/]+)/([^/]+)/([^/]+)/.*`) pathParts := pathmatches.FindStringSubmatch(matches[2]) if len(pathParts) < 4 { - LogWarning("Invalid path: %s", rawPath) + logWarning("Invalid path: %s", rawPath) c.String(http.StatusForbidden, "Invalid path; expected username/repo.") return } username := pathParts[2] repo := pathParts[3] - LogWarning("Blacklist Check > Username: %s, Repo: %s", username, repo) + logWarning("Blacklist Check > Username: %s, Repo: %s", username, repo) fullrepo := fmt.Sprintf("%s/%s", username, repo) // 白名单检查 @@ -67,7 +67,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { if !whitelistpass { errMsg := fmt.Sprintf("Whitelist Blocked repo: %s", fullrepo) c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) - LogWarning(errMsg) + logWarning(errMsg) return } } @@ -78,7 +78,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { if blacklistpass { errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", fullrepo) c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) - LogWarning(errMsg) + logWarning(errMsg) return } } @@ -95,7 +95,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { if !auth.AuthHandler(c, cfg) { c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"}) - LogWarning("Unauthorized request: %s", rawPath) + logWarning("Unauthorized request: %s", rawPath) return } @@ -139,7 +139,7 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { defer resp.Body.Close() if err := HandleResponseSize(resp, cfg, c); err != nil { - LogWarning("Error handling response size: %v", err) + logWarning("Error handling response size: %v", err) return } @@ -211,7 +211,7 @@ func HandleResponseSize(resp *req.Response, cfg *config.Config, c *gin.Context) if err == nil && size > cfg.Server.SizeLimit { finalURL := resp.Request.URL.String() c.Redirect(http.StatusMovedPermanently, finalURL) - LogWarning("Size limit exceeded: %s, Size: %d", finalURL, size) + logWarning("Size limit exceeded: %s, Size: %d", finalURL, size) return fmt.Errorf("size limit exceeded: %d", size) } } @@ -268,7 +268,7 @@ func setDefaultHeaders(c *gin.Context) { func HandleError(c *gin.Context, message string) { c.String(http.StatusInternalServerError, fmt.Sprintf("server error %v", message)) - LogWarning(message) + logWarning(message) } func CheckURL(u string) []string { @@ -279,6 +279,6 @@ func CheckURL(u string) []string { } } errMsg := fmt.Sprintf("Invalid URL: %s", u) - LogWarning(errMsg) + logWarning(errMsg) return nil } From ddd12729a41cc17951e35bb99229ab0b2a623da7 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sun, 20 Oct 2024 18:56:37 +0800 Subject: [PATCH 010/405] 24w18f --- CHANGELOG.md | 6 ++++++ DEV-VERSION | 2 +- README.md | 2 +- deploy/config.toml | 2 +- deploy/install-dev.sh | 15 ++++++++------- pages/index.html | 10 +++++----- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc6ea8..0e17a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +24w18f +--- +- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 +- CHANGE: 修正前端页面的部分样式问题 +- FIX: 修正部分问题 + 24w18e --- - PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index 164704b..430b82d 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w18e \ No newline at end of file +24w18f \ No newline at end of file diff --git a/README.md b/README.md index d7fe435..f15824d 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ host = "127.0.0.1" # 监听地址 port = 8080 # 监听端口 sizeLimit = 131072000 # 125MB -[page] +[pages] enabled = true # 是否开启内置静态页面 staticPath = "/data/www" # 静态页面文件路径 diff --git a/deploy/config.toml b/deploy/config.toml index 11a64b6..4ffbd54 100644 --- a/deploy/config.toml +++ b/deploy/config.toml @@ -3,7 +3,7 @@ host = "127.0.0.1" port = 8080 sizeLimit = 131072000 # 125MB -[page] +[pages] enabled = true staticDir = "/root/data/ghproxy/pages" diff --git a/deploy/install-dev.sh b/deploy/install-dev.sh index 15b68d7..50c18a8 100644 --- a/deploy/install-dev.sh +++ b/deploy/install-dev.sh @@ -57,30 +57,31 @@ mkdir -p /root/data/ghproxy/pages # 获取最新版本号 VERSION=$(curl -s https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION) -wget -O /root/data/ghproxy/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION +wget -q -O /root/data/ghproxy/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION # 下载ghproxy -wget -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH +wget -q -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH chmod +x /root/data/ghproxy/ghproxy # 下载pages -wget -O /root/data/ghproxy/pages/index.html https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/index.html -wget -O /root/data/ghproxy/pages/favicon.ico https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/favicon.ico +wget -q -O /root/data/ghproxy/pages/index.html https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/index.html +wget -q -O /root/data/ghproxy/pages/favicon.ico https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/favicon.ico # 下载配置文件 if [ -f /root/data/ghproxy/config/config.toml ]; then echo "配置文件已存在, 跳过下载" - echo "请检查配置文件是否正确,DEV版本升级时请注意配置文件兼容性" + echo "[WARNING] 请检查配置文件是否正确,DEV版本升级时请注意配置文件兼容性" + sleep 2 else - wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml + wget -q -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml fi # 替换 port = 8080 sed -i "s/port = 8080/port = $PORT/g" /root/data/ghproxy/config/config.toml # 下载systemd服务文件 -wget -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service +wget -q -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service # 启动ghproxy systemctl daemon-reload diff --git a/pages/index.html b/pages/index.html index f03fd4b..3b69dd3 100644 --- a/pages/index.html +++ b/pages/index.html @@ -10,7 +10,7 @@ @@ -160,7 +244,9 @@

         
         
-

GitHub链接带不带协议头均可,支持release、archive以及文件,转换后链接均可使用。

+
+

GitHub链接带不带协议头均可,支持release、archive以及文件,转换后链接均可使用。

+

文件大小限制: ...

白名单状态: ...

@@ -279,7 +365,7 @@