2020-10-08 16:14:07 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2021-01-13 16:30:04 -05:00
|
|
|
"net"
|
2020-10-08 16:14:07 -04:00
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
//MyDNS is my dns server
|
|
|
|
var MyDNS *dns.Server
|
|
|
|
|
2021-01-13 16:30:04 -05:00
|
|
|
//ZabovCacheTTL is the amount of hours we cache records of DNS (global)
|
2020-10-08 16:14:07 -04:00
|
|
|
var ZabovCacheTTL int
|
|
|
|
|
2021-01-13 16:30:04 -05:00
|
|
|
//ZabovKillTTL is the amount of hours we cache the killfile (global)
|
2020-10-08 16:14:07 -04:00
|
|
|
var ZabovKillTTL int
|
|
|
|
|
2021-01-14 14:25:10 -05:00
|
|
|
//ZabovLocalResponder is the default DNS server for local domains (global)
|
2021-01-13 17:38:33 -05:00
|
|
|
var ZabovLocalResponder string
|
|
|
|
|
2021-01-14 14:25:10 -05:00
|
|
|
//ZabovLocalDomain is the default local domain (global)
|
2021-01-13 17:38:33 -05:00
|
|
|
var ZabovLocalDomain string
|
|
|
|
|
2021-01-16 12:54:31 -05:00
|
|
|
//ZabovDefaultTimetable is the default timetable, applied to any client that is not already in any IP Group (global)
|
|
|
|
var ZabovDefaultTimetable string
|
|
|
|
|
2021-01-14 14:25:10 -05:00
|
|
|
//ZabovDebug activate more logging if set to true (global)
|
|
|
|
var ZabovDebug bool
|
|
|
|
|
2021-01-15 12:50:59 -05:00
|
|
|
//ZabovDebugDBPath path to store debug query logs: activate logging of each single query in a csv like file (global)
|
|
|
|
var ZabovDebugDBPath string
|
|
|
|
|
2020-10-08 16:14:07 -04:00
|
|
|
type handler struct{}
|
|
|
|
|
2021-01-11 18:04:34 -05:00
|
|
|
// ZabovConfig contains all Zabov configs
|
|
|
|
type ZabovConfig struct {
|
2021-01-13 16:30:04 -05:00
|
|
|
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
|
2021-01-25 11:00:34 -05:00
|
|
|
ZabovAddBL net.IP // json:blackholeip -> ZabovAddBL is the IP we want to send all the clients to. Usually is 127.0.0.1
|
2021-01-13 16:30:04 -05:00
|
|
|
ZabovHostsFile string // json:hostsfile -> ZabovHostsFile is the file we use to keep our hosts
|
2021-05-11 04:32:48 -04:00
|
|
|
ZabovWhiteList string // json:hostsfile -> ZabovWhiteList is the file we use to keep white listed hosts
|
2021-01-13 16:30:04 -05:00
|
|
|
ZabovUpDNS string // json:upstream -> ZabovUpDNS keeps the name of upstream DNSs
|
|
|
|
ZabovDNSArray []string // contains all the DNS we mention, parsed from ZabovUpDNS file
|
2021-01-29 07:01:18 -05:00
|
|
|
ZabovCache bool // allows to disable cache
|
2021-01-14 09:38:46 -05:00
|
|
|
references int // contains references to this config; if zero, config shall be removed
|
2021-01-11 18:04:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ZabovConfigs contains all Zabov configs
|
2021-01-14 09:38:46 -05:00
|
|
|
var ZabovConfigs map[string]*ZabovConfig
|
2021-01-11 18:04:34 -05:00
|
|
|
|
|
|
|
// ZabovIPGroup contains Zabov groups of IPs
|
|
|
|
type ZabovIPGroup struct {
|
2021-01-13 16:30:04 -05:00
|
|
|
ips []net.IP // IPs in this group
|
2021-01-11 18:04:34 -05:00
|
|
|
cfg string // config name to be used if there is no timetable
|
|
|
|
timetable string // timetable name to be used for this group; timetable SHALL reference to config name to use
|
|
|
|
}
|
|
|
|
|
|
|
|
// ZabovIPGroups contains an array of all Zabov groups of IP rules
|
|
|
|
var ZabovIPGroups []ZabovIPGroup
|
|
|
|
|
2021-01-13 16:30:04 -05:00
|
|
|
// ZabovTime contains Zabov single time
|
|
|
|
type ZabovTime struct {
|
|
|
|
hour int
|
|
|
|
minute int
|
|
|
|
}
|
|
|
|
|
|
|
|
// ZabovTimeRange contains Zabov single time range
|
|
|
|
type ZabovTimeRange struct {
|
|
|
|
start ZabovTime
|
|
|
|
stop ZabovTime
|
|
|
|
}
|
|
|
|
|
2021-01-11 18:04:34 -05:00
|
|
|
// ZabovTimetableEntry contains Zabov single time table entry
|
|
|
|
type ZabovTimetableEntry struct {
|
2021-01-13 16:30:04 -05:00
|
|
|
times []*ZabovTimeRange
|
|
|
|
days map[string]bool
|
2021-01-11 18:04:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ZabovTimetable contains a Zabov time table
|
|
|
|
type ZabovTimetable struct {
|
2021-01-13 16:30:04 -05:00
|
|
|
table []*ZabovTimetableEntry
|
2021-01-11 18:04:34 -05:00
|
|
|
cfgin string // configuration name to be used if "inside" timetable
|
|
|
|
cfgout string // configuration name to be used if "outiside" timetable
|
|
|
|
}
|
|
|
|
|
|
|
|
// ZabovTimetables contains all Zabov time tables, by name
|
2021-01-13 16:30:04 -05:00
|
|
|
var ZabovTimetables map[string]*ZabovTimetable
|
2021-01-11 18:04:34 -05:00
|
|
|
|
|
|
|
// ZabovIPAliases contains an array of all Zabov IP aliases
|
|
|
|
var ZabovIPAliases map[string]string
|
|
|
|
|
2020-10-08 16:14:07 -04:00
|
|
|
func main() {
|
|
|
|
|
|
|
|
MyDNS.Handler = &handler{}
|
|
|
|
if err := MyDNS.ListenAndServe(); err != nil {
|
|
|
|
log.Printf("Failed to set udp listener %s\n", err.Error())
|
|
|
|
} else {
|
|
|
|
log.Printf("Listener running \n")
|
|
|
|
}
|
|
|
|
}
|