mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-03 08:11:11 +08:00
1.3.0
This commit is contained in:
parent
61e741c9b3
commit
5ac08bba56
6 changed files with 36 additions and 12 deletions
10
CHANGELOG.md
10
CHANGELOG.md
|
|
@ -1,5 +1,15 @@
|
||||||
# 更新日志
|
# 更新日志
|
||||||
|
|
||||||
|
v1.3.0
|
||||||
|
---
|
||||||
|
- CHANGE: 优化代码结构,提升性能
|
||||||
|
- CHANGE: 优化黑名单功能,提升稳定性
|
||||||
|
- CHANGE: 剃刀计划,减少调试用日志输出
|
||||||
|
- ADD: 新增auth子模块blacklist.go,支持黑名单功能
|
||||||
|
- ADD: 新增blacklist.json文件,用于配置黑名单
|
||||||
|
- CHANGE: config.yaml文件格式修改,使其具备更好的可读性
|
||||||
|
- WARNING: 此版本为大版本更新,配置文件重构,此版本不再向前兼容,请注意备份文件并重新部署
|
||||||
|
|
||||||
24w09b
|
24w09b
|
||||||
---
|
---
|
||||||
- CHANGE: 优化代码结构,提升性能
|
- CHANGE: 优化代码结构,提升性能
|
||||||
|
|
|
||||||
24
README.md
24
README.md
|
|
@ -16,6 +16,7 @@
|
||||||
- 支持Docker部署
|
- 支持Docker部署
|
||||||
- 支持速率限制
|
- 支持速率限制
|
||||||
- 支持用户鉴权
|
- 支持用户鉴权
|
||||||
|
- 支持自定义黑名单
|
||||||
- 符合[RFC 7234](https://httpwg.org/specs/rfc7234.html)的HTTP Cache
|
- 符合[RFC 7234](https://httpwg.org/specs/rfc7234.html)的HTTP Cache
|
||||||
- 使用Caddy作为Web Server
|
- 使用Caddy作为Web Server
|
||||||
- 基于[WJQSERVER-STUDIO/golang-temp](https://github.com/WJQSERVER-STUDIO/golang-temp)模板构建,具有标准化的日志记录与构建流程
|
- 基于[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作为外部配置,默认配置如下
|
本项目采用config.yaml作为外部配置,默认配置如下
|
||||||
使用Docker部署时,慎重修改config.yaml,以免造成不必要的麻烦
|
使用Docker部署时,慎重修改config.yaml,以免造成不必要的麻烦
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
# 核心配置
|
# 核心配置
|
||||||
server:
|
server:
|
||||||
port: 8080 # 监听端口(小白请勿修改)
|
port: 8080 # 监听端口(小白请勿修改)
|
||||||
|
|
@ -86,13 +87,27 @@ auth:
|
||||||
# 黑名单配置
|
# 黑名单配置
|
||||||
blacklist:
|
blacklist:
|
||||||
enabled: true
|
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反代配置
|
### Caddy反代配置
|
||||||
|
|
||||||
```
|
```Caddyfile
|
||||||
example.com {
|
example.com {
|
||||||
reverse_proxy {
|
reverse_proxy {
|
||||||
to 127.0.0.1:7210
|
to 127.0.0.1:7210
|
||||||
|
|
@ -112,9 +127,8 @@ example.com {
|
||||||
- [x] 允许更多参数通过config结构传入
|
- [x] 允许更多参数通过config结构传入
|
||||||
- [x] 改进程序效率
|
- [x] 改进程序效率
|
||||||
- [x] 用户鉴权
|
- [x] 用户鉴权
|
||||||
- [ ] 仓库黑名单
|
- [x] 仓库黑名单
|
||||||
|
|
||||||
### DEV
|
### DEV
|
||||||
|
|
||||||
- [x] Docker Pull 代理
|
- [x] Docker Pull 代理
|
||||||
- [x] 仓库黑名单
|
|
||||||
|
|
|
||||||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
||||||
1.2.0
|
1.3.0
|
||||||
|
|
@ -12,7 +12,6 @@ var logw = logger.Logw
|
||||||
func AuthHandler(c *gin.Context, cfg *config.Config) bool {
|
func AuthHandler(c *gin.Context, cfg *config.Config) bool {
|
||||||
// 如果身份验证未启用,直接返回 true
|
// 如果身份验证未启用,直接返回 true
|
||||||
if !cfg.Auth.Enabled {
|
if !cfg.Auth.Enabled {
|
||||||
logw("auth PASSED")
|
|
||||||
return true
|
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 FAILED: invalid auth_token: %s", authToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logw("auth SUCCESS: %t", isValid)
|
||||||
return isValid
|
return isValid
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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) && \
|
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}
|
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}/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 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 /data/${APPLICATION}/${APPLICATION}
|
||||||
RUN chmod +x /usr/local/bin/init.sh
|
RUN chmod +x /usr/local/bin/init.sh
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||||
rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/")
|
rawPath := strings.TrimPrefix(c.Request.URL.RequestURI(), "/")
|
||||||
re := regexp.MustCompile(`^(http:|https:)?/?/?(.*)`)
|
re := regexp.MustCompile(`^(http:|https:)?/?/?(.*)`)
|
||||||
matches := re.FindStringSubmatch(rawPath)
|
matches := re.FindStringSubmatch(rawPath)
|
||||||
logw("Matches: %v", matches[2])
|
|
||||||
|
|
||||||
if len(matches) < 3 {
|
if len(matches) < 3 {
|
||||||
logw("Invalid URL: %s", rawPath)
|
logw("Invalid URL: %s", rawPath)
|
||||||
|
|
@ -59,8 +58,9 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||||
// 黑名单检查
|
// 黑名单检查
|
||||||
blacklistpass := auth.CheckBlacklist(fullrepo)
|
blacklistpass := auth.CheckBlacklist(fullrepo)
|
||||||
if blacklistpass {
|
if blacklistpass {
|
||||||
c.AbortWithStatus(http.StatusForbidden)
|
errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", fullrepo)
|
||||||
logw("Blacklisted repo: %s", fullrepo)
|
c.JSON(http.StatusForbidden, gin.H{"error": errMsg})
|
||||||
|
logw(errMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,7 +80,6 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logw("Request: %s %s", c.Request.Method, rawPath)
|
|
||||||
logw("Matches: %v", matches)
|
logw("Matches: %v", matches)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|
@ -99,7 +98,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||||
|
|
||||||
func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
|
func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
|
||||||
method := c.Request.Method
|
method := c.Request.Method
|
||||||
logw("%s Method: %s", u, method)
|
logw("%s %s", method, u)
|
||||||
|
|
||||||
client := req.C()
|
client := req.C()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue