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