增加了API断电
This commit is contained in:
@@ -1275,6 +1275,131 @@ func (m *ShieldManager) GetHostsCount() int {
|
||||
return len(m.hostsMap)
|
||||
}
|
||||
|
||||
// GetLocalRules 获取仅本地规则
|
||||
func (m *ShieldManager) GetLocalRules() map[string]interface{} {
|
||||
m.rulesMutex.RLock()
|
||||
defer m.rulesMutex.RUnlock()
|
||||
|
||||
// 转换map和slice为字符串列表,只包含本地规则
|
||||
domainRulesList := make([]string, 0)
|
||||
for domain, isLocal := range m.domainRulesIsLocal {
|
||||
if isLocal && m.domainRules[domain] {
|
||||
domainRulesList = append(domainRulesList, "||"+domain+"^")
|
||||
}
|
||||
}
|
||||
|
||||
domainExceptionsList := make([]string, 0)
|
||||
for domain, isLocal := range m.domainExceptionsIsLocal {
|
||||
if isLocal && m.domainExceptions[domain] {
|
||||
domainExceptionsList = append(domainExceptionsList, "@@||"+domain+"^")
|
||||
}
|
||||
}
|
||||
|
||||
// 获取本地正则规则原始字符串
|
||||
regexRulesList := make([]string, 0)
|
||||
for _, re := range m.regexRules {
|
||||
if re.isLocal {
|
||||
regexRulesList = append(regexRulesList, re.original)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取本地正则排除规则原始字符串
|
||||
regexExceptionsList := make([]string, 0)
|
||||
for _, re := range m.regexExceptions {
|
||||
if re.isLocal {
|
||||
regexExceptionsList = append(regexExceptionsList, re.original)
|
||||
}
|
||||
}
|
||||
|
||||
// 计算本地规则数量
|
||||
localDomainRulesCount := 0
|
||||
for _, isLocal := range m.domainRulesIsLocal {
|
||||
if isLocal {
|
||||
localDomainRulesCount++
|
||||
}
|
||||
}
|
||||
localRegexRulesCount := 0
|
||||
for _, re := range m.regexRules {
|
||||
if re.isLocal {
|
||||
localRegexRulesCount++
|
||||
}
|
||||
}
|
||||
localRulesCount := localDomainRulesCount + localRegexRulesCount
|
||||
|
||||
return map[string]interface{}{
|
||||
"domainRules": domainRulesList,
|
||||
"domainExceptions": domainExceptionsList,
|
||||
"regexRules": regexRulesList,
|
||||
"regexExceptions": regexExceptionsList,
|
||||
"localRulesCount": localRulesCount,
|
||||
"localDomainRulesCount": localDomainRulesCount,
|
||||
"localRegexRulesCount": localRegexRulesCount,
|
||||
}
|
||||
}
|
||||
|
||||
// GetRemoteRules 获取仅远程规则
|
||||
func (m *ShieldManager) GetRemoteRules() map[string]interface{} {
|
||||
m.rulesMutex.RLock()
|
||||
defer m.rulesMutex.RUnlock()
|
||||
|
||||
// 转换map和slice为字符串列表,只包含远程规则
|
||||
domainRulesList := make([]string, 0)
|
||||
for domain, isLocal := range m.domainRulesIsLocal {
|
||||
if !isLocal && m.domainRules[domain] {
|
||||
domainRulesList = append(domainRulesList, "||"+domain+"^")
|
||||
}
|
||||
}
|
||||
|
||||
domainExceptionsList := make([]string, 0)
|
||||
for domain, isLocal := range m.domainExceptionsIsLocal {
|
||||
if !isLocal && m.domainExceptions[domain] {
|
||||
domainExceptionsList = append(domainExceptionsList, "@@||"+domain+"^")
|
||||
}
|
||||
}
|
||||
|
||||
// 获取远程正则规则原始字符串
|
||||
regexRulesList := make([]string, 0)
|
||||
for _, re := range m.regexRules {
|
||||
if !re.isLocal {
|
||||
regexRulesList = append(regexRulesList, re.original)
|
||||
}
|
||||
}
|
||||
|
||||
// 获取远程正则排除规则原始字符串
|
||||
regexExceptionsList := make([]string, 0)
|
||||
for _, re := range m.regexExceptions {
|
||||
if !re.isLocal {
|
||||
regexExceptionsList = append(regexExceptionsList, re.original)
|
||||
}
|
||||
}
|
||||
|
||||
// 计算远程规则数量
|
||||
remoteDomainRulesCount := 0
|
||||
for _, isLocal := range m.domainRulesIsLocal {
|
||||
if !isLocal {
|
||||
remoteDomainRulesCount++
|
||||
}
|
||||
}
|
||||
remoteRegexRulesCount := 0
|
||||
for _, re := range m.regexRules {
|
||||
if !re.isLocal {
|
||||
remoteRegexRulesCount++
|
||||
}
|
||||
}
|
||||
remoteRulesCount := remoteDomainRulesCount + remoteRegexRulesCount
|
||||
|
||||
return map[string]interface{}{
|
||||
"domainRules": domainRulesList,
|
||||
"domainExceptions": domainExceptionsList,
|
||||
"regexRules": regexRulesList,
|
||||
"regexExceptions": regexExceptionsList,
|
||||
"remoteRulesCount": remoteRulesCount,
|
||||
"remoteDomainRulesCount": remoteDomainRulesCount,
|
||||
"remoteRegexRulesCount": remoteRegexRulesCount,
|
||||
"blacklists": m.config.Blacklists,
|
||||
}
|
||||
}
|
||||
|
||||
// GetRules 获取所有规则
|
||||
func (m *ShieldManager) GetRules() map[string]interface{} {
|
||||
m.rulesMutex.RLock()
|
||||
|
||||
Reference in New Issue
Block a user