public function downloadFreeGeoIP2DB()
    {
        $this->dieIfGeolocationAdminIsDisabled();
        Piwik::checkUserHasSuperUserAccess();
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $this->checkTokenInUrl();
            Json::sendHeaderJSON();
            $outputPath = GeoIp2::getPathForGeoIpDatabase('GeoLite2-City.tar') . '.gz';
            try {
                $result = Http::downloadChunk(
                    $url = GeoIp2::GEO_LITE_URL,
                    $outputPath,
                    $continue = Common::getRequestVar('continue', true, 'int')
                );

                // if the file is done
                if ($result['current_size'] >= $result['expected_file_size']) {
                    try {
                        GeoIP2AutoUpdater::unzipDownloadedFile($outputPath, 'loc', $unlink = true);
                    } catch (\Exception $e) {
                        // remove downloaded file on error
                        unlink($outputPath);
                        throw $e;
                    }

                    // setup the auto updater
                    GeoIP2AutoUpdater::setUpdaterOptions(array(
                                                             'loc' => GeoIp2::GEO_LITE_URL,
                                                             'period' => GeoIP2AutoUpdater::SCHEDULE_PERIOD_MONTHLY,
                                                        ));

                    $result['settings'] = GeoIP2AutoUpdater::getConfiguredUrls();
                }

                return json_encode($result);
            } catch (Exception $ex) {
                return json_encode(array('error' => $ex->getMessage()));
            }
        }
    }
public function downloadFreeGeoIP2DB()
    {
        $this->dieIfGeolocationAdminIsDisabled();
        Piwik::checkUserHasSuperUserAccess();
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $this->checkTokenInUrl();
            Json::sendHeaderJSON();
            $outputPath = GeoIp2::getPathForGeoIpDatabase('GeoLite2-City.tar') . '.gz';
            try {
                $result = Http::downloadChunk(
                    $url = GeoIp2::GEO_LITE_URL,
                    $outputPath,
                    $continue = Common::getRequestVar('continue', true, 'int')
                );

                // if the file is done
                if ($result['current_size'] >= $result['expected_file_size']) {
                    try {
                        GeoIP2AutoUpdater::unzipDownloadedFile($outputPath, 'loc', $unlink = true);
                    } catch (\Exception $e) {
                        // remove downloaded file on error
                        unlink($outputPath);
                        throw $e;
                    }

                    // setup the auto updater
                    GeoIP2AutoUpdater::setUpdaterOptions(array(
                                                             'loc' => GeoIp2::GEO_LITE_URL,
                                                             'period' => GeoIP2AutoUpdater::SCHEDULE_PERIOD_MONTHLY,
                                                        ));

                    $result['settings'] = GeoIP2AutoUpdater::getConfiguredUrls();
                }

                return json_encode($result);
            } catch (Exception $ex) {
                return json_encode(array('error' => $ex->getMessage()));
            }
        }
    }
public function downloadFreeGeoIP2DB ( ) { $ this -> dieIfGeolocationAdminIsDisabled ( ) ; Piwik :: checkUserHasSuperUserAccess ( ) ; if ( $ _SERVER [ "REQUEST_METHOD" ] == "POST" ) { $ this -> checkTokenInUrl ( ) ; Json :: sendHeaderJSON ( ) ; $ outputPath = GeoIp2 :: getPathForGeoIpDatabase ( 'GeoLite2-City.tar' ) . '.gz' ; try { $ result = Http :: downloadChunk ( $ url = GeoIp2 :: GEO_LITE_URL , $ outputPath , $ continue = Common :: getRequestVar ( 'continue' , true , 'int' ) ) ; // if the file is done if ( $ result [ 'current_size' ] >= $ result [ 'expected_file_size' ] ) { try { GeoIP2AutoUpdater :: unzipDownloadedFile ( $ outputPath , 'loc' , $ unlink = true ) ; } catch ( \ Exception $ e ) { // remove downloaded file on error unlink ( $ outputPath ) ; throw $ e ; } // setup the auto updater GeoIP2AutoUpdater :: setUpdaterOptions ( array ( 'loc' => GeoIp2 :: GEO_LITE_URL , 'period' => GeoIP2AutoUpdater :: SCHEDULE_PERIOD_MONTHLY , ) ) ; $ result [ 'settings' ] = GeoIP2AutoUpdater :: getConfiguredUrls ( ) ; } return json_encode ( $ result ) ; } catch ( Exception $ ex ) { return json_encode ( array ( 'error' => $ ex -> getMessage ( ) ) ) ; } } }
Starts or continues download of GeoLite2-City.mmdb.

To avoid a server/PHP timeout & to show progress of the download to the user, we
use the HTTP Range header to download one chunk of the file at a time. After each
chunk, it is the browser's responsibility to call the method again to continue the download.

Input:
'continue' query param - if set to 1, will assume we are currently downloading & use
Range: HTTP header to get another chunk of the file.

Output (in JSON):
'current_size' - Current size of the partially downloaded file on disk.
'expected_file_size' - The expected finished file size as returned by the HTTP server.
'next_screen' - When the download finishes, this is the next screen that should be shown.
'error' - When an error occurs, the message is returned in this property.
Starts or continues download of GeoLite2 - City . mmdb .