require.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //find the config.conf file
  22. if (file_exists('/usr/local/etc/fusionpbx/config.conf')) {
  23. $config_file = '/usr/local/etc/fusionpbx/config.conf';
  24. }
  25. elseif (file_exists('/etc/fusionpbx/config.conf')) {
  26. $config_file = '/etc/fusionpbx/config.conf';
  27. }
  28. elseif (file_exists(getenv('SystemDrive') . DIRECTORY_SEPARATOR . 'ProgramData' . DIRECTORY_SEPARATOR . 'fusionpbx' . DIRECTORY_SEPARATOR . 'config.conf')) {
  29. $config_file = getenv('SystemDrive') . DIRECTORY_SEPARATOR . 'ProgramData' . DIRECTORY_SEPARATOR . 'fusionpbx' . DIRECTORY_SEPARATOR . 'config.conf';
  30. }
  31. elseif (file_exists(__DIR__ . '/config.php')) {
  32. //set a custom config_file variable after the config.php has been validated
  33. $file_content = trim(file_get_contents(__DIR__ . '/config.php'));
  34. $pattern = '/^<\?php\s+\$config_file\s+=\s+[\'"](.+?)[\'"];\s+\?>$/';
  35. if (preg_match($pattern, $file_content, $matches) && file_exists($matches[1])) {
  36. $config_file = $matches[1];
  37. }
  38. }
  39. //config.conf file not found re-direct the request to the install
  40. if (empty($config_file)) {
  41. header("Location: /core/install/install.php");
  42. exit;
  43. }
  44. //parse the config.conf file
  45. $conf = parse_ini_file($config_file);
  46. //set the include path
  47. set_include_path($conf['document.root']);
  48. //set document root
  49. $_SERVER["DOCUMENT_ROOT"] = substr($conf['document.root'], -1) === '/' ? substr($conf['document.root'], 0, -1) : $conf['document.root'];
  50. //set project path
  51. if (isset($conf['project.path']) && !defined('PROJECT_PATH')) {
  52. if (substr($conf['project.path'], 0, 1) === '/') {
  53. define("PROJECT_PATH", $conf['project.path']);
  54. } else {
  55. if (!empty($conf['project.path'])) {
  56. define("PROJECT_PATH", '/' . $conf['project.path']);
  57. } else {
  58. define("PROJECT_PATH", '');
  59. }
  60. }
  61. }
  62. $_SERVER["PROJECT_PATH"] = PROJECT_PATH;
  63. //set project root using project path
  64. if (!defined('PROJECT_ROOT')) { define("PROJECT_ROOT", $conf['document.root'] . PROJECT_PATH); }
  65. $_SERVER["PROJECT_ROOT"] = PROJECT_ROOT;
  66. //set the error reporting
  67. ini_set('display_errors', '1');
  68. if (isset($conf['error.reporting'])) {
  69. $error_reporting_scope = $conf['error.reporting'];
  70. }
  71. else {
  72. $error_reporting_scope = 'user';
  73. }
  74. switch ($error_reporting_scope) {
  75. case 'user':
  76. error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
  77. break;
  78. case 'dev':
  79. error_reporting(E_ALL ^ E_NOTICE);
  80. break;
  81. case 'all':
  82. error_reporting(E_ALL);
  83. break;
  84. default:
  85. error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
  86. }
  87. //get the database connection settings
  88. //$db_type = $settings['database']['type'];
  89. //$db_host = $settings['database']['host'];
  90. //$db_port = $settings['database']['port'];
  91. //$db_name = $settings['database']['name'];
  92. //$db_username = $settings['database']['username'];
  93. //$db_password = $settings['database']['password'];
  94. //get the database connection settings
  95. $db_type = $conf['database.0.type'];
  96. $db_host = $conf['database.0.host'];
  97. $db_port = $conf['database.0.port'];
  98. $db_name = $conf['database.0.name'];
  99. $db_username = $conf['database.0.username'];
  100. $db_password = $conf['database.0.password'];
  101. //debug info
  102. //echo "Include Path: ".get_include_path()."\n";
  103. //echo "Document Root: ".$_SERVER["DOCUMENT_ROOT"]."\n";
  104. //echo "Project Root: ".$_SERVER["PROJECT_ROOT"]."\n";
  105. //class auto loader
  106. if (!class_exists('auto_loader')) {
  107. require_once "resources/classes/auto_loader.php";
  108. $autoload = new auto_loader();
  109. }
  110. //connect to the database
  111. global $database;
  112. $database = database::new(['config' => $config]);
  113. //load settings
  114. global $settings;
  115. $settings = new settings(['database' => $database, 'domain_uuid' => $_SESSION['domain_uuid'] ?? '', 'user_uuid' => $_SESSION['user_uuid'] ?? '']);
  116. //additional includes
  117. if (!defined('STDIN')) {
  118. require_once "resources/php.php";
  119. }
  120. require_once "resources/functions.php";
  121. if (is_array($conf) && count($conf) > 0) {
  122. require_once "resources/pdo.php";
  123. if (!defined('STDIN')) {
  124. require_once "resources/cidr.php";
  125. }
  126. if (file_exists($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/resources/switch.php")) {
  127. require_once "resources/switch.php";
  128. }
  129. }
  130. //change language on the fly - for translate tool (if available)
  131. if (!defined('STDIN') && isset($_REQUEST['view_lang_code']) && ($_REQUEST['view_lang_code']) != '') {
  132. $_SESSION['domain']['language']['code'] = $_REQUEST['view_lang_code'];
  133. }
  134. ?>