io-developer / php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 8.0 compatible (5.4+ old versions)
MIT License
438 stars 117 forks source link

Wrong expiration date detected #129

Closed mlocati closed 3 years ago

mlocati commented 4 years ago

PHP-Whois version: 4.0.0

PHP version: 7.2.33

Description The reported expiration for one of our domains (progesoft-italia.com) is wrong. From the control panel offered by our domain registration provider, we can read this:

image

(Sorry for Italian, it says that the domain expiration is 2021-07-22)

But this library says that the expiration is 2020-07-22

How to reproduce

Try the following code:

<?php
use Iodev\Whois\Factory;
require_once './vendor/autoload.php';
$whois = Factory::get()->createWhois();
$info = $whois->loadDomainInfo('progesoft-italia.com');
echo gmdate('Y-m-d', $info->expirationDate);

I'd expect it outputs 2021-07-22, but it outputs 2020-07-22

Possible Solution

I've seen that the library performs 2 queries, the first using whois.verisign-grs.com and the second using whois.register.it Manually running those queries, we have:

$ whois -h whois.verisign-grs.com progesoft-italia.com 2>/dev/null | grep -i exp | grep 20
   Registry Expiry Date: 2021-07-22T13:07:14Z
$ whois -h whois.register.it progesoft-italia.com 2>/dev/null | grep -i exp | grep 20
Registrar Registration Expiration Date: 2020-07-22T00:00:00Z

As you can see, whois.verisign-grs.com returns 2021-07-22 (the value we'd expect), whereas whois.register.it returns the value returned by this library.

bessone commented 3 years ago

Somehow related to #123

mlocati commented 3 years ago

Yep, they are related. It'd be nice to have a way to get only the first query result (thus, skipping this second query).

I have a patch file for this. Are the maintainers interested in this?

io-developer commented 3 years ago

Checked. Now it's correct. Maybe previous parsing improvements fixed it..

mlocati commented 3 years ago

Checked. Now it's correct. Maybe previous parsing improvements fixed it..

Nope, that's not the reason. The reason is that the whois server returned two dates, and php-whois always return the second date.

mlocati commented 3 years ago

I solved this issue by patching php-whois version 3.5.0 (the version we are using) like this:

From 4e88993de778be765624ab09f1bd42f05c6f295d Mon Sep 17 00:00:00 2001
From: Michele Locati <michele@locati.it>
Date: Tue, 15 Sep 2020 08:52:23 +0200
Subject: [PATCH] Allow skipping recursive whois

---
 src/Iodev/Whois/Modules/Tld/TldModule.php | 22 +++++++++++++---------
 src/Iodev/Whois/Whois.php                 |  5 +++--
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/Iodev/Whois/Modules/Tld/TldModule.php b/src/Iodev/Whois/Modules/Tld/TldModule.php
index d72a17a..c570744 100644
--- a/src/Iodev/Whois/Modules/Tld/TldModule.php
+++ b/src/Iodev/Whois/Modules/Tld/TldModule.php
@@ -122,30 +122,32 @@ class TldModule extends Module
     /**
      * @param string $domain
      * @param TldServer $server
+     * @param bool $descend
      * @return DomainResponse
      * @throws ServerMismatchException
      * @throws ConnectionException
      * @throws WhoisException
      */
-    public function lookupDomain($domain, TldServer $server = null)
+    public function lookupDomain($domain, TldServer $server = null, $descend = true)
     {
         $servers = $server ? [$server] : $this->matchServers($domain);
-        list ($response) = $this->loadDomainData($domain, $servers);
+        list ($response) = $this->loadDomainData($domain, $servers, $descend);
         return $response;
     }

     /**
      * @param string $domain
      * @param TldServer $server
+     * @param bool $descend
      * @return DomainInfo
      * @throws ServerMismatchException
      * @throws ConnectionException
      * @throws WhoisException
      */
-    public function loadDomainInfo($domain, TldServer $server = null)
+    public function loadDomainInfo($domain, TldServer $server = null, $descend = true)
     {
         $servers = $server ? [$server] : $this->matchServers($domain);
-        list (, $info) = $this->loadDomainData($domain, $servers);
+        list (, $info) = $this->loadDomainData($domain, $servers, $descend);
         return $info;
     }

@@ -169,11 +171,12 @@ class TldModule extends Module
     /**
      * @param string $domain
      * @param TldServer[] $servers
+     * @param bool $descend
      * @return array
      * @throws ConnectionException
      * @throws WhoisException
      */
-    private function loadDomainData($domain, $servers)
+    private function loadDomainData($domain, $servers, $descend)
     {
         $this->lastUsedServers = [];
         $domain = DomainHelper::toAscii($domain);
@@ -182,7 +185,7 @@ class TldModule extends Module
         $lastError = null;
         foreach ($servers as $server) {
             $this->lastUsedServers[] = $server;
-            $this->loadParsedTo($response, $info, $server, $domain, false, null, $lastError);
+            $this->loadParsedTo($response, $info, $server, $domain, false, null, $lastError, $descend);
             if ($info) {
                 break;
             }
@@ -201,10 +204,11 @@ class TldModule extends Module
      * @param $strict
      * @param $host
      * @param $lastError
+     * @param bool $descend
      * @throws ConnectionException
      * @throws WhoisException
      */
-    private function loadParsedTo(&$outResponse, &$outInfo, $server, $domain, $strict = false, $host = null, &$lastError = null)
+    private function loadParsedTo(&$outResponse, &$outInfo, $server, $domain, $strict = false, $host = null, &$lastError = null, $descend = true)
     {
         try {
             $outResponse = $this->loadResponse($server, $domain, $strict, $host);
@@ -216,11 +220,11 @@ class TldModule extends Module
             throw $lastError;
         }
         if (!$strict && !$outInfo) {
-            $this->loadParsedTo($tmpResponse, $tmpInfo, $server, $domain, true, $host, $lastError);
+            $this->loadParsedTo($tmpResponse, $tmpInfo, $server, $domain, true, $host, $lastError, $descend);
             $outResponse = $tmpInfo ? $tmpResponse : $outResponse;
             $outInfo = $tmpInfo ?: $outInfo;
         }
-        if (!$outInfo || $host == $outInfo->getWhoisServer()) {
+        if (!$outInfo || $host == $outInfo->getWhoisServer() || !$descend) {
             return;
         }
         $host = $outInfo->getWhoisServer();
diff --git a/src/Iodev/Whois/Whois.php b/src/Iodev/Whois/Whois.php
index 6ec78f2..3621807 100644
--- a/src/Iodev/Whois/Whois.php
+++ b/src/Iodev/Whois/Whois.php
@@ -93,14 +93,15 @@ class Whois

     /**
      * @param string $domain
+     * @param bool $descend
      * @return DomainInfo
      * @throws ServerMismatchException
      * @throws ConnectionException
      * @throws WhoisException
      */
-    public function loadDomainInfo($domain)
+    public function loadDomainInfo($domain, $descend = true)
     {
-        return $this->getTldModule()->loadDomainInfo($domain);
+        return $this->getTldModule()->loadDomainInfo($domain, null, $descend);
     }

     /**
jordanade commented 1 year ago

I'm still getting out of date expiries. In my case it was on the domain 'rsuttonart.org'.