summaryrefslogtreecommitdiff
path: root/ifconfig/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'ifconfig/index.php')
-rw-r--r--ifconfig/index.php31
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;