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