]>
git.agnieray.net Git - galette.git/blob - galette/webroot/installer.php
4e9287e4892576f384faf82a5ef91db897025cec
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Main Galette initialisation
10 * Copyright © 2013-2014 The Galette Team
12 * This file is part of Galette (http://galette.eu).
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.
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.
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/>.
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
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.8
38 use Galette\Core\Install
as GaletteInstall
;
39 use Galette\Core\Db
as GaletteDb
;
42 use Analog\Handler\LevelName
;
44 //set a flag saying we work from installer
45 //that way, in galette.inc.php, we'll only include relevant parts
47 define('GALETTE_ROOT', __DIR__
. '/../');
50 require_once GALETTE_ROOT
. '/vendor/autoload.php';
51 require_once GALETTE_ROOT
. 'config/versions.inc.php';
53 if (version_compare(PHP_VERSION
, GALETTE_PHP_MIN
, '<') ||
!extension_loaded('intl')) {
54 header('location: compat_test.php');
58 //specific logfile for installer
59 $logfile = 'galette_install';
60 define('GALETTE_BASE_PATH', '../');
61 define('GALETTE_THEME_DIR', './themes/default/');
63 require_once '../includes/galette.inc.php';
66 $session_name = 'galette_install_' . str_replace('.', '_', GALETTE_VERSION
);
67 $session = &$_SESSION['galette'][$session_name];
71 'templates.path' => GALETTE_ROOT
. 'templates/default/',
75 require_once '../includes/dependencies.php';
77 if (isset($_POST['abort_btn'])) {
78 if (isset($session[md5(GALETTE_ROOT
)])) {
79 unset($session[md5(GALETTE_ROOT
)]);
81 header('location: ' . GALETTE_BASE_PATH
);
85 if (isset($session[md5(GALETTE_ROOT
)]) && !isset($_GET['raz'])) {
86 $install = unserialize($session[md5(GALETTE_ROOT
)]);
88 $install = new GaletteInstall();
91 $error_detected = array();
94 * Initialize database constants to connect
96 * @param Install $install Installer
100 function initDbConstants($install)
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());
111 if ($install->isStepPassed(GaletteInstall
::STEP_TYPE
)) {
112 define('GALETTE_LOGGER_CHECKED', true);
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));
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');
123 $logfile = 'galette_install';
124 $log_path = GALETTE_LOGS_PATH
. $logfile . '.log';
125 $galette_run_log = LevelName
::init(Handler\File
::init($log_path));
131 Analog
::NOTICE
=> Handler\Threshold
::init(
135 Analog
::DEBUG
=> $galette_debug_log
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);
151 if (empty($_POST['install_dbhost'])) {
152 $error_detected[] = _T("No host");
154 if (empty($_POST['install_dbport'])) {
155 $error_detected[] = _T("No port");
157 if (empty($_POST['install_dbuser'])) {
158 $error_detected[] = _T("No user name");
160 if (empty($_POST['install_dbpass'])) {
161 $error_detected[] = _T("No password");
163 if (empty($_POST['install_dbname'])) {
164 $error_detected[] = _T("No database name");
167 if (count($error_detected) == 0) {
169 $_POST['install_dbhost'],
170 $_POST['install_dbport'],
171 $_POST['install_dbname'],
172 $_POST['install_dbuser'],
173 $_POST['install_dbpass']
175 $install->setTablesPrefix(
176 $_POST['install_dbprefix']
178 $install->atDbCheckStep();
180 } elseif (isset($_POST['install_dbperms_ok'])) {
181 if ($install->isInstall()) {
182 $install->atDbInstallStep();
183 } elseif ($install->isUpgrade()) {
184 $install->atVersionSelection();
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()
197 if ($_POST['install_adminlogin'] == '') {
198 $error_detected[] = _T("No user name");
200 if (strpos($_POST['install_adminlogin'], '@') != false) {
201 $error_detected[] = _T("The username cannot contain the @ character");
203 if ($_POST['install_adminpass'] == '') {
204 $error_detected[] = _T("No password");
206 if (!isset($_POST['install_passwdverified'])
208 $_POST['install_adminpass'],
209 $_POST['install_adminpass_verif']
212 $error_detected[] = _T("Passwords mismatch");
214 if (count($error_detected) == 0) {
215 $install->setAdminInfos(
216 $_POST['install_adminlogin'],
217 $_POST['install_adminpass']
219 $install->atGaletteInitStep();
221 } elseif (isset($_POST['install_prefs_ok'])) {
222 $install->atEndStep();
225 if (!$install->isEndStep()
226 && ($install->postCheckDb() ||
$install->isDbCheckStep())
228 //if we have passed database configuration, define required constants
229 initDbConstants($install);
231 if ($install->postCheckDb()) {
232 //while before check db, connection is not checked
233 $zdb = new GaletteDb();
237 header('Content-Type: text/html; charset=UTF-8');
240 <html lang
="<?php echo $i18n->getAbbrev(); ?>">
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" />
253 <?php
echo _T("Galette installation") . ' - ' . $install->getStepTitle(); ?
>
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(); ?
>
260 <ul id
="lang_selector">
262 foreach ($i18n->getList() as $langue) {
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
>
274 if (count($error_detected) > 0) {
277 <h1
><?php
echo _T("- ERROR -"); ?
></h1
>
280 foreach ($error_detected as $error) {
282 <li
><?php
echo $error; ?
></li
>
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';
315 <p
><?php
echo _T("Steps:"); ?
></p
>
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
>
322 if ($install->isUpgrade()) {
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
>
329 <li
<?php
if ($install->isDbinstallStep()) echo ' class="current"'; ?
>><?php
echo _T("Database installation"); ?
> - </li
>
333 if (!$install->isUpgrade()) {
335 <li
<?php
if ($install->isAdminStep()) echo ' class="current"'; ?
>><?php
echo _T("Admin parameters"); ?
> - </li
>
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
>
344 <a id
="copyright" href
="http://galette.eu/">Galette
<?php
echo GALETTE_VERSION
; ?
></a
>
348 if (!$install->isEndStep()) {
349 $session[md5(GALETTE_ROOT
)] = serialize($install);
352 if (isset($profiler)) {