whois client code moved to whois.client.php & class inheritence revised
This commit is contained in:
parent
518497bd1c
commit
5292b3d27a
|
@ -1,8 +1,10 @@
|
|||
2005/07/252 David Saez <david@ols.es>
|
||||
2005/07/25 David Saez <david@ols.es>
|
||||
- removed unused file denic.whois
|
||||
- added support for za.net and za.org, thanx
|
||||
to luca@clamav.net
|
||||
- rewritte of .uk handler
|
||||
- whois client code moved to whois.client.php
|
||||
- class inheritence revised
|
||||
|
||||
2005/07/22 David Saez <david@ols.es>
|
||||
- added CDIR to inetnum conversion for ip whois and
|
||||
|
|
|
@ -34,8 +34,8 @@ if(!defined("__AT_HANDLER__")) define("__AT_HANDLER__",1);
|
|||
|
||||
include_once('generic.whois');
|
||||
|
||||
class at_handler extends Whois
|
||||
{
|
||||
class at_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
$translate = array (
|
||||
|
|
|
@ -35,7 +35,7 @@ if(!defined("__AU_HANDLER__")) define("__AU_HANDLER__",1);
|
|||
|
||||
include_once('generic2.whois');
|
||||
|
||||
class au_handler extends Whois {
|
||||
class au_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ include_once('getdate.whois');
|
|||
|
||||
if(!defined("__BE_HANDLER__")) define("__BE_HANDLER__",1);
|
||||
|
||||
class be_handler extends Whois {
|
||||
class be_handler {
|
||||
|
||||
function parse ($data) {
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ if(!defined("__BIZ_HANDLER__")) define("__BIZ_HANDLER__",1);
|
|||
|
||||
require_once('generic2.whois');
|
||||
|
||||
class biz_handler extends Whois {
|
||||
class biz_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -32,25 +32,25 @@ include_once("generic.whois");
|
|||
|
||||
if(!defined("__BR_HANDLER__")) define("__BR_HANDLER__",1);
|
||||
|
||||
class br_handler extends Whois {
|
||||
class br_handler {
|
||||
|
||||
function parse ($data_str)
|
||||
{
|
||||
$translate = array (
|
||||
"fax-no" => "fax",
|
||||
"e-mail" => "email",
|
||||
"nic-hdl-br" => "handle",
|
||||
"person" => "name",
|
||||
"netname" => "name",
|
||||
"domain" => "name",
|
||||
"updated" => ""
|
||||
"fax-no" => "fax",
|
||||
"e-mail" => "email",
|
||||
"nic-hdl-br" => "handle",
|
||||
"person" => "name",
|
||||
"netname" => "name",
|
||||
"domain" => "name",
|
||||
"updated" => ""
|
||||
);
|
||||
|
||||
$contacts = array (
|
||||
"owner-c" => "owner",
|
||||
"tech-c" => "tech",
|
||||
"admin-c" => "admin",
|
||||
"billing-c" => "billing"
|
||||
"owner-c" => "owner",
|
||||
"tech-c" => "tech",
|
||||
"admin-c" => "admin",
|
||||
"billing-c" => "billing"
|
||||
);
|
||||
|
||||
$r = generic_whois($data_str["rawdata"],$translate,$contacts,"domain",'Ymd');
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__CA_HANDLER__")) define("__CA_HANDLER__",1);
|
|||
|
||||
include_once("generic2.whois");
|
||||
|
||||
class ca_handler extends Whois {
|
||||
class ca_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
@ -42,7 +42,7 @@ $items=array( "owner.organization" => "Organization:",
|
|||
"registrar" => "Registrar:",
|
||||
"domain.created" => "Date-Approved:",
|
||||
"domain.changed" => "Date-Modified:",
|
||||
"domain.expires" => "Renewal-Date:",
|
||||
"domain.expires" => "Renewal-Date:",
|
||||
"domain.desc" => "Description:",
|
||||
"admin.name" => "Admin-Name:",
|
||||
"admin.address." => "Admin-Postal:",
|
||||
|
|
|
@ -37,7 +37,7 @@ require_once('getdate.whois');
|
|||
|
||||
if(!defined("__CH_HANDLER__")) define("__CH_HANDLER__",1);
|
||||
|
||||
class ch_handler extends Whois {
|
||||
class ch_handler {
|
||||
|
||||
function parse ($data_str)
|
||||
{
|
||||
|
|
263
src/whois.client.php
Executable file
263
src/whois.client.php
Executable file
|
@ -0,0 +1,263 @@
|
|||
<?php
|
||||
|
||||
class WhoisClient {
|
||||
|
||||
// Recursion allowed ?
|
||||
var $gtld_recurse = false;
|
||||
|
||||
// Default WHOIS port
|
||||
var $PORT = 43;
|
||||
|
||||
// Maximum number of retries on connection failure
|
||||
var $RETRY = 0;
|
||||
|
||||
// Time to wait between retries
|
||||
var $SLEEP = 2;
|
||||
|
||||
// Read buffer size (0 == char by char)
|
||||
var $BUFFER = 255;
|
||||
|
||||
// Communications timeout
|
||||
var $STIMEOUT = 20;
|
||||
|
||||
// List of servers and handlers (loaded from servers.whois)
|
||||
var $DATA = array();
|
||||
|
||||
// Array to contain all query variables
|
||||
var $Query = array(
|
||||
'tld' => '',
|
||||
'type' => 'domain',
|
||||
'string' => '',
|
||||
'status',
|
||||
'server'
|
||||
);
|
||||
|
||||
/*
|
||||
* Constructor function
|
||||
*/
|
||||
function WhoisClient () {
|
||||
// Load DATA array
|
||||
@require('whois.servers.php');
|
||||
}
|
||||
|
||||
/*
|
||||
* 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='') {
|
||||
// If domain to query passed in, use it, otherwise use domain from initialisation
|
||||
$string = !empty($query) ? $query : $this->Query['string'];
|
||||
|
||||
if (!isset($this->Query['server'])) {
|
||||
$this->Query['status'] = -1;
|
||||
$this->Query['errstr'][] = 'No server specified';
|
||||
return(array());
|
||||
}
|
||||
|
||||
// Check if protocol is http
|
||||
if (substr($this->Query['server'],0,7)=='http://' ||
|
||||
substr($this->Query['server'],0,8)=='https://')
|
||||
{
|
||||
$output = $this->httpQuery($this->Query['server']);
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the '.cx' whois server is broken, return an error now (saves attempting and timing out)
|
||||
/*
|
||||
if($this->HACKS["cx_is_broken"] && $this->Query["tld"] == "cx") {
|
||||
$this->Query["errstr"][] = ".cx doesn't work. Turn off HACKS[\"cx_is_broken\"] if ".$this->Query["server"]." finally got fixed.";
|
||||
return("");
|
||||
}
|
||||
*/
|
||||
// Connect to whois server, or return if failed
|
||||
$ptr = $this->Connect();
|
||||
|
||||
if($ptr < 0) {
|
||||
$this->Query['status'] = -1;
|
||||
$this->Query['errstr'][] = 'Connect failed to: '.$this->Query['server'];
|
||||
return(array());
|
||||
}
|
||||
|
||||
stream_set_timeout($ptr,$this->STIMEOUT);
|
||||
|
||||
if (isset($this->WHOIS_PARAM[$this->Query['server']]))
|
||||
fputs($ptr, $this->WHOIS_PARAM[$this->Query['server']].trim($string)."\r\n");
|
||||
else
|
||||
fputs($ptr, trim($string)."\r\n");
|
||||
|
||||
// Prepare to receive result
|
||||
$raw = '';
|
||||
$output = array();
|
||||
while(!feof($ptr)) {
|
||||
// If a buffer size is set, fetch line-by-line into an array
|
||||
if($this->BUFFER)
|
||||
$output[] = trim(fgets($ptr, $this->BUFFER));
|
||||
// If not, fetch char-by-char into a string
|
||||
else
|
||||
$raw .= fgetc($ptr);
|
||||
}
|
||||
|
||||
// If captured char-by-char, convert to an array of lines
|
||||
if(!$this->BUFFER)
|
||||
$output = explode("\n", $raw);
|
||||
|
||||
// Drop empty last line
|
||||
unset($output[count($output)-1]);
|
||||
}
|
||||
|
||||
// Create result and set 'rawdata'
|
||||
$result = array();
|
||||
$result['rawdata'] = $output;
|
||||
|
||||
// Set whois server
|
||||
$result['regyinfo']['whois'] = $this->Query['server'];
|
||||
|
||||
// If we have a handler, post-process it with that
|
||||
|
||||
if(isSet($this->Query['handler']))
|
||||
$result = $this->Process($result);
|
||||
|
||||
// Add error information if any
|
||||
if (isset($this->Query['errstr']))
|
||||
$result['errstr'] = $this->Query['errstr'];
|
||||
|
||||
// If no rawdata use rawdata from first whois server
|
||||
if (!isset($result['rawdata']))
|
||||
$result['rawdata'] = $output;
|
||||
|
||||
// Fix/add nameserver information
|
||||
if (method_exists($this,'FixResult') && $this->Query['tld']!='ip')
|
||||
$this->FixResult($result,$string);
|
||||
|
||||
return($result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert html output to plain text
|
||||
*/
|
||||
function httpQuery ($query) {
|
||||
$lines = file($this->Query['server']);
|
||||
$output = '';
|
||||
$pre = '';
|
||||
|
||||
while (list($key, $val)=each($lines)) {
|
||||
$val = trim($val);
|
||||
|
||||
$pos=strpos(strtoupper($val),'<PRE>');
|
||||
if ($pos!==false) {
|
||||
$pre = "\n";
|
||||
$output.=substr($val,0,$pos)."\n";
|
||||
$val = substr($val,$pos+5);
|
||||
}
|
||||
$pos=strpos(strtoupper($val),'</PRE>');
|
||||
if ($pos!==false) {
|
||||
$pre = '';
|
||||
$output.=substr($val,0,$pos)."\n";
|
||||
$val = substr($val,$pos+6);
|
||||
}
|
||||
$output.=$val.$pre;
|
||||
}
|
||||
|
||||
$search = array (
|
||||
'<BR>', '<P>', '</TITLE>',
|
||||
'</H1>', '</H2>', '</H3>',
|
||||
'<br>', '<p>', '</title>',
|
||||
'</h1>', '</h2>', '</h3>' );
|
||||
|
||||
$output = str_replace($search,"\n",$output);
|
||||
$output = str_replace('<TD',' <td',$output);
|
||||
$output = str_replace('<td',' <td',$output);
|
||||
$output = str_replace('<tr',"\n<tr",$output);
|
||||
$output = str_replace('<TR',"\n<tr",$output);
|
||||
$output = str_replace(' ',' ',$output);
|
||||
$output = html_entity_decode($output);
|
||||
$output = explode("\n",strip_tags($output));
|
||||
|
||||
$rawdata = array();
|
||||
$null = 0;
|
||||
|
||||
while (list($key, $val)=each($output)) {
|
||||
$val=trim($val);
|
||||
if ($val=='') {
|
||||
if (++$null>2) continue;
|
||||
}
|
||||
else $null=0;
|
||||
$rawdata[]=$val;
|
||||
}
|
||||
return $rawdata;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a socket to the whois server.
|
||||
*
|
||||
* Returns a socket connection pointer on success, or -1 on failure.
|
||||
*/
|
||||
function Connect () {
|
||||
|
||||
// Fail if server not set
|
||||
if(!isSet($this->Query['server']))
|
||||
return(-1);
|
||||
|
||||
// Enter connection attempt loop
|
||||
$server = $this->Query['server'];
|
||||
$retry = 0;
|
||||
while($retry <= $this->RETRY) {
|
||||
// Set query status
|
||||
$this->Query['status'] = 'ready';
|
||||
|
||||
// Connect to whois port
|
||||
$ptr = @fsockopen($server, $this->PORT);
|
||||
if($ptr > 0) {
|
||||
$this->Query['status']='ok';
|
||||
return($ptr);
|
||||
}
|
||||
|
||||
// Failed this attempt
|
||||
$this->Query['status'] = 'error';
|
||||
$retry++;
|
||||
|
||||
// Sleep before retrying
|
||||
sleep($this->SLEEP);
|
||||
}
|
||||
|
||||
// If we get this far, it hasn't worked
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Post-process result with handler class. On success, returns the result
|
||||
* from the handler. On failure, returns passed in result unaltered.
|
||||
*/
|
||||
function Process (&$result) {
|
||||
|
||||
// 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))
|
||||
include($this->Query['file']);
|
||||
|
||||
// If the handler has still not been included, append to query errors list and return
|
||||
if(!defined($HANDLER_FLAG)) {
|
||||
$this->Query['errstr'][] = "Can't find ".$this->Query['tld'].' handler: '.$this->Query["file"];
|
||||
return($result);
|
||||
}
|
||||
|
||||
if (!$this->gtld_recurse && $this->Query['file']=='whois.gtld.php')
|
||||
return $result;
|
||||
|
||||
// Pass result to handler
|
||||
$object = $this->Query['handler'].'_handler';
|
||||
|
||||
$handler = new $object('');
|
||||
|
||||
// If handler returned an error, append it to the query errors list
|
||||
if(isSet($handler->Query['errstr']))
|
||||
$this->Query['errstr'][] = $handler->Query['errstr'];
|
||||
|
||||
// Return the result
|
||||
return $handler->parse($result,$this->Query);
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ if(!defined("__CN_HANDLER__")) define("__CN_HANDLER__",1);
|
|||
|
||||
require_once("generic2.whois");
|
||||
|
||||
class cn_handler extends Whois {
|
||||
class cn_handler {
|
||||
|
||||
function parse($data_str) {
|
||||
$items = array(
|
||||
|
|
|
@ -32,7 +32,7 @@ if(!defined("__FM_HANDLER__")) define("__FM_HANDLER__",1);
|
|||
require_once('generic2.whois');
|
||||
require_once('generic3.whois');
|
||||
|
||||
class fm_handler extends Whois {
|
||||
class fm_handler {
|
||||
|
||||
function parse ($data)
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__ASCIO_HANDLER__")) define("__ASCIO_HANDLER__",1);
|
|||
require_once("generic3.whois");
|
||||
require_once('getdate.whois');
|
||||
|
||||
class ascio_handler extends gtld_handler {
|
||||
class ascio_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__DIRECTNIC_HANDLER__")) define("__DIRECTNIC_HANDLER__",1);
|
|||
require_once("generic3.whois");
|
||||
require_once('getdate.whois');
|
||||
|
||||
class directnic_handler extends gtld_handler {
|
||||
class directnic_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ if(!defined("__DOTSTER_HANDLER__")) define("__DOTSTER_HANDLER__",1);
|
|||
require_once("generic3.whois");
|
||||
require_once('getdate.whois');
|
||||
|
||||
class dotster_handler extends gtld_handler {
|
||||
class dotster_handler {
|
||||
|
||||
function parse ($data_str)
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@ if(!defined("__ENOM_HANDLER__")) define("__ENOM_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class enom_handler extends gtld_handler {
|
||||
class enom_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__GODADDY_HANDLER__")) define("__GODADDY_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class godaddy_handler extends gtld_handler {
|
||||
class godaddy_handler {
|
||||
|
||||
function godaddy($data) {
|
||||
$this->result=$this->parse($data);
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__INTERDOMAIN_HANDLER__")) define("__INTERDOMAIN_HANDLER__",1);
|
|||
|
||||
require_once("generic2.whois");
|
||||
|
||||
class interdomain_handler extends gtld_handler {
|
||||
class interdomain_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ if(!defined("__JOKER_HANDLER__")) define("__JOKER_HANDLER__",1);
|
|||
|
||||
include_once('generic2.whois');
|
||||
|
||||
class joker_handler extends gtld_handler {
|
||||
class joker_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__MONIKER_HANDLER__")) define("__MONIKER_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class moniker_handler extends gtld_handler {
|
||||
class moniker_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ if(!defined("__NICLINE_HANDLER__")) define("__NICLINE_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class nicline_handler extends gtld_handler {
|
||||
class nicline_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ if(!defined("__GTLD_HANDLER__")) define("__GTLD_HANDLER__",1);
|
|||
|
||||
require_once("generic2.whois");
|
||||
|
||||
class gtld_handler extends Whois {
|
||||
class gtld_handler extends WhoisClient {
|
||||
|
||||
var $HANDLER_VERSION = "1.1";
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ if(!defined("__SCHLUND_HANDLER__")) define("__SCHLUND_HANDLER__",1);
|
|||
|
||||
include_once("generic2.whois");
|
||||
|
||||
class schlund_handler extends gtld_handler {
|
||||
class schlund_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__SRSPLUS_HANDLER__")) define("__SRSPLUS_HANDLER__",1);
|
|||
require_once("generic3.whois");
|
||||
require_once('getdate.whois');
|
||||
|
||||
class srsplus_handler extends gtld_handler {
|
||||
class srsplus_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined('__TVCORP_HANDLER__')) define('__TVCORP_HANDLER__',1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class tvcorp_handler extends gtld_handler {
|
||||
class tvcorp_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,8 +33,7 @@ if(!defined("__HU_HANDLER__")) define("__HU_HANDLER__",1);
|
|||
include_once("generic.whois");
|
||||
include_once('getdate.whois');
|
||||
|
||||
class hu_handler extends Whois
|
||||
{
|
||||
class hu_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__INFO_HANDLER__")) define("__INFO_HANDLER__",1);
|
|||
|
||||
require_once("generic2.whois");
|
||||
|
||||
class info_handler extends Whois {
|
||||
class info_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ require_once("generic.whois");
|
|||
|
||||
if(!defined("__APNIC_HANDLER__")) define("__APNIC_HANDLER__",1);
|
||||
|
||||
class apnic_handler extends ip_handler {
|
||||
class apnic_handler {
|
||||
|
||||
function parse ($data_str,$query)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ if(!defined("__ARIN_HANDLER__")) define("__ARIN_HANDLER__",1);
|
|||
|
||||
require_once("generic2.whois");
|
||||
|
||||
class arin_handler extends ip_handler {
|
||||
class arin_handler {
|
||||
|
||||
function parse ($data_str)
|
||||
{
|
||||
|
|
|
@ -32,7 +32,7 @@ if(!defined("__KRNIC_HANDLER__")) define("__KRNIC_HANDLER__",1);
|
|||
require_once("generic2.whois");
|
||||
require_once("generic3.whois");
|
||||
|
||||
class krnic_handler extends ip_handler {
|
||||
class krnic_handler {
|
||||
|
||||
function parse ($data_str,$query)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ require_once("generic.whois");
|
|||
|
||||
if(!defined("__LACNIC_HANDLER__")) define("__LACNIC_HANDLER__",1);
|
||||
|
||||
class lacnic_handler extends ip_handler {
|
||||
class lacnic_handler {
|
||||
|
||||
function parse ($data_str,$query)
|
||||
{
|
||||
|
|
|
@ -34,11 +34,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
/* 207.217.120.54 (arin) */
|
||||
/* 200.165.206.74 (brnic) */
|
||||
/* 210.178.148.129 (krnic) */
|
||||
/* 200.44.33.31 (lacnic) */
|
||||
/* 200.44.33.31 (lacnic) */
|
||||
|
||||
if (!defined("__IP_HANDLER__")) define("__IP_HANDLER__",1);
|
||||
if (!defined('__IP_HANDLER__')) define('__IP_HANDLER__',1);
|
||||
|
||||
class ip_handler extends Whois {
|
||||
class ip_handler extends WhoisClient {
|
||||
|
||||
var $HANDLER_VERSION = '1.0';
|
||||
|
||||
|
@ -215,6 +215,7 @@ if ($n>0)
|
|||
$bits1=str_pad(decbin(ip2long($start)),32,'0','STR_PAD_LEFT');
|
||||
$net=pow(2,(32-substr(strstr($net,'/'),1)))-1;
|
||||
$bits2=str_pad(decbin($net),32,'0','STR_PAD_LEFT');
|
||||
$final='';
|
||||
|
||||
for ($i=0;$i<32;$i++)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ require_once("generic.whois");
|
|||
|
||||
if(!defined("__RIPE_HANDLER__")) define("__RIPE_HANDLER__",1);
|
||||
|
||||
class ripe_handler extends ip_handler {
|
||||
class ripe_handler {
|
||||
|
||||
function parse ($data_str)
|
||||
{
|
||||
|
|
|
@ -31,8 +31,7 @@ if(!defined("__IS_HANDLER__")) define("__IS_HANDLER__",1);
|
|||
|
||||
include_once('generic.whois');
|
||||
|
||||
class is_handler extends Whois
|
||||
{
|
||||
class is_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__LU_HANDLER__")) define("__LU_HANDLER__",1);
|
|||
|
||||
require_once("generic2.whois");
|
||||
|
||||
class lu_handler extends Whois {
|
||||
class lu_handler {
|
||||
|
||||
function parse($data_str) {
|
||||
$items = array(
|
||||
|
|
|
@ -26,7 +26,9 @@
|
|||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
class Whois {
|
||||
require_once('whois.client.php');
|
||||
|
||||
class Whois extends WhoisClient {
|
||||
// Windows based ?
|
||||
|
||||
var $windows = false;
|
||||
|
@ -44,37 +46,19 @@ class Whois {
|
|||
var $NSI_REGISTRY = "whois.nsiregistry.net";
|
||||
|
||||
// Network Solutions registrar server (?)
|
||||
var $NSI_REGISTRAR = "whois.networksolutions.com";
|
||||
|
||||
// Default WHOIS port
|
||||
var $PORT = 43;
|
||||
|
||||
// Maximum number of retries on connection failure
|
||||
var $RETRY = 0;
|
||||
|
||||
// Time to wait between retries
|
||||
var $SLEEP = 2;
|
||||
|
||||
// Read buffer size (0 == char by char)
|
||||
var $BUFFER = 255;
|
||||
|
||||
// Status response codes
|
||||
var $STAT = array(
|
||||
-1 => "error",
|
||||
0 => "ready",
|
||||
1 => "ok"
|
||||
);
|
||||
//var $NSI_REGISTRAR = "whois.networksolutions.com";
|
||||
|
||||
// Array to contain all query variables
|
||||
var $Query = array(
|
||||
"tld" => "",
|
||||
"type" => "domain",
|
||||
"string" => "",
|
||||
"status",
|
||||
"server"
|
||||
/* var $Query = array(
|
||||
'tld' => '',
|
||||
'type' => 'domain',
|
||||
'string' => '',
|
||||
'status',
|
||||
'server'
|
||||
);
|
||||
|
||||
*/
|
||||
// Various hacks. In a perfect world we don't need these.
|
||||
/*
|
||||
var $HACKS = array(
|
||||
// force "dom" keywork
|
||||
"nsi_force_dom" => 1,
|
||||
|
@ -85,17 +69,18 @@ class Whois {
|
|||
// ???
|
||||
"real_netsol_whois" => "whois.networksolutions.com",
|
||||
// force english output on .jp for us ethnocentric types, unset or comment out for Japanese output
|
||||
"force_slash_e" => "whois.nic.ad.jp",
|
||||
"force_slash_e" => "whois.nic.ad.jp"
|
||||
// whois.nic.cx hangs forever
|
||||
"cx_is_broken" => 1
|
||||
//"cx_is_broken" => 1
|
||||
);
|
||||
|
||||
*/
|
||||
// List of servers and handlers (loaded from servers.whois)
|
||||
var $DATA = array();
|
||||
//var $DATA = array();
|
||||
|
||||
// Communications timeout
|
||||
|
||||
var $timeout = 20;
|
||||
//var $timeout = 20;
|
||||
|
||||
/*
|
||||
* Constructor function
|
||||
*/
|
||||
|
@ -250,46 +235,11 @@ class Whois {
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open a socket to the whois server.
|
||||
*
|
||||
* Returns a socket connection pointer on success, or -1 on failure.
|
||||
*/
|
||||
function Connect () {
|
||||
// Fail if server not set
|
||||
if(!isSet($this->Query["server"]))
|
||||
return(-1);
|
||||
|
||||
// Enter connection attempt loop
|
||||
$server = $this->Query["server"];
|
||||
$retry = 0;
|
||||
while($retry <= $this->RETRY) {
|
||||
// Set query status
|
||||
$this->Query["status"] = "ready";
|
||||
|
||||
// Connect to whois port
|
||||
$ptr = @fsockopen($server, $this->PORT);
|
||||
if($ptr > 0) {
|
||||
$this->Query["status"]="ok";
|
||||
return($ptr);
|
||||
}
|
||||
|
||||
// Failed this attempt
|
||||
$this->Query["status"] = "error";
|
||||
$retry++;
|
||||
|
||||
// Sleep before retrying
|
||||
sleep($this->SLEEP);
|
||||
}
|
||||
|
||||
// If we get this far, it hasn't worked
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Post-process result with handler class. On success, returns the result
|
||||
* from the handler. On failure, returns passed in result unaltered.
|
||||
*/
|
||||
/*
|
||||
function Process (&$result) {
|
||||
|
||||
// If the handler has not already been included somehow, include it now
|
||||
|
@ -319,63 +269,7 @@ class Whois {
|
|||
// Return the result
|
||||
return $handler->parse($result,$this->Query);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert html output to plain text
|
||||
*/
|
||||
function httpQuery ($query) {
|
||||
$lines = file($this->Query["server"]);
|
||||
$output = "";
|
||||
$pre = "";
|
||||
|
||||
while (list($key, $val)=each($lines)) {
|
||||
$val = trim($val);
|
||||
|
||||
$pos=strpos(strtoupper($val),"<PRE>");
|
||||
if ($pos!==false) {
|
||||
$pre = "\n";
|
||||
$output.=substr($val,0,$pos)."\n";
|
||||
$val = substr($val,$pos+5);
|
||||
}
|
||||
$pos=strpos(strtoupper($val),"</PRE>");
|
||||
if ($pos!==false) {
|
||||
$pre = "";
|
||||
$output.=substr($val,0,$pos)."\n";
|
||||
$val = substr($val,$pos+6);
|
||||
}
|
||||
$output.=$val.$pre;
|
||||
}
|
||||
|
||||
$search = array (
|
||||
"<BR>", "<P>", "</TITLE>",
|
||||
"</H1>", "</H2>", "</H3>,",
|
||||
"<br>", "<p>", "</title>",
|
||||
"</h1>", "</h2>", "</h3>" );
|
||||
|
||||
$output = str_replace($search,"\n",$output);
|
||||
$output = str_replace("<TD"," <td",$output);
|
||||
$output = str_replace("<td"," <td",$output);
|
||||
$output = str_replace("<tr","\n<tr",$output);
|
||||
$output = str_replace("<TR","\n<tr",$output);
|
||||
$output = str_replace(' ',' ',$output);
|
||||
$output = html_entity_decode($output);
|
||||
$output = explode("\n",strip_tags($output));
|
||||
|
||||
$rawdata = array();
|
||||
$null = 0;
|
||||
|
||||
while (list($key, $val)=each($output)) {
|
||||
$val=trim($val);
|
||||
if ($val=='') {
|
||||
if (++$null>2) continue;
|
||||
}
|
||||
else $null=0;
|
||||
$rawdata[]=$val;
|
||||
}
|
||||
|
||||
return $rawdata;
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
* Fix and/or add name server information
|
||||
*/
|
||||
|
@ -387,10 +281,10 @@ class Whois {
|
|||
// Check if nameservers exist
|
||||
|
||||
if (!isset($result['regrinfo']['registered'])) {
|
||||
if ($this->windows)
|
||||
$has_ns = $this->checkdnsrr_win($domain, "NS");
|
||||
else
|
||||
$has_ns = checkdnsrr($domain, "NS");
|
||||
if ($this->windows)
|
||||
$has_ns = $this->checkdnsrr_win($domain, "NS");
|
||||
else
|
||||
$has_ns = checkdnsrr($domain, "NS");
|
||||
|
||||
if ($has_ns)
|
||||
$result['regrinfo']['registered']='yes';
|
||||
|
@ -440,108 +334,6 @@ class Whois {
|
|||
|
||||
$result['regrinfo']['domain']['nserver']=$dns;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 = "") {
|
||||
// If domain to query passed in, use it, otherwise use domain from initialisation
|
||||
$string = !empty($query) ? $query : $this->Query["string"];
|
||||
|
||||
//echo "GetData ".$this->Query["server"]." $string\n<br>";
|
||||
if (!isset($this->Query["server"])) {
|
||||
$this->Query["status"] = -1;
|
||||
$this->Query["errstr"][] = "No server specified";
|
||||
return(array());
|
||||
}
|
||||
|
||||
// Check if protocol is http
|
||||
if (substr($this->Query["server"],0,7)=="http://" ||
|
||||
substr($this->Query["server"],0,8)=="https://")
|
||||
{
|
||||
$result['rawdata'] = $this->httpQuery($this->Query["server"]);
|
||||
|
||||
// If we have a handler, post-process it with that
|
||||
|
||||
if(isSet($this->DATA[$this->Query["tld"]]))
|
||||
$result = $this->Process($result);
|
||||
|
||||
$result['regyinfo']['whois'] = strtok($this->Query["server"],'?');
|
||||
// Fix/add nameserver information
|
||||
$this->FixResult($result,$string);
|
||||
return($result);
|
||||
}
|
||||
|
||||
// If the '.cx' whois server is broken, return an error now (saves attempting and timing out)
|
||||
if($this->HACKS["cx_is_broken"] && $this->Query["tld"] == "cx") {
|
||||
$this->Query["errstr"][] = ".cx doesn't work. Turn off HACKS[\"cx_is_broken\"] if ".$this->Query["server"]." finally got fixed.";
|
||||
return("");
|
||||
}
|
||||
|
||||
// Connect to whois server, or return if failed
|
||||
$ptr = $this->Connect();
|
||||
|
||||
if($ptr < 0) {
|
||||
$this->Query["status"] = -1;
|
||||
$this->Query["errstr"][] = "Connect failed to: ".$this->Query["server"];
|
||||
return(array());
|
||||
}
|
||||
|
||||
stream_set_timeout($ptr,$this->timeout);
|
||||
|
||||
if (isset($this->WHOIS_PARAM[$this->Query["server"]]))
|
||||
fputs($ptr, $this->WHOIS_PARAM[$this->Query["server"]].trim($string)."\r\n");
|
||||
else
|
||||
fputs($ptr, trim($string)."\r\n");
|
||||
|
||||
// Prepare to receive result
|
||||
$raw = "";
|
||||
$output = array();
|
||||
while(!feof($ptr)) {
|
||||
// If a buffer size is set, fetch line-by-line into an array
|
||||
if($this->BUFFER)
|
||||
$output[] = trim(fgets($ptr, $this->BUFFER));
|
||||
// If not, fetch char-by-char into a string
|
||||
else
|
||||
$raw .= fgetc($ptr);
|
||||
}
|
||||
|
||||
// If captured char-by-char, convert to an array of lines
|
||||
if(!$this->BUFFER)
|
||||
$output = explode("\n", $raw);
|
||||
|
||||
// Drop empty last line
|
||||
unset($output[count($output)-1]);
|
||||
|
||||
// Create result and set 'rawdata'
|
||||
$result = array();
|
||||
$result['rawdata'] = $output;
|
||||
|
||||
// Set whois server
|
||||
$result['regyinfo']['whois'] = $this->Query["server"];
|
||||
|
||||
// If we have a handler, post-process it with that
|
||||
|
||||
if(isSet($this->Query["handler"]))
|
||||
$result = $this->Process($result);
|
||||
|
||||
// Add error information if any
|
||||
if (isset($this->Query["errstr"]))
|
||||
$result["errstr"] = $this->Query["errstr"];
|
||||
|
||||
// If no rawdata use rawdata from first whois server
|
||||
if (!isset($result["rawdata"]))
|
||||
$result["rawdata"] = $output;
|
||||
|
||||
// Fix/add nameserver information
|
||||
if (method_exists($this,'FixResult') && $this->Query['tld']!='ipw')
|
||||
$this->FixResult($result,$string);
|
||||
return($result);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__MX_HANDLER__")) define("__MX_HANDLER__",1);
|
|||
|
||||
require_once('getdate.whois');
|
||||
|
||||
class mx_handler extends Whois {
|
||||
class mx_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ if(!defined("__NL_HANDLER__")) define("__NL_HANDLER__",1);
|
|||
require_once("generic3.whois");
|
||||
require_once('getdate.whois');
|
||||
|
||||
class nl_handler extends Whois {
|
||||
class nl_handler {
|
||||
|
||||
function parse ($data)
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__NU_HANDLER__")) define("__NU_HANDLER__",1);
|
|||
|
||||
require_once('getdate.whois');
|
||||
|
||||
class nu_handler extends Whois {
|
||||
class nu_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
$items=array(
|
||||
|
|
|
@ -32,7 +32,7 @@ if(!defined("__ORG_HANDLER__")) define("__ORG_HANDLER__",1);
|
|||
|
||||
require_once("generic2.whois");
|
||||
|
||||
class org_handler extends Whois {
|
||||
class org_handler {
|
||||
|
||||
function org($data) {
|
||||
$this->result = $this->parse($data);
|
||||
|
|
|
@ -34,7 +34,7 @@ if(!defined("__SE_HANDLER__")) define("__SE_HANDLER__",1);
|
|||
|
||||
require_once('generic2.whois');
|
||||
|
||||
class se_handler extends Whois {
|
||||
class se_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
$items=array(
|
||||
|
|
|
@ -40,7 +40,7 @@ if(!defined("__UK_HANDLER__")) define("__UK_HANDLER__",1);
|
|||
require_once('getdate.whois');
|
||||
require_once('generic3.whois');
|
||||
|
||||
class uk_handler extends Whois {
|
||||
class uk_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ if(!defined("__US_HANDLER__")) define("__US_HANDLER__",1);
|
|||
|
||||
require_once("generic2.whois");
|
||||
|
||||
class us_handler extends Whois {
|
||||
class us_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ if(!defined("__WS_HANDLER__")) define("__WS_HANDLER__",1);
|
|||
|
||||
require_once('getdate.whois');
|
||||
|
||||
class ws_handler extends Whois {
|
||||
class ws_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
$items=array(
|
||||
|
|
|
@ -41,7 +41,7 @@ if(!defined("__ES_HANDLER__")) define("__ES_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class es_handler extends Whois {
|
||||
class es_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ if(!defined("__BULKR_HANDLER__")) define("__BULKR_HANDLER__",1);
|
|||
|
||||
require_once('getdate.whois');
|
||||
|
||||
class bulkr_handler extends gtld_handler {
|
||||
class bulkr_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
$data_str=preg_replace("/\n+/","_",implode("\n",$data_str));
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__BUYDOMAINS_HANDLER__")) define("__BUYDOMAINS_HANDLER__",1);
|
|||
require_once("generic3.whois");
|
||||
require_once('getdate.whois');
|
||||
|
||||
class buydomains_handler extends gtld_handler {
|
||||
class buydomains_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ require_once("generic2.whois");
|
|||
|
||||
if(!defined("__CORE_HANDLER__")) define("__CORE_HANDLER__",1);
|
||||
|
||||
class core_handler extends gtld_handler {
|
||||
class core_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__CRONON_HANDLER__")) define("__CRONON_HANDLER__",1);
|
|||
require_once("generic3.whois");
|
||||
require_once('getdate.whois');
|
||||
|
||||
class cronon_handler extends gtld_handler {
|
||||
class cronon_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ if(!defined("__DOMAINBANK_HANDLER__")) define("__DOMAINBANK_HANDLER__",1);
|
|||
|
||||
require_once("generic3.whois");
|
||||
|
||||
class domainbank_handler extends gtld_handler {
|
||||
class domainbank_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ if(!defined("__DOTREGISTRAR_HANDLER__")) define("__DOTREGISTRAR_HANDLER__",1);
|
|||
require_once("generic3.whois");
|
||||
require_once('getdate.whois');
|
||||
|
||||
class dotregistrar_handler extends gtld_handler {
|
||||
class dotregistrar_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__INNERWISE_HANDLER__")) define("__INNERWISE_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class innerwise_handler extends gtld_handler {
|
||||
class innerwise_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ require_once("generic2.whois");
|
|||
|
||||
if(!defined("__INWWCOM_HANDLER__")) define("__INWWCOM_HANDLER__",1);
|
||||
|
||||
class inwwcom_handler extends gtld_handler {
|
||||
class inwwcom_handler {
|
||||
|
||||
function parse($data_str,$query) {
|
||||
$items = array ( "domain.name" => "Domain Name..........",
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__NETSOL_HANDLER__")) define("__NETSOL_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class netsol_handler extends gtld_handler {
|
||||
class netsol_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ if(!defined("__OPENSRSNET_HANDLER__")) define("__OPENSRSNET_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class opensrsnet_handler extends gtld_handler {
|
||||
class opensrsnet_handler {
|
||||
|
||||
function parse ($data_str) {
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ if(!defined("__REGISTERCOM_HANDLER__")) define("__REGISTERCOM_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class registercom_handler extends gtld_handler {
|
||||
class registercom_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if(!defined("__STARGATE_HANDLER__")) define("__STARGATE_HANDLER__",1);
|
|||
require_once('generic3.whois');
|
||||
require_once('getdate.whois');
|
||||
|
||||
class stargate_handler extends gtld_handler {
|
||||
class stargate_handler {
|
||||
|
||||
function parse ($data_str,$query) {
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ require_once("generic.whois");
|
|||
|
||||
if(!defined("__BRIPW_HANDLER__")) define("__BRIPW_HANDLER__",1);
|
||||
|
||||
class bripw_handler extends ip_handler {
|
||||
class bripw_handler {
|
||||
|
||||
function parse ($data_str)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue