global_settings.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. Copyright (C) 2010-2015
  17. All Rights Reserved.
  18. Contributor(s):
  19. Matthew Vale <[email protected]>
  20. */
  21. require_once "root.php";
  22. //define the install class
  23. class global_settings {
  24. // cached data
  25. protected $_switch_dirs;
  26. protected $_switch_vdirs;
  27. public function get_switch_dirs() { return $this->_switch_dirs; }
  28. public function get_switch_vdirs() { return $this->_switch_vdirs; }
  29. // dirs - detected from the switch
  30. protected $_switch_base_dir = '';
  31. protected $_switch_cache_dir = '';
  32. protected $_switch_conf_dir = '';
  33. protected $_switch_db_dir = '';
  34. protected $_switch_grammar_dir = '';
  35. protected $_switch_htdocs_dir = '';
  36. protected $_switch_log_dir = '';
  37. protected $_switch_mod_dir = '';
  38. protected $_switch_recordings_dir = '';
  39. protected $_switch_run_dir = '';
  40. protected $_switch_script_dir = '';
  41. protected $_switch_sounds_dir = '';
  42. protected $_switch_storage_dir = '';
  43. protected $_switch_temp_dir = '';
  44. public function switch_base_dir() { return $this->_switch_base_dir; }
  45. public function switch_cache_dir() { return $this->_switch_cache_dir; }
  46. public function switch_conf_dir() { return $this->_switch_conf_dir; }
  47. public function switch_db_dir() { return $this->_switch_db_dir; }
  48. public function switch_grammar_dir() { return $this->_switch_grammar_dir; }
  49. public function switch_htdocs_dir() { return $this->_switch_htdocs_dir; }
  50. public function switch_log_dir() { return $this->_switch_log_dir; }
  51. public function switch_mod_dir() { return $this->_switch_mod_dir; }
  52. public function switch_recordings_dir() { return $this->_switch_recordings_dir; }
  53. public function switch_run_dir() { return $this->_switch_run_dir; }
  54. public function switch_script_dir() { return $this->_switch_script_dir; }
  55. public function switch_sounds_dir() { return $this->_switch_sounds_dir; }
  56. public function switch_storage_dir() { return $this->_switch_storage_dir; }
  57. public function switch_temp_dir() { return $this->_switch_temp_dir; }
  58. // virtual dirs - assumed based on the detected dirs
  59. protected $_switch_voicemail_vdir = '';
  60. protected $_switch_phrases_vdir = '';
  61. protected $_switch_extensions_vdir = '';
  62. protected $_switch_sip_profiles_vdir = '';
  63. protected $_switch_dialplan_vdir = '';
  64. protected $_switch_backup_vdir = '';
  65. public function switch_voicemail_vdir() { return $this->_switch_voicemail_vdir; }
  66. public function switch_phrases_vdir() { return $this->_switch_phrases_vdir; }
  67. public function switch_extensions_vdir() { return $this->_switch_extensions_vdir; }
  68. public function switch_sip_profiles_vdir() { return $this->_switch_sip_profiles_vdir; }
  69. public function switch_dialplan_vdir() { return $this->_switch_dialplan_vdir; }
  70. public function switch_backup_vdir() { return $this->_switch_backup_vdir; }
  71. // event socket
  72. protected $_switch_event_host;
  73. protected $_switch_event_port;
  74. protected $_switch_event_password;
  75. public function switch_event_host() { return $this->_switch_event_host; }
  76. public function switch_event_port() { return $this->_switch_event_port; }
  77. public function switch_event_password() { return $this->_switch_event_password; }
  78. // database information
  79. protected $_db_type;
  80. protected $_db_path;
  81. protected $_db_host;
  82. protected $_db_port;
  83. protected $_db_name;
  84. protected $_db_username;
  85. protected $_db_password;
  86. protected $_db_create;
  87. protected $_db_create_username;
  88. protected $_db_create_password;
  89. public function db_type() { return $this->_db_type; }
  90. public function db_path() { return $this->_db_path; }
  91. public function db_host() { return $this->_db_host; }
  92. public function db_port() { return $this->_db_port; }
  93. public function db_name() { return $this->_db_name; }
  94. public function db_username() { return $this->_db_username; }
  95. public function db_password() { return $this->_db_password; }
  96. public function db_create() { return $this->_db_create; }
  97. public function db_create_username() { return $this->_db_create_username; }
  98. public function db_create_password() { return $this->_db_create_password; }
  99. //misc information
  100. protected $_domain_uuid;
  101. protected $_domain_name;
  102. protected $_domain_count;
  103. public function domain_uuid() { return $this->_domain_uuid; }
  104. public function domain_name() { return $this->_domain_name; }
  105. public function domain_count() { return $this->_domain_count; }
  106. public function set_domain_uuid($domain_uuid) {
  107. $e = new Exception();
  108. $trace = $e->getTrace();
  109. if($trace[1]['function'] != 'create_domain'){
  110. throw new Exception('Only create_domain is allowed to update the domain_uuid');
  111. }
  112. $this->_domain_uuid = $domain_uuid;
  113. }
  114. public function __construct($detect_switch = null, $domain_name = null, $domain_uuid = null) {
  115. $this->_switch_dirs = preg_grep ('/^switch_.*_dir$/', get_class_methods('global_settings') );
  116. sort( $this->_switch_dirs );
  117. $this->_switch_vdirs = preg_grep ('/^switch_.*_vdir$/', get_class_methods('global_settings') );
  118. sort( $this->_switch_vdirs );
  119. if(is_null($detect_switch)){
  120. //take settings from session
  121. foreach ($this->_switch_dirs as $dir){
  122. $category = 'switch';
  123. $session_var;
  124. preg_match( '/^switch_(.*)_dir$/', $dir, $session_var);
  125. $dir = "_$dir";
  126. if($session_var[1] == 'script'){ $session_var[1] = 'scripts'; }
  127. if($session_var[1] == 'temp'){ $category = 'server'; }
  128. $this->$dir = $_SESSION[$category][$session_var[1]]['dir'];
  129. }
  130. foreach ($this->_switch_vdirs as $vdir){
  131. $category = 'switch';
  132. $session_var;
  133. preg_match( '/^switch_(.*)_vdir$/', $vdir, $session_var);
  134. $vdir = "_$vdir";
  135. if($session_var[1] == 'backup'){ $category = 'server'; }
  136. $this->$vdir = $_SESSION[$category][$session_var[1]]['dir'];
  137. }
  138. $this->_switch_event_host = $_SESSION['event_socket_ip_address'];
  139. $this->_switch_event_port = $_SESSION['event_socket_port'];
  140. $this->_switch_event_password = $_SESSION['event_socket_password'];
  141. // domain info
  142. $this->_domain_name = $_SESSION['domain_name'];
  143. $this->_domain_uuid = $_SESSION['domain_uuid'];
  144. // collect misc info
  145. $this->_domain_count = count($_SESSION["domains"]);
  146. // collect db_info
  147. global $db_type, $db_path, $db_host, $db_port, $db_name, $db_username, $db_password;
  148. $this->_db_type = $db_type;
  149. $this->_db_path = $db_path;
  150. $this->_db_host = $db_host;
  151. $this->_db_port = $db_port;
  152. $this->_db_name = $db_name;
  153. $this->_db_username = $db_username;
  154. $this->_db_password = $db_password;
  155. }elseif(!is_a($detect_switch, 'detect_switch')){
  156. throw new Exception('The parameter $detect_switch must be a detect_switch object (or a subclass of)');
  157. }else{
  158. //copy from detect_switch
  159. foreach($detect_switch->get_dirs() as $dir){
  160. $t_dir = "_switch_$dir";
  161. $this->$t_dir = $detect_switch->$dir();
  162. }
  163. foreach($detect_switch->get_vdirs() as $vdir){
  164. $t_vdir = "_switch_$vdir";
  165. $this->$t_vdir = $detect_switch->$vdir();
  166. }
  167. $this->_switch_event_host = $detect_switch->event_host;
  168. $this->_switch_event_port = $detect_switch->event_port;
  169. $this->_switch_event_password = $detect_switch->event_password;
  170. //copy from _POST
  171. foreach($_POST as $key=>$value){
  172. if(substr($key,0,3) == "db_"){
  173. $o_key = "_$key";
  174. $this->$o_key = $value;
  175. }
  176. }
  177. if($this->_db_create and strlen($this->_db_create_username) == 0)
  178. {
  179. $this->_db_create_username = $this->_db_username;
  180. $this->_db_create_password = $this->_db_password;
  181. }
  182. if (strlen($this->_db_port) == 0) { $this->_db_port = "5432"; }
  183. // domain info
  184. if(strlen($domain_uuid) == 0){ $domain_uuid = uuid(); }
  185. $this->_domain_name = $domain_name;
  186. $this->_domain_uuid = $domain_uuid;
  187. //collect misc info
  188. $this->_domain_count = 1; //assumed to be one
  189. }
  190. }
  191. }
  192. ?>