|
1 | 1 | <?php |
2 | 2 |
|
3 | | -include __DIR__ . '/vendor/autoload.php'; |
4 | | - |
5 | 3 | include __DIR__ . '/config.php'; |
6 | 4 |
|
7 | 5 | define('INSTANCE_TITLE', 'CheckMyHTTPS API server'); |
|
57 | 55 | if (isset($_GET['port'])) $request_port = $_GET['port']; |
58 | 56 | if (isset($_GET['ip'])) $request_ip = $_GET['ip']; |
59 | 57 |
|
| 58 | +//error_log("AFFICHAGE DES VALEURS"); |
| 59 | +//error_log("Valeur host" . print_r($request_host, true) ); |
| 60 | +//error_log("Valeur ip" . print_r($request_ip, true) ); |
| 61 | + |
60 | 62 |
|
61 | 63 | // Service requested by the user |
62 | 64 | $service = (object) [ |
|
68 | 70 | // Parse host:port from URL |
69 | 71 | if ((isset($request_url)) && (!isset($request_host) && !isset($request_port))) |
70 | 72 | { |
71 | | - if ((!filter_var($request_url, FILTER_VALIDATE_URL)) && (!filter_var((new \Mso\IdnaConvert\IdnaConvert)->encode($request_url), FILTER_VALIDATE_URL))) |
| 73 | + if ((!filter_var($request_url, FILTER_VALIDATE_URL)) && (!filter_var(unicodeToPunycode($request_url), FILTER_VALIDATE_URL))) |
72 | 74 | { |
73 | 75 | echo json_encode(hashAndEncrypt((object)['error' => 'INVALID_URL'], $sign)); |
74 | 76 | exit(); |
|
100 | 102 | else |
101 | 103 | { |
102 | 104 | // Convert IDNA 2008 |
103 | | - $request_host = (new \Mso\IdnaConvert\IdnaConvert)->encode($request_host); |
| 105 | + $request_host = unicodeToPunycode($request_host); |
104 | 106 |
|
105 | 107 | if (preg_match('/^[a-zA-Z0-9-_.]+$/', $request_host)) |
106 | 108 | $service->host = $request_host; |
@@ -449,4 +451,17 @@ function checkHostWhitelisted($host) |
449 | 451 | } |
450 | 452 | return false; |
451 | 453 | } |
| 454 | + |
| 455 | +function unicodeToPunycode($input) { |
| 456 | + $normalized = \Normalizer::normalize($input, \Normalizer::FORM_C); |
| 457 | + $punycode = idn_to_ascii($normalized, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); |
| 458 | + return $punycode; |
| 459 | +} |
| 460 | + |
| 461 | +function punycodeToUnicode($input) { |
| 462 | + $unicode = idn_to_utf8($input, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); |
| 463 | + $normalized = \Normalizer::normalize($unicode, \Normalizer::FORM_C); |
| 464 | + return $normalized; |
| 465 | +} |
| 466 | + |
452 | 467 | ?> |
0 commit comments