generic3.whois code moved to whois.parser.php

This commit is contained in:
sparc 2005-07-26 19:00:06 +00:00
parent e4ce29ec45
commit 885976e15e
30 changed files with 239 additions and 286 deletions

View file

@ -1,6 +1,7 @@
2005/07/26 David Saez <david@ols.es>
- added handler for za.org & za.net, thanx to
luca@clamav.net
- generic3.whois code moved to whois.parser.php
2005/07/25 David Saez <david@ols.es>
- removed unused file denic.whois

View file

@ -1,235 +0,0 @@
<?php
/*
Generic3.php PHP functions for parsing whois output
Copyright (C)2003
Maintained by Mark Jeftovic <markjr@easydns.com>
For the most recent version of this package:
http://www.easydns.com/~markjr/whois2/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
require_once('genutil.whois');
function get_blocks ( $rawdata, $items )
{
$r=array();
$endtag='';
while (list($key,$val)=each($rawdata))
{
$val=trim($val);
if ($val=='') continue;
$found=false;
reset($items);
while (list($field, $match)=each($items)) {
$pos=strpos($val,$match);
if ($field!='' && $pos!==false) {
if ($val==$match) {
$found=true;
$endtag='';
$line=$val;
break;
}
$last=substr($val,-1,1);
if ($last==':' || $last=='-' || $last==']') {
$found=true;
$endtag=$last;
$line=$val;
break;
}
else {
$var=getvarname(strtok($field,"#"));
$itm=trim(substr($val,$pos+strlen($match)));
eval("\$r".$var."=\$itm;");
}
}
}
if (!$found) continue;
$block=array();
$found=false;
$spaces=0;
while (list($key,$val)=each($rawdata))
{
$val=trim($val);
if ($val=="") {
if ($found && ++$spaces==2) break;
continue;
}
if (!$found) {
$found=true;
$block[]=$val;
continue;
}
$last=substr(trim($val),-1,1);
if ($last==$endtag) {
prev($rawdata);
break;
}
if ($spaces>0) {
reset($items);
$ok=true;
while (list($field, $match)=each($items)) {
$pos=strpos($val,$match);
if ($pos!==false) $ok=false;
}
if (!$ok) {
prev($rawdata);
break;
}
}
$block[]=$val;
}
reset($items);
while (list($field, $match)=each($items)) {
$pos=strpos($line,$match);
if ($pos!==false) {
$var=getvarname($field);
eval("\$r".$var."=\$block;");
}
}
}
return $r;
}
function get_contact ( $array, $extra_items='' )
{
if (!is_array($array))
return array();
$items = array (
'fax..:' => 'fax',
'fax-' => 'fax',
'fax:' => 'fax',
'[fax]' => 'fax',
'(fax)' => 'fax',
'fax' => 'fax',
'phone:' => 'phone',
'email:' => 'email',
'company name:' => 'organization',
'first name:' => 'name.first',
'last name:' => 'name.last',
'street:' => 'address.street',
'language:' => '',
'location:' => 'address.city',
'country:' => 'address.country',
'name:' => 'name',
'fax.' => 'fax',
'tel.' => 'phone'
);
if ($extra_items!='')
$items=array_merge($extra_items,$items);
while (list($key,$val)=each($array))
{
$ok=true;
while ($ok)
{
reset($items);
$ok=false;
while (list($match,$field)=each($items))
{
$pos=strpos(strtolower($val),$match);
if ($pos===false) continue;
$itm=trim(substr($val,$pos+strlen($match)));
if ($field!='')
{
eval("\$r".getvarname($field)."=\$itm;");
}
$val=trim(substr($val,0,$pos));
if ($val=='')
unset($array[$key]);
else
{
$array[$key]=$val;
$ok=true;
}
break;
}
}
if ($val=='') continue;
if (!preg_match("/[^0-9\(\)\-\.\+ ]/", $val) && strlen($val)>5)
{
if (isset($r['phone']))
$r['fax']=$val;
else
$r['phone']=$val;
unset($array[$key]);
continue;
}
if (strstr($val,'@'))
{
$val=str_replace("\t",' ',$val);
$parts=explode(' ',$val);
$top=count($parts)-1;
$r['email']=str_replace('(','',$parts[$top]);
$r['email']=str_replace(')','',$r['email']);
array_pop($parts);
$val=implode(' ',$parts);
if ($val=='') {
unset($array[$key]);
continue;
}
$r['name']=$val;
unset($array[$key]);
if ($key==1)
{
$r['organization']=$array[0];
unset($array[0]);
}
}
}
if (!isset($r['name']) && isset($array[0]))
{
$r['name']=$array[0];
unset($array[0]);
}
if (isset($r['name']) && is_array($r['name']))
{
$r['name']=implode($r['name'],' ');
}
if (!empty($array) && !isset($r['address']))
$r['address']=$array;
return $r;
}
?>

View file

@ -28,8 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* benic.whois 1.0 Matthijs Koot <koot@cyberwar.nl> */
/* benic.whois 1.2 David Saez */
include_once('generic3.whois');
include_once('getdate.whois');
require_once('whois.parser.php');
if(!defined("__BE_HANDLER__")) define("__BE_HANDLER__",1);

