mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
ci: add php cs fixer
This commit is contained in:
@@ -9,4 +9,4 @@ interface ConnectorInterface
|
||||
public static function verifyAuthData(array $authData): array;
|
||||
|
||||
public function orderDomain(Domain $domain, bool $dryRun): void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,29 +3,29 @@
|
||||
namespace App\Config\Connector;
|
||||
|
||||
use App\Entity\Domain;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Ovh\Api;
|
||||
|
||||
readonly class OvhConnector implements ConnectorInterface
|
||||
{
|
||||
|
||||
public function __construct(private array $authData)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Order a domain name with the OVH API
|
||||
* @throws Exception
|
||||
* Order a domain name with the OVH API.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function orderDomain(Domain $domain, bool $dryRun = false
|
||||
): void
|
||||
{
|
||||
if (!$domain->getDeleted()) throw new Exception('The domain name still appears in the WHOIS database');
|
||||
): void {
|
||||
if (!$domain->getDeleted()) {
|
||||
throw new \Exception('The domain name still appears in the WHOIS database');
|
||||
}
|
||||
|
||||
$ldhName = $domain->getLdhName();
|
||||
if (!$ldhName) throw new Exception("Domain name cannot be null");
|
||||
if (!$ldhName) {
|
||||
throw new \Exception('Domain name cannot be null');
|
||||
}
|
||||
|
||||
$authData = self::verifyAuthData($this->authData);
|
||||
|
||||
@@ -41,57 +41,59 @@ readonly class OvhConnector implements ConnectorInterface
|
||||
);
|
||||
|
||||
$cart = $conn->post('/order/cart', [
|
||||
"ovhSubsidiary" => $authData['ovhSubsidiary'],
|
||||
"description" => "Domain Watchdog"
|
||||
'ovhSubsidiary' => $authData['ovhSubsidiary'],
|
||||
'description' => 'Domain Watchdog',
|
||||
]);
|
||||
$cartId = $cart['cartId'];
|
||||
|
||||
$offers = $conn->get("/order/cart/{$cartId}/domain", [
|
||||
"domain" => $ldhName
|
||||
'domain' => $ldhName,
|
||||
]);
|
||||
$offer = array_filter($offers, fn($offer) => $offer['action'] === 'create' &&
|
||||
$offer['orderable'] === true &&
|
||||
$offer['pricingMode'] === $authData['pricingMode']
|
||||
$offer = array_filter($offers, fn ($offer) => 'create' === $offer['action']
|
||||
&& true === $offer['orderable']
|
||||
&& $offer['pricingMode'] === $authData['pricingMode']
|
||||
);
|
||||
if (empty($offer)) {
|
||||
$conn->delete("/order/cart/{$cartId}");
|
||||
throw new Exception('Cannot buy this domain name');
|
||||
throw new \Exception('Cannot buy this domain name');
|
||||
}
|
||||
|
||||
$item = $conn->post("/order/cart/{$cartId}/domain", [
|
||||
"domain" => $ldhName,
|
||||
"duration" => "P1Y"
|
||||
'domain' => $ldhName,
|
||||
'duration' => 'P1Y',
|
||||
]);
|
||||
$itemId = $item['itemId'];
|
||||
|
||||
//$conn->get("/order/cart/{$cartId}/summary");
|
||||
// $conn->get("/order/cart/{$cartId}/summary");
|
||||
$conn->post("/order/cart/{$cartId}/assign");
|
||||
$conn->get("/order/cart/{$cartId}/item/{$itemId}/requiredConfiguration");
|
||||
|
||||
$configuration = [
|
||||
"ACCEPT_CONDITIONS" => $acceptConditions,
|
||||
"OWNER_LEGAL_AGE" => $ownerLegalAge
|
||||
'ACCEPT_CONDITIONS' => $acceptConditions,
|
||||
'OWNER_LEGAL_AGE' => $ownerLegalAge,
|
||||
];
|
||||
|
||||
foreach ($configuration as $label => $value) {
|
||||
$conn->post("/order/cart/{$cartId}/item/{$itemId}/configuration", [
|
||||
"cartId" => $cartId,
|
||||
"itemId" => $itemId,
|
||||
"label" => $label,
|
||||
"value" => $value
|
||||
'cartId' => $cartId,
|
||||
'itemId' => $itemId,
|
||||
'label' => $label,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
$conn->get("/order/cart/{$cartId}/checkout");
|
||||
|
||||
if ($dryRun) return;
|
||||
if ($dryRun) {
|
||||
return;
|
||||
}
|
||||
$conn->post("/order/cart/{$cartId}/checkout", [
|
||||
"autoPayWithPreferredPaymentMethod" => true,
|
||||
"waiveRetractationPeriod" => $waiveRetractationPeriod
|
||||
'autoPayWithPreferredPaymentMethod' => true,
|
||||
'waiveRetractationPeriod' => $waiveRetractationPeriod,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function verifyAuthData(array $authData): array
|
||||
{
|
||||
@@ -106,18 +108,19 @@ readonly class OvhConnector implements ConnectorInterface
|
||||
$ownerLegalAge = $authData['ownerLegalAge'];
|
||||
$waiveRetractationPeriod = $authData['waiveRetractationPeriod'];
|
||||
|
||||
if (!is_string($appKey) || empty($appKey) ||
|
||||
!is_string($appSecret) || empty($appSecret) ||
|
||||
!is_string($consumerKey) || empty($consumerKey) ||
|
||||
!is_string($apiEndpoint) || empty($apiEndpoint) ||
|
||||
!is_string($ovhSubsidiary) || empty($ovhSubsidiary) ||
|
||||
!is_string($pricingMode) || empty($pricingMode) ||
|
||||
if (!is_string($appKey) || empty($appKey)
|
||||
|| !is_string($appSecret) || empty($appSecret)
|
||||
|| !is_string($consumerKey) || empty($consumerKey)
|
||||
|| !is_string($apiEndpoint) || empty($apiEndpoint)
|
||||
|| !is_string($ovhSubsidiary) || empty($ovhSubsidiary)
|
||||
|| !is_string($pricingMode) || empty($pricingMode)
|
||||
|
||||
true !== $acceptConditions ||
|
||||
true !== $ownerLegalAge ||
|
||||
true !== $waiveRetractationPeriod
|
||||
|
||||
) throw new Exception("Bad authData schema");
|
||||
|| true !== $acceptConditions
|
||||
|| true !== $ownerLegalAge
|
||||
|| true !== $waiveRetractationPeriod
|
||||
) {
|
||||
throw new \Exception('Bad authData schema');
|
||||
}
|
||||
|
||||
$conn = new Api(
|
||||
$appKey,
|
||||
@@ -127,22 +130,25 @@ readonly class OvhConnector implements ConnectorInterface
|
||||
);
|
||||
|
||||
$res = $conn->get('/auth/currentCredential');
|
||||
if ($res['expiration'] !== null && new DateTime($res['expiration']) < new DateTime())
|
||||
throw new Exception('These credentials have expired');
|
||||
if (null !== $res['expiration'] && new \DateTime($res['expiration']) < new \DateTime()) {
|
||||
throw new \Exception('These credentials have expired');
|
||||
}
|
||||
|
||||
$status = $res['status'];
|
||||
if ($status !== 'validated') throw new Exception("The status of these credentials is not valid ($status)");
|
||||
if ('validated' !== $status) {
|
||||
throw new \Exception("The status of these credentials is not valid ($status)");
|
||||
}
|
||||
|
||||
return [
|
||||
"appKey" => $appKey,
|
||||
"appSecret" => $appSecret,
|
||||
"apiEndpoint" => $apiEndpoint,
|
||||
"consumerKey" => $consumerKey,
|
||||
"ovhSubsidiary" => $ovhSubsidiary,
|
||||
"pricingMode" => $pricingMode,
|
||||
"acceptConditions" => $acceptConditions,
|
||||
"ownerLegalAge" => $ownerLegalAge,
|
||||
"waiveRetractationPeriod" => $waiveRetractationPeriod
|
||||
'appKey' => $appKey,
|
||||
'appSecret' => $appSecret,
|
||||
'apiEndpoint' => $apiEndpoint,
|
||||
'consumerKey' => $consumerKey,
|
||||
'ovhSubsidiary' => $ovhSubsidiary,
|
||||
'pricingMode' => $pricingMode,
|
||||
'acceptConditions' => $acceptConditions,
|
||||
'ownerLegalAge' => $ownerLegalAge,
|
||||
'waiveRetractationPeriod' => $waiveRetractationPeriod,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Config;
|
||||
|
||||
|
||||
enum ConnectorProvider: string
|
||||
{
|
||||
case OVH = 'ovh';
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
|
||||
namespace App\Config;
|
||||
|
||||
|
||||
enum TldType: string
|
||||
{
|
||||
case iTLD = 'iTLD';
|
||||
case gTLD = "gTLD";
|
||||
case sTLD = "sTLD";
|
||||
case ccTLD = "ccTLD";
|
||||
case tTLD = "tTLD";
|
||||
case gTLD = 'gTLD';
|
||||
case sTLD = 'sTLD';
|
||||
case ccTLD = 'ccTLD';
|
||||
case tTLD = 'tTLD';
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Config;
|
||||
|
||||
|
||||
enum TriggerAction: string
|
||||
{
|
||||
case SendEmail = 'email';
|
||||
|
||||
@@ -8,7 +8,6 @@ use App\Entity\Connector;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -18,8 +17,7 @@ class ConnectorController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SerializerInterface $serializer, private readonly EntityManagerInterface $em
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(
|
||||
@@ -35,11 +33,12 @@ class ConnectorController extends AbstractController
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
return $user->getConnectors();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[Route(
|
||||
path: '/api/connectors',
|
||||
@@ -55,15 +54,16 @@ class ConnectorController extends AbstractController
|
||||
$connector = $this->serializer->deserialize($request->getContent(), Connector::class, 'json', ['groups' => 'connector:create']);
|
||||
$connector->setUser($this->getUser());
|
||||
|
||||
if ($connector->getProvider() === ConnectorProvider::OVH) {
|
||||
if (ConnectorProvider::OVH === $connector->getProvider()) {
|
||||
$authData = OvhConnector::verifyAuthData($connector->getAuthData());
|
||||
$connector->setAuthData($authData);
|
||||
} else throw new Exception('Unknown provider');
|
||||
} else {
|
||||
throw new \Exception('Unknown provider');
|
||||
}
|
||||
|
||||
$this->em->persist($connector);
|
||||
$this->em->flush();
|
||||
|
||||
return $connector;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ use App\Entity\WatchList;
|
||||
use App\Message\ProcessDomainTrigger;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Service\RDAPService;
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
@@ -21,11 +19,10 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
class DomainRefreshController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(private readonly DomainRepository $domainRepository,
|
||||
private readonly RDAPService $RDAPService,
|
||||
private readonly RateLimiterFactory $authenticatedApiLimiter,
|
||||
private readonly MessageBusInterface $bus)
|
||||
public function __construct(private readonly DomainRepository $domainRepository,
|
||||
private readonly RDAPService $RDAPService,
|
||||
private readonly RateLimiterFactory $authenticatedApiLimiter,
|
||||
private readonly MessageBusInterface $bus)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -34,26 +31,30 @@ class DomainRefreshController extends AbstractController
|
||||
* @throws HttpExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __invoke(string $ldhName, KernelInterface $kernel): ?Domain
|
||||
{
|
||||
/** @var Domain $domain */
|
||||
$domain = $this->domainRepository->findOneBy(["ldhName" => $ldhName]);
|
||||
$domain = $this->domainRepository->findOneBy(['ldhName' => $ldhName]);
|
||||
|
||||
// If the domain name exists in the database, recently updated and not important, we return the stored Domain
|
||||
if ($domain !== null &&
|
||||
!$domain->getDeleted() &&
|
||||
($domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days < 7) &&
|
||||
!$this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt())
|
||||
) return $domain;
|
||||
if (null !== $domain
|
||||
&& !$domain->getDeleted()
|
||||
&& ($domain->getUpdatedAt()->diff(new \DateTimeImmutable('now'))->days < 7)
|
||||
&& !$this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt())
|
||||
) {
|
||||
return $domain;
|
||||
}
|
||||
|
||||
if (false === $kernel->isDebug()) {
|
||||
$limiter = $this->authenticatedApiLimiter->create($this->getUser()->getUserIdentifier());
|
||||
if (false === $limiter->consume()->isAccepted()) throw new TooManyRequestsHttpException();
|
||||
if (false === $limiter->consume()->isAccepted()) {
|
||||
throw new TooManyRequestsHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
$updatedAt = $domain === null ? new DateTimeImmutable('now') : $domain->getUpdatedAt();
|
||||
$updatedAt = null === $domain ? new \DateTimeImmutable('now') : $domain->getUpdatedAt();
|
||||
$domain = $this->RDAPService->registerDomain($ldhName);
|
||||
|
||||
/** @var WatchList $watchList */
|
||||
@@ -63,4 +64,4 @@ class DomainRefreshController extends AbstractController
|
||||
|
||||
return $domain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,29 +12,30 @@ use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(private readonly RouterInterface $router)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route(path: "/", name: "index")]
|
||||
#[Route(path: '/', name: 'index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('base.html.twig');
|
||||
}
|
||||
|
||||
#[Route(path: "/login/oauth", name: "oauth_connect")]
|
||||
#[Route(path: '/login/oauth', name: 'oauth_connect')]
|
||||
public function connectAction(ClientRegistry $clientRegistry): Response
|
||||
{
|
||||
return $clientRegistry->getClient('oauth')->redirect();
|
||||
}
|
||||
|
||||
#[Route(path: "/logout", name: "logout")]
|
||||
#[Route(path: '/logout', name: 'logout')]
|
||||
public function logout(Security $security): ?RedirectResponse
|
||||
{
|
||||
$response = new RedirectResponse($this->router->generate('index'));
|
||||
$response->headers->clearCookie('BEARER');
|
||||
if ($security->isGranted('IS_AUTHENTICATED')) $security->logout(false);
|
||||
if ($security->isGranted('IS_AUTHENTICATED')) {
|
||||
$security->logout(false);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,8 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
class MeController extends AbstractController
|
||||
{
|
||||
|
||||
public function __invoke(): UserInterface
|
||||
{
|
||||
return $this->getUser();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ use Eluceo\iCal\Domain\ValueObject\Date;
|
||||
use Eluceo\iCal\Domain\ValueObject\EmailAddress;
|
||||
use Eluceo\iCal\Domain\ValueObject\SingleDay;
|
||||
use Eluceo\iCal\Presentation\Factory\CalendarFactory;
|
||||
use Exception;
|
||||
use Sabre\VObject\EofException;
|
||||
use Sabre\VObject\InvalidDataException;
|
||||
use Sabre\VObject\ParseException;
|
||||
@@ -30,17 +29,15 @@ use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
class WatchListController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private readonly SerializerInterface $serializer,
|
||||
private readonly SerializerInterface $serializer,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly WatchListRepository $watchListRepository
|
||||
)
|
||||
{
|
||||
private readonly WatchListRepository $watchListRepository
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[Route(
|
||||
path: '/api/watchlists',
|
||||
@@ -66,7 +63,7 @@ class WatchListController extends AbstractController
|
||||
* @throws ParseException
|
||||
* @throws EofException
|
||||
* @throws InvalidDataException
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[Route(
|
||||
path: '/api/watchlists/{token}/calendar',
|
||||
@@ -79,7 +76,7 @@ class WatchListController extends AbstractController
|
||||
public function getWatchlistCalendar(string $token): Response
|
||||
{
|
||||
/** @var WatchList $watchList */
|
||||
$watchList = $this->watchListRepository->findOneBy(["token" => $token]);
|
||||
$watchList = $this->watchListRepository->findOneBy(['token' => $token]);
|
||||
|
||||
$calendar = new Calendar();
|
||||
|
||||
@@ -89,16 +86,18 @@ class WatchListController extends AbstractController
|
||||
/** @var DomainEntity $entity */
|
||||
foreach ($domain->getDomainEntities()->toArray() as $entity) {
|
||||
$vCard = Reader::readJson($entity->getEntity()->getJCard());
|
||||
$email = (string)$vCard->EMAIL;
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) continue;
|
||||
$email = (string) $vCard->EMAIL;
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attendees[] = (new Attendee(new EmailAddress($email)))->setDisplayName((string)$vCard->FN);
|
||||
$attendees[] = (new Attendee(new EmailAddress($email)))->setDisplayName((string) $vCard->FN);
|
||||
}
|
||||
|
||||
/** @var DomainEvent $event */
|
||||
foreach ($domain->getEvents()->toArray() as $event) {
|
||||
$calendar->addEvent((new Event())
|
||||
->setSummary($domain->getLdhName() . ' (' . $event->getAction() . ')')
|
||||
->setSummary($domain->getLdhName().' ('.$event->getAction().')')
|
||||
->addCategory(new Category($event->getAction()))
|
||||
->setAttendees($attendees)
|
||||
->setOccurrence(new SingleDay(new Date($event->getDate())))
|
||||
@@ -107,7 +106,7 @@ class WatchListController extends AbstractController
|
||||
}
|
||||
|
||||
return new Response((new CalendarFactory())->createCalendar($calendar), Response::HTTP_OK, [
|
||||
"Content-Type" => 'text/calendar; charset=utf-8'
|
||||
'Content-Type' => 'text/calendar; charset=utf-8',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -124,7 +123,7 @@ class WatchListController extends AbstractController
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
return $user->getWatchLists();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ use Symfony\Component\Uid\Uuid;
|
||||
denormalizationContext: ['groups' => 'connector:create'],
|
||||
name: 'create'
|
||||
),
|
||||
new Delete()
|
||||
new Delete(),
|
||||
]
|
||||
)]
|
||||
#[ORM\Entity(repositoryClass: ConnectorRepository::class)]
|
||||
@@ -46,7 +46,6 @@ class Connector
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?User $user = null;
|
||||
|
||||
|
||||
#[Groups(['connector:list', 'connector:create', 'watchlist:list'])]
|
||||
#[ORM\Column(enumType: ConnectorProvider::class)]
|
||||
private ?ConnectorProvider $provider = null;
|
||||
@@ -61,7 +60,6 @@ class Connector
|
||||
#[ORM\OneToMany(targetEntity: WatchList::class, mappedBy: 'connector')]
|
||||
private Collection $watchLists;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->id = Uuid::v4();
|
||||
@@ -138,5 +136,4 @@ class Connector
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\Controller\DomainRefreshController;
|
||||
use App\Repository\DomainRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
@@ -27,7 +26,7 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
),
|
||||
*/
|
||||
new Get(
|
||||
uriTemplate: '/domains/{ldhName}', # Do not delete this line, otherwise Symfony interprets the TLD of the domain name as a return type
|
||||
uriTemplate: '/domains/{ldhName}', // Do not delete this line, otherwise Symfony interprets the TLD of the domain name as a return type
|
||||
controller: DomainRefreshController::class,
|
||||
normalizationContext: [
|
||||
'groups' => [
|
||||
@@ -36,11 +35,11 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
'domain-entity:entity',
|
||||
'nameserver-entity:nameserver',
|
||||
'nameserver-entity:entity',
|
||||
'tld:item'
|
||||
]
|
||||
'tld:item',
|
||||
],
|
||||
],
|
||||
read: false
|
||||
)
|
||||
),
|
||||
]
|
||||
)]
|
||||
class Domain
|
||||
@@ -91,10 +90,10 @@ class Domain
|
||||
private Collection $nameservers;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
private ?DateTimeImmutable $createdAt = null;
|
||||
private ?\DateTimeImmutable $createdAt = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
private ?DateTimeImmutable $updatedAt = null;
|
||||
private ?\DateTimeImmutable $updatedAt = null;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'tld', nullable: false)]
|
||||
@@ -111,8 +110,8 @@ class Domain
|
||||
$this->domainEntities = new ArrayCollection();
|
||||
$this->watchLists = new ArrayCollection();
|
||||
$this->nameservers = new ArrayCollection();
|
||||
$this->createdAt = new DateTimeImmutable('now');
|
||||
$this->updatedAt = new DateTimeImmutable('now');
|
||||
$this->createdAt = new \DateTimeImmutable('now');
|
||||
$this->updatedAt = new \DateTimeImmutable('now');
|
||||
|
||||
$this->deleted = false;
|
||||
}
|
||||
@@ -264,7 +263,7 @@ class Domain
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUpdatedAt(): ?DateTimeImmutable
|
||||
public function getUpdatedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
@@ -273,27 +272,25 @@ class Domain
|
||||
#[ORM\PreUpdate]
|
||||
public function updateTimestamps(): void
|
||||
{
|
||||
$this->setUpdatedAt(new DateTimeImmutable('now'));
|
||||
if ($this->getCreatedAt() === null) {
|
||||
$this->setCreatedAt(new DateTimeImmutable('now'));
|
||||
$this->setUpdatedAt(new \DateTimeImmutable('now'));
|
||||
if (null === $this->getCreatedAt()) {
|
||||
$this->setCreatedAt(new \DateTimeImmutable('now'));
|
||||
}
|
||||
}
|
||||
|
||||
private function setUpdatedAt(?DateTimeImmutable $updatedAt): void
|
||||
private function setUpdatedAt(?\DateTimeImmutable $updatedAt): void
|
||||
{
|
||||
$this->updatedAt = $updatedAt;
|
||||
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?DateTimeImmutable
|
||||
public function getCreatedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
private function setCreatedAt(?DateTimeImmutable $createdAt): void
|
||||
private function setCreatedAt(?\DateTimeImmutable $createdAt): void
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
|
||||
}
|
||||
|
||||
public function getTld(): ?Tld
|
||||
|
||||
@@ -27,7 +27,6 @@ class DomainEntity
|
||||
#[Groups(['domain-entity:entity', 'domain-entity:domain'])]
|
||||
private array $roles = [];
|
||||
|
||||
|
||||
public function getDomain(): ?Domain
|
||||
{
|
||||
return $this->domain;
|
||||
@@ -66,5 +65,4 @@ class DomainEntity
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,16 +31,14 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
'domain-entity:domain',
|
||||
'domain:list',
|
||||
'nameserver-entity:nameserver',
|
||||
'nameserver:list'
|
||||
]
|
||||
'nameserver:list',
|
||||
],
|
||||
]
|
||||
)
|
||||
),
|
||||
]
|
||||
)]
|
||||
class Entity
|
||||
{
|
||||
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['entity:list', 'entity:item', 'domain:item'])]
|
||||
@@ -193,5 +191,4 @@ class Entity
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,10 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
#[ORM\Entity(repositoryClass: EntityEventRepository::class)]
|
||||
class EntityEvent extends Event
|
||||
{
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Entity::class, inversedBy: 'events')]
|
||||
#[ORM\JoinColumn(referencedColumnName: 'handle', nullable: false)]
|
||||
private ?Entity $entity = null;
|
||||
|
||||
|
||||
public function getEntity(): ?Entity
|
||||
{
|
||||
return $this->entity;
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Config\EventAction;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
@@ -21,8 +19,7 @@ class Event
|
||||
|
||||
#[ORM\Column(type: 'datetime_immutable')]
|
||||
#[Groups(['event:list'])]
|
||||
private ?DateTimeImmutable $date = null;
|
||||
|
||||
private ?\DateTimeImmutable $date = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
@@ -41,16 +38,15 @@ class Event
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDate(): ?DateTimeImmutable
|
||||
public function getDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function setDate(DateTimeImmutable $date): static
|
||||
public function setDate(\DateTimeImmutable $date): static
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
uriTemplate: '/nameservers',
|
||||
normalizationContext: [
|
||||
'groups' => [
|
||||
'nameserver:list'
|
||||
]
|
||||
'nameserver:list',
|
||||
],
|
||||
]
|
||||
),
|
||||
new Get(
|
||||
@@ -30,15 +30,14 @@ use Symfony\Component\Serializer\Attribute\SerializedName;
|
||||
'nameserver:item',
|
||||
'nameserver-entity:entity',
|
||||
'entity:list',
|
||||
"event:list"
|
||||
]
|
||||
'event:list',
|
||||
],
|
||||
]
|
||||
)
|
||||
),
|
||||
]
|
||||
)]
|
||||
class Nameserver
|
||||
{
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
#[Groups(['nameserver:item', 'nameserver:list', 'domain:item'])]
|
||||
@@ -133,5 +132,4 @@ class Nameserver
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ class NameserverEntity
|
||||
#[Groups(['nameserver-entity:entity'])]
|
||||
private ?Entity $entity = null;
|
||||
|
||||
|
||||
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
|
||||
#[Groups(['nameserver-entity:entity', 'nameserver-entity:nameserver'])]
|
||||
private array $roles = [];
|
||||
@@ -82,5 +81,4 @@ class NameserverEntity
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,30 +3,27 @@
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\RdapServerRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: RdapServerRepository::class)]
|
||||
class RdapServer
|
||||
{
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 255)]
|
||||
private ?string $url = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
private ?DateTimeImmutable $updatedAt = null;
|
||||
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');
|
||||
$this->updatedAt = new \DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
public function getUrl(): ?string
|
||||
@@ -41,12 +38,12 @@ class RdapServer
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUpdatedAt(): ?DateTimeImmutable
|
||||
public function getUpdatedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
public function setUpdatedAt(DateTimeImmutable $updatedAt): static
|
||||
public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
|
||||
{
|
||||
$this->updatedAt = $updatedAt;
|
||||
|
||||
@@ -57,7 +54,7 @@ class RdapServer
|
||||
#[ORM\PreUpdate]
|
||||
public function updateTimestamps(): void
|
||||
{
|
||||
$this->setUpdatedAt(new DateTimeImmutable('now'));
|
||||
$this->setUpdatedAt(new \DateTimeImmutable('now'));
|
||||
}
|
||||
|
||||
public function getTld(): ?Tld
|
||||
|
||||
@@ -9,7 +9,6 @@ use ApiPlatform\Metadata\Get;
|
||||
use ApiPlatform\Metadata\GetCollection;
|
||||
use App\Config\TldType;
|
||||
use App\Repository\TldRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
@@ -26,7 +25,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
new Get(
|
||||
uriTemplate: '/tld/{tld}',
|
||||
normalizationContext: ['groups' => ['tld:item']]
|
||||
)
|
||||
),
|
||||
]
|
||||
)]
|
||||
#[ApiFilter(SearchFilter::class)]
|
||||
@@ -35,7 +34,7 @@ class Tld
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column(length: 63)]
|
||||
#[Groups(["tld:list", "tld:item"])]
|
||||
#[Groups(['tld:list', 'tld:item'])]
|
||||
private ?string $tld = null;
|
||||
/**
|
||||
* @var Collection<int, RdapServer>
|
||||
@@ -44,31 +43,31 @@ class Tld
|
||||
private Collection $rdapServers;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
#[Groups(["tld:list", "tld:item"])]
|
||||
#[Groups(['tld:list', 'tld:item'])]
|
||||
private ?bool $contractTerminated = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||
#[Groups(["tld:item"])]
|
||||
private ?DateTimeImmutable $dateOfContractSignature = null;
|
||||
#[Groups(['tld:item'])]
|
||||
private ?\DateTimeImmutable $dateOfContractSignature = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||
#[Groups(["tld:item"])]
|
||||
private ?DateTimeImmutable $delegationDate = null;
|
||||
#[Groups(['tld:item'])]
|
||||
private ?\DateTimeImmutable $delegationDate = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
#[Groups(["tld:list", "tld:item"])]
|
||||
#[Groups(['tld:list', 'tld:item'])]
|
||||
private ?string $registryOperator = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
|
||||
#[Groups(["tld:item"])]
|
||||
private ?DateTimeImmutable $removalDate = null;
|
||||
#[Groups(['tld:item'])]
|
||||
private ?\DateTimeImmutable $removalDate = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
#[Groups(["tld:list", "tld:item"])]
|
||||
#[Groups(['tld:list', 'tld:item'])]
|
||||
private ?bool $specification13 = null;
|
||||
|
||||
#[ORM\Column(length: 10, enumType: TldType::class)]
|
||||
#[Groups(["tld:item"])]
|
||||
#[Groups(['tld:item'])]
|
||||
private ?TldType $type = null;
|
||||
|
||||
public function __construct()
|
||||
@@ -130,24 +129,24 @@ class Tld
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDateOfContractSignature(): ?DateTimeImmutable
|
||||
public function getDateOfContractSignature(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->dateOfContractSignature;
|
||||
}
|
||||
|
||||
public function setDateOfContractSignature(?DateTimeImmutable $dateOfContractSignature): static
|
||||
public function setDateOfContractSignature(?\DateTimeImmutable $dateOfContractSignature): static
|
||||
{
|
||||
$this->dateOfContractSignature = $dateOfContractSignature;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDelegationDate(): ?DateTimeImmutable
|
||||
public function getDelegationDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->delegationDate;
|
||||
}
|
||||
|
||||
public function setDelegationDate(?DateTimeImmutable $delegationDate): static
|
||||
public function setDelegationDate(?\DateTimeImmutable $delegationDate): static
|
||||
{
|
||||
$this->delegationDate = $delegationDate;
|
||||
|
||||
@@ -166,12 +165,12 @@ class Tld
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRemovalDate(): ?DateTimeImmutable
|
||||
public function getRemovalDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->removalDate;
|
||||
}
|
||||
|
||||
public function setRemovalDate(?DateTimeImmutable $removalDate): static
|
||||
public function setRemovalDate(?\DateTimeImmutable $removalDate): static
|
||||
{
|
||||
$this->removalDate = $removalDate;
|
||||
|
||||
|
||||
@@ -16,16 +16,16 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
|
||||
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
||||
#[ORM\UniqueConstraint(name: 'UNIQ_IDENTIFIER_EMAIL', fields: ['email'])]
|
||||
#[ORM\Table(name: "`user`")]
|
||||
#[ORM\Table(name: '`user`')]
|
||||
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
|
||||
#[ApiResource(
|
||||
operations: [
|
||||
new Get(
|
||||
uriTemplate: '/me',
|
||||
controller: MeController::class,
|
||||
normalizationContext: ["groups" => "user:list"],
|
||||
normalizationContext: ['groups' => 'user:list'],
|
||||
read: false
|
||||
)
|
||||
),
|
||||
]
|
||||
)]
|
||||
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
@@ -94,13 +94,13 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
*/
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
return (string)$this->email;
|
||||
return (string) $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
* @see UserInterface
|
||||
*
|
||||
* @see UserInterface
|
||||
*/
|
||||
public function getRoles(): array
|
||||
{
|
||||
@@ -112,7 +112,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $roles
|
||||
* @return User
|
||||
*/
|
||||
public function setRoles(array $roles): static
|
||||
|
||||
@@ -40,12 +40,12 @@ use Symfony\Component\Uid\Uuid;
|
||||
'text/calendar' => [
|
||||
'schema' => [
|
||||
'type' => 'string',
|
||||
'format' => 'text'
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
'format' => 'text',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
read: false,
|
||||
deserialize: false,
|
||||
@@ -61,7 +61,7 @@ use Symfony\Component\Uid\Uuid;
|
||||
normalizationContext: ['groups' => 'watchlist:item'],
|
||||
denormalizationContext: ['groups' => 'watchlist:update']
|
||||
),
|
||||
new Delete()
|
||||
new Delete(),
|
||||
],
|
||||
)]
|
||||
class WatchList
|
||||
@@ -90,14 +90,13 @@ class WatchList
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: WatchListTrigger::class, mappedBy: 'watchList', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
||||
#[SerializedName("triggers")]
|
||||
#[SerializedName('triggers')]
|
||||
private Collection $watchListTriggers;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'watchLists')]
|
||||
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
|
||||
private ?Connector $connector = null;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->token = Uuid::v4();
|
||||
|
||||
@@ -2,17 +2,12 @@
|
||||
|
||||
namespace App\Message;
|
||||
|
||||
use App\Entity\Domain;
|
||||
use App\Entity\WatchList;
|
||||
use DateTimeImmutable;
|
||||
|
||||
final class ProcessDomainTrigger
|
||||
{
|
||||
public function __construct(
|
||||
public string $watchListToken,
|
||||
public string $ldhName,
|
||||
public DateTimeImmutable $updatedAt
|
||||
)
|
||||
{
|
||||
public string $watchListToken,
|
||||
public string $ldhName,
|
||||
public \DateTimeImmutable $updatedAt
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,10 @@
|
||||
|
||||
namespace App\Message;
|
||||
|
||||
use App\Entity\WatchList;
|
||||
|
||||
final readonly class ProcessWatchListTrigger
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
public string $watchListToken,
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,63 +14,61 @@ use App\Entity\WatchListTrigger;
|
||||
use App\Message\ProcessDomainTrigger;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Repository\WatchListRepository;
|
||||
use Exception;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Throwable;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final readonly class ProcessDomainTriggerHandler
|
||||
{
|
||||
public function __construct(
|
||||
private string $mailerSenderEmail,
|
||||
private MailerInterface $mailer,
|
||||
private string $mailerSenderEmail,
|
||||
private MailerInterface $mailer,
|
||||
private WatchListRepository $watchListRepository,
|
||||
private DomainRepository $domainRepository,
|
||||
private KernelInterface $kernel
|
||||
|
||||
)
|
||||
{
|
||||
private DomainRepository $domainRepository,
|
||||
private KernelInterface $kernel
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __invoke(ProcessDomainTrigger $message): void
|
||||
{
|
||||
/** @var WatchList $watchList */
|
||||
$watchList = $this->watchListRepository->findOneBy(["token" => $message->watchListToken]);
|
||||
$watchList = $this->watchListRepository->findOneBy(['token' => $message->watchListToken]);
|
||||
/** @var Domain $domain */
|
||||
$domain = $this->domainRepository->findOneBy(["ldhName" => $message->ldhName]);
|
||||
$domain = $this->domainRepository->findOneBy(['ldhName' => $message->ldhName]);
|
||||
|
||||
$connector = $watchList->getConnector();
|
||||
if (null !== $connector && $domain->getDeleted()) {
|
||||
try {
|
||||
if ($connector->getProvider() === ConnectorProvider::OVH) {
|
||||
$ovh = new OVHConnector($connector->getAuthData());
|
||||
if (ConnectorProvider::OVH === $connector->getProvider()) {
|
||||
$ovh = new OvhConnector($connector->getAuthData());
|
||||
$isDebug = $this->kernel->isDebug();
|
||||
|
||||
$ovh->orderDomain($domain, $isDebug);
|
||||
$this->sendEmailDomainOrdered($domain, $connector, $watchList->getUser());
|
||||
} else throw new Exception("Unknown provider");
|
||||
} catch (Throwable) {
|
||||
} else {
|
||||
throw new \Exception('Unknown provider');
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
$this->sendEmailDomainOrderError($domain, $watchList->getUser());
|
||||
}
|
||||
}
|
||||
|
||||
/** @var DomainEvent $event */
|
||||
foreach ($domain->getEvents()->filter(fn($event) => $message->updatedAt < $event->getDate()) as $event) {
|
||||
foreach ($domain->getEvents()->filter(fn ($event) => $message->updatedAt < $event->getDate()) as $event) {
|
||||
$watchListTriggers = $watchList->getWatchListTriggers()
|
||||
->filter(fn($trigger) => $trigger->getEvent() === $event->getAction());
|
||||
->filter(fn ($trigger) => $trigger->getEvent() === $event->getAction());
|
||||
|
||||
/** @var WatchListTrigger $watchListTrigger */
|
||||
foreach ($watchListTriggers->getIterator() as $watchListTrigger) {
|
||||
if ($watchListTrigger->getAction() == TriggerAction::SendEmail) {
|
||||
if (TriggerAction::SendEmail == $watchListTrigger->getAction()) {
|
||||
$this->sendEmailDomainUpdated($event, $watchList->getUser());
|
||||
}
|
||||
}
|
||||
@@ -90,8 +88,8 @@ final readonly class ProcessDomainTriggerHandler
|
||||
->htmlTemplate('emails/success/domain_ordered.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
"domain" => $domain,
|
||||
"provider" => $connector->getProvider()->value
|
||||
'domain' => $domain,
|
||||
'provider' => $connector->getProvider()->value,
|
||||
]);
|
||||
|
||||
$this->mailer->send($email);
|
||||
@@ -109,7 +107,7 @@ final readonly class ProcessDomainTriggerHandler
|
||||
->htmlTemplate('emails/errors/domain_order.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
"domain" => $domain
|
||||
'domain' => $domain,
|
||||
]);
|
||||
|
||||
$this->mailer->send($email);
|
||||
@@ -128,10 +126,9 @@ final readonly class ProcessDomainTriggerHandler
|
||||
->htmlTemplate('emails/success/domain_updated.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
"event" => $domainEvent
|
||||
'event' => $domainEvent,
|
||||
]);
|
||||
|
||||
$this->mailer->send($email);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ use App\Message\ProcessDomainTrigger;
|
||||
use App\Message\ProcessWatchListTrigger;
|
||||
use App\Repository\WatchListRepository;
|
||||
use App\Service\RDAPService;
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
@@ -18,36 +16,33 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final readonly class ProcessWatchListTriggerHandler
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private RDAPService $RDAPService,
|
||||
private MailerInterface $mailer,
|
||||
private string $mailerSenderEmail,
|
||||
private RDAPService $RDAPService,
|
||||
private MailerInterface $mailer,
|
||||
private string $mailerSenderEmail,
|
||||
private MessageBusInterface $bus,
|
||||
private WatchListRepository $watchListRepository
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @throws ExceptionInterface
|
||||
*/
|
||||
public function __invoke(ProcessWatchListTrigger $message): void
|
||||
{
|
||||
/** @var WatchList $watchList */
|
||||
$watchList = $this->watchListRepository->findOneBy(["token" => $message->watchListToken]);
|
||||
$watchList = $this->watchListRepository->findOneBy(['token' => $message->watchListToken]);
|
||||
/** @var Domain $domain */
|
||||
foreach ($watchList->getDomains()
|
||||
->filter(fn($domain) => $domain->getUpdatedAt()
|
||||
->filter(fn ($domain) => $domain->getUpdatedAt()
|
||||
->diff(
|
||||
new DateTimeImmutable('now'))->days >= 7
|
||||
new \DateTimeImmutable('now'))->days >= 7
|
||||
|| $this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt())
|
||||
) as $domain
|
||||
) {
|
||||
@@ -55,8 +50,10 @@ final readonly class ProcessWatchListTriggerHandler
|
||||
|
||||
try {
|
||||
$domain = $this->RDAPService->registerDomain($domain->getLdhName());
|
||||
} catch (Throwable $e) {
|
||||
if (!($e instanceof HttpExceptionInterface)) continue;
|
||||
} catch (\Throwable $e) {
|
||||
if (!($e instanceof HttpExceptionInterface)) {
|
||||
continue;
|
||||
}
|
||||
$this->sendEmailDomainUpdateError($domain, $watchList->getUser());
|
||||
}
|
||||
|
||||
@@ -77,7 +74,6 @@ final readonly class ProcessWatchListTriggerHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
@@ -90,7 +86,7 @@ final readonly class ProcessWatchListTriggerHandler
|
||||
->htmlTemplate('emails/errors/domain_update.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
"domain" => $domain
|
||||
'domain' => $domain,
|
||||
]);
|
||||
|
||||
$this->mailer->send($email);
|
||||
|
||||
@@ -11,14 +11,12 @@ use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
#[AsMessageHandler]
|
||||
readonly final class ProcessWatchListsTriggerHandler
|
||||
final readonly class ProcessWatchListsTriggerHandler
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private WatchListRepository $watchListRepository,
|
||||
private MessageBusInterface $bus
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,5 +29,4 @@ readonly final class ProcessWatchListsTriggerHandler
|
||||
$this->bus->dispatch(new ProcessWatchListTrigger($watchList->getToken()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,14 +10,12 @@ 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
|
||||
{
|
||||
public function __construct(private RDAPService $RDAPService)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,23 +23,25 @@ final readonly class UpdateRdapServersHandler
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ClientExceptionInterface|Throwable
|
||||
* @throws ClientExceptionInterface|\Throwable
|
||||
*/
|
||||
public function __invoke(UpdateRdapServers $message): void
|
||||
{
|
||||
/** @var Throwable[] $throws */
|
||||
/** @var \Throwable[] $throws */
|
||||
$throws = [];
|
||||
try {
|
||||
$this->RDAPService->updateTldListIANA();
|
||||
$this->RDAPService->updateGTldListICANN();
|
||||
} catch (Throwable $throwable) {
|
||||
} catch (\Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
try {
|
||||
$this->RDAPService->updateRDAPServers();
|
||||
} catch (Throwable $throwable) {
|
||||
} catch (\Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
if (!empty($throws)) throw $throws[0];
|
||||
if (!empty($throws)) {
|
||||
throw $throws[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,28 +16,28 @@ class DomainEntityRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, DomainEntity::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return DomainEntity[] Returns an array of DomainEntity objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('d')
|
||||
// ->andWhere('d.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('d.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
// /**
|
||||
// * @return DomainEntity[] Returns an array of DomainEntity objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('d')
|
||||
// ->andWhere('d.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('d.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?DomainEntity
|
||||
// {
|
||||
// return $this->createQueryBuilder('d')
|
||||
// ->andWhere('d.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
// public function findOneBySomeField($value): ?DomainEntity
|
||||
// {
|
||||
// return $this->createQueryBuilder('d')
|
||||
// ->andWhere('d.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -16,28 +16,28 @@ class RdapServerRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, RdapServer::class);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return RdapServer[] Returns an array of RdapServer objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('r.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
// /**
|
||||
// * @return RdapServer[] Returns an array of RdapServer objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('r.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
// public function findOneBySomeField($value): ?RdapServer
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
// public function findOneBySomeField($value): ?RdapServer
|
||||
// {
|
||||
// return $this->createQueryBuilder('r')
|
||||
// ->andWhere('r.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->getQuery()
|
||||
// ->getOneOrNullResult()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -14,8 +14,7 @@ final readonly class SendNotifWatchListTriggerSchedule implements ScheduleProvid
|
||||
{
|
||||
public function __construct(
|
||||
private CacheInterface $cache,
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
public function getSchedule(): Schedule
|
||||
|
||||
@@ -14,8 +14,7 @@ final readonly class UpdateRdapServersSchedule implements ScheduleProviderInterf
|
||||
{
|
||||
public function __construct(
|
||||
private CacheInterface $cache,
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
public function getSchedule(): Schedule
|
||||
|
||||
@@ -20,17 +20,15 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
|
||||
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
||||
|
||||
class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEntrypointInterface
|
||||
class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEntryPointInterface
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private readonly ClientRegistry $clientRegistry,
|
||||
private readonly UserRepository $userRepository,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly RouterInterface $router,
|
||||
private readonly ClientRegistry $clientRegistry,
|
||||
private readonly UserRepository $userRepository,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly RouterInterface $router,
|
||||
private readonly JWTTokenManagerInterface $JWTManager
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +38,7 @@ class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEn
|
||||
*/
|
||||
public function supports(Request $request): ?bool
|
||||
{
|
||||
return $request->attributes->get('_route') === 'oauth_connect_check';
|
||||
return 'oauth_connect_check' === $request->attributes->get('_route');
|
||||
}
|
||||
|
||||
public function authenticate(Request $request): Passport
|
||||
@@ -50,13 +48,14 @@ class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEn
|
||||
|
||||
return new SelfValidatingPassport(
|
||||
new UserBadge($accessToken->getToken(), function () use ($accessToken, $client) {
|
||||
|
||||
/** @var OAuthResourceOwner $userFromToken */
|
||||
$userFromToken = $client->fetchUserFromToken($accessToken);
|
||||
|
||||
$existingUser = $this->userRepository->findOneBy(['email' => $userFromToken->getEmail()]);
|
||||
|
||||
if ($existingUser) return $existingUser;
|
||||
if ($existingUser) {
|
||||
return $existingUser;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user->setEmail($userFromToken->getEmail());
|
||||
@@ -85,6 +84,7 @@ class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEn
|
||||
'strict'
|
||||
)
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,9 @@ class OAuthProvider extends AbstractProvider
|
||||
{
|
||||
use BearerAuthorizationTrait;
|
||||
|
||||
|
||||
public function __construct(private readonly array $options = [], array $collaborators = [])
|
||||
{
|
||||
parent::__construct($options, $collaborators);
|
||||
|
||||
}
|
||||
|
||||
public function getBaseAuthorizationUrl(): string
|
||||
@@ -43,11 +41,7 @@ class OAuthProvider extends AbstractProvider
|
||||
protected function checkResponse(ResponseInterface $response, $data): void
|
||||
{
|
||||
if ($response->getStatusCode() >= 400) {
|
||||
throw new IdentityProviderException(
|
||||
$data['error'] ?? 'Unknown error',
|
||||
$response->getStatusCode(),
|
||||
$response
|
||||
);
|
||||
throw new IdentityProviderException($data['error'] ?? 'Unknown error', $response->getStatusCode(), $response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,4 +49,4 @@ class OAuthProvider extends AbstractProvider
|
||||
{
|
||||
return new OAuthResourceOwner($response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,4 @@ class OAuthResourceOwner implements ResourceOwnerInterface
|
||||
{
|
||||
return $this->response['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Config\EventAction;
|
||||
@@ -23,10 +22,8 @@ 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;
|
||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||
@@ -40,9 +37,9 @@ readonly class RDAPService
|
||||
/**
|
||||
* @see https://www.iana.org/domains/root/db
|
||||
*/
|
||||
const ISO_TLD_EXCEPTION = ['ac', 'eu', 'uk', 'su', 'tp'];
|
||||
const INFRA_TLD = ['arpa'];
|
||||
const SPONSORED_TLD = [
|
||||
public const ISO_TLD_EXCEPTION = ['ac', 'eu', 'uk', 'su', 'tp'];
|
||||
public const INFRA_TLD = ['arpa'];
|
||||
public const SPONSORED_TLD = [
|
||||
'aero',
|
||||
'asia',
|
||||
'cat',
|
||||
@@ -58,7 +55,7 @@ readonly class RDAPService
|
||||
'travel',
|
||||
'xxx',
|
||||
];
|
||||
const TEST_TLD = [
|
||||
public const TEST_TLD = [
|
||||
'xn--kgbechtv',
|
||||
'xn--hgbk6aj7f53bba',
|
||||
'xn--0zwm56d',
|
||||
@@ -69,42 +66,43 @@ readonly class RDAPService
|
||||
'xn--9t4b11yi5a',
|
||||
'xn--deba0ad',
|
||||
'xn--zckzah',
|
||||
'xn--hlcj6aya9esc7a'
|
||||
'xn--hlcj6aya9esc7a',
|
||||
];
|
||||
|
||||
const IMPORTANT_EVENTS = [EventAction::Deletion->value, EventAction::Expiration->value];
|
||||
|
||||
public function __construct(private HttpClientInterface $client,
|
||||
private EntityRepository $entityRepository,
|
||||
private DomainRepository $domainRepository,
|
||||
private DomainEventRepository $domainEventRepository,
|
||||
private NameserverRepository $nameserverRepository,
|
||||
private NameserverEntityRepository $nameserverEntityRepository,
|
||||
private EntityEventRepository $entityEventRepository,
|
||||
private DomainEntityRepository $domainEntityRepository,
|
||||
private RdapServerRepository $rdapServerRepository,
|
||||
private TldRepository $tldRepository,
|
||||
private EntityManagerInterface $em
|
||||
)
|
||||
{
|
||||
public const IMPORTANT_EVENTS = [EventAction::Deletion->value, EventAction::Expiration->value];
|
||||
|
||||
public function __construct(private HttpClientInterface $client,
|
||||
private EntityRepository $entityRepository,
|
||||
private DomainRepository $domainRepository,
|
||||
private DomainEventRepository $domainEventRepository,
|
||||
private NameserverRepository $nameserverRepository,
|
||||
private NameserverEntityRepository $nameserverEntityRepository,
|
||||
private EntityEventRepository $entityEventRepository,
|
||||
private DomainEntityRepository $domainEntityRepository,
|
||||
private RdapServerRepository $rdapServerRepository,
|
||||
private TldRepository $tldRepository,
|
||||
private EntityManagerInterface $em
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a domain name needs special attention.
|
||||
* These domain names are those whose last event was expiration or deletion.
|
||||
* @throws Exception
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function isToBeWatchClosely(Domain $domain, DateTimeImmutable $updatedAt): bool
|
||||
public static function isToBeWatchClosely(Domain $domain, \DateTimeImmutable $updatedAt): bool
|
||||
{
|
||||
if ($updatedAt->diff(new DateTimeImmutable('now'))->days < 1) return false;
|
||||
if ($updatedAt->diff(new \DateTimeImmutable('now'))->days < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var DomainEvent[] $events */
|
||||
$events = $domain->getEvents()
|
||||
->filter(fn(DomainEvent $e) => $e->getDate() <= new DateTimeImmutable('now'))
|
||||
->filter(fn (DomainEvent $e) => $e->getDate() <= new \DateTimeImmutable('now'))
|
||||
->toArray();
|
||||
|
||||
usort($events, fn(DomainEvent $e1, DomainEvent $e2) => $e2->getDate() > $e1->getDate());
|
||||
usort($events, fn (DomainEvent $e1, DomainEvent $e2) => $e2->getDate() > $e1->getDate());
|
||||
|
||||
return !empty($events) && in_array($events[0]->getAction(), self::IMPORTANT_EVENTS);
|
||||
}
|
||||
@@ -122,7 +120,7 @@ readonly class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws HttpExceptionInterface
|
||||
@@ -133,20 +131,21 @@ readonly class RDAPService
|
||||
$tld = $this->getTld($idnDomain);
|
||||
|
||||
/** @var RdapServer|null $rdapServer */
|
||||
$rdapServer = $this->rdapServerRepository->findOneBy(["tld" => $tld], ["updatedAt" => "DESC"]);
|
||||
$rdapServer = $this->rdapServerRepository->findOneBy(['tld' => $tld], ['updatedAt' => 'DESC']);
|
||||
|
||||
if ($rdapServer === null) throw new Exception("Unable to determine which RDAP server to contact");
|
||||
if (null === $rdapServer) {
|
||||
throw new \Exception('Unable to determine which RDAP server to contact');
|
||||
}
|
||||
|
||||
/** @var ?Domain $domain */
|
||||
$domain = $this->domainRepository->findOneBy(["ldhName" => $idnDomain]);
|
||||
|
||||
$domain = $this->domainRepository->findOneBy(['ldhName' => $idnDomain]);
|
||||
|
||||
try {
|
||||
$res = $this->client->request(
|
||||
'GET', $rdapServer->getUrl() . 'domain/' . $idnDomain
|
||||
'GET', $rdapServer->getUrl().'domain/'.$idnDomain
|
||||
)->toArray();
|
||||
} catch (HttpExceptionInterface $e) {
|
||||
if ($domain !== null) {
|
||||
if (null !== $domain) {
|
||||
$domain->setDeleted(true)
|
||||
->updateTimestamps();
|
||||
$this->em->persist($domain);
|
||||
@@ -155,36 +154,45 @@ readonly class RDAPService
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
if ($domain === null) $domain = new Domain();
|
||||
if (null === $domain) {
|
||||
$domain = new Domain();
|
||||
}
|
||||
$domain->setTld($tld)->setLdhName($idnDomain)->setDeleted(false);
|
||||
|
||||
if (array_key_exists('status', $res)) $domain->setStatus($res['status']);
|
||||
if (array_key_exists('handle', $res)) $domain->setHandle($res['handle']);
|
||||
if (array_key_exists('status', $res)) {
|
||||
$domain->setStatus($res['status']);
|
||||
}
|
||||
if (array_key_exists('handle', $res)) {
|
||||
$domain->setHandle($res['handle']);
|
||||
}
|
||||
|
||||
$this->em->persist($domain);
|
||||
$this->em->flush();
|
||||
|
||||
foreach ($res['events'] as $rdapEvent) {
|
||||
if ($rdapEvent['eventAction'] === EventAction::LastUpdateOfRDAPDatabase->value) continue;
|
||||
if ($rdapEvent['eventAction'] === EventAction::LastUpdateOfRDAPDatabase->value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$event = $this->domainEventRepository->findOneBy([
|
||||
"action" => $rdapEvent['eventAction'],
|
||||
"date" => new DateTimeImmutable($rdapEvent["eventDate"]),
|
||||
"domain" => $domain
|
||||
'action' => $rdapEvent['eventAction'],
|
||||
'date' => new \DateTimeImmutable($rdapEvent['eventDate']),
|
||||
'domain' => $domain,
|
||||
]);
|
||||
|
||||
if ($event === null) $event = new DomainEvent();
|
||||
if (null === $event) {
|
||||
$event = new DomainEvent();
|
||||
}
|
||||
$domain->addEvent($event
|
||||
->setAction($rdapEvent['eventAction'])
|
||||
->setDate(new DateTimeImmutable($rdapEvent['eventDate'])));
|
||||
|
||||
->setDate(new \DateTimeImmutable($rdapEvent['eventDate'])));
|
||||
}
|
||||
|
||||
if (array_key_exists('entities', $res) && is_array($res['entities'])) {
|
||||
|
||||
foreach ($res['entities'] as $rdapEntity) {
|
||||
if (!array_key_exists('handle', $rdapEntity) || $rdapEntity['handle'] === '') continue;
|
||||
if (!array_key_exists('handle', $rdapEntity) || '' === $rdapEntity['handle']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entity = $this->registerEntity($rdapEntity);
|
||||
|
||||
@@ -192,21 +200,25 @@ readonly class RDAPService
|
||||
$this->em->flush();
|
||||
|
||||
$domainEntity = $this->domainEntityRepository->findOneBy([
|
||||
"domain" => $domain,
|
||||
"entity" => $entity
|
||||
'domain' => $domain,
|
||||
'entity' => $entity,
|
||||
]);
|
||||
|
||||
if ($domainEntity === null) $domainEntity = new DomainEntity();
|
||||
if (null === $domainEntity) {
|
||||
$domainEntity = new DomainEntity();
|
||||
}
|
||||
|
||||
$roles = array_map(
|
||||
fn($e) => $e['roles'],
|
||||
fn ($e) => $e['roles'],
|
||||
array_filter(
|
||||
$res['entities'],
|
||||
fn($e) => array_key_exists('handle', $e) && $e['handle'] === $rdapEntity['handle']
|
||||
fn ($e) => array_key_exists('handle', $e) && $e['handle'] === $rdapEntity['handle']
|
||||
)
|
||||
);
|
||||
|
||||
if (count($roles) !== count($roles, COUNT_RECURSIVE)) $roles = array_merge(...$roles);
|
||||
if (count($roles) !== count($roles, COUNT_RECURSIVE)) {
|
||||
$roles = array_merge(...$roles);
|
||||
}
|
||||
|
||||
$domain->addDomainEntity($domainEntity
|
||||
->setDomain($domain)
|
||||
@@ -221,9 +233,11 @@ readonly class RDAPService
|
||||
if (array_key_exists('nameservers', $res) && is_array($res['nameservers'])) {
|
||||
foreach ($res['nameservers'] as $rdapNameserver) {
|
||||
$nameserver = $this->nameserverRepository->findOneBy([
|
||||
"ldhName" => strtolower($rdapNameserver['ldhName'])
|
||||
'ldhName' => strtolower($rdapNameserver['ldhName']),
|
||||
]);
|
||||
if ($nameserver === null) $nameserver = new Nameserver();
|
||||
if (null === $nameserver) {
|
||||
$nameserver = new Nameserver();
|
||||
}
|
||||
|
||||
$nameserver->setLdhName($rdapNameserver['ldhName']);
|
||||
|
||||
@@ -233,29 +247,32 @@ readonly class RDAPService
|
||||
}
|
||||
|
||||
foreach ($rdapNameserver['entities'] as $rdapEntity) {
|
||||
if (!array_key_exists('handle', $rdapEntity) || $rdapEntity['handle'] === '') continue;
|
||||
if (!array_key_exists('handle', $rdapEntity) || '' === $rdapEntity['handle']) {
|
||||
continue;
|
||||
}
|
||||
$entity = $this->registerEntity($rdapEntity);
|
||||
|
||||
$this->em->persist($entity);
|
||||
$this->em->flush();
|
||||
|
||||
$nameserverEntity = $this->nameserverEntityRepository->findOneBy([
|
||||
"nameserver" => $nameserver,
|
||||
"entity" => $entity
|
||||
'nameserver' => $nameserver,
|
||||
'entity' => $entity,
|
||||
]);
|
||||
if ($nameserverEntity === null) $nameserverEntity = new NameserverEntity();
|
||||
if (null === $nameserverEntity) {
|
||||
$nameserverEntity = new NameserverEntity();
|
||||
}
|
||||
|
||||
$roles = array_merge(
|
||||
...array_map(
|
||||
fn(array $e): array => $e['roles'],
|
||||
fn (array $e): array => $e['roles'],
|
||||
array_filter(
|
||||
$rdapNameserver['entities'],
|
||||
fn($e) => array_key_exists('handle', $e) && $e['handle'] === $rdapEntity['handle']
|
||||
fn ($e) => array_key_exists('handle', $e) && $e['handle'] === $rdapEntity['handle']
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$nameserver->addNameserverEntity($nameserverEntity
|
||||
->setNameserver($nameserver)
|
||||
->setEntity($entity)
|
||||
@@ -275,29 +292,31 @@ readonly class RDAPService
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getTld($domain): ?object
|
||||
{
|
||||
$lastDotPosition = strrpos($domain, '.');
|
||||
if ($lastDotPosition === false) {
|
||||
throw new Exception("Domain must contain at least one dot");
|
||||
if (false === $lastDotPosition) {
|
||||
throw new \Exception('Domain must contain at least one dot');
|
||||
}
|
||||
$tld = strtolower(substr($domain, $lastDotPosition + 1));
|
||||
|
||||
return $this->tldRepository->findOneBy(["tld" => $tld]);
|
||||
return $this->tldRepository->findOneBy(['tld' => $tld]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function registerEntity(array $rdapEntity): Entity
|
||||
{
|
||||
$entity = $this->entityRepository->findOneBy([
|
||||
"handle" => $rdapEntity['handle']
|
||||
'handle' => $rdapEntity['handle'],
|
||||
]);
|
||||
|
||||
if ($entity === null) $entity = new Entity();
|
||||
if (null === $entity) {
|
||||
$entity = new Entity();
|
||||
}
|
||||
|
||||
$entity->setHandle($rdapEntity['handle']);
|
||||
|
||||
@@ -312,28 +331,34 @@ readonly class RDAPService
|
||||
foreach ($entity->getJCard()[1] as $prop) {
|
||||
$properties[$prop[0]] = $prop;
|
||||
}
|
||||
$entity->setJCard(["vcard", array_values($properties)]);
|
||||
$entity->setJCard(['vcard', array_values($properties)]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!array_key_exists('events', $rdapEntity)) return $entity;
|
||||
if (!array_key_exists('events', $rdapEntity)) {
|
||||
return $entity;
|
||||
}
|
||||
|
||||
foreach ($rdapEntity['events'] as $rdapEntityEvent) {
|
||||
$eventAction = $rdapEntityEvent["eventAction"];
|
||||
if ($eventAction === EventAction::LastChanged->value || $eventAction === EventAction::LastUpdateOfRDAPDatabase->value) continue;
|
||||
$eventAction = $rdapEntityEvent['eventAction'];
|
||||
if ($eventAction === EventAction::LastChanged->value || $eventAction === EventAction::LastUpdateOfRDAPDatabase->value) {
|
||||
continue;
|
||||
}
|
||||
$event = $this->entityEventRepository->findOneBy([
|
||||
"action" => $rdapEntityEvent["eventAction"],
|
||||
"date" => new DateTimeImmutable($rdapEntityEvent["eventDate"])
|
||||
'action' => $rdapEntityEvent['eventAction'],
|
||||
'date' => new \DateTimeImmutable($rdapEntityEvent['eventDate']),
|
||||
]);
|
||||
|
||||
if ($event !== null) continue;
|
||||
if (null !== $event) {
|
||||
continue;
|
||||
}
|
||||
$entity->addEvent(
|
||||
(new EntityEvent())
|
||||
->setEntity($entity)
|
||||
->setAction($rdapEntityEvent["eventAction"])
|
||||
->setDate(new DateTimeImmutable($rdapEntityEvent['eventDate'])));
|
||||
|
||||
->setAction($rdapEntityEvent['eventAction'])
|
||||
->setDate(new \DateTimeImmutable($rdapEntityEvent['eventDate'])));
|
||||
}
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
@@ -352,19 +377,21 @@ readonly class RDAPService
|
||||
)->toArray();
|
||||
|
||||
foreach ($dnsRoot['services'] as $service) {
|
||||
|
||||
foreach ($service[0] as $tld) {
|
||||
if ($tld === "") continue;
|
||||
if ('' === $tld) {
|
||||
continue;
|
||||
}
|
||||
$tldReference = $this->em->getReference(Tld::class, $tld);
|
||||
foreach ($service[1] as $rdapServerUrl) {
|
||||
$server = $this->rdapServerRepository->findOneBy(["tld" => $tldReference, "url" => $rdapServerUrl]);
|
||||
if ($server === null) $server = new RdapServer();
|
||||
$server = $this->rdapServerRepository->findOneBy(['tld' => $tldReference, 'url' => $rdapServerUrl]);
|
||||
if (null === $server) {
|
||||
$server = new RdapServer();
|
||||
}
|
||||
$server->setTld($tldReference)->setUrl($rdapServerUrl)->updateTimestamps();
|
||||
|
||||
$this->em->persist($server);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$this->em->flush();
|
||||
}
|
||||
@@ -378,7 +405,7 @@ readonly class RDAPService
|
||||
public function updateTldListIANA(): void
|
||||
{
|
||||
$tldList = array_map(
|
||||
fn($tld) => strtolower($tld),
|
||||
fn ($tld) => strtolower($tld),
|
||||
explode(PHP_EOL,
|
||||
$this->client->request(
|
||||
'GET', 'https://data.iana.org/TLD/tlds-alpha-by-domain.txt'
|
||||
@@ -387,20 +414,22 @@ readonly class RDAPService
|
||||
array_shift($tldList);
|
||||
|
||||
foreach ($tldList as $tld) {
|
||||
if ($tld === "") continue;
|
||||
if ('' === $tld) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tldEntity = $this->tldRepository->findOneBy(['tld' => $tld]);
|
||||
|
||||
if ($tldEntity === null) {
|
||||
if (null === $tldEntity) {
|
||||
$tldEntity = new Tld();
|
||||
$tldEntity->setTld($tld);
|
||||
}
|
||||
|
||||
$type = $this->getTldType($tld);
|
||||
|
||||
if ($type !== null) {
|
||||
if (null !== $type) {
|
||||
$tldEntity->setType($type);
|
||||
} elseif ($tldEntity->isContractTerminated() === null) { // ICANN managed, must be a ccTLD
|
||||
} elseif (null === $tldEntity->isContractTerminated()) { // ICANN managed, must be a ccTLD
|
||||
$tldEntity->setType(TldType::ccTLD);
|
||||
} else {
|
||||
$tldEntity->setType(TldType::gTLD);
|
||||
@@ -413,11 +442,18 @@ readonly class RDAPService
|
||||
|
||||
private function getTldType(string $tld): ?TldType
|
||||
{
|
||||
|
||||
if (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;
|
||||
if (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 null;
|
||||
}
|
||||
@@ -428,7 +464,7 @@ readonly class RDAPService
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateGTldListICANN(): void
|
||||
{
|
||||
@@ -437,7 +473,9 @@ readonly class RDAPService
|
||||
)->toArray()['gTLDs'];
|
||||
|
||||
foreach ($gTldList as $gTld) {
|
||||
if ($gTld['gTLD'] === "") continue;
|
||||
if ('' === $gTld['gTLD']) {
|
||||
continue;
|
||||
}
|
||||
/** @var Tld $gtTldEntity */
|
||||
$gtTldEntity = $this->tldRepository->findOneBy(['tld' => $gTld['gTLD']]);
|
||||
|
||||
@@ -452,12 +490,18 @@ readonly class RDAPService
|
||||
->setSpecification13($gTld['specification13'])
|
||||
->setType(TldType::gTLD);
|
||||
|
||||
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']));
|
||||
if (null !== $gTld['removalDate']) {
|
||||
$gtTldEntity->setRemovalDate(new \DateTimeImmutable($gTld['removalDate']));
|
||||
}
|
||||
if (null !== $gTld['delegationDate']) {
|
||||
$gtTldEntity->setDelegationDate(new \DateTimeImmutable($gTld['delegationDate']));
|
||||
}
|
||||
if (null !== $gTld['dateOfContractSignature']) {
|
||||
$gtTldEntity->setDateOfContractSignature(new \DateTimeImmutable($gTld['dateOfContractSignature']));
|
||||
}
|
||||
$this->em->persist($gtTldEntity);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user