feat(installer) : check also www. for fullname domains
This commit is contained in:
parent
5c135f2cbb
commit
2b76cdc7e6
3 changed files with 31 additions and 8 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
function checkDNS($domain)
|
||||
function checkDNS($domain, $withWww = false)
|
||||
{
|
||||
if (!preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', strtolower($domain))) {
|
||||
throw new Exception('not valid domain : "'.$domain.'".');
|
||||
|
@ -17,6 +17,28 @@ function checkDNS($domain)
|
|||
if ($currentip[1]['ipv6'] !== $_SERVER['ip6']) {
|
||||
throw new Exception('the current ip v6 address of '.$domain.' is '.$currentip[1]['ipv6'].'. it should be '.$_SERVER['ip6']);
|
||||
}
|
||||
if ($withWww) {
|
||||
$dnsentries = dns_get_record('www.'.$domain, DNS_A + DNS_AAAA + DNS_CNAME);
|
||||
$foundCnameEntry = false;
|
||||
$foundIp4 = false;
|
||||
$foundIp6 = false;
|
||||
foreach($dnsentries as $key => $row) {
|
||||
if ($row['host'] == 'www.'.$domain && $row['type']=='CNAME' && $row['target'] == $domain) {
|
||||
$foundCnameEntry = true;
|
||||
}
|
||||
if ($row['host'] == 'www.'.$domain && $row['type']=='A' && $row['ip'] == $_SERVER['ip4']) {
|
||||
$foundIp4 = true;
|
||||
}
|
||||
if ($row['host'] == 'www.'.$domain && $row['type']=='AAAA' && $row['ipv6'] == $_SERVER['ip6']) {
|
||||
$foundIp6 = true;
|
||||
}
|
||||
}
|
||||
if (!$foundCnameEntry) {
|
||||
if (!$foundIp4 && !$foundIp6) {
|
||||
throw new Exception('the domain www.'.$domain.' was not found in DNS record as a CNAME targeting '.$domain."\n".' or A entry to '.$_SERVER['ip4'].' and a AAAA entry to '.$_SERVER['ip6'].'.');
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue