Subversion Repositories oidplus

Rev

Rev 261 | Rev 557 | 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
 
511 daniel-mar 4
/*
5
 * OIDplus 2.0
6
 * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
 
183 daniel-mar 21
require_once __DIR__ . '/../includes/oidplus.inc.php';
22
 
23
OIDplus::init(false);
261 daniel-mar 24
if (!OIDplus::baseConfig()->exists('OIDINFO_API_URL')) {
183 daniel-mar 25
	die("OIDINFO_API_URL not available (API is currently not public)\n");
26
}
27
 
28
define('VERBOSE', false);
29
define('DEFAULT_EMAIL', 'oidra@viathinksoft.de');
30
define('ALL_OID_LIST', '/home/oidplus/all_oids.txt'); // contains all OIDs (non-public file)
31
define('DESIRED_ROOT', '1.3.6.1.4.1.37476');
32
 
33
# ---
34
 
35
exec("cat ".escapeshellarg(ALL_OID_LIST)." | sort | grep '^".DESIRED_ROOT."'", $out, $ec);
36
 
37
foreach ($out as $oid) {
38
	$oid = trim($oid);
39
	if ($oid == '') continue;
40
 
41
	check_oid($oid);
42
}
43
 
44
function check_oid($oid, $root=DESIRED_ROOT) {
45
	$data = ft_get_oid_data($oid);
46
 
47
	// ASN.1 IDs
48
 
49
	if (!isset($data['oid']['identifier'])) $data['oid']['identifier'] = array();
50
	if (is_array($data['oid']['identifier'])) {
51
		asort($data['oid']['identifier']);
52
		$oidinfo = implode('|',$data['oid']['identifier']);
53
	} else {
54
		$oidinfo = $data['oid']['identifier'];
55
	}
56
	$oidplus = array();
261 daniel-mar 57
	$resx = OIDplus::db()->query("select name from ###asn1id where oid = ?", array("oid:$oid"));
236 daniel-mar 58
	while ($rowx = $resx->fetch_array()) {
183 daniel-mar 59
		$oidplus[] = $rowx['name'];
60
	}
61
	asort($oidplus);
62
	$oidplus = implode('|',$oidplus);
63
 
64
	if ($oidinfo != $oidplus) {
65
		echo "ASN.1 : $oid (oidinfo '$oidinfo' vs oidplus '$oidplus')\n";
66
	}
67
 
68
	// Unicode Labels
69
 
70
	if (!isset($data['oid']['unicode-label'])) $data['oid']['unicode-label'] = array();
71
	if (is_array($data['oid']['unicode-label'])) {
72
		asort($data['oid']['unicode-label']);
73
		$oidinfo = implode('|',$data['oid']['unicode-label']);
74
	} else {
75
		$oidinfo = $data['oid']['unicode-label'];
76
	}
77
	$oidplus = array();
261 daniel-mar 78
	$resx = OIDplus::db()->query("select name from ###iri where oid = ?", array("oid:$oid"));
236 daniel-mar 79
	while ($rowx = $resx->fetch_array()) {
183 daniel-mar 80
		$oidplus[] = $rowx['name'];
81
	}
82
	asort($oidplus);
83
	$oidplus = implode('|',$oidplus);
84
 
85
	if ($oidinfo != $oidplus) {
86
		echo "IRI : $oid (oidinfo '$oidinfo' vs oidplus '$oidplus')\n";
87
	}
88
}
89
 
90
echo "OK\n";
91
 
92
# ---
93
 
94
function ft_get_oid_data($oid) {
261 daniel-mar 95
	$url = OIDplus::baseConfig()->getValue('OIDINFO_API_URL') . '&oid='.urlencode($oid);
183 daniel-mar 96
	$cont_json = @file_get_contents($url);
97
	if (!$cont_json) {
98
		sleep(5);
99
                $cont_json = @file_get_contents($url);
100
                if (!$cont_json) return false;
101
	}
102
	$data = json_decode($cont_json,true);
103
 
104
	return $data;
105
}