Subversion Repositories vgwhois

Rev

Rev 77 | 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
#
148 daniel-mar 8
#  (c) 2012-2024 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) {
148 daniel-mar 46
			@unlink("$outfile.fail");
47
			@touch("$outfile.success");
2 daniel-mar 48
			return true;
49
		}
50
	}
51
 
52
	$cont = file_get_contents($url);
53
 
54
	if (!$cont) {
148 daniel-mar 55
		@unlink("$outfile.success");
56
		@touch("$outfile.fail");
2 daniel-mar 57
		return false;
58
	}
59
 
60
	if ($do_md5_check) {
61
		$md5_ist = md5($cont);
62
		if (!isset($md5_soll)) $md5_soll = rir_get_md5_sum($url);
63
		if ($md5_soll != $md5_ist) {
148 daniel-mar 64
			@unlink("$outfile.success");
65
			@touch("$outfile.fail");
2 daniel-mar 66
			return false;
67
		}
68
	}
69
 
70
	$h = fopen($outfile, 'w');
71
	if (!$h) return false;
72
	if (!fwrite($h, $cont)) {
148 daniel-mar 73
		@unlink("$outfile.success");
74
		@touch("$outfile.fail");
2 daniel-mar 75
		return false;
76
	}
77
	fclose($h);
78
 
148 daniel-mar 79
	@unlink("$outfile.fail");
80
	@touch("$outfile.success");
2 daniel-mar 81
	return true;
82
}
83
 
84
$rirs[] = 'iana';
85
 
86
@mkdir(RIRSTATS_CACHE_DIR.'/', 0777, true);
87
 
88
foreach ($rirs as $rir) {
77 daniel-mar 89
	if (!isset($rirstat_urls[$rir])) continue;
90
 
2 daniel-mar 91
	$url = $rirstat_urls[$rir];
92
 
93
	$failcounter = 0;
94
	while (!rir_download_report($url, RIRSTATS_CACHE_DIR."/$rir", $rir != 'iana')) {
95
		$failcounter++;
96
		echo "Retry downloading $rir stats ($failcounter)...\n";
97
		if ($failcounter > 100) break;
98
		sleep(60);
99
	}
100
}