38require_once
'version.inc.php';
41setlocale(LC_NUMERIC,
'C');
44if (!defined(
'LOG_DEBUG')) {
45 if (!function_exists(
"syslog")) {
47 define(
'LOG_EMERG', 0);
48 define(
'LOG_ALERT', 1);
49 define(
'LOG_CRIT', 2);
51 define(
'LOG_WARNING', 4);
52 define(
'LOG_NOTICE', 5);
53 define(
'LOG_INFO', 6);
54 define(
'LOG_DEBUG', 7);
59if (defined(
'DOL_INC_FOR_VERSION_ERROR')) {
81 return session_regenerate_id();
96 $session_backup = $_SESSION;
99 $_SESSION[
'OBSOLETE'] =
true;
100 $_SESSION[
'EXPIRES'] = time() + 60;
103 session_write_close();
106 session_name($sessionname);
110 $_SESSION = $session_backup;
113 unset($session_backup);
114 unset($_SESSION[
'OBSOLETE']);
115 unset($_SESSION[
'EXPIRES']);
126$conffiletoshow =
"htdocs/conf/conf.php";
187if (!$result && !empty($_SERVER[
"GATEWAY_INTERFACE"])) {
188 if (!empty($_SERVER[
"CONTEXT_PREFIX"])) {
189 $path = $_SERVER[
"CONTEXT_PREFIX"];
190 if (!preg_match(
'/\/$/', $path)) {
193 } elseif (preg_match(
'/index\.php/', $_SERVER[
'PHP_SELF'])) {
203 $TDir = explode(
'/', $_SERVER[
'PHP_SELF']);
207 if (empty($TDir[$i]) || $TDir[$i] ==
'htdocs') {
210 if ($TDir[$i] ==
'dolibarr') {
213 if (substr($TDir[$i], -4, 4) ==
'.php') {
221 header(
"Location: ".$path.
"install/index.php");
233if (version_compare(phpversion(),
'8.4',
'<')) {
234 if (!empty($dolibarr_strict_mode)) {
235 error_reporting(E_ALL | E_STRICT);
237 error_reporting(E_ALL & ~(E_STRICT | E_NOTICE | E_DEPRECATED));
241 if (!empty($dolibarr_strict_mode)) {
242 error_reporting(E_ALL);
244 error_reporting(E_ALL & ~(E_NOTICE | E_DEPRECATED));
249if (!empty($dolibarr_main_prod)) {
250 ini_set(
'display_errors',
'Off');
254$dolibarr_main_data_root = (empty($dolibarr_main_data_root) ?
'' : trim($dolibarr_main_data_root));
256$dolibarr_main_url_root_alt = (empty($dolibarr_main_url_root_alt) ?
'' : trim($dolibarr_main_url_root_alt));
257$dolibarr_main_document_root = (empty($dolibarr_main_document_root) ?
'' : trim($dolibarr_main_document_root));
258$dolibarr_main_document_root_alt = (empty($dolibarr_main_document_root_alt) ?
'' : trim($dolibarr_main_document_root_alt));
260if (!isset($dolibarr_main_db_port)) {
261 $dolibarr_main_db_port = 3306;
263if (empty($dolibarr_main_db_type)) {
264 $dolibarr_main_db_type =
'mysqli';
268if ($dolibarr_main_db_type ==
'mysql') {
269 $dolibarr_main_db_type =
'mysqli';
271if (empty($dolibarr_main_db_prefix)) {
272 $dolibarr_main_db_prefix =
'llx_';
274if (empty($dolibarr_main_db_character_set)) {
275 $dolibarr_main_db_character_set = ($dolibarr_main_db_type ==
'mysqli' ?
'utf8' :
'');
277if (empty($dolibarr_main_db_collation)) {
278 $dolibarr_main_db_collation = ($dolibarr_main_db_type ==
'mysqli' ?
'utf8_unicode_ci' :
'');
280if (empty($dolibarr_main_db_encryption)) {
281 $dolibarr_main_db_encryption = 0;
283if (empty($dolibarr_main_db_cryptkey)) {
284 $dolibarr_main_db_cryptkey =
'';
286if (empty($dolibarr_main_limit_users)) {
287 $dolibarr_main_limit_users = 0;
289if (empty($dolibarr_mailing_limit_sendbyweb)) {
290 $dolibarr_mailing_limit_sendbyweb = 0;
292if (empty($dolibarr_mailing_limit_sendbycli)) {
293 $dolibarr_mailing_limit_sendbycli = 0;
295if (empty($dolibarr_mailing_limit_sendbyday)) {
296 $dolibarr_mailing_limit_sendbyday = 0;
298if (empty($dolibarr_strict_mode)) {
299 $dolibarr_strict_mode = 0;
302if (!defined(
'DOL_DOCUMENT_ROOT')) {
303 define(
'DOL_DOCUMENT_ROOT', $dolibarr_main_document_root);
307if (empty(DOL_DOCUMENT_ROOT) || !file_exists(DOL_DOCUMENT_ROOT.
"/core/lib/functions.lib.php")) {
308 print
"Error: Dolibarr config file content seems to be not correctly defined";
309 if (empty($dolibarr_main_document_root)) {
310 print
" (dolibarr_main_document_root can't be unknown).<br>\n";
312 print
" (file ".DOL_DOCUMENT_ROOT.
"/core/lib/functions.lib.php not found).<br>\n";
314 print
"Please run dolibarr setup by calling page <b>/install</b>.<br>\n";
320include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
321include_once DOL_DOCUMENT_ROOT.
'/core/lib/html.lib.php';
322include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
323include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/securitycore.lib.php';
332if (!defined(
'NOCSRFCHECK') && isset($dolibarr_nocsrfcheck) && $dolibarr_nocsrfcheck == 1) {
333 if (!empty($_SERVER[
'REQUEST_METHOD']) && !in_array($_SERVER[
'REQUEST_METHOD'], array(
'GET',
'HEAD')) && !empty($_SERVER[
'HTTP_HOST'])) {
335 if (empty($_SERVER[
'HTTP_REFERER'])) {
338 $tmpa = parse_url($_SERVER[
'HTTP_HOST']);
339 $tmpb = parse_url($_SERVER[
'HTTP_REFERER']);
340 if ((empty($tmpa[
'host']) ? $tmpa[
'path'] : $tmpa[
'host']) != (empty($tmpb[
'host']) ? $tmpb[
'path'] : $tmpb[
'host'])) {
347 dol_syslog(
"--- Access to ".(empty($_SERVER[
"REQUEST_METHOD"]) ?
'' : $_SERVER[
"REQUEST_METHOD"].
' ').$_SERVER[
"PHP_SELF"].
" refused by CSRF protection (Bad referrer).", LOG_WARNING);
348 print
"Access refused by CSRF protection in main.inc.php. Referrer of form (".htmlentities(empty($_SERVER[
'HTTP_REFERER']) ?
'' : $_SERVER[
'HTTP_REFERER'], ENT_COMPAT,
'UTF-8').
") is outside the server that serve this page (with method = ".htmlentities($_SERVER[
'REQUEST_METHOD'], ENT_COMPAT,
'UTF-8').
").\n";
349 print
"If you access your server behind a proxy using url rewriting, you might check that all HTTP headers are propagated (or add the line \$dolibarr_nocsrfcheck=1 into your conf.php file to remove this security check).\n";
355if (empty($dolibarr_main_db_host) && !defined(
'NOREQUIREDB')) {
356 print
'<div class="center">Dolibarr setup is not yet complete.<br><br>'.
"\n";
357 print
'<a href="install/index.php">Click here to finish Dolibarr install process</a> ...</div>'.
"\n";
360if (empty($dolibarr_main_url_root) && !defined(
'NOREQUIREVIRTUALURL')) {
361 print
'Value for parameter \'dolibarr_main_url_root\' is not defined in your \'htdocs\conf\conf.php\' file.<br>'.
"\n";
362 print
'You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)'.
"\n";
366if (empty($dolibarr_main_url_root_alt)) {
367 $dolibarr_main_url_root_alt =
'/custom';
369if (empty($dolibarr_main_document_root_alt)) {
370 $dolibarr_main_document_root_alt = $dolibarr_main_document_root.
'/custom';
373if (empty($dolibarr_main_data_root)) {
375 $dolibarr_main_data_root = str_replace(
"/htdocs",
"", $dolibarr_main_document_root);
376 $dolibarr_main_data_root .=
"/documents";
380define(
'DOL_CLASS_PATH',
'class/');
381define(
'DOL_DATA_ROOT', $dolibarr_main_data_root);
386$real_dolibarr_main_document_root = str_replace(
'\\',
'/', realpath($dolibarr_main_document_root));
387if (!empty($_SERVER[
"DOCUMENT_ROOT"])) {
388 $pathroot = $_SERVER[
"DOCUMENT_ROOT"];
390 $pathroot =
'NOTDEFINED';
392$paths = explode(
'/', str_replace(
'\\',
'/', $_SERVER[
"SCRIPT_NAME"]));
396foreach ($paths as $tmppath) {
397 if (empty($tmppath)) {
400 $concatpath .=
'/'.$tmppath;
403 if ($real_dolibarr_main_document_root == @realpath($pathroot.$concatpath)) {
419 $tmp =
'http'.((!
isHTTPS() && (empty($_SERVER[
"SERVER_PORT"]) || $_SERVER[
"SERVER_PORT"] != 443)) ?
'' :
's').
'://'.$_SERVER[
"SERVER_NAME"].((empty($_SERVER[
"SERVER_PORT"]) || $_SERVER[
"SERVER_PORT"] == 80 || $_SERVER[
"SERVER_PORT"] == 443) ?
'' :
':'.$_SERVER[
"SERVER_PORT"]).($tmp3 ? (preg_match(
'/^\//', $tmp3) ?
'' :
'/').$tmp3 :
'');
423if (!empty($dolibarr_main_force_https)) {
424 $tmp = preg_replace(
'/^http:/i',
'https:', $tmp);
427define(
'DOL_MAIN_URL_ROOT', $tmp);
428$uri = preg_replace(
'/^http(s?):\/\//i',
'', constant(
'DOL_MAIN_URL_ROOT'));
429$suburi = strstr($uri,
'/');
430if (empty($suburi) || $suburi ===
'/') {
433if (!defined(
'DOL_URL_ROOT')) {
434 define(
'DOL_URL_ROOT', $suburi);
439define(
'MAIN_DB_PREFIX', $dolibarr_main_db_prefix);
447if (!defined(
'TCPDF_PATH')) {
448 define(
'TCPDF_PATH', (empty($dolibarr_lib_TCPDF_PATH)) ? DOL_DOCUMENT_ROOT.
'/includes/tecnickcom/tcpdf/' : $dolibarr_lib_TCPDF_PATH.
'/');
450if (!defined(
'TCPDI_PATH')) {
451 define(
'TCPDI_PATH', (empty($dolibarr_lib_TCPDI_PATH)) ? DOL_DOCUMENT_ROOT.
'/includes/tcpdi/' : $dolibarr_lib_TCPDI_PATH.
'/');
453if (!defined(
'NUSOAP_PATH')) {
454 define(
'NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH)) ? DOL_DOCUMENT_ROOT.
'/includes/nusoap/lib/' : (empty($dolibarr_lib_NUSOAP_PATH) ?
'' : $dolibarr_lib_NUSOAP_PATH.
'/'));
456if (!defined(
'PHPEXCELNEW_PATH')) {
457 define(
'PHPEXCELNEW_PATH', (!isset($dolibarr_lib_PHPEXCELNEW_PATH)) ? DOL_DOCUMENT_ROOT.
'/includes/phpoffice/phpspreadsheet/src/PhpSpreadsheet/' : (empty($dolibarr_lib_PHPEXCELNEW_PATH) ?
'' : $dolibarr_lib_PHPEXCELNEW_PATH.
'/'));
459if (!defined(
'ODTPHP_PATH')) {
460 define(
'ODTPHP_PATH', (!isset($dolibarr_lib_ODTPHP_PATH)) ? DOL_DOCUMENT_ROOT.
'/includes/odtphp/' : (empty($dolibarr_lib_ODTPHP_PATH) ?
'' : $dolibarr_lib_ODTPHP_PATH.
'/'));
462if (!defined(
'ODTPHP_PATHTOPCLZIP')) {
463 define(
'ODTPHP_PATHTOPCLZIP', (!isset($dolibarr_lib_ODTPHP_PATHTOPCLZIP)) ? DOL_DOCUMENT_ROOT.
'/includes/odtphp/zip/pclzip/' : (empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP) ?
'' : $dolibarr_lib_ODTPHP_PATHTOPCLZIP.
'/'));
465if (!defined(
'JS_CKEDITOR')) {
466 define(
'JS_CKEDITOR', (!isset($dolibarr_js_CKEDITOR)) ?
'' : (empty($dolibarr_js_CKEDITOR) ?
'' : $dolibarr_js_CKEDITOR.
'/'));
468if (!defined(
'JS_JQUERY')) {
469 define(
'JS_JQUERY', (!isset($dolibarr_js_JQUERY)) ?
'' : (empty($dolibarr_js_JQUERY) ?
'' : $dolibarr_js_JQUERY.
'/'));
471if (!defined(
'JS_JQUERY_UI')) {
472 define(
'JS_JQUERY_UI', (!isset($dolibarr_js_JQUERY_UI)) ?
'' : (empty($dolibarr_js_JQUERY_UI) ?
'' : $dolibarr_js_JQUERY_UI.
'/'));
475if (!defined(
'DOL_DEFAULT_TTF')) {
476 define(
'DOL_DEFAULT_TTF', (!isset($dolibarr_font_DOL_DEFAULT_TTF)) ? DOL_DOCUMENT_ROOT.
'/includes/fonts/Aerial.ttf' : (empty($dolibarr_font_DOL_DEFAULT_TTF) ?
'' : $dolibarr_font_DOL_DEFAULT_TTF));
478if (!defined(
'DOL_DEFAULT_TTF_BOLD')) {
479 define(
'DOL_DEFAULT_TTF_BOLD', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD)) ? DOL_DOCUMENT_ROOT.
'/includes/fonts/AerialBd.ttf' : (empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD) ?
'' : $dolibarr_font_DOL_DEFAULT_TTF_BOLD));
488if ((!empty($dolibarr_main_db_pass) && preg_match(
'/(dolcrypt|crypted):/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
489 if (!empty($dolibarr_main_db_pass) && preg_match(
'/crypted:/i', $dolibarr_main_db_pass)) {
490 $dolibarr_main_db_pass = preg_replace(
'/crypted:/i',
'', $dolibarr_main_db_pass);
491 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
492 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_pass);
493 } elseif (!empty($dolibarr_main_db_pass) && preg_match(
'/dolcrypt:/i', $dolibarr_main_db_pass)) {
494 $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass;
495 $dolibarr_main_db_pass =
dolDecrypt($dolibarr_main_db_pass, (empty($dolibarr_main_dolcrypt_key) ? (empty($dolibarr_main_instance_unique_id) ?
'' : $dolibarr_main_instance_unique_id) : $dolibarr_main_dolcrypt_key));
497 $dolibarr_main_db_pass =
dol_decode($dolibarr_main_db_encrypted_pass);
global $dolibarr_main_url_root
if(!defined('LOG_DEBUG')) if(defined( 'DOL_INC_FOR_VERSION_ERROR')) dol_session_start()
Replace session_start()
dol_session_regenerate_id()
Replace session_regenerate_id()
dol_session_rotate($sessionname='')
Destroy and recreate a new session without losing content.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_decode($chain, $key='1')
Decode a base 64 encoded + specific delta change.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
isHTTPS()
Return if we are using a HTTPS connection Check HTTPS (no way to be modified by user but may be empty...