From e768d834c1719a8a44a01b1ab102bd45d3a21064 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Sat, 30 Apr 2022 14:01:49 +0200 Subject: [PATCH] add new setting to preselect system distribution to ease configuration Signed-off-by: Michael Kaufmann --- admin_configfiles.php | 10 +++++++ install/froxlor.sql.php | 1 + .../updates/froxlor/0.11/update_0.11.inc.php | 2 ++ .../preconfig/0.11/preconfig_0.11.inc.php | 28 ++++++++++++++++++- lib/Froxlor/Cli/RunApiCommand.php | 2 +- lng/en.lng.php | 3 ++ 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/admin_configfiles.php b/admin_configfiles.php index 85c16933..2742c43a 100644 --- a/admin_configfiles.php +++ b/admin_configfiles.php @@ -43,6 +43,11 @@ if ($userinfo['change_serversettings'] == '1') { // get distro from URL param $distribution = Request::get('distribution'); + // check for possible setting + if (empty($distribution)) { + $distribution = Settings::Get('system.distribution') ?? ""; + } + $distributions_select = []; $services = []; @@ -53,6 +58,11 @@ if ($userinfo['change_serversettings'] == '1') { Response::dynamicError("Unknown distribution"); } + // update setting if different + if ($distribution != Settings::Get('system.distribution')) { + Settings::Set('system.distribution', $distribution); + } + // create configparser object $configfiles = new ConfigParser($config_dir . '/' . $distribution . ".xml"); diff --git a/install/froxlor.sql.php b/install/froxlor.sql.php index 51f177e2..7ccb1407 100644 --- a/install/froxlor.sql.php +++ b/install/froxlor.sql.php @@ -699,6 +699,7 @@ opcache.validate_timestamps'), ('system', 'froxlorusergroup', ''), ('system', 'froxlorusergroup_gid', ''), ('system', 'acmeshpath', '/root/.acme.sh/acme.sh'), + ('system', 'distribution', ''), ('api', 'enabled', '0'), ('2fa', 'enabled', '1'), ('panel', 'decimal_places', '4'), diff --git a/install/updates/froxlor/0.11/update_0.11.inc.php b/install/updates/froxlor/0.11/update_0.11.inc.php index 82712c91..ef7c5c0e 100644 --- a/install/updates/froxlor/0.11/update_0.11.inc.php +++ b/install/updates/froxlor/0.11/update_0.11.inc.php @@ -126,6 +126,8 @@ if (Froxlor::isFroxlorVersion('0.10.99')) { Update::showUpdateStep("Adding new settings"); $panel_settings_mode = isset($_POST['panel_settings_mode']) ? (int) $_POST['panel_settings_mode'] : 0; Settings::AddNew("panel.settings_mode", $panel_settings_mode); + $system_distribution = isset($_POST['system_distribution']) ? $_POST['system_distribution'] : ''; + Settings::AddNew("system.distribution", $system_distribution); Update::lastStepStatus(0); Update::showUpdateStep("Adjusting existing settings"); diff --git a/install/updates/preconfig/0.11/preconfig_0.11.inc.php b/install/updates/preconfig/0.11/preconfig_0.11.inc.php index c86d8bb2..e9a7f959 100644 --- a/install/updates/preconfig/0.11/preconfig_0.11.inc.php +++ b/install/updates/preconfig/0.11/preconfig_0.11.inc.php @@ -15,6 +15,10 @@ * */ +use Froxlor\Froxlor; +use Froxlor\FileDir; +use Froxlor\Config\ConfigParser; + /** * checks if the new-version has some updating to do * @@ -29,7 +33,6 @@ */ function parseAndOutputPreconfig011(&$has_preconfig, &$return, $current_version, $current_db_version) { - global $lng; if (versionInUpdate($current_version, '0.10.99')) { $has_preconfig = true; @@ -45,5 +48,28 @@ function parseAndOutputPreconfig011(&$has_preconfig, &$return, $current_version, 'selected' => 1, 'label' => $question ]; + + $description = 'The configuration page now can preselect a distribution, please select your current distribution'; + $return['system_distribution_note'] = ['type' => 'infotext', 'value' => $description]; + $question = 'Select distribution'; + $config_dir = FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/lib/configfiles/'); + // show list of available distro's + $distros = glob($config_dir . '*.xml'); + $distributions_select[''] = '-'; + // read in all the distros + foreach ($distros as $_distribution) { + // get configparser object + $dist = new ConfigParser($_distribution); + // store in tmp array + $distributions_select[str_replace(".xml", "", strtolower(basename($_distribution)))] = $dist->getCompleteDistroName(); + } + // sort by distribution name + asort($distributions_select); + $return['system_distribution'] = [ + 'type' => 'select', + 'select_var' => $distributions_select, + 'selected' => '', + 'label' => $question + ]; } } diff --git a/lib/Froxlor/Cli/RunApiCommand.php b/lib/Froxlor/Cli/RunApiCommand.php index 71399aa5..8efcd223 100644 --- a/lib/Froxlor/Cli/RunApiCommand.php +++ b/lib/Froxlor/Cli/RunApiCommand.php @@ -94,7 +94,7 @@ final class RunApiCommand extends CliCommand } else { $rows = []; foreach ($docs['params'] as $param) { - $rows[] = [$param['type'], ''.$param['parameter'].'', $param['desc'] ?? ""]; + $rows[] = [$param['type'], '' . $param['parameter'] . '', $param['desc'] ?? ""]; } $io->table(['Type', 'Name', 'Description'], $rows); } diff --git a/lng/en.lng.php b/lng/en.lng.php index 73292c22..3aee9789 100644 --- a/lng/en.lng.php +++ b/lng/en.lng.php @@ -1354,6 +1354,9 @@ Yours sincerely, your administrator', 'maintitle' => 'PHP Configurations', 'fpmdaemons' => 'PHP-FPM versions', ], + 'logger' => [ + 'logger' => 'System log', + ], ], 'message' => [ 'norecipients' => 'No e-mail has been sent because there are no recipients in the database',