dolibarr 24.0.0-beta
step5.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5 * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
6 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
41define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
42include_once 'inc.php';
48if (file_exists($conffile)) {
49 include_once $conffile;
50}
68require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
69require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; // for dol_hash
70require_once $dolibarr_main_document_root.'/core/lib/functions2.lib.php';
71
72'
73@phan-var-force ?string $modulesdir
74@phan-var-force ?string $dolibarr_main_db_encryption
75@phan-var-force ?string $dolibarr_main_db_cryptkey
76';
77
78global $langs;
79
80$versionfrom = GETPOST("versionfrom", 'alpha', 3) ? GETPOST("versionfrom", 'alpha', 3) : (empty($argv[1]) ? '' : $argv[1]);
81$versionto = GETPOST("versionto", 'alpha', 3) ? GETPOST("versionto", 'alpha', 3) : (empty($argv[2]) ? '' : $argv[2]);
82$setuplang = GETPOST('selectlang', 'aZ09', 3) ? GETPOST('selectlang', 'aZ09', 3) : (empty($argv[3]) ? 'auto' : $argv[3]);
83$langs->setDefaultLang($setuplang);
84$action = GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : (empty($argv[4]) ? '' : $argv[4]);
85
86// Define targetversion used to update MAIN_VERSION_LAST_INSTALL for first install
87// or MAIN_VERSION_LAST_UPGRADE for upgrade.
88$targetversion = DOL_VERSION; // If it's latest upgrade
89if (!empty($action) && preg_match('/upgrade/i', $action)) {
90 // If it's an old upgrade
91 $tmp = explode('_', $action, 2);
92 if ($tmp[0] == 'upgrade') {
93 if (!empty($tmp[1])) {
94 $targetversion = $tmp[1]; // if $action = 'upgrade_6.0.0-beta', we use '6.0.0-beta'
95 } else {
96 $targetversion = DOL_VERSION; // if $action = 'upgrade', we use DOL_VERSION
97 }
98 }
99}
100
101$langs->loadLangs(array("admin", "install"));
102
103$login = GETPOST('login', 'alpha') ? GETPOST('login', 'alpha') : (empty($argv[5]) ? '' : $argv[5]);
104$pass = GETPOST('pass', 'password') ? GETPOST('pass', 'password') : (empty($argv[6]) ? '' : $argv[6]);
105$pass_verif = GETPOST('pass_verif', 'password') ? GETPOST('pass_verif', 'password') : (empty($argv[7]) ? '' : $argv[7]);
106
107$success = 0;
108
109$useforcedwizard = false;
110$forcedfile = "./install.forced.php";
111if ($conffile == "/etc/dolibarr/conf.php") {
112 $forcedfile = "/etc/dolibarr/install.forced.php";
113}
114if (@file_exists($forcedfile)) {
115 $useforcedwizard = true;
116 include_once $forcedfile;
138 '
139 @phan-var-force int $force_install_noedit
140 ';
141 // If forced install is enabled, replace post values. These are empty because form fields are disabled.
142 if ($force_install_noedit == 2) {
143 if (!empty($force_install_dolibarrlogin)) {
144 $login = $force_install_dolibarrlogin;
145 }
146 }
147}
148
149$force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (GETPOST('installlock', 'aZ09') ? GETPOST('installlock', 'aZ09') : (empty($argv[8]) ? '' : $argv[8])));
150
151
152// Case the password was in forced mode
153if (@$force_install_noedit == 2 && isset($force_install_dolibarrpassword)) {
154 $pass = $force_install_dolibarrpassword;
155 $pass_verif = $force_install_dolibarrpassword;
156}
157
158
159dolibarr_install_syslog("--- step5: entering step5.php page ".$versionfrom." ".$versionto);
160
161$error = 0;
162
163
164/*
165 * Actions
166 */
167
168// If install, check password and password_verification used to create admin account
169if ($action == "set") { // Test on permissions not required here
170 if ($pass != $pass_verif) {
171 header("Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
172 exit;
173 }
174
175 if (dol_strlen(trim($pass)) == 0) {
176 header("Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
177 exit;
178 }
179
180 if (dol_strlen(trim($login)) == 0) {
181 header("Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
182 exit;
183 }
184 if ($pass === '**********' || $pass_verif == '**********') {
185 header("Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
186 exit;
187 }
188}
189
190
191/*
192 * View
193 */
194
195$morehtml = '';
196
197pHeader($langs->trans("DolibarrSetup"), "step5", 'set', '', '', 'main-inside main-inside-borderbottom no-bottom');
198print '<br>';
199
200// Test if we can run a first install process
201if (empty($versionfrom) && empty($versionto) && !is_writable($conffile)) {
202 print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
203 pFooter(1, $setuplang, 'jscheckparam');
204 exit;
205}
206
207// Ensure $modulesdir is set and array
208if (!isset($modulesdir) || !is_array($modulesdir)) {
209 $modulesdir = array();
210}
211
212if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) {
213 $error = 0;
214
215 // If password is encoded, we decode it
216 if ((!empty($dolibarr_main_db_pass) && preg_match('/(crypted|dolcrypt):/i', (string) $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
217 require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
218 if (!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', (string) $dolibarr_main_db_pass)) {
219 $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', (string) $dolibarr_main_db_pass);
220 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
221 $dolibarr_main_db_pass = dol_decode((string) $dolibarr_main_db_pass);
222 } elseif (preg_match('/dolcrypt:/i', (string) $dolibarr_main_db_pass)) {
223 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially encrypted
224 $dolibarr_main_db_pass = dolDecrypt((string) $dolibarr_main_db_pass);
225 } else {
226 $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
227 }
228 }
229
230 $conf->db->type = $dolibarr_main_db_type;
231 $conf->db->host = $dolibarr_main_db_host;
232 $conf->db->port = $dolibarr_main_db_port;
233 $conf->db->name = $dolibarr_main_db_name;
234 $conf->db->user = $dolibarr_main_db_user;
235 $conf->db->pass = $dolibarr_main_db_pass;
236 $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption : 0;
237 $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey : '';
238
239 $db = getDoliDBInstance($conf->db->type, $conf->db->host, (string) $conf->db->user, (string) $conf->db->pass, $conf->db->name, (int) $conf->db->port);
240
241 // Create the global $hookmanager object
242 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
243 $hookmanager = new HookManager($db);
244
245 $ok = 0;
246
247 // If first install
248 if ($action == "set") {
249 // Active module user
250 $modName = 'modUser';
251 $file = $modName.".class.php";
252 dolibarr_install_syslog('step5: load module user '.DOL_DOCUMENT_ROOT."/core/modules/".$file, LOG_INFO);
253 include_once DOL_DOCUMENT_ROOT."/core/modules/".$file;
254 $objMod = new $modName($db);
255 $result = $objMod->init();
256 if (!$result) {
257 print "ERROR: failed to init module file = ".$file;
258 }
259
260 if ($db->connected) {
261 $conf->setValues($db);
262 // Reset forced setup after the setValues
263 if (defined('SYSLOG_FILE')) {
264 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
265 }
266 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
267
268 // Create admin user
269 include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
270
271 // Set default encryption to yes, generate a salt and set default encryption algorithm (but only if there is no user yet into database)
272 $sql = "SELECT u.rowid, u.pass, u.pass_crypted";
273 $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
274 $resql = $db->query($sql);
275 if ($resql) {
276 $numrows = $db->num_rows($resql);
277 if ($numrows == 0) {
278 // Define default setup for password encryption
279 // DATABASE_PWD_ENCRYPTED is shared across all entities (admin/security.php:75
280 // stores it with entity=0). Use entity 0 here too.
281 dolibarr_set_const($db, "DATABASE_PWD_ENCRYPTED", "1", 'chaine', 0, '', 0);
282
283 if (function_exists('password_hash')) {
284 dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'password_hash', 'chaine', 0, '', 0); // All entities
285 } else {
286 dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'sha1md5', 'chaine', 0, '', 0); // All entities
287 dolibarr_set_const($db, "MAIN_SECURITY_SALT", dol_print_date(dol_now(), 'dayhourlog'), 'chaine', 0, '', 0); // All entities
288 }
289 }
290
291 dolibarr_install_syslog('step5: DATABASE_PWD_ENCRYPTED = ' . getDolGlobalString('DATABASE_PWD_ENCRYPTED').' MAIN_SECURITY_HASH_ALGO = ' . getDolGlobalString('MAIN_SECURITY_HASH_ALGO'), LOG_INFO);
292 }
293
294 // Set some default variables
295 dolibarr_set_const($db, "PAYMENT_SECURITY_TOKEN", bin2hex(random_bytes(12)), 'chaine', 0, '', 0); // All entities
296
297
298 // Create user used to create the admin user
299 $createuser = new User($db);
300 $createuser->id = 0;
301 $createuser->admin = 1;
302
303 // Set admin user
304 $newuser = new User($db);
305 $newuser->lastname = 'SuperAdmin';
306 $newuser->firstname = '';
307 $newuser->ldap_sid = '';
308 $newuser->login = $login;
309 $newuser->pass = $pass;
310 $newuser->admin = 1;
311 $newuser->entity = 0;
312
313 $conf->global->USER_MAIL_REQUIRED = 0; // Force global option to be sure to create a new user with no email
314 $conf->global->USER_PASSWORD_GENERATED = ''; // To not use any rule for password validation
315
316 $result = $newuser->create($createuser, 1);
317 if ($result > 0) {
318 print $langs->trans("AdminLoginCreatedSuccessfuly", $login)."<br>";
319 $success = 1;
320 } else {
321 if ($result == -6) { //login or email already exists
322 dolibarr_install_syslog('step5: AdminLoginAlreadyExists', LOG_WARNING);
323 print '<br><div class="warning">'.$newuser->error."</div><br>";
324 $success = 1;
325 } else {
326 dolibarr_install_syslog('step5: FailedToCreateAdminLogin '.$newuser->error, LOG_ERR);
327 setEventMessages($langs->trans("FailedToCreateAdminLogin").' '.$newuser->error, null, 'errors');
328 //header("Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
329 print '<br><div class="error">'.$langs->trans("FailedToCreateAdminLogin").': '.$newuser->error.'</div><br><br>';
330 print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
331 }
332 }
333
334 if ($success) {
335 // Insert MAIN_VERSION_FIRST_INSTALL in a dedicated transaction. So if it fails (when first install was already done), we can do other following requests.
336 $db->begin();
337 dolibarr_install_syslog('step5: set MAIN_VERSION_FIRST_INSTALL const to '.$targetversion, LOG_DEBUG);
338 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name, value, type, visible, note, entity) values(".$db->encrypt('MAIN_VERSION_FIRST_INSTALL').", ".$db->encrypt($targetversion).", 'chaine', 0, 'Dolibarr version when first install', 0)");
339 if ($resql) {
340 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
341 $db->commit();
342 } else {
343 //if (! $resql) dol_print_error($db,'Error in setup program'); // We ignore errors. Key may already exists
344 $db->commit();
345 }
346
347 $db->begin();
348
349 dolibarr_install_syslog('step5: set MAIN_VERSION_LAST_INSTALL const to '.$targetversion, LOG_DEBUG);
350 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_VERSION_LAST_INSTALL'");
351 if (!$resql) {
352 dol_print_error($db, 'Error in setup program');
353 }
354 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_VERSION_LAST_INSTALL').", ".$db->encrypt($targetversion).", 'chaine', 0, 'Dolibarr version when last install', 0)");
355 if (!$resql) {
356 dol_print_error($db, 'Error in setup program');
357 }
358 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
359
360 if ($useforcedwizard) {
361 dolibarr_install_syslog('step5: set MAIN_REMOVE_INSTALL_WARNING const to 1', LOG_DEBUG);
362 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_REMOVE_INSTALL_WARNING'");
363 if (!$resql) {
364 dol_print_error($db, 'Error in setup program');
365 }
366 // The install.lock file is created few lines later if version is last one or if option MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE is on
367 /* No need to enable this
368 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) values(".$db->encrypt('MAIN_REMOVE_INSTALL_WARNING').", ".$db->encrypt(1).", 'chaine', 1, 'Disable install warnings', 0)");
369 if (!$resql) {
370 dol_print_error($db, 'Error in setup program');
371 }
372 $conf->global->MAIN_REMOVE_INSTALL_WARNING = 1;
373 */
374 }
375
376 // List of modules to enable
377 $tmparray = array();
378
379 // If we ask to force some modules to be enabled
380 if (!empty($force_install_module)) {
381 if (!defined('DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
382 define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
383 }
384
385 $tmparray = explode(',', $force_install_module);
386 }
387
388 $modNameLoaded = array();
389
390 // Search modules dirs
391 $modulesdir[] = $dolibarr_main_document_root.'/core/modules/';
392
393 foreach ($modulesdir as $dir) {
394 // Load modules attributes in arrays (name, numero, orders) from dir directory
395 //print $dir."\n<br>";
396 dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
397 $handle = @opendir($dir);
398 if (is_resource($handle)) {
399 while (($file = readdir($handle)) !== false) {
400 if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
401 $modName = substr($file, 0, dol_strlen($file) - 10);
402 if ($modName) {
403 if (!empty($modNameLoaded[$modName])) { // In cache of already loaded modules ?
404 $mesg = "Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.<br>";
405 setEventMessages($mesg, null, 'warnings');
406 dol_syslog($mesg, LOG_ERR);
407 continue;
408 }
409
410 try {
411 $res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
412 if (class_exists($modName)) {
413 $objMod = new $modName($db);
414 $modNameLoaded[$modName] = $dir;
415 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
416 $tmparray[] = $file;
417 }
418 }
419 } catch (Exception $e) {
420 dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
421 }
422 }
423 }
424 }
425 }
426 }
427
428 // Loop on each modules to activate it
429 if (!empty($tmparray)) {
430 foreach ($tmparray as $modtoactivate) {
431 $modtoactivatenew = preg_replace('/\.class\.php$/i', '', $modtoactivate);
432 //print $langs->trans("ActivateModule", $modtoactivatenew).'<br>';
433
434 $file = $modtoactivatenew.'.class.php';
435 dolibarr_install_syslog('step5: activate module file='.$file);
436 $res = dol_include_once("/core/modules/".$file);
437
438 $res = activateModule($modtoactivatenew, 1);
439 if (!empty($res['errors'])) {
440 print 'ERROR: failed to activateModule() file='.$file;
441 }
442 }
443 //print '<br>';
444 }
445
446 // Now delete the flag that say installation is not complete
447 dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const');
448 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_NOT_INSTALLED'");
449 if (!$resql) {
450 dol_print_error($db, 'Error in setup program');
451 }
452
453 // May fail if parameter already defined
454 dolibarr_install_syslog('step5: set the default language');
455 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name,value,type,visible,note,entity) VALUES (".$db->encrypt('MAIN_LANG_DEFAULT').", ".$db->encrypt($setuplang).", 'chaine', 0, 'Default language', 1)");
456 //if (! $resql) dol_print_error($db,'Error in setup program');
457
458 $db->commit();
459 }
460 } else {
461 print $langs->trans("ErrorFailedToConnect")."<br>";
462 }
463 } elseif (empty($action) || preg_match('/upgrade/i', $action)) {
464 // If upgrade
465 if ($db->connected) {
466 $conf->setValues($db);
467 // Reset forced setup after the setValues
468 if (defined('SYSLOG_FILE')) {
469 $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
470 }
471 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
472
473 // Define if we need to update the MAIN_VERSION_LAST_UPGRADE value in database
474 $tagdatabase = false;
475 if (!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE')) {
476 $tagdatabase = true; // We don't know what it was before, so now we consider we at the chosen version.
477 } else {
478 $mainversionlastupgradearray = preg_split('/[.-]/', $conf->global->MAIN_VERSION_LAST_UPGRADE);
479 $targetversionarray = preg_split('/[.-]/', $targetversion);
480 if (versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
481 $tagdatabase = true;
482 }
483 }
484
485 if ($tagdatabase) {
486 dolibarr_install_syslog('step5: set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion);
487 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_VERSION_LAST_UPGRADE'");
488 if (!$resql) {
489 dol_print_error($db, 'Error in setup program');
490 }
491 $resql = $db->query("INSERT INTO ".MAIN_DB_PREFIX."const(name, value, type, visible, note, entity) VALUES (".$db->encrypt('MAIN_VERSION_LAST_UPGRADE').", ".$db->encrypt($targetversion).", 'chaine', 0, 'Dolibarr version for last upgrade', 0)");
492 if (!$resql) {
493 dol_print_error($db, 'Error in setup program');
494 }
495 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
496 } else {
497 dolibarr_install_syslog('step5: we run an upgrade to version '.$targetversion.' but database was already upgraded to ' . getDolGlobalString('MAIN_VERSION_LAST_UPGRADE').'. We keep MAIN_VERSION_LAST_UPGRADE as it is.');
498
499 // Force the delete of the flag that say installation is not complete
500 dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)');
501 $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_NOT_INSTALLED'");
502 if (!$resql) {
503 dol_print_error($db, 'Error in setup program');
504 }
505 }
506 } else {
507 print $langs->trans("ErrorFailedToConnect")."<br>";
508 }
509 } else {
510 dol_print_error(null, 'step5.php: unknown choice of action');
511 }
512
513 $db->close();
514}
515
516
517
518// Create lock file
519
520// If first install
521if ($action == "set") {
522 if ($success) {
523 if (!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || (getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') == DOL_VERSION)) {
524 // Install is finished (database is on same version than files)
525 print '<br>'.$langs->trans("SystemIsInstalled")."<br>";
526
527 // Create install.lock file
528 // No need for the moment to create it automatically, creation by web assistant means permissions are given
529 // to the web user, it is better to show a warning to say to create it manually with correct user/permission (not erasable by a web process)
530 $createlock = 0;
531 if (!empty($force_install_lockinstall) || getDolGlobalString('MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
532 // Install is finished, we create the "install.lock" file, so install won't be possible anymore.
533 // TODO Upgrade will be still be possible if a file "upgrade.unlock" is present
534 $lockfile = DOL_DATA_ROOT.'/install.lock';
535 $fp = @fopen($lockfile, "w");
536 if ($fp) {
537 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
538 $force_install_lockinstall = '444'; // For backward compatibility
539 }
540 fwrite($fp, "This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.")");
541 fclose($fp);
542 dolChmod($lockfile, $force_install_lockinstall);
543
544 $createlock = 1;
545 }
546 }
547 if (empty($createlock)) {
548 print '<div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
549 }
550
551 print "<br>";
552
553 print '<span class="opacitymedium">'.$langs->trans("YouNeedToPersonalizeSetup")."</span><br><br><br>";
554
555 print '<div class="center divlinktogotosetup"><a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ? '&username='.urlencode($login) : '').'">';
556 print '<span class="fas fa-external-link-alt"></span> '.$langs->trans("GoToSetupArea");
557 print '</a></div><br><br>';
558 } else {
559 // If here MAIN_VERSION_LAST_UPGRADE is not empty
560 print $langs->trans("VersionLastUpgrade").': <b><span class="ok">' . getDolGlobalString('MAIN_VERSION_LAST_UPGRADE').'</span></b><br>';
561 print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b><br>';
562 print $langs->trans("MigrationNotFinished").'<br>';
563 print "<br>";
564
565 print '<div class="center"><a href="'.$dolibarr_main_url_root.'/install/index.php">';
566 print '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToUpgradePage");
567 print '</a>';
568 print '</div>';
569 }
570 }
571} elseif (empty($action) || preg_match('/upgrade/i', $action)) {
572 // If upgrade
573 if (!getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') || getDolGlobalString('MAIN_VERSION_LAST_UPGRADE') == DOL_VERSION) {
574 // Upgrade is finished (database is on the same version than files)
575 print '<img class="valignmiddle inline-block paddingright" src="../public/theme/common/checklist.svg" width="30" alt="Configuration">';
576 print ' <span class="valignmiddle">'.$langs->trans("SystemIsUpgraded")."</span><br>";
577
578 // Create install.lock file if it does not exists.
579 // Note: it should always exists. A better solution to allow upgrade will be to add an upgrade.unlock file
580 $createlock = 0;
581 if (!empty($force_install_lockinstall) || getDolGlobalString('MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
582 // Upgrade is finished, we modify the lock file
583 $lockfile = DOL_DATA_ROOT.'/install.lock';
584 $fp = @fopen($lockfile, "w");
585 if ($fp) {
586 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
587 $force_install_lockinstall = '444'; // For backward compatibility
588 }
589 fwrite($fp, "This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.")");
590 fclose($fp);
591 dolChmod($lockfile, $force_install_lockinstall);
592
593 $createlock = 1;
594 }
595 }
596 if (empty($createlock)) {
597 print '<br><div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
598 }
599
600 // Delete the upgrade.unlock file it it exists
601 $unlockupgradefile = DOL_DATA_ROOT.'/upgrade.unlock';
602 dol_delete_file($unlockupgradefile, 0, 0, 0, null, false, 0);
603
604 print "<br>";
605
606 $morehtml = '<br><div class="center"><a class="buttonGoToupgrade" href="../index.php?mainmenu=home'.(isset($login) ? '&username='.urlencode($login) : '').'">';
607 $morehtml .= '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToDolibarr").'...';
608 $morehtml .= '</a></div><br>';
609 } else {
610 // If here MAIN_VERSION_LAST_UPGRADE is not empty
611 print $langs->trans("VersionLastUpgrade").': <b><span class="okinversed">' . getDolGlobalString('MAIN_VERSION_LAST_UPGRADE').'</span></b><br>';
612 print '<br>';
613 print $langs->trans("VersionProgram").': <b><span class="okinversed">'.DOL_VERSION.'</span></b>';
614
615 print "<br><br>";
616
617 $morehtml = '<br><div class="center"><a class="buttonGoToupgrade" href="../install/index.php">';
618 $morehtml .= '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToUpgradePage");
619 $morehtml .= '</a></div>';
620 }
621} else {
622 dol_print_error(null, 'step5.php: unknown choice of action='.$action.' in create lock file seaction');
623}
624
625// Clear cache files
626clearstatcache();
627
628$ret = 0;
629if ($error && isset($argv[1])) {
630 $ret = 1;
631}
632dolibarr_install_syslog("Exit ".$ret);
633
634dolibarr_install_syslog("--- step5: Dolibarr setup finished");
635
636pFooter(1, $setuplang, '', 0, $morehtml);
637
638// Return code if ran from command line
639if ($ret) {
640 exit($ret);
641}
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays), to know if a version (a,b,c) is lower than (x,...
Definition admin.lib.php:72
Class to manage hooks.
Class to manage Dolibarr users.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$conffile
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dolChmod($filepath, $newmask='')
Change mod of a file.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getDoliDBInstance($type, $host, $user, $pass, $name, $port)
Return a DoliDB instance (database handler).
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition inc.php:541
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition inc.php:635
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition inc.php:699
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.