Source code of /package/share/subprograms/gov

Last modified: 2015-05-17 17:12:52

Download

#!/usr/bin/php
<?php

#
#  generic Whois - Subprogram "gov"
#
#  (c) 2014 by Daniel Marschall, ViaThinkSoft <www.viathinksoft.de>
#
#  Distribution, usage etc. pp. regulated by the current version of GPL.
#
#
#
# History:
# 2014-01-28  mar   Initial release
# 2014-09-12  mar   Fixed
#

require_once __DIR__ '/../includes/common_functions.inc.php';

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

// This service does output more verbose information (e.g. Agency) in comparison to the whois service.
$friendly_url 'https://www.dotgov.gov/portal/web/dotgov/whois';

/*
$viewstate  = 'H4sIAAAAAAAAAKVXXYwTVRS+7XZ3uyvq/hiCPwtlQRbiMl1ayrZbCHS7W7axXch2QYGH5Xbm7nZgOjPM3NnOgmzACERJjAY1mqyRRB98gBd948Gf+GAkQeMmPmhiQoyJMfEnMSaoD+q9dzpttzttgc7DdH7OPefM+b7vnNtrv4JWQwO9x1In4DzkJCjPcQeyJxCPo698+ew7Xfo2yQ2AqQIAvLoGgryS53RD5mYhj3QOqqok8hCLisxlMMQoDWU4h7RkXpU2T2sITSoC+nP2xkfXh/Z/vIb6KWwF9PDRaGbRC/GpKjKSMXcoeVhEhSlFwcRWPwUWgbuQYAs2OS/I4bzETZBTQtHy4HFByUNRjs1DUYJZURLxQjyH+JP0pe0uTpy5wNYG7pKyauBpZGLQq6FTBtIxEsaY80mYR7avnczXQANfaaTrpCg6aD0xIwpBe/EIWzzYYHFcyeehLIwaGCsyaNONbF7EtguOuPCAjbVqeRBqJFmMNCtyyF4WZpGfahD5gIFJDWjpILYcDDfrIGIa1AE93KUrb+mqQyUHIVl3mYqjiiIhKN/yaee+WfrnNzdwHQWt81AykKm6WDYPAbaml60xsChxMU2DCylRx+b55b63PodvtwBXEnh08TRiPAYFDzm1EWw7J6bTqZnRWCYZxyDif2Z8dHtyMuE36Sf4NTRHfGiM3P4axOKYKQnfVQ6fUngoocW/uo8vDf39ixt4ksCbg3qOJ1JIgXZ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rN7NcKAbQED7xiVwoYm+EQwM7giGfWRrQIwbNY56afZTrHuYra/yhfOAXDklnXY6jSdiFdvCgbtSXKiouFCZa2oNXhFJaQhKmSJHPVgzUC2ZtN9/4rOh6j152JrHXg3JZMIioWIkF5lOf/ayc7wwBiL1YVvxTkI+dMo3kIilMuMDZ0F71treN8+knaHByC6fnXIjKtXJiY6ihjAO23+IarYM619PGVp3Gdrn7ZFSxUOnGdAMsLwjsCyD+pDGQfjeyzc9daga0YvghSYQDQ03i6iV0l0BGrH/oJYBpacX7w3A/wF62oXTTBEAAA==';
$session_id = 'k2NNSnyK9Kvh3BZHpTphvrL12yFTn6TcMJpZrj865x7qLQCvvjs2SK3XB0GxG5qSlX2JhcxymvNqTWqlmdQ311gwVywf8fxNJKVG9p4mccGvXQLbl1LLMxdDBzWt2jFD';
$unknown1   = '1882029245';
$unknown2   = '1390916170265';
*/

$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);

if (!
preg_match('getSessionId:function\\(\\){return"([^!]+)!([^!]+)!([^!]+)"}ismU'$x$m)) {
    echo 
"Error (B) while querying whois service. Please manually check at $friendly_url\n";
    exit(
1);
}
$session_id $m[1];
$unknown1   $m[2];
$unknown2   $m[3];

# ---

$bef  '';
#$bef .= 'vtor -- ';
$bef .= 'curl "https://www.dotgov.gov/portal/web/dotgov/whois?p_p_id=domainAvailabilityCheck_portlet_WAR_dotgov_portlets&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-3&p_p_col_count=1&_domainAvailabilityCheck_portlet_WAR_dotgov_portlets_com.sun.faces.portlet.VIEW_ID="%"2FWEB-INF"%"2Fxhtml"%"2Fregistration"%"2FdomainAvailabilityCheck.xhtml&_domainAvailabilityCheck_portlet_WAR_dotgov_portlets_com.sun.faces.portlet.NAME_SPACE=_domainAvailabilityCheck_portlet_WAR_dotgov_portlets_"';

$bef .= ' -H "Cookie: JSESSIONID='.$session_id.'!'.$unknown1.'; GUEST_LANGUAGE_ID=en_US; COOKIE_SUPPORT=true"';
$bef .= ' -H "Host: www.dotgov.gov"';
$bef .= ' -H "Origin: https://www.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: https://www.dotgov.gov/portal/web/dotgov/whois;jsessionid='.$session_id.'!'.$unknown1.'!'.$unknown2.'?p_p_id=domainAvailabilityCheck_portlet_WAR_dotgov_portlets&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-3&p_p_col_count=1&_domainAvailabilityCheck_portlet_WAR_dotgov_portlets_com.sun.faces.portlet.VIEW_ID="%"2FWEB-INF"%"2Fxhtml"%"2Fregistration"%"2FdomainAvailabilityCheck.xhtml&_domainAvailabilityCheck_portlet_WAR_dotgov_portlets_com.sun.faces.portlet.NAME_SPACE=_domainAvailabilityCheck_portlet_WAR_dotgov_portlets_"';
$bef .= ' -H "Connection: keep-alive"';
$bef .= ' --data '.escapeshellarg('domainAvailabilityCheckForm=domainAvailabilityCheckForm&domainAvailabilityCheckForm%3ArequestedDomainName='.$domain.'&domainAvailabilityCheckForm%3Asubmit=Check+Availability&javax.faces.ViewState='.$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>(.*)</tr>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)));
}