2010-01-27 08:54:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file is part of the Froxlor project.
|
|
|
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-01-27 08:54:31 +00:00
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2011-05-04 09:59:20 +00:00
|
|
|
*
|
2022-04-28 18:48:00 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you can also view it online at
|
|
|
|
* https://files.froxlor.org/misc/COPYING.txt
|
|
|
|
*
|
|
|
|
* @copyright the authors
|
|
|
|
* @author Froxlor team <team@froxlor.org>
|
|
|
|
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
2010-01-27 08:54:31 +00:00
|
|
|
*/
|
2022-02-20 17:00:44 +00:00
|
|
|
|
|
|
|
const AREA = 'admin';
|
|
|
|
require __DIR__ . '/lib/init.php';
|
2013-11-18 11:53:33 +00:00
|
|
|
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\Config\ConfigParser;
|
|
|
|
use Froxlor\FileDir;
|
|
|
|
use Froxlor\Froxlor;
|
2018-12-19 15:57:03 +00:00
|
|
|
use Froxlor\Settings;
|
2022-03-18 08:37:50 +00:00
|
|
|
use Froxlor\UI\Panel\UI;
|
|
|
|
use Froxlor\UI\Request;
|
2022-04-28 18:48:00 +00:00
|
|
|
use Froxlor\UI\Response;
|
2023-07-07 07:46:31 +00:00
|
|
|
use Froxlor\Validate\Validate;
|
2018-12-18 12:45:05 +00:00
|
|
|
|
2018-12-22 07:15:31 +00:00
|
|
|
if ($userinfo['change_serversettings'] == '1') {
|
2018-12-21 11:24:07 +00:00
|
|
|
if ($action == 'setconfigured') {
|
2018-12-10 19:34:43 +00:00
|
|
|
Settings::Set('panel.is_configured', '1', true);
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo('admin_configfiles.php');
|
2018-12-10 19:34:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 07:41:38 +00:00
|
|
|
// get distro from URL param
|
2022-12-30 20:43:27 +00:00
|
|
|
$distribution = Request::any('distribution');
|
|
|
|
$reselect = Request::any('reselect', 0);
|
2016-05-29 07:41:38 +00:00
|
|
|
|
2022-04-30 12:01:49 +00:00
|
|
|
// check for possible setting
|
|
|
|
if (empty($distribution)) {
|
|
|
|
$distribution = Settings::Get('system.distribution') ?? "";
|
|
|
|
}
|
2022-05-06 08:19:19 +00:00
|
|
|
if ($reselect == 1) {
|
|
|
|
$distribution = '';
|
|
|
|
}
|
2022-04-30 12:01:49 +00:00
|
|
|
|
2022-03-18 08:37:50 +00:00
|
|
|
$distributions_select = [];
|
2016-05-29 07:41:38 +00:00
|
|
|
|
2022-03-18 08:37:50 +00:00
|
|
|
$services = [];
|
2022-04-28 18:48:00 +00:00
|
|
|
$config_dir = FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/lib/configfiles/');
|
2016-05-29 07:41:38 +00:00
|
|
|
|
2022-03-18 08:37:50 +00:00
|
|
|
if (!empty($distribution)) {
|
|
|
|
if (!file_exists($config_dir . '/' . $distribution . ".xml")) {
|
2023-12-10 18:23:58 +00:00
|
|
|
// unknown distribution -> redirect to select a valid distribution for config-templates
|
|
|
|
Settings::Set('system.distribution', '');
|
|
|
|
Response::redirectTo('admin_configfiles.php', ['reselect' => 1]);
|
2017-12-27 09:01:07 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 12:01:49 +00:00
|
|
|
// update setting if different
|
|
|
|
if ($distribution != Settings::Get('system.distribution')) {
|
|
|
|
Settings::Set('system.distribution', $distribution);
|
|
|
|
}
|
|
|
|
|
2016-05-29 07:41:38 +00:00
|
|
|
// create configparser object
|
2022-04-28 18:48:00 +00:00
|
|
|
$configfiles = new ConfigParser($config_dir . '/' . $distribution . ".xml");
|
2016-05-29 07:41:38 +00:00
|
|
|
|
|
|
|
// get distro-info
|
2022-04-24 09:08:09 +00:00
|
|
|
$dist_display = $configfiles->getCompleteDistroName();
|
2016-05-29 07:41:38 +00:00
|
|
|
|
|
|
|
// get all the services from the distro
|
|
|
|
$services = $configfiles->getServices();
|
|
|
|
} else {
|
|
|
|
// show list of available distro's
|
|
|
|
$distros = glob($config_dir . '*.xml');
|
|
|
|
// read in all the distros
|
|
|
|
foreach ($distros as $_distribution) {
|
|
|
|
// get configparser object
|
2022-04-28 18:48:00 +00:00
|
|
|
$dist = new ConfigParser($_distribution);
|
2016-05-29 07:41:38 +00:00
|
|
|
// store in tmp array
|
2022-04-24 09:08:09 +00:00
|
|
|
$distributions_select[str_replace(".xml", "", strtolower(basename($_distribution)))] = $dist->getCompleteDistroName();
|
2016-05-29 07:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sort by distribution name
|
2022-03-18 08:37:50 +00:00
|
|
|
asort($distributions_select);
|
2016-05-29 07:41:38 +00:00
|
|
|
}
|
|
|
|
|
2024-05-09 13:48:23 +00:00
|
|
|
if ($distribution != "" && !empty(Request::post('finish'))) {
|
2024-01-05 15:52:40 +00:00
|
|
|
$valid_keys = ['http', 'dns', 'smtp', 'mail', 'antispam', 'ftp', 'system', 'distro'];
|
2022-03-18 08:37:50 +00:00
|
|
|
unset($_POST['finish']);
|
2023-01-15 22:48:37 +00:00
|
|
|
unset($_POST['csrf_token']);
|
2024-05-09 13:48:23 +00:00
|
|
|
$params = Request::postAll();
|
2022-03-18 08:37:50 +00:00
|
|
|
$params['distro'] = $distribution;
|
|
|
|
$params['system'] = [];
|
2024-05-09 13:48:23 +00:00
|
|
|
foreach (Request::post('system', []) as $sysdaemon) {
|
2022-03-18 08:37:50 +00:00
|
|
|
$params['system'][] = $sysdaemon;
|
2017-12-27 09:01:07 +00:00
|
|
|
}
|
2023-07-07 07:46:31 +00:00
|
|
|
// validate params
|
|
|
|
foreach ($params as $key => $value) {
|
|
|
|
if (!in_array($key, $valid_keys)) {
|
|
|
|
unset($params[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!is_array($value)) {
|
|
|
|
$params[$key] = Validate::validate($value, $key);
|
|
|
|
} else {
|
|
|
|
foreach ($value as $subkey => $subvalue) {
|
|
|
|
$params[$key][$subkey] = Validate::validate($subvalue, $key.'.'.$subkey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-18 08:37:50 +00:00
|
|
|
$params_content = json_encode($params);
|
2022-04-28 18:48:00 +00:00
|
|
|
$params_filename = FileDir::makeCorrectFile(Froxlor::getInstallDir() . 'install/' . Froxlor::genSessionId() . '.json');
|
2022-03-18 08:37:50 +00:00
|
|
|
file_put_contents($params_filename, $params_content);
|
|
|
|
|
|
|
|
UI::twigBuffer('settings/configuration-final.html.twig', [
|
|
|
|
'distribution' => $distribution,
|
|
|
|
// alert
|
|
|
|
'type' => 'info',
|
2022-04-28 18:48:00 +00:00
|
|
|
'alert_msg' => lng('admin.configfiles.finishnote'),
|
|
|
|
'basedir' => Froxlor::getInstallDir(),
|
2022-03-18 08:37:50 +00:00
|
|
|
'params_filename' => $params_filename
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
if (!empty($distribution)) {
|
|
|
|
// show available services to configure
|
|
|
|
$fields = $services;
|
|
|
|
$link_params = ['section' => 'configfiles', 'distribution' => $distribution];
|
|
|
|
UI::twigBuffer('settings/configuration.html.twig', [
|
|
|
|
'action' => $linker->getLink($link_params),
|
|
|
|
'fields' => $fields,
|
|
|
|
'distribution' => $distribution
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
$cfg_formfield = [
|
|
|
|
'config' => [
|
2022-04-28 18:48:00 +00:00
|
|
|
'title' => lng('admin.configfiles.serverconfiguration'),
|
2022-03-18 08:37:50 +00:00
|
|
|
'image' => 'fa-solid fa-wrench',
|
2022-04-28 18:48:00 +00:00
|
|
|
'description' => lng('admin.configfiles.description'),
|
2022-03-18 08:37:50 +00:00
|
|
|
'sections' => [
|
|
|
|
'section_config' => [
|
|
|
|
'fields' => [
|
2022-04-28 18:48:00 +00:00
|
|
|
'distribution' => [
|
|
|
|
'type' => 'select',
|
|
|
|
'select_var' => $distributions_select,
|
2022-05-06 08:19:19 +00:00
|
|
|
'label' => lng('admin.configfiles.distribution'),
|
|
|
|
'selected' => Settings::Get('system.distribution') ?? ''
|
2022-04-28 18:48:00 +00:00
|
|
|
]
|
2022-03-18 08:37:50 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'buttons' => [
|
|
|
|
[
|
|
|
|
'class' => 'btn-outline-secondary',
|
2022-04-28 18:48:00 +00:00
|
|
|
'label' => lng('panel.cancel'),
|
2022-03-18 08:37:50 +00:00
|
|
|
'type' => 'reset'
|
|
|
|
],
|
|
|
|
[
|
2022-04-28 18:48:00 +00:00
|
|
|
'label' => lng('update.proceed')
|
2022-03-18 08:37:50 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
UI::twigBuffer('user/form-note.html.twig', [
|
2022-04-28 18:48:00 +00:00
|
|
|
'formaction' => $linker->getLink(['section' => 'configfiles']),
|
2022-03-18 08:37:50 +00:00
|
|
|
'formdata' => $cfg_formfield['config'],
|
2022-04-28 18:48:00 +00:00
|
|
|
'actions_links' => (int)Settings::Get('panel.is_configured') == 0 ? [
|
|
|
|
[
|
|
|
|
'href' => $linker->getLink([
|
|
|
|
'section' => 'configfiles',
|
|
|
|
'page' => 'overview',
|
|
|
|
'action' => 'setconfigured'
|
|
|
|
]),
|
|
|
|
'label' => lng('panel.ihave_configured'),
|
|
|
|
'class' => 'btn-outline-warning',
|
2022-09-08 11:13:06 +00:00
|
|
|
'icon' => 'fa-solid fa-circle-check'
|
2022-04-28 18:48:00 +00:00
|
|
|
]
|
|
|
|
] : [],
|
2022-03-18 08:37:50 +00:00
|
|
|
// alert
|
|
|
|
'type' => 'warning',
|
2022-04-28 18:48:00 +00:00
|
|
|
'alert_msg' => lng('panel.settings_before_configuration') . ((int)Settings::Get('panel.is_configured') == 1 ? '<br><br>' . lng('panel.system_is_configured') : '')
|
2022-03-18 08:37:50 +00:00
|
|
|
]);
|
2016-05-29 07:41:38 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-18 08:37:50 +00:00
|
|
|
|
|
|
|
UI::twigOutputBuffer();
|
2015-02-09 12:54:55 +00:00
|
|
|
} else {
|
2022-04-28 18:48:00 +00:00
|
|
|
Response::redirectTo('admin_index.php');
|
2015-02-09 12:54:55 +00:00
|
|
|
}
|