step5.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2015-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/install/step5.php
  24. * \ingroup install
  25. * \brief Last page of upgrade / install process
  26. *
  27. * This page is called with parameter action=set by step4.php or action=upgrade by upgrade2.php
  28. * For installation:
  29. * It creates the login admin and set the MAIN_SECURITY_SALT to a random value.
  30. * It set the value for MAIN_VERSION_LAST_INSTALL
  31. * It activates some modules
  32. * It creates the install.lock and shows the final message.
  33. * For upgrade:
  34. * It updates the value for MAIN_VERSION_LAST_UPGRADE.
  35. * It (re)creates the install.lock and shows the final message.
  36. */
  37. define('ALLOWED_IF_UPGRADE_UNLOCK_FOUND', 1);
  38. include_once 'inc.php';
  39. if (file_exists($conffile)) {
  40. include_once $conffile;
  41. }
  42. require_once $dolibarr_main_document_root.'/core/lib/admin.lib.php';
  43. require_once $dolibarr_main_document_root.'/core/lib/security.lib.php'; // for dol_hash
  44. require_once $dolibarr_main_document_root.'/core/lib/functions2.lib.php';
  45. global $langs;
  46. $versionfrom = GETPOST("versionfrom", 'alpha', 3) ?GETPOST("versionfrom", 'alpha', 3) : (empty($argv[1]) ? '' : $argv[1]);
  47. $versionto = GETPOST("versionto", 'alpha', 3) ?GETPOST("versionto", 'alpha', 3) : (empty($argv[2]) ? '' : $argv[2]);
  48. $setuplang = GETPOST('selectlang', 'aZ09', 3) ?GETPOST('selectlang', 'aZ09', 3) : (empty($argv[3]) ? 'auto' : $argv[3]);
  49. $langs->setDefaultLang($setuplang);
  50. $action = GETPOST('action', 'alpha') ?GETPOST('action', 'alpha') : (empty($argv[4]) ? '' : $argv[4]);
  51. // Define targetversion used to update MAIN_VERSION_LAST_INSTALL for first install
  52. // or MAIN_VERSION_LAST_UPGRADE for upgrade.
  53. $targetversion = DOL_VERSION; // If it's latest upgrade
  54. if (!empty($action) && preg_match('/upgrade/i', $action)) {
  55. // If it's an old upgrade
  56. $tmp = explode('_', $action, 2);
  57. if ($tmp[0] == 'upgrade') {
  58. if (!empty($tmp[1])) {
  59. $targetversion = $tmp[1]; // if $action = 'upgrade_6.0.0-beta', we use '6.0.0-beta'
  60. } else {
  61. $targetversion = DOL_VERSION; // if $action = 'upgrade', we use DOL_VERSION
  62. }
  63. }
  64. }
  65. $langs->loadLangs(array("admin", "install"));
  66. $login = GETPOST('login', 'alpha') ?GETPOST('login', 'alpha') : (empty($argv[5]) ? '' : $argv[5]);
  67. $pass = GETPOST('pass', 'alpha') ?GETPOST('pass', 'alpha') : (empty($argv[6]) ? '' : $argv[6]);
  68. $pass_verif = GETPOST('pass_verif', 'alpha') ?GETPOST('pass_verif', 'alpha') : (empty($argv[7]) ? '' : $argv[7]);
  69. $force_install_lockinstall = (int) (!empty($force_install_lockinstall) ? $force_install_lockinstall : (GETPOST('installlock', 'aZ09') ?GETPOST('installlock', 'aZ09') : (empty($argv[8]) ? '' : $argv[8])));
  70. $success = 0;
  71. $useforcedwizard = false;
  72. $forcedfile = "./install.forced.php";
  73. if ($conffile == "/etc/dolibarr/conf.php") {
  74. $forcedfile = "/etc/dolibarr/install.forced.php";
  75. }
  76. if (@file_exists($forcedfile)) {
  77. $useforcedwizard = true;
  78. include_once $forcedfile;
  79. // If forced install is enabled, replace post values. These are empty because form fields are disabled.
  80. if ($force_install_noedit == 2) {
  81. if (!empty($force_install_dolibarrlogin)) {
  82. $login = $force_install_dolibarrlogin;
  83. }
  84. }
  85. }
  86. dolibarr_install_syslog("--- step5: entering step5.php page ".$versionfrom." ".$versionto);
  87. $error = 0;
  88. /*
  89. * Actions
  90. */
  91. // If install, check password and password_verification used to create admin account
  92. if ($action == "set") {
  93. if ($pass <> $pass_verif) {
  94. header("Location: step4.php?error=1&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
  95. exit;
  96. }
  97. if (dol_strlen(trim($pass)) == 0) {
  98. header("Location: step4.php?error=2&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
  99. exit;
  100. }
  101. if (dol_strlen(trim($login)) == 0) {
  102. header("Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
  103. exit;
  104. }
  105. }
  106. /*
  107. * View
  108. */
  109. $morehtml = '';
  110. pHeader($langs->trans("SetupEnd"), "step5", 'set', '', '', 'main-inside main-inside-borderbottom');
  111. print '<br>';
  112. // Test if we can run a first install process
  113. if (empty($versionfrom) && empty($versionto) && !is_writable($conffile)) {
  114. print $langs->trans("ConfFileIsNotWritable", $conffiletoshow);
  115. pFooter(1, $setuplang, 'jscheckparam');
  116. exit;
  117. }
  118. if ($action == "set" || empty($action) || preg_match('/upgrade/i', $action)) {
  119. $error = 0;
  120. // If password is encoded, we decode it
  121. if ((!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
  122. require_once $dolibarr_main_document_root.'/core/lib/security.lib.php';
  123. if (!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
  124. $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
  125. $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
  126. $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted
  127. } else {
  128. $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
  129. }
  130. }
  131. $conf->db->type = $dolibarr_main_db_type;
  132. $conf->db->host = $dolibarr_main_db_host;
  133. $conf->db->port = $dolibarr_main_db_port;
  134. $conf->db->name = $dolibarr_main_db_name;
  135. $conf->db->user = $dolibarr_main_db_user;
  136. $conf->db->pass = $dolibarr_main_db_pass;
  137. $conf->db->dolibarr_main_db_encryption = isset($dolibarr_main_db_encryption) ? $dolibarr_main_db_encryption : '';
  138. $conf->db->dolibarr_main_db_cryptkey = isset($dolibarr_main_db_cryptkey) ? $dolibarr_main_db_cryptkey : '';
  139. $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, (int) $conf->db->port);
  140. // Create the global $hookmanager object
  141. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  142. $hookmanager = new HookManager($db);
  143. $ok = 0;
  144. // If first install
  145. if ($action == "set") {
  146. // Active module user
  147. $modName = 'modUser';
  148. $file = $modName.".class.php";
  149. dolibarr_install_syslog('step5: load module user '.DOL_DOCUMENT_ROOT."/core/modules/".$file, LOG_INFO);
  150. include_once DOL_DOCUMENT_ROOT."/core/modules/".$file;
  151. $objMod = new $modName($db);
  152. $result = $objMod->init();
  153. if (!$result) {
  154. print "ERROR: failed to init module file = ".$file;
  155. }
  156. if ($db->connected) {
  157. $conf->setValues($db);
  158. // Reset forced setup after the setValues
  159. if (defined('SYSLOG_FILE')) {
  160. $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
  161. }
  162. $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
  163. // Create admin user
  164. include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  165. // Set default encryption to yes, generate a salt and set default encryption algorythm (but only if there is no user yet into database)
  166. $sql = "SELECT u.rowid, u.pass, u.pass_crypted";
  167. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  168. $resql = $db->query($sql);
  169. if ($resql) {
  170. $numrows = $db->num_rows($resql);
  171. if ($numrows == 0) {
  172. // Define default setup for password encryption
  173. dolibarr_set_const($db, "DATABASE_PWD_ENCRYPTED", "1", 'chaine', 0, '', $conf->entity);
  174. dolibarr_set_const($db, "MAIN_SECURITY_SALT", dol_print_date(dol_now(), 'dayhourlog'), 'chaine', 0, '', 0); // All entities
  175. if (function_exists('password_hash')) {
  176. dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'password_hash', 'chaine', 0, '', 0); // All entities
  177. } else {
  178. dolibarr_set_const($db, "MAIN_SECURITY_HASH_ALGO", 'sha1md5', 'chaine', 0, '', 0); // All entities
  179. }
  180. }
  181. dolibarr_install_syslog('step5: DATABASE_PWD_ENCRYPTED = ' . getDolGlobalString('DATABASE_PWD_ENCRYPTED').' MAIN_SECURITY_HASH_ALGO = ' . getDolGlobalString('MAIN_SECURITY_HASH_ALGO'), LOG_INFO);
  182. }
  183. // Create user used to create the admin user
  184. $createuser = new User($db);
  185. $createuser->id = 0;
  186. $createuser->admin = 1;
  187. // Set admin user
  188. $newuser = new User($db);
  189. $newuser->lastname = 'SuperAdmin';
  190. $newuser->firstname = '';
  191. $newuser->login = $login;
  192. $newuser->pass = $pass;
  193. $newuser->admin = 1;
  194. $newuser->entity = 0;
  195. $conf->global->USER_MAIL_REQUIRED = 0; // Force global option to be sure to create a new user with no email
  196. $conf->global->USER_PASSWORD_GENERATED = ''; // To not use any rule for password validation
  197. $result = $newuser->create($createuser, 1);
  198. if ($result > 0) {
  199. print $langs->trans("AdminLoginCreatedSuccessfuly", $login)."<br>";
  200. $success = 1;
  201. } else {
  202. if ($result == -6) { //login or email already exists
  203. dolibarr_install_syslog('step5: AdminLoginAlreadyExists', LOG_WARNING);
  204. print '<br><div class="warning">'.$newuser->error."</div><br>";
  205. $success = 1;
  206. } else {
  207. dolibarr_install_syslog('step5: FailedToCreateAdminLogin '.$newuser->error, LOG_ERR);
  208. setEventMessages($langs->trans("FailedToCreateAdminLogin").' '.$newuser->error, null, 'errors');
  209. //header("Location: step4.php?error=3&selectlang=$setuplang".(isset($login) ? '&login='.$login : ''));
  210. print '<br><div class="error">'.$langs->trans("FailedToCreateAdminLogin").': '.$newuser->error.'</div><br><br>';
  211. print $langs->trans("ErrorGoBackAndCorrectParameters").'<br><br>';
  212. }
  213. }
  214. if ($success) {
  215. // Insert MAIN_VERSION_FIRST_INSTALL in a dedicated transaction. So if it fails (when first install was already done), we can do other following requests.
  216. $db->begin();
  217. dolibarr_install_syslog('step5: set MAIN_VERSION_FIRST_INSTALL const to '.$targetversion, LOG_DEBUG);
  218. $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)");
  219. if ($resql) {
  220. $conf->global->MAIN_VERSION_FIRST_INSTALL = $targetversion;
  221. $db->commit();
  222. } else {
  223. //if (! $resql) dol_print_error($db,'Error in setup program'); // We ignore errors. Key may already exists
  224. $db->commit();
  225. }
  226. $db->begin();
  227. dolibarr_install_syslog('step5: set MAIN_VERSION_LAST_INSTALL const to '.$targetversion, LOG_DEBUG);
  228. $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_VERSION_LAST_INSTALL'");
  229. if (!$resql) {
  230. dol_print_error($db, 'Error in setup program');
  231. }
  232. $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)");
  233. if (!$resql) {
  234. dol_print_error($db, 'Error in setup program');
  235. }
  236. $conf->global->MAIN_VERSION_LAST_INSTALL = $targetversion;
  237. if ($useforcedwizard) {
  238. dolibarr_install_syslog('step5: set MAIN_REMOVE_INSTALL_WARNING const to 1', LOG_DEBUG);
  239. $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_REMOVE_INSTALL_WARNING'");
  240. if (!$resql) {
  241. dol_print_error($db, 'Error in setup program');
  242. }
  243. // The install.lock file is created few lines later if version is last one or if option MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE is on
  244. /* No need to enable this
  245. $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)");
  246. if (!$resql) {
  247. dol_print_error($db, 'Error in setup program');
  248. }
  249. $conf->global->MAIN_REMOVE_INSTALL_WARNING = 1;
  250. */
  251. }
  252. // List of modules to enable
  253. $tmparray = array();
  254. // If we ask to force some modules to be enabled
  255. if (!empty($force_install_module)) {
  256. if (!defined('DOL_DOCUMENT_ROOT') && !empty($dolibarr_main_document_root)) {
  257. define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
  258. }
  259. $tmparray = explode(',', $force_install_module);
  260. }
  261. $modNameLoaded = array();
  262. // Search modules dirs
  263. $modulesdir[] = $dolibarr_main_document_root.'/core/modules/';
  264. foreach ($modulesdir as $dir) {
  265. // Load modules attributes in arrays (name, numero, orders) from dir directory
  266. //print $dir."\n<br>";
  267. dol_syslog("Scan directory ".$dir." for module descriptor files (modXXX.class.php)");
  268. $handle = @opendir($dir);
  269. if (is_resource($handle)) {
  270. while (($file = readdir($handle)) !== false) {
  271. if (is_readable($dir.$file) && substr($file, 0, 3) == 'mod' && substr($file, dol_strlen($file) - 10) == '.class.php') {
  272. $modName = substr($file, 0, dol_strlen($file) - 10);
  273. if ($modName) {
  274. if (!empty($modNameLoaded[$modName])) { // In cache of already loaded modules ?
  275. $mesg = "Error: Module ".$modName." was found twice: Into ".$modNameLoaded[$modName]." and ".$dir.". You probably have an old file on your disk.<br>";
  276. setEventMessages($mesg, null, 'warnings');
  277. dol_syslog($mesg, LOG_ERR);
  278. continue;
  279. }
  280. try {
  281. $res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
  282. if (class_exists($modName)) {
  283. $objMod = new $modName($db);
  284. $modNameLoaded[$modName] = $dir;
  285. if (!empty($objMod->enabled_bydefault) && !in_array($file, $tmparray)) {
  286. $tmparray[] = $file;
  287. }
  288. }
  289. } catch (Exception $e) {
  290. dol_syslog("Failed to load ".$dir.$file." ".$e->getMessage(), LOG_ERR);
  291. }
  292. }
  293. }
  294. }
  295. }
  296. }
  297. // Loop on each modules to activate it
  298. if (!empty($tmparray)) {
  299. foreach ($tmparray as $modtoactivate) {
  300. $modtoactivatenew = preg_replace('/\.class\.php$/i', '', $modtoactivate);
  301. //print $langs->trans("ActivateModule", $modtoactivatenew).'<br>';
  302. $file = $modtoactivatenew.'.class.php';
  303. dolibarr_install_syslog('step5: activate module file='.$file);
  304. $res = dol_include_once("/core/modules/".$file);
  305. $res = activateModule($modtoactivatenew, 1);
  306. if (!empty($res['errors'])) {
  307. print 'ERROR: failed to activateModule() file='.$file;
  308. }
  309. }
  310. //print '<br>';
  311. }
  312. // Now delete the flag that say installation is not complete
  313. dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const');
  314. $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_NOT_INSTALLED'");
  315. if (!$resql) {
  316. dol_print_error($db, 'Error in setup program');
  317. }
  318. $db->commit();
  319. }
  320. } else {
  321. print $langs->trans("ErrorFailedToConnect")."<br>";
  322. }
  323. } elseif (empty($action) || preg_match('/upgrade/i', $action)) {
  324. // If upgrade
  325. if ($db->connected) {
  326. $conf->setValues($db);
  327. // Reset forced setup after the setValues
  328. if (defined('SYSLOG_FILE')) {
  329. $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
  330. }
  331. $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
  332. // Define if we need to update the MAIN_VERSION_LAST_UPGRADE value in database
  333. $tagdatabase = false;
  334. if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE)) {
  335. $tagdatabase = true; // We don't know what it was before, so now we consider we are version choosed.
  336. } else {
  337. $mainversionlastupgradearray = preg_split('/[.-]/', $conf->global->MAIN_VERSION_LAST_UPGRADE);
  338. $targetversionarray = preg_split('/[.-]/', $targetversion);
  339. if (versioncompare($targetversionarray, $mainversionlastupgradearray) > 0) {
  340. $tagdatabase = true;
  341. }
  342. }
  343. if ($tagdatabase) {
  344. dolibarr_install_syslog('step5: set MAIN_VERSION_LAST_UPGRADE const to value '.$targetversion);
  345. $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_VERSION_LAST_UPGRADE'");
  346. if (!$resql) {
  347. dol_print_error($db, 'Error in setup program');
  348. }
  349. $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)");
  350. if (!$resql) {
  351. dol_print_error($db, 'Error in setup program');
  352. }
  353. $conf->global->MAIN_VERSION_LAST_UPGRADE = $targetversion;
  354. } else {
  355. 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.');
  356. // Force the delete of the flag that say installation is not complete
  357. dolibarr_install_syslog('step5: remove MAIN_NOT_INSTALLED const after upgrade process (should not exists but this is a security)');
  358. $resql = $db->query("DELETE FROM ".MAIN_DB_PREFIX."const WHERE ".$db->decrypt('name')." = 'MAIN_NOT_INSTALLED'");
  359. if (!$resql) {
  360. dol_print_error($db, 'Error in setup program');
  361. }
  362. }
  363. // May fail if parameter already defined
  364. dolibarr_install_syslog('step5: set the default language');
  365. $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)");
  366. //if (! $resql) dol_print_error($db,'Error in setup program');
  367. } else {
  368. print $langs->trans("ErrorFailedToConnect")."<br>";
  369. }
  370. } else {
  371. dol_print_error('', 'step5.php: unknown choice of action');
  372. }
  373. $db->close();
  374. }
  375. // Create lock file
  376. // If first install
  377. if ($action == "set") {
  378. if ($success) {
  379. if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
  380. // Install is finished (database is on same version than files)
  381. print '<br>'.$langs->trans("SystemIsInstalled")."<br>";
  382. // Create install.lock file
  383. // No need for the moment to create it automatically, creation by web assistant means permissions are given
  384. // to the web user, it is better to show a warning to say to create it manually with correct user/permission (not erasable by a web process)
  385. $createlock = 0;
  386. if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE)) {
  387. // Install is finished, we create the "install.lock" file, so install won't be possible anymore.
  388. // TODO Upgrade will be still be possible if a file "upgrade.unlock" is present
  389. $lockfile = DOL_DATA_ROOT.'/install.lock';
  390. $fp = @fopen($lockfile, "w");
  391. if ($fp) {
  392. if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
  393. $force_install_lockinstall = '444'; // For backward compatibility
  394. }
  395. fwrite($fp, "This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.")");
  396. fclose($fp);
  397. dolChmod($lockfile, $force_install_lockinstall);
  398. $createlock = 1;
  399. }
  400. }
  401. if (empty($createlock)) {
  402. print '<div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
  403. }
  404. print "<br>";
  405. print $langs->trans("YouNeedToPersonalizeSetup")."<br><br><br>";
  406. print '<div class="center">&gt; <a href="../admin/index.php?mainmenu=home&leftmenu=setup'.(isset($login) ? '&username='.urlencode($login) : '').'">';
  407. print '<span class="fas fa-external-link-alt"></span> '.$langs->trans("GoToSetupArea");
  408. print '</a></div><br>';
  409. } else {
  410. // If here MAIN_VERSION_LAST_UPGRADE is not empty
  411. print $langs->trans("VersionLastUpgrade").': <b><span class="ok">' . getDolGlobalString('MAIN_VERSION_LAST_UPGRADE').'</span></b><br>';
  412. print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b><br>';
  413. print $langs->trans("MigrationNotFinished").'<br>';
  414. print "<br>";
  415. print '<div class="center"><a href="'.$dolibarr_main_url_root.'/install/index.php">';
  416. print '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToUpgradePage");
  417. print '</a></div>';
  418. }
  419. }
  420. } elseif (empty($action) || preg_match('/upgrade/i', $action)) {
  421. // If upgrade
  422. if (empty($conf->global->MAIN_VERSION_LAST_UPGRADE) || ($conf->global->MAIN_VERSION_LAST_UPGRADE == DOL_VERSION)) {
  423. // Upgrade is finished (database is on the same version than files)
  424. print '<img class="valignmiddle inline-block paddingright" src="../theme/common/octicons/build/svg/checklist.svg" width="20" alt="Configuration">';
  425. print ' <span class="valignmiddle">'.$langs->trans("SystemIsUpgraded")."</span><br>";
  426. // Create install.lock file if it does not exists.
  427. // Note: it should always exists. A better solution to allow upgrade will be to add an upgrade.unlock file
  428. $createlock = 0;
  429. if (!empty($force_install_lockinstall) || !empty($conf->global->MAIN_ALWAYS_CREATE_LOCK_AFTER_LAST_UPGRADE)) {
  430. // Upgrade is finished, we modify the lock file
  431. $lockfile = DOL_DATA_ROOT.'/install.lock';
  432. $fp = @fopen($lockfile, "w");
  433. if ($fp) {
  434. if (empty($force_install_lockinstall) || $force_install_lockinstall == 1) {
  435. $force_install_lockinstall = '444'; // For backward compatibility
  436. }
  437. fwrite($fp, "This is a lock file to prevent use of install or upgrade pages (set with permission ".$force_install_lockinstall.")");
  438. fclose($fp);
  439. dolChmod($lockfile, $force_install_lockinstall);
  440. $createlock = 1;
  441. }
  442. }
  443. if (empty($createlock)) {
  444. print '<br><div class="warning">'.$langs->trans("WarningRemoveInstallDir")."</div>";
  445. }
  446. // Delete the upgrade.unlock file it it exists
  447. $unlockupgradefile = DOL_DATA_ROOT.'/upgrade.unlock';
  448. dol_delete_file($unlockupgradefile, 0, 0, 0, null, false, 0);
  449. print "<br>";
  450. $morehtml = '<br><div class="center"><a href="../index.php?mainmenu=home'.(isset($login) ? '&username='.urlencode($login) : '').'">';
  451. $morehtml .= '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToDolibarr").'...';
  452. $morehtml .= '</a></div><br>';
  453. } else {
  454. // If here MAIN_VERSION_LAST_UPGRADE is not empty
  455. print $langs->trans("VersionLastUpgrade").': <b><span class="ok">' . getDolGlobalString('MAIN_VERSION_LAST_UPGRADE').'</span></b><br>';
  456. print $langs->trans("VersionProgram").': <b><span class="ok">'.DOL_VERSION.'</span></b>';
  457. print "<br>";
  458. $morehtml = '<br><div class="center"><a href="../install/index.php">';
  459. $morehtml .= '<span class="fas fa-link-alt"></span> '.$langs->trans("GoToUpgradePage");
  460. $morehtml .= '</a></div>';
  461. }
  462. } else {
  463. dol_print_error('', 'step5.php: unknown choice of action='.$action.' in create lock file seaction');
  464. }
  465. // Clear cache files
  466. clearstatcache();
  467. $ret = 0;
  468. if ($error && isset($argv[1])) {
  469. $ret = 1;
  470. }
  471. dolibarr_install_syslog("Exit ".$ret);
  472. dolibarr_install_syslog("--- step5: Dolibarr setup finished");
  473. pFooter(1, $setuplang, '', 0, $morehtml);
  474. // Return code if ran from command line
  475. if ($ret) {
  476. exit($ret);
  477. }