Compare commits
No commits in common. "7cb896ac59808e4e0b3830653ac832128d8dc207" and "13dd24b7b500d685f8264b20d629b4039ffee3e5" have entirely different histories.
7cb896ac59
...
13dd24b7b5
27
01.conf.go
27
01.conf.go
|
@ -13,13 +13,10 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
var localresponderConfigName string
|
||||
|
||||
type stringarray []string
|
||||
type urlsMap map[string]stringarray
|
||||
|
||||
func init() {
|
||||
localresponderConfigName = "__localresponder__"
|
||||
var MyConfRaw interface{}
|
||||
|
||||
file, err := ioutil.ReadFile("config.json")
|
||||
|
@ -110,14 +107,9 @@ func init() {
|
|||
conf.ZabovUpDNS = confRaw["upstream"].(string)
|
||||
conf.ZabovSingleBL = confRaw["singlefilters"].(string)
|
||||
conf.ZabovDoubleBL = confRaw["doublefilters"].(string)
|
||||
conf.ZabovAddBL = net.ParseIP(confRaw["blackholeip"].(string))
|
||||
conf.ZabovAddBL = confRaw["blackholeip"].(string)
|
||||
conf.ZabovHostsFile = confRaw["hostsfile"].(string)
|
||||
|
||||
if confRaw["cache"] != nil {
|
||||
conf.ZabovCache = confRaw["cache"].(bool)
|
||||
} else {
|
||||
conf.ZabovCache = true
|
||||
}
|
||||
conf.ZabovDNSArray = fileByLines(conf.ZabovUpDNS)
|
||||
ZabovConfigs[name] = &conf
|
||||
|
||||
|
@ -224,16 +216,8 @@ func init() {
|
|||
}
|
||||
groupStruct.ips = append(groupStruct.ips, ip)
|
||||
}
|
||||
if groupMap["cfg"] != nil {
|
||||
groupStruct.cfg = groupMap["cfg"].(string)
|
||||
}
|
||||
if groupMap["timetable"] != nil {
|
||||
groupStruct.timetable = groupMap["timetable"].(string)
|
||||
}
|
||||
if len(groupStruct.cfg) == 0 && len(groupStruct.timetable) == 0 {
|
||||
log.Println("ip group error: specify cfg or timetable")
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(groupStruct.cfg) > 0 {
|
||||
refConfig, ok := ZabovConfigs[groupStruct.cfg]
|
||||
if !ok {
|
||||
|
@ -242,17 +226,14 @@ func init() {
|
|||
} else {
|
||||
refConfig.references++
|
||||
}
|
||||
fmt.Println("cfg:", groupStruct.cfg)
|
||||
}
|
||||
if len(groupStruct.timetable) > 0 {
|
||||
fmt.Println("cfg:", groupStruct.cfg)
|
||||
fmt.Println("timetable:", groupStruct.timetable)
|
||||
_, ok := ZabovTimetables[groupStruct.timetable]
|
||||
if !ok {
|
||||
log.Println("inexistent timetable:", groupStruct.timetable)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
ZabovIPGroups = append(ZabovIPGroups, groupStruct)
|
||||
}
|
||||
}
|
||||
|
@ -267,7 +248,7 @@ func init() {
|
|||
}
|
||||
|
||||
//************************
|
||||
// Local responder section
|
||||
// Local responser section
|
||||
//************************
|
||||
if MyConf["localresponder"] != nil {
|
||||
localresponder := MyConf["localresponder"].(map[string]interface{})
|
||||
|
@ -277,7 +258,7 @@ func init() {
|
|||
ZabovLocalResponder = localresponder["responder"].(string)
|
||||
if len(ZabovLocalResponder) > 0 {
|
||||
local := ZabovConfig{ZabovDNSArray: []string{ZabovLocalResponder}, references: 1}
|
||||
ZabovConfigs[localresponderConfigName] = &local
|
||||
ZabovConfigs["__localresponder__"] = &local
|
||||
fmt.Println("ZabovLocalResponder:", ZabovLocalResponder)
|
||||
}
|
||||
}
|
||||
|
|
19
README.md
19
README.md
|
@ -62,8 +62,7 @@ Minimal config file should look like:
|
|||
"singlefilters":"./urls-domains.txt",
|
||||
"doublefilters":"./urls-hosts.txt",
|
||||
"blackholeip":"127.0.0.1",
|
||||
"hostsfile":"./urls-local.txt",
|
||||
"cache":true
|
||||
"hostsfile":"./urls-local.txt"
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +84,7 @@ configs:
|
|||
- doublefilters: name of the file, for blacklists following the "doublefilter" schema.(one URL per line)
|
||||
- blackholeip: IP address to return when the IP is banned. This is because you may want to avoid MX issues, mail loops on localhost, or you have a web server running on localhost
|
||||
- hostsfile: path where you keep your local blacklistfile : this is in the format "singlefilter", meaning one domain per line, unlike hosts file.
|
||||
- cache: if set to false disable the cache for this configuration. Boolean, defaults true
|
||||
|
||||
|
||||
Advanced configuration includes support for multiple configurations based on IP Source and timetables:
|
||||
<pre>
|
||||
|
@ -105,7 +104,6 @@ Advanced configuration includes support for multiple configurations based on IP
|
|||
},
|
||||
"ipaliases":{
|
||||
"pc8":"192.168.178.29",
|
||||
"lg-tv":"192.168.178.10",
|
||||
"localhost":"127.0.0.1"
|
||||
},
|
||||
"ipgroups":[
|
||||
|
@ -113,11 +111,6 @@ Advanced configuration includes support for multiple configurations based on IP
|
|||
"ips":["localhost", "::1", "192.168.178.30", "192.168.178.31", "pc8"],
|
||||
"cfg":"",
|
||||
"timetable":"tt_children"
|
||||
},
|
||||
{
|
||||
"ips":["lg-tv"],
|
||||
"cfg":"tv",
|
||||
"timetable":""
|
||||
}
|
||||
],
|
||||
"timetables":{
|
||||
|
@ -153,14 +146,6 @@ Advanced configuration includes support for multiple configurations based on IP
|
|||
"doublefilters":"./urls-hosts-restricted.txt",
|
||||
"blackholeip":"127.0.0.1",
|
||||
"hostsfile":"./urls-local.txt"
|
||||
},
|
||||
"tv":{
|
||||
"upstream":"./dns-upstream.txt",
|
||||
"singlefilters":"",
|
||||
"doublefilters":"",
|
||||
"blackholeip":"127.0.0.1",
|
||||
"hostsfile":"",
|
||||
"cache":false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"math/rand"
|
||||
|
@ -15,9 +14,7 @@ import (
|
|||
//first server to answer wins
|
||||
//accepts config name to select the UP DNS source list
|
||||
func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
||||
if ZabovDebug {
|
||||
log.Println("ForwardQuery: nocache", nocache)
|
||||
}
|
||||
|
||||
go incrementStats("ForwardQueries", 1)
|
||||
|
||||
r := new(dns.Msg)
|
||||
|
@ -30,14 +27,8 @@ func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
|||
if !nocache {
|
||||
if cached := GetDomainFromCache(lfqdn); cached != nil {
|
||||
go incrementStats("CacheHit", 1)
|
||||
Rcode := cached.MsgHdr.Rcode
|
||||
cached.SetReply(query)
|
||||
cached.MsgHdr.Rcode = Rcode
|
||||
cached.Authoritative = true
|
||||
if ZabovDebug {
|
||||
log.Println("ForwardQuery: CacheHit")
|
||||
}
|
||||
cached.Compress = true
|
||||
return cached
|
||||
|
||||
}
|
||||
|
@ -51,8 +42,7 @@ func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
|||
for {
|
||||
// round robin with retry
|
||||
|
||||
// local responder should always be available also if no internet connection
|
||||
if !NetworkUp && localresponderConfigName != config {
|
||||
if !NetworkUp {
|
||||
time.Sleep(10 * time.Second)
|
||||
go incrementStats("Network Problems ", 1)
|
||||
continue
|
||||
|
@ -67,16 +57,9 @@ func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
|||
continue
|
||||
} else {
|
||||
go incrementStats(d, 1)
|
||||
Rcode := in.MsgHdr.Rcode
|
||||
in.SetReply(query)
|
||||
in.MsgHdr.Rcode = Rcode
|
||||
in.Authoritative = true
|
||||
in.Compress = true
|
||||
go DomainCache(lfqdn, in)
|
||||
if ZabovDebug {
|
||||
log.Println("ForwardQuery: OK!")
|
||||
}
|
||||
|
||||
return in
|
||||
|
||||
}
|
||||
|
|
|
@ -269,7 +269,7 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
|||
if len(ZabovLocalResponder) > 0 {
|
||||
if !strings.Contains(fqdn, ".") ||
|
||||
(len(ZabovLocalDomain) > 0 && strings.HasSuffix(fqdn, ZabovLocalDomain)) {
|
||||
config = localresponderConfigName
|
||||
config = "__localresponder__"
|
||||
ret := ForwardQuery(r, config, true)
|
||||
w.WriteMsg(ret)
|
||||
go logQuery(remIP, fqdn, QType, config, timetable, "localresponder")
|
||||
|
@ -282,12 +282,12 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
|||
|
||||
msg.Answer = append(msg.Answer, &dns.A{
|
||||
Hdr: dns.RR_Header{Name: domain, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 60},
|
||||
A: ZabovConfig.ZabovAddBL,
|
||||
A: net.ParseIP(ZabovConfig.ZabovAddBL),
|
||||
})
|
||||
go logQuery(remIP, fqdn, QType, config, timetable, "killed")
|
||||
} else {
|
||||
go logQuery(remIP, fqdn, QType, config, timetable, "forwarded")
|
||||
ret := ForwardQuery(r, config, !ZabovConfig.ZabovCache)
|
||||
ret := ForwardQuery(r, config, false)
|
||||
w.WriteMsg(ret)
|
||||
}
|
||||
case dns.TypePTR:
|
||||
|
@ -297,13 +297,13 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
|||
|
||||
if len(ZabovLocalResponder) > 0 {
|
||||
// if set use local responder for reverse lookup (suffix ".in-addr.arpa.")
|
||||
config = localresponderConfigName
|
||||
config = "__localresponder__"
|
||||
}
|
||||
ret := ForwardQuery(r, config, true)
|
||||
w.WriteMsg(ret)
|
||||
go logQuery(remIP, msg.Question[0].Name, QType, config, timetable, "localresponder")
|
||||
default:
|
||||
ret := ForwardQuery(r, config, !ZabovConfig.ZabovCache)
|
||||
ret := ForwardQuery(r, config, false)
|
||||
w.WriteMsg(ret)
|
||||
if len(ZabovDebugDBPath) > 0 {
|
||||
go logQuery(remIP, msg.Question[0].Name, QType, config, timetable, "forwarded")
|
||||
|
|
3
main.go
3
main.go
|
@ -37,11 +37,10 @@ type handler struct{}
|
|||
type ZabovConfig struct {
|
||||
ZabovSingleBL string // json:singlefilters -> ZabovSingleBL list of urls returning a file with just names of domains
|
||||
ZabovDoubleBL string // json:doublefilters -> ZabovDoubleBL list of urls returning a file with IP<space>domain
|
||||
ZabovAddBL net.IP // json:blackholeip -> ZabovAddBL is the IP we want to send all the clients to. Usually is 127.0.0.1
|
||||
ZabovAddBL string // json:blackholeip -> ZabovAddBL is the IP we want to send all the clients to. Usually is 127.0.0.1
|
||||
ZabovHostsFile string // json:hostsfile -> ZabovHostsFile is the file we use to keep our hosts
|
||||
ZabovUpDNS string // json:upstream -> ZabovUpDNS keeps the name of upstream DNSs
|
||||
ZabovDNSArray []string // contains all the DNS we mention, parsed from ZabovUpDNS file
|
||||
ZabovCache bool // allows to disable cache
|
||||
references int // contains references to this config; if zero, config shall be removed
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue