config.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * config
  4. *
  5. * @method get config.php
  6. * @method find find the path to the config.php file
  7. * @method exists determin if the the config.php file exists
  8. */
  9. class config {
  10. /**
  11. * database variables and config path
  12. */
  13. public $db_type;
  14. public $db_name;
  15. public $db_username;
  16. public $db_password;
  17. public $db_host;
  18. public $db_path;
  19. public $db_port;
  20. public $db_secure;
  21. public $db_cert_authority;
  22. public $config_path;
  23. /**
  24. * Called when the object is created
  25. */
  26. public function __construct() {
  27. //place holder
  28. }
  29. /**
  30. * Determine whether the config.php exists
  31. * @var string $db_type - type of database
  32. * @var string $db_name - name of the database
  33. * @var string $db_username - username to access the database
  34. * @var string $db_password - password to access the database
  35. * @var string $db_host - hostname of the database server
  36. * @var string $db_path - path of the database file
  37. * @var string $db_port - network port to connect to the database
  38. * @var bool $db_secure - whether or not to connect with SSL
  39. * @var string $db_cert_authority - location of certificate authority
  40. */
  41. public function get() {
  42. $this->find();
  43. if ($this->exists()) {
  44. require $this->config_path;
  45. $this->db_type = $db_type;
  46. $this->db_name = $db_name;
  47. $this->db_username = $db_username;
  48. $this->db_password = $db_password;
  49. $this->db_secure = $db_secure;
  50. $this->db_cert_authority = $db_cert_authority;
  51. $this->db_host = $db_host;
  52. $this->db_path = $db_path;
  53. $this->db_port = $db_port;
  54. }
  55. }
  56. /**
  57. * Find the path to the config.php
  58. * @var string $config_path - full path to the config.php file
  59. */
  60. public function find() {
  61. //set the include path
  62. $conf = glob("{/usr/local/etc,/etc}/fusionpbx/config.conf", GLOB_BRACE);
  63. set_include_path(parse_ini_file($conf[0])['document.root']);
  64. //includes files
  65. require_once "resources/require.php";
  66. // find the file
  67. if (file_exists($_SERVER["PROJECT_ROOT"]."/resources/config.php")) {
  68. $this->config_path = $_SERVER["PROJECT_ROOT"]."/resources/config.php";
  69. } elseif (file_exists("/etc/fusionpbx/config.php")) {
  70. $this->config_path = "/etc/fusionpbx/config.php";
  71. } elseif (file_exists("/usr/local/etc/fusionpbx/config.php")) {
  72. $this->config_path = "/usr/local/etc/fusionpbx/config.php";
  73. }
  74. else {
  75. $this->config_path = '';
  76. }
  77. //return the path
  78. return $this->config_path;
  79. }
  80. /**
  81. * Determine whether the config.php exists
  82. */
  83. public function exists() {
  84. $this->find();
  85. if (!empty($this->config_path)) {
  86. return true;
  87. }
  88. else {
  89. return false;
  90. }
  91. }
  92. }
  93. /*
  94. $config = new config;
  95. $config_exists = $config->exists();
  96. $config_path = $config->find();
  97. $config->get();
  98. $db_type = $config->db_type;
  99. $db_name = $config->db_name;
  100. $db_username = $config->db_username;
  101. $db_password = $config->db_password;
  102. $db_host = $config->db_host;
  103. $db_path = $config->db_path;
  104. $db_port = $config->db_port;
  105. echo "config_path: ".$config_path."\n";
  106. if ($config_exists) {
  107. echo "config_exists: true\n";
  108. } else {
  109. echo "config_exists: false\n";
  110. }
  111. echo "db_type: ".$db_type."\n";
  112. echo "db_name: ".$db_name."\n";
  113. echo "db_username: ".$db_username."\n";
  114. echo "db_password: ".$db_password."\n";
  115. echo "db_host: ".$db_host."\n";
  116. echo "db_path: ".$db_path."\n";
  117. echo "db_port: ".$db_port."\n";
  118. */
  119. ?>