2020-10-08 22:14:07 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
go downloadDoubleThread()
|
|
|
|
}
|
|
|
|
|
|
|
|
//DoubleIndexFilter puts the domains inside file
|
2021-01-12 00:04:34 +01:00
|
|
|
func DoubleIndexFilter(durl string, configs stringarray) error {
|
2020-10-08 22:14:07 +02:00
|
|
|
|
2021-01-12 00:04:34 +01:00
|
|
|
fmt.Println("DoubleIndexFilter: Retrieving HostFile from: ", durl)
|
2020-10-08 22:14:07 +02:00
|
|
|
|
2021-01-12 13:35:36 +01:00
|
|
|
// resets malformed HostLines for url
|
|
|
|
setstatsvalue("Malformed HostLines "+durl, 0)
|
|
|
|
|
2020-10-08 22:14:07 +02:00
|
|
|
var err error
|
|
|
|
|
|
|
|
// Get the data
|
|
|
|
resp, err := http.Get(durl)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("HTTP problem: ", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
if resp.StatusCode == 200 { // OK
|
|
|
|
fmt.Println(durl + " Response: OK")
|
|
|
|
} else {
|
|
|
|
fmt.Println("Server <"+durl+"> returned status code: ", resp.StatusCode)
|
|
|
|
return errors.New("Server <" + durl + "> returned status code: " + resp.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(resp.Body)
|
|
|
|
splitter := func(c rune) bool {
|
|
|
|
return c == ' ' || c == '\t'
|
|
|
|
}
|
|
|
|
|
|
|
|
var numLines int64
|
|
|
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
|
|
|
line := scanner.Text()
|
|
|
|
|
2021-01-12 13:35:36 +01:00
|
|
|
if len(line) == 0 || strings.TrimSpace(line)[0] == '#' {
|
|
|
|
continue
|
|
|
|
}
|
2020-10-08 22:14:07 +02:00
|
|
|
h := strings.FieldsFunc(line, splitter)
|
|
|
|
|
|
|
|
if h == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(h) < 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if net.ParseIP(h[0]) != nil {
|
2021-01-12 00:04:34 +01:00
|
|
|
|
|
|
|
DomainKill(h[1], durl, configs)
|
2020-10-08 22:14:07 +02:00
|
|
|
|
|
|
|
// fmt.Println("MATCH: ", h[1])
|
|
|
|
numLines++
|
|
|
|
} else {
|
|
|
|
incrementStats("Malformed HostLines "+durl, 1)
|
|
|
|
// fmt.Println("Malformed line: <" + line + ">")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Finished to parse: "+durl+" ,number of lines", numLines)
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-12 00:04:34 +01:00
|
|
|
func getDoubleFilters(urls urlsMap) {
|
2020-10-08 22:14:07 +02:00
|
|
|
|
2021-01-12 00:04:34 +01:00
|
|
|
fmt.Println("getDoubleFilters: downloading all urls:", len(urls))
|
|
|
|
for url, configs := range urls {
|
|
|
|
DoubleIndexFilter(url, configs)
|
2020-10-08 22:14:07 +02:00
|
|
|
}
|
2021-01-13 22:30:04 +01:00
|
|
|
fmt.Println("getDoubleFilters: DONE!")
|
2020-10-08 22:14:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func downloadDoubleThread() {
|
|
|
|
fmt.Println("Starting updater of DOUBLE lists, each (hours):", ZabovKillTTL)
|
2021-01-12 00:04:34 +01:00
|
|
|
|
|
|
|
_urls := urlsMap{}
|
|
|
|
|
2020-10-08 22:14:07 +02:00
|
|
|
for {
|
2021-01-12 00:04:34 +01:00
|
|
|
fmt.Println("downloadDoubleThread: collecting urls from all configs...")
|
|
|
|
for config := range ZabovConfigs {
|
|
|
|
ZabovDoubleBL := ZabovConfigs[config].ZabovDoubleBL
|
2021-01-13 23:38:33 +01:00
|
|
|
if len(ZabovDoubleBL) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
2021-01-12 00:04:34 +01:00
|
|
|
s := fileByLines(ZabovDoubleBL)
|
|
|
|
for _, v := range s {
|
|
|
|
configs := _urls[v]
|
|
|
|
if configs == nil {
|
|
|
|
configs = stringarray{}
|
|
|
|
_urls[v] = configs
|
|
|
|
}
|
|
|
|
configs = append(configs, config)
|
|
|
|
_urls[v] = configs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getDoubleFilters(_urls)
|
2020-10-08 22:14:07 +02:00
|
|
|
time.Sleep(time.Duration(ZabovKillTTL) * time.Hour)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|