summaryrefslogtreecommitdiff
path: root/ifconfig
diff options
context:
space:
mode:
authormoehm2014-11-17 15:34:04 +0100
committermoehm2014-11-17 15:34:04 +0100
commitaaef9981946924d5da7b244ee2c5bcd7167f6820 (patch)
tree9c991e7bd077c6eaffc0ac04da6b578c456b04cd /ifconfig
parentf7755964e8703d66cee123a18519a07d49df0ae0 (diff)
downloadtools.iamfabulous.de-aaef9981946924d5da7b244ee2c5bcd7167f6820.tar.gz
tool: ifconfig
Diffstat (limited to 'ifconfig')
-rw-r--r--ifconfig/ifconfig.php51
-rw-r--r--ifconfig/index.php48
-rw-r--r--ifconfig/template.php31
3 files changed, 130 insertions, 0 deletions
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 @@
+<?php
+
+class Ifconfig {
+
+ public $ip;
+
+ public function __construct($ip){
+ $this->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 @@
+<?php
+
+if ( strpos($_SERVER['HTTP_USER_AGENT'], 'libcurl') === true ){
+ echo $_SERVER["REMOTE_ADDR"];
+ exit;
+}
+
+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");
+ exit;
+}
+
+if ( ! isset($_GET["ip"]) || $_GET["ip"] == "" ){
+ $ip = $_SERVER["REMOTE_ADDR"];
+} else {
+ $ip = $_GET["ip"];
+}
+
+require 'ifconfig.php';
+
+$if = new Ifconfig($ip);
+
+$result = array("ip" => $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 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
+ <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
+ <style>
+ <?php echo file_get_contents("../tools/style.css"); ?>
+ </style>
+ <noscript><style>.navbar{margin-bottom:0;}</style></noscript>
+ <title>IP API</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel='shortcut icon' href='../tools/favicon.ico' type='image/x-icon'>
+</head>
+<body>
+ <?php require("../tools/navbar.php"); ?>
+<div class="container">
+ <div class="text-center">
+ <div class="row">
+ <dl class="dl-horizontal">
+ <?php
+ foreach($result as $key => $value){
+ echo " <dt>".$key."</dd><dd>".$value."</dd>";
+ }
+ ?>
+ </dl>
+ </div>
+ </div>
+</div>
+
+ <?php require("../tools/footer.php"); ?>