-
-
Notifications
You must be signed in to change notification settings - Fork 458
/
admin_configfiles.php
198 lines (180 loc) · 6.1 KB
/
admin_configfiles.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* 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.
*
* 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.
*
* 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
*/
const AREA = 'admin';
require __DIR__ . '/lib/init.php';
use Froxlor\Config\ConfigParser;
use Froxlor\FileDir;
use Froxlor\Froxlor;
use Froxlor\Settings;
use Froxlor\UI\Panel\UI;
use Froxlor\UI\Request;
use Froxlor\UI\Response;
use Froxlor\Validate\Validate;
if ($userinfo['change_serversettings'] == '1') {
if ($action == 'setconfigured') {
Settings::Set('panel.is_configured', '1', true);
Response::redirectTo('admin_configfiles.php');
}
// get distro from URL param
$distribution = Request::any('distribution');
$reselect = Request::any('reselect', 0);
// check for possible setting
if (empty($distribution)) {
$distribution = Settings::Get('system.distribution') ?? "";
}
if ($reselect == 1) {
$distribution = '';
}
$distributions_select = [];
$services = [];
$config_dir = FileDir::makeCorrectDir(Froxlor::getInstallDir() . '/lib/configfiles/');
if (!empty($distribution)) {
if (!file_exists($config_dir . '/' . $distribution . ".xml")) {
// unknown distribution -> redirect to select a valid distribution for config-templates
Settings::Set('system.distribution', '');
Response::redirectTo('admin_configfiles.php', ['reselect' => 1]);
}
// 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");
// get distro-info
$dist_display = $configfiles->getCompleteDistroName();
// 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
$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);
}
if ($distribution != "" && !empty(Request::post('finish'))) {
$valid_keys = ['http', 'dns', 'smtp', 'mail', 'antispam', 'ftp', 'system', 'distro'];
unset($_POST['finish']);
unset($_POST['csrf_token']);
$params = Request::postAll();
$params['distro'] = $distribution;
$params['system'] = [];
foreach (Request::post('system', []) as $sysdaemon) {
$params['system'][] = $sysdaemon;
}
// 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);
}
}
}
$params_content = json_encode($params);
$params_filename = FileDir::makeCorrectFile(Froxlor::getInstallDir() . 'install/' . Froxlor::genSessionId() . '.json');
file_put_contents($params_filename, $params_content);
UI::twigBuffer('settings/configuration-final.html.twig', [
'distribution' => $distribution,
// alert
'type' => 'info',
'alert_msg' => lng('admin.configfiles.finishnote'),
'basedir' => Froxlor::getInstallDir(),
'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' => [
'title' => lng('admin.configfiles.serverconfiguration'),
'image' => 'fa-solid fa-wrench',
'description' => lng('admin.configfiles.description'),
'sections' => [
'section_config' => [
'fields' => [
'distribution' => [
'type' => 'select',
'select_var' => $distributions_select,
'label' => lng('admin.configfiles.distribution'),
'selected' => Settings::Get('system.distribution') ?? ''
]
]
]
],
'buttons' => [
[
'class' => 'btn-outline-secondary',
'label' => lng('panel.cancel'),
'type' => 'reset'
],
[
'label' => lng('update.proceed')
]
]
]
];
UI::twigBuffer('user/form-note.html.twig', [
'formaction' => $linker->getLink(['section' => 'configfiles']),
'formdata' => $cfg_formfield['config'],
'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',
'icon' => 'fa-solid fa-circle-check'
]
] : [],
// alert
'type' => 'warning',
'alert_msg' => lng('panel.settings_before_configuration') . ((int)Settings::Get('panel.is_configured') == 1 ? '<br><br>' . lng('panel.system_is_configured') : '')
]);
}
}
UI::twigOutputBuffer();
} else {
Response::redirectTo('admin_index.php');
}