Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb45ab8798 | ||
|
|
2b7e949658 | ||
|
|
fe652821bd | ||
|
|
92b3e19954 | ||
|
|
19f753a515 | ||
|
|
157cbf9d3a | ||
|
|
f80782b803 | ||
|
|
b1c8658a1c |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,5 +1,28 @@
|
||||
# 更新日志
|
||||
|
||||
v1.6.2
|
||||
---
|
||||
- CHANGE: 优化前端界面,优化部分样式
|
||||
- ADD: 前端加入黑夜模式
|
||||
- CHANGE: 优化移动端适配
|
||||
- CHANGE: 优化一键部署脚本,使其更加易用,并增加更多的功能(已于早些时候hotfix)
|
||||
- CHANGE: 优化部分代码结构,提升性能
|
||||
- CHANGE: 优化日志记录,对各个部分的日志记录进行统一格式,并对部分重复日志进行合并
|
||||
|
||||
24w20b
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.2的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 优化前端界面,优化部分样式
|
||||
- ADD: 前端加入黑夜模式
|
||||
- CHANGE: 优化移动端适配
|
||||
|
||||
24w20a
|
||||
---
|
||||
- PRE-RELEASE: 此版本是v1.6.2的预发布版本,请勿在生产环境中使用
|
||||
- CHANGE: 大幅修改日志记录,对各个部分的日志记录进行统一格式,并对部分重复日志进行合并
|
||||
- CHANGE: 大幅优化一键部署脚本,使其更加易用,并增加更多的功能(已于早些时候hotfix)
|
||||
- CHANGE: 优化部分代码结构,提升性能
|
||||
|
||||
v1.6.1
|
||||
---
|
||||
- CHANGE: 根据社区建议,将`sizeLimit`由过去的以`byte`为单位,改为以`MB`为单位,以便于直观理解
|
||||
|
||||
@@ -1 +1 @@
|
||||
24w19d
|
||||
24w20b
|
||||
23
README.md
23
README.md
@@ -1,4 +1,4 @@
|
||||
# GhProxy
|
||||
# GHProxy
|
||||
|
||||

|
||||
[](https://goreportcard.com/report/github.com/WJQSERVER-STUDIO/ghproxy)
|
||||
@@ -9,6 +9,8 @@
|
||||
|
||||
[TG讨论群组](https://t.me/ghproxy_go)
|
||||
|
||||
[版本更新介绍](https://blog.wjqserver.com/categories/my-program/)
|
||||
|
||||
## 项目说明
|
||||
|
||||
### 项目特点
|
||||
@@ -26,11 +28,10 @@
|
||||
### 项目开发过程
|
||||
|
||||
**本项目是[WJQSERVER-STUDIO/ghproxy-go](https://github.com/WJQSERVER-STUDIO/ghproxy-go)的重构版本,实现了原项目原定功能的同时,进一步优化了性能**
|
||||
本项目源于[WJQSERVER-STUDIO/ghproxy-go](https://github.com/WJQSERVER-STUDIO/ghproxy-go)与[WJQSERVER/ghproxy-go-0RTT](https://github.com/WJQSERVER/ghproxy-go-0RTT)两个项目,前者带来了实现框架与资源,后者带来了解决Git clone问题的办法,使得本项目从net/http标准库切换至Gin框架,已解决此困扰已久的问题,在此基础上,本项目进一步优化了性能,并添加了用户鉴权功能,使得部署更加安全可靠。
|
||||
关于此项目的详细开发过程,请参看Commit记录与[CHANGELOG.md](https://github.com/WJQSERVER-STUDIO/ghproxy/blob/main/CHANGELOG.md)
|
||||
|
||||
- V1.0.0 迁移至本仓库,并再次重构内容实现
|
||||
- v0.2.0 重构项目实现,Git clone的实现完全自主化
|
||||
- v0.2.0 重构项目实现
|
||||
|
||||
### LICENSE
|
||||
|
||||
@@ -56,7 +57,7 @@ git clone https://ghproxy.1888866.xyz/github.com/WJQSERVER-STUDIO/ghproxy.git
|
||||
docker run -p 7210:80 -v ./ghproxy/log/run:/data/ghproxy/log -v ./ghproxy/log/caddy:/data/caddy/log -v ./ghproxy/config:/data/ghproxy/config --restart always wjqserver/ghproxy
|
||||
```
|
||||
|
||||
- Docker-Compose
|
||||
- Docker-Compose (建议使用)
|
||||
|
||||
参看[docker-compose.yml](https://github.com/WJQSERVER-STUDIO/ghproxy/blob/main/docker/compose/docker-compose.yml)
|
||||
|
||||
@@ -153,13 +154,9 @@ example.com {
|
||||
|
||||

|
||||
|
||||
## TODO & DEV
|
||||
结语
|
||||
---
|
||||
|
||||
### TODO
|
||||
- [x] 用户鉴权
|
||||
- [x] 仓库黑名单
|
||||
- [x] 仓库白名单
|
||||
|
||||
### DEV
|
||||
|
||||
- [x] Docker Pull 代理
|
||||
本项目基于Go语言实现的GHProxy,使用Gin框架与req库
|
||||
Docker镜像基于[WJQSERVER-STUDIO/caddy](https://github.com/WJQSERVER-STUDIO/caddy)
|
||||
本项目使用WSL LICENSE Version1.2 (WJQSERVER STUDIO LICENSE Version1.2) 授权协议,请遵守相关条例。
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
| 版本 | 是否支持 |
|
||||
| --- | --- |
|
||||
| v1.x.x | :white_check_mark: |
|
||||
| **w**a/b/c... | :warning: 此为PRE-RELEASE版本,用于开发与测试,可能存在未知的问题 |
|
||||
| 24w*a/b/c... | :warning: 此为PRE-RELEASE版本,用于开发与测试,可能存在未知的问题 |
|
||||
| v0.x.x | :x: 这些版本不再受支持 |
|
||||
|
||||
### 用户须知
|
||||
|
||||
@@ -46,6 +46,7 @@ func InitHandleRouter(cfg *config.Config, router *gin.Engine) {
|
||||
|
||||
func SizeLimitHandler(cfg *config.Config, c *gin.Context) {
|
||||
sizeLimit := cfg.Server.SizeLimit
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"MaxResponseBodySize": sizeLimit,
|
||||
@@ -53,6 +54,7 @@ func SizeLimitHandler(cfg *config.Config, c *gin.Context) {
|
||||
}
|
||||
|
||||
func WhiteListStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Whitelist": cfg.Whitelist.Enabled,
|
||||
@@ -60,6 +62,7 @@ func WhiteListStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
}
|
||||
|
||||
func BlackListStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Blacklist": cfg.Blacklist.Enabled,
|
||||
@@ -67,6 +70,7 @@ func BlackListStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
}
|
||||
|
||||
func CorsStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Cors": cfg.CORS.Enabled,
|
||||
@@ -74,6 +78,7 @@ func CorsStatusHandler(c *gin.Context, cfg *config.Config) {
|
||||
}
|
||||
|
||||
func HealthcheckHandler(c *gin.Context) {
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto)
|
||||
c.Writer.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(c.Writer).Encode(map[string]interface{}{
|
||||
"Status": "OK",
|
||||
|
||||
19
auth/auth.go
19
auth/auth.go
@@ -1,6 +1,7 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ghproxy/config"
|
||||
"ghproxy/logger"
|
||||
|
||||
@@ -26,27 +27,29 @@ func Init(cfg *config.Config) {
|
||||
logInfo("Auth Init")
|
||||
}
|
||||
|
||||
func AuthHandler(c *gin.Context, cfg *config.Config) bool {
|
||||
func AuthHandler(c *gin.Context, cfg *config.Config) (isValid bool, err string) {
|
||||
// 如果身份验证未启用,直接返回 true
|
||||
if !cfg.Auth.Enabled {
|
||||
return true
|
||||
return true, ""
|
||||
}
|
||||
|
||||
// 获取 auth_token 参数
|
||||
authToken := c.Query("auth_token")
|
||||
logInfo("auth_token received: %s", authToken)
|
||||
// IP METHOD URL USERAGENT PROTO TOKEN
|
||||
logInfo("%s %s %s %s %s AUTH_TOKEN: %s", c.ClientIP(), c.Request.Method, c.Request.URL.Path, c.Request.UserAgent(), c.Request.Proto, authToken)
|
||||
|
||||
// 验证 token
|
||||
if authToken == "" {
|
||||
logWarning("auth FAILED: no auth_token provided")
|
||||
return false
|
||||
err := "Auth token == nil"
|
||||
return false, err
|
||||
}
|
||||
|
||||
isValid := authToken == cfg.Auth.AuthToken
|
||||
isValid = authToken == cfg.Auth.AuthToken
|
||||
if !isValid {
|
||||
logWarning("auth FAILED: invalid auth_token: %s", authToken)
|
||||
err := fmt.Sprintf("Auth token incorrect: %s", authToken)
|
||||
return false, err
|
||||
}
|
||||
|
||||
logInfo("auth SUCCESS: %t", isValid)
|
||||
return isValid
|
||||
return isValid, ""
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ sizeLimit = 125 # MB
|
||||
|
||||
[pages]
|
||||
enabled = true
|
||||
staticDir = "/root/data/ghproxy/pages"
|
||||
staticDir = "/usr/local/ghproxy/pages"
|
||||
|
||||
[log]
|
||||
logFilePath = "/root/data/ghproxy/log/ghproxy.log"
|
||||
logFilePath = "/usr/local/ghproxy/log/ghproxy.log"
|
||||
maxLogSize = 5 # MB
|
||||
|
||||
[cors]
|
||||
@@ -19,9 +19,9 @@ authToken = "token"
|
||||
enabled = false
|
||||
|
||||
[blacklist]
|
||||
blacklistFile = "/root/data/ghproxy/config/blacklist.json"
|
||||
blacklistFile = "/usr/local/ghproxy/config/blacklist.json"
|
||||
enabled = false
|
||||
|
||||
[whitelist]
|
||||
enabled = false
|
||||
whitelistFile = "/root/data/ghproxy/config/whitelist.json"
|
||||
whitelistFile = "/usr/local/ghproxy/config/whitelist.json"
|
||||
|
||||
@@ -3,8 +3,8 @@ Description=Github Proxy Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c '/root/data/ghproxy/ghproxy -cfg /root/data/ghproxy/config/config.toml > /root/data/ghproxy/log/run.log 2>&1'
|
||||
WorkingDirectory=/root/data/ghproxy
|
||||
ExecStart=/bin/bash -c '/usr/local/ghproxy/ghproxy -cfg /usr/local/ghproxy/config/config.toml > /usr/local/ghproxy/log/run.log 2>&1'
|
||||
WorkingDirectory=/usr/local/ghproxy
|
||||
Restart=always
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
# /bin/bash
|
||||
# https://github.com/WJQSERVER-STUDIO/ghproxy
|
||||
|
||||
ghproxy_dir="/usr/local/ghproxy"
|
||||
|
||||
# install packages
|
||||
install() {
|
||||
@@ -27,6 +30,26 @@ install() {
|
||||
return 0
|
||||
}
|
||||
|
||||
make_systemd_service() {
|
||||
cat <<EOF > /etc/systemd/system/ghproxy.service
|
||||
[Unit]
|
||||
Description=Github Proxy Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c '$ghproxy_dir/ghproxy -cfg $ghproxy_dir/config/config.toml > $ghproxy_dir/log/run.log 2>&1'
|
||||
WorkingDirectory=$ghproxy_dir
|
||||
Restart=always
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
# 安装依赖包
|
||||
install curl wget sed
|
||||
|
||||
@@ -44,44 +67,66 @@ elif [ "$ARCH" == "aarch64" ]; then
|
||||
ARCH="arm64"
|
||||
fi
|
||||
|
||||
# 获取监听端口
|
||||
read -p "请输入程序监听的端口(默认8080): " PORT
|
||||
if [ -z "$PORT" ]; then
|
||||
PORT=8080
|
||||
fi
|
||||
|
||||
# 本机监听/泛监听(127.0.0.1/0.0.0.0)
|
||||
read -p "请键入程序监听的IP(默认127.0.0.1)(0.0.0.0为泛监听): " IP
|
||||
if [ -z "$IP" ]; then
|
||||
IP="127.0.0.1"
|
||||
fi
|
||||
|
||||
# 安装目录
|
||||
read -p "请输入安装目录(默认/usr/local/ghproxy): " ghproxy_dir
|
||||
if [ -z "$ghproxy_dir" ]; then
|
||||
ghproxy_dir="/usr/local/ghproxy"
|
||||
fi
|
||||
|
||||
# 创建目录
|
||||
mkdir -p /root/data/ghproxy
|
||||
mkdir -p /root/data/ghproxy/config
|
||||
mkdir -p /root/data/ghproxy/log
|
||||
mkdir -p /root/data/ghproxy/pages
|
||||
mkdir -p ${ghproxy_dir}
|
||||
mkdir -p ${ghproxy_dir}/config
|
||||
mkdir -p ${ghproxy_dir}/log
|
||||
mkdir -p ${ghproxy_dir}/pages
|
||||
|
||||
# 获取最新版本号
|
||||
VERSION=$(curl -s https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION)
|
||||
wget -q -O /root/data/ghproxy/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION
|
||||
wget -q -O ${ghproxy_dir}/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/DEV-VERSION
|
||||
|
||||
# 下载ghproxy
|
||||
wget -q -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH
|
||||
chmod +x /root/data/ghproxy/ghproxy
|
||||
wget -q -O ${ghproxy_dir}/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH
|
||||
chmod +x ${ghproxy_dir}/ghproxy
|
||||
|
||||
# 下载pages
|
||||
wget -q -O /root/data/ghproxy/pages/index.html https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/index.html
|
||||
wget -q -O /root/data/ghproxy/pages/favicon.ico https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/favicon.ico
|
||||
wget -q -O ${ghproxy_dir}/pages/index.html https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/index.html
|
||||
wget -q -O ${ghproxy_dir}/pages/favicon.ico https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/favicon.ico
|
||||
|
||||
|
||||
# 下载配置文件
|
||||
if [ -f /root/data/ghproxy/config/config.toml ]; then
|
||||
if [ -f ${ghproxy_dir}/config/config.toml ]; then
|
||||
echo "配置文件已存在, 跳过下载"
|
||||
echo "[WARNING] 请检查配置文件是否正确,DEV版本升级时请注意配置文件兼容性"
|
||||
sleep 2
|
||||
else
|
||||
wget -q -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml
|
||||
wget -q -O ${ghproxy_dir}/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml
|
||||
fi
|
||||
|
||||
# 替换 port = 8080
|
||||
sed -i "s/port = 8080/port = $PORT/g" /root/data/ghproxy/config/config.toml
|
||||
sed -i "s/port = 8080/port = $PORT/g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i 's/host = "127.0.0.1"/host = "'"$IP"'"/g' ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|staticDir = \"/usr/local/ghproxy/pages\"|staticDir = \"${ghproxy_dir}/pages\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|logFilePath = \"/usr/local/ghproxy/log/ghproxy.log\"|logFilePath = \"${ghproxy_dir}/log/ghproxy.log\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|blacklistFile = \"/usr/local/ghproxy/config/blacklist.json\"|blacklistFile = \"${ghproxy_dir}/config/blacklist.json\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|whitelistFile = \"/usr/local/ghproxy/config/whitelist.json\"|whitelistFile = \"${ghproxy_dir}/config/whitelist.json\"|g" ${ghproxy_dir}/config/config.toml
|
||||
|
||||
# 下载systemd服务文件
|
||||
wget -q -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service
|
||||
if [ "$ghproxy_dir" = "/usr/local/ghproxy" ]; then
|
||||
wget -q -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service
|
||||
else
|
||||
make_systemd_service
|
||||
fi
|
||||
|
||||
# 启动ghproxy
|
||||
systemctl daemon-reload
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
# /bin/bash
|
||||
# https://github.com/WJQSERVER-STUDIO/ghproxy
|
||||
|
||||
ghproxy_dir="/usr/local/ghproxy"
|
||||
|
||||
# install packages
|
||||
install() {
|
||||
@@ -27,8 +30,28 @@ install() {
|
||||
return 0
|
||||
}
|
||||
|
||||
make_systemd_service() {
|
||||
cat <<EOF > /etc/systemd/system/ghproxy.service
|
||||
[Unit]
|
||||
Description=Github Proxy Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/bash -c '$ghproxy_dir/ghproxy -cfg $ghproxy_dir/config/config.toml > $ghproxy_dir/log/run.log 2>&1'
|
||||
WorkingDirectory=$ghproxy_dir
|
||||
Restart=always
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
# 安装依赖包
|
||||
install curl wget -q sed
|
||||
install curl wget sed
|
||||
|
||||
# 查看当前架构是否为linux/amd64或linux/arm64
|
||||
ARCH=$(uname -m)
|
||||
@@ -44,38 +67,66 @@ elif [ "$ARCH" == "aarch64" ]; then
|
||||
ARCH="arm64"
|
||||
fi
|
||||
|
||||
# 获取监听端口
|
||||
read -p "请输入程序监听的端口(默认8080): " PORT
|
||||
if [ -z "$PORT" ]; then
|
||||
PORT=8080
|
||||
fi
|
||||
|
||||
# 本机监听/泛监听(127.0.0.1/0.0.0.0)
|
||||
read -p "请键入程序监听的IP(默认127.0.0.1)(0.0.0.0为泛监听): " IP
|
||||
if [ -z "$IP" ]; then
|
||||
IP="127.0.0.1"
|
||||
fi
|
||||
|
||||
# 安装目录
|
||||
read -p "请输入安装目录(默认/usr/local/ghproxy): " ghproxy_dir
|
||||
if [ -z "$ghproxy_dir" ]; then
|
||||
ghproxy_dir="/usr/local/ghproxy"
|
||||
fi
|
||||
|
||||
# 创建目录
|
||||
mkdir -p /root/data/ghproxy
|
||||
mkdir -p /root/data/ghproxy/config
|
||||
mkdir -p /root/data/ghproxy/log
|
||||
mkdir -p ${ghproxy_dir}
|
||||
mkdir -p ${ghproxy_dir}/config
|
||||
mkdir -p ${ghproxy_dir}/log
|
||||
mkdir -p ${ghproxy_dir}/pages
|
||||
|
||||
# 获取最新版本号
|
||||
VERSION=$(curl -s https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/VERSION)
|
||||
wget -q -O /root/data/ghproxy/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/VERSION
|
||||
wget -q -O ${ghproxy_dir}/VERSION https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/VERSION
|
||||
|
||||
# 下载ghproxy
|
||||
wget -q -O /root/data/ghproxy/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH
|
||||
chmod +x /root/data/ghproxy/ghproxy
|
||||
wget -q -O ${ghproxy_dir}/ghproxy https://github.com/WJQSERVER-STUDIO/ghproxy/releases/download/$VERSION/ghproxy-linux-$ARCH
|
||||
chmod +x ${ghproxy_dir}/ghproxy
|
||||
|
||||
# 下载pages
|
||||
wget -q -O ${ghproxy_dir}/pages/index.html https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/index.html
|
||||
wget -q -O ${ghproxy_dir}/pages/favicon.ico https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/pages/favicon.ico
|
||||
|
||||
|
||||
# 下载配置文件
|
||||
if [ -f /root/data/ghproxy/config/config.toml ]; then
|
||||
if [ -f ${ghproxy_dir}/config/config.toml ]; then
|
||||
echo "配置文件已存在, 跳过下载"
|
||||
echo "请检查配置文件是否正确,跨大版本升级时请注意配置文件兼容性"
|
||||
echo "[WARNING] 请检查配置文件是否正确,DEV版本升级时请注意配置文件兼容性"
|
||||
sleep 2
|
||||
else
|
||||
wget -q -O /root/data/ghproxy/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml
|
||||
wget -q -O ${ghproxy_dir}/config/config.toml https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/config.toml
|
||||
fi
|
||||
|
||||
# 替换 port = 8080
|
||||
sed -i "s/port = 8080/port = $PORT/g" /root/data/ghproxy/config/config.toml
|
||||
sed -i "s/port = 8080/port = $PORT/g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i 's/host = "127.0.0.1"/host = "'"$IP"'"/g' ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|staticDir = \"/usr/local/ghproxy/pages\"|staticDir = \"${ghproxy_dir}/pages\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|logFilePath = \"/usr/local/ghproxy/log/ghproxy.log\"|logFilePath = \"${ghproxy_dir}/log/ghproxy.log\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|blacklistFile = \"/usr/local/ghproxy/config/blacklist.json\"|blacklistFile = \"${ghproxy_dir}/config/blacklist.json\"|g" ${ghproxy_dir}/config/config.toml
|
||||
sed -i "s|whitelistFile = \"/usr/local/ghproxy/config/whitelist.json\"|whitelistFile = \"${ghproxy_dir}/config/whitelist.json\"|g" ${ghproxy_dir}/config/config.toml
|
||||
|
||||
# 下载systemd服务文件
|
||||
wget -q -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service
|
||||
if [ "$ghproxy_dir" = "/usr/local/ghproxy" ]; then
|
||||
wget -q -O /etc/systemd/system/ghproxy.service https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghproxy/main/deploy/ghproxy.service
|
||||
else
|
||||
make_systemd_service
|
||||
fi
|
||||
|
||||
# 启动ghproxy
|
||||
systemctl daemon-reload
|
||||
|
||||
@@ -7,7 +7,21 @@ systemctl stop ghproxy
|
||||
systemctl disable ghproxy
|
||||
rm /etc/systemd/system/ghproxy.service
|
||||
|
||||
# 获取安装文件夹
|
||||
read -p "请输入 ghproxy 安装文件夹路径(默认 /usr/local/ghproxy): " install_path
|
||||
if [ -z "$install_path" ]; then
|
||||
install_path="/usr/local/ghproxy"
|
||||
fi
|
||||
|
||||
# 删除 ghproxy 文件夹
|
||||
rm -r /root/data/ghproxy
|
||||
# 检查目录是否存在ghproxy文件
|
||||
if [ -f "$install_path" ]; then
|
||||
echo "ghproxy 未安装或安装路径错误"
|
||||
exit 1
|
||||
else
|
||||
echo "ghproxy 安装目录已确认,正在卸载..."
|
||||
rm -r $install_path
|
||||
fi
|
||||
|
||||
|
||||
echo "ghproxy 已成功卸载"
|
||||
14
main.go
14
main.go
@@ -22,7 +22,6 @@ var (
|
||||
cfgfile string
|
||||
)
|
||||
|
||||
// 日志模块
|
||||
var (
|
||||
logw = logger.Logw
|
||||
logInfo = logger.LogInfo
|
||||
@@ -36,7 +35,6 @@ func readFlag() {
|
||||
|
||||
func loadConfig() {
|
||||
var err error
|
||||
// 初始化配置
|
||||
cfg, err = config.LoadConfig(cfgfile)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load config: %v", err)
|
||||
@@ -46,9 +44,8 @@ func loadConfig() {
|
||||
}
|
||||
|
||||
func setupLogger(cfg *config.Config) {
|
||||
// 初始化日志模块
|
||||
var err error
|
||||
err = logger.Init(cfg.Log.LogFilePath, cfg.Log.MaxLogSize) // 传递日志文件路径
|
||||
err = logger.Init(cfg.Log.LogFilePath, cfg.Log.MaxLogSize)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize logger: %v", err)
|
||||
}
|
||||
@@ -89,8 +86,8 @@ func init() {
|
||||
router.StaticFile("/favicon.ico", faviconPath)
|
||||
} else if !cfg.Pages.Enabled {
|
||||
router.GET("/", func(c *gin.Context) {
|
||||
c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.")
|
||||
logWarning("Forbidden: IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto)
|
||||
c.String(http.StatusForbidden, "403 Forbidden Access")
|
||||
logWarning("403 > Path:/ IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -100,11 +97,10 @@ func init() {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// 启动服务器
|
||||
err := router.Run(fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port))
|
||||
if err != nil {
|
||||
logError("Error starting server: %v\n", err)
|
||||
logError("Failed to start server: %v\n", err)
|
||||
}
|
||||
|
||||
fmt.Println("Program finished")
|
||||
fmt.Println("Program Exit")
|
||||
}
|
||||
|
||||
115
pages/index.html
115
pages/index.html
@@ -5,12 +5,31 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Github文件加速">
|
||||
<meta name="keywords" content="Github,文件加速,ghproxy">
|
||||
<meta name="color-scheme" content="dark light">
|
||||
<title>Github文件加速</title>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://font.sec.miui.com/font/css?family=MiSans:400,700:MiSans">
|
||||
<style>
|
||||
|
||||
:root {
|
||||
--color: #dadada;
|
||||
--fontcolor: #333;
|
||||
--inputcolor: #a19f9f;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--color: #53535338;
|
||||
--fontcolor: #b8b8b8;
|
||||
--inputcolor: #012333;
|
||||
--inputcolor-font: #969696d8;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #ecececf3;
|
||||
background-color: var(--color);
|
||||
color: var(--fontcolor);
|
||||
font-family: 'Misans', Arial, sans-serif;
|
||||
padding: 30px;
|
||||
display: flex;
|
||||
@@ -23,14 +42,16 @@
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 800px;
|
||||
max-width: 80%;
|
||||
text-align: center;
|
||||
min-height: 45vh;
|
||||
min-height: 65%;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: var(--fontcolor);
|
||||
font-weight: bold;
|
||||
margin-bottom: 85px;
|
||||
margin-bottom: 20%;
|
||||
}
|
||||
|
||||
.rounded-button {
|
||||
@@ -40,7 +61,7 @@
|
||||
background-color: #555c5c;
|
||||
color: rgb(255, 255, 255);
|
||||
border: none;
|
||||
margin-bottom: 10px;
|
||||
margin-bottom: 3%;
|
||||
}
|
||||
|
||||
.rounded-button:hover {
|
||||
@@ -51,7 +72,8 @@
|
||||
.tips>p:first-child::before {
|
||||
position: sticky;
|
||||
color: #7b7b7b;
|
||||
margin-bottom: 5px;
|
||||
margin-bottom: 1%;
|
||||
font-size: 60%;
|
||||
}
|
||||
|
||||
footer {
|
||||
@@ -61,6 +83,7 @@
|
||||
left: 0;
|
||||
right: 0;
|
||||
text-align: center;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
pre {
|
||||
@@ -91,15 +114,83 @@
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
footer {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 100%;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.tips {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.tips-content {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.status-container {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
footer {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 80%;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.tips {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.tips-content {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.status-container {
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
h1 {
|
||||
margin-bottom: 10%;
|
||||
}
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 3%;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
background-color: var(--inputcolor);
|
||||
color: var(--inputcolor-font);
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
background-color: var(--inputcolor);
|
||||
color: var(--inputcolor-font);
|
||||
}
|
||||
|
||||
.tips-content {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.status-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-bottom: 5px;
|
||||
margin-bottom: 1px;
|
||||
margin-top: -2%;
|
||||
}
|
||||
|
||||
.status-container p {
|
||||
margin: 0px 5px;
|
||||
margin: 0px 1px;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +232,7 @@
|
||||
color: white;
|
||||
padding: 15px 20px;
|
||||
border-radius: 10px;
|
||||
font-size: 16px;
|
||||
font-size: 90%;
|
||||
z-index: 1000;
|
||||
}
|
||||
</style>
|
||||
@@ -160,7 +251,9 @@
|
||||
<pre id="formattedLinkOutput"></pre>
|
||||
</div>
|
||||
<div class="tips">
|
||||
<p>GitHub链接带不带协议头均可,支持release、archive以及文件,转换后链接均可使用</a>。</p>
|
||||
<div class="tips-content">
|
||||
<p>GitHub链接带不带协议头均可,支持release、archive以及文件,转换后链接均可使用</a>。</p><br>
|
||||
</div>
|
||||
<div class="status-container">
|
||||
<p id="sizeLimitDisplay">文件大小限制: ...</p>
|
||||
<p id="whiteListStatus">白名单状态: ...</p>
|
||||
@@ -279,7 +372,7 @@
|
||||
<footer>
|
||||
<p>
|
||||
Copyright © 2024 WJQSERVER-STUDIO<br>
|
||||
GitHub仓库地址:<a href="https://github.com/WJQSERVER-STUDIO/ghproxy">https://github.com/WJQSERVER-STUDIO/ghproxy</a>
|
||||
GitHub仓库地址:<a href="https://github.com/WJQSERVER-STUDIO/ghproxy">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;">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// proxy/proxy.go 实验性
|
||||
package proxy
|
||||
|
||||
import (
|
||||
@@ -40,8 +39,9 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||
matches := re.FindStringSubmatch(rawPath)
|
||||
|
||||
if len(matches) < 3 {
|
||||
logWarning("Invalid URL: %s", rawPath)
|
||||
c.String(http.StatusForbidden, "Invalid URL.")
|
||||
errMsg := fmt.Sprintf("%s %s %s %s %s Invalid URL", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning(errMsg)
|
||||
c.String(http.StatusForbidden, "Invalid URL Format. Path: %s", rawPath)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -49,34 +49,37 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||
|
||||
username, repo := MatchUserRepo(rawPath, cfg, c, matches)
|
||||
|
||||
logWarning("Blacklist Check > Username: %s, Repo: %s", username, repo)
|
||||
logInfo("%s %s %s %s %s Matched-Username: %s, Matched-Repo: %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, username, repo)
|
||||
fullrepo := fmt.Sprintf("%s/%s", username, repo)
|
||||
|
||||
// 白名单检查
|
||||
if cfg.Whitelist.Enabled {
|
||||
whitelistpass := auth.CheckWhitelist(fullrepo)
|
||||
if !whitelistpass {
|
||||
whitelist := auth.CheckWhitelist(fullrepo)
|
||||
if !whitelist {
|
||||
logErrMsg := fmt.Sprintf("%s %s %s %s %s Whitelist Blocked repo: %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, fullrepo)
|
||||
errMsg := fmt.Sprintf("Whitelist Blocked repo: %s", fullrepo)
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": errMsg})
|
||||
logWarning(errMsg)
|
||||
logWarning(logErrMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 黑名单检查
|
||||
if cfg.Blacklist.Enabled {
|
||||
blacklistpass := auth.CheckBlacklist(fullrepo)
|
||||
if blacklistpass {
|
||||
blacklist := auth.CheckBlacklist(fullrepo)
|
||||
if blacklist {
|
||||
logErrMsg := fmt.Sprintf("%s %s %s %s %s Whitelist Blocked repo: %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, fullrepo)
|
||||
errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", fullrepo)
|
||||
c.JSON(http.StatusForbidden, gin.H{"error": errMsg})
|
||||
logWarning(errMsg)
|
||||
logWarning(logErrMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
matches = CheckURL(rawPath)
|
||||
matches = CheckURL(rawPath, c)
|
||||
if matches == nil {
|
||||
c.AbortWithStatus(http.StatusNotFound)
|
||||
logError("%s %s %s %s %s 404-NOMATCH", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -84,13 +87,16 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||
rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
|
||||
}
|
||||
|
||||
if !auth.AuthHandler(c, cfg) {
|
||||
// 鉴权
|
||||
authcheck, err := auth.AuthHandler(c, cfg)
|
||||
if !authcheck {
|
||||
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"})
|
||||
logWarning("Unauthorized request: %s", rawPath)
|
||||
logWarning("%s %s %s %s %s Auth-Error: %v", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
|
||||
logInfo("Matches: %v", matches)
|
||||
// IP METHOD URL USERAGENT PROTO MATCHES
|
||||
logInfo("%s %s %s %s %s Matches: %v", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, matches)
|
||||
|
||||
switch {
|
||||
case exps[0].MatchString(rawPath), exps[1].MatchString(rawPath), exps[3].MatchString(rawPath), exps[4].MatchString(rawPath):
|
||||
@@ -99,6 +105,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc {
|
||||
ProxyRequest(c, rawPath, cfg, "git")
|
||||
default:
|
||||
c.String(http.StatusForbidden, "Invalid input.")
|
||||
fmt.Println("Invalid input.")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -110,24 +117,24 @@ func MatchUserRepo(rawPath string, cfg *config.Config, c *gin.Context, matches [
|
||||
var gistmatches []string
|
||||
if gistregex.MatchString(rawPath) {
|
||||
gistmatches = gistregex.FindStringSubmatch(rawPath)
|
||||
logInfo("Gist Matched > Username: %s, URL: %s", gistmatches[1], rawPath)
|
||||
logInfo("%s %s %s %s %s Matched-Username: %s", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto, gistmatches[1])
|
||||
return gistmatches[1], ""
|
||||
}
|
||||
// 定义路径匹配的正则表达式
|
||||
// 定义路径
|
||||
pathRegex := regexp.MustCompile(`^([^/]+)/([^/]+)/([^/]+)/.*`)
|
||||
if pathMatches := pathRegex.FindStringSubmatch(matches[2]); len(pathMatches) >= 4 {
|
||||
return pathMatches[2], pathMatches[3]
|
||||
}
|
||||
|
||||
// 返回错误信息
|
||||
logWarning("Invalid path: %s", rawPath)
|
||||
c.String(http.StatusForbidden, "Invalid path; expected username/repo.")
|
||||
errMsg := fmt.Sprintf("%s %s %s %s %s Invalid URL", c.ClientIP(), c.Request.Method, rawPath, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning(errMsg)
|
||||
c.String(http.StatusForbidden, "Invalid path; expected username/repo, Path: %s", rawPath)
|
||||
return "", ""
|
||||
}
|
||||
|
||||
func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
|
||||
method := c.Request.Method
|
||||
// 记录日志 IP 地址、请求方法、请求 URL、请求头 User-Agent 、HTTP版本
|
||||
logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
|
||||
client := createHTTPClient(mode)
|
||||
@@ -141,7 +148,7 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
|
||||
req := client.R().SetBody(body)
|
||||
setRequestHeaders(c, req)
|
||||
|
||||
resp, err := SendRequest(req, method, u)
|
||||
resp, err := SendRequest(c, req, method, u)
|
||||
if err != nil {
|
||||
HandleError(c, fmt.Sprintf("Failed to send request: %v", err))
|
||||
return
|
||||
@@ -149,17 +156,18 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) {
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err := HandleResponseSize(resp, cfg, c); err != nil {
|
||||
logWarning("Error handling response size: %v", err)
|
||||
logWarning("%s %s %s %s %s Response-Size-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
return
|
||||
}
|
||||
|
||||
CopyResponseHeaders(resp, c, cfg)
|
||||
c.Status(resp.StatusCode)
|
||||
if err := copyResponseBody(c, resp.Body); err != nil {
|
||||
logError("Failed to copy response body: %v", err)
|
||||
logError("%s %s %s %s %s Response-Copy-Error: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 判断并选择TLS指纹
|
||||
func createHTTPClient(mode string) *req.Client {
|
||||
client := req.C()
|
||||
switch mode {
|
||||
@@ -198,7 +206,7 @@ func copyResponseBody(c *gin.Context, respBody io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func SendRequest(req *req.Request, method, url string) (*req.Response, error) {
|
||||
func SendRequest(c *gin.Context, req *req.Request, method, url string) (*req.Response, error) {
|
||||
switch method {
|
||||
case "GET":
|
||||
return req.Get(url)
|
||||
@@ -209,8 +217,10 @@ func SendRequest(req *req.Request, method, url string) (*req.Response, error) {
|
||||
case "DELETE":
|
||||
return req.Delete(url)
|
||||
default:
|
||||
logInfo("Unsupported method: %s", method)
|
||||
return nil, fmt.Errorf("unsupported method: %s", method)
|
||||
// IP METHOD URL USERAGENT PROTO UNSUPPORTED-METHOD
|
||||
errmsg := fmt.Sprintf("%s %s %s %s %s Unsupported method", c.ClientIP(), method, url, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning(errmsg)
|
||||
return nil, fmt.Errorf(errmsg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,8 +232,8 @@ func HandleResponseSize(resp *req.Response, cfg *config.Config, c *gin.Context)
|
||||
if err == nil && size > sizelimit {
|
||||
finalURL := resp.Request.URL.String()
|
||||
c.Redirect(http.StatusMovedPermanently, finalURL)
|
||||
logWarning("Size limit exceeded: %s, Size: %d", finalURL, size)
|
||||
return fmt.Errorf("size limit exceeded: %d", size)
|
||||
logWarning("%s %s %s %s %s Final-URL: %s Size-Limit-Exceeded: %d", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto, finalURL, size)
|
||||
return fmt.Errorf("Path: %s size limit exceeded: %d", finalURL, size)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -282,14 +292,13 @@ func HandleError(c *gin.Context, message string) {
|
||||
logWarning(message)
|
||||
}
|
||||
|
||||
func CheckURL(u string) []string {
|
||||
func CheckURL(u string, c *gin.Context) []string {
|
||||
for _, exp := range exps {
|
||||
if matches := exp.FindStringSubmatch(u); matches != nil {
|
||||
logInfo("URL matched: %s, Matches: %v", u, matches[1:])
|
||||
return matches[1:]
|
||||
}
|
||||
}
|
||||
errMsg := fmt.Sprintf("Invalid URL: %s", u)
|
||||
errMsg := fmt.Sprintf("%s %s %s %s %s Invalid URL", c.ClientIP(), c.Request.Method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto)
|
||||
logWarning(errMsg)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user