From aaef9981946924d5da7b244ee2c5bcd7167f6820 Mon Sep 17 00:00:00 2001 From: moehm Date: Mon, 17 Nov 2014 15:34:04 +0100 Subject: tool: ifconfig --- ifconfig/ifconfig.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ ifconfig/index.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ ifconfig/template.php | 31 +++++++++++++++++++++++++++++++ tools/navbar.php | 3 +++ 4 files changed, 133 insertions(+) create mode 100644 ifconfig/ifconfig.php create mode 100644 ifconfig/index.php create mode 100644 ifconfig/template.php diff --git a/ifconfig/ifconfig.php b/ifconfig/ifconfig.php new file mode 100644 index 0000000..215f0df --- /dev/null +++ b/ifconfig/ifconfig.php @@ -0,0 +1,51 @@ +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(){ + return geoip_record_by_name( $this->ip ); + } + + public function encodeInJson($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/ifconfig/index.php b/ifconfig/index.php new file mode 100644 index 0000000..ff30813 --- /dev/null +++ b/ifconfig/index.php @@ -0,0 +1,48 @@ + $ip, "hostname" => $if->getReverseDNS()); + +if( isset($_GET["geoip"]) && $_GET["geoip"] != 0){ + $result = array_merge($result, $if->getAllGeoipRecords()); +} + +if( isset($_GET["header"]) && $_GET["header"] != 0){ + $result = array_merge($result, $if->getHeader()); +} + +if( ! isset($_GET["output"]) || $_GET["output"] == "" ){ + $_GET["output"] = "html"; +} + +switch($_GET["output"]){ + case("json"): + echo $if->encodeJSON($result); + break; + case("html"): + require 'template.php'; + break; + default: + require 'template.php'; + break; +} diff --git a/ifconfig/template.php b/ifconfig/template.php new file mode 100644 index 0000000..2271887 --- /dev/null +++ b/ifconfig/template.php @@ -0,0 +1,31 @@ + + + + + + + + + IP API + + + + + +
+
+
+
+ $value){ + echo "
".$key."
".$value."
"; + } + ?> +
+
+
+
+ + diff --git a/tools/navbar.php b/tools/navbar.php index 1efa262..d63bcb4 100644 --- a/tools/navbar.php +++ b/tools/navbar.php @@ -15,6 +15,9 @@ +
  • + ifconfig +
  • -- cgit v1.2.3