add checkDNSValidity function

This commit is contained in:
Nicolas Roman 2019-06-06 15:41:58 +02:00
parent 4a14333d41
commit 12b907ea63
1 changed files with 28 additions and 0 deletions

View File

@ -8,6 +8,7 @@ class LetsEncrypt
{ {
const HTTP_OK = 200; const HTTP_OK = 200;
const HTTP_CHALLENGE_URL = '/.well-known/acme-challenge/'; const HTTP_CHALLENGE_URL = '/.well-known/acme-challenge/';
/** /**
* perform a cURL call on the remote resource * perform a cURL call on the remote resource
* the cURL call follows redirections and pushes the last valid URL to an array * the cURL call follows redirections and pushes the last valid URL to an array
@ -45,6 +46,10 @@ class LetsEncrypt
$returned_http_url = curl_getinfo($curl_handle, CURLINFO_EFFECTIVE_URL); $returned_http_url = curl_getinfo($curl_handle, CURLINFO_EFFECTIVE_URL);
if ($returned_http_code === self::HTTP_OK && strpos($returned_http_url, self::HTTP_CHALLENGE_URL)) { if ($returned_http_code === self::HTTP_OK && strpos($returned_http_url, self::HTTP_CHALLENGE_URL)) {
// retrieve the FQDN
$returned_http_url = str_replace(self::HTTP_CHALLENGE_URL, '.', $returned_http_url);
$returned_http_url = preg_replace('#^https?://#', '', $returned_http_url);
array_push($checked_domains, $returned_http_url); array_push($checked_domains, $returned_http_url);
} }
curl_multi_remove_handle($curl_multi, $curl_handle); curl_multi_remove_handle($curl_multi, $curl_handle);
@ -53,4 +58,27 @@ class LetsEncrypt
return $checked_domains; return $checked_domains;
} }
/**
* Query the corresponding IP for each domain
* @param Array $domains list of HTTP checked domains
* @return Array $valid_dns_domains list of valid domains
*/
public function checkDNSValidity($domains)
{
$valid_dns_domains = array();
foreach ($domains as $domain) {
$dns_record_ipv4 = dns_get_record($domain, DNS_A);
$dns_record_ipv6 = dns_get_record($domain, DNS_AAAA);
if ($dns_record_ipv4 || $dns_record_ipv6) {
// remove the last dot added for the FQDN syntax
$domain = rtrim($domain, '.');
array_push($valid_dns_domains, $domain);
}
}
return $valid_dns_domains;
}
} }