forked from loweel/zabov
Compare commits
No commits in common. "c96c9f23e2f5793bfe4b53cecacbc5320912a4df" and "15ec9f49ac2fde58dd792bebec8156b4b8f7d33b" have entirely different histories.
c96c9f23e2
...
15ec9f49ac
33
01.conf.go
33
01.conf.go
|
@ -69,7 +69,7 @@ func init() {
|
||||||
MyDNS.Addr = zabovString
|
MyDNS.Addr = zabovString
|
||||||
MyDNS.Net = ZabovType
|
MyDNS.Net = ZabovType
|
||||||
|
|
||||||
ZabovConfigs = map[string]*ZabovConfig{}
|
ZabovConfigs = map[string]ZabovConfig{}
|
||||||
ZabovIPGroups = []ZabovIPGroup{}
|
ZabovIPGroups = []ZabovIPGroup{}
|
||||||
ZabovTimetables = map[string]*ZabovTimetable{}
|
ZabovTimetables = map[string]*ZabovTimetable{}
|
||||||
ZabovIPAliases = map[string]string{}
|
ZabovIPAliases = map[string]string{}
|
||||||
|
@ -92,12 +92,10 @@ func init() {
|
||||||
conf.ZabovHostsFile = confRaw["hostsfile"].(string)
|
conf.ZabovHostsFile = confRaw["hostsfile"].(string)
|
||||||
|
|
||||||
conf.ZabovDNSArray = fileByLines(conf.ZabovUpDNS)
|
conf.ZabovDNSArray = fileByLines(conf.ZabovUpDNS)
|
||||||
ZabovConfigs[name] = &conf
|
ZabovConfigs[name] = conf
|
||||||
ZabovCreateKDB(name)
|
ZabovCreateKDB(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
ZabovConfigs["default"].references++
|
|
||||||
|
|
||||||
timetables := MyConf["timetables"].(map[string]interface{})
|
timetables := MyConf["timetables"].(map[string]interface{})
|
||||||
|
|
||||||
for name, v := range timetables {
|
for name, v := range timetables {
|
||||||
|
@ -115,19 +113,17 @@ func init() {
|
||||||
timetable.cfgout = "default"
|
timetable.cfgout = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
refConfig, ok := ZabovConfigs[timetable.cfgin]
|
_, ok := ZabovConfigs[timetable.cfgin]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("timetable: inexistent cfgin:", timetable.cfgin)
|
log.Println("timetable: inexistent cfgin:", timetable.cfgin)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
refConfig.references++
|
_, ok = ZabovConfigs[timetable.cfgout]
|
||||||
refConfig, ok = ZabovConfigs[timetable.cfgout]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("timetable: inexistent cfgout:", timetable.cfgout)
|
log.Println("timetable: inexistent cfgout:", timetable.cfgout)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
refConfig.references++
|
|
||||||
|
|
||||||
tables := timetableRaw["tables"].([]interface{})
|
tables := timetableRaw["tables"].([]interface{})
|
||||||
|
|
||||||
|
@ -189,15 +185,6 @@ func init() {
|
||||||
}
|
}
|
||||||
groupStruct.cfg = groupMap["cfg"].(string)
|
groupStruct.cfg = groupMap["cfg"].(string)
|
||||||
groupStruct.timetable = groupMap["timetable"].(string)
|
groupStruct.timetable = groupMap["timetable"].(string)
|
||||||
if len(groupStruct.cfg) > 0 {
|
|
||||||
refConfig, ok := ZabovConfigs[groupStruct.cfg]
|
|
||||||
if !ok {
|
|
||||||
log.Println("ipgroups: inexistent cfg:", groupStruct.cfg)
|
|
||||||
os.Exit(1)
|
|
||||||
} else {
|
|
||||||
refConfig.references++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Println("cfg:", groupStruct.cfg)
|
fmt.Println("cfg:", groupStruct.cfg)
|
||||||
fmt.Println("timetable:", groupStruct.timetable)
|
fmt.Println("timetable:", groupStruct.timetable)
|
||||||
_, ok := ZabovTimetables[groupStruct.timetable]
|
_, ok := ZabovTimetables[groupStruct.timetable]
|
||||||
|
@ -214,8 +201,9 @@ func init() {
|
||||||
if localresponder["responder"] != nil {
|
if localresponder["responder"] != nil {
|
||||||
ZabovLocalResponder = localresponder["responder"].(string)
|
ZabovLocalResponder = localresponder["responder"].(string)
|
||||||
if len(ZabovLocalResponder) > 0 {
|
if len(ZabovLocalResponder) > 0 {
|
||||||
local := ZabovConfig{ZabovDNSArray: []string{ZabovLocalResponder}, references: 1}
|
local := ZabovConfig{}
|
||||||
ZabovConfigs["__localresponder__"] = &local
|
local.ZabovDNSArray = []string{ZabovLocalResponder}
|
||||||
|
ZabovConfigs["__localresponder__"] = local
|
||||||
fmt.Println("ZabovLocalResponder:", ZabovLocalResponder)
|
fmt.Println("ZabovLocalResponder:", ZabovLocalResponder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,13 +211,6 @@ func init() {
|
||||||
ZabovLocalDomain = localresponder["localdomain"].(string)
|
ZabovLocalDomain = localresponder["localdomain"].(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, conf := range ZabovConfigs {
|
|
||||||
if conf.references == 0 {
|
|
||||||
log.Println("WARNING: disabling unused configuration:", name)
|
|
||||||
delete(ZabovConfigs, name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//fmt.Println("ZabovConfigs:", ZabovConfigs)
|
//fmt.Println("ZabovConfigs:", ZabovConfigs)
|
||||||
//fmt.Println("ZabovTimetables:", ZabovTimetables)
|
//fmt.Println("ZabovTimetables:", ZabovTimetables)
|
||||||
//fmt.Println("ZabovIPAliases:", ZabovIPAliases)
|
//fmt.Println("ZabovIPAliases:", ZabovIPAliases)
|
||||||
|
|
117
README.md
117
README.md
|
@ -44,133 +44,42 @@ The second is the format zabov calls "doublefilter" (a file in "/etc/hosts" form
|
||||||
|
|
||||||
This is why configuration file has two separated items.
|
This is why configuration file has two separated items.
|
||||||
|
|
||||||
Minimal config file should look like:
|
The config file should look like:
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
{
|
{
|
||||||
"zabov":{
|
"zabov": {
|
||||||
"port":"53",
|
"port":"53",
|
||||||
"proto":"udp",
|
"proto":"udp",
|
||||||
"ipaddr":"0.0.0.0",
|
"ipaddr":"127.0.0.1",
|
||||||
"cachettl": 1,
|
|
||||||
"killfilettl": 12
|
|
||||||
},
|
|
||||||
"configs":{
|
|
||||||
"default":{
|
|
||||||
"upstream":"./dns-upstream.txt",
|
"upstream":"./dns-upstream.txt",
|
||||||
"singlefilters":"./urls-domains.txt",
|
"cachettl": "4",
|
||||||
"doublefilters":"./urls-hosts.txt",
|
"killfilettl": "12",
|
||||||
|
"singlefilters":"./urls-hosts.txt" ,
|
||||||
|
"doublefilters":"./urls-domains.txt",
|
||||||
"blackholeip":"127.0.0.1",
|
"blackholeip":"127.0.0.1",
|
||||||
"hostsfile":"./urls-local.txt"
|
"hostsfile":"./urls-local.txt"
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
Global zabov settings:
|
Where:
|
||||||
|
|
||||||
- port is the port number. Usually is 53, you can change for docker, if you like
|
- port is the port number. Usually is 53, you can change for docker, if you like
|
||||||
- proto is the protocol. Choices are "udp", "tcp", "tcp/udp"
|
- proto is the protocol. Choices are "udp", "tcp", "tcp/udp"
|
||||||
- ipaddr is the port to listen to. Maybe empty, (which will result in listening to 0.0.0.0) to avoid issues with docker.
|
- ipaddr is the port to listen to. Maybe empty, (which will result in listening to 0.0.0.0) to avoid issues with docker.
|
||||||
|
- upstream: file containing all DNS we want to query : each line in format IP:PORT
|
||||||
- cachettl: amount of time the cache is kept (in hours)
|
- cachettl: amount of time the cache is kept (in hours)
|
||||||
- killfilettl: refresh time for _killfiles_
|
- killfilettl: refresh time for _killfiles_
|
||||||
|
|
||||||
configs:
|
|
||||||
- contains multiple zabov configuration dictionaries. "default" configuration name is mandatory
|
|
||||||
- upstream: file containing all DNS we want to query : each line in format IP:PORT
|
|
||||||
- singlefilters: name of the file for blacklists following the "singlefilter" schema.(one URL per line)
|
- singlefilters: name of the file for blacklists following the "singlefilter" schema.(one URL per line)
|
||||||
- doublefilters: name of the file, for blacklists following the "doublefilter" schema.(one URL per line)
|
- 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
|
- 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.
|
- 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:
|
|
||||||
<pre>
|
|
||||||
{
|
|
||||||
"zabov":{
|
|
||||||
"port":"53",
|
|
||||||
"proto":"udp",
|
|
||||||
"ipaddr":"0.0.0.0",
|
|
||||||
"cachettl": 1,
|
|
||||||
"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":"default"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"configs":{
|
|
||||||
"default":{
|
|
||||||
"upstream":"./dns-upstream.txt",
|
|
||||||
"singlefilters":"./urls-domains.txt",
|
|
||||||
"doublefilters":"./urls-hosts.txt",
|
|
||||||
"blackholeip":"127.0.0.1",
|
|
||||||
"hostsfile":"./urls-local.txt"
|
|
||||||
},
|
|
||||||
"children":{
|
|
||||||
"upstream":"./dns-upstream-safe.txt",
|
|
||||||
"singlefilters":"./urls-domains.txt",
|
|
||||||
"doublefilters":"./urls-hosts.txt",
|
|
||||||
"blackholeip":"127.0.0.1",
|
|
||||||
"hostsfile":"./urls-local.txt"
|
|
||||||
},
|
|
||||||
"children_restricted":{
|
|
||||||
"upstream":"./dns-upstream-safe.txt",
|
|
||||||
"singlefilters":"./urls-domains-restricted.txt",
|
|
||||||
"doublefilters":"./urls-hosts-restricted.txt",
|
|
||||||
"blackholeip":"127.0.0.1",
|
|
||||||
"hostsfile":"./urls-local.txt"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</pre>
|
|
||||||
|
|
||||||
localresponder:
|
|
||||||
- allows to set a local DNS to respond for "local" domains. A domain name is handled as "local" if dosen't contains "." (dots) or if it ends with a well known prefix, such as ".local".
|
|
||||||
Note: the cache is not used for local responder.
|
|
||||||
- responder: is the local DNS server address in the IP:PORT format.
|
|
||||||
- localdomain: is the suffix for local domain names. All domains ending with this prefix are resolved by local responder
|
|
||||||
|
|
||||||
ipaliases: a dictionary of IPs
|
|
||||||
- each entry in this dictionary define a domain-alias name and his IP address. It works as replacement of /etc/hosts file.
|
|
||||||
- each entry is used by Zabov to resolve that names and to replace any value in the ipgroups.ips array.
|
|
||||||
|
|
||||||
timetables: a dictionary of timetable dictionaries
|
|
||||||
- allow to define timetables in the format "time-ranges" and "days-of-week"
|
|
||||||
- tables: contain an array of dictionaries, each defining a time rule.
|
|
||||||
- each table is a dictinary containing "time" and "days" values
|
|
||||||
- time: is a string in the form "start:time1-stop:time1;start:time2-stop:time2..."
|
|
||||||
- days: is a string containing semicolon separated day names to apply the rule such as "Mo;Tu;We;Th;Fr"
|
|
||||||
- days names are: "Mo", "Tu" "We", "Th", "Fr", "Sa", "Su"
|
|
||||||
- empty value means all week-days
|
|
||||||
You can define complex time rules using more than one entry in this dictionay
|
|
||||||
- cfgin: is the name of the configuration to apply if current time is "inside" the timetable
|
|
||||||
- cfgout: is the name of the configuration to apply if current time is "outside" the timetable
|
|
||||||
|
|
||||||
ipgroups: an array of ipgroup dictionaries
|
|
||||||
- let you define a set of IP addresses that shall use a configuration other than "default"
|
|
||||||
- ips: is an array of strings, each containing an ip address or a name defined in the "ipaliases" config branch
|
|
||||||
- cfg: is a string containing the name of the configuration to be used for this group; ignored if timetable is also defined
|
|
||||||
- timetable: is a string containing the name of the tiemtable to be aplied to this group
|
|
||||||
|
|
||||||
|
|
||||||
# DOCKER
|
# DOCKER
|
||||||
Multistage Dockerfiles are provided for AMD64, ARMv7, ARM64V8
|
Multistage Dockerfiles are provided for AMD64, ARMv7, ARM64V8
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -21,7 +22,7 @@ func getCurTime() (time.Time, error) {
|
||||||
func confFromTimeTable(timetable string) string {
|
func confFromTimeTable(timetable string) string {
|
||||||
tt := ZabovTimetables[timetable]
|
tt := ZabovTimetables[timetable]
|
||||||
if tt == nil {
|
if tt == nil {
|
||||||
//fmt.Println("confFromTimeTable: return default")
|
fmt.Println("confFromTimeTable: return default")
|
||||||
return "default"
|
return "default"
|
||||||
}
|
}
|
||||||
for _, ttentry := range tt.table {
|
for _, ttentry := range tt.table {
|
||||||
|
@ -35,14 +36,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)) {
|
||||||
go 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
go 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,12 +55,12 @@ func confFromIP(clientIP net.IP) string {
|
||||||
if len(ipgroup.timetable) > 0 {
|
if len(ipgroup.timetable) > 0 {
|
||||||
return confFromTimeTable(ipgroup.timetable)
|
return confFromTimeTable(ipgroup.timetable)
|
||||||
}
|
}
|
||||||
//fmt.Println("confFromIP: ipgroup.cfg")
|
fmt.Println("confFromIP: ipgroup.cfg")
|
||||||
return ipgroup.cfg
|
return ipgroup.cfg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//fmt.Println("confFromIP: return default")
|
fmt.Println("confFromIP: return default")
|
||||||
return "default"
|
return "default"
|
||||||
}
|
}
|
||||||
func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
|
|
3
main.go
3
main.go
|
@ -32,11 +32,10 @@ type ZabovConfig struct {
|
||||||
ZabovHostsFile string // json:hostsfile -> ZabovHostsFile is the file we use to keep our hosts
|
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
|
ZabovUpDNS string // json:upstream -> ZabovUpDNS keeps the name of upstream DNSs
|
||||||
ZabovDNSArray []string // contains all the DNS we mention, parsed from ZabovUpDNS file
|
ZabovDNSArray []string // contains all the DNS we mention, parsed from ZabovUpDNS file
|
||||||
references int // contains references to this config; if zero, config shall be removed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZabovConfigs contains all Zabov configs
|
// ZabovConfigs contains all Zabov configs
|
||||||
var ZabovConfigs map[string]*ZabovConfig
|
var ZabovConfigs map[string]ZabovConfig
|
||||||
|
|
||||||
// ZabovIPGroup contains Zabov groups of IPs
|
// ZabovIPGroup contains Zabov groups of IPs
|
||||||
type ZabovIPGroup struct {
|
type ZabovIPGroup struct {
|
||||||
|
|
Loading…
Reference in New Issue