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