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