bugfix and ws handler improvements

This commit is contained in:
sparc 2007-02-06 18:28:48 +00:00
parent 5f90802ea6
commit 7b572c3838
7 changed files with 94 additions and 118 deletions

View file

@ -1,3 +1,6 @@
2007/02/06
- changed the way gTLD handlers are detected
2006/12/21
- fix/improvement for register.com handler

View file

@ -77,17 +77,12 @@ class WhoisClient {
}
/*
* Perform lookup. Returns an array. The 'rawdata' element contains an
* array of lines gathered from the whois query. If a top level domain
* handler class was found for the domain, other elements will have been
* populated too.
* Perform lookup
*/
function GetData ($query='', $deep_whois=true) {
// If domain to query passed in, use it, otherwise use domain from initialisation
$string = !empty($query) ? $query : $this->Query['string'];
function GetRawData ($query, &$query_args) {
$this->Query['string'] = $string;
$this->Query['string'] = $query;
// clear error description
if (isset($this->Query['errstr'])) unset($this->Query['errstr']);
@ -131,7 +126,7 @@ class WhoisClient {
$query_args = trim($parts[1]);
// replace substitution parameters
$query_args = str_replace('{query}', $string, $query_args);
$query_args = str_replace('{query}', $query, $query_args);
$query_args = str_replace('{version}', 'phpWhois'.$this->CODE_VERSION, $query_args);
if (strpos($query_args,'{ip}')!==false)
@ -145,7 +140,7 @@ class WhoisClient {
}
}
else
$query_args = $string;
$query_args = $query;
if (substr($this->Query['server'],0,9)=='rwhois://')
$this->Query['server']=substr($this->Query['server'],9);
@ -197,10 +192,26 @@ class WhoisClient {
if (empty($output[count($output)-1]))
unset($output[count($output)-1]);
}
return $output;
}
/*
* Perform lookup. Returns an array. The 'rawdata' element contains an
* array of lines gathered from the whois query. If a top level domain
* handler class was found for the domain, other elements will have been
* populated too.
*/
function GetData ($query='', $deep_whois=true) {
// If domain to query passed in, use it, otherwise use domain from initialisation
$query = !empty($query) ? $query : $this->Query['string'];
$output = $this->GetRawData($query,$query_args);
// Create result and set 'rawdata'
$result = array();
$result['rawdata'] = $output;
$result = array( 'rawdata' => $output );
// If we have a handler, post-process it with that
if (isSet($this->Query['handler']))
@ -227,12 +238,12 @@ class WhoisClient {
$result['errstr'] = $this->Query['errstr'];
// If no rawdata use rawdata from first whois server
if (!isset($result['rawdata']))
$result['rawdata'] = $output;
/*if (!isset($result['rawdata']))
$result['rawdata'] = $output;*/
// Fix/add nameserver information
if (method_exists($this,'FixResult') && $this->Query['tld']!='ip')
$this->FixResult($result,$string);
$this->FixResult($result,$query);
return($result);
}
@ -369,7 +380,7 @@ class WhoisClient {
// If the handler has not already been included somehow, include it now
$HANDLER_FLAG = sprintf("__%s_HANDLER__", strtoupper($this->Query['handler']));
if(!defined($HANDLER_FLAG))
if (!defined($HANDLER_FLAG))
include($this->Query['file']);
// If the handler has still not been included, append to query errors list and return
@ -391,9 +402,12 @@ class WhoisClient {
$this->Query['errstr'][] = $handler->Query['errstr'];
$handler->deep_whois = $deep_whois;
// Process
$res = $handler->parse($result,$this->Query['string']);
// Return the result
return $handler->parse($result,$this->Query['string']);
return $res;
}
/*
@ -405,11 +419,11 @@ class WhoisClient {
if (isset($result['regyinfo']['whois']))
$this->Query['server'] = $result['regyinfo']['whois'];
$subresult = $this->GetData($query);
$subresult = $this->GetRawData($query,$query_args);
if (isset($subresult['rawdata']))
if (!empty($subresult))
{
$result['rawdata'] = $subresult['rawdata'];
$result['rawdata'] = $subresult;
@$this->Query['handler'] = $this->WHOIS_HANDLER[$result['regyinfo']['whois']];
@ -417,9 +431,11 @@ class WhoisClient {
{
$this->Query['file'] = sprintf('whois.gtld.%s.php', $this->Query['handler']);
$regrinfo = $this->Process($result['rawdata']);
$result['regrinfo'] = $this->merge_results($result['regrinfo'], $regrinfo);
$result['regrinfo'] = $this->merge_results($result['regrinfo'], $regrinfo);
$result['rawdata'] = $subresult;
}
}
return $result;
}

View file

@ -76,7 +76,7 @@ class gtld_handler extends WhoisClient
$this->result['regrinfo']['registered'] = 'yes';
if ($this->deep_whois) $this->result = $this->DeepWhois($query,$this->result);
return $this->result;
}
}

View file

@ -102,16 +102,14 @@ class ip_handler extends WhoisClient
switch ($this->Query['server'])
{
case 'whois.apnic.net':
$rawdata = $this->GetData($query);
$rawdata = $this->GetRawData($query,$query_args);
if (!isset($rawdata['rawdata']))
if (empty($rawdata))
{
$rawdata = $data['rawdata'];
break;
}
$rawdata = $rawdata['rawdata'];
while (list($ln, $line) = each($rawdata))
{
if (strstr($line, 'KRNIC whois server at whois.krnic.net') ||
@ -119,8 +117,7 @@ class ip_handler extends WhoisClient
{
$this->Query['server'] = 'whois.krnic.net';
$result['regyinfo']['registrar'] = 'Korea Network Information Center (KRNIC)';
$rawdata = $this->GetData($query);
$rawdata = $rawdata['rawdata'];
$rawdata = $this->GetRawData($query,$query_args);
break;
}
}
@ -159,23 +156,21 @@ class ip_handler extends WhoisClient
{
$this->Query['server'] = 'whois.registro.br';
$result['regyinfo']['registrar'] = 'Comite Gestor da Internet no Brasil';
$rawdata = $this->GetData($query);
$rawdata = $rawdata['rawdata'];
$rawdata = $this->GetRawData($query,$query_args);
break;
}
$rawdata = $this->GetData('!'.$newquery);
$rawdata = $rawdata['rawdata'];
$rawdata = $this->GetRawData('!'.$newquery,$query_args);
//$rawdata = $rawdata['rawdata'];
}
break;
case 'whois.lacnic.net':
$rawdata = $this->GetData($query);
$rawdata = $this->GetRawData($query,$query_args);
if (!isset($rawdata['rawdata']))
if (empty($rawdata))
{
$rawdata = $data['rawdata'];
break;
}
@ -192,43 +187,37 @@ class ip_handler extends WhoisClient
{
$this->Query['server'] = 'whois.registro.br';
$result['regyinfo']['registrar'] = 'Comite Gestor da Internet do Brazil';
$rawdata = $this->GetData($query);
$rawdata = $rawdata['rawdata'];
$rawdata = $this->GetRawData($query,$query_args);
break;
}
}
break;
case 'whois.ripe.net':
$rawdata = $this->GetData($query);
$rawdata = $this->GetRawData($query,$query_args);
if (!isset($rawdata['rawdata']))
if (empty($rawdata))
{
$rawdata = $data['rawdata'];
break;
}
$rawdata = $rawdata['rawdata'];
while (list($ln, $line) = each($rawdata))
{
if (strstr($line, 'AFRINIC-NET-TRANSFERRED-'))
{
$this->Query['server'] = 'whois.afrinic.net';
$result['regyinfo']['registrar'] = 'African Network Information Center';
$rawdata = $this->GetData($query);
$rawdata = $rawdata['rawdata'];
$rawdata = $this->GetRawData($query,$query_args);
break;
}
}
break;
default:
$rawdata = $this->GetData($query);
$rawdata = $this->GetRawData($query,$query_args);
if (isset($rawdata['rawdata']))
$rawdata = $rawdata['rawdata'];
else
if (empty($rawdata))
$rawdata = $data['rawdata'];
}
@ -296,7 +285,7 @@ class ip_handler extends WhoisClient
{
$this->Query['server'] = $srv_data['server'];
unset($this->Query['handler']);
$rwdata = $this->GetData($srv_data['query']);
$rwdata = $this->GetRawData($srv_data['query'],$query_args);
if (!empty($rwdata))
{

View file

@ -31,84 +31,52 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
if (!defined("__WS_HANDLER__"))
define("__WS_HANDLER__", 1);
if (!defined('__WS_HANDLER__'))
define('__WS_HANDLER__', 1);
require_once('whois.parser.php');
class ws_handler
class ws_handler extends WhoisClient
{
function parse($data_str, $query)
{
$items = array(
"domain.name" => "Domain Name:", "owner.organization" =>
"Registrant:", "domain.created" => "Domain created on",
"domain.changed" => "Domain last updated on"
'Domain Name:' => 'domain.name',
'Registrant Name:' => 'owner.organization',
'Registrant Email:' => 'owner.email',
'Domain created on' => 'domain.created',
'Domain last updated on' => 'domain.changed',
'Registrar Name:' => 'domain.sponsor',
'Current Nameservers:' => 'domain.nserver.',
'Administrative Contact Email:' => 'admin.email',
'Administrative Contact Telephone:' => 'admin.phone',
'Registrar Whois:' => 'rwhois'
);
while (list($key, $val) = each($data_str["rawdata"]))
{
$val = trim($val);
$r['regrinfo'] = generic_parser_b($data_str['rawdata'], $items, 'ymd');
$r['regyinfo']['referrer'] = 'http://www.samoanic.ws';
$r['regyinfo']['registrar'] = 'Samoa Nic';
if ($val != "")
{
if ($val == "Name servers:")
{
$breaker = 0;
while (list($key, $val) = each($data_str["rawdata"]))
{
// There's a blank line before the list- hack it out.
if (!($value = trim($val)))
$breaker++;
if ($breaker == 2)
break;
if ($value)
$r["regrinfo"]["domain"]["nserver"][] = strtok($value, ' ');
}
break;
}
reset($items);
while (list($field, $match) = each($items))
if (strstr($val, $match))
{
$v = trim(substr($val, strlen($match)));
if ($v == "")
{
$v = each($data_str["rawdata"]);
$v = trim($v["value"]);
}
$parts = explode(".", $field);
$var = "\$r[\"regrinfo\"]";
while (list($fn, $mn) = each($parts))
$var = $var."[\"".$mn."\"]";
eval($var."=\"".$v."\";");
break;
}
}
}
$r["regyinfo"]["referrer"] = "http://www.samoanic.ws";
$r["regyinfo"]["registrar"] = "Samoa Nic";
if (!empty($r["regrinfo"]["domain"]["name"]))
{
$r["regrinfo"]["registered"] = "yes";
if (!empty($r["regrinfo"]["domain"]["nserver"]))
$r["regrinfo"]["domain"]["status"] = "active";
else
{
if (strstr($r["regrinfo"]["domain"]["sponsor"], "DETAGGED"))
$r["regrinfo"]["domain"]["status"] = "detagged";
else
$r["regrinfo"]["domain"]["status"] = "inactive";
}
}
if (!empty($r['regrinfo']['domain']['name']))
{
$r['regrinfo']['registered'] = 'yes';
if (isset($r['regrinfo']['rwhois']))
{
if ($this->deep_whois)
{
$r['regyinfo']['whois'] = $r['regrinfo']['rwhois'];
$r = $this->DeepWhois($query,$r);
}
unset($r['regrinfo']['rwhois']);
}
}
else
$r["regrinfo"]["registered"] = "no";
$r['regrinfo']['registered'] = 'no';
format_dates($r, 'ymd');
return ($r);
}
}

View file

@ -28,7 +28,7 @@ sc admin.sc
se nic-se.se
uk olsns.co.uk
us neustar.us
ws samoanic.ws
ws samoanic.ws informe.ws
// .com/.net/.tv/.jobs
@ -44,7 +44,7 @@ domainbank domainbank.com
dotregistrar dotregistrar.com
dotster dotster.com
encirca nic.jobs
enom enom.com adultlaw.com
enom enom.com adultlaw.com alabanza.com
godaddy godaddy.com
iana example.com
innerwise sexido.com

File diff suppressed because one or more lines are too long