feat(installer) : check also www. for fullname domains

This commit is contained in:
mrflos 2023-03-31 19:43:21 +03:00
parent 5c135f2cbb
commit 2b76cdc7e6
3 changed files with 31 additions and 8 deletions

12
composer.lock generated
View file

@ -117,16 +117,16 @@
}, },
{ {
"name": "league/plates", "name": "league/plates",
"version": "v3.4.0", "version": "v3.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/plates.git", "url": "https://github.com/thephpleague/plates.git",
"reference": "6d3ee31199b536a4e003b34a356ca20f6f75496a" "reference": "a6a3238e46c6e19af7318fdc36bfbe49b0620231"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/plates/zipball/6d3ee31199b536a4e003b34a356ca20f6f75496a", "url": "https://api.github.com/repos/thephpleague/plates/zipball/a6a3238e46c6e19af7318fdc36bfbe49b0620231",
"reference": "6d3ee31199b536a4e003b34a356ca20f6f75496a", "reference": "a6a3238e46c6e19af7318fdc36bfbe49b0620231",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -175,9 +175,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/thephpleague/plates/issues", "issues": "https://github.com/thephpleague/plates/issues",
"source": "https://github.com/thephpleague/plates/tree/v3.4.0" "source": "https://github.com/thephpleague/plates/tree/v3.5.0"
}, },
"time": "2020-12-25T05:00:37+00:00" "time": "2023-01-16T20:25:45+00:00"
}, },
{ {
"name": "psr/log", "name": "psr/log",

View file

@ -2,7 +2,7 @@
require 'vendor/autoload.php'; 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))) { 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.'".'); throw new Exception('not valid domain : "'.$domain.'".');
@ -17,6 +17,28 @@ function checkDNS($domain)
if ($currentip[1]['ipv6'] !== $_SERVER['ip6']) { 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']); 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; return true;
} }

View file

@ -66,7 +66,8 @@ if (0 == posix_getuid()) {
$confirm = $climate->arguments->get('confirm'); $confirm = $climate->arguments->get('confirm');
$herseUser = $climate->arguments->get('herseuser'); $herseUser = $climate->arguments->get('herseuser');
$hersePass = $climate->arguments->get('hersepass'); $hersePass = $climate->arguments->get('hersepass');
checkDNS($domain); $isFullDomain = !preg_match('/.'.$_SERVER['maindomain'].'$/isU', $domain, $matches, PREG_OFFSET_CAPTURE, 0);
checkDNS($domain, $isFullDomain);
checkIfInstalled($domain); checkIfInstalled($domain);
$needHerse = checkHerse($herseUser, $hersePass); $needHerse = checkHerse($herseUser, $hersePass);
$user = generateUserFromDomain($domain); $user = generateUserFromDomain($domain);