update
This commit is contained in:
+96
-34
@@ -7,34 +7,34 @@ import (
|
||||
"gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
// DomainSpecificDNS 域名特定DNS服务器配置
|
||||
// INI格式:domain_域名匹配字符串 = DNS服务器1, DNS服务器2
|
||||
// DomainSpecificDNS 域名特定 DNS 服务器配置
|
||||
// INI 格式:domain_域名匹配字符串 = DNS 服务器 1, DNS 服务器 2
|
||||
// 例如:domain_google.com = 8.8.8.8:53, 8.8.4.4:53
|
||||
|
||||
type DomainSpecificDNS map[string][]string
|
||||
|
||||
// DNSConfig DNS配置
|
||||
// DNSConfig DNS 配置
|
||||
type DNSConfig struct {
|
||||
Port int `json:"port"`
|
||||
UpstreamDNS []string `json:"upstreamDNS"`
|
||||
DNSSECUpstreamDNS []string `json:"dnssecUpstreamDNS"` // 用于DNSSEC查询的专用服务器
|
||||
DNSSECUpstreamDNS []string `json:"dnssecUpstreamDNS"` // 用于 DNSSEC 查询的专用服务器
|
||||
SaveInterval int `json:"saveInterval"` // 数据保存间隔(秒)
|
||||
CacheTTL int `json:"cacheTTL"` // DNS缓存过期时间(分钟)
|
||||
EnableDNSSEC bool `json:"enableDNSSEC"` // 是否启用DNSSEC支持
|
||||
QueryMode string `json:"queryMode"` // 查询模式:"parallel"(并行请求)、"fastest-ip"(最快的IP地址)
|
||||
CacheTTL int `json:"cacheTTL"` // DNS 缓存过期时间(分钟)
|
||||
EnableDNSSEC bool `json:"enableDNSSEC"` // 是否启用 DNSSEC 支持
|
||||
QueryMode string `json:"queryMode"` // 查询模式:"parallel"(并行请求)、"fastest-ip"(最快的 IP 地址)
|
||||
QueryTimeout int `json:"queryTimeout"` // 查询超时时间(毫秒)
|
||||
EnableFastReturn bool `json:"enableFastReturn"` // 是否启用快速返回机制
|
||||
DomainSpecificDNS DomainSpecificDNS `json:"domainSpecificDNS"` // 域名特定DNS服务器配置
|
||||
NoDNSSECDomains []string `json:"noDNSSECDomains"` // 不验证DNSSEC的域名模式列表
|
||||
EnableIPv6 bool `json:"enableIPv6"` // 是否启用IPv6解析(AAAA记录)
|
||||
DomainSpecificDNS DomainSpecificDNS `json:"domainSpecificDNS"` // 域名特定 DNS 服务器配置
|
||||
NoDNSSECDomains []string `json:"noDNSSECDomains"` // 不验证 DNSSEC 的域名模式列表
|
||||
EnableIPv6 bool `json:"enableIPv6"` // 是否启用 IPv6 解析(AAAA 记录)
|
||||
CacheMode string `json:"cacheMode"` // 缓存模式:"memory"(内存缓存)、"file"(文件缓存)
|
||||
CacheSize int `json:"cacheSize"` // 缓存大小限制(MB),0表示不缓存
|
||||
MaxCacheTTL int `json:"maxCacheTTL"` // 最大缓存TTL(分钟)
|
||||
MinCacheTTL int `json:"minCacheTTL"` // 最小缓存TTL(分钟)
|
||||
CacheSize int `json:"cacheSize"` // 缓存大小限制(MB),0 表示不缓存
|
||||
MaxCacheTTL int `json:"maxCacheTTL"` // 最大缓存 TTL(分钟)
|
||||
MinCacheTTL int `json:"minCacheTTL"` // 最小缓存 TTL(分钟)
|
||||
CacheFilePath string `json:"cacheFilePath"` // 缓存文件路径
|
||||
}
|
||||
|
||||
// HTTPConfig HTTP控制台配置
|
||||
// HTTPConfig HTTP 控制台配置
|
||||
type HTTPConfig struct {
|
||||
Port int `json:"port"`
|
||||
Host string `json:"host"`
|
||||
@@ -52,20 +52,37 @@ type BlacklistEntry struct {
|
||||
LastUpdateTime string `json:"lastUpdateTime,omitempty"`
|
||||
}
|
||||
|
||||
// DomainInfoEntry 域名信息条目
|
||||
type DomainInfoEntry struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Type string `json:"type"` // domain-info, threat-database, tracker
|
||||
RuleCount int `json:"ruleCount,omitempty"`
|
||||
LastUpdateTime string `json:"lastUpdateTime,omitempty"`
|
||||
}
|
||||
|
||||
// DomainInfoConfig 域名信息配置
|
||||
type DomainInfoConfig struct {
|
||||
DomainInfoLists []DomainInfoEntry `json:"domainInfoLists"`
|
||||
UpdateInterval int `json:"updateInterval"` // 更新间隔(秒)
|
||||
EnableAutoUpdate bool `json:"enableAutoUpdate"` // 是否启用自动更新
|
||||
}
|
||||
|
||||
// ShieldConfig 屏蔽规则配置
|
||||
type ShieldConfig struct {
|
||||
Blacklists []BlacklistEntry `json:"blacklists"`
|
||||
UpdateInterval int `json:"updateInterval"`
|
||||
BlockMethod string `json:"blockMethod"` // 屏蔽方法: "NXDOMAIN", "refused", "emptyIP", "customIP"
|
||||
CustomBlockIP string `json:"customBlockIP"` // 自定义屏蔽IP,当BlockMethod为"customIP"时使用
|
||||
BlockMethod string `json:"blockMethod"` // 屏蔽方法:"NXDOMAIN", "refused", "emptyIP", "customIP"
|
||||
CustomBlockIP string `json:"customBlockIP"` // 自定义屏蔽 IP,当 BlockMethod 为"customIP"时使用
|
||||
StatsSaveInterval int `json:"statsSaveInterval"` // 计数数据保存间隔(秒)
|
||||
}
|
||||
|
||||
// GFWListConfig GFWList配置
|
||||
// GFWListConfig GFWList 配置
|
||||
type GFWListConfig struct {
|
||||
IP string `json:"ip"` // GFWList域名解析的目标IP地址
|
||||
Content string `json:"content"` // GFWList规则文件路径
|
||||
Enabled bool `json:"enabled"` // 是否启用GFWList功能
|
||||
IP string `json:"ip"` // GFWList 域名解析的目标 IP 地址
|
||||
Content string `json:"content"` // GFWList 规则文件路径
|
||||
Enabled bool `json:"enabled"` // 是否启用 GFWList 功能
|
||||
}
|
||||
|
||||
// LogConfig 日志配置
|
||||
@@ -102,24 +119,25 @@ type QueryLogConfig struct {
|
||||
|
||||
// Config 整体配置
|
||||
type Config struct {
|
||||
DNS DNSConfig `json:"dns"`
|
||||
HTTP HTTPConfig `json:"http"`
|
||||
Shield ShieldConfig `json:"shield"`
|
||||
GFWList GFWListConfig `json:"gfwList"` // GFWList 配置
|
||||
Threat ThreatConfig `json:"threat"` // 威胁检测配置
|
||||
Log LogConfig `json:"log"`
|
||||
QueryLog QueryLogConfig `json:"queryLog"` // 查询日志配置
|
||||
DNS DNSConfig `json:"dns"`
|
||||
HTTP HTTPConfig `json:"http"`
|
||||
Shield ShieldConfig `json:"shield"`
|
||||
GFWList GFWListConfig `json:"gfwList"` // GFWList 配置
|
||||
Threat ThreatConfig `json:"threat"` // 威胁检测配置
|
||||
Log LogConfig `json:"log"`
|
||||
QueryLog QueryLogConfig `json:"queryLog"` // 查询日志配置
|
||||
DomainInfo DomainInfoConfig `json:"domainInfo"` // 域名信息配置
|
||||
}
|
||||
|
||||
// ThreatConfig 威胁检测配置
|
||||
type ThreatConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
QueryRateThreshold int `json:"queryRateThreshold"` // 每分钟查询阈值,0表示不限制
|
||||
NXDomainThreshold int `json:"nxDomainThreshold"` // 每分钟NXDOMAIN阈值,0表示不限制
|
||||
MaxDomainLength int `json:"maxDomainLength"` // 最大域名长度,0表示不限制
|
||||
QueryRateThreshold int `json:"queryRateThreshold"` // 每分钟查询阈值,0 表示不限制
|
||||
NXDomainThreshold int `json:"nxDomainThreshold"` // 每分钟 NXDOMAIN 阈值,0 表示不限制
|
||||
MaxDomainLength int `json:"maxDomainLength"` // 最大域名长度,0 表示不限制
|
||||
SuspiciousPatterns []string `json:"suspiciousPatterns"` // 可疑域名模式
|
||||
UnusualQueryTypes []string `json:"unusualQueryTypes"` // 不常见的查询类型
|
||||
AlertRetentionDays int `json:"alertRetentionDays"` // 告警保留天数,0表示一直保存
|
||||
AlertRetentionDays int `json:"alertRetentionDays"` // 告警保留天数,0 表示一直保存
|
||||
ThreatDatabasePath string `json:"threatDatabasePath"` // 威胁域名数据库路径
|
||||
}
|
||||
|
||||
@@ -131,7 +149,7 @@ func LoadConfig(path string) (*Config, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 解析INI文件
|
||||
// 解析 INI 文件
|
||||
cfg, err := ini.Load(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -209,6 +227,11 @@ func LoadConfig(path string) (*Config, error) {
|
||||
AlertRetentionDays: cfg.Section("threat").Key("alertRetentionDays").MustInt(0),
|
||||
ThreatDatabasePath: cfg.Section("threat").Key("threatDatabasePath").MustString("./static/domain-info/threats/threats-database.csv"),
|
||||
},
|
||||
DomainInfo: DomainInfoConfig{
|
||||
UpdateInterval: cfg.Section("domainInfo").Key("updateInterval").MustInt(3600),
|
||||
EnableAutoUpdate: cfg.Section("domainInfo").Key("enableAutoUpdate").MustBool(true),
|
||||
DomainInfoLists: parseDomainInfoLists(cfg.Section("domainInfo")),
|
||||
},
|
||||
}
|
||||
|
||||
// 如果黑名单列表为空,添加一些默认的黑名单
|
||||
@@ -221,6 +244,15 @@ func LoadConfig(path string) (*Config, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果域名信息列表为空,添加默认的域名信息列表
|
||||
if len(config.DomainInfo.DomainInfoLists) == 0 {
|
||||
config.DomainInfo.DomainInfoLists = []DomainInfoEntry{
|
||||
{Name: "域名信息列表", URL: "https://gitea.amazehome.xyz/AMAZEHOME/domain-info/raw/branch/main/domains/domain-info.json", Enabled: true, Type: "domain-info"},
|
||||
{Name: "威胁数据库", URL: "https://gitea.amazehome.xyz/AMAZEHOME/domain-info/raw/branch/main/threats/threats-database.csv", Enabled: true, Type: "threat-database"},
|
||||
{Name: "跟踪器列表", URL: "https://gitea.amazehome.xyz/AMAZEHOME/domain-info/raw/branch/main/tracker/trackers.json", Enabled: true, Type: "tracker"},
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
@@ -241,7 +273,7 @@ func parseStringList(s string) []string {
|
||||
return parts
|
||||
}
|
||||
|
||||
// parseDomainSpecificDNS 解析域名特定DNS服务器配置
|
||||
// parseDomainSpecificDNS 解析域名特定 DNS 服务器配置
|
||||
func parseDomainSpecificDNS(section *ini.Section) DomainSpecificDNS {
|
||||
domainDNS := make(DomainSpecificDNS)
|
||||
|
||||
@@ -270,7 +302,7 @@ func parseBlacklists(section *ini.Section) []BlacklistEntry {
|
||||
name := strings.TrimPrefix(key.Name(), "blacklist_")
|
||||
value := key.String()
|
||||
|
||||
// 解析黑名单URL和启用状态,格式: url,enabled
|
||||
// 解析黑名单 URL 和启用状态,格式:url,enabled
|
||||
parts := strings.Split(value, ",")
|
||||
if len(parts) >= 2 {
|
||||
url := strings.TrimSpace(parts[0])
|
||||
@@ -286,3 +318,33 @@ func parseBlacklists(section *ini.Section) []BlacklistEntry {
|
||||
|
||||
return blacklists
|
||||
}
|
||||
|
||||
// parseDomainInfoLists 解析域名信息列表配置
|
||||
func parseDomainInfoLists(section *ini.Section) []DomainInfoEntry {
|
||||
domainInfoLists := []DomainInfoEntry{}
|
||||
|
||||
// 遍历所有键,查找以"domainInfo_"开头的键
|
||||
for _, key := range section.Keys() {
|
||||
if strings.HasPrefix(key.Name(), "domainInfo_") {
|
||||
// 提取域名信息名称和属性
|
||||
name := strings.TrimPrefix(key.Name(), "domainInfo_")
|
||||
value := key.String()
|
||||
|
||||
// 解析域名信息 URL 和启用状态,格式:url,type,enabled
|
||||
parts := strings.Split(value, ",")
|
||||
if len(parts) >= 3 {
|
||||
url := strings.TrimSpace(parts[0])
|
||||
entryType := strings.TrimSpace(parts[1])
|
||||
enabled := strings.TrimSpace(parts[2]) == "true"
|
||||
domainInfoLists = append(domainInfoLists, DomainInfoEntry{
|
||||
Name: name,
|
||||
URL: url,
|
||||
Type: entryType,
|
||||
Enabled: enabled,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return domainInfoLists
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user