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