2004-10-20 00:24:10 +02:00
< ? php
2015-07-06 15:29:58 +02:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2017-05-23 15:13:52 +02:00
* Copyright ( C ) 2004 - 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2015-07-06 15:29:58 +02:00
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
* Copyright ( C ) 2004 Sebastien DiCintio < sdicintio @ ressource - toi . org >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2016-02-22 18:45:00 +01:00
* Copyright ( C ) 2015 - 2016 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2025-02-03 14:28:54 +01:00
* Copyright ( C ) 2025 MDW < mdeweerd @ users . noreply . github . com >
2004-02-05 00:11:46 +01:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2004-02-05 00:11:46 +01:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2004-02-05 00:11:46 +01:00
*/
2005-01-08 12:40:21 +01:00
2005-06-11 13:35:58 +02:00
/**
2015-07-06 15:29:58 +02:00
* \file htdocs / install / step5 . php
* \ingroup install
2018-07-07 23:50:41 +02:00
* \brief Last page of upgrade / install process
2023-02-02 12:58:12 +01:00
*
* This page is called with parameter action = set by step4 . php or action = upgrade by upgrade2 . php
* For installation :
* It creates the login admin and set the MAIN_SECURITY_SALT to a random value .
* It set the value for MAIN_VERSION_LAST_INSTALL
2023-02-09 00:47:33 +01:00
* It activates some modules
2023-02-02 12:58:12 +01:00
* It creates the install . lock and shows the final message .
* For upgrade :
* It updates the value for MAIN_VERSION_LAST_UPGRADE .
* It ( re ) creates the install . lock and shows the final message .
2009-08-04 15:28:22 +02:00
*/
2005-01-08 12:40:21 +01:00
2023-02-02 12:58:12 +01:00
define ( 'ALLOWED_IF_UPGRADE_UNLOCK_FOUND' , 1 );
2012-08-23 02:46:16 +02:00
include_once 'inc.php' ;
2021-02-22 15:18:01 +01:00
if ( file_exists ( $conffile )) {
include_once $conffile ;
}
2020-04-10 10:59:32 +02:00
require_once $dolibarr_main_document_root . '/core/lib/admin.lib.php' ;
require_once $dolibarr_main_document_root . '/core/lib/security.lib.php' ; // for dol_hash
2023-02-09 00:47:33 +01:00
require_once $dolibarr_main_document_root . '/core/lib/functions2.lib.php' ;
2005-02-12 22:25:39 +01:00
2025-02-03 14:28:54 +01:00
'
@ phan - var - force ? string $modulesdir
@ phan - var - force ? string $dolibarr_main_db_encryption
@ phan - var - force ? string $dolibarr_main_db_cryptkey
' ;
2016-02-22 18:45:00 +01:00
global $langs ;
2008-04-19 23:52:14 +02:00
2023-12-04 12:36:19 +01:00
$versionfrom = GETPOST ( " versionfrom " , 'alpha' , 3 ) ? GETPOST ( " versionfrom " , 'alpha' , 3 ) : ( empty ( $argv [ 1 ]) ? '' : $argv [ 1 ]);
$versionto = GETPOST ( " versionto " , 'alpha' , 3 ) ? GETPOST ( " versionto " , 'alpha' , 3 ) : ( empty ( $argv [ 2 ]) ? '' : $argv [ 2 ]);
$setuplang = GETPOST ( 'selectlang' , 'aZ09' , 3 ) ? GETPOST ( 'selectlang' , 'aZ09' , 3 ) : ( empty ( $argv [ 3 ]) ? 'auto' : $argv [ 3 ]);
2018-04-12 19:13:06 +02:00
$langs -> setDefaultLang ( $setuplang );
2023-12-04 12:36:19 +01:00
$action = GETPOST ( 'action' , 'alpha' ) ? GETPOST ( 'action' , 'alpha' ) : ( empty ( $argv [ 4 ]) ? '' : $argv [ 4 ]);
2005-10-30 02:07:00 +01:00
2009-08-14 02:30:43 +02:00
// Define targetversion used to update MAIN_VERSION_LAST_INSTALL for first install
// or MAIN_VERSION_LAST_UPGRADE for upgrade.
2020-04-10 10:59:32 +02:00
$targetversion = DOL_VERSION ; // If it's latest upgrade
2021-02-22 15:18:01 +01:00
if ( ! empty ( $action ) && preg_match ( '/upgrade/i' , $action )) {
// If it's an old upgrade
2020-04-10 10:59:32 +02:00
$tmp = explode ( '_' , $action , 2 );
2021-02-22 15:18:01 +01:00
if ( $tmp [ 0 ] == 'upgrade' ) {
if ( ! empty ( $tmp [ 1 ])) {
$targetversion = $tmp [ 1 ]; // if $action = 'upgrade_6.0.0-beta', we use '6.0.0-beta'
} else {
$targetversion = DOL_VERSION ; // if $action = 'upgrade', we use DOL_VERSION
}
2020-03-23 15:54:02 +01:00
}
2009-08-14 02:30:43 +02:00
}
2009-08-10 14:54:37 +02:00
2018-10-01 08:22:23 +02:00
$langs -> loadLangs ( array ( " admin " , " install " ));
2005-02-12 22:25:39 +01:00
2023-12-04 12:36:19 +01:00
$login = GETPOST ( 'login' , 'alpha' ) ? GETPOST ( 'login' , 'alpha' ) : ( empty ( $argv [ 5 ]) ? '' : $argv [ 5 ]);
$pass = GETPOST ( 'pass' , 'alpha' ) ? GETPOST ( 'pass' , 'alpha' ) : ( empty ( $argv [ 6 ]) ? '' : $argv [ 6 ]);
$pass_verif = GETPOST ( 'pass_verif' , 'alpha' ) ? GETPOST ( 'pass_verif' , 'alpha' ) : ( empty ( $argv [ 7 ]) ? '' : $argv [ 7 ]);
$force_install_lockinstall = ( int ) ( ! empty ( $force_install_lockinstall ) ? $force_install_lockinstall : ( GETPOST ( 'installlock' , 'aZ09' ) ? GETPOST ( 'installlock' , 'aZ09' ) : ( empty ( $argv [ 8 ]) ? '' : $argv [ 8 ])));
2016-02-22 18:45:00 +01:00
2020-04-10 10:59:32 +02:00
$success = 0 ;
2004-02-05 00:24:24 +01:00
2020-04-10 10:59:32 +02:00
$useforcedwizard = false ;
$forcedfile = " ./install.forced.php " ;
2021-02-22 15:18:01 +01:00
if ( $conffile == " /etc/dolibarr/conf.php " ) {
$forcedfile = " /etc/dolibarr/install.forced.php " ;
}
2016-02-22 18:45:00 +01:00
if ( @ file_exists ( $forcedfile )) {
$useforcedwizard = true ;
include_once $forcedfile ;
2018-07-07 23:50:41 +02:00
// If forced install is enabled, replace post values. These are empty because form fields are disabled.
2016-02-22 18:45:00 +01:00
if ( $force_install_noedit == 2 ) {
if ( ! empty ( $force_install_dolibarrlogin )) {
$login = $force_install_dolibarrlogin ;
}
}
}
2008-04-04 02:30:57 +02:00
2023-10-25 17:03:37 +02:00
dolibarr_install_syslog ( " --- step5: entering step5.php page " . $versionfrom . " " . $versionto );
2004-01-27 15:36:40 +01:00
2020-04-10 10:59:32 +02:00
$error = 0 ;
2018-04-12 19:13:06 +02:00
2024-09-01 20:34:20 +02:00
2008-04-21 09:21:13 +02:00
/*
2009-08-04 15:28:22 +02:00
* Actions
*/
2008-04-21 09:21:13 +02:00
2018-07-07 23:50:41 +02:00
// If install, check password and password_verification used to create admin account
2024-09-01 20:34:20 +02:00
if ( $action == " set " ) { // Test on permissions not required here
2023-12-27 12:12:20 +01:00
if ( $pass != $pass_verif ) {
2020-04-10 10:59:32 +02:00
header ( " Location: step4.php?error=1&selectlang= $setuplang " . ( isset ( $login ) ? '&login=' . $login : '' ));
2016-02-22 18:45:00 +01:00
exit ;
}
if ( dol_strlen ( trim ( $pass )) == 0 ) {
2020-04-10 10:59:32 +02:00
header ( " Location: step4.php?error=2&selectlang= $setuplang " . ( isset ( $login ) ? '&login=' . $login : '' ));
2016-02-22 18:45:00 +01:00
exit ;
}
if ( dol_strlen ( trim ( $login )) == 0 ) {
2020-04-10 10:59:32 +02:00
header ( " Location: step4.php?error=3&selectlang= $setuplang " . ( isset ( $login ) ? '&login=' . $login : '' ));
2016-02-22 18:45:00 +01:00
exit ;
}
2008-04-04 00:25:22 +02:00
}
2004-02-12 17:44:49 +01:00
2008-04-04 00:25:22 +02:00
/*
2009-08-04 15:28:22 +02:00
* View
*/
2008-04-04 00:25:22 +02:00
2021-02-27 12:45:07 +01:00
$morehtml = '' ;
2024-09-05 11:49:33 +02:00
pHeader ( $langs -> trans ( " DolibarrSetup " ) . ' - ' . $langs -> trans ( " SetupEnd " ), " step5 " , 'set' , '' , '' , 'main-inside main-inside-borderbottom' );
2011-07-30 16:56:11 +02:00
print '<br>' ;
2008-04-04 00:25:22 +02:00
2010-09-29 10:09:17 +02:00
// Test if we can run a first install process
2021-02-22 15:18:01 +01:00
if ( empty ( $versionfrom ) && empty ( $versionto ) && ! is_writable ( $conffile )) {
2020-03-23 15:54:02 +01:00
print $langs -> trans ( " ConfFileIsNotWritable " , $conffiletoshow );
pFooter ( 1 , $setuplang , 'jscheckparam' );
exit ;
2010-09-29 10:09:17 +02:00
}
2024-03-09 16:32:02 +01:00
// Ensure $modulesdir is set and array
if ( ! isset ( $modulesdir ) || ! is_array ( $modulesdir )) {
$modulesdir = array ();
}
2021-02-22 15:18:01 +01:00
if ( $action == " set " || empty ( $action ) || preg_match ( '/upgrade/i' , $action )) {
2020-04-10 10:59:32 +02:00
$error = 0 ;
2020-03-23 15:54:02 +01:00
// If password is encoded, we decode it
2022-09-21 03:31:58 +02:00
if (( ! empty ( $dolibarr_main_db_pass ) && preg_match ( '/crypted:/i' , $dolibarr_main_db_pass )) || ! empty ( $dolibarr_main_db_encrypted_pass )) {
2020-03-23 15:54:02 +01:00
require_once $dolibarr_main_document_root . '/core/lib/security.lib.php' ;
2022-09-21 03:31:58 +02:00
if ( ! empty ( $dolibarr_main_db_pass ) && preg_match ( '/crypted:/i' , $dolibarr_main_db_pass )) {
2020-03-23 15:54:02 +01:00
$dolibarr_main_db_pass = preg_replace ( '/crypted:/i' , '' , $dolibarr_main_db_pass );
$dolibarr_main_db_pass = dol_decode ( $dolibarr_main_db_pass );
2024-01-11 10:07:06 +01:00
$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
2021-02-22 15:18:01 +01:00
} else {
$dolibarr_main_db_pass = dol_decode ( $dolibarr_main_db_encrypted_pass );
}
2020-03-23 15:54:02 +01:00
}
$conf -> db -> type = $dolibarr_main_db_type ;
$conf -> db -> host = $dolibarr_main_db_host ;
$conf -> db -> port = $dolibarr_main_db_port ;
$conf -> db -> name = $dolibarr_main_db_name ;
$conf -> db -> user = $dolibarr_main_db_user ;
$conf -> db -> pass = $dolibarr_main_db_pass ;
2024-05-15 17:41:58 +02:00
$conf -> db -> dolibarr_main_db_encryption = isset ( $dolibarr_main_db_encryption ) ? $dolibarr_main_db_encryption : 0 ;
2020-04-10 10:59:32 +02:00
$conf -> db -> dolibarr_main_db_cryptkey = isset ( $dolibarr_main_db_cryptkey ) ? $dolibarr_main_db_cryptkey : '' ;
2020-03-23 15:54:02 +01:00
2023-06-24 04:04:02 +02:00
$db = getDoliDBInstance ( $conf -> db -> type , $conf -> db -> host , $conf -> db -> user , $conf -> db -> pass , $conf -> db -> name , ( int ) $conf -> db -> port );
2020-03-23 15:54:02 +01:00
// Create the global $hookmanager object
include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php' ;
2020-04-10 10:59:32 +02:00
$hookmanager = new HookManager ( $db );
2020-03-23 15:54:02 +01:00
$ok = 0 ;
// If first install
2021-02-22 15:18:01 +01:00
if ( $action == " set " ) {
2020-03-23 15:54:02 +01:00
// Active module user
2020-04-10 10:59:32 +02:00
$modName = 'modUser' ;
$file = $modName . " .class.php " ;
dolibarr_install_syslog ( 'step5: load module user ' . DOL_DOCUMENT_ROOT . " /core/modules/ " . $file , LOG_INFO );
include_once DOL_DOCUMENT_ROOT . " /core/modules/ " . $file ;
2020-03-23 15:54:02 +01:00
$objMod = new $modName ( $db );
2020-04-10 10:59:32 +02:00
$result = $objMod -> init ();
2021-02-22 15:18:01 +01:00
if ( ! $result ) {
2022-01-03 18:15:19 +01:00
print " ERROR: failed to init module file = " . $file ;
2021-02-22 15:18:01 +01:00
}
2020-03-23 15:54:02 +01:00
2021-02-22 15:18:01 +01:00
if ( $db -> connected ) {
2020-03-23 15:54:02 +01:00
$conf -> setValues ( $db );
// Reset forced setup after the setValues
2021-02-22 15:18:01 +01:00
if ( defined ( 'SYSLOG_FILE' )) {
$conf -> global -> SYSLOG_FILE = constant ( 'SYSLOG_FILE' );
}
2020-03-23 15:54:02 +01:00
$conf -> global -> MAIN_ENABLE_LOG_TO_HTML = 1 ;
// Create admin user
2020-04-10 10:59:32 +02:00
include_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2020-03-23 15:54:02 +01:00
2024-01-13 19:48:41 +01:00
// Set default encryption to yes, generate a salt and set default encryption algorithm (but only if there is no user yet into database)
2020-03-23 15:54:02 +01:00
$sql = " SELECT u.rowid, u.pass, u.pass_crypted " ;
2020-04-10 10:59:32 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " user as u " ;
$resql = $db -> query ( $sql );
2021-02-22 15:18:01 +01:00
if ( $resql ) {
2020-04-10 10:59:32 +02:00
$numrows = $db -> num_rows ( $resql );
2021-02-22 15:18:01 +01:00
if ( $numrows == 0 ) {
2020-03-23 15:54:02 +01:00
// Define default setup for password encryption
dolibarr_set_const ( $db , " DATABASE_PWD_ENCRYPTED " , " 1 " , 'chaine' , 0 , '' , $conf -> entity );
2020-04-10 10:59:32 +02:00
dolibarr_set_const ( $db , " MAIN_SECURITY_SALT " , dol_print_date ( dol_now (), 'dayhourlog' ), 'chaine' , 0 , '' , 0 ); // All entities
2021-02-22 15:18:01 +01:00
if ( function_exists ( 'password_hash' )) {
2020-04-10 10:59:32 +02:00
dolibarr_set_const ( $db , " MAIN_SECURITY_HASH_ALGO " , 'password_hash' , 'chaine' , 0 , '' , 0 ); // All entities
2021-02-22 15:18:01 +01:00
} else {
dolibarr_set_const ( $db , " MAIN_SECURITY_HASH_ALGO " , 'sha1md5' , 'chaine' , 0 , '' , 0 ); // All entities
}
2020-03-23 15:54:02 +01:00
}
2023-10-15 18:12:03 +02:00
dolibarr_install_syslog ( 'step5: DATABASE_PWD_ENCRYPTED = ' . getDolGlobalString ( 'DATABASE_PWD_ENCRYPTED' ) . ' MAIN_SECURITY_HASH_ALGO = ' . getDolGlobalString ( 'MAIN_SECURITY_HASH_ALGO' ), LOG_INFO );
2020-03-23 15:54:02 +01:00
}
// Create user used to create the admin user
2020-04-10 10:59:32 +02:00
$createuser = new User ( $db );
$createuser -> id = 0 ;
$createuser -> admin = 1 ;
2020-03-23 15:54:02 +01:00
// Set admin user
$newuser = new User ( $db );
2020-04-10 10:59:32 +02:00
$newuser -> lastname = 'SuperAdmin' ;
$newuser -> firstname = '' ;
2020-03-23 15:54:02 +01:00
$newuser -> login = $login ;
$newuser -> pass = $pass ;
2020-04-10 10:59:32 +02:00
$newuser -> admin = 1 ;
$newuser -> entity = 0 ;
2020-03-23 15:54:02 +01:00
2022-02-07 14:25:20 +01:00
$conf -> global -> USER_MAIL_REQUIRED = 0 ; // Force global option to be sure to create a new user with no email
$conf -> global -> USER_PASSWORD_GENERATED = '' ; // To not use any rule for password validation
2020-04-10 10:59:32 +02:00
$result = $newuser -> create ( $createuser , 1 );
2021-02-22 15:18:01 +01:00
if ( $result > 0 ) {
2020-04-10 10:59:32 +02:00
print $langs -> trans ( " AdminLoginCreatedSuccessfuly " , $login ) . " <br> " ;
2020-03-23 15:54:02 +01:00
$success = 1 ;
2020-05-21 15:05:19 +02:00
} else {
2022-11-02 00:00:02 +01:00
if ( $result == - 6 ) { //login or email already exists
2020-03-23 15:54:02 +01:00
dolibarr_install_syslog ( 'step5: AdminLoginAlreadyExists' , LOG_WARNING );
2022-11-02 00:00:02 +01:00
print '<br><div class="warning">' . $newuser -> error . " </div><br> " ;
2020-03-23 15:54:02 +01:00
$success = 1 ;
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
dolibarr_install_syslog ( 'step5: FailedToCreateAdminLogin ' . $newuser -> error , LOG_ERR );
2022-05-18 11:34:54 +02:00
setEventMessages ( $langs -> trans ( " FailedToCreateAdminLogin " ) . ' ' . $newuser -> error , null , 'errors' );
2022-02-07 14:25:20 +01:00
//header("Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
print '<br><div class="error">' . $langs -> trans ( " FailedToCreateAdminLogin " ) . ': ' . $newuser -> error . '</div><br><br>' ;
print $langs -> trans ( " ErrorGoBackAndCorrectParameters " ) . '<br><br>' ;
2020-03-23 15:54:02 +01:00
}
}
2021-02-22 15:18:01 +01:00
if ( $success ) {
2020-03-23 15:54:02 +01:00
// 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.
$db -> begin ();
2020-04-10 10:59:32 +02:00
dolibarr_install_syslog ( 'step5: set MAIN_VERSION_FIRST_INSTALL const to ' . $targetversion , LOG_DEBUG );
2021-09-02 13:25:00 +02:00
$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) " );
2021-02-22 15:18:01 +01:00
if ( $resql ) {
2020-04-10 10:59:32 +02:00
$conf -> global -> MAIN_VERSION_FIRST_INSTALL = $targetversion ;
2020-03-23 15:54:02 +01:00
$db -> commit ();
2020-05-21 15:05:19 +02:00
} else {
2020-03-23 15:54:02 +01:00
//if (! $resql) dol_print_error($db,'Error in setup program'); // We ignore errors. Key may already exists
$db -> commit ();
}
$db -> begin ();
2020-04-10 10:59:32 +02:00
dolibarr_install_syslog ( 'step5: set MAIN_VERSION_LAST_INSTALL const to ' . $targetversion , LOG_DEBUG );
2021-08-28 03:09:18 +02:00
$resql = $db -> query ( " DELETE FROM " . MAIN_DB_PREFIX . " const WHERE " . $db -> decrypt ( 'name' ) . " = 'MAIN_VERSION_LAST_INSTALL' " );
2021-02-22 15:18:01 +01:00
if ( ! $resql ) {
dol_print_error ( $db , 'Error in setup program' );
}
2021-09-02 13:25:00 +02:00
$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) " );
2021-02-22 15:18:01 +01:00
if ( ! $resql ) {
dol_print_error ( $db , 'Error in setup program' );
}
2020-04-10 10:59:32 +02:00
$conf -> global -> MAIN_VERSION_LAST_INSTALL = $targetversion ;
2020-03-23 15:54:02 +01:00
2021-02-22 15:18:01 +01:00
if ( $useforcedwizard ) {
2020-03-23 15:54:02 +01:00
dolibarr_install_syslog ( 'step5: set MAIN_REMOVE_INSTALL_WARNING const to 1' , LOG_DEBUG );
2021-08-28 03:09:18 +02:00
$resql = $db -> query ( " DELETE FROM " . MAIN_DB_PREFIX . " const WHERE " . $db -> decrypt ( 'name' ) . " = 'MAIN_REMOVE_INSTALL_WARNING' " );
2021-02-22 15:18:01 +01:00
if ( ! $resql ) {
dol_print_error ( $db , 'Error in setup program' );
}
2022-12-27 10:38:06 +01:00
// 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
/* No need to enable this
2021-09-02 13:25:00 +02:00
$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) " );
2021-02-22 15:18:01 +01:00
if ( ! $resql ) {
dol_print_error ( $db , 'Error in setup program' );
}
2020-04-10 10:59:32 +02:00
$conf -> global -> MAIN_REMOVE_INSTALL_WARNING = 1 ;
2022-12-27 10:38:06 +01:00
*/
2020-03-23 15:54:02 +01:00
}
2023-02-09 00:47:33 +01:00
// List of modules to enable
$tmparray = array ();
2020-03-23 15:54:02 +01:00
// If we ask to force some modules to be enabled
2021-02-22 15:18:01 +01:00
if ( ! empty ( $force_install_module )) {
if ( ! defined ( 'DOL_DOCUMENT_ROOT' ) && ! empty ( $dolibarr_main_document_root )) {
define ( 'DOL_DOCUMENT_ROOT' , $dolibarr_main_document_root );
}
2020-03-23 15:54:02 +01:00
2020-04-10 10:59:32 +02:00
$tmparray = explode ( ',' , $force_install_module );
2023-02-09 00:47:33 +01:00
}
$modNameLoaded = array ();
// Search modules dirs
$modulesdir [] = $dolibarr_main_document_root . '/core/modules/' ;
foreach ( $modulesdir as $dir ) {
// Load modules attributes in arrays (name, numero, orders) from dir directory
//print $dir."\n<br>";
dol_syslog ( " Scan directory " . $dir . " for module descriptor files (modXXX.class.php) " );
$handle = @ opendir ( $dir );
if ( is_resource ( $handle )) {
while (( $file = readdir ( $handle )) !== false ) {
if ( is_readable ( $dir . $file ) && substr ( $file , 0 , 3 ) == 'mod' && substr ( $file , dol_strlen ( $file ) - 10 ) == '.class.php' ) {
$modName = substr ( $file , 0 , dol_strlen ( $file ) - 10 );
if ( $modName ) {
if ( ! empty ( $modNameLoaded [ $modName ])) { // In cache of already loaded modules ?
$mesg = " Error: Module " . $modName . " was found twice: Into " . $modNameLoaded [ $modName ] . " and " . $dir . " . You probably have an old file on your disk.<br> " ;
setEventMessages ( $mesg , null , 'warnings' );
dol_syslog ( $mesg , LOG_ERR );
continue ;
}
try {
$res = include_once $dir . $file ; // A class already exists in a different file will send a non catchable fatal error.
if ( class_exists ( $modName )) {
$objMod = new $modName ( $db );
$modNameLoaded [ $modName ] = $dir ;
if ( ! empty ( $objMod -> enabled_bydefault ) && ! in_array ( $file , $tmparray )) {
$tmparray [] = $file ;
}
}
} catch ( Exception $e ) {
dol_syslog ( " Failed to load " . $dir . $file . " " . $e -> getMessage (), LOG_ERR );
}
}
}
}
}
}
// Loop on each modules to activate it
if ( ! empty ( $tmparray )) {
2021-02-22 15:18:01 +01:00
foreach ( $tmparray as $modtoactivate ) {
2020-04-10 10:59:32 +02:00
$modtoactivatenew = preg_replace ( '/\.class\.php$/i' , '' , $modtoactivate );
2023-02-09 00:47:33 +01:00
//print $langs->trans("ActivateModule", $modtoactivatenew).'<br>';
2020-03-23 15:54:02 +01:00
2020-04-10 10:59:32 +02:00
$file = $modtoactivatenew . '.class.php' ;
dolibarr_install_syslog ( 'step5: activate module file=' . $file );
$res = dol_include_once ( " /core/modules/ " . $file );
2020-03-23 15:54:02 +01:00
2020-04-10 10:59:32 +02:00
$res = activateModule ( $modtoactivatenew , 1 );
2021-02-22 15:18:01 +01:00
if ( ! empty ( $res [ 'errors' ])) {
2022-01-03 18:15:19 +01:00
print 'ERROR: failed to activateModule() file=' . $file ;
2021-02-22 15:18:01 +01:00
}
2020-03-23 15:54:02 +01:00
}
2023-02-09 00:47:33 +01:00
//print '<br>';
2020-03-23 15:54:02 +01:00
}
2023-07-02 12:57:38 +02:00
// Now delete the flag that say installation is not complete
2020-03-23 15:54:02 +01:00
dolibarr_install_syslog ( 'step5: remove MAIN_NOT_INSTALLED const' );
2022-11-22 23:53:00 +01:00
$resql = $db -> query ( " DELETE FROM " . MAIN_DB_PREFIX . " const WHERE " . $db -> decrypt ( 'name' ) . " = 'MAIN_NOT_INSTALLED' " );
2021-02-22 15:18:01 +01:00
if ( ! $resql ) {
dol_print_error ( $db , 'Error in setup program' );
}
2020-03-23 15:54:02 +01:00
2023-11-20 20:38:42 +01:00
// May fail if parameter already defined
dolibarr_install_syslog ( 'step5: set the default language' );
$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) " );
//if (! $resql) dol_print_error($db,'Error in setup program');
2020-03-23 15:54:02 +01:00
$db -> commit ();
}
2020-05-21 15:05:19 +02:00
} else {
2020-03-23 15:54:02 +01:00
print $langs -> trans ( " ErrorFailedToConnect " ) . " <br> " ;
}
2021-02-22 15:18:01 +01:00
} elseif ( empty ( $action ) || preg_match ( '/upgrade/i' , $action )) {
// If upgrade
if ( $db -> connected ) {
2020-03-23 15:54:02 +01:00
$conf -> setValues ( $db );
// Reset forced setup after the setValues
2021-02-22 15:18:01 +01:00
if ( defined ( 'SYSLOG_FILE' )) {
$conf -> global -> SYSLOG_FILE = constant ( 'SYSLOG_FILE' );
}
2020-03-23 15:54:02 +01:00
$conf -> global -> MAIN_ENABLE_LOG_TO_HTML = 1 ;
// Define if we need to update the MAIN_VERSION_LAST_UPGRADE value in database
2020-04-10 10:59:32 +02:00
$tagdatabase = false ;
2023-11-27 11:46:58 +01:00
if ( ! getDolGlobalString ( 'MAIN_VERSION_LAST_UPGRADE' )) {
2024-01-13 19:48:41 +01:00
$tagdatabase = true ; // We don't know what it was before, so now we consider we at the chosen version.
2021-02-22 15:18:01 +01:00
} else {
2020-04-10 10:59:32 +02:00
$mainversionlastupgradearray = preg_split ( '/[.-]/' , $conf -> global -> MAIN_VERSION_LAST_UPGRADE );
$targetversionarray = preg_split ( '/[.-]/' , $targetversion );
2021-02-22 15:18:01 +01:00
if ( versioncompare ( $targetversionarray , $mainversionlastupgradearray ) > 0 ) {
$tagdatabase = true ;
}
2020-03-23 15:54:02 +01:00
}
2021-02-22 15:18:01 +01:00
if ( $tagdatabase ) {
2020-04-10 10:59:32 +02:00
dolibarr_install_syslog ( 'step5: set MAIN_VERSION_LAST_UPGRADE const to value ' . $targetversion );
2021-08-28 03:09:18 +02:00
$resql = $db -> query ( " DELETE FROM " . MAIN_DB_PREFIX . " const WHERE " . $db -> decrypt ( 'name' ) . " = 'MAIN_VERSION_LAST_UPGRADE' " );
2021-02-22 15:18:01 +01:00
if ( ! $resql ) {
dol_print_error ( $db , 'Error in setup program' );
}
2021-09-02 13:25:00 +02:00
$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) " );
2021-02-22 15:18:01 +01:00
if ( ! $resql ) {
dol_print_error ( $db , 'Error in setup program' );
}
2020-04-10 10:59:32 +02:00
$conf -> global -> MAIN_VERSION_LAST_UPGRADE = $targetversion ;
2020-05-21 15:05:19 +02:00
} else {
2023-10-15 18:12:03 +02:00
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.' );
2023-07-02 12:57:38 +02:00
// Force the delete of the flag that say installation is not complete
dolibarr_install_syslog ( 'step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)' );
$resql = $db -> query ( " DELETE FROM " . MAIN_DB_PREFIX . " const WHERE " . $db -> decrypt ( 'name' ) . " = 'MAIN_NOT_INSTALLED' " );
if ( ! $resql ) {
dol_print_error ( $db , 'Error in setup program' );
}
2020-03-23 15:54:02 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-03-23 15:54:02 +01:00
print $langs -> trans ( " ErrorFailedToConnect " ) . " <br> " ;
}
2020-05-21 15:05:19 +02:00
} else {
2024-01-20 09:22:38 +01:00
dol_print_error ( null , 'step5.php: unknown choice of action' );
2020-03-23 15:54:02 +01:00
}
$db -> close ();
2004-01-27 15:36:40 +01:00
}
2004-01-30 17:00:18 +01:00
2005-06-26 00:06:00 +02:00
2009-08-10 14:54:37 +02:00
// Create lock file
2005-10-03 03:14:50 +02:00
// If first install
2022-02-07 14:25:20 +01:00
if ( $action == " set " ) {
if ( $success ) {
2023-11-27 11:46:58 +01:00
if ( ! getDolGlobalString ( 'MAIN_VERSION_LAST_UPGRADE' ) || ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE == DOL_VERSION )) {
2023-01-27 11:52:58 +01:00
// Install is finished (database is on same version than files)
2022-02-07 14:25:20 +01:00
print '<br>' . $langs -> trans ( " SystemIsInstalled " ) . " <br> " ;
2023-01-27 11:52:58 +01:00
// Create install.lock file
// No need for the moment to create it automatically, creation by web assistant means permissions are given
// 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)
2022-02-07 14:25:20 +01:00
$createlock = 0 ;
2023-11-27 11:46:58 +01:00
if ( ! empty ( $force_install_lockinstall ) || getDolGlobalString ( 'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE' )) {
2023-01-27 11:52:58 +01:00
// Install is finished, we create the "install.lock" file, so install won't be possible anymore.
// TODO Upgrade will be still be possible if a file "upgrade.unlock" is present
2022-02-07 14:25:20 +01:00
$lockfile = DOL_DATA_ROOT . '/install.lock' ;
$fp = @ fopen ( $lockfile , " w " );
if ( $fp ) {
if ( empty ( $force_install_lockinstall ) || $force_install_lockinstall == 1 ) {
2023-02-17 19:30:50 +01:00
$force_install_lockinstall = '444' ; // For backward compatibility
2022-02-07 14:25:20 +01:00
}
2023-02-02 12:58:12 +01:00
fwrite ( $fp , " This is a lock file to prevent use of install or upgrade pages (set with permission " . $force_install_lockinstall . " ) " );
2022-02-07 14:25:20 +01:00
fclose ( $fp );
2023-02-17 19:30:50 +01:00
dolChmod ( $lockfile , $force_install_lockinstall );
2022-02-07 14:25:20 +01:00
$createlock = 1 ;
2021-02-22 15:18:01 +01:00
}
2020-03-23 15:54:02 +01:00
}
2022-02-07 14:25:20 +01:00
if ( empty ( $createlock )) {
print '<div class="warning">' . $langs -> trans ( " WarningRemoveInstallDir " ) . " </div> " ;
}
2020-03-23 15:54:02 +01:00
2022-02-07 14:25:20 +01:00
print " <br> " ;
2020-03-23 15:54:02 +01:00
2022-02-07 14:25:20 +01:00
print $langs -> trans ( " YouNeedToPersonalizeSetup " ) . " <br><br><br> " ;
2020-03-23 15:54:02 +01:00
2022-02-07 14:25:20 +01:00
print '<div class="center">> <a href="../admin/index.php?mainmenu=home&leftmenu=setup' . ( isset ( $login ) ? '&username=' . urlencode ( $login ) : '' ) . '">' ;
print '<span class="fas fa-external-link-alt"></span> ' . $langs -> trans ( " GoToSetupArea " );
print '</a></div><br>' ;
} else {
// If here MAIN_VERSION_LAST_UPGRADE is not empty
2023-10-15 18:12:03 +02:00
print $langs -> trans ( " VersionLastUpgrade " ) . ': <b><span class="ok">' . getDolGlobalString ( 'MAIN_VERSION_LAST_UPGRADE' ) . '</span></b><br>' ;
2022-02-07 14:25:20 +01:00
print $langs -> trans ( " VersionProgram " ) . ': <b><span class="ok">' . DOL_VERSION . '</span></b><br>' ;
print $langs -> trans ( " MigrationNotFinished " ) . '<br>' ;
print " <br> " ;
print '<div class="center"><a href="' . $dolibarr_main_url_root . '/install/index.php">' ;
print '<span class="fas fa-link-alt"></span> ' . $langs -> trans ( " GoToUpgradePage " );
print '</a></div>' ;
}
2020-03-23 15:54:02 +01:00
}
2021-02-22 15:18:01 +01:00
} elseif ( empty ( $action ) || preg_match ( '/upgrade/i' , $action )) {
// If upgrade
2023-11-27 11:46:58 +01:00
if ( ! getDolGlobalString ( 'MAIN_VERSION_LAST_UPGRADE' ) || ( $conf -> global -> MAIN_VERSION_LAST_UPGRADE == DOL_VERSION )) {
2023-02-02 12:58:12 +01:00
// Upgrade is finished (database is on the same version than files)
print '<img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/checklist.svg" width="20" alt="Configuration">' ;
print ' <span class="valignmiddle">' . $langs -> trans ( " SystemIsUpgraded " ) . " </span><br> " ;
2020-03-23 15:54:02 +01:00
2023-01-27 11:52:58 +01:00
// Create install.lock file if it does not exists.
// Note: it should always exists. A better solution to allow upgrade will be to add an upgrade.unlock file
2020-04-10 10:59:32 +02:00
$createlock = 0 ;
2023-11-27 11:46:58 +01:00
if ( ! empty ( $force_install_lockinstall ) || getDolGlobalString ( 'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE' )) {
2023-01-27 11:52:58 +01:00
// Upgrade is finished, we modify the lock file
2020-04-10 10:59:32 +02:00
$lockfile = DOL_DATA_ROOT . '/install.lock' ;
2020-03-23 15:54:02 +01:00
$fp = @ fopen ( $lockfile , " w " );
2021-02-22 15:18:01 +01:00
if ( $fp ) {
if ( empty ( $force_install_lockinstall ) || $force_install_lockinstall == 1 ) {
2023-02-17 19:30:50 +01:00
$force_install_lockinstall = '444' ; // For backward compatibility
2021-02-22 15:18:01 +01:00
}
2023-02-02 12:58:12 +01:00
fwrite ( $fp , " This is a lock file to prevent use of install or upgrade pages (set with permission " . $force_install_lockinstall . " ) " );
2020-03-23 15:54:02 +01:00
fclose ( $fp );
2023-02-17 19:30:50 +01:00
dolChmod ( $lockfile , $force_install_lockinstall );
2020-04-10 10:59:32 +02:00
$createlock = 1 ;
2020-03-23 15:54:02 +01:00
}
}
2021-02-22 15:18:01 +01:00
if ( empty ( $createlock )) {
2020-03-23 15:54:02 +01:00
print '<br><div class="warning">' . $langs -> trans ( " WarningRemoveInstallDir " ) . " </div> " ;
}
2023-01-27 11:52:58 +01:00
// Delete the upgrade.unlock file it it exists
$unlockupgradefile = DOL_DATA_ROOT . '/upgrade.unlock' ;
dol_delete_file ( $unlockupgradefile , 0 , 0 , 0 , null , false , 0 );
2021-02-27 12:45:07 +01:00
print " <br> " ;
2020-03-23 15:54:02 +01:00
2024-07-09 16:33:10 +02:00
$morehtml = '<br><div class="center"><a class="buttonGoToupgrade" href="../index.php?mainmenu=home' . ( isset ( $login ) ? '&username=' . urlencode ( $login ) : '' ) . '">' ;
2021-02-27 12:45:07 +01:00
$morehtml .= '<span class="fas fa-link-alt"></span> ' . $langs -> trans ( " GoToDolibarr " ) . '...' ;
$morehtml .= '</a></div><br>' ;
2020-05-21 15:05:19 +02:00
} else {
2020-03-23 15:54:02 +01:00
// If here MAIN_VERSION_LAST_UPGRADE is not empty
2023-10-15 18:12:03 +02:00
print $langs -> trans ( " VersionLastUpgrade " ) . ': <b><span class="ok">' . getDolGlobalString ( 'MAIN_VERSION_LAST_UPGRADE' ) . '</span></b><br>' ;
2020-03-23 15:54:02 +01:00
print $langs -> trans ( " VersionProgram " ) . ': <b><span class="ok">' . DOL_VERSION . '</span></b>' ;
print " <br> " ;
2024-07-09 16:33:10 +02:00
$morehtml = '<br><div class="center"><a class="buttonGoToupgrade" href="../install/index.php">' ;
2021-02-27 12:45:07 +01:00
$morehtml .= '<span class="fas fa-link-alt"></span> ' . $langs -> trans ( " GoToUpgradePage " );
$morehtml .= '</a></div>' ;
2020-03-23 15:54:02 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2024-01-20 09:22:38 +01:00
dol_print_error ( null , 'step5.php: unknown choice of action=' . $action . ' in create lock file seaction' );
2009-08-05 12:33:49 +02:00
}
2004-02-05 00:24:24 +01:00
2008-03-03 02:56:46 +01:00
// Clear cache files
clearstatcache ();
2006-06-17 16:13:49 +02:00
2020-04-10 10:59:32 +02:00
$ret = 0 ;
2021-02-22 15:18:01 +01:00
if ( $error && isset ( $argv [ 1 ])) {
$ret = 1 ;
}
2018-04-12 19:13:06 +02:00
dolibarr_install_syslog ( " Exit " . $ret );
2023-10-25 17:03:37 +02:00
dolibarr_install_syslog ( " --- step5: Dolibarr setup finished " );
2005-10-30 02:07:00 +01:00
2021-02-27 12:45:07 +01:00
pFooter ( 1 , $setuplang , '' , 0 , $morehtml );
2018-04-12 19:13:06 +02:00
// Return code if ran from command line
2021-02-22 15:18:01 +01:00
if ( $ret ) {
exit ( $ret );
}