- removed unused/commented code

- ZabovCreateKDB is called only on active configurations
This commit is contained in:
bloved 2021-01-16 23:26:29 +01:00
parent d2f8601185
commit 740e0a387b
2 changed files with 25 additions and 15 deletions

View File

@ -7,9 +7,6 @@ import (
"github.com/syndtr/goleveldb/leveldb"
)
//MyZabovKDB is the storage where we'll put domains to block (obsolete)
//var MyZabovKDB *leveldb.DB
//MyZabovCDB is the storage where we'll put domains to cache (global for all configs)
var MyZabovCDB *leveldb.DB
@ -23,13 +20,6 @@ func init() {
os.RemoveAll("./db")
os.MkdirAll("./db", 0755)
/*
MyZabovKDB, err = leveldb.OpenFile("./db/killfile", nil)
if err != nil {
fmt.Println("Cannot create Killfile db: ", err.Error())
} else {
fmt.Println("Killfile DB created")
}*/
MyZabovCDB, err = leveldb.OpenFile("./db/cache", nil)
if err != nil {

View File

@ -38,6 +38,9 @@ func init() {
MyConf := MyConfRaw.(map[string]interface{})
//******************************
// zabov section (global config)
//******************************
zabov := MyConf["zabov"].(map[string]interface{})
ZabovPort := zabov["port"].(string)
@ -82,6 +85,9 @@ func init() {
ZabovTimetables = map[string]*ZabovTimetable{}
ZabovIPAliases = map[string]string{}
//*******************
// IP aliases section
//*******************
IPAliasesRaw := MyConf["ipaliases"].(map[string]interface{})
for alias, ip := range IPAliasesRaw {
@ -89,6 +95,9 @@ func init() {
ZabovIPAliases[alias] = ip.(string)
}
//****************
// configs section
//****************
for name, v := range configs {
fmt.Println("evaluaing config name:", name)
confRaw := v.(map[string]interface{})
@ -101,11 +110,15 @@ func init() {
conf.ZabovDNSArray = fileByLines(conf.ZabovUpDNS)
ZabovConfigs[name] = &conf
ZabovCreateKDB(name)
}
// default config is mandatory
ZabovConfigs["default"].references++
//*******************
// timetables section
//*******************
timetables := MyConf["timetables"].(map[string]interface{})
for name, v := range timetables {
@ -174,6 +187,9 @@ func init() {
ZabovTimetables[name] = &timetable
}
//******************
// IP groups section
//******************
IPGroups := MyConf["ipgroups"].([]interface{})
fmt.Println("evaluating IP Groups: ", len(IPGroups))
@ -225,6 +241,9 @@ func init() {
}
}
//************************
// Local responser section
//************************
localresponder := MyConf["localresponder"].(map[string]interface{})
if localresponder != nil {
@ -241,15 +260,16 @@ func init() {
}
}
//******************************************
// clearing unused config to save resources
//******************************************
for name, conf := range ZabovConfigs {
if conf.references == 0 {
log.Println("WARNING: disabling unused configuration:", name)
delete(ZabovConfigs, name)
} else {
ZabovCreateKDB(name)
}
}
//fmt.Println("ZabovConfigs:", ZabovConfigs)
//fmt.Println("ZabovTimetables:", ZabovTimetables)
//fmt.Println("ZabovIPAliases:", ZabovIPAliases)
//fmt.Println("ZabovIPGroups:", ZabovIPGroups)
}