web重做
This commit is contained in:
@@ -438,7 +438,8 @@ func (m *ShieldManager) addRegexRule(re *regexp.Regexp, original string, block b
|
||||
}
|
||||
|
||||
// IsBlocked 检查域名是否被屏蔽
|
||||
func (m *ShieldManager) IsBlocked(domain string) bool {
|
||||
// CheckDomainBlockDetails 检查域名是否被屏蔽,并返回详细信息
|
||||
func (m *ShieldManager) CheckDomainBlockDetails(domain string) map[string]interface{} {
|
||||
m.rulesMutex.RLock()
|
||||
defer m.rulesMutex.RUnlock()
|
||||
|
||||
@@ -448,10 +449,30 @@ func (m *ShieldManager) IsBlocked(domain string) bool {
|
||||
domain = parts[0]
|
||||
}
|
||||
|
||||
// 首先检查排除规则(优先级最高)
|
||||
result := map[string]interface{}{
|
||||
"domain": domain,
|
||||
"blocked": false,
|
||||
"blockRule": "",
|
||||
"blockRuleType": "",
|
||||
"excluded": false,
|
||||
"excludeRule": "",
|
||||
"excludeRuleType": "",
|
||||
"hasHosts": false,
|
||||
"hostsIP": "",
|
||||
}
|
||||
|
||||
// 检查hosts记录
|
||||
hostsIP, hasHosts := m.GetHostsIP(domain)
|
||||
result["hasHosts"] = hasHosts
|
||||
result["hostsIP"] = hostsIP
|
||||
|
||||
// 检查排除规则(优先级最高)
|
||||
// 检查域名排除规则
|
||||
if m.domainExceptions[domain] {
|
||||
return false
|
||||
result["excluded"] = true
|
||||
result["excludeRule"] = domain
|
||||
result["excludeRuleType"] = "exact_domain"
|
||||
return result
|
||||
}
|
||||
|
||||
// 检查子域名排除规则
|
||||
@@ -459,21 +480,30 @@ func (m *ShieldManager) IsBlocked(domain string) bool {
|
||||
for i := 0; i < len(parts)-1; i++ {
|
||||
subdomain := strings.Join(parts[i:], ".")
|
||||
if m.domainExceptions[subdomain] {
|
||||
return false
|
||||
result["excluded"] = true
|
||||
result["excludeRule"] = subdomain
|
||||
result["excludeRuleType"] = "subdomain"
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// 检查正则表达式排除规则
|
||||
for _, re := range m.regexExceptions {
|
||||
if re.pattern.MatchString(domain) {
|
||||
return false
|
||||
result["excluded"] = true
|
||||
result["excludeRule"] = re.original
|
||||
result["excludeRuleType"] = "regex"
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// 然后检查阻止规则
|
||||
// 检查阻止规则
|
||||
// 检查精确域名匹配
|
||||
if m.domainRules[domain] {
|
||||
return true
|
||||
result["blocked"] = true
|
||||
result["blockRule"] = domain
|
||||
result["blockRuleType"] = "exact_domain"
|
||||
return result
|
||||
}
|
||||
|
||||
// 检查子域名匹配(AdGuardHome风格)
|
||||
@@ -481,18 +511,30 @@ func (m *ShieldManager) IsBlocked(domain string) bool {
|
||||
for i := 0; i < len(parts)-1; i++ {
|
||||
subdomain := strings.Join(parts[i:], ".")
|
||||
if m.domainRules[subdomain] {
|
||||
return true
|
||||
result["blocked"] = true
|
||||
result["blockRule"] = subdomain
|
||||
result["blockRuleType"] = "subdomain"
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// 检查正则表达式匹配
|
||||
for _, re := range m.regexRules {
|
||||
if re.pattern.MatchString(domain) {
|
||||
return true
|
||||
result["blocked"] = true
|
||||
result["blockRule"] = re.original
|
||||
result["blockRuleType"] = "regex"
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return result
|
||||
}
|
||||
|
||||
// IsBlocked 检查域名是否被屏蔽(保留原有方法以保持兼容性)
|
||||
func (m *ShieldManager) IsBlocked(domain string) bool {
|
||||
details := m.CheckDomainBlockDetails(domain)
|
||||
return details["blocked"].(bool)
|
||||
}
|
||||
|
||||
// RecordBlockedDomain 记录被屏蔽的域名
|
||||
|
||||
Reference in New Issue
Block a user