mirror of https://git.keinpfusch.net/loweel/zabov
- config:
- unused configurations are disabled to avoid wasting resources
This commit is contained in:
parent
15ec9f49ac
commit
cfabc60645
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,10 +92,12 @@ 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 {
|
||||||
|
@ -113,17 +115,19 @@ func init() {
|
||||||
timetable.cfgout = "default"
|
timetable.cfgout = "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := ZabovConfigs[timetable.cfgin]
|
refConfig, 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok = ZabovConfigs[timetable.cfgout]
|
refConfig.references++
|
||||||
|
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{})
|
||||||
|
|
||||||
|
@ -185,6 +189,15 @@ 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]
|
||||||
|
@ -201,9 +214,8 @@ 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{}
|
local := ZabovConfig{ZabovDNSArray: []string{ZabovLocalResponder}, references: 1}
|
||||||
local.ZabovDNSArray = []string{ZabovLocalResponder}
|
ZabovConfigs["__localresponder__"] = &local
|
||||||
ZabovConfigs["__localresponder__"] = local
|
|
||||||
fmt.Println("ZabovLocalResponder:", ZabovLocalResponder)
|
fmt.Println("ZabovLocalResponder:", ZabovLocalResponder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,6 +223,13 @@ 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)
|
||||||
|
|
3
main.go
3
main.go
|
@ -32,10 +32,11 @@ 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