From a31396fb8c67f27a0055e4c4a6fa95e3cde24d1a Mon Sep 17 00:00:00 2001 From: root Date: Wed, 1 Apr 2015 23:53:58 +0200 Subject: Small improvements. --- ip/ifconfig.php | 60 ++++++++++++++++++++++++++ ip/index.php | 60 ++++++++++++++++++++++++++ ip/template.php | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 252 insertions(+) create mode 100644 ip/ifconfig.php create mode 100644 ip/index.php create mode 100644 ip/template.php (limited to 'ip') diff --git a/ip/ifconfig.php b/ip/ifconfig.php new file mode 100644 index 0000000..33ec5ba --- /dev/null +++ b/ip/ifconfig.php @@ -0,0 +1,60 @@ +ip=$ip; + } + + public function getHeader(){ + $headers = ''; + foreach ($_SERVER as $name => $value){ + if (substr($name, 0, 5) == 'HTTP_'){ + $headers[str_replace(' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5) ) ) ) )] = $value; + } + } + return $headers; + } + + public function getAllGeoipRecords(){ + + $tmp = geoip_record_by_name( $this->ip ); + if( $tmp ){ + unset($tmp['dma_code']); + unset($tmp['area_code']); + } else { + $tmp = array ( "status" => "Data not available"); + } + + return $tmp; + } + + public function encodeJson($value){ + + if( empty($value) || is_null($value) || $value == "" ) + return json_encode($output = array( "status" => "failure" )); + else + $output = array( "status" => "success" ); + + if ( ! is_array($value) ){ + $output[] = $value; + } else { + $output = array_merge($output, $value); + } + + return json_encode($output); + } + + public function getReverseDNS($ip = NULL){ + if ( is_null($ip) ) + $ip = $this->ip; + + return gethostbyaddr($ip); + } + + public function __destruct(){ + return true; + } +} diff --git a/ip/index.php b/ip/index.php new file mode 100644 index 0000000..a390ec2 --- /dev/null +++ b/ip/index.php @@ -0,0 +1,60 @@ + $ip, "hostname" => $if->getReverseDNS()); + +if( isset($_GET["geoip"]) && $_GET["geoip"] != 0){ + $geoip = $result = array_merge($result, $if->getAllGeoipRecords()); +} + +if( isset($_GET["header"]) && $_GET["header"] != 0){ + $header = $if->getHeader(); + $result = array_merge($result, $header); +} + +if( ! isset($_GET["output"]) || $_GET["output"] == "" ){ + $_GET["output"] = "html"; +} + +switch($_GET["output"]){ + case("json"): + 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; +} diff --git a/ip/template.php b/ip/template.php new file mode 100644 index 0000000..50e9b74 --- /dev/null +++ b/ip/template.php @@ -0,0 +1,132 @@ + + +
+ + + + + +$ curl http://tools.iamfabulous.de/ifconfig/ => $ curl http://tools.iamfabulous.de/ifconfig/?output=json$ curl http://tools.iamfabulous.de/ifconfig/?geoip=1&header=1&output=json
+
+
+