From 2187514da7cf1794266cef9ebb948855ddc802f6 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Wed, 16 Oct 2024 12:48:02 +0800 Subject: [PATCH] 24w17b --- CHANGELOG.md | 7 +++++++ deploy/install-dev.sh | 7 ++++++- deploy/install.sh | 7 ++++++- main.go | 11 +++++++---- proxy/proxy.go | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be8344..baa3eab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 更新日志 +24w17b +--- +- PRE-RELEASE: 此版本是v1.5.2的预发布版本,请勿在生产环境中使用 +- FIX: 修正flag传入问题 +- CHANGE: 去除/路径重定向,改为返回403,并记录对应请求日志 +- CHANGE: 优化Proxy模块的日志记录,记录请求详细信息 + 24w17a --- - PRE-RELEASE: 此版本是v1.5.2的预发布版本,请勿在生产环境中使用 diff --git a/deploy/install-dev.sh b/deploy/install-dev.sh index cc719aa..fd87dbd 100644 --- a/deploy/install-dev.sh +++ b/deploy/install-dev.sh @@ -63,7 +63,12 @@ wget -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/r chmod +x /root/data/ghproxy/ghproxy # 下载配置文件 -wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml +if [ -f /root/data/ghproxy/config/config.toml ]; then + echo "配置文件已存在, 跳过下载" +else + wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/config.toml +fi + # 替换 port = 8080 sed -i "s/port = 8080/port = $PORT/g" /root/data/ghproxy/config/config.toml diff --git a/deploy/install.sh b/deploy/install.sh index b260752..9e28eb7 100644 --- a/deploy/install.sh +++ b/deploy/install.sh @@ -63,7 +63,12 @@ wget -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/r chmod +x /root/data/ghproxy/ghproxy # 下载配置文件 -wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml +if [ -f /root/data/ghproxy/config/config.toml ]; then + echo "配置文件已存在, 跳过下载" +else + wget -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/config.toml +fi + # 替换 port = 8080 sed -i "s/port = 8080/port = $PORT/g" /root/data/ghproxy/config/config.toml diff --git a/main.go b/main.go index 27b1d1e..90144dc 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,7 @@ func loadConfig() { if err != nil { log.Fatalf("Failed to load config: %v", err) } + fmt.Println("Config File Path: ", cfgfile) fmt.Printf("Loaded config: %v\n", cfg) } @@ -51,7 +52,8 @@ func setupLogger(cfg *config.Config) { if err != nil { log.Fatalf("Failed to initialize logger: %v", err) } - logInfo("Logger initialized") + logInfo("Config File Path: ", cfgfile) + logInfo("Loaded config: %v\n", cfg) logInfo("Init Completed") } @@ -71,8 +73,6 @@ func init() { setupLogger(cfg) Loadlist(cfg) - fmt.Println("Config File Path: ", cfgfile) - // 设置 Gin 模式 gin.SetMode(gin.ReleaseMode) @@ -83,7 +83,10 @@ func init() { // 定义路由 router.GET("/", func(c *gin.Context) { - c.Redirect(http.StatusMovedPermanently, "https://ghproxy0rtt.1888866.xyz/") + // 返回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/proxy/proxy.go b/proxy/proxy.go index 309ddb0..76e62b6 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -117,7 +117,8 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { method := c.Request.Method - logInfo("%s %s", method, u) + // 记录 IP Method URL UA + logInfo("%s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent")) client := createHTTPClient(mode)