Skip to content

Commit

Permalink
Instead of FreeGeoIP use local GeoIP database
Browse files Browse the repository at this point in the history
  • Loading branch information
plepe committed Sep 9, 2017
1 parent a06d493 commit ff3e2ba
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1 +1,4 @@
/conf.php
/vendor/
/data/
/composer.lock
5 changes: 5 additions & 0 deletions 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 changes: 5 additions & 0 deletions composer.json
@@ -0,0 +1,5 @@
{
"require": {
"geoip2/geoip2": "~2.0"
}
}
1 change: 1 addition & 0 deletions 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
Expand Down
1 change: 1 addition & 0 deletions modulekit.php
Expand Up @@ -13,6 +13,7 @@
'php' => array(
'src/options.php',
'src/language.php',
'src/ip-location.php',
),
'css' => array(
'style.css',
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Expand Up @@ -21,7 +21,6 @@ var lastPopupClose = 0
// Optional modules
require('./options')
require('./language')
require('./location')
require('./overpassChooser')
require('./fullscreen')
require('./mapLayers')
Expand Down
19 changes: 0 additions & 19 deletions src/ip-location.js

This file was deleted.

24 changes: 24 additions & 0 deletions 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 changes: 0 additions & 17 deletions src/location.js

This file was deleted.

0 comments on commit ff3e2ba

Please sign in to comment.