From cb3143e76df5167de92746e2959efddf0aa3e260 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 11 May 2022 16:51:27 +0200 Subject: [PATCH] possibility to specify both ipv4 and ipv6 Signed-off-by: Michael Kaufmann --- lib/Froxlor/Install/Install.php | 12 ++++-- lib/Froxlor/Install/Install/Core.php | 58 +++++++++++++++++++++------- lng/en.lng.php | 3 +- 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/lib/Froxlor/Install/Install.php b/lib/Froxlor/Install/Install.php index d9c4fc52..eaf33c48 100644 --- a/lib/Froxlor/Install/Install.php +++ b/lib/Froxlor/Install/Install.php @@ -31,6 +31,7 @@ use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; use Froxlor\Config\ConfigParser; use Froxlor\Validate\Validate; +use Froxlor\System\IPTools; class Install { @@ -256,13 +257,18 @@ class Install */ private function checkSystem(array $validatedData): void { - $serverip = $validatedData['serverip'] ?? ''; + $serveripv4 = $validatedData['serveripv4'] ?? ''; + $serveripv6 = $validatedData['serveripv6'] ?? ''; $servername = $validatedData['servername'] ?? ''; $httpuser = $validatedData['httpuser'] ?? 'www-data'; $httpgroup = $validatedData['httpgroup'] ?? 'www-data'; - if (!Validate::validate_ip2($serverip, true, '', false, true)) { - throw new Exception(lng('error.invalidip', [$serverip])); + if (empty($serveripv4) && empty($serveripv6)) { + throw new Exception(lng('install.errors.nov4andnov6ip')); + } elseif (!Validate::validate_ip2($serveripv4, true, '', false, true) || IPTools::is_ipv6($serveripv4)) { + throw new Exception(lng('error.invalidip', [$serveripv4])); + } elseif (!Validate::validate_ip2($serveripv6, true, '', false, true) || IPTools::is_ipv6($serveripv6) == false) { + throw new Exception(lng('error.invalidip', [$serveripv6])); } elseif (!Validate::validateDomain($servername) && !Validate::validateLocalHostname($servername)) { throw new Exception(lng('install.errors.servernameneedstobevalid')); } elseif (posix_getpwnam($httpuser) === false) { diff --git a/lib/Froxlor/Install/Install/Core.php b/lib/Froxlor/Install/Install/Core.php index 3f4d89e1..222b3718 100644 --- a/lib/Froxlor/Install/Install/Core.php +++ b/lib/Froxlor/Install/Install/Core.php @@ -231,6 +231,7 @@ class Core $mysql_access_host_array = array_map('trim', explode(',', $this->validatedData['mysql_access_host'])); // @todo localhost/127.0.0.1/serverip checks and addition is only required if mysql_access_host is not a separate machine + /* if (in_array('127.0.0.1', $mysql_access_host_array) && !in_array('localhost', $mysql_access_host_array)) { $mysql_access_host_array[] = 'localhost'; } @@ -240,6 +241,7 @@ class Core if (!in_array($this->validatedData['serverip'], $mysql_access_host_array)) { $mysql_access_host_array[] = $this->validatedData['serverip']; } + */ $mysql_access_host_array = array_unique($mysql_access_host_array); @@ -370,8 +372,10 @@ class Core WHERE `settinggroup` = :group AND `varname` = :varname "); + $mainip = !empty($this->validatedData['serveripv6']) ? $this->validatedData['serveripv6'] : $this->validatedData['serveripv4']; + $this->updateSetting($upd_stmt, 'admin@' . $this->validatedData['servername'], 'panel', 'adminmail'); - $this->updateSetting($upd_stmt, $this->validatedData['serverip'], 'system', 'ipaddress'); + $this->updateSetting($upd_stmt, $mainip, 'system', 'ipaddress'); if ($this->validatedData['use_ssl']) { $this->updateSetting($upd_stmt, 1, 'system', 'use_ssl'); $this->updateSetting($upd_stmt, 1, 'system', 'leenabled'); @@ -496,23 +500,47 @@ class Core `ssl` = :ssl "); $nvh = $this->validatedData['webserver'] == 'apache2' ? '1' : '0'; - $stmt->execute([ - 'nvh' => $nvh, - 'serverip' => $this->validatedData['serverip'], - 'serverport' => 80, - 'ssl' => 0 - ]); - $defaultip = $db_user->lastInsertId(); + if (!empty($this->validatedData['serveripv6'])) { + $stmt->execute([ + 'nvh' => $nvh, + 'serverip' => $this->validatedData['serveripv6'], + 'serverport' => 80, + 'ssl' => 0 + ]); + $defaultip = $db_user->lastInsertId(); + } + if (!empty($this->validatedData['serveripv4'])) { + $stmt->execute([ + 'nvh' => $nvh, + 'serverip' => $this->validatedData['serveripv4'], + 'serverport' => 80, + 'ssl' => 0 + ]); + $lastinsert = $db_user->lastInsertId(); + $defaultip = $defaultip != false ? $defaultip . ',' . $lastinsert : $lastinsert; + } $defaultsslip = false; if ($this->validatedData['use_ssl']) { - $stmt->execute([ - 'nvh' => $this->validatedData['webserver'] == 'apache2' ? '1' : '0', - 'serverip' => $this->validatedData['serverip'], - 'serverport' => 443, - 'ssl' => 1 - ]); - $defaultsslip = $db_user->lastInsertId(); + if (!empty($this->validatedData['serveripv6'])) { + $stmt->execute([ + 'nvh' => $this->validatedData['webserver'] == 'apache2' ? '1' : '0', + 'serverip' => $this->validatedData['serveripv6'], + 'serverport' => 443, + 'ssl' => 1 + ]); + $defaultsslip = $db_user->lastInsertId(); + } + if (!empty($this->validatedData['serveripv4'])) { + $stmt->execute([ + 'nvh' => $this->validatedData['webserver'] == 'apache2' ? '1' : '0', + 'serverip' => $this->validatedData['serveripv4'], + 'serverport' => 443, + 'ssl' => 1 + ]); + $lastinsert = $db_user->lastInsertId(); + $defaultsslip = $defaultsslip != false ? $defaultsslip . ',' . $lastinsert : $lastinsert; + } } // insert the defaultip diff --git a/lng/en.lng.php b/lng/en.lng.php index 24443e84..5e66e913 100644 --- a/lng/en.lng.php +++ b/lng/en.lng.php @@ -2493,7 +2493,7 @@ Yours sincerely, your administrator', 'ipv6' => 'Primary IPv6 address (if applicable)', 'servername' => 'Server name (FQDN, no ip-address)', 'phpbackend' => 'PHP backend', - 'activate_newsfeed' => 'Enable the official newsfeed
(https://inside.froxlor.org/news/)', + 'activate_newsfeed' => 'Enable the official newsfeed
(external source: https://inside.froxlor.org/news/)', ], 'install' => [ 'top' => 'Finish setup', @@ -2509,6 +2509,7 @@ Yours sincerely, your administrator', 'unabletocreateuser' => 'Test user could not be created', 'unabletodropuser' => 'Test user could not be dropped', 'unabletoflushprivs' => 'Given privileged user is unable to flush privileges', + 'nov4andnov6ip' => 'Either IPv4- or IPv6-address must be given', 'servernameneedstobevalid' => 'Given servername does not seem to be a FQDN or hostname', 'websrvuserdoesnotexist' => 'Given webserver-user does not seem to exist on the system', 'websrvgrpdoesnotexist' => 'Given webserver-group does not seem to exist on the system',