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