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.

1177 lines
42 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-2018
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. Luis Daniel Lucio Quiroz <dlucio@okay.com.mx>
  21. Riccardo Granchi <riccardo.granchi@nems.it>
  22. */
  23. //includes
  24. require_once "root.php";
  25. require_once "resources/require.php";
  26. //get the event socket information
  27. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/settings/app_config.php")) {
  28. if ((! isset($_SESSION['event_socket_ip_address'])) or strlen($_SESSION['event_socket_ip_address']) == 0) {
  29. $sql = "select * from v_settings ";
  30. $database = new database;
  31. $row = $database->select($sql, null, 'row');
  32. if (is_array($row) && @sizeof($row) != 0) {
  33. $_SESSION['event_socket_ip_address'] = $row["event_socket_ip_address"];
  34. $_SESSION['event_socket_port'] = $row["event_socket_port"];
  35. $_SESSION['event_socket_password'] = $row["event_socket_password"];
  36. }
  37. unset($sql, $row);
  38. }
  39. }
  40. function event_socket_create($host, $port, $password) {
  41. $esl = new event_socket;
  42. if ($esl->connect($host, $port, $password)) {
  43. return $esl->reset_fp();
  44. }
  45. return false;
  46. }
  47. function event_socket_request($fp, $cmd) {
  48. $esl = new event_socket($fp);
  49. $result = $esl->request($cmd);
  50. $esl->reset_fp();
  51. return $result;
  52. }
  53. function event_socket_request_cmd($cmd) {
  54. //get the database connection
  55. require_once "resources/classes/database.php";
  56. $database = new database;
  57. $database->connect();
  58. $db = $database->db;
  59. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/settings/app_config.php")) {
  60. $sql = "select * from v_settings ";
  61. $database = new database;
  62. $row = $database->select($sql, null, 'row');
  63. if (is_array($row) && @sizeof($row) != 0) {
  64. $event_socket_ip_address = $row["event_socket_ip_address"];
  65. $event_socket_port = $row["event_socket_port"];
  66. $event_socket_password = $row["event_socket_password"];
  67. }
  68. unset($sql, $row);
  69. }
  70. $esl = new event_socket;
  71. if (!$esl->connect($event_socket_ip_address, $event_socket_port, $event_socket_password)) {
  72. return false;
  73. }
  74. $response = $esl->request($cmd);
  75. $esl->close();
  76. return $response;
  77. }
  78. function remove_config_from_cache($name) {
  79. $cache = new cache;
  80. $cache->delete($name);
  81. $hostname = trim(event_socket_request_cmd('api switchname'));
  82. if($hostname){
  83. $cache->delete($name . ':' . $hostname);
  84. }
  85. }
  86. function ListFiles($dir) {
  87. if($dh = opendir($dir)) {
  88. $files = Array();
  89. $inner_files = Array();
  90. while($file = readdir($dh)) {
  91. if($file != "." && $file != ".." && $file[0] != '.') {
  92. if(is_dir($dir . "/" . $file)) {
  93. //$inner_files = ListFiles($dir . "/" . $file); //recursive
  94. if(is_array($inner_files)) $files = array_merge($files, $inner_files);
  95. } else {
  96. array_push($files, $file);
  97. //array_push($files, $dir . "/" . $file);
  98. }
  99. }
  100. }
  101. closedir($dh);
  102. return $files;
  103. }
  104. }
  105. function save_setting_xml() {
  106. global $domain_uuid, $host, $config;
  107. $sql = "select * from v_settings ";
  108. $database = new database;
  109. $row = $database->select($sql, null, 'row');
  110. if (is_array($row) && @sizeof($row) != 0) {
  111. $fout = fopen($_SESSION['switch']['conf']['dir']."/directory/default/default.xml","w");
  112. $xml = "<include>\n";
  113. $xml .= " <user id=\"default\"> <!--if id is numeric mailbox param is not necessary-->\n";
  114. $xml .= " <variables>\n";
  115. $xml .= " <!--all variables here will be set on all inbound calls that originate from this user -->\n";
  116. $xml .= " <!-- set these to take advantage of a dialplan localized to this user -->\n";
  117. $xml .= " <variable name=\"numbering_plan\" value=\"" . $row['numbering_plan'] . "\"/>\n";
  118. $xml .= " <variable name=\"default_gateway\" value=\"" . $row['default_gateway'] . "\"/>\n";
  119. $xml .= " <variable name=\"default_area_code\" value=\"" . $row['default_area_code'] . "\"/>\n";
  120. $xml .= " </variables>\n";
  121. $xml .= " </user>\n";
  122. $xml .= "</include>\n";
  123. fwrite($fout, $xml);
  124. unset($xml);
  125. fclose($fout);
  126. $event_socket_ip_address = $row['event_socket_ip_address'];
  127. if (strlen($event_socket_ip_address) == 0) { $event_socket_ip_address = '127.0.0.1'; }
  128. $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/event_socket.conf.xml","w");
  129. $xml = "<configuration name=\"event_socket.conf\" description=\"Socket Client\">\n";
  130. $xml .= " <settings>\n";
  131. $xml .= " <param name=\"listen-ip\" value=\"" . $event_socket_ip_address . "\"/>\n";
  132. $xml .= " <param name=\"listen-port\" value=\"" . $row['event_socket_port'] . "\"/>\n";
  133. $xml .= " <param name=\"password\" value=\"" . $row['event_socket_password'] . "\"/>\n";
  134. if (strlen($row['event_socket_acl']) > 0) {
  135. $xml .= " <param name=\"apply-inbound-acl\" value=\"" . $row['event_socket_acl'] . "\"/>\n";
  136. }
  137. $xml .= " </settings>\n";
  138. $xml .= "</configuration>";
  139. fwrite($fout, $xml);
  140. unset($xml, $event_socket_password);
  141. fclose($fout);
  142. $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/xml_rpc.conf.xml","w");
  143. $xml = "<configuration name=\"xml_rpc.conf\" description=\"XML RPC\">\n";
  144. $xml .= " <settings>\n";
  145. $xml .= " <!-- The port where you want to run the http service (default 8080) -->\n";
  146. $xml .= " <param name=\"http-port\" value=\"" . $row['xml_rpc_http_port'] . "\"/>\n";
  147. $xml .= " <!-- if all 3 of the following params exist all http traffic will require auth -->\n";
  148. $xml .= " <param name=\"auth-realm\" value=\"" . $row['xml_rpc_auth_realm'] . "\"/>\n";
  149. $xml .= " <param name=\"auth-user\" value=\"" . $row['xml_rpc_auth_user'] . "\"/>\n";
  150. $xml .= " <param name=\"auth-pass\" value=\"" . $row['xml_rpc_auth_pass'] . "\"/>\n";
  151. $xml .= " </settings>\n";
  152. $xml .= "</configuration>\n";
  153. fwrite($fout, $xml);
  154. unset($xml);
  155. fclose($fout);
  156. //shout.conf.xml
  157. $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/shout.conf.xml","w");
  158. $xml = "<configuration name=\"shout.conf\" description=\"mod shout config\">\n";
  159. $xml .= " <settings>\n";
  160. $xml .= " <!-- Don't change these unless you are insane -->\n";
  161. $xml .= " <param name=\"decoder\" value=\"" . $row['mod_shout_decoder'] . "\"/>\n";
  162. $xml .= " <param name=\"volume\" value=\"" . $row['mod_shout_volume'] . "\"/>\n";
  163. $xml .= " <!--<param name=\"outscale\" value=\"8192\"/>-->\n";
  164. $xml .= " </settings>\n";
  165. $xml .= "</configuration>";
  166. fwrite($fout, $xml);
  167. unset($xml);
  168. fclose($fout);
  169. }
  170. unset($sql, $row);
  171. //apply settings
  172. $_SESSION["reload_xml"] = true;
  173. //$cmd = "api reloadxml";
  174. //event_socket_request_cmd($cmd);
  175. //unset($cmd);
  176. }
  177. function filename_safe($filename) {
  178. //lower case
  179. $filename = strtolower($filename);
  180. //replace spaces with a '_'
  181. $filename = str_replace(" ", "_", $filename);
  182. //loop through string
  183. $result = '';
  184. for ($i=0; $i<strlen($filename); $i++) {
  185. if (preg_match('([0-9]|[a-z]|_)', $filename[$i])) {
  186. $result .= $filename[$i];
  187. }
  188. }
  189. //return filename
  190. return $result;
  191. }
  192. function save_gateway_xml() {
  193. //skip saving the gateway xml if the directory is not set
  194. if (strlen($_SESSION['switch']['sip_profiles']['dir']) == 0) {
  195. return;
  196. }
  197. //declare the global variables
  198. global $domain_uuid, $config;
  199. //delete all old gateways to prepare for new ones
  200. if (count($_SESSION["domains"]) > 1) {
  201. $v_needle = 'v_'.$_SESSION['domain_name'].'-';
  202. }
  203. else {
  204. $v_needle = 'v_';
  205. }
  206. $gateway_list = glob($_SESSION['switch']['sip_profiles']['dir'] . "/*/".$v_needle."*.xml");
  207. foreach ($gateway_list as $gateway_file) {
  208. unlink($gateway_file);
  209. }
  210. //get the list of gateways and write the xml
  211. $sql = "select * from v_gateways ";
  212. $sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
  213. $parameters['domain_uuid'] = $domain_uuid;
  214. $database = new database;
  215. $result = $database->select($sql, $parameters, 'all');
  216. if (is_array($result) && @sizeof($result) != 0) {
  217. foreach ($result as &$row) {
  218. if ($row['enabled'] != "false") {
  219. //set the default profile as external
  220. $profile = $row['profile'];
  221. if (strlen($profile) == 0) {
  222. $profile = "external";
  223. }
  224. //open the xml file
  225. $fout = fopen($_SESSION['switch']['sip_profiles']['dir']."/".$profile."/v_".strtolower($row['gateway_uuid']).".xml","w");
  226. //build the xml
  227. $xml .= "<include>\n";
  228. $xml .= " <gateway name=\"" . strtolower($row['gateway_uuid']) . "\">\n";
  229. if (strlen($row['username']) > 0) {
  230. $xml .= " <param name=\"username\" value=\"" . $row['username'] . "\"/>\n";
  231. }
  232. if (strlen($row['distinct_to']) > 0) {
  233. $xml .= " <param name=\"distinct-to\" value=\"" . $row['distinct_to'] . "\"/>\n";
  234. }
  235. if (strlen($row['auth_username']) > 0) {
  236. $xml .= " <param name=\"auth-username\" value=\"" . $row['auth_username'] . "\"/>\n";
  237. }
  238. if (strlen($row['password']) > 0) {
  239. $xml .= " <param name=\"password\" value=\"" . $row['password'] . "\"/>\n";
  240. }
  241. if (strlen($row['realm']) > 0) {
  242. $xml .= " <param name=\"realm\" value=\"" . $row['realm'] . "\"/>\n";
  243. }
  244. if (strlen($row['from_user']) > 0) {
  245. $xml .= " <param name=\"from-user\" value=\"" . $row['from_user'] . "\"/>\n";
  246. }
  247. if (strlen($row['from_domain']) > 0) {
  248. $xml .= " <param name=\"from-domain\" value=\"" . $row['from_domain'] . "\"/>\n";
  249. }
  250. if (strlen($row['proxy']) > 0) {
  251. $xml .= " <param name=\"proxy\" value=\"" . $row['proxy'] . "\"/>\n";
  252. }
  253. if (strlen($row['register_proxy']) > 0) {
  254. $xml .= " <param name=\"register-proxy\" value=\"" . $row['register_proxy'] . "\"/>\n";
  255. }
  256. if (strlen($row['outbound_proxy']) > 0) {
  257. $xml .= " <param name=\"outbound-proxy\" value=\"" . $row['outbound_proxy'] . "\"/>\n";
  258. }
  259. if (strlen($row['expire_seconds']) > 0) {
  260. $xml .= " <param name=\"expire-seconds\" value=\"" . $row['expire_seconds'] . "\"/>\n";
  261. }
  262. if (strlen($row['register']) > 0) {
  263. $xml .= " <param name=\"register\" value=\"" . $row['register'] . "\"/>\n";
  264. }
  265. if (strlen($row['register_transport']) > 0) {
  266. switch ($row['register_transport']) {
  267. case "udp":
  268. $xml .= " <param name=\"register-transport\" value=\"udp\"/>\n";
  269. break;
  270. case "tcp":
  271. $xml .= " <param name=\"register-transport\" value=\"tcp\"/>\n";
  272. break;
  273. case "tls":
  274. $xml .= " <param name=\"register-transport\" value=\"tls\"/>\n";
  275. $xml .= " <param name=\"contact-params\" value=\"transport=tls\"/>\n";
  276. break;
  277. default:
  278. $xml .= " <param name=\"register-transport\" value=\"" . $row['register_transport'] . "\"/>\n";
  279. }
  280. }
  281. if (strlen($row['retry_seconds']) > 0) {
  282. $xml .= " <param name=\"retry-seconds\" value=\"" . $row['retry_seconds'] . "\"/>\n";
  283. }
  284. if (strlen($row['extension']) > 0) {
  285. $xml .= " <param name=\"extension\" value=\"" . $row['extension'] . "\"/>\n";
  286. }
  287. if (strlen($row['ping']) > 0) {
  288. $xml .= " <param name=\"ping\" value=\"" . $row['ping'] . "\"/>\n";
  289. }
  290. if (strlen($row['context']) > 0) {
  291. $xml .= " <param name=\"context\" value=\"" . $row['context'] . "\"/>\n";
  292. }
  293. if (strlen($row['caller_id_in_from']) > 0) {
  294. $xml .= " <param name=\"caller-id-in-from\" value=\"" . $row['caller_id_in_from'] . "\"/>\n";
  295. }
  296. if (strlen($row['supress_cng']) > 0) {
  297. $xml .= " <param name=\"supress-cng\" value=\"" . $row['supress_cng'] . "\"/>\n";
  298. }
  299. if (strlen($row['sip_cid_type']) > 0) {
  300. $xml .= " <param name=\"sip_cid_type\" value=\"" . $row['sip_cid_type'] . "\"/>\n";
  301. }
  302. if (strlen($row['extension_in_contact']) > 0) {
  303. $xml .= " <param name=\"extension-in-contact\" value=\"" . $row['extension_in_contact'] . "\"/>\n";
  304. }
  305. $xml .= " </gateway>\n";
  306. $xml .= "</include>";
  307. //write the xml
  308. fwrite($fout, $xml);
  309. unset($xml);
  310. fclose($fout);
  311. }
  312. }
  313. }
  314. unset($sql, $parameters, $result, $row);
  315. //apply settings
  316. $_SESSION["reload_xml"] = true;
  317. }
  318. function save_var_xml() {
  319. if (is_array($_SESSION['switch']['conf'])) {
  320. global $config, $domain_uuid;
  321. //open the vars.xml file
  322. $fout = fopen($_SESSION['switch']['conf']['dir']."/vars.xml","w");
  323. //get the hostname
  324. $hostname = trim(event_socket_request_cmd('api switchname'));
  325. if (strlen($hostname) == 0){
  326. $hostname = trim(gethostname());
  327. }
  328. if (strlen($hostname) == 0){
  329. return;
  330. }
  331. //build the xml
  332. $sql = "select * from v_vars ";
  333. $sql .= "where var_enabled = 'true' ";
  334. $sql .= "order by var_category, var_order asc ";
  335. $database = new database;
  336. $variables = $database->select($sql, $parameters, 'all');
  337. $prev_var_category = '';
  338. $xml = '';
  339. if (is_array($variables) && @sizeof($variables) != 0) {
  340. foreach ($variables as &$row) {
  341. if ($row['var_category'] != 'Provision') {
  342. if ($prev_var_category != $row['var_category']) {
  343. $xml .= "\n<!-- ".$row['var_category']." -->\n";
  344. if (strlen($row["var_description"]) > 0) {
  345. $xml .= "<!-- ".base64_decode($row['var_description'])." -->\n";
  346. }
  347. }
  348. if (strlen($row['var_command']) == 0) { $row['var_command'] = 'set'; }
  349. if ($row['var_category'] == 'Exec-Set') { $row['var_command'] = 'exec-set'; }
  350. if (strlen($row['var_hostname']) == 0) {
  351. $xml .= "<X-PRE-PROCESS cmd=\"".$row['var_command']."\" data=\"".$row['var_name']."=".$row['var_value']."\" />\n";
  352. } elseif ($row['var_hostname'] == $hostname) {
  353. $xml .= "<X-PRE-PROCESS cmd=\"".$row['var_command']."\" data=\"".$row['var_name']."=".$row['var_value']."\" />\n";
  354. }
  355. }
  356. $prev_var_category = $row['var_category'];
  357. }
  358. }
  359. $xml .= "\n";
  360. fwrite($fout, $xml);
  361. unset($sql, $variables, $xml);
  362. fclose($fout);
  363. //apply settings
  364. $_SESSION["reload_xml"] = true;
  365. //$cmd = "api reloadxml";
  366. //event_socket_request_cmd($cmd);
  367. //unset($cmd);
  368. }
  369. }
  370. function outbound_route_to_bridge($domain_uuid, $destination_number, array $channel_variables=null) {
  371. $destination_number = trim($destination_number);
  372. preg_match('/^[\*\+0-9]*$/', $destination_number, $matches, PREG_OFFSET_CAPTURE);
  373. if (count($matches) > 0) {
  374. //not found, continue to process the function
  375. }
  376. else {
  377. //not a number, brige_array and exit the function
  378. $bridge_array[0] = $destination_number;
  379. return $bridge_array;
  380. }
  381. //get the hostname
  382. $hostname = trim(event_socket_request_cmd('api switchname'));
  383. if (strlen($hostname) == 0) {
  384. $hostname = 'unknown';
  385. }
  386. $sql = "select d.dialplan_uuid, ";
  387. $sql .= "d.dialplan_name, ";
  388. $sql .= "dd.dialplan_detail_uuid, ";
  389. $sql .= "dd.dialplan_detail_tag, ";
  390. $sql .= "dd.dialplan_detail_type, ";
  391. $sql .= "dd.dialplan_detail_data , ";
  392. $sql .= "d.dialplan_continue ";
  393. $sql .= "from v_dialplans d, v_dialplan_details dd ";
  394. $sql .= "where d.dialplan_uuid = dd.dialplan_uuid ";
  395. if (is_uuid($domain_uuid)) {
  396. $sql .= "and (d.domain_uuid = :domain_uuid or d.domain_uuid is null) ";
  397. $parameters['domain_uuid'] = $domain_uuid;
  398. }
  399. else {
  400. $sql .= "and (d.domain_uuid is null) ";
  401. }
  402. $sql .= "and (hostname = :hostname or hostname is null) ";
  403. $sql .= "and d.app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' ";
  404. $sql .= "and d.dialplan_enabled = 'true' ";
  405. $sql .= "order by d.domain_uuid, d.dialplan_order, dd.dialplan_detail_order ";
  406. $parameters['hostname'] = $hostname;
  407. $database = new database;
  408. $result = $database->select($sql, $parameters, 'all');
  409. unset($sql, $parameters);
  410. if (is_array($result) && @sizeof($result) != 0) {
  411. foreach ($result as &$row) {
  412. $dialplan_uuid = $row["dialplan_uuid"];
  413. $dialplan_detail_uuid = $row["dialplan_detail_uuid"];
  414. $outbound_routes[$dialplan_uuid][$dialplan_detail_uuid]["dialplan_detail_tag"] = $row["dialplan_detail_tag"];
  415. $outbound_routes[$dialplan_uuid][$dialplan_detail_uuid]["dialplan_detail_type"] = $row["dialplan_detail_type"];
  416. $outbound_routes[$dialplan_uuid][$dialplan_detail_uuid]["dialplan_detail_data"] = $row["dialplan_detail_data"];
  417. $outbound_routes[$dialplan_uuid]["dialplan_continue"] = $row["dialplan_continue"];
  418. }
  419. }
  420. if (is_array($outbound_routes) && @sizeof($outbound_routes) != 0) {
  421. $x = 0;
  422. foreach ($outbound_routes as &$dialplan) {
  423. $condition_match = false;
  424. foreach ($dialplan as &$dialplan_details) {
  425. if ($dialplan_details['dialplan_detail_tag'] == "condition") {
  426. if ($dialplan_details['dialplan_detail_type'] == "destination_number") {
  427. $pattern = '/'.$dialplan_details['dialplan_detail_data'].'/';
  428. preg_match($pattern, $destination_number, $matches, PREG_OFFSET_CAPTURE);
  429. if (count($matches) == 0) {
  430. $condition_match[] = 'false';
  431. }
  432. else {
  433. $condition_match[] = 'true';
  434. $regex_match_1 = $matches[1][0];
  435. $regex_match_2 = $matches[2][0];
  436. $regex_match_3 = $matches[3][0];
  437. $regex_match_4 = $matches[4][0];
  438. $regex_match_5 = $matches[5][0];
  439. }
  440. }
  441. elseif ($dialplan_details['dialplan_detail_type'] == "\${toll_allow}") {
  442. $pattern = '/'.$dialplan_details['dialplan_detail_data'].'/';
  443. preg_match($pattern, $channel_variables['toll_allow'], $matches, PREG_OFFSET_CAPTURE);
  444. if (count($matches) == 0) {
  445. $condition_match[] = 'false';
  446. }
  447. else {
  448. $condition_match[] = 'true';
  449. }
  450. }
  451. }
  452. }
  453. if (!in_array('false', $condition_match)) {
  454. foreach ($dialplan as &$dialplan_details) {
  455. $dialplan_detail_data = $dialplan_details['dialplan_detail_data'];
  456. if ($dialplan_details['dialplan_detail_tag'] == "action" && $dialplan_details['dialplan_detail_type'] == "bridge" && $dialplan_detail_data != "\${enum_auto_route}") {
  457. $dialplan_detail_data = str_replace("\$1", $regex_match_1, $dialplan_detail_data);
  458. $dialplan_detail_data = str_replace("\$2", $regex_match_2, $dialplan_detail_data);
  459. $dialplan_detail_data = str_replace("\$3", $regex_match_3, $dialplan_detail_data);
  460. $dialplan_detail_data = str_replace("\$4", $regex_match_4, $dialplan_detail_data);
  461. $dialplan_detail_data = str_replace("\$5", $regex_match_5, $dialplan_detail_data);
  462. $bridge_array[$x] = $dialplan_detail_data;
  463. $x++;
  464. }
  465. }
  466. if ($dialplan["dialplan_continue"] == "false") {
  467. break;
  468. }
  469. }
  470. }
  471. }
  472. return $bridge_array;
  473. }
  474. //$destination_number = '1231234';
  475. //$bridge_array = outbound_route_to_bridge ($domain_uuid, $destination_number);
  476. //foreach ($bridge_array as &$bridge) {
  477. // echo "bridge: ".$bridge."<br />";
  478. //}
  479. function extension_exists($extension) {
  480. global $domain_uuid;
  481. $sql = "select count(*) from v_extensions ";
  482. $sql .= "where domain_uuid = :domain_uuid ";
  483. $sql .= "and ( ";
  484. $sql .= "extension = :extension ";
  485. $sql .= "or number_alias = :extension ";
  486. $sql .= ") ";
  487. $sql .= "and enabled = 'true' ";
  488. $parameters['domain_uuid'] = $domain_uuid;
  489. $parameters['extension'] = $extension;
  490. $database = new database;
  491. $num_rows = $database->select($sql, $parameters, 'column');
  492. unset($sql, $parameters);
  493. return $num_rows > 0 ? true : false;
  494. }
  495. function extension_presence_id($extension, $number_alias = false) {
  496. global $domain_uuid;
  497. if ($number_alias === false) {
  498. $sql = "select extension, number_alias from v_extensions ";
  499. $sql .= "where domain_uuid = :domain_uuid ";
  500. $sql .= "and ( ";
  501. $sql .= "extension = :extension ";
  502. $sql .= "or number_alias = :extension ";
  503. $sql .= ") ";
  504. $parameters['domain_uuid'] = $domain_uuid;
  505. $parameters['extension'] = $extension;
  506. $database = new database;
  507. $row = $database->select($sql, $parameters, 'row');
  508. if (is_array($row) && @sizeof($row) != 0) {
  509. $extension = $row['extension'];
  510. $number_alias = $row['number_alias'];
  511. }
  512. else {
  513. return false;
  514. }
  515. unset($sql, $parameters, $row);
  516. }
  517. if (strlen($number_alias) > 0) {
  518. if ($_SESSION['provision']['number_as_presence_id']['text'] === 'true') {
  519. return $number_alias;
  520. }
  521. }
  522. return $extension;
  523. }
  524. function get_recording_filename($id) {
  525. global $domain_uuid;
  526. $sql = "select * from v_recordings ";
  527. $sql .= "where recording_uuid = :recording_uuid ";
  528. $sql .= "and domain_uuid = :domain_uuid ";
  529. $parameters['recording_uuid'] = $id;
  530. $parameters['domain_uuid'] = $domain_uuid;
  531. $database = new database;
  532. $row = $database->select($sql, $parameters, 'row');
  533. if (is_array($row) && @sizeof($row) != 0) {
  534. //$filename = $row["filename"];
  535. //$recording_name = $row["recording_name"];
  536. //$recording_uuid = $row["recording_uuid"];
  537. return $row["filename"];
  538. }
  539. unset($sql, $parameters, $row);
  540. }
  541. function dialplan_add($domain_uuid, $dialplan_uuid, $dialplan_name, $dialplan_order, $dialplan_context, $dialplan_enabled, $dialplan_description, $app_uuid) {
  542. //build insert array
  543. $array['dialplans'][0]['dialplan_uuid'] = $dialplan_uuid;
  544. $array['dialplans'][0]['domain_uuid'] = $domain_uuid;
  545. if (is_uuid($app_uuid)) {
  546. $array['dialplans'][0]['app_uuid'] = $app_uuid;
  547. }
  548. $array['dialplans'][0]['dialplan_name'] = $dialplan_name;
  549. $array['dialplans'][0]['dialplan_order'] = $dialplan_order;
  550. $array['dialplans'][0]['dialplan_context'] = $dialplan_context;
  551. $array['dialplans'][0]['dialplan_enabled'] = $dialplan_enabled;
  552. $array['dialplans'][0]['dialplan_description'] = $dialplan_description;
  553. //grant temporary permissions
  554. $p = new permissions;
  555. $p->add('dialplan_add', 'temp');
  556. //execute insert
  557. $database = new database;
  558. $database->app_name = 'switch-function-dialplan_add';
  559. $database->app_uuid = '2fa2243c-47a1-41a0-b144-eb2b609219e0';
  560. $database->save($array);
  561. unset($array);
  562. //revoke temporary permissions
  563. $p->delete('dialplan_add', 'temp');
  564. }
  565. if (!function_exists('phone_letter_to_number')) {
  566. function phone_letter_to_number($tmp) {
  567. $tmp = strtolower($tmp);
  568. if ($tmp == "a" | $tmp == "b" | $tmp == "c") { return 2; }
  569. if ($tmp == "d" | $tmp == "e" | $tmp == "f") { return 3; }
  570. if ($tmp == "g" | $tmp == "h" | $tmp == "i") { return 4; }
  571. if ($tmp == "j" | $tmp == "k" | $tmp == "l") { return 5; }
  572. if ($tmp == "m" | $tmp == "n" | $tmp == "o") { return 6; }
  573. if ($tmp == "p" | $tmp == "q" | $tmp == "r" | $tmp == "s") { return 7; }
  574. if ($tmp == "t" | $tmp == "u" | $tmp == "v") { return 8; }
  575. if ($tmp == "w" | $tmp == "x" | $tmp == "y" | $tmp == "z") { return 9; }
  576. }
  577. }
  578. if (!function_exists('save_call_center_xml')) {
  579. function save_call_center_xml() {
  580. global $domain_uuid;
  581. if (strlen($_SESSION['switch']['call_center']['dir']) > 0) {
  582. //get the call center queue array
  583. $sql = "select * from v_call_center_queues ";
  584. $database = new database;
  585. $call_center_queues = $database->select($sql, null, 'all');
  586. unset($sql);
  587. if (is_array($call_center_queues) && @sizeof($call_center_queues) != 0) {
  588. //prepare Queue XML string
  589. $x=0;
  590. foreach ($call_center_queues as &$row) {
  591. $queue_name = $row["queue_name"];
  592. $queue_extension = $row["queue_extension"];
  593. $queue_strategy = $row["queue_strategy"];
  594. $queue_moh_sound = $row["queue_moh_sound"];
  595. $queue_record_template = $row["queue_record_template"];
  596. $queue_time_base_score = $row["queue_time_base_score"];
  597. $queue_max_wait_time = $row["queue_max_wait_time"];
  598. $queue_max_wait_time_with_no_agent = $row["queue_max_wait_time_with_no_agent"];
  599. $queue_tier_rules_apply = $row["queue_tier_rules_apply"];
  600. $queue_tier_rule_wait_second = $row["queue_tier_rule_wait_second"];
  601. $queue_tier_rule_wait_multiply_level = $row["queue_tier_rule_wait_multiply_level"];
  602. $queue_tier_rule_no_agent_no_wait = $row["queue_tier_rule_no_agent_no_wait"];
  603. $queue_discard_abandoned_after = $row["queue_discard_abandoned_after"];
  604. $queue_abandoned_resume_allowed = $row["queue_abandoned_resume_allowed"];
  605. $queue_announce_sound = $row["queue_announce_sound"];
  606. $queue_announce_frequency = $row ["queue_announce_frequency"];
  607. $queue_description = $row["queue_description"];
  608. //replace space with an underscore
  609. $queue_name = str_replace(" ", "_", $queue_name);
  610. if ($x > 0) {
  611. $v_queues .= "\n";
  612. $v_queues .= " ";
  613. }
  614. $v_queues .= " <queue name=\"$queue_name@".$_SESSION['domains'][$row["domain_uuid"]]['domain_name']."\">\n";
  615. $v_queues .= " <param name=\"strategy\" value=\"$queue_strategy\"/>\n";
  616. if (strlen($queue_moh_sound) == 0) {
  617. $v_queues .= " <param name=\"moh-sound\" value=\"local_stream://default\"/>\n";
  618. }
  619. else {
  620. if (substr($queue_moh_sound, 0, 15) == 'local_stream://') {
  621. $v_queues .= " <param name=\"moh-sound\" value=\"".$queue_moh_sound."\"/>\n";
  622. }
  623. elseif (substr($queue_moh_sound, 0, 2) == '${' && substr($queue_moh_sound, -5) == 'ring}') {
  624. $v_queues .= " <param name=\"moh-sound\" value=\"tone_stream://".$queue_moh_sound.";loops=-1\"/>\n";
  625. }
  626. else {
  627. $v_queues .= " <param name=\"moh-sound\" value=\"".$queue_moh_sound."\"/>\n";
  628. }
  629. }
  630. if (strlen($queue_record_template) > 0) {
  631. $v_queues .= " <param name=\"record-template\" value=\"$queue_record_template\"/>\n";
  632. }
  633. $v_queues .= " <param name=\"time-base-score\" value=\"$queue_time_base_score\"/>\n";
  634. $v_queues .= " <param name=\"max-wait-time\" value=\"$queue_max_wait_time\"/>\n";
  635. $v_queues .= " <param name=\"max-wait-time-with-no-agent\" value=\"$queue_max_wait_time_with_no_agent\"/>\n";
  636. $v_queues .= " <param name=\"max-wait-time-with-no-agent-time-reached\" value=\"$queue_max_wait_time_with_no_agent_time_reached\"/>\n";
  637. $v_queues .= " <param name=\"tier-rules-apply\" value=\"$queue_tier_rules_apply\"/>\n";
  638. $v_queues .= " <param name=\"tier-rule-wait-second\" value=\"$queue_tier_rule_wait_second\"/>\n";
  639. $v_queues .= " <param name=\"tier-rule-wait-multiply-level\" value=\"$queue_tier_rule_wait_multiply_level\"/>\n";
  640. $v_queues .= " <param name=\"tier-rule-no-agent-no-wait\" value=\"$queue_tier_rule_no_agent_no_wait\"/>\n";
  641. $v_queues .= " <param name=\"discard-abandoned-after\" value=\"$queue_discard_abandoned_after\"/>\n";
  642. $v_queues .= " <param name=\"abandoned-resume-allowed\" value=\"$queue_abandoned_resume_allowed\"/>\n";
  643. $v_queues .= " <param name=\"announce-sound\" value=\"$queue_announce_sound\"/>\n";
  644. $v_queues .= " <param name=\"announce-frequency\" value=\"$queue_announce_frequency\"/>\n";
  645. $v_queues .= " </queue>";
  646. $x++;
  647. }
  648. //prepare Agent XML string
  649. $v_agents = '';
  650. $sql = "select * from v_call_center_agents ";
  651. $database = new database;
  652. $result = $database->select($sql, null, 'all');
  653. unset($sql);
  654. $x=0;
  655. if (is_array($result) && @sizeof($result) != 0) {
  656. foreach ($result as &$row) {
  657. //get the values from the db and set as php variables
  658. $agent_name = $row["agent_name"];
  659. $agent_type = $row["agent_type"];
  660. $agent_call_timeout = $row["agent_call_timeout"];
  661. $agent_contact = $row["agent_contact"];
  662. $agent_status = $row["agent_status"];
  663. $agent_no_answer_delay_time = $row["agent_no_answer_delay_time"];
  664. $agent_max_no_answer = $row["agent_max_no_answer"];
  665. $agent_wrap_up_time = $row["agent_wrap_up_time"];
  666. $agent_reject_delay_time = $row["agent_reject_delay_time"];
  667. $agent_busy_delay_time = $row["agent_busy_delay_time"];
  668. if ($x > 0) {
  669. $v_agents .= "\n";
  670. $v_agents .= " ";
  671. }
  672. //get and then set the complete agent_contact with the call_timeout and when necessary confirm
  673. //$tmp_confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1";
  674. //if you change this variable also change app/call_center/call_center_agent_edit.php
  675. $tmp_confirm = "group_confirm_file=custom/press_1_to_accept_this_call.wav,group_confirm_key=1,group_confirm_read_timeout=2000,leg_timeout=".$agent_call_timeout;
  676. if(strstr($agent_contact, '}') === FALSE) {
  677. //not found
  678. if(stristr($agent_contact, 'sofia/gateway') === FALSE) {
  679. //add the call_timeout
  680. $tmp_agent_contact = "{call_timeout=".$agent_call_timeout."}".$agent_contact;
  681. }
  682. else {
  683. //add the call_timeout and confirm
  684. $tmp_agent_contact = $tmp_first.',call_timeout='.$agent_call_timeout.$tmp_last;
  685. $tmp_agent_contact = "{".$tmp_confirm.",call_timeout=".$agent_call_timeout."}".$agent_contact;
  686. }
  687. }
  688. else {
  689. //found
  690. if(stristr($agent_contact, 'sofia/gateway') === FALSE) {
  691. //not found
  692. if(stristr($agent_contact, 'call_timeout') === FALSE) {
  693. //add the call_timeout
  694. $tmp_pos = strrpos($agent_contact, "}");
  695. $tmp_first = substr($agent_contact, 0, $tmp_pos);
  696. $tmp_last = substr($agent_contact, $tmp_pos);
  697. $tmp_agent_contact = $tmp_first.',call_timeout='.$agent_call_timeout.$tmp_last;
  698. }
  699. else {
  700. //the string has the call timeout
  701. $tmp_agent_contact = $agent_contact;
  702. }
  703. }
  704. else {
  705. //found
  706. $tmp_pos = strrpos($agent_contact, "}");
  707. $tmp_first = substr($agent_contact, 0, $tmp_pos);
  708. $tmp_last = substr($agent_contact, $tmp_pos);
  709. if(stristr($agent_contact, 'call_timeout') === FALSE) {
  710. //add the call_timeout and confirm
  711. $tmp_agent_contact = $tmp_first.','.$tmp_confirm.',call_timeout='.$agent_call_timeout.$tmp_last;
  712. }
  713. else {
  714. //add confirm
  715. $tmp_agent_contact = $tmp_first.','.$tmp_confirm.$tmp_last;
  716. }
  717. }
  718. }
  719. $v_agents .= "<agent ";
  720. $v_agents .= "name=\"$agent_name@".$_SESSION['domains'][$row["domain_uuid"]]['domain_name']."\" ";
  721. $v_agents .= "type=\"$agent_type\" ";
  722. $v_agents .= "contact=\"$tmp_agent_contact\" ";
  723. $v_agents .= "status=\"$agent_status\" ";
  724. $v_agents .= "no-answer-delay-time=\"$agent_no_answer_delay_time\" ";
  725. $v_agents .= "max-no-answer=\"$agent_max_no_answer\" ";
  726. $v_agents .= "wrap-up-time=\"$agent_wrap_up_time\" ";
  727. $v_agents .= "reject-delay-time=\"$agent_reject_delay_time\" ";
  728. $v_agents .= "busy-delay-time=\"$agent_busy_delay_time\" ";
  729. $v_agents .= "/>";
  730. $x++;
  731. }
  732. }
  733. unset($result, $row);
  734. //prepare Tier XML string
  735. $v_tiers = '';
  736. $sql = "select * from v_call_center_tiers ";
  737. $database = new database;
  738. $result = $database->select($sql, null, 'all');
  739. unset($sql);
  740. $x=0;
  741. if (is_array($result) && @sizeof($result) != 0) {
  742. foreach ($result as &$row) {
  743. $agent_name = $row["agent_name"];
  744. $queue_name = $row["queue_name"];
  745. $tier_level = $row["tier_level"];
  746. $tier_position = $row["tier_position"];
  747. if ($x > 0) {
  748. $v_tiers .= "\n";
  749. $v_tiers .= " ";
  750. }
  751. $v_tiers .= "<tier agent=\"$agent_name@".$_SESSION['domains'][$row["domain_uuid"]]['domain_name']."\" queue=\"$queue_name@".$_SESSION['domains'][$row["domain_uuid"]]['domain_name']."\" level=\"$tier_level\" position=\"$tier_position\"/>";
  752. $x++;
  753. }
  754. }
  755. unset($result, $row);
  756. //set the path
  757. if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')) {
  758. $path = "/usr/share/examples/fusionpbx/resources/templates/conf";
  759. }
  760. else {
  761. $path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
  762. }
  763. //get the contents of the template
  764. $file_contents = file_get_contents($path."/autoload_configs/callcenter.conf.xml.noload");
  765. //add the Call Center Queues, Agents and Tiers to the XML config
  766. $file_contents = str_replace("{v_queues}", $v_queues, $file_contents);
  767. unset($v_queues);
  768. $file_contents = str_replace("{v_agents}", $v_agents, $file_contents);
  769. unset($v_agents);
  770. $file_contents = str_replace("{v_tiers}", $v_tiers, $file_contents);
  771. unset($v_tiers);
  772. //write the XML config file
  773. $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/callcenter.conf.xml","w");
  774. fwrite($fout, $file_contents);
  775. fclose($fout);
  776. //apply settings
  777. $_SESSION["reload_xml"] = true;
  778. }
  779. unset($call_center_queues);
  780. }
  781. }
  782. }
  783. if (!function_exists('switch_conf_xml')) {
  784. function switch_conf_xml() {
  785. //get the contents of the template
  786. if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')) {
  787. $path = "/usr/share/examples/fusionpbx/resources/templates/conf";
  788. }
  789. else {
  790. $path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
  791. }
  792. $file_contents = file_get_contents($path."/autoload_configs/switch.conf.xml");
  793. //prepare the php variables
  794. if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
  795. $php_bin = win_find_php('php.exe');
  796. if(!$php_bin){ // relay on system path
  797. $php_bin = 'php.exe';
  798. }
  799. $secure_path = path_join($_SERVER["DOCUMENT_ROOT"], PROJECT_PATH, 'secure');
  800. $v_mail_bat = path_join($secure_path, 'mailto.bat');
  801. $v_mail_cmd = '@' .
  802. '"' . str_replace('/', '\\', $php_bin) . '" ' .
  803. '"' . str_replace('/', '\\', path_join($secure_path, 'v_mailto.php')) . '" ';
  804. $fout = fopen($v_mail_bat, "w+");
  805. fwrite($fout, $v_mail_cmd);
  806. fclose($fout);
  807. $v_mailer_app = '"' . str_replace('/', '\\', $v_mail_bat) . '"';
  808. $v_mailer_app_args = "";
  809. unset($v_mail_bat, $v_mail_cmd, $secure_path, $php_bin, $fout);
  810. }
  811. else {
  812. if (file_exists(PHP_BINDIR.'/php')) { define("PHP_BIN", "php"); }
  813. $v_mailer_app = PHP_BINDIR."/".PHP_BIN." ".$_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/secure/v_mailto.php";
  814. $v_mailer_app_args = "-t";
  815. }
  816. //replace the values in the template
  817. $file_contents = str_replace("{v_mailer_app}", $v_mailer_app, $file_contents);
  818. unset ($v_mailer_app);
  819. //replace the values in the template
  820. $file_contents = str_replace("{v_mailer_app_args}", $v_mailer_app_args, $file_contents);
  821. unset ($v_mailer_app_args);
  822. //write the XML config file
  823. $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/switch.conf.xml","w");
  824. fwrite($fout, $file_contents);
  825. fclose($fout);
  826. //apply settings
  827. $_SESSION["reload_xml"] = true;
  828. }
  829. }
  830. if (!function_exists('xml_cdr_conf_xml')) {
  831. function xml_cdr_conf_xml() {
  832. //get the contents of the template
  833. if (file_exists('/usr/share/examples/fusionpbx/resources/templates/conf')) {
  834. $path = "/usr/share/examples/fusionpbx/resources/templates/conf";
  835. }
  836. else {
  837. $path = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/conf";
  838. }
  839. $file_contents = file_get_contents($path."/autoload_configs/xml_cdr.conf.xml");
  840. //replace the values in the template
  841. $file_contents = str_replace("{v_http_protocol}", "http", $file_contents);
  842. $file_contents = str_replace("{domain_name}", "127.0.0.1", $file_contents);
  843. $file_contents = str_replace("{v_project_path}", PROJECT_PATH, $file_contents);
  844. $v_user = generate_password();
  845. $file_contents = str_replace("{v_user}", $v_user, $file_contents);
  846. unset ($v_user);
  847. $v_pass = generate_password();
  848. $file_contents = str_replace("{v_pass}", $v_pass, $file_contents);
  849. unset ($v_pass);
  850. //write the XML config file
  851. $fout = fopen($_SESSION['switch']['conf']['dir']."/autoload_configs/xml_cdr.conf.xml","w");
  852. fwrite($fout, $file_contents);
  853. fclose($fout);
  854. //apply settings
  855. $_SESSION["reload_xml"] = true;
  856. }
  857. }
  858. if (!function_exists('save_sip_profile_xml')) {
  859. function save_sip_profile_xml() {
  860. //skip saving the sip profile xml if the directory is not set
  861. if (strlen($_SESSION['switch']['sip_profiles']['dir']) == 0) {
  862. return;
  863. }
  864. // make profile dir if needed
  865. $profile_dir = $_SESSION['switch']['conf']['dir']."/sip_profiles";
  866. if (!is_readable($profile_dir)) {
  867. mkdir($profile_dir, 0770, false);
  868. }
  869. //get the sip profiles from the database
  870. $sql = "select * from v_sip_profiles";
  871. $database = new database;
  872. $result = $database->select($sql, null, 'all');
  873. unset($sql);
  874. if (is_array($result) && @sizeof($result) != 0) {
  875. foreach($result as $row) {
  876. $sip_profile_uuid = $row['sip_profile_uuid'];
  877. $sip_profile_name = $row['sip_profile_name'];
  878. $sip_profile_enabled = $row['sip_profile_enabled'];
  879. if ($sip_profile_enabled == 'false') {
  880. $fout = fopen($profile_dir.'/'.$sip_profile_name.".xml","w");
  881. if ($fout) {
  882. fclose($fout);
  883. }
  884. continue;
  885. }
  886. //get the xml sip profile template
  887. if ($sip_profile_name == "internal" || $sip_profile_name == "external" || $sip_profile_name == "internal-ipv6") {
  888. $file_contents = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/sip_profiles/resources/xml/sip_profiles/".$sip_profile_name.".xml");
  889. }
  890. else {
  891. $file_contents = file_get_contents($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/sip_profiles/resources/xml/sip_profiles/default.xml");
  892. }
  893. //get the sip profile settings
  894. $sql = "select * from v_sip_profile_settings ";
  895. $sql .= "where sip_profile_uuid = :sip_profile_uuid ";
  896. $sql .= "and sip_profile_setting_enabled = 'true' ";
  897. $parameters['sip_profile_uuid'] = $sip_profile_uuid;
  898. $database = new database;
  899. $result_2 = $database->select($sql, $parameters, 'all');
  900. if (is_array($result_2) && @sizeof($result_2) != 0) {
  901. $sip_profile_settings = '';
  902. foreach ($result_2 as &$row_2) {
  903. $sip_profile_settings .= " <param name=\"".$row_2["sip_profile_setting_name"]."\" value=\"".$row_2["sip_profile_setting_value"]."\"/>\n";
  904. }
  905. }
  906. unset($sql, $parameters, $result_2, $row_2);
  907. //replace the values in the template
  908. $file_contents = str_replace("{v_sip_profile_name}", $sip_profile_name, $file_contents);
  909. $file_contents = str_replace("{v_sip_profile_settings}", $sip_profile_settings, $file_contents);
  910. //write the XML config file
  911. if (is_readable($profile_dir.'/')) {
  912. $fout = fopen($profile_dir.'/'.$sip_profile_name.".xml","w");
  913. fwrite($fout, $file_contents);
  914. fclose($fout);
  915. }
  916. //if the directory does not exist then create it
  917. if (!is_readable($profile_dir.'/'.$sip_profile_name)) {
  918. mkdir($profile_dir.'/'.$sip_profile_name, 0770, false);
  919. }
  920. }
  921. unset($result, $row);
  922. }
  923. //apply settings
  924. $_SESSION["reload_xml"] = true;
  925. }
  926. }
  927. if (!function_exists('save_switch_xml')) {
  928. function save_switch_xml() {
  929. if (is_readable($_SESSION['switch']['extensions']['dir'])) {
  930. if (file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/extensions/resources/classes/extension.php")) {
  931. require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."app/extensions/resources/classes/extension.php";
  932. $extension = new extension;
  933. $extension->xml();
  934. }
  935. }
  936. if (is_readable($_SESSION['switch']['conf']['dir'])) {
  937. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/settings/app_config.php")) {
  938. save_setting_xml();
  939. }
  940. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/modules/app_config.php")) {
  941. require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/modules/resources/classes/modules.php";
  942. $module = new modules;
  943. $module->xml();
  944. //$msg = $module->msg;
  945. }
  946. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/vars/app_config.php")) {
  947. save_var_xml();
  948. }
  949. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/call_center/app_config.php")) {
  950. save_call_center_xml();
  951. }
  952. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/gateways/app_config.php")) {
  953. save_gateway_xml();
  954. }
  955. //if (file_exists($_SERVER["PROJECT_ROOT"]."/app/ivr_menu/app_config.php")) {
  956. // save_ivr_menu_xml();
  957. //}
  958. if (file_exists($_SERVER["PROJECT_ROOT"]."/app/sip_profiles/app_config.php")) {
  959. save_sip_profile_xml();
  960. }
  961. }
  962. }
  963. }
  964. if(!function_exists('path_join')) {
  965. function path_join() {
  966. $args = func_get_args();
  967. $paths = array();
  968. foreach ($args as $arg) {
  969. $paths = array_merge($paths, (array)$arg);
  970. }
  971. $prefix = null;
  972. foreach($paths as &$path) {
  973. if($prefix === null && strlen($path) > 0) {
  974. if(substr($path, 0, 1) == '/') $prefix = '/';
  975. else $prefix = '';
  976. }
  977. $path = trim( $path, '/' );
  978. $path = trim( $path, '\\' );
  979. }
  980. if($prefix === null){
  981. return '';
  982. }
  983. $paths = array_filter($paths);
  984. return $prefix . join('/', $paths);
  985. }
  986. }
  987. if(!function_exists('win_find_php')) {
  988. function win_find_php_in_root($root, $bin){
  989. while(true) {
  990. $php_bin = path_join($root, $bin);
  991. if(file_exists($php_bin)){
  992. $php_bin = str_replace('/', '\\', $php_bin);
  993. return $php_bin;
  994. }
  995. $prev_root = $root;
  996. $root = dirname($root);
  997. if((!$root)&&($prev_root == $root)){
  998. return false;
  999. }
  1000. }
  1001. }
  1002. //Tested on WAMP and OpenServer
  1003. //Can get wrong result if `extension_dir` set as relative path.
  1004. function win_find_php_by_extension($bin_name){
  1005. $bin_dir = get_cfg_var('extension_dir');
  1006. return win_find_php_in_root($bin_dir, $bin_name);
  1007. }
  1008. // Works since PHP 5.4
  1009. function win_find_php_by_binary($bin_name){
  1010. if(!defined('PHP_BINARY')){
  1011. return false;
  1012. }
  1013. $bin_dir = realpath(PHP_BINARY);
  1014. if(!$bin_dir){
  1015. $bin_dir = PHP_BINARY;
  1016. }
  1017. $bin_dir = dirname($bin_dir);
  1018. return win_find_php_in_root($bin_dir, $bin_name);
  1019. }
  1020. function win_find_php_by_phprc($bin_name){
  1021. $bin_dir = getenv(PHPRC);
  1022. if(!$bin_dir){
  1023. return false;
  1024. }
  1025. $bin_dir = realpath($bin_dir);
  1026. return win_find_php_in_root($bin_dir, $bin_name);
  1027. }
  1028. //on Windows PHP_BIN set in compile time to c:\php
  1029. //It possible redifine it in env, but not all installation do it
  1030. function win_find_php_by_bin($bin_name){
  1031. if(!defined('PHP_BIN')){
  1032. return false;
  1033. }
  1034. $bin_dir = realpath(PHP_BIN);
  1035. if(!$bin_dir){
  1036. $bin_dir = PHP_BIN;
  1037. }
  1038. $bin_dir = dirname($bin_dir);
  1039. return win_find_php_in_root($bin_dir, $bin_name);
  1040. }
  1041. function win_find_php($bin_name){
  1042. $php_bin = win_find_php_by_binary($bin_name);
  1043. if($php_bin) return $php_bin;
  1044. $php_bin = win_find_php_by_extension($bin_name);
  1045. if($php_bin) return $php_bin;
  1046. $php_bin = win_find_php_by_bin($bin_name);
  1047. if($php_bin) return $php_bin;
  1048. $php_bin = win_find_php_by_phprc($bin_name);
  1049. if($php_bin) return $php_bin;
  1050. return false;
  1051. }
  1052. }
  1053. ?>