2020-10-08 22:14:07 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
fmt.Println("Ingesting local hosts file")
|
2021-01-12 00:04:34 +01:00
|
|
|
ingestLocalBlacklists()
|
2020-10-08 22:14:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-12 00:04:34 +01:00
|
|
|
func ingestLocalBlacklists() {
|
|
|
|
|
|
|
|
fmt.Println("ingestLocalBlacklist: collecting urls from all configs...")
|
|
|
|
_files := urlsMap{}
|
|
|
|
for config := range ZabovConfigs {
|
|
|
|
ZabovHostsFile := ZabovConfigs[config].ZabovHostsFile
|
2021-01-13 23:38:33 +01:00
|
|
|
if len(ZabovHostsFile) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2021-01-12 00:04:34 +01:00
|
|
|
configs := _files[ZabovHostsFile]
|
|
|
|
if configs == nil {
|
|
|
|
configs = stringarray{}
|
|
|
|
_files[ZabovHostsFile] = configs
|
|
|
|
}
|
|
|
|
configs = append(configs, config)
|
|
|
|
_files[ZabovHostsFile] = configs
|
2020-10-08 22:14:07 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 00:04:34 +01:00
|
|
|
for ZabovHostsFile, configs := range _files {
|
|
|
|
file, err := os.Open(ZabovHostsFile)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
defer file.Close()
|
2020-10-08 22:14:07 +02:00
|
|
|
|
2021-01-12 00:04:34 +01:00
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
|
|
d := scanner.Text()
|
|
|
|
DomainKill(d, ZabovHostsFile, configs)
|
|
|
|
incrementStats("Blacklist", 1)
|
2020-10-08 22:14:07 +02:00
|
|
|
|
2021-01-12 00:04:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
2020-10-08 22:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func fileByLines(filename string) (blurls []string) {
|
|
|
|
|
|
|
|
file, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
|
|
d := scanner.Text()
|
|
|
|
blurls = append(blurls, d)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|