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 IP2Location\Database; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class IP2LocationBinLookup. |
18
|
|
|
*/ |
19
|
|
|
class IP2LocationBinLookup extends AbstractLocalDataLookup |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @return string |
23
|
|
|
*/ |
24
|
|
|
public function getAttribution() |
25
|
|
|
{ |
26
|
|
|
return 'IP2Location Local Bin File DB9BIN only'; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function getLocalDataStoreFilepath() |
33
|
|
|
{ |
34
|
|
|
return $this->getDataDir(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
public function getRemoteDateStoreDownloadUrl() |
41
|
|
|
{ |
42
|
|
|
$usernamePass = explode(':', $this->auth); |
43
|
|
|
$data = []; |
44
|
|
|
|
45
|
|
|
if (isset($usernamePass[0]) && isset($usernamePass[1])) { |
46
|
|
|
$data['login'] = $usernamePass[0]; |
47
|
|
|
$data['password'] = $usernamePass[1]; |
48
|
|
|
$data['productcode'] = 'DB9BIN'; |
49
|
|
|
$queryString = http_build_query($data); |
50
|
|
|
// the system gets the file name from end of remove file path url so use hardedcoded name |
51
|
|
|
$queryString .= '&filename=/ip2locaion.zip'; |
52
|
|
|
|
53
|
|
|
return 'https://www.ip2location.com/download?'.$queryString; |
54
|
|
|
} else { |
55
|
|
|
$this->logger->warn('Both username and password are required'); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Extract the IP from the local database. |
61
|
|
|
*/ |
62
|
|
|
protected function lookup() |
63
|
|
|
{ |
64
|
|
|
try { |
65
|
|
|
$reader = new Database($this->getLocalDataStoreFilepath().'/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE.BIN', Database::FILE_IO); |
66
|
|
|
$record = $reader->lookup($this->ip, Database::ALL); |
67
|
|
|
|
68
|
|
|
if (isset($record['countryName'])) { |
69
|
|
|
$this->country = $record['countryName']; |
70
|
|
|
$this->region = $record['regionName']; |
71
|
|
|
$this->city = $record['cityName']; |
72
|
|
|
$this->latitude = $record['latitude']; |
73
|
|
|
$this->longitude = $record['longitude']; |
74
|
|
|
$this->zipcode = $record['zipCode']; |
75
|
|
|
$this->isp = $record['isp']; |
76
|
|
|
$this->timezone = $record['timeZone']; |
77
|
|
|
} |
78
|
|
|
} catch (\Exception $exception) { |
79
|
|
|
if ($this->logger) { |
80
|
|
|
$this->logger->warn('IP LOOKUP: '.$exception->getMessage()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.