Subversion Repositories vgwhois

Rev

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
#
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__ . '/../../shared/php_includes/common_functions.inc.php';
17
require_once __DIR__ . '/rirs.inc.php';
18
 
19
$out = '';
20
$out .= "# TLDs\n";
11 daniel-mar 21
$out .= "# Automatically generated by ".__DIR__."/vgwhois-pattern-update\n";
2 daniel-mar 22
$out .= "# Generation timestamp: ".date('Y-m-d H:i:s \G\M\TO')."\n";
23
$out .= "\n";
24
 
25
$max_version = 0;
26
 
27
# ---
28
 
29
echo "Deleted TLD: Get deleted TLD list (".DELETED_TLD_LIST.")\n";
30
 
31
$iana_tld_data = cached_file(DELETED_TLD_LIST, CACHE_FILE_DIR);
32
$iana_tld_data = str_replace("\r", '', $iana_tld_data);
33
$iana_tld_data = trim($iana_tld_data);
34
$iana_tld_data = explode("\n", $iana_tld_data);
35
 
36
echo "Deleted TLD: Parsing...\n";
37
 
38
if (preg_match('@# Latest update detected on (.*)@', $iana_tld_data[0], $m)) {
39
	$version = $m[1];
40
	$version = substr($version, 0, 10);
41
	$version = str_replace('-', '', $version);
42
	if ($version > $max_version) $max_version = $version;
43
}
44
 
45
array_shift($iana_tld_data);
46
 
47
$tlds = implode('|', $iana_tld_data);
48
 
49
$iana_tld_data = implode("\n", $iana_tld_data);
50
 
51
$out .= "# Source: ($version) ".DELETED_TLD_LIST."\n";
52
$out .= "\n";
53
 
54
$out .= ":notice||Disallocated by IANA";
55
if ($tld_additional_params['iana'] != '') {
56
	$out .= '|prefix='.$tld_additional_params['iana'].'|';
57
}
58
$out .= "\n";
59
$out .= "^(tld\\s){0,1}($tlds)\$\n";
60
$out .= "\n";
61
 
62
# ---
63
 
64
echo "TLD: Get IANA delegation file (".IANA_TLD_REGISTRY.")\n";
65
 
3 daniel-mar 66
$iana_tld_data = explode("\n", cached_file(IANA_TLD_REGISTRY, CACHE_FILE_DIR));
67
$iana_tld_data = array_map('trim', $iana_tld_data);
2 daniel-mar 68
 
69
echo "TLD: Parsing...\n";
70
 
71
if (preg_match('@# Version (\d+), Last Updated (.*)@', $iana_tld_data[0], $m)) {
72
	$version = $m[1];
73
	$version = substr($version, 0, 8);
74
	if ($version > $max_version) $max_version = $version;
75
}
76
 
77
array_shift($iana_tld_data);
78
 
79
$tlds = implode('|', $iana_tld_data);
80
 
81
$iana_tld_data = implode("\n", $iana_tld_data);
82
 
83
$out .= "# Source: ($version) ".IANA_TLD_REGISTRY."\n";
84
$out .= "\n";
85
 
86
$out .= ":whois|".$rir_whois_server['iana'];
87
if ($tld_additional_params['iana'] != '') {
88
	$out .= '|prefix='.$tld_additional_params['iana'].'|';
89
}
90
$out .= "\n";
91
$out .= "^($tlds)\$\n";
92
$out .= "\n";
93
$out .= ":whois|".$rir_whois_server['iana']."|strip=tld ";
94
if ($tld_additional_params['iana'] != '') {
95
	$out .= '|prefix='.$tld_additional_params['iana'];
96
}
97
$out .= "|\n";
98
$out .= "^tld\\s\\S+\$\n";
99
$out .= "\n";
100
 
101
# ---
102
 
103
$out = "#: version $max_version\n\n".$out;
104
 
105
echo "TLD-Generator: Write to output file\n";
106
 
107
$h = fopen(PATTERN_DIR.'/tld', 'w') or die('Error opening file '.PATTERN_DIR.'/tld');
108
fwrite($h, $out) or die('Could not write to output file');
109
fclose($h);
110
 
111
echo "TLD-Generator: Finished\n";