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