View file

@ -32,8 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/* 24/7/2002 2.0 David Saez - updated to new object model */
/* 17/3/2003 2.1 David Saez - rewritten to use generic3.whois */
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
if(!defined("__CH_HANDLER__")) define("__CH_HANDLER__",1);

View file

@ -39,8 +39,7 @@
if(!defined("__DE_HANDLER__")) define("__DE_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class de_handler {

View file

@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if(!defined("__FM_HANDLER__")) define("__FM_HANDLER__",1);
require_once('generic2.whois');
require_once('generic3.whois');
require_once('whois.parser.php');
class fm_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__ASCIO_HANDLER__")) define("__ASCIO_HANDLER__",1);
require_once("generic3.whois");
require_once('getdate.whois');
require_once('whois.parser.php');
class ascio_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__DIRECTNIC_HANDLER__")) define("__DIRECTNIC_HANDLER__",1);
require_once("generic3.whois");
require_once('getdate.whois');
require_once('whois.parser.php');
class directnic_handler {

View file

@ -31,8 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if(!defined("__DOTSTER_HANDLER__")) define("__DOTSTER_HANDLER__",1);
require_once("generic3.whois");
require_once('getdate.whois');
require_once('whois.parser.php');
class dotster_handler {

View file

@ -32,8 +32,7 @@
if(!defined("__ENOM_HANDLER__")) define("__ENOM_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class enom_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__GODADDY_HANDLER__")) define("__GODADDY_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class godaddy_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__MONIKER_HANDLER__")) define("__MONIKER_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class moniker_handler {

View file

@ -32,8 +32,7 @@
if(!defined("__NICLINE_HANDLER__")) define("__NICLINE_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class nicline_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__SRSPLUS_HANDLER__")) define("__SRSPLUS_HANDLER__",1);
require_once("generic3.whois");
require_once('getdate.whois');
require_once('whois.parser.php');
class srsplus_handler {

View file

@ -30,8 +30,7 @@
if(!defined('__TVCORP_HANDLER__')) define('__TVCORP_HANDLER__',1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class tvcorp_handler {

View file

@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if(!defined("__KRNIC_HANDLER__")) define("__KRNIC_HANDLER__",1);
require_once("generic2.whois");
require_once("generic3.whois");
require_once('whois.parser.php');
class krnic_handler {

View file

@ -31,8 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if(!defined("__NL_HANDLER__")) define("__NL_HANDLER__",1);
require_once("generic3.whois");
require_once('getdate.whois');
require_once('whois.parser.php');
class nl_handler {

View file

@ -1,6 +1,8 @@
<?php
require_once('getdate.whois');
require_once('genutil.whois');
//-------------------------------------------------------------------------
function generic_parser_a ($rawdata,$translate,$contacts,$main='domain',$dateformat='dmy')
{
@ -91,4 +93,213 @@ format_dates($ret,$dateformat);
return $ret;
}
//-------------------------------------------------------------------------
function get_blocks ( $rawdata, $items )
{
$r=array();
$endtag='';
while (list($key,$val)=each($rawdata))
{
$val=trim($val);
if ($val=='') continue;
$found=false;
reset($items);
while (list($field, $match)=each($items)) {
$pos=strpos($val,$match);
if ($field!='' && $pos!==false) {
if ($val==$match) {
$found=true;
$endtag='';
$line=$val;
break;
}
$last=substr($val,-1,1);
if ($last==':' || $last=='-' || $last==']') {
$found=true;
$endtag=$last;
$line=$val;
break;
}
else {
$var=getvarname(strtok($field,"#"));
$itm=trim(substr($val,$pos+strlen($match)));
eval("\$r".$var."=\$itm;");
}
}
}
if (!$found) continue;
$block=array();
$found=false;
$spaces=0;
while (list($key,$val)=each($rawdata))
{
$val=trim($val);
if ($val=="") {
if ($found && ++$spaces==2) break;
continue;
}
if (!$found) {
$found=true;
$block[]=$val;
continue;
}
$last=substr(trim($val),-1,1);
if ($last==$endtag) {
prev($rawdata);
break;
}
if ($spaces>0) {
reset($items);
$ok=true;
while (list($field, $match)=each($items)) {
$pos=strpos($val,$match);
if ($pos!==false) $ok=false;
}
if (!$ok) {
prev($rawdata);
break;
}
}
$block[]=$val;
}
reset($items);
while (list($field, $match)=each($items)) {
$pos=strpos($line,$match);
if ($pos!==false) {
$var=getvarname($field);
eval("\$r".$var."=\$block;");
}
}
}
return $r;
}
//-------------------------------------------------------------------------
function get_contact ( $array, $extra_items='' )
{
if (!is_array($array))
return array();
$items = array (
'fax..:' => 'fax',
'fax-' => 'fax',
'fax:' => 'fax',
'[fax]' => 'fax',
'(fax)' => 'fax',
'fax' => 'fax',
'phone:' => 'phone',
'email:' => 'email',
'company name:' => 'organization',
'first name:' => 'name.first',
'last name:' => 'name.last',
'street:' => 'address.street',
'language:' => '',
'location:' => 'address.city',
'country:' => 'address.country',
'name:' => 'name',
'fax.' => 'fax',
'tel.' => 'phone'
);
if ($extra_items!='')
$items=array_merge($extra_items,$items);
while (list($key,$val)=each($array))
{
$ok=true;
while ($ok)
{
reset($items);
$ok=false;
while (list($match,$field)=each($items))
{
$pos=strpos(strtolower($val),$match);
if ($pos===false) continue;
$itm=trim(substr($val,$pos+strlen($match)));
if ($field!='')
{
eval("\$r".getvarname($field)."=\$itm;");
}
$val=trim(substr($val,0,$pos));
if ($val=='')
unset($array[$key]);
else
{
$array[$key]=$val;
$ok=true;
}
break;
}
}
if ($val=='') continue;
if (!preg_match("/[^0-9\(\)\-\.\+ ]/", $val) && strlen($val)>5)
{
if (isset($r['phone']))
$r['fax']=$val;
else
$r['phone']=$val;
unset($array[$key]);
continue;
}
if (strstr($val,'@'))
{
$val=str_replace("\t",' ',$val);
$parts=explode(' ',$val);
$top=count($parts)-1;
$r['email']=str_replace('(','',$parts[$top]);
$r['email']=str_replace(')','',$r['email']);
array_pop($parts);
$val=implode(' ',$parts);
if ($val=='') {
unset($array[$key]);
continue;
}
$r['name']=$val;
unset($array[$key]);
if ($key==1)
{
$r['organization']=$array[0];
unset($array[0]);
}
}
}
if (!isset($r['name']) && isset($array[0]))
{
$r['name']=$array[0];
unset($array[0]);
}
if (isset($r['name']) && is_array($r['name']))
{
$r['name']=implode($r['name'],' ');
}
if (!empty($array) && !isset($r['address']))
$r['address']=$array;
return $r;
}
?>

View file

@ -37,8 +37,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if(!defined("__UK_HANDLER__")) define("__UK_HANDLER__",1);
require_once('getdate.whois');
require_once('generic3.whois');
require_once('whois.parser.php');
class uk_handler {

View file

@ -38,8 +38,7 @@
if(!defined("__ES_HANDLER__")) define("__ES_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class es_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__BUYDOMAINS_HANDLER__")) define("__BUYDOMAINS_HANDLER__",1);
require_once("generic3.whois");
require_once('getdate.whois');
require_once('whois.parser.php');
class buydomains_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__CRONON_HANDLER__")) define("__CRONON_HANDLER__",1);
require_once("generic3.whois");
require_once('getdate.whois');
require_once('whois.parser.php');
class cronon_handler {

View file

@ -30,7 +30,7 @@
if(!defined("__DOMAINBANK_HANDLER__")) define("__DOMAINBANK_HANDLER__",1);
require_once("generic3.whois");
require_once('whois.parser.php');
class domainbank_handler {

View file

@ -32,8 +32,7 @@
if(!defined("__DOTREGISTRAR_HANDLER__")) define("__DOTREGISTRAR_HANDLER__",1);
require_once("generic3.whois");
require_once('getdate.whois');
require_once('whois.parser.php');
class dotregistrar_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__INNERWISE_HANDLER__")) define("__INNERWISE_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class innerwise_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__NETSOL_HANDLER__")) define("__NETSOL_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class netsol_handler {

View file

@ -31,8 +31,7 @@
if(!defined("__OPENSRSNET_HANDLER__")) define("__OPENSRSNET_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class opensrsnet_handler {

View file

@ -31,8 +31,7 @@
if(!defined("__REGISTERCOM_HANDLER__")) define("__REGISTERCOM_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class registercom_handler {

View file

@ -30,8 +30,7 @@
if(!defined("__STARGATE_HANDLER__")) define("__STARGATE_HANDLER__",1);
require_once('generic3.whois');
require_once('getdate.whois');
require_once('whois.parser.php');
class stargate_handler {

View file

@ -33,8 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if(!defined("__ZA_HANDLER__")) define("__ZA_HANDLER__",1);
require_once("generic3.whois");
require_once("getdate.whois");
require_once('whois.parser.php');
class za_handler {