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