dolibarr  16.0.5
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 and ADODB_PATH used for install/upgrade process
39 if (!defined('DOL_DOCUMENT_ROOT')) {
40  define('DOL_DOCUMENT_ROOT', '..');
41 }
42 if (!defined('ADODB_PATH')) {
43  $foundpath = DOL_DOCUMENT_ROOT.'/includes/adodbtime/';
44  if (!is_dir($foundpath)) {
45  $foundpath = '/usr/share/php/adodb/';
46  }
47  define('ADODB_PATH', $foundpath);
48 }
49 
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';
56 
57 $conf = new Conf();
58 
59 // Force $_REQUEST["logtohtml"]
60 $_REQUEST["logtohtml"] = 1;
61 
62 // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
63 // et non path absolu.
64 if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) {
65  $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
66 }
67 
68 
69 $includeconferror = '';
70 
71 
72 // Define vars
73 $conffiletoshowshort = "conf.php";
74 // Define localization of conf file
75 $conffile = "../conf/conf.php";
76 $conffiletoshow = "htdocs/conf/conf.php";
77 // For debian/redhat like systems
78 //$conffile = "/etc/dolibarr/conf.php";
79 //$conffiletoshow = "/etc/dolibarr/conf.php";
80 
81 
82 // Load conf file if it is already defined
83 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
84  $result = include_once $conffile; // Load conf file
85  if ($result) {
86  if (empty($dolibarr_main_db_type)) {
87  $dolibarr_main_db_type = 'mysqli'; // For backward compatibility
88  }
89 
90  //Mysql driver support has been removed in favor of mysqli
91  if ($dolibarr_main_db_type == 'mysql') {
92  $dolibarr_main_db_type = 'mysqli';
93  }
94 
95  if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type == 'mysqli')) {
96  $dolibarr_main_db_port = '3306'; // For backward compatibility
97  }
98 
99  // Clean parameters
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) : '';
105 
106  // Remove last / or \ on directories or url value
107  if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) {
108  $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root);
109  }
110  if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) {
111  $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root);
112  }
113  if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) {
114  $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root);
115  }
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);
118  }
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);
121  }
122 
123  // Create conf object
124  if (!empty($dolibarr_main_document_root)) {
125  $result = conf($dolibarr_main_document_root);
126  }
127  // Load database driver
128  if ($result) {
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';
131  if (!$result) {
132  $includeconferror = 'ErrorBadValueForDolibarrMainDBType';
133  }
134  }
135  } else {
136  $includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot';
137  }
138  } else {
139  $includeconferror = 'ErrorBadFormatForConfFile';
140  }
141 }
142 $conf->global->MAIN_ENABLE_LOG_TO_HTML = 1;
143 
144 // Define prefix
145 if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
146  $dolibarr_main_db_prefix = 'llx_';
147 }
148 define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : ''));
149 
150 define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir
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 : '')); // URL relative root
153 $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
154 $suburi = strstr($uri, '/'); // $suburi contains url without domain
155 if ($suburi == '/') {
156  $suburi = ''; // If $suburi is /, it is now ''
157 }
158 define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
159 
160 
161 if (empty($conf->file->character_set_client)) {
162  $conf->file->character_set_client = "utf-8";
163 }
164 if (empty($conf->db->character_set)) {
165  $conf->db->character_set = 'utf8';
166 }
167 if (empty($conf->db->dolibarr_main_db_collation)) {
168  $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
169 }
170 if (empty($conf->db->dolibarr_main_db_encryption)) {
171  $conf->db->dolibarr_main_db_encryption = 0;
172 }
173 if (empty($conf->db->dolibarr_main_db_cryptkey)) {
174  $conf->db->dolibarr_main_db_cryptkey = '';
175 }
176 if (empty($conf->db->user)) {
177  $conf->db->user = '';
178 }
179 
180 // Define array of document root directories
181 $conf->file->dol_document_root = array(DOL_DOCUMENT_ROOT);
182 if (!empty($dolibarr_main_document_root_alt)) {
183  // dolibarr_main_document_root_alt contains several directories
184  $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
185  foreach ($values as $value) {
186  $conf->file->dol_document_root[] = $value;
187  }
188 }
189 
190 
191 // Security check (old method, when directory is renamed /install.lock)
192 if (preg_match('/install\.lock/i', $_SERVER["SCRIPT_FILENAME"])) {
193  if (!is_object($langs)) {
194  $langs = new Translate('..', $conf);
195  $langs->setDefaultLang('auto');
196  }
197  $langs->load("install");
198 
199  header("X-Content-Type-Options: nosniff");
200  header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
201 
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");
206  print '</a>';
207  }
208  exit;
209 }
210 
211 $lockfile = DOL_DATA_ROOT.'/install.lock';
212 if (constant('DOL_DATA_ROOT') === null) {
213  // We don't have a configuration file yet
214  // Try to detect any lockfile in the default documents path
215  $lockfile = '../../documents/install.lock';
216 }
217 if (@file_exists($lockfile)) {
218  if (!isset($langs) || !is_object($langs)) {
219  $langs = new Translate('..', $conf);
220  $langs->setDefaultLang('auto');
221  }
222  $langs->load("install");
223 
224  header("X-Content-Type-Options: nosniff");
225  header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
226 
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");
232  print '</a>';
233  } else {
234  print 'If you always reach this page, you must remove install.lock file manually.<br>';
235  }
236  exit;
237 }
238 
239 
240 // Force usage of log file for install and upgrades
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"]');
245 }
246 if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
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'); // For DoliWamp
255  } elseif (@is_writable('../../')) {
256  define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
257  }
258  //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
259 }
260 if (defined('SYSLOG_FILE')) {
261  $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
262 }
263 if (!defined('SYSLOG_FILE_NO_ERROR')) {
264  define('SYSLOG_FILE_NO_ERROR', 1);
265 }
266 // We init log handler for install
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');
272  }
273 
274  require_once $file;
275  $loghandlerinstance = new $handler();
276  if (!$loghandlerinstance instanceof LogHandlerInterface) {
277  throw new Exception('Log handler does not extend LogHandlerInterface');
278  }
279 
280  if (empty($conf->loghandlers[$handler])) {
281  $conf->loghandlers[$handler] = $loghandlerinstance;
282  }
283 }
284 
285 // Define object $langs
286 $langs = new Translate('..', $conf);
287 if (GETPOST('lang', 'aZ09')) {
288  $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
289 } else {
290  $langs->setDefaultLang('auto');
291 }
292 
293 
300 function conf($dolibarr_main_document_root)
301 {
302  global $conf;
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;
310 
311  $return = include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
312  if (!$return) {
313  return -1;
314  }
315 
316  $conf = new Conf();
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);
323 
324  // Mysql driver support has been removed in favor of mysqli
325  if ($conf->db->type == 'mysql') {
326  $conf->db->type = 'mysqli';
327  }
328  if (empty($character_set_client)) {
329  $character_set_client = "UTF-8";
330  }
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' : '');
334  }
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' : '');
338  }
339  $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
340  if (empty($dolibarr_main_db_encryption)) {
341  $dolibarr_main_db_encryption = 0;
342  }
343  $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
344  if (empty($dolibarr_main_db_cryptkey)) {
345  $dolibarr_main_db_cryptkey = '';
346  }
347  $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
348 
349  // Force usage of log file for install and upgrades
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"]');
354  }
355  if (!defined('SYSLOG_FILE')) { // To avoid warning on systems with constant already defined
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'); // For DoliWamp
364  } elseif (@is_writable('../../')) {
365  define('SYSLOG_FILE', '../../dolibarr_install.log'); // For others
366  }
367  //print 'SYSLOG_FILE='.SYSLOG_FILE;exit;
368  }
369  if (defined('SYSLOG_FILE')) {
370  $conf->global->SYSLOG_FILE = constant('SYSLOG_FILE');
371  }
372  if (!defined('SYSLOG_FILE_NO_ERROR')) {
373  define('SYSLOG_FILE_NO_ERROR', 1);
374  }
375  // We init log handler for install
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');
381  }
382 
383  require_once $file;
384  $loghandlerinstance = new $handler();
385  if (!$loghandlerinstance instanceof LogHandlerInterface) {
386  throw new Exception('Log handler does not extend LogHandlerInterface');
387  }
388 
389  if (empty($conf->loghandlers[$handler])) {
390  $conf->loghandlers[$handler] = $loghandlerinstance;
391  }
392  }
393 
394  return 1;
395 }
396 
397 
409 function pHeader($subtitle, $next, $action = 'set', $param = '', $forcejqueryurl = '', $csstable = 'main-inside')
410 {
411  global $conf;
412  global $langs;
413  $langs->load("main");
414  $langs->load("admin");
415  $langs->load("install");
416 
417  $jquerytheme = 'base';
418 
419  if ($forcejqueryurl) {
420  $jQueryCustomPath = $forcejqueryurl;
421  $jQueryUiCustomPath = $forcejqueryurl;
422  } else {
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;
425  }
426 
427  // We force the content charset
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"); // Frames allowed only if on same domain (stop some XSS attacks)
431 
432  print '<!DOCTYPE HTML>'."\n";
433  print '<html>'."\n";
434  print '<head>'."\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";
439 
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"; // JQuery
443  } else {
444  print '<link rel="stylesheet" type="text/css" href="../includes/jquery/css/'.$jquerytheme.'/jquery-ui.min.css" />'."\n"; // JQuery
445  }
446 
447  print '<!-- Includes JS for JQuery -->'."\n";
448  if ($jQueryCustomPath) {
449  print '<script type="text/javascript" src="'.$jQueryCustomPath.'jquery.min.js"></script>'."\n";
450  } else {
451  print '<script type="text/javascript" src="../includes/jquery/js/jquery.min.js"></script>'."\n";
452  }
453  if ($jQueryUiCustomPath) {
454  print '<script type="text/javascript" src="'.$jQueryUiCustomPath.'jquery-ui.min.js"></script>'."\n";
455  } else {
456  print '<script type="text/javascript" src="../includes/jquery/js/jquery-ui.min.js"></script>'."\n";
457  }
458 
459  print '<title>'.$langs->trans("DolibarrSetup").'</title>'."\n";
460  print '</head>'."\n";
461 
462  print '<body>'."\n";
463 
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>';
466  print DOL_VERSION;
467  print '</div><br>';
468 
469  print '<span class="titre">'.$langs->trans("DolibarrSetup");
470  if ($subtitle) {
471  print ' - '.$subtitle;
472  }
473  print '</span>'."\n";
474 
475  print '<form name="forminstall" style="width: 100%" action="'.$next.'.php'.($param ? '?'.$param : '').'" method="POST"';
476  if ($next == 'step5') {
477  print ' autocomplete="off"';
478  }
479  print '>'."\n";
480  print '<input type="hidden" name="testpost" value="ok">'."\n";
481  print '<input type="hidden" name="action" value="'.$action.'">'."\n";
482 
483  print '<table class="main" width="100%"><tr><td>'."\n";
484 
485  print '<table class="'.$csstable.'" width="100%"><tr><td>'."\n";
486 }
487 
498 function pFooter($nonext = 0, $setuplang = '', $jscheckfunction = '', $withpleasewait = 0, $morehtml = '')
499 {
500  global $conf, $langs;
501 
502  $langs->loadLangs(array("main", "other", "admin"));
503 
504  print '</td></tr></table>'."\n";
505  print '</td></tr></table>'."\n";
506 
507  print '<!-- pFooter -->'."\n";
508 
509  print $morehtml;
510 
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' : '');
516  print '</span>';
517  print '<br><br>';
518  }
519 
520  print '<input type="submit" '.($nonext == '2' ? 'disabled="disabled" ' : '').'value="'.$langs->trans("NextStep").' ->"';
521  if ($jscheckfunction) {
522  print ' onClick="return '.$jscheckfunction.'();"';
523  }
524  print '></div>';
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>';
527  }
528  }
529  if ($setuplang) {
530  print '<input type="hidden" name="selectlang" value="'.dol_escape_htmltag($setuplang).'">';
531  }
532 
533  print '</form><br>'."\n";
534 
535  // If there is some logs in buffer to show
536  if (isset($conf->logbuffer) && count($conf->logbuffer)) {
537  print "\n";
538  print "<!-- Start of log output\n";
539  //print '<div class="hidden">'."\n";
540  foreach ($conf->logbuffer as $logline) {
541  print $logline."<br>\n";
542  }
543  //print '</div>'."\n";
544  print "End of log output -->\n";
545  print "\n";
546  }
547 
548  print '</body>'."\n";
549  print '</html>'."\n";
550 }
551 
559 function dolibarr_install_syslog($message, $level = LOG_DEBUG)
560 {
561  if (!defined('LOG_DEBUG')) {
562  define('LOG_DEBUG', 6);
563  }
564  dol_syslog($message, $level);
565 }
566 
573 {
574  // If PHP is in CGI mode, SCRIPT_FILENAME is PHP's path.
575  // Since that's not what we want, we suggest $_SERVER["DOCUMENT_ROOT"]
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"];
578 
579  if (!preg_match('/[\\/]dolibarr[\\/]htdocs$/i', $dolibarr_main_document_root)) {
580  $dolibarr_main_document_root .= "/dolibarr/htdocs";
581  }
582  } else {
583  // We assume /install to be under /htdocs, so we get the parent directory of the current directory
584  $dolibarr_main_document_root = dirname(dirname($_SERVER["SCRIPT_FILENAME"]));
585  }
586 
587  return $dolibarr_main_document_root;
588 }
589 
596 function detect_dolibarr_main_data_root($dolibarr_main_document_root)
597 {
598  $dolibarr_main_data_root = preg_replace("/\/htdocs$/", "", $dolibarr_main_document_root);
599  $dolibarr_main_data_root .= "/documents";
600  return $dolibarr_main_data_root;
601 }
602 
609 {
610  // If defined (Ie: Apache with Linux)
611  if (isset($_SERVER["SCRIPT_URI"])) {
612  $dolibarr_main_url_root = $_SERVER["SCRIPT_URI"];
613  } elseif (isset($_SERVER["SERVER_URL"]) && isset($_SERVER["DOCUMENT_URI"])) {
614  // If defined (Ie: Apache with Caudium)
615  $dolibarr_main_url_root = $_SERVER["SERVER_URL"].$_SERVER["DOCUMENT_URI"];
616  } else {
617  // If SCRIPT_URI, SERVER_URL, DOCUMENT_URI not defined (Ie: Apache 2.0.44 for Windows)
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"];
623  } else {
624  $serverport = 'localhost';
625  }
626  $dolibarr_main_url_root = $proto."://".$serverport.$_SERVER["SCRIPT_NAME"];
627  }
628  // Clean proposed URL
629  // We assume /install to be under /htdocs, so we get the parent path of the current URL
630  $dolibarr_main_url_root = dirname(dirname($dolibarr_main_url_root));
631 
632  return $dolibarr_main_url_root;
633 }
634 
641 function parse_database_login($force_install_databaserootlogin)
642 {
643  return preg_replace('/__SUPERUSERLOGIN__/', 'root', $force_install_databaserootlogin);
644 }
645 
652 function parse_database_pass($force_install_databaserootpass)
653 {
654  return preg_replace('/__SUPERUSERPASSWORD__/', '', $force_install_databaserootpass);
655 }
detect_dolibarr_main_data_root
detect_dolibarr_main_data_root($dolibarr_main_document_root)
Automatically detect Dolibarr's main data root.
Definition: inc.php:596
detect_dolibarr_main_url_root
detect_dolibarr_main_url_root()
Automatically detect Dolibarr's main URL root.
Definition: inc.php:608
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
detect_dolibarr_main_document_root
detect_dolibarr_main_document_root()
Automatically detect Dolibarr's main document root.
Definition: inc.php:572
Translate
Class to manage translations.
Definition: translate.class.php:30
parse_database_pass
parse_database_pass($force_install_databaserootpass)
Replaces automatic database password by actual value.
Definition: inc.php:652
Conf
Class to stock current configuration.
Definition: conf.class.php:33
parse_database_login
parse_database_login($force_install_databaserootlogin)
Replaces automatic database login by actual value.
Definition: inc.php:641
Exception
LogHandlerInterface
LogHandlerInterface.
Definition: logHandlerInterface.php:27
dolibarr_install_syslog
dolibarr_install_syslog($message, $level=LOG_DEBUG)
Log function for install pages.
Definition: inc.php:559
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
conf
conf($dolibarr_main_document_root)
Load conf file (file must exists)
Definition: inc.php:300
pHeader
pHeader($subtitle, $next, $action='set', $param='', $forcejqueryurl='', $csstable='main-inside')
Show HTML header of install pages.
Definition: inc.php:409
pFooter
pFooter($nonext=0, $setuplang='', $jscheckfunction='', $withpleasewait=0, $morehtml='')
Print HTML footer of install pages.
Definition: inc.php:498
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386