Subversion Repositories vgwhois

Rev

Rev 5 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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