41define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
42include_once
'inc.php';
68require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
69require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
70require_once $dolibarr_main_document_root.
'/core/lib/functions2.lib.php';
73@phan-var-force ?string $modulesdir
74@phan-var-force ?string $dolibarr_main_db_encryption
75@phan-var-force ?string $dolibarr_main_db_cryptkey
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]);
88$targetversion = DOL_VERSION;
89if (!empty($action) && preg_match(
'/upgrade/i', $action)) {
91 $tmp = explode(
'_', $action, 2);
92 if ($tmp[0] ==
'upgrade') {
93 if (!empty($tmp[1])) {
94 $targetversion = $tmp[1];
96 $targetversion = DOL_VERSION;
101$langs->loadLangs(array(
"admin",
"install"));
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]);
109$useforcedwizard =
false;
110$forcedfile =
"./install.forced.php";
111if (
$conffile ==
"/etc/dolibarr/conf.php") {
112 $forcedfile =
"/etc/dolibarr/install.forced.php";
114if (@file_exists($forcedfile)) {
115 $useforcedwizard =
true;
116 include_once $forcedfile;
139 @phan-var-force int $force_install_noedit
142 if ($force_install_noedit == 2) {
143 if (!empty($force_install_dolibarrlogin)) {
144 $login = $force_install_dolibarrlogin;
149$force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (
GETPOST(
'installlock',
'aZ09') ?
GETPOST(
'installlock',
'aZ09') : (empty($argv[8]) ?
'' : $argv[8])));
153if (@$force_install_noedit == 2 && isset($force_install_dolibarrpassword)) {
154 $pass = $force_install_dolibarrpassword;
155 $pass_verif = $force_install_dolibarrpassword;
169if ($action ==
"set") {
170 if ($pass != $pass_verif) {
171 header(
"Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
176 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
181 header(
"Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
184 if ($pass ===
'**********' || $pass_verif ==
'**********') {
185 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
197pHeader($langs->trans(
"DolibarrSetup"),
"step5",
'set',
'',
'',
'main-inside main-inside-borderbottom no-bottom');
201if (empty($versionfrom) && empty($versionto) && !is_writable(
$conffile)) {
202 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
203 pFooter(1, $setuplang,
'jscheckparam');
208if (!isset($modulesdir) || !is_array($modulesdir)) {
209 $modulesdir = array();
212if ($action ==
"set" || empty($action) || preg_match(
'/upgrade/i', $action)) {
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;
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;
224 $dolibarr_main_db_pass =
dolDecrypt((
string) $dolibarr_main_db_pass);
226 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
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 :
'';
242 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
248 if ($action ==
"set") {
250 $modName =
'modUser';
251 $file = $modName.
".class.php";
253 include_once DOL_DOCUMENT_ROOT.
"/core/modules/".$file;
254 $objMod =
new $modName(
$db);
255 $result = $objMod->init();
257 print
"ERROR: failed to init module file = ".$file;
260 if (
$db->connected) {
263 if (defined(
'SYSLOG_FILE')) {
264 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
266 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
269 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
272 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
273 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
274 $resql =
$db->query($sql);
276 $numrows =
$db->num_rows($resql);
283 if (function_exists(
'password_hash')) {
301 $createuser->admin = 1;
305 $newuser->lastname =
'SuperAdmin';
306 $newuser->firstname =
'';
307 $newuser->ldap_sid =
'';
308 $newuser->login = $login;
309 $newuser->pass = $pass;
311 $newuser->entity = 0;
313 $conf->global->USER_MAIL_REQUIRED = 0;
314 $conf->global->USER_PASSWORD_GENERATED =
'';
316 $result = $newuser->create($createuser, 1);
318 print $langs->trans(
"AdminLoginCreatedSuccessfuly", $login).
"<br>";
323 print
'<br><div class="warning">'.$newuser->error.
"</div><br>";
327 setEventMessages($langs->trans(
"FailedToCreateAdminLogin").
' '.$newuser->error,
null,
'errors');
329 print
'<br><div class="error">'.$langs->trans(
"FailedToCreateAdminLogin").
': '.$newuser->error.
'</div><br><br>';
330 print $langs->trans(
"ErrorGoBackAndCorrectParameters").
'<br><br>';
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)");
340 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
350 $resql =
$db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".
$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_INSTALL'");
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)");
358 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
360 if ($useforcedwizard) {
362 $resql =
$db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".
$db->decrypt(
'name').
" = 'MAIN_REMOVE_INSTALL_WARNING'");
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);
385 $tmparray = explode(
',', $force_install_module);
388 $modNameLoaded = array();
391 $modulesdir[] = $dolibarr_main_document_root.
'/core/modules/';
393 foreach ($modulesdir as $dir) {
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);
403 if (!empty($modNameLoaded[$modName])) {
404 $mesg =
"Error: Module ".$modName.
" was found twice: Into ".$modNameLoaded[$modName].
" and ".$dir.
". You probably have an old file on your disk.<br>";
411 $res = include_once $dir.$file;
412 if (class_exists($modName)) {
413 $objMod =
new $modName(
$db);
414 $modNameLoaded[$modName] = $dir;
415 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
420 dol_syslog(
"Failed to load ".$dir.$file.
" ".$e->getMessage(), LOG_ERR);
429 if (!empty($tmparray)) {
430 foreach ($tmparray as $modtoactivate) {
431 $modtoactivatenew = preg_replace(
'/\.class\.php$/i',
'', $modtoactivate);
434 $file = $modtoactivatenew.
'.class.php';
438 $res = activateModule($modtoactivatenew, 1);
439 if (!empty($res[
'errors'])) {
440 print
'ERROR: failed to activateModule() file='.$file;
448 $resql =
$db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".
$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
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)");
461 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
463 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
465 if (
$db->connected) {
468 if (defined(
'SYSLOG_FILE')) {
469 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
471 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
474 $tagdatabase =
false;
478 $mainversionlastupgradearray = preg_split(
'/[.-]/',
$conf->global->MAIN_VERSION_LAST_UPGRADE);
479 $targetversionarray = preg_split(
'/[.-]/', $targetversion);
480 if (
versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
487 $resql =
$db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".
$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_UPGRADE'");
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)");
495 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
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.');
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'");
507 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
521if ($action ==
"set") {
525 print
'<br>'.$langs->trans(
"SystemIsInstalled").
"<br>";
531 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
534 $lockfile = DOL_DATA_ROOT.
'/install.lock';
535 $fp = @fopen($lockfile,
"w");
537 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
538 $force_install_lockinstall =
'444';
540 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
542 dolChmod($lockfile, $force_install_lockinstall);
547 if (empty($createlock)) {
548 print
'<div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
553 print
'<span class="opacitymedium">'.$langs->trans(
"YouNeedToPersonalizeSetup").
"</span><br><br><br>";
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>';
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>';
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");
571} elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
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>";
581 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
583 $lockfile = DOL_DATA_ROOT.
'/install.lock';
584 $fp = @fopen($lockfile,
"w");
586 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
587 $force_install_lockinstall =
'444';
589 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
591 dolChmod($lockfile, $force_install_lockinstall);
596 if (empty($createlock)) {
597 print
'<br><div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
601 $unlockupgradefile = DOL_DATA_ROOT.
'/upgrade.unlock';
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>';
611 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="okinversed">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
613 print $langs->trans(
"VersionProgram").
': <b><span class="okinversed">'.DOL_VERSION.
'</span></b>';
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>';
622 dol_print_error(
null,
'step5.php: unknown choice of action='.$action.
' in create lock file seaction');
629if ($error && isset($argv[1])) {
636pFooter(1, $setuplang,
'', 0, $morehtml);
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,...
Class to manage Dolibarr users.
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.
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.