dolibarr/htdocs/filefunc.inc.php

454 lines
20 KiB
PHP
Raw Permalink Normal View History

2012-08-22 23:27:53 +02:00
<?php
/* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
2017-01-03 10:36:27 +01:00
* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
2018-10-27 14:43:12 +02:00
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
* Copyright (C) 2006 Andre Cianfarani <andre.cianfarani@acdeveloppement.net>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
2015-04-18 21:59:00 +02:00
* Copyright (C) 2015 Bahfir Abbes <bafbes@gmail.com>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/filefunc.inc.php
* \ingroup core
* \brief File that include conf.php file and commons lib like functions.lib.php
*/
2021-02-23 20:24:49 +01:00
if (!defined('DOL_APPLICATION_TITLE')) {
define('DOL_APPLICATION_TITLE', 'Dolibarr');
}
if (!defined('DOL_VERSION')) {
2025-01-05 16:14:21 +01:00
define('DOL_VERSION', '22.0.0-alpha'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c
2021-02-23 20:24:49 +01:00
}
2021-02-23 20:24:49 +01:00
if (!defined('EURO')) {
define('EURO', chr(128));
}
2012-01-29 20:57:40 +01:00
// Define syslog constants
2021-02-23 20:24:49 +01:00
if (!defined('LOG_DEBUG')) {
if (!function_exists("syslog")) {
// For PHP versions without syslog (like running on Windows OS)
define('LOG_EMERG', 0);
define('LOG_ALERT', 1);
define('LOG_CRIT', 2);
define('LOG_ERR', 3);
define('LOG_WARNING', 4);
define('LOG_NOTICE', 5);
define('LOG_INFO', 6);
define('LOG_DEBUG', 7);
}
}
// End of common declaration part
2021-02-23 20:24:49 +01:00
if (defined('DOL_INC_FOR_VERSION_ERROR')) {
return;
}
2024-03-14 22:06:43 +01:00
/**
* Replace session_start()
*
* @return void
*/
function dol_session_start()
{
session_start();
}
/**
* Replace session_regenerate_id()
*
* @return bool True if success, false if failed
2024-03-14 22:06:43 +01:00
*/
function dol_session_regenerate_id()
{
return session_regenerate_id();
2024-03-14 22:06:43 +01:00
}
/**
* Destroy and recreate a new session without losing content.
* Not used yet.
*
* @param string $sessionname Session name
2024-03-14 22:06:43 +01:00
* @return void
*/
function dol_session_rotate($sessionname = '')
{
$oldsessionid = session_id();
// Backup the current session
$session_backup = $_SESSION;
// Set current session to expire in 1 minute
$_SESSION['OBSOLETE'] = true;
$_SESSION['EXPIRES'] = time() + 60;
// Close the current session
session_write_close();
// Set a new session id and start the session
session_name($sessionname);
dol_session_start();
// Restore the previous session backup
$_SESSION = $session_backup;
// Clean up
unset($session_backup);
unset($_SESSION['OBSOLETE']);
unset($_SESSION['EXPIRES']);
$newsessionid = session_id();
//var_dump("oldsessionid=".$oldsessionid." - newsessionid=".$newsessionid);
}
// Define vars
$conffiletoshowshort = "conf.php";
// Define localization of conf file
2015-07-12 23:47:39 +02:00
// --- Start of part replaced by Dolibarr packager makepack-dolibarr
$conffile = "conf/conf.php";
$conffiletoshow = "htdocs/conf/conf.php";
// For debian/redhat like systems
//$conffile = "/etc/dolibarr/conf.php";
//$conffiletoshow = "/etc/dolibarr/conf.php";
2015-07-12 23:47:39 +02:00
// Include configuration
// --- End of part replaced by Dolibarr packager makepack-dolibarr
2015-09-13 22:50:08 +02:00
// Include configuration
// @phpstan-ignore-next-line
2024-03-14 22:06:43 +01:00
$result = @include_once $conffile; // Keep @ because with some error reporting mode, this breaks the redirect done when file is not found
2013-03-09 18:55:57 +01:00
// Disable some not used PHP stream
$listofwrappers = stream_get_wrappers();
// We need '.phar' for geoip2. TODO Replace phar in geoip with exploded files so we can disable phar by default.
2023-12-21 11:43:30 +01:00
// phar stream does not auto unserialize content (possible code execution) since PHP 8.1
2024-03-23 19:39:47 +01:00
// zip stream is necessary by excel import module
2024-03-21 17:08:14 +01:00
$arrayofstreamtodisable = array('compress.zlib', 'compress.bzip2', 'ftp', 'ftps', 'glob', 'data', 'expect', 'ogg', 'rar', 'zlib');
if (!empty($dolibarr_main_stream_to_disable) && is_array($dolibarr_main_stream_to_disable)) {
$arrayofstreamtodisable = $dolibarr_main_stream_to_disable;
}
foreach ($arrayofstreamtodisable as $streamtodisable) {
if (!empty($listofwrappers) && in_array($streamtodisable, $listofwrappers)) {
/*if (!empty($dolibarr_main_stream_do_not_disable) && is_array($dolibarr_main_stream_do_not_disable) && in_array($streamtodisable, $dolibarr_main_stream_do_not_disable)) {
continue; // We do not disable this stream
}*/
stream_wrapper_unregister($streamtodisable);
}
}
2021-02-23 20:24:49 +01:00
if (!$result && !empty($_SERVER["GATEWAY_INTERFACE"])) { // If install not done and we are in a web session
if (!empty($_SERVER["CONTEXT_PREFIX"])) { // CONTEXT_PREFIX and CONTEXT_DOCUMENT_ROOT are not defined on all apache versions
$path = $_SERVER["CONTEXT_PREFIX"]; // example '/dolibarr/' when using an apache alias.
2021-02-23 20:24:49 +01:00
if (!preg_match('/\/$/', $path)) {
$path .= '/';
}
} elseif (preg_match('/index\.php/', $_SERVER['PHP_SELF'])) {
// When we ask index.php, we MUST BE SURE that $path is '' at the end. This is required to make install process
// when using apache alias like '/dolibarr/' that point to htdocs.
// Note: If calling page was an index.php not into htdocs (ie comm/index.php, ...), then this redirect will fails,
// but we don't want to change this because when URL is correct, we must be sure the redirect to install/index.php will be correct.
$path = '';
} else {
// If what we look is not index.php, we can try to guess location of root. May not work all the time.
// There is no real solution, because the only way to know the apache url relative path is to have it into conf file.
// If it fails to find correct $path, then only solution is to ask user to enter the correct URL to index.php or install/index.php
$TDir = explode('/', $_SERVER['PHP_SELF']);
$path = '';
$i = count($TDir);
2021-02-23 20:24:49 +01:00
while ($i--) {
if (empty($TDir[$i]) || $TDir[$i] == 'htdocs') {
break;
}
if ($TDir[$i] == 'dolibarr') {
break;
}
if (substr($TDir[$i], -4, 4) == '.php') {
continue;
}
$path .= '../';
}
}
2016-06-04 14:31:53 +02:00
header("Location: ".$path."install/index.php");
2022-05-06 20:03:59 +02:00
/*
print '<br><center>';
print 'The conf/conf.php file was not found or is not readable by the web server. If this is your first access, <a href="'.$path.'install/index.php">click here to start the Dolibarr installation process</a> to create it...';
print '</center><br>';
*/
2011-02-23 19:20:57 +01:00
exit;
}
// Force PHP error_reporting setup (Dolibarr may report warning without this)
if (version_compare(phpversion(), '8.4', '<')) {
if (!empty($dolibarr_strict_mode)) {
error_reporting(E_ALL | E_STRICT);
} else {
error_reporting(E_ALL & ~(E_STRICT | E_NOTICE | E_DEPRECATED));
}
2020-05-21 01:10:33 +02:00
} else {
// E_STRICT is deprecated since PHP 8.4
if (!empty($dolibarr_strict_mode)) {
error_reporting(E_ALL);
} else {
error_reporting(E_ALL & ~(E_NOTICE | E_DEPRECATED));
}
}
// Disable php display errors
2021-02-23 20:24:49 +01:00
if (!empty($dolibarr_main_prod)) {
ini_set('display_errors', 'Off');
}
2012-03-07 14:21:49 +01:00
// Clean parameters
2023-01-17 23:56:22 +01:00
$dolibarr_main_data_root = (empty($dolibarr_main_data_root) ? '' : trim($dolibarr_main_data_root));
$dolibarr_main_url_root = trim(preg_replace('/\/+$/', '', empty($dolibarr_main_url_root) ? '' : $dolibarr_main_url_root));
$dolibarr_main_url_root_alt = (empty($dolibarr_main_url_root_alt) ? '' : trim($dolibarr_main_url_root_alt));
2023-01-17 23:56:22 +01:00
$dolibarr_main_document_root = (empty($dolibarr_main_document_root) ? '' : trim($dolibarr_main_document_root));
$dolibarr_main_document_root_alt = (empty($dolibarr_main_document_root_alt) ? '' : trim($dolibarr_main_document_root_alt));
2012-03-07 14:21:49 +01:00
2024-03-24 15:34:19 +01:00
if (!isset($dolibarr_main_db_port)) {
2021-02-23 20:24:49 +01:00
$dolibarr_main_db_port = 3306; // For compatibility with old configs, if not defined, we take 'mysql' type
}
if (empty($dolibarr_main_db_type)) {
$dolibarr_main_db_type = 'mysqli'; // For compatibility with old configs, if not defined, we take 'mysql' type
}
// Mysql driver support has been removed in favor of mysqli
2021-02-23 20:24:49 +01:00
if ($dolibarr_main_db_type == 'mysql') {
$dolibarr_main_db_type = 'mysqli';
}
if (empty($dolibarr_main_db_prefix)) {
$dolibarr_main_db_prefix = 'llx_';
}
if (empty($dolibarr_main_db_character_set)) {
$dolibarr_main_db_character_set = ($dolibarr_main_db_type == 'mysqli' ? 'utf8' : ''); // Old installation
}
if (empty($dolibarr_main_db_collation)) {
$dolibarr_main_db_collation = ($dolibarr_main_db_type == 'mysqli' ? 'utf8_unicode_ci' : ''); // Old installation
}
if (empty($dolibarr_main_db_encryption)) {
$dolibarr_main_db_encryption = 0;
}
if (empty($dolibarr_main_db_cryptkey)) {
$dolibarr_main_db_cryptkey = '';
}
if (empty($dolibarr_main_limit_users)) {
$dolibarr_main_limit_users = 0;
}
if (empty($dolibarr_mailing_limit_sendbyweb)) {
$dolibarr_mailing_limit_sendbyweb = 0;
}
if (empty($dolibarr_mailing_limit_sendbycli)) {
$dolibarr_mailing_limit_sendbycli = 0;
}
2022-07-13 01:01:44 +02:00
if (empty($dolibarr_mailing_limit_sendbyday)) {
$dolibarr_mailing_limit_sendbyday = 0;
}
2021-02-23 20:24:49 +01:00
if (empty($dolibarr_strict_mode)) {
$dolibarr_strict_mode = 0; // For debug in php strict mode
}
2021-09-05 01:42:15 +02:00
define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem core php (htdocs)
if (!file_exists(DOL_DOCUMENT_ROOT."/core/lib/functions.lib.php")) {
2024-11-20 13:22:37 +01:00
print "Error: Dolibarr config file content seems to be not correctly defined (file ".DOL_DOCUMENT_ROOT."/core/lib/functions.lib.php not found).<br>\n";
2021-09-05 01:42:15 +02:00
print "Please run dolibarr setup by calling page <b>/install</b>.<br>\n";
2024-07-06 17:44:20 +02:00
exit(1);
2021-09-05 01:42:15 +02:00
}
// Included by default (must be before the CSRF check so wa can use the dol_syslog)
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
//print memory_get_usage();
// Security: CSRF protection
// This test check if referrer ($_SERVER['HTTP_REFERER']) is same web site than Dolibarr ($_SERVER['HTTP_HOST'])
2021-03-16 11:58:03 +01:00
// when we post forms (we allow GET and HEAD to accept direct link from a particular page).
// Note about $_SERVER[HTTP_HOST/SERVER_NAME]: http://shiflett.org/blog/2006/mar/server-name-versus-http-host
2021-03-16 11:58:03 +01:00
// See also CSRF protections done into main.inc.php
if (!defined('NOCSRFCHECK') && isset($dolibarr_nocsrfcheck) && $dolibarr_nocsrfcheck == 1) { // If $dolibarr_nocsrfcheck is 0, there is a strict CSRF test with token in main
2021-02-23 20:24:49 +01:00
if (!empty($_SERVER['REQUEST_METHOD']) && !in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD')) && !empty($_SERVER['HTTP_HOST'])) {
$csrfattack = false;
2021-02-23 20:24:49 +01:00
if (empty($_SERVER['HTTP_REFERER'])) {
$csrfattack = true; // An evil browser was used
} else {
$tmpa = parse_url($_SERVER['HTTP_HOST']);
$tmpb = parse_url($_SERVER['HTTP_REFERER']);
2021-02-23 20:24:49 +01:00
if ((empty($tmpa['host']) ? $tmpa['path'] : $tmpa['host']) != (empty($tmpb['host']) ? $tmpb['path'] : $tmpb['host'])) {
$csrfattack = true;
}
}
2021-02-23 20:24:49 +01:00
if ($csrfattack) {
//print 'NOCSRFCHECK='.defined('NOCSRFCHECK').' REQUEST_METHOD='.$_SERVER['REQUEST_METHOD'].' HTTP_HOST='.$_SERVER['HTTP_HOST'].' HTTP_REFERER='.$_SERVER['HTTP_REFERER'];
// Note: We can't use dol_escape_htmltag here to escape output because lib functions.lib.ph is not yet loaded.
dol_syslog("--- Access to ".(empty($_SERVER["REQUEST_METHOD"]) ? '' : $_SERVER["REQUEST_METHOD"].' ').$_SERVER["PHP_SELF"]." refused by CSRF protection (Bad referrer).", LOG_WARNING);
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";
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";
die;
}
}
// Another test is done later on token if option MAIN_SECURITY_CSRF_WITH_TOKEN is on.
}
2021-03-10 13:12:28 +01:00
if (empty($dolibarr_main_db_host) && !defined('NOREQUIREDB')) {
2019-02-23 23:36:21 +01:00
print '<div class="center">Dolibarr setup is not yet complete.<br><br>'."\n";
print '<a href="install/index.php">Click here to finish Dolibarr install process</a> ...</div>'."\n";
die;
}
2021-03-10 13:12:28 +01:00
if (empty($dolibarr_main_url_root) && !defined('NOREQUIREVIRTUALURL')) {
print 'Value for parameter \'dolibarr_main_url_root\' is not defined in your \'htdocs\conf\conf.php\' file.<br>'."\n";
print 'You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)'."\n";
die;
}
2021-03-10 13:12:28 +01:00
if (empty($dolibarr_main_document_root_alt)) {
$dolibarr_main_document_root_alt = $dolibarr_main_document_root.'/custom';
}
2021-02-23 20:24:49 +01:00
if (empty($dolibarr_main_data_root)) {
2021-03-10 13:12:28 +01:00
// If directory not defined, we use the default hardcoded value
$dolibarr_main_data_root = str_replace("/htdocs", "", $dolibarr_main_document_root);
$dolibarr_main_data_root .= "/documents";
}
// Define some constants
define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir (defined only for some code that want to be compatible with old versions without this parameter)
define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem data (documents)
2022-10-31 19:51:04 +01:00
// Try to autodetect DOL_MAIN_URL_ROOT and DOL_URL_ROOT when root is not directly the main domain.
2013-09-18 17:59:57 +02:00
// Note: autodetect works only in case 1, 2, 3 and 4 of phpunit test CoreTest.php. For case 5, 6, only setting value into conf.php will works.
$tmp = '';
$found = 0;
$real_dolibarr_main_document_root = str_replace('\\', '/', realpath($dolibarr_main_document_root)); // A) Value found into config file, to say where are store htdocs files. Ex: C:/xxx/dolibarr, C:/xxx/dolibarr/htdocs
Better Travis CI NEW: Cleaned up routines for better readability of both declaration and results. PHP versions now really covered. The old code forced install of PHP and didn't use Travis provided versions. This resulted in the process not being executed with the declared PHP version. Dropped MySQL in favor of MariaDB. This is now the FLOSS community standard. This should help avoid problems with buggy MySQL releases. Fast finish enabled to show results faster. Optimized tools installation with composer. The right version of the tool is installed for the PHP version under test. New PHP linter to check for syntax errors. Parallelized for better speed. Apache + PHP FPM for testing webservices. The previous mod_php configuration was not supported on Travis. New global DEBUG environment variable to show verbose output with configuration files content. IRC notification on #dolibarr@freenode for community awareness. FIXES: Bug in scripts preventing execution with environmentalized PHP. Wrong detection of MAIN_URL_ROOT under specific circumstances. $_SERVER["DOCUMENT_ROOT"] empty and $_SERVER["SCRIPT_NAME"] populated. Relative ignore directive in coding style ruleset to avoid bypassing test. Unit test errors without an exit status. This prevented the CI from properly detecting and reporting the error. TODOS: PostgreSQL support. This one is tricky since we only have a MySQL dump and the syntax is not directly compatible. SQLite support. Disabled in core at the moment. Nginx + PHP FPM support. Test webservices on the second most popular webserver. Run dev/* checks. We have a nice collection of scripts we could leverage. Check Javascript. Check CSS. Check SQL.
2015-12-11 05:08:32 +01:00
if (!empty($_SERVER["DOCUMENT_ROOT"])) {
$pathroot = $_SERVER["DOCUMENT_ROOT"]; // B) Value reported by web server setup (not defined on CLI mode), to say where is root of web server instance. Ex: C:/xxx/dolibarr, C:/xxx/dolibarr/htdocs
Better Travis CI NEW: Cleaned up routines for better readability of both declaration and results. PHP versions now really covered. The old code forced install of PHP and didn't use Travis provided versions. This resulted in the process not being executed with the declared PHP version. Dropped MySQL in favor of MariaDB. This is now the FLOSS community standard. This should help avoid problems with buggy MySQL releases. Fast finish enabled to show results faster. Optimized tools installation with composer. The right version of the tool is installed for the PHP version under test. New PHP linter to check for syntax errors. Parallelized for better speed. Apache + PHP FPM for testing webservices. The previous mod_php configuration was not supported on Travis. New global DEBUG environment variable to show verbose output with configuration files content. IRC notification on #dolibarr@freenode for community awareness. FIXES: Bug in scripts preventing execution with environmentalized PHP. Wrong detection of MAIN_URL_ROOT under specific circumstances. $_SERVER["DOCUMENT_ROOT"] empty and $_SERVER["SCRIPT_NAME"] populated. Relative ignore directive in coding style ruleset to avoid bypassing test. Unit test errors without an exit status. This prevented the CI from properly detecting and reporting the error. TODOS: PostgreSQL support. This one is tricky since we only have a MySQL dump and the syntax is not directly compatible. SQLite support. Disabled in core at the moment. Nginx + PHP FPM support. Test webservices on the second most popular webserver. Run dev/* checks. We have a nice collection of scripts we could leverage. Check Javascript. Check CSS. Check SQL.
2015-12-11 05:08:32 +01:00
} else {
$pathroot = 'NOTDEFINED';
Better Travis CI NEW: Cleaned up routines for better readability of both declaration and results. PHP versions now really covered. The old code forced install of PHP and didn't use Travis provided versions. This resulted in the process not being executed with the declared PHP version. Dropped MySQL in favor of MariaDB. This is now the FLOSS community standard. This should help avoid problems with buggy MySQL releases. Fast finish enabled to show results faster. Optimized tools installation with composer. The right version of the tool is installed for the PHP version under test. New PHP linter to check for syntax errors. Parallelized for better speed. Apache + PHP FPM for testing webservices. The previous mod_php configuration was not supported on Travis. New global DEBUG environment variable to show verbose output with configuration files content. IRC notification on #dolibarr@freenode for community awareness. FIXES: Bug in scripts preventing execution with environmentalized PHP. Wrong detection of MAIN_URL_ROOT under specific circumstances. $_SERVER["DOCUMENT_ROOT"] empty and $_SERVER["SCRIPT_NAME"] populated. Relative ignore directive in coding style ruleset to avoid bypassing test. Unit test errors without an exit status. This prevented the CI from properly detecting and reporting the error. TODOS: PostgreSQL support. This one is tricky since we only have a MySQL dump and the syntax is not directly compatible. SQLite support. Disabled in core at the moment. Nginx + PHP FPM support. Test webservices on the second most popular webserver. Run dev/* checks. We have a nice collection of scripts we could leverage. Check Javascript. Check CSS. Check SQL.
2015-12-11 05:08:32 +01:00
}
$paths = explode('/', str_replace('\\', '/', $_SERVER["SCRIPT_NAME"])); // C) Value reported by web server, to say full path on filesystem of a file. Ex: /dolibarr/htdocs/admin/system/phpinfo.php
// Try to detect if $_SERVER["DOCUMENT_ROOT"]+start of $_SERVER["SCRIPT_NAME"] is $dolibarr_main_document_root. If yes, relative url to add before dol files is this start part.
$concatpath = '';
2021-02-23 20:24:49 +01:00
foreach ($paths as $tmppath) { // We check to find (B+start of C)=A
if (empty($tmppath)) {
continue;
}
$concatpath .= '/'.$tmppath;
//if ($tmppath) $concatpath.='/'.$tmppath;
//print $_SERVER["SCRIPT_NAME"].'-'.$pathroot.'-'.$concatpath.'-'.$real_dolibarr_main_document_root.'-'.realpath($pathroot.$concatpath).'<br>';
2021-02-23 20:24:49 +01:00
if ($real_dolibarr_main_document_root == @realpath($pathroot.$concatpath)) { // @ avoid warning when safe_mode is on.
2021-02-23 20:25:33 +01:00
//print "Found relative url = ".$concatpath;
$tmp3 = $concatpath;
$found = 1;
break;
}
//else print "Not found yet for concatpath=".$concatpath."<br>\n";
}
2015-12-18 21:56:00 +01:00
//print "found=".$found." dolibarr_main_url_root=".$dolibarr_main_url_root."\n";
2021-02-23 20:24:49 +01:00
if (!$found) {
2022-10-31 19:51:04 +01:00
// There is no subdir that compose the main url root or autodetect fails (Ie: when using apache alias that point outside default DOCUMENT_ROOT).
$tmp = $dolibarr_main_url_root;
2021-02-23 20:24:49 +01:00
} else {
$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 : '');
2021-02-23 20:24:49 +01:00
}
//print "tmp1=".$tmp1." tmp2=".$tmp2." tmp3=".$tmp3." tmp=".$tmp."\n";
2021-02-23 20:24:49 +01:00
if (!empty($dolibarr_main_force_https)) {
$tmp = preg_replace('/^http:/i', 'https:', $tmp);
}
define('DOL_MAIN_URL_ROOT', $tmp); // URL absolute root (https://sss/dolibarr, ...)
$uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
$suburi = strstr($uri, '/'); // $suburi contains url without domain:port
2023-06-05 14:52:02 +02:00
if (empty($suburi) || $suburi === '/') {
$suburi = ''; // If $suburi is null or /, it is now ''
2021-02-23 20:24:49 +01:00
}
2022-06-13 16:45:30 +02:00
if (!defined('DOL_URL_ROOT')) {
define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
}
//print DOL_MAIN_URL_ROOT.'-'.DOL_URL_ROOT."\n";
// Define prefix MAIN_DB_PREFIX
define('MAIN_DB_PREFIX', $dolibarr_main_db_prefix);
/*
* Define PATH to external libraries
* To use other version than embedded libraries, define here constant to path. Use '' to use include class path autodetect.
*/
// Path to root libraries
2021-02-23 20:24:49 +01:00
if (!defined('TCPDF_PATH')) {
define('TCPDF_PATH', (empty($dolibarr_lib_TCPDF_PATH)) ? DOL_DOCUMENT_ROOT.'/includes/tecnickcom/tcpdf/' : $dolibarr_lib_TCPDF_PATH.'/');
2021-02-23 20:24:49 +01:00
}
if (!defined('TCPDI_PATH')) {
define('TCPDI_PATH', (empty($dolibarr_lib_TCPDI_PATH)) ? DOL_DOCUMENT_ROOT.'/includes/tcpdi/' : $dolibarr_lib_TCPDI_PATH.'/');
2021-02-23 20:24:49 +01:00
}
if (!defined('NUSOAP_PATH')) {
define('NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH)) ? DOL_DOCUMENT_ROOT.'/includes/nusoap/lib/' : (empty($dolibarr_lib_NUSOAP_PATH) ? '' : $dolibarr_lib_NUSOAP_PATH.'/'));
2021-02-23 20:24:49 +01:00
}
if (!defined('PHPEXCELNEW_PATH')) {
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.'/'));
2021-02-23 20:24:49 +01:00
}
if (!defined('ODTPHP_PATH')) {
define('ODTPHP_PATH', (!isset($dolibarr_lib_ODTPHP_PATH)) ? DOL_DOCUMENT_ROOT.'/includes/odtphp/' : (empty($dolibarr_lib_ODTPHP_PATH) ? '' : $dolibarr_lib_ODTPHP_PATH.'/'));
2021-02-23 20:24:49 +01:00
}
if (!defined('ODTPHP_PATHTOPCLZIP')) {
define('ODTPHP_PATHTOPCLZIP', (!isset($dolibarr_lib_ODTPHP_PATHTOPCLZIP)) ? DOL_DOCUMENT_ROOT.'/includes/odtphp/zip/pclzip/' : (empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP) ? '' : $dolibarr_lib_ODTPHP_PATHTOPCLZIP.'/'));
2021-02-23 20:24:49 +01:00
}
if (!defined('JS_CKEDITOR')) {
define('JS_CKEDITOR', (!isset($dolibarr_js_CKEDITOR)) ? '' : (empty($dolibarr_js_CKEDITOR) ? '' : $dolibarr_js_CKEDITOR.'/'));
}
if (!defined('JS_JQUERY')) {
define('JS_JQUERY', (!isset($dolibarr_js_JQUERY)) ? '' : (empty($dolibarr_js_JQUERY) ? '' : $dolibarr_js_JQUERY.'/'));
}
if (!defined('JS_JQUERY_UI')) {
define('JS_JQUERY_UI', (!isset($dolibarr_js_JQUERY_UI)) ? '' : (empty($dolibarr_js_JQUERY_UI) ? '' : $dolibarr_js_JQUERY_UI.'/'));
}
// Other required path
2021-02-23 20:24:49 +01:00
if (!defined('DOL_DEFAULT_TTF')) {
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));
2021-02-23 20:24:49 +01:00
}
if (!defined('DOL_DEFAULT_TTF_BOLD')) {
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));
2021-02-23 20:24:49 +01:00
}
/*
* Include functions
*/
2020-09-10 11:09:20 +02:00
// If password is encoded, we decode it. Note: When page is called for install, $dolibarr_main_db_pass may not be defined yet.
2020-10-22 21:55:01 +02:00
if ((!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', $dolibarr_main_db_pass)) || !empty($dolibarr_main_db_encrypted_pass)) {
if (!empty($dolibarr_main_db_pass) && preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
$dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
$dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
$dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this so we can use it later to know the password was initially encrypted
2020-10-22 21:55:01 +02:00
} else {
$dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
}
}