diff --git a/README.md b/README.md index 5a19c83..63d856b 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,9 @@ $ cp geostat.service /lib/systemd/system/ ``` 3) Download latest GeoLiteCity.dat from MaxMind ```sh -$ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz -$ gunzip GeoLiteCity.dat.gz +$ wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz +$ tar -xvf GeoLite2-City.tar.gz +$ cp ./GeoLite2-City_some-date/GeoLite2-City.mmdb ./ ``` 4) Then enable and start service ```sh diff --git a/geoparser.py b/geoparser.py index 60a296f..95f8309 100755 --- a/geoparser.py +++ b/geoparser.py @@ -25,7 +25,7 @@ def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSER username=INFLUXUSER, password=INFLUXUSERPASS, database=INFLUXDBDB) # NOQA re_IPV4 = re.compile('(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})') - re_IPV6 = re.compile('(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))') + re_IPV6 = re.compile('(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))') # NOQA GI = geoip2.database.Reader(GEOIPDB) @@ -45,12 +45,12 @@ def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSER time.sleep(1) FILE.seek(WHERE) else: - if re_IPV4.match(LINE): - m = re_IPV4.match(LINE) - IP = m.group(1) - elif re_IPV6.match(LINE): - m = re_IPV6.match(LINE) - IP = m.group(1) + if re_IPV4.match(LINE): + m = re_IPV4.match(LINE) + IP = m.group(1) + elif re_IPV6.match(LINE): + m = re_IPV6.match(LINE) + IP = m.group(1) if IP: INFO = GI.city(IP) diff --git a/install.sh b/install.sh index 2200abc..cb7a205 100755 --- a/install.sh +++ b/install.sh @@ -5,11 +5,16 @@ ## Alexey Nizhegolenko 2018 ## +WORKDIR=$(pwd) + echo "" echo "Downloading latest GeoLiteCity.dat from MaxMind" sleep 1 -wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz -gunzip GeoLiteCity.dat.gz +wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz +mkdir tmpgeo +tar -xvf GeoLite2-City.tar.gz -C ./tmpgeo && cd ./tmpgeo/*/. +cp ./GeoLite2-City.mmdb $WORKDIR +cd $WORKDIR echo "" echo "Creating virtual ENV and installing requirements..." diff --git a/settings.ini.back b/settings.ini.back index d2d58aa..cdeacc2 100644 --- a/settings.ini.back +++ b/settings.ini.back @@ -3,8 +3,8 @@ logpath = /var/log/nginx/access.log [GEOIP] -geoipdb = /usr/local/share/GeoIP/GeoLite2-City.mmdb -# For country use /usr/local/share/GeoIP/GeoLite2-Country.mmdb +#Path for the GEOIP DB file +geoipdb = ./GeoLite2-City.mmdb [INFLUXDB] # Database URL