2020-10-08 15:14:07 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
|
|
)
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
//MyZabovCDB is the storage where we'll put domains to cache (global for all configs)
|
2020-10-08 15:14:07 -05:00
|
|
|
var MyZabovCDB *leveldb.DB
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
//MyZabovKDBs is the storage where we'll put domains to block (one for each config)
|
|
|
|
var MyZabovKDBs map[string]*leveldb.DB
|
|
|
|
|
2021-05-11 03:32:48 -05:00
|
|
|
//MyZabovWLDBs is the storage where we'll put domains to whitelist (one for each config)
|
|
|
|
var MyZabovWLDBs map[string]*leveldb.DB
|
|
|
|
|
2020-10-08 15:14:07 -05:00
|
|
|
func init() {
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
os.RemoveAll("./db")
|
|
|
|
|
|
|
|
os.MkdirAll("./db", 0755)
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
MyZabovCDB, err = leveldb.OpenFile("./db/cache", nil)
|
2020-10-08 15:14:07 -05:00
|
|
|
if err != nil {
|
2021-01-11 17:04:34 -06:00
|
|
|
fmt.Println("Cannot create Cache db: ", err.Error())
|
2020-10-08 15:14:07 -05:00
|
|
|
} else {
|
2021-01-11 17:04:34 -06:00
|
|
|
fmt.Println("Cache DB created")
|
2020-10-08 15:14:07 -05:00
|
|
|
}
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
MyZabovKDBs = map[string]*leveldb.DB{}
|
2021-05-11 03:32:48 -05:00
|
|
|
MyZabovWLDBs = map[string]*leveldb.DB{}
|
2021-01-11 17:04:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ZabovCreateKDB creates Kill DBs
|
|
|
|
func ZabovCreateKDB(conf string) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
dbname := "./db/killfile_" + conf
|
|
|
|
KDB, err := leveldb.OpenFile(dbname, nil)
|
2020-10-08 15:14:07 -05:00
|
|
|
if err != nil {
|
2021-01-11 17:04:34 -06:00
|
|
|
fmt.Println("Cannot create Killfile db: ", err.Error())
|
2020-10-08 15:14:07 -05:00
|
|
|
} else {
|
2021-01-17 09:15:12 -06:00
|
|
|
fmt.Println("Killfile DB created:", dbname)
|
2020-10-08 15:14:07 -05:00
|
|
|
}
|
|
|
|
|
2021-01-11 17:04:34 -06:00
|
|
|
MyZabovKDBs[conf] = KDB
|
|
|
|
|
2020-10-08 15:14:07 -05:00
|
|
|
}
|
2021-05-11 03:32:48 -05:00
|
|
|
|
|
|
|
// ZabovCreateWLDB creates Whitelist DBs
|
|
|
|
func ZabovCreateWLDB(conf string) {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
dbname := "./db/whitelist_" + conf
|
|
|
|
WLDB, err := leveldb.OpenFile(dbname, nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Cannot create whitelist db: ", err.Error())
|
|
|
|
} else {
|
|
|
|
fmt.Println("whitelist DB created:", dbname)
|
|
|
|
}
|
|
|
|
|
|
|
|
MyZabovWLDBs[conf] = WLDB
|
|
|
|
|
|
|
|
}
|