增加更多匹配的域名信息

This commit is contained in:
Alex Yang
2026-01-14 23:08:46 +08:00
parent f247eaeaa8
commit 8159577be0
60 changed files with 11716 additions and 1022 deletions

View File

@@ -12,6 +12,7 @@ import (
"dns-server/config"
"dns-server/dns"
"dns-server/gfw"
"dns-server/logger"
"dns-server/shield"
@@ -24,6 +25,7 @@ type Server struct {
config *config.HTTPConfig
dnsServer *dns.Server
shieldManager *shield.ShieldManager
gfwManager *gfw.GFWListManager
server *http.Server
// 会话管理相关字段
@@ -39,12 +41,13 @@ type Server struct {
}
// NewServer 创建HTTP服务器实例
func NewServer(globalConfig *config.Config, dnsServer *dns.Server, shieldManager *shield.ShieldManager) *Server {
func NewServer(globalConfig *config.Config, dnsServer *dns.Server, shieldManager *shield.ShieldManager, gfwManager *gfw.GFWListManager) *Server {
server := &Server{
globalConfig: globalConfig,
config: &globalConfig.HTTP,
dnsServer: dnsServer,
shieldManager: shieldManager,
gfwManager: gfwManager,
upgrader: websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
@@ -584,7 +587,7 @@ func (s *Server) handleRecentBlockedDomains(w http.ResponseWriter, r *http.Reque
for i, domain := range domains {
result[i] = map[string]interface{}{
"domain": domain.Domain,
"time": domain.LastSeen.Format("15:04:05"),
"time": time.Unix(domain.LastSeen, 0).Format("15:04:05"),
}
}
@@ -1239,6 +1242,10 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
"blacklists": s.globalConfig.Shield.Blacklists,
"updateInterval": s.globalConfig.Shield.UpdateInterval,
},
"GFWList": map[string]interface{}{
"ip": s.globalConfig.GFWList.IP,
"content": s.globalConfig.GFWList.Content,
},
"DNSServer": map[string]interface{}{
"port": s.globalConfig.DNS.Port,
"UpstreamServers": s.globalConfig.DNS.UpstreamDNS,
@@ -1272,6 +1279,10 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
Blacklists []config.BlacklistEntry `json:"blacklists"`
UpdateInterval int `json:"updateInterval"`
} `json:"shield"`
GFWList struct {
IP string `json:"ip"`
Content string `json:"content"`
} `json:"gfwList"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
@@ -1334,6 +1345,17 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
s.globalConfig.Shield.CustomBlockIP = req.Shield.CustomBlockIP
}
// 更新GFWList配置
s.globalConfig.GFWList.IP = req.GFWList.IP
s.globalConfig.GFWList.Content = req.GFWList.Content
// 重新加载GFWList规则
if s.gfwManager != nil {
if err := s.gfwManager.LoadRules(); err != nil {
logger.Error("重新加载GFWList规则失败", "error", err)
}
}
// 更新黑名单配置
if req.Shield.Blacklists != nil {
// 验证黑名单配置