Compare commits

...

2 Commits

Author SHA1 Message Date
WJQSERVER
822b6c8cea 1.3.1 2024-10-06 19:19:54 +08:00
WJQSERVER
5ac08bba56 1.3.0 2024-10-06 04:32:55 +08:00
11 changed files with 55 additions and 26 deletions

View File

@@ -1,5 +1,27 @@
# 更新日志
v1.3.1
---
- CHANGE: 优化代码结构,提升性能
- CHANGE: 剃刀计划,减少多余日志输出
- CHANGE: 调整缓存参数
24w10a
---
- CHANGE: 优化代码结构,提升性能
- CHANGE: 剃刀计划,减少多余日志输出
- CHANGE: 调整缓存参数
v1.3.0
---
- CHANGE: 优化代码结构,提升性能
- CHANGE: 优化黑名单功能,提升稳定性
- CHANGE: 剃刀计划,减少多余日志输出
- ADD 新增auth子模块blacklist.go,支持黑名单功能
- ADD: 新增blacklist.json文件,用于配置黑名单
- CHANGE: config.yaml文件格式修改,使其具备更好的可读性
- WARNING: 此版本为大版本更新,配置文件重构,此版本不再向前兼容,请注意备份文件并重新部署
24w09b
---
- CHANGE: 优化代码结构,提升性能

View File

@@ -1 +1 @@
24w09b
24w10a

View File

@@ -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 # 监听端口(小白请勿修改)
@@ -72,7 +73,7 @@ server:
# 日志配置
logger:
logfilepath: "/data/ghproxy/log/ghproxy.log" # 日志文件路径(小白请勿修改)
maxlogsize: 25 # MB
maxlogsize: 5 # MB
# CORS 配置
cors:
@@ -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] 仓库黑名单

View File

@@ -1 +1 @@
1.2.0
1.3.1

View File

@@ -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
}

View File

@@ -41,6 +41,5 @@ func forRangeCheck(blist []string, fullrepo string) bool {
return true
}
}
logw("%s not in blacklist", fullrepo)
return false
}

View File

@@ -72,7 +72,7 @@
import header_realip
}
import log ghproxy
import cache 0s 600s
import cache 0s 300s
import error_page
import encode
import rate_limit 60
@@ -84,7 +84,7 @@
route /favicon.ico {
root /data/www
file_server
import cache 60s 24h
import cache 0s 24h
}
handle_errors {
@redirects `{err.status_code} in [301, 302, 307]`

View File

@@ -60,12 +60,6 @@
header_up X-Forwarded-Proto {http.request.header.CF-Visitor}
}
(buffer) {
flush_interval 2000s
buffer_responses
max_buffer_size 256k
}
(rate_limit) {
route /* {
rate_limit {remote.ip} {args[0]}r/m 10000 429
@@ -78,7 +72,7 @@
import header_realip
}
import log ghproxy
import cache 0s 600s
import cache 0s 300s
import error_page
import encode
route /* {
@@ -92,7 +86,7 @@
route /favicon.ico {
root /data/www
file_server
import cache 60s 24h
import cache 0s 24h
}
}

View File

@@ -7,7 +7,7 @@ server:
# Logging Configuration
logger:
logfilepath: "/data/ghproxy/log/ghproxy.log"
maxlogsize: 25 # MB
maxlogsize: 5 # MB
# CORS Configuration
cors:

View File

@@ -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

View File

@@ -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()