Subversion Repositories oidplus

Rev

Rev 1130 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
557 daniel-mar 1
#!/usr/bin/env php
183 daniel-mar 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
 
1162 daniel-mar 21
use ViaThinkSoft\OIDplus\OIDplus;
22
 
183 daniel-mar 23
require_once __DIR__ . '/../includes/oidplus.inc.php';
24
 
25
OIDplus::init(false);
261 daniel-mar 26
if (!OIDplus::baseConfig()->exists('OIDINFO_API_URL')) {
183 daniel-mar 27
	die("OIDINFO_API_URL not available (API is currently not public)\n");
28
}
29
 
1116 daniel-mar 30
const VERBOSE = false;
31
const DEFAULT_EMAIL = 'oidra@viathinksoft.de';
32
const ALL_OID_LIST = '/home/oidplus/all_oids.txt'; // contains all OIDs (non-public file)
33
const DESIRED_ROOT = '1.3.6.1.4.1.37476';
183 daniel-mar 34
 
35
# ---
36
 
37
exec("cat ".escapeshellarg(ALL_OID_LIST)." | sort | grep '^".DESIRED_ROOT."'", $out, $ec);
38
 
39
foreach ($out as $oid) {
40
	$oid = trim($oid);
41
	if ($oid == '') continue;
42
 
43
	check_oid($oid);
44
}
45
 
1130 daniel-mar 46
/**
47
 * @param string $oid
48
 * @param string $root
49
 * @return void
50
 */
51
function check_oid(string $oid, string $root=DESIRED_ROOT) {
183 daniel-mar 52
	$data = ft_get_oid_data($oid);
53
 
54
	// ASN.1 IDs
55
 
56
	if (!isset($data['oid']['identifier'])) $data['oid']['identifier'] = array();
57
	if (is_array($data['oid']['identifier'])) {
58
		asort($data['oid']['identifier']);
59
		$oidinfo = implode('|',$data['oid']['identifier']);
60
	} else {
61
		$oidinfo = $data['oid']['identifier'];
62
	}
63
	$oidplus = array();
261 daniel-mar 64
	$resx = OIDplus::db()->query("select name from ###asn1id where oid = ?", array("oid:$oid"));
236 daniel-mar 65
	while ($rowx = $resx->fetch_array()) {
183 daniel-mar 66
		$oidplus[] = $rowx['name'];
67
	}
68
	asort($oidplus);
69
	$oidplus = implode('|',$oidplus);
70
 
71
	if ($oidinfo != $oidplus) {
72
		echo "ASN.1 : $oid (oidinfo '$oidinfo' vs oidplus '$oidplus')\n";
73
	}
74
 
75
	// Unicode Labels
76
 
77
	if (!isset($data['oid']['unicode-label'])) $data['oid']['unicode-label'] = array();
78
	if (is_array($data['oid']['unicode-label'])) {
79
		asort($data['oid']['unicode-label']);
80
		$oidinfo = implode('|',$data['oid']['unicode-label']);
81
	} else {
82
		$oidinfo = $data['oid']['unicode-label'];
83
	}
84
	$oidplus = array();
261 daniel-mar 85
	$resx = OIDplus::db()->query("select name from ###iri where oid = ?", array("oid:$oid"));
236 daniel-mar 86
	while ($rowx = $resx->fetch_array()) {
183 daniel-mar 87
		$oidplus[] = $rowx['name'];
88
	}
89
	asort($oidplus);
90
	$oidplus = implode('|',$oidplus);
91
 
92
	if ($oidinfo != $oidplus) {
93
		echo "IRI : $oid (oidinfo '$oidinfo' vs oidplus '$oidplus')\n";
94
	}
95
}
96
 
97
echo "OK\n";
98
 
99
# ---
100
 
1130 daniel-mar 101
/**
102
 * @param string $oid
103
 * @return false|array
104
 */
105
function ft_get_oid_data(string $oid) {
261 daniel-mar 106
	$url = OIDplus::baseConfig()->getValue('OIDINFO_API_URL') . '&oid='.urlencode($oid);
183 daniel-mar 107
	$cont_json = @file_get_contents($url);
108
	if (!$cont_json) {
109
		sleep(5);
110
                $cont_json = @file_get_contents($url);
111
                if (!$cont_json) return false;
112
	}
1130 daniel-mar 113
	return json_decode($cont_json,true);
183 daniel-mar 114
}