mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: add tld type property
This commit is contained in:
38
migrations/Version20240724160636.php
Normal file
38
migrations/Version20240724160636.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20240724160636 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE tld ADD COLUMN type VARCHAR(10) DEFAULT NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('CREATE TEMPORARY TABLE __temp__tld AS SELECT tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13 FROM tld');
|
||||||
|
$this->addSql('DROP TABLE tld');
|
||||||
|
$this->addSql('CREATE TABLE tld (tld VARCHAR(63) NOT NULL, contract_terminated BOOLEAN DEFAULT NULL, date_of_contract_signature DATE DEFAULT NULL --(DC2Type:date_immutable)
|
||||||
|
, delegation_date DATE DEFAULT NULL --(DC2Type:date_immutable)
|
||||||
|
, registry_operator VARCHAR(255) DEFAULT NULL, removal_date DATE DEFAULT NULL --(DC2Type:date_immutable)
|
||||||
|
, specification13 BOOLEAN DEFAULT NULL, PRIMARY KEY(tld))');
|
||||||
|
$this->addSql('INSERT INTO tld (tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13) SELECT tld, contract_terminated, date_of_contract_signature, delegation_date, registry_operator, removal_date, specification13 FROM __temp__tld');
|
||||||
|
$this->addSql('DROP TABLE __temp__tld');
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/Config/TldType.php
Normal file
13
src/Config/TldType.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Config;
|
||||||
|
|
||||||
|
|
||||||
|
enum TldType: string
|
||||||
|
{
|
||||||
|
case iTLD = 'iTLD';
|
||||||
|
case gTLD = "gTLD";
|
||||||
|
case sTLD = "sTLD";
|
||||||
|
case ccTLD = "ccTLD";
|
||||||
|
case tTLD = "tTLD";
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace App\Entity;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
|
use App\Config\TldType;
|
||||||
use App\Repository\TldRepository;
|
use App\Repository\TldRepository;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@@ -63,6 +64,9 @@ class Tld
|
|||||||
#[Groups(["tld:item"])]
|
#[Groups(["tld:item"])]
|
||||||
private ?bool $specification13 = null;
|
private ?bool $specification13 = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 10, nullable: true, enumType: TldType::class)]
|
||||||
|
private ?TldType $type = null;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->rdapServers = new ArrayCollection();
|
$this->rdapServers = new ArrayCollection();
|
||||||
@@ -181,4 +185,16 @@ class Tld
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getType(): ?TldType
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType(TldType $type): static
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\MessageHandler;
|
|||||||
|
|
||||||
use App\Message\UpdateRdapServers;
|
use App\Message\UpdateRdapServers;
|
||||||
use App\Service\RDAPService;
|
use App\Service\RDAPService;
|
||||||
|
use Symfony\Component\Intl\Countries;
|
||||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||||
@@ -33,10 +34,6 @@ final readonly class UpdateRdapServersHandler
|
|||||||
$throws = [];
|
$throws = [];
|
||||||
try {
|
try {
|
||||||
$this->RDAPService->updateTldListIANA();
|
$this->RDAPService->updateTldListIANA();
|
||||||
} catch (Throwable $throwable) {
|
|
||||||
$throws[] = $throwable;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
$this->RDAPService->updateGTldListICANN();
|
$this->RDAPService->updateGTldListICANN();
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
$throws[] = $throwable;
|
$throws[] = $throwable;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\Config\EventAction;
|
use App\Config\EventAction;
|
||||||
|
use App\Config\TldType;
|
||||||
use App\Entity\Domain;
|
use App\Entity\Domain;
|
||||||
use App\Entity\DomainEntity;
|
use App\Entity\DomainEntity;
|
||||||
use App\Entity\DomainEvent;
|
use App\Entity\DomainEvent;
|
||||||
@@ -26,6 +27,7 @@ use DateTimeImmutable;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Exception\ORMException;
|
use Doctrine\ORM\Exception\ORMException;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Symfony\Component\Intl\Countries;
|
||||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||||
@@ -36,6 +38,22 @@ use Throwable;
|
|||||||
|
|
||||||
readonly class RDAPService
|
readonly class RDAPService
|
||||||
{
|
{
|
||||||
|
const ISO_TLD_EXCEPTION = ['ac', 'eu', 'uk', 'su', 'tp'];
|
||||||
|
const INFRA_TLD = ['arpa'];
|
||||||
|
const SPONSORED_TLD = ['edu', 'gov', 'int', 'mil'];
|
||||||
|
const TEST_TLD = [
|
||||||
|
'xn--kgbechtv',
|
||||||
|
'xn--hgbk6aj7f53bba',
|
||||||
|
'xn--0zwm56d',
|
||||||
|
'xn--g6w251d',
|
||||||
|
'xn--80akhbyknj4f',
|
||||||
|
'xn--11b5bs3a9aj6g',
|
||||||
|
'xn--jxalpdlp',
|
||||||
|
'xn--9t4b11yi5a',
|
||||||
|
'xn--deba0ad',
|
||||||
|
'xn--zckzah',
|
||||||
|
'xn--hlcj6aya9esc7a'
|
||||||
|
];
|
||||||
|
|
||||||
public function __construct(private HttpClientInterface $client,
|
public function __construct(private HttpClientInterface $client,
|
||||||
private EntityRepository $entityRepository,
|
private EntityRepository $entityRepository,
|
||||||
@@ -288,7 +306,7 @@ readonly class RDAPService
|
|||||||
if ($tld === "") continue;
|
if ($tld === "") continue;
|
||||||
$tldReference = $this->em->getReference(Tld::class, $tld);
|
$tldReference = $this->em->getReference(Tld::class, $tld);
|
||||||
foreach ($service[1] as $rdapServerUrl) {
|
foreach ($service[1] as $rdapServerUrl) {
|
||||||
$server = $this->rdapServerRepository->findOneBy(["tld" => $tldReference, "url" => $rdapServerUrl]); //ICI
|
$server = $this->rdapServerRepository->findOneBy(["tld" => $tldReference, "url" => $rdapServerUrl]);
|
||||||
if ($server === null) $server = new RdapServer();
|
if ($server === null) $server = new RdapServer();
|
||||||
$server->setTld($tldReference)->setUrl($rdapServerUrl)->updateTimestamps();
|
$server->setTld($tldReference)->setUrl($rdapServerUrl)->updateTimestamps();
|
||||||
|
|
||||||
@@ -316,16 +334,31 @@ readonly class RDAPService
|
|||||||
)->getContent()
|
)->getContent()
|
||||||
));
|
));
|
||||||
array_shift($tldList);
|
array_shift($tldList);
|
||||||
$storedTldList = array_map(fn($tld) => $tld->getTld(), $this->tldRepository->findAll());
|
|
||||||
|
|
||||||
|
foreach ($tldList as $tld) {
|
||||||
foreach (array_diff($tldList, $storedTldList) as $tld) {
|
|
||||||
if ($tld === "") continue;
|
if ($tld === "") continue;
|
||||||
$this->em->persist((new Tld())->setTld($tld));
|
$tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]);
|
||||||
|
if ($tldEntity === null) $tldEntity = new Tld();
|
||||||
|
|
||||||
|
$tldEntity->setTld($tld)->setType($this->getTldType($tld));
|
||||||
|
if ($tldEntity->getRegistryOperator() === NULL) $tldEntity->setType(TldType::ccTLD);
|
||||||
|
|
||||||
|
$this->em->persist($tldEntity);
|
||||||
}
|
}
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getTldType(string $tld): ?TldType
|
||||||
|
{
|
||||||
|
|
||||||
|
if (Countries::exists(strtoupper($tld)) || in_array($tld, self::ISO_TLD_EXCEPTION)) return TldType::ccTLD;
|
||||||
|
if (in_array(strtolower($tld), self::INFRA_TLD)) return TldType::iTLD;
|
||||||
|
if (in_array(strtolower($tld), self::SPONSORED_TLD)) return TldType::sTLD;
|
||||||
|
if (in_array(strtolower($tld), self::TEST_TLD)) return TldType::tTLD;
|
||||||
|
|
||||||
|
return TldType::gTLD;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
* @throws ServerExceptionInterface
|
* @throws ServerExceptionInterface
|
||||||
@@ -333,6 +366,7 @@ readonly class RDAPService
|
|||||||
* @throws ClientExceptionInterface
|
* @throws ClientExceptionInterface
|
||||||
* @throws DecodingExceptionInterface
|
* @throws DecodingExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
* @throws ORMException
|
||||||
*/
|
*/
|
||||||
public function updateGTldListICANN(): void
|
public function updateGTldListICANN(): void
|
||||||
{
|
{
|
||||||
@@ -342,14 +376,13 @@ readonly class RDAPService
|
|||||||
|
|
||||||
foreach ($gTldList as $gTld) {
|
foreach ($gTldList as $gTld) {
|
||||||
if ($gTld['gTLD'] === "") continue;
|
if ($gTld['gTLD'] === "") continue;
|
||||||
$gtTldEntity = $this->tldRepository->findOneBy(['tld' => $gTld['gTLD']]);
|
/** @var Tld $gtTldEntity */
|
||||||
if ($gtTldEntity === null) $gtTldEntity = new Tld();
|
$gtTldEntity = $this->em->getReference(Tld::class, $gTld['gTLD']);
|
||||||
|
|
||||||
$gtTldEntity
|
$gtTldEntity->setContractTerminated($gTld['contractTerminated'])
|
||||||
->setTld($gTld['gTLD'])
|
|
||||||
->setContractTerminated($gTld['contractTerminated'])
|
|
||||||
->setRegistryOperator($gTld['registryOperator'])
|
->setRegistryOperator($gTld['registryOperator'])
|
||||||
->setSpecification13($gTld['specification13']);
|
->setSpecification13($gTld['specification13']);
|
||||||
|
|
||||||
if ($gTld['removalDate'] !== null) $gtTldEntity->setRemovalDate(new DateTimeImmutable($gTld['removalDate']));
|
if ($gTld['removalDate'] !== null) $gtTldEntity->setRemovalDate(new DateTimeImmutable($gTld['removalDate']));
|
||||||
if ($gTld['delegationDate'] !== null) $gtTldEntity->setDelegationDate(new DateTimeImmutable($gTld['delegationDate']));
|
if ($gTld['delegationDate'] !== null) $gtTldEntity->setDelegationDate(new DateTimeImmutable($gTld['delegationDate']));
|
||||||
if ($gTld['dateOfContractSignature'] !== null) $gtTldEntity->setDateOfContractSignature(new DateTimeImmutable($gTld['dateOfContractSignature']));
|
if ($gTld['dateOfContractSignature'] !== null) $gtTldEntity->setDateOfContractSignature(new DateTimeImmutable($gTld['dateOfContractSignature']));
|
||||||
|
|||||||
Reference in New Issue
Block a user