inc.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/support/inc.php
  22. * \ingroup core
  23. * \brief File that define environment for support pages
  24. */
  25. // Define DOL_DOCUMENT_ROOT
  26. if (!defined('DOL_DOCUMENT_ROOT')) {
  27. define('DOL_DOCUMENT_ROOT', '..');
  28. }
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/conf.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  34. $conf = new Conf();
  35. // Force $_REQUEST["logtohtml"]
  36. $_REQUEST["logtohtml"] = 1;
  37. // Correction PHP_SELF (ex pour apache via caudium) car PHP_SELF doit valoir URL relative
  38. // et non path absolu.
  39. if (isset($_SERVER["DOCUMENT_URI"]) && $_SERVER["DOCUMENT_URI"]) {
  40. $_SERVER["PHP_SELF"] = $_SERVER["DOCUMENT_URI"];
  41. }
  42. $includeconferror = '';
  43. // Define vars
  44. $conffiletoshowshort = "conf.php";
  45. // Define localization of conf file
  46. $conffile = "../conf/conf.php";
  47. $conffiletoshow = "htdocs/conf/conf.php";
  48. // For debian/redhat like systems
  49. /*
  50. if (!file_exists($conffile)) {
  51. $conffile = "/etc/dolibarr/conf.php";
  52. $conffiletoshow = "/etc/dolibarr/conf.php";
  53. }
  54. */
  55. // Load conf file if it is already defined
  56. 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
  57. $result = include_once $conffile; // Load conf file
  58. if ($result) {
  59. if (empty($dolibarr_main_db_type)) {
  60. $dolibarr_main_db_type = 'mysql'; // For backward compatibility
  61. }
  62. //Mysql driver support has been removed in favor of mysqli
  63. if ($dolibarr_main_db_type == 'mysql') {
  64. $dolibarr_main_db_type = 'mysqli';
  65. }
  66. if (empty($dolibarr_main_db_port) && ($dolibarr_main_db_type == 'mysqli')) {
  67. $dolibarr_main_db_port = '3306'; // For backward compatibility
  68. }
  69. // Clean parameters
  70. $dolibarr_main_data_root = isset($dolibarr_main_data_root) ?trim($dolibarr_main_data_root) : '';
  71. $dolibarr_main_url_root = isset($dolibarr_main_url_root) ?trim($dolibarr_main_url_root) : '';
  72. $dolibarr_main_url_root_alt = isset($dolibarr_main_url_root_alt) ?trim($dolibarr_main_url_root_alt) : '';
  73. $dolibarr_main_document_root = isset($dolibarr_main_document_root) ?trim($dolibarr_main_document_root) : '';
  74. $dolibarr_main_document_root_alt = isset($dolibarr_main_document_root_alt) ?trim($dolibarr_main_document_root_alt) : '';
  75. // Remove last / or \ on directories or url value
  76. if (!empty($dolibarr_main_document_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root)) {
  77. $dolibarr_main_document_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root);
  78. }
  79. if (!empty($dolibarr_main_url_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root)) {
  80. $dolibarr_main_url_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root);
  81. }
  82. if (!empty($dolibarr_main_data_root) && !preg_match('/^[\\/]+$/', $dolibarr_main_data_root)) {
  83. $dolibarr_main_data_root = preg_replace('/[\\/]+$/', '', $dolibarr_main_data_root);
  84. }
  85. if (!empty($dolibarr_main_document_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_document_root_alt)) {
  86. $dolibarr_main_document_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_document_root_alt);
  87. }
  88. if (!empty($dolibarr_main_url_root_alt) && !preg_match('/^[\\/]+$/', $dolibarr_main_url_root_alt)) {
  89. $dolibarr_main_url_root_alt = preg_replace('/[\\/]+$/', '', $dolibarr_main_url_root_alt);
  90. }
  91. // Create conf object
  92. if (!empty($dolibarr_main_document_root)) {
  93. $result = loadconf($dolibarr_main_document_root);
  94. }
  95. // Load database driver
  96. if ($result) {
  97. if (!empty($dolibarr_main_document_root) && !empty($dolibarr_main_db_type)) {
  98. $result = include_once $dolibarr_main_document_root."/core/db/".$dolibarr_main_db_type.'.class.php';
  99. if (!$result) {
  100. $includeconferror = 'ErrorBadValueForDolibarrMainDBType';
  101. }
  102. }
  103. } else {
  104. $includeconferror = 'ErrorBadValueForDolibarrMainDocumentRoot';
  105. }
  106. } else {
  107. $includeconferror = 'ErrorBadFormatForConfFile';
  108. }
  109. }
  110. $conf->global->MAIN_LOGTOHTML = 1;
  111. // Define prefix
  112. if (!isset($dolibarr_main_db_prefix) || !$dolibarr_main_db_prefix) {
  113. $dolibarr_main_db_prefix = 'llx_';
  114. }
  115. define('MAIN_DB_PREFIX', (isset($dolibarr_main_db_prefix) ? $dolibarr_main_db_prefix : ''));
  116. define('DOL_CLASS_PATH', 'class/'); // Filsystem path to class dir
  117. define('DOL_DATA_ROOT', (isset($dolibarr_main_data_root) ? $dolibarr_main_data_root : ''));
  118. define('DOL_MAIN_URL_ROOT', (isset($dolibarr_main_url_root) ? $dolibarr_main_url_root : '')); // URL relative root
  119. $uri = preg_replace('/^http(s?):\/\//i', '', constant('DOL_MAIN_URL_ROOT')); // $uri contains url without http*
  120. $suburi = strstr($uri, '/'); // $suburi contains url without domain
  121. if ($suburi == '/') {
  122. $suburi = ''; // If $suburi is /, it is now ''
  123. }
  124. define('DOL_URL_ROOT', $suburi); // URL relative root ('', '/dolibarr', ...)
  125. if (empty($character_set_client)) {
  126. $character_set_client = "UTF-8";
  127. }
  128. $conf->file->character_set_client = strtoupper($character_set_client);
  129. if (empty($dolibarr_main_db_character_set)) {
  130. $dolibarr_main_db_character_set = ($conf->db->type == 'mysqli' ? 'utf8' : ''); // Old installation
  131. }
  132. $conf->db->character_set = $dolibarr_main_db_character_set;
  133. if (empty($dolibarr_main_db_collation)) {
  134. $dolibarr_main_db_collation = ($conf->db->type == 'mysqli' ? 'utf8_unicode_ci' : ''); // Old installation
  135. }
  136. $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
  137. if (empty($dolibarr_main_db_encryption)) {
  138. $dolibarr_main_db_encryption = 0;
  139. }
  140. $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
  141. if (empty($dolibarr_main_db_cryptkey)) {
  142. $dolibarr_main_db_cryptkey = '';
  143. }
  144. $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
  145. if (empty($conf->db->user)) {
  146. $conf->db->user = '';
  147. }
  148. // Defini objet langs
  149. $langs = new Translate('..', $conf);
  150. if (GETPOST('lang', 'aZ09')) {
  151. $langs->setDefaultLang(GETPOST('lang', 'aZ09'));
  152. } else {
  153. $langs->setDefaultLang('auto');
  154. }
  155. $bc[false] = ' class="bg1"';
  156. $bc[true] = ' class="bg2"';
  157. /**
  158. * Load conf file (file must exists)
  159. *
  160. * @param string $dolibarr_main_document_root Root directory of Dolibarr bin files
  161. * @return int <0 if KO, >0 if OK
  162. */
  163. function loadconf($dolibarr_main_document_root)
  164. {
  165. global $conf;
  166. global $dolibarr_main_db_type;
  167. global $dolibarr_main_db_host;
  168. global $dolibarr_main_db_port;
  169. global $dolibarr_main_db_name;
  170. global $dolibarr_main_db_user;
  171. global $dolibarr_main_db_pass;
  172. global $character_set_client;
  173. $return = 1;
  174. if (!class_exists('Conf')) {
  175. $return = include_once $dolibarr_main_document_root.'/core/class/conf.class.php';
  176. }
  177. if (!$return) {
  178. return -1;
  179. }
  180. $conf = new Conf();
  181. $conf->db->type = trim($dolibarr_main_db_type);
  182. $conf->db->host = trim($dolibarr_main_db_host);
  183. $conf->db->port = trim($dolibarr_main_db_port);
  184. $conf->db->name = trim($dolibarr_main_db_name);
  185. $conf->db->user = trim($dolibarr_main_db_user);
  186. $conf->db->pass = trim($dolibarr_main_db_pass);
  187. if (empty($conf->db->dolibarr_main_db_collation)) {
  188. $conf->db->dolibarr_main_db_collation = 'utf8_unicode_ci';
  189. }
  190. return 1;
  191. }
  192. /**
  193. * Show HTML header
  194. *
  195. * @param string $soutitre Title
  196. * @param string $next Next
  197. * @param string $action Action code
  198. * @return void
  199. */
  200. function pHeader($soutitre, $next, $action = 'none')
  201. {
  202. global $conf, $langs;
  203. $langs->loadLangs(array("main", "admin"));
  204. // On force contenu dans format sortie
  205. header("Content-type: text/html; charset=".$conf->file->character_set_client);
  206. // Security options
  207. header("X-Content-Type-Options: nosniff");
  208. header("X-Frame-Options: SAMEORIGIN"); // Frames allowed only if on same domain (stop some XSS attacks)
  209. print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
  210. print '<head>'."\n";
  211. print '<meta http-equiv="content-type" content="text/html; charset='.$conf->file->character_set_client.'">'."\n";
  212. print '<meta name="robots" content="index,follow">'."\n";
  213. print '<meta name="viewport" content="width=device-width, initial-scale=1.0">'."\n";
  214. print '<meta name="keywords" content="help, center, dolibarr, doliwamp">'."\n";
  215. print '<meta name="description" content="Dolibarr help center">'."\n";
  216. print '<link rel="stylesheet" type="text/css" href="../install/default.css">'."\n";
  217. print '<title>'.$langs->trans("DolibarrHelpCenter").'</title>'."\n";
  218. print '</head>'."\n";
  219. print '<body class="center">'."\n";
  220. print '<div class="noborder centpercent center valignmiddle inline-block">';
  221. print '<img src="helpcenter.png" alt="logohelpcenter" class="inline-block"><br><br>';
  222. print '<span class="titre inline-block">'.$soutitre.'</span>'."\n";
  223. print '</div><br>';
  224. }
  225. /**
  226. * Print HTML footer
  227. *
  228. * @param integer $nonext No button "Next step"
  229. * @param string $setuplang Language code
  230. * @return void
  231. */
  232. function pFooter($nonext = 0, $setuplang = '')
  233. {
  234. global $langs;
  235. $langs->load("main");
  236. $langs->load("admin");
  237. print '</body>'."\n";
  238. print '</html>'."\n";
  239. }