Skip to content

Commit

Permalink
Completely remove offline location db support.
Browse files Browse the repository at this point in the history
  • Loading branch information
IRainman committed Aug 16, 2024
1 parent 18a5ac6 commit 9efcca5
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
Binary file removed backend/country_asn.mmdb
Binary file not shown.
Binary file removed backend/geoip2.phar
Binary file not shown.
29 changes: 2 additions & 27 deletions backend/getIP.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

define('API_KEY_FILE', 'getIP_ipInfo_apikey.php');
define('SERVER_LOCATION_CACHE_FILE', 'getIP_serverLocation.php');
define('OFFLINE_IPINFO_DB_FILE', 'country_asn.mmdb');

require_once 'getIP_util.php';

Expand Down Expand Up @@ -134,25 +133,6 @@ function getIspInfo_ipinfoApi($ip){
]);
}

if (PHP_MAJOR_VERSION >= 8){
require_once("geoip2.phar");
}
function getIspInfo_ipinfoOfflineDb($ip){
if (PHP_MAJOR_VERSION < 8 || !file_exists(OFFLINE_IPINFO_DB_FILE) || !is_readable(OFFLINE_IPINFO_DB_FILE)){
return null;
}
$reader = new MaxMind\Db\Reader(OFFLINE_IPINFO_DB_FILE);
$data = $reader->get($ip);
if(!is_array($data)){
return null;
}
$processedString = $ip.' - ' . $data['as_name'] . ', ' . $data['country_name'];
return json_encode([
'processedString' => $processedString,
'rawIspInfo' => $data ?: '',
]);
}

function formatResponse_simple($ip,$ispName=null){
$processedString=$ip;
if(is_string($ispName)){
Expand All @@ -174,7 +154,7 @@ function formatResponse_simple($ip,$ispName=null){
header('Pragma: no-cache');

$ip = getClientIp();
//if the user requested the ISP info, we first try to fetch it using ipinfo.io (if there is no api key set it fails without sending data, it can also fail because of rate limiting or invalid responses), then we try with the offline db, if that also fails (or if ISP info was not requested) we just respond with the IP address
//if the user requested the ISP info, we first try to fetch it using ipinfo.io (if there is no api key set it fails without sending data, it can also fail because of rate limiting or invalid responses), then if fails (or if ISP info was not requested) we just respond with the IP address
if(isset($_GET['isp'])){
$localIpInfo = getLocalOrPrivateIpInfo($ip);
//local ip, no need to fetch further information
Expand All @@ -185,12 +165,7 @@ function formatResponse_simple($ip,$ispName=null){
if(!is_null($r)){
echo $r;
}else{
$r=getIspInfo_ipinfoOfflineDb($ip);
if(!is_null($r)){
echo $r;
}else{
echo formatResponse_simple($ip);
}
echo formatResponse_simple($ip);
}
}
}else{
Expand Down

0 comments on commit 9efcca5

Please sign in to comment.