This commit is contained in:
Alex Yang
2025-11-23 19:35:02 +08:00
parent d870f6bfcc
commit 5a1d44c3b3
10 changed files with 4783 additions and 17 deletions

View File

@@ -373,11 +373,13 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
// 返回当前配置(只返回必要的部分
// 返回当前配置(包括远程规则相关配置
config := map[string]interface{}{
"shield": map[string]string{
"shield": map[string]interface{}{
"blockMethod": s.globalConfig.Shield.BlockMethod,
"customBlockIP": s.globalConfig.Shield.CustomBlockIP,
"remoteRules": s.globalConfig.Shield.RemoteRules,
"updateInterval": s.globalConfig.Shield.UpdateInterval,
},
}
json.NewEncoder(w).Encode(config)
@@ -386,8 +388,10 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
// 更新配置
var req struct {
Shield struct {
BlockMethod string `json:"blockMethod"`
BlockMethod string `json:"blockMethod"`
CustomBlockIP string `json:"customBlockIP"`
RemoteRules []string `json:"remoteRules"`
UpdateInterval int `json:"updateInterval"`
} `json:"shield"`
}
@@ -431,6 +435,23 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
s.globalConfig.Shield.CustomBlockIP = req.Shield.CustomBlockIP
}
// 更新远程规则列表
if req.Shield.RemoteRules != nil {
s.globalConfig.Shield.RemoteRules = req.Shield.RemoteRules
// 重新加载规则
if err := s.shieldManager.LoadRules(); err != nil {
logger.Error("重新加载规则失败", "error", err)
}
}
// 更新更新间隔
if req.Shield.UpdateInterval > 0 {
s.globalConfig.Shield.UpdateInterval = req.Shield.UpdateInterval
// 重新启动自动更新
s.shieldManager.StopAutoUpdate()
s.shieldManager.StartAutoUpdate()
}
// 返回成功响应
json.NewEncoder(w).Encode(map[string]interface{}{
"success": true,