This commit is contained in:
YouROK
2021-04-27 09:01:09 +03:00
parent b1653549a3
commit 5f4b702a1a

View File

@@ -23,21 +23,12 @@ func Blocker() gin.HandlerFunc {
} }
name := filepath.Join(settings.Path, "bip.txt") name := filepath.Join(settings.Path, "bip.txt")
buf, err := ioutil.ReadFile(name) buf, _ := ioutil.ReadFile(name)
if err != nil {
return emptyFN
}
blackIpList := scanBuf(buf) blackIpList := scanBuf(buf)
name = filepath.Join(settings.Path, "wip.txt") name = filepath.Join(settings.Path, "wip.txt")
buf, err = ioutil.ReadFile(name) buf, _ = ioutil.ReadFile(name)
if err != nil {
return emptyFN
}
whiteIpList := scanBuf(buf) whiteIpList := scanBuf(buf)
if blackIpList.NumRanges() == 0 {
return emptyFN
}
if blackIpList.NumRanges() == 0 && whiteIpList.NumRanges() == 0 { if blackIpList.NumRanges() == 0 && whiteIpList.NumRanges() == 0 {
return emptyFN return emptyFN
@@ -70,8 +61,11 @@ func Blocker() gin.HandlerFunc {
} }
func scanBuf(buf []byte) iplist.Ranger { func scanBuf(buf []byte) iplist.Ranger {
scanner := bufio.NewScanner(strings.NewReader(string(buf))) if len(buf) == 0 {
return iplist.New(nil)
}
var ranges []iplist.Range var ranges []iplist.Range
scanner := bufio.NewScanner(strings.NewReader(string(buf)))
for scanner.Scan() { for scanner.Scan() {
r, ok, err := parseLine(scanner.Bytes()) r, ok, err := parseLine(scanner.Bytes())
if err != nil { if err != nil {