possibility to specify both ipv4 and ipv6

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-05-11 16:51:27 +02:00
parent 4c9b6adb1f
commit cb3143e76d
3 changed files with 54 additions and 19 deletions

View File

@@ -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) {

View File

@@ -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,24 +500,48 @@ class Core
`ssl` = :ssl
");
$nvh = $this->validatedData['webserver'] == 'apache2' ? '1' : '0';
if (!empty($this->validatedData['serveripv6'])) {
$stmt->execute([
'nvh' => $nvh,
'serverip' => $this->validatedData['serverip'],
'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']) {
if (!empty($this->validatedData['serveripv6'])) {
$stmt->execute([
'nvh' => $this->validatedData['webserver'] == 'apache2' ? '1' : '0',
'serverip' => $this->validatedData['serverip'],
'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
$upd_stmt = $db_user->prepare("

View File

@@ -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<br><small>(https://inside.froxlor.org/news/)</small>',
'activate_newsfeed' => 'Enable the official newsfeed<br><small>(external source: https://inside.froxlor.org/news/)</small>',
],
'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',