Merge branch 'master' into docker

This commit is contained in:
dosse91 2018-04-25 21:04:02 +02:00
commit ccc032e4d9

150
getIP.php
View file

@ -1,68 +1,94 @@
<?php <?php
$ip="";
header('Content-Type: text/plain; charset=utf-8'); $ip = "";
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { header('Content-Type: text/plain; charset=utf-8');
$ip=$_SERVER['HTTP_CLIENT_IP']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
} elseif (!empty($_SERVER['X-Real-IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP'];
$ip=$_SERVER['X-Real-IP']; } elseif (!empty($_SERVER['X-Real-IP'])) {
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['X-Real-IP'];
$ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
} else { $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ip=$_SERVER['REMOTE_ADDR']; } else {
} $ip = $_SERVER['REMOTE_ADDR'];
$ip=preg_replace("/^::ffff:/", "", $ip); }
/**
* Optimized algorithm from http://www.codexworld.com $ip = preg_replace("/^::ffff:/", "", $ip);
*
* @param float $latitudeFrom if (strpos($ip, '::1') !== false) {
* @param float $longitudeFrom echo $ip . " - localhost ipv6 access";
* @param float $latitudeTo die();
* @param float $longitudeTo }
* if (strpos($ip, '127.0.0') !== false) {
* @return float [km] echo $ip . " - localhost ipv4 access";
*/ die();
function distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo){ }
$rad = M_PI / 180;
$theta = $longitudeFrom - $longitudeTo; /**
$dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad); * Optimized algorithm from http://www.codexworld.com
return acos($dist) / $rad * 60 * 1.853; *
} * @param float $latitudeFrom
if(isset($_GET["isp"])){ * @param float $longitudeFrom
$isp=""; * @param float $latitudeTo
try{ * @param float $longitudeTo
$json = file_get_contents("https://ipinfo.io/".$ip."/json"); *
$details = json_decode($json,true); * @return float [km]
if(array_key_exists("org",$details)) $isp.=$details["org"]; else $isp.="Unknown ISP"; */
if(array_key_exists("country",$details)) $isp.=", ".$details["country"]; function distance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo) {
$clientLoc=NULL; $serverLoc=NULL; $rad = M_PI / 180;
if(array_key_exists("loc",$details)) $clientLoc=$details["loc"]; $theta = $longitudeFrom - $longitudeTo;
if(isset($_GET["distance"])){ $dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad);
if($clientLoc){ return acos($dist) / $rad * 60 * 1.853;
$json = file_get_contents("https://ipinfo.io/json"); }
$details = json_decode($json,true);
if(array_key_exists("loc",$details)) $serverLoc=$details["loc"]; if (isset($_GET["isp"])) {
if($serverLoc){ $isp = "";
try{ try {
$clientLoc=explode(",",$clientLoc); $json = file_get_contents("https://ipinfo.io/" . $ip . "/json");
$serverLoc=explode(",",$serverLoc); $details = json_decode($json, true);
$dist=distance($clientLoc[0],$clientLoc[1],$serverLoc[0],$serverLoc[1]); if (array_key_exists("org", $details))
if($_GET["distance"]=="mi"){ $isp .= $details["org"];
$dist/=1.609344; else
$dist=round($dist,-1); $isp .= "Unknown ISP";
if($dist<15) $dist="<15"; if (array_key_exists("country", $details))
$isp.=" (".$dist." mi)"; $isp .= ", " . $details["country"];
}else if($_GET["distance"]=="km"){ $clientLoc = NULL;
$dist=round($dist,-1); $serverLoc = NULL;
if($dist<20) $dist="<20"; if (array_key_exists("loc", $details))
$isp.=" (".$dist." km)"; $clientLoc = $details["loc"];
} if (isset($_GET["distance"])) {
}catch(Exception $e){} if ($clientLoc) {
$json = file_get_contents("https://ipinfo.io/json");
$details = json_decode($json, true);
if (array_key_exists("loc", $details))
$serverLoc = $details["loc"];
if ($serverLoc) {
try {
$clientLoc = explode(",", $clientLoc);
$serverLoc = explode(",", $serverLoc);
$dist = distance($clientLoc[0], $clientLoc[1], $serverLoc[0], $serverLoc[1]);
if ($_GET["distance"] == "mi") {
$dist /= 1.609344;
$dist = round($dist, -1);
if ($dist < 15)
$dist = "<15";
$isp .= " (" . $dist . " mi)";
}else if ($_GET["distance"] == "km") {
$dist = round($dist, -1);
if ($dist < 20)
$dist = "<20";
$isp .= " (" . $dist . " km)";
}
} catch (Exception $e) {
} }
} }
} }
}catch(Exception $ex){
$isp="Unknown ISP";
} }
echo $ip." - ".$isp; } catch (Exception $ex) {
} else echo $ip; $isp = "Unknown ISP";
}
echo $ip . " - " . $isp;
} else {
echo $ip;
}
?> ?>