<?PHP
include "var.php";
include "install_connect.php";
include "whm_functions.php";

$WHERE[here] = "http://".$_SERVER['HTTP_HOST'];
		if (!strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) 
		{
		header("Location: $WHERE[here]");
		exit();
		}

$xinput_style="style=\"BORDER-STYLE: solid;BORDER-COLOR: #999999; BACKGROUND-COLOR: #ffffff; BORDER-WIDTH: 1px; FONT-FAMILY: Verdana; FONT-SIZE: 8pt\"";

if(phpversion() <= "4.0.6") { $_POST=$HTTP_POST_VARS; }
if ($_POST['submit'])
	{
	if (trim($_POST['license'])=="") { $e69=true; }
	else
		{
		/*
		$server_ip=$_SERVER['SERVER_ADDR'];
		$server_name=$_SERVER['SERVER_NAME'];
		$call_home_to="66.246.21.246";
		$install_dir="/newmembers";
		$inc_dir=$install_dir."/inc";
		# --> last good --> $result=call_home($server_ip, $server_name, $license, $call_home_to, $install_dir);
		# $result=call_home($server_ip, $server_name, $license);
		*/

		$call_home_to="69.93.49.28";
		$installed_directory="/";
		$querystring="iaccess_ip=".base64_encode($_SERVER['SERVER_ADDR']);
		$querystring.="&iaccess_host=".base64_encode($_SERVER['SERVER_NAME']);
		$querystring.="&license=".urlencode($license)."\n\n";

		$fp=@fsockopen($call_home_to, 80, $errno, $errstr, 5);
		if (!$fp) { return 1; }
		else
		   {
		   $header="POST ".$installed_directory."/validate_internal.php HTTP/1.1\n";
		   $header.="Host: ".$call_home_to."\n";
		   $header.="Content-Length: ".strlen($querystring)."\n";
		   $header.="Content-Type: application/x-www-form-urlencoded\n";
		   $header.="Connection: Close\n\n";
		   $header.=$querystring;

		   fputs ($fp, $header);
		   while (!feof($fp)) { $data.=@fgets($fp, 1024); }
		   fclose ($fp);

		   list($a, $result, $c)=explode("{{", $data);
			/*
		   function parse_template($template)
			  {
			  $buffer="";
			  $fh=file($template);
			  foreach($fh as $line) { $buffer.=$line; }
			  return $buffer;
			  }
		
		   $path_home="http://".$call_home_to.$installed_directory."/inc";
		   if ($b==69) 
			  { 
			  echo parse_template($path_home."/license_invalid.tpl");
			  exit; 
			  }		
		   else if ($b==2) 
			  { 
			  echo parse_template($path_home."/license_suspended.tpl"); 
			  exit;	
			  }
		   else if ($b==3) 
			  { 
			  echo parse_template($path_home."/license_expired.tpl"); 
			  exit; 
			  }
			*/
		   }

		if ($result==69) { $e69=true; }		// 69 == invalid
		else if ($result==2) { $e2=true; }	//  2 == suspended
		else if ($result==3) { $e3=true; }	//  3 == expired
		else if ($result==1) 
			{
			mysql_query("update config set license='".addslashes(trim($license))."'");
			header("Location: install4.php"); 
			exit; 
			}
		}
	}

$b=3;
include "install_header.php";

echo("
	<form action='".$PHP_SELF."' method='POST'>
	<table width='100%' cellpadding='2' cellspacing='0' border='0'>
		<tr>
			<td colspan='2'><img src='install[1].gif'>&nbsp;<font color='#0F82B8'><b>Step 3:</b></font> <b>Register WHM AutoPilot</b></td>
		</tr>
		<tr>
			<td colspan='2' align='left' valign='middle'>&nbsp;</td>
		</tr>
	");
if (isset($e69))
	{
	echo("
		<tr>
			<td colspan='2'><img src='install[26].gif'><font color='#C60C08'>You must enter a valid license number to continue.</font></td>
		</tr>
		");
	}
if (isset($e2))
	{
	echo("
		<tr>
			<td colspan='2'><img src='install[26].gif'><font color='#C60C08'>This license is suspended.</font></td>
		</tr>
		");
	}
if (isset($e3))
	{
	echo("
		<tr>
			<td colspan='2'><img src='install[26].gif'><font color='#C60C08'>This license is expired.</font></td>
		</tr>
		");
	}
if (isset($e69)||isset($e2)||isset($e3))
	{
	echo("
		<tr>
			<td colspan='2' align='left' valign='middle'>&nbsp;</td>
		</tr>
		");
	}
echo("
		<tr>
			<td width='25%' align='left' valign='top'>Enter License #:</td>
			<td width='75%' align='left' valign='middle'><textarea name='license' rows='3' cols='59' ".$xinput_style.">".((isset($license))?"".$license."":"")."</textarea></td>
		</tr>
		<tr>
			<td colspan='2' align='left' valign='middle'>&nbsp;</td>
		</tr>
		<tr>
			<td width='25%' align='left' valign='middle'></td>
			<td width='75%' align='left' valign='middle'><input type='hidden' name='submit' value='5'><input type='image' src='install[29].gif' onmouseover='this.src=\"install[30].gif\"' onmouseout='this.src=\"install[29].gif\"' alt='Click to Continue'></td>
		</tr>
	</table>
	</form>
	");

include "install_footer.php";
mysql_close($dblink);
?>