-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
install.php
255 lines (214 loc) · 10.4 KB
/
install.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
/*
part-db version 0.1
Copyright (C) 2005 Christoph Lechner
http://www.cl-projects.de/
part-db version 0.2+
Copyright (C) 2009 K. Jacobs and others (see authors.php)
http://code.google.com/p/part-db/
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/*
* Steps:
*
* - set_locales
* - set_admin_password
* - set_db_settings
* - set_db_backup_path
*
*/
include_once __DIR__ . '/start_session.php';
use PartDB\Database;
use PartDB\HTML;
use PartDB\Tools\SystemVersion;
$messages = array();
$fatal_error = false;
/********************************************************************************
*
* Evaluate $_REQUEST
*
*********************************************************************************/
// step "set_locales"
$timezone = isset($_REQUEST['timezone']) ? (string)$_REQUEST['timezone'] : 'Europe/Berlin';
$language = isset($_REQUEST['language']) ? (string)$_REQUEST['language'] : 'de_DE';
// step "set_admin_password"
$adminpass_1 = isset($_REQUEST['adminpass_1']) ? trim((string)$_REQUEST['adminpass_1']) : '';
$adminpass_2 = isset($_REQUEST['adminpass_2']) ? trim((string)$_REQUEST['adminpass_2']) : '';
// step "set_db_settings"
$db_type = isset($_REQUEST['db_type']) ? (string)$_REQUEST['db_type'] : 'mysql';
$db_charset = isset($_REQUEST['db_charset']) ? (string)$_REQUEST['db_charset'] : 'utf8';
$db_host = isset($_REQUEST['db_host']) ? (string)$_REQUEST['db_host'] : 'localhost';
$db_name = isset($_REQUEST['db_name']) ? (string)$_REQUEST['db_name'] : 'part-db';
$db_user = isset($_REQUEST['db_user']) ? (string)$_REQUEST['db_user'] : '';
$db_password = isset($_REQUEST['db_password']) ? trim((string)$_REQUEST['db_password']) : '';
$space_fix = isset($_REQUEST['space_fix']) ? true : false;
// step "set_db_backup_path"
$db_backup_name = isset($_REQUEST['db_backup_name']) ? (string)$_REQUEST['db_backup_name'] : '';
$db_backup_path = isset($_REQUEST['db_backup_path']) ? (string)$_REQUEST['db_backup_path'] : '';
// actions
$action = 'default';
if (isset($_REQUEST['save_locales'])) {
$action = 'save_locales';
}
if (isset($_REQUEST['save_admin_password'])) {
$action = 'save_admin_password';
}
if (isset($_REQUEST['save_db_settings'])) {
$action = 'save_db_settings';
}
if (isset($_REQUEST['save_db_backup_path'])) {
$action = 'save_db_backup_path';
}
/********************************************************************************
*
* Initialize Objects
*
*********************************************************************************/
$html = new HTML($config['html']['theme'], $user_config['theme'], _('Part-DB Installation/Update'));
try {
$system_version = SystemVersion::getInstalledVersion();
} catch (Exception $e) {
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
$fatal_error = true;
}
/********************************************************************************
*
* Execute actions
*
*********************************************************************************/
if (! $fatal_error) {
switch ($action) {
case 'save_locales':
try {
$config['timezone'] = $timezone;
$config['language'] = $language;
// check if the server supports the selected language and print a warning if not
if (! ownSetlocale(LC_ALL, $config['language'])) {
throw new Exception(sprintf(_('Die gewählte Sprache "%s" wird vom Server nicht unterstützt!'.
"\nBitte installieren Sie diese Sprache oder wählen Sie eine andere."), $config['language']));
}
$config['installation_complete']['locales'] = true; // locales successful set
} catch (Exception $e) {
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
}
break;
case 'save_admin_password':
try {
// set_admin_password() throws an exception if the new passwords are not valid
setTempAdminPassword($adminpass_1, $adminpass_2, false);
$config['installation_complete']['admin_password'] = true; // admin password successful set
} catch (Exception $e) {
$messages[] = array('text' => nl2br($e->getMessage()), 'strong' => true, 'color' => 'red');
}
break;
case 'save_db_settings':
try {
$config['db']['type'] = $db_type;
//$config['db']['charset'] = $db_charset; // temporarly deactivated
$config['db']['host'] = $db_host;
$config['db']['name'] = $db_name;
$config['db']['user'] = $db_user;
$config['db']['password'] = $db_password;
$config['db']['space_fix'] = $space_fix;
if (strlen($config['db']['name']) == 0) {
throw new Exception('Der Datenbankname darf nicht leer sein!');
}
$database = new Database(); // test the connection --> Exception if it doesn't work
$config['installation_complete']['database'] = true; // database settings successful set
$config['installation_complete']['db_backup_path'] = true; //Workaround, because we removed the dialog for this
} catch (Exception $e) {
$messages[] = array('text' => nl2br(htmlentities($e->getMessage())), 'strong' => true, 'color' => 'red');
}
break;
case 'save_db_backup_path':
try {
$config['db']['backup']['name'] = $db_backup_name;
$config['db']['backup']['url'] = $db_backup_path;
$config['installation_complete']['db_backup_path'] = true; // database backup path successful set
} catch (Exception $e) {
$messages[] = array('text' => nl2br(htmlentities($e->getMessage())), 'strong' => true, 'color' => 'red');
}
break;
default:
break;
}
}
// try to save the config array in config.php --> fatal error if this does not work!
try {
saveConfig();
} catch (Exception $e) {
$messages[] = array('text' => nl2br(htmlentities($e->getMessage())), 'strong' => true, 'color' => 'red');
$fatal_error = true;
}
/********************************************************************************
*
* Decide which installation step should be displayed next
* and set the rest of the HTML variables
*
*********************************************************************************/
if (! $fatal_error) {
try {
// global variables
$html->setVariable('system_version', $system_version->asString(false, true, true, false), 'string');
$html->setVariable('system_version_full', $system_version->asString(false, false, false, true), 'string');
if (!$config['installation_complete']['locales']) {
// step "set_locales"
$tmpl_site_to_show = 'set_locales';
//Convert timezonelist, to a format, we can use
$timezones_raw = DateTimeZone::listIdentifiers();
$timezones = array();
foreach ($timezones_raw as $timezone) {
$timezones[$timezone] = $timezone;
}
$html->setVariable('timezone_loop', arrayToTemplateLoop($timezones, $config['timezone']));
$html->setVariable('language_loop', arrayToTemplateLoop($config['languages'], $config['language']));
} elseif (!$config['installation_complete']['admin_password']) {
$tmpl_site_to_show = 'set_admin_password';
} elseif (!$config['installation_complete']['database']) {
// step "set_db_settings"
$tmpl_site_to_show = 'set_db_settings';
$html->setVariable('db_type_loop', arrayToTemplateLoop($config['db_types'], $config['db']['type']));
$html->setVariable('db_charset_loop', arrayToTemplateLoop($config['db_charsets'], $config['db']['charset']));
$html->setVariable('db_host', $config['db']['host'], 'string');
$html->setVariable('db_name', $config['db']['name'], 'string');
$html->setVariable('db_user', $config['db']['user'], 'string');
$html->setVariable('space_fix', $config['db']['space_fix'], 'boolean');
} /* elseif (!$config['installation_complete']['db_backup_path']) {
// step "set_db_backup_path"
$tmpl_site_to_show = 'set_db_backup_path';
$html->setVariable('db_backup_name', $config['db']['backup']['name'], 'string');
$html->setVariable('db_backup_path', $config['db']['backup']['url'], 'string');
}*/ else {
// installation/update complete
$tmpl_site_to_show = 'finish';
}
} catch (Exception $e) {
$messages[] = array('text' => nl2br(htmlspecialchars($e->getMessage())), 'strong' => true, 'color' => 'red');
$fatal_error = true;
}
}
/********************************************************************************
*
* Generate HTML Output
*
*********************************************************************************/
$reload_link = $fatal_error ? 'install.php' : ''; // an empty string means that the...
//$html->print_header($messages, $reload_link); // ...reload-button won't be visible
if (!empty($messages)) {
$html->setVariable('messages', $messages);
}
$html->printTemplate('header');
if (! $fatal_error) {
$html->printTemplate($tmpl_site_to_show);
}
//$html->print_footer();