inc.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  4. * Copyright (C) 2004 Sebastien DiCintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2007-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. * Copyright (C) 2021 Charlene Benke <charlene@patas-monkey.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/install/inc.php
  25. * \ingroup core
  26. * \brief File that define environment for support pages
  27. */
  28. // Just to define version DOL_VERSION
  29. if (!defined('DOL_INC_FOR_VERSION_ERROR')) {
  30. define('DOL_INC_FOR_VERSION_ERROR', '1');
  31. }
  32. require_once '../filefunc.inc.php';
  33. // Define DOL_DOCUMENT_ROOT used for install/upgrade process
  34. if (!defined('DOL_DOCUMENT_ROOT')) {
  35. define('DOL_DOCUMENT_ROOT', '..');
  36. }
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  42. $conf = new Conf();
  43. // Force $_REQUEST["logtohtml"]
  44. $_REQUEST["logtohtml"] = 1;
  45. // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
  46. // et non path absolu.
  47. if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) {
  48. $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
  49. }
  50. $includeconferror = '';
  51. // Define vars
  52. $conffiletoshowshort = "conf.php";
  53. // Define localization of conf file
  54. $conffile = "../conf/conf.php";
  55. $conffiletoshow = "htdocs/conf/conf.php";
  56. // For debian/redhat like systems
  57. //$conffile = "/etc/dolibarr/conf.php";
  58. //$conffiletoshow = "/etc/dolibarr/conf.php";
  59. // Load conf file if it is already defined
  60. if (!defined('DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > 8) { // Test on filesize is to ensure that conf file is more that an empty template with just <?php in first line
  61. $result = include_once $conffile; // Load conf file
  62. if ($result) {
  63. if (empty($dolibarr_main_db_type)) {
  64. $dolibarr_main_db_type = 'mysqli'; // For backward compatibility
  65. }
  66. //Mysql driver support has been removed in favor of mysqli
  67. if ($dolibarr_main_db_type == 'mysql') {
  68. $dolibarr_main_db_type = 'mysqli';
  69. }
  70. if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type == 'mysqli')) {
  71. $dolibarr_main_db_port = '3306'; // For backward compatibility
  72. }
  73. // Clean parameters
  74. $dolibarr_main_data_root = isset($dolibarr_main_data_root) ?trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.'/../documents';
  75. $dolibarr_main_url_root = isset($dolibarr_main_url_root) ?trim($dolibarr_main_url_root) : '';
  76. $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ?trim($dolibarr_main_url_root_alt) : '';
  77. $dolibarr_main_document_root = isset($dolibarr_main_document_root) ?trim($dolibarr_main_document_root) : '';
  78. $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ?trim($dolibarr_main_document_root_alt) : '';
  79. // Remove last / or \ on directories or url value
  80. if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) {
  81. $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root);
  82. }
  83. if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) {
  84. $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root);
  85. }
  86. if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) {
  87. $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root);
  88. }
  89. if (!empty($dolibarr_main_document_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
  90. $dolibarr_main_document_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root_alt);
  91. }
  92. if (!empty($dolibarr_main_url_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
  93. $dolibarr_main_url_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root_alt);
  94. }
  95. // Create conf object
  96. if (!empty($dolibarr_main_document_root)) {
  97. $result = conf($dolibarr_main_document_root);
  98. }
  99. // Load database driver
  100. if ($result) {
  101. if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
  102. $result = include_once $dolibarr_main_document_root."/core/db/".$dolibarr_main_db_type.'.class.php';
  103. if (!$result) {
  104. $includeconferror = 'ErrorBadValueForDolibarrMainDBType';
  105. }
  106. }
  107. } else {
  108. $includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot';
  109. }
  110. } else {
  111. $includeconferror = 'ErrorBadFormatForConfFile';
  112. }
  113. }
  114. $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
  115. // Define prefix
  116. if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
  117. $dolibarr_main_db_prefix = 'llx_';
  118. }
  119. define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : ''));
  120. define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir
  121. define('DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.'/../documents'));
  122. define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root
  123. $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
  124. $suburi = strstr($uri, '/'); // $suburi contains url without domain
  125. if ($suburi == '/') {
  126. $suburi = ''; // If $suburi is /, it is now ''
  127. }
  128. define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
  129. if (empty($conf->file->character_set_client)) {
  130. $conf->file->character_set_client = "utf-8";
  131. }
  132. if (empty($conf->db->character_set)) {
  133. $conf->db->character_set = 'utf8';
  134. }
  135. if (empty($conf->db->dolibarr_main_db_collation)) {
  136. $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
  137. }
  138. if (empty($conf->db->dolibarr_main_db_encryption)) {
  139. $conf->db->dolibarr_main_db_encryption = 0;
  140. }
  141. if (empty($conf->db->dolibarr_main_db_cryptkey)) {
  142. $conf->db->dolibarr_main_db_cryptkey = '';
  143. }
  144. if (empty($conf->db->user)) {
  145. $conf->db->user = '';
  146. }
  147. // Define array of document root directories
  148. $conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
  149. if (!empty($dolibarr_main_document_root_alt)) {
  150. // dolibarr_main_document_root_alt contains several directories
  151. $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
  152. foreach ($values as $value) {
  153. $conf->file->dol_document_root[] = $value;
  154. }
  155. }
  156. // Security check (old method, when directory is renamed /install.lock)
  157. if (preg_match('/install\.lock/i', $_SERVER["SCRIPT_FILENAME"])) {
  158. if (!is_object($langs)) {
  159. $langs = new Translate('..', $conf);
  160. $langs->setDefaultLang('auto');
  161. }
  162. $langs->load("install");
  163. header("X-Content-Type-Options: nosniff");
  164. header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
  165. print $langs->trans("YouTryInstallDisabledByDirLock");
  166. if (!empty($dolibarr_main_url_root)) {
  167. print 'Click on following link, <a href="'.$dolibarr_main_url_root.'/admin/index.php?mainmenu=home&leftmenu=setup'.(GETPOSTISSET("login") ? '&username='.urlencode(GETPOST("login")) : '').'">';
  168. print $langs->trans("ClickHereToGoToApp");
  169. print '</a>';
  170. }
  171. exit;
  172. }
  173. $lockfile = DOL_DATA_ROOT.'/install.lock';
  174. if (constant('DOL_DATA_ROOT') === null) {
  175. // We don't have a configuration file yet
  176. // Try to detect any lockfile in the default documents path
  177. $lockfile = '../../documents/install.lock';
  178. }
  179. if (@file_exists($lockfile)) {
  180. if (!isset($langs) || !is_object($langs)) {
  181. $langs = new Translate('..', $conf);
  182. $langs->setDefaultLang('auto');
  183. }
  184. $langs->load("install");
  185. header("X-Content-Type-Options: nosniff");
  186. header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
  187. print $langs->trans("YouTryInstallDisabledByFileLock");
  188. if (!empty($dolibarr_main_url_root)) {
  189. print $langs->trans("ClickOnLinkOrRemoveManualy").'<br>';
  190. print '<a href="'.$dolibarr_main_url_root.'/admin/index.php?mainmenu=home&leftmenu=setup'.(GETPOSTISSET("login") ? '&username='.urlencode(GETPOST("login")) : '').'">';
  191. print $langs->trans("ClickHereToGoToApp");
  192. print '</a>';
  193. } else {
  194. print 'If you always reach this page, you must remove install.lock file manually.<br>';
  195. }
  196. exit;
  197. }
  198. // Force usage of log file for install and upgrades
  199. $conf->syslog->enabled = 1;
  200. $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
  201. if (!defined('SYSLOG_HANDLERS')) {
  202. define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
  203. }
  204. if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
  205. if (@is_writable('/tmp')) {
  206. define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
  207. } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
  208. define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
  209. } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
  210. define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
  211. } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
  212. define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
  213. } elseif (@is_writable('../../')) {
  214. define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
  215. }
  216. //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
  217. }
  218. if (defined('SYSLOG_FILE')) {
  219. $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
  220. }
  221. if (!defined('SYSLOG_FILE_NO_ERROR')) {
  222. define('SYSLOG_FILE_NO_ERROR', 1);
  223. }
  224. // We init log handler for install
  225. $handlers = array('mod_syslog_file');
  226. foreach ($handlers as $handler) {
  227. $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
  228. if (!file_exists($file)) {
  229. throw new Exception('Missing log handler file '.$handler.'.php');
  230. }
  231. require_once $file;
  232. $loghandlerinstance = new $handler();
  233. if (!$loghandlerinstance instanceof LogHandlerInterface) {
  234. throw new Exception('Log handler does not extend LogHandlerInterface');
  235. }
  236. if (empty($conf->loghandlers[$handler])) {
  237. $conf->loghandlers[$handler] = $loghandlerinstance;
  238. }
  239. }
  240. // Define object $langs
  241. $langs = new Translate('..', $conf);
  242. if (GETPOST('lang', 'aZ09')) {
  243. $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
  244. } else {
  245. $langs->setDefaultLang('auto');
  246. }
  247. /**
  248. * Load conf file (file must exists)
  249. *
  250. * @param string $dolibarr_main_document_root Root directory of Dolibarr bin files
  251. * @return int <0 if KO, >0 if OK
  252. */
  253. function conf($dolibarr_main_document_root)
  254. {
  255. global $conf;
  256. global $dolibarr_main_db_type;
  257. global $dolibarr_main_db_host;
  258. global $dolibarr_main_db_port;
  259. global $dolibarr_main_db_name;
  260. global $dolibarr_main_db_user;
  261. global $dolibarr_main_db_pass;
  262. global $character_set_client;
  263. $return = include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
  264. if (!$return) {
  265. return -1;
  266. }
  267. $conf = new Conf();
  268. $conf->db->type = trim($dolibarr_main_db_type);
  269. $conf->db->host = trim($dolibarr_main_db_host);
  270. $conf->db->port = trim($dolibarr_main_db_port);
  271. $conf->db->name = trim($dolibarr_main_db_name);
  272. $conf->db->user = trim($dolibarr_main_db_user);
  273. $conf->db->pass = (empty($dolibarr_main_db_pass) ? '' : trim($dolibarr_main_db_pass));
  274. // Mysql driver support has been removed in favor of mysqli
  275. if ($conf->db->type == 'mysql') {
  276. $conf->db->type = 'mysqli';
  277. }
  278. if (empty($character_set_client)) {
  279. $character_set_client = "UTF-8";
  280. }
  281. $conf->file->character_set_client = strtoupper($character_set_client);
  282. if (empty($dolibarr_main_db_character_set)) {
  283. $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : '');
  284. }
  285. $conf->db->character_set = $dolibarr_main_db_character_set;
  286. if (empty($dolibarr_main_db_collation)) {
  287. $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : '');
  288. }
  289. $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
  290. if (empty($dolibarr_main_db_encryption)) {
  291. $dolibarr_main_db_encryption = 0;
  292. }
  293. $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
  294. if (empty($dolibarr_main_db_cryptkey)) {
  295. $dolibarr_main_db_cryptkey = '';
  296. }
  297. $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
  298. // Force usage of log file for install and upgrades
  299. $conf->syslog->enabled = 1;
  300. $conf->global->SYSLOG_LEVEL = constant('LOG_DEBUG');
  301. if (!defined('SYSLOG_HANDLERS')) {
  302. define('SYSLOG_HANDLERS', '["mod_syslog_file"]');
  303. }
  304. if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
  305. if (@is_writable('/tmp')) {
  306. define('SYSLOG_FILE', '/tmp/dolibarr_install.log');
  307. } elseif (!empty($_ENV["TMP"]) && @is_writable($_ENV["TMP"])) {
  308. define('SYSLOG_FILE', $_ENV["TMP"].'/dolibarr_install.log');
  309. } elseif (!empty($_ENV["TEMP"]) && @is_writable($_ENV["TEMP"])) {
  310. define('SYSLOG_FILE', $_ENV["TEMP"].'/dolibarr_install.log');
  311. } elseif (@is_writable('../../../../') && @file_exists('../../../../startdoliwamp.bat')) {
  312. define('SYSLOG_FILE', '../../../../dolibarr_install.log'); // For DoliWamp
  313. } elseif (@is_writable('../../')) {
  314. define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
  315. }
  316. //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
  317. }
  318. if (defined('SYSLOG_FILE')) {
  319. $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
  320. }
  321. if (!defined('SYSLOG_FILE_NO_ERROR')) {
  322. define('SYSLOG_FILE_NO_ERROR', 1);
  323. }
  324. // We init log handler for install
  325. $handlers = array('mod_syslog_file');
  326. foreach ($handlers as $handler) {
  327. $file = DOL_DOCUMENT_ROOT.'/core/modules/syslog/'.$handler.'.php';
  328. if (!file_exists($file)) {
  329. throw new Exception('Missing log handler file '.$handler.'.php');
  330. }
  331. require_once $file;
  332. $loghandlerinstance = new $handler();
  333. if (!$loghandlerinstance instanceof LogHandlerInterface) {
  334. throw new Exception('Log handler does not extend LogHandlerInterface');
  335. }
  336. if (empty($conf->loghandlers[$handler])) {
  337. $conf->loghandlers[$handler] = $loghandlerinstance;
  338. }
  339. }
  340. return 1;
  341. }
  342. /**
  343. * Show HTML header of install pages
  344. *
  345. * @param string $subtitle Title
  346. * @param string $next Next
  347. * @param string $action Action code ('set' or 'upgrade')
  348. * @param string $param Param
  349. * @param string $forcejqueryurl Set jquery relative URL (must end with / if defined)
  350. * @param string $csstable Css for table
  351. * @return void
  352. */
  353. function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl = '', $csstable = 'main-inside')
  354. {
  355. global $conf;
  356. global $langs;
  357. $langs->load("main");
  358. $langs->load("admin");
  359. $langs->load("install");
  360. $jquerytheme = 'base';
  361. if ($forcejqueryurl) {
  362. $jQueryCustomPath = $forcejqueryurl;
  363. $jQueryUiCustomPath = $forcejqueryurl;
  364. } else {
  365. $jQueryCustomPath = (defined('JS_JQUERY') && constant('JS_JQUERY')) ? JS_JQUERY : false;
  366. $jQueryUiCustomPath = (defined('JS_JQUERY_UI') && constant('JS_JQUERY_UI')) ? JS_JQUERY_UI : false;
  367. }
  368. // We force the content charset
  369. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  370. header("X-Content-Type-Options: nosniff");
  371. header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
  372. print '<!DOCTYPE HTML>'."\n";
  373. print '<html>'."\n";
  374. print '<head>'."\n";
  375. print '<meta charset="'.$conf->file->character_set_client.'">'."\n";
  376. print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
  377. print '<meta name="generator" content="Dolibarr installer">'."\n";
  378. print '<link rel="stylesheet" type="text/css" href="default.css">'."\n";
  379. print '<!-- Includes CSS for JQuery -->'."\n";
  380. if ($jQueryUiCustomPath) {
  381. print '<link rel="stylesheet" type="text/css" href="'.$jQueryUiCustomPath.'css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
  382. } else {
  383. print '<link rel="stylesheet" type="text/css" href="../includes/jquery/css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
  384. }
  385. print '<!-- Includes JS for JQuery -->'."\n";
  386. if ($jQueryCustomPath) {
  387. print '<script type="text/javascript" src="'.$jQueryCustomPath.'jquery.min.js"></script>'."\n";
  388. } else {
  389. print '<script type="text/javascript" src="../includes/jquery/js/jquery.min.js"></script>'."\n";
  390. }
  391. if ($jQueryUiCustomPath) {
  392. print '<script type="text/javascript" src="'.$jQueryUiCustomPath.'jquery-ui.min.js"></script>'."\n";
  393. } else {
  394. print '<script type="text/javascript" src="../includes/jquery/js/jquery-ui.min.js"></script>'."\n";
  395. }
  396. print '<title>'.$langs->trans("DolibarrSetup").'</title>'."\n";
  397. print '</head>'."\n";
  398. print '<body>'."\n";
  399. print '<div class="divlogoinstall" style="text-align:center">';
  400. print '<img class="imglogoinstall" src="../theme/dolibarr_logo.svg" alt="Dolibarr logo" width="300px"><br>';
  401. print DOL_VERSION;
  402. print '</div><br>';
  403. print '<span class="titre">'.$langs->trans("DolibarrSetup");
  404. if ($subtitle) {
  405. print ' - '.$subtitle;
  406. }
  407. print '</span>'."\n";
  408. print '<form name="forminstall" style="width: 100%" action="'.$next.'.php'.($param ? '?'.$param : '').'" method="POST"';
  409. if ($next == 'step5') {
  410. print ' autocomplete="off"';
  411. }
  412. print '>'."\n";
  413. print '<input type="hidden" name="testpost" value="ok">'."\n";
  414. print '<input type="hidden" name="action" value="'.$action.'">'."\n";
  415. print '<table class="main" width="100%"><tr><td>'."\n";
  416. print '<table class="'.$csstable.'" width="100%"><tr><td>'."\n";
  417. }
  418. /**
  419. * Print HTML footer of install pages
  420. *
  421. * @param integer $nonext 1=No button "Next step", 2=Show button but disabled with a link to enable
  422. * @param string $setuplang Language code
  423. * @param string $jscheckfunction Add a javascript check function
  424. * @param integer $withpleasewait Add also please wait tags
  425. * @param string $morehtml Add more HTML content
  426. * @return void
  427. */
  428. function pFooter($nonext = 0, $setuplang = '', $jscheckfunction = '', $withpleasewait = 0, $morehtml = '')
  429. {
  430. global $conf, $langs;
  431. $langs->loadLangs(array("main", "other", "admin"));
  432. print '</td></tr></table>'."\n";
  433. print '</td></tr></table>'."\n";
  434. print '<!-- pFooter -->'."\n";
  435. print $morehtml;
  436. if (!$nonext || ($nonext == '2')) {
  437. print '<div class="nextbutton" id="nextbutton">';
  438. if ($nonext == '2') {
  439. print '<span class="warning">';
  440. print $langs->trans("ErrorFoundDuringMigration", isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"].'&ignoreerrors=1' : '');
  441. print '</span>';
  442. print '<br><br>';
  443. }
  444. print '<input type="submit" '.($nonext == '2' ? 'disabled="disabled" ' : '').'value="'.$langs->trans("NextStep").' ->"';
  445. if ($jscheckfunction) {
  446. print ' onClick="return '.$jscheckfunction.'();"';
  447. }
  448. print '></div>';
  449. if ($withpleasewait) {
  450. print '<div style="visibility: hidden;" class="pleasewait" id="pleasewait"><br>'.$langs->trans("NextStepMightLastALongTime").'<br><br><div class="blinkwait">'.$langs->trans("PleaseBePatient").'</div></div>';
  451. }
  452. }
  453. if ($setuplang) {
  454. print '<input type="hidden" name="selectlang" value="'.dol_escape_htmltag($setuplang).'">';
  455. }
  456. print '</form><br>'."\n";
  457. // If there is some logs in buffer to show
  458. if (isset($conf->logbuffer) && count($conf->logbuffer)) {
  459. print "\n";
  460. print "<!-- Start of log output\n";
  461. //print '<div class="hidden">'."\n";
  462. foreach ($conf->logbuffer as $logline) {
  463. print $logline."<br>\n";
  464. }
  465. //print '</div>'."\n";
  466. print "End of log output -->\n";
  467. print "\n";
  468. }
  469. print '</body>'."\n";
  470. print '</html>'."\n";
  471. }
  472. /**
  473. * Log function for install pages
  474. *
  475. * @param string $message Message
  476. * @param int $level Level of log
  477. * @return void
  478. */
  479. function dolibarr_install_syslog($message, $level = LOG_DEBUG)
  480. {
  481. if (!defined('LOG_DEBUG')) {
  482. define('LOG_DEBUG', 6);
  483. }
  484. dol_syslog($message, $level);
  485. }
  486. /**
  487. * Automatically detect Dolibarr's main document root
  488. *
  489. * @return string
  490. */
  491. function detect_dolibarr_main_document_root()
  492. {
  493. // If PHP is in CGI mode, SCRIPT_FILENAME is PHP's path.
  494. // Since that's not what we want, we suggest $_SERVER["DOCUMENT_ROOT"]
  495. if ($_SERVER["SCRIPT_FILENAME"] == 'php' || preg_match('/[\\/]php$/i', $_SERVER["SCRIPT_FILENAME"]) || preg_match('/php\.exe$/i', $_SERVER["SCRIPT_FILENAME"])) {
  496. $dolibarr_main_document_root = $_SERVER["DOCUMENT_ROOT"];
  497. if (!preg_match('/[\\/]dolibarr[\\/]htdocs$/i', $dolibarr_main_document_root)) {
  498. $dolibarr_main_document_root .= "/dolibarr/htdocs";
  499. }
  500. } else {
  501. // We assume /install to be under /htdocs, so we get the parent directory of the current directory
  502. $dolibarr_main_document_root = dirname(dirname($_SERVER["SCRIPT_FILENAME"]));
  503. }
  504. return $dolibarr_main_document_root;
  505. }
  506. /**
  507. * Automatically detect Dolibarr's main data root
  508. *
  509. * @param string $dolibarr_main_document_root Current main document root
  510. * @return string
  511. */
  512. function detect_dolibarr_main_data_root($dolibarr_main_document_root)
  513. {
  514. $dolibarr_main_data_root = preg_replace("/\/htdocs$/", "", $dolibarr_main_document_root);
  515. $dolibarr_main_data_root .= "/documents";
  516. return $dolibarr_main_data_root;
  517. }
  518. /**
  519. * Automatically detect Dolibarr's main URL root
  520. *
  521. * @return string
  522. */
  523. function detect_dolibarr_main_url_root()
  524. {
  525. // If defined (Ie: Apache with Linux)
  526. if (isset($_SERVER["SCRIPT_URI"])) {
  527. $dolibarr_main_url_root = $_SERVER["SCRIPT_URI"];
  528. } elseif (isset($_SERVER["SERVER_URL"]) && isset($_SERVER["DOCUMENT_URI"])) {
  529. // If defined (Ie: Apache with Caudium)
  530. $dolibarr_main_url_root = $_SERVER["SERVER_URL"].$_SERVER["DOCUMENT_URI"];
  531. } else {
  532. // If SCRIPT_URI, SERVER_URL, DOCUMENT_URI not defined (Ie: Apache 2.0.44 for Windows)
  533. $proto = ((!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on') || (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) ? 'https' : 'http';
  534. if (!empty($_SERVER["HTTP_HOST"])) {
  535. $serverport = $_SERVER["HTTP_HOST"];
  536. } elseif (!empty($_SERVER["SERVER_NAME"])) {
  537. $serverport = $_SERVER["SERVER_NAME"];
  538. } else {
  539. $serverport = 'localhost';
  540. }
  541. $dolibarr_main_url_root = $proto."://".$serverport.$_SERVER["SCRIPT_NAME"];
  542. }
  543. // Clean proposed URL
  544. // We assume /install to be under /htdocs, so we get the parent path of the current URL
  545. $dolibarr_main_url_root = dirname(dirname($dolibarr_main_url_root));
  546. return $dolibarr_main_url_root;
  547. }
  548. /**
  549. * Replaces automatic database login by actual value
  550. *
  551. * @param string $force_install_databaserootlogin Login
  552. * @return string
  553. */
  554. function parse_database_login($force_install_databaserootlogin)
  555. {
  556. return preg_replace('/__SUPERUSERLOGIN__/', 'root', $force_install_databaserootlogin);
  557. }
  558. /**
  559. * Replaces automatic database password by actual value
  560. *
  561. * @param string $force_install_databaserootpass Password
  562. * @return string
  563. */
  564. function parse_database_pass($force_install_databaserootpass)
  565. {
  566. return preg_replace('/__SUPERUSERPASSWORD__/', '', $force_install_databaserootpass);
  567. }