fix checkbox-value for installation; fix session-initialization; preselect various guessable fields to ease installation

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-05-05 17:26:28 +02:00
parent 65eeab299d
commit d0eaf12b34
4 changed files with 63 additions and 22 deletions

View File

@@ -67,6 +67,10 @@ class Install
// sort by distribution name
asort($this->supportedOS);
// guess distribution and webserver to preselect in formfield
$guessedDistribution = $this->guessDistribution();
$guessedWebserver = $this->guessWebserver();
// set formfield, so we can get the fields and steps etc.
$this->formfield = require dirname(__DIR__, 3) . '/lib/formfields/install/formfield.install.php';
@@ -78,10 +82,6 @@ class Install
$this->phpVersion = phpversion();
$this->loadedExtensions = get_loaded_extensions();
// init twig
UI::initTwig(true);
UI::sendHeaders();
// set global variables
UI::twig()->addGlobal('install_mode', true);
UI::twig()->addGlobal('basehref', '../');
@@ -155,6 +155,7 @@ class Install
if ($this->currentStep == ($this->maxSteps - 1)) {
$core = new Core($_SESSION['installation']);
$core->doInstall();
// @todo no going back after this point!
}
// redirect user to home if the installation is done
@@ -271,7 +272,7 @@ class Install
if (!preg_match('/^[^\r\n\t\f\0]*$/D', $name)) {
throw new Exception(lng('error.stringformaterror', ['admin_name']));
} elseif (empty(trim($loginname)) || !preg_match('/^[a-z][a-z0-9]', $loginname)) {
} elseif (empty(trim($loginname)) || !preg_match('/^[a-z][a-z0-9]+$/', $loginname)) {
throw new Exception(lng('error.loginnameiswrong', [$loginname]));
} elseif (empty(trim($email)) || !Validate::validateEmail($email)) {
throw new Exception(lng('error.emailiswrong', [$email]));
@@ -332,4 +333,37 @@ class Install
// @todo build and set $validatedData['mysql_access_host']
}
private function guessWebserver(): ?string
{
if (strtoupper(@php_sapi_name()) == "APACHE2HANDLER" || stristr($_SERVER['SERVER_SOFTWARE'], "apache/2")) {
return 'apache24';
} elseif (substr(strtoupper(@php_sapi_name()), 0, 8) == "LIGHTTPD" || stristr($_SERVER['SERVER_SOFTWARE'], "lighttpd")) {
return 'lighttpd';
} elseif (substr(strtoupper(@php_sapi_name()), 0, 8) == "NGINX" || stristr($_SERVER['SERVER_SOFTWARE'], "nginx")) {
return 'nginx';
}
return null;
}
private function guessDistribution(): ?string
{
// set default os.
$os_dist = array(
'VERSION_CODENAME' => 'bullseye'
);
// read os-release
if (@file_exists('/etc/os-release')) {
$os_dist_content = file_get_contents('/etc/os-release');
$os_dist_arr = explode("\n", $os_dist_content);
$os_dist = [];
foreach ($os_dist_arr as $os_dist_line) {
if (empty(trim($os_dist_line))) continue;
$tmp = explode("=", $os_dist_line);
$os_dist[$tmp[0]] = str_replace('"', "", trim($tmp[1]));
}
return strtolower($os_dist['VERSION_CODENAME']);
}
return null;
}
}

View File

@@ -132,7 +132,7 @@ return [
'admin_email' => [
'label' => lng('customer.email'),
'placeholder' => lng('customer.email'),
'type' => 'text',
'type' => 'email',
'mandatory' => true,
'value' => old('admin_email', null, 'installation'),
],
@@ -147,20 +147,21 @@ return [
'type' => 'select',
'mandatory' => true,
'select_var' => $this->supportedOS,
'selected' => $guessedDistribution
],
'serverip' => [
'label' => lng('serversettings.ipaddress.title'),
'placeholder' => lng('serversettings.ipaddress.title'),
'type' => 'text',
'mandatory' => true,
'value' => old('serverip', null, 'installation'),
'value' => old('serverip', $_SERVER['SERVER_ADDR'] ?? null, 'installation'),
],
'servername' => [
'label' => lng('install.system.servername'),
'placeholder' => lng('install.system.servername'),
'type' => 'text',
'mandatory' => true,
'value' => old('servername', null, 'installation'),
'value' => old('servername', filter_var($_SERVER['SERVER_NAME'] ?? "", FILTER_VALIDATE_IP) ? null : $_SERVER['SERVER_NAME'], 'installation'),
],
'use_ssl' => [
'label' => lng('serversettings.ssl.use_ssl.title'),
@@ -173,7 +174,7 @@ return [
'type' => 'select',
'mandatory' => true,
'select_var' => ['apache24' => 'Apache 2.4', 'nginx' => 'Nginx', 'lighttpd' => 'LigHTTPd'],
'value' => old('webserver', 'apache24', 'installation'),
'value' => old('webserver', $guessedWebserver, 'installation'),
],
'webserver_backend' => [
'label' => lng('install.system.phpbackend'),
@@ -187,14 +188,14 @@ return [
'placeholder' => lng('admin.webserver_user'),
'type' => 'text',
'mandatory' => true,
'value' => old('httpuser', posix_getpwuid(posix_getuid()), 'installation'),
'value' => old('httpuser', posix_getpwuid(posix_getuid())['name'] ?? '', 'installation'),
],
'httpgroup' => [
'label' => lng('admin.webserver_group'),
'placeholder' => lng('admin.webserver_group'),
'type' => 'text',
'mandatory' => true,
'value' => old('httpgroup', posix_getgrgid(posix_getgid()), 'installation'),
'value' => old('httpgroup', posix_getgrgid(posix_getgid())['name'] ?? '', 'installation'),
],
'activate_newsfeed' => [
'label' => lng('install.system.activate_newsfeed'),