]> git.agnieray.net Git - galette.git/blob - galette/webroot/installer.php
3c08a77212a116af8be2f74ba71cb151acc32740
[galette.git] / galette / webroot / installer.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Main Galette initialisation
7 *
8 * PHP version 5
9 *
10 * Copyright © 2013-2014 The Galette Team
11 *
12 * This file is part of Galette (http://galette.eu).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Main
28 * @package Galette
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2013-2014 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
34 * @since Available since 0.8
35 */
36
37 use Galette\Core\Install as GaletteInstall;
38 use Galette\Core\Db as GaletteDb;
39 use Analog\Analog;
40 use Analog\Handler;
41 use Analog\Handler\LevelName;
42
43 //set a flag saying we work from installer
44 //that way, in galette.inc.php, we'll only include relevant parts
45 $installer = true;
46 define('GALETTE_ROOT', __DIR__ . '/../');
47 define('GALETTE_MODE', 'INSTALL');
48
49 // check PHP modules
50 require_once GALETTE_ROOT . '/vendor/autoload.php';
51 require_once GALETTE_ROOT . 'config/versions.inc.php';
52
53 if (version_compare(PHP_VERSION, GALETTE_PHP_MIN, '<') || !extension_loaded('intl')) {
54 header('location: compat_test.php');
55 die(1);
56 }
57
58 //specific logfile for installer
59 $logfile = 'galette_install';
60 define('GALETTE_BASE_PATH', '../');
61
62 require_once '../includes/galette.inc.php';
63
64 session_start();
65 $session_name = 'galette_install_' . str_replace('.', '_', GALETTE_VERSION);
66 $session = &$_SESSION['galette'][$session_name];
67
68 $gapp = new \Galette\Core\SlimApp();
69 $app = $gapp->getApp();
70 require_once '../includes/dependencies.php';
71
72 if (isset($_POST['abort_btn'])) {
73 if (isset($session[md5(GALETTE_ROOT)])) {
74 unset($session[md5(GALETTE_ROOT)]);
75 }
76 header('location: ' . GALETTE_BASE_PATH);
77 }
78
79 $install = null;
80 if (isset($session[md5(GALETTE_ROOT)]) && !isset($_GET['raz'])) {
81 $install = unserialize($session[md5(GALETTE_ROOT)]);
82 } else {
83 $install = new GaletteInstall();
84 }
85
86 $error_detected = array();
87
88 /**
89 * Initialize database constants to connect
90 *
91 * @param Install $install Installer
92 *
93 * @return void
94 */
95 function initDbConstants($install)
96 {
97 define('TYPE_DB', $install->getDbType());
98 define('PREFIX_DB', $install->getTablesPrefix());
99 define('USER_DB', $install->getDbUser());
100 define('PWD_DB', $install->getDbPass());
101 define('HOST_DB', $install->getDbHost());
102 define('PORT_DB', $install->getDbPort());
103 define('NAME_DB', $install->getDbName());
104 }
105
106 if ($install->isStepPassed(GaletteInstall::STEP_TYPE)) {
107 define('GALETTE_LOGGER_CHECKED', true);
108
109 $log_path = GALETTE_LOGS_PATH . $logfile . '.log';
110 $galette_run_log = LevelName::init(Handler\File::init($log_path));
111 Analog::handler($galette_run_log);
112 }
113
114 if (isset($_POST['stepback_btn'])) {
115 $install->atPreviousStep();
116 } elseif (isset($_POST['install_permsok']) && $_POST['install_permsok'] == 1) {
117 $install->atTypeStep();
118 } elseif (isset($_POST['install_type'])) {
119 $install->setMode($_POST['install_type']);
120 $install->atDbStep();
121 } elseif (isset($_POST['install_dbtype'])) {
122 $install->setDbType($_POST['install_dbtype'], $error_detected);
123
124 if (empty($_POST['install_dbhost'])) {
125 $error_detected[] = _T("No host");
126 }
127 if (empty($_POST['install_dbport'])) {
128 $error_detected[] = _T("No port");
129 }
130 if (empty($_POST['install_dbuser'])) {
131 $error_detected[] = _T("No user name");
132 }
133 if (empty($_POST['install_dbpass'])) {
134 $error_detected[] = _T("No password");
135 }
136 if (empty($_POST['install_dbname'])) {
137 $error_detected[] = _T("No database name");
138 }
139
140 if (count($error_detected) == 0) {
141 $install->setDsn(
142 $_POST['install_dbhost'],
143 $_POST['install_dbport'],
144 $_POST['install_dbname'],
145 $_POST['install_dbuser'],
146 $_POST['install_dbpass']
147 );
148 $install->setTablesPrefix(
149 $_POST['install_dbprefix']
150 );
151 $install->atDbCheckStep();
152 }
153 } elseif (isset($_POST['install_dbperms_ok'])) {
154 if ($install->isInstall()) {
155 $install->atDbInstallStep();
156 } elseif ($install->isUpgrade()) {
157 $install->atVersionSelection();
158 }
159 } elseif (isset($_POST['previous_version'])) {
160 $install->setInstalledVersion($_POST['previous_version']);
161 $install->atDbUpgradeStep();
162 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isInstall()) {
163 $install->atAdminStep();
164 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isUpgrade()) {
165 $install->atGaletteInitStep();
166 } elseif (isset($_POST['install_adminlogin'])
167 && isset($_POST['install_adminpass'])
168 && $install->isInstall()
169 ) {
170 if ($_POST['install_adminlogin'] == '') {
171 $error_detected[] = _T("No user name");
172 }
173 if (strpos($_POST['install_adminlogin'], '@') != false) {
174 $error_detected[] = _T("The username cannot contain the @ character");
175 }
176 if ($_POST['install_adminpass'] == '') {
177 $error_detected[] = _T("No password");
178 }
179 if (!isset($_POST['install_passwdverified'])
180 && strcmp(
181 $_POST['install_adminpass'],
182 $_POST['install_adminpass_verif']
183 )
184 ) {
185 $error_detected[] = _T("Passwords mismatch");
186 }
187 if (count($error_detected) == 0) {
188 $install->setAdminInfos(
189 $_POST['install_adminlogin'],
190 $_POST['install_adminpass']
191 );
192 $install->atGaletteInitStep();
193 }
194 } elseif (isset($_POST['install_prefs_ok'])) {
195 $install->atEndStep();
196 }
197
198 if (!$install->isEndStep()
199 && ($install->postCheckDb() || $install->isDbCheckStep())
200 ) {
201 //if we have passed database configuration, define required constants
202 initDbConstants($install);
203
204 if ($install->postCheckDb()) {
205 //while before check db, connection is not checked
206 $zdb = new GaletteDb();
207 }
208 }
209
210 header('Content-Type: text/html; charset=UTF-8');
211 ?>
212 <!DOCTYPE html>
213 <html lang="<?php echo $i18n->getAbbrev(); ?>">
214 <head>
215 <title><?php echo _T("Galette Installation") . ' - ' . $install->getStepTitle(); ?></title>
216 <meta charset="UTF-8"/>
217 <meta name="viewport" content="width=device-width" />
218 <link rel="stylesheet" type="text/css" href="./themes/default/ui/semantic.min.css" />
219 <link rel="shortcut icon" href="./themes/default/images/favicon.png" />
220 <script type="text/javascript" src="./assets/js/jquery.min.js"></script>
221 </head>
222 <body class="pushable">
223 <header id="top-navbar" class="ui fixed menu bgcolor">
224 <div class="ui container">
225 <div class="header item">
226 <span><?php echo _T("Galette installation") ?></span>
227 </div>
228 <div class="language ui dropdown right item">
229 <i class="icon language" aria-hidden="true"></i>
230 <span><?php echo $i18n->getAbbrev(); ?></span>
231 <i class="icon dropdown" aria-hidden="true"></i>
232 <div class="menu">
233 <?php
234 foreach ($i18n->getList() as $langue) {
235 ?>
236 <a href="?ui_pref_lang=<?php echo $langue->getID(); ?>" lang="<?php echo $langue->getAbbrev(); ?>" class="item"><?php echo $langue->getName(); ?> <span>(<?php echo $langue->getAbbrev(); ?>)</span></a>
237 <?php
238 }
239 ?>
240 </div>
241 </div>
242 </div>
243 </header>
244 <div class="pusher">
245 <div id="main" class="ui container">
246 <div class="ui basic segment">
247 <div class="ui basic center aligned fitted segment">
248 <img class="icon" alt="[ Galette ]" src="./themes/default/images/galette.png"/>
249 </div>
250 <h1 class="ui block center aligned header">
251 <?php echo $install->getStepTitle(); ?>
252 </h1>
253 <?php
254 if (count($error_detected) > 0) {
255 ?>
256 <div id="errorbox" class="ui red message">
257 <h1><?php echo _T("- ERROR -"); ?></h1>
258 <ul>
259 <?php
260 foreach ($error_detected as $error) {
261 ?>
262 <li><?php echo $error; ?></li>
263 <?php
264 }
265 ?>
266 </ul>
267 </div>
268 <?php
269 }
270 ?>
271 <?php
272 if ($install->isCheckStep()) {
273 include_once __DIR__ . '/../install/steps/check.php';
274 } elseif ($install->isTypeStep()) {
275 include_once __DIR__ . '/../install/steps/type.php';
276 } elseif ($install->isDbStep()) {
277 include_once __DIR__ . '/../install/steps/db.php';
278 } elseif ($install->isDbCheckStep()) {
279 include_once __DIR__ . '/../install/steps/db_checks.php';
280 } elseif ($install->isVersionSelectionStep()) {
281 include_once __DIR__ . '/../install/steps/db_select_version.php';
282 } elseif ($install->isDbinstallStep() || $install->isDbUpgradeStep()) {
283 include_once __DIR__ . '/../install/steps/db_install.php';
284 } elseif ($install->isAdminStep()) {
285 include_once __DIR__ . '/../install/steps/admin.php';
286 } elseif ($install->isGaletteInitStep()) {
287 include_once __DIR__ . '/../install/steps/galette.php';
288 } elseif ($install->isEndStep()) {
289 include_once __DIR__ . '/../install/steps/end.php';
290 }
291 ?>
292 <div class="ui tablet stackable mini eight steps">
293 <div class="step<?php if ($install->isCheckStep()) echo ' active'; ?>">
294 <i class="tasks icon"></i>
295 <div class="content">
296 <div class="title"><?php echo _T("Checks"); ?></div>
297 </div>
298 </div>
299 <div class="step<?php if ($install->isTypeStep()) echo ' active'; ?>">
300 <i class="question icon"></i>
301 <div class="content">
302 <div class="title"><?php echo _T("Installation mode"); ?></div>
303 </div>
304 </div>
305 <div class="step<?php if ($install->isDbStep()) echo ' active'; ?>">
306 <i class="database icon"></i>
307 <div class="content">
308 <div class="title"><?php echo _T("Database"); ?></div>
309 </div>
310 </div>
311 <div class="step<?php if ($install->isDbCheckStep()) echo ' active'; ?>">
312 <i class="key icon"></i>
313 <div class="content">
314 <div class="title"><?php echo _T("Database access/permissions"); ?></div>
315 </div>
316 </div>
317 <?php
318 if ($install->isUpgrade()) {
319 ?>
320 <div class="step<?php if ($install->isVersionSelectionStep()) echo ' active'; ?>">
321 <i class="tag icon"></i>
322 <div class="content">
323 <div class="title"><?php echo _T("Version selection"); ?></div>
324 </div>
325 </div>
326 <div class="step<?php if ($install->isDbUpgradeStep()) echo ' active'; ?>">
327 <i class="sync alt icon"></i>
328 <div class="content">
329 <div class="title"><?php echo _T("Database upgrade"); ?></div>
330 </div>
331 </div>
332 <?php
333 } else {
334 ?>
335 <div class="step<?php if ($install->isDbinstallStep()) echo ' active'; ?>">
336 <i class="spinner icon"></i>
337 <div class="content">
338 <div class="title"><?php echo _T("Database installation"); ?></div>
339 </div>
340 </div>
341 <?php
342 }
343
344 if (!$install->isUpgrade()) {
345 ?>
346 <div class="step<?php if ($install->isAdminStep()) echo ' active'; ?>">
347 <i class="user icon"></i>
348 <div class="content">
349 <div class="title"><?php echo _T("Admin parameters"); ?></div>
350 </div>
351 </div>
352 <?php
353 }
354 ?>
355 <div class="step<?php if ($install->isGaletteInitStep()) echo ' active'; ?>">
356 <i class="cogs icon"></i>
357 <div class="content">
358 <div class="title"><?php echo _T("Galette initialisation"); ?></div>
359 </div>
360 </div>
361 <div class="step<?php if ($install->isEndStep()) echo ' active'; ?>">
362 <i class="flag checkered icon"></i>
363 <div class="content">
364 <div class="title"><?php echo _T("End!"); ?></div>
365 </div>
366 </div>
367 </div>
368 </div>
369 <footer class="ui basic center aligned segment">
370 <div class="row">
371 <nav class="ui horizontal bulleted link list">
372 <a href="https://galette.eu" class="item">
373 <i class="icon globe europe"></i>
374 <?php echo _T("Website"); ?>
375 </a>
376 <a href="https://doc.galette.eu" class="item">
377 <i class="icon book"></i>
378 <?php echo _T("Documentation"); ?>
379 </a>
380 <a href="https://twitter.com/galette_soft" class="item">
381 <i class="icon twitter"></i>
382 @galette_soft
383 </a>
384 <a href="https://framapiaf.org/@galette" class="item">
385 <i class="icon mastodon"></i>
386 @galette
387 </a>
388 </nav>
389 </div>
390 <div class="row">
391 <nav class="ui horizontal bulleted link list">
392 <a id="copyright" href="https://galette.eu/" class="item">
393 <i class="icon cookie bite"></i>
394 Galette <?php echo GALETTE_DISPLAY_VERSION; ?>
395 </a>
396 </nav>
397 </div>
398 </footer>
399 </div>
400 <script type="text/javascript" src="./assets/js/galette-main.bundle.min.js"></script>
401 <script type="text/javascript" src="./themes/default/ui/semantic.min.js"></script>
402 </body>
403 </html>
404 <?php
405 if (!$install->isEndStep()) {
406 $session[md5(GALETTE_ROOT)] = serialize($install);
407 }
408
409 if (isset($profiler)) {
410 $profiler->stop();
411 }
412 ?>