Subversion Repositories vgwhois

Rev

Rev 5 | Go to most recent revision | 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
 
17
$domain = isset($argv[1]) ? $argv[1] : '';
18
 
19
$url = "https://www.dom-enic.com/whois.html";
20
 
21
$res  = "% Parsing via regex from '$url'\n\n";
22
 
23
// Split up "naked" domain name and TLD
24
if (!preg_match('@^(.*)(\.(mq|gf|gp))$@', $domain, $m)) {
25
	echo "Error: Can only handle .mq, .gf and .gp TLDs.\n";
26
	exit(1);
27
}
28
$domain = $m[1];
29
$ext    = $m[2];
30
 
31
$x = file_get_contents2($url, 'domain='.urlencode($domain).'&' .
32
                              'extension='.urlencode($ext).'&' .
33
                              'Submit=Soumettre');
34
 
35
if (strpos($x, /* $domain. */ ' est disponible.') !== false) {
36
	define('BEGIN', '<div align="center" class="texte1"><p>');
37
	define('END',   '</p></div>');
38
} else {
39
	// For some domains it is <p> and not <h1>
40
	$x = str_replace('<p class="titre1">WHOIS result</p>', '<h1 class="titre1">WHOIS result</h1>', $x);
41
	define('BEGIN', '<h1 class="titre1">WHOIS result</h1>');
42
	// define('END',   '</div>');
43
	// In comparison to </div>, this includes the disclaimer at the bottom:
44
	define('END',   '</td>');
45
}
46
 
47
preg_match_all('@'.preg_quote(BEGIN, '@').'(.*)'.preg_quote(END, '@').'@ismU', $x, $m);
48
 
49
if (!isset($m[1][0])) {
50
	echo "Error while parsing the web content. Could not find limitations.\n";
51
	exit(1);
52
}
53
$x = $m[1][0];
54
 
55
$x = preg_replace('@<br />(?!\n)@', "\n", $x);
56
$x = strip_tags($x);
57
 
58
$x = html_entity_decode($x);
59
 
60
// é -> É @ strtoupper()
61
/*
62
$locals = array('es_ES@euro', 'es_ES', 'es');
63
reset($locals);
64
while (list(, $locale) = each ($locals)) {
65
	if ( setlocale(LC_CTYPE, $locale) == $locale ) {                
66
		break; // Exit when we were successfull
67
	}
68
}
69
*/
70
 
71
$x = preg_replace("@\n\s+\n@", "\n\n", $x);
72
while (strpos($x, "\n\n\n") !== false) $x = str_replace("\n\n\n", "\n\n", $x);
73
 
74
$special_words = array(
75
	'Registrant:',
76
	'Administrative Contact:',
77
	'Technical Contact:',
78
	'Billing Contact:'
79
);
80
 
81
foreach ($special_words as $s) {
82
	$x = str_replace($s, "\n".uc_latin1($s)."\n", $x);
83
}
84
 
85
$x = trim($x);
86
 
87
echo $res.trim_each_line($x)."\n";