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