31 if (!defined(
'DOL_INC_FOR_VERSION_ERROR')) {
32 define(
'DOL_INC_FOR_VERSION_ERROR',
'1');
34 require_once
'../filefunc.inc.php';
39 if (!defined(
'DOL_DOCUMENT_ROOT')) {
40 define(
'DOL_DOCUMENT_ROOT',
'..');
42 if (!defined(
'ADODB_PATH')) {
43 $foundpath = DOL_DOCUMENT_ROOT.
'/includes/adodbtime/';
44 if (!is_dir($foundpath)) {
45 $foundpath =
'/usr/share/php/adodb/';
47 define(
'ADODB_PATH', $foundpath);
50 require_once DOL_DOCUMENT_ROOT.
'/core/class/translate.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/conf.class.php';
52 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
53 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
55 require_once ADODB_PATH.
'adodb-time.inc.php';
60 $_REQUEST[
"logtohtml"] = 1;
64 if (isset($_SERVER[
"DOCUMENT_URI"]) && $_SERVER[
"DOCUMENT_URI"]) {
65 $_SERVER[
"PHP_SELF"] = $_SERVER[
"DOCUMENT_URI"];
69 $includeconferror =
'';
73 $conffiletoshowshort =
"conf.php";
75 $conffile =
"../conf/conf.php";
76 $conffiletoshow =
"htdocs/conf/conf.php";
83 if (!defined(
'DONOTLOADCONF') && file_exists($conffile) && filesize($conffile) > 8) {
84 $result = include_once $conffile;
86 if (empty($dolibarr_main_db_type)) {
87 $dolibarr_main_db_type =
'mysqli';
91 if ($dolibarr_main_db_type ==
'mysql') {
92 $dolibarr_main_db_type =
'mysqli';
95 if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type ==
'mysqli')) {
96 $dolibarr_main_db_port =
'3306';
100 $dolibarr_main_data_root = isset($dolibarr_main_data_root) ?trim($dolibarr_main_data_root) : DOL_DOCUMENT_ROOT.
'/../documents';
101 $dolibarr_main_url_root = isset($dolibarr_main_url_root) ?trim($dolibarr_main_url_root) :
'';
102 $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ?trim($dolibarr_main_url_root_alt) :
'';
103 $dolibarr_main_document_root = isset($dolibarr_main_document_root) ?trim($dolibarr_main_document_root) :
'';
104 $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ?trim($dolibarr_main_document_root_alt) :
'';
107 if (!empty($dolibarr_main_document_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_document_root)) {
108 $dolibarr_main_document_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_document_root);
110 if (!empty($dolibarr_main_url_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_url_root)) {
111 $dolibarr_main_url_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_url_root);
113 if (!empty($dolibarr_main_data_root) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_data_root)) {
114 $dolibarr_main_data_root = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_data_root);
116 if (!empty($dolibarr_main_document_root_alt) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
117 $dolibarr_main_document_root_alt = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_document_root_alt);
119 if (!empty($dolibarr_main_url_root_alt) && !preg_match(
'/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
120 $dolibarr_main_url_root_alt = preg_replace(
'/[\\/]+$/',
'', $dolibarr_main_url_root_alt);
124 if (!empty($dolibarr_main_document_root)) {
125 $result =
conf($dolibarr_main_document_root);
129 if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
130 $result = include_once $dolibarr_main_document_root.
"/core/db/".$dolibarr_main_db_type.
'.class.php';
132 $includeconferror =
'ErrorBadValueForDolibarrMainDBType';
136 $includeconferror =
'ErrorBadValueForDolibarrMainDocumentRoot';
139 $includeconferror =
'ErrorBadFormatForConfFile';
142 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
145 if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
146 $dolibarr_main_db_prefix =
'llx_';
148 define(
'MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix :
''));
150 define(
'DOL_CLASS_PATH',
'class/');
151 define(
'DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : DOL_DOCUMENT_ROOT.
'/../documents'));
152 define(
'DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root :
''));
153 $uri = preg_replace(
'/^http(s?):\/\//i',
'', constant(
'DOL_MAIN_URL_ROOT'));
154 $suburi = strstr($uri,
'/');
155 if ($suburi ==
'/') {
158 define(
'DOL_URL_ROOT', $suburi);
161 if (empty($conf->file->character_set_client)) {
162 $conf->file->character_set_client =
"utf-8";
164 if (empty($conf->db->character_set)) {
165 $conf->db->character_set =
'utf8';
167 if (empty($conf->db->dolibarr_main_db_collation)) {
168 $conf->db->dolibarr_main_db_collation =
'utf8_unicode_ci';
170 if (empty($conf->db->dolibarr_main_db_encryption)) {
171 $conf->db->dolibarr_main_db_encryption = 0;
173 if (empty($conf->db->dolibarr_main_db_cryptkey)) {
174 $conf->db->dolibarr_main_db_cryptkey =
'';
176 if (empty($conf->db->user)) {
177 $conf->db->user =
'';
181 $conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
182 if (!empty($dolibarr_main_document_root_alt)) {
184 $values = preg_split(
'/[;,]/', $dolibarr_main_document_root_alt);
185 foreach ($values as $value) {
186 $conf->file->dol_document_root[] = $value;
192 if (preg_match(
'/install\.lock/i', $_SERVER[
"SCRIPT_FILENAME"])) {
193 if (!is_object($langs)) {
195 $langs->setDefaultLang(
'auto');
197 $langs->load(
"install");
199 header(
"X-Content-Type-Options: nosniff");
200 header(
"X-Frame-Options: SAMEORIGIN");
202 print $langs->trans(
"YouTryInstallDisabledByDirLock");
203 if (!empty($dolibarr_main_url_root)) {
204 print
'Click on following link, <a href="'.$dolibarr_main_url_root.
'/admin/index.php?mainmenu=home&leftmenu=setup'.(
GETPOSTISSET(
"login") ?
'&username='.urlencode(
GETPOST(
"login")) :
'').
'">';
205 print $langs->trans(
"ClickHereToGoToApp");
211 $lockfile = DOL_DATA_ROOT.
'/install.lock';
212 if (constant(
'DOL_DATA_ROOT') ===
null) {
215 $lockfile =
'../../documents/install.lock';
217 if (@file_exists($lockfile)) {
218 if (!isset($langs) || !is_object($langs)) {
220 $langs->setDefaultLang(
'auto');
222 $langs->load(
"install");
224 header(
"X-Content-Type-Options: nosniff");
225 header(
"X-Frame-Options: SAMEORIGIN");
227 print $langs->trans(
"YouTryInstallDisabledByFileLock");
228 if (!empty($dolibarr_main_url_root)) {
229 print $langs->trans(
"ClickOnLinkOrRemoveManualy").
'<br>';
230 print
'<a href="'.$dolibarr_main_url_root.
'/admin/index.php?mainmenu=home&leftmenu=setup'.(
GETPOSTISSET(
"login") ?
'&username='.urlencode(
GETPOST(
"login")) :
'').
'">';
231 print $langs->trans(
"ClickHereToGoToApp");
234 print
'If you always reach this page, you must remove install.lock file manually.<br>';
241 $conf->syslog->enabled = 1;
242 $conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
243 if (!defined(
'SYSLOG_HANDLERS')) {
244 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
246 if (!defined(
'SYSLOG_FILE')) {
247 if (@is_writable(
'/tmp')) {
248 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
249 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
250 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
251 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
252 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
253 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
254 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
255 } elseif (@is_writable(
'../../')) {
256 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
260 if (defined(
'SYSLOG_FILE')) {
261 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
263 if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
264 define(
'SYSLOG_FILE_NO_ERROR', 1);
267 $handlers = array(
'mod_syslog_file');
268 foreach ($handlers as $handler) {
269 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
270 if (!file_exists($file)) {
271 throw new Exception(
'Missing log handler file '.$handler.
'.php');
275 $loghandlerinstance =
new $handler();
277 throw new Exception(
'Log handler does not extend LogHandlerInterface');
280 if (empty($conf->loghandlers[$handler])) {
281 $conf->loghandlers[$handler] = $loghandlerinstance;
288 $langs->setDefaultLang(
GETPOST(
'lang',
'aZ09'));
290 $langs->setDefaultLang(
'auto');
300 function conf($dolibarr_main_document_root)
303 global $dolibarr_main_db_type;
304 global $dolibarr_main_db_host;
305 global $dolibarr_main_db_port;
306 global $dolibarr_main_db_name;
307 global $dolibarr_main_db_user;
308 global $dolibarr_main_db_pass;
309 global $character_set_client;
311 $return = include_once $dolibarr_main_document_root.
'/core/class/conf.class.php';
317 $conf->db->type = trim($dolibarr_main_db_type);
318 $conf->db->host = trim($dolibarr_main_db_host);
319 $conf->db->port = trim($dolibarr_main_db_port);
320 $conf->db->name = trim($dolibarr_main_db_name);
321 $conf->db->user = trim($dolibarr_main_db_user);
322 $conf->db->pass = trim($dolibarr_main_db_pass);
325 if ($conf->db->type ==
'mysql') {
326 $conf->db->type =
'mysqli';
328 if (empty($character_set_client)) {
329 $character_set_client =
"UTF-8";
331 $conf->file->character_set_client = strtoupper($character_set_client);
332 if (empty($dolibarr_main_db_character_set)) {
333 $dolibarr_main_db_character_set = ($conf->db->type ==
'mysqli' ?
'utf8' :
'');
335 $conf->db->character_set = $dolibarr_main_db_character_set;
336 if (empty($dolibarr_main_db_collation)) {
337 $dolibarr_main_db_collation = ($conf->db->type ==
'mysqli' ?
'utf8_unicode_ci' :
'');
339 $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
340 if (empty($dolibarr_main_db_encryption)) {
341 $dolibarr_main_db_encryption = 0;
343 $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
344 if (empty($dolibarr_main_db_cryptkey)) {
345 $dolibarr_main_db_cryptkey =
'';
347 $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
350 $conf->syslog->enabled = 1;
351 $conf->global->SYSLOG_LEVEL = constant(
'LOG_DEBUG');
352 if (!defined(
'SYSLOG_HANDLERS')) {
353 define(
'SYSLOG_HANDLERS',
'["mod_syslog_file"]');
355 if (!defined(
'SYSLOG_FILE')) {
356 if (@is_writable(
'/tmp')) {
357 define(
'SYSLOG_FILE',
'/tmp/dolibarr_install.log');
358 } elseif (!empty($_ENV[
"TMP"]) && @is_writable($_ENV[
"TMP"])) {
359 define(
'SYSLOG_FILE', $_ENV[
"TMP"].
'/dolibarr_install.log');
360 } elseif (!empty($_ENV[
"TEMP"]) && @is_writable($_ENV[
"TEMP"])) {
361 define(
'SYSLOG_FILE', $_ENV[
"TEMP"].
'/dolibarr_install.log');
362 } elseif (@is_writable(
'../../../../') && @file_exists(
'../../../../startdoliwamp.bat')) {
363 define(
'SYSLOG_FILE',
'../../../../dolibarr_install.log');
364 } elseif (@is_writable(
'../../')) {
365 define(
'SYSLOG_FILE',
'../../dolibarr_install.log');
369 if (defined(
'SYSLOG_FILE')) {
370 $conf->global->SYSLOG_FILE = constant(
'SYSLOG_FILE');
372 if (!defined(
'SYSLOG_FILE_NO_ERROR')) {
373 define(
'SYSLOG_FILE_NO_ERROR', 1);
376 $handlers = array(
'mod_syslog_file');
377 foreach ($handlers as $handler) {
378 $file = DOL_DOCUMENT_ROOT.
'/core/modules/syslog/'.$handler.
'.php';
379 if (!file_exists($file)) {
380 throw new Exception(
'Missing log handler file '.$handler.
'.php');
384 $loghandlerinstance =
new $handler();
386 throw new Exception(
'Log handler does not extend LogHandlerInterface');
389 if (empty($conf->loghandlers[$handler])) {
390 $conf->loghandlers[$handler] = $loghandlerinstance;
409 function pHeader($subtitle, $next, $action =
'set', $param =
'', $forcejqueryurl =
'', $csstable =
'main-inside')
413 $langs->load(
"main");
414 $langs->load(
"admin");
415 $langs->load(
"install");
417 $jquerytheme =
'base';
419 if ($forcejqueryurl) {
420 $jQueryCustomPath = $forcejqueryurl;
421 $jQueryUiCustomPath = $forcejqueryurl;
423 $jQueryCustomPath = (defined(
'JS_JQUERY') && constant(
'JS_JQUERY')) ? JS_JQUERY :
false;
424 $jQueryUiCustomPath = (defined(
'JS_JQUERY_UI') && constant(
'JS_JQUERY_UI')) ? JS_JQUERY_UI :
false;
428 header(
"Content-type: text/html; charset=".$conf->file->character_set_client);
429 header(
"X-Content-Type-Options: nosniff");
430 header(
"X-Frame-Options: SAMEORIGIN");
432 print
'<!DOCTYPE HTML>'.
"\n";
435 print
'<meta charset="'.$conf->file->character_set_client.
'">'.
"\n";
436 print
'<meta name="viewport" content="width=device-width, initial-scale=1.0">'.
"\n";
437 print
'<meta name="generator" content="Dolibarr installer">'.
"\n";
438 print
'<link rel="stylesheet" type="text/css" href="default.css">'.
"\n";
440 print
'<!-- Includes CSS for JQuery -->'.
"\n";
441 if ($jQueryUiCustomPath) {
442 print
'<link rel="stylesheet" type="text/css" href="'.$jQueryUiCustomPath.
'css/'.$jquerytheme.
'/jquery-ui.min.css" />'.
"\n";
444 print
'<link rel="stylesheet" type="text/css" href="../includes/jquery/css/'.$jquerytheme.
'/jquery-ui.min.css" />'.
"\n";
447 print
'<!-- Includes JS for JQuery -->'.
"\n";
448 if ($jQueryCustomPath) {
449 print
'<script type="text/javascript" src="'.$jQueryCustomPath.
'jquery.min.js"></script>'.
"\n";
451 print
'<script type="text/javascript" src="../includes/jquery/js/jquery.min.js"></script>'.
"\n";
453 if ($jQueryUiCustomPath) {
454 print
'<script type="text/javascript" src="'.$jQueryUiCustomPath.
'jquery-ui.min.js"></script>'.
"\n";
456 print
'<script type="text/javascript" src="../includes/jquery/js/jquery-ui.min.js"></script>'.
"\n";
459 print
'<title>'.$langs->trans(
"DolibarrSetup").
'</title>'.
"\n";
460 print
'</head>'.
"\n";
464 print
'<div class="divlogoinstall" style="text-align:center">';
465 print
'<img class="imglogoinstall" src="../theme/dolibarr_logo.svg" alt="Dolibarr logo" width="300px"><br>';
469 print
'<span class="titre">'.$langs->trans(
"DolibarrSetup");
471 print
' - '.$subtitle;
473 print
'</span>'.
"\n";
475 print
'<form name="forminstall" style="width: 100%" action="'.$next.
'.php'.($param ?
'?'.$param :
'').
'" method="POST"';
476 if ($next ==
'step5') {
477 print
' autocomplete="off"';
480 print
'<input type="hidden" name="testpost" value="ok">'.
"\n";
481 print
'<input type="hidden" name="action" value="'.$action.
'">'.
"\n";
483 print
'<table class="main" width="100%"><tr><td>'.
"\n";
485 print
'<table class="'.$csstable.
'" width="100%"><tr><td>'.
"\n";
498 function pFooter($nonext = 0, $setuplang =
'', $jscheckfunction =
'', $withpleasewait = 0, $morehtml =
'')
500 global $conf, $langs;
502 $langs->loadLangs(array(
"main",
"other",
"admin"));
504 print
'</td></tr></table>'.
"\n";
505 print
'</td></tr></table>'.
"\n";
507 print
'<!-- pFooter -->'.
"\n";
511 if (!$nonext || ($nonext ==
'2')) {
512 print
'<div class="nextbutton" id="nextbutton">';
513 if ($nonext ==
'2') {
514 print
'<span class="warning">';
515 print $langs->trans(
"ErrorFoundDuringMigration", isset($_SERVER[
"REQUEST_URI"]) ? $_SERVER[
"REQUEST_URI"].
'&ignoreerrors=1' :
'');
520 print
'<input type="submit" '.($nonext ==
'2' ?
'disabled="disabled" ' :
'').
'value="'.$langs->trans(
"NextStep").
' ->"';
521 if ($jscheckfunction) {
522 print
' onClick="return '.$jscheckfunction.
'();"';
525 if ($withpleasewait) {
526 print
'<div style="visibility: hidden;" class="pleasewait" id="pleasewait"><br>'.$langs->trans(
"NextStepMightLastALongTime").
'<br><br><div class="blinkwait">'.$langs->trans(
"PleaseBePatient").
'</div></div>';
530 print
'<input type="hidden" name="selectlang" value="'.dol_escape_htmltag($setuplang).
'">';
533 print
'</form><br>'.
"\n";
536 if (isset($conf->logbuffer) && count($conf->logbuffer)) {
538 print
"<!-- Start of log output\n";
540 foreach ($conf->logbuffer as $logline) {
541 print $logline.
"<br>\n";
544 print
"End of log output -->\n";
548 print
'</body>'.
"\n";
549 print
'</html>'.
"\n";
561 if (!defined(
'LOG_DEBUG')) {
562 define(
'LOG_DEBUG', 6);
576 if ($_SERVER[
"SCRIPT_FILENAME"] ==
'php' || preg_match(
'/[\\/]php$/i', $_SERVER[
"SCRIPT_FILENAME"]) || preg_match(
'/php\.exe$/i', $_SERVER[
"SCRIPT_FILENAME"])) {
577 $dolibarr_main_document_root = $_SERVER[
"DOCUMENT_ROOT"];
579 if (!preg_match(
'/[\\/]dolibarr[\\/]htdocs$/i', $dolibarr_main_document_root)) {
580 $dolibarr_main_document_root .=
"/dolibarr/htdocs";
584 $dolibarr_main_document_root = dirname(dirname($_SERVER[
"SCRIPT_FILENAME"]));
587 return $dolibarr_main_document_root;
598 $dolibarr_main_data_root = preg_replace(
"/\/htdocs$/",
"", $dolibarr_main_document_root);
599 $dolibarr_main_data_root .=
"/documents";
600 return $dolibarr_main_data_root;
611 if (isset($_SERVER[
"SCRIPT_URI"])) {
612 $dolibarr_main_url_root = $_SERVER[
"SCRIPT_URI"];
613 } elseif (isset($_SERVER[
"SERVER_URL"]) && isset($_SERVER[
"DOCUMENT_URI"])) {
615 $dolibarr_main_url_root = $_SERVER[
"SERVER_URL"].$_SERVER[
"DOCUMENT_URI"];
618 $proto = ((!empty($_SERVER[
"HTTPS"]) && $_SERVER[
"HTTPS"] ==
'on') || (!empty($_SERVER[
'SERVER_PORT']) && $_SERVER[
'SERVER_PORT'] == 443)) ?
'https' :
'http';
619 if (!empty($_SERVER[
"HTTP_HOST"])) {
620 $serverport = $_SERVER[
"HTTP_HOST"];
621 } elseif (!empty($_SERVER[
"SERVER_NAME"])) {
622 $serverport = $_SERVER[
"SERVER_NAME"];
624 $serverport =
'localhost';
626 $dolibarr_main_url_root = $proto.
"://".$serverport.$_SERVER[
"SCRIPT_NAME"];
630 $dolibarr_main_url_root = dirname(dirname($dolibarr_main_url_root));
632 return $dolibarr_main_url_root;
643 return preg_replace(
'/__SUPERUSERLOGIN__/',
'root', $force_install_databaserootlogin);
654 return preg_replace(
'/__SUPERUSERPASSWORD__/',
'', $force_install_databaserootpass);