Subversion Repositories vgwhois

Rev

Rev 4 | Rev 7 | 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
#
5 daniel-mar 5
#  VWhois (ViaThinkSoft WHOIS, a fork of generic Whois / gwhois)
6
#  Maintenance / Developer utilities
2 daniel-mar 7
#
5 daniel-mar 8
#  (c) 2012-2019 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: strikte trennung zwischen pattern entwicklung ( = im sdk enthalten ) und lokaler gwi entwicklung ( = packages, eigene vwi services )
14
# TODO: alles modular machen, vieles cachen
15
 
16
# TODO: was wenn ein rwi entfernt wird? prüfung notwendig dann!
17
#       --> das wird im whois-ping test geprueft
18
# TODO: auch unnoetige excludes (anormalities) in config.inc.php melden
19
 
20
# TODO pattern.d/tld --> check if all existing and disallocated TLDs are inside
21
 
22
# TODO: konsolenfarben z.b. grün für qa-audit
23
 
24
error_reporting(E_ALL | E_NOTICE | E_STRICT | E_DEPRECATED);
25
 
4 daniel-mar 26
# ---
2 daniel-mar 27
 
4 daniel-mar 28
define('DIR', realpath(__DIR__));
2 daniel-mar 29
 
4 daniel-mar 30
require_once DIR . '/../../shared/php_includes/common_functions.inc.php';
2 daniel-mar 31
 
4 daniel-mar 32
define('CACHE_FILE_DIR', DIR . '/../.cache/web');
2 daniel-mar 33
 
34
$anormale_whois = array();
35
require DIR . '/config.inc.php';
36
 
37
$pattern_cont = get_united_pattern();
38
 
39
$global_status = 0;
40
 
41
# ---
42
 
43
echo "* Check if every deleted TLD has a notice ( ".DELETED_TLD_LIST." )\n";
44
 
45
# does not exist as static file at VTS server
46
$del_tld_cont = explode("\n", cached_file(DELETED_TLD_LIST, CACHE_FILE_DIR));
47
 
48
$loc_good = true;
49
foreach ($del_tld_cont as $tld) {
50
	$tld = trim($tld);
51
	if ($tld == '') continue;
52
	if ($tld[0] == '#') continue;
53
	$tld = strtolower($tld);
54
	if (!preg_match('@:notice\\|\\|Disallocated by IANA([^\\n]*)[\\r\\n]+\\\\.'.$tld.'\\$@smU', $pattern_cont, $m)) {
55
		$loc_good = false;
56
		echo "[ !! ] Does not have a notice beginning with \"Disallocated by IANA\": $tld\n";
57
	}
58
}
59
 
60
if ($loc_good) {
61
	echo "[ OK ]\n";
62
} else {
63
	$global_status=1;
64
}
65
 
66
# ---
67
 
68
echo "* Check if every TLD has a single whois entry\n";
69
 
70
$tld_cont = explode("\n", cached_file(IANA_TLD_REGISTRY, CACHE_FILE_DIR));
71
 
72
$loc_good = true;
73
foreach ($tld_cont as $tld) {
74
	$tld = trim($tld);
75
	if ($tld == '') continue;
76
	if ($tld[0] == '#') continue;
77
	$tld = strtolower($tld);
78
	$regex = '@[\r\n]\s*(?<!#)\s*[^a-zA-Z\r\n#]*\\\\.'.trim($tld).'\\$\s*[\r\n]@isU';
79
	$pc = $pattern_cont;
80
	$pc = preg_replace('@\\(\\?\\:[a-zA-Z\\|]+\\)@isU', '', $pc); # z.B. \.((?:ac|co|net|or|web|sch|mil|go|my|biz)\.id)$
81
	$pc = str_replace('(', '', $pc);
82
	$pc = str_replace(')', '', $pc); # wegen regexes, z.b. \.(pn)$
83
	# if (strpos($pattern_cont, '\.'.trim($tld)) === false) {
84
	# if (strpos(str_replace(')', '', $pattern_cont), '\.'.trim($tld).'$') === false) { # ')' wegen RegEx'es
85
	if (!preg_match($regex, $pc)) {
86
		$iana_url = sprintf(IANA_TLD_ENTRY, $tld);
87
		$iana_cont = file_get_contents($iana_url);
88
		if (strpos($iana_cont, 'This domain is not present in the root zone at this time.') === false) {
89
			$loc_good = false;
90
 
91
			# TODO: hier sollte man evtl schon gucken, ob bei iana.org ein whois-name vorliegt.
92
			echo "[ !! ] Not in pattern-file: $tld (see $iana_url )\n";
93
		}
94
	}
95
}
96
 
97
if ($loc_good) {
98
	echo "[ OK ]\n";
99
} else {
100
	$global_status=1;
101
}
102
 
103
# ---
104
 
105
echo "* Check if TLDs have the latest Root-Whois-Server URLs ( ".ROOT_WHOIS_SERVER_LIST." )\n";
106
 
