更新web

This commit is contained in:
Alex Yang
2026-01-21 09:46:49 +08:00
parent ac96c7c10b
commit 073f1961b1
80 changed files with 75919 additions and 12379 deletions

View File

@@ -1250,6 +1250,7 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
},
"DNSServer": map[string]interface{}{
"port": s.globalConfig.DNS.Port,
"QueryMode": s.globalConfig.DNS.QueryMode,
"UpstreamServers": s.globalConfig.DNS.UpstreamDNS,
"DNSSECUpstreamServers": s.globalConfig.DNS.DNSSECUpstreamDNS,
"saveInterval": s.globalConfig.DNS.SaveInterval,
@@ -1270,6 +1271,7 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
var req struct {
DNSServer struct {
Port int `json:"port"`
QueryMode string `json:"queryMode"`
UpstreamServers []string `json:"upstreamServers"`
DnssecUpstreamServers []string `json:"dnssecUpstreamServers"`
Timeout int `json:"timeout"`
@@ -1314,6 +1316,10 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
s.globalConfig.DNS.SaveInterval = req.DNSServer.SaveInterval
}
s.globalConfig.DNS.EnableIPv6 = req.DNSServer.EnableIPv6
// 更新查询模式
if req.DNSServer.QueryMode != "" {
s.globalConfig.DNS.QueryMode = req.DNSServer.QueryMode
}
// 更新缓存配置
if req.DNSServer.CacheMode != "" {
s.globalConfig.DNS.CacheMode = req.DNSServer.CacheMode
@@ -1409,29 +1415,29 @@ func (s *Server) handleConfig(w http.ResponseWriter, r *http.Request) {
}
// 更新现有的DNSCache实例配置
// 最大和最小TTL
maxCacheTTL := time.Duration(s.globalConfig.DNS.MaxCacheTTL) * time.Second
minCacheTTL := time.Duration(s.globalConfig.DNS.MinCacheTTL) * time.Second
// 最大缓存大小(字节)
maxCacheSize := int64(s.globalConfig.DNS.CacheSize) * 1024 * 1024
// 最大和最小TTL
maxCacheTTL := time.Duration(s.globalConfig.DNS.MaxCacheTTL) * time.Second
minCacheTTL := time.Duration(s.globalConfig.DNS.MinCacheTTL) * time.Second
// 最大缓存大小(字节)
maxCacheSize := int64(s.globalConfig.DNS.CacheSize) * 1024 * 1024
// 更新缓存配置
s.dnsServer.DnsCache.SetMaxCacheTTL(maxCacheTTL)
s.dnsServer.DnsCache.SetMinCacheTTL(minCacheTTL)
s.dnsServer.DnsCache.SetCacheMode(s.globalConfig.DNS.CacheMode)
s.dnsServer.DnsCache.SetMaxCacheSize(maxCacheSize)
// 更新缓存配置
s.dnsServer.DnsCache.SetMaxCacheTTL(maxCacheTTL)
s.dnsServer.DnsCache.SetMinCacheTTL(minCacheTTL)
s.dnsServer.DnsCache.SetCacheMode(s.globalConfig.DNS.CacheMode)
s.dnsServer.DnsCache.SetMaxCacheSize(maxCacheSize)
// 保存配置到文件
if err := saveConfigToFile(s.globalConfig, "./config.json"); err != nil {
logger.Error("保存配置到文件失败", "error", err)
// 不返回错误,只记录日志,因为配置已经在内存中更新成功
}
// 保存配置到文件
if err := saveConfigToFile(s.globalConfig, "./config.json"); err != nil {
logger.Error("保存配置到文件失败", "error", err)
// 不返回错误,只记录日志,因为配置已经在内存中更新成功
}
// 返回成功响应
json.NewEncoder(w).Encode(map[string]interface{}{
"success": true,
"message": "配置已更新",
})
// 返回成功响应
json.NewEncoder(w).Encode(map[string]interface{}{
"success": true,
"message": "配置已更新",
})
default:
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)