diff --git a/cp/app/Controllers/RegistrarsController.php b/cp/app/Controllers/RegistrarsController.php index ddbff6d..0479fb4 100644 --- a/cp/app/Controllers/RegistrarsController.php +++ b/cp/app/Controllers/RegistrarsController.php @@ -67,9 +67,9 @@ class RegistrarsController extends Controller 'owner' => v::optional(v::keySet(...$contactValidator)), 'billing' => v::optional(v::keySet(...$contactValidator)), 'abuse' => v::optional(v::keySet(...$contactValidator)), - 'whoisServer' => v::domain(), - 'rdapServer' => v::domain(), - 'url' => v::url(), + 'whoisServer' => v::domain(false), + 'rdapServer' => v::domain(false), + 'url' => v::domain(false), 'abuseEmail' => v::email(), 'abusePhone' => v::optional($phoneValidator), 'accountBalance' => v::numericVal(), @@ -85,6 +85,11 @@ class RegistrarsController extends Controller 'panelPassword' => v::stringType()->notEmpty(), ]; + // Convert specified fields to Punycode if necessary + $data['whoisServer'] = isset($data['whoisServer']) ? toPunycode($data['whoisServer']) : null; + $data['rdapServer'] = isset($data['rdapServer']) ? toPunycode($data['rdapServer']) : null; + $data['url'] = isset($data['url']) ? toPunycode($data['url']) : null; + $errors = []; foreach ($validators as $field => $validator) { try { @@ -138,9 +143,9 @@ class RegistrarsController extends Controller 'pw' => $eppPassword, 'prefix' => $randomPrefix, 'email' => $data['email'], - 'url' => $data['url'], - 'whois_server' => $data['whoisServer'], - 'rdap_server' => $data['rdapServer'], + 'url' => isset($data['url']) ? toUnicode($data['url']) : null, + 'whois_server' => isset($data['whoisServer']) ? toUnicode($data['whoisServer']) : null, + 'rdap_server' => isset($data['rdapServer']) ? toUnicode($data['rdapServer']) : null, 'abuse_email' => $data['abuseEmail'], 'abuse_phone' => $data['abusePhone'], 'accountBalance' => $data['accountBalance'], @@ -565,9 +570,9 @@ class RegistrarsController extends Controller 'owner' => v::optional(v::keySet(...$contactValidator)), 'billing' => v::optional(v::keySet(...$contactValidator)), 'abuse' => v::optional(v::keySet(...$contactValidator)), - 'whoisServer' => v::domain(), - 'rdapServer' => v::domain(), - 'url' => v::url(), + 'whoisServer' => v::domain(false), + 'rdapServer' => v::domain(false), + 'url' => v::domain(false), 'abuseEmail' => v::email(), 'abusePhone' => v::optional($phoneValidator), 'creditLimit' => v::numericVal(), @@ -575,6 +580,11 @@ class RegistrarsController extends Controller 'ipAddress' => v::optional($ipAddressValidator) ]; + // Convert specified fields to Punycode if necessary + $data['whoisServer'] = isset($data['whoisServer']) ? toPunycode($data['whoisServer']) : null; + $data['rdapServer'] = isset($data['rdapServer']) ? toPunycode($data['rdapServer']) : null; + $data['url'] = isset($data['url']) ? toPunycode($data['url']) : null; + $errors = []; foreach ($validators as $field => $validator) { try { @@ -596,14 +606,14 @@ class RegistrarsController extends Controller $errorText = rtrim($errorText, '; '); $this->container->get('flash')->addMessage('error', $errorText); - return $response->withHeader('Location', '/registrars')->withStatus(302); + return $response->withHeader('Location', '/registrar/update/'.$registrar)->withStatus(302); } if (!empty($_SESSION['registrars_user_email'])) { $regEmail = $_SESSION['registrars_user_email'][0]; } else { $this->container->get('flash')->addMessage('error', 'No email specified for update'); - return $response->withHeader('Location', '/registrars')->withStatus(302); + return $response->withHeader('Location', '/registrar/update/'.$registrar)->withStatus(302); } $db->beginTransaction(); @@ -621,9 +631,9 @@ class RegistrarsController extends Controller 'name' => $data['name'], 'iana_id' => $data['ianaId'], 'email' => $data['email'], - 'url' => $data['url'], - 'whois_server' => $data['whoisServer'], - 'rdap_server' => $data['rdapServer'], + 'url' => isset($data['url']) ? toUnicode($data['url']) : null, + 'whois_server' => isset($data['whoisServer']) ? toUnicode($data['whoisServer']) : null, + 'rdap_server' => isset($data['rdapServer']) ? toUnicode($data['rdapServer']) : null, 'abuse_email' => $data['abuseEmail'], 'abuse_phone' => $data['abusePhone'], 'creditLimit' => $data['creditLimit'], @@ -807,13 +817,18 @@ class RegistrarsController extends Controller 'owner' => v::optional(v::keySet(...$contactValidator)), 'billing' => v::optional(v::keySet(...$contactValidator)), 'abuse' => v::optional(v::keySet(...$contactValidator)), - 'whoisServer' => v::domain(), - 'rdapServer' => v::domain(), - 'url' => v::url(), + 'whoisServer' => v::domain(false), + 'rdapServer' => v::domain(false), + 'url' => v::domain(false), 'abuseEmail' => v::email(), 'abusePhone' => v::optional($phoneValidator), 'ipAddress' => v::optional($ipAddressValidator) ]; + + // Convert specified fields to Punycode if necessary + $data['whoisServer'] = isset($data['whoisServer']) ? toPunycode($data['whoisServer']) : null; + $data['rdapServer'] = isset($data['rdapServer']) ? toPunycode($data['rdapServer']) : null; + $data['url'] = isset($data['url']) ? toPunycode($data['url']) : null; $errors = []; foreach ($validators as $field => $validator) { @@ -861,9 +876,9 @@ class RegistrarsController extends Controller 'name' => $data['name'], 'iana_id' => $data['ianaId'], 'email' => $data['email'], - 'url' => $data['url'], - 'whois_server' => $data['whoisServer'], - 'rdap_server' => $data['rdapServer'], + 'url' => isset($data['url']) ? toUnicode($data['url']) : null, + 'whois_server' => isset($data['whoisServer']) ? toUnicode($data['whoisServer']) : null, + 'rdap_server' => isset($data['rdapServer']) ? toUnicode($data['rdapServer']) : null, 'abuse_email' => $data['abuseEmail'], 'abuse_phone' => $data['abusePhone'], 'currency' => $currency, diff --git a/cp/bootstrap/helper.php b/cp/bootstrap/helper.php index 4b8f062..e109477 100644 --- a/cp/bootstrap/helper.php +++ b/cp/bootstrap/helper.php @@ -576,4 +576,14 @@ function validateUniversalEmail($email) { // Validate using regex return preg_match($emailPattern, $emailToValidate); +} + +function toPunycode($value) { + // Convert to Punycode if it contains non-ASCII characters + return preg_match('/[^\x00-\x7F]/', $value) ? idn_to_ascii($value, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) : $value; +} + +function toUnicode($value) { + // Convert from Punycode to UTF-8 if it's a valid IDN format + return (strpos($value, 'xn--') === 0) ? idn_to_utf8($value, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) : $value; } \ No newline at end of file diff --git a/cp/resources/views/admin/registrars/create.twig b/cp/resources/views/admin/registrars/create.twig index a16a0d2..48bc637 100644 --- a/cp/resources/views/admin/registrars/create.twig +++ b/cp/resources/views/admin/registrars/create.twig @@ -46,12 +46,17 @@