This commit is contained in:
WJQSERVER 2024-10-19 16:05:18 +08:00
parent 47d062a1c4
commit c50f23c399
14 changed files with 78 additions and 70 deletions

View file

@ -1,5 +1,13 @@
# 更新日志
24w18d
---
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用
- CHANGE: 更新相关依赖库
- ADD: 增加CORS状态API
- CHANGE: 优化部分函数执行顺序
- CHANGE: 优化前端界面
24w18c
---
- PRE-RELEASE: 此版本是预发布版本,请勿在生产环境中使用

View file

@ -1 +1 @@
24w18c
24w18d

View file

@ -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" # 白名单文件路径
```

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

8
go.mod
View file

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

9
go.sum
View file

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

View file

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

View file

@ -10,7 +10,7 @@
<link rel="stylesheet" href="https://font.sec.miui.com/font/css?family=MiSans:400,700:MiSans">
<style>
body {
background-color: #f8f9fac5;
background-color: #d6d6d6c5;
font-family: 'Misans', Arial, sans-serif;
padding: 30px;
display: flex;
@ -30,15 +30,15 @@
h1 {
font-weight: bold;
margin-bottom: 75px;
margin-bottom: 85px;
}
.rounded-button {
border-radius: 6px;
transition: background-color 0.3s, transform 0.2s;
padding: 10px 30px;
background-color: #39c5bb;
color: white;
background-color: #555c5c;
color: rgb(255, 255, 255);
border: none;
margin-bottom: 10px;
}
@ -55,6 +55,7 @@
}
footer {
line-height: 1.1;
position: absolute;
bottom: 0;
left: 0;
@ -63,8 +64,8 @@
}
pre {
background: #2d2d2d;
color: #f8f8f2;
background: #012333;
color: #39c5bb;
padding: 20px 20px;
margin: 10px 0;
border-radius: 8px;
@ -80,15 +81,14 @@
left: 10px;
width: 12px;
height: 12px;
background: #ff5f56;
background: #bd3c35;
border-radius: 50%;
box-shadow: 20px 0 0 #ffbd2e, 40px 0 0 #27c93f;
box-shadow: 20px 0 0 #d69f27, 40px 0 0 #39c5bb;
}
code {
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 0.875em;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 1em;
}
.status-container {
@ -112,7 +112,7 @@
position: absolute;
top: 5px;
right: 10px;
background: rgba(118, 119, 121, 0.7);
background: rgba(0, 217, 224, 0.822);
color: white;
border: none;
padding: 5px 10px;
@ -135,23 +135,14 @@
#toast {
position: fixed;
top: 10%;
/* 垂直居中 */
left: 50%;
/* 水平居中 */
transform: translate(-50%, -50%);
/* 调整使其中心对齐 */
background-color: rgba(97, 97, 97, 0.7);
/* 半透明黑色背景 */
background-color: #39c5bcd2;
color: white;
/* 字体颜色 */
padding: 15px 20px;
/* 内边距 */
border-radius: 10px;
/* 圆角 */
font-size: 16px;
/* 字体大小 */
z-index: 1000;
/* 确保显示在其他元素上面 */
}
</style>
</head>
@ -160,12 +151,12 @@
<div class="container">
<h1>Github文件加速</h1>
<div class="form-group">
<input type="text" class="form-control" id="githubLinkInput" placeholder="键入Github链接">
<input type="text" class="form-control" id="githubLinkInput" placeholder="键入需要代理Github链接">
</div>
<button class="btn rounded-button" id="formatButton">获取文件链接</button>
<div class="code" id="outputBlock">
<button class="copy-button" id="copyButton">Copy</button>
<button class="copy-button" id="copyButton">复制</button>
<pre id="formattedLinkOutput"></pre>
</div>
<div class="tips">
@ -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 @@
<footer>
<p>
Copyright &copy; 2024 WJQSERVER-STUDIO
</p>
<p>
Copyright &copy; 2024 WJQSERVER-STUDIO<br>
GitHub仓库地址<a href="https://github.com/WJQSERVER-STUDIO/ghproxy">https://github.com/WJQSERVER-STUDIO/ghproxy</a> <br><a href="https://t.me/ghproxy_go">Telegram交流群</a>
</p>
<div id="visitor-info" style="text-align: center; margin-top: 15px;">

View file

@ -117,7 +117,6 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
method := c.Request.Method
// 记录 IP Method URL UA
logInfo("%s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"))
client := createHTTPClient(mode)
@ -150,7 +149,6 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
}
}
// createHTTPClient 创建并配置 HTTP 客户端
func createHTTPClient(mode string) *req.Client {
client := req.C()
switch mode {
@ -220,10 +218,11 @@ func HandleResponseSize(resp *req.Response, cfg *config.Config, c *gin.Context)
}
func CopyResponseHeaders(resp *req.Response, c *gin.Context, cfg *config.Config) {
removeHeaders(resp)
copyHeaders(resp, c)
removeHeaders(resp)
setCORSHeaders(c, cfg)
setDefaultHeaders(c)