- config:

- added "debug" mode
- updated documentation in README.md
- BL downloader threads: added 2 seconds delay to allow local DNS service go up & running
remotes/1680050961956510080/tmp_refs/heads/master
bloved 2021-01-14 20:25:10 +01:00
parent c96c9f23e2
commit 31e05cb177
6 changed files with 49 additions and 10 deletions

View File

@ -43,9 +43,12 @@ func init() {
ZabovPort := zabov["port"].(string)
ZabovType := zabov["proto"].(string)
ZabovAddr := zabov["ipaddr"].(string)
DebugStr := (zabov["debug"].(string))
ZabovCacheTTL = int(zabov["cachettl"].(float64))
ZabovKillTTL = int(zabov["killfilettl"].(float64))
ZabovDebug = DebugStr == "true"
if MyConf["configs"] == nil {
log.Println("configs not set: you shall set at least 'default' config")
os.Exit(1)

View File

@ -53,7 +53,8 @@ Minimal config file should look like:
"proto":"udp",
"ipaddr":"0.0.0.0",
"cachettl": 1,
"killfilettl": 12
"killfilettl": 12,
"debug:"false"
},
"configs":{
"default":{
@ -74,6 +75,7 @@ Global zabov settings:
- ipaddr is the port to listen to. Maybe empty, (which will result in listening to 0.0.0.0) to avoid issues with docker.
- cachettl: amount of time the cache is kept (in hours)
- killfilettl: refresh time for _killfiles_
- debug: if set to "true" Zabov prints verbose logs, such as config selection and single DNS requests
configs:
- contains multiple zabov configuration dictionaries. "default" configuration name is mandatory
@ -84,7 +86,7 @@ configs:
- hostsfile: path where you keep your local blacklistfile : this is in the format "singlefilter", meaning one domain per line, unlike hosts file.
Advanced configuration includes support for multiple configuration based on IP Soruce and timetables:
Advanced configuration includes support for multiple configurations based on IP Source and timetables:
<pre>
{
"zabov":{

View File

@ -95,7 +95,7 @@ func getDoubleFilters(urls urlsMap) {
func downloadDoubleThread() {
fmt.Println("Starting updater of DOUBLE lists, each (hours):", ZabovKillTTL)
time.Sleep(2 * time.Second) // wait for local DNS server up & running (may be our DNS)
_urls := urlsMap{}
for {

View File

@ -93,6 +93,8 @@ func getSingleFilters(urls urlsMap) {
func downloadThread() {
fmt.Println("Starting updater of SINGLE lists, each (hours): ", ZabovKillTTL)
time.Sleep(2 * time.Second) // wait for local DNS server up & running (may be our DNS)
_urls := urlsMap{}
for {

View File

@ -1,6 +1,7 @@
package main
import (
"log"
"net"
"strings"
"time"
@ -21,7 +22,9 @@ func getCurTime() (time.Time, error) {
func confFromTimeTable(timetable string) string {
tt := ZabovTimetables[timetable]
if tt == nil {
//fmt.Println("confFromTimeTable: return default")
if ZabovDebug {
log.Println("confFromTimeTable: return default")
}
return "default"
}
for _, ttentry := range tt.table {
@ -35,14 +38,18 @@ func confFromTimeTable(timetable string) string {
if (nowHour > t.start.hour || (nowHour == t.start.hour && nowMinute >= t.start.minute)) &&
(nowHour < t.stop.hour || (nowHour == t.stop.hour && nowMinute <= t.stop.minute)) {
go incrementStats("TIMETABLE IN: "+timetable, 1)
//fmt.Println("confFromTimeTable: return IN", tt.cfgin)
if ZabovDebug {
log.Println("confFromTimeTable: return IN", tt.cfgin)
}
return tt.cfgin
}
}
}
}
go incrementStats("TIMETABLE OUT: "+timetable, 1)
//fmt.Println("confFromTimeTable: return OUT", tt.cfgout)
if ZabovDebug {
log.Println("confFromTimeTable: return OUT", tt.cfgout)
}
return tt.cfgout
}
@ -54,12 +61,16 @@ func confFromIP(clientIP net.IP) string {
if len(ipgroup.timetable) > 0 {
return confFromTimeTable(ipgroup.timetable)
}
//fmt.Println("confFromIP: ipgroup.cfg")
if ZabovDebug {
log.Println("confFromIP: ipgroup.cfg")
}
return ipgroup.cfg
}
}
}
//fmt.Println("confFromIP: return default")
if ZabovDebug {
log.Println("confFromIP: return default")
}
return "default"
}
func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
@ -77,6 +88,9 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
config := confFromIP(net.ParseIP(remIP))
if ZabovDebug {
log.Println("REQUEST:", remIP, config)
}
ZabovConfig := ZabovConfigs[config]
switch r.Question[0].Qtype {
case dns.TypeA:
@ -84,6 +98,10 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
domain := msg.Question[0].Name
fqdn := strings.TrimRight(domain, ".")
if ZabovDebug {
log.Println("TypeA: fqdn:", fqdn)
}
if len(ZabovIPAliases[fqdn]) > 0 {
config = "__aliases__"
msg.Answer = append(msg.Answer, &dns.A{
@ -113,6 +131,17 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
ret := ForwardQuery(r, config, false)
w.WriteMsg(ret)
}
case dns.TypePTR:
if ZabovDebug {
log.Println("TypePTR: Name:", msg.Question[0].Name)
}
if len(ZabovLocalResponder) > 0 {
// if set use local responder for reverse lookup (suffix ".in-addr.arpa.")
config = "__localresponder__"
}
ret := ForwardQuery(r, config, true)
w.WriteMsg(ret)
default:
ret := ForwardQuery(r, config, false)
w.WriteMsg(ret)

View File

@ -16,12 +16,15 @@ var ZabovCacheTTL int
//ZabovKillTTL is the amount of hours we cache the killfile (global)
var ZabovKillTTL int
//ZabovLocalResponder is the default DNS server for loca domains
//ZabovLocalResponder is the default DNS server for local domains (global)
var ZabovLocalResponder string
//ZabovLocalDomain is the default local domain
//ZabovLocalDomain is the default local domain (global)
var ZabovLocalDomain string
//ZabovDebug activate more logging if set to true (global)
var ZabovDebug bool
type handler struct{}
// ZabovConfig contains all Zabov configs