From 2b76cdc7e6f04a0d41a224072e583cc6aee93b71 Mon Sep 17 00:00:00 2001 From: mrflos Date: Fri, 31 Mar 2023 19:43:21 +0300 Subject: [PATCH] feat(installer) : check also www. for fullname domains --- composer.lock | 12 ++++++------ utils.inc.php | 24 +++++++++++++++++++++++- yeswiki-installer.php | 3 ++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index 8f0be61..21c0fc7 100644 --- a/composer.lock +++ b/composer.lock @@ -117,16 +117,16 @@ }, { "name": "league/plates", - "version": "v3.4.0", + "version": "v3.5.0", "source": { "type": "git", "url": "https://github.com/thephpleague/plates.git", - "reference": "6d3ee31199b536a4e003b34a356ca20f6f75496a" + "reference": "a6a3238e46c6e19af7318fdc36bfbe49b0620231" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/plates/zipball/6d3ee31199b536a4e003b34a356ca20f6f75496a", - "reference": "6d3ee31199b536a4e003b34a356ca20f6f75496a", + "url": "https://api.github.com/repos/thephpleague/plates/zipball/a6a3238e46c6e19af7318fdc36bfbe49b0620231", + "reference": "a6a3238e46c6e19af7318fdc36bfbe49b0620231", "shasum": "" }, "require": { @@ -175,9 +175,9 @@ ], "support": { "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", diff --git a/utils.inc.php b/utils.inc.php index f18abd2..f531c97 100644 --- a/utils.inc.php +++ b/utils.inc.php @@ -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; } diff --git a/yeswiki-installer.php b/yeswiki-installer.php index 74994a1..cae9c16 100755 --- a/yeswiki-installer.php +++ b/yeswiki-installer.php @@ -66,7 +66,8 @@ if (0 == posix_getuid()) { $confirm = $climate->arguments->get('confirm'); $herseUser = $climate->arguments->get('herseuser'); $hersePass = $climate->arguments->get('hersepass'); - checkDNS($domain); + $isFullDomain = !preg_match('/.'.$_SERVER['maindomain'].'$/isU', $domain, $matches, PREG_OFFSET_CAPTURE, 0); + checkDNS($domain, $isFullDomain); checkIfInstalled($domain); $needHerse = checkHerse($herseUser, $hersePass); $user = generateUserFromDomain($domain);