]> git.agnieray.net Git - galette.git/blob - galette/webroot/installer.php
4e9287e4892576f384faf82a5ef91db897025cec
[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 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.8
36 */
37
38 use Galette\Core\Install as GaletteInstall;
39 use Galette\Core\Db as GaletteDb;
40 use Analog\Analog;
41 use Analog\Handler;
42 use Analog\Handler\LevelName;
43
44 //set a flag saying we work from installer
45 //that way, in galette.inc.php, we'll only include relevant parts
46 $installer = true;
47 define('GALETTE_ROOT', __DIR__ . '/../');
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 define('GALETTE_THEME_DIR', './themes/default/');
62
63 require_once '../includes/galette.inc.php';
64
65 session_start();
66 $session_name = 'galette_install_' . str_replace('.', '_', GALETTE_VERSION);
67 $session = &$_SESSION['galette'][$session_name];
68
69 $app = new \Slim\App(
70 array(
71 'templates.path' => GALETTE_ROOT . 'templates/default/',
72 'mode' => 'INSTALL'
73 )
74 );
75 require_once '../includes/dependencies.php';
76
77 if (isset($_POST['abort_btn'])) {
78 if (isset($session[md5(GALETTE_ROOT)])) {
79 unset($session[md5(GALETTE_ROOT)]);
80 }
81 header('location: ' . GALETTE_BASE_PATH);
82 }
83
84 $install = null;
85 if (isset($session[md5(GALETTE_ROOT)]) && !isset($_GET['raz'])) {
86 $install = unserialize($session[md5(GALETTE_ROOT)]);
87 } else {
88 $install = new GaletteInstall();
89 }
90
91 $error_detected = array();
92
93 /**
94 * Initialize database constants to connect
95 *
96 * @param Install $install Installer
97 *
98 * @return void
99 */
100 function initDbConstants($install)
101 {
102 define('TYPE_DB', $install->getDbType());
103 define('PREFIX_DB', $install->getTablesPrefix());
104 define('USER_DB', $install->getDbUser());
105 define('PWD_DB', $install->getDbPass());
106 define('HOST_DB', $install->getDbHost());
107 define('PORT_DB', $install->getDbPort());
108 define('NAME_DB', $install->getDbName());
109 }
110
111 if ($install->isStepPassed(GaletteInstall::STEP_TYPE)) {
112 define('GALETTE_LOGGER_CHECKED', true);
113
114 $now = new \DateTime();
115 $dbg_log_path = GALETTE_LOGS_PATH . 'galette_debug_' .
116 $now->format('Y-m-d') . '.log';
117 $galette_debug_log = LevelName::init(Handler\File::init($dbg_log_path));
118
119 if (defined('GALETTE_SYS_LOG') && GALETTE_SYS_LOG === true) {
120 //logs everything in PHP logs (per chance /var/log/http/error_log or /var/log/php-fpm/error.log)
121 $galette_run_log = \Analog\Handler\Syslog::init('galette', 'user');
122 } else {
123 $logfile = 'galette_install';
124 $log_path = GALETTE_LOGS_PATH . $logfile . '.log';
125 $galette_run_log = LevelName::init(Handler\File::init($log_path));
126 }
127
128 Analog::handler(
129 Handler\Multi::init(
130 array(
131 Analog::NOTICE => Handler\Threshold::init(
132 $galette_run_log,
133 GALETTE_LOG_LVL
134 ),
135 Analog::DEBUG => $galette_debug_log
136 )
137 )
138 );
139 }
140
141 if (isset($_POST['stepback_btn'])) {
142 $install->atPreviousStep();
143 } elseif (isset($_POST['install_permsok']) && $_POST['install_permsok'] == 1) {
144 $install->atTypeStep();
145 } elseif (isset($_POST['install_type'])) {
146 $install->setMode($_POST['install_type']);
147 $install->atDbStep();
148 } elseif (isset($_POST['install_dbtype'])) {
149 $install->setDbType($_POST['install_dbtype'], $error_detected);
150
151 if (empty($_POST['install_dbhost'])) {
152 $error_detected[] = _T("No host");
153 }
154 if (empty($_POST['install_dbport'])) {
155 $error_detected[] = _T("No port");
156 }
157 if (empty($_POST['install_dbuser'])) {
158 $error_detected[] = _T("No user name");
159 }
160 if (empty($_POST['install_dbpass'])) {
161 $error_detected[] = _T("No password");
162 }
163 if (empty($_POST['install_dbname'])) {
164 $error_detected[] = _T("No database name");
165 }
166
167 if (count($error_detected) == 0) {
168 $install->setDsn(
169 $_POST['install_dbhost'],
170 $_POST['install_dbport'],
171 $_POST['install_dbname'],
172 $_POST['install_dbuser'],
173 $_POST['install_dbpass']
174 );
175 $install->setTablesPrefix(
176 $_POST['install_dbprefix']
177 );
178 $install->atDbCheckStep();
179 }
180 } elseif (isset($_POST['install_dbperms_ok'])) {
181 if ($install->isInstall()) {
182 $install->atDbInstallStep();
183 } elseif ($install->isUpgrade()) {
184 $install->atVersionSelection();
185 }
186 } elseif (isset($_POST['previous_version'])) {
187 $install->setInstalledVersion($_POST['previous_version']);
188 $install->atDbUpgradeStep();
189 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isInstall()) {
190 $install->atAdminStep();
191 } elseif (isset($_POST['install_dbwrite_ok']) && $install->isUpgrade()) {
192 $install->atGaletteInitStep();
193 } elseif (isset($_POST['install_adminlogin'])
194 && isset($_POST['install_adminpass'])
195 && $install->isInstall()
196 ) {
197 if ($_POST['install_adminlogin'] == '') {
198 $error_detected[] = _T("No user name");
199 }
200 if (strpos($_POST['install_adminlogin'], '@') != false) {
201 $error_detected[] = _T("The username cannot contain the @ character");
202 }
203 if ($_POST['install_adminpass'] == '') {
204 $error_detected[] = _T("No password");
205 }
206 if (!isset($_POST['install_passwdverified'])
207 && strcmp(
208 $_POST['install_adminpass'],
209 $_POST['install_adminpass_verif']
210 )
211 ) {
212 $error_detected[] = _T("Passwords mismatch");
213 }
214 if (count($error_detected) == 0) {
215 $install->setAdminInfos(
216 $_POST['install_adminlogin'],
217 $_POST['install_adminpass']
218 );
219 $install->atGaletteInitStep();
220 }
221 } elseif (isset($_POST['install_prefs_ok'])) {
222 $install->atEndStep();
223 }
224
225 if (!$install->isEndStep()
226 && ($install->postCheckDb() || $install->isDbCheckStep())
227 ) {
228 //if we have passed database configuration, define required constants
229 initDbConstants($install);
230
231 if ($install->postCheckDb()) {
232 //while before check db, connection is not checked
233 $zdb = new GaletteDb();
234 }
235 }
236
237 header('Content-Type: text/html; charset=UTF-8');
238 ?>
239 <!DOCTYPE html>
240 <html lang="<?php echo $i18n->getAbbrev(); ?>">
241 <head>
242 <title><?php echo _T("Galette Installation") . ' - ' . $install->getStepTitle(); ?></title>
243 <meta charset="UTF-8"/>
244 <link rel="stylesheet" type="text/css" href="./assets/css/galette-main.bundle.min.css" />
245 <link rel="stylesheet" type="text/css" href="./themes/default/install.css"/>
246 <script type="text/javascript" src="./assets/js/galette-main.bundle.min.js"></script>
247 <link rel="shortcut icon" href="./themes/default/images/favicon.png" />
248 </head>
249 <body>
250 <section>
251 <header>
252 <h1 id="titre">
253 <?php echo _T("Galette installation") . ' - ' . $install->getStepTitle(); ?>
254 </h1>
255 <nav id="plang_selector" class="onhover">
256 <a href="#plang_selector" class="tooltip" aria-expanded="false" aria-controls="lang_selector" title="<?php echo _T("Change language"); ?>">
257 <i class="fas fa-language"></i>
258 <?php echo $i18n->getName(); ?>
259 </a>
260 <ul id="lang_selector">
261 <?php
262 foreach ($i18n->getList() as $langue) {
263 ?>
264 <li <?php if ($i18n->getAbbrev() == $langue->getAbbrev()) { echo ' selected="selected"'; } ?>>
265 <a href="?ui_pref_lang=<?php echo $langue->getID(); ?>" lang="<?php echo $langue->getAbbrev(); ?>"><?php echo $langue->getName(); ?></a>
266 </li>
267 <?php
268 }
269 ?>
270 </ul>
271 </nav>
272 </header>
273 <?php
274 if (count($error_detected) > 0) {
275 ?>
276 <div id="errorbox">
277 <h1><?php echo _T("- ERROR -"); ?></h1>
278 <ul>
279 <?php
280 foreach ($error_detected as $error) {
281 ?>
282 <li><?php echo $error; ?></li>
283 <?php
284 }
285 ?>
286 </ul>
287 </div>
288 <?php
289 }
290 ?>
291 <div>
292 <?php
293 if ($install->isCheckStep()) {
294 include_once __DIR__ . '/../install/steps/check.php';
295 } elseif ($install->isTypeStep()) {
296 include_once __DIR__ . '/../install/steps/type.php';
297 } elseif ($install->isDbStep()) {
298 include_once __DIR__ . '/../install/steps/db.php';
299 } elseif ($install->isDbCheckStep()) {
300 include_once __DIR__ . '/../install/steps/db_checks.php';
301 } elseif ($install->isVersionSelectionStep()) {
302 include_once __DIR__ . '/../install/steps/db_select_version.php';
303 } elseif ($install->isDbinstallStep() || $install->isDbUpgradeStep()) {
304 include_once __DIR__ . '/../install/steps/db_install.php';
305 } elseif ($install->isAdminStep()) {
306 include_once __DIR__ . '/../install/steps/admin.php';
307 } elseif ($install->isGaletteInitStep()) {
308 include_once __DIR__ . '/../install/steps/galette.php';
309 } elseif ($install->isEndStep()) {
310 include_once __DIR__ . '/../install/steps/end.php';
311 }
312 ?>
313 </div>
314 <footer>
315 <p><?php echo _T("Steps:"); ?></p>
316 <ol>
317 <li<?php if ($install->isCheckStep()) echo ' class="current"'; ?>><?php echo _T("Checks"); ?> - </li>
318 <li<?php if ($install->isTypeStep()) echo ' class="current"'; ?>><?php echo _T("Installation mode"); ?> - </li>
319 <li<?php if ($install->isDbStep()) echo ' class="current"'; ?>><?php echo _T("Database"); ?> - </li>
320 <li<?php if ($install->isDbCheckStep()) echo ' class="current"'; ?>><?php echo _T("Database access/permissions"); ?> - </li>
321 <?php
322 if ($install->isUpgrade()) {
323 ?>
324 <li<?php if ($install->isVersionSelectionStep()) echo ' class="current"'; ?>><?php echo _T("Version selection"); ?> - </li>
325 <li<?php if ($install->isDbUpgradeStep()) echo ' class="current"'; ?>><?php echo _T("Database upgrade"); ?> - </li>
326 <?php
327 } else {
328 ?>
329 <li<?php if ($install->isDbinstallStep()) echo ' class="current"'; ?>><?php echo _T("Database installation"); ?> - </li>
330 <?php
331 }
332
333 if (!$install->isUpgrade()) {
334 ?>
335 <li<?php if ($install->isAdminStep()) echo ' class="current"'; ?>><?php echo _T("Admin parameters"); ?> - </li>
336 <?php
337 }
338 ?>
339 <li<?php if ($install->isGaletteInitStep()) echo ' class="current"'; ?>><?php echo _T("Galette initialisation"); ?> - </li>
340 <li<?php if ($install->isEndStep()) echo ' class="current"'; ?>><?php echo _T("End!"); ?></li>
341 </ol>
342 </footer>
343 </section>
344 <a id="copyright" href="http://galette.eu/">Galette <?php echo GALETTE_VERSION; ?></a>
345 </body>
346 </html>
347 <?php
348 if (!$install->isEndStep()) {
349 $session[md5(GALETTE_ROOT)] = serialize($install);
350 }
351
352 if (isset($profiler)) {
353 $profiler->stop();
354 }
355 ?>