29 include_once
'inc.php';
30 if (file_exists($conffile)) {
31 include_once $conffile;
33 require_once $dolibarr_main_document_root.
'/core/lib/admin.lib.php';
34 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
38 $versionfrom =
GETPOST(
"versionfrom",
'alpha', 3) ?
GETPOST(
"versionfrom",
'alpha', 3) : (empty($argv[1]) ?
'' : $argv[1]);
39 $versionto =
GETPOST(
"versionto",
'alpha', 3) ?
GETPOST(
"versionto",
'alpha', 3) : (empty($argv[2]) ?
'' : $argv[2]);
40 $setuplang =
GETPOST(
'selectlang',
'aZ09', 3) ?
GETPOST(
'selectlang',
'aZ09', 3) : (empty($argv[3]) ?
'auto' : $argv[3]);
41 $langs->setDefaultLang($setuplang);
42 $action =
GETPOST(
'action',
'alpha') ?
GETPOST(
'action',
'alpha') : (empty($argv[4]) ?
'' : $argv[4]);
46 $targetversion = DOL_VERSION;
47 if (!empty($action) && preg_match(
'/upgrade/i', $action)) {
49 $tmp = explode(
'_', $action, 2);
50 if ($tmp[0] ==
'upgrade') {
51 if (!empty($tmp[1])) {
52 $targetversion = $tmp[1];
54 $targetversion = DOL_VERSION;
59 $langs->loadLangs(array(
"admin",
"install"));
61 $login =
GETPOST(
'login',
'alpha') ?
GETPOST(
'login',
'alpha') : (empty($argv[5]) ?
'' : $argv[5]);
62 $pass =
GETPOST(
'pass',
'alpha') ?
GETPOST(
'pass',
'alpha') : (empty($argv[6]) ?
'' : $argv[6]);
63 $pass_verif =
GETPOST(
'pass_verif',
'alpha') ?
GETPOST(
'pass_verif',
'alpha') : (empty($argv[7]) ?
'' : $argv[7]);
64 $force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (
GETPOST(
'installlock',
'aZ09') ?
GETPOST(
'installlock',
'aZ09') : (empty($argv[8]) ?
'' : $argv[8])));
68 $useforcedwizard =
false;
69 $forcedfile =
"./install.forced.php";
70 if ($conffile ==
"/etc/dolibarr/conf.php") {
71 $forcedfile =
"/etc/dolibarr/install.forced.php";
73 if (@file_exists($forcedfile)) {
74 $useforcedwizard =
true;
75 include_once $forcedfile;
77 if ($force_install_noedit == 2) {
78 if (!empty($force_install_dolibarrlogin)) {
79 $login = $force_install_dolibarrlogin;
93 if ($action ==
"set") {
94 if ($pass <> $pass_verif) {
95 header(
"Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
100 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
105 header(
"Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
117 pHeader($langs->trans(
"SetupEnd"),
"step5",
'set',
'',
'',
'main-inside main-inside-borderbottom');
121 if (empty($versionfrom) && empty($versionto) && !is_writable($conffile)) {
122 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
123 pFooter(1, $setuplang,
'jscheckparam');
127 if ($action ==
"set" || empty($action) || preg_match(
'/upgrade/i', $action)) {
131 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
132 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
133 if (preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
134 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
135 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
136 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
138 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
142 $conf->db->type = $dolibarr_main_db_type;
143 $conf->db->host = $dolibarr_main_db_host;
144 $conf->db->port = $dolibarr_main_db_port;
145 $conf->db->name = $dolibarr_main_db_name;
146 $conf->db->user = $dolibarr_main_db_user;
147 $conf->db->pass = $dolibarr_main_db_pass;
148 $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption :
'';
149 $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
151 $db =
getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
154 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
160 if ($action ==
"set") {
162 $modName =
'modUser';
163 $file = $modName.
".class.php";
165 include_once DOL_DOCUMENT_ROOT.
"/core/modules/".$file;
166 $objMod =
new $modName($db);
167 $result = $objMod->init();
169 print
"ERROR: failed to init module file = ".$file;
172 if ($db->connected) {
173 $conf->setValues($db);
175 if (defined(
'SYSLOG_FILE')) {
176 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
178 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
181 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
184 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
185 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
186 $resql = $db->query($sql);
188 $numrows = $db->num_rows(
$resql);
191 dolibarr_set_const($db,
"DATABASE_PWD_ENCRYPTED",
"1",
'chaine', 0,
'', $conf->entity);
193 if (function_exists(
'password_hash')) {
194 dolibarr_set_const($db,
"MAIN_SECURITY_HASH_ALGO",
'password_hash',
'chaine', 0,
'', 0);
200 dolibarr_install_syslog(
'step5: DATABASE_PWD_ENCRYPTED = '.$conf->global->DATABASE_PWD_ENCRYPTED.
' MAIN_SECURITY_HASH_ALGO = '.$conf->global->MAIN_SECURITY_HASH_ALGO, LOG_INFO);
204 $createuser =
new User($db);
206 $createuser->admin = 1;
209 $newuser =
new User($db);
210 $newuser->lastname =
'SuperAdmin';
211 $newuser->firstname =
'';
212 $newuser->login = $login;
213 $newuser->pass = $pass;
215 $newuser->entity = 0;
217 $conf->global->USER_MAIL_REQUIRED = 0;
218 $conf->global->USER_PASSWORD_GENERATED =
'';
220 $result = $newuser->create($createuser, 1);
222 print $langs->trans(
"AdminLoginCreatedSuccessfuly", $login).
"<br>";
227 print
'<br><div class="warning">'.$newuser->error.
"</div><br>";
231 setEventMessages($langs->trans(
"FailedToCreateAdminLogin").
' '.$newuser->error,
null,
'errors');
233 print
'<br><div class="error">'.$langs->trans(
"FailedToCreateAdminLogin").
': '.$newuser->error.
'</div><br><br>';
234 print $langs->trans(
"ErrorGoBackAndCorrectParameters").
'<br><br>';
242 $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)");
244 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
254 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_INSTALL'");
258 $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)");
262 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
264 if ($useforcedwizard) {
266 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_REMOVE_INSTALL_WARNING'");
270 $resql = $db->query(
"INSERT INTO ".MAIN_DB_PREFIX.
"const(name,value,type,visible,note,entity) values(".$db->encrypt(
'MAIN_REMOVE_INSTALL_WARNING').
", ".$db->encrypt(1).
", 'chaine', 1, 'Disable install warnings', 0)");
274 $conf->global->MAIN_REMOVE_INSTALL_WARNING = 1;
278 if (!empty($force_install_module)) {
279 if (!defined(
'DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
280 define(
'DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
283 $tmparray = explode(
',', $force_install_module);
284 foreach ($tmparray as $modtoactivate) {
285 $modtoactivatenew = preg_replace(
'/\.class\.php$/i',
'', $modtoactivate);
286 print $langs->trans(
"ActivateModule", $modtoactivatenew).
'<br>';
288 $file = $modtoactivatenew.
'.class.php';
293 if (!empty($res[
'errors'])) {
294 print
'ERROR: failed to activateModule() file='.$file;
300 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
"='MAIN_NOT_INSTALLED'");
308 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
310 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
312 if ($db->connected) {
313 $conf->setValues($db);
315 if (defined(
'SYSLOG_FILE')) {
316 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
318 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
321 $tagdatabase =
false;
322 if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE)) {
325 $mainversionlastupgradearray = preg_split(
'/[.-]/', $conf->global->MAIN_VERSION_LAST_UPGRADE);
326 $targetversionarray = preg_split(
'/[.-]/', $targetversion);
327 if (
versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
334 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_UPGRADE'");
338 $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)");
342 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
344 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.');
347 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
354 $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)");
365 if ($action ==
"set") {
367 if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
369 print
'<br>'.$langs->trans(
"SystemIsInstalled").
"<br>";
373 if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE)) {
375 $lockfile = DOL_DATA_ROOT.
'/install.lock';
376 $fp = @fopen($lockfile,
"w");
378 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
379 $force_install_lockinstall = 444;
381 fwrite($fp,
"This is a lock file to prevent use of install pages (set with permission ".$force_install_lockinstall.
")");
383 @chmod($lockfile, octdec($force_install_lockinstall));
387 if (empty($createlock)) {
388 print
'<div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
393 print $langs->trans(
"YouNeedToPersonalizeSetup").
"<br><br><br>";
395 print
'<div class="center">> <a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
396 print
'<span class="fas fa-external-link-alt"></span> '.$langs->trans(
"GoToSetupArea");
397 print
'</a></div><br>';
400 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">'.$conf->global->MAIN_VERSION_LAST_UPGRADE.
'</span></b><br>';
401 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b><br>';
402 print $langs->trans(
"MigrationNotFinished").
'<br>';
405 print
'<div class="center"><a href="'.$dolibarr_main_url_root.
'/install/index.php">';
406 print
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
410 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
412 if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
414 print
'<img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/checklist.svg" width="20" alt="Configuration"> <span class="valignmiddle">'.$langs->trans(
"SystemIsUpgraded").
"</span><br>";
418 if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE)) {
420 $lockfile = DOL_DATA_ROOT.
'/install.lock';
421 $fp = @fopen($lockfile,
"w");
423 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
424 $force_install_lockinstall = 444;
426 fwrite($fp,
"This is a lock file to prevent use of install pages (set with permission ".$force_install_lockinstall.
")");
428 @chmod($lockfile, octdec($force_install_lockinstall));
432 if (empty($createlock)) {
433 print
'<br><div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
438 $morehtml =
'<br><div class="center"><a href="../index.php?mainmenu=home'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
439 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToDolibarr").
'...';
440 $morehtml .=
'</a></div><br>';
443 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">'.$conf->global->MAIN_VERSION_LAST_UPGRADE.
'</span></b><br>';
444 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b>';
448 $morehtml =
'<br><div class="center"><a href="../install/index.php">';
449 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
450 $morehtml .=
'</a></div>';
453 dol_print_error(
'',
'step5.php: unknown choice of action='.$action.
' in create lock file seaction');
460 if ($error && isset($argv[1])) {
467 pFooter(1, $setuplang,
'', 0, $morehtml);