Rev 1040 | Rev 1086 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1040 | Rev 1050 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2022 Daniel Marschall, ViaThinkSoft / Till Wehowski, Frdlweb |
5 | * Copyright 2022 Daniel Marschall, ViaThinkSoft / Till Wehowski, Frdlweb |
6 | * |
6 | * |
7 | * Licensed under the MIT License. |
7 | * Licensed under the MIT License. |
8 | */ |
8 | */ |
9 | 9 | ||
- | 10 | namespace Frdlweb\OIDplus; |
|
- | 11 | ||
- | 12 | use ViaThinkSoft\OIDplus\OIDplus; |
|
10 | if (!defined('INSIDE_OIDPLUS')) die(); |
13 | use ViaThinkSoft\OIDplus\OIDplusObject; |
- | 14 | use ViaThinkSoft\OIDplus\OIDplusPagePluginPublic; |
|
11 | 15 | ||
12 | class OIDplusPagePublicAltIds extends OIDplusPagePluginPublic { |
16 | class OIDplusPagePublicAltIds extends OIDplusPagePluginPublic { |
13 | 17 | ||
14 | public function action($actionID, $params) { |
18 | public function action($actionID, $params) { |
15 | 19 | ||
16 | } |
20 | } |
17 | 21 | ||
18 | public function gui($id, &$out, &$handled) { |
22 | public function gui($id, &$out, &$handled) { |
19 | 23 | ||
20 | } |
24 | } |
21 | 25 | ||
22 | public function publicSitemap(&$out) { |
26 | public function publicSitemap(&$out) { |
23 | 27 | ||
24 | } |
28 | } |
25 | 29 | ||
26 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
30 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
27 | return false; |
31 | return false; |
28 | } |
32 | } |
29 | 33 | ||
30 | private function cache_id() { |
34 | private function cache_id() { |
31 | static $cache_id = null; |
35 | static $cache_id = null; |
32 | if (!is_null($cache_id)) return $cache_id; |
36 | if (!is_null($cache_id)) return $cache_id; |
33 | $cache_id = 'Create='.OIDplus::db()->getScalar("select max(created) as ts from ###objects where created is not null;"); |
37 | $cache_id = 'Create='.OIDplus::db()->getScalar("select max(created) as ts from ###objects where created is not null;"); |
34 | $cache_id .= '/Update='.OIDplus::db()->getScalar("select max(updated) as ts from ###objects where updated is not null;"); |
38 | $cache_id .= '/Update='.OIDplus::db()->getScalar("select max(updated) as ts from ###objects where updated is not null;"); |
35 | $cache_id .= '/Count='.OIDplus::db()->getScalar("select count(id) as cnt from ###objects;"); |
39 | $cache_id .= '/Count='.OIDplus::db()->getScalar("select count(id) as cnt from ###objects;"); |
36 | $plugin_versions = array(); |
40 | $plugin_versions = array(); |
37 | foreach (OIDplus::getObjectTypePluginsEnabled() as $otp) { |
41 | foreach (OIDplus::getObjectTypePluginsEnabled() as $otp) { |
38 | $plugin_versions[] = '/'.$otp->getManifest()->getOid().'='.$otp->getManifest()->getVersion(); |
42 | $plugin_versions[] = '/'.$otp->getManifest()->getOid().'='.$otp->getManifest()->getVersion(); |
39 | } |
43 | } |
40 | sort($plugin_versions); |
44 | sort($plugin_versions); |
41 | $cache_id .= implode('',$plugin_versions); |
45 | $cache_id .= implode('',$plugin_versions); |
42 | return $cache_id; |
46 | return $cache_id; |
43 | } |
47 | } |
44 | 48 | ||
45 | public function readAll($noCache = false) { |
49 | public function readAll($noCache = false) { |
46 | static $local_cache = null; |
50 | static $local_cache = null; |
47 | 51 | ||
48 | $cache_file = OIDplus::localpath().'/userdata/cache/frdl_alt_id.ser'; |
52 | $cache_file = OIDplus::localpath().'/userdata/cache/frdl_alt_id.ser'; |
49 | if ($noCache === false) { |
53 | if ($noCache === false) { |
50 | // Local cache (to save time for multiple calls during the same HTTP request) |
54 | // Local cache (to save time for multiple calls during the same HTTP request) |
51 | if (!is_null($local_cache)) return $local_cache; |
55 | if (!is_null($local_cache)) return $local_cache; |
52 | 56 | ||
53 | // File cache (to save time between HTTP requests) |
57 | // File cache (to save time between HTTP requests) |
54 | if (file_exists($cache_file)) { |
58 | if (file_exists($cache_file)) { |
55 | $cache_data = unserialize(file_get_contents($cache_file)); |
59 | $cache_data = unserialize(file_get_contents($cache_file)); |
56 | $cache_id = $cache_data[0]; |
60 | $cache_id = $cache_data[0]; |
57 | if ($cache_id == $this->cache_id()) { |
61 | if ($cache_id == $this->cache_id()) { |
58 | return $cache_data[1]; |
62 | return $cache_data[1]; |
59 | } |
63 | } |
60 | } |
64 | } |
61 | } |
65 | } |
62 | 66 | ||
63 | $alt_ids = array(); |
67 | $alt_ids = array(); |
64 | $rev_lookup = array(); |
68 | $rev_lookup = array(); |
65 | 69 | ||
66 | $res = OIDplus::db()->query("select id from ###objects"); |
70 | $res = OIDplus::db()->query("select id from ###objects"); |
67 | while ($row = $res->fetch_array()) { |
71 | while ($row = $res->fetch_array()) { |
68 | $obj = OIDplusObject::parse($row['id']); |
72 | $obj = OIDplusObject::parse($row['id']); |
69 | if (!$obj) continue; // e.g. if plugin is disabled |
73 | if (!$obj) continue; // e.g. if plugin is disabled |
70 | $ary = $obj->getAltIds(); |
74 | $ary = $obj->getAltIds(); |
71 | foreach ($ary as $a) { |
75 | foreach ($ary as $a) { |
72 | $origin = $obj->nodeId(true); |
76 | $origin = $obj->nodeId(true); |
73 | $alternative = $a->getNamespace() . ':' . $a->getId(); |
77 | $alternative = $a->getNamespace() . ':' . $a->getId(); |
74 | 78 | ||
75 | if (!isset($alt_ids[$origin])) $alt_ids[$origin] = array(); |
79 | if (!isset($alt_ids[$origin])) $alt_ids[$origin] = array(); |
76 | $alt_ids[$origin][] = $alternative; |
80 | $alt_ids[$origin][] = $alternative; |
77 | 81 | ||
78 | if (!isset($rev_lookup[$alternative])) $rev_lookup[$alternative] = array(); |
82 | if (!isset($rev_lookup[$alternative])) $rev_lookup[$alternative] = array(); |
79 | $rev_lookup[$alternative][] = $origin; |
83 | $rev_lookup[$alternative][] = $origin; |
80 | } |
84 | } |
81 | } |
85 | } |
82 | 86 | ||
83 | $data = array($alt_ids, $rev_lookup); |
87 | $data = array($alt_ids, $rev_lookup); |
84 | 88 | ||
85 | // File cache (to save time between HTTP requests) |
89 | // File cache (to save time between HTTP requests) |
86 | $cache_data = array($this->cache_id(), $data); |
90 | $cache_data = array($this->cache_id(), $data); |
87 | @file_put_contents($cache_file, serialize($cache_data)); |
91 | @file_put_contents($cache_file, serialize($cache_data)); |
88 | 92 | ||
89 | // Local cache (to save time for multiple calls during the same HTTP request) |
93 | // Local cache (to save time for multiple calls during the same HTTP request) |
90 | $local_cache = $data; |
94 | $local_cache = $data; |
91 | 95 | ||
92 | return $data; |
96 | return $data; |
93 | } |
97 | } |
94 | 98 | ||
95 | public function getAlternativesForQuery($id/* 1.3.6.1.4.1.37476.2.5.2.3.7 signature takes just 1 param!? , $noCache = false*/) { |
99 | public function getAlternativesForQuery($id/* 1.3.6.1.4.1.37476.2.5.2.3.7 signature takes just 1 param!? , $noCache = false*/) { |
96 | 100 | ||
97 | static $caches = array(); |
101 | static $caches = array(); |
98 | 102 | ||
99 | if(/*$noCache === false && */isset($caches[$id]) ){ |
103 | if(/*$noCache === false && */isset($caches[$id]) ){ |
100 | return $caches[$id]; |
104 | return $caches[$id]; |
101 | } |
105 | } |
102 | 106 | ||
103 | if (strpos($id,':') !== false) { |
107 | if (strpos($id,':') !== false) { |
104 | list($ns, $altIdRaw) = explode(':', $id, 2); |
108 | list($ns, $altIdRaw) = explode(':', $id, 2); |
105 | if($ns === 'weid'){ |
109 | if($ns === 'weid'){ |
106 | $id='oid:'.\WeidOidConverter::weid2oid($id); |
110 | $id='oid:'.\Frdl\Weid\WeidOidConverter::weid2oid($id); |
107 | } |
111 | } |
108 | } |
112 | } |
109 | 113 | ||
110 | list($alt_ids, $rev_lookup) = $this->readAll(false); |
114 | list($alt_ids, $rev_lookup) = $this->readAll(false); |
111 | 115 | ||
112 | $res = [ |
116 | $res = [ |
113 | $id, |
117 | $id, |
114 | ]; |
118 | ]; |
115 | if(isset($rev_lookup[$id])){ |
119 | if(isset($rev_lookup[$id])){ |
116 | $res = array_merge($res, $rev_lookup[$id]); |
120 | $res = array_merge($res, $rev_lookup[$id]); |
117 | } |
121 | } |
118 | foreach($alt_ids as $original => $altIds){ |
122 | foreach($alt_ids as $original => $altIds){ |
119 | if($id === $original || in_array($id, $altIds) ){ |
123 | if($id === $original || in_array($id, $altIds) ){ |
120 | $res = array_merge($res, $altIds); |
124 | $res = array_merge($res, $altIds); |
121 | $res = array_merge($res, [$original]); |
125 | $res = array_merge($res, [$original]); |
122 | } |
126 | } |
123 | } |
127 | } |
124 | 128 | ||
125 | $weid = false; |
129 | $weid = false; |
126 | foreach($res as $alt){ |
130 | foreach($res as $alt){ |
127 | if (strpos($alt,':') !== false) { |
131 | if (strpos($alt,':') !== false) { |
128 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
132 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
129 | if($ns === 'oid'){ |
133 | if($ns === 'oid'){ |
130 | $weid=\WeidOidConverter::oid2weid($altIdRaw); |
134 | $weid=\Frdl\Weid\WeidOidConverter::oid2weid($altIdRaw); |
131 | break; |
135 | break; |
132 | } |
136 | } |
133 | } |
137 | } |
134 | } |
138 | } |
135 | 139 | ||
136 | if ($weid !== false) { |
140 | if ($weid !== false) { |
137 | $res[]=$weid; |
141 | $res[]=$weid; |
138 | } |
142 | } |
139 | $res = array_unique($res); |
143 | $res = array_unique($res); |
140 | 144 | ||
141 | $caches[$id] = $res; |
145 | $caches[$id] = $res; |
142 | 146 | ||
143 | return $res; |
147 | return $res; |
144 | } |
148 | } |
145 | 149 | ||
146 | public function implementsFeature($id) { |
150 | public function implementsFeature($id) { |
147 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.4') return true; // whois*Attributes |
151 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.4') return true; // whois*Attributes |
148 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.7') return true; // getAlternativesForQuery |
152 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.7') return true; // getAlternativesForQuery |
149 | return false; |
153 | return false; |
150 | } |
154 | } |
151 | 155 | ||
152 | public function tree_search($request) { |
156 | public function tree_search($request) { |
153 | return false; |
157 | return false; |
154 | } |
158 | } |
155 | 159 | ||
156 | public function getCanonical($id){ |
160 | public function getCanonical($id){ |
157 | foreach($this->getAlternativesForQuery($id) as $alt){ |
161 | foreach($this->getAlternativesForQuery($id) as $alt){ |
158 | if (strpos($alt,':') !== false) { |
162 | if (strpos($alt,':') !== false) { |
159 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
163 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
160 | if($ns === 'oid'){ |
164 | if($ns === 'oid'){ |
161 | return $alt; |
165 | return $alt; |
162 | } |
166 | } |
163 | } |
167 | } |
164 | } |
168 | } |
165 | 169 | ||
166 | return false; |
170 | return false; |
167 | } |
171 | } |
168 | 172 | ||
169 | public function whoisObjectAttributes($id, &$out) { |
173 | public function whoisObjectAttributes($id, &$out) { |
170 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.4 |
174 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.4 |
171 | 175 | ||
172 | $xmlns = 'oidplus-frdlweb-altids-plugin'; |
176 | $xmlns = 'oidplus-frdlweb-altids-plugin'; |
173 | $xmlschema = 'urn:oid:1.3.6.1.4.1.37553.8.1.8.8.53354196964.641310544.1714020422'; |
177 | $xmlschema = 'urn:oid:1.3.6.1.4.1.37553.8.1.8.8.53354196964.641310544.1714020422'; |
174 | $xmlschemauri = OIDplus::webpath(__DIR__.'/altids.xsd',OIDplus::PATH_ABSOLUTE); |
178 | $xmlschemauri = OIDplus::webpath(__DIR__.'/altids.xsd',OIDplus::PATH_ABSOLUTE); |
175 | 179 | ||
176 | $handleShown = false; |
180 | $handleShown = false; |
177 | $canonicalShown = false; |
181 | $canonicalShown = false; |
178 | 182 | ||
179 | foreach($this->getAlternativesForQuery($id) as $alt) { |
183 | foreach($this->getAlternativesForQuery($id) as $alt) { |
180 | 184 | ||
181 | if (strpos($alt,':') === false) continue; |
185 | if (strpos($alt,':') === false) continue; |
182 | 186 | ||
183 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
187 | list($ns, $altIdRaw) = explode(':', $alt, 2); |
184 | 188 | ||
185 | if (($canonicalShown === false) && ($ns === 'oid')) { |
189 | if (($canonicalShown === false) && ($ns === 'oid')) { |
186 | $canonicalShown=true; |
190 | $canonicalShown=true; |
187 | 191 | ||
188 | $out[] = [ |
192 | $out[] = [ |
189 | 'xmlns' => $xmlns, |
193 | 'xmlns' => $xmlns, |
190 | 'xmlschema' => $xmlschema, |
194 | 'xmlschema' => $xmlschema, |
191 | 'xmlschemauri' => $xmlschemauri, |
195 | 'xmlschemauri' => $xmlschemauri, |
192 | 'name' => 'canonical-identifier', |
196 | 'name' => 'canonical-identifier', |
193 | 'value' => $ns.':'.$altIdRaw, |
197 | 'value' => $ns.':'.$altIdRaw, |
194 | ]; |
198 | ]; |
195 | 199 | ||
196 | } |
200 | } |
197 | 201 | ||
198 | if (($handleShown === false) && ($alt === $id)) { |
202 | if (($handleShown === false) && ($alt === $id)) { |
199 | $handleShown=true; |
203 | $handleShown=true; |
200 | 204 | ||
201 | $out[] = [ |
205 | $out[] = [ |
202 | 'xmlns' => $xmlns, |
206 | 'xmlns' => $xmlns, |
203 | 'xmlschema' => $xmlschema, |
207 | 'xmlschema' => $xmlschema, |
204 | 'xmlschemauri' => $xmlschemauri, |
208 | 'xmlschemauri' => $xmlschemauri, |
205 | 'name' => 'handle-identifier', |
209 | 'name' => 'handle-identifier', |
206 | 'value' => $alt, |
210 | 'value' => $alt, |
207 | ]; |
211 | ]; |
208 | 212 | ||
209 | } |
213 | } |
210 | 214 | ||
211 | $out[] = [ |
215 | $out[] = [ |
212 | 'xmlns' => $xmlns, |
216 | 'xmlns' => $xmlns, |
213 | 'xmlschema' => $xmlschema, |
217 | 'xmlschema' => $xmlschema, |
214 | 'xmlschemauri' => $xmlschemauri, |
218 | 'xmlschemauri' => $xmlschemauri, |
215 | 'name' => 'alternate-identifier', |
219 | 'name' => 'alternate-identifier', |
216 | 'value' => $ns.':'.$altIdRaw, |
220 | 'value' => $ns.':'.$altIdRaw, |
217 | ]; |
221 | ]; |
218 | 222 | ||
219 | } |
223 | } |
220 | } |
224 | } |
221 | 225 | ||
222 | public function whoisRaAttributes($email, &$out) { |
226 | public function whoisRaAttributes($email, &$out) { |
223 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.4 |
227 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.4 |
224 | } |
228 | } |
225 | 229 | ||
226 | } |
230 | } |
227 | 231 |