41define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
42include_once
'inc.php';
70require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
71require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
72require_once $dolibarr_main_document_root.
'/core/lib/functions2.lib.php';
75@phan-var-force ?string $modulesdir
76@phan-var-force ?string $dolibarr_main_db_encryption
77@phan-var-force ?string $dolibarr_main_db_cryptkey
78@phan-var-force ?int $force_install_dolibarrpassword
79@phan-var-force ?int $force_install_noedit
84$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
85$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
86$setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[3]) ?
'auto' : $argv[3]);
87$langs->setDefaultLang($setuplang);
88$action =
GETPOST(
'action',
'alpha') ?
GETPOST(
'action',
'alpha') : (empty($argv[4]) ?
'' : $argv[4]);
92$targetversion = DOL_VERSION;
93if (!empty($action) && preg_match(
'/upgrade/i', $action)) {
95 $tmp = explode(
'_', $action, 2);
96 if ($tmp[0] ==
'upgrade') {
97 if (!empty($tmp[1])) {
98 $targetversion = $tmp[1];
100 $targetversion = DOL_VERSION;
105$langs->loadLangs(array(
"admin",
"install"));
107$login =
GETPOST(
'login',
'alpha') ?
GETPOST(
'login',
'alpha') : (empty($argv[5]) ?
'' : $argv[5]);
108$pass =
GETPOST(
'pass',
'password') ?
GETPOST(
'pass',
'password') : (empty($argv[6]) ?
'' : $argv[6]);
109$pass_verif =
GETPOST(
'pass_verif',
'password') ?
GETPOST(
'pass_verif',
'password') : (empty($argv[7]) ?
'' : $argv[7]);
113$useforcedwizard =
false;
114$forcedfile =
"./install.forced.php";
115if (
$conffile ==
"/etc/dolibarr/conf.php") {
116 $forcedfile =
"/etc/dolibarr/install.forced.php";
118if (@file_exists($forcedfile)) {
119 $useforcedwizard =
true;
120 include_once $forcedfile;
143 @phan-var-force int $force_install_noedit
146 if ($force_install_noedit == 2) {
147 if (!empty($force_install_dolibarrlogin)) {
148 $login = $force_install_dolibarrlogin;
153$force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (
GETPOST(
'installlock',
'aZ09') ?
GETPOST(
'installlock',
'aZ09') : (empty($argv[8]) ?
'' : $argv[8])));
157if (@$force_install_noedit == 2 && isset($force_install_dolibarrpassword)) {
158 $pass = $force_install_dolibarrpassword;
159 $pass_verif = $force_install_dolibarrpassword;
173if ($action ==
"set") {
174 if ($pass != $pass_verif) {
175 header(
"Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
180 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
185 header(
"Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
188 if ($pass ===
'**********' || $pass_verif ==
'**********') {
189 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
201pHeader($langs->trans(
"DolibarrSetup"),
"step5",
'set',
'',
'',
'main-inside main-inside-borderbottom no-bottom');
205if (empty($versionfrom) && empty($versionto) && !is_writable(
$conffile)) {
206 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
207 pFooter(1, $setuplang,
'jscheckparam');
212if (!isset($modulesdir) || !is_array($modulesdir)) {
213 $modulesdir = array();
216if ($action ==
"set" || empty($action) || preg_match(
'/upgrade/i', $action)) {
220 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/(crypted|dolcrypt):/i', (
string) $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
221 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
222 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', (
string) $dolibarr_main_db_pass)) {
223 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', (
string) $dolibarr_main_db_pass);
224 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
225 $dolibarr_main_db_pass =
dol_decode((
string) $dolibarr_main_db_pass);
226 } elseif (preg_match(
'/dolcrypt:/i', (
string) $dolibarr_main_db_pass)) {
227 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
228 $dolibarr_main_db_pass =
dolDecrypt((
string) $dolibarr_main_db_pass);
230 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
234 $conf->db->type = $dolibarr_main_db_type;
235 $conf->db->host = $dolibarr_main_db_host;
236 $conf->db->port = $dolibarr_main_db_port;
237 $conf->db->name = $dolibarr_main_db_name;
238 $conf->db->user = $dolibarr_main_db_user;
239 $conf->db->pass = $dolibarr_main_db_pass;
240 $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption : 0;
241 $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
246 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
252 if ($action ==
"set") {
254 $modName =
'modUser';
255 $file = $modName.
".class.php";
257 include_once DOL_DOCUMENT_ROOT.
"/core/modules/".$file;
258 $objMod =
new $modName($db);
259 $result = $objMod->init();
261 print
"ERROR: failed to init module file = ".$file;
264 if ($db->connected) {
265 $conf->setValues($db);
267 if (defined(
'SYSLOG_FILE')) {
268 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
270 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
273 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
276 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
277 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
278 $resql = $db->query($sql);
280 $numrows = $db->num_rows($resql);
287 if (function_exists(
'password_hash')) {
288 dolibarr_set_const($db,
"MAIN_SECURITY_HASH_ALGO",
'password_hash',
'chaine', 0,
'', 0);
299 dolibarr_set_const($db,
"PAYMENT_SECURITY_TOKEN", bin2hex(random_bytes(12)),
'chaine', 0,
'', 0);
303 $createuser =
new User($db);
305 $createuser->admin = 1;
308 $newuser =
new User($db);
309 $newuser->lastname =
'SuperAdmin';
310 $newuser->firstname =
'';
311 $newuser->ldap_sid =
'';
312 $newuser->login = $login;
313 $newuser->pass = $pass;
315 $newuser->entity = 0;
317 $conf->global->USER_MAIL_REQUIRED = 0;
318 $conf->global->USER_PASSWORD_GENERATED =
'';
320 $result = $newuser->create($createuser, 1);
322 print $langs->trans(
"AdminLoginCreatedSuccessfuly", $login).
"<br>";
327 print
'<div class="warning warningbackground">'.$newuser->error.
"</div>";
331 setEventMessages($langs->trans(
"FailedToCreateAdminLogin").
' '.$newuser->error,
null,
'errors');
333 print
'<br><div class="error">'.$langs->trans(
"FailedToCreateAdminLogin").
': '.$newuser->error.
'</div><br><br>';
334 print $langs->trans(
"ErrorGoBackAndCorrectParameters").
'<br><br>';
342 $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)");
344 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
354 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_INSTALL'");
356 dol_print_error($db,
'Error in setup program');
358 $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)");
360 dol_print_error($db,
'Error in setup program');
362 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
364 if ($useforcedwizard) {
366 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_REMOVE_INSTALL_WARNING'");
368 dol_print_error($db,
'Error in setup program');
384 if (!empty($force_install_module)) {
385 if (!defined(
'DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
386 define(
'DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
389 $tmparray = explode(
',', $force_install_module);
392 $modNameLoaded = array();
395 $modulesdir[] = $dolibarr_main_document_root.
'/core/modules/';
397 foreach ($modulesdir as $dir) {
400 dol_syslog(
"Scan directory ".$dir.
" for module descriptor files (modXXX.class.php)");
401 $handle = @opendir($dir);
402 if (is_resource($handle)) {
403 while (($file = readdir($handle)) !==
false) {
407 if (!empty($modNameLoaded[$modName])) {
408 $mesg =
"Error: Module ".$modName.
" was found twice: Into ".$modNameLoaded[$modName].
" and ".$dir.
". You probably have an old file on your disk.<br>";
409 setEventMessages($mesg,
null,
'warnings');
415 $res = include_once $dir.$file;
416 if (class_exists($modName)) {
417 $objMod =
new $modName($db);
418 $modNameLoaded[$modName] = $dir;
419 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
424 dol_syslog(
"Failed to load ".$dir.$file.
" ".$e->getMessage(), LOG_ERR);
433 if (!empty($tmparray)) {
434 foreach ($tmparray as $modtoactivate) {
435 $modtoactivatenew = preg_replace(
'/\.class\.php$/i',
'', $modtoactivate);
438 $file = $modtoactivatenew.
'.class.php';
442 $res = activateModule($modtoactivatenew, 1);
443 if (!empty($res[
'errors'])) {
444 print
'ERROR: failed to activateModule() file='.$file;
452 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
454 dol_print_error($db,
'Error in setup program');
459 $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)");
465 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
467 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
469 if ($db->connected) {
470 $conf->setValues($db);
472 if (defined(
'SYSLOG_FILE')) {
473 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
475 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
478 $tagdatabase =
false;
482 $mainversionlastupgradearray = preg_split(
'/[.-]/',
$conf->global->MAIN_VERSION_LAST_UPGRADE);
483 $targetversionarray = preg_split(
'/[.-]/', $targetversion);
484 if (
versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
491 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_UPGRADE'");
493 dol_print_error($db,
'Error in setup program');
495 $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)");
497 dol_print_error($db,
'Error in setup program');
499 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
501 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.');
504 dolibarr_install_syslog(
'step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)');
505 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
507 dol_print_error($db,
'Error in setup program');
511 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
514 dol_print_error(
null,
'step5.php: unknown choice of action');
525if ($action ==
"set") {
529 print
'<br><div class="info">'.$langs->trans(
"SystemIsInstalled").
"</div><br>";
535 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
538 $lockfile = DOL_DATA_ROOT.
'/install.lock';
539 $fp = @fopen($lockfile,
"w");
541 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
542 $force_install_lockinstall =
'444';
544 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
546 dolChmod($lockfile, $force_install_lockinstall);
551 if (empty($createlock)) {
552 print
'<div class="warning warningbackground">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
557 print
'<span class="opacitymedium">'.$langs->trans(
"YouNeedToPersonalizeSetup").
"</span><br><br><br>";
559 print
'<div class="center divlinktogotosetup"><a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
560 print
'<span class="fas fa-external-link-alt"></span> '.$langs->trans(
"GoToSetupArea");
561 print
'</a></div><br><br>';
564 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
565 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b><br>';
566 print $langs->trans(
"MigrationNotFinished").
'<br>';
569 print
'<div class="center"><a href="'.$dolibarr_main_url_root.
'/install/index.php">';
570 print
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
575} elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
579 print
'<img class="valignmiddle inline-block paddingright" src="../public/theme/common/checklist.svg" width="30" alt="Configuration">';
580 print
' <span class="valignmiddle">'.$langs->trans(
"SystemIsUpgraded").
"</span><br>";
585 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
587 $lockfile = DOL_DATA_ROOT.
'/install.lock';
588 $fp = @fopen($lockfile,
"w");
590 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
591 $force_install_lockinstall =
'444';
593 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
595 dolChmod($lockfile, $force_install_lockinstall);
600 if (empty($createlock)) {
601 print
'<div class="warning warningbackground">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
605 $unlockupgradefile = DOL_DATA_ROOT.
'/upgrade.unlock';
610 $morehtml =
'<br><div class="center"><a class="buttonGoToupgrade" href="../index.php?mainmenu=home'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
611 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToDolibarr").
'...';
612 $morehtml .=
'</a></div><br>';
615 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="okinversed">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
617 print $langs->trans(
"VersionProgram").
': <b><span class="okinversed">'.DOL_VERSION.
'</span></b>';
621 $morehtml =
'<br><div class="center"><a class="buttonGoToupgrade" href="../install/index.php">';
622 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
623 $morehtml .=
'</a></div>';
626 dol_print_error(
null,
'step5.php: unknown choice of action='.$action.
' in create lock file seaction');
633if ($error && isset($argv[1])) {
640pFooter(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.
getDoliDBInstance($type, $host, $user, $pass, $name, $port, $forcenew=false)
Return a DoliDB instance (database handler).
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
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).
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.
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.