107
# TODO: geht nicht wenn 2 TLDs sich einen :whois teilen
108
# geht auch nicht mit domains mit third level tlds oder regexes usw
109
 
110
# TODO: allerdings wird keine kontrolle gemacht ob die auskommentierte Zeile wirklich zu $tld gehört!
111
echo "Note: For following TLDs, the root whois server may be commented out: ".implode(', ', $anormale_whois)."\n";
112
 
113
$loc_good = true;
114
$rws_cont = rws_get_list();
115
foreach ($rws_cont as $tld => $whois) {
116
	$c = "$tld => $whois";
117
 
118
	$g = false;
119
	if (in_arrayi($tld, $anormale_whois)) {
120
		# Sonderfälle... whois server die nicht gehen...
121
		# Der Server muss dann nur irgendwo vorkommen, in Form einer auskommentierten Zeile
122
		$g = (
123
			(stripos($pattern_cont, ':whois|'.$whois."\n") !== false) ||
124
			(stripos($pattern_cont, 'whois::'.$whois.":::") !== false) || // multiple
125
			(stripos($pattern_cont, 'whois::'.$whois."\n") !== false) || // multiple
126
			(stripos($pattern_cont, ':inicwhois|'.$whois."\n") !== false) ||
127
			(stripos($pattern_cont, 'inicwhois::'.$whois.":::") !== false) || // multiple
128
			(stripos($pattern_cont, 'inicwhois::'.$whois."\n") !== false) // multiple
129
		);
130
	} else {
131
		# TODO: auch auskommentierte einträge erlauben, falls die RWI outdated ist
132
		$regex = "@\\n:(inic){0,1}whois\\|".preg_quote($whois, '@')."(\\|.*)*\\n(#.*\n)*\\\\.".preg_quote($tld, '@')."\\$@ismU";
133
		$g = preg_match($regex, $pattern_cont);
134
 
135
		if (!$g) {
136
			# Multiple?
137
			# TODO: bessere pruefung auf auskommentiere eintraege
138
			$regex = "@(:multiple\\|\\||:::)(inic){0,1}whois::".preg_quote($whois, '@')."(:[^\n]*|)\s*\n(#.*\n)*(\\(\\.\\*\\)){0,1}\\\\.".preg_quote($tld, '@')."\\$@ismU";
139
			$g = preg_match($regex, $pattern_cont);
140
		}
141
	}
142
 
143
	if (!$g) {
144
		# If the data is not live, we need to check if the whois server is still official (and not changed since then)
145
		if ((!rws_is_live()) && (iana_get_whois($tld) != $whois)) continue;
146
 
147
		# If we reported it as dead, we trust that. (In case it is wrong, the whois-ping will warn about it)
148
		if (reported_dead($whois)) continue;
149
 
150
		# Whois servers which are official but are down, are not interesting. Do not warn.
151
		if (!gwitc_is_port_open($whois, 43)) continue;
152
 
153
		$loc_good = false;
154
		echo "[ !! ] Not in TLD file: $c\n";
155
	}
156
	unset($g);
157
}
158
 
159
if ($loc_good) {
160
	echo "[ OK ]\n";
161
} else {
162
	$global_status=1;
163
}
164
 
165
# ---
166
 
167
define('CUR_VER', gwi_getInstalledBaseVersion());
168
 
4 daniel-mar 169
echo "* Check if there is a newer official version of gwhois which needs to be merged with the ViaThinkSoft fork ( ".DEBIAN_GWHOIS_PACKAGE_URL." , current base version ".CUR_VER.")\n";
170
 
2 daniel-mar 171
$latest_official = getLatestGWIversion();
172
$latest_official = str_replace('-', '.', $latest_official); // they use the reserved '-' character in their versions (used for delimiting upstream versions)
173
$loc_good = true;
174
if (CUR_VER != $latest_official) {
175
	echo '[ !! ] Latest version: '.$latest_official." (This version: ".CUR_VER.")\n";
176
	$loc_good = false;
177
}
178
 
179
if ($loc_good) {
180
	echo "[ OK ]\n";
181
} else {
182
	$global_status=1;
183
}
184
 
185
# ---
186
 
187
echo "* Check if IANA has (probably) a TLD whois list in ".IANA_TLD_FOLDER."\n";
188
 
189
$x = cached_file(IANA_TLD_FOLDER, CACHE_FILE_DIR);
190
$loc_good = substr_count($x, '.txt">') == 1;
191
 
192
if ($loc_good) {
193
	echo "[ OK ]\n";
194
} else {
195
	$global_status=1;
196
	echo "[ !! ] Something has changed ! Please change rws_*() in the QA tool!\n";
197
}
198
 
199
# ---
200
 
201
echo "* Check if testcases require attention\n";
202
 
4 daniel-mar 203
$loc_good = true;
204
 
205
# First check tesetcases in background, if necessary
206
 
