Subversion Repositories vgwhois

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
#!/usr/bin/php
2
<?php
3
 
4
#
5
#  generic Whois - Subprogram "pk"
6
#
7
#  (c) 2012 by Daniel Marschall, ViaThinkSoft <www.viathinksoft.de>
8
#
9
#  Distribution, usage etc. pp. regulated by the current version of GPL.
10
#
11
#
12
#
13
# History:
14
# 2012-11-19  mar   Initial release
15
#
16
 
17
require_once __DIR__ . '/../../shared/php_includes/common_functions.inc.php';
18
 
19
$domain = isset($argv[1]) ? $argv[1] : '';
20
 
21
$url = "http://pk5.pknic.net.pk/pk5/lookup.PK";
22
 
23
$res  = "% Parsing via regex from '$url'\n\n";
24
 
25
$x = file_get_contents2($url, 'name='.$domain);
26
 
27
if (strpos($x, '<XPC_RESULT_NOTFOUND/>') !== false) {
28
	define('BEGIN', '<td id="Tmain">');
29
	define('END',   '<XPC_RESULT_NOTFOUND/>');
30
} else {
31
	define('BEGIN', '<p class="pkheading">');
32
	define('END',   '<SPAN class="sideHead">');
33
}
34
 
35
preg_match_all('@'.preg_quote(BEGIN, '@').'(.*)'.preg_quote(END, '@').'@ismU', $x, $m);
36
 
37
if (!isset($m[1][0])) {
38
	echo "Error while parsing the web content. Could not find limitations.\n";
39
	exit(1);
40
}
41
$x = $m[1][0];
42
 
43
$x = strip_tags($x);
44
 
45
// é -> É @ strtoupper()
46
/*
47
$locals = array('es_ES@euro', 'es_ES', 'es');
48
reset($locals);
49
while (list(, $locale) = each ($locals)) {
50
	if ( setlocale(LC_CTYPE, $locale) == $locale ) {                
51
		break; // Exit when we were successfull
52
	}
53
}
54
*/
55
 
56
$x = str_replace('&nbsp;', ' ', $x);
57
 
58
$x = html_entity_decode($x);
59
 
60
$x = preg_replace("| +|", ' ', $x);
61
$x = preg_replace("|\n *|", "\n", $x);
62
$x = preg_replace("| *\n|", "\n", $x);
63
$x = preg_replace("|\n+|", "\n", $x);
64
 
65
$x = str_replace(":\n", ": ", $x);
66
 
67
while (strpos($x, "\t") !== false) $x = str_replace("\t", '', $x);
68
while (strpos($x, '  ') !== false) $x = str_replace('  ', ' ', $x);
69
 
70
# Avoid "Contact person: Address:" if there is no contact person. Add a line break
71
$x = preg_replace('@^([^:\n]+):\s+([^\n:]+):@m', "\\1:\n\\2:", $x);
72
 
73
$x = make_tabs($x);
74
 
75
$x = trim($x);
76
 
77
$x = preg_replace("@\n\s+\n@", "\n\n", $x);
78
 
79
while (strpos($x, "\n\n") !== false) $x = str_replace("\n\n", "\n", $x);
80
 
81
$x = preg_replace('@The Domain record for(.*)\n@', 'The Domain record for\\1'."\n\n", $x);
82
 
83
$special_words = array(
84
	'Technical Contact',
85
	'Billing Contact',
86
	'Nameservers'
87
);
88
 
89
foreach ($special_words as $s) {
90
	$x = str_replace($s, "\n".uc_latin1($s)."\n", $x);
91
}
92
 
93
echo $res.trim_each_line($x)."\n";