mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add tld properties
This commit is contained in:
@@ -105,6 +105,10 @@ class Domain
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
private ?DateTimeImmutable $updatedAt = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'tld', nullable: false)]
|
||||
private ?Tld $tld = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->events = new ArrayCollection();
|
||||
@@ -293,4 +297,16 @@ class Domain
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
}
|
||||
|
||||
public function getTld(): ?Tld
|
||||
{
|
||||
return $this->tld;
|
||||
}
|
||||
|
||||
public function setTld(?Tld $tld): static
|
||||
{
|
||||
$this->tld = $tld;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,6 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
#[ORM\Entity(repositoryClass: RdapServerRepository::class)]
|
||||
class RdapServer
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 63)]
|
||||
private ?string $tld = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
@@ -21,23 +18,17 @@ class RdapServer
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
private ?DateTimeImmutable $updatedAt = null;
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\ManyToOne(inversedBy: 'rdapServers')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'tld', nullable: false)]
|
||||
private ?Tld $tld = null;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->updatedAt = new DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
public function getTld(): ?string
|
||||
{
|
||||
return $this->tld;
|
||||
}
|
||||
|
||||
public function setTld(string $tld): static
|
||||
{
|
||||
$this->tld = $tld;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(): ?string
|
||||
{
|
||||
return $this->url;
|
||||
@@ -68,4 +59,16 @@ class RdapServer
|
||||
{
|
||||
$this->setUpdatedAt(new DateTimeImmutable('now'));
|
||||
}
|
||||
|
||||
public function getTld(): ?Tld
|
||||
{
|
||||
return $this->tld;
|
||||
}
|
||||
|
||||
public function setTld(?Tld $tld): static
|
||||
{
|
||||
$this->tld = $tld;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
160
src/Entity/Tld.php
Normal file
160
src/Entity/Tld.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\TldRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: TldRepository::class)]
|
||||
class Tld
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 63)]
|
||||
private ?string $tld = null;
|
||||
/**
|
||||
* @var Collection<int, RdapServer>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: RdapServer::class, mappedBy: 'tld', orphanRemoval: true)]
|
||||
private Collection $rdapServers;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $contractTerminated = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||
private ?DateTimeImmutable $dateOfContractSignature = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||
private ?DateTimeImmutable $delegationDate = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $registryOperator = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||
private ?DateTimeImmutable $removalDate = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $specification13 = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->rdapServers = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, RdapServer>
|
||||
*/
|
||||
public function getRdapServers(): Collection
|
||||
{
|
||||
return $this->rdapServers;
|
||||
}
|
||||
|
||||
public function addRdapServer(RdapServer $rdapServer): static
|
||||
{
|
||||
if (!$this->rdapServers->contains($rdapServer)) {
|
||||
$this->rdapServers->add($rdapServer);
|
||||
$rdapServer->setTld($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeRdapServer(RdapServer $rdapServer): static
|
||||
{
|
||||
if ($this->rdapServers->removeElement($rdapServer)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($rdapServer->getTld() === $this) {
|
||||
$rdapServer->setTld(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTld(): ?string
|
||||
{
|
||||
return $this->tld;
|
||||
}
|
||||
|
||||
public function setTld(string $tld): static
|
||||
{
|
||||
$this->tld = strtolower($tld);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isContractTerminated(): ?bool
|
||||
{
|
||||
return $this->contractTerminated;
|
||||
}
|
||||
|
||||
public function setContractTerminated(?bool $contractTerminated): static
|
||||
{
|
||||
$this->contractTerminated = $contractTerminated;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateOfContractSignature(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->dateOfContractSignature;
|
||||
}
|
||||
|
||||
public function setDateOfContractSignature(?DateTimeImmutable $dateOfContractSignature): static
|
||||
{
|
||||
$this->dateOfContractSignature = $dateOfContractSignature;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDelegationDate(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->delegationDate;
|
||||
}
|
||||
|
||||
public function setDelegationDate(?DateTimeImmutable $delegationDate): static
|
||||
{
|
||||
$this->delegationDate = $delegationDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRegistryOperator(): ?string
|
||||
{
|
||||
return $this->registryOperator;
|
||||
}
|
||||
|
||||
public function setRegistryOperator(?string $registryOperator): static
|
||||
{
|
||||
$this->registryOperator = $registryOperator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRemovalDate(): ?DateTimeImmutable
|
||||
{
|
||||
return $this->removalDate;
|
||||
}
|
||||
|
||||
public function setRemovalDate(?DateTimeImmutable $removalDate): static
|
||||
{
|
||||
$this->removalDate = $removalDate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSpecification13(): ?bool
|
||||
{
|
||||
return $this->specification13;
|
||||
}
|
||||
|
||||
public function setSpecification13(?bool $specification13): static
|
||||
{
|
||||
$this->specification13 = $specification13;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final readonly class UpdateRdapServersHandler
|
||||
@@ -25,10 +26,28 @@ final readonly class UpdateRdapServersHandler
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws ClientExceptionInterface|Throwable
|
||||
*/
|
||||
public function __invoke(UpdateRdapServers $message): void
|
||||
{
|
||||
$this->RDAPService->updateRDAPServers();
|
||||
/** @var Throwable[] $throws */
|
||||
$throws = [];
|
||||
try {
|
||||
$this->RDAPService->updateTldListIANA();
|
||||
} catch (Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->RDAPService->updateGTldListICANN();
|
||||
} catch (Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
try {
|
||||
$this->RDAPService->updateRDAPServers();
|
||||
} catch (Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
if (!empty($throwable)) throw $throws[0];
|
||||
}
|
||||
}
|
||||
|
||||
43
src/Repository/TldRepository.php
Normal file
43
src/Repository/TldRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Tld;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Tld>
|
||||
*/
|
||||
class TldRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, Tld::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Tld[] Returns an array of Tld objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('t')
|
||||
// ->andWhere('t.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('t.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Tld
|
||||
// {
|
||||
// return $this->createQueryBuilder('t')
|
||||
// ->andWhere('t.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -22,7 +22,7 @@ final readonly class UpdateRdapServersSchedule implements ScheduleProviderInterf
|
||||
{
|
||||
return (new Schedule())
|
||||
->add(
|
||||
RecurringMessage::every('1 month', new UpdateRdapServers()),
|
||||
RecurringMessage::every('30 seconds', new UpdateRdapServers()),
|
||||
)->stateful($this->cache);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\Entity\EntityEvent;
|
||||
use App\Entity\Nameserver;
|
||||
use App\Entity\NameserverEntity;
|
||||
use App\Entity\RdapServer;
|
||||
use App\Entity\Tld;
|
||||
use App\Repository\DomainEntityRepository;
|
||||
use App\Repository\DomainEventRepository;
|
||||
use App\Repository\DomainRepository;
|
||||
@@ -21,8 +22,10 @@ use App\Repository\EntityRepository;
|
||||
use App\Repository\NameserverEntityRepository;
|
||||
use App\Repository\NameserverRepository;
|
||||
use App\Repository\RdapServerRepository;
|
||||
use App\Repository\TldRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Exception\ORMException;
|
||||
use Exception;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
@@ -44,6 +47,7 @@ readonly class RDAPService
|
||||
private EntityEventRepository $entityEventRepository,
|
||||
private DomainEntityRepository $domainEntityRepository,
|
||||
private RdapServerRepository $rdapServerRepository,
|
||||
private TldRepository $tldRepository,
|
||||
private EntityManagerInterface $em
|
||||
)
|
||||
{
|
||||
@@ -66,9 +70,10 @@ readonly class RDAPService
|
||||
private function registerDomain(string $fqdn): void
|
||||
{
|
||||
$idnDomain = idn_to_ascii($fqdn);
|
||||
$tld = $this->getTld($idnDomain);
|
||||
|
||||
/** @var RdapServer|null $rdapServer */
|
||||
$rdapServer = $this->rdapServerRepository->findOneBy(["tld" => RDAPService::getTld($idnDomain)]);
|
||||
$rdapServer = $this->rdapServerRepository->findOneBy(["tld" => $tld], ["updatedAt" => "DESC"]);
|
||||
|
||||
if ($rdapServer === null) throw new Exception("Unable to determine which RDAP server to contact");
|
||||
|
||||
@@ -84,6 +89,7 @@ readonly class RDAPService
|
||||
if ($domain === null) $domain = new Domain();
|
||||
|
||||
$domain
|
||||
->setTld($tld)
|
||||
->setLdhName($res['ldhName'])
|
||||
->setHandle($res['handle'])
|
||||
->setStatus($res['status']);
|
||||
@@ -178,13 +184,15 @@ readonly class RDAPService
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function getTld($domain): string
|
||||
private function getTld($domain): ?object
|
||||
{
|
||||
$lastDotPosition = strrpos($domain, '.');
|
||||
if ($lastDotPosition === false) {
|
||||
throw new Exception("Domain must contain at least one dot");
|
||||
}
|
||||
return strtolower(substr($domain, $lastDotPosition + 1));
|
||||
$tld = strtolower(substr($domain, $lastDotPosition + 1));
|
||||
|
||||
return $this->tldRepository->findOneBy(["tld" => $tld]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,6 +248,7 @@ readonly class RDAPService
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws ORMException
|
||||
*/
|
||||
public function updateRDAPServers(): void
|
||||
{
|
||||
@@ -250,11 +259,11 @@ readonly class RDAPService
|
||||
foreach ($dnsRoot['services'] as $service) {
|
||||
|
||||
foreach ($service[0] as $tld) {
|
||||
$tldReference = $this->em->getReference(Tld::class, $tld);
|
||||
foreach ($service[1] as $rdapServerUrl) {
|
||||
$server = $this->rdapServerRepository->findOneBy(["tld" => $tld, "url" => $rdapServerUrl]);
|
||||
$server = $this->rdapServerRepository->findOneBy(["tld" => $tldReference, "url" => $rdapServerUrl]); //ICI
|
||||
if ($server === null) $server = new RdapServer();
|
||||
|
||||
$server->setTld($tld)->setUrl($rdapServerUrl)->updateTimestamps();
|
||||
$server->setTld($tldReference)->setUrl($rdapServerUrl)->updateTimestamps();
|
||||
|
||||
$this->em->persist($server);
|
||||
}
|
||||
@@ -263,4 +272,60 @@ readonly class RDAPService
|
||||
}
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
*/
|
||||
public function updateTldListIANA(): void
|
||||
{
|
||||
$tldList = array_map(
|
||||
fn($tld) => strtolower($tld),
|
||||
explode(PHP_EOL,
|
||||
$this->client->request(
|
||||
'GET', 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt'
|
||||
)->getContent()
|
||||
));
|
||||
array_shift($tldList);
|
||||
$storedTldList = array_map(fn($tld) => $tld->getTld(), $this->tldRepository->findAll());
|
||||
|
||||
|
||||
foreach (array_diff($tldList, $storedTldList) as $tld) {
|
||||
$this->em->persist((new Tld())->setTld($tld));
|
||||
}
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateGTldListICANN(): void
|
||||
{
|
||||
$gTldList = $this->client->request(
|
||||
'GET', 'https://www.icann.org/resources/registries/gtlds/v2/gtlds.json'
|
||||
)->toArray()['gTLDs'];
|
||||
|
||||
foreach ($gTldList as $gTld) {
|
||||
$gtTldEntity = $this->tldRepository->findOneBy(['tld' => $gTld['gTLD']]);
|
||||
if ($gtTldEntity === null) $gtTldEntity = new Tld();
|
||||
|
||||
$gtTldEntity
|
||||
->setTld($gTld['gTLD'])
|
||||
->setContractTerminated($gTld['contractTerminated'])
|
||||
->setRegistryOperator($gTld['registryOperator'])
|
||||
->setSpecification13($gTld['specification13']);
|
||||
if ($gTld['removalDate'] !== null) $gtTldEntity->setRemovalDate(new DateTimeImmutable($gTld['removalDate']));
|
||||
if ($gTld['delegationDate'] !== null) $gtTldEntity->setDelegationDate(new DateTimeImmutable($gTld['delegationDate']));
|
||||
if ($gTld['dateOfContractSignature'] !== null) $gtTldEntity->setDateOfContractSignature(new DateTimeImmutable($gTld['dateOfContractSignature']));
|
||||
$this->em->persist($gtTldEntity);
|
||||
}
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user