Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug #17476 [test.com] Undefined index: server

git-svn-id: http://svn.php.net/repository/pear/packages/Net_Whois/trunk@300314 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 661dc0d309ed9700ce2cda9897f5f73f3bb60a15 1 parent 4a9eae1
Ken Guest kenguest authored
Showing with 78 additions and 41 deletions.
  1. +37 −41 Whois.php
  2. +41 −0 tests/test17476.php
78 Whois.php
View
@@ -58,18 +58,18 @@ class Net_Whois extends PEAR
* @access private
*/
var $_nicServers = array (
- "NICHOST" => "whois.crsnic.net",
- "INICHOST" => "whois.networksolutions.com",
- "DNICHOST" => "whois.nic.mil",
- "GNICHOST" => "whois.nic.gov",
- "ANICHOST" => "whois.arin.net",
- "RNICHOST" => "whois.ripe.net",
- "PNICHOST" => "whois.apnic.net",
- "RUNICHOST" => "whois.ripn.net",
- "MNICHOST" => "whois.ra.net",
- "QNICHOST_TAIL" => ".whois-servers.net",
- "SNICHOST" => "whois.6bone.net",
- "BNICHOST" => "whois.registro.br"
+ 'NICHOST' => 'whois.crsnic.net',
+ 'INICHOST' => 'whois.networksolutions.com',
+ 'DNICHOST' => 'whois.nic.mil',
+ 'GNICHOST' => 'whois.nic.gov',
+ 'ANICHOST' => 'whois.arin.net',
+ 'RNICHOST' => 'whois.ripe.net',
+ 'PNICHOST' => 'whois.apnic.net',
+ 'RUNICHOST' => 'whois.ripn.net',
+ 'MNICHOST' => 'whois.ra.net',
+ 'QNICHOST_TAIL' => '.whois-servers.net',
+ 'SNICHOST' => 'whois.6bone.net',
+ 'BNICHOST' => 'whois.registro.br'
);
/**
@@ -78,7 +78,7 @@ class Net_Whois extends PEAR
* @var string
* @access private
*/
- var $_whoisServerID = "Whois Server: ";
+ var $_whoisServerID = 'Whois Server: ';
/**
* Server to search for IP address lookups
@@ -86,7 +86,7 @@ class Net_Whois extends PEAR
* @var array
* @access private
*/
- var $_ipNicServers = array ("RNICHOST", "PNICHOST", "BNICHOST");
+ var $_ipNicServers = array ('RNICHOST', 'PNICHOST', 'BNICHOST');
/**
* List of error codes and text
@@ -171,35 +171,31 @@ function query($domain, $userWhoisServer = null)
if (isset($userWhoisServer)) {
$whoisServer = $userWhoisServer;
- } elseif (preg_match("/^!.*/", $domain)) {
- $whoisServer = $this->_nicServers["INICHOST"];
- } elseif (preg_match("/.*?-arin/i", $domain)) {
- $whoisServer = $this->_nicServers["ANICHOST"];
+ } elseif (preg_match('/^!.*/', $domain)) {
+ $whoisServer = $this->_nicServers['INICHOST'];
+ } elseif (preg_match('/.*?-arin/i', $domain)) {
+ $whoisServer = $this->_nicServers['ANICHOST'];
} elseif (preg_match('/\.gov$/i', $domain)) {
- $whoisServer = $this->_nicServers["GNICHOST"];
+ $whoisServer = $this->_nicServers['GNICHOST'];
} elseif (preg_match('/\.mil$/i', $domain)) {
$whoisServer = $this->_nicServers["DNICHOST"];
} else {
$whoisServer = $this->_chooseServer($domain);
}
- $whoisData = $this->_connect($whoisServer, $domain);
+ $_domain = $this->authoritative ? 'domain ' . $domain : $domain;
+ $whoisData = $this->_connect($whoisServer, $_domain);
+
if (PEAR::isError($whoisData)) {
return $whoisData;
}
- if (($this->authoritative)
- && (preg_match('/To single out one record/i', $whoisData))
- ) {
- $whoisData = $this->_connect('whois.crsnic.net', "=$domain");
- $pos = strpos($whoisData, 'Domain Name:');
- $chunk = substr($whoisData, $pos);
- $matches = array();
- preg_match('/Whois Server:(?<server>.*)/', $chunk, $matches);
- $server = trim($matches['server']);
- $whoisData = $this->_connect(trim($matches['server']), "$domain");
+ if ($this->authoritative) {
+ $pattern = '/\s+' . $this->_whoisServerID . '(.+?)\n/';
+ if (preg_match($pattern, $whoisData, $matches)) {
+ $whoisData = $this->_connect(trim(array_pop($matches)), $domain);
+ }
}
-
return $whoisData;
}
// }}}
@@ -217,7 +213,7 @@ function query($domain, $userWhoisServer = null)
*/
function queryAPNIC($domain)
{
- return $this->query($domain, $this->_nicServers["PNICHOST"]);
+ return $this->query($domain, $this->_nicServers['PNICHOST']);
}
// }}}
@@ -233,7 +229,7 @@ function queryAPNIC($domain)
*/
function queryIPv6($domain)
{
- return $this->query($domain, $this->_nicServers["SNICHOST"]);
+ return $this->query($domain, $this->_nicServers['SNICHOST']);
}
// }}}
@@ -250,7 +246,7 @@ function queryIPv6($domain)
*/
function queryRADB($ipAddress)
{
- return $this->query($ipAddress, $this->_nicServers["MNICHOST"]);
+ return $this->query($ipAddress, $this->_nicServers['MNICHOST']);
}
// }}}
@@ -265,16 +261,16 @@ function queryRADB($ipAddress)
*/
function _chooseServer($domain)
{
- if (!strpos($domain, ".")) {
- return $this->_nicServers["NICHOST"];
+ if (!strpos($domain, '.')) {
+ return $this->_nicServers['NICHOST'];
}
- $TLD = end(explode(".", $domain));
+ $TLD = end(explode('.', $domain));
if (is_numeric($TLD)) {
- $whoisServer = $this->_nicServers["ANICHOST"];
+ $whoisServer = $this->_nicServers['ANICHOST'];
} else {
- $whoisServer = $TLD . $this->_nicServers["QNICHOST_TAIL"];
+ $whoisServer = $TLD . $this->_nicServers['QNICHOST_TAIL'];
}
return $whoisServer;
@@ -334,10 +330,10 @@ function _connect($nicServer, $domain)
// check for whois server redirection
if (!isset($nHost)) {
- $pattern = "/" . $this->_whoisServerID . "(.*)/";
+ $pattern='/'.$this->_whoisServerID.'(.*)/';
if (preg_match($pattern, $line, $matches)) {
$nHost = $matches[1];
- } elseif ($nicServer == $this->_nicServers["ANICHOST"]) {
+ } elseif ($nicServer == $this->_nicServers['ANICHOST']) {
foreach ($this->_ipNicServers as $ipNicServer) {
if (strstr($line, $this->_nicServers[$ipNicServer])) {
$nHost = $this->_nicServers[$ipNicServer];
41 tests/test17476.php
View
@@ -0,0 +1,41 @@
+<?php
+/**
+ * test17476.php
+ * 09-Jun-2010
+ *
+ * PHP Version 5
+ *
+ * @category test17476
+ * @package test17476
+ * @author Ken Guest <ken.guest@blacknight.com>
+ * @license GPL (see http://www.gnu.org/licenses/gpl.txt)
+ * @version CVS: <cvs_id>
+ * @link test17476.php
+ * @todo
+*/
+
+
+
+?>
+<?php
+$q=isset($_REQUEST['q'])?htmlspecialchars($_REQUEST['q']):NULL;
+$s=isset($_REQUEST['s'])?htmlspecialchars($_REQUEST['s']):NULL;
+$q = 'test.com';
+if (strchr($q,'.')) {
+ require_once "Net/Whois.php";
+ $whois = new Net_Whois;
+ $q=strtolower($q);
+ if (!$s && $q[0] == '.') {
+ $s='whois.iana.org';
+ }
+ $q=trim($q,'.');
+ $tld=pathinfo($q,PATHINFO_EXTENSION);
+ if ($tld=='com') {
+ $whois->setAuthoritative(1);
+ } elseif ($tld=='name') {
+ $q='domain = '.$q;
+ }
+ $data=htmlspecialchars($whois->query($q,$s));
+ echo "<pre>$data</pre>";
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.