Rev 5 | Rev 77 | 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 | # |
||
11 | daniel-mar | 5 | # VGWhoIs (ViaThinkSoft Global WhoIs, a fork of generic Whois / gwhois) |
5 | daniel-mar | 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 | error_reporting(E_ALL | E_NOTICE | E_STRICT | E_DEPRECATED); |
||
14 | |||
15 | require_once __DIR__ . '/config.inc.php'; |
||
16 | require_once __DIR__ . '/rirs.inc.php'; |
||
17 | |||
18 | function rir_get_md5_sum($url) { |
||
19 | // MD5 (/var/opt/ftp/pub/apnic/stats/apnic/delegated-apnic-extended-latest) = 82c291bb5d4363a3db254853c1602777 |
||
20 | // MD5 (delegated-lacnic-extended-latest) = 2815f0b5837d5658acf1659dff98bb52 |
||
21 | // MD5 (delegated-ripencc-extended-latest) = d4caddde59952c44b584cacf720ef836 |
||
22 | // MD5 (delegated-arin-latest) = 3137d635d5e647481af972ddc87e5570 |
||
23 | // MD5 (delegated-afrinic-latest) = 9c1cd55e8894402062282e3ebdcf53c8 <-- WRONG FILE NAME SHOWN FOR delegated-afrinic-extended-latest.md5! |
||
24 | |||
25 | $md5_cont = file_get_contents($url.'.md5'); |
||
26 | |||
27 | if (substr($md5_cont, 0, 5) != 'MD5 (') { |
||
28 | // Some older *.md5 files of AfriNIC have following formats: |
||
29 | // 73d5e32afd43eac0beb4635b6a9056c4 delegated-afrinic-latest |
||
30 | // since 2012-06-25 AfriNIC uses the "normal" format |
||
31 | // MD5 (delegated-afrinic-latest) = 9c1cd55e8894402062282e3ebdcf53c8 |
||
32 | // however, the filename is wrong (delegated-afrinic-latest instead of delegated-afrinic-extended-latest) |
||
33 | return substr($md5_cont, 0, 32); |
||
34 | } else { |
||
35 | // Die anderen RIRs |
||
36 | $tmp = explode(' = ', $md5_cont); |
||
37 | return trim($tmp[1]); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | function rir_download_report($url, $outfile, $do_md5_check = true) { |
||
42 | if (($do_md5_check) && (file_exists($outfile))) { |
||
43 | $md5_ist = md5_file($outfile); |
||
44 | $md5_soll = rir_get_md5_sum($url); |
||
45 | if ($md5_soll == $md5_ist) { |
||
46 | touch("$outfile.success"); |
||
47 | return true; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | $cont = file_get_contents($url); |
||
52 | |||
53 | if (!$cont) { |
||
54 | touch("$outfile.fail"); |
||
55 | return false; |
||
56 | } |
||
57 | |||
58 | if ($do_md5_check) { |
||
59 | $md5_ist = md5($cont); |
||
60 | if (!isset($md5_soll)) $md5_soll = rir_get_md5_sum($url); |
||
61 | if ($md5_soll != $md5_ist) { |
||
62 | touch("$outfile.fail"); |
||
63 | return false; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | $h = fopen($outfile, 'w'); |
||
68 | if (!$h) return false; |
||
69 | if (!fwrite($h, $cont)) { |
||
70 | touch("$outfile.fail"); |
||
71 | return false; |
||
72 | } |
||
73 | fclose($h); |
||
74 | |||
75 | touch("$outfile.success"); |
||
76 | return true; |
||
77 | } |
||
78 | |||
79 | $rirs[] = 'iana'; |
||
80 | |||
81 | @mkdir(RIRSTATS_CACHE_DIR.'/', 0777, true); |
||
82 | |||
83 | foreach ($rirs as $rir) { |
||
84 | $url = $rirstat_urls[$rir]; |
||
85 | |||
86 | $failcounter = 0; |
||
87 | while (!rir_download_report($url, RIRSTATS_CACHE_DIR."/$rir", $rir != 'iana')) { |
||
88 | $failcounter++; |
||
89 | echo "Retry downloading $rir stats ($failcounter)...\n"; |
||
90 | if ($failcounter > 100) break; |
||
91 | sleep(60); |
||
92 | } |
||
93 | } |