Compare commits

..

2 Commits

Author SHA1 Message Date
bloved 0752a7e443 - FIX: Query logger: moved to different thread to serialize access to log file 2021-01-17 16:15:12 +01:00
bloved 749029ba5b - FIX: optional settings were not optional
- Dockerfile: updated golang image to 1.15.6
- config.json: restored minimal settings
- added config.sample.json with all advanced settings
- urls-domains-updated.txt: removed/updated obsolete urls (CHEF-KOCH, malwaredomains.com)
2021-01-17 15:28:20 +01:00
9 changed files with 218 additions and 165 deletions

View File

@ -40,7 +40,7 @@ func ZabovCreateKDB(conf string) {
if err != nil { if err != nil {
fmt.Println("Cannot create Killfile db: ", err.Error()) fmt.Println("Cannot create Killfile db: ", err.Error())
} else { } else {
fmt.Println("Killfile DB created") fmt.Println("Killfile DB created:", dbname)
} }
MyZabovKDBs[conf] = KDB MyZabovKDBs[conf] = KDB

View File

@ -88,12 +88,14 @@ func init() {
//******************* //*******************
// IP aliases section // IP aliases section
//******************* //*******************
if MyConf["ipaliases"] != nil {
IPAliasesRaw := MyConf["ipaliases"].(map[string]interface{}) IPAliasesRaw := MyConf["ipaliases"].(map[string]interface{})
for alias, ip := range IPAliasesRaw { for alias, ip := range IPAliasesRaw {
fmt.Println("IP Alias:", alias, ip) fmt.Println("IP Alias:", alias, ip)
ZabovIPAliases[alias] = ip.(string) ZabovIPAliases[alias] = ip.(string)
} }
}
//**************** //****************
// configs section // configs section
@ -119,6 +121,7 @@ func init() {
//******************* //*******************
// timetables section // timetables section
//******************* //*******************
if MyConf["timetables"] != nil {
timetables := MyConf["timetables"].(map[string]interface{}) timetables := MyConf["timetables"].(map[string]interface{})
for name, v := range timetables { for name, v := range timetables {
@ -186,10 +189,12 @@ func init() {
} }
ZabovTimetables[name] = &timetable ZabovTimetables[name] = &timetable
} }
}
//****************** //******************
// IP groups section // IP groups section
//****************** //******************
if MyConf["ipgroups"] != nil {
IPGroups := MyConf["ipgroups"].([]interface{}) IPGroups := MyConf["ipgroups"].([]interface{})
fmt.Println("evaluating IP Groups: ", len(IPGroups)) fmt.Println("evaluating IP Groups: ", len(IPGroups))
@ -231,6 +236,7 @@ func init() {
} }
ZabovIPGroups = append(ZabovIPGroups, groupStruct) ZabovIPGroups = append(ZabovIPGroups, groupStruct)
} }
}
if zabov["timetable"] != nil { if zabov["timetable"] != nil {
ZabovDefaultTimetable = zabov["timetable"].(string) ZabovDefaultTimetable = zabov["timetable"].(string)
@ -244,6 +250,7 @@ func init() {
//************************ //************************
// Local responser section // Local responser section
//************************ //************************
if MyConf["localresponder"] != nil {
localresponder := MyConf["localresponder"].(map[string]interface{}) localresponder := MyConf["localresponder"].(map[string]interface{})
if localresponder != nil { if localresponder != nil {
@ -259,9 +266,9 @@ func init() {
ZabovLocalDomain = localresponder["localdomain"].(string) ZabovLocalDomain = localresponder["localdomain"].(string)
} }
} }
}
//****************************************** //******************************************
// clearing unused config to save resources // clearing unused configs to save resources
//****************************************** //******************************************
for name, conf := range ZabovConfigs { for name, conf := range ZabovConfigs {
if conf.references == 0 { if conf.references == 0 {

View File

@ -1,4 +1,4 @@
FROM golang:1.14.1 AS builder FROM arm64v8/golang:1.15.6 AS builder
RUN apt install git -y RUN apt install git -y
RUN mkdir -p /go/src/zabov RUN mkdir -p /go/src/zabov
RUN git clone https://git.keinpfusch.net/loweel/zabov /go/src/zabov RUN git clone https://git.keinpfusch.net/loweel/zabov /go/src/zabov
@ -17,4 +17,3 @@ COPY --from=builder /go/src/zabov /opt/zabov
EXPOSE 53/udp EXPOSE 53/udp
ENV TZ Europe/Rome ENV TZ Europe/Rome
ENTRYPOINT ["/opt/zabov/zabov"] ENTRYPOINT ["/opt/zabov/zabov"]

View File

@ -1,4 +1,4 @@
FROM arm32v7/golang:1.14.1 AS builder FROM arm64v8/golang:1.15.6 AS builder
RUN apt install git -y RUN apt install git -y
RUN mkdir -p /go/src/zabov RUN mkdir -p /go/src/zabov
RUN git clone https://git.keinpfusch.net/loweel/zabov /go/src/zabov RUN git clone https://git.keinpfusch.net/loweel/zabov /go/src/zabov

View File

@ -1,4 +1,4 @@
FROM arm64v8/golang:1.14.1 AS builder FROM arm64v8/golang:1.15.6 AS builder
RUN apt install git -y RUN apt install git -y
RUN mkdir -p /go/src/zabov RUN mkdir -p /go/src/zabov
RUN git clone https://git.keinpfusch.net/loweel/zabov /go/src/zabov RUN git clone https://git.keinpfusch.net/loweel/zabov /go/src/zabov

View File

@ -6,28 +6,6 @@
"cachettl": 1, "cachettl": 1,
"killfilettl": 12 "killfilettl": 12
}, },
"localresponder":{
"responder":"192.168.178.1:53",
"localdomain":"fritz.box"
},
"ipaliases":{
"pc8":"192.168.178.29",
"localhost":"127.0.0.1"
},
"ipgroups":[
{
"ips":["localhost", "::1", "192.168.178.30", "192.168.178.31", "pc8"],
"cfg":"",
"timetable":"tt_children"
}
],
"timetables":{
"tt_children":{
"tables":[{"times":"00:00-05:00;8:30-12:30;18:30-22:59", "days":"Mo;Tu;We;Th;Fr;Sa;Su"}],
"cfgin":"children_restricted",
"cfgout":"children"
}
},
"configs":{ "configs":{
"default":{ "default":{
"upstream":"./dns-upstream.txt", "upstream":"./dns-upstream.txt",
@ -35,21 +13,6 @@
"doublefilters":"./urls-hosts.txt", "doublefilters":"./urls-hosts.txt",
"blackholeip":"127.0.0.1", "blackholeip":"127.0.0.1",
"hostsfile":"./urls-local.txt" "hostsfile":"./urls-local.txt"
},
"children":{
"upstream":"./dns-upstream.txt",
"singlefilters":"./urls-domains.txt",
"doublefilters":"./urls-hosts.txt",
"blackholeip":"127.0.0.1",
"hostsfile":"./urls-local.txt"
},
"children_restricted":{
"upstream":"./dns-upstream.txt",
"singlefilters":"./urls-domains.txt",
"doublefilters":"./urls-hosts.txt",
"blackholeip":"127.0.0.1",
"hostsfile":"./urls-local.txt"
} }
} }
} }

57
config.sample.json Normal file
View File

@ -0,0 +1,57 @@
{
"zabov":{
"port":"53",
"proto":"udp",
"ipaddr":"0.0.0.0",
"cachettl": 1,
"killfilettl": 12,
"debug":"true",
"debugdbpath":"./logs",
"timetable":""
},
"localresponder":{
"responder":"192.168.1.1:53",
"localdomain":".local"
},
"ipaliases":{
"pc8":"192.168.1.2",
},
"ipgroups":[
{
"ips":["pc8"],
"cfg":"",
"timetable":"tt_children"
}
],
"timetables":{
"tt_children":{
"tables":[{"times":"9:30-11:30", "days":"Mo;Tu;We;Th;Fr;Sa"}],
"cfgin":"children_restricted",
"cfgout":"children"
}
},
"configs":{
"default":{
"upstream":"./dns-upstream.txt",
"singlefilters":"./urls-domains-updated.txt",
"doublefilters":"./urls-hosts-normal.txt",
"blackholeip":"127.0.0.1",
"hostsfile":"./urls-local-normal.txt"
},
"children":{
"upstream":"./dns-familyscreen.txt",
"singlefilters":"./urls-domains-updated.txt",
"doublefilters":"./urls-hosts-nofb.txt",
"blackholeip":"127.0.0.1",
"hostsfile":"./urls-local-normal.txt"
},
"children_restricted":{
"upstream":"./dns-familyscreen.txt",
"singlefilters":"./urls-domains-updated.txt",
"doublefilters":"./urls-hosts-nofb.txt",
"blackholeip":"127.0.0.1",
"hostsfile":"./urls-local-restricted.txt"
}
}
}

View File

@ -16,7 +16,20 @@ var reqTypes map[uint16]string
var weekdays []string var weekdays []string
type logItem struct {
clientIP string
name string
reqType uint16
config string
timetable string
killed string
}
// logChannel used by logging thread
var logChannel chan logItem
func init() { func init() {
weekdays = []string{"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"} weekdays = []string{"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}
if len(ZabovDebugDBPath) > 0 { if len(ZabovDebugDBPath) > 0 {
@ -107,13 +120,18 @@ func init() {
dns.TypeReserved: "TypeReserved"} dns.TypeReserved: "TypeReserved"}
fmt.Println("Local Time:", getLocalTime().Format(time.ANSIC)) fmt.Println("Local Time:", getLocalTime().Format(time.ANSIC))
if len(ZabovDebugDBPath) > 0 {
logChannel = make(chan logItem, 1024)
go logWriteThread()
}
} }
func logQuery(clientIP string, name string, reqType uint16, config string, timetable string, killed string) { func logWriteThread() {
if len(ZabovDebugDBPath) > 0 { for item := range logChannel {
var header string var header string
d := time.Now().Format("2006-01-02") d := time.Now().Format("2006-01-02")
logpath := path.Join(ZabovDebugDBPath, strings.Replace(clientIP, ":", "_", -1)+"-"+d+".log") logpath := path.Join(ZabovDebugDBPath, strings.Replace(item.clientIP, ":", "_", -1)+"-"+d+".log")
_, err1 := os.Stat(logpath) _, err1 := os.Stat(logpath)
if os.IsNotExist(err1) { if os.IsNotExist(err1) {
@ -121,12 +139,12 @@ func logQuery(clientIP string, name string, reqType uint16, config string, timet
} }
f, err := os.OpenFile(logpath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) f, err := os.OpenFile(logpath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err == nil { if err == nil {
reqTypeName, err := reqTypes[reqType] reqTypeName, err := reqTypes[item.reqType]
if !err { if !err {
reqTypeName = fmt.Sprintf("%d", reqType) reqTypeName = fmt.Sprintf("%d", item.reqType)
} }
ct := time.Now().Format(time.RFC3339) ct := time.Now().Format(time.RFC3339)
log := strings.Join([]string{ct, clientIP, strings.TrimRight(name, "."), reqTypeName, config, timetable, killed}, "\t") log := strings.Join([]string{ct, item.clientIP, strings.TrimRight(item.name, "."), reqTypeName, item.config, item.timetable, item.killed}, "\t")
if len(header) > 0 { if len(header) > 0 {
f.Write([]byte(header)) f.Write([]byte(header))
f.Write([]byte("\n")) f.Write([]byte("\n"))
@ -138,6 +156,15 @@ func logQuery(clientIP string, name string, reqType uint16, config string, timet
} }
} }
func logQuery(clientIP string, name string, reqType uint16, config string, timetable string, killed string) {
if len(ZabovDebugDBPath) > 0 {
k := logItem{clientIP: clientIP, name: name, reqType: reqType, config: config, timetable: timetable, killed: killed}
logChannel <- k
}
}
func getLocalTime() time.Time { func getLocalTime() time.Time {
return time.Now().Local() return time.Now().Local()
} }

View File

@ -1,12 +1,8 @@
https://mirror1.malwaredomains.com/files/justdomains
https://raw.githubusercontent.com/hectorm/hmirror/master/data/adaway.org/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/adaway.org/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/adblock-nocoin-list/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/adblock-nocoin-list/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/adguard-simplified/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/adguard-simplified/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/anudeepnd-adservers/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/antipopads/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/disconnect.me-ad/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/digitalside-threat-intel/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/disconnect.me-malvertising/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/disconnect.me-malware/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/disconnect.me-tracking/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/easylist/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/easylist/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/easyprivacy/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/easyprivacy/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/eth-phishing-detect/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/eth-phishing-detect/list.txt
@ -14,24 +10,28 @@ https://raw.githubusercontent.com/hectorm/hmirror/master/data/fademind-add.2o7ne
https://raw.githubusercontent.com/hectorm/hmirror/master/data/fademind-add.dead/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/fademind-add.dead/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/fademind-add.risk/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/fademind-add.risk/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/fademind-add.spam/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/fademind-add.spam/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/gfrogeye-firstparty-trackers/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/hostsvn/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/kadhosts/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/kadhosts/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/malwaredomainlist.com/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/lightswitch05-ads-and-tracking/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/malwaredomains.com-immortaldomains/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/malwaredomains.com-justdomains/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/matomo.org-spammers/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/matomo.org-spammers/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/mitchellkrogza-badd-boyz-hosts/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/mitchellkrogza-badd-boyz-hosts/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/pgl.yoyo.org/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/pgl.yoyo.org/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/ransomwaretracker.abuse.ch/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/phishing.army/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/socram8888-notonmyshift/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/someonewhocares.org/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/someonewhocares.org/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/spam404.com/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/spam404.com/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/stevenblack/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/stevenblack/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/ublock/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/ublock-abuse/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/ublock-badware/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/ublock-privacy/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/urlhaus/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/winhelp2002.mvps.org/list.txt https://raw.githubusercontent.com/hectorm/hmirror/master/data/winhelp2002.mvps.org/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/zerodot1-coinblockerlists-browser/list.txt
https://raw.githubusercontent.com/hectorm/hmirror/master/data/zeustracker.abuse.ch/list.txt
https://raw.githubusercontent.com/CHEF-KOCH/Audio-fingerprint-pages/master/AudioFp.txt
https://raw.githubusercontent.com/CHEF-KOCH/Canvas-fingerprinting-pages/master/Canvas.txt
https://raw.githubusercontent.com/CHEF-KOCH/WebRTC-tracking/master/WebRTC.txt
https://raw.githubusercontent.com/CHEF-KOCH/CKs-FilterList/master/Anti-Corp/hosts/NSABlocklist.txt
https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-blocklist.txt
https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt
https://www.stopforumspam.com/downloads/toxic_domains_whole.txt https://www.stopforumspam.com/downloads/toxic_domains_whole.txt
https://mirror.cedia.org.ec/malwaredomains/immortal_domains.txt