39define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
40include_once
'inc.php';
41if (file_exists($conffile)) {
42 include_once $conffile;
44require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
45require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
46require_once $dolibarr_main_document_root.
'/core/lib/functions2.lib.php';
50$versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
51$versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
52$setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[3]) ?
'auto' : $argv[3]);
53$langs->setDefaultLang($setuplang);
54$action =
GETPOST(
'action',
'alpha') ?
GETPOST(
'action',
'alpha') : (empty($argv[4]) ?
'' : $argv[4]);
58$targetversion = DOL_VERSION;
59if (!empty($action) && preg_match(
'/upgrade/i', $action)) {
61 $tmp = explode(
'_', $action, 2);
62 if ($tmp[0] ==
'upgrade') {
63 if (!empty($tmp[1])) {
64 $targetversion = $tmp[1];
66 $targetversion = DOL_VERSION;
71$langs->loadLangs(array(
"admin",
"install"));
73$login =
GETPOST(
'login',
'alpha') ?
GETPOST(
'login',
'alpha') : (empty($argv[5]) ?
'' : $argv[5]);
74$pass =
GETPOST(
'pass',
'alpha') ?
GETPOST(
'pass',
'alpha') : (empty($argv[6]) ?
'' : $argv[6]);
75$pass_verif =
GETPOST(
'pass_verif',
'alpha') ?
GETPOST(
'pass_verif',
'alpha') : (empty($argv[7]) ?
'' : $argv[7]);
76$force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (
GETPOST(
'installlock',
'aZ09') ?
GETPOST(
'installlock',
'aZ09') : (empty($argv[8]) ?
'' : $argv[8])));
80$useforcedwizard =
false;
81$forcedfile =
"./install.forced.php";
82if ($conffile ==
"/etc/dolibarr/conf.php") {
83 $forcedfile =
"/etc/dolibarr/install.forced.php";
85if (@file_exists($forcedfile)) {
86 $useforcedwizard =
true;
87 include_once $forcedfile;
89 if ($force_install_noedit == 2) {
90 if (!empty($force_install_dolibarrlogin)) {
91 $login = $force_install_dolibarrlogin;
105if ($action ==
"set") {
106 if ($pass <> $pass_verif) {
107 header(
"Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
112 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
117 header(
"Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
129pHeader($langs->trans(
"SetupEnd"),
"step5",
'set',
'',
'',
'main-inside main-inside-borderbottom');
133if (empty($versionfrom) && empty($versionto) && !is_writable($conffile)) {
134 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
135 pFooter(1, $setuplang,
'jscheckparam');
139if ($action ==
"set" || empty($action) || preg_match(
'/upgrade/i', $action)) {
143 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
144 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
145 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
146 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
147 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
148 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
150 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
154 $conf->db->type = $dolibarr_main_db_type;
155 $conf->db->host = $dolibarr_main_db_host;
156 $conf->db->port = $dolibarr_main_db_port;
157 $conf->db->name = $dolibarr_main_db_name;
158 $conf->db->user = $dolibarr_main_db_user;
159 $conf->db->pass = $dolibarr_main_db_pass;
160 $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption :
'';
161 $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
163 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
166 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
172 if ($action ==
"set") {
174 $modName =
'modUser';
175 $file = $modName.
".class.php";
177 include_once DOL_DOCUMENT_ROOT.
"/core/modules/".$file;
178 $objMod =
new $modName($db);
179 $result = $objMod->init();
181 print
"ERROR: failed to init module file = ".$file;
184 if ($db->connected) {
185 $conf->setValues($db);
187 if (defined(
'SYSLOG_FILE')) {
188 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
190 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
193 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
196 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
198 $resql = $db->query($sql);
200 $numrows = $db->num_rows($resql);
203 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $conf->entity);
205 if (function_exists(
'password_hash')) {
206 dolibarr_set_const($db,
"MAIN_SECURITY_HASH_ALGO",
'password_hash',
'chaine', 0,
'', 0);
212 dolibarr_install_syslog(
'step5: DATABASE_PWD_ENCRYPTED = '.$conf->global->DATABASE_PWD_ENCRYPTED.
' MAIN_SECURITY_HASH_ALGO = '.$conf->global->MAIN_SECURITY_HASH_ALGO, LOG_INFO);
216 $createuser =
new User($db);
218 $createuser->admin = 1;
221 $newuser =
new User($db);
222 $newuser->lastname =
'SuperAdmin';
223 $newuser->firstname =
'';
224 $newuser->login = $login;
225 $newuser->pass = $pass;
227 $newuser->entity = 0;
229 $conf->global->USER_MAIL_REQUIRED = 0;
230 $conf->global->USER_PASSWORD_GENERATED =
'';
232 $result = $newuser->create($createuser, 1);
234 print $langs->trans(
"AdminLoginCreatedSuccessfuly", $login).
"<br>";
239 print
'<br><div class="warning">'.$newuser->error.
"</div><br>";
243 setEventMessages($langs->trans(
"FailedToCreateAdminLogin").
' '.$newuser->error,
null,
'errors');
245 print
'<br><div class="error">'.$langs->trans(
"FailedToCreateAdminLogin").
': '.$newuser->error.
'</div><br><br>';
246 print $langs->trans(
"ErrorGoBackAndCorrectParameters").
'<br><br>';
254 $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)");
256 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
266 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_INSTALL'");
270 $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)");
274 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
276 if ($useforcedwizard) {
278 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_REMOVE_INSTALL_WARNING'");
296 if (!empty($force_install_module)) {
297 if (!defined(
'DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
298 define(
'DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
301 $tmparray = explode(
',', $force_install_module);
304 $modNameLoaded = array();
307 $modulesdir[] = $dolibarr_main_document_root.
'/core/modules/';
309 foreach ($modulesdir as $dir) {
312 dol_syslog(
"Scan directory ".$dir.
" for module descriptor files (modXXX.class.php)");
313 $handle = @opendir($dir);
314 if (is_resource($handle)) {
315 while (($file = readdir($handle)) !==
false) {
316 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php') {
317 $modName = substr($file, 0,
dol_strlen($file) - 10);
319 if (!empty($modNameLoaded[$modName])) {
320 $mesg =
"Error: Module ".$modName.
" was found twice: Into ".$modNameLoaded[$modName].
" and ".$dir.
". You probably have an old file on your disk.<br>";
327 $res = include_once $dir.$file;
328 if (class_exists($modName)) {
329 $objMod =
new $modName($db);
330 $modNameLoaded[$modName] = $dir;
331 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
336 dol_syslog(
"Failed to load ".$dir.$file.
" ".$e->getMessage(), LOG_ERR);
345 if (!empty($tmparray)) {
346 foreach ($tmparray as $modtoactivate) {
347 $modtoactivatenew = preg_replace(
'/\.class\.php$/i',
'', $modtoactivate);
350 $file = $modtoactivatenew.
'.class.php';
355 if (!empty($res[
'errors'])) {
356 print
'ERROR: failed to activateModule() file='.$file;
364 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
372 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
374 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
376 if ($db->connected) {
377 $conf->setValues($db);
379 if (defined(
'SYSLOG_FILE')) {
380 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
382 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
385 $tagdatabase =
false;
386 if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE)) {
389 $mainversionlastupgradearray = preg_split(
'/[.-]/', $conf->global->MAIN_VERSION_LAST_UPGRADE);
390 $targetversionarray = preg_split(
'/[.-]/', $targetversion);
391 if (
versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
398 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_UPGRADE'");
402 $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)");
406 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
408 dolibarr_install_syslog(
'step5: we run an upgrade to version '.$targetversion.
' but database was already upgraded to '.$conf->global->MAIN_VERSION_LAST_UPGRADE.
'. We keep MAIN_VERSION_LAST_UPGRADE as it is.');
411 dolibarr_install_syslog(
'step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)');
412 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
420 $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)");
423 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
437if ($action ==
"set") {
439 if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
441 print
'<br>'.$langs->trans(
"SystemIsInstalled").
"<br>";
447 if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE)) {
450 $lockfile = DOL_DATA_ROOT.
'/install.lock';
451 $fp = @fopen($lockfile,
"w");
453 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
454 $force_install_lockinstall =
'444';
456 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
458 dolChmod($lockfile, $force_install_lockinstall);
463 if (empty($createlock)) {
464 print
'<div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
469 print $langs->trans(
"YouNeedToPersonalizeSetup").
"<br><br><br>";
471 print
'<div class="center">> <a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
472 print
'<span class="fas fa-external-link-alt"></span> '.$langs->trans(
"GoToSetupArea");
473 print
'</a></div><br>';
476 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">'.$conf->global->MAIN_VERSION_LAST_UPGRADE.
'</span></b><br>';
477 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b><br>';
478 print $langs->trans(
"MigrationNotFinished").
'<br>';
481 print
'<div class="center"><a href="'.$dolibarr_main_url_root.
'/install/index.php">';
482 print
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
486} elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
488 if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
490 print
'<img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/checklist.svg" width="20" alt="Configuration">';
491 print
' <span class="valignmiddle">'.$langs->trans(
"SystemIsUpgraded").
"</span><br>";
496 if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE)) {
498 $lockfile = DOL_DATA_ROOT.
'/install.lock';
499 $fp = @fopen($lockfile,
"w");
501 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
502 $force_install_lockinstall =
'444';
504 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
506 dolChmod($lockfile, $force_install_lockinstall);
511 if (empty($createlock)) {
512 print
'<br><div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
516 $unlockupgradefile = DOL_DATA_ROOT.
'/upgrade.unlock';
521 $morehtml =
'<br><div class="center"><a href="../index.php?mainmenu=home'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
522 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToDolibarr").
'...';
523 $morehtml .=
'</a></div><br>';
526 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">'.$conf->global->MAIN_VERSION_LAST_UPGRADE.
'</span></b><br>';
527 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b>';
531 $morehtml =
'<br><div class="center"><a href="../install/index.php">';
532 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
533 $morehtml .=
'</a></div>';
536 dol_print_error(
'',
'step5.php: unknown choice of action='.$action.
' in create lock file seaction');
543if ($error && isset($argv[1])) {
550pFooter(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).
activateModule($value, $withdeps=1, $noconfverification=0)
Enable a module.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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.