summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot2014-11-17 20:10:50 +0100
committerroot2014-11-17 20:10:50 +0100
commit2b24f3ef0e800f878177973eefcb28380a292503 (patch)
tree43ec21909460cf947d13a6a5056216c145bd66f9
parentaaef9981946924d5da7b244ee2c5bcd7167f6820 (diff)
downloadtools.iamfabulous.de-2b24f3ef0e800f878177973eefcb28380a292503.tar.gz
ifconfig stable
-rw-r--r--ifconfig/ifconfig.php7
-rw-r--r--ifconfig/index.php31
-rw-r--r--ifconfig/template.php105
-rw-r--r--tools/footer.php2
-rw-r--r--tools/navbar.php2
-rw-r--r--tools/style.css6
6 files changed, 139 insertions, 14 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&amp;header=1&amp;output=json</code>
+ <!--p class="">JSON: <code>$ curl http://tools.iamfabulous.de/ifconfig/&amp;geoip=1&amp;header=1&amp;output=json</code></p-->
+
</div>
</div>
</div>
diff --git a/tools/footer.php b/tools/footer.php
index fedea9f..ce072aa 100644
--- a/tools/footer.php
+++ b/tools/footer.php
@@ -23,5 +23,5 @@
return n;
}
- addClass("<?php echo trim(str_replace("/index.php", "", $_SERVER["PHP_SELF"] ), "/");?>", "active");
+ addClass("<?php echo trim(str_replace("/index.php", "", $_SERVER["PHP_SELF"] ), "/");?>", "actives");
</script>
diff --git a/tools/navbar.php b/tools/navbar.php
index d63bcb4..5546fc3 100644
--- a/tools/navbar.php
+++ b/tools/navbar.php
@@ -16,7 +16,7 @@
<a href="/header/" title="Check HTTP header online!"><span class="glyphicon glyphicon-globe"></span> Header</a>
</li>
<li id="ifconfig">
- <a href="/ifconfig/" title="Simple IP API"><span class="glyphicon glyphicon-info-sign"></span> ifconfig</a>
+ <a href="/ifconfig/" title="Simple IP API"><span class="glyphicon glyphicon-transfer"></span> ifconfig</a>
</li>
</ul>
</div>
diff --git a/tools/style.css b/tools/style.css
index 02249d3..b5aa321 100644
--- a/tools/style.css
+++ b/tools/style.css
@@ -60,3 +60,9 @@ a {
.underline {
text-decoration: underline;
}
+
+.actives {
+ color: white !important;
+ text-decoration: underline;
+ font-weight: bold;
+}