diff options
Diffstat (limited to 'ifconfig')
| -rw-r--r-- | ifconfig/ifconfig.php | 7 | ||||
| -rw-r--r-- | ifconfig/index.php | 31 | ||||
| -rw-r--r-- | ifconfig/template.php | 105 |
3 files changed, 131 insertions, 12 deletions
diff --git a/ifconfig/ifconfig.php b/ifconfig/ifconfig.php index 215f0df..cf1dc8f 100644 --- a/ifconfig/ifconfig.php +++ b/ifconfig/ifconfig.php @@ -19,10 +19,13 @@ class Ifconfig { } public function getAllGeoipRecords(){ - return geoip_record_by_name( $this->ip ); + $tmp = geoip_record_by_name( $this->ip ); + unset($tmp['dma_code']); + unset($tmp['area_code']); + return $tmp; } - public function encodeInJson($value){ + public function encodeJson($value){ if( empty($value) || is_null($value) || $value == "" ) return json_encode($output = array( "status" => "failure" )); 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; diff --git a/ifconfig/template.php b/ifconfig/template.php index 2271887..50e9b74 100644 --- a/ifconfig/template.php +++ b/ifconfig/template.php @@ -17,13 +17,114 @@ <div class="container"> <div class="text-center"> <div class="row"> + <h1>Ifconfig</h1> + <h3>Basic IP API/Look up.</h3> + <hr> + <?php if( isset($geoip) ){ + ?> + + <h3 class="text-left"><strong>IP API</strong></h3> + <dl class="dl-horizontal"> + <?php + foreach($geoip as $key => $value){ + echo "<dt>".str_replace('_', ' ', ucfirst($key))."</dt><dd class='text-left'>".$value."</dd>"; + } + ?> + </dl> + <?php + } + if ( isset($header) ){ + ?> + <h3 class="text-left"><strong>HTTP Header</strong></h3> <dl class="dl-horizontal"> <?php - foreach($result as $key => $value){ - echo " <dt>".$key."</dd><dd>".$value."</dd>"; + foreach($header as $key => $value){ + echo "<dt>".$key."</dt><dd class='text-left'>".$value."</dd>"; } ?> </dl> + <?php + } + ?> + + <form class="form-horizontal"> + <fieldset> + + <!-- Form Name --> + <legend></legend> + + <!-- Text input--> + <div class="form-group"> + <label class="col-md-4 control-label" for="input">IP/Domain</label> + <div class="col-md-4"> + <input id="input" name="ip" placeholder="Look up a host based on IP or FQDN." class="form-control input-md" type="text"> + <!--span class="help-block text-left">Look up a host based on IP or FQDN.</span--> + </div> + </div> + + + <div class="text-left"> + <div class="form-group"> + <label class="col-md-4 control-label" for="geoip">Show GeoIP Data</label> + <div class="col-md-4"> + <input id="geoip" name="geoip" value="1" type="checkbox" checked> + </div> + </div> + </div> + + <div class="text-left"> + <div class="form-group"> + <label class="col-md-4 control-label" for="requestheader">Show Request Header</label> + <div class="col-md-4"> + <input id="requestheader" name="header" value="1" type="checkbox" checked> + </div> + </div> + </div> + +<div class="text-center"> +<!-- Multiple Radios (inline) --> +<div class="form-group text-left"> + <label class="col-md-4 control-label" for="output"></label> + <!--label class="col-md-4" for="output">Output Format</label--> + <div class="col-md-4"> + <label class="radio-inline" for="output-0"> + <input name="output" id="output-0" value="html" checked="checked" type="radio"> + HTML + </label> + <label class="radio-inline" for="output-1"> + <input name="output" id="output-1" value="json" type="radio"> + JSON + </label> + <label class="radio-inline" for="output-2"> + <input name="output" id="output-2" value="php" type="radio"> + PHP (serialized) + </label> +<span class="help-block text-left">Choose output format.</span> + </div> +</div> +</div> + + <!-- Button --> + <div class="form-group"> + <label class="col-md-4 control-label" for=""></label> + <div class="col-md-4"> + <button id="" name="" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> Look Up</button> + </div> + </div> + + <!--input type="hidden" name="output" value="html"--> + + </fieldset> + </form> + <hr> + + <h4>Command Line Interface: </h4> + <!--p class="">Command Line Interface: <code>$ curl http://tools.iamfabulous.de/ifconfig/</code></p--> + Get IP: <code>$ curl http://tools.iamfabulous.de/ifconfig/</code> => <?php echo $_SERVER['REMOTE_ADDR']; ?><br> + JSON: <code>$ curl http://tools.iamfabulous.de/ifconfig/?output=json</code><br> + Get everything: <code>$ curl http://tools.iamfabulous.de/ifconfig/?geoip=1&header=1&output=json</code> + <!--p class="">JSON: <code>$ curl http://tools.iamfabulous.de/ifconfig/&geoip=1&header=1&output=json</code></p--> + </div> </div> </div> |
