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