Subversion Repositories vgwhois

Rev

Rev 5 | Go to most recent revision | 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: mq, gf and gp TLD whois
#
#  (c) 2012 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
#
#  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
#

# TODO: for many domains, the format is completely different! do we have a good enough parser?

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

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

$url = "https://www.dom-enic.com/whois.html";

$res  = "% Parsing via regex from '$url'\n\n";

// Split up "naked" domain name and TLD
if (!preg_match('@^(.*)(\.(mq|gf|gp))$@', $domain, $m)) {
        echo "Error: Can only handle .mq, .gf and .gp TLDs.\n";
        exit(1);
}
$domain = $m[1];
$ext    = $m[2];

$x = file_get_contents2($url, 'domain='.urlencode($domain).'&' .
                              'extension='.urlencode($ext).'&' .
                              'Submit=Soumettre');

if (strpos($x, /* $domain. */ ' est disponible.') !== false) {
        define('BEGIN', '<div align="center" class="texte1"><p>');
        define('END',   '</p></div>');
} else {
        // For some domains it is <p> and not <h1>
        $x = str_replace('<p class="titre1">WHOIS result</p>', '<h1 class="titre1">WHOIS result</h1>', $x);
        define('BEGIN', '<h1 class="titre1">WHOIS result</h1>');
        // define('END',   '</div>');
        // In comparison to </div>, this includes the disclaimer at the bottom:
        define('END',   '</td>');
}

preg_match_all('@'.preg_quote(BEGIN, '@').'(.*)'.preg_quote(END, '@').'@ismU', $x, $m);

if (!isset($m[1][0])) {
        echo "Error while parsing the web content. Could not find limitations.\n";
        exit(1);
}
$x = $m[1][0];

$x = preg_replace('@<br />(?!\n)@', "\n", $x);
$x = strip_tags($x);

$x = html_entity_decode($x);

// é -> É @ strtoupper()
/*
$locals = array('es_ES@euro', 'es_ES', 'es');
reset($locals);
while (list(, $locale) = each ($locals)) {
        if ( setlocale(LC_CTYPE, $locale) == $locale ) {                
                break; // Exit when we were successfull
        }
}
*/

$x = preg_replace("@\n\s+\n@", "\n\n", $x);
while (strpos($x, "\n\n\n") !== false) $x = str_replace("\n\n\n", "\n\n", $x);

$special_words = array(
        'Registrant:',
        'Administrative Contact:',
        'Technical Contact:',
        'Billing Contact:'
);

foreach ($special_words as $s) {
        $x = str_replace($s, "\n".uc_latin1($s)."\n", $x);
}

$x = trim($x);

echo $res.trim_each_line($x)."\n";