40define(
'ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
41include_once
'inc.php';
48if (file_exists($conffile)) {
49 include_once $conffile;
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',
'alpha') ?
GETPOST(
'pass',
'alpha') : (empty($argv[6]) ?
'' : $argv[6]);
105$pass_verif =
GETPOST(
'pass_verif',
'alpha') ?
GETPOST(
'pass_verif',
'alpha') : (empty($argv[7]) ?
'' : $argv[7]);
106$force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (
GETPOST(
'installlock',
'aZ09') ?
GETPOST(
'installlock',
'aZ09') : (empty($argv[8]) ?
'' : $argv[8])));
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;
138 if ($force_install_noedit == 2) {
139 if (!empty($force_install_dolibarrlogin)) {
140 $login = $force_install_dolibarrlogin;
155if ($action ==
"set") {
156 if ($pass != $pass_verif) {
157 header(
"Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
162 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
167 header(
"Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
179pHeader($langs->trans(
"DolibarrSetup").
' - '.$langs->trans(
"SetupEnd"),
"step5",
'set',
'',
'',
'main-inside main-inside-borderbottom no-bottom');
183if (empty($versionfrom) && empty($versionto) && !is_writable($conffile)) {
184 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
185 pFooter(1, $setuplang,
'jscheckparam');
190if (!isset($modulesdir) || !is_array($modulesdir)) {
191 $modulesdir = array();
194if ($action ==
"set" || empty($action) || preg_match(
'/upgrade/i', $action)) {
198 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/(crypted|dolcrypt):/i', (
string) $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
199 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
200 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', (
string) $dolibarr_main_db_pass)) {
201 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', (
string) $dolibarr_main_db_pass);
202 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
203 $dolibarr_main_db_pass =
dol_decode((
string) $dolibarr_main_db_pass);
204 } elseif (preg_match(
'/dolcrypt:/i', (
string) $dolibarr_main_db_pass)) {
205 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
206 $dolibarr_main_db_pass =
dolDecrypt((
string) $dolibarr_main_db_pass);
208 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
212 $conf->db->type = $dolibarr_main_db_type;
213 $conf->db->host = $dolibarr_main_db_host;
214 $conf->db->port = $dolibarr_main_db_port;
215 $conf->db->name = $dolibarr_main_db_name;
216 $conf->db->user = $dolibarr_main_db_user;
217 $conf->db->pass = $dolibarr_main_db_pass;
218 $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption : 0;
219 $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
224 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
230 if ($action ==
"set") {
232 $modName =
'modUser';
233 $file = $modName.
".class.php";
235 include_once DOL_DOCUMENT_ROOT.
"/core/modules/".$file;
236 $objMod =
new $modName($db);
237 $result = $objMod->init();
239 print
"ERROR: failed to init module file = ".$file;
242 if ($db->connected) {
243 $conf->setValues($db);
245 if (defined(
'SYSLOG_FILE')) {
246 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
248 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
251 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
254 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
255 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
256 $resql = $db->query($sql);
258 $numrows = $db->num_rows($resql);
263 if (function_exists(
'password_hash')) {
264 dolibarr_set_const($db,
"MAIN_SECURITY_HASH_ALGO",
'password_hash',
'chaine', 0,
'', 0);
274 $createuser =
new User($db);
276 $createuser->admin = 1;
279 $newuser =
new User($db);
280 $newuser->lastname =
'SuperAdmin';
281 $newuser->firstname =
'';
282 $newuser->login = $login;
283 $newuser->pass = $pass;
285 $newuser->entity = 0;
287 $conf->global->USER_MAIL_REQUIRED = 0;
288 $conf->global->USER_PASSWORD_GENERATED =
'';
290 $result = $newuser->create($createuser, 1);
292 print $langs->trans(
"AdminLoginCreatedSuccessfuly", $login).
"<br>";
297 print
'<br><div class="warning">'.$newuser->error.
"</div><br>";
301 setEventMessages($langs->trans(
"FailedToCreateAdminLogin").
' '.$newuser->error,
null,
'errors');
303 print
'<br><div class="error">'.$langs->trans(
"FailedToCreateAdminLogin").
': '.$newuser->error.
'</div><br><br>';
304 print $langs->trans(
"ErrorGoBackAndCorrectParameters").
'<br><br>';
312 $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)");
314 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
324 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_INSTALL'");
328 $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)");
332 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
334 if ($useforcedwizard) {
336 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_REMOVE_INSTALL_WARNING'");
354 if (!empty($force_install_module)) {
355 if (!defined(
'DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
356 define(
'DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
359 $tmparray = explode(
',', $force_install_module);
362 $modNameLoaded = array();
365 $modulesdir[] = $dolibarr_main_document_root.
'/core/modules/';
367 foreach ($modulesdir as $dir) {
370 dol_syslog(
"Scan directory ".$dir.
" for module descriptor files (modXXX.class.php)");
371 $handle = @opendir($dir);
372 if (is_resource($handle)) {
373 while (($file = readdir($handle)) !==
false) {
374 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php') {
375 $modName = substr($file, 0,
dol_strlen($file) - 10);
377 if (!empty($modNameLoaded[$modName])) {
378 $mesg =
"Error: Module ".$modName.
" was found twice: Into ".$modNameLoaded[$modName].
" and ".$dir.
". You probably have an old file on your disk.<br>";
385 $res = include_once $dir.$file;
386 if (class_exists($modName)) {
387 $objMod =
new $modName($db);
388 $modNameLoaded[$modName] = $dir;
389 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
394 dol_syslog(
"Failed to load ".$dir.$file.
" ".$e->getMessage(), LOG_ERR);
403 if (!empty($tmparray)) {
404 foreach ($tmparray as $modtoactivate) {
405 $modtoactivatenew = preg_replace(
'/\.class\.php$/i',
'', $modtoactivate);
408 $file = $modtoactivatenew.
'.class.php';
413 if (!empty($res[
'errors'])) {
414 print
'ERROR: failed to activateModule() file='.$file;
422 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
429 $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)");
435 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
437 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
439 if ($db->connected) {
440 $conf->setValues($db);
442 if (defined(
'SYSLOG_FILE')) {
443 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
445 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
448 $tagdatabase =
false;
452 $mainversionlastupgradearray = preg_split(
'/[.-]/',
$conf->global->MAIN_VERSION_LAST_UPGRADE);
453 $targetversionarray = preg_split(
'/[.-]/', $targetversion);
454 if (
versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
461 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_UPGRADE'");
465 $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)");
469 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
471 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.');
474 dolibarr_install_syslog(
'step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)');
475 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
481 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
495if ($action ==
"set") {
497 if (!
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE') || (
$conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
499 print
'<br>'.$langs->trans(
"SystemIsInstalled").
"<br>";
505 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
508 $lockfile = DOL_DATA_ROOT.
'/install.lock';
509 $fp = @fopen($lockfile,
"w");
511 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
512 $force_install_lockinstall =
'444';
514 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
516 dolChmod($lockfile, $force_install_lockinstall);
521 if (empty($createlock)) {
522 print
'<div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
527 print $langs->trans(
"YouNeedToPersonalizeSetup").
"<br><br><br>";
529 print
'<div class="center">> <a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
530 print
'<span class="fas fa-external-link-alt"></span> '.$langs->trans(
"GoToSetupArea");
531 print
'</a></div><br>';
534 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
535 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b><br>';
536 print $langs->trans(
"MigrationNotFinished").
'<br>';
539 print
'<div class="center"><a href="'.$dolibarr_main_url_root.
'/install/index.php">';
540 print
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
544} elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
548 print
'<img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/checklist.svg" width="30" alt="Configuration">';
549 print
' <span class="valignmiddle">'.$langs->trans(
"SystemIsUpgraded").
"</span><br>";
554 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
556 $lockfile = DOL_DATA_ROOT.
'/install.lock';
557 $fp = @fopen($lockfile,
"w");
559 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
560 $force_install_lockinstall =
'444';
562 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
564 dolChmod($lockfile, $force_install_lockinstall);
569 if (empty($createlock)) {
570 print
'<br><div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
574 $unlockupgradefile = DOL_DATA_ROOT.
'/upgrade.unlock';
579 $morehtml =
'<br><div class="center"><a class="buttonGoToupgrade" href="../index.php?mainmenu=home'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
580 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToDolibarr").
'...';
581 $morehtml .=
'</a></div><br>';
584 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
585 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b>';
589 $morehtml =
'<br><div class="center"><a class="buttonGoToupgrade" href="../install/index.php">';
590 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
591 $morehtml .=
'</a></div>';
594 dol_print_error(
null,
'step5.php: unknown choice of action='.$action.
' in create lock file seaction');
601if ($error && isset($argv[1])) {
608pFooter(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), 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.
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.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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_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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.