<?
if($_POST['action'] == "view")
$_GET['action'] = "view";
if(!$_GET['action'] == "view" && ($_POST['domain'] || $_POST['domaintld']))
{
if(strstr($domain, "."))
$userTLD = trim(strtolower(substr($_POST['domain'], strpos($_POST['domain'], ".")+1)));
if($domainInfo[$userTLD])
$_POST['tld'] = $userTLD;
if($_POST['domaintld'])
{
$_POST['domain'] = substr($_POST['domaintld'], 0, strpos($_POST['domaintld'], "."));
$_POST['tld'] = substr($_POST['domaintld'], strpos($_POST['domaintld'], ".")+1);
}
$_POST['tld'] = strtolower($_POST['tld']);
$_POST['domain'] = cleanUpDomain($_POST['domain']);
print "<div id='whoiswait'><div class='outer'><div class='inner'>";
print getLabel("please_wait")."<br />";
if($_POST['tld'] != "all")
print "<strong>www.".$_POST['domain'].".".$_POST['tld']."</strong>";
else
print "<strong>www.".$_POST['domain'].".<span id='whoistld'>com</span></strong>";
if($showProgressPercent)
print "<br /><span id='whoispc'>%</span>";
if($showProgressImage)
print "<br /><img src=\"".$whoisUrl."/images/".(($progressImage) ? $progressImage : "progressbar1.gif")."\" border=\"0\" alt=\"Please Wait\" />";
print "</div></div></div>";
flush();
}
$GLOBAL_DOMAIN = $_POST['domain'];
$_SESSION['whoiscounter'] = 0;
function cleanUpDomain($domain)
{
$domain = strtolower($domain);
$remove = array("http://", "www.", "!", "\"", "£", "$", "%", "^", "*", "(", ")", "+", "=", "{", "}", "[", "]", ":", ";", "@", "'", "~", "#", "<", ",", ">", "?", "/", "¬", "|");
$domain = str_replace($remove, "", trim($domain));
if(strstr($domain, "."))
$domain = substr($domain, 0, strpos($domain, "."));
return trim($domain);
}
function displayResultsTable($results)
{
global $GLOBAL_DOMAIN, $domainInfo, $registerUrl, $showRegisterButton, $whoisUrl;
global $whoisWindowWidth, $whoisWindowHeight, $showPriceColumn;
$results = array_reverse($results, true);
if($_POST['tld'] != "all")
{
if($results[$_POST['tld']] == "available")
{
print "<p>".getLabel("domain_available")."</p>";
}
else if($results[$_POST['tld']] == "adown")
{
print "<p>".getLabel("whois_server_down", false, $_POST['tld'])."</p>";;
}
else
{
print "<p>".getLabel("domain_unavailable")."</p>";
}
}
print "<table id='whoistable' border='0' width='100%' cellpadding='5' cellspacing='0'>\n";
print "<tr>";
print "<th>".getLabel("domain_table_head")."</th>";
print "<th>".getLabel("availability_table_head")."</th>";
if($showPriceColumn) print "<th>".getLabel("price_table_head")."</th>";
print "<th> </th>";
print "</tr>";
$bg = true;
foreach($results as $tld => $result)
{
if($bg)
{
$class = "whoisrow1";
$bg = false;
}
else
{
$class = "whoisrow2";
$bg = true;
}
print "<tr>";
print "<td class=\"".$class."";
if($result == "available") print "available";
print "\">";
if($result != "available") print "<a href=\"http://www.".$GLOBAL_DOMAIN.".".$tld."\" target=\"_blank\">";
print $GLOBAL_DOMAIN.".".$tld;
if($result != "available") print "</a>";
print" </td>";
if($result == "available")
{
print "<td class=\"".$class."available\"><span class=\"domainavailable\">".getLabel("domain_available_short")."</span></td>";
if($showPriceColumn) print "<td class=\"".$class."available\">".getLabel("currency_symbol").number_format(($domainInfo[$tld]['price']), 2)."/".getLabel("year_label")."</td>";
print "<td class=\"".$class."available\">";
if($registerUrl && $showRegisterButton)
print "<input type=\"button\" class=\"linkbutton\" onclick=\"document.location='".str_replace(array("%domain%", "%tld%"), array($GLOBAL_DOMAIN, $tld), $registerUrl)."';\" value=\"".getLabel("register_label")."\" />";
else
print " ";
print "</td>";
}
else if($result == "adown")
{
print "<td class=\"".$class."\"><span class=\"error\">".getLabel("whois_timeout")."</span></td>";
if($showPriceColumn) print "<td class=\"".$class."\">-</td>";
print "<td class=\"".$class."\"><form method=\"post\" action=\"".$whoisUrl."/whois.php?action=view\" target=\"whoisWindow\" class=\"whoisform\" onsubmit=\"whoisDetails('600','400','yes','center');\"><input type=\"hidden\" name=\"tld\" value=\"".$tld."\" /><input type=\"hidden\" name=\"domain\" value=\"".$GLOBAL_DOMAIN."\" /><input class=\"linkbutton\" value=\"Whois\" type=\"submit\" /></form></td>";
}
else
{
print "<td class=\"".$class."\"><span class=\"domaintaken\">".getLabel("domain_unavailable_short")."</span></td>";
if($showPriceColumn) print "<td class=\"".$class."\">-</td>";
print "<td class=\"".$class."\"><form method=\"post\" action=\"".$whoisUrl."/whois.php?action=view\" target=\"whoisWindow\" class=\"whoisform\" onsubmit=\"whoisDetails('600','400','yes','center');\"><input type=\"hidden\" name=\"tld\" value=\"".$tld."\" /><input type=\"hidden\" name=\"domain\" value=\"".$GLOBAL_DOMAIN."\" /><input class=\"linkbutton\" value=\"Whois\" type=\"submit\" /></form></td>";
}
print "</tr>";
}
print "</table>";
}
function whoisStackFull()
{
global $domainInfo;
if(count($_SESSION['whois']) > count($domainInfo))
{
array_shift($_SESSION['whois']);
return false;
}
else
return false;
}
function getWhoisRecords($tld, $domain, $checkoutput=false)
{
global $domainInfo, $showProgressPercent, $useSocket;
$result = "";
$domainCheck = $domain.".".$tld;
if(!$_SESSION['whoiscounter'])
$_SESSION['whoiscounter'] = 0;
if($checkoutput)
{
print "<script type='text/javascript'>if(document.getElementById('whoistld')) document.getElementById('whoistld').innerHTML=\"".$tld."\";</script>\n";
if($showProgressPercent)
{
$pc = number_format((($_SESSION['whoiscounter']+1) / count($domainInfo)) * 100, 0)."%";
//print "Percent: (TOTAL ".count($domainInfo).") CURRENT: ".($_SESSION['whoiscounter']+1)." PC: ".$pc."<hr>";
print "<script type='text/javascript'>if(document.getElementById('whoispc')) document.getElementById('whoispc').innerHTML=\"".$pc."\";</script>\n";
}
flush();
}
$_SESSION['whoiscounter']++;
if($_SESSION['whoiscounter'] == count($domainInfo))
$_SESSION['whoiscounter'] = 0;
if(isset($_SESSION['whois'][$domain][$tld]))
return $_SESSION['whois'][$domain][$tld];
if($useSocket)
{
$ns = fsockopen($domainInfo[$tld]['server'],43,$errno, $errstr, 15);
if($ns)
{
@fputs($ns,"$domainCheck\r\n");
while(@!feof($ns))
$result .= @fgets($ns, 1024);
@fclose($ns);
}
}
else
{
$queryDomain = escapeshellcmd($domainCheck);
$string = "whois -h ".$domainInfo[$tld]['server']." \"".$queryDomain."\"";
exec($string, $resultList);
$result = cleanUpResult($resultList);
}
if($_SESSION['whoiscounter'] == 0)
$_SESSION['cjwhois_searches']++;
if(!$result)
{
if(!whoisStackFull())
$_SESSION['whois'][$domain][$tld] = "adown";
return "adown";
}
/*print "<h1>Raw Result (".$tld.")</h1><pre>";
print $result;
print "</pre><hr>";*/
if(eregi($domainInfo[$tld]['nomatch'],strtolower($result)))
{
if(!whoisStackFull())
$_SESSION['whois'][$domain][$tld] = false;
return false;
}
else
{
if(!whoisStackFull())
$_SESSION['whois'][$domain][$tld] = $result;
return $result;
}
}
function cleanUpResult($resultIn)
{
if(!is_array($resultIn))
return false;
$resultOut = "";
foreach($resultIn as $line)
{
if(!strstr($line, "[") && !strstr($line, "]"))
$resultOut .= $line."\n";
}
return trim($resultOut);
}
function renderTLDList()
{
global $domainInfo;
?>
<select name="tld" size="1">
<option value="all">all</option>
<?
foreach($domainInfo as $tld => $attribs)
{
print "<option value=\"".$tld."\"";
if($_POST['tld'] == $tld)
print " selected";
print ">".$tld."</option>\n";
}
?>
</select>
<?
}
function renderForm($submitText = "Go")
{
?>
<form method="post" class="whoisform" action="<? print $_SERVER['REQUEST_URI']; ?>" onsubmit="return validateDomain(this.domain)"><span style="position:relative;top:-1px;">www.</span><input type="text" name="domain" value="<? print $_POST['domain']; ?>" />.
<?
renderTLDList();
?>
<input type="submit" value="<? print $submitText; ?>" />
</form>
<?
}
function closeWhoisProgress()
{
print "<script type='text/javascript'>\n";
print "if(document.getElementById('whoiswait'))\n";
print " document.getElementById('whoiswait').style.display='none';";
print "</script>\n";
}
function checkTLD($tld)
{
global $domainInfo;
if($tld == "all") return true;
if($domainInfo[$tld])
return true;
else
return false;
}
function getLabel($msg, $domain="", $tld="")
{
global $lang;
if($lang[$msg])
return str_replace(array("%domain%", "%tld%"), array($domain, $tld), $lang[$msg]);
}
?>