diff options
| author | root | 2014-11-17 20:10:50 +0100 |
|---|---|---|
| committer | root | 2014-11-17 20:10:50 +0100 |
| commit | 2b24f3ef0e800f878177973eefcb28380a292503 (patch) | |
| tree | 43ec21909460cf947d13a6a5056216c145bd66f9 /ifconfig/index.php | |
| parent | aaef9981946924d5da7b244ee2c5bcd7167f6820 (diff) | |
| download | tools.iamfabulous.de-2b24f3ef0e800f878177973eefcb28380a292503.tar.gz | |
ifconfig stable
Diffstat (limited to 'ifconfig/index.php')
| -rw-r--r-- | ifconfig/index.php | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/ifconfig/index.php b/ifconfig/index.php index ff30813..b87d316 100644 --- a/ifconfig/index.php +++ b/ifconfig/index.php @@ -1,20 +1,29 @@ <?php -if ( strpos($_SERVER['HTTP_USER_AGENT'], 'libcurl') === true ){ - echo $_SERVER["REMOTE_ADDR"]; - exit; +if ( strpos($_SERVER['HTTP_USER_AGENT'], 'libcurl') ){ + if ( empty($_GET) ){ + echo $_SERVER["REMOTE_ADDR"]; + exit; + } else { + // avoid redirect + $_GET["curl"] = true; + } } if ( empty($_GET) ){ header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved"); - header("Location: http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_Self"]."?ip=".$_SERVER["REMOTE_ADDR"]."&geoip=1&header=1&output=html"); + header("Location: http://".$_SERVER["HTTP_HOST"].str_replace("/index.php", "", $_SERVER["PHP_SELF"] )."/?ip=".$_SERVER["REMOTE_ADDR"]."&geoip=1&header=1&output=html"); exit; } if ( ! isset($_GET["ip"]) || $_GET["ip"] == "" ){ $ip = $_SERVER["REMOTE_ADDR"]; } else { - $ip = $_GET["ip"]; + if( preg_match("/([0-9]+\.){3}[0-9]+/", $ip) ){ + $ip = $_GET["ip"]; + } else { + $ip = gethostbyname($_GET["ip"]); + } } require 'ifconfig.php'; @@ -24,11 +33,12 @@ $if = new Ifconfig($ip); $result = array("ip" => $ip, "hostname" => $if->getReverseDNS()); if( isset($_GET["geoip"]) && $_GET["geoip"] != 0){ - $result = array_merge($result, $if->getAllGeoipRecords()); + $geoip = $result = array_merge($result, $if->getAllGeoipRecords()); } if( isset($_GET["header"]) && $_GET["header"] != 0){ - $result = array_merge($result, $if->getHeader()); + $header = $if->getHeader(); + $result = array_merge($result, $header); } if( ! isset($_GET["output"]) || $_GET["output"] == "" ){ @@ -37,11 +47,16 @@ if( ! isset($_GET["output"]) || $_GET["output"] == "" ){ switch($_GET["output"]){ case("json"): - echo $if->encodeJSON($result); + header("Content-Type: application/json"); + echo $if->encodeJson($result); break; case("html"): require 'template.php'; break; + case("php"): + header("Content-Type: text/plain"); + echo serialize($result); + break; default: require 'template.php'; break; |
