Fixed couple of IDN related bugs

This commit is contained in:
Pinga 2024-01-25 10:26:30 +02:00
parent 4799d57f77
commit c737147aae
4 changed files with 6 additions and 4 deletions

View file

@ -1068,6 +1068,7 @@ class DomainsController extends Controller
$csrfTokenValue = $this->container->get('csrf')->getTokenValue(); $csrfTokenValue = $this->container->get('csrf')->getTokenValue();
if (strpos($domain['name'], 'xn--') === 0) { if (strpos($domain['name'], 'xn--') === 0) {
$domain['punycode'] = $domain['name'];
$domain['name'] = idn_to_utf8($domain['name'], IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46); $domain['name'] = idn_to_utf8($domain['name'], IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
} }
return view($response,'admin/domains/updateDomain.twig', [ return view($response,'admin/domains/updateDomain.twig', [

View file

@ -386,6 +386,7 @@ class HostsController extends Controller
[ $host['id'] ]); [ $host['id'] ]);
if (strpos($host['name'], 'xn--') === 0) { if (strpos($host['name'], 'xn--') === 0) {
$host['punycode'] = $host['name'];
$host['name'] = idn_to_utf8($host['name'], IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46); $host['name'] = idn_to_utf8($host['name'], IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
} }
return view($response,'admin/hosts/updateHost.twig', [ return view($response,'admin/hosts/updateHost.twig', [
@ -529,8 +530,8 @@ class HostsController extends Controller
$hostname = idn_to_ascii($hostname, 0, INTL_IDNA_VARIANT_UTS46); $hostname = idn_to_ascii($hostname, 0, INTL_IDNA_VARIANT_UTS46);
} }
// Regular expression for validating a hostname (simplified version) // Regular expression for validating a hostname
$pattern = '/^([a-zA-Z0-9-]{1,63}\.){1,}[a-zA-Z]{2,63}$/'; $pattern = '/^((xn--[a-zA-Z0-9-]{1,63}|[a-zA-Z0-9-]{1,63})\.){2,}(xn--[a-zA-Z0-9-]{2,63}|[a-zA-Z]{2,63})$/';
return preg_match($pattern, $hostname); return preg_match($pattern, $hostname);
} }

View file

@ -30,7 +30,7 @@
<div class="card mb-3"> <div class="card mb-3">
<div class="card-header"> <div class="card-header">
<h3 class="card-title"> <h3 class="card-title">
{{ __('Domain') }} {{ domain.name }}&nbsp;<input type="hidden" name="domainName" value="{{ domain.name }}"> {{ __('Domain') }} {{ domain.name }}&nbsp;<input type="hidden" name="domainName" value="{{ domain.punycode }}">
{% if domainStatus.status or domain.rgpstatus %} {% if domainStatus.status or domain.rgpstatus %}
{% if domainStatus is iterable %} {% if domainStatus is iterable %}
{% for status in domainStatus %} {% for status in domainStatus %}

View file

@ -28,7 +28,7 @@
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<form action="/host/update" method="post"> <form action="/host/update" method="post">
{{ csrf.field | raw }}<input type="hidden" name="hostName" value="{{ host.name }}"> {{ csrf.field | raw }}<input type="hidden" name="hostName" value="{{ host.punycode }}">
<div class="form-group mt-3"> <div class="form-group mt-3">
<label for="ipv4" class="form-label">{{ __('IPv4 Address') }}:</label> <label for="ipv4" class="form-label">{{ __('IPv4 Address') }}:</label>
<input type="text" class="form-control" id="ipv4" name="ipv4" placeholder="192.168.1.1" pattern="^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$" value="{{ hostIPv4[0].addr }}"> <input type="text" class="form-control" id="ipv4" name="ipv4" placeholder="192.168.1.1" pattern="^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$" value="{{ hostIPv4[0].addr }}">