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;
106if ($action ==
"set") {
107 if ($pass != $pass_verif) {
108 header(
"Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
113 header(
"Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
118 header(
"Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ?
'&login='.$login :
''));
130pHeader($langs->trans(
"DolibarrSetup").
' - '.$langs->trans(
"SetupEnd"),
"step5",
'set',
'',
'',
'main-inside main-inside-borderbottom');
134if (empty($versionfrom) && empty($versionto) && !is_writable($conffile)) {
135 print $langs->trans(
"ConfFileIsNotWritable", $conffiletoshow);
136 pFooter(1, $setuplang,
'jscheckparam');
141if (!isset($modulesdir) || !is_array($modulesdir)) {
142 $modulesdir = array();
145if ($action ==
"set" || empty($action) || preg_match(
'/upgrade/i', $action)) {
149 if ((!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
150 require_once $dolibarr_main_document_root.
'/core/lib/security.lib.php';
151 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
152 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
153 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
154 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
156 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
160 $conf->db->type = $dolibarr_main_db_type;
161 $conf->db->host = $dolibarr_main_db_host;
162 $conf->db->port = $dolibarr_main_db_port;
163 $conf->db->name = $dolibarr_main_db_name;
164 $conf->db->user = $dolibarr_main_db_user;
165 $conf->db->pass = $dolibarr_main_db_pass;
166 $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption : 0;
167 $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey :
'';
172 include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
178 if ($action ==
"set") {
180 $modName =
'modUser';
181 $file = $modName.
".class.php";
183 include_once DOL_DOCUMENT_ROOT.
"/core/modules/".$file;
184 $objMod =
new $modName($db);
185 $result = $objMod->init();
187 print
"ERROR: failed to init module file = ".$file;
190 if ($db->connected) {
191 $conf->setValues($db);
193 if (defined(
'SYSLOG_FILE')) {
194 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
196 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
199 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
202 $sql =
"SELECT u.rowid, u.pass, u.pass_crypted";
203 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
204 $resql = $db->query($sql);
206 $numrows = $db->num_rows($resql);
211 if (function_exists(
'password_hash')) {
212 dolibarr_set_const($db,
"MAIN_SECURITY_HASH_ALGO",
'password_hash',
'chaine', 0,
'', 0);
222 $createuser =
new User($db);
224 $createuser->admin = 1;
227 $newuser =
new User($db);
228 $newuser->lastname =
'SuperAdmin';
229 $newuser->firstname =
'';
230 $newuser->login = $login;
231 $newuser->pass = $pass;
233 $newuser->entity = 0;
235 $conf->global->USER_MAIL_REQUIRED = 0;
236 $conf->global->USER_PASSWORD_GENERATED =
'';
238 $result = $newuser->create($createuser, 1);
240 print $langs->trans(
"AdminLoginCreatedSuccessfuly", $login).
"<br>";
245 print
'<br><div class="warning">'.$newuser->error.
"</div><br>";
249 setEventMessages($langs->trans(
"FailedToCreateAdminLogin").
' '.$newuser->error,
null,
'errors');
251 print
'<br><div class="error">'.$langs->trans(
"FailedToCreateAdminLogin").
': '.$newuser->error.
'</div><br><br>';
252 print $langs->trans(
"ErrorGoBackAndCorrectParameters").
'<br><br>';
260 $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)");
262 $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
272 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_INSTALL'");
276 $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)");
280 $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
282 if ($useforcedwizard) {
284 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_REMOVE_INSTALL_WARNING'");
302 if (!empty($force_install_module)) {
303 if (!defined(
'DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
304 define(
'DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
307 $tmparray = explode(
',', $force_install_module);
310 $modNameLoaded = array();
313 $modulesdir[] = $dolibarr_main_document_root.
'/core/modules/';
315 foreach ($modulesdir as $dir) {
318 dol_syslog(
"Scan directory ".$dir.
" for module descriptor files (modXXX.class.php)");
319 $handle = @opendir($dir);
320 if (is_resource($handle)) {
321 while (($file = readdir($handle)) !==
false) {
322 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php') {
323 $modName = substr($file, 0,
dol_strlen($file) - 10);
325 if (!empty($modNameLoaded[$modName])) {
326 $mesg =
"Error: Module ".$modName.
" was found twice: Into ".$modNameLoaded[$modName].
" and ".$dir.
". You probably have an old file on your disk.<br>";
333 $res = include_once $dir.$file;
334 if (class_exists($modName)) {
335 $objMod =
new $modName($db);
336 $modNameLoaded[$modName] = $dir;
337 if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
342 dol_syslog(
"Failed to load ".$dir.$file.
" ".$e->getMessage(), LOG_ERR);
351 if (!empty($tmparray)) {
352 foreach ($tmparray as $modtoactivate) {
353 $modtoactivatenew = preg_replace(
'/\.class\.php$/i',
'', $modtoactivate);
356 $file = $modtoactivatenew.
'.class.php';
361 if (!empty($res[
'errors'])) {
362 print
'ERROR: failed to activateModule() file='.$file;
370 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
377 $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)");
383 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
385 } elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
387 if ($db->connected) {
388 $conf->setValues($db);
390 if (defined(
'SYSLOG_FILE')) {
391 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
393 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
396 $tagdatabase =
false;
400 $mainversionlastupgradearray = preg_split(
'/[.-]/',
$conf->global->MAIN_VERSION_LAST_UPGRADE);
401 $targetversionarray = preg_split(
'/[.-]/', $targetversion);
402 if (
versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
409 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_VERSION_LAST_UPGRADE'");
413 $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)");
417 $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
419 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.');
422 dolibarr_install_syslog(
'step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)');
423 $resql = $db->query(
"DELETE FROM ".MAIN_DB_PREFIX.
"const WHERE ".$db->decrypt(
'name').
" = 'MAIN_NOT_INSTALLED'");
429 print $langs->trans(
"ErrorFailedToConnect").
"<br>";
443if ($action ==
"set") {
445 if (!
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE') || (
$conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
447 print
'<br>'.$langs->trans(
"SystemIsInstalled").
"<br>";
453 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
456 $lockfile = DOL_DATA_ROOT.
'/install.lock';
457 $fp = @fopen($lockfile,
"w");
459 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
460 $force_install_lockinstall =
'444';
462 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
464 dolChmod($lockfile, $force_install_lockinstall);
469 if (empty($createlock)) {
470 print
'<div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
475 print $langs->trans(
"YouNeedToPersonalizeSetup").
"<br><br><br>";
477 print
'<div class="center">> <a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
478 print
'<span class="fas fa-external-link-alt"></span> '.$langs->trans(
"GoToSetupArea");
479 print
'</a></div><br>';
482 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
483 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b><br>';
484 print $langs->trans(
"MigrationNotFinished").
'<br>';
487 print
'<div class="center"><a href="'.$dolibarr_main_url_root.
'/install/index.php">';
488 print
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
492} elseif (empty($action) || preg_match(
'/upgrade/i', $action)) {
494 if (!
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE') || (
$conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
496 print
'<img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/checklist.svg" width="20" alt="Configuration">';
497 print
' <span class="valignmiddle">'.$langs->trans(
"SystemIsUpgraded").
"</span><br>";
502 if (!empty($force_install_lockinstall) ||
getDolGlobalString(
'MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE')) {
504 $lockfile = DOL_DATA_ROOT.
'/install.lock';
505 $fp = @fopen($lockfile,
"w");
507 if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
508 $force_install_lockinstall =
'444';
510 fwrite($fp,
"This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.
")");
512 dolChmod($lockfile, $force_install_lockinstall);
517 if (empty($createlock)) {
518 print
'<br><div class="warning">'.$langs->trans(
"WarningRemoveInstallDir").
"</div>";
522 $unlockupgradefile = DOL_DATA_ROOT.
'/upgrade.unlock';
527 $morehtml =
'<br><div class="center"><a class="buttonGoToupgrade" href="../index.php?mainmenu=home'.(isset($login) ?
'&username='.urlencode($login) :
'').
'">';
528 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToDolibarr").
'...';
529 $morehtml .=
'</a></div><br>';
532 print $langs->trans(
"VersionLastUpgrade").
': <b><span class="ok">' .
getDolGlobalString(
'MAIN_VERSION_LAST_UPGRADE').
'</span></b><br>';
533 print $langs->trans(
"VersionProgram").
': <b><span class="ok">'.DOL_VERSION.
'</span></b>';
537 $morehtml =
'<br><div class="center"><a class="buttonGoToupgrade" href="../install/index.php">';
538 $morehtml .=
'<span class="fas fa-link-alt"></span> '.$langs->trans(
"GoToUpgradePage");
539 $morehtml .=
'</a></div>';
542 dol_print_error(
null,
'step5.php: unknown choice of action='.$action.
' in create lock file seaction');
549if ($error && isset($argv[1])) {
556pFooter(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.
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.