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(
"DolibarrSetup").
' - '.$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');
140if (!isset($modulesdir) || !is_array($modulesdir)) {
141 $modulesdir = array();
144if ($action ==
"set" || empty($action) || preg_match(
'/upgrade/i', $action)) {
148 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
149 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
150 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
151 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
152 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
153 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
155 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
159 $conf->db->type = $dolibarr_main_db_type;
160 $conf->db->host = $dolibarr_main_db_host;
161 $conf->db->port = $dolibarr_main_db_port;
162 $conf->db->name = $dolibarr_main_db_name;
163 $conf->db->user = $dolibarr_main_db_user;
164 $conf->db->pass = $dolibarr_main_db_pass;
165 $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption : 0;
166 $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
168 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (
int) $conf->db->port);
171 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
177 if ($action ==
"set") {
179 $modName =
'modUser';
180 $file = $modName.
".class.php";
182 include_once DOL_DOCUMENT_ROOT.
"/core/modules/".$file;
183 $objMod =
new $modName($db);
184 $result = $objMod->init();
186 print
"ERROR: failed to init module file = ".$file;
189 if ($db->connected) {
190 $conf->setValues($db);
192 if (defined(
'SYSLOG_FILE')) {
193 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
195 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
198 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
201 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
202 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
203 $resql = $db->query($sql);
205 $numrows = $db->num_rows($resql);
208 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $conf->entity);
210 if (function_exists(
'password_hash')) {
211 dolibarr_set_const($db,
"MAIN_SECURITY_HASH_ALGO",
'password_hash',
'chaine', 0,
'', 0);
221 $createuser =
new User($db);
223 $createuser->admin = 1;
226 $newuser =
new User($db);
227 $newuser->lastname =
'SuperAdmin';
228 $newuser->firstname =
'';
229 $newuser->login = $login;
230 $newuser->pass = $pass;
232 $newuser->entity = 0;
234 $conf->global->USER_MAIL_REQUIRED = 0;
235 $conf->global->USER_PASSWORD_GENERATED =
'';
237 $result = $newuser->create($createuser, 1);
239 print $langs->trans(
"AdminLoginCreatedSuccessfuly", $login).
"<br>";
244 print
'<br><div class="warning">'.$newuser->error.
"</div><br>";
248 setEventMessages($langs->trans(
"FailedToCreateAdminLogin").
' '.$newuser->error,
null,
'errors');
250 print
'<br><div class="error">'.$langs->trans(
"FailedToCreateAdminLogin").
': '.$newuser->error.
'</div><br><br>';
251 print $langs->trans(
"ErrorGoBackAndCorrectParameters").
'<br><br>';
259 $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)");
261 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
271 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_INSTALL'");
275 $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)");
279 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
281 if ($useforcedwizard) {
283 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_REMOVE_INSTALL_WARNING'");
301 if (!empty($force_install_module)) {
302 if (!defined(
'DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
303 define(
'DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
306 $tmparray = explode(
',', $force_install_module);
309 $modNameLoaded = array();
312 $modulesdir[] = $dolibarr_main_document_root.
'/core/modules/';
314 foreach ($modulesdir as $dir) {
317 dol_syslog(
"Scan directory ".$dir.
" for module descriptor files (modXXX.class.php)");
318 $handle = @opendir($dir);
319 if (is_resource($handle)) {
320 while (($file = readdir($handle)) !==
false) {
321 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php') {
322 $modName = substr($file, 0,
dol_strlen($file) - 10);
324 if (!empty($modNameLoaded[$modName])) {
325 $mesg =
"Error: Module ".$modName.
" was found twice: Into ".$modNameLoaded[$modName].
" and ".$dir.
". You probably have an old file on your disk.<br>";
332 $res = include_once $dir.$file;
333 if (class_exists($modName)) {
334 $objMod =
new $modName($db);
335 $modNameLoaded[$modName] = $dir;
336 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
341 dol_syslog(
"Failed to load ".$dir.$file.
" ".$e->getMessage(), LOG_ERR);
350 if (!empty($tmparray)) {
351 foreach ($tmparray as $modtoactivate) {
352 $modtoactivatenew = preg_replace(
'/\.class\.php$/i',
'', $modtoactivate);
355 $file = $modtoactivatenew.
'.class.php';
360 if (!empty($res[
'errors'])) {
361 print
'ERROR: failed to activateModule() file='.$file;
369 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
376 $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)");
382 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
384 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
386 if ($db->connected) {
387 $conf->setValues($db);
389 if (defined(
'SYSLOG_FILE')) {
390 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
392 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
395 $tagdatabase =
false;
399 $mainversionlastupgradearray = preg_split(
'/[.-]/', $conf->global->MAIN_VERSION_LAST_UPGRADE);
400 $targetversionarray = preg_split(
'/[.-]/', $targetversion);
401 if (
versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
408 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_UPGRADE'");
412 $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)");
416 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
418 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.');
421 dolibarr_install_syslog(
'step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)');
422 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
428 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
442if ($action ==
"set") {
444 if (!
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE') || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
446 print
'<br>'.$langs->trans(
"SystemIsInstalled").
"<br>";
452 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
455 $lockfile = DOL_DATA_ROOT.
'/install.lock';
456 $fp = @fopen($lockfile,
"w");
458 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
459 $force_install_lockinstall =
'444';
461 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
463 dolChmod($lockfile, $force_install_lockinstall);
468 if (empty($createlock)) {
469 print
'<div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
474 print $langs->trans(
"YouNeedToPersonalizeSetup").
"<br><br><br>";
476 print
'<div class="center">> <a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
477 print
'<span class="fas fa-external-link-alt"></span> '.$langs->trans(
"GoToSetupArea");
478 print
'</a></div><br>';
481 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
482 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b><br>';
483 print $langs->trans(
"MigrationNotFinished").
'<br>';
486 print
'<div class="center"><a href="'.$dolibarr_main_url_root.
'/install/index.php">';
487 print
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
491} elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
493 if (!
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE') || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
495 print
'<img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/checklist.svg" width="20" alt="Configuration">';
496 print
' <span class="valignmiddle">'.$langs->trans(
"SystemIsUpgraded").
"</span><br>";
501 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
503 $lockfile = DOL_DATA_ROOT.
'/install.lock';
504 $fp = @fopen($lockfile,
"w");
506 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
507 $force_install_lockinstall =
'444';
509 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
511 dolChmod($lockfile, $force_install_lockinstall);
516 if (empty($createlock)) {
517 print
'<br><div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
521 $unlockupgradefile = DOL_DATA_ROOT.
'/upgrade.unlock';
526 $morehtml =
'<br><div class="center"><a class="buttonGoToupgrade" href="../index.php?mainmenu=home'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
527 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToDolibarr").
'...';
528 $morehtml .=
'</a></div><br>';
531 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
532 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b>';
536 $morehtml =
'<br><div class="center"><a class="buttonGoToupgrade" href="../install/index.php">';
537 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
538 $morehtml .=
'</a></div>';
541 dol_print_error(
null,
'step5.php: unknown choice of action='.$action.
' in create lock file seaction');
548if ($error && isset($argv[1])) {
555pFooter(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_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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.