2020-10-08 15:14:07 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-01-15 06:28:15 -06:00
|
|
|
"strings"
|
2020-10-08 15:14:07 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
fmt.Println("Ingesting local hosts file")
|
2021-01-11 17:04:34 -06:00
|
|
|
ingestLocalBlacklists()
|
2021-05-11 03:32:48 -05:00
|
|
|
ingestLocalWhiteLists()
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
func ingestLocalBlacklists() {
|
|
|
|
|
|
|
|
fmt.Println("ingestLocalBlacklist: collecting urls from all configs...")
|
2021-05-11 03:32:48 -05:00
|
|
|
_HostsFiles := urlsMap{}
|
2021-01-11 17:04:34 -06:00
|
|
|
for config := range ZabovConfigs {
|
|
|
|
ZabovHostsFile := ZabovConfigs[config].ZabovHostsFile
|
2021-01-13 16:38:33 -06:00
|
|
|
if len(ZabovHostsFile) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2021-05-11 03:32:48 -05:00
|
|
|
configs := _HostsFiles[ZabovHostsFile]
|
2021-01-11 17:04:34 -06:00
|
|
|
if configs == nil {
|
|
|
|
configs = stringarray{}
|
2021-05-11 03:32:48 -05:00
|
|
|
_HostsFiles[ZabovHostsFile] = configs
|
2021-01-11 17:04:34 -06:00
|
|
|
}
|
|
|
|
configs = append(configs, config)
|
2021-05-11 03:32:48 -05:00
|
|
|
_HostsFiles[ZabovHostsFile] = configs
|
2020-10-08 15:14:07 -05:00
|
|
|
}
|
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
for ZabovHostsFile, configs := range _HostsFiles {
|
2021-01-11 17:04:34 -06:00
|
|
|
file, err := os.Open(ZabovHostsFile)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
defer file.Close()
|
2020-10-08 15:14:07 -05:00
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
|
|
d := scanner.Text()
|
2021-01-15 06:28:15 -06:00
|
|
|
if len(d) == 0 || strings.TrimSpace(d)[0] == '#' {
|
|
|
|
continue
|
|
|
|
}
|
2021-01-11 17:04:34 -06:00
|
|
|
DomainKill(d, ZabovHostsFile, configs)
|
|
|
|
incrementStats("Blacklist", 1)
|
2020-10-08 15:14:07 -05:00
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
2020-10-08 15:14:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
func ingestLocalWhiteLists() {
|
|
|
|
|
|
|
|
fmt.Println("ingestLocalWhiteLists: collecting urls from all configs...")
|
|
|
|
_WhiteListFiles := urlsMap{}
|
|
|
|
for config := range ZabovConfigs {
|
|
|
|
ZabovWhiteList := ZabovConfigs[config].ZabovWhiteList
|
|
|
|
if len(ZabovWhiteList) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
configs := _WhiteListFiles[ZabovWhiteList]
|
|
|
|
if configs == nil {
|
|
|
|
configs = stringarray{}
|
|
|
|
_WhiteListFiles[ZabovWhiteList] = configs
|
|
|
|
}
|
|
|
|
configs = append(configs, config)
|
|
|
|
_WhiteListFiles[ZabovWhiteList] = configs
|
|
|
|
}
|
|
|
|
|
|
|
|
for ZabovWhiteList, configs := range _WhiteListFiles {
|
|
|
|
file, err := os.Open(ZabovWhiteList)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
|
|
d := scanner.Text()
|
|
|
|
if len(d) == 0 || strings.TrimSpace(d)[0] == '#' {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
DomainWhiteList(d, ZabovWhiteList, configs)
|
|
|
|
incrementStats("WhiteList", 1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-08 15:14:07 -05: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
|
|
|
|
|
|
|
|
}
|