feat(yeswiki-installer) : allow no ip v6

This commit is contained in:
mrflos 2023-04-21 08:22:10 +03:00
parent 30c9718ad4
commit 6ecb34cee5
2 changed files with 25 additions and 11 deletions

View file

@ -2,7 +2,7 @@
require 'vendor/autoload.php';
function checkDNS($domain, $withWww = false)
function checkDNS($domain, $withWww = false, $noip6 = 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,11 +17,13 @@ function checkDNS($domain, $withWww = false)
if ($currentip[0]['ip'] !== $_SERVER['ip4']) {
throw new Exception('the current ip v4 address of '.$domain.' is '.$currentip[0]['ip'].'. it should be '.$_SERVER['ip4']);
}
if (empty($currentip[0]['ipv6'])) {
throw new Exception('the domain '.$domain.' has no ip v6 in DNS record.');
}
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 (!$noip6) {
if (empty($currentip[0]['ipv6'])) {
throw new Exception('the domain '.$domain.' has no ip v6 in DNS record.');
}
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);
@ -35,13 +37,18 @@ function checkDNS($domain, $withWww = false)
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 (!$noip6) {
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'].'.');
if (!$foundIp4) {
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']);
}
if (!$noip6 && !$foundIp6) {
throw new Exception('the domain www.'.$domain.' was not found in DNS record as a CNAME targeting '.$domain."\n".' or AAAA entry to '.$_SERVER['ip6'].'.');
}
}
}