PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/filefunc.inc.php

https://github.com/asterix14/dolibarr
PHP | 231 lines | 145 code | 21 blank | 65 comment | 65 complexity | 4c042c6f1ad0e48ec5e03fd9b99e70e3 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?PHP
  2. /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Xavier Dutoit <doli@sydesy.com>
  4. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  7. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  8. * Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
  9. * Copyright (C) 2006 Andre Cianfarani <andre.cianfarani@acdeveloppement.net>
  10. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/filefunc.inc.php
  27. * \ingroup core
  28. * \brief File that include conf.php file and commons lib like functions.lib.php
  29. */
  30. if (! defined('DOL_VERSION')) define('DOL_VERSION','3.2.0-alpha'); // Also defined in htdocs/install/inc.php (Ex: x.y.z-alpha, x.y.z)
  31. if (! defined('EURO')) define('EURO',chr(128));
  32. // Definition des constantes syslog
  33. if (! defined('LOG_DEBUG'))
  34. {
  35. if (function_exists("define_syslog_variables"))
  36. {
  37. define_syslog_variables(); // Deprecated since php 5.3.0, syslog variables no longer need to be initialized
  38. }
  39. else
  40. {
  41. // Pour PHP sans syslog (comme sous Windows)
  42. define('LOG_EMERG',0);
  43. define('LOG_ALERT',1);
  44. define('LOG_CRIT',2);
  45. define('LOG_ERR',3);
  46. define('LOG_WARNING',4);
  47. define('LOG_NOTICE',5);
  48. define('LOG_INFO',6);
  49. define('LOG_DEBUG',7);
  50. }
  51. }
  52. // Forcage du parametrage PHP error_reporting (Dolibarr non utilisable en mode error E_ALL)
  53. error_reporting(E_ALL ^ E_NOTICE);
  54. //error_reporting(E_ALL | E_STRICT);
  55. // Define vars
  56. $conffiletoshowshort = "conf.php";
  57. // Define localization of conf file
  58. $conffile = "conf/conf.php";
  59. $conffiletoshow = "htdocs/conf/conf.php";
  60. // For debian/redhat like systems
  61. //$conffile = "/etc/dolibarr/conf.php";
  62. //$conffiletoshow = "/etc/dolibarr/conf.php";
  63. // Include configuration
  64. $result=@include_once($conffile);
  65. if (! $result && ! empty($_SERVER["GATEWAY_INTERFACE"])) // If install not done and we are in a web session
  66. {
  67. header("Location: install/index.php");
  68. exit;
  69. }
  70. if (empty($dolibarr_main_db_port)) $dolibarr_main_db_port=0; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
  71. if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
  72. if (empty($dolibarr_main_db_prefix)) $dolibarr_main_db_prefix='llx_';
  73. if (empty($dolibarr_main_db_character_set)) $dolibarr_main_db_character_set='latin1'; // Old installation
  74. if (empty($dolibarr_main_db_collation)) $dolibarr_main_db_collation='latin1_swedish_ci'; // Old installation
  75. if (empty($dolibarr_main_db_encryption)) $dolibarr_main_db_encryption=0;
  76. if (empty($dolibarr_main_db_cryptkey)) $dolibarr_main_db_cryptkey='';
  77. if (empty($dolibarr_main_limit_users)) $dolibarr_main_limit_users=0;
  78. if (empty($dolibarr_mailing_limit_sendbyweb)) $dolibarr_mailing_limit_sendbyweb=0;
  79. if (empty($force_charset_do_notuse)) $force_charset_do_notuse='UTF-8';
  80. if (empty($multicompany_transverse_mode)) $multicompany_transverse_mode=0;
  81. // Security: CSRF protection
  82. // This test check if referrer ($_SERVER['HTTP_REFERER']) is same web site than Dolibarr ($_SERVER['HTTP_HOST'])
  83. // when we post forms (we allow GET to allow direct link to access a particular page).
  84. if (! defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && ! empty($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET' && ! empty($_SERVER['HTTP_HOST']) && ! empty($_SERVER['HTTP_REFERER']) && ! preg_match('/'.preg_quote($_SERVER['HTTP_HOST'],'/').'/i', $_SERVER['HTTP_REFERER']))
  85. {
  86. //print 'HTTP_POST='.$_SERVER['HTTP_HOST'].' HTTP_REFERER='.$_SERVER['HTTP_REFERER'];
  87. print "Access refused by CSRF protection in main.inc.php.\n";
  88. print "If you access your server behind a proxy using url rewriting, you might add the line \$dolibarr_nocsrfcheck=1 into your conf.php file.\n";
  89. die;
  90. }
  91. if (empty($dolibarr_main_db_host))
  92. {
  93. print 'Dolibarr setup is not yet complete.<br><br>'."\n";
  94. print '<a href="install/index.php">Click here to finish Dolibarr install process</a> ...'."\n";
  95. die;
  96. }
  97. if (empty($dolibarr_main_url_root))
  98. {
  99. print 'Value for parameter \'dolibarr_main_url_root\' is not defined in your \'htdocs\conf\conf.php\' file.<br>'."\n";
  100. print 'You must add this parameter with your full Dolibarr root Url (Example: http://myvirtualdomain/ or http://mydomain/mydolibarrurl/)'."\n";
  101. die;
  102. }
  103. if (empty($dolibarr_main_db_type)) $dolibarr_main_db_type='mysql'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
  104. if (empty($dolibarr_main_data_root))
  105. {
  106. // Si repertoire documents non defini, on utilise celui par defaut
  107. $dolibarr_main_data_root=str_replace("/htdocs","",$dolibarr_main_document_root);
  108. $dolibarr_main_data_root.="/documents";
  109. }
  110. // Define some constants
  111. 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)
  112. define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem data (documents)
  113. define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem core php (htdocs)
  114. if (! empty($dolibarr_main_document_root_alt))
  115. {
  116. define('DOL_DOCUMENT_ROOT_ALT', $dolibarr_main_document_root_alt); // Filesystem paths to alternate core php (alternate htdocs)
  117. }
  118. // Define DOL_MAIN_URL_ROOT and DOL_URL_ROOT
  119. $tmp='';
  120. $found=0;
  121. $real_dolibarr_main_document_root=str_replace('\\','/',realpath($dolibarr_main_document_root));
  122. $pathroot=$_SERVER["DOCUMENT_ROOT"];
  123. $paths=explode('/',str_replace('\\','/',$_SERVER["SCRIPT_NAME"]));
  124. $concatpath='';
  125. foreach($paths as $tmppath)
  126. {
  127. if ($tmppath) $concatpath.='/'.$tmppath;
  128. //print $real_$dolibarr_main_document_root.'-'.realpath($pathroot.$concatpath).'<br>';
  129. if ($real_dolibarr_main_document_root == realpath($pathroot.$concatpath))
  130. {
  131. $tmp3=$concatpath;
  132. //print "Found relative url = ".$tmp3;
  133. $found=1;
  134. break;
  135. }
  136. }
  137. if (! $found) // If autodetect fails (Ie: when uing apache alias that point outside default DOCUMENT_ROOT.
  138. {
  139. $tmp=$dolibarr_main_url_root;
  140. }
  141. else $tmp='http'.((empty($_SERVER["HTTPS"]) || $_SERVER["HTTPS"] != 'on')?'':'s').'://'.$_SERVER["SERVER_NAME"].((empty($_SERVER["SERVER_PORT"])||$_SERVER["SERVER_PORT"]==80)?'':':'.$_SERVER["SERVER_PORT"]).($tmp3?(preg_match('/^\//',$tmp3)?'':'/').$tmp3:'');
  142. //print "tmp1=".$tmp1." tmp2=".$tmp2." tmp3=".$tmp3." tmp=".$tmp;
  143. if (! empty($dolibarr_main_force_https)) $tmp=preg_replace('/^http:/i','https:',$tmp);
  144. define('DOL_MAIN_URL_ROOT', $tmp); // URL absolute root (https://sss/dolibarr, ...)
  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 == '/') $suburi = ''; // If $suburi is /, it is now ''
  148. define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
  149. // Define DOL_MAIN_URL_ROOT_ALT and DOL_URL_ROOT_ALT
  150. if (! empty($dolibarr_main_url_root_alt))
  151. {
  152. $altpart=str_replace($dolibarr_main_url_root,'',$dolibarr_main_url_root_alt);
  153. if (! preg_match('/^\//',$altpart) && ! empty($altpart)) { $tmp_alt=$dolibarr_main_url_root_alt; } // Manage case url=http://localhost/aaa and url_alt=http://localhost/aaabbb
  154. else $tmp_alt=$tmp.((preg_match('/\/$/',$tmp)||preg_match('/^\//',$altpart))?'':'/').$altpart;
  155. //$tmp_alt=$dolibarr_main_url_root_alt;
  156. define('DOL_MAIN_URL_ROOT_ALT', $tmp_alt); // URL absolute root (https://sss/dolibarr/custom, ...)
  157. $uri=preg_replace('/^http(s?):\/\//i','',constant('DOL_MAIN_URL_ROOT_ALT')); // $uri contains url without http*
  158. $suburi = strstr($uri, '/'); // $suburi contains url without domain
  159. if ($suburi == '/') $suburi = ''; // If $suburi is /, it is now ''
  160. define('DOL_URL_ROOT_ALT', $suburi); // URL relative root ('', '/dolibarr/custom', ...)
  161. }
  162. // Define prefix
  163. define('MAIN_DB_PREFIX',$dolibarr_main_db_prefix);
  164. //print DOL_URL_ROOT.'-'.DOL_URL_ROOT_ALT;
  165. /*
  166. * Define PATH to external libraries
  167. * To use other version than embeded libraries, define here constant to path. Use '' to use include class path autodetect.
  168. */
  169. // Path to root libraries
  170. if (! defined('ADODB_PATH')) { define('ADODB_PATH', (!isset($dolibarr_lib_ADODB_PATH))?DOL_DOCUMENT_ROOT.'/includes/adodbtime/':(empty($dolibarr_lib_ADODB_PATH)?'':$dolibarr_lib_ADODB_PATH.'/')); }
  171. if (! defined('TCPDF_PATH')) { define('TCPDF_PATH', (!isset($dolibarr_lib_TCPDF_PATH))?DOL_DOCUMENT_ROOT.'/includes/tcpdf/':(empty($dolibarr_lib_TCPDF_PATH)?'':$dolibarr_lib_TCPDF_PATH.'/')); }
  172. if (! defined('FPDFI_PATH')) { define('FPDFI_PATH', (!isset($dolibarr_lib_FPDFI_PATH))?DOL_DOCUMENT_ROOT.'/includes/fpdfi/':(empty($dolibarr_lib_FPDFI_PATH)?'':$dolibarr_lib_FPDFI_PATH.'/')); }
  173. 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.'/')); }
  174. if (! defined('PHPEXCEL_PATH')) { define('PHPEXCEL_PATH', (!isset($dolibarr_lib_PHPEXCEL_PATH))?DOL_DOCUMENT_ROOT.'/includes/phpexcel/':(empty($dolibarr_lib_PHPEXCEL_PATH)?'':$dolibarr_lib_PHPEXCEL_PATH.'/')); }
  175. if (! defined('GEOIP_PATH')) { define('GEOIP_PATH', (!isset($dolibarr_lib_GEOIP_PATH))?DOL_DOCUMENT_ROOT.'/includes/geoip/':(empty($dolibarr_lib_GEOIP_PATH)?'':$dolibarr_lib_GEOIP_PATH.'/')); }
  176. 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.'/')); }
  177. 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.'/')); }
  178. if (! defined('ARTICHOW_PATH')) { define('ARTICHOW_PATH', (!isset($dolibarr_lib_ARTICHOW))?DOL_DOCUMENT_ROOT.'/includes/artichow/':(empty($dolibarr_lib_ARTICHOW)?'':$dolibarr_lib_ARTICHOW.'/')); }
  179. // Other required path
  180. if (! defined('ARTICHOW_FONT')) { define('ARTICHOW_FONT', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/artichow/font':dirname($dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
  181. if (! defined('ARTICHOW_FONT_NAMES')) { define('ARTICHOW_FONT_NAMES', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?'Tuffy,TuffyBold,TuffyBoldItalic,TuffyItalic':'DejaVuSans,DejaVuSans-Bold,DejaVuSans-BoldOblique,DejaVuSans-Oblique'); }
  182. if (! defined('DOL_DEFAULT_TTF')) { define('DOL_DEFAULT_TTF', (!isset($dolibarr_font_DOL_DEFAULT_TTF))?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/Aerial.ttf':(empty($dolibarr_font_DOL_DEFAULT_TTF)?'':$dolibarr_font_DOL_DEFAULT_TTF)); }
  183. if (! defined('DOL_DEFAULT_TTF_BOLD')) { define('DOL_DEFAULT_TTF_BOLD', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/AerialBd.ttf':(empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?'':$dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
  184. // Old path to root deprecated (no more used).
  185. //if (! defined('FPDF_PATH')) { define('FPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/fpdf/'); }
  186. /*
  187. * Include functions
  188. */
  189. if (! defined('ADODB_DATE_VERSION')) include_once(ADODB_PATH.'adodb-time.inc.php');
  190. if (! file_exists(DOL_DOCUMENT_ROOT ."/core/lib/functions.lib.php"))
  191. {
  192. print "Error: Dolibarr config file content seems to be not correctly defined.<br>\n";
  193. print "Please run dolibarr setup by calling page <b>/install</b>.<br>\n";
  194. exit;
  195. }
  196. include_once(DOL_DOCUMENT_ROOT ."/core/lib/functions.lib.php"); // Need 970ko memory (1.1 in 2.2)
  197. include_once(DOL_DOCUMENT_ROOT ."/core/lib/security.lib.php"); // Include by default
  198. // If password is encoded, we decode it
  199. if (preg_match('/crypted:/i',$dolibarr_main_db_pass) || ! empty($dolibarr_main_db_encrypted_pass))
  200. {
  201. if (preg_match('/crypted:/i',$dolibarr_main_db_pass))
  202. {
  203. $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
  204. $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
  205. $dolibarr_main_db_encrypted_pass = $dolibarr_main_db_pass; // We need to set this as it is used to know the password was initially crypted
  206. }
  207. else $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
  208. }
  209. //print memory_get_usage();
  210. ?>