| @@ -6,6 +6,13 @@ use MaxMind\Db\Reader; |
| 6 | function loadGeo(string $ipAddress): ?array |
6 | function loadGeo(string $ipAddress): ?array |
| 7 | { |
7 | { |
| 8 | $databaseFile = 'GeoLite2-City.mmdb'; |
8 | $databaseFile = 'GeoLite2-City.mmdb'; |
| |
9 | |
| |
10 | // Not shipped with the source: it is MaxMind-licensed and ~69 MB. Without |
| |
11 | // it the page still serves, just with no geolocation block. |
| |
12 | if (!is_readable($databaseFile)) { |
| |
13 | return null; |
| |
14 | } |
| |
15 | |
| 9 | $reader = new Reader($databaseFile); |
16 | $reader = new Reader($databaseFile); |
| 10 | $results = $reader->get($ipAddress); |
17 | $results = $reader->get($ipAddress); |
| 11 | $reader->close(); |
18 | $reader->close(); |
| @@ -17,7 +24,7 @@ function loadGeo(string $ipAddress): ?array |
| 17 | $site_title = 'ip.cleberg.net'; |
24 | $site_title = 'ip.cleberg.net'; |
| 18 | $site_owner_name = 'Christian Cleberg'; |
25 | $site_owner_name = 'Christian Cleberg'; |
| 19 | $site_owner_url = 'https://cleberg.net'; |
26 | $site_owner_url = 'https://cleberg.net'; |
| 20 | $source_repository = 'https://git.cleberg.net/ifconfig.php.git'; |
27 | $source_repository = 'https://github.com/krazywarez/ifconfig.php'; |
| 21 | |
28 | |
| 22 | // Extract geolocation |
29 | // Extract geolocation |
| 23 | $geo = loadGeo($_SERVER['REMOTE_ADDR']); |
30 | $geo = loadGeo($_SERVER['REMOTE_ADDR']); |
| @@ -40,12 +47,12 @@ $user = array( |
| 40 | 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'], |
47 | 'fwd_ip' => $_SERVER['HTTP_X_FORWARDED_FOR'], |
| 41 | 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""), |
48 | 'fwd_host' => (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']) : ""), |
| 42 | 'dnt' => $_SERVER['HTTP_DNT'], |
49 | 'dnt' => $_SERVER['HTTP_DNT'], |
| 43 | 'continent_code' => $geo['continent']['code'], |
50 | 'continent_code' => $geo['continent']['code'] ?? '', |
| 44 | 'continent_name' => $geo['continent']['names']['en'], |
51 | 'continent_name' => $geo['continent']['names']['en'] ?? '', |
| 45 | 'country_code' => $geo['country']['geoname_id'], |
52 | 'country_code' => $geo['country']['geoname_id'] ?? '', |
| 46 | 'country_iso' => $geo['country']['iso_code'], |
53 | 'country_iso' => $geo['country']['iso_code'] ?? '', |
| 47 | 'country_name' => $geo['country']['names']['en'], |
54 | 'country_name' => $geo['country']['names']['en'] ?? '', |
| 48 | 'time_zone' => $geo['location']['time_zone'] |
55 | 'time_zone' => $geo['location']['time_zone'] ?? '' |
| 49 | ); |
56 | ); |
| 50 | |
57 | |
| 51 | // Check request (ex. ifconfig.php?q=ip) |
58 | // Check request (ex. ifconfig.php?q=ip) |