Rev 8 | 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 | require_once __DIR__ . '/config.inc.php'; |
||
14 | require_once __DIR__ . '/../../shared/php_includes/common_functions.inc.php'; |
||
15 | |||
16 | error_reporting(E_ALL | E_NOTICE | E_STRICT | E_DEPRECATED); |
||
17 | |||
18 | $iana_tld_data = null; |
||
19 | |||
20 | // Step 1: |
||
21 | // Check if in the meantime TLDs without an official whois server were updated to have one |
||
22 | // Attention/TODO: A change of the whois name still needs manual intervention! |
||
23 | |||
24 | $domains_cont_original = file_get_contents(DOMAINS_PATTERN_FILE); |
||
25 | |||
26 | $domains_cont_new = preg_replace_callback( |
||
27 | '@# TODO: Entry generated automatically\. Needs manual check\.\n:notice\|\|Whois server unknown \((.*)\)\n\\\.(.*)\$\n@imU', |
||
28 | function ($treffer) { |
||
29 | $in_all = $treffer[0]; |
||
30 | $in_ts = $treffer[1]; |
||
31 | $in_tld = $treffer[2]; |
||
32 | |||
33 | $days_passed = (time()-strtotime($treffer[1]))/(60*60*24); |
||
34 | if ($days_passed < DOMAINS_RECHECK_MISSING_WHOIS_SERVERS) { |
||
35 | return $in_all; // leave everything unchanged |
||
36 | } |
||
37 | |||
38 | $whois_serv = find_rootzone_whois_server($in_tld); |
||
39 | |||
40 | if (!$whois_serv) { |
||
41 | // Nothing found. Just update last check date. |
||
42 | return str_replace($in_ts, date('Y-m-d'), $in_all); |
||
43 | } else { |
||
44 | // Update the entry |
||
45 | return ":whois|$whois_serv\n.${in_tld}\$\n"; |
||
46 | } |
||
47 | }, |
||
48 | $domains_cont_original |
||
49 | ); |
||
50 | |||
51 | if ($domains_cont_original != $domains_cont_new) { |
||
52 | file_put_contents(DOMAINS_PATTERN_FILE, $domains_cont_new); |
||
53 | gwi_update_domains_patternfile(); |
||
54 | } |
||
55 | |||
56 | // Step 2: |
||
57 | // Search for new TLDs which are not in our pattern file |
||
58 | |||
3 | daniel-mar | 59 | if (!isset($iana_tld_data)) { |
60 | $iana_tld_data = explode("\n", cached_file(IANA_TLD_REGISTRY, CACHE_FILE_DIR)); |
||
61 | $iana_tld_data = array_map('trim', $iana_tld_data); |
||
62 | } |
||
2 | daniel-mar | 63 | |
64 | foreach ($iana_tld_data as $tld) { |
||
3 | daniel-mar | 65 | if ($tld == '') continue; |
2 | daniel-mar | 66 | if ($tld[0] == '#') continue; |
67 | |||
68 | $tld = strtolower($tld); |
||
69 | |||
70 | if (!does_exist($tld)) { |
||
71 | $whois_serv = find_rootzone_whois_server($tld); |
||
72 | |||
73 | $to_append = "\n"; |
||
74 | if ($whois_serv) { |
||
75 | $to_append .= ":whois|$whois_serv\n"; |
||
76 | } else { |
||
77 | $to_append .= "# TODO: Entry generated automatically. Needs manual check.\n"; |
||
78 | $to_append .= ":notice||Whois server unknown (".date('Y-m-d').")\n"; |
||
79 | } |
||
80 | $to_append .= "\\.$tld$\n"; |
||
81 | |||
82 | file_put_contents(DOMAINS_PATTERN_FILE, $to_append, FILE_APPEND); |
||
83 | |||
84 | gwi_update_domains_patternfile(); |
||
85 | |||
86 | echo "Added: $tld\n"; |
||
87 | } |
||
88 | |||
89 | } |
||
90 | |||
91 | # ------------------------------------------------------ |
||
92 | |||
93 | function does_exist($tld) { |
||
94 | $cont = get_united_pattern(); |
||
95 | $cont = preg_replace('@#[^\n]*\n@ismU', '', $cont); |
||
96 | $tld = strtolower($tld); |
||
97 | $cont = strtolower($cont); |
||
98 | $cont = str_replace(array('(', ')'), '', $cont); |
||
99 | return (strpos($cont, "\\.$tld\$\n") !== false); |
||
100 | } |
||
101 | |||
102 | function gwi_update_domains_patternfile() { |
||
103 | $now = date('Ymd'); |
||
104 | |||
105 | $pcont_original = file_get_contents(DOMAINS_PATTERN_FILE); |
||
106 | $pcont = $pcont_original; |
||
107 | |||
108 | $count = 0; |
||
109 | $pcont = preg_replace("@#: version (\\S+)@i", "#: version $now", $pcont, 1, $count); |
||
110 | |||
111 | if ($count == 0) { |
||
112 | // Add header |
||
113 | $pcont = "#: version $now\n". |
||
114 | "# Domains\n". |
||
11 | daniel-mar | 115 | "# This file can be updated by running \"vgwhois-pattern-update\", but it does only ADD new \"New gTLDs\"\n". |
2 | daniel-mar | 116 | "# --------------------------------------------------------------------\n". |
117 | "\n".$pcont; |
||
118 | } |
||
119 | |||
120 | if ($pcont != $pcont_original) { |
||
121 | file_put_contents(DOMAINS_PATTERN_FILE, $pcont); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | function find_rootzone_whois_server($tld) { |
||
126 | $whois_serv = iana_get_rootzone_whois_server($tld); |
||
127 | |||
128 | // Try to find undocumented whois servers |
||
129 | if (TRY_FINDING_HIDDEN_WHOIS_SERVERS) { |
||
130 | // TODO: also try out to use the URL of the homepage (in IANAs root DB) |
||
131 | if (!$whois_serv) { |
||
132 | $check_server = "whois.nic.$tld"; |
||
133 | if (gwitc_is_port_open($check_server, 43)) { |
||
134 | $whois_serv = $check_server; |
||
135 | } |
||
136 | } |
||
137 | if (!$whois_serv) { |
||
138 | $check_server = "whois.$tld"; |
||
139 | if (gwitc_is_port_open($check_server, 43)) { |
||
140 | $whois_serv = $check_server; |
||
141 | } |
||
142 | } |
||
143 | if (!$whois_serv) { |
||
144 | $check_server = "$tld"; |
||
145 | if (gwitc_is_port_open($check_server, 43)) { |
||
146 | $whois_serv = $check_server; |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | |||
151 | return $whois_serv; |
||
152 | } |
||
153 | |||
154 | function iana_get_rootzone_whois_server($tld) { |
||
155 | $tld = strtolower($tld); |
||
156 | $cont = QueryWhoisServer('whois.iana.org', $tld); |
||
157 | if (!preg_match('@whois:\\s*(\\S+)@i', $cont, $m)) return false; |
||
158 | return $m[1]; |
||
159 | } |