Rev 496 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
101 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
511 | daniel-mar | 5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
101 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | require_once __DIR__ . '/../../../../includes/oidplus.inc.php'; |
||
21 | |||
22 | OIDplus::init(true); |
||
440 | daniel-mar | 23 | set_exception_handler(array('OIDplusGui', 'html_exception_handler')); |
101 | daniel-mar | 24 | |
180 | daniel-mar | 25 | originHeaders(); |
101 | daniel-mar | 26 | |
27 | // Step 0: Get request parameter |
||
28 | |||
444 | daniel-mar | 29 | if (PHP_SAPI == 'cli') { |
386 | daniel-mar | 30 | if ($_SERVER['argc'] != 2) { |
31 | echo _L('Syntax').': '.$_SERVER['argv'][0].' <query>'."\n"; |
||
101 | daniel-mar | 32 | exit(2); |
33 | } |
||
386 | daniel-mar | 34 | $query = $_SERVER['argv'][1]; |
101 | daniel-mar | 35 | } else { |
36 | if (!isset($_REQUEST['query'])) { |
||
37 | http_response_code(400); |
||
360 | daniel-mar | 38 | die('<h1>'._L('Error').'</h1><p>'._L('Argument "%1" is missing','query').'<p>'); |
101 | daniel-mar | 39 | } |
40 | $query = $_REQUEST['query']; |
||
41 | } |
||
42 | |||
43 | $authTokens = explode('$', $query); |
||
44 | $query = array_shift($authTokens); |
||
104 | daniel-mar | 45 | |
101 | daniel-mar | 46 | $query = str_replace('oid:.', 'oid:', $query); // allow leading dot |
47 | |||
48 | // Step 1: Collect data |
||
49 | |||
50 | $out = array(); |
||
51 | |||
52 | $out[] = "query: $query"; |
||
53 | |||
54 | $distance = null; |
||
55 | $found = null; |
||
56 | |||
57 | try { |
||
58 | $obj = OIDplusObject::findFitting($query); |
||
59 | if (!$obj) $obj = OIDplusObject::parse($query); // in case we didn't find anything fitting, we take it as it is and later use getParent() to find something else |
||
416 | daniel-mar | 60 | $query = $obj->nodeId(); |
101 | daniel-mar | 61 | } catch (Exception $e) { |
62 | $obj = null; |
||
63 | } |
||
64 | |||
416 | daniel-mar | 65 | $only_wellknown_ids_found = false; |
66 | $continue = false; |
||
67 | |||
101 | daniel-mar | 68 | if (!$obj) { |
416 | daniel-mar | 69 | $out[] = "result: Not found"; // DO NOT TRANSLATE! |
70 | $continue = false; |
||
101 | daniel-mar | 71 | } else { |
416 | daniel-mar | 72 | $obj = null; |
73 | $distance = 0; |
||
101 | daniel-mar | 74 | |
416 | daniel-mar | 75 | $init_query = $query; |
76 | while (true) { |
||
77 | $res = OIDplus::db()->query("select * from ###objects where id = ?", array($query)); |
||
78 | if ($res->num_rows() > 0) { |
||
79 | $obj = OIDplusObject::parse($query); |
||
80 | if ($distance > 0) { |
||
81 | $out[] = "result: Not found; superior object found"; // DO NOT TRANSLATE! |
||
82 | $out[] = "distance: $distance"; // DO NOT TRANSLATE |
||
83 | } else { |
||
84 | $out[] = "result: Found"; // DO NOT TRANSLATE! |
||
85 | } |
||
86 | $continue = true; |
||
87 | break; |
||
101 | daniel-mar | 88 | } |
416 | daniel-mar | 89 | |
90 | if (substr($query,0,4) === 'oid:') { |
||
91 | $query_prev = $query; |
||
92 | $query = 'oid:'.oid_up(explode(':',$query,2)[1]); |
||
93 | if ($query == $query_prev) break; |
||
94 | $distance++; |
||
95 | } else { |
||
96 | $obj = OIDplusObject::parse($query)->getParent(); // For objects, we assume that they are parents of each other |
||
97 | if ($obj) { |
||
98 | $res = OIDplus::db()->query("select * from ###objects where id = ?", array($obj->nodeId())); |
||
99 | $distance = $obj->distance($query); |
||
100 | assert($res->num_rows() > 0); |
||
101 | |||
102 | $query = $obj->nodeId(); |
||
103 | } |
||
104 | break; |
||
105 | } |
||
101 | daniel-mar | 106 | } |
107 | |||
416 | daniel-mar | 108 | if ((substr($query,0,4) === 'oid:') && (!$obj)) { |
109 | $query = $init_query; |
||
110 | $distance = 0; |
||
111 | while (true) { |
||
112 | $res = OIDplus::db()->query("select * from ###asn1id where oid = ? union select * from ###iri where oid = ?", array($query, $query)); |
||
113 | if ($res->num_rows() > 0) { |
||
114 | $obj = OIDplusObject::parse($query); |
||
115 | $res = null; |
||
116 | if ($distance > 0) { |
||
117 | $out[] = "result: Not found; superior object found"; // DO NOT TRANSLATE! |
||
118 | $out[] = "distance: $distance"; // DO NOT TRANSLATE |
||
119 | } else { |
||
120 | $out[] = "result: Found"; // DO NOT TRANSLATE! |
||
121 | } |
||
122 | $only_wellknown_ids_found = true; // Information partially available |
||
123 | $continue = true; |
||
124 | break; |
||
125 | } |
||
126 | $query_prev = $query; |
||
127 | $query = 'oid:'.oid_up(explode(':',$query,2)[1]); |
||
128 | if ($query == $query_prev) break; |
||
129 | $distance++; |
||
130 | } |
||
131 | } |
||
132 | |||
133 | if (!$obj) { |
||
360 | daniel-mar | 134 | $out[] = "result: Not found"; // DO NOT TRANSLATE! |
101 | daniel-mar | 135 | $continue = false; |
136 | } |
||
416 | daniel-mar | 137 | |
138 | $found = $distance == 0; |
||
101 | daniel-mar | 139 | } |
140 | |||
141 | if ($continue) { |
||
142 | $out[] = ""; |
||
360 | daniel-mar | 143 | $out[] = "object: $query"; // DO NOT TRANSLATE! |
416 | daniel-mar | 144 | if (!allowObjectView($obj, $authTokens)) { |
360 | daniel-mar | 145 | $out[] = "status: Information unavailable"; // DO NOT TRANSLATE! |
146 | $out[] = "attribute: confidential"; // DO NOT TRANSLATE! |
||
101 | daniel-mar | 147 | } else { |
416 | daniel-mar | 148 | if ($only_wellknown_ids_found) { |
149 | $out[] = "status: Information partially available"; // DO NOT TRANSLATE! |
||
150 | } else { |
||
151 | $out[] = "status: Information available"; // DO NOT TRANSLATE! |
||
152 | } |
||
101 | daniel-mar | 153 | |
416 | daniel-mar | 154 | $row = $res ? $res->fetch_object() : null; |
101 | daniel-mar | 155 | |
416 | daniel-mar | 156 | if (!is_null($row)) $out[] = 'name: ' . $row->title; // DO NOT TRANSLATE! |
337 | daniel-mar | 157 | |
416 | daniel-mar | 158 | if (!is_null($row)) { |
159 | $cont = $row->description; |
||
160 | $cont = preg_replace('@<a[^>]+href\s*=\s*["\']([^\'"]+)["\'][^>]*>(.+)<\s*/\s*a\s*>@ismU', '\2 (\1)', $cont); |
||
161 | $cont = preg_replace('@<br.*>@', "\n", $cont); |
||
162 | $cont = preg_replace('@\\n+@', "\n", $cont); |
||
163 | $out[] = 'description: ' . trim(html_entity_decode(strip_tags($cont))); // DO NOT TRANSLATE! |
||
164 | } |
||
337 | daniel-mar | 165 | |
101 | daniel-mar | 166 | if (substr($query,0,4) === 'oid:') { |
360 | daniel-mar | 167 | $out[] = 'asn1-notation: ' . $obj->getAsn1Notation(false); // DO NOT TRANSLATE! |
168 | $out[] = 'iri-notation: ' . $obj->getIriNotation(false); // DO NOT TRANSLATE! |
||
337 | daniel-mar | 169 | |
416 | daniel-mar | 170 | $res2 = OIDplus::db()->query("select * from ###asn1id where oid = ?", array($obj->nodeId())); |
236 | daniel-mar | 171 | while ($row2 = $res2->fetch_object()) { |
360 | daniel-mar | 172 | $out[] = 'identifier: ' . $row2->name; // DO NOT TRANSLATE! |
101 | daniel-mar | 173 | } |
174 | |||
416 | daniel-mar | 175 | $res2 = OIDplus::db()->query("select * from ###asn1id where standardized = ? and oid = ?", array(true, $obj->nodeId())); |
236 | daniel-mar | 176 | while ($row2 = $res2->fetch_object()) { |
360 | daniel-mar | 177 | $out[] = 'standardized-id: ' . $row2->name; // DO NOT TRANSLATE! |
101 | daniel-mar | 178 | } |
179 | |||
416 | daniel-mar | 180 | $res2 = OIDplus::db()->query("select * from ###iri where oid = ?", array($obj->nodeId())); |
236 | daniel-mar | 181 | while ($row2 = $res2->fetch_object()) { |
360 | daniel-mar | 182 | $out[] = 'unicode-label: ' . $row2->name; // DO NOT TRANSLATE! |
101 | daniel-mar | 183 | } |
184 | |||
416 | daniel-mar | 185 | $res2 = OIDplus::db()->query("select * from ###iri where longarc = ? and oid = ?", array(true, $obj->nodeId())); |
236 | daniel-mar | 186 | while ($row2 = $res2->fetch_object()) { |
360 | daniel-mar | 187 | $out[] = 'long-arc: ' . $row2->name; // DO NOT TRANSLATE! |
101 | daniel-mar | 188 | } |
189 | } |
||
336 | daniel-mar | 190 | |
416 | daniel-mar | 191 | if ($obj->isConfidential()) { // yes, we use isConfidential() instead of allowObjectView()! |
192 | $out[] = 'attribute: confidential'; |
||
193 | } |
||
336 | daniel-mar | 194 | |
337 | daniel-mar | 195 | foreach (OIDplus::getPagePlugins() as $plugin) { |
196 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.4')) { |
||
416 | daniel-mar | 197 | $plugin->whoisObjectAttributes($obj->nodeId(), $out); |
337 | daniel-mar | 198 | } |
199 | } |
||
336 | daniel-mar | 200 | |
416 | daniel-mar | 201 | if (substr($query,0,4) === 'oid:') { |
202 | $sParent = 'oid:'.oid_up(explode(':',$query,2)[1]); |
||
203 | |||
204 | $objTest = OIDplusObject::parse($sParent); |
||
205 | if (allowObjectView($objTest, $authTokens)) { |
||
206 | $out[] = 'parent: ' . $sParent . show_asn1_appendix($sParent); // DO NOT TRANSLATE! |
||
207 | } else { |
||
208 | $out[] = 'parent: ' . $sParent; // DO NOT TRANSLATE! |
||
209 | } |
||
210 | } else if (!is_null($row) && !empty($row->parent) && (!is_root($row->parent))) { |
||
211 | $sParent = $row->parent; |
||
212 | $out[] = 'parent: ' . $row->parent; // DO NOT TRANSLATE! |
||
322 | daniel-mar | 213 | } |
101 | daniel-mar | 214 | |
416 | daniel-mar | 215 | $res2 = OIDplus::db()->query("select * from ###objects where parent = ? order by ".OIDplus::db()->natOrder('id'), array($obj->nodeId())); |
236 | daniel-mar | 216 | while ($row2 = $res2->fetch_object()) { |
416 | daniel-mar | 217 | $objTest = OIDplusObject::parse($row2->id); |
218 | if (allowObjectView($objTest, $authTokens)) { |
||
219 | $out[] = 'subordinate: ' . $row2->id . show_asn1_appendix($row2->id); // DO NOT TRANSLATE! |
||
220 | } else { |
||
221 | $out[] = 'subordinate: ' . $row2->id; // DO NOT TRANSLATE! |
||
222 | } |
||
101 | daniel-mar | 223 | } |
224 | |||
416 | daniel-mar | 225 | if (!is_null($row)) { |
226 | if ($row->created) $out[] = 'created: ' . date('Y-m-d H:i:s', strtotime($row->created)); // DO NOT TRANSLATE! |
||
227 | if ($row->updated) $out[] = 'updated: ' . date('Y-m-d H:i:s', strtotime($row->updated)); // DO NOT TRANSLATE! |
||
228 | } |
||
336 | daniel-mar | 229 | |
101 | daniel-mar | 230 | $out[] = ''; |
231 | |||
416 | daniel-mar | 232 | $res2 = OIDplus::db()->query("select * from ###ra where email = ?", array(is_null($row) ? '' : $row->ra_email)); |
236 | daniel-mar | 233 | if ($row2 = $res2->fetch_object()) { |
360 | daniel-mar | 234 | $out[] = 'ra: '.(!empty($row2->ra_name) ? $row2->ra_name : (!empty($row2->email) ? $row2->email : _L('Unknown'))); // DO NOT TRANSLATE! |
235 | $out[] = 'ra-status: Information available'; // DO NOT TRANSLATE! |
||
336 | daniel-mar | 236 | |
237 | $tmp = array(); |
||
238 | if (!empty($row2->office)) $tmp[] = $row2->office; |
||
239 | if (!empty($row2->organization)) $tmp[] = $row2->organization; |
||
240 | $tmp = implode(', ', $tmp); |
||
241 | |||
360 | daniel-mar | 242 | $out[] = 'ra-contact-name: ' . $row2->personal_name.(!empty($tmp) ? " ($tmp)" : ''); // DO NOT TRANSLATE! |
416 | daniel-mar | 243 | if (!allowRAView($row2, $authTokens)) { |
336 | daniel-mar | 244 | if (!empty($row2->street) || !empty($row2->zip_town) || !empty($row2->country)) { |
360 | daniel-mar | 245 | $out[] = 'ra-address: '._L('(redacted)'); // DO NOT TRANSLATE! |
336 | daniel-mar | 246 | } |
360 | daniel-mar | 247 | $out[] = 'ra-phone: ' . (!empty($row2->phone) ? _L('(redacted)') : ''); // DO NOT TRANSLATE! |
248 | $out[] = 'ra-mobile: ' . (!empty($row2->mobile) ? _L('(redacted)') : ''); // DO NOT TRANSLATE! |
||
249 | $out[] = 'ra-fax: ' . (!empty($row2->fax) ? _L('(redacted)') : ''); // DO NOT TRANSLATE! |
||
101 | daniel-mar | 250 | } else { |
360 | daniel-mar | 251 | if (!empty($row2->street)) $out[] = 'ra-address: ' . $row2->street; // DO NOT TRANSLATE! |
252 | if (!empty($row2->zip_town)) $out[] = 'ra-address: ' . $row2->zip_town; // DO NOT TRANSLATE! |
||
253 | if (!empty($row2->country)) $out[] = 'ra-address: ' . $row2->country; // DO NOT TRANSLATE! |
||
254 | $out[] = 'ra-phone: ' . $row2->phone; // DO NOT TRANSLATE! |
||
255 | $out[] = 'ra-mobile: ' . $row2->mobile; // DO NOT TRANSLATE! |
||
256 | $out[] = 'ra-fax: ' . $row2->fax; // DO NOT TRANSLATE! |
||
101 | daniel-mar | 257 | } |
360 | daniel-mar | 258 | $out[] = 'ra-email: ' . $row->ra_email; // DO NOT TRANSLATE! |
322 | daniel-mar | 259 | foreach (OIDplus::getPagePlugins() as $plugin) { |
260 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.4')) { |
||
261 | $plugin->whoisRaAttributes($row->ra_email, $out); |
||
262 | } |
||
263 | } |
||
416 | daniel-mar | 264 | |
265 | if ($row2->privacy) { // yes, we use row2->privacy() instead of allowRAView()! |
||
266 | $out[] = 'ra-attribute: confidential'; |
||
267 | } |
||
268 | |||
269 | if ($row2->registered) $out[] = 'ra-created: ' . date('Y-m-d H:i:s', strtotime($row2->registered)); // DO NOT TRANSLATE! |
||
270 | if ($row2->updated) $out[] = 'ra-updated: ' . date('Y-m-d H:i:s', strtotime($row2->updated)); // DO NOT TRANSLATE! |
||
101 | daniel-mar | 271 | } else { |
416 | daniel-mar | 272 | $out[] = 'ra: '.(!is_null($row) && !empty($row->ra_email) ? $row->ra_email : _L('Unknown')); // DO NOT TRANSLATE! |
273 | if (!is_null($row)) { |
||
274 | foreach (OIDplus::getPagePlugins() as $plugin) { |
||
275 | if ($plugin->implementsFeature('1.3.6.1.4.1.37476.2.5.2.3.4')) { |
||
276 | $plugin->whoisRaAttributes($row->ra_email, $out); |
||
277 | } |
||
322 | daniel-mar | 278 | } |
279 | } |
||
360 | daniel-mar | 280 | $out[] = "ra-status: Information unavailable"; // DO NOT TRANSLATE! |
101 | daniel-mar | 281 | } |
282 | } |
||
283 | } |
||
284 | |||
285 | // Step 2: Format output |
||
286 | |||
287 | ob_start(); |
||
288 | |||
201 | daniel-mar | 289 | $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : 'txt'; |
101 | daniel-mar | 290 | |
201 | daniel-mar | 291 | if ($format == 'txt') { |
292 | header('Content-Type:text/plain; charset=UTF-8'); |
||
101 | daniel-mar | 293 | |
201 | daniel-mar | 294 | $longest_key = 0; |
295 | foreach ($out as $line) { |
||
296 | $longest_key = max($longest_key, strlen(trim(explode(':',$line,2)[0]))); |
||
101 | daniel-mar | 297 | } |
298 | |||
332 | daniel-mar | 299 | //echo '% ' . str_repeat('*', OIDplus::config()->getValue('webwhois_output_format_max_line_length', 80)-2)."\n"; |
101 | daniel-mar | 300 | |
201 | daniel-mar | 301 | foreach ($out as $line) { |
302 | if (trim($line) == '') { |
||
303 | echo "\n"; |
||
304 | continue; |
||
305 | } |
||
101 | daniel-mar | 306 | |
201 | daniel-mar | 307 | $ary = explode(':', $line, 2); |
101 | daniel-mar | 308 | |
201 | daniel-mar | 309 | $key = trim($ary[0]); |
310 | |||
322 | daniel-mar | 311 | $value = isset($ary[1]) ? trim($ary[1]) : ''; |
346 | daniel-mar | 312 | $value = mb_wordwrap($value, OIDplus::config()->getValue('webwhois_output_format_max_line_length', 80) - $longest_key - strlen(':') - OIDplus::config()->getValue('webwhois_output_format_spacer', 2)); |
261 | daniel-mar | 313 | $value = str_replace("\n", "\n$key:".str_repeat(' ', $longest_key-strlen($key)) . str_repeat(' ', OIDplus::config()->getValue('webwhois_output_format_spacer', 2)), $value); |
201 | daniel-mar | 314 | |
339 | daniel-mar | 315 | if (!empty($value)) { |
316 | echo $key.':' . str_repeat(' ', $longest_key-strlen($key)) . str_repeat(' ', OIDplus::config()->getValue('webwhois_output_format_spacer', 2)) . $value . "\n"; |
||
317 | } |
||
201 | daniel-mar | 318 | } |
319 | |||
332 | daniel-mar | 320 | //echo '% ' . str_repeat('*', OIDplus::config()->getValue('webwhois_output_format_max_line_length', 80)-2)."\n"; |
201 | daniel-mar | 321 | |
322 | $cont = ob_get_contents(); |
||
323 | ob_end_clean(); |
||
324 | |||
325 | echo $cont; |
||
326 | |||
227 | daniel-mar | 327 | if (OIDplus::getPkiStatus(true)) { |
201 | daniel-mar | 328 | $signature = ''; |
239 | daniel-mar | 329 | if (@openssl_sign($cont, $signature, OIDplus::config()->getValue('oidplus_private_key'))) { |
201 | daniel-mar | 330 | $signature = base64_encode($signature); |
346 | daniel-mar | 331 | $signature = mb_wordwrap($signature, OIDplus::config()->getValue('webwhois_output_format_max_line_length', 80) - strlen('% '), "\n", true); |
332 | daniel-mar | 332 | $signature = "% -----BEGIN RSA SIGNATURE-----\n". |
333 | preg_replace('/^/m', '% ', $signature)."\n". |
||
334 | "% -----END RSA SIGNATURE-----\n"; |
||
201 | daniel-mar | 335 | echo $signature; |
336 | } |
||
337 | } |
||
101 | daniel-mar | 338 | } |
339 | |||
201 | daniel-mar | 340 | if ($format == 'json') { |
341 | $ary = array(); |
||
101 | daniel-mar | 342 | |
201 | daniel-mar | 343 | $current_section = array(); |
344 | $ary[] = &$current_section; |
||
101 | daniel-mar | 345 | |
201 | daniel-mar | 346 | foreach ($out as $line) { |
347 | if ($line == '') { |
||
348 | unset($current_section); |
||
349 | $current_section = array(); |
||
350 | $ary[] = &$current_section; |
||
351 | } else { |
||
352 | list($key,$val) = explode(':', $line, 2); |
||
353 | $val = trim($val); |
||
339 | daniel-mar | 354 | if (!empty($val)) { |
355 | if (!isset($current_section[$key])) { |
||
356 | $current_section[$key] = $val; |
||
357 | } elseif (is_array($current_section[$key])) { |
||
358 | $current_section[$key][] = $val; |
||
359 | } else { |
||
360 | $current_section[$key] = array($current_section[$key], $val); |
||
361 | } |
||
201 | daniel-mar | 362 | } |
363 | } |
||
364 | } |
||
331 | daniel-mar | 365 | $ary = array( |
366 | // https://code.visualstudio.com/docs/languages/json#_mapping-in-the-json |
||
367 | // Note that this syntax is VS Code-specific and not part of the JSON Schema specification. |
||
368 | //'$schema' => 'https://oidplus.viathinksoft.com/oidplus/plugins/publicPages/100_whois/whois/json_schema.json', |
||
496 | daniel-mar | 369 | '$schema' => OIDplus::webpath().'plugins/publicPages/100_whois/whois/json_schema.json', |
101 | daniel-mar | 370 | |
331 | daniel-mar | 371 | // we need this NAMED root, otherwise PHP will name the sections "0", "1", "2" if the array is not sequencial (e.g. because "signature" is added) |
372 | 'whois' => $ary |
||
373 | ); |
||
374 | |||
227 | daniel-mar | 375 | if (OIDplus::getPkiStatus(true)) { |
201 | daniel-mar | 376 | $cont = json_encode($ary); |
377 | $signature = ''; |
||
239 | daniel-mar | 378 | if (@openssl_sign($cont, $signature, OIDplus::config()->getValue('oidplus_private_key'))) { |
201 | daniel-mar | 379 | $signature = base64_encode($signature); |
380 | $ary['signature'] = array('content' => $cont, 'signature' => $signature); |
||
381 | } |
||
382 | } |
||
339 | daniel-mar | 383 | |
384 | // Good JSON schema validator here: https://www.jsonschemavalidator.net |
||
201 | daniel-mar | 385 | header('Content-Type:application/json; charset=UTF-8'); |
386 | echo json_encode($ary); |
||
387 | } |
||
101 | daniel-mar | 388 | |
201 | daniel-mar | 389 | if ($format == 'xml') { |
390 | $xml = '<whois><section>'; |
||
391 | foreach ($out as $line) { |
||
392 | if ($line == '') { |
||
393 | $xml .= '</section><section>'; |
||
394 | } else { |
||
395 | list($key,$val) = explode(':', $line, 2); |
||
396 | $val = trim($val); |
||
339 | daniel-mar | 397 | if (!empty($val)) { |
398 | $xml .= "<$key>".htmlspecialchars($val)."</$key>"; |
||
399 | } |
||
201 | daniel-mar | 400 | } |
401 | } |
||
402 | $xml .= '</section></whois>'; |
||
101 | daniel-mar | 403 | |
339 | daniel-mar | 404 | $xml = preg_replace('@<section><(.+)>(.+)</section>@ismU', '<\\1Section><\\1>\\2</\\1Section>', $xml); |
405 | |||
227 | daniel-mar | 406 | if (OIDplus::getPkiStatus(true)) { |
201 | daniel-mar | 407 | $cont = $xml; |
408 | $signature = ''; |
||
239 | daniel-mar | 409 | if (@openssl_sign($cont, $signature, OIDplus::config()->getValue('oidplus_private_key'))) { |
201 | daniel-mar | 410 | $signature = base64_encode($signature); |
411 | $xml .= "<signature><content>".htmlspecialchars($cont)."</content><signature>".htmlspecialchars($signature)."</signature></signature>"; |
||
412 | } |
||
101 | daniel-mar | 413 | } |
201 | daniel-mar | 414 | |
339 | daniel-mar | 415 | // Good XSD validator here: https://www.liquid-technologies.com/online-xsd-validator |
201 | daniel-mar | 416 | header('Content-Type:application/xml; charset=UTF-8'); |
417 | echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'; |
||
339 | daniel-mar | 418 | echo '<root xmlns="urn:oid:1.3.6.1.4.1.37476.2.5.2.5.1.1"'; |
330 | daniel-mar | 419 | echo ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'; |
386 | daniel-mar | 420 | //echo ' xsi:schemaLocation="urn:oid:1.3.6.1.4.1.37476.2.5.2.5.1.1 https://oidplus.viathinksoft.com/oidplus/plugins/publicPages/100_whois/whois/xml_schema.xsd">'; |
496 | daniel-mar | 421 | echo ' xsi:schemaLocation="urn:oid:1.3.6.1.4.1.37476.2.5.2.5.1.1 '.OIDplus::webpath().'plugins/publicPages/100_whois/whois/xml_schema.xsd">'; |
330 | daniel-mar | 422 | echo $xml; |
423 | echo '</root>'; |
||
101 | daniel-mar | 424 | } |
425 | |||
426 | # --- |
||
427 | |||
428 | function show_asn1_appendix($id) { |
||
429 | if (substr($id,0,4) === 'oid:') { |
||
430 | $appendix_asn1ids = array(); |
||
261 | daniel-mar | 431 | $res3 = OIDplus::db()->query("select * from ###asn1id where oid = ?", array($id)); |
236 | daniel-mar | 432 | while ($row3 = $res3->fetch_object()) { |
101 | daniel-mar | 433 | $appendix_asn1ids[] = $row3->name; |
434 | } |
||
435 | |||
436 | $appendix = implode(', ', $appendix_asn1ids); |
||
437 | if (!empty($appendix)) $appendix = " ($appendix)"; |
||
438 | } else { |
||
439 | $appendix = ''; |
||
440 | } |
||
441 | return $appendix; |
||
442 | } |
||
443 | |||
444 | function is_root($id) { |
||
445 | return empty(explode(':',$id,2)[1]); |
||
416 | daniel-mar | 446 | } |
447 | |||
448 | function authTokenAccepted($content, $authTokens) { |
||
449 | foreach ($authTokens as $token) { |
||
450 | if (OIDplusPagePublicWhois::genWhoisAuthToken($content) == $token) return true; |
||
451 | } |
||
452 | return false; |
||
453 | } |
||
454 | |||
455 | function allowObjectView($obj, $authTokens) { |
||
456 | // Master auth token |
||
457 | $authToken = trim(OIDplus::config()->getValue('whois_auth_token')); |
||
458 | if (empty($authToken)) $authToken = false; |
||
459 | if ($authToken && in_array($authToken, $authTokens)) return true; |
||
460 | |||
461 | // Per-OID auth tokens |
||
462 | $curid = $obj->nodeId(); |
||
463 | while (($res = OIDplus::db()->query("select parent, confidential from ###objects where id = ?", array($curid)))->num_rows() > 0) { |
||
464 | $row = $res->fetch_array(); |
||
465 | // Example: You have an auth Token for 2.999.1.2.3 |
||
466 | // This allows you to view 2.999.1.2.3 and all of its children, |
||
467 | // as long as they are not confidential (then you need their auth token). |
||
468 | // 2, 2.999, 2.999.1 and 2.999.1.2 are visible, |
||
469 | // (because their existence is now obvious). |
||
470 | if ($row['confidential'] && !authTokenAccepted($curid, $authTokens)) return false; |
||
471 | $curid = $row['parent']; |
||
472 | } |
||
473 | |||
474 | // Allow |
||
475 | return true; |
||
476 | } |
||
477 | |||
478 | function allowRAView($row, $authTokens) { |
||
479 | // Master auth token |
||
480 | $authToken = trim(OIDplus::config()->getValue('whois_auth_token')); |
||
481 | if (empty($authToken)) $authToken = false; |
||
482 | if ($authToken && in_array($authToken, $authTokens)) return true; |
||
483 | |||
484 | // Per-RA auth tokens |
||
485 | if ($row->privacy && !authTokenAccepted('ra:'.$row->ra_name, $authTokens)) return false; |
||
486 | |||
487 | // Allow |
||
488 | return true; |
||
360 | daniel-mar | 489 | } |