mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add ICANN accreditation status on domain result page
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Api\Extension;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
|
||||
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use App\Entity\Entity;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
class NotNullAccreditationIcannExtension implements QueryCollectionExtensionInterface
|
||||
{
|
||||
public function applyToCollection(
|
||||
QueryBuilder $queryBuilder,
|
||||
QueryNameGeneratorInterface $queryNameGenerator,
|
||||
string $resourceClass,
|
||||
?Operation $operation = null,
|
||||
array $context = [],
|
||||
): void {
|
||||
if (Entity::class !== $resourceClass) {
|
||||
return;
|
||||
}
|
||||
if ($operation && 'icann_accreditations_collection' === $operation->getName()) {
|
||||
$rootAlias = $queryBuilder->getRootAliases()[0];
|
||||
$queryBuilder->andWhere(sprintf('%s.icannAccreditation.status IS NOT NULL', $rootAlias));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,11 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use App\Repository\EntityRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\Mapping\Embedded;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
|
||||
@@ -20,31 +16,6 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
)]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/entities/icann-accreditations',
|
||||
openapiContext: [
|
||||
'parameters' => [
|
||||
[
|
||||
'name' => 'icannAccreditation.status',
|
||||
'in' => 'query',
|
||||
'required' => true,
|
||||
'schema' => [
|
||||
'type' => 'array',
|
||||
'items' => [
|
||||
'type' => 'string',
|
||||
'enum' => ['Accredited', 'Terminated', 'Reserved'],
|
||||
],
|
||||
],
|
||||
'style' => 'form',
|
||||
'explode' => true,
|
||||
'description' => 'Filter by ICANN accreditation status',
|
||||
],
|
||||
],
|
||||
],
|
||||
description: 'ICANN Registrar IDs list',
|
||||
normalizationContext: ['groups' => ['entity:list']],
|
||||
name: 'icann_accreditations_collection'
|
||||
),
|
||||
/*
|
||||
new GetCollection(
|
||||
uriTemplate: '/entities',
|
||||
@@ -67,12 +38,6 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
*/
|
||||
]
|
||||
)]
|
||||
#[ApiFilter(
|
||||
SearchFilter::class,
|
||||
properties: [
|
||||
'icannAccreditation.status' => 'exact',
|
||||
]
|
||||
)]
|
||||
class Entity
|
||||
{
|
||||
#[ORM\Id]
|
||||
@@ -81,7 +46,7 @@ class Entity
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Tld::class, inversedBy: 'entities')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'tld', nullable: true)]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'tld', nullable: false)]
|
||||
#[Groups(['entity:list', 'entity:item', 'domain:item'])]
|
||||
private ?Tld $tld = null;
|
||||
|
||||
@@ -120,7 +85,7 @@ class Entity
|
||||
#[Groups(['entity:item', 'domain:item'])]
|
||||
private ?array $remarks = null;
|
||||
|
||||
#[Embedded(class: IcannAccreditation::class, columnPrefix: 'icann_')]
|
||||
#[ORM\ManyToOne(inversedBy: 'entities')]
|
||||
#[Groups(['entity:list', 'entity:item', 'domain:item'])]
|
||||
private ?IcannAccreditation $icannAccreditation = null;
|
||||
|
||||
@@ -129,7 +94,6 @@ class Entity
|
||||
$this->domainEntities = new ArrayCollection();
|
||||
$this->nameserverEntities = new ArrayCollection();
|
||||
$this->events = new ArrayCollection();
|
||||
$this->icannAccreditation = new IcannAccreditation();
|
||||
}
|
||||
|
||||
public function getHandle(): ?string
|
||||
@@ -284,11 +248,13 @@ class Entity
|
||||
|
||||
public function getIcannAccreditation(): ?IcannAccreditation
|
||||
{
|
||||
return null === $this->icannAccreditation->getStatus() ? null : $this->icannAccreditation;
|
||||
return $this->icannAccreditation;
|
||||
}
|
||||
|
||||
public function setIcannAccreditation(?IcannAccreditation $icannAccreditation): void
|
||||
public function setIcannAccreditation(?IcannAccreditation $icannAccreditation): static
|
||||
{
|
||||
$this->icannAccreditation = $icannAccreditation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,35 +2,92 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
|
||||
use ApiPlatform\Metadata\ApiFilter;
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use App\Config\RegistrarStatus;
|
||||
use App\Repository\IcannAccreditationRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\ORM\Mapping\Embeddable;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[Embeddable]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new GetCollection(
|
||||
uriTemplate: '/icann-accreditations',
|
||||
openapiContext: [
|
||||
'parameters' => [
|
||||
[
|
||||
'name' => 'status',
|
||||
'in' => 'query',
|
||||
'required' => true,
|
||||
'schema' => [
|
||||
'type' => 'array',
|
||||
'items' => [
|
||||
'type' => 'string',
|
||||
'enum' => ['Accredited', 'Terminated', 'Reserved'],
|
||||
],
|
||||
],
|
||||
'style' => 'form',
|
||||
'explode' => true,
|
||||
'description' => 'Filter by ICANN accreditation status',
|
||||
],
|
||||
],
|
||||
],
|
||||
shortName: 'ICANN Accreditation',
|
||||
description: 'ICANN Registrar IDs list',
|
||||
normalizationContext: ['groups' => ['icann:list']]
|
||||
),
|
||||
]
|
||||
)]
|
||||
#[ApiFilter(
|
||||
SearchFilter::class,
|
||||
properties: [
|
||||
'status' => 'exact',
|
||||
]
|
||||
)]
|
||||
#[ORM\Entity(repositoryClass: IcannAccreditationRepository::class)]
|
||||
class IcannAccreditation
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column]
|
||||
#[Groups(['icann:item', 'icann:list', 'domain:item'])]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Groups(['entity:item', 'entity:list', 'domain:item'])]
|
||||
#[Groups(['icann:item', 'icann:list', 'domain:item'])]
|
||||
private ?string $registrarName = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Groups(['entity:item', 'domain:item'])]
|
||||
#[Groups(['icann:item'])]
|
||||
private ?string $rdapBaseUrl = null;
|
||||
|
||||
#[ORM\Column(nullable: true, enumType: RegistrarStatus::class)]
|
||||
#[Groups(['entity:item', 'entity:list', 'domain:item'])]
|
||||
#[Groups(['icann:item', 'icann:list', 'domain:item'])]
|
||||
private ?RegistrarStatus $status = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||
#[Groups(['entity:item', 'entity:list', 'domain:item'])]
|
||||
#[Groups(['icann:item', 'icann:list', 'domain:item'])]
|
||||
private ?\DateTimeImmutable $updated = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||
#[Groups(['entity:item', 'entity:list', 'domain:item'])]
|
||||
#[Groups(['icann:item', 'icann:list', 'domain:item'])]
|
||||
private ?\DateTimeImmutable $date = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, Entity>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Entity::class, mappedBy: 'icannAccreditation')]
|
||||
private Collection $entities;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->entities = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getRegistrarName(): ?string
|
||||
{
|
||||
return $this->registrarName;
|
||||
@@ -90,4 +147,46 @@ class IcannAccreditation
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(?int $id): static
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Entity>
|
||||
*/
|
||||
public function getEntities(): Collection
|
||||
{
|
||||
return $this->entities;
|
||||
}
|
||||
|
||||
public function addEntity(Entity $entity): static
|
||||
{
|
||||
if (!$this->entities->contains($entity)) {
|
||||
$this->entities->add($entity);
|
||||
$entity->setIcannAccreditation($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeEntity(Entity $entity): static
|
||||
{
|
||||
if ($this->entities->removeElement($entity)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($entity->getIcannAccreditation() === $this) {
|
||||
$entity->setIcannAccreditation(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
43
src/Repository/IcannAccreditationRepository.php
Normal file
43
src/Repository/IcannAccreditationRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\IcannAccreditation;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<IcannAccreditation>
|
||||
*/
|
||||
class IcannAccreditationRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, IcannAccreditation::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Connector[] Returns an array of Connector objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('c')
|
||||
// ->andWhere('c.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('c.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?Connector
|
||||
// {
|
||||
// return $this->createQueryBuilder('c')
|
||||
// ->andWhere('c.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
@@ -14,6 +14,7 @@ use App\Entity\DomainEvent;
|
||||
use App\Entity\DomainStatus;
|
||||
use App\Entity\Entity;
|
||||
use App\Entity\EntityEvent;
|
||||
use App\Entity\IcannAccreditation;
|
||||
use App\Entity\Nameserver;
|
||||
use App\Entity\NameserverEntity;
|
||||
use App\Entity\RdapServer;
|
||||
@@ -23,6 +24,7 @@ use App\Repository\DomainEventRepository;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Repository\EntityEventRepository;
|
||||
use App\Repository\EntityRepository;
|
||||
use App\Repository\IcannAccreditationRepository;
|
||||
use App\Repository\NameserverEntityRepository;
|
||||
use App\Repository\NameserverRepository;
|
||||
use App\Repository\RdapServerRepository;
|
||||
@@ -105,6 +107,7 @@ class RDAPService
|
||||
private DomainEntityRepository $domainEntityRepository,
|
||||
private RdapServerRepository $rdapServerRepository,
|
||||
private TldRepository $tldRepository,
|
||||
private IcannAccreditationRepository $icannAccreditationRepository,
|
||||
private EntityManagerInterface $em,
|
||||
private LoggerInterface $logger,
|
||||
private StatService $statService,
|
||||
@@ -344,7 +347,6 @@ class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \DateMalformedStringException
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function updateDomainEvents(Domain $domain, array $rdapData): void
|
||||
@@ -380,7 +382,6 @@ class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \DateMalformedStringException
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function updateDomainEntities(Domain $domain, array $rdapData): void
|
||||
@@ -418,7 +419,7 @@ class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \DateMalformedStringException
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function updateDomainNameservers(Domain $domain, array $rdapData): void
|
||||
{
|
||||
@@ -461,7 +462,7 @@ class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \DateMalformedStringException
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function updateNameserverEntities(Nameserver $nameserver, array $rdapNameserver, Tld $tld): void
|
||||
{
|
||||
@@ -517,36 +518,10 @@ class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \DateMalformedStringException
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function registerEntity(array $rdapEntity, array $roles, string $domain, Tld $tld): Entity
|
||||
{
|
||||
$entity = null;
|
||||
|
||||
/**
|
||||
* If the RDAP server transmits the entity's IANA number, it is used as a priority to identify the entity.
|
||||
*
|
||||
* @see https://datatracker.ietf.org/doc/html/rfc7483#section-4.8
|
||||
*/
|
||||
$isIANAid = false;
|
||||
if (isset($rdapEntity['publicIds'])) {
|
||||
foreach ($rdapEntity['publicIds'] as $publicId) {
|
||||
if ('IANA Registrar ID' === $publicId['type'] && isset($publicId['identifier']) && '' !== $publicId['identifier']) {
|
||||
$entity = $this->entityRepository->findOneBy([
|
||||
'handle' => $publicId['identifier'],
|
||||
'tld' => null,
|
||||
]);
|
||||
|
||||
if (null !== $entity) {
|
||||
$rdapEntity['handle'] = $publicId['identifier'];
|
||||
$isIANAid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If there is no number to identify the entity, one is generated from the domain name and the roles associated with this entity
|
||||
*/
|
||||
@@ -559,16 +534,10 @@ class RDAPService
|
||||
]);
|
||||
}
|
||||
|
||||
if (null === $entity) {
|
||||
$entity = $this->entityRepository->findOneBy([
|
||||
'handle' => $rdapEntity['handle'],
|
||||
'tld' => $tld,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($isIANAid && null !== $entity) {
|
||||
return $entity;
|
||||
}
|
||||
$entity = $this->entityRepository->findOneBy([
|
||||
'handle' => $rdapEntity['handle'],
|
||||
'tld' => $tld,
|
||||
]);
|
||||
|
||||
if (null === $entity) {
|
||||
$entity = (new Entity())->setTld($tld);
|
||||
@@ -578,7 +547,23 @@ class RDAPService
|
||||
]);
|
||||
}
|
||||
|
||||
$entity->setHandle($rdapEntity['handle']);
|
||||
/**
|
||||
* If the RDAP server transmits the entity's IANA number, it is used as a priority to identify the entity.
|
||||
*
|
||||
* @see https://datatracker.ietf.org/doc/html/rfc7483#section-4.8
|
||||
*/
|
||||
$icannAccreditation = null;
|
||||
if (isset($rdapEntity['publicIds'])) {
|
||||
foreach ($rdapEntity['publicIds'] as $publicId) {
|
||||
if ('IANA Registrar ID' === $publicId['type'] && isset($publicId['identifier']) && '' !== $publicId['identifier']) {
|
||||
$icannAccreditation = $this->icannAccreditationRepository->findOneBy([
|
||||
'id' => (int) $publicId['identifier'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$entity->setHandle($rdapEntity['handle'])->setIcannAccreditation($icannAccreditation);
|
||||
|
||||
if (isset($rdapEntity['remarks']) && is_array($rdapEntity['remarks'])) {
|
||||
$entity->setRemarks($rdapEntity['remarks']);
|
||||
@@ -719,7 +704,7 @@ class RDAPService
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws ORMException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateRDAPServersFromIANA(): void
|
||||
{
|
||||
@@ -733,7 +718,6 @@ class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ORMException
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function updateRDAPServers(array $dnsRoot): void
|
||||
@@ -772,6 +756,7 @@ class RDAPService
|
||||
|
||||
/**
|
||||
* @throws ORMException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateRDAPServersFromFile(string $fileName): void
|
||||
{
|
||||
@@ -836,7 +821,6 @@ class RDAPService
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws \Exception
|
||||
*/
|
||||
@@ -850,23 +834,20 @@ class RDAPService
|
||||
$data = new \SimpleXMLElement($registrarList->getContent());
|
||||
|
||||
foreach ($data->registry->record as $registrar) {
|
||||
$entity = $this->entityRepository->findOneBy(['handle' => $registrar->value, 'tld' => null]);
|
||||
if (null === $entity) {
|
||||
$entity = new Entity();
|
||||
$icannAcreditation = $this->icannAccreditationRepository->findOneBy(['id' => (int) $registrar->value]);
|
||||
if (null === $icannAcreditation) {
|
||||
$icannAcreditation = new IcannAccreditation();
|
||||
}
|
||||
$entity
|
||||
->setHandle($registrar->value)
|
||||
->setTld(null)
|
||||
->setJCard(['vcard', [['version', [], 'text', '4.0'], ['fn', [], 'text', (string) $registrar->name]]])
|
||||
->setRemarks(null)
|
||||
->getIcannAccreditation()
|
||||
->setRegistrarName($registrar->name)
|
||||
->setStatus(RegistrarStatus::from($registrar->status))
|
||||
->setRdapBaseUrl($registrar->rdapurl->count() ? ($registrar->rdapurl->server) : null)
|
||||
->setUpdated(null !== $registrar->attributes()->updated ? new \DateTimeImmutable($registrar->attributes()->updated) : null)
|
||||
->setDate(null !== $registrar->attributes()->date ? new \DateTimeImmutable($registrar->attributes()->date) : null);
|
||||
|
||||
$this->em->persist($entity);
|
||||
$icannAcreditation
|
||||
->setId((int) $registrar->value)
|
||||
->setRegistrarName($registrar->name)
|
||||
->setStatus(RegistrarStatus::from($registrar->status))
|
||||
->setRdapBaseUrl($registrar->rdapurl->count() ? ($registrar->rdapurl->server) : null)
|
||||
->setUpdated(null !== $registrar->attributes()->updated ? new \DateTimeImmutable($registrar->attributes()->updated) : null)
|
||||
->setDate(null !== $registrar->attributes()->date ? new \DateTimeImmutable($registrar->attributes()->date) : null);
|
||||
|
||||
$this->em->persist($icannAcreditation);
|
||||
}
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user