mirror of https://git.keinpfusch.net/loweel/zabov
- config:
- more sanity checks - added localresponder: if set use specified DNS server for local domains - ipaliases is now used in DNS responses (works same as /etc/hosts file) - ForwardQuery(): accept param to avoid cache
This commit is contained in:
parent
e86ead83b7
commit
945709f24e
26
01.conf.go
26
01.conf.go
|
@ -46,15 +46,20 @@ func init() {
|
||||||
ZabovCacheTTL = int(zabov["cachettl"].(float64))
|
ZabovCacheTTL = int(zabov["cachettl"].(float64))
|
||||||
ZabovKillTTL = int(zabov["killfilettl"].(float64))
|
ZabovKillTTL = int(zabov["killfilettl"].(float64))
|
||||||
|
|
||||||
|
if MyConf["configs"] == nil {
|
||||||
|
log.Println("configs not set: you shall set at least 'default' config")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
configs := MyConf["configs"].(map[string]interface{})
|
configs := MyConf["configs"].(map[string]interface{})
|
||||||
|
|
||||||
if len(configs) == 0 {
|
if len(configs) == 0 {
|
||||||
log.Println("you shall set at least default config")
|
log.Println("you shall set at least 'default' config")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if configs["default"] == nil {
|
if configs["default"] == nil {
|
||||||
log.Println("default config is required")
|
log.Println("'default' config is required")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +194,23 @@ func init() {
|
||||||
}
|
}
|
||||||
ZabovIPGroups = append(ZabovIPGroups, groupStruct)
|
ZabovIPGroups = append(ZabovIPGroups, groupStruct)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localresponder := MyConf["localresponder"].(map[string]interface{})
|
||||||
|
|
||||||
|
if localresponder != nil {
|
||||||
|
if localresponder["responder"] != nil {
|
||||||
|
ZabovLocalResponder = localresponder["responder"].(string)
|
||||||
|
if len(ZabovLocalResponder) > 0 {
|
||||||
|
local := ZabovConfig{}
|
||||||
|
local.ZabovDNSArray = []string{ZabovLocalResponder}
|
||||||
|
ZabovConfigs["__localresponder__"] = local
|
||||||
|
fmt.Println("ZabovLocalResponder:", ZabovLocalResponder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if localresponder["localdomain"] != nil {
|
||||||
|
ZabovLocalDomain = localresponder["localdomain"].(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
//fmt.Println("ZabovConfigs:", ZabovConfigs)
|
//fmt.Println("ZabovConfigs:", ZabovConfigs)
|
||||||
//fmt.Println("ZabovTimetables:", ZabovTimetables)
|
//fmt.Println("ZabovTimetables:", ZabovTimetables)
|
||||||
//fmt.Println("ZabovIPAliases:", ZabovIPAliases)
|
//fmt.Println("ZabovIPAliases:", ZabovIPAliases)
|
||||||
|
|
|
@ -102,7 +102,9 @@ func downloadDoubleThread() {
|
||||||
fmt.Println("downloadDoubleThread: collecting urls from all configs...")
|
fmt.Println("downloadDoubleThread: collecting urls from all configs...")
|
||||||
for config := range ZabovConfigs {
|
for config := range ZabovConfigs {
|
||||||
ZabovDoubleBL := ZabovConfigs[config].ZabovDoubleBL
|
ZabovDoubleBL := ZabovConfigs[config].ZabovDoubleBL
|
||||||
|
if len(ZabovDoubleBL) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
s := fileByLines(ZabovDoubleBL)
|
s := fileByLines(ZabovDoubleBL)
|
||||||
for _, v := range s {
|
for _, v := range s {
|
||||||
configs := _urls[v]
|
configs := _urls[v]
|
||||||
|
|
|
@ -100,6 +100,10 @@ func downloadThread() {
|
||||||
for config := range ZabovConfigs {
|
for config := range ZabovConfigs {
|
||||||
ZabovSingleBL := ZabovConfigs[config].ZabovSingleBL
|
ZabovSingleBL := ZabovConfigs[config].ZabovSingleBL
|
||||||
|
|
||||||
|
if len(ZabovSingleBL) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
s := fileByLines(ZabovSingleBL)
|
s := fileByLines(ZabovSingleBL)
|
||||||
for _, v := range s {
|
for _, v := range s {
|
||||||
configs := _urls[v]
|
configs := _urls[v]
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
"cachettl": 1,
|
"cachettl": 1,
|
||||||
"killfilettl": 12
|
"killfilettl": 12
|
||||||
},
|
},
|
||||||
|
"localresponder":{
|
||||||
|
"responder":"192.168.178.1:53",
|
||||||
|
"localdomain":"fritz.box"
|
||||||
|
},
|
||||||
"ipaliases":{
|
"ipaliases":{
|
||||||
"pc8":"192.168.178.29",
|
"pc8":"192.168.178.29",
|
||||||
"localhost":"127.0.0.1"
|
"localhost":"127.0.0.1"
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
//ForwardQuery forwards the query to the upstream server
|
//ForwardQuery forwards the query to the upstream server
|
||||||
//first server to answer wins
|
//first server to answer wins
|
||||||
//accepts config name to select the UP DNS source list
|
//accepts config name to select the UP DNS source list
|
||||||
func ForwardQuery(query *dns.Msg, config string) *dns.Msg {
|
func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
||||||
|
|
||||||
go incrementStats("ForwardQueries", 1)
|
go incrementStats("ForwardQueries", 1)
|
||||||
|
|
||||||
|
@ -24,12 +24,14 @@ func ForwardQuery(query *dns.Msg, config string) *dns.Msg {
|
||||||
fqdn := strings.TrimRight(query.Question[0].Name, ".")
|
fqdn := strings.TrimRight(query.Question[0].Name, ".")
|
||||||
|
|
||||||
lfqdn := fmt.Sprintf("%d", query.Question[0].Qtype) + "." + fqdn
|
lfqdn := fmt.Sprintf("%d", query.Question[0].Qtype) + "." + fqdn
|
||||||
if cached := GetDomainFromCache(lfqdn); cached != nil {
|
if !nocache {
|
||||||
go incrementStats("CacheHit", 1)
|
if cached := GetDomainFromCache(lfqdn); cached != nil {
|
||||||
cached.SetReply(query)
|
go incrementStats("CacheHit", 1)
|
||||||
cached.Authoritative = true
|
cached.SetReply(query)
|
||||||
return cached
|
cached.Authoritative = true
|
||||||
|
return cached
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
|
|
|
@ -35,14 +35,14 @@ func confFromTimeTable(timetable string) string {
|
||||||
|
|
||||||
if (nowHour > t.start.hour || (nowHour == t.start.hour && nowMinute >= t.start.minute)) &&
|
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)) {
|
(nowHour < t.stop.hour || (nowHour == t.stop.hour && nowMinute <= t.stop.minute)) {
|
||||||
incrementStats("TIMETABLE IN: "+timetable, 1)
|
go incrementStats("TIMETABLE IN: "+timetable, 1)
|
||||||
fmt.Println("confFromTimeTable: return IN", tt.cfgin)
|
fmt.Println("confFromTimeTable: return IN", tt.cfgin)
|
||||||
return tt.cfgin
|
return tt.cfgin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
incrementStats("TIMETABLE OUT: "+timetable, 1)
|
go incrementStats("TIMETABLE OUT: "+timetable, 1)
|
||||||
fmt.Println("confFromTimeTable: return OUT", tt.cfgout)
|
fmt.Println("confFromTimeTable: return OUT", tt.cfgout)
|
||||||
return tt.cfgout
|
return tt.cfgout
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
msg.SetReply(r)
|
msg.SetReply(r)
|
||||||
|
|
||||||
config := confFromIP(net.ParseIP(remIP))
|
config := confFromIP(net.ParseIP(remIP))
|
||||||
incrementStats("CONFIG: "+config, 1)
|
|
||||||
|
|
||||||
ZabovConfig := ZabovConfigs[config]
|
ZabovConfig := ZabovConfigs[config]
|
||||||
switch r.Question[0].Qtype {
|
switch r.Question[0].Qtype {
|
||||||
|
@ -86,6 +85,24 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
domain := msg.Question[0].Name
|
domain := msg.Question[0].Name
|
||||||
fqdn := strings.TrimRight(domain, ".")
|
fqdn := strings.TrimRight(domain, ".")
|
||||||
|
|
||||||
|
if len(ZabovIPAliases[fqdn]) > 0 {
|
||||||
|
config = "__aliases__"
|
||||||
|
msg.Answer = append(msg.Answer, &dns.A{
|
||||||
|
Hdr: dns.RR_Header{Name: domain, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 60},
|
||||||
|
A: net.ParseIP(ZabovIPAliases[fqdn]),
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if len(ZabovLocalResponder) > 0 {
|
||||||
|
if !strings.Contains(fqdn, ".") ||
|
||||||
|
(len(ZabovLocalDomain) > 0 && strings.HasSuffix(fqdn, ZabovLocalDomain)) {
|
||||||
|
config = "__localresponder__"
|
||||||
|
ret := ForwardQuery(r, config, true)
|
||||||
|
w.WriteMsg(ret)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
if domainInKillfile(fqdn, config) {
|
if domainInKillfile(fqdn, config) {
|
||||||
go incrementStats("Killed", 1)
|
go incrementStats("Killed", 1)
|
||||||
|
|
||||||
|
@ -94,13 +111,14 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
A: net.ParseIP(ZabovConfig.ZabovAddBL),
|
A: net.ParseIP(ZabovConfig.ZabovAddBL),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ret := ForwardQuery(r, config)
|
ret := ForwardQuery(r, config, false)
|
||||||
w.WriteMsg(ret)
|
w.WriteMsg(ret)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ret := ForwardQuery(r, config)
|
ret := ForwardQuery(r, config, false)
|
||||||
w.WriteMsg(ret)
|
w.WriteMsg(ret)
|
||||||
}
|
}
|
||||||
|
go incrementStats("CONFIG: "+config, 1)
|
||||||
w.WriteMsg(&msg)
|
w.WriteMsg(&msg)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ func ingestLocalBlacklists() {
|
||||||
_files := urlsMap{}
|
_files := urlsMap{}
|
||||||
for config := range ZabovConfigs {
|
for config := range ZabovConfigs {
|
||||||
ZabovHostsFile := ZabovConfigs[config].ZabovHostsFile
|
ZabovHostsFile := ZabovConfigs[config].ZabovHostsFile
|
||||||
|
if len(ZabovHostsFile) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
configs := _files[ZabovHostsFile]
|
configs := _files[ZabovHostsFile]
|
||||||
if configs == nil {
|
if configs == nil {
|
||||||
configs = stringarray{}
|
configs = stringarray{}
|
||||||
|
|
6
main.go
6
main.go
|
@ -16,6 +16,12 @@ var ZabovCacheTTL int
|
||||||
//ZabovKillTTL is the amount of hours we cache the killfile (global)
|
//ZabovKillTTL is the amount of hours we cache the killfile (global)
|
||||||
var ZabovKillTTL int
|
var ZabovKillTTL int
|
||||||
|
|
||||||
|
//ZabovLocalResponder is the default DNS server for loca domains
|
||||||
|
var ZabovLocalResponder string
|
||||||
|
|
||||||
|
//ZabovLocalDomain is the default local domain
|
||||||
|
var ZabovLocalDomain string
|
||||||
|
|
||||||
type handler struct{}
|
type handler struct{}
|
||||||
|
|
||||||
// ZabovConfig contains all Zabov configs
|
// ZabovConfig contains all Zabov configs
|
||||||
|
|
Loading…
Reference in New Issue