install_awstats_geoip2.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # info: enable GeoIP2 in Awstats
  3. #
  4. # This function enables GeoIP2 location lookup for
  5. # IP addresses that are listed in awstats.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Includes
  10. # shellcheck source=/usr/local/hestia/func/main.sh
  11. source $HESTIA/func/main.sh
  12. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  13. source $HESTIA/conf/hestia.conf
  14. #----------------------------------------------------------#
  15. # Verifications #
  16. #----------------------------------------------------------#
  17. #check if string already exists
  18. if grep "geoip2" $HESTIA/data/templates/web/awstats/awstats.tpl; then
  19. echo "Plugin allready enabled"
  20. exit 0
  21. fi
  22. #----------------------------------------------------------#
  23. # Action #
  24. #----------------------------------------------------------#
  25. if [ -d /etc/awstats ]; then
  26. apt-get install make libssl-dev zlib1g-dev libdata-validate-ip-perl
  27. perl -MCPAN -f -e "GeoIP2::Database::Reader"
  28. sed -i '/LoadPlugin=\"geoip2_country \/pathto\/GeoLite2-Country.mmdb\"/s/^#//g;s/pathto/usr\/share\/GeoIP/g' /etc/awstats/awstats.conf
  29. echo "LoadPlugin=\"geoip2_country /usr/share/GeoIP/GeoLite2-Country.mmdb\"" >> $HESTIA/data/templates/web/awstats/awstats.tpl
  30. for user in $($BIN/v-list-sys-users plain); do
  31. $BIN/v-rebuild-web-domains $user no
  32. done
  33. fi
  34. #----------------------------------------------------------#
  35. # Hestia #
  36. #----------------------------------------------------------#
  37. # Logging
  38. log_history "Enabled GeoIP2 Awstats" '' 'admin'
  39. log_event "$OK" "$ARGUMENTS"
  40. exit 0