2020-10-08 15:14:07 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2021-01-13 15:30:04 -06:00
|
|
|
"net"
|
2020-10-08 15:14:07 -05:00
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
//MyDNS is my dns server
|
|
|
|
var MyDNS *dns.Server
|
|
|
|
|
2021-01-13 15:30:04 -06:00
|
|
|
//ZabovCacheTTL is the amount of hours we cache records of DNS (global)
|
2020-10-08 15:14:07 -05:00
|
|
|
var ZabovCacheTTL int
|
|
|
|
|
2021-01-13 15:30:04 -06:00
|
|
|
//ZabovKillTTL is the amount of hours we cache the killfile (global)
|
2020-10-08 15:14:07 -05:00
|
|
|
var ZabovKillTTL int
|
|
|
|
|
2021-01-14 13:25:10 -06:00
|
|
|
//ZabovLocalResponder is the default DNS server for local domains (global)
|
2021-01-13 16:38:33 -06:00
|
|
|
var ZabovLocalResponder string
|
|
|
|
|
2021-01-14 13:25:10 -06:00
|
|
|
//ZabovLocalDomain is the default local domain (global)
|
2021-01-13 16:38:33 -06:00
|
|
|
var ZabovLocalDomain string
|
|
|
|
|
2021-01-16 11:54:31 -06: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 13:25:10 -06:00
|
|
|
//ZabovDebug activate more logging if set to true (global)
|
|
|
|
var ZabovDebug bool
|
|
|
|
|
2021-01-15 11:50:59 -06: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 15:14:07 -05:00
|
|
|
type handler struct{}
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
// ZabovConfig contains all Zabov configs
|
|
|
|
type ZabovConfig struct {
|
2021-01-13 15:30:04 -06: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 10:00:34 -06: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 15:30:04 -06:00
|
|
|
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
|
2021-01-29 06:01:18 -06:00
|
|
|
ZabovCache bool // allows to disable cache
|
2021-01-14 08:38:46 -06:00
|
|
|
references int // contains references to this config; if zero, config shall be removed
|
2021-01-11 17:04:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ZabovConfigs contains all Zabov configs
|
2021-01-14 08:38:46 -06:00
|
|
|
var ZabovConfigs map[string]*ZabovConfig
|
2021-01-11 17:04:34 -06:00
|
|
|
|
|
|
|
// ZabovIPGroup contains Zabov groups of IPs
|
|
|
|
type ZabovIPGroup struct {
|
2021-01-13 15:30:04 -06:00
|
|
|
ips []net.IP // IPs in this group
|
2021-01-11 17:04:34 -06: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 15:30:04 -06: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 17:04:34 -06:00
|
|
|
// ZabovTimetableEntry contains Zabov single time table entry
|
|
|
|
type ZabovTimetableEntry struct {
|
2021-01-13 15:30:04 -06:00
|
|
|
times []*ZabovTimeRange
|
|
|
|
days map[string]bool
|
2021-01-11 17:04:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ZabovTimetable contains a Zabov time table
|
|
|
|
type ZabovTimetable struct {
|
2021-01-13 15:30:04 -06:00
|
|
|
table []*ZabovTimetableEntry
|
2021-01-11 17:04:34 -06: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 15:30:04 -06:00
|
|
|
var ZabovTimetables map[string]*ZabovTimetable
|
2021-01-11 17:04:34 -06:00
|
|
|
|
|
|
|
// ZabovIPAliases contains an array of all Zabov IP aliases
|
|
|
|
var ZabovIPAliases map[string]string
|
|
|
|
|
2020-10-08 15:14:07 -05: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")
|
|
|
|
}
|
|
|
|
}
|