✨ feat(Cloudflare): Ajoute les méthodes pour récupérer l'ID et les enregistrements.
🐛 fix(EsyWeb): Vérifie le pointage DNS via Cloudflare si configuré.
This commit is contained in:
@@ -128,7 +128,7 @@ class EsyWebController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route(path: '/artemis/esyweb/website/{id}', name: 'artemis_esyweb_view', methods: ['GET', 'POST'])]
|
||||
public function websiteView(?Website $website, Mailer $mailer, VaultClient $vaultClient, LicenseManager $licenseManager, LoggerService $loggerService, Request $request, EntityManagerInterface $entityManager, WebsiteRepository $websiteRepository)
|
||||
public function websiteView(?Website $website,Client $cloudFlareClient, Mailer $mailer, VaultClient $vaultClient, LicenseManager $licenseManager, LoggerService $loggerService, Request $request, EntityManagerInterface $entityManager, WebsiteRepository $websiteRepository)
|
||||
{
|
||||
if (is_null($website)) {
|
||||
return $this->redirectToRoute('artemis_esyweb');
|
||||
@@ -217,8 +217,19 @@ class EsyWebController extends AbstractController
|
||||
$websiteDn->isPointingCorrectly = false;
|
||||
$websiteDn->pointingIp = "";
|
||||
if ($websiteDn->getCustomerDns() instanceof CustomerDns) {
|
||||
$websiteDn->isPointingCorrectly = true;
|
||||
$websiteDn->pointingIp = "EsyWeb";
|
||||
$customerDns = $websiteDn->getCustomerDns();
|
||||
if($customerDns->getZoneDns() == "cloudflare") {
|
||||
$zoneId = $cloudFlareClient->zoneId($customerDns->getNdd());
|
||||
if(!is_null($zoneId)) {
|
||||
$recordsWww = $cloudFlareClient->recordsWebsite($zoneId, 'www.' . $customerDns->getNdd());
|
||||
if ($recordsWww == $website->getServer()->getExternalIp()) {
|
||||
$websiteDn->isPointingCorrectly = true;
|
||||
$websiteDn->pointingIp = "EsyWeb";
|
||||
} else {
|
||||
$websiteDn->pointingIp = $recordsWww;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (str_contains($websiteDn->getDns(), ".esy-web.dev")) {
|
||||
$websiteDn->isPointingCorrectly = true;
|
||||
$websiteDn->pointingIp = "EsyWeb";
|
||||
|
||||
@@ -32,4 +32,37 @@ class Client
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function zoneId(?string $ndd)
|
||||
{
|
||||
$result = $this->httpClient->request('GET','https://api.cloudflare.com/client/v4/zones?name='.$ndd,[
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer '.$_ENV['CLOUDFLARE_TOKEN'],
|
||||
]
|
||||
]);
|
||||
$content = json_decode($result->getContent());
|
||||
if(count($content->result) >0) {
|
||||
$result = $content->result[0];
|
||||
return $result->id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function recordsWebsite(string $zoneId, string $entry)
|
||||
{
|
||||
$result = $this->httpClient->request('GET','https://api.cloudflare.com/client/v4/zones/'.$zoneId.'/dns_records?type=A&name='.$entry,[
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer '.$_ENV['CLOUDFLARE_TOKEN'],
|
||||
]
|
||||
]);
|
||||
$content = json_decode($result->getContent());
|
||||
if(count($content->result) >0) {
|
||||
$result = $content->result[0];
|
||||
return $result->content;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user