mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: custom RDAP servers
This commit is contained in:
1
config/app/.gitignore
vendored
Normal file
1
config/app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/custom_rdap_servers.yaml
|
||||
@@ -4,6 +4,8 @@
|
||||
# Put parameters here that don't need to change on each machine where the app is deployed
|
||||
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
||||
parameters:
|
||||
custom_rdap_servers_file: '%kernel.project_dir%/config/app/custom_rdap_servers.yaml'
|
||||
|
||||
mailer_sender_email: '%env(string:MAILER_SENDER_EMAIL)%'
|
||||
mailer_sender_name: '%env(string:MAILER_SENDER_NAME)%'
|
||||
oauth_enabled: '%env(OAUTH_CLIENT_ID)%'
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\MessageHandler;
|
||||
|
||||
use App\Message\UpdateRdapServers;
|
||||
use App\Service\RDAPService;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
@@ -14,8 +15,10 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
#[AsMessageHandler]
|
||||
final readonly class UpdateRdapServersHandler
|
||||
{
|
||||
public function __construct(private RDAPService $RDAPService)
|
||||
{
|
||||
public function __construct(
|
||||
private RDAPService $RDAPService,
|
||||
private ParameterBagInterface $bag
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,17 +32,32 @@ final readonly class UpdateRdapServersHandler
|
||||
{
|
||||
/** @var \Throwable[] $throws */
|
||||
$throws = [];
|
||||
|
||||
try {
|
||||
$this->RDAPService->updateTldListIANA();
|
||||
$this->RDAPService->updateGTldListICANN();
|
||||
} catch (\Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->RDAPService->updateRDAPServers();
|
||||
$this->RDAPService->updateRDAPServersFromIANA();
|
||||
} catch (\Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->RDAPService->updateRDAPServersFromIANA();
|
||||
} catch (\Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->RDAPService->updateRDAPServersFromFile($this->bag->get('custom_rdap_servers_file'));
|
||||
} catch (\Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
|
||||
if (!empty($throws)) {
|
||||
throw $throws[0];
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpClient\Exception\ClientException;
|
||||
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||
@@ -424,14 +425,35 @@ readonly class RDAPService
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws ORMException
|
||||
*/
|
||||
public function updateRDAPServers(): void
|
||||
public function updateRDAPServersFromIANA(): void
|
||||
{
|
||||
$this->logger->info('Started updating the RDAP server list.');
|
||||
$this->logger->info('Start of update the RDAP server list from IANA.');
|
||||
|
||||
$dnsRoot = $this->client->request(
|
||||
'GET', 'https://data.iana.org/rdap/dns.json'
|
||||
)->toArray();
|
||||
|
||||
$this->updateRDAPServers($dnsRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ORMException
|
||||
*/
|
||||
public function updateRDAPServersFromFile(string $fileName): void
|
||||
{
|
||||
if (!file_exists($fileName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->logger->info('Start of update the RDAP server list from custom config file.');
|
||||
$this->updateRDAPServers(Yaml::parseFile($fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ORMException
|
||||
*/
|
||||
private function updateRDAPServers(array $dnsRoot): void
|
||||
{
|
||||
foreach ($dnsRoot['services'] as $service) {
|
||||
foreach ($service[0] as $tld) {
|
||||
if ('' === $tld) {
|
||||
|
||||
Reference in New Issue
Block a user