2020-10-08 15:14:07 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type killfileItem struct {
|
2021-01-11 17:04:34 -06:00
|
|
|
Kdomain string
|
|
|
|
Ksource string
|
|
|
|
Kconfigs stringarray
|
2020-10-08 15:14:07 -05:00
|
|
|
}
|
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
var bKillChannel chan killfileItem
|
|
|
|
var bWhiteListChannel chan killfileItem
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
bKillChannel = make(chan killfileItem, 1024)
|
|
|
|
bWhiteListChannel = make(chan killfileItem, 1024)
|
2020-10-08 15:14:07 -05:00
|
|
|
fmt.Println("Initializing kill channel engine.")
|
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
go bWriteKillThread()
|
|
|
|
go bWriteWhiteListThread()
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
func bWriteKillThread() {
|
2020-10-08 15:14:07 -05:00
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
for item := range bKillChannel {
|
2020-10-08 15:14:07 -05:00
|
|
|
|
2021-01-12 06:35:36 -06:00
|
|
|
alreadyInSomeDB := false
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
for _, config := range item.Kconfigs {
|
2021-01-12 06:35:36 -06:00
|
|
|
if !alreadyInSomeDB {
|
|
|
|
alreadyInSomeDB = domainInKillfile(item.Kdomain, config)
|
|
|
|
}
|
2021-01-11 17:04:34 -06:00
|
|
|
writeInKillfile(item.Kdomain, item.Ksource, config)
|
|
|
|
}
|
2021-01-12 06:35:36 -06:00
|
|
|
if !alreadyInSomeDB {
|
|
|
|
incrementStats("BL domains from "+item.Ksource, 1)
|
|
|
|
incrementStats("TOTAL", 1)
|
|
|
|
}
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//DomainKill stores a domain name inside the killfile
|
2021-01-11 17:04:34 -06:00
|
|
|
func DomainKill(s, durl string, configs stringarray) {
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
if len(s) > 2 {
|
|
|
|
|
|
|
|
s = strings.ToLower(s)
|
|
|
|
|
|
|
|
var k killfileItem
|
|
|
|
|
|
|
|
k.Kdomain = s
|
|
|
|
k.Ksource = durl
|
2021-01-11 17:04:34 -06:00
|
|
|
k.Kconfigs = configs
|
2020-10-08 15:14:07 -05:00
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
bKillChannel <- k
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
func writeInKillfile(key, value string, config string) {
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
stK := []byte(key)
|
|
|
|
stV := []byte(value)
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
MyZabovKDB := MyZabovKDBs[config]
|
2020-10-08 15:14:07 -05:00
|
|
|
err := MyZabovKDB.Put(stK, stV, nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Cannot write to Killfile DB: ", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
func domainInKillfile(domain string, config string) bool {
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
s := strings.ToLower(domain)
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
MyZabovKDB := MyZabovKDBs[config]
|
2020-10-08 15:14:07 -05:00
|
|
|
has, err := MyZabovKDB.Has([]byte(s), nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Cannot read from Killfile DB: ", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return has
|
|
|
|
|
|
|
|
}
|
2021-05-11 03:32:48 -05:00
|
|
|
|
|
|
|
func bWriteWhiteListThread() {
|
|
|
|
|
|
|
|
for item := range bWhiteListChannel {
|
|
|
|
|
|
|
|
alreadyInSomeDB := false
|
|
|
|
|
|
|
|
for _, config := range item.Kconfigs {
|
|
|
|
if !alreadyInSomeDB {
|
|
|
|
alreadyInSomeDB = domainInWhiteListfile(item.Kdomain, config)
|
|
|
|
}
|
|
|
|
writeInWhiteListfile(item.Kdomain, item.Ksource, config)
|
|
|
|
}
|
|
|
|
if !alreadyInSomeDB {
|
|
|
|
incrementStats("WL domains from "+item.Ksource, 1)
|
|
|
|
incrementStats("WL TOTAL", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//DomainWhiteList stores a domain name inside the killfile
|
|
|
|
func DomainWhiteList(s, durl string, configs stringarray) {
|
|
|
|
|
|
|
|
if len(s) > 2 {
|
|
|
|
|
|
|
|
s = strings.ToLower(s)
|
|
|
|
|
|
|
|
var k killfileItem
|
|
|
|
|
|
|
|
k.Kdomain = s
|
|
|
|
k.Ksource = durl
|
|
|
|
k.Kconfigs = configs
|
|
|
|
|
|
|
|
bWhiteListChannel <- k
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeInWhiteListfile(key, value string, config string) {
|
|
|
|
|
|
|
|
stK := []byte(key)
|
|
|
|
stV := []byte(value)
|
|
|
|
|
|
|
|
MyZabovWLDB := MyZabovWLDBs[config]
|
|
|
|
err := MyZabovWLDB.Put(stK, stV, nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Cannot write to Whitelist DB: ", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
func domainInWhiteListfile(domain string, config string) bool {
|
|
|
|
|
|
|
|
s := strings.ToLower(domain)
|
|
|
|
|
|
|
|
MyZabovWLDB := MyZabovWLDBs[config]
|
|
|
|
has, err := MyZabovWLDB.Has([]byte(s), nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Cannot read from Whitelist DB: ", err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return has
|
|
|
|
|
|
|
|
}
|