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