diff --git a/backend/getIP.php b/backend/getIP.php index 902e2e4..7d7c400 100644 --- a/backend/getIP.php +++ b/backend/getIP.php @@ -7,8 +7,13 @@ error_reporting(0); $ip = ""; header('Content-Type: application/json; charset=utf-8'); -header('Access-Control-Allow-Origin: *'); -header('Access-Control-Allow-Methods: GET, POST'); +if(isset($_GET["cors"])){ + header('Access-Control-Allow-Origin: *'); + header('Access-Control-Allow-Methods: GET, POST'); +} +header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0, s-maxage=0'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['X-Real-IP'])) { @@ -42,10 +47,6 @@ if (preg_match('/^172\.(1[6-9]|2\d|3[01])\./', $ip) === 1) { // 172.16/12 privat echo json_encode(['processedString' => $ip . " - private IPv4 access", 'rawIspInfo' => ""]); die(); } -if (preg_match('/^100\.([6-9][0-9]|1[0-2][0-7])\./', $ip) === 1) { // 100.64/10 CGNAT IPv4 - echo json_encode(['processedString' => $ip . " - CGNAT IPv4 access", 'rawIspInfo' => ""]); - die(); -} if (strpos($ip, '192.168.') === 0) { // 192.168/16 private IPv4 echo json_encode(['processedString' => $ip . " - private IPv4 access", 'rawIspInfo' => ""]); die(); @@ -71,12 +72,18 @@ function distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo) { $dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad); return acos($dist) / $rad * 60 * 1.853; } - +function getIpInfoTokenString(){ + $apikeyFile="getIP_ipInfo_apikey.php"; + if(!file_exists($apikeyFile)) return ""; + require $apikeyFile; + if(empty($IPINFO_APIKEY)) return ""; + return "?token=".$IPINFO_APIKEY; +} if (isset($_GET["isp"])) { $isp = ""; $rawIspInfo=null; try { - $json = file_get_contents("https://ipinfo.io/" . $ip . "/json"); + $json = file_get_contents("https://ipinfo.io/" . $ip . "/json".getIpInfoTokenString()); $details = json_decode($json, true); $rawIspInfo=$details; if (array_key_exists("org", $details)){ @@ -100,7 +107,7 @@ if (isset($_GET["isp"])) { if(file_exists($locFile)){ require $locFile; }else{ - $json = file_get_contents("https://ipinfo.io/json"); + $json = file_get_contents("https://ipinfo.io/json".getIpInfoTokenString()); $details = json_decode($json, true); if (array_key_exists("loc", $details)){ $serverLoc = $details["loc"];