mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: check malformed domain names
This commit is contained in:
@@ -6,6 +6,7 @@ use ApiPlatform\Metadata\ApiProperty;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Config\EventAction;
|
||||
use App\Exception\MalformedDomainException;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Service\RDAPService;
|
||||
use App\State\AutoRegisterDomainProvider;
|
||||
@@ -177,6 +178,9 @@ class Domain
|
||||
return $this->ldhName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MalformedDomainException
|
||||
*/
|
||||
public function setLdhName(string $ldhName): static
|
||||
{
|
||||
$this->ldhName = RDAPService::convertToIdn($ldhName);
|
||||
|
||||
@@ -6,6 +6,6 @@ class MalformedDomainException extends \Exception
|
||||
{
|
||||
public static function fromDomain(string $ldhName): self
|
||||
{
|
||||
return new self("Domain name ($ldhName) must contain at least one dot");
|
||||
return new self("Malformed domain name ($ldhName)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,9 +197,18 @@ class RDAPService
|
||||
return $tldEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MalformedDomainException
|
||||
*/
|
||||
public static function convertToIdn(string $fqdn): string
|
||||
{
|
||||
return strtolower(idn_to_ascii($fqdn));
|
||||
$ascii = strtolower(idn_to_ascii($fqdn));
|
||||
|
||||
if (OfficialDataService::DOMAIN_DOT !== $fqdn && !preg_match('/^(xn--)?[a-z0-9-]+(\.[a-z0-9-]+)*$/', $ascii)) {
|
||||
throw MalformedDomainException::fromDomain($fqdn);
|
||||
}
|
||||
|
||||
return $ascii;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -52,7 +52,6 @@ readonly class AutoRegisterDomainProvider implements ProviderInterface
|
||||
if (null !== $domain
|
||||
&& !$domain->getDeleted()
|
||||
&& !$domain->isToBeUpdated(true, true)
|
||||
&& !$this->kernel->isDebug()
|
||||
&& ($request && !filter_var($request->get('forced', false), FILTER_VALIDATE_BOOLEAN))
|
||||
) {
|
||||
$this->logger->debug('It is not necessary to update the domain name', [
|
||||
|
||||
Reference in New Issue
Block a user