Subversion Repositories oidplus

Rev

Rev 183 | Rev 261 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
183 daniel-mar 1
#!/usr/bin/php
2
<?php
3
 
4
require_once __DIR__ . '/../includes/oidplus.inc.php';
5
 
6
OIDplus::init(false);
7
if (!defined('OIDINFO_API_URL')) {
8
	die("OIDINFO_API_URL not available (API is currently not public)\n");
9
}
10
 
11
define('VERBOSE', false);
12
define('DEFAULT_EMAIL', 'oidra@viathinksoft.de');
13
define('ALL_OID_LIST', '/home/oidplus/all_oids.txt'); // contains all OIDs (non-public file)
14
define('DESIRED_ROOT', '1.3.6.1.4.1.37476');
15
 
16
# ---
17
 
18
exec("cat ".escapeshellarg(ALL_OID_LIST)." | sort | grep '^".DESIRED_ROOT."'", $out, $ec);
19
 
20
foreach ($out as $oid) {
21
	$oid = trim($oid);
22
	if ($oid == '') continue;
23
 
24
	check_oid($oid);
25
}
26
 
27
function check_oid($oid, $root=DESIRED_ROOT) {
28
	$data = ft_get_oid_data($oid);
29
 
30
	// ASN.1 IDs
31
 
32
	if (!isset($data['oid']['identifier'])) $data['oid']['identifier'] = array();
33
	if (is_array($data['oid']['identifier'])) {
34
		asort($data['oid']['identifier']);
35
		$oidinfo = implode('|',$data['oid']['identifier']);
36
	} else {
37
		$oidinfo = $data['oid']['identifier'];
38
	}
39
	$oidplus = array();
40
	$resx = OIDplus::db()->query("select name from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = ?", array("oid:$oid"));
236 daniel-mar 41
	while ($rowx = $resx->fetch_array()) {
183 daniel-mar 42
		$oidplus[] = $rowx['name'];
43
	}
44
	asort($oidplus);
45
	$oidplus = implode('|',$oidplus);
46
 
47
	if ($oidinfo != $oidplus) {
48
		echo "ASN.1 : $oid (oidinfo '$oidinfo' vs oidplus '$oidplus')\n";
49
	}
50
 
51
	// Unicode Labels
52
 
53
	if (!isset($data['oid']['unicode-label'])) $data['oid']['unicode-label'] = array();
54
	if (is_array($data['oid']['unicode-label'])) {
55
		asort($data['oid']['unicode-label']);
56
		$oidinfo = implode('|',$data['oid']['unicode-label']);
57
	} else {
58
		$oidinfo = $data['oid']['unicode-label'];
59
	}
60
	$oidplus = array();
61
	$resx = OIDplus::db()->query("select name from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = ?", array("oid:$oid"));
236 daniel-mar 62
	while ($rowx = $resx->fetch_array()) {
183 daniel-mar 63
		$oidplus[] = $rowx['name'];
64
	}
65
	asort($oidplus);
66
	$oidplus = implode('|',$oidplus);
67
 
68
	if ($oidinfo != $oidplus) {
69
		echo "IRI : $oid (oidinfo '$oidinfo' vs oidplus '$oidplus')\n";
70
	}
71
}
72
 
73
echo "OK\n";
74
 
75
# ---
76
 
77
function ft_get_oid_data($oid) {
78
	$url = OIDINFO_API_URL . '&oid='.urlencode($oid);
79
	$cont_json = @file_get_contents($url);
80
	if (!$cont_json) {
81
		sleep(5);
82
                $cont_json = @file_get_contents($url);
83
                if (!$cont_json) return false;
84
	}
85
	$data = json_decode($cont_json,true);
86
 
87
	return $data;
88
}