Browse Source

Instead of FreeGeoIP use local GeoIP database

master
parent
commit
ff3e2bad8c
  1. 3
      .gitignore
  2. 5
      bin/download_dependencies
  3. 5
      composer.json
  4. 1
      index.php
  5. 1
      modulekit.php
  6. 1
      src/index.js
  7. 19
      src/ip-location.js
  8. 24
      src/ip-location.php
  9. 17
      src/location.js

3
.gitignore

@ -1 +1,4 @@
/conf.php
/vendor/
/data/
/composer.lock

5
bin/download_dependencies

@ -0,0 +1,5 @@
#!/bin/sh
mkdir -p data/GeoIP
cd data/GeoIP
wget -O- http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz | tar --strip-components=1 -xvzf -

5
composer.json

@ -0,0 +1,5 @@
{
"require": {
"geoip2/geoip2": "~2.0"
}
}

1
index.php

@ -1,5 +1,6 @@
<?php include "conf.php"; /* load a local configuration */ ?>
<?php session_start(); ?>
<?php require 'vendor/autoload.php'; /* composer includes */ ?>
<?php include "modulekit/loader.php"; /* loads all php-includes */ ?>
<?php call_hooks("init"); /* initialize submodules */ ?>
<?php

1
modulekit.php

@ -13,6 +13,7 @@ $include = array(
'php' => array(
'src/options.php',
'src/language.php',
'src/ip-location.php',
),
'css' => array(
'style.css',

1
src/index.js

@ -21,7 +21,6 @@ var lastPopupClose = 0
// Optional modules
require('./options')
require('./language')
require('./location')
require('./overpassChooser')
require('./fullscreen')
require('./mapLayers')

19
src/ip-location.js

@ -1,19 +0,0 @@
var ipLocation = require('ip-location')
ipLocation.httpGet = function (url, callback) {
var xhr = new XMLHttpRequest()
xhr.open('get', url, true)
xhr.responseType = 'text'
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
callback(null, { body: xhr.responseText })
} else {
callback(xhr.responseText)
}
}
}
xhr.send()
}
module.exports = ipLocation

24
src/ip-location.php

@ -0,0 +1,24 @@
<?php
use GeoIp2\Database\Reader;
register_hook('init', function () {
global $config;
if (isset($config['checkIpLocation']) && !$config['checkIpLocation']) {
return;
}
$reader = new Reader('data/GeoIP/GeoLite2-City.mmdb');
try {
$record = $reader->city($_SERVER['REMOTE_ADDR']);
$config['defaultView']['lat'] = $record->location->latitude;
$config['defaultView']['lon'] = $record->location->longitude;
$config['defaultView']['zoom'] = 10;
}
catch (Exception $e) {
// ignore error
trigger_error("Can't resolve IP address: " . $e->getMessage(), E_USER_WARNING);
}
});

17
src/location.js

@ -1,17 +0,0 @@
var ipLocation = require('./ip-location')
register_hook('init_callback', function (initState, callback) {
if ('checkIpLocation' in config && !config.checkIpLocation) {
return callback()
}
ipLocation('', function (err, ipLoc) {
if (typeof ipLoc === 'object' && 'latitude' in ipLoc) {
initState.zoom = 14
initState.lat = ipLoc.latitude
initState.lon = ipLoc.longitude
}
callback(err)
})
})
Loading…
Cancel
Save