From 740e0a387b583c37ffdc3362c5e39a8f95f3f114 Mon Sep 17 00:00:00 2001 From: bloved Date: Sat, 16 Jan 2021 23:26:29 +0100 Subject: [PATCH] - removed unused/commented code - ZabovCreateKDB is called only on active configurations --- 00.database.go | 10 ---------- 01.conf.go | 30 +++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/00.database.go b/00.database.go index 62cdd6c..67fdba8 100644 --- a/00.database.go +++ b/00.database.go @@ -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 { diff --git a/01.conf.go b/01.conf.go index 580e115..a48e951 100644 --- a/01.conf.go +++ b/01.conf.go @@ -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) }