<?php
/*
+------------------------------------------------------------------------------+
|     ShowMyIP - a plugin by nlstart
|
|	Plugin Support Site: e107.webstartinternet.com
|
|	For the e107 website system visit http://e107.org
|
|	Released under the terms and conditions of the
|	GNU General Public License (http://gnu.org).
+------------------------------------------------------------------------------+
*/
// Protect the file from direct access
//if(!defined("e107_INIT")){ exit; }

// class2.php is the heart of e107, always include it first to give access to e107 constants and variables
require_once("../../class2.php");

// Get language file (assume that the English language file is always present)
$lan_file = e_PLUGIN."showmyip/languages/".e_LANGUAGE.".php";
include_lan($lan_file);

// Check URL query
if(e_QUERY){
	$tmp = explode(".", e_QUERY); // Divide the URL query in separate arrays e.g. locator.php?full.2
	$action = $tmp[0];    // e.g. $action = 'full'
	$action_id = $tmp[1]; // e.g. $action_id = '2' Currently not used
	unset($tmp); // unset the arrays, so next time URL query will be determined as new
}

// use HEADERF for USER PAGES and e_ADMIN."auth.php" for admin pages
require_once(HEADERF);

// The heart of ShowMyIP application goes below this line
function get_showmyip() {
$ip = "";
if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR");
// PHP function getenv() doesn't work Server API is ASAPI (IIS)
else if($_SERVER["REMOTE_ADDR"]) $ip = $_SERVER["REMOTE_ADDR"];
else $ip = SHOWMYIP_CORE_01; // Return 'Unknown'
return $ip;
}

function get_fullip() {
$full = "";
// Time stamp
$timestamp = getdate();
$full .= "<b>".SHOWMYIP_CORE_02.":</b> ";
$full .= $timestamp[weekday].", ".$timestamp[month]." ".$timestamp[mday].", ".$timestamp[year]." ".$timestamp[hours].":".$timestamp[minutes].":".$timestamp[seconds]."<br />";
// Proxy (from IE)
$full .= "<b>".SHOWMYIP_CORE_03.": </b>";
$proxy=getProxyFromIE();
if(!$proxy)
  $full .= SHOWMYIP_CORE_04."<br />"; // Message: Can't find proxy
else
  $full .= $proxy."<br />";
// Proxy Wikipedia definition
$full .= SHOWMYIP_CORE_05."<br />";
// Get My GID
if (getmygid()) $full .= "<b>GID:</b> "; // Only shown if there is a value returned
if (getmygid()) $full .= getmygid()."<br />"; // Only shown if there is a value returned
// Browser (User-Agent)
$full .= "<b>".SHOWMYIP_CORE_06.":</b> ";
$full .= $_SERVER['HTTP_USER_AGENT']."<br />";
// Host name
$ip_address = get_showmyip();
$hostname = gethostbyaddr($ip_address);
$full .= "<b>".SHOWMYIP_CORE_07.":</b> ";
$full .= $hostname."<br />";
// PHP Magic quotes setting
$full .= "<b>".SHOWMYIP_CORE_08.": </b>";
if (get_magic_quotes_gpc() == 0) $full .= SHOWMYIP_CORE_09."<br />"; // Off
if (get_magic_quotes_gpc() == 1) $full .= SHOWMYIP_CORE_10."<br />"; // On
// PHP Display errors setting
$full .= "<b>".SHOWMYIP_CORE_11.": </b>";
if (ini_get('display_errors') == 0) $full .= SHOWMYIP_CORE_09."<br />"; // Off
if (ini_get('display_errors') == 1) $full .= SHOWMYIP_CORE_10."<br />"; // On
// PHP Post Max Size
$full .= "<b>".SHOWMYIP_CORE_12.": </b>";
$full .=ini_get('post_max_size')."<br />"; // xMb
// PHP Post Max Size in bytes
$full .= "<b>".SHOWMYIP_CORE_13.": </b>";
$full .=(ini_get('post_max_size')*1024*1024)."<br />";
return $full;
}

function getProxyFromIE() {
exec("reg query \"HKEY_CURRENT_USER\Software\Microsoft"."\Windows\CurrentVersion\Internet Settings\" /v ProxyEnable",$proxyenable,$proxyenable_status);
exec("reg query \"HKEY_CURRENT_USER\Software\Microsoft"."\Windows\CurrentVersion\Internet Settings\" /v ProxyServer",$proxyserver);

if($proxyenable_status!=0)
  return false; // Can't access the registry! Maybe not a M$ user...
else
  {
  $enabled=substr($proxyenable[4],-1,1);
  if($enabled==0)
    return false;
  else
    {
    $proxy=ereg_replace("^[ \t]{1,10}ProxyServer\tREG_SZ[ \t]{1,20}","",
    $proxyserver[4]);

    if(ereg("[\=\;]",$proxy))
    {
      $proxy=explode(";",$proxy);
      foreach($proxy as $i => $v)
      {
        if(ereg("http",$v))
          {
          $proxy=str_replace("http=","",$v);
          break;
          }
      }
      if(@!ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:"."[0-9]{1,5}$",$proxy))
        return false;
      else
        return $proxy;
    }
    else
      return $proxy;
    }
  }
}


// Gather the desired results in the variable $text
$ip_address = get_showmyip();
$text .="
	<table>
		<tr>
			<td>
				<h2>".SHOWMYIP_CORE_97." ".$ip_address."</h2><br />
        ";

if ($action == "") { // Inform user about full IP info
$text .="
       <br />
       ".SHOWMYIP_CORE_98."
       <br />
";
}


if ($action == full) { // Show the full IP info
$text .="
       <br />
       ".get_fullip()."
       <br />
";
}

$text .="
			</td>
		</tr>
	</table>
";

// Render the value of $text in a table.
$title = SHOWMYIP_CORE_99;
$ns -> tablerender($title, $text);

// === End of BODY ===
// use FOOTERF for USER PAGES and e_ADMIN.'footer.php' for admin pages
require_once(FOOTERF);
?> 