1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class TEST_GEOIP_COUNTRY_CODE_BY_NAME extends BuildTask |
4
|
|
|
{ |
5
|
|
|
protected $title = "Test GEOIP Functionality"; |
6
|
|
|
|
7
|
|
|
protected $description = "test a bunch of IP addresses using geoip_country_code_by_name"; |
8
|
|
|
|
9
|
|
|
private static $test_ips = array( |
10
|
|
|
"95.141.32.46" => "IT", |
11
|
|
|
"95.211.217.68" => "NL", |
12
|
|
|
"91.109.115.41" => "PT", |
13
|
|
|
"83.170.113.210" => "GB", |
14
|
|
|
"188.138.118.144" => "DE", |
15
|
|
|
"174.34.224.167" => "US", |
16
|
|
|
"72.46.140.106" => "US", |
17
|
|
|
"76.72.172.208" => "US", |
18
|
|
|
"184.75.210.226" => "CA", |
19
|
|
|
"78.40.124.16" => "FR", |
20
|
|
|
"67.205.67.76" => "CA", |
21
|
|
|
"188.138.118.184" => "DE", |
22
|
|
|
"188.138.124.110" => "DE", |
23
|
|
|
"85.17.156.99" => "NL", |
24
|
|
|
"85.17.156.11" => "NL", |
25
|
|
|
"85.17.156.76" => "NL", |
26
|
|
|
"72.46.153.26" => "US", |
27
|
|
|
"208.64.28.194" => "US", |
28
|
|
|
"76.164.194.74" => "US", |
29
|
|
|
"184.75.210.90" => "CA", |
30
|
|
|
"184.75.208.210" => "CA", |
31
|
|
|
"184.75.209.18" => "CA", |
32
|
|
|
"46.165.195.139" => "DE", |
33
|
|
|
"199.87.228.66" => "US", |
34
|
|
|
"76.72.167.90" => "US", |
35
|
|
|
"94.247.174.83" => "SE", |
36
|
|
|
"69.64.56.47" => "US", |
37
|
|
|
"184.75.210.186" => "CA", |
38
|
|
|
"108.62.115.226" => "US", |
39
|
|
|
"94.46.4.1" => "PT", |
40
|
|
|
"46.20.45.18" => "DE", |
41
|
|
|
"50.23.94.74" => "US", |
42
|
|
|
"64.141.100.136" => "CA", |
43
|
|
|
"69.59.28.19" => "US", |
44
|
|
|
"178.255.154.2" => "CZ", |
45
|
|
|
"178.255.153.2" => "CH", |
46
|
|
|
"178.255.155.2" => "IT", |
47
|
|
|
"64.237.55.3" => "US", |
48
|
|
|
"178.255.152.2" => "AT", |
49
|
|
|
"212.84.74.156" => "GB", |
50
|
|
|
"173.204.85.217" => "US", |
51
|
|
|
"173.248.147.18" => "US", |
52
|
|
|
"72.46.130.42" => "US", |
53
|
|
|
"94.46.240.121" => "ES", |
54
|
|
|
"208.43.68.59" => "US", |
55
|
|
|
"67.228.213.178" => "US", |
56
|
|
|
"96.31.66.245" => "US", |
57
|
|
|
"82.103.128.63" => "DK", |
58
|
|
|
"174.34.156.130" => "US", |
59
|
|
|
"70.32.40.2" => "US", |
60
|
|
|
"174.34.162.242" => "US", |
61
|
|
|
"85.25.176.167" => "FR", |
62
|
|
|
"204.152.200.42" => "US", |
63
|
|
|
"95.211.87.85" => "NL", |
64
|
|
|
"5.178.78.77" => "SE", |
65
|
|
|
"207.244.80.239" => "US", |
66
|
|
|
"159.8.146.132" => "GB", |
67
|
|
|
"50.22.90.227" => "US", |
68
|
|
|
"69.64.56.153" => "US", |
69
|
|
|
"188.138.40.20" => "DE", |
70
|
|
|
"64.120.6.122" => "US", |
71
|
|
|
"158.58.173.160" => "IT", |
72
|
|
|
"76.72.171.180" => "US", |
73
|
|
|
"72.46.140.186" => "US", |
74
|
|
|
"78.31.69.179" => "DE", |
75
|
|
|
"95.211.198.87" => "NL" |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
public function run($request) |
79
|
|
|
{ |
80
|
|
|
if (isset($_GET["ip"])) { |
81
|
|
|
$ar = array($_GET["ip"] => "user defined"); |
82
|
|
|
} else { |
83
|
|
|
$ar = Config::inst()->get('TEST_GEOIP_COUNTRY_CODE_BY_NAME', 'test_ips'); |
84
|
|
|
} |
85
|
|
|
if (count($ar)) { |
86
|
|
|
foreach ($ar as $ip => $description) { |
|
|
|
|
87
|
|
|
$codeArray = Geoip::ip2country($ip); |
88
|
|
|
echo "<hr /><h2>$ip: ---".print_r($codeArray, 1)."---</h2>"; |
89
|
|
|
if ($codeArray["code"] != $description && strlen($description) == 2) { |
90
|
|
|
DB::alteration_message("ERROR - this should be: ".$description, "deleted"); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
echo " |
95
|
|
|
<hr /> |
96
|
|
|
<p> |
97
|
|
|
You can also add your own IP address at the end of the URL |
98
|
|
|
- e.g. dev/tasks/TEST_GEOIP_COUNTRY_CODE_BY_NAME?ip=111.111.111.111 |
99
|
|
|
to test a specific IP address |
100
|
|
|
</p>"; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.