Merge branch 'datafiles_in_hub' of github.com:crowdsecurity/crowdsec into datafiles_in_hub

This commit is contained in:
alteredCoder 2022-02-04 16:26:34 +01:00
commit 78da1e77f1

View file

@ -87,32 +87,54 @@ func GeoIpCity(field string, p *types.Event, ctx interface{}) (map[string]string
return ret, nil return ret, nil
} }
/*deal with data versioning without breaking : support crowdsecurity/xxx or xxx*/
func GeoIPCityInit(cfg map[string]string) (interface{}, error) { func GeoIPCityInit(cfg map[string]string) (interface{}, error) {
dbCityReader, err := geoip2.Open(cfg["datadir"] + "/GeoLite2-City.mmdb") dbCityReader, err := geoip2.Open(cfg["datadir"] + "/GeoLite2-City.mmdb")
if err != nil { if err == nil {
log.Debugf("couldn't open geoip : %v", err) return dbCityReader, nil
return nil, err
} }
dbCityReader, err = geoip2.Open(cfg["datadir"] + "/crowdsecurity/GeoLite2-City.mmdb")
if err == nil {
return dbCityReader, nil
return dbCityReader, nil }
log.Debugf("couldn't open geoip (%s nor %s) : %v",
cfg["datadir"]+"/crowdsecurity/GeoLite2-City.mmdb",
cfg["datadir"]+"/GeoLite2-City.mmdb",
err)
return nil, err
} }
func GeoIPASNInit(cfg map[string]string) (interface{}, error) { func GeoIPASNInit(cfg map[string]string) (interface{}, error) {
dbASReader, err := geoip2.Open(cfg["datadir"] + "/GeoLite2-ASN.mmdb") dbASReader, err := geoip2.Open(cfg["datadir"] + "/GeoLite2-ASN.mmdb")
if err != nil { if err == nil {
log.Debugf("couldn't open geoip : %v", err) return dbASReader, nil
return nil, err
}
return dbASReader, nil }
dbASReader, err = geoip2.Open(cfg["datadir"] + "/crowdsecurity/GeoLite2-ASN.mmdb")
if err == nil {
return dbASReader, nil
}
log.Debugf("couldn't open geoip (%s nor %s) : %v",
cfg["datadir"]+"/crowdsecurity/GeoLite2-ASN.mmdb",
cfg["datadir"]+"/GeoLite2-ASN.mmdb",
err)
return nil, err
} }
func IpToRangeInit(cfg map[string]string) (interface{}, error) { func IpToRangeInit(cfg map[string]string) (interface{}, error) {
ipToRangeReader, err := maxminddb.Open(cfg["datadir"] + "/GeoLite2-ASN.mmdb") ipToRangeReader, err := maxminddb.Open(cfg["datadir"] + "/GeoLite2-ASN.mmdb")
if err != nil { if err == nil {
log.Debugf("couldn't open geoip : %v", err) return ipToRangeReader, nil
return nil, err
} }
ipToRangeReader, err = maxminddb.Open(cfg["datadir"] + "/crowdsecurity/GeoLite2-ASN.mmdb")
return ipToRangeReader, nil if err == nil {
return ipToRangeReader, nil
}
log.Debugf("couldn't open geoip (%s nor %s) : %v",
cfg["datadir"]+"/crowdsecurity/GeoLite2-ASN.mmdb",
cfg["datadir"]+"/GeoLite2-ASN.mmdb",
err)
return nil, err
} }