1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Malm18\IPChecker; |
4
|
|
|
|
5
|
|
|
class IPHandler |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Check active. |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
// public function checkIP($theIP) |
14
|
|
|
// { |
15
|
|
|
// $theIP2 = $theIP . " svansen"; |
16
|
|
|
// return $theIP2; |
17
|
|
|
// } |
18
|
|
|
|
19
|
|
|
// public function checkIP2($theIP) |
20
|
|
|
// { |
21
|
|
|
// $hostname = ""; |
22
|
|
|
// $type = ""; |
23
|
|
|
// |
24
|
|
|
// |
25
|
|
|
// if (filter_var($theIP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { |
26
|
|
|
// $type = "IPv6"; |
27
|
|
|
// $hostname = gethostbyaddr("$theIP"); |
28
|
|
|
// } elseif (filter_var($theIP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { |
29
|
|
|
// $type = "IPv4"; |
30
|
|
|
// $hostname = gethostbyaddr("$theIP"); |
31
|
|
|
// } else { |
32
|
|
|
// $type = "Inte riktig IP-adress"; |
33
|
|
|
// } |
34
|
|
|
// |
35
|
|
|
// $ipInfo = array("ipaddress"=>$theIP, "hostname"=>$hostname, "type"=>$type); |
36
|
|
|
// return $ipInfo; |
37
|
|
|
// } |
38
|
|
|
|
39
|
|
|
|
40
|
3 |
|
public function checkIP($theIP) |
41
|
|
|
{ |
42
|
3 |
|
if (filter_var($theIP, FILTER_VALIDATE_IP)) { |
43
|
1 |
|
$url = 'http://api.ipstack.com/'; |
44
|
1 |
|
$keys = require ANAX_INSTALL_PATH . "/config/keys.php"; |
45
|
|
|
// $this->ipstackKey = $keys["ipstackKey"]; |
46
|
|
|
// $apiKey = $this->ipstackKey; |
47
|
1 |
|
$apiKey = $keys["ipstackKey"]; |
48
|
1 |
|
$requestUrl = $url . $theIP . '?access_key=' . $apiKey; |
49
|
1 |
|
$curl = curl_init($requestUrl); |
50
|
|
|
// if ($curl) { |
51
|
1 |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
|
|
|
52
|
|
|
// curl_setopt($curl, CURLOPT_HTTPHEADER, [ |
53
|
|
|
// 'X-RapidAPI-Host: kvstore.p.rapidapi.com', |
54
|
|
|
// 'X-RapidAPI-Key: 7xxxxxxxxxxxxxxxxxxxxxxx', |
55
|
|
|
// 'Content-Type: application/json' |
56
|
|
|
// ]); |
57
|
1 |
|
$response = curl_exec($curl); |
|
|
|
|
58
|
1 |
|
$response2 = json_decode($response, true); |
59
|
1 |
|
curl_close($curl); |
|
|
|
|
60
|
|
|
// echo $response . PHP_EOL; |
61
|
1 |
|
return $response2; |
62
|
|
|
// } |
63
|
|
|
} else { |
64
|
2 |
|
$response = array("type" => "not valid ip", "ip" => "", "latitude"=> "", "longitude"=> "", |
65
|
|
|
"city" => "", "country_name" => "", "region_name" => "", "continent_name" => "", "location['country_code']" => ""); |
66
|
|
|
// $response2 = json_decode($response, true); |
67
|
2 |
|
return $response; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
5 |
|
public function minLong($longitude) |
73
|
|
|
{ |
74
|
|
|
|
75
|
5 |
|
$minLong = floatval($longitude) - 0.6427; |
76
|
5 |
|
return $minLong; |
77
|
|
|
} |
78
|
|
|
|
79
|
5 |
|
public function maxLong($longitude) |
80
|
|
|
{ |
81
|
|
|
|
82
|
5 |
|
$maxLong = floatval($longitude) + 0.6427; |
83
|
5 |
|
return $maxLong; |
84
|
|
|
} |
85
|
|
|
|
86
|
5 |
|
public function minLat($latitude) |
87
|
|
|
{ |
88
|
|
|
|
89
|
5 |
|
$minLat = (floatval($latitude)) - 0.260; |
90
|
5 |
|
return $minLat; |
91
|
|
|
} |
92
|
|
|
|
93
|
5 |
|
public function maxLat($latitude) |
94
|
|
|
{ |
95
|
|
|
|
96
|
5 |
|
$maxLat = (floatval($latitude)) + 0.260; |
97
|
5 |
|
return $maxLat; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
// public function mapLink($latitude, $longitude, $minLat, $maxLat, $minLong, $maxLong) |
102
|
|
|
// { |
103
|
|
|
// https://www.openstreetmap.org/export/embed.html?bbox=-6.8860333396912%2C53.093889465332%2C-5.6006333396912%2C53.613889465332&layer=mapnik&marker=53.353889465332%2-6.2433333396912 |
104
|
|
|
// // $link = "https://www.openstreetmap.org/export/embed.html?bbox=12.669982910156252%2C55.56592203025787%2C13.955383300781252%2C56.08506381314523&layer=mapnik&marker=55.82635894724891%2C13.31268310546875" |
105
|
|
|
// |
106
|
|
|
// $link = "https://www.openstreetmap.org/export/embed.html?bbox=" . $minLong . "%2C" . $minLat . "%2C" . $maxLong . "%2C" . $maxLat . "&layer=mapnik&marker=" . $latitude . "%2C" . $longitude; |
107
|
|
|
// |
108
|
|
|
// return $link; |
109
|
|
|
// } |
110
|
|
|
|
111
|
5 |
|
public function mapLink($latitude, $longitude, $minLat, $maxLat, $minLong, $maxLong) |
112
|
|
|
{ |
113
|
5 |
|
if ($latitude) { |
114
|
4 |
|
$link = "https://www.openstreetmap.org/export/embed.html?bbox=" . $minLong . "%2C" . $minLat . "%2C" . $maxLong . "%2C" . $maxLat . "&layer=mapnik&marker=" . $latitude . "%2C" . $longitude; |
115
|
|
|
} else { |
116
|
1 |
|
$link = "https://www.openstreetmap.org/export/embed.html?bbox=-0.64%2C85%2C0.64%2C90&layer=mapnik&marker=87.5%2C0"; |
117
|
|
|
} |
118
|
|
|
|
119
|
5 |
|
return $link; |
120
|
|
|
} |
121
|
|
|
|
122
|
1 |
|
public function largeMapLink($latitude, $longitude) |
123
|
|
|
{ |
124
|
1 |
|
$link = ""; |
125
|
1 |
|
if ($latitude) { |
126
|
1 |
|
$link = "https://www.openstreetmap.org/?mlat=" . $latitude . "&mlon=" . $longitude . "#map=10/" . $latitude . "/" . $longitude; |
127
|
|
|
// <a href="https://www.openstreetmap.org/?mlat=55.8264&mlon=13.3127#map=10/55.8264/13.3127"> |
128
|
|
|
} |
129
|
1 |
|
return $link; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
3 |
|
public function checkOwnIP() |
134
|
|
|
{ |
135
|
3 |
|
$remoteAddr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'; |
136
|
3 |
|
return $remoteAddr; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|