1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* @copyright 2015 Mautic Contributors. All rights reserved |
5
|
|
|
* @author Mautic |
6
|
|
|
* |
7
|
|
|
* @link http://mautic.org |
8
|
|
|
* |
9
|
|
|
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mautic\CoreBundle\IpLookup; |
13
|
|
|
|
14
|
|
|
use GeoIp2\Database\Reader; |
15
|
|
|
|
16
|
|
|
class MaxmindDownloadLookup extends AbstractLocalDataLookup |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @return string |
20
|
|
|
*/ |
21
|
|
|
public function getAttribution() |
22
|
|
|
{ |
23
|
|
|
return 'Free lookup that leverages GeoLite2 data created by MaxMind, available from <a href="https://maxmind.com" target="_blank">maxmind.com</a>. Databases must be downloaded and periodically updated.'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return string |
28
|
|
|
*/ |
29
|
|
|
public function getLocalDataStoreFilepath() |
30
|
|
|
{ |
31
|
|
|
return $this->getDataDir().'/GeoLite2-City.mmdb'; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return string |
36
|
|
|
*/ |
37
|
|
|
public function getRemoteDateStoreDownloadUrl() |
38
|
|
|
{ |
39
|
|
|
if (!empty($this->getLicenceKey())) { |
40
|
|
|
$data = []; |
41
|
|
|
$data['license_key'] = $this->getLicenceKey(); |
42
|
|
|
$data['edition_id'] = 'GeoLite2-City'; |
43
|
|
|
$data['suffix'] = 'tar.gz'; |
44
|
|
|
$queryString = http_build_query($data); |
45
|
|
|
|
46
|
|
|
return 'https://download.maxmind.com/app/geoip_download?'.$queryString; |
47
|
|
|
} else { |
48
|
|
|
$this->logger->warn('MaxMind license key is required.'); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
private function getLicenceKey() |
56
|
|
|
{ |
57
|
|
|
$auth = explode(':', $this->auth, 2); |
58
|
|
|
if (array_key_exists(1, $auth)) { |
59
|
|
|
return $auth[1]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return ''; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Extract the IP from the local database. |
67
|
|
|
*/ |
68
|
|
|
protected function lookup() |
69
|
|
|
{ |
70
|
|
|
try { |
71
|
|
|
$reader = new Reader($this->getLocalDataStoreFilepath()); |
72
|
|
|
$record = $reader->city($this->ip); |
73
|
|
|
|
74
|
|
|
if (isset($record->subdivisions[0])) { |
75
|
|
|
if (count($record->subdivisions) > 1) { |
76
|
|
|
// Use the first listed as the country and second as state |
77
|
|
|
// UK -> England -> Winchester |
78
|
|
|
$this->country = $record->subdivisions[0]->name; |
79
|
|
|
$this->region = $record->subdivisions[1]->name; |
80
|
|
|
} else { |
81
|
|
|
$this->region = $record->subdivisions[0]->name; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->city = $record->city->name; |
86
|
|
|
$this->country = $record->country->name; |
87
|
|
|
$this->latitude = $record->location->latitude; |
88
|
|
|
$this->longitude = $record->location->longitude; |
89
|
|
|
$this->timezone = $record->location->timeZone; |
90
|
|
|
$this->zipcode = $record->location->postalCode; |
91
|
|
|
} catch (\Exception $exception) { |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.