PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/master.inc.php

https://bitbucket.org/speedealing/speedealing
PHP | 199 lines | 119 code | 20 blank | 60 comment | 34 complexity | d99dda9fb506817d493c27c23e16c1a8 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. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. */
  26. //require_once("filefunc.inc.php"); // May have been already require by main.inc.php. But may not by scripts.
  27. /* error_reporting(E_ALL);
  28. ini_set('display_errors', true);
  29. ini_set('html_errors', false); */
  30. /*
  31. * Create $conf object
  32. */
  33. if (!class_exists('Conf'))
  34. require DOL_DOCUMENT_ROOT . '/core/class/conf.class.php';
  35. $conf = new Conf();
  36. // Identifiant propres au serveur couchdb
  37. //$conf->Couchdb->protocol = $dolibarr_main_couchdb_protocol;
  38. $conf->Couchdb->host = $dolibarr_main_couchdb_host;
  39. $conf->Couchdb->port = $dolibarr_main_couchdb_port;
  40. $conf->Couchdb->name = null;
  41. // Identifiant pour le serveur memcached
  42. $conf->memcached->host = $dolibarr_main_memcached_host;
  43. $conf->memcached->port = $dolibarr_main_memcached_port;
  44. // Is urlrewrite enable for multicompany db
  45. $conf->urlrewrite = $dolibarr_urlrewrite;
  46. // Identifiant propres au serveur base de donnee
  47. // TODO deprecated
  48. if (!empty($dolibarr_main_db_host)) {
  49. $conf->db->host = $dolibarr_main_db_host;
  50. $conf->db->port = $dolibarr_main_db_port;
  51. $conf->db->name = $dolibarr_main_db_name;
  52. $conf->db->user = $dolibarr_main_db_user;
  53. $conf->db->pass = $dolibarr_main_db_pass;
  54. $conf->db->type = $dolibarr_main_db_type;
  55. $conf->db->prefix = $dolibarr_main_db_prefix;
  56. $conf->db->character_set = $dolibarr_main_db_character_set;
  57. $conf->db->dolibarr_main_db_collation = $dolibarr_main_db_collation;
  58. $conf->db->dolibarr_main_db_encryption = $dolibarr_main_db_encryption;
  59. $conf->db->dolibarr_main_db_cryptkey = $dolibarr_main_db_cryptkey;
  60. }
  61. $conf->file->main_limit_users = $dolibarr_main_limit_users;
  62. $conf->file->mailing_limit_sendbyweb = $dolibarr_mailing_limit_sendbyweb;
  63. // Identification mode
  64. $conf->file->main_authentication = empty($dolibarr_main_authentication) ? '' : $dolibarr_main_authentication;
  65. // Force https
  66. $conf->file->main_force_https = empty($dolibarr_main_force_https) ? '' : $dolibarr_main_force_https;
  67. // Cookie cryptkey
  68. $conf->file->cookie_cryptkey = empty($dolibarr_main_cookie_cryptkey) ? '' : $dolibarr_main_cookie_cryptkey;
  69. // Define array of document root directories
  70. $conf->file->dol_document_root = array('main' => DOL_DOCUMENT_ROOT);
  71. if (!empty($dolibarr_main_document_root_alt)) {
  72. // dolibarr_main_document_root_alt contains several directories
  73. $values = preg_split('/[;,]/', $dolibarr_main_document_root_alt);
  74. foreach ($values as $value) {
  75. $conf->file->dol_document_root['alt'] = $value;
  76. }
  77. }
  78. // Chargement des includes principaux de librairies communes
  79. if (!defined('NOREQUIREUSER')) {
  80. if (!class_exists('User'))
  81. require DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; // Need 500ko memory
  82. }
  83. // For couchdb
  84. if (!class_exists('couch'))
  85. require DOL_DOCUMENT_ROOT . '/core/db/couchdb/lib/couch.php';
  86. if (!class_exists('couchClient'))
  87. require DOL_DOCUMENT_ROOT . '/core/db/couchdb/lib/couchClient.php';
  88. if (!class_exists('nosqlDocument'))
  89. require DOL_DOCUMENT_ROOT . '/core/class/nosqlDocument.class.php';
  90. // Load Memcache configuration
  91. if (!empty($conf->memcached->host) && class_exists('Memcached')) {
  92. $memcache = new Memcached();
  93. $result = $memcache->addServer($conf->memcached->host, $conf->memcached->port);
  94. if ($result)
  95. $conf->memcached->enabled = true;
  96. } elseif (!empty($conf->memcached->host) && class_exists('Memcache')) {
  97. $memcache = new Memcache();
  98. $result = $memcache->addServer($conf->memcached->host, $conf->memcached->port);
  99. if ($result)
  100. $conf->memcached->enabled = true;
  101. }
  102. // Creation objet $langs (must be before all other code)
  103. if (!defined('NOREQUIRETRAN')) {
  104. if (!class_exists('TranslateStandalone'))
  105. require DOL_DOCUMENT_ROOT . '/core/class/translatestandalone.class.php';
  106. $langs = new TranslateStandalone(); // Use translations files
  107. }
  108. /*
  109. * Object $db
  110. */
  111. if (!defined('NOREQUIREDB')) {
  112. if (!empty($conf->db->host)) {
  113. //var_dump($conf->db);
  114. $db = getDoliDBInstance($conf->db->type, $conf->db->host, $conf->db->user, $conf->db->pass, $conf->db->name, $conf->db->port);
  115. if ($db->error) {
  116. dol_print_error($db, "host=" . $conf->db->host . ", port=" . $conf->db->port . ", user=" . $conf->db->user . ", databasename=" . $conf->db->name . ", " . $db->error);
  117. exit;
  118. }
  119. } else {
  120. // For backward compatibility
  121. $db = new stdClass();
  122. }
  123. // By default conf->entity is 1, but we change this if we ask another value
  124. if ($conf->urlrewrite && GETPOST("db")) // Value pass from url for the name of the database : need url rewrite
  125. $conf->Couchdb->name = strtolower(GETPOST("db", 'alpha'));
  126. else { //Query standard
  127. if (session_id()) { // Entity inside an opened session
  128. $conf->Couchdb->name = dol_getcache("dol_entity");
  129. if (is_int($conf->Couchdb->name))
  130. $conf->Couchdb->name = null;
  131. }
  132. if (empty($conf->Couchdb->name) && !empty($_ENV["dol_entity"])) { // Entity inside a CLI script
  133. $conf->Couchdb->name = strtolower($_ENV["dol_entity"]);
  134. dol_setcache("dol_entity", $conf->Couchdb->name);
  135. }
  136. if (GETPOST("entity", 'alpha')) { // Just after a login page
  137. $conf->Couchdb->name = strtolower(GETPOST("entity", 'alpha'));
  138. dol_setcache("dol_entity", $conf->Couchdb->name);
  139. //} else if (defined('DOLENTITY') && is_int(DOLENTITY)) { // For public page with MultiCompany module
  140. // $conf->entity = DOLENTITY;
  141. }
  142. }
  143. if (empty($conf->Couchdb->name))
  144. $conf->Couchdb->name = "_users"; // login phase
  145. if (!empty($dolibarr_main_resolver)) {
  146. $conf->main_resolver = $dolibarr_main_resolver;
  147. $conf->Couchdb->host = dol_getcache("couchdb_host");
  148. if ($conf->Couchdb->host < 0) {
  149. require_once(DOL_DOCUMENT_ROOT . '/includes/net/dns2.php');
  150. $r = new Net_DNS2_Resolver(array('nameservers' => array($dolibarr_main_resolver)));
  151. try {
  152. $result = $r->query($_SERVER["HTTP_HOST"], 'A');
  153. $conf->Couchdb->host = "http://" . $result->answer[0]->address;
  154. dol_setcache("couchdb_host", $conf->Couchdb->host);
  155. } catch (Net_DNS2_Exception $e) {
  156. echo "::query() failed: ", $e->getMessage(), "\n";
  157. }
  158. }
  159. }
  160. $couch = new couchClient($conf->Couchdb->host . ':' . $conf->Couchdb->port . '/', $conf->Couchdb->name);
  161. if (!empty($_COOKIE['AuthSession']))
  162. $couch->setSessionCookie("AuthSession=" . $_COOKIE['AuthSession']);
  163. }
  164. // Create the global $hookmanager object
  165. if (!defined('NOREQUIREHOOK')) {
  166. if (!class_exists('HookManager'))
  167. require DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
  168. $hookmanager = new HookManager($db); // TODO remove $db object
  169. }
  170. // Now database connexion is known, so we can forget password
  171. unset($dolibarr_main_db_pass); // We comment this because this constant is used in a lot of pages
  172. unset($conf->db->pass); // This is to avoid password to be shown in memory/swap dump
  173. // TODO move this parameter in database
  174. if (!defined('MAIN_LABEL_MENTION_NPR'))
  175. define('MAIN_LABEL_MENTION_NPR', 'NPR');
  176. // We force feature to help debug
  177. // TODO move this parameter in database
  178. //$conf->global->MAIN_JS_ON_PAYMENT=0;
  179. ?>