PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/filefunc.inc.php

https://bitbucket.org/speedealing/speedealing
PHP | 286 lines | 191 code | 25 blank | 70 comment | 75 complexity | 927d2dad6353eacbd9abca2789150c61 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-2012 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-2013 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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. if (!defined('DOL_VERSION'))
  26. define('DOL_VERSION', '0.2.45');
  27. if (!defined('EURO'))
  28. define('EURO', chr(128));
  29. // Define syslog constants
  30. if (!defined('LOG_DEBUG')) {
  31. if (function_exists("define_syslog_variables")) {
  32. define_syslog_variables(); // Deprecated since php 5.3.0, syslog variables no longer need to be initialized
  33. } else {
  34. // Pour PHP sans syslog (comme sous Windows)
  35. define('LOG_EMERG', 0);
  36. define('LOG_ALERT', 1);
  37. define('LOG_CRIT', 2);
  38. define('LOG_ERR', 3);
  39. define('LOG_WARNING', 4);
  40. define('LOG_NOTICE', 5);
  41. define('LOG_INFO', 6);
  42. define('LOG_DEBUG', 7);
  43. }
  44. }
  45. // Define DOL_DOCUMENT_ROOT
  46. define('DOL_DOCUMENT_ROOT', realpath(dirname(__FILE__))); // Filesystem core php (htdocs)
  47. // Define MAIN_PROTOCOL
  48. $protocol = ((!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == 'on')?'https':'http');
  49. define('MAIN_PROTOCOL', $protocol);
  50. // End of common declaration part
  51. if (defined('DOL_INC_FOR_VERSION_ERROR'))
  52. return;
  53. // Define vars
  54. $conffiletoshowshort = "conf.php";
  55. // Define localization of conf file
  56. $conffile = "conf/conf.php";
  57. // Include configuration
  58. $result = @include_once $conffile;
  59. if (!$result && !empty($_SERVER["GATEWAY_INTERFACE"])) { // If install not done and we are in a web session
  60. header("Location: install/index.php");
  61. exit;
  62. }
  63. // Force PHP error_reporting setup (Speedealing may report warning without this)
  64. if (!empty($main_strict_mode)) {
  65. error_reporting(E_ALL | E_STRICT);
  66. } else {
  67. if (!defined('E_DEPRECATED'))
  68. define('E_DEPRECATED', 0); // For PHP < 5.3.0 compatibility
  69. error_reporting(E_ALL & ~(E_STRICT | E_NOTICE | E_DEPRECATED));
  70. }
  71. // Disable php display errors
  72. if (!empty($dolibarr_main_prod))
  73. ini_set('display_errors', 'Off');
  74. // Clean parameters
  75. // TODO deprecated
  76. if (!empty($dolibarr_main_data_root)) {
  77. $dolibarr_main_data_root = trim($dolibarr_main_data_root);
  78. $dolibarr_main_url_root = trim($dolibarr_main_url_root);
  79. $dolibarr_main_url_root_alt = trim($dolibarr_main_url_root_alt);
  80. $dolibarr_main_document_root = realpath(dirname(__FILE__));
  81. $dolibarr_main_document_root_alt = trim($dolibarr_main_document_root_alt);
  82. }
  83. if (empty($dolibarr_main_db_port))
  84. $dolibarr_main_db_port = 0; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
  85. if (empty($dolibarr_main_db_type))
  86. $dolibarr_main_db_type = 'mysqli'; // Pour compatibilite avec anciennes configs, si non defini, on prend 'mysql'
  87. if (empty($dolibarr_main_db_prefix))
  88. $dolibarr_main_db_prefix = 'llx_';
  89. if (empty($dolibarr_main_db_character_set))
  90. $dolibarr_main_db_character_set = 'utf8';
  91. if (empty($dolibarr_main_db_collation))
  92. $dolibarr_main_db_collation = 'utf8_general_ci';
  93. if (empty($dolibarr_main_db_encryption))
  94. $dolibarr_main_db_encryption = 0;
  95. if (empty($dolibarr_main_db_cryptkey))
  96. $dolibarr_main_db_cryptkey = '';
  97. if (empty($dolibarr_main_limit_users))
  98. $dolibarr_main_limit_users = 0;
  99. if (empty($dolibarr_mailing_limit_sendbyweb))
  100. $dolibarr_mailing_limit_sendbyweb = 0;
  101. if (empty($force_charset_do_notuse))
  102. $force_charset_do_notuse = 'UTF-8';
  103. if (empty($main_strict_mode))
  104. $main_strict_mode = 0; // For debug in php strict mode
  105. // Security: CSRF protection
  106. // This test check if referrer ($_SERVER['HTTP_REFERER']) is same web site than Speedealing ($_SERVER['HTTP_HOST'])
  107. // when we post forms (we allow GET to allow direct link to access a particular page).
  108. 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'])) {
  109. //print 'HTTP_POST='.$_SERVER['HTTP_HOST'].' HTTP_REFERER='.$_SERVER['HTTP_REFERER'];
  110. print "Access refused by CSRF protection in main.inc.php.\n";
  111. 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";
  112. die;
  113. }
  114. /*if (empty($dolibarr_main_couchdb_host)) {
  115. print '<div align="center">Speedealing setup is not yet complete.<br><br>' . "\n";
  116. print '<a href="install/index.php">Click here to finish Speedealing install process</a> ...</div>' . "\n";
  117. die;
  118. }*/
  119. // Define some constants
  120. 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)
  121. // TODO deprecated
  122. if (!empty($dolibarr_main_data_root)) {
  123. define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem data (documents)
  124. if (!empty($dolibarr_main_document_root_alt)) {
  125. define('DOL_DOCUMENT_ROOT_ALT', $dolibarr_main_document_root_alt); // Filesystem paths to alternate core php (alternate htdocs)
  126. }
  127. }
  128. // Define DOL_MAIN_URL_ROOT and DOL_URL_ROOT
  129. $tmp = '';
  130. $found = 0;
  131. // TODO deprecated
  132. if (!empty($dolibarr_main_document_root)) {
  133. $real_dolibarr_main_document_root = str_replace('\\', '/', realpath($dolibarr_main_document_root));
  134. $pathroot = $_SERVER["DOCUMENT_ROOT"];
  135. $paths = explode('/', str_replace('\\', '/', $_SERVER["SCRIPT_NAME"]));
  136. $concatpath = '';
  137. foreach ($paths as $tmppath) {
  138. if ($tmppath)
  139. $concatpath.='/' . $tmppath;
  140. //print $_SERVER["SCRIPT_NAME"].'-'.$pathroot.'-'.$concatpath.'-'.$real_dolibarr_main_document_root.'-'.realpath($pathroot.$concatpath).'<br>';
  141. if ($real_dolibarr_main_document_root == @realpath($pathroot . $concatpath)) { // @ avoid warning when safe_mode is on.
  142. $tmp3 = $concatpath;
  143. //print "Found relative url = ".$tmp3;
  144. $found = 1;
  145. break;
  146. }
  147. //else print "Not found yet for concatpath=".$concatpath."<br>\n";
  148. }
  149. }
  150. if (!$found && !empty($dolibarr_main_url_root)) { // If autodetect fails (Ie: when using apache alias that point outside default DOCUMENT_ROOT.
  151. $tmp = $dolibarr_main_url_root;
  152. }
  153. else
  154. $tmp = MAIN_PROTOCOL . '://' . $_SERVER["SERVER_NAME"] . ((empty($_SERVER["SERVER_PORT"]) || $_SERVER["SERVER_PORT"] == 80) ? '' : ':' . $_SERVER["SERVER_PORT"]) . (!empty($tmp3) ? (preg_match('/^\//', $tmp3) ? '' : '/') . $tmp3 : '');
  155. //print "tmp1=".$tmp1." tmp2=".$tmp2." tmp3=".$tmp3." tmp=".$tmp;
  156. if (!empty($dolibarr_main_force_https))
  157. $tmp = preg_replace('/^http:/i', 'https:', $tmp);
  158. define('DOL_MAIN_URL_ROOT', $tmp); // URL absolute root (https://sss/dolibarr, ...)
  159. $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
  160. $suburi = strstr($uri, '/'); // $suburi contains url without domain
  161. if ($suburi == '/')
  162. $suburi = ''; // If $suburi is /, it is now ''
  163. if (!empty($dolibarr_urlrewrite) && !empty($_GET['db'])) //URL rewrite + entity in url www.speedealing.com/[entity]/...
  164. $suburi .= "/" . $_GET['db'];
  165. define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
  166. // Define DOL_MAIN_URL_ROOT_ALT and DOL_URL_ROOT_ALT
  167. if (!empty($dolibarr_main_url_root_alt)) {
  168. $altpart = str_replace($dolibarr_main_url_root, '', $dolibarr_main_url_root_alt);
  169. if (!preg_match('/^\//', $altpart) && !empty($altpart)) {
  170. $tmp_alt = $dolibarr_main_url_root_alt;
  171. } // Manage case url=http://localhost/aaa and url_alt=http://localhost/aaabbb
  172. else
  173. $tmp_alt = $tmp . ((preg_match('/\/$/', $tmp) || preg_match('/^\//', $altpart)) ? '' : '/') . $altpart;
  174. //$tmp_alt=$dolibarr_main_url_root_alt;
  175. define('DOL_MAIN_URL_ROOT_ALT', $tmp_alt); // URL absolute root (https://sss/dolibarr/custom, ...)
  176. $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT_ALT')); // $uri contains url without http*
  177. $suburi = strstr($uri, '/'); // $suburi contains url without domain
  178. if ($suburi == '/')
  179. $suburi = ''; // If $suburi is /, it is now ''
  180. define('DOL_URL_ROOT_ALT', $suburi); // URL relative root ('', '/dolibarr/custom', ...)
  181. }
  182. // Define prefix
  183. define('MAIN_DB_PREFIX', $dolibarr_main_db_prefix);
  184. //print DOL_URL_ROOT.'-'.DOL_URL_ROOT_ALT;
  185. /*
  186. * Define PATH to external libraries
  187. * To use other version than embeded libraries, define here constant to path. Use '' to use include class path autodetect.
  188. */
  189. // Path to root libraries
  190. // TODO deprecated and unused
  191. if (!defined('ADODB_PATH')) {
  192. define('ADODB_PATH', (!isset($dolibarr_lib_ADODB_PATH)) ? DOL_DOCUMENT_ROOT . '/includes/adodbtime/' : (empty($dolibarr_lib_ADODB_PATH) ? '' : $dolibarr_lib_ADODB_PATH . '/'));
  193. }
  194. if (!defined('TCPDF_PATH')) {
  195. define('TCPDF_PATH', (!isset($dolibarr_lib_TCPDF_PATH)) ? DOL_DOCUMENT_ROOT . '/includes/tcpdf/' : (empty($dolibarr_lib_TCPDF_PATH) ? '' : $dolibarr_lib_TCPDF_PATH . '/'));
  196. }
  197. if (!defined('FPDI_PATH')) {
  198. define('FPDI_PATH', (!isset($dolibarr_lib_FPDI_PATH)) ? DOL_DOCUMENT_ROOT . '/includes/fpdfi/' : (empty($dolibarr_lib_FPDI_PATH) ? '' : $dolibarr_lib_FPDI_PATH . '/'));
  199. }
  200. if (!defined('NUSOAP_PATH')) {
  201. define('NUSOAP_PATH', (!isset($dolibarr_lib_NUSOAP_PATH)) ? DOL_DOCUMENT_ROOT . '/includes/nusoap/lib/' : (empty($dolibarr_lib_NUSOAP_PATH) ? '' : $dolibarr_lib_NUSOAP_PATH . '/'));
  202. }
  203. if (!defined('PHPEXCEL_PATH')) {
  204. define('PHPEXCEL_PATH', (!isset($dolibarr_lib_PHPEXCEL_PATH)) ? DOL_DOCUMENT_ROOT . '/includes/phpexcel/' : (empty($dolibarr_lib_PHPEXCEL_PATH) ? '' : $dolibarr_lib_PHPEXCEL_PATH . '/'));
  205. }
  206. if (!defined('GEOIP_PATH')) {
  207. define('GEOIP_PATH', (!isset($dolibarr_lib_GEOIP_PATH)) ? DOL_DOCUMENT_ROOT . '/includes/geoip/' : (empty($dolibarr_lib_GEOIP_PATH) ? '' : $dolibarr_lib_GEOIP_PATH . '/'));
  208. }
  209. if (!defined('ODTPHP_PATH')) {
  210. define('ODTPHP_PATH', (!isset($dolibarr_lib_ODTPHP_PATH)) ? DOL_DOCUMENT_ROOT . '/includes/odtphp/' : (empty($dolibarr_lib_ODTPHP_PATH) ? '' : $dolibarr_lib_ODTPHP_PATH . '/'));
  211. }
  212. if (!defined('ODTPHP_PATHTOPCLZIP')) {
  213. define('ODTPHP_PATHTOPCLZIP', (!isset($dolibarr_lib_ODTPHP_PATHTOPCLZIP)) ? DOL_DOCUMENT_ROOT . '/includes/odtphp/zip/pclzip/' : (empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP) ? '' : $dolibarr_lib_ODTPHP_PATHTOPCLZIP . '/'));
  214. }
  215. if (!defined('JS_CKEDITOR')) {
  216. define('JS_CKEDITOR', (!isset($dolibarr_js_CKEDITOR)) ? '' : (empty($dolibarr_js_CKEDITOR) ? '' : $dolibarr_js_CKEDITOR . '/'));
  217. }
  218. if (!defined('JS_JQUERY')) {
  219. define('JS_JQUERY', (!isset($dolibarr_js_JQUERY)) ? '' : (empty($dolibarr_js_JQUERY) ? '' : $dolibarr_js_JQUERY . '/'));
  220. }
  221. if (!defined('JS_JQUERY_UI')) {
  222. define('JS_JQUERY_UI', (!isset($dolibarr_js_JQUERY_UI)) ? '' : (empty($dolibarr_js_JQUERY_UI) ? '' : $dolibarr_js_JQUERY_UI . '/'));
  223. }
  224. if (!defined('JS_JQUERY_FLOT')) {
  225. define('JS_JQUERY_FLOT', (!isset($dolibarr_js_JQUERY_FLOT)) ? '' : (empty($dolibarr_js_JQUERY_FLOT) ? '' : $dolibarr_js_JQUERY_FLOT . '/'));
  226. }
  227. // Other required path
  228. if (!defined('DOL_DEFAULT_TTF')) {
  229. 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));
  230. }
  231. if (!defined('DOL_DEFAULT_TTF_BOLD')) {
  232. 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));
  233. }
  234. /*
  235. * Include functions
  236. */
  237. if (!defined('ADODB_DATE_VERSION'))
  238. include_once ADODB_PATH . 'adodb-time.inc.php';
  239. if (!file_exists(DOL_DOCUMENT_ROOT . "/core/lib/functions.lib.php")) {
  240. print "Error: Speedealing config file content seems to be not correctly defined.<br>\n";
  241. print "Please run speedealing setup by calling page <b>/install</b>.<br>\n";
  242. exit;
  243. }
  244. // Included by default
  245. include_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
  246. include_once DOL_DOCUMENT_ROOT . '/core/lib/security.lib.php';
  247. //print memory_get_usage();
  248. // If password is encoded, we decode it
  249. // TODO deprecated
  250. if (!empty($dolibarr_main_db_pass)) {
  251. if (preg_match('/crypted:/i', $dolibarr_main_db_pass) || !empty($dolibarr_main_db_encrypted_pass)) {
  252. if (preg_match('/crypted:/i', $dolibarr_main_db_pass)) {
  253. $dolibarr_main_db_pass = preg_replace('/crypted:/i', '', $dolibarr_main_db_pass);
  254. $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_pass);
  255. $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
  256. }
  257. else
  258. $dolibarr_main_db_pass = dol_decode($dolibarr_main_db_encrypted_pass);
  259. }
  260. }
  261. ?>