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/412] 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/412] 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/412] 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/412] 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/412] 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/412] 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/412] 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 00d21139041e87406d8737c30e9ef07e687776e2 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Thu, 17 Oct 2024 00:04:29 +0800 Subject: [PATCH 008/412] hotfix --- caddyfile/dev/Caddyfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/caddyfile/dev/Caddyfile b/caddyfile/dev/Caddyfile index a7855b2..b0e2893 100644 --- a/caddyfile/dev/Caddyfile +++ b/caddyfile/dev/Caddyfile @@ -102,9 +102,9 @@ header_up X-Forwarded-For {http.request.header.X-Forwarded-For} header_up X-Forwarded-Proto {scheme} header_up Authorization {http.request.header.Authorization} - header { + } + header { www-authenticate 'Bearer realm="https://${host}/token",service="registry.docker.io"' - } } } From d6b8f2b8123e53641d557697d0bad3b865cfbf70 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Thu, 17 Oct 2024 09:57:14 +0800 Subject: [PATCH 009/412] hotfix --- caddyfile/dev/Caddyfile | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/caddyfile/dev/Caddyfile b/caddyfile/dev/Caddyfile index b0e2893..6b6eab1 100644 --- a/caddyfile/dev/Caddyfile +++ b/caddyfile/dev/Caddyfile @@ -97,20 +97,29 @@ route /v2* { reverse_proxy https://registry-1.docker.io { - header_up Host registry-1.docker.io + header_up Host {reverse_proxy.upstream.hostport} header_up X-Real-IP {remote} header_up X-Forwarded-For {http.request.header.X-Forwarded-For} header_up X-Forwarded-Proto {scheme} header_up Authorization {http.request.header.Authorization} - } - header { - www-authenticate 'Bearer realm="https://${host}/token",service="registry.docker.io"' + header_down WWW-Authenticate "https://auth.docker.io" "https://{host}" + header_down Location "https://production.cloudflare.docker.com" "https://{host}" } } route /token* { reverse_proxy https://auth.docker.io { - header_up Host auth.docker.io + header_up Host {reverse_proxy.upstream.hostport} + header_up X-Real-IP {remote} + header_up X-Forwarded-For {http.request.header.X-Forwarded-For} + header_up X-Forwarded-Proto {scheme} + header_up Authorization {http.request.header.Authorization} + } + } + + route /registry-v2* { + reverse_proxy https://production.cloudflare.docker.com { + header_up Host {reverse_proxy.upstream.hostport} header_up X-Real-IP {remote} header_up X-Forwarded-For {http.request.header.X-Forwarded-For} header_up X-Forwarded-Proto {scheme} From 52fdaf5f81f1b1899d65968fea56740ee6283b4a Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Thu, 17 Oct 2024 10:43:36 +0800 Subject: [PATCH 010/412] 24w18b --- CHANGELOG.md | 6 ++++++ DEV-VERSION | 2 +- caddyfile/dev/Caddyfile | 41 ++++------------------------------------- logger/logger.go | 18 ++++++++---------- proxy/proxy.go | 2 +- 5 files changed, 20 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f129a8..e6236a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +24w18b +--- +- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 +- CHANGE: 经团队考量,移除 Docker 代理功能,若造成了不便敬请谅解 +- CHANGE: 修改日志检查周期 + 24w18a --- - PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index e99003d..4730c0a 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w18a \ No newline at end of file +24w18b \ No newline at end of file diff --git a/caddyfile/dev/Caddyfile b/caddyfile/dev/Caddyfile index 6b6eab1..d4a1f98 100644 --- a/caddyfile/dev/Caddyfile +++ b/caddyfile/dev/Caddyfile @@ -88,44 +88,11 @@ file_server import cache 0s 24h } - handle_errors { - @redirects `{err.status_code} in [301, 302, 307]` - reverse_proxy @redirects { - header_up Location {http.response.header.Location} - } - } - route /v2* { - reverse_proxy https://registry-1.docker.io { - header_up Host {reverse_proxy.upstream.hostport} - header_up X-Real-IP {remote} - header_up X-Forwarded-For {http.request.header.X-Forwarded-For} - header_up X-Forwarded-Proto {scheme} - header_up Authorization {http.request.header.Authorization} - header_down WWW-Authenticate "https://auth.docker.io" "https://{host}" - header_down Location "https://production.cloudflare.docker.com" "https://{host}" - } - } - - route /token* { - reverse_proxy https://auth.docker.io { - header_up Host {reverse_proxy.upstream.hostport} - header_up X-Real-IP {remote} - header_up X-Forwarded-For {http.request.header.X-Forwarded-For} - header_up X-Forwarded-Proto {scheme} - header_up Authorization {http.request.header.Authorization} - } - } - - route /registry-v2* { - reverse_proxy https://production.cloudflare.docker.com { - header_up Host {reverse_proxy.upstream.hostport} - header_up X-Real-IP {remote} - header_up X-Forwarded-For {http.request.header.X-Forwarded-For} - header_up X-Forwarded-Proto {scheme} - header_up Authorization {http.request.header.Authorization} - } - } + route /api* { + rate_limit 15r/m 10000 429 + import cache 0s 6h + } } import /data/caddy/config.d/* diff --git a/logger/logger.go b/logger/logger.go index 09d262f..e5e5b75 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -18,11 +18,11 @@ var ( logger *log.Logger logChannel = make(chan string, 100) quitChannel = make(chan struct{}) - logFileMutex sync.Mutex // 保护 logFile 的互斥锁 + logFileMutex sync.Mutex logFilePath = "/data/ghproxy/log/ghproxy.log" ) -// Init 初始化日志记录器,接受日志文件路径作为参数 +// 初始化,接受日志文件路径作为参数 func Init(logFilePath_input string, maxLogsize int) error { logFileMutex.Lock() defer logFileMutex.Unlock() @@ -40,7 +40,6 @@ func Init(logFilePath_input string, maxLogsize int) error { return nil } -// logWorker 处理日志记录 func logWorker() { for { select { @@ -53,38 +52,37 @@ func logWorker() { } } -// Log 直接记录日志的函数 func Log(customMessage string) { logChannel <- customMessage } -// Logw 用于格式化日志记录 +// 格式化日志记录 func Logw(format string, args ...interface{}) { message := fmt.Sprintf(format, args...) Log(message) } -// 日志等级INFO +// INFO func LogInfo(format string, args ...interface{}) { message := fmt.Sprintf(format, args...) output := fmt.Sprintf("[INFO] %s", message) Log(output) } -// 日志等级WARNING +// WARNING func LogWarning(format string, args ...interface{}) { message := fmt.Sprintf(format, args...) output := fmt.Sprintf("[WARNING] %s", message) Log(output) } -// 日志等级ERROR +// ERROR func LogError(format string, args ...interface{}) { message := fmt.Sprintf(format, args...) Log(message) } -// Close 关闭日志文件 +// 关闭日志文件 func Close() { logFileMutex.Lock() defer logFileMutex.Unlock() @@ -100,7 +98,7 @@ func Close() { func monitorLogSize(logFilePath string, maxLogsize int) { var maxLogsizeBytes int64 = int64(maxLogsize) * 1024 * 1024 // 最大日志文件大小,单位为MB for { - time.Sleep(600 * time.Second) // 每10分钟检查一次 + time.Sleep(120 * time.Minute) // 每120分钟检查一次日志文件大小 logFileMutex.Lock() info, err := logFile.Stat() logFileMutex.Unlock() diff --git a/proxy/proxy.go b/proxy/proxy.go index 76e62b6..1bd1599 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -155,7 +155,7 @@ func createHTTPClient(mode string) *req.Client { client := req.C() switch mode { case "chrome": - client.SetUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"). + client.SetUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"). SetTLSFingerprintChrome(). ImpersonateChrome() case "git": From 57ba06e01e8f6a57cfaf2d855c3b5829a58a3edc Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Thu, 17 Oct 2024 17:45:29 +0800 Subject: [PATCH 011/412] 24w18c --- CHANGELOG.md | 6 ++++++ DEV-VERSION | 2 +- config/config.go | 12 ++++++------ config/config.toml | 15 +++++++++------ main.go | 8 ++++---- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6236a7..d6e496e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +24w18c +--- +- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 +- CHANGE: 修正配置命名,改为驼峰式命名 +- CHANGE: 修正函数命名 + 24w18b --- - PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index 4730c0a..8074ad4 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w18b \ No newline at end of file +24w18c \ No newline at end of file diff --git a/config/config.go b/config/config.go index e6d46a8..85fcc22 100644 --- a/config/config.go +++ b/config/config.go @@ -16,12 +16,12 @@ type Config struct { type ServerConfig struct { Port int `toml:"port"` Host string `toml:"host"` - SizeLimit int `toml:"sizelimit"` + SizeLimit int `toml:"sizeLimit"` } type LogConfig struct { - LogFilePath string `toml:"logfilepath"` - MaxLogSize int `toml:"maxlogsize"` + LogFilePath string `toml:"logFilePath"` + MaxLogSize int `toml:"maxLogSize"` } type CORSConfig struct { @@ -30,17 +30,17 @@ type CORSConfig struct { type AuthConfig struct { Enabled bool `toml:"enabled"` - AuthToken string `toml:"authtoken"` + AuthToken string `toml:"authToken"` } type BlacklistConfig struct { Enabled bool `toml:"enabled"` - BlacklistFile string `toml:"blacklistfile"` + BlacklistFile string `toml:"blacklistFile"` } type WhitelistConfig struct { Enabled bool `toml:"enabled"` - WhitelistFile string `toml:"whitelistfile"` + WhitelistFile string `toml:"whitelistFile"` } // LoadConfig 从 TOML 配置文件加载配置 diff --git a/config/config.toml b/config/config.toml index 9ad12bf..f71d806 100644 --- a/config/config.toml +++ b/config/config.toml @@ -1,23 +1,26 @@ [server] host = "127.0.0.1" port = 8080 -sizelimit = 131072000 # 125MB +sizeLimit = 131072000 # 125MB [log] -logfilepath = "/data/ghproxy/log/ghproxy.log" -maxlogsize = 5 # MB +logFilePath = "/data/ghproxy/log/ghproxy.log" +maxLogSize = 5 # MB [cors] enabled = true [auth] -authtoken = "test" +authToken = "test" enabled = false [blacklist] -blacklistfile = "/data/ghproxy/config/blacklist.json" +blacklistFile = "/data/ghproxy/config/blacklist.json" enabled = false [whitelist] enabled = false -whitelistfile = "/data/ghproxy/config/whitelist.json" +whitelistFile = "/data/ghproxy/config/whitelist.json" + +[downloadFolder] +enabled = false diff --git a/main.go b/main.go index 90144dc..2ba1fc3 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ var ( logError = logger.LogError ) -func ReadFlag() { +func readFlag() { flag.StringVar(&cfgfile, "cfg", configfile, "config file path") } @@ -57,7 +57,7 @@ func setupLogger(cfg *config.Config) { logInfo("Init Completed") } -func Loadlist(cfg *config.Config) { +func loadlist(cfg *config.Config) { auth.Init(cfg) } @@ -67,11 +67,11 @@ func setupApi(cfg *config.Config, router *gin.Engine) { } func init() { - ReadFlag() + readFlag() flag.Parse() loadConfig() setupLogger(cfg) - Loadlist(cfg) + loadlist(cfg) // 设置 Gin 模式 gin.SetMode(gin.ReleaseMode) From 47d062a1c421108678ec681b30bfac51fa8297cc Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Thu, 17 Oct 2024 18:01:15 +0800 Subject: [PATCH 012/412] hotfix --- caddyfile/dev/Caddyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caddyfile/dev/Caddyfile b/caddyfile/dev/Caddyfile index d4a1f98..0b2318e 100644 --- a/caddyfile/dev/Caddyfile +++ b/caddyfile/dev/Caddyfile @@ -90,7 +90,7 @@ } route /api* { - rate_limit 15r/m 10000 429 + rate_limit {remote.ip} 15r/m 10000 429 import cache 0s 6h } } From c50f23c39973b1a61ad6538d9b0ca48d8b1afa24 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sat, 19 Oct 2024 16:05:18 +0800 Subject: [PATCH 013/412] 24w18d --- CHANGELOG.md | 8 +++++++ DEV-VERSION | 2 +- README.md | 20 ++++++++-------- api/api.go | 15 ++++++++---- caddyfile/release/Caddyfile | 10 +++++--- config/config.toml | 5 +--- deploy/config.toml | 12 +++++----- deploy/install-dev.sh | 1 + deploy/install.sh | 1 + go.mod | 8 +++---- go.sum | 9 ++++++++ main.go | 6 ----- pages/index.html | 46 +++++++++++++++---------------------- proxy/proxy.go | 5 ++-- 14 files changed, 78 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6e496e..2ece206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # 更新日志 +24w18d +--- +- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 +- CHANGE: 更新相关依赖库 +- ADD: 增加CORS状态API +- CHANGE: 优化部分函数执行顺序 +- CHANGE: 优化前端界面 + 24w18c --- - PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index 8074ad4..fd72f28 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w18c \ No newline at end of file +24w18d \ No newline at end of file diff --git a/README.md b/README.md index cd65398..da48636 100644 --- a/README.md +++ b/README.md @@ -77,28 +77,28 @@ wget -O install.sh https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/ma ```toml [server] -host = "127.0.0.1" # 监听地址(小白请勿修改) -port = 8080 #监听端口(小白请勿修改) -sizelimit = 131072000 # 125MB +host = "127.0.0.1" # 监听地址 +port = 8080 # 监听端口 +sizeLimit = 131072000 # 125MB [log] -logfilepath = "/data/ghproxy/log/ghproxy.log" # 日志文件路径(小白请勿修改) -maxlogsize = 5 # MB +logFilePath = "/data/ghproxy/log/ghproxy.log" # 日志文件路径 +maxLogSize = 5 # MB 日志文件最大大小 [cors] -enabled = true # 是否开启CORS +enabled = true # 是否开启跨域 [auth] -authtoken = "test" # 鉴权Token -enabled = false # 是否开启鉴权 +authToken = "token" # 用户鉴权Token +enabled = false # 是否开启用户鉴权 [blacklist] -blacklistfile = "/data/ghproxy/config/blacklist.json" # 黑名单文件路径 +blacklistFile = "/data/ghproxy/config/blacklist.json" # 黑名单文件路径 enabled = false # 是否开启黑名单 [whitelist] enabled = false # 是否开启白名单 -whitelistfile = "/data/ghproxy/config/whitelist.json" # 白名单文件路径 +whitelistFile = "/data/ghproxy/config/whitelist.json" # 白名单文件路径 ``` diff --git a/api/api.go b/api/api.go index b30d80b..7b3c5f8 100644 --- a/api/api.go +++ b/api/api.go @@ -34,6 +34,9 @@ func InitHandleRouter(cfg *config.Config, router *gin.Engine) { apiRouter.GET("/blacklist/status", func(c *gin.Context) { BlackListStatusHandler(c, cfg) }) + apiRouter.GET("/cors/status", func(c *gin.Context) { + CorsStatusHandler(c, cfg) + }) apiRouter.GET("/healthcheck", func(c *gin.Context) { HealthcheckHandler(c) }) @@ -42,9 +45,7 @@ func InitHandleRouter(cfg *config.Config, router *gin.Engine) { } func SizeLimitHandler(cfg *config.Config, c *gin.Context) { - // 转换为MB sizeLimit := cfg.Server.SizeLimit / 1024 / 1024 - // 设置响应头 c.Writer.Header().Set("Content-Type", "application/json") json.NewEncoder(c.Writer).Encode(map[string]interface{}{ "MaxResponseBodySize": sizeLimit, @@ -52,7 +53,6 @@ func SizeLimitHandler(cfg *config.Config, c *gin.Context) { } func WhiteListStatusHandler(c *gin.Context, cfg *config.Config) { - // 设置响应头 c.Writer.Header().Set("Content-Type", "application/json") json.NewEncoder(c.Writer).Encode(map[string]interface{}{ "Whitelist": cfg.Whitelist.Enabled, @@ -60,15 +60,20 @@ func WhiteListStatusHandler(c *gin.Context, cfg *config.Config) { } func BlackListStatusHandler(c *gin.Context, cfg *config.Config) { - // 设置响应头 c.Writer.Header().Set("Content-Type", "application/json") json.NewEncoder(c.Writer).Encode(map[string]interface{}{ "Blacklist": cfg.Blacklist.Enabled, }) } +func CorsStatusHandler(c *gin.Context, cfg *config.Config) { + c.Writer.Header().Set("Content-Type", "application/json") + json.NewEncoder(c.Writer).Encode(map[string]interface{}{ + "Cors": cfg.CORS.Enabled, + }) +} + func HealthcheckHandler(c *gin.Context) { - // 设置响应头 c.Writer.Header().Set("Content-Type", "application/json") json.NewEncoder(c.Writer).Encode(map[string]interface{}{ "Status": "OK", diff --git a/caddyfile/release/Caddyfile b/caddyfile/release/Caddyfile index 959f1c3..4f3c5b6 100644 --- a/caddyfile/release/Caddyfile +++ b/caddyfile/release/Caddyfile @@ -75,9 +75,7 @@ import cache 0s 300s import error_page import encode - route /* { - rate_limit {remote.ip} 60r/m 10000 429 - } + import rate_limit 60 route / { root /data/www file_server @@ -87,6 +85,12 @@ root /data/www file_server import cache 0s 24h + + } + + route /api* { + rate_limit {remote.ip} 15r/m 10000 429 + import cache 0s 6h } } diff --git a/config/config.toml b/config/config.toml index f71d806..1047984 100644 --- a/config/config.toml +++ b/config/config.toml @@ -11,7 +11,7 @@ maxLogSize = 5 # MB enabled = true [auth] -authToken = "test" +authToken = "token" enabled = false [blacklist] @@ -21,6 +21,3 @@ enabled = false [whitelist] enabled = false whitelistFile = "/data/ghproxy/config/whitelist.json" - -[downloadFolder] -enabled = false diff --git a/deploy/config.toml b/deploy/config.toml index 2e2fd46..3b74289 100644 --- a/deploy/config.toml +++ b/deploy/config.toml @@ -1,23 +1,23 @@ [server] host = "127.0.0.1" port = 8080 -sizelimit = 131072000 # 125MB +sizeLimit = 131072000 # 125MB [log] -logfilepath = "/root/data/ghproxy/log/ghproxy.log" -maxlogsize = 5 # MB +logFilePath = "/root/data/ghproxy/log/ghproxy.log" +maxLogSize = 5 # MB [cors] enabled = true [auth] -authtoken = "test" +authToken = "token" enabled = false [blacklist] -blacklistfile = "/root/data/ghproxy/config/blacklist.json" +blacklistFile = "/root/data/ghproxy/config/blacklist.json" enabled = false [whitelist] enabled = false -whitelistfile = "/root/data/ghproxy/config/whitelist.json" +whitelistFile = "/root/data/ghproxy/config/whitelist.json" diff --git a/deploy/install-dev.sh b/deploy/install-dev.sh index 6e4b675..3197c8b 100644 --- a/deploy/install-dev.sh +++ b/deploy/install-dev.sh @@ -65,6 +65,7 @@ chmod +x /root/data/ghproxy/ghproxy # 下载配置文件 if [ -f /root/data/ghproxy/config/config.toml ]; then echo "配置文件已存在, 跳过下载" + echo "请检查配置文件是否正确,DEV版本升级时请注意配置文件兼容性" else wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml fi diff --git a/deploy/install.sh b/deploy/install.sh index 18ab6a6..25cd9b0 100644 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -65,6 +65,7 @@ chmod +x /root/data/ghproxy/ghproxy # 下载配置文件 if [ -f /root/data/ghproxy/config/config.toml ]; then echo "配置文件已存在, 跳过下载" + echo "请检查配置文件是否正确,跨大版本升级时请注意配置文件兼容性" else wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml fi diff --git a/go.mod b/go.mod index 980ef26..1e85761 100644 --- a/go.mod +++ b/go.mod @@ -15,14 +15,14 @@ require ( github.com/cloudflare/circl v1.5.0 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.5 // indirect + github.com/gabriel-vasile/mimetype v1.4.6 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.22.1 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/goccy/go-json v0.10.3 // indirect - github.com/google/pprof v0.0.0-20241009165004-a3522334989c // indirect + github.com/google/pprof v0.0.0-20241017200806-017d972448fc // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -35,11 +35,11 @@ require ( github.com/onsi/ginkgo/v2 v2.20.2 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/quic-go/qpack v0.5.1 // indirect - github.com/quic-go/quic-go v0.47.0 // indirect + github.com/quic-go/quic-go v0.48.0 // indirect github.com/refraction-networking/utls v1.6.7 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect - go.uber.org/mock v0.4.0 // indirect + go.uber.org/mock v0.5.0 // indirect golang.org/x/arch v0.11.0 // indirect golang.org/x/crypto v0.28.0 // indirect golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect diff --git a/go.sum b/go.sum index bf9a9e5..27c3095 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4= github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4= +github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc= +github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= @@ -32,6 +34,7 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= @@ -41,6 +44,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20241009165004-a3522334989c h1:NDovD0SMpBYXlE1zJmS1q55vWB/fUQBcPAqAboZSccA= github.com/google/pprof v0.0.0-20241009165004-a3522334989c/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/pprof v0.0.0-20241017200806-017d972448fc h1:NGyrhhFhwvRAZg02jnYVg3GBQy0qGBKmFQJwaPmpmxs= +github.com/google/pprof v0.0.0-20241017200806-017d972448fc/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -77,6 +82,8 @@ github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI= github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg= github.com/quic-go/quic-go v0.47.0 h1:yXs3v7r2bm1wmPTYNLKAAJTHMYkPEsfYJmTazXrCZ7Y= github.com/quic-go/quic-go v0.47.0/go.mod h1:3bCapYsJvXGZcipOHuu7plYtaV6tnF+z7wIFsU0WK9E= +github.com/quic-go/quic-go v0.48.0 h1:2TCyvBrMu1Z25rvIAlnp2dPT4lgh/uTqLqiXVpp5AeU= +github.com/quic-go/quic-go v0.48.0/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs= github.com/refraction-networking/utls v1.6.7 h1:zVJ7sP1dJx/WtVuITug3qYUq034cDq9B2MR1K67ULZM= github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5DDhzJfkV1tdqtawQIH0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -97,6 +104,8 @@ github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZ github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= +go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= +go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4= golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= diff --git a/main.go b/main.go index 2ba1fc3..0c6e62d 100644 --- a/main.go +++ b/main.go @@ -62,7 +62,6 @@ func loadlist(cfg *config.Config) { } func setupApi(cfg *config.Config, router *gin.Engine) { - // 注册 API 接口 api.InitHandleRouter(cfg, router) } @@ -73,19 +72,14 @@ func init() { setupLogger(cfg) loadlist(cfg) - // 设置 Gin 模式 gin.SetMode(gin.ReleaseMode) - // 初始化路由 router = gin.Default() setupApi(cfg, router) - // 定义路由 router.GET("/", func(c *gin.Context) { - // 返回403错误 c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.") - // 记录访问者IP UA METHOD LogWarning("Forbidden: IP:%s UA:%s METHOD:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method) }) diff --git a/pages/index.html b/pages/index.html index 7eae23f..f03fd4b 100644 --- a/pages/index.html +++ b/pages/index.html @@ -10,7 +10,7 @@ @@ -160,12 +151,12 @@

Github文件加速

- +
- +

         
@@ -197,7 +188,8 @@ } else if (githubLinkInput.value.startsWith("raw.githubusercontent.com/")) { formattedLink = "https://" + currentHost + "/" + githubLinkInput.value; } else if (!githubLinkInput.value.trim()) { - alert('请输入有效的GitHub链接'); + //alert('请输入有效的GitHub链接'); + showToast('请输入有效的GitHub链接'); } var formattedLinkOutput = document.getElementById('formattedLinkOutput'); formattedLinkOutput.textContent = formattedLink; @@ -283,9 +275,7 @@