Rev 1116 | Go to most recent revision | 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 | |||
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 | |||
1116 | daniel-mar | 28 | const VERBOSE = false; |
29 | const DEFAULT_EMAIL = 'oidra@viathinksoft.de'; |
||
30 | const ALL_OID_LIST = '/home/oidplus/all_oids.txt'; // contains all OIDs (non-public file) |
||
31 | const DESIRED_ROOT = '1.3.6.1.4.1.37476'; |
||
183 | daniel-mar | 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 | |||
1130 | daniel-mar | 44 | /** |
45 | * @param string $oid |
||
46 | * @param string $root |
||
47 | * @return void |
||
48 | */ |
||
49 | function check_oid(string $oid, string $root=DESIRED_ROOT) { |
||
183 | daniel-mar | 50 | $data = ft_get_oid_data($oid); |
51 | |||
52 | // ASN.1 IDs |
||
53 | |||
54 | if (!isset($data['oid']['identifier'])) $data['oid']['identifier'] = array(); |
||
55 | if (is_array($data['oid']['identifier'])) { |
||
56 | asort($data['oid']['identifier']); |
||
57 | $oidinfo = implode('|',$data['oid']['identifier']); |
||
58 | } else { |
||
59 | $oidinfo = $data['oid']['identifier']; |
||
60 | } |
||
61 | $oidplus = array(); |
||
261 | daniel-mar | 62 | $resx = OIDplus::db()->query("select name from ###asn1id where oid = ?", array("oid:$oid")); |
236 | daniel-mar | 63 | while ($rowx = $resx->fetch_array()) { |
183 | daniel-mar | 64 | $oidplus[] = $rowx['name']; |
65 | } |
||
66 | asort($oidplus); |
||
67 | $oidplus = implode('|',$oidplus); |
||
68 | |||
69 | if ($oidinfo != $oidplus) { |
||
70 | echo "ASN.1 : $oid (oidinfo '$oidinfo' vs oidplus '$oidplus')\n"; |
||
71 | } |
||
72 | |||
73 | // Unicode Labels |
||
74 | |||
75 | if (!isset($data['oid']['unicode-label'])) $data['oid']['unicode-label'] = array(); |
||
76 | if (is_array($data['oid']['unicode-label'])) { |
||
77 | asort($data['oid']['unicode-label']); |
||
78 | $oidinfo = implode('|',$data['oid']['unicode-label']); |
||
79 | } else { |
||
80 | $oidinfo = $data['oid']['unicode-label']; |
||
81 | } |
||
82 | $oidplus = array(); |
||
261 | daniel-mar | 83 | $resx = OIDplus::db()->query("select name from ###iri where oid = ?", array("oid:$oid")); |
236 | daniel-mar | 84 | while ($rowx = $resx->fetch_array()) { |
183 | daniel-mar | 85 | $oidplus[] = $rowx['name']; |
86 | } |
||
87 | asort($oidplus); |
||
88 | $oidplus = implode('|',$oidplus); |
||
89 | |||
90 | if ($oidinfo != $oidplus) { |
||
91 | echo "IRI : $oid (oidinfo '$oidinfo' vs oidplus '$oidplus')\n"; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | echo "OK\n"; |
||
96 | |||
97 | # --- |
||
98 | |||
1130 | daniel-mar | 99 | /** |
100 | * @param string $oid |
||
101 | * @return false|array |
||
102 | */ |
||
103 | function ft_get_oid_data(string $oid) { |
||
261 | daniel-mar | 104 | $url = OIDplus::baseConfig()->getValue('OIDINFO_API_URL') . '&oid='.urlencode($oid); |
183 | daniel-mar | 105 | $cont_json = @file_get_contents($url); |
106 | if (!$cont_json) { |
||
107 | sleep(5); |
||
108 | $cont_json = @file_get_contents($url); |
||
109 | if (!$cont_json) return false; |
||
110 | } |
||
1130 | daniel-mar | 111 | return json_decode($cont_json,true); |
183 | daniel-mar | 112 | } |