2020-10-08 15:14:07 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
go downloadThread()
|
|
|
|
}
|
|
|
|
|
|
|
|
//SingleIndexFilter puts the domains inside file
|
2021-01-11 17:04:34 -06:00
|
|
|
func SingleIndexFilter(durl string, configs stringarray) error {
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
fmt.Println("Retrieving DomainFile from: ", durl)
|
|
|
|
|
2021-01-12 06:35:36 -06:00
|
|
|
// resets malformed HostLines for url
|
|
|
|
setstatsvalue("Malformed DomainLines "+durl, 0)
|
|
|
|
|
2020-10-08 15:14:07 -05: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 06:35:36 -06:00
|
|
|
if len(line) == 0 || strings.TrimSpace(line)[0] == '#' {
|
|
|
|
continue
|
|
|
|
}
|
2020-10-08 15:14:07 -05:00
|
|
|
h := strings.FieldsFunc(line, splitter)
|
|
|
|
|
|
|
|
if h == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(h) < 1 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(h[0], "#") {
|
2021-01-11 17:04:34 -06:00
|
|
|
|
|
|
|
DomainKill(h[0], durl, configs)
|
|
|
|
|
2020-10-08 15:14:07 -05:00
|
|
|
// fmt.Println("MATCH: ", h[1])
|
|
|
|
numLines++
|
|
|
|
} else {
|
|
|
|
incrementStats("Malformed DomainLines "+durl, 1)
|
|
|
|
// fmt.Println("Malformed line: <" + line + ">")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Finished to parse: "+durl+" ,number of lines", numLines)
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
func getSingleFilters(urls urlsMap) {
|
2020-10-08 15:14:07 -05:00
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
fmt.Println("getSingleFilters: downloading all urls:", len(urls))
|
|
|
|
for url, configs := range urls {
|
|
|
|
SingleIndexFilter(url, configs)
|
2020-10-08 15:14:07 -05:00
|
|
|
}
|
2021-01-13 15:30:04 -06:00
|
|
|
fmt.Println("getSingleFilters: DONE!")
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func downloadThread() {
|
|
|
|
fmt.Println("Starting updater of SINGLE lists, each (hours): ", ZabovKillTTL)
|
2021-01-14 13:25:10 -06:00
|
|
|
time.Sleep(2 * time.Second) // wait for local DNS server up & running (may be our DNS)
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
_urls := urlsMap{}
|
|
|
|
|
2020-10-08 15:14:07 -05:00
|
|
|
for {
|
2021-01-11 17:04:34 -06:00
|
|
|
fmt.Println("downloadThread: collecting urls from all configs...")
|
|
|
|
for config := range ZabovConfigs {
|
|
|
|
ZabovSingleBL := ZabovConfigs[config].ZabovSingleBL
|
|
|
|
|
2021-01-13 16:38:33 -06:00
|
|
|
if len(ZabovSingleBL) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
s := fileByLines(ZabovSingleBL)
|
|
|
|
for _, v := range s {
|
2021-01-15 06:28:15 -06:00
|
|
|
if len(v) == 0 || strings.TrimSpace(v)[0] == '#' {
|
|
|
|
continue
|
|
|
|
}
|
2021-01-11 17:04:34 -06:00
|
|
|
configs := _urls[v]
|
|
|
|
if configs == nil {
|
|
|
|
configs = stringarray{}
|
|
|
|
_urls[v] = configs
|
|
|
|
}
|
|
|
|
configs = append(configs, config)
|
|
|
|
_urls[v] = configs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getSingleFilters(_urls)
|
2020-10-08 15:14:07 -05:00
|
|
|
time.Sleep(time.Duration(ZabovKillTTL) * time.Hour)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|