Subversion Repositories vgwhois

Rev

Rev 11 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/php
<?php

#
#  VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois)
#  Subprogram: gov TLD whois
#
#  (c) 2014-2019 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
#
#  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
#

require_once __DIR__ . '/../../shared/php_includes/common_functions.inc.php';

$domain = isset($argv[1]) ? $argv[1] : '';

// This subprogram does output more verbose information (e.g. Agency) in comparison to the whois service.

$friendly_url = 'https://domains.dotgov.gov/dotgov-web/registration/whois.xhtml';

$x = file_get_contents2($friendly_url);

if (!preg_match('@name="javax.faces.ViewState" id="javax.faces.ViewState" value="(.*)"@ismU', $x, $m)) {
        echo "Error (A) while querying whois service. Please manually check at $friendly_url\n";
        exit(1);
}
$viewstate = $m[1];
$viewstate = str_replace('+', '%2B', $viewstate);
$viewstate = str_replace('/', '%2F', $viewstate);

# ---

$bef  = '';
#$bef .= 'vtor -- ';
$bef .= 'curl "https://domains.dotgov.gov/dotgov-web/registration/whois.xhtml" ';
#$bef .= ' -H "Cookie: JSESSIONID='.$session_id.'; seen-cookie-message=yes';
$bef .= ' --cookie ~/.cookiejar --cookie-jar ~/.cookiejar  ';   # <-- cookiejar is maintained by file_get_contents2()
$bef .= ' -H "Host: domains.dotgov.gov"';
$bef .= ' -H "Origin: https://domains.dotgov.gov"';
$bef .= ' -H "Accept-Encoding: gzip,deflate"';
$bef .= ' -H "Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4"';
$bef .= ' -H "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:32.0) Gecko/20100101 Firefox/32.0"';
#$bef .= ' -H "Content-Type: application/x-www-form-urlencoded"';
$bef .= ' -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"';
$bef .= ' -H "Cache-Control: max-age=0"';
$bef .= ' -H "Referer: '.$friendly_url.'" ';
$bef .= ' -H "Connection: keep-alive"';
$bef .= ' --data '.escapeshellarg('domainAvailabilityCheckForm=domainAvailabilityCheckForm&domainAvailabilityCheckForm%3ArequestedDomainName='.urlencode($domain).'&domainAvailabilityCheckForm%3Asubmit=Check+Availability&javax.faces.ViewState='.urlencode($viewstate));
$bef .= ' --compressed';
$bef .= ' --silent';

$out = array();
exec($bef, $out, $code);

if ($code != 0) {
        echo "Error (C) while querying whois service. Please manually check at $friendly_url\n";
        exit($code);
}

$x = implode('', $out);

if (!preg_match('@<strong>\s*(Currently.+)</td>@ismU', $x, $m)) {
        echo "Error (D) while querying whois service. Please manually check at $friendly_url\n";
        exit(1);
}

$x = $m[1];

$x = str_replace('<br />', "\n", $x);

$x = strip_tags($x);
$x = trim($x);
$x = trimHereDoc($x); // jede einzelne Zeile

$x = preg_replace('@[ \\t]+@m', ' ', $x);

echo "% Parsing via regex from '$friendly_url'\n\n";
echo "$x\n\n";
exit(0);

# ---

function trimHereDoc($t) {
        # http://stackoverflow.com/a/1655176
        return implode("\n", array_map('trim', explode("\n", $t)));
}