2 daniel-mar 207
$out = array();
4 daniel-mar 208
exec(DIR . "/testcases/batch --mode b", $out, $ec);
2 daniel-mar 209
 
4 daniel-mar 210
if ($ec > 2) {
211
	$loc_good = false;
212
	echo "[ !! ] testcases/batch error code $ec\n";
213
	echo trim(implode("\n", $out))."\n";
214
}
215
 
216
# Now check if testcases require attention
217
 
218
$out = array();
219
exec(DIR . '/testcases/status_short', $out, $ec);
220
 
221
if ($ec != 0) {
222
	$loc_good = false;
223
	echo trim(implode("\n", $out))."\n";
224
}
225
 
226
# Status?
227
 
2 daniel-mar 228
if ($loc_good) {
229
	echo "[ OK ]\n";
230
} else {
231
	$global_status=1;
232
}
233
 
234
# ---
235
 
236
echo "* Check the status of whois-ping\n";
237
 
4 daniel-mar 238
$loc_good = true;
239
 
240
# First ping the servers
241
 
2 daniel-mar 242
$out = array();
4 daniel-mar 243
exec(DIR . "/whois-ping/whoisping", $out, $ec);
2 daniel-mar 244
 
4 daniel-mar 245
if ($ec != 0) {
246
	$loc_good = false;
247
	echo "[ !! ] whois-ping/whoisping error code $ec\n";
248
}
249
 
250
# Now show errors (but only if a time treshold is exceeded)
251
 
252
$out = array();
253
exec(DIR . '/whois-ping/showerrors', $out, $ec);
254
 
255
if ($ec != 0) {
256
	$loc_good = false;
257
	echo trim(implode("\n", $out))."\n";
258
}
259
 
260
# Status?
261
 
2 daniel-mar 262
if ($loc_good) {
263
	echo "[ OK ]\n";
264
} else {
265
	$global_status=1;
266
}
267
 
268
# ---
269
 
270
echo "* Check syntax of all script files (Perl, PHP)\n";
271
 
272
$out = array();
4 daniel-mar 273
exec(DIR . '/syntax/global-syntax-check', $out, $ec);
2 daniel-mar 274
 
4 daniel-mar 275
$loc_good = $ec == 0;
276
 
2 daniel-mar 277
if ($loc_good) {
278
	echo "[ OK ]\n";
279
} else {
280
	$global_status=1;
281
	echo trim(implode("\n", $out))."\n";
282
}
283
 
284
# ---
285
 
286
exit($global_status);
287
 
288
# ---
289
 
290
function getLatestGWIversion() {
291
	$x = cached_file(DEBIAN_GWHOIS_PACKAGE_URL, CACHE_FILE_DIR);
292
	preg_match_all('@<br>(.*): all@isU', $x, $m);
293
	$m = $m[1];
294
	rsort($m);
295
	return $m[0]; // biggest version
296
}
297
 
298
// RWS = Root Whois Server List functions
299
// (needs to be updated as soon as IANA implements this service.)
300
function rws_get_list() {
301
	$result = array();
302
 
303
	$tld_cont = explode("\n", cached_file(ROOT_WHOIS_SERVER_LIST, CACHE_FILE_DIR));
304
 
305
	foreach ($tld_cont as &$c) {
306
		$c = trim($c);
307
		if ($c == '') continue;
308
		if ($c[0] == '#') continue;
309
		$ary = explode(" => ", $c);
310
		$tld = $ary[0];
311
		$whois = trim($ary[1]);
312
 
313
		$result[$tld] = $whois;
314
	}
315
 
316
	return $result;
317
}
318
 
319
function rws_is_live() {
320
	// The data is collected every week.
321
	return false;
322
}
323
 
324
function iana_get_whois($tld) {
325
	$out = QueryWhoisServer('whois.iana.org', $tld);
326
 
327
	if (strpos($out, 'domain:') === false) return false;
328
	if (!preg_match("@\nwhois:\\s*([^\\s]+)\n@ismU", $out, $m)) return false;
329
	return $m[1];
330
}
331
 
332
function gwi_getInstalledBaseVersion() {
333
	# TODO: auch andere dateien anschauen
334
 
335
	$pattern = file(DIR . '/../../main/pattern/001_subdomains');
336
	if (!preg_match('@#: version (.+)\+@iU', $pattern[0], $m)) return false;
337
 
338
	return $m[1];
339
}
340
 
341
function in_arrayi($needle, $haystack) {
342
	return in_array(strtolower($needle), array_map('strtolower', $haystack));
343
}
344
 
345
function reported_dead($whois) {
346
	$dead_servers_raw = file(DIR . '/../config/dead-servers.list');
347
	foreach ($dead_servers_raw as &$server) {
348
		$server = trim($server);
349
		if ($server == '') continue;
350
		if ($server[0] == '#') continue;
351
		if ($server == $whois) return true;
352
	}
353
	return false;
354
}