Update geoip to use new update system

This commit is contained in:
Daniel 2019-07-02 13:00:44 +02:00
parent 960e1bcc16
commit 30c3fdcba8

View file

@ -1,13 +1,13 @@
package geoip package geoip
import ( import (
"errors" "fmt"
"sync" "sync"
maxminddb "github.com/oschwald/maxminddb-golang" maxminddb "github.com/oschwald/maxminddb-golang"
"github.com/Safing/safing-core/log" "github.com/Safing/portbase/log"
"github.com/Safing/safing-core/update" "github.com/Safing/portmaster/updates"
) )
var ( var (
@ -17,9 +17,6 @@ var (
dbLock sync.Mutex dbLock sync.Mutex
dbInUse = false // only activate if used for first time dbInUse = false // only activate if used for first time
dbDoReload = true // if database should be reloaded dbDoReload = true // if database should be reloaded
// mmdbCityFile = "/opt/safing/GeoLite2-City.mmdb"
// mmdbASNFile = "/opt/safing/GeoLite2-ASN.mmdb"
) )
func ReloadDatabases() error { func ReloadDatabases() error {
@ -56,19 +53,19 @@ func doReload() error {
func openDBs() error { func openDBs() error {
var err error var err error
filepath := update.GetGeoIPCityPath() file, err := updates.GetFile("intel/geoip-city.mmdb")
if filepath == "" { if err != nil {
return errors.New("could not get GeoIP City filepath") return fmt.Errorf("could not get GeoIP City database file: %s", err)
} }
dbCity, err = maxminddb.Open(filepath) dbCity, err = maxminddb.Open(file.Path())
if err != nil { if err != nil {
return err return err
} }
filepath = update.GetGeoIPASNPath() file, err = updates.GetFile("intel/geoip-asn.mmdb")
if filepath == "" { if err != nil {
return errors.New("could not get GeoIP ASN filepath") return fmt.Errorf("could not get GeoIP ASN database file: %s", err)
} }
dbASN, err = maxminddb.Open(filepath) dbASN, err = maxminddb.Open(file.Path())
if err != nil { if err != nil {
return err return err
} }