inc.php 23 KB

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