去除代理头支持, 增加节点面板通信加密 增加导出sql

This commit is contained in:
qaq
2025-07-11 16:24:12 +08:00
parent b690e68951
commit e313a1953c
21 changed files with 960 additions and 143 deletions
+65 -3
View File
@@ -11,11 +11,13 @@ import (
"github.com/go-gost/core/observer/stats"
"github.com/go-gost/x/config"
"github.com/go-gost/x/internal/util/crypto"
"github.com/go-gost/x/registry"
)
var httpReportURL string
var configReportURL string
var httpAESCrypto *crypto.AESCrypto // 新增:HTTP上报加密器
// TrafficReportItem 流量报告项(压缩格式)
type TrafficReportItem struct {
@@ -28,6 +30,16 @@ type TrafficReportItem struct {
func SetHTTPReportURL(addr string, secret string) {
httpReportURL = "http://" + addr + "/flow/upload?secret=" + secret
configReportURL = "http://" + addr + "/flow/config?secret=" + secret
// 创建 AES 加密器
var err error
httpAESCrypto, err = crypto.NewAESCrypto(secret)
if err != nil {
fmt.Printf("❌ 创建 HTTP AES 加密器失败: %v\n", err)
httpAESCrypto = nil
} else {
fmt.Printf("🔐 HTTP AES 加密器创建成功\n")
}
}
// sendTrafficReport 发送流量报告到HTTP接口
@@ -37,7 +49,32 @@ func sendTrafficReport(ctx context.Context, reportItems []TrafficReportItem) (bo
return false, fmt.Errorf("序列化报告数据失败: %v", err)
}
req, err := http.NewRequestWithContext(ctx, "POST", httpReportURL, bytes.NewBuffer(jsonData))
var requestBody []byte
// 如果有加密器,则加密数据
if httpAESCrypto != nil {
encryptedData, err := httpAESCrypto.Encrypt(jsonData)
if err != nil {
fmt.Printf("⚠️ 加密流量报告失败,发送原始数据: %v\n", err)
requestBody = jsonData
} else {
// 创建加密消息包装器
encryptedMessage := map[string]interface{}{
"encrypted": true,
"data": encryptedData,
"timestamp": time.Now().Unix(),
}
requestBody, err = json.Marshal(encryptedMessage)
if err != nil {
fmt.Printf("⚠️ 序列化加密流量报告失败,发送原始数据: %v\n", err)
requestBody = jsonData
}
}
} else {
requestBody = jsonData
}
req, err := http.NewRequestWithContext(ctx, "POST", httpReportURL, bytes.NewBuffer(requestBody))
if err != nil {
return false, fmt.Errorf("创建HTTP请求失败: %v", err)
}
@@ -88,13 +125,38 @@ func sendConfigReport(ctx context.Context) (bool, error) {
return false, fmt.Errorf("获取配置数据失败: %v", err)
}
req, err := http.NewRequestWithContext(ctx, "POST", configReportURL, bytes.NewBuffer(configData))
var requestBody []byte
// 如果有加密器,则加密数据
if httpAESCrypto != nil {
encryptedData, err := httpAESCrypto.Encrypt(configData)
if err != nil {
fmt.Printf("⚠️ 加密配置报告失败,发送原始数据: %v\n", err)
requestBody = configData
} else {
// 创建加密消息包装器
encryptedMessage := map[string]interface{}{
"encrypted": true,
"data": encryptedData,
"timestamp": time.Now().Unix(),
}
requestBody, err = json.Marshal(encryptedMessage)
if err != nil {
fmt.Printf("⚠️ 序列化加密配置报告失败,发送原始数据: %v\n", err)
requestBody = configData
}
}
} else {
requestBody = configData
}
req, err := http.NewRequestWithContext(ctx, "POST", configReportURL, bytes.NewBuffer(requestBody))
if err != nil {
return false, fmt.Errorf("创建HTTP请求失败: %v", err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "GOST-Config-Reporter/1.0")
req.Header.Set("User-Agent", "Config-Reporter/1.0")
client := &http.Client{
Timeout: 10 * time.Second, // 配置上报可以稍长一些