Subversion Repositories vgwhois

Rev

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