]> git.agnieray.net Git - galette.git/blob - galette/webroot/installer.php
Drop few duplicated source strings
[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 use Galette\Core\Plugins;
43 use Galette\Core\Preferences;
44 use Galette\Util\Telemetry;
45
46 //set a flag saying we work from installer
47 //that way, in galette.inc.php, we'll only include relevant parts
48 $installer = true;
49 define('GALETTE_ROOT', __DIR__ . '/../');
50 define('GALETTE_MODE', 'INSTALL');
51
52 // check PHP modules
53 require_once GALETTE_ROOT . '/vendor/autoload.php';
54 require_once GALETTE_ROOT . 'config/versions.inc.php';
55
56 if (version_compare(PHP_VERSION, GALETTE_PHP_MIN, '<') || !extension_loaded('intl')) {
57 header('location: compat_test.php');
58 die(1);
59 }
60
61 //specific logfile for installer
62 $logfile = 'galette_install';
63 define('GALETTE_BASE_PATH', '../');
64
65 require_once '../includes/galette.inc.php';
66
67 session_start();
68 $session_name = 'galette_install_' . str_replace('.', '_', GALETTE_VERSION);
69 $session = &$_SESSION['galette'][$session_name];
70
71 $gapp = new \Galette\Core\SlimApp();
72 $app = $gapp->getApp();
73 require_once '../includes/dependencies.php';
74
75 if (isset($_POST['abort_btn'])) {
76 if (isset($session[md5(GALETTE_ROOT)])) {
77 unset($session[md5(GALETTE_ROOT)]);
78 }
79 header('location: ' . GALETTE_BASE_PATH);
80 }
81
82 $install = null;
83 if (isset($session[md5(GALETTE_ROOT)]) && !isset($_GET['raz'])) {
84 $install = unserialize($session[md5(GALETTE_ROOT)]);
85 } else {
86 $install = new GaletteInstall();
87 }
88
89 $error_detected = array();
90
91 /**
92 * Initialize database constants to connect
93 *
94 * @param Install $install Installer
95 *
96 * @return void
97 */
98 function initDbConstants($install)
99 {
100 define('TYPE_DB', $install->getDbType());
101 define('PREFIX_DB', $install->getTablesPrefix());
102 define('USER_DB', $install->getDbUser());
103 define('PWD_DB', $install->getDbPass());
104 define('HOST_DB', $install->getDbHost());
105 define('PORT_DB', $install->getDbPort());
106 define('NAME_DB', $install->getDbName());
107 }
108
109 if ($install->isStepPassed(GaletteInstall::STEP_TYPE)) {
110 define('GALETTE_LOGGER_CHECKED', true);
111
112 $log_path = GALETTE_LOGS_PATH . $logfile . '.log';
113 $galette_run_log = LevelName::init(Handler\File::init($log_path));
114 Analog::handler($galette_run_log);
115 }
116
117 if (!$install->isEndStep()
118 && ($install->postCheckDb())
119 ) {
120 //if we have passed database configuration, define required constants
121 initDbConstants($install);
122
123 if ($install->postCheckDb()) {
124 try {
125 $zdb = new GaletteDb();
126 } catch (Throwable $e) {
127 if (!$install->isDbCheckStep()) {
128 throw $e;
129 }
130 }
131
132 }
133 }
134
135 if (isset($_POST['stepback_btn'])) {
136 $install->atPreviousStep();
137 } elseif (isset($_POST['install_permsok']) && $_POST['install_permsok'] == 1) {
138 $install->atTypeStep();
139 } elseif (isset($_POST['install_type'])) {
140 $install->setMode($_POST['install_type']);
141 $install->atDbStep();
142 } elseif (isset($_POST['install_dbtype'])) {
143 $install->setDbType($_POST['install_dbtype'], $error_detected);
144
145 if (empty($_POST['install_dbhost'])) {
146 $error_detected[] = _T("No host");
147 }
148 if (empty($_POST['install_dbport'])) {
149 $error_detected[] = _T("No port");
150 }
151 if (empty($_POST['install_dbuser'])) {
152 $error_detected[] = _T("No user name");
153 }
154 if (empty($_POST['install_dbpass'])) {
155 $error_detected[] = _T("No password");
156 }
157 if (empty($_POST['install_dbname'])) {
158 $error_detected[] = _T("No database name");
159 }
160
161 if (count($error_detected) == 0) {
162 $install->setDsn(
163 $_POST['install_dbhost'],
164 $_POST['install_dbport'],
165 $_POST['install_dbname'],
166 $_POST['install_dbuser'],
167 $_POST['install_dbpass']
168 );
169 $install->setTablesPrefix(
170 $_POST['install_dbprefix']
171 );
172 $install->atDbCheckStep();
173 initDbConstants($install);
174 }
175 } elseif (isset($_POST['install_dbperms_ok'])) {
176 if ($install->isInstall()) {
177 $install->atDbInstallStep();
178 } elseif ($install->isUpgrade()) {
179 $install->atVersionSelection();
180 }
181 } elseif (isset($_POST['previous_version'])) {
182 $install->setInstalledVersion($_POST['previous_version']);
183 $install->atDbUpgradeStep();
184 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isInstall()) {
185 $install->atAdminStep();
186 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isUpgrade()) {
187 $install->atTelemetryStep();
188 } elseif (isset($_POST['install_adminlogin'])
189 && isset($_POST['install_adminpass'])
190 && $install->isInstall()
191 ) {
192 if ($_POST['install_adminlogin'] == '') {
193 $error_detected[] = _T("No user name");
194 }
195 if (strpos($_POST['install_adminlogin'], '@')) {
196 $error_detected[] = _T("The username cannot contain the @ character");
197 }
198 if ($_POST['install_adminpass'] == '') {
199 $error_detected[] = _T("No password");
200 }
201 if (!isset($_POST['install_passwdverified'])
202 && strcmp(
203 $_POST['install_adminpass'],
204 $_POST['install_adminpass_verif']
205 )
206 ) {
207 $error_detected[] = _T("Passwords mismatch");
208 }
209 if (count($error_detected) == 0) {
210 $install->setAdminInfos(
211 $_POST['install_adminlogin'],
212 $_POST['install_adminpass']
213 );
214 $install->atTelemetryStep();
215 }
216 } elseif (isset($_POST['install_telemetry_ok'])) {
217 if (isset($_POST['send_telemetry'])) {
218 $preferences = new Preferences($zdb);
219 $plugins = new Plugins();
220 $telemetry = new Telemetry(
221 $zdb,
222 $preferences,
223 $plugins
224 );
225 try {
226 $telemetry->send();
227 } catch (Throwable $e) {
228 Analog::log($e->getMessage(), Analog::ERROR);
229 }
230 }
231 $install->atGaletteInitStep();
232 } elseif (isset($_POST['install_prefs_ok'])) {
233 $install->atEndStep();
234 }
235
236 header('Content-Type: text/html; charset=UTF-8');
237 ?>
238 <!DOCTYPE html>
239 <html lang="<?php echo $i18n->getAbbrev(); ?>">
240 <head>
241 <title><?php echo _T("Galette Installation") . ' - ' . $install->getStepTitle(); ?></title>
242 <meta charset="UTF-8"/>
243 <meta name="viewport" content="width=device-width" />
244 <link rel="stylesheet" type="text/css" href="./themes/default/ui/semantic.min.css" />
245 <link rel="shortcut icon" href="./themes/default/images/favicon.png" />
246 <script type="text/javascript" src="./assets/js/jquery.min.js"></script>
247 </head>
248 <body class="pushable">
249 <header id="top-navbar" class="ui fixed menu bgcolor">
250 <div class="ui wide container">
251 <div class="header item">
252 <span><?php echo _T("Galette installation") ?></span>
253 </div>
254 <div class="language ui dropdown right item">
255 <i class="icon language" aria-hidden="true"></i>
256 <span><?php echo $i18n->getAbbrev(); ?></span>
257 <i class="icon dropdown" aria-hidden="true"></i>
258 <div class="menu">
259 <?php
260 foreach ($i18n->getList() as $langue) {
261 ?>
262 <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>
263 <?php
264 }
265 ?>
266 </div>
267 </div>
268 </div>
269 </header>
270 <div class="pusher">
271 <div id="main" class="ui wide container">
272 <div class="ui basic segment">
273 <div class="ui basic center aligned fitted segment">
274 <img class="icon" alt="[ Galette ]" src="./themes/default/images/galette.png"/>
275 </div>
276 <h1 class="ui block center aligned header">
277 <?php echo $install->getStepTitle(); ?>
278 </h1>
279 <?php
280 if (count($error_detected) > 0) {
281 ?>
282 <div id="errorbox" class="ui red message">
283 <h1><?php echo _T("- ERROR -"); ?></h1>
284 <ul>
285 <?php
286 foreach ($error_detected as $error) {
287 ?>
288 <li><?php echo $error; ?></li>
289 <?php
290 }
291 ?>
292 </ul>
293 </div>
294 <?php
295 }
296 ?>
297 <div class="ui mobile reversed stackable two column grid">
298 <div class="four wide column">
299 <div class="ui stackable mini vertical steps fluid">
300 <div class="step<?php if ($install->isCheckStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_CHECK)) echo ' disabled'; ?>">
301 <i class="tasks icon<?php if($install->isStepPassed(GaletteInstall::STEP_CHECK)) { echo ' green'; } ?>"></i>
302 <div class="content">
303 <div class="title"><?php echo _T("Checks"); ?></div>
304 </div>
305 </div>
306 <div class="step<?php if ($install->isTypeStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_TYPE)) echo ' disabled'; ?>">
307 <i class="question icon<?php if($install->isStepPassed(GaletteInstall::STEP_TYPE)) { echo ' green'; } ?>"></i>
308 <div class="content">
309 <div class="title"><?php echo _T("Installation mode"); ?></div>
310 </div>
311 </div>
312 <div class="step<?php if ($install->isDbStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_DB)) echo ' disabled'; ?>">
313 <i class="database icon<?php if($install->isStepPassed(GaletteInstall::STEP_DB)) { echo ' green'; } ?>"></i>
314 <div class="content">
315 <div class="title"><?php echo _T("Database"); ?></div>
316 </div>
317 </div>
318 <div class="step<?php if ($install->isDbCheckStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_DB_CHECKS)) echo ' disabled'; ?>">
319 <i class="key icon<?php if($install->isStepPassed(GaletteInstall::STEP_DB_CHECKS)) { echo ' green'; } ?>"></i>
320 <div class="content">
321 <div class="title"><?php echo _T("Database access and permissions"); ?></div>
322 </div>
323 </div>
324 <?php
325 if ($install->isUpgrade()) {
326 ?>
327 <div class="step<?php if ($install->isVersionSelectionStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_VERSION)) echo ' disabled'; ?>">
328 <i class="tag icon<?php if($install->isStepPassed(GaletteInstall::STEP_VERSION)) { echo ' green'; } ?>"></i>
329 <div class="content">
330 <div class="title"><?php echo _T("Version selection"); ?></div>
331 </div>
332 </div>
333 <div class="step<?php if ($install->isDbUpgradeStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_DB_UPGRADE)) echo ' disabled'; ?>">
334 <i class="sync alt icon<?php if($install->isStepPassed(GaletteInstall::STEP_DB_UPGRADE)) { echo ' green'; } ?>"></i>
335 <div class="content">
336 <div class="title"><?php echo _T("Database upgrade"); ?></div>
337 </div>
338 </div>
339 <?php
340 } else {
341 ?>
342 <div class="step<?php if ($install->isDbinstallStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_DB_INSTALL)) echo ' disabled'; ?>">
343 <i class="spinner icon<?php if($install->isStepPassed(GaletteInstall::STEP_DB_INSTALL)) { echo ' green'; } ?>"></i>
344 <div class="content">
345 <div class="title"><?php echo _T("Database installation"); ?></div>
346 </div>
347 </div>
348 <?php
349 }
350
351 if (!$install->isUpgrade()) {
352 ?>
353 <div class="step<?php if ($install->isAdminStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_ADMIN)) echo ' disabled'; ?>">
354 <i class="user icon<?php if($install->isStepPassed(GaletteInstall::STEP_ADMIN)) { echo ' green'; } ?>"></i>
355 <div class="content">
356 <div class="title"><?php echo _T("Admin parameters"); ?></div>
357 </div>
358 </div>
359 <?php
360 }
361 ?>
362 <div class="step<?php if ($install->isTelemetryStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_TELEMETRY)) echo ' disabled'; ?>">
363 <i class="chart bar icon<?php if($install->isStepPassed(GaletteInstall::STEP_TELEMETRY)) { echo ' green'; } ?>"></i>
364 <div class="content">
365 <div class="title"><?php echo _T("Telemetry"); ?></div>
366 </div>
367 </div>
368 <div class="step<?php if ($install->isGaletteInitStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_GALETTE_INIT)) echo ' disabled'; ?>">
369 <i class="cogs icon<?php if($install->isStepPassed(GaletteInstall::STEP_GALETTE_INIT)) { echo ' green'; } ?>"></i>
370 <div class="content">
371 <div class="title"><?php echo _T("Galette initialisation"); ?></div>
372 </div>
373 </div>
374 <div class="step<?php if ($install->isEndStep()) echo ' active'; elseif (!$install->isStepPassed(GaletteInstall::STEP_END)) echo ' disabled'; ?>">
375 <i class="flag checkered icon<?php if($install->isStepPassed(GaletteInstall::STEP_END)) { echo ' green'; } ?>"></i>
376 <div class="content">
377 <div class="title"><?php echo _T("End!"); ?></div>
378 </div>
379 </div>
380 </div>
381 </div>
382 <div class="twelve wide column">
383 <?php
384 if ($install->isCheckStep()) {
385 include_once __DIR__ . '/../install/steps/check.php';
386 } elseif ($install->isTypeStep()) {
387 include_once __DIR__ . '/../install/steps/type.php';
388 } elseif ($install->isDbStep()) {
389 include_once __DIR__ . '/../install/steps/db.php';
390 } elseif ($install->isDbCheckStep()) {
391 include_once __DIR__ . '/../install/steps/db_checks.php';
392 } elseif ($install->isVersionSelectionStep()) {
393 include_once __DIR__ . '/../install/steps/db_select_version.php';
394 } elseif ($install->isDbinstallStep() || $install->isDbUpgradeStep()) {
395 include_once __DIR__ . '/../install/steps/db_install.php';
396 } elseif ($install->isAdminStep()) {
397 include_once __DIR__ . '/../install/steps/admin.php';
398 } elseif ($install->isTelemetryStep()) {
399 include_once __DIR__ . '/../install/steps/telemetry.php';
400 } elseif ($install->isGaletteInitStep()) {
401 include_once __DIR__ . '/../install/steps/galette.php';
402 } elseif ($install->isEndStep()) {
403 include_once __DIR__ . '/../install/steps/end.php';
404 }
405 ?>
406 </div>
407 </div>
408 </div>
409 <footer class="ui basic center aligned segment">
410 <div class="row">
411 <nav class="ui horizontal bulleted link list">
412 <a href="https://galette.eu" class="item">
413 <i class="icon globe europe"></i>
414 <?php echo _T("Website"); ?>
415 </a>
416 <a href="https://doc.galette.eu" class="item">
417 <i class="icon book"></i>
418 <?php echo _T("Documentation"); ?>
419 </a>
420 <a href="https://framapiaf.org/@galette" class="item">
421 <i class="icon mastodon"></i>
422 @galette
423 </a>
424 </nav>
425 </div>
426 <div class="row">
427 <nav class="ui horizontal bulleted link list">
428 <a id="copyright" href="https://galette.eu/" class="item">
429 <i class="icon cookie bite"></i>
430 Galette <?php echo GALETTE_DISPLAY_VERSION; ?>
431 </a>
432 </nav>
433 </div>
434 </footer>
435 </div>
436 </div>
437 <script type="text/javascript" src="./assets/js/galette-main.bundle.min.js"></script>
438 <script type="text/javascript" src="./themes/default/ui/semantic.min.js"></script>
439 </body>
440 </html>
441 <?php
442 if (!$install->isEndStep()) {
443 $session[md5(GALETTE_ROOT)] = serialize($install);
444 }
445
446 if (isset($profiler)) {
447 $profiler->stop();
448 }
449 ?>