Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update_geoip.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?
  2. ini_set('memory_limit', '1G');
  3. set_time_limit(0);
  4. if (!check_perms('site_debug')) {
  5. error(403);
  6. }
  7. View::show_header();
  8. chdir('/tmp');
  9. //requires wget, unzip, gunzip commands to be installed
  10. shell_exec('wget http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip');
  11. shell_exec('wget http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz');
  12. shell_exec('unzip GeoIPCountryCSV.zip');
  13. shell_exec('gunzip GeoIPv6.csv.gz');
  14. shell_exec('cut -d , -f 3-5 GeoIPCountryWhois.csv > GeoIPCountry.csv');
  15. shell_exec('cut -d , -f 3-5 GeoIPv6.csv | tr -d " " >> GeoIPCountry.csv');
  16. shell_exec('rm GeoIPCountryCSV.zip GeoIPv6.csv.gz GeoIPCountryWhois.csv GeoIPv6.csv');
  17. if (($Blocks = file("GeoIPCountry.csv", FILE_IGNORE_NEW_LINES)) === false) {
  18. echo 'Error';
  19. }
  20. echo 'There are '.count($Blocks).' blocks';
  21. echo '<br />';
  22. //Because the old code reading a 2mil line database had splitting, we're just gonna keep using it with this much more reasonable 140k line db
  23. $SplitOn = 1000;
  24. $DB->query("TRUNCATE TABLE geoip_country");
  25. $Values = array();
  26. foreach ($Blocks as $Index => $Block) {
  27. list($StartIP, $EndIP, $CountryID) = explode(",", $Block);
  28. $StartIP = trim($StartIP, '"');
  29. $EndIP = trim($EndIP, '"');
  30. $CountryID = trim($CountryID, '"');
  31. $Values[] = "('$StartIP', '$EndIP', '".$CountryID."')";
  32. if ($Index % $SplitOn == 0) {
  33. $DB->query('
  34. INSERT INTO geoip_country (StartIP, EndIP, Code)
  35. VALUES '.implode(', ', $Values));
  36. $Values = array();
  37. }
  38. }
  39. if (count($Values) > 0) {
  40. $DB->query("
  41. INSERT INTO geoip_country (StartIP, EndIP, Code)
  42. VALUES ".implode(', ', $Values));
  43. }
  44. View::show_footer();