From 0bdad0d69d2ba4363aeed97d5b81a1bc4fae4eb7 Mon Sep 17 00:00:00 2001 From: Dmitry Lukashin Date: Fri, 18 Dec 2015 22:59:13 +0300 Subject: [PATCH 01/23] [WIP] Rewrite of basic classes --- .travis.yml | 3 - LICENSE | 0 README.md | 39 +- composer.json | 5 +- docs/UPGRADE.md | 21 +- handler.template.php | 0 src/Handler/HandlerAbstract.php | 45 +++ src/Handler/Ru.php | 38 ++ src/HandlerMap.php | 77 ++++ src/IpTools.php | 55 +-- src/Parser/ParserA.php | 7 + src/Parser/ParserB.php | 0 src/Parser/iParser.php | 6 + src/Provider/HttpServer.php | 41 +++ src/Provider/ProviderAbstract.php | 33 ++ src/Provider/WhoisServer.php | 36 ++ src/Query.php | 65 ++++ src/Utils.php | 2 +- src/Whois.php | 313 ++-------------- src/WhoisClient.php | 8 +- src/Whois_Old.php | 334 ++++++++++++++++++ src/{ => old/extends}/whois.gtld.php | 0 src/{ => old/extends}/whois.ip.php | 0 src/{ => old/extends}/whois.jp.php | 0 src/{ => old/extends}/whois.ws.php | 0 src/{ => old/gtld}/whois.gtld.afternic.php | 0 src/{ => old/gtld}/whois.gtld.alldomains.php | 0 src/{ => old/gtld}/whois.gtld.ascio.php | 0 src/{ => old/gtld}/whois.gtld.assorted.php | 0 .../gtld}/whois.gtld.corporatedomains.php | 0 src/{ => old/gtld}/whois.gtld.directnic.php | 0 .../gtld}/whois.gtld.domaindiscover.php | 0 .../gtld}/whois.gtld.domainpeople.php | 0 src/{ => old/gtld}/whois.gtld.dotster.php | 0 src/{ => old/gtld}/whois.gtld.dreamhost.php | 0 src/{ => old/gtld}/whois.gtld.enom.php | 0 src/{ => old/gtld}/whois.gtld.fabulous.php | 0 src/{ => old/gtld}/whois.gtld.fastdomain.php | 0 src/{ => old/gtld}/whois.gtld.gandi.php | 0 src/{ => old/gtld}/whois.gtld.genericb.php | 0 src/{ => old/gtld}/whois.gtld.godaddy.php | 0 src/{ => old/gtld}/whois.gtld.iana.php | 0 src/{ => old/gtld}/whois.gtld.interdomain.php | 0 .../gtld}/whois.gtld.itsyourdomain.php | 0 src/{ => old/gtld}/whois.gtld.joker.php | 0 src/{ => old/gtld}/whois.gtld.markmonitor.php | 0 src/{ => old/gtld}/whois.gtld.melbourneit.php | 0 src/{ => old/gtld}/whois.gtld.moniker.php | 0 src/{ => old/gtld}/whois.gtld.name.php | 0 src/{ => old/gtld}/whois.gtld.nameintel.php | 0 src/{ => old/gtld}/whois.gtld.namejuice.php | 0 src/{ => old/gtld}/whois.gtld.nameking.php | 0 src/{ => old/gtld}/whois.gtld.names4ever.php | 0 src/{ => old/gtld}/whois.gtld.namevault.php | 0 .../gtld}/whois.gtld.networksolutions.php | 0 src/{ => old/gtld}/whois.gtld.nicco.php | 0 src/{ => old/gtld}/whois.gtld.nicline.php | 0 src/{ => old/gtld}/whois.gtld.onlinenic.php | 0 src/{ => old/gtld}/whois.gtld.opensrs.php | 0 src/{ => old/gtld}/whois.gtld.ovh.php | 0 src/{ => old/gtld}/whois.gtld.psiusa.php | 0 .../gtld}/whois.gtld.publicdomainregistry.php | 0 src/{ => old/gtld}/whois.gtld.register.php | 0 src/{ => old/gtld}/whois.gtld.rrpproxy.php | 0 src/{ => old/gtld}/whois.gtld.schlund.php | 0 src/{ => old/gtld}/whois.gtld.srsplus.php | 0 src/{ => old/gtld}/whois.gtld.tmagnic.php | 0 src/{ => old/gtld}/whois.gtld.tvcorp.php | 0 .../gtld}/whois.gtld.wildwestdomains.php | 0 src/{ => old/special}/whois.rwhois.php | 0 src/{ => old}/whois.ae.php | 0 src/{ => old}/whois.aero.php | 0 src/{ => old}/whois.ag.php | 0 src/{ => old}/whois.am.php | 0 src/{ => old}/whois.asia.php | 0 src/{ => old}/whois.at.php | 0 src/{ => old}/whois.au.php | 0 src/{ => old}/whois.be.php | 0 src/{ => old}/whois.bh.php | 0 src/{ => old}/whois.biz.php | 0 src/{ => old}/whois.br.php | 0 src/{ => old}/whois.ca.php | 0 src/{ => old}/whois.cat.php | 0 src/{ => old}/whois.ch.php | 0 src/{ => old}/whois.cl.php | 0 src/{ => old}/whois.cn.php | 0 src/{ => old}/whois.co.php | 0 src/{ => old}/whois.co.za.php | 0 src/{ => old}/whois.coop.php | 0 src/{ => old}/whois.cz.php | 0 src/{ => old}/whois.de.php | 0 src/{ => old}/whois.edu.php | 0 src/{ => old}/whois.eu.php | 0 src/{ => old}/whois.fi.php | 0 src/{ => old}/whois.fj.php | 0 src/{ => old}/whois.fm.php | 0 src/{ => old}/whois.fr.php | 0 src/{ => old}/whois.hu.php | 0 src/{ => old}/whois.ie.php | 0 src/{ => old}/whois.il.php | 0 src/{ => old}/whois.in.php | 0 src/{ => old}/whois.info.php | 0 src/{ => old}/whois.int.php | 0 src/{ => old}/whois.ip.afrinic.php | 0 src/{ => old}/whois.ip.apnic.php | 0 src/{ => old}/whois.ip.arin.php | 0 src/{ => old}/whois.ip.krnic.php | 0 src/{ => old}/whois.ip.lacnic.php | 0 src/{ => old}/whois.ip.ripe.php | 0 src/{ => old}/whois.ir.php | 0 src/{ => old}/whois.is.php | 0 src/{ => old}/whois.it.php | 0 src/{ => old}/whois.lt.php | 0 src/{ => old}/whois.lu.php | 0 src/{ => old}/whois.ly.php | 0 src/{ => old}/whois.me.php | 0 src/{ => old}/whois.mobi.php | 0 src/{ => old}/whois.museum.php | 0 src/{ => old}/whois.mx.php | 0 src/{ => old}/whois.name.php | 0 src/{ => old}/whois.nl.php | 0 src/{ => old}/whois.nu.php | 0 src/{ => old}/whois.nz.php | 0 src/{ => old}/whois.org.php | 0 src/{ => old}/whois.org.za.php | 0 src/{ => old}/whois.pl.php | 0 src/{ => old}/whois.pro.php | 0 src/{ => old}/whois.pt.php | 0 src/{ => old}/whois.ro.php | 0 src/{ => old}/whois.ru.php | 0 src/{ => old}/whois.sc.php | 0 src/{ => old}/whois.se.php | 0 src/{ => old}/whois.si.php | 0 src/{ => old}/whois.su.php | 0 src/{ => old}/whois.tel.php | 0 src/{ => old}/whois.travel.php | 0 src/{ => old}/whois.uk.php | 0 src/{ => old}/whois.us.php | 0 src/{ => old}/whois.ve.php | 0 src/{ => old}/whois.xxx.php | 0 src/{ => old}/whois.zanet.php | 0 test.php | 22 ++ tests/IpToolsTest.php | 6 +- tests/WhoisTest.php | 2 +- testsuite.php | 0 145 files changed, 794 insertions(+), 364 deletions(-) mode change 100755 => 100644 LICENSE mode change 100755 => 100644 handler.template.php create mode 100644 src/Handler/HandlerAbstract.php create mode 100644 src/Handler/Ru.php create mode 100644 src/HandlerMap.php create mode 100644 src/Parser/ParserA.php create mode 100644 src/Parser/ParserB.php create mode 100644 src/Parser/iParser.php create mode 100644 src/Provider/HttpServer.php create mode 100644 src/Provider/ProviderAbstract.php create mode 100644 src/Provider/WhoisServer.php create mode 100644 src/Query.php create mode 100644 src/Whois_Old.php rename src/{ => old/extends}/whois.gtld.php (100%) rename src/{ => old/extends}/whois.ip.php (100%) rename src/{ => old/extends}/whois.jp.php (100%) rename src/{ => old/extends}/whois.ws.php (100%) rename src/{ => old/gtld}/whois.gtld.afternic.php (100%) rename src/{ => old/gtld}/whois.gtld.alldomains.php (100%) rename src/{ => old/gtld}/whois.gtld.ascio.php (100%) rename src/{ => old/gtld}/whois.gtld.assorted.php (100%) rename src/{ => old/gtld}/whois.gtld.corporatedomains.php (100%) rename src/{ => old/gtld}/whois.gtld.directnic.php (100%) rename src/{ => old/gtld}/whois.gtld.domaindiscover.php (100%) rename src/{ => old/gtld}/whois.gtld.domainpeople.php (100%) rename src/{ => old/gtld}/whois.gtld.dotster.php (100%) rename src/{ => old/gtld}/whois.gtld.dreamhost.php (100%) rename src/{ => old/gtld}/whois.gtld.enom.php (100%) rename src/{ => old/gtld}/whois.gtld.fabulous.php (100%) rename src/{ => old/gtld}/whois.gtld.fastdomain.php (100%) rename src/{ => old/gtld}/whois.gtld.gandi.php (100%) rename src/{ => old/gtld}/whois.gtld.genericb.php (100%) rename src/{ => old/gtld}/whois.gtld.godaddy.php (100%) rename src/{ => old/gtld}/whois.gtld.iana.php (100%) rename src/{ => old/gtld}/whois.gtld.interdomain.php (100%) rename src/{ => old/gtld}/whois.gtld.itsyourdomain.php (100%) rename src/{ => old/gtld}/whois.gtld.joker.php (100%) rename src/{ => old/gtld}/whois.gtld.markmonitor.php (100%) rename src/{ => old/gtld}/whois.gtld.melbourneit.php (100%) rename src/{ => old/gtld}/whois.gtld.moniker.php (100%) rename src/{ => old/gtld}/whois.gtld.name.php (100%) rename src/{ => old/gtld}/whois.gtld.nameintel.php (100%) rename src/{ => old/gtld}/whois.gtld.namejuice.php (100%) rename src/{ => old/gtld}/whois.gtld.nameking.php (100%) rename src/{ => old/gtld}/whois.gtld.names4ever.php (100%) rename src/{ => old/gtld}/whois.gtld.namevault.php (100%) rename src/{ => old/gtld}/whois.gtld.networksolutions.php (100%) rename src/{ => old/gtld}/whois.gtld.nicco.php (100%) rename src/{ => old/gtld}/whois.gtld.nicline.php (100%) rename src/{ => old/gtld}/whois.gtld.onlinenic.php (100%) rename src/{ => old/gtld}/whois.gtld.opensrs.php (100%) rename src/{ => old/gtld}/whois.gtld.ovh.php (100%) rename src/{ => old/gtld}/whois.gtld.psiusa.php (100%) rename src/{ => old/gtld}/whois.gtld.publicdomainregistry.php (100%) rename src/{ => old/gtld}/whois.gtld.register.php (100%) rename src/{ => old/gtld}/whois.gtld.rrpproxy.php (100%) rename src/{ => old/gtld}/whois.gtld.schlund.php (100%) rename src/{ => old/gtld}/whois.gtld.srsplus.php (100%) rename src/{ => old/gtld}/whois.gtld.tmagnic.php (100%) rename src/{ => old/gtld}/whois.gtld.tvcorp.php (100%) rename src/{ => old/gtld}/whois.gtld.wildwestdomains.php (100%) rename src/{ => old/special}/whois.rwhois.php (100%) rename src/{ => old}/whois.ae.php (100%) rename src/{ => old}/whois.aero.php (100%) rename src/{ => old}/whois.ag.php (100%) rename src/{ => old}/whois.am.php (100%) rename src/{ => old}/whois.asia.php (100%) rename src/{ => old}/whois.at.php (100%) rename src/{ => old}/whois.au.php (100%) rename src/{ => old}/whois.be.php (100%) rename src/{ => old}/whois.bh.php (100%) rename src/{ => old}/whois.biz.php (100%) rename src/{ => old}/whois.br.php (100%) rename src/{ => old}/whois.ca.php (100%) rename src/{ => old}/whois.cat.php (100%) rename src/{ => old}/whois.ch.php (100%) rename src/{ => old}/whois.cl.php (100%) rename src/{ => old}/whois.cn.php (100%) rename src/{ => old}/whois.co.php (100%) rename src/{ => old}/whois.co.za.php (100%) rename src/{ => old}/whois.coop.php (100%) rename src/{ => old}/whois.cz.php (100%) rename src/{ => old}/whois.de.php (100%) rename src/{ => old}/whois.edu.php (100%) rename src/{ => old}/whois.eu.php (100%) rename src/{ => old}/whois.fi.php (100%) rename src/{ => old}/whois.fj.php (100%) rename src/{ => old}/whois.fm.php (100%) rename src/{ => old}/whois.fr.php (100%) rename src/{ => old}/whois.hu.php (100%) rename src/{ => old}/whois.ie.php (100%) rename src/{ => old}/whois.il.php (100%) rename src/{ => old}/whois.in.php (100%) rename src/{ => old}/whois.info.php (100%) rename src/{ => old}/whois.int.php (100%) rename src/{ => old}/whois.ip.afrinic.php (100%) rename src/{ => old}/whois.ip.apnic.php (100%) rename src/{ => old}/whois.ip.arin.php (100%) rename src/{ => old}/whois.ip.krnic.php (100%) rename src/{ => old}/whois.ip.lacnic.php (100%) rename src/{ => old}/whois.ip.ripe.php (100%) rename src/{ => old}/whois.ir.php (100%) rename src/{ => old}/whois.is.php (100%) rename src/{ => old}/whois.it.php (100%) rename src/{ => old}/whois.lt.php (100%) rename src/{ => old}/whois.lu.php (100%) rename src/{ => old}/whois.ly.php (100%) rename src/{ => old}/whois.me.php (100%) rename src/{ => old}/whois.mobi.php (100%) rename src/{ => old}/whois.museum.php (100%) rename src/{ => old}/whois.mx.php (100%) rename src/{ => old}/whois.name.php (100%) rename src/{ => old}/whois.nl.php (100%) rename src/{ => old}/whois.nu.php (100%) rename src/{ => old}/whois.nz.php (100%) rename src/{ => old}/whois.org.php (100%) rename src/{ => old}/whois.org.za.php (100%) rename src/{ => old}/whois.pl.php (100%) rename src/{ => old}/whois.pro.php (100%) rename src/{ => old}/whois.pt.php (100%) rename src/{ => old}/whois.ro.php (100%) rename src/{ => old}/whois.ru.php (100%) rename src/{ => old}/whois.sc.php (100%) rename src/{ => old}/whois.se.php (100%) rename src/{ => old}/whois.si.php (100%) rename src/{ => old}/whois.su.php (100%) rename src/{ => old}/whois.tel.php (100%) rename src/{ => old}/whois.travel.php (100%) rename src/{ => old}/whois.uk.php (100%) rename src/{ => old}/whois.us.php (100%) rename src/{ => old}/whois.ve.php (100%) rename src/{ => old}/whois.xxx.php (100%) rename src/{ => old}/whois.zanet.php (100%) create mode 100644 test.php mode change 100755 => 100644 testsuite.php diff --git a/.travis.yml b/.travis.yml index 7e96aaf3..5a1f603e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,10 @@ language: php php: - - 5.3 - 5.4 - 5.5 - 5.6 - 7 - - hhvm - - hhvm-nightly matrix: fast_finish: true diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/README.md b/README.md index 510bbcdf..c1311ea5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,24 @@ +NEWS +---- + +phpWhois v5 is finally out! + +Fully rewritten with OOP, supports lot of new domains, fixed IP querying. +Helper functions for obtaining most important information about domain: + - Created, Modified, Expires + - DNS + - Contact info + +Whois info is now serializable for easy monitoring for changes + +Tests for the list of top-level domains run daily at http://phpwhois.pw/tests + +(!) Check whois.iana.org domain server to get the whois server of a top level domain of a given domain. + Introduction ------------ -This package contains a Whois (RFC954) library for PHP. It allows a PHP program to create a Whois object, and obtain the output of a whois query with the `lookup` function. +This package contains a Whois (RFC954) library for PHP. It allows a PHP program to create a Whois object, and obtain the output of a whois query with the `lookup` method. The response is an array containing, at least, an element 'rawdata', containing the raw output from the whois request. @@ -19,7 +36,7 @@ provided. Requirements ------------ -phpWhois requires PHP 5.3 or better with OpenSSL support to work properly. +phpWhois requires PHP 5.5 or later with OpenSSL support to work properly. Without SSL support you will not be able to query domains which do not have a whois server but that have a https based whois. @@ -94,12 +111,12 @@ The currently known whois services that offer special acccess are: that allow to pass the real client ip address. This feature is only available to registered gateways. If you are registered you can use this service when querying ripe ip addresses that way: - ```php - use phpWhois\Whois; - $whois = new Whois(); - $whois->useServer('uk','whois.ripe.net?-V{version},{ip} {query}'); - $result = $whois->lookup('62.97.102.115'); - ``` +```php +use phpWhois\Whois; +$whois = new Whois(); +$whois->useServer('uk','whois.ripe.net?-V{version},{ip} {query}'); +$result = $whois->lookup('62.97.102.115'); +``` ### whois.isoc.org.il This server is also using the new ripe whois server software and @@ -187,9 +204,9 @@ the `NON_UTF8` array in `whois.servers.php` Workflow of getting domain info ------------------------------- -1. Call method `phpWhois\Whois::lookup()` with domain name as parameter -2. If second parameter of method is **true** (default), phpWhois will try to convert the domain name to punycode -3. If domain is not listed in predefined handlers (`WHOIS_SPECIAL` at `src/whois.servers.php`), try to query **[tld].whois-servers.net**. If it has ip address, assume that it is valid whois server +1. Call method `phpWhois\Whois::lookup()` with domain name as parameter +2. If second parameter of method is **true** (default), phpWhois will try to convert the domain name to punycode +3. If domain is not listed in predefined handlers (`WHOIS_SPECIAL` at `src/whois.servers.php`), try to query **[tld].whois-servers.net**. If it has ip address, assume that it is valid whois server 4. Try to query found whois server or fill response array with `unknown()` method Notes diff --git a/composer.json b/composer.json index f03e3692..71c62d3d 100644 --- a/composer.json +++ b/composer.json @@ -25,12 +25,9 @@ ], "minimum-stability": "dev", "require": { - "php": ">=5.3.0", + "php": ">=5.4.0", "mso/idna-convert": "*" }, - "require-dev": { - "phpunit/phpunit": "4.4.1" - }, "suggest": { "lib-openssl": "*" }, diff --git a/docs/UPGRADE.md b/docs/UPGRADE.md index f3714bcc..9283796b 100644 --- a/docs/UPGRADE.md +++ b/docs/UPGRADE.md @@ -1,11 +1,10 @@ -Migration from v4 to v5 -======================= - -This document is intended to guide users through the process of migration from old version v4 to v5. - -What's new in v5? ----------------------------------------- - -1. You can check the list of new features in CHANGELOG.md -2. Minimum supported version of PHP is **5.3** because of namespaces -3. Project has external depencies and can be installed only through composer +Migration from v4 to v5 +======================= + +This document is intended to guide users through the process of migration from old version v4 to v5. + +What's new in v5? +---------------------------------------- + +1. You can check the list of new features in CHANGELOG.md +1. Project has external depencies and can be installed only through composer diff --git a/handler.template.php b/handler.template.php old mode 100755 new mode 100644 diff --git a/src/Handler/HandlerAbstract.php b/src/Handler/HandlerAbstract.php new file mode 100644 index 00000000..1cf91fcc --- /dev/null +++ b/src/Handler/HandlerAbstract.php @@ -0,0 +1,45 @@ +provider = $provider; + } +} \ No newline at end of file diff --git a/src/Handler/Ru.php b/src/Handler/Ru.php new file mode 100644 index 00000000..4c7ced6f --- /dev/null +++ b/src/Handler/Ru.php @@ -0,0 +1,38 @@ +setProvider(new WhoisServer()); + } + + public function parse() + { + return 'Parsing stub'; + } +} \ No newline at end of file diff --git a/src/HandlerMap.php b/src/HandlerMap.php new file mode 100644 index 00000000..1527cd93 --- /dev/null +++ b/src/HandlerMap.php @@ -0,0 +1,77 @@ + Handler\Ru::class, +// TODO: su is utf8 as well +// TODO: ru.com is a different registrar (Available with centralnic) +// '/^(?:[a-z0-9\-]+?\.){1,2}ru$/i' => Handler\Registrar\NicRu::class, +// '/^(?:[a-z0-9\-]+?\.){1,2}su$/i' => Handler\Registrar\NicRu::class, +// '/^(?:[a-z0-9\-]+?\.){1}ru\.net$/i' => Handler\Registrar\NicRu::class, +// '/^(?:[a-z0-9\-]+?\.){1}\.moscow$/i' => Handler\Registrar\NicRu::class, + ]; + + protected static function getMap() + { + return self::$map; + } + + /** + * Check if domain handler exists in mapping table + * + * @param string $domain + * @return bool + */ + public static function mappingExists($domain = '') + { + return $domain && is_string($domain) && array_key_exists($domain, self::getMap()); + } + + /** + * @param string $domain + * @return Handler\HandlerAbstract|false + */ + public static function getHandler($domain = '') + { + if (self::mappingExists($domain)) { + $map = self::getMap(); + return new $map[$domain]; + } + /** + * TODO: Try whois.nic.$tld, etc + */ + return false; + } +} \ No newline at end of file diff --git a/src/IpTools.php b/src/IpTools.php index 301c4aa9..0b01fc90 100644 --- a/src/IpTools.php +++ b/src/IpTools.php @@ -38,24 +38,21 @@ class IpTools * * @return boolean True if ip is valid. False otherwise */ - public function validIp($ip, $type = 'any', $strict = true) + public static function validIp($ip, $type = 'any', $strict = true) { switch ($type) { case 'any': - return $this->validIpv4($ip, $strict) || $this->validIpv6($ip, $strict); - break; + return self::validIpv4($ip, $strict) || self::validIpv6($ip, $strict); case 'ipv4': - return $this->validIpv4($ip, $strict); - break; + return self::validIpv4($ip, $strict); case 'ipv6': - return $this->validIpv6($ip, $strict); - break; + return self::validIpv6($ip, $strict); } return false; } /** - * Check if given IP is valid ipv4 address and doesn't belong to private and + * Check if given IP is a valid ipv4 address and doesn't belong to private and * reserved ranges * * @param string $ip Ip address @@ -63,7 +60,7 @@ public function validIp($ip, $type = 'any', $strict = true) * * @return boolean */ - public function validIpv4($ip, $strict = true) + public static function validIpv4($ip, $strict = true) { $flags = FILTER_FLAG_IPV4; if ($strict) { @@ -77,14 +74,14 @@ public function validIpv4($ip, $strict = true) } /** - * Check if given IP is valid ipv6 address and doesn't belong to private ranges + * Check if given IP is a valid ipv6 address and doesn't belong to private ranges * * @param string $ip Ip address * @param boolean $strict If true - fail validation on reserved and private ip ranges * * @return boolean */ - public function validIpv6($ip, $strict = true) + public static function validIpv6($ip, $strict = true) { $flags = FILTER_FLAG_IPV6; if ($strict) { @@ -98,40 +95,6 @@ public function validIpv6($ip, $strict = true) return false; } - /** - * Try to get real IP from client web request - * - * @return string - */ - public function getClientIp() - { - if (!empty($_SERVER['HTTP_CLIENT_IP']) && $this->validIp($_SERVER['HTTP_CLIENT_IP'])) { - return $_SERVER['HTTP_CLIENT_IP']; - } - - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { - foreach (explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']) as $ip) { - if ($this->validIp(trim($ip))) { - return trim($ip); - } - } - } - - if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validIp($_SERVER['HTTP_X_FORWARDED'])) { - return $_SERVER['HTTP_X_FORWARDED']; - } - - if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validIp($_SERVER['HTTP_FORWARDED_FOR'])) { - return $_SERVER['HTTP_FORWARDED_FOR']; - } - - if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validIp($_SERVER['HTTP_FORWARDED'])) { - return $_SERVER['HTTP_FORWARDED']; - } - - return $_SERVER['REMOTE_ADDR']; - } - /** * Convert CIDR to net range * @@ -140,7 +103,7 @@ public function getClientIp() * @param string $net * @return string */ - public function cidrConv($net) + public static function cidrConv($net) { $start = strtok($net, '/'); $n = 3 - substr_count($net, '.'); diff --git a/src/Parser/ParserA.php b/src/Parser/ParserA.php new file mode 100644 index 00000000..f661e199 --- /dev/null +++ b/src/Parser/ParserA.php @@ -0,0 +1,7 @@ +address if missing + * @return mixed + */ + abstract function lookup($address); + + /** + * @string $address Address to lookup + * @return mixed + */ + public function setAddress($address) + { + $this->address = $address; + return $this; + } + + abstract protected function setQuery(Query $query); +} \ No newline at end of file diff --git a/src/Provider/WhoisServer.php b/src/Provider/WhoisServer.php new file mode 100644 index 00000000..ef52fb4e --- /dev/null +++ b/src/Provider/WhoisServer.php @@ -0,0 +1,36 @@ +setAddress($address); + } + return true; + } +} \ No newline at end of file diff --git a/src/Query.php b/src/Query.php new file mode 100644 index 00000000..917a5c2a --- /dev/null +++ b/src/Query.php @@ -0,0 +1,65 @@ + tags diff --git a/src/Whois.php b/src/Whois.php index b58604d6..313e5bf6 100644 --- a/src/Whois.php +++ b/src/Whois.php @@ -17,320 +17,77 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * @link http://phpwhois.pw - * @copyright Copyright (C)1999,2005 easyDNS Technologies Inc. & Mark Jeftovic - * @copyright Maintained by David Saez - * @copyright Copyright (c) 2014 Dmitry Lukashin + * @copyright Copyright (c) 2015 Dmitry Lukashin */ namespace phpWhois; + /** * phpWhois main class * * This class supposed to be instantiated for using the phpWhois library */ -class Whois extends WhoisClient +class Whois { - - /** @var boolean Deep whois? */ - public $deepWhois = true; - - /** @inheritdoc */ - public $gtldRecurse = true; - - /** @var array Query array */ - public $query = array(); - - /** @var string Network Solutions registry server */ - public $nsiRegistry = 'whois.nsiregistry.net'; - - const QTYPE_UNKNOWN = 0; - const QTYPE_DOMAIN = 1; - const QTYPE_IPV4 = 2; - const QTYPE_IPV6 = 3; - const QTYPE_AS = 4; + /** + * @var \phpWhois\Handler\HandlerAbstract Handler for obtaining address whois information + */ + protected $handler; /** - * Use special whois server (Populate WHOIS_SPECIAL array) - * - * @param string $tld Top-level domain - * @param string $server Server address + * @var string Address to lookup */ - public function useServer($tld, $server) - { - $this->WHOIS_SPECIAL[$tld] = $server; - } + protected $address; /** - * Lookup query - * - * @param string $query Domain name or other entity - * @param boolean $is_utf True if domain name encoding is utf-8 already, otherwise convert it with utf8_encode() first - * + * @param string $address + * @return $this + * @throws \InvalidArgumentException if address is empty */ - public function lookup($query = '', $is_utf = true) + public function setAddress($address = '') { - // start clean - $this->query = array('status' => ''); - - $query = trim($query); - - $idn = new \idna_convert(); - - if ($is_utf) { - $query = $idn->encode($query); + if ($address && is_string($address)) { + $this->address = $address; } else { - $query = $idn->encode(utf8_encode($query)); - } - - // If domain to query was not set - if (!isset($query) || $query == '') { - // Configure to use default whois server - $this->query['server'] = $this->nsiRegistry; - return; - } - - // Set domain to query in query array - $this->query['query'] = $domain = $query = strtolower($query); - - // Find a query type - $qType = $this->getQueryType($query); - - switch ($qType) { - case self::QTYPE_IPV4: - // IPv4 Prepare to do lookup via the 'ip' handler - $ip = @gethostbyname($query); - - if (isset($this->WHOIS_SPECIAL['ip'])) { - $this->query['server'] = $this->WHOIS_SPECIAL['ip']; - $this->query['args'] = $ip; - } else { - $this->query['server'] = 'whois.arin.net'; - $this->query['args'] = "n $ip"; - $this->query['file'] = 'whois.ip.php'; - $this->query['handler'] = 'ip'; - } - $this->query['host_ip'] = $ip; - $this->query['query'] = $ip; - $this->query['tld'] = 'ip'; - $this->query['host_name'] = @gethostbyaddr($ip); - - return $this->getData('', $this->deepWhois); - break; - - case self::QTYPE_IPV6: - // IPv6 AS Prepare to do lookup via the 'ip' handler - $ip = @gethostbyname($query); - - if (isset($this->WHOIS_SPECIAL['ip'])) { - $this->query['server'] = $this->WHOIS_SPECIAL['ip']; - } else { - $this->query['server'] = 'whois.ripe.net'; - $this->query['file'] = 'whois.ip.ripe.php'; - $this->query['handler'] = 'ripe'; - } - $this->query['query'] = $ip; - $this->query['tld'] = 'ip'; - return $this->getData('', $this->deepWhois); - break; - - case self::QTYPE_AS: - // AS Prepare to do lookup via the 'ip' handler - $ip = @gethostbyname($query); - $this->query['server'] = 'whois.arin.net'; - if (strtolower(substr($ip, 0, 2)) == 'as') { - $as = substr($ip, 2); - } else { - $as = $ip; - } - $this->query['args'] = "a $as"; - $this->query['file'] = 'whois.ip.php'; - $this->query['handler'] = 'ip'; - $this->query['query'] = $ip; - $this->query['tld'] = 'as'; - return $this->getData('', $this->deepWhois); - break; - } - - // Build array of all possible tld's for that domain - $tld = ''; - $server = ''; - $dp = explode('.', $domain); - $np = count($dp) - 1; - $tldtests = array(); - - for ($i = 0; $i < $np; $i++) { - array_shift($dp); - $tldtests[] = implode('.', $dp); - } - - // Search the correct whois server - $special_tlds = $this->WHOIS_SPECIAL; - - foreach ($tldtests as $tld) { - // Test if we know in advance that no whois server is - // available for this domain and that we can get the - // data via http or whois request - if (isset($special_tlds[$tld])) { - $val = $special_tlds[$tld]; - - if ($val == '') { - return $this->unknown(); - } - - $domain = substr($query, 0, -strlen($tld) - 1); - $val = str_replace('{domain}', $domain, $val); - $server = str_replace('{tld}', $tld, $val); - break; - } - } - - if ($server == '') { - foreach ($tldtests as $tld) { - // Determine the top level domain, and it's whois server using - // DNS lookups on 'whois-servers.net'. - // Assumes a valid DNS response indicates a recognised tld (!?) - $cname = $tld . '.whois-servers.net'; - - if (gethostbyname($cname) == $cname) { - continue; - } - $server = $tld . '.whois-servers.net'; - break; - } - } - - if ($tld && $server) { - // If found, set tld and whois server in query array - $this->query['server'] = $server; - $this->query['tld'] = $tld; - $handler = ''; - - foreach ($tldtests as $htld) { - // special handler exists for the tld ? - if (isset($this->DATA[$htld])) { - $handler = $this->DATA[$htld]; - break; - } - - // Regular handler exists for the tld ? - if (file_exists('whois.' . $htld . '.php')) { - $handler = $htld; - break; - } - } - - // If there is a handler set it - if ($handler != '') { - $this->query['file'] = "whois.$handler.php"; - $this->query['handler'] = $handler; - } - - // Special parameters ? - if (isset($this->WHOIS_PARAM[$server])) { - $this->query['server'] = $this->query['server'] . '?' . str_replace('$', $domain, - $this->WHOIS_PARAM[$server]); - } - - $result = $this->getData('', $this->deepWhois); - $this->checkDns($result); - return $result; + throw new \InvalidArgumentException('Address cannot be empty'); } - - // If tld not known, and domain not in DNS, return error - return $this->unknown(); + return $this; } /** - * Unsupported domains + * @return string|null */ - public function unknown() + public function getAddress() { - unset($this->query['server']); - $this->query['status'] = 'error'; - $result = array('rawdata' => array()); - $result['rawdata'][] = $this->query['errstr'][] = $this->query['query'] . ' domain is not supported'; - $this->checkDns($result); - $this->fixResult($result, $this->query['query']); - return $result; + return $this->address; } /** - * Get nameservers if missing + * @param Handler\HandlerAbstract $handler Handler for obtaining address whois information */ - public function checkDns(&$result) + public function setHandler(\phpWhois\Handler\HandlerAbstract $handler) { - if ($this->deepWhois && empty($result['regrinfo']['domain']['nserver'])) { - $ns = @dns_get_record($this->query['query'], DNS_NS); - if (!is_array($ns)) { - return; - } - $nserver = array(); - foreach ($ns as $row) { - $nserver[] = $row['target']; - } - if (count($nserver) > 0) { - $result['regrinfo']['domain']['nserver'] = $this->fixNameServer($nserver); - } - } + $this->handler = $handler; } /** - * Fix and/or add name server information + * @param string $address + * @return mixed + * @throws \InvalidArgumentException if address is empty */ - public function fixResult(&$result, $domain) + public function lookup($address = '') { - // Add usual fields - $result['regrinfo']['domain']['name'] = $domain; - - // Check if nameservers exist - if (!isset($result['regrinfo']['registered'])) { - if (function_exists('checkdnsrr') && checkdnsrr($domain, 'NS')) { - $result['regrinfo']['registered'] = 'yes'; - } else { - $result['regrinfo']['registered'] = 'unknown'; - } + if ($address) { + $this->setAddress($address); } - // Normalize nameserver fields - if (isset($result['regrinfo']['domain']['nserver'])) { - if (!is_array($result['regrinfo']['domain']['nserver'])) { - unset($result['regrinfo']['domain']['nserver']); - } else { - $result['regrinfo']['domain']['nserver'] = $this->fixNameServer($result['regrinfo']['domain']['nserver']); - } + if (!($address = $this->getAddress())) { + throw new \InvalidArgumentException('Address cannot be empty'); } - } - /** - * Guess query type - * - * @param string $query - * - * @return int Query type - */ - public function getQueryType($query) - { - $ipTools = new IpTools; - - if ($ipTools->validIp($query, 'ipv4', false)) { - if ($ipTools->validIp($query, 'ipv4')) { - return self::QTYPE_IPV4; - } else { - return self::QTYPE_UNKNOWN; - } - } elseif ($ipTools->validIp($query, 'ipv6', false)) { - if ($ipTools->validIp($query, 'ipv6')) { - return self::QTYPE_IPV6; - } else { - return self::QTYPE_UNKNOWN; - } - } elseif (!empty($query) && strpos($query, '.') !== false) { - return self::QTYPE_DOMAIN; - } elseif (!empty($query) && strpos($query, '.') === false) { - return self::QTYPE_AS; - } else { - return self::QTYPE_UNKNOWN; - } + $handler = HandlerMap::getHandler($address); + $this->setHandler($handler); + return $this->handler->parse(); } -} +} \ No newline at end of file diff --git a/src/WhoisClient.php b/src/WhoisClient.php index f378d38a..af83b10b 100644 --- a/src/WhoisClient.php +++ b/src/WhoisClient.php @@ -152,13 +152,12 @@ public function getRawData($query) $query_args = str_replace('{query}', $query, $query_args); $query_args = str_replace('{version}', 'phpWhois' . $this->codeVersion, $query_args); - $iptools = new IpTools; if (strpos($query_args, '{ip}') !== false) { - $query_args = str_replace('{ip}', $iptools->getClientIp(), $query_args); + $query_args = str_replace('{ip}', IpTools::getClientIp(), $query_args); } if (strpos($query_args, '{hname}') !== false) { - $query_args = str_replace('{hname}', gethostbyaddr($iptools->getClientIp()), $query_args); + $query_args = str_replace('{hname}', gethostbyaddr(IpTools::getClientIp()), $query_args); } } else { if (empty($this->query['args'])) { @@ -656,8 +655,7 @@ public function parseServer($server) $server = trim($server); $server = preg_replace('/\/$/', '', $server); - $ipTools = new IpTools; - if ($ipTools->validIpv6($server)) { + if (IpTools::validIpv6($server)) { $result = array('host' => "[$server]"); } else { $parsed = parse_url($server); diff --git a/src/Whois_Old.php b/src/Whois_Old.php new file mode 100644 index 00000000..d76f0e31 --- /dev/null +++ b/src/Whois_Old.php @@ -0,0 +1,334 @@ +WHOIS_SPECIAL[$tld] = $server; + } + + /** + * Lookup query + * + * @param string $query Domain name or other entity + * @param boolean $is_utf True if domain name encoding is utf-8 already, otherwise convert it with utf8_encode() first + * + */ + public function lookup($query = '', $is_utf = true) + { + // start clean + $this->query = array('status' => ''); + + $query = trim($query); + + $idn = new \idna_convert(); + + if ($is_utf) { + $query = $idn->encode($query); + } else { + $query = $idn->encode(utf8_encode($query)); + } + + // If domain to query was not set + if (!isset($query) || $query == '') { + // Configure to use default whois server + $this->query['server'] = $this->nsiRegistry; + return; + } + + // Set domain to query in query array + $this->query['query'] = $domain = $query = strtolower($query); + + // Find a query type + $qType = $this->getQueryType($query); + + switch ($qType) { + case self::QTYPE_IPV4: + // IPv4 Prepare to do lookup via the 'ip' handler + $ip = @gethostbyname($query); + + if (isset($this->WHOIS_SPECIAL['ip'])) { + $this->query['server'] = $this->WHOIS_SPECIAL['ip']; + $this->query['args'] = $ip; + } else { + $this->query['server'] = 'whois.arin.net'; + $this->query['args'] = "n $ip"; + $this->query['file'] = 'whois.ip.php'; + $this->query['handler'] = 'ip'; + } + $this->query['host_ip'] = $ip; + $this->query['query'] = $ip; + $this->query['tld'] = 'ip'; + $this->query['host_name'] = @gethostbyaddr($ip); + + return $this->getData('', $this->deepWhois); + break; + + case self::QTYPE_IPV6: + // IPv6 AS Prepare to do lookup via the 'ip' handler + $ip = @gethostbyname($query); + + if (isset($this->WHOIS_SPECIAL['ip'])) { + $this->query['server'] = $this->WHOIS_SPECIAL['ip']; + } else { + $this->query['server'] = 'whois.ripe.net'; + $this->query['file'] = 'whois.ip.ripe.php'; + $this->query['handler'] = 'ripe'; + } + $this->query['query'] = $ip; + $this->query['tld'] = 'ip'; + return $this->getData('', $this->deepWhois); + break; + + case self::QTYPE_AS: + // AS Prepare to do lookup via the 'ip' handler + $ip = @gethostbyname($query); + $this->query['server'] = 'whois.arin.net'; + if (strtolower(substr($ip, 0, 2)) == 'as') { + $as = substr($ip, 2); + } else { + $as = $ip; + } + $this->query['args'] = "a $as"; + $this->query['file'] = 'whois.ip.php'; + $this->query['handler'] = 'ip'; + $this->query['query'] = $ip; + $this->query['tld'] = 'as'; + return $this->getData('', $this->deepWhois); + break; + } + + // Build array of all possible tld's for that domain + $tld = ''; + $server = ''; + $dp = explode('.', $domain); + $np = count($dp) - 1; + $tldtests = array(); + + for ($i = 0; $i < $np; $i++) { + array_shift($dp); + $tldtests[] = implode('.', $dp); + } + + // Search the correct whois server + $special_tlds = $this->WHOIS_SPECIAL; + + foreach ($tldtests as $tld) { + // Test if we know in advance that no whois server is + // available for this domain and that we can get the + // data via http or whois request + if (isset($special_tlds[$tld])) { + $val = $special_tlds[$tld]; + + if ($val == '') { + return $this->unknown(); + } + + $domain = substr($query, 0, -strlen($tld) - 1); + $val = str_replace('{domain}', $domain, $val); + $server = str_replace('{tld}', $tld, $val); + break; + } + } + + if ($server == '') { + foreach ($tldtests as $tld) { + // Determine the top level domain, and it's whois server using + // DNS lookups on 'whois-servers.net'. + // Assumes a valid DNS response indicates a recognised tld (!?) + $cname = $tld . '.whois-servers.net'; + + if (gethostbyname($cname) == $cname) { + continue; + } + $server = $tld . '.whois-servers.net'; + break; + } + } + + if ($tld && $server) { + // If found, set tld and whois server in query array + $this->query['server'] = $server; + $this->query['tld'] = $tld; + $handler = ''; + + foreach ($tldtests as $htld) { + // special handler exists for the tld ? + if (isset($this->DATA[$htld])) { + $handler = $this->DATA[$htld]; + break; + } + + // Regular handler exists for the tld ? + if (file_exists('whois.' . $htld . '.php')) { + $handler = $htld; + break; + } + } + + // If there is a handler set it + if ($handler != '') { + $this->query['file'] = "whois.$handler.php"; + $this->query['handler'] = $handler; + } + + // Special parameters ? + if (isset($this->WHOIS_PARAM[$server])) { + $this->query['server'] = $this->query['server'] . '?' . str_replace('$', $domain, + $this->WHOIS_PARAM[$server]); + } + + $result = $this->getData('', $this->deepWhois); + $this->checkDns($result); + return $result; + } + + // If tld not known, and domain not in DNS, return error + return $this->unknown(); + } + + /** + * Unsupported domains + */ + public function unknown() + { + unset($this->query['server']); + $this->query['status'] = 'error'; + $result = array('rawdata' => array()); + $result['rawdata'][] = $this->query['errstr'][] = $this->query['query'] . ' domain is not supported'; + $this->checkDns($result); + $this->fixResult($result, $this->query['query']); + return $result; + } + + /** + * Get nameservers if missing + */ + public function checkDns(&$result) + { + if ($this->deepWhois && empty($result['regrinfo']['domain']['nserver'])) { + $ns = @dns_get_record($this->query['query'], DNS_NS); + if (!is_array($ns)) { + return; + } + $nserver = array(); + foreach ($ns as $row) { + $nserver[] = $row['target']; + } + if (count($nserver) > 0) { + $result['regrinfo']['domain']['nserver'] = $this->fixNameServer($nserver); + } + } + } + + /** + * Fix and/or add name server information + */ + public function fixResult(&$result, $domain) + { + // Add usual fields + $result['regrinfo']['domain']['name'] = $domain; + + // Check if nameservers exist + if (!isset($result['regrinfo']['registered'])) { + if (function_exists('checkdnsrr') && checkdnsrr($domain, 'NS')) { + $result['regrinfo']['registered'] = 'yes'; + } else { + $result['regrinfo']['registered'] = 'unknown'; + } + } + + // Normalize nameserver fields + if (isset($result['regrinfo']['domain']['nserver'])) { + if (!is_array($result['regrinfo']['domain']['nserver'])) { + unset($result['regrinfo']['domain']['nserver']); + } else { + $result['regrinfo']['domain']['nserver'] = $this->fixNameServer($result['regrinfo']['domain']['nserver']); + } + } + } + + /** + * Guess query type + * + * @param string $query + * + * @return int Query type + */ + public function getQueryType($query) + { + if (IpTools::validIp($query, 'ipv4', false)) { + if (IpTools::validIp($query, 'ipv4')) { + return self::QTYPE_IPV4; + } else { + return self::QTYPE_UNKNOWN; + } + } elseif (IpTools::validIp($query, 'ipv6', false)) { + if (IpTools::validIp($query, 'ipv6')) { + return self::QTYPE_IPV6; + } else { + return self::QTYPE_UNKNOWN; + } + } elseif (!empty($query) && strpos($query, '.') !== false) { + return self::QTYPE_DOMAIN; + } elseif (!empty($query) && strpos($query, '.') === false) { + return self::QTYPE_AS; + } else { + return self::QTYPE_UNKNOWN; + } + } +} diff --git a/src/whois.gtld.php b/src/old/extends/whois.gtld.php similarity index 100% rename from src/whois.gtld.php rename to src/old/extends/whois.gtld.php diff --git a/src/whois.ip.php b/src/old/extends/whois.ip.php similarity index 100% rename from src/whois.ip.php rename to src/old/extends/whois.ip.php diff --git a/src/whois.jp.php b/src/old/extends/whois.jp.php similarity index 100% rename from src/whois.jp.php rename to src/old/extends/whois.jp.php diff --git a/src/whois.ws.php b/src/old/extends/whois.ws.php similarity index 100% rename from src/whois.ws.php rename to src/old/extends/whois.ws.php diff --git a/src/whois.gtld.afternic.php b/src/old/gtld/whois.gtld.afternic.php similarity index 100% rename from src/whois.gtld.afternic.php rename to src/old/gtld/whois.gtld.afternic.php diff --git a/src/whois.gtld.alldomains.php b/src/old/gtld/whois.gtld.alldomains.php similarity index 100% rename from src/whois.gtld.alldomains.php rename to src/old/gtld/whois.gtld.alldomains.php diff --git a/src/whois.gtld.ascio.php b/src/old/gtld/whois.gtld.ascio.php similarity index 100% rename from src/whois.gtld.ascio.php rename to src/old/gtld/whois.gtld.ascio.php diff --git a/src/whois.gtld.assorted.php b/src/old/gtld/whois.gtld.assorted.php similarity index 100% rename from src/whois.gtld.assorted.php rename to src/old/gtld/whois.gtld.assorted.php diff --git a/src/whois.gtld.corporatedomains.php b/src/old/gtld/whois.gtld.corporatedomains.php similarity index 100% rename from src/whois.gtld.corporatedomains.php rename to src/old/gtld/whois.gtld.corporatedomains.php diff --git a/src/whois.gtld.directnic.php b/src/old/gtld/whois.gtld.directnic.php similarity index 100% rename from src/whois.gtld.directnic.php rename to src/old/gtld/whois.gtld.directnic.php diff --git a/src/whois.gtld.domaindiscover.php b/src/old/gtld/whois.gtld.domaindiscover.php similarity index 100% rename from src/whois.gtld.domaindiscover.php rename to src/old/gtld/whois.gtld.domaindiscover.php diff --git a/src/whois.gtld.domainpeople.php b/src/old/gtld/whois.gtld.domainpeople.php similarity index 100% rename from src/whois.gtld.domainpeople.php rename to src/old/gtld/whois.gtld.domainpeople.php diff --git a/src/whois.gtld.dotster.php b/src/old/gtld/whois.gtld.dotster.php similarity index 100% rename from src/whois.gtld.dotster.php rename to src/old/gtld/whois.gtld.dotster.php diff --git a/src/whois.gtld.dreamhost.php b/src/old/gtld/whois.gtld.dreamhost.php similarity index 100% rename from src/whois.gtld.dreamhost.php rename to src/old/gtld/whois.gtld.dreamhost.php diff --git a/src/whois.gtld.enom.php b/src/old/gtld/whois.gtld.enom.php similarity index 100% rename from src/whois.gtld.enom.php rename to src/old/gtld/whois.gtld.enom.php diff --git a/src/whois.gtld.fabulous.php b/src/old/gtld/whois.gtld.fabulous.php similarity index 100% rename from src/whois.gtld.fabulous.php rename to src/old/gtld/whois.gtld.fabulous.php diff --git a/src/whois.gtld.fastdomain.php b/src/old/gtld/whois.gtld.fastdomain.php similarity index 100% rename from src/whois.gtld.fastdomain.php rename to src/old/gtld/whois.gtld.fastdomain.php diff --git a/src/whois.gtld.gandi.php b/src/old/gtld/whois.gtld.gandi.php similarity index 100% rename from src/whois.gtld.gandi.php rename to src/old/gtld/whois.gtld.gandi.php diff --git a/src/whois.gtld.genericb.php b/src/old/gtld/whois.gtld.genericb.php similarity index 100% rename from src/whois.gtld.genericb.php rename to src/old/gtld/whois.gtld.genericb.php diff --git a/src/whois.gtld.godaddy.php b/src/old/gtld/whois.gtld.godaddy.php similarity index 100% rename from src/whois.gtld.godaddy.php rename to src/old/gtld/whois.gtld.godaddy.php diff --git a/src/whois.gtld.iana.php b/src/old/gtld/whois.gtld.iana.php similarity index 100% rename from src/whois.gtld.iana.php rename to src/old/gtld/whois.gtld.iana.php diff --git a/src/whois.gtld.interdomain.php b/src/old/gtld/whois.gtld.interdomain.php similarity index 100% rename from src/whois.gtld.interdomain.php rename to src/old/gtld/whois.gtld.interdomain.php diff --git a/src/whois.gtld.itsyourdomain.php b/src/old/gtld/whois.gtld.itsyourdomain.php similarity index 100% rename from src/whois.gtld.itsyourdomain.php rename to src/old/gtld/whois.gtld.itsyourdomain.php diff --git a/src/whois.gtld.joker.php b/src/old/gtld/whois.gtld.joker.php similarity index 100% rename from src/whois.gtld.joker.php rename to src/old/gtld/whois.gtld.joker.php diff --git a/src/whois.gtld.markmonitor.php b/src/old/gtld/whois.gtld.markmonitor.php similarity index 100% rename from src/whois.gtld.markmonitor.php rename to src/old/gtld/whois.gtld.markmonitor.php diff --git a/src/whois.gtld.melbourneit.php b/src/old/gtld/whois.gtld.melbourneit.php similarity index 100% rename from src/whois.gtld.melbourneit.php rename to src/old/gtld/whois.gtld.melbourneit.php diff --git a/src/whois.gtld.moniker.php b/src/old/gtld/whois.gtld.moniker.php similarity index 100% rename from src/whois.gtld.moniker.php rename to src/old/gtld/whois.gtld.moniker.php diff --git a/src/whois.gtld.name.php b/src/old/gtld/whois.gtld.name.php similarity index 100% rename from src/whois.gtld.name.php rename to src/old/gtld/whois.gtld.name.php diff --git a/src/whois.gtld.nameintel.php b/src/old/gtld/whois.gtld.nameintel.php similarity index 100% rename from src/whois.gtld.nameintel.php rename to src/old/gtld/whois.gtld.nameintel.php diff --git a/src/whois.gtld.namejuice.php b/src/old/gtld/whois.gtld.namejuice.php similarity index 100% rename from src/whois.gtld.namejuice.php rename to src/old/gtld/whois.gtld.namejuice.php diff --git a/src/whois.gtld.nameking.php b/src/old/gtld/whois.gtld.nameking.php similarity index 100% rename from src/whois.gtld.nameking.php rename to src/old/gtld/whois.gtld.nameking.php diff --git a/src/whois.gtld.names4ever.php b/src/old/gtld/whois.gtld.names4ever.php similarity index 100% rename from src/whois.gtld.names4ever.php rename to src/old/gtld/whois.gtld.names4ever.php diff --git a/src/whois.gtld.namevault.php b/src/old/gtld/whois.gtld.namevault.php similarity index 100% rename from src/whois.gtld.namevault.php rename to src/old/gtld/whois.gtld.namevault.php diff --git a/src/whois.gtld.networksolutions.php b/src/old/gtld/whois.gtld.networksolutions.php similarity index 100% rename from src/whois.gtld.networksolutions.php rename to src/old/gtld/whois.gtld.networksolutions.php diff --git a/src/whois.gtld.nicco.php b/src/old/gtld/whois.gtld.nicco.php similarity index 100% rename from src/whois.gtld.nicco.php rename to src/old/gtld/whois.gtld.nicco.php diff --git a/src/whois.gtld.nicline.php b/src/old/gtld/whois.gtld.nicline.php similarity index 100% rename from src/whois.gtld.nicline.php rename to src/old/gtld/whois.gtld.nicline.php diff --git a/src/whois.gtld.onlinenic.php b/src/old/gtld/whois.gtld.onlinenic.php similarity index 100% rename from src/whois.gtld.onlinenic.php rename to src/old/gtld/whois.gtld.onlinenic.php diff --git a/src/whois.gtld.opensrs.php b/src/old/gtld/whois.gtld.opensrs.php similarity index 100% rename from src/whois.gtld.opensrs.php rename to src/old/gtld/whois.gtld.opensrs.php diff --git a/src/whois.gtld.ovh.php b/src/old/gtld/whois.gtld.ovh.php similarity index 100% rename from src/whois.gtld.ovh.php rename to src/old/gtld/whois.gtld.ovh.php diff --git a/src/whois.gtld.psiusa.php b/src/old/gtld/whois.gtld.psiusa.php similarity index 100% rename from src/whois.gtld.psiusa.php rename to src/old/gtld/whois.gtld.psiusa.php diff --git a/src/whois.gtld.publicdomainregistry.php b/src/old/gtld/whois.gtld.publicdomainregistry.php similarity index 100% rename from src/whois.gtld.publicdomainregistry.php rename to src/old/gtld/whois.gtld.publicdomainregistry.php diff --git a/src/whois.gtld.register.php b/src/old/gtld/whois.gtld.register.php similarity index 100% rename from src/whois.gtld.register.php rename to src/old/gtld/whois.gtld.register.php diff --git a/src/whois.gtld.rrpproxy.php b/src/old/gtld/whois.gtld.rrpproxy.php similarity index 100% rename from src/whois.gtld.rrpproxy.php rename to src/old/gtld/whois.gtld.rrpproxy.php diff --git a/src/whois.gtld.schlund.php b/src/old/gtld/whois.gtld.schlund.php similarity index 100% rename from src/whois.gtld.schlund.php rename to src/old/gtld/whois.gtld.schlund.php diff --git a/src/whois.gtld.srsplus.php b/src/old/gtld/whois.gtld.srsplus.php similarity index 100% rename from src/whois.gtld.srsplus.php rename to src/old/gtld/whois.gtld.srsplus.php diff --git a/src/whois.gtld.tmagnic.php b/src/old/gtld/whois.gtld.tmagnic.php similarity index 100% rename from src/whois.gtld.tmagnic.php rename to src/old/gtld/whois.gtld.tmagnic.php diff --git a/src/whois.gtld.tvcorp.php b/src/old/gtld/whois.gtld.tvcorp.php similarity index 100% rename from src/whois.gtld.tvcorp.php rename to src/old/gtld/whois.gtld.tvcorp.php diff --git a/src/whois.gtld.wildwestdomains.php b/src/old/gtld/whois.gtld.wildwestdomains.php similarity index 100% rename from src/whois.gtld.wildwestdomains.php rename to src/old/gtld/whois.gtld.wildwestdomains.php diff --git a/src/whois.rwhois.php b/src/old/special/whois.rwhois.php similarity index 100% rename from src/whois.rwhois.php rename to src/old/special/whois.rwhois.php diff --git a/src/whois.ae.php b/src/old/whois.ae.php similarity index 100% rename from src/whois.ae.php rename to src/old/whois.ae.php diff --git a/src/whois.aero.php b/src/old/whois.aero.php similarity index 100% rename from src/whois.aero.php rename to src/old/whois.aero.php diff --git a/src/whois.ag.php b/src/old/whois.ag.php similarity index 100% rename from src/whois.ag.php rename to src/old/whois.ag.php diff --git a/src/whois.am.php b/src/old/whois.am.php similarity index 100% rename from src/whois.am.php rename to src/old/whois.am.php diff --git a/src/whois.asia.php b/src/old/whois.asia.php similarity index 100% rename from src/whois.asia.php rename to src/old/whois.asia.php diff --git a/src/whois.at.php b/src/old/whois.at.php similarity index 100% rename from src/whois.at.php rename to src/old/whois.at.php diff --git a/src/whois.au.php b/src/old/whois.au.php similarity index 100% rename from src/whois.au.php rename to src/old/whois.au.php diff --git a/src/whois.be.php b/src/old/whois.be.php similarity index 100% rename from src/whois.be.php rename to src/old/whois.be.php diff --git a/src/whois.bh.php b/src/old/whois.bh.php similarity index 100% rename from src/whois.bh.php rename to src/old/whois.bh.php diff --git a/src/whois.biz.php b/src/old/whois.biz.php similarity index 100% rename from src/whois.biz.php rename to src/old/whois.biz.php diff --git a/src/whois.br.php b/src/old/whois.br.php similarity index 100% rename from src/whois.br.php rename to src/old/whois.br.php diff --git a/src/whois.ca.php b/src/old/whois.ca.php similarity index 100% rename from src/whois.ca.php rename to src/old/whois.ca.php diff --git a/src/whois.cat.php b/src/old/whois.cat.php similarity index 100% rename from src/whois.cat.php rename to src/old/whois.cat.php diff --git a/src/whois.ch.php b/src/old/whois.ch.php similarity index 100% rename from src/whois.ch.php rename to src/old/whois.ch.php diff --git a/src/whois.cl.php b/src/old/whois.cl.php similarity index 100% rename from src/whois.cl.php rename to src/old/whois.cl.php diff --git a/src/whois.cn.php b/src/old/whois.cn.php similarity index 100% rename from src/whois.cn.php rename to src/old/whois.cn.php diff --git a/src/whois.co.php b/src/old/whois.co.php similarity index 100% rename from src/whois.co.php rename to src/old/whois.co.php diff --git a/src/whois.co.za.php b/src/old/whois.co.za.php similarity index 100% rename from src/whois.co.za.php rename to src/old/whois.co.za.php diff --git a/src/whois.coop.php b/src/old/whois.coop.php similarity index 100% rename from src/whois.coop.php rename to src/old/whois.coop.php diff --git a/src/whois.cz.php b/src/old/whois.cz.php similarity index 100% rename from src/whois.cz.php rename to src/old/whois.cz.php diff --git a/src/whois.de.php b/src/old/whois.de.php similarity index 100% rename from src/whois.de.php rename to src/old/whois.de.php diff --git a/src/whois.edu.php b/src/old/whois.edu.php similarity index 100% rename from src/whois.edu.php rename to src/old/whois.edu.php diff --git a/src/whois.eu.php b/src/old/whois.eu.php similarity index 100% rename from src/whois.eu.php rename to src/old/whois.eu.php diff --git a/src/whois.fi.php b/src/old/whois.fi.php similarity index 100% rename from src/whois.fi.php rename to src/old/whois.fi.php diff --git a/src/whois.fj.php b/src/old/whois.fj.php similarity index 100% rename from src/whois.fj.php rename to src/old/whois.fj.php diff --git a/src/whois.fm.php b/src/old/whois.fm.php similarity index 100% rename from src/whois.fm.php rename to src/old/whois.fm.php diff --git a/src/whois.fr.php b/src/old/whois.fr.php similarity index 100% rename from src/whois.fr.php rename to src/old/whois.fr.php diff --git a/src/whois.hu.php b/src/old/whois.hu.php similarity index 100% rename from src/whois.hu.php rename to src/old/whois.hu.php diff --git a/src/whois.ie.php b/src/old/whois.ie.php similarity index 100% rename from src/whois.ie.php rename to src/old/whois.ie.php diff --git a/src/whois.il.php b/src/old/whois.il.php similarity index 100% rename from src/whois.il.php rename to src/old/whois.il.php diff --git a/src/whois.in.php b/src/old/whois.in.php similarity index 100% rename from src/whois.in.php rename to src/old/whois.in.php diff --git a/src/whois.info.php b/src/old/whois.info.php similarity index 100% rename from src/whois.info.php rename to src/old/whois.info.php diff --git a/src/whois.int.php b/src/old/whois.int.php similarity index 100% rename from src/whois.int.php rename to src/old/whois.int.php diff --git a/src/whois.ip.afrinic.php b/src/old/whois.ip.afrinic.php similarity index 100% rename from src/whois.ip.afrinic.php rename to src/old/whois.ip.afrinic.php diff --git a/src/whois.ip.apnic.php b/src/old/whois.ip.apnic.php similarity index 100% rename from src/whois.ip.apnic.php rename to src/old/whois.ip.apnic.php diff --git a/src/whois.ip.arin.php b/src/old/whois.ip.arin.php similarity index 100% rename from src/whois.ip.arin.php rename to src/old/whois.ip.arin.php diff --git a/src/whois.ip.krnic.php b/src/old/whois.ip.krnic.php similarity index 100% rename from src/whois.ip.krnic.php rename to src/old/whois.ip.krnic.php diff --git a/src/whois.ip.lacnic.php b/src/old/whois.ip.lacnic.php similarity index 100% rename from src/whois.ip.lacnic.php rename to src/old/whois.ip.lacnic.php diff --git a/src/whois.ip.ripe.php b/src/old/whois.ip.ripe.php similarity index 100% rename from src/whois.ip.ripe.php rename to src/old/whois.ip.ripe.php diff --git a/src/whois.ir.php b/src/old/whois.ir.php similarity index 100% rename from src/whois.ir.php rename to src/old/whois.ir.php diff --git a/src/whois.is.php b/src/old/whois.is.php similarity index 100% rename from src/whois.is.php rename to src/old/whois.is.php diff --git a/src/whois.it.php b/src/old/whois.it.php similarity index 100% rename from src/whois.it.php rename to src/old/whois.it.php diff --git a/src/whois.lt.php b/src/old/whois.lt.php similarity index 100% rename from src/whois.lt.php rename to src/old/whois.lt.php diff --git a/src/whois.lu.php b/src/old/whois.lu.php similarity index 100% rename from src/whois.lu.php rename to src/old/whois.lu.php diff --git a/src/whois.ly.php b/src/old/whois.ly.php similarity index 100% rename from src/whois.ly.php rename to src/old/whois.ly.php diff --git a/src/whois.me.php b/src/old/whois.me.php similarity index 100% rename from src/whois.me.php rename to src/old/whois.me.php diff --git a/src/whois.mobi.php b/src/old/whois.mobi.php similarity index 100% rename from src/whois.mobi.php rename to src/old/whois.mobi.php diff --git a/src/whois.museum.php b/src/old/whois.museum.php similarity index 100% rename from src/whois.museum.php rename to src/old/whois.museum.php diff --git a/src/whois.mx.php b/src/old/whois.mx.php similarity index 100% rename from src/whois.mx.php rename to src/old/whois.mx.php diff --git a/src/whois.name.php b/src/old/whois.name.php similarity index 100% rename from src/whois.name.php rename to src/old/whois.name.php diff --git a/src/whois.nl.php b/src/old/whois.nl.php similarity index 100% rename from src/whois.nl.php rename to src/old/whois.nl.php diff --git a/src/whois.nu.php b/src/old/whois.nu.php similarity index 100% rename from src/whois.nu.php rename to src/old/whois.nu.php diff --git a/src/whois.nz.php b/src/old/whois.nz.php similarity index 100% rename from src/whois.nz.php rename to src/old/whois.nz.php diff --git a/src/whois.org.php b/src/old/whois.org.php similarity index 100% rename from src/whois.org.php rename to src/old/whois.org.php diff --git a/src/whois.org.za.php b/src/old/whois.org.za.php similarity index 100% rename from src/whois.org.za.php rename to src/old/whois.org.za.php diff --git a/src/whois.pl.php b/src/old/whois.pl.php similarity index 100% rename from src/whois.pl.php rename to src/old/whois.pl.php diff --git a/src/whois.pro.php b/src/old/whois.pro.php similarity index 100% rename from src/whois.pro.php rename to src/old/whois.pro.php diff --git a/src/whois.pt.php b/src/old/whois.pt.php similarity index 100% rename from src/whois.pt.php rename to src/old/whois.pt.php diff --git a/src/whois.ro.php b/src/old/whois.ro.php similarity index 100% rename from src/whois.ro.php rename to src/old/whois.ro.php diff --git a/src/whois.ru.php b/src/old/whois.ru.php similarity index 100% rename from src/whois.ru.php rename to src/old/whois.ru.php diff --git a/src/whois.sc.php b/src/old/whois.sc.php similarity index 100% rename from src/whois.sc.php rename to src/old/whois.sc.php diff --git a/src/whois.se.php b/src/old/whois.se.php similarity index 100% rename from src/whois.se.php rename to src/old/whois.se.php diff --git a/src/whois.si.php b/src/old/whois.si.php similarity index 100% rename from src/whois.si.php rename to src/old/whois.si.php diff --git a/src/whois.su.php b/src/old/whois.su.php similarity index 100% rename from src/whois.su.php rename to src/old/whois.su.php diff --git a/src/whois.tel.php b/src/old/whois.tel.php similarity index 100% rename from src/whois.tel.php rename to src/old/whois.tel.php diff --git a/src/whois.travel.php b/src/old/whois.travel.php similarity index 100% rename from src/whois.travel.php rename to src/old/whois.travel.php diff --git a/src/whois.uk.php b/src/old/whois.uk.php similarity index 100% rename from src/whois.uk.php rename to src/old/whois.uk.php diff --git a/src/whois.us.php b/src/old/whois.us.php similarity index 100% rename from src/whois.us.php rename to src/old/whois.us.php diff --git a/src/whois.ve.php b/src/old/whois.ve.php similarity index 100% rename from src/whois.ve.php rename to src/old/whois.ve.php diff --git a/src/whois.xxx.php b/src/old/whois.xxx.php similarity index 100% rename from src/whois.xxx.php rename to src/old/whois.xxx.php diff --git a/src/whois.zanet.php b/src/old/whois.zanet.php similarity index 100% rename from src/whois.zanet.php rename to src/old/whois.zanet.php diff --git a/test.php b/test.php new file mode 100644 index 00000000..bf0f2f07 --- /dev/null +++ b/test.php @@ -0,0 +1,22 @@ +setAddress(true) + ->lookup('ru'); + echo $a; +} catch (Exception $e) { + echo 'Error: '.$e->getMessage(); +} + +echo "Memory used: ".memory_get_usage()."\n"; + +echo "\n"; diff --git a/tests/IpToolsTest.php b/tests/IpToolsTest.php index c4cbabf8..23dddd96 100644 --- a/tests/IpToolsTest.php +++ b/tests/IpToolsTest.php @@ -9,8 +9,7 @@ class IpToolsTest extends \PHPUnit_Framework_TestCase */ public function testValidIp($ip) { - $ipTools = new IpTools; - $this->assertTrue($ipTools->validIp($ip)); + $this->assertTrue(IpTools::validIp($ip)); } public function validIpsProvider() @@ -26,8 +25,7 @@ public function validIpsProvider() */ public function testInvalidIp($ip) { - $ipTools = new IpTools; - $this->assertFalse($ipTools->validIp($ip)); + $this->assertFalse(IpTools::validIp($ip)); } public function invalidIpsProvider() diff --git a/tests/WhoisTest.php b/tests/WhoisTest.php index 3a34fe32..3cf93e7d 100644 --- a/tests/WhoisTest.php +++ b/tests/WhoisTest.php @@ -17,7 +17,7 @@ public function testWhois() public function testQtype($type, $domain) { $whois = new Whois; - $this->assertEquals($type, $whois->getQueryType($domain)); + $this->assertEquals($type, $whois->guessQueryType($domain)); } public function domainsProvider() diff --git a/testsuite.php b/testsuite.php old mode 100755 new mode 100644 From 9b6fd2ccf269af2bb63428c3a1ef0ca4d2b22fb4 Mon Sep 17 00:00:00 2001 From: Dmitry Lukashin Date: Sat, 19 Dec 2015 08:53:27 +0300 Subject: [PATCH 02/23] [WIP] setting Query and Handler in Whois class --- .travis.yml | 1 - composer.json | 5 +- src/{HandlerMap.php => DomainHandlerMap.php} | 40 ++--- src/Handler/HandlerAbstract.php | 2 +- src/Provider/ProviderAbstract.php | 7 +- src/Query.php | 121 ++++++++++++-- src/{IpTools.php => QueryUtils.php} | 61 +++---- src/Utils.php | 161 ------------------- src/Whois.php | 62 ++++--- src/WhoisClient.php | 8 +- test.php | 7 +- tests/DomainHandlerMapTest.php | 11 ++ tests/IpToolsTest.php | 44 ----- tests/QueryTest.php | 47 ++++++ tests/QueryUtilsTest.php | 84 ++++++++++ tests/WhoisClientTest.php | 52 +++--- tests/WhoisTest.php | 35 ---- 17 files changed, 382 insertions(+), 366 deletions(-) rename src/{HandlerMap.php => DomainHandlerMap.php} (71%) rename src/{IpTools.php => QueryUtils.php} (63%) delete mode 100644 src/Utils.php create mode 100644 tests/DomainHandlerMapTest.php delete mode 100644 tests/IpToolsTest.php create mode 100644 tests/QueryTest.php create mode 100644 tests/QueryUtilsTest.php delete mode 100644 tests/WhoisTest.php diff --git a/.travis.yml b/.travis.yml index 5a1f603e..656a4842 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.4 - 5.5 - 5.6 - 7 diff --git a/composer.json b/composer.json index 71c62d3d..fec13822 100644 --- a/composer.json +++ b/composer.json @@ -25,9 +25,12 @@ ], "minimum-stability": "dev", "require": { - "php": ">=5.4.0", + "php": ">=5.5.0", "mso/idna-convert": "*" }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, "suggest": { "lib-openssl": "*" }, diff --git a/src/HandlerMap.php b/src/DomainHandlerMap.php similarity index 71% rename from src/HandlerMap.php rename to src/DomainHandlerMap.php index 1527cd93..bb7152f6 100644 --- a/src/HandlerMap.php +++ b/src/DomainHandlerMap.php @@ -25,16 +25,16 @@ use phpWhois\Handler; -class HandlerMap +class DomainHandlerMap { /** * @var array Mappings from domain name to handler class */ protected static $map = [ /** - * TODO: Some domains should be bound to registrars handlers rather than to specific domains handlers + * TODO: Some domains should be bound to registrars handlers rather than to the specific domains handlers */ - 'ru' => Handler\Ru::class, + '/\.ru$/' => Handler\Ru::class, // TODO: su is utf8 as well // TODO: ru.com is a different registrar (Available with centralnic) // '/^(?:[a-z0-9\-]+?\.){1,2}ru$/i' => Handler\Registrar\NicRu::class, @@ -49,25 +49,29 @@ protected static function getMap() } /** - * Check if domain handler exists in mapping table + * Return handler class based on domain name analysis + * + * Step 1. Look for domain in predefined map + * Step 2. Look for whois server on standard addresses like whois.nic.TLD + * + * @param string|\phpWhois\Query $query * - * @param string $domain - * @return bool - */ - public static function mappingExists($domain = '') - { - return $domain && is_string($domain) && array_key_exists($domain, self::getMap()); - } - - /** - * @param string $domain * @return Handler\HandlerAbstract|false */ - public static function getHandler($domain = '') + public static function findHandler($query = null) { - if (self::mappingExists($domain)) { - $map = self::getMap(); - return new $map[$domain]; + if ($query instanceof \phpWhois\Query) { + $query = $query->getAddress(); + } + + if (!QueryUtils::validDomain($query)) { + return false; + } + + foreach (self::getMap() as $pattern => $class) { + if (preg_match($pattern, $query)) { + return new $class; + } } /** * TODO: Try whois.nic.$tld, etc diff --git a/src/Handler/HandlerAbstract.php b/src/Handler/HandlerAbstract.php index 1cf91fcc..655477be 100644 --- a/src/Handler/HandlerAbstract.php +++ b/src/Handler/HandlerAbstract.php @@ -38,7 +38,7 @@ abstract class HandlerAbstract * @param \phpWhois\Provider\ProviderAbstract $provider Whois info provider * @return mixed */ - public function setProvider(\phpWhois\Provider\ProviderAbstract $provider) + protected function setProvider(\phpWhois\Provider\ProviderAbstract $provider) { $this->provider = $provider; } diff --git a/src/Provider/ProviderAbstract.php b/src/Provider/ProviderAbstract.php index 700d721f..8942f186 100644 --- a/src/Provider/ProviderAbstract.php +++ b/src/Provider/ProviderAbstract.php @@ -4,6 +4,11 @@ use phpWhois\Query; +/** + * Abstract class Provider - defines the algorithms for communicating with various whois servers + * + * @package phpWhois\Provider + */ abstract class ProviderAbstract { /** * @var string Address to lookup @@ -29,5 +34,5 @@ public function setAddress($address) return $this; } - abstract protected function setQuery(Query $query); + //abstract protected function setQuery(Query $query); } \ No newline at end of file diff --git a/src/Query.php b/src/Query.php index 917a5c2a..75841d17 100644 --- a/src/Query.php +++ b/src/Query.php @@ -33,29 +33,130 @@ class Query const QTYPE_AS = 4; /** - * Guess query type + * @var int Query type (see constants) + */ + private $type; + + /** + * @var string Original address received + */ + private $addressOrig; + + /** + * @var string Address optimized for querying the whois server + */ + private $address; + + public function __construct($address = null) + { + if (!is_null($address)) { + $this->setAddress($address); + } + } + + /** + * Set address, make necessary checks and transformations + * + * @param string $address + * + * @return $this + * + * @throws \InvalidArgumentException if address is not recognized + */ + public function setAddress($address) + { + $type = $this->guessType($address); + + if ($type == self::QTYPE_UNKNOWN) { + throw new \InvalidArgumentException('Address is not recognized, can\'t find whois server'); + } else { + $this->setType($type); + } + + $this->setAddressOrig($address); + + $address = $this->optimizeAddress($address); + + $this->address = $address; + + return $this; + } + + public function getAddress() + { + return $this->address; + } + + private function setAddressOrig($address) + { + $this->addressOrig = $address; + } + + /** + * @return string Original unoptimized address + */ + public function getAddressOrig() + { + return $this->addressOrig; + } + + private function setType($type) + { + $this->type = $type; + } + + public function getType() + { + return $this->type; + } + + /** + * Find the type of a given address and make some optimizations like removing www. + * + * @param $address + * + * @return string optimized address + */ + public static function optimizeAddress($address) + { + $type = self::guessType($address); + // TODO: handle IDN + if ($type == self::QTYPE_DOMAIN) { + $address = strtolower($address); + + $address_nowww = preg_replace('/^www./', '', $address); + if (QueryUtils::validDomain($address_nowww)) { + $address = $address_nowww; + } + } + return $address; + } + + /** + * Guess address type * - * @param string $query + * @param string $query * - * @return int Query type + * @return int Query type */ - public static function guessQueryType($query) + public static function guessType($query) { - if (IpTools::validIp($query, 'ipv4', false)) { - if (IpTools::validIp($query, 'ipv4')) { + if (QueryUtils::validIp($query, 'ipv4', false)) { + if (QueryUtils::validIp($query, 'ipv4')) { return self::QTYPE_IPV4; } else { return self::QTYPE_UNKNOWN; } - } elseif (IpTools::validIp($query, 'ipv6', false)) { - if (IpTools::validIp($query, 'ipv6')) { + } elseif (QueryUtils::validIp($query, 'ipv6', false)) { + if (QueryUtils::validIp($query, 'ipv6')) { return self::QTYPE_IPV6; } else { return self::QTYPE_UNKNOWN; } - } elseif ($query && strpos($query, '.') !== false) { + } elseif (QueryUtils::validDomain($query)) { return self::QTYPE_DOMAIN; - } elseif ($query && strpos($query, '.') === false) { + // TODO: replace with AS validator + } elseif ($query && is_string($query) && strpos($query, '.') === false) { return self::QTYPE_AS; } else { return self::QTYPE_UNKNOWN; diff --git a/src/IpTools.php b/src/QueryUtils.php similarity index 63% rename from src/IpTools.php rename to src/QueryUtils.php index 0b01fc90..3dcf5d9a 100644 --- a/src/IpTools.php +++ b/src/QueryUtils.php @@ -25,16 +25,16 @@ namespace phpWhois; /** - * Utilities for parsing ip addresses + * Utilities for parsing and validating queries */ -class IpTools +class QueryUtils { /** * Check if ip address is valid * - * @param string $ip IP address for validation - * @param string $type Type of ip address. Possible value are: any, ipv4, ipv6 - * @param boolean $strict If true - fail validation on reserved and private ip ranges + * @param string $ip IP address for validation + * @param string $type Type of ip address. Possible value are: any, ipv4, ipv6 + * @param boolean $strict If true - fail validation on reserved and private ip ranges * * @return boolean True if ip is valid. False otherwise */ @@ -55,8 +55,8 @@ public static function validIp($ip, $type = 'any', $strict = true) * Check if given IP is a valid ipv4 address and doesn't belong to private and * reserved ranges * - * @param string $ip Ip address - * @param boolean $strict If true - fail validation on reserved and private ip ranges + * @param string $ip Ip address + * @param boolean $strict If true - fail validation on reserved and private ip ranges * * @return boolean */ @@ -76,8 +76,8 @@ public static function validIpv4($ip, $strict = true) /** * Check if given IP is a valid ipv6 address and doesn't belong to private ranges * - * @param string $ip Ip address - * @param boolean $strict If true - fail validation on reserved and private ip ranges + * @param string $ip Ip address + * @param boolean $strict If true - fail validation on reserved and private ip ranges * * @return boolean */ @@ -96,41 +96,22 @@ public static function validIpv6($ip, $strict = true) } /** - * Convert CIDR to net range + * Check if given domain name is valid * - * @TODO provide example + * @param $domain Domain name to check + * @param $type 'latin', 'idn', 'any' * - * @param string $net - * @return string + * @return boolean */ - public static function cidrConv($net) + public static function validDomain($domain, $type = 'any') { - $start = strtok($net, '/'); - $n = 3 - substr_count($net, '.'); - - if ($n > 0) { - for ($i = $n; $i > 0; $i--) { - $start .= '.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++) { - if ($bits1[$i] == $bits2[$i]) { - $final .= $bits1[$i]; - } - if ($bits1[$i] == 1 and $bits2[$i] == 0) { - $final .= $bits1[$i]; - } - if ($bits1[$i] == 0 and $bits2[$i] == 1) { - $final .= $bits2[$i]; - } + // TODO: Implement IDN + $pattern = '/^[a-z\d\.\-]*\.[a-z]{2,6}$/i'; + // preg_match doesn't return boolean + if (preg_match($pattern, $domain)) { + return true; + } else { + return false; } - - return $start . " - " . long2ip(bindec($final)); } } diff --git a/src/Utils.php b/src/Utils.php deleted file mode 100644 index efdac9ca..00000000 --- a/src/Utils.php +++ /dev/null @@ -1,161 +0,0 @@ - tags - * @param $obj - * @return string - */ - public function showObject(&$obj) - { - $r = $this->debugObject($obj); - return "
$r
\n"; - } - - /** - * Return object or array as formatted string - * @param $obj - * @param int $indent - * @return string - */ - public function debugObject($obj, $indent = 0) - { - if (is_array($obj)) { - $return = ''; - foreach ($obj as $k => $v) { - $return .= str_repeat(' ', $indent); - if (is_array($v)) { - $return .= $k . "->Array\n"; - $return .= $this->debugObject($v, $indent + 1); - } else { - $return .= $k . "->$v\n"; - } - } - return $return; - } - } - - public function nsRrDefined($query) - { - return checkdnsrr($query, 'NS'); - } - - /** - * Get nice HTML output - */ - public function showHTML($result, $link_myself = true, $params = 'query=$0&output=nice') - { - - // adds links for HTML output - - $email_regex = "/([-_\w\.]+)(@)([-_\w\.]+)\b/i"; - $html_regex = "/(?:^|\b)((((http|https|ftp):\/\/)|(www\.))([\w\.]+)([,:%#&\/?~=\w+\.-]+))(?:\b|$)/is"; - $ip_regex = "/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/i"; - - $out = ''; - $lempty = true; - - foreach ($result['rawdata'] as $line) { - $line = trim($line); - - if ($line == '') { - if ($lempty) { - continue; - } else { - $lempty = true; - } - } else { - $lempty = false; - } - - $out .= $line . "\n"; - } - - if ($lempty) { - $out = trim($out); - } - - $out = strip_tags($out); - $out = preg_replace($email_regex, '$0', $out); - $out = preg_replace_callback( - $html_regex, - function ($matches) { - if (substr($matches[0], 0, 4) == 'www.') { - $web = $matches[0]; - $url = 'http://' . $web; - } else { - $web = $matches[0]; - $url = $web; - } - - return '' . $web . ''; - }, - $out - ); - - if ($link_myself) { - if ($params[0] == '/') { - $link = $params; - } else { - $link = $_SERVER['PHP_SELF'] . '?' . $params; - } - - $out = preg_replace($ip_regex, '$0', $out); - - if (isset($result['regrinfo']['domain']['nserver'])) { - $nserver = $result['regrinfo']['domain']['nserver']; - } else { - $nserver = false; - } - - if (isset($result['regrinfo']['network']['nserver'])) { - $nserver = $result['regrinfo']['network']['nserver']; - } - - if (is_array($nserver)) { - reset($nserver); - while (list($host, $ip) = each($nserver)) { - $url = '$host"; - $out = str_replace($host, $url, $out); - $out = str_replace(strtoupper($host), $url, $out); - } - } - } - - // Add bold field names - $out = preg_replace("/(?m)^([-\s\.&;'\w\t\(\)\/]+:\s*)/", '$1', $out); - - // Add italics for disclaimer - $out = preg_replace("/(?m)^(%.*)/", '$0', $out); - - return str_replace("\n", "
\n", $out); - } -} diff --git a/src/Whois.php b/src/Whois.php index 313e5bf6..0bb503d9 100644 --- a/src/Whois.php +++ b/src/Whois.php @@ -22,7 +22,6 @@ namespace phpWhois; - /** * phpWhois main class * @@ -36,37 +35,58 @@ class Whois protected $handler; /** - * @var string Address to lookup + * @var \phpWhois\Query Query object created from given domain name */ - protected $address; + public $query; - /** - * @param string $address - * @return $this - * @throws \InvalidArgumentException if address is empty - */ - public function setAddress($address = '') + public function __construct($address = null) { - if ($address && is_string($address)) { - $this->address = $address; - } else { - throw new \InvalidArgumentException('Address cannot be empty'); + $this->setQuery(new Query()); + + if (!is_null($address)) { + $this->setAddress($address); + } + } + + protected function setQuery(\phpWhois\Query $query) + { + $this->query = $query; + } + + public function setAddress($address) + { + $this->query->setAddress($address); + + // TODO: Allow people to use their own handlers + $handler = DomainHandlerMap::findHandler($this->query); + if ($handler === false) { + throw new \InvalidArgumentException('Handler not found for this address. Giving up'); } + $this->setHandler($handler); + return $this; } /** - * @return string|null + * @return null|string Optimized address */ public function getAddress() { - return $this->address; + return $this->query->getAddress(); } /** - * @param Handler\HandlerAbstract $handler Handler for obtaining address whois information + * @return null|string Original unoptimized address */ - public function setHandler(\phpWhois\Handler\HandlerAbstract $handler) + public function getAddressOrig() + { + return $this->query->getAddressOrig(); + } + + /** + * @param Handler\HandlerAbstract $handler Handler for querying whois server + */ + protected function setHandler(\phpWhois\Handler\HandlerAbstract $handler) { $this->handler = $handler; } @@ -76,18 +96,16 @@ public function setHandler(\phpWhois\Handler\HandlerAbstract $handler) * @return mixed * @throws \InvalidArgumentException if address is empty */ - public function lookup($address = '') + public function lookup($address = null) { - if ($address) { + if (!is_null($address)) { $this->setAddress($address); } - if (!($address = $this->getAddress())) { + if (is_null($this->getAddress())) { throw new \InvalidArgumentException('Address cannot be empty'); } - $handler = HandlerMap::getHandler($address); - $this->setHandler($handler); return $this->handler->parse(); } } \ No newline at end of file diff --git a/src/WhoisClient.php b/src/WhoisClient.php index af83b10b..26d05461 100644 --- a/src/WhoisClient.php +++ b/src/WhoisClient.php @@ -24,7 +24,7 @@ namespace phpWhois; -use phpWhois\IpTools; +use phpWhois\QueryUtils; /** * phpWhois basic class @@ -153,11 +153,11 @@ public function getRawData($query) $query_args = str_replace('{version}', 'phpWhois' . $this->codeVersion, $query_args); if (strpos($query_args, '{ip}') !== false) { - $query_args = str_replace('{ip}', IpTools::getClientIp(), $query_args); + $query_args = str_replace('{ip}', QueryUtils::getClientIp(), $query_args); } if (strpos($query_args, '{hname}') !== false) { - $query_args = str_replace('{hname}', gethostbyaddr(IpTools::getClientIp()), $query_args); + $query_args = str_replace('{hname}', gethostbyaddr(QueryUtils::getClientIp()), $query_args); } } else { if (empty($this->query['args'])) { @@ -655,7 +655,7 @@ public function parseServer($server) $server = trim($server); $server = preg_replace('/\/$/', '', $server); - if (IpTools::validIpv6($server)) { + if (QueryUtils::validIpv6($server)) { $result = array('host' => "[$server]"); } else { $parsed = parse_url($server); diff --git a/test.php b/test.php index bf0f2f07..f3e2d428 100644 --- a/test.php +++ b/test.php @@ -11,12 +11,15 @@ try { $a = $whois //->setAddress(true) - ->lookup('ru'); + ->lookup('www.HELLO.su'); + //->lookup(); + $address = $whois->getAddress(); echo $a; + echo "\n$address"; } catch (Exception $e) { echo 'Error: '.$e->getMessage(); } -echo "Memory used: ".memory_get_usage()."\n"; +echo "\nMemory used: ".memory_get_usage()."\n"; echo "\n"; diff --git a/tests/DomainHandlerMapTest.php b/tests/DomainHandlerMapTest.php new file mode 100644 index 00000000..aea4c582 --- /dev/null +++ b/tests/DomainHandlerMapTest.php @@ -0,0 +1,11 @@ +assertTrue(IpTools::validIp($ip)); - } - - public function validIpsProvider() - { - return array( - array('123.123.123.123'), - array('1a80:1f45::ebb:12'), - ); - } - - /** - * @dataProvider invalidIpsProvider - */ - public function testInvalidIp($ip) - { - $this->assertFalse(IpTools::validIp($ip)); - } - - public function invalidIpsProvider() - { - return array( - array(''), - array('169.254.255.200'), - array('172.17.255.100'), - array('123.a15.255.100'), - array('fd80::1'), - array('fc80:19c::1'), - array('1a80:1f45::ebm:12'), - array('[1a80:1f45::ebb:12]'), - ); - } -} diff --git a/tests/QueryTest.php b/tests/QueryTest.php new file mode 100644 index 00000000..10171798 --- /dev/null +++ b/tests/QueryTest.php @@ -0,0 +1,47 @@ +assertEquals($type, Query::guessType($domain)); + } + + public function domainsProvider() + { + return [ + [Query::QTYPE_DOMAIN, 'www.google.com'], + //[Query::QTYPE_DOMAIN, 'президент.рф'], + [Query::QTYPE_IPV4, '212.212.12.12'], + [Query::QTYPE_UNKNOWN, '127.0.0.1'], + [Query::QTYPE_IPV6, '1a80:1f45::ebb:12'], + [Query::QTYPE_UNKNOWN, 'fc80:19c::1'], + [Query::QTYPE_AS, 'ABCD_EF-GH:IJK'], + ]; + } + + /** + * @dataProvider optimizeProvider + */ + public function testOptimizeAddress($unoptimized, $optimized) + { + $this->assertEquals($optimized, Query::optimizeAddress($unoptimized)); + } + + public function optimizeProvider() + { + return [ + ['Help.Co.uk', 'help.co.uk'], + ['www.help.co.uk', 'help.co.uk'], + ['WWW.Help.co.Uk', 'help.co.uk'], + ['WWW.SPACE', 'www.space'], + ['www.co.uk', 'co.uk'], // Sad but true + ]; + } +} diff --git a/tests/QueryUtilsTest.php b/tests/QueryUtilsTest.php new file mode 100644 index 00000000..32ea98c1 --- /dev/null +++ b/tests/QueryUtilsTest.php @@ -0,0 +1,84 @@ +assertTrue(QueryUtils::validIp($ip)); + } + + public function validIpsProvider() + { + return [ + ['123.123.123.123'], + ['1a80:1f45::ebb:12'], + ]; + } + + /** + * @dataProvider invalidIpsProvider + */ + public function testInvalidIp($ip) + { + $this->assertFalse(QueryUtils::validIp($ip)); + } + + public function invalidIpsProvider() + { + return [ + [''], + ['169.254.255.200'], + ['172.17.255.100'], + ['123.a15.255.100'], + ['fd80::1'], + ['fc80:19c::1'], + ['1a80:1f45::ebm:12'], + ['[1a80:1f45::ebb:12]'], + ]; + } + + /** + * @dataProvider validDomainsProvider + */ + public function testValidDomain($domain) + { + $this->assertTrue(QueryUtils::validDomain($domain)); + } + + public function validDomainsProvider() + { + return [ + ['domain.space'], + ['www.domain.space'], + ['sub.domain.space'], + ['www.sub.domain.space'], + ['domain.co.uk'], + ['www.domain.co.uk'], + ['sub.www.domain.co.uk'] + ]; + } + + /** + * @dataProvider invalidDomainsProvider + */ + public function testInvalidDomain($domain) + { + $this->assertFalse(QueryUtils::validDomain($domain)); + } + + public function invalidDomainsProvider() + { + return [ + ['212.12.212.12'], + ['domain'], + ['domain.1com'], + ['domain.abcdefg'], // 7 symbols TLD + ['domain.co.u'], + ]; + } +} diff --git a/tests/WhoisClientTest.php b/tests/WhoisClientTest.php index b02798c1..3105fffc 100644 --- a/tests/WhoisClientTest.php +++ b/tests/WhoisClientTest.php @@ -4,11 +4,11 @@ class WhoisClientTest extends \PHPUnit_Framework_TestCase { - public function testVersion() + /*public function testVersion() { $client = new WhoisClient; $this->assertRegExp('/^(\d+)\.(\d+)\.(\d+)(-\w+)*$/', $client->codeVersion); - } + }*/ /** * @dataProvider serversProvider @@ -21,29 +21,29 @@ public function testParseServer($server, $result) public function serversProvider() { - return array( - array('http://www.phpwhois.pw:80/', array('scheme' => 'http', 'host' => 'www.phpwhois.pw', 'port' => 80)), - array('http://www.phpwhois.pw:80', array('scheme' => 'http', 'host' => 'www.phpwhois.pw', 'port' => 80)), - array('http://www.phpwhois.pw', array('scheme' => 'http', 'host' => 'www.phpwhois.pw')), - array('www.phpwhois.pw:80', array('host' => 'www.phpwhois.pw', 'port' => 80)), - array('www.phpwhois.pw:80/', array('host' => 'www.phpwhois.pw', 'port' => 80)), - array('www.phpwhois.pw', array('host' => 'www.phpwhois.pw')), - array('www.phpwhois.pw/', array('host' => 'www.phpwhois.pw')), - array('http://127.0.0.1:80/', array('scheme' => 'http', 'host' => '127.0.0.1', 'port' => 80)), - array('http://127.0.0.1:80', array('scheme' => 'http', 'host' => '127.0.0.1', 'port' => 80)), - array('http://127.0.0.1', array('scheme' => 'http', 'host' => '127.0.0.1')), - array('127.0.0.1:80', array('host' => '127.0.0.1', 'port' => 80)), - array('127.0.0.1:80/', array('host' => '127.0.0.1', 'port' => 80)), - array('127.0.0.1', array('host' => '127.0.0.1')), - array('127.0.0.1/', array('host' => '127.0.0.1')), - array('http://[1a80:1f45::ebb:12]:80/', array('scheme' => 'http', 'host' => '[1a80:1f45::ebb:12]', 'port' => 80)), - array('http://[1a80:1f45::ebb:12]:80', array('scheme' => 'http', 'host' => '[1a80:1f45::ebb:12]', 'port' => 80)), - array('http://[1a80:1f45::ebb:12]', array('scheme' => 'http', 'host' => '[1a80:1f45::ebb:12]')), - //array('http://1a80:1f45::ebb:12', array('scheme' => 'http', 'host' => '[1a80:1f45::ebb:12]')), - array('[1a80:1f45::ebb:12]:80', array('host' => '[1a80:1f45::ebb:12]', 'port' => 80)), - array('[1a80:1f45::ebb:12]:80/', array('host' => '[1a80:1f45::ebb:12]', 'port' => 80)), - array('1a80:1f45::ebb:12', array('host' => '[1a80:1f45::ebb:12]')), - array('1a80:1f45::ebb:12/', array('host' => '[1a80:1f45::ebb:12]')), - ); + return [ + ['http://www.phpwhois.pw:80/', ['scheme' => 'http', 'host' => 'www.phpwhois.pw', 'port' => 80]], + ['http://www.phpwhois.pw:80', ['scheme' => 'http', 'host' => 'www.phpwhois.pw', 'port' => 80]], + ['http://www.phpwhois.pw', ['scheme' => 'http', 'host' => 'www.phpwhois.pw']], + ['www.phpwhois.pw:80', ['host' => 'www.phpwhois.pw', 'port' => 80]], + ['www.phpwhois.pw:80/', ['host' => 'www.phpwhois.pw', 'port' => 80]], + ['www.phpwhois.pw', ['host' => 'www.phpwhois.pw']], + ['www.phpwhois.pw/', ['host' => 'www.phpwhois.pw']], + ['http://127.0.0.1:80/', ['scheme' => 'http', 'host' => '127.0.0.1', 'port' => 80]], + ['http://127.0.0.1:80', ['scheme' => 'http', 'host' => '127.0.0.1', 'port' => 80]], + ['http://127.0.0.1', ['scheme' => 'http', 'host' => '127.0.0.1']], + ['127.0.0.1:80', ['host' => '127.0.0.1', 'port' => 80]], + ['127.0.0.1:80/', ['host' => '127.0.0.1', 'port' => 80]], + ['127.0.0.1', ['host' => '127.0.0.1']], + ['127.0.0.1/', ['host' => '127.0.0.1']], + ['http://[1a80:1f45::ebb:12]:80/', ['scheme' => 'http', 'host' => '[1a80:1f45::ebb:12]', 'port' => 80]], + ['http://[1a80:1f45::ebb:12]:80', ['scheme' => 'http', 'host' => '[1a80:1f45::ebb:12]', 'port' => 80]], + ['http://[1a80:1f45::ebb:12]', ['scheme' => 'http', 'host' => '[1a80:1f45::ebb:12]']], + //['http://1a80:1f45::ebb:12', [scheme' => 'http', 'host' => '[1a80:1f45::ebb:12]']], + ['[1a80:1f45::ebb:12]:80', ['host' => '[1a80:1f45::ebb:12]', 'port' => 80]], + ['[1a80:1f45::ebb:12]:80/', ['host' => '[1a80:1f45::ebb:12]', 'port' => 80]], + ['1a80:1f45::ebb:12', ['host' => '[1a80:1f45::ebb:12]']], + ['1a80:1f45::ebb:12/', ['host' => '[1a80:1f45::ebb:12]']], + ]; } } diff --git a/tests/WhoisTest.php b/tests/WhoisTest.php deleted file mode 100644 index 3cf93e7d..00000000 --- a/tests/WhoisTest.php +++ /dev/null @@ -1,35 +0,0 @@ -lookup('phpwhois.pw'); - $this->assertEquals('yes', $result['regrinfo']['registered']); - } - - /** - * @dataProvider domainsProvider - */ - public function testQtype($type, $domain) - { - $whois = new Whois; - $this->assertEquals($type, $whois->guessQueryType($domain)); - } - - public function domainsProvider() - { - return array( - array(Whois::QTYPE_DOMAIN, 'www.google.com'), - array(Whois::QTYPE_DOMAIN, 'президент.рф'), - array(Whois::QTYPE_IPV4, '212.212.12.12'), - array(Whois::QTYPE_UNKNOWN, '127.0.0.1'), - array(Whois::QTYPE_IPV6, '1a80:1f45::ebb:12'), - array(Whois::QTYPE_UNKNOWN, 'fc80:19c::1'), - array(Whois::QTYPE_AS, 'ABCD_EF-GH:IJK'), - ); - } -} From 1334231296f6954e00bf89f798f28d7fac9cee41 Mon Sep 17 00:00:00 2001 From: Dmitry Lukashin Date: Sun, 20 Dec 2015 23:15:36 +0300 Subject: [PATCH 03/23] [WIP] Some rework of classes structure --- .gitignore | 1 + .scrutinizer.yml | 14 +++++- .travis.yml | 2 - phpdoc.dist.xml | 16 +++++++ src/DomainHandlerMap.php | 17 +++---- src/Handler/HandlerAbstract.php | 31 +++++++++++-- src/Handler/Ru.php | 6 ++- src/Parser/ParserA.php | 9 ++++ src/Parser/ParserB.php | 16 +++++++ src/Parser/iParser.php | 2 + src/Provider/HttpServer.php | 13 ++---- src/Provider/ProviderAbstract.php | 76 +++++++++++++++++++++++++------ src/Provider/WhoisServer.php | 15 +++--- src/Query.php | 45 ++++++++++++------ src/Whois.php | 28 +++++++++--- test.php | 6 +-- tests/DomainHandlerMapTest.php | 35 +++++++++++++- 17 files changed, 259 insertions(+), 73 deletions(-) create mode 100644 phpdoc.dist.xml diff --git a/.gitignore b/.gitignore index 6c47867a..2a5b8d9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/docs/phpdoc composer.lock /vendor nbproject diff --git a/.scrutinizer.yml b/.scrutinizer.yml index c289cfc1..4100e1b0 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,2 +1,14 @@ +filter: + excluded_paths: + - example/example.php + - handler.template.php + - src/old/ + - src/Whois_Old.php + - src/whois.parser.php + - src/whois.servers.php + - src/WhoisClient.php + - test.php + - testsuite.php + tools: - external_code_coverage: true \ No newline at end of file + external_code_coverage: true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 656a4842..f219eed9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ php: matrix: fast_finish: true - allow_failures: - - php: hhvm-nightly # faster builds on new travis containers sudo: false diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml new file mode 100644 index 00000000..b65af764 --- /dev/null +++ b/phpdoc.dist.xml @@ -0,0 +1,16 @@ + + + + docs/phpdoc + + + docs/phpdoc + + + src + src/old/* + + +