summaryrefslogtreecommitdiff
path: root/ifconfig/index.php
blob: ff30813a158b9abbbfa677141420ae8ca679c4a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
}