mirror of
https://github.com/Simple-Tracker/qBittorrent-ClientBlocker.git
synced 2025-01-08 11:47:54 +08:00
Bug fix
This commit is contained in:
parent
79bfbe69f8
commit
952484f6f8
36
config.go
36
config.go
@ -195,13 +195,13 @@ var config = ConfigStruct{
|
||||
BanByRelativePUAntiErrorRatio: 3,
|
||||
}
|
||||
|
||||
func SetBlockListFromContent(blockListContent []string) int {
|
||||
func SetBlockListFromContent(blockListContent []string, blockListSource string) int {
|
||||
setCount := 0
|
||||
|
||||
for index, content := range blockListContent {
|
||||
content = StrTrim(ProcessRemark(content))
|
||||
if content == "" {
|
||||
Log("Debug-SetBlockListFromContent_Compile", GetLangText("Error-Debug-EmptyLine"), false, index)
|
||||
Log("Debug-SetBlockListFromContent_Compile", GetLangText("Error-Debug-EmptyLine"), false, index, blockListSource)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -209,11 +209,11 @@ func SetBlockListFromContent(blockListContent []string) int {
|
||||
continue
|
||||
}
|
||||
|
||||
Log("Debug-SetBlockListFromContent_Compile", ":%d %s", false, index, content)
|
||||
Log("Debug-SetBlockListFromContent_Compile", ":%d %s (Source: %s)", false, index, content, blockListSource)
|
||||
|
||||
reg, err := regexp2.Compile("(?i)"+content, 0)
|
||||
if err != nil {
|
||||
Log("SetBlockListFromContent_Compile", GetLangText("Error-SetBlockListFromContent_Compile"), true, index, content)
|
||||
Log("SetBlockListFromContent_Compile", GetLangText("Error-SetBlockListFromContent_Compile"), true, index, content, blockListSource)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -272,7 +272,7 @@ func SetBlockListFromFile() bool {
|
||||
content = strings.Split(string(blockListContent), "\n")
|
||||
}
|
||||
|
||||
setCount += SetBlockListFromContent(content)
|
||||
setCount += SetBlockListFromContent(content, filePath)
|
||||
}
|
||||
|
||||
Log("SetBlockListFromFile", GetLangText("Success-SetBlockListFromFile"), true, setCount)
|
||||
@ -301,7 +301,7 @@ func SetBlockListFromURL() bool {
|
||||
}
|
||||
|
||||
var content []string
|
||||
if strings.HasSuffix(httpHeader.Get("Content-Type"), "json") {
|
||||
if strings.HasSuffix(strings.ToLower(strings.Split(httpHeader.Get("Content-Type"), ";")[0]), "json") {
|
||||
err := json.Unmarshal(blockListContent, &content)
|
||||
if err != nil {
|
||||
Log("SetBlockListFromFile", GetLangText("Error-GenJSON"), true, blockListURL)
|
||||
@ -311,19 +311,19 @@ func SetBlockListFromURL() bool {
|
||||
content = strings.Split(string(blockListContent), "\n")
|
||||
}
|
||||
|
||||
setCount += SetBlockListFromContent(content)
|
||||
setCount += SetBlockListFromContent(content, blockListURL)
|
||||
}
|
||||
|
||||
Log("SetBlockListFromURL", GetLangText("Success-SetBlockListFromURL"), true, setCount)
|
||||
return true
|
||||
}
|
||||
func SetIPBlockListFromContent(ipBlockListContent []string) int {
|
||||
func SetIPBlockListFromContent(ipBlockListContent []string, ipBlockListSource string) int {
|
||||
setCount := 0
|
||||
|
||||
for index, content := range ipBlockListContent {
|
||||
content = StrTrim(ProcessRemark(content))
|
||||
if content == "" {
|
||||
Log("Debug-SetIPBlockListFromContent_Compile", GetLangText("Error-Debug-EmptyLine"), false, index)
|
||||
Log("Debug-SetIPBlockListFromContent_Compile", GetLangText("Error-Debug-EmptyLine"), false, index, ipBlockListSource)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -331,10 +331,10 @@ func SetIPBlockListFromContent(ipBlockListContent []string) int {
|
||||
continue
|
||||
}
|
||||
|
||||
Log("Debug-SetIPBlockListFromContent_Compile", ":%d %s", false, index, content)
|
||||
Log("Debug-SetIPBlockListFromContent_Compile", ":%d %s (Source: %s)", false, index, content, ipBlockListSource)
|
||||
cidr := ParseIPCIDR(content)
|
||||
if cidr == nil {
|
||||
Log("SetIPBlockListFromContent_Compile", GetLangText("Error-SetIPBlockListFromContent_Compile"), true, index, content)
|
||||
Log("SetIPBlockListFromContent_Compile", GetLangText("Error-SetIPBlockListFromContent_Compile"), true, index, content, ipBlockListSource)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -385,7 +385,7 @@ func SetIPBlockListFromFile() bool {
|
||||
content = strings.Split(string(ipBlockListFile), "\n")
|
||||
}
|
||||
|
||||
setCount += SetIPBlockListFromContent(content)
|
||||
setCount += SetIPBlockListFromContent(content, filePath)
|
||||
}
|
||||
|
||||
Log("SetIPBlockListFromFile", GetLangText("Success-SetIPBlockListFromFile"), true, setCount)
|
||||
@ -422,7 +422,7 @@ func SetIPBlockListFromURL() bool {
|
||||
content = strings.Split(string(ipBlockListContent), "\n")
|
||||
}
|
||||
|
||||
setCount += SetIPBlockListFromContent(content)
|
||||
setCount += SetIPBlockListFromContent(content, ipBlockListURL)
|
||||
}
|
||||
|
||||
Log("SetIPBlockListFromURL", GetLangText("Success-SetIPBlockListFromURL"), true, setCount)
|
||||
@ -530,17 +530,11 @@ func InitConfig() {
|
||||
|
||||
blockListCompiled = make(map[string]*regexp2.Regexp)
|
||||
blockListURLLastFetch = 0
|
||||
SetBlockListFromContent(config.BlockList)
|
||||
if errCount := len(config.BlockList) != len(blockListCompiled); errCount {
|
||||
Log("LoadConfig_CompileBlockList", GetLangText("Error-CompileBlockList"), false, errCount)
|
||||
}
|
||||
SetBlockListFromContent(config.BlockList, "BlockList")
|
||||
|
||||
ipBlockListCompiled = make(map[string]*net.IPNet, len(config.IPBlockList))
|
||||
ipBlockListURLLastFetch = 0
|
||||
SetIPBlockListFromContent(config.IPBlockList)
|
||||
if errCount := len(config.IPBlockList) != len(ipBlockListCompiled); errCount {
|
||||
Log("LoadConfig_CompileIPBlockList", GetLangText("Error-CompileIPBlockList"), false, errCount)
|
||||
}
|
||||
SetIPBlockListFromContent(config.IPBlockList, "IPBlockList")
|
||||
}
|
||||
func LoadInitConfig(firstLoad bool) bool {
|
||||
loadConfigStatus := LoadConfig(configFilename, true)
|
||||
|
11
config.json
11
config.json
@ -12,25 +12,26 @@
|
||||
"clientPassword": "",
|
||||
"useBasicAuth": false,
|
||||
"skipCertVerification": false,
|
||||
"blockList": [],
|
||||
"blockListFile": [
|
||||
"blockList.json",
|
||||
// "blockList-Optional.json"
|
||||
//"blockList-Optional.json"
|
||||
],
|
||||
"blockListURL": [
|
||||
"https://bta.iaalai.cn/qBittorrent-ClientBlocker/blockList.json",
|
||||
"https://cdn.jsdelivr.net/gh/Simple-Tracker/qBittorrent-ClientBlocker@dev/blockList.json"
|
||||
],
|
||||
"portBlockList": [],
|
||||
"ipBlockList": [
|
||||
"ipBlockList": [],
|
||||
"ipBlockListFile": [
|
||||
"ipBlockList.txt"
|
||||
],
|
||||
"ipBlockListURL": [
|
||||
"https://bta.iaalai.cn/BTN-Collected-Rules/combine/all.txt",
|
||||
"https://cdn.jsdelivr.net/gh/PBH-BTN/BTN-Collected-Rules@main/combine/all.txt",
|
||||
"https://bta.iaalai.cn/BTN-Collected-Rules/qBittorrent-ClientBlocker/ipBlockList.txt",
|
||||
//"https://bta.iaalai.cn/BTN-Collected-Rules/qBittorrent-ClientBlocker/ipBlockList.txt",
|
||||
"https://cdn.jsdelivr.net/gh/Simple-Tracker/qBittorrent-ClientBlocker@dev/ipBlockList.txt"
|
||||
],
|
||||
"ipBlockListFile": []
|
||||
]
|
||||
/*
|
||||
"debug_CheckTorrent": false,
|
||||
"debug_CheckPeer": false,
|
||||
|
8
i18n.go
8
i18n.go
@ -55,12 +55,10 @@ var defaultLangContent = map[string]string{
|
||||
"Error-LoadConfig": "加载配置文件 (%s) 时发生了错误: %s",
|
||||
"Error-ParseConfig": "解析配置文件 (%s) 时发生了错误: %s",
|
||||
"Error-LoadFile": "加载文件 (%s) 时发生了错误: %s",
|
||||
"Error-CompileBlockList": "表达式存在 %d 处错误",
|
||||
"Error-CompileIPBlockList": "IP %s 有错误",
|
||||
"Error-GetClientConfig_LoadConfig": "加载客户端配置文件时发生了错误: %s",
|
||||
"Error-GetClientConfig_LoadConfigMeta": "读取客户端配置文件元数据时发生了错误: %s",
|
||||
"Error-SetBlocklistFromContent_Compile": ":%d 表达式 %s 有错误",
|
||||
"Error-SetIPBlockListFromContent_Compile": ":%d IP %s 有错误",
|
||||
"Error-SetBlockListFromContent_Compile": ":%d 表达式 %s 有错误 (来源: %s)",
|
||||
"Error-SetIPBlockListFromContent_Compile": ":%d IP %s 有错误 (来源: %s)",
|
||||
"Error-SyncWithServer_Compile": ":%d IP %s 有错误",
|
||||
"Error-RestartTorrentByMap_Stop": "停止 Torrent 时发生了错误: %s",
|
||||
"Error-RestartTorrentByMap_Start": "开始 Torrent 时发生了错误: %s",
|
||||
@ -99,7 +97,7 @@ var defaultLangContent = map[string]string{
|
||||
"Success-SetCSRFToken": "设置 CSRF Token 成功: %s",
|
||||
"Success-SetURL": "读取客户端配置文件成功 (WebUIEnabled: %t, URL: %s, Username: %s)",
|
||||
"Success-GenIPFilter": "生成了 %d 条 IP 规则",
|
||||
"Success-SetBlocklistFromURL": "设置了 %d 条 表达式 规则 (来源: BlockListURL)",
|
||||
"Success-SetBlockListFromURL": "设置了 %d 条 表达式 规则 (来源: BlockListURL)",
|
||||
"Success-SetIPBlockListFromURL": "设置了 %d 条 IP 规则 (来源: IPBlockListURL)",
|
||||
"Success-SetBlockListFromFile": "设置了 %d 条 表达式 规则 (来源: BlockListFile)",
|
||||
"Success-SetIPBlockListFromFile": "设置了 %d 条 IP 规则 (来源: IPBlockListFile)",
|
||||
|
@ -44,12 +44,10 @@
|
||||
"Error-LoadConfig": "An error occurred while loading config (%s): %s",
|
||||
"Error-ParseConfig": "An error occurred while parsing config (%s): %s",
|
||||
"Error-LoadFile": "An error occurred while parsing file (%s): %s",
|
||||
"Error-CompileBlockList": "Expression has %d error",
|
||||
"Error-CompileIPBlockList": "IP %s has error",
|
||||
"Error-GetClientConfig_LoadConfig": "An error occurred while loading client config file: %s",
|
||||
"Error-GetClientConfig_LoadConfigMeta": "An error occurred while reading client config file: %s",
|
||||
"Error-SetBlocklistFromContent_Compile": ":%d regexp %s has error",
|
||||
"Error-SetIPBlockListFromContent_Compile": ":%d IP %s has error",
|
||||
"Error-SetBlocklistFromContent_Compile": ":%d regexp %s has error (Source: %s)",
|
||||
"Error-SetIPBlockListFromContent_Compile": ":%d IP %s has error (Source: %s)",
|
||||
"Error-SyncWithServer_Compile": ":%d IP %s has error",
|
||||
"Error-RestartTorrentByMap_Stop": "An error occurred while stop torrent: %s",
|
||||
"Error-RestartTorrentByMap_Start": "An error occurred while start torrent: %s",
|
||||
|
Loading…
Reference in New Issue
Block a user