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:
@@ -23,6 +23,7 @@
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
use Froxlor\UI\Panel\UI;
|
||||
use Froxlor\Install\Install;
|
||||
|
||||
// define default theme for configurehint, etc.
|
||||
@@ -31,20 +32,20 @@ $_deftheme = 'Froxlor';
|
||||
// validate correct php version
|
||||
if (version_compare("7.4.0", PHP_VERSION, ">=")) {
|
||||
die(view($_deftheme . '/misc/phprequirementfailed.html.twig', [
|
||||
'{{ basehref }}' => '../',
|
||||
'{{ froxlor_min_version }}' => '7.4.0',
|
||||
'{{ current_version }}' => PHP_VERSION,
|
||||
'{{ current_year }}' => date('Y', time()),
|
||||
]));
|
||||
'{{ basehref }}' => '../',
|
||||
'{{ froxlor_min_version }}' => '7.4.0',
|
||||
'{{ current_version }}' => PHP_VERSION,
|
||||
'{{ current_year }}' => date('Y', time()),
|
||||
]));
|
||||
}
|
||||
|
||||
// validate vendor autoloader
|
||||
if (!file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
|
||||
die(view($_deftheme . '/misc/vendormissinghint.html.twig', [
|
||||
'{{ basehref }}' => '../',
|
||||
'{{ froxlor_install_dir }}' => dirname(__DIR__),
|
||||
'{{ current_year }}' => date('Y', time()),
|
||||
]));
|
||||
'{{ basehref }}' => '../',
|
||||
'{{ froxlor_install_dir }}' => dirname(__DIR__),
|
||||
'{{ current_year }}' => date('Y', time()),
|
||||
]));
|
||||
}
|
||||
|
||||
// check installation status
|
||||
@@ -54,8 +55,13 @@ if (file_exists(dirname(__DIR__) . '/lib/userdata.inc.php')) {
|
||||
}
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
require dirname(__DIR__) . '/lib/functions.php';
|
||||
require dirname(__DIR__) . '/lib/tables.inc.php';
|
||||
|
||||
// init twig
|
||||
UI::initTwig(true);
|
||||
UI::sendHeaders();
|
||||
|
||||
require dirname(__DIR__) . '/lib/functions.php';
|
||||
|
||||
$installer = new Install();
|
||||
$installer->handle();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
{% else %}
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input type="hidden" value="0" name="{{ id }}" />
|
||||
<input type="checkbox" {% if (field.visible is defined and field.visible == false) or (field.disabled is defined and field.disabled == true) %} disabled {% endif %} value="{{ subfield.value }}" name="{{ id }}[]" class="form-check-input" {% if field.value is defined and subfield.value in field.value %} checked="checked" {% endif %}>
|
||||
<input type="checkbox" {% if (field.visible is defined and field.visible == false) or (field.disabled is defined and field.disabled == true) %} disabled {% endif %} value="{{ subfield.value }}" name="{{ id }}[]" class="form-check-input" {% if field.checked is defined and field.checked == 1 %} checked="checked" {% endif %}>
|
||||
<label for="{{ id }}" class="form-check-label">{{ field.label|raw }}</label>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user