Rev 5 | Rev 68 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5 | 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 | # Subprogram: OID over Whois |
6 | # Subprogram: OID over Whois |
7 | # |
7 | # |
8 | # (c) 2011-2019 by Daniel Marschall, ViaThinkSoft <info@daniel-marschall.de> |
8 | # (c) 2011-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 | # OID resolution over WhoIs |
13 | # OID resolution over WhoIs |
14 | # Not really whois, but handy! |
14 | # Not really whois, but handy! |
15 | 15 | ||
16 | # TODO: weitere oid repositories einbinden |
16 | # TODO: weitere oid repositories einbinden |
17 | # TODO: tabs |
17 | # TODO: tabs |
18 | # TODO: der encoding anzeigen |
18 | # TODO: der encoding anzeigen |
19 | # TODO ALVESTRAND_NO fertig machen (404 erkennung, formatierung usw) |
19 | # TODO ALVESTRAND_NO fertig machen (404 erkennung, formatierung usw) |
20 | 20 | ||
21 | require_once __DIR__ . '/../../shared/php_includes/common_functions.inc.php'; |
21 | require_once __DIR__ . '/../../shared/php_includes/common_functions.inc.php'; |
22 | 22 | ||
23 | define('WALK_UP', true); |
23 | define('WALK_UP', true); |
24 | define('ASK_FRANCE_TELECOM', true); |
24 | define('ASK_FRANCE_TELECOM', true); |
25 | define('ASK_ALVESTRAND_NO', false); |
25 | define('ASK_ALVESTRAND_NO', false); |
26 | 26 | ||
27 | $domain = $argv[1]; |
27 | $domain = $argv[1]; |
28 | 28 | ||
29 | # normalize to "2.999", removing leading zeros, urn:oid: and oid: as well as leading dot |
29 | # normalize to "2.999", removing leading zeros, urn:oid: and oid: as well as leading dot |
30 | $domain = normalize_oid($domain, false); |
30 | $domain = normalize_oid($domain, false); |
31 | 31 | ||
32 | // Check if the OID is correct and handle the special case of the root zone "oid:." |
32 | // Check if the OID is correct and handle the special case of the root zone "oid:." |
33 | $test_oid = explode('.', $domain, 2); |
33 | $test_oid = explode('.', $domain, 2); |
34 | if ($domain === '') { |
34 | if ($domain === '') { |
35 | echo "You cannot lookup the root zone of the OIDs.\n"; |
35 | echo "You cannot lookup the root zone of the OIDs.\n"; |
36 | echo "Please choose at least one of these root OIDs:\n"; |
36 | echo "Please choose at least one of these root OIDs:\n"; |
37 | echo "- itu-t(0)\n"; |
37 | echo "- itu-t(0)\n"; |
38 | echo "- iso(1)\n"; |
38 | echo "- iso(1)\n"; |
39 | echo "- joint-iso-itu-t(2)\n\n"; |
39 | echo "- joint-iso-itu-t(2)\n\n"; |
40 | # exit(1); |
40 | # exit(1); |
41 | exit; |
41 | exit; |
42 | } else { |
42 | } else { |
43 | $first_arc = $test_oid[0]; |
43 | $first_arc = $test_oid[0]; |
44 | $oid_ok = ($first_arc === '0') || ($first_arc === '1') || ($first_arc === '2'); |
44 | $oid_ok = ($first_arc === '0') || ($first_arc === '1') || ($first_arc === '2'); |
45 | if (!$oid_ok) { |
45 | if (!$oid_ok) { |
46 | echo "The OID is invalid. The root arc needs to be 0, 1 or 2\n\n"; |
46 | echo "The OID is invalid. The root arc needs to be 0, 1 or 2\n\n"; |
47 | # exit(1); |
47 | # exit(1); |
48 | exit; |
48 | exit; |
49 | } |
49 | } |
50 | } |
50 | } |
51 | 51 | ||
52 | ob_start(); |
52 | ob_start(); |
53 | 53 | ||
54 | if (ASK_FRANCE_TELECOM) { |
54 | if (ASK_FRANCE_TELECOM) { |
55 | check_oidinfo_com($domain); |
55 | check_oidinfo_com($domain); |
56 | } |
56 | } |
57 | 57 | ||
58 | if (ASK_ALVESTRAND_NO) { |
58 | if (ASK_ALVESTRAND_NO) { |
59 | if (ASK_FRANCE_TELECOM) { |
59 | if (ASK_FRANCE_TELECOM) { |
60 | echo "\n\n"; |
60 | echo "\n\n"; |
61 | echo "% ===========================================================\n"; |
61 | echo "% ===========================================================\n"; |
62 | echo "% ===========================================================\n"; |
62 | echo "% ===========================================================\n"; |
63 | echo "\n"; |
63 | echo "\n"; |
64 | } |
64 | } |
65 | check_alvestrand_no($domain); |
65 | check_alvestrand_no($domain); |
66 | } |
66 | } |
67 | 67 | ||
68 | $x = ob_get_contents(); |
68 | $x = ob_get_contents(); |
69 | ob_end_clean(); |
69 | ob_end_clean(); |
70 | 70 | ||
71 | $x = wordwrap($x, 75, "\n", false); |
71 | $x = wordwrap($x, 75, "\n", false); |
72 | echo html_entity_decode($x, ENT_QUOTES, 'utf-8'); |
72 | echo html_entity_decode($x, ENT_QUOTES, 'utf-8'); |
73 | #echo $x; |
73 | #echo $x; |
74 | 74 | ||
75 | # ----------------- FRANCE TELECOM OID REPOSITORY |
75 | # ----------------- FRANCE TELECOM OID REPOSITORY |
76 | 76 | ||
77 | # Callback for Link-Replacing |
77 | # Callback for Link-Replacing |
78 | function fto_link_replacing_cb($treffer) { |
78 | function fto_link_replacing_cb($treffer) { |
79 | # '[$4] <$2>' |
79 | # '[$4] <$2>' |
80 | 80 | ||
81 | $name = $treffer[4]; |
81 | $name = $treffer[4]; |
82 | $link = $treffer[2]; |
82 | $link = $treffer[2]; |
83 | 83 | ||
84 | if (trim(strip_tags($name)) == '') { |
84 | if (trim(strip_tags($name)) == '') { |
85 | return ''; |
85 | return ''; |
86 | } |
86 | } |
87 | 87 | ||
88 | # relative -> absolute links |
88 | # relative -> absolute links |
89 | if (substr($link, 0, 3) == '../') { |
89 | if (substr($link, 0, 3) == '../') { |
90 | $link = 'http://oid-info.com/'.$link; |
90 | $link = 'http://oid-info.com/'.$link; |
91 | } else if ($link[0] == '/') { |
91 | } else if ($link[0] == '/') { |
92 | $link = 'http://oid-info.com'.$link; |
92 | $link = 'http://oid-info.com'.$link; |
93 | } |
93 | } |
94 | 94 | ||
95 | return $name . ' <' . $link . '>'; |
95 | return $name . ' <' . $link . '>'; |
96 | } |
96 | } |
97 | 97 | ||
98 | function check_oidinfo_com($oid) { |
98 | function check_oidinfo_com($oid) { |
99 | $url = "http://oid-info.com/get/$oid"; |
99 | $url = "http://oid-info.com/get/$oid"; |
100 | 100 | ||
101 | $x = file_get_contents2($url); |
101 | $x = file_get_contents2($url); |
102 | 102 | ||
103 | $father = fto_find_father($x); |
103 | $father = fto_find_father($x); |
104 | 104 | ||
105 | $err = 'The following error must be corrected to take your request into account:'; |
105 | $err = 'The following error must be corrected to take your request into account:'; |
106 | 106 | ||
107 | if (strpos($x, $err) !== false) { |
107 | if (strpos($x, $err) !== false) { |
108 | echo "\nError:\n"; # TODO: warum \n am anfang? |
108 | echo "\nError:\n"; # TODO: warum \n am anfang? |
109 | 109 | ||
110 | preg_match_all('|<font color="#ff0000">(.*)</font>|ismU', $x, $m); |
110 | preg_match_all('|<font color="#ff0000">(.*)</font>|ismU', $x, $m); |
111 | 111 | ||
112 | $x = implode("\n", $m[1]); |
112 | $x = implode("\n", $m[1]); |
113 | 113 | ||
114 | $x = strip_tags($x); |
114 | $x = strip_tags($x); |
115 | 115 | ||
116 | $x = trim($x); |
116 | $x = trim($x); |
117 | 117 | ||
118 | echo $x; |
118 | echo $x; |
119 | 119 | ||
120 | if (WALK_UP && ($father !== false)) { |
120 | if (WALK_UP && ($father !== false)) { |
121 | echo "\n\n"; |
121 | echo "\n\n"; |
122 | echo "% ===========================================================\n"; |
122 | echo "% ===========================================================\n"; |
123 | echo "% Requesting father OID '$father'\n"; |
123 | echo "% Requesting father OID '$father'\n"; |
124 | echo check_oidinfo_com($father); |
124 | echo check_oidinfo_com($father); |
125 | } |
125 | } |
126 | 126 | ||
127 | return; |
127 | return; |
128 | } else { |
128 | } else { |
129 | if ((strpos($x, '<td>(<a href="/faq.htm#17">ASN.1</a> notation)</td>') === false) && |
129 | if ((strpos($x, '<td>(<a href="/faq.htm#17">ASN.1</a> notation)</td>') === false) && |
130 | (strpos($x, 'This OID description has not yet been validated') === false)) { |
130 | (strpos($x, 'This OID description has not yet been validated') === false)) { |
131 | echo "\nUnknown error! Please try again later.\n"; |
131 | echo "\nUnknown error! Please try again later.\n"; |
132 | 132 | ||
133 | if (WALK_UP && ($father !== false)) { |
133 | if (WALK_UP && ($father !== false)) { |
134 | echo "\n\n"; |
134 | echo "\n\n"; |
135 | echo "% ===========================================================\n"; |
135 | echo "% ===========================================================\n"; |
136 | echo "% Requesting father OID '$father'\n"; |
136 | echo "% Requesting father OID '$father'\n"; |
137 | echo check_oidinfo_com($father); |
137 | echo check_oidinfo_com($father); |
138 | } |
138 | } |
139 | 139 | ||
140 | return; |
140 | return; |
141 | } |
141 | } |
142 | } |
142 | } |
143 | 143 | ||
144 | if (strpos($x, 'This OID description has not yet been validated') !== false) { |
144 | if (strpos($x, 'This OID description has not yet been validated') !== false) { |
145 | // <i>This OID description has not yet been validated by the OID repository administrator and/or the registrant of the superior OID.</i> |
145 | // <i>This OID description has not yet been validated by the OID repository administrator and/or the registrant of the superior OID.</i> |
146 | preg_match_all('|<i>(.+?)</i>|', $x, $m); |
146 | preg_match_all('|<i>(.+?)</i>|', $x, $m); |
147 | echo $m[1][0]; |
147 | echo $m[1][0]; |
148 | 148 | ||
149 | if (WALK_UP && ($father !== false)) { |
149 | if (WALK_UP && ($father !== false)) { |
150 | echo "\n\n"; |
150 | echo "\n\n"; |
151 | echo "% ===========================================================\n"; |
151 | echo "% ===========================================================\n"; |
152 | echo "% Requesting father OID '$father'\n"; |
152 | echo "% Requesting father OID '$father'\n"; |
153 | echo check_oidinfo_com($father); |
153 | echo check_oidinfo_com($father); |
154 | } |
154 | } |
155 | 155 | ||
156 | return; |
156 | return; |
157 | } |
157 | } |
158 | 158 | ||
159 | $x = str_replace('<strong>Short URL for this page</strong>'."\n:", '', $x); |
159 | $x = str_replace('<strong>Short URL for this page</strong>'."\n:", '', $x); |
160 | $x = str_replace('<font size="-2">Webmaster</font></td>', '</td>', $x); |
160 | $x = str_replace('<font size="-2">Webmaster</font></td>', '</td>', $x); |
161 | $x = str_replace('<strong>Disclaimer:</strong>', "\n\n".'<strong>Disclaimer:</strong>'."\n\n", $x); |
161 | $x = str_replace('<strong>Disclaimer:</strong>', "\n\n".'<strong>Disclaimer:</strong>'."\n\n", $x); |
162 | 162 | ||
163 | $del = '<tr bgcolor="#CCCCCC">'; |
163 | $del = '<tr bgcolor="#CCCCCC">'; |
164 | $ary = explode($del, $x, 2); |
164 | $ary = explode($del, $x, 2); |
165 | if (isset($ary[1])) $x = $ary[1]; |
165 | if (isset($ary[1])) $x = $ary[1]; |
166 | 166 | ||
167 | echo "% Parsing via regex from '$url'\n\n"; |
167 | echo "% Parsing via regex from '$url'\n\n"; |
168 | 168 | ||
169 | $x = preg_replace_callback('|<a\s([^>]*?)href="(.*)"([^>]*?)>(.*)</a>|ismU', 'fto_link_replacing_cb', $x); |
169 | $x = preg_replace_callback('|<a\s([^>]*?)href="(.*)"([^>]*?)>(.*)</a>|ismU', 'fto_link_replacing_cb', $x); |
170 | 170 | ||
171 | $x = strip_tags($x); |
171 | $x = strip_tags($x); |
172 | 172 | ||
173 | $x = str_replace(' ', ' ', $x); |
173 | $x = str_replace(' ', ' ', $x); |
174 | $x = str_replace(' ', ' ', $x); |
174 | $x = str_replace(' ', ' ', $x); |
175 | 175 | ||
176 | $x = html_entity_decode($x); |
176 | $x = html_entity_decode($x); |
177 | 177 | ||
178 | $x = preg_replace("| +|", ' ', $x); |
178 | $x = preg_replace("| +|", ' ', $x); |
179 | $x = preg_replace("|\n *|", "\n", $x); |
179 | $x = preg_replace("|\n *|", "\n", $x); |
180 | $x = preg_replace("| *\n|", "\n", $x); |
180 | $x = preg_replace("| *\n|", "\n", $x); |
181 | $x = preg_replace("|\n+|", "\n", $x); |
181 | $x = preg_replace("|\n+|", "\n", $x); |
182 | 182 | ||
183 | $x = preg_replace('|<mailto:(.*)&(.*)>|ismU', '<$1@$2>', $x); |
183 | $x = preg_replace('|<mailto:(.*)&(.*)>|ismU', '<$1@$2>', $x); |
184 | $x = str_replace("<#top>\n", '', $x); |
184 | $x = str_replace("<#top>\n", '', $x); |
185 | 185 | ||
186 | $x = str_replace('(OID-IRI <http://oid-info.com/faq.htm#iri> notation)', '(OID-IRI notation)', $x); |
186 | $x = str_replace('(OID-IRI <http://oid-info.com/faq.htm#iri> notation)', '(OID-IRI notation)', $x); |
187 | $x = str_replace('(ASN.1 <http://oid-info.com/faq.htm#17> notation)', '(ASN.1 notation)', $x); |
187 | $x = str_replace('(ASN.1 <http://oid-info.com/faq.htm#17> notation)', '(ASN.1 notation)', $x); |
188 | $x = str_replace('(dot <http://oid-info.com/faq.htm#14> notation)', '(dot notation)', $x); |
188 | $x = str_replace('(dot <http://oid-info.com/faq.htm#14> notation)', '(dot notation)', $x); |
189 | $x = str_replace(' <http://oid-info.com/faq.htm#iri>', '', $x); |
189 | $x = str_replace(' <http://oid-info.com/faq.htm#iri>', '', $x); |
190 | 190 | ||
191 | 191 | ||
192 | $prev_swap_lines = array( |
192 | $prev_swap_lines = array( |
193 | '(ASN.1 notation)', |
193 | '(ASN.1 notation)', |
194 | '(dot notation)', |
194 | '(dot notation)', |
195 | '(OID-IRI notation)', |
195 | '(OID-IRI notation)', |
196 | ); |
196 | ); |
197 | 197 | ||
198 | $ary = explode("\n", $x); |
198 | $ary = explode("\n", $x); |
199 | foreach ($prev_swap_lines as $s) { |
199 | foreach ($prev_swap_lines as $s) { |
200 | foreach ($ary as $n => $l) { |
200 | foreach ($ary as $n => $l) { |
201 | if ($l == $s) { |
201 | if ($l == $s) { |
202 | $tmp = $ary[$n-1]; |
202 | $tmp = $ary[$n-1]; |
203 | $ary[$n-1] = $ary[$n]; |
203 | $ary[$n-1] = $ary[$n]; |
204 | $ary[$n] = $tmp; |
204 | $ary[$n] = $tmp; |
205 | } |
205 | } |
206 | } |
206 | } |
207 | } |
207 | } |
208 | $x = implode("\n", $ary); |
208 | $x = implode("\n", $ary); |
209 | 209 | ||
210 | foreach ($prev_swap_lines as $s) { |
210 | foreach ($prev_swap_lines as $s) { |
211 | $sx = str_replace('(', '', $s); |
211 | $sx = str_replace('(', '', $s); |
212 | $sx = str_replace(')', '', $sx); |
212 | $sx = str_replace(')', '', $sx); |
213 | $x = str_replace("$s\n", "$sx: ", $x); |
213 | $x = str_replace("$s\n", "$sx: ", $x); |
214 | } |
214 | } |
215 | 215 | ||
216 | $ary = explode("\n", $x); |
216 | $ary = explode("\n", $x); |
217 | $c = count($ary); |
217 | $c = count($ary); |
218 | $tmp = $ary[$c-2]; |
218 | $tmp = $ary[$c-2]; |
219 | $ary[$c-2] = "Last modified:\n$tmp"; |
219 | $ary[$c-2] = "Last modified:\n$tmp"; |
220 | $x = implode("\n", $ary); |
220 | $x = implode("\n", $ary); |
221 | 221 | ||
222 | $x = preg_replace("|\nFirst Registration Authority$|ismU", "\nFirst Registration Authority:", $x); |
222 | $x = preg_replace("|\nFirst Registration Authority$|ismU", "\nFirst Registration Authority:", $x); |
223 | $x = preg_replace("|\nCurrent Registration Authority$|ismU", "\nCurrent Registration Authority:", $x); |
223 | $x = preg_replace("|\nCurrent Registration Authority$|ismU", "\nCurrent Registration Authority:", $x); |
224 | 224 | ||
225 | $special_words = array( |
225 | $special_words = array( |
226 | 'Name:', |
226 | 'Name:', |
227 | 'Address:', |
227 | 'Address:', |
228 | 'Phone:', |
228 | 'Phone:', |
229 | 'Fax:', |
229 | 'Fax:', |
230 | 'Creation date:' |
230 | 'Creation date:' |
231 | ); |
231 | ); |
232 | 232 | ||
233 | foreach ($special_words as $s) { |
233 | foreach ($special_words as $s) { |
234 | $x = str_replace("$s\n", "$s ", $x); |
234 | $x = str_replace("$s\n", "$s ", $x); |
235 | } |
235 | } |
236 | 236 | ||
237 | $special_words = array( |
237 | $special_words = array( |
238 | 'OID:', |
238 | 'OID:', |
239 | 'Information:', |
239 | 'Information:', |
240 | 'Description:', |
240 | 'Description:', |
241 | 'Disclaimer:', |
241 | 'Disclaimer:', |
242 | 'Last modified:', |
242 | 'Last modified:', |
243 | 'First Registration Authority:', |
243 | 'First Registration Authority:', |
244 | 'Current Registration Authority:' |
244 | 'Current Registration Authority:' |
245 | ); |
245 | ); |
246 | 246 | ||
247 | foreach ($special_words as $s) { |
247 | foreach ($special_words as $s) { |
248 | $x = str_replace("\n$s\n", "\n\n".strtoupper($s)."\n\n", $x); |
248 | $x = str_replace("\n$s\n", "\n\n".strtoupper($s)."\n\n", $x); |
249 | } |
249 | } |
250 | 250 | ||
251 | $x = preg_replace("/To contact the (first|current) Registration Authority, replace \"&\" by \"@\" in the email address\n/ismU", '', $x); |
251 | $x = preg_replace("/To contact the (first|current) Registration Authority, replace \"&\" by \"@\" in the email address\n/ismU", '', $x); |
252 | $x = preg_replace("/Short URL for this page:\n/ismU", '', $x); |
252 | $x = preg_replace("/Short URL for this page:\n/ismU", '', $x); |
253 | 253 | ||
254 | $x = trim($x); |
254 | $x = trim($x); |
255 | 255 | ||
256 | $x = utf8_encode($x); |
256 | $x = utf8_encode($x); |
257 | 257 | ||
258 | echo $x; |
258 | echo $x; |
259 | 259 | ||
260 | if (WALK_UP && ($father !== false)) { |
260 | if (WALK_UP && ($father !== false)) { |
261 | echo "\n\n"; |
261 | echo "\n\n"; |
262 | echo "% ===========================================================\n"; |
262 | echo "% ===========================================================\n"; |
263 | echo "% Requesting father OID '$father'\n"; |
263 | echo "% Requesting father OID '$father'\n"; |
264 | echo check_oidinfo_com($father); |
264 | echo check_oidinfo_com($father); |
265 | } |
265 | } |
266 | } |
266 | } |
267 | 267 | ||
268 | function fto_find_father($content) { |
268 | function fto_find_father($content) { |
269 | 269 | ||
270 | # Works for... |
270 | # Works for... |
271 | # ... root OIDS, e.g. 2 |
271 | # ... root OIDS, e.g. 2 |
272 | # ... existing OIDs, e.g. 2.999 |
272 | # ... existing OIDs, e.g. 2.999 |
273 | # ... non existing OIDs, 2.999.1 and 2.999.1.2 |
273 | # ... non existing OIDs, 2.999.1 and 2.999.1.2 |
274 | # ... orphan OIDs, e.g. 1.3.6.1.4.1.311.1.1.3.1.2 |
274 | # ... orphan OIDs, e.g. 1.3.6.1.4.1.311.1.1.3.1.2 |
275 | # ... non validated OIDs... |
275 | # ... non validated OIDs... |
276 | 276 | ||
277 | $content = str_replace('<img src="/images/bullet.gif" width="10" height="8" border="0"><a href="/basic-search.htm">', '', $content); |
277 | $content = str_replace('<img src="/images/bullet.gif" width="10" height="8" border="0"><a href="/basic-search.htm">', '', $content); |
278 | 278 | ||
279 | // For non validated OIDs |
279 | // For non validated OIDs |
280 | $content = str_replace('<br><img src="/images/bullet.gif" width="10" height="8" border="0"><a href="/cgi-bin/manage?father_oid=', '', $content); |
280 | $content = str_replace('<br><img src="/images/bullet.gif" width="10" height="8" border="0"><a href="/cgi-bin/manage?father_oid=', '', $content); |
281 | 281 | ||
282 | $ary = explode('<font size="+2" color="#FF5500"><strong>OID description</strong></font>', $content, 2); |
282 | $ary = explode('<font size="+2" color="#FF5500"><strong>OID description</strong></font>', $content, 2); |
283 | $content = $ary[0]; |
283 | $content = $ary[0]; |
284 | 284 | ||
285 | preg_match_all('|<img src="/images/bullet.gif" width="10" height="8" border="0"><a href="(.*)">|ismU', $content, $m); |
285 | preg_match_all('|<img src="/images/bullet.gif" width="10" height="8" border="0"><a href="(.*)">|ismU', $content, $m); |
286 | 286 | ||
287 | $c = count($m[1]); |
287 | $c = count($m[1]); |
288 | 288 | ||
289 | if ($c == 0) return false; |
289 | if ($c == 0) return false; |
290 | 290 | ||
291 | $last = $m[1][$c-1]; |
291 | $last = $m[1][$c-1]; |
292 | $last = str_replace('/cgi-bin/manage?action=create&oid=', '', $last); |
292 | $last = str_replace('/cgi-bin/manage?action=create&oid=', '', $last); |
293 | $last = str_replace('http://www.oid-info.com/get/', '', $last); |
293 | $last = str_replace('http://www.oid-info.com/get/', '', $last); |
294 | $last = str_replace('http://oid-info.com/get/', '', $last); |
294 | $last = str_replace('http://oid-info.com/get/', '', $last); |
295 | 295 | ||
296 | return $last; |
296 | return $last; |
297 | } |
297 | } |
298 | 298 | ||
299 | # ----------------- ALVESTRAND.NO |
299 | # ----------------- ALVESTRAND.NO |
300 | # Note that oid-info.com usually contains all OIDs in alvestrands repository. |
300 | # Note that oid-info.com usually contains all OIDs in alvestrands repository. |
301 | 301 | ||
302 | # todo: + submissions checken (not proofread) |
302 | # todo: + submissions checken (not proofread) |
303 | # todo: 404 |
303 | # todo: 404 |
304 | # todo: fertig |
304 | # todo: fertig |
305 | # todo: <p> als \n werten, alles andere als nichts |
305 | # todo: <p> als \n werten, alles andere als nichts |
306 | 306 | ||
307 | # Callback for Link-Replacing |
307 | # Callback for Link-Replacing |
308 | function alv_link_replacing_cb($treffer) { |
308 | function alv_link_replacing_cb($treffer) { |
309 | # '[$4] <$2>' |
309 | # '[$4] <$2>' |
310 | 310 | ||
311 | $name = $treffer[4]; |
311 | $name = $treffer[4]; |
312 | $link = $treffer[2]; |
312 | $link = $treffer[2]; |
313 | 313 | ||
314 | if (trim(strip_tags($name)) == '') { |
314 | if (trim(strip_tags($name)) == '') { |
315 | return ''; |
315 | return ''; |
316 | } |
316 | } |
317 | 317 | ||
318 | # relative -> absolute links |
318 | # relative -> absolute links |
319 | if (substr($link, 0, 3) == '../') { |
319 | if (substr($link, 0, 3) == '../') { |
320 | $link = 'http://www.alvestrand.no/'.$link; |
320 | $link = 'http://www.alvestrand.no/'.$link; |
321 | } else if ($link[0] == '/') { |
321 | } else if ($link[0] == '/') { |
322 | $link = 'http://www.alvestrand.no'.$link; |
322 | $link = 'http://www.alvestrand.no'.$link; |
323 | } |
323 | } |
324 | 324 | ||
325 | return $name . ' <' . $link . '>'; |
325 | return $name . ' <' . $link . '>'; |
326 | } |
326 | } |
327 | 327 | ||
328 | function check_alvestrand_no($oid) { |
328 | function check_alvestrand_no($oid) { |
329 | $oid = convert_to_dot($oid); |
329 | $oid = convert_to_dot($oid); |
330 | 330 | ||
331 | $father = oid_up($oid); |
331 | $father = oid_up($oid); |
332 | if ($father == $oid) $father = false; |
332 | if ($father == $oid) $father = false; |
333 | 333 | ||
334 | $url = "http://www.alvestrand.no/objectid/$oid.html"; |
334 | $url = "http://www.alvestrand.no/objectid/$oid.html"; |
335 | 335 | ||
336 | $x = file_get_contents2($url); |
336 | $x = file_get_contents2($url); |
337 | 337 | ||
338 | echo "% Parsing via regex from '$url'\n\n"; |
338 | echo "% Parsing via regex from '$url'\n\n"; |
339 | 339 | ||
340 | $x = preg_replace_callback('|<a\s([^>]*?)href="(.*)"([^>]*?)>(.*)</a>|ismU', 'alv_link_replacing_cb', $x); |
340 | $x = preg_replace_callback('|<a\s([^>]*?)href="(.*)"([^>]*?)>(.*)</a>|ismU', 'alv_link_replacing_cb', $x); |
341 | 341 | ||
342 | $x = strip_tags($x); |
342 | $x = strip_tags($x); |
343 | 343 | ||
344 | $x = str_replace(' ', ' ', $x); |
344 | $x = str_replace(' ', ' ', $x); |
345 | $x = str_replace(' ', ' ', $x); |
345 | $x = str_replace(' ', ' ', $x); |
346 | 346 | ||
347 | $x = html_entity_decode($x); |
347 | $x = html_entity_decode($x); |
348 | 348 | ||
349 | $x = preg_replace("| +|", ' ', $x); |
349 | $x = preg_replace("| +|", ' ', $x); |
350 | $x = preg_replace("|\n *|", "\n", $x); |
350 | $x = preg_replace("|\n *|", "\n", $x); |
351 | $x = preg_replace("| *\n|", "\n", $x); |
351 | $x = preg_replace("| *\n|", "\n", $x); |
352 | $x = preg_replace("|\n+|", "\n", $x); |
352 | $x = preg_replace("|\n+|", "\n", $x); |
353 | 353 | ||
354 | $x = preg_replace('|<mailto:(.*)&(.*)>|ismU', '<$1@$2>', $x); |
354 | $x = preg_replace('|<mailto:(.*)&(.*)>|ismU', '<$1@$2>', $x); |
355 | 355 | ||
356 | $x = preg_replace('|Superior references(.*)Incoming OIDs <submissions> that have not been proofread yet|ismU', '', $x); |
356 | $x = preg_replace('|Superior references(.*)Incoming OIDs <submissions> that have not been proofread yet|ismU', '', $x); |
357 | 357 | ||
358 | $x = trim($x); |
358 | $x = trim($x); |
359 | 359 | ||
360 | echo $x; |
360 | echo $x; |
361 | 361 | ||
362 | if (WALK_UP && ($father !== false)) { |
362 | if (WALK_UP && ($father !== false)) { |
363 | echo "\n\n"; |
363 | echo "\n\n"; |
364 | echo "% ===========================================================\n"; |
364 | echo "% ===========================================================\n"; |
365 | echo "% Requesting father OID '$father'\n"; |
365 | echo "% Requesting father OID '$father'\n"; |
366 | echo check_alvestrand_no($father); |
366 | echo check_alvestrand_no($father); |
367 | } |
367 | } |
368 | } |
368 | } |
369 | 369 | ||
370 | function oid_up($oid) { |
370 | function oid_up($oid) { |
371 | $p = strrpos($oid, '.'); |
371 | $p = strrpos($oid, '.'); |
372 | if ($p === false) return $oid; |
372 | if ($p === false) return $oid; |
373 | return substr($oid, 0, $p); |
373 | return substr($oid, 0, $p); |
374 | } |
374 | } |
375 | 375 | ||
376 | function convert_to_dot($oid) { |
376 | function convert_to_dot($oid) { |
377 | // {joint-iso-itu-t(2) example(999) 1 2 3} --> 2.999.1.2.3 |
377 | // {joint-iso-itu-t(2) example(999) 1 2 3} --> 2.999.1.2.3 |
378 | // 2.999 --> 2.999 |
378 | // 2.999 --> 2.999 |
379 | // joint-iso-itu-t.999 --> 2.999 |
379 | // joint-iso-itu-t.999 --> 2.999 |
380 | 380 | ||
381 | $oid = str_replace('.', ' ', $oid); |
381 | $oid = str_replace('.', ' ', $oid); |
382 | 382 | ||
383 | # Standardized identifiers |
383 | # Standardized identifiers |
384 | $oid = " $oid "; |
384 | $oid = " $oid "; |
385 | $oid = str_replace(' ccitt ', '0 ', $oid); |
385 | $oid = str_replace(' ccitt ', '0 ', $oid); |
386 | $oid = str_replace(' itu-r ', '0 ', $oid); |
386 | $oid = str_replace(' itu-r ', '0 ', $oid); |
387 | $oid = str_replace(' itu-t ', '0 ', $oid); |
387 | $oid = str_replace(' itu-t ', '0 ', $oid); |
388 | $oid = str_replace(' iso ', '1 ', $oid); |
388 | $oid = str_replace(' iso ', '1 ', $oid); |
389 | $oid = str_replace(' joint-iso-ccitt ', '2 ', $oid); |
389 | $oid = str_replace(' joint-iso-ccitt ', '2 ', $oid); |
390 | $oid = str_replace(' joint-iso-itu-t ', '2 ', $oid); |
390 | $oid = str_replace(' joint-iso-itu-t ', '2 ', $oid); |
391 | 391 | ||
392 | $oid = preg_replace("|([^0123456789 ]*)|ismU", "", $oid); |
392 | $oid = preg_replace("|([^0123456789 ]*)|ismU", "", $oid); |
393 | $oid = trim($oid); |
393 | $oid = trim($oid); |
394 | $oid = str_replace(' ', '.', $oid); |
394 | $oid = str_replace(' ', '.', $oid); |
395 | return $oid; |
395 | return $oid; |
396 | } |
396 | } |