Fork of FusionPBX but with LDAP kinda working
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
8.1 KiB

2 years ago
  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 <markjcrane@fusionpbx.com>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2017
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. if ($domains_processed == 1) {
  22. //add the variables to the database
  23. $sql = "select count(*) from v_vars ";
  24. $database = new database;
  25. $num_rows = $database->select($sql, null, 'column');
  26. unset($sql);
  27. if ($num_rows == 0) {
  28. //get the xml
  29. if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf/vars.xml')) {
  30. $xml_file = '/usr/share/examples/fusionpbx/resources/templates/conf/vars.xml';
  31. }
  32. elseif (file_exists('/usr/local/share/fusionpbx/resources/templates/conf/vars.xml')) {
  33. $xml_file = '/usr/local/share/fusionpbx/resources/templates/conf/vars.xml';
  34. }
  35. else {
  36. $xml_file = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/templates/conf/vars.xml';
  37. }
  38. //load the xml and save it into an array
  39. $xml_string = file_get_contents($xml_file);
  40. $xml = simplexml_load_string($xml_string);
  41. $json = json_encode($xml);
  42. $variables = json_decode($json, true);
  43. //<X-PRE-PROCESS cmd="set" data="global_codec_prefs=G7221@32000h,G7221@16000h,G722,PCMU,PCMA" category="Codecs" enabled="true"/>
  44. $x = 0;
  45. foreach ($variables['X-PRE-PROCESS'] as $variable) {
  46. $var_category = $variable['@attributes']['category'];
  47. $data = explode('=', $variable['@attributes']['data']);
  48. $var_name = $data[0];
  49. $var_value = $data[1];
  50. $var_command = $variable['@attributes']['cmd'];
  51. $var_enabled = $variable['@attributes']['enabled'];
  52. $var_order = '';
  53. $var_description = '';
  54. $array['vars'][$x]['var_category'] = $var_category;
  55. $array['vars'][$x]['var_uuid'] = uuid();
  56. $array['vars'][$x]['var_name'] = $var_name;
  57. $array['vars'][$x]['var_value'] = $var_value;
  58. $array['vars'][$x]['var_command'] = $var_command;
  59. $array['vars'][$x]['var_enabled'] = $var_enabled;
  60. $array['vars'][$x]['var_order'] = $var_order;
  61. $array['vars'][$x]['var_description'] = $var_description;
  62. $x++;
  63. }
  64. //grant temporary permissions
  65. $p = new permissions;
  66. $p->add("var_add", "temp");
  67. $p->add("var_edit", "temp");
  68. //execute insert
  69. $database = new database;
  70. $database->app_name = 'vars';
  71. $database->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8';
  72. $database->save($array, false);
  73. $message = $database->message;
  74. //revoke temporary permissions
  75. $p->delete("var_add", "temp");
  76. $p->delete("var_edit", "temp");
  77. }
  78. //set country depend variables as country code and international direct dialing code (exit code)
  79. if (!function_exists('set_country_vars')) {
  80. function set_country_vars($x) {
  81. require "resources/countries.php";
  82. //$country_iso=$_SESSION['domain']['country']['iso_code'];
  83. $sql = "select default_setting_value ";
  84. $sql .= "from v_default_settings ";
  85. $sql .= "where default_setting_name = 'iso_code' ";
  86. $sql .= "and default_setting_category = 'domain' ";
  87. $sql .= "and default_setting_subcategory = 'country' ";
  88. $sql .= "and default_setting_enabled = 'true';";
  89. $database = new database;
  90. $country_iso = $database->select($sql, null, 'column');
  91. unset($sql);
  92. if ($country_iso === null ) {
  93. return;
  94. }
  95. if (isset($countries[$country_iso])) {
  96. $country = $countries[$country_iso];
  97. //set default country iso code
  98. $sql = "select count(*) from v_vars ";
  99. $sql .= "where var_name = 'default_country' ";
  100. $sql .= "and var_category = 'Defaults' ";
  101. $database = new database;
  102. $num_rows = $database->select($sql, null, 'column');
  103. unset($sql);
  104. if ($num_rows == 0) {
  105. $array['vars'][$x]['var_uuid'] = uuid();
  106. $array['vars'][$x]['var_name'] = 'default_country';
  107. $array['vars'][$x]['var_value'] = $country["isocode"];
  108. $array['vars'][$x]['var_category'] = 'Defaults';
  109. $array['vars'][$x]['var_enabled'] = 'true';
  110. $array['vars'][$x]['var_order'] = $x;
  111. $array['vars'][$x]['var_description'] = null;
  112. $x++;
  113. }
  114. unset($num_rows);
  115. //set default country code
  116. $sql = "select count(*) from v_vars ";
  117. $sql .= "where var_name = 'default_countrycode' ";
  118. $sql .= "and var_category = 'Defaults' ";
  119. $database = new database;
  120. $num_rows = $database->select($sql, null, 'column');
  121. unset($sql);
  122. if ($num_rows == 0) {
  123. $array['vars'][$x]['var_uuid'] = uuid();
  124. $array['vars'][$x]['var_name'] = 'default_countrycode';
  125. $array['vars'][$x]['var_value'] = $country["countrycode"];
  126. $array['vars'][$x]['var_category'] = 'Defaults';
  127. $array['vars'][$x]['var_enabled'] = 'true';
  128. $array['vars'][$x]['var_order'] = $x;
  129. $array['vars'][$x]['var_description'] = null;
  130. $x++;
  131. }
  132. unset($num_rows);
  133. //set default international direct dialing code
  134. $sql = "select count(*) from v_vars ";
  135. $sql .= "where var_name = 'default_exitcode' ";
  136. $sql .= "and var_category = 'Defaults' ";
  137. $database = new database;
  138. $num_rows = $database->select($sql, null, 'column');
  139. unset($sql);
  140. if ($num_rows == 0) {
  141. $array['vars'][$x]['var_uuid'] = uuid();
  142. $array['vars'][$x]['var_name'] = 'default_exitcode';
  143. $array['vars'][$x]['var_value'] = $country["exitcode"];
  144. $array['vars'][$x]['var_category'] = 'Defaults';
  145. $array['vars'][$x]['var_enabled'] = 'true';
  146. $array['vars'][$x]['var_order'] = $x;
  147. $array['vars'][$x]['var_description'] = null;
  148. $x++;
  149. }
  150. unset($num_rows, $countries);
  151. }
  152. if (is_array($array) && @sizeof($array) != 0) {
  153. //grant temporary permissions
  154. $p = new permissions;
  155. $p->add("var_add", "temp");
  156. //execute inserts
  157. $database = new database;
  158. $database->app_name = 'vars';
  159. $database->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8';
  160. $database->save($array, false);
  161. unset($array);
  162. //revoke temporary permissions
  163. $p->delete("var_add", "temp");
  164. }
  165. }
  166. }
  167. //adjust the variables required variables
  168. //set variables that depend on the number of domains
  169. if (count($_SESSION['domains']) > 1) {
  170. //disable the domain and domain_uuid for systems with multiple domains
  171. $sql = "update v_vars set ";
  172. $sql .= "var_enabled = 'false' ";
  173. $sql .= "where (var_name = 'domain' or var_name = 'domain_uuid') ";
  174. $database = new database;
  175. $database->execute($sql);
  176. unset($sql);
  177. }
  178. else {
  179. //set the domain_uuid
  180. $sql = "select count(*) from v_vars ";
  181. $sql .= "where var_name = 'domain_uuid' ";
  182. $database = new database;
  183. $num_rows = $database->select($sql, null, 'column');
  184. unset($sql);
  185. if ($num_rows == 0) {
  186. //build insert array
  187. $array['vars'][0]['var_uuid'] = uuid();
  188. $array['vars'][0]['var_name'] = 'domain_uuid';
  189. $array['vars'][0]['var_value'] = $domain_uuid;
  190. $array['vars'][0]['var_category'] = 'Defaults';
  191. $array['vars'][0]['var_enabled'] = 'true';
  192. $array['vars'][0]['var_order'] = 999;
  193. $array['vars'][0]['var_description'] = null;
  194. //grant temporary permissions
  195. $p = new permissions;
  196. $p->add("var_add", "temp");
  197. //execute inserts
  198. $database = new database;
  199. $database->app_name = 'vars';
  200. $database->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8';
  201. $database->save($array, false);
  202. unset($array);
  203. //revoke temporary permissions
  204. $p->delete("var_add", "temp");
  205. }
  206. unset($num_rows);
  207. }
  208. //set country code variables
  209. set_country_vars($db, $x);
  210. //save the vars.xml file
  211. save_var_xml();
  212. }
  213. ?>