Subversion Repositories vgwhois

Rev

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

Rev Author Line No. Line
2 daniel-mar 1
#!/usr/bin/php
2
<?php
3
 
4
#
11 daniel-mar 5
#  VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois)
5 daniel-mar 6
#  Subprogram: mq, gf and gp TLD whois
2 daniel-mar 7
#
5 daniel-mar 8
#  (c) 2012 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de>
2 daniel-mar 9
#
5 daniel-mar 10
#  License: https://www.gnu.org/licenses/gpl-2.0.html (GPL version 2)
2 daniel-mar 11
#
12
 
13
# TODO: for many domains, the format is completely different! do we have a good enough parser?
14
 
15
require_once __DIR__ . '/../../shared/php_includes/common_functions.inc.php';
16
 
149 daniel-mar 17
ini_set('default_charset', 'UTF-8');
18
 
2 daniel-mar 19
$domain = isset($argv[1]) ? $argv[1] : '';
20
 
21
$url = "https://www.dom-enic.com/whois.html";
22
 
23
$res  = "% Parsing via regex from '$url'\n\n";
24
 
25
// Split up "naked" domain name and TLD
26
if (!preg_match('@^(.*)(\.(mq|gf|gp))$@', $domain, $m)) {
27
	echo "Error: Can only handle .mq, .gf and .gp TLDs.\n";
28
	exit(1);
29
}
30
$domain = $m[1];
31
$ext    = $m[2];
32
 
33
$x = file_get_contents2($url, 'domain='.urlencode($domain).'&' .
34
                              'extension='.urlencode($ext).'&' .
35
                              'Submit=Soumettre');
36
 
37
if (strpos($x, /* $domain. */ ' est disponible.') !== false) {
38
	define('BEGIN', '<div align="center" class="texte1"><p>');
39
	define('END',   '</p></div>');
40
} else {
41
	// For some domains it is <p> and not <h1>
42
	$x = str_replace('<p class="titre1">WHOIS result</p>', '<h1 class="titre1">WHOIS result</h1>', $x);
43
	define('BEGIN', '<h1 class="titre1">WHOIS result</h1>');
44
	// define('END',   '</div>');
45
	// In comparison to </div>, this includes the disclaimer at the bottom:
46
	define('END',   '</td>');
47
}
48
 
49
preg_match_all('@'.preg_quote(BEGIN, '@').'(.*)'.preg_quote(END, '@').'@ismU', $x, $m);
50
 
51
if (!isset($m[1][0])) {
149 daniel-mar 52
	echo "Error while parsing the web content (RegEx failed).\n";
2 daniel-mar 53
	exit(1);
54
}
55
$x = $m[1][0];
56
 
57
$x = preg_replace('@<br />(?!\n)@', "\n", $x);
58
$x = strip_tags($x);
59
 
60
$x = html_entity_decode($x);
61
 
62
$x = preg_replace("@\n\s+\n@", "\n\n", $x);
63
while (strpos($x, "\n\n\n") !== false) $x = str_replace("\n\n\n", "\n\n", $x);
64
 
65
$special_words = array(
66
	'Registrant:',
67
	'Administrative Contact:',
68
	'Technical Contact:',
69
	'Billing Contact:'
70
);
71
 
72
foreach ($special_words as $s) {
149 daniel-mar 73
	$x = str_replace($s, "\n".mb_strtoupper($s)."\n", $x);
2 daniel-mar 74
}
75
 
76
$x = trim($x);
77
 
78
echo $res.trim_each_line($x)."\n";