40define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
41include_once
'inc.php';
69require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
70require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
71require_once $dolibarr_main_document_root.
'/core/lib/functions2.lib.php';
74@phan-var-force ?string $modulesdir
75@phan-var-force ?string $dolibarr_main_db_encryption
76@phan-var-force ?string $dolibarr_main_db_cryptkey
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]);
89$targetversion = DOL_VERSION;
90if (!empty($action) && preg_match(
'/upgrade/i', $action)) {
92 $tmp = explode(
'_', $action, 2);
93 if ($tmp[0] ==
'upgrade') {
94 if (!empty($tmp[1])) {
95 $targetversion = $tmp[1];
97 $targetversion = DOL_VERSION;
102$langs->loadLangs(array(
"admin",
"install"));
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]);
110$useforcedwizard =
false;
111$forcedfile =
"./install.forced.php";
112if (
$conffile ==
"/etc/dolibarr/conf.php") {
113 $forcedfile =
"/etc/dolibarr/install.forced.php";
115if (@file_exists($forcedfile)) {
116 $useforcedwizard =
true;
117 include_once $forcedfile;
139 if ($force_install_noedit == 2) {
140 if (!empty($force_install_dolibarrlogin)) {
141 $login = $force_install_dolibarrlogin;
146$force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (
GETPOST(
'installlock',
'aZ09') ?
GETPOST(
'installlock',
'aZ09') : (empty($argv[8]) ?
'' : $argv[8])));
150if (@$force_install_noedit == 2 && isset($force_install_dolibarrpassword)) {
151 $pass = $force_install_dolibarrpassword;
152 $pass_verif = $force_install_dolibarrpassword;
166if ($action ==
"set") {
167 if ($pass != $pass_verif) {
168 header(
"Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
173 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
178 header(
"Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
181 if ($pass ===
'**********' || $pass_verif ==
'**********') {
182 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
194pHeader($langs->trans(
"DolibarrSetup"),
"step5",
'set',
'',
'',
'main-inside main-inside-borderbottom no-bottom');
198if (empty($versionfrom) && empty($versionto) && !is_writable(
$conffile)) {
199 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
200 pFooter(1, $setuplang,
'jscheckparam');
205if (!isset($modulesdir) || !is_array($modulesdir)) {
206 $modulesdir = array();
209if ($action ==
"set" || empty($action) || preg_match(
'/upgrade/i', $action)) {
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;
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;
221 $dolibarr_main_db_pass =
dolDecrypt((
string) $dolibarr_main_db_pass);
223 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
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 :
'';
236 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
239 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
245 if ($action ==
"set") {
247 $modName =
'modUser';
248 $file = $modName.
".class.php";
250 include_once DOL_DOCUMENT_ROOT.
"/core/modules/".$file;
251 $objMod =
new $modName($db);
252 $result = $objMod->init();
254 print
"ERROR: failed to init module file = ".$file;
257 if ($db->connected) {
258 $conf->setValues($db);
260 if (defined(
'SYSLOG_FILE')) {
261 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
263 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
266 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
269 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
270 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
271 $resql = $db->query($sql);
273 $numrows = $db->num_rows($resql);
282 if (function_exists(
'password_hash')) {
283 dolibarr_set_const($db,
"MAIN_SECURITY_HASH_ALGO",
'password_hash',
'chaine', 0,
'', 0);
293 $createuser =
new User($db);
295 $createuser->admin = 1;
298 $newuser =
new User($db);
299 $newuser->lastname =
'SuperAdmin';
300 $newuser->firstname =
'';
301 $newuser->login = $login;
302 $newuser->pass = $pass;
304 $newuser->entity = 0;
306 $conf->global->USER_MAIL_REQUIRED = 0;
307 $conf->global->USER_PASSWORD_GENERATED =
'';
309 $result = $newuser->create($createuser, 1);
311 print $langs->trans(
"AdminLoginCreatedSuccessfuly", $login).
"<br>";
316 print
'<br><div class="warning">'.$newuser->error.
"</div><br>";
320 setEventMessages($langs->trans(
"FailedToCreateAdminLogin").
' '.$newuser->error,
null,
'errors');
322 print
'<br><div class="error">'.$langs->trans(
"FailedToCreateAdminLogin").
': '.$newuser->error.
'</div><br><br>';
323 print $langs->trans(
"ErrorGoBackAndCorrectParameters").
'<br><br>';
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)");
333 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
343 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_INSTALL'");
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)");
351 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
353 if ($useforcedwizard) {
355 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_REMOVE_INSTALL_WARNING'");
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);
378 $tmparray = explode(
',', $force_install_module);
381 $modNameLoaded = array();
384 $modulesdir[] = $dolibarr_main_document_root.
'/core/modules/';
386 foreach ($modulesdir as $dir) {
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);
396 if (!empty($modNameLoaded[$modName])) {
397 $mesg =
"Error: Module ".$modName.
" was found twice: Into ".$modNameLoaded[$modName].
" and ".$dir.
". You probably have an old file on your disk.<br>";
404 $res = include_once $dir.$file;
405 if (class_exists($modName)) {
406 $objMod =
new $modName($db);
407 $modNameLoaded[$modName] = $dir;
408 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
413 dol_syslog(
"Failed to load ".$dir.$file.
" ".$e->getMessage(), LOG_ERR);
422 if (!empty($tmparray)) {
423 foreach ($tmparray as $modtoactivate) {
424 $modtoactivatenew = preg_replace(
'/\.class\.php$/i',
'', $modtoactivate);
427 $file = $modtoactivatenew.
'.class.php';
431 $res = activateModule($modtoactivatenew, 1);
432 if (!empty($res[
'errors'])) {
433 print
'ERROR: failed to activateModule() file='.$file;
441 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
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)");
454 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
456 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
458 if ($db->connected) {
459 $conf->setValues($db);
461 if (defined(
'SYSLOG_FILE')) {
462 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
464 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
467 $tagdatabase =
false;
471 $mainversionlastupgradearray = preg_split(
'/[.-]/', $conf->global->MAIN_VERSION_LAST_UPGRADE);
472 $targetversionarray = preg_split(
'/[.-]/', $targetversion);
473 if (
versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
480 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_UPGRADE'");
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)");
488 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
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.');
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'");
500 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
514if ($action ==
"set") {
518 print
'<br>'.$langs->trans(
"SystemIsInstalled").
"<br>";
524 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
527 $lockfile = DOL_DATA_ROOT.
'/install.lock';
528 $fp = @fopen($lockfile,
"w");
530 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
531 $force_install_lockinstall =
'444';
533 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
535 dolChmod($lockfile, $force_install_lockinstall);
540 if (empty($createlock)) {
541 print
'<div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
546 print
'<span class="opacitymedium">'.$langs->trans(
"YouNeedToPersonalizeSetup").
"</span><br><br><br>";
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>';
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>';
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");
564} elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
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>";
574 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
576 $lockfile = DOL_DATA_ROOT.
'/install.lock';
577 $fp = @fopen($lockfile,
"w");
579 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
580 $force_install_lockinstall =
'444';
582 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
584 dolChmod($lockfile, $force_install_lockinstall);
589 if (empty($createlock)) {
590 print
'<br><div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
594 $unlockupgradefile = DOL_DATA_ROOT.
'/upgrade.unlock';
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>';
604 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="okinversed">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
606 print $langs->trans(
"VersionProgram").
': <b><span class="okinversed">'.DOL_VERSION.
'</span></b>';
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>';
615 dol_print_error(
null,
'step5.php: unknown choice of action='.$action.
' in create lock file seaction');
622if ($error && isset($argv[1])) {
629pFooter(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='')
Decode a string with a symmetric encryption.