1<?php 2 3if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) .'/../../../../') . '/'); 4if(!defined('NOSESSION')) define('NOSESSION',true); 5require_once(DOKU_INC.'inc/init.php'); 6require_once(DOKU_INC.'inc/io.php'); 7 8 9function get_GeoLiteCity($db) { 10 11 @set_time_limit(120); 12 $geoip_local = $_POST['geoip_local']; 13 $helper = plugin_load('helper', 'quickstats'); 14 $dnld_dir = DOKU_INC . 'lib/plugins/quickstats/GEOIP/'; 15 $url = "http://geolite.maxmind.com/download/geoip/database/${db}.gz"; 16 17 $data_file = $dnld_dir . $db; 18 $gzfile = $data_file .'.gz'; 19 20 $http = new DokuHTTPClient(); 21 $http->max_bodysize = 32777216; 22 $http->timeout = 120; 23 $http->keep_alive = false; 24 25 $data = $http->get($url); 26 if(!$data) { 27 qs_say($helper->getLang('download_fail'), $gzfile); 28 return; 29 } 30 31 $fp = @fopen($gzfile,'wb'); 32 if($fp === false) { 33 qs_say($helper->getLang('write_fail'), $gzfile); 34 return; 35 } 36 if(!fwrite($fp,$data)) { 37 qs_say($helper->getLang('write_fail'), $gzfile); 38 return; 39 } 40 fclose($fp); 41 qs_say($helper->getLang('file_saved'), $gzfile); 42 43 $gz = gzopen($gzfile, "rb"); 44 $data= gzread($gz, 32777216); 45 gzclose($gz); 46 47 if( io_saveFile($data_file, $data)) { 48 qs_say($helper->getLang('file_saved'), $data_file); 49 } 50 else { 51 qs_say($helper->getLang('no_unpack'), $gzfile); 52 return; 53 } 54 if(!$geoip_local) { 55 qs_say($helper->getLang('no_geoip_local')); 56 } 57 58} 59 60 function qs_say(){ 61 $args = func_get_args(); 62 echo vsprintf(array_shift($args)."\n",$args); 63 ob_flush(); 64 } 65 66get_GeoLiteCity('GeoLiteCity.dat'); 67get_GeoLiteCity('GeoIPv6.dat'); 68 69 70 71