inc.php 9.9 KB

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