xmpp_profile_edit.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /* $Id$ */
  3. /*
  4. FusionPBX
  5. Version: MPL 1.1
  6. The contents of this file are subject to the Mozilla Public License Version
  7. 1.1 (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.mozilla.org/MPL/
  10. Software distributed under the License is distributed on an "AS IS" basis,
  11. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. for the specific language governing rights and limitations under the
  13. License.
  14. The Original Code is FusionPBX
  15. The Initial Developer of the Original Code is
  16. Mark J Crane <[email protected]>
  17. Portions created by the Initial Developer are Copyright (C) 2008-2012
  18. the Initial Developer. All Rights Reserved.
  19. Contributor(s):
  20. Ken Rice <[email protected]>
  21. Mark J Crane <[email protected]>
  22. Luis Daniel Lucio Quiroz <[email protected]>
  23. */
  24. include "root.php";
  25. require_once "resources/require.php";
  26. require_once "resources/check_auth.php";
  27. if (permission_exists('xmpp_add') || permission_exists('xmpp_edit')) {
  28. //access granted
  29. }
  30. else {
  31. echo "access denied";
  32. exit;
  33. }
  34. //add multi-lingual support
  35. $language = new text;
  36. $text = $language->get();
  37. //add or update the database
  38. if (isset($_REQUEST["id"])) {
  39. $action = "update";
  40. $profile_id = check_str($_REQUEST["id"]);
  41. } else {
  42. $action = "add";
  43. }
  44. if ($action == "update") {
  45. $document['title'] = $text['title-xmpp-edit'];
  46. }
  47. else if ($action == "add") {
  48. $document['title'] = $text['title-xmpp-add'];
  49. }
  50. $domain_name = $_SESSION['domains'][$_SESSION['domain_uuid']]['domain_name'];
  51. if ($action == "update") {
  52. $sql = "";
  53. $sql .= "select * from v_xmpp ";
  54. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  55. $sql .= "and xmpp_profile_uuid = '$profile_id' ";
  56. $prep_statement = $db->prepare(check_sql($sql));
  57. $prep_statement->execute();
  58. $x = 0;
  59. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  60. foreach ($result as &$row) {
  61. $profiles_array[$x] = $row;
  62. $x++;
  63. }
  64. $profile = $profiles_array[0];
  65. unset ($prep_statement);
  66. $profile['profile_username'] = $profile['username'];
  67. $profile['profile_password'] = $profile['password'];
  68. } else {
  69. $profile['dialplan'] = "XML";
  70. $profile['context'] = $_SESSION['domain_name'];
  71. $profile['rtp_ip'] = '$${local_ip_v4}';
  72. $profile['ext_rtp_ip'] = '$${external_rtp_ip}';
  73. $profile['auto_login'] = "true";
  74. $profile['sasl_type'] = "md5";
  75. $profile['tls_enable'] = "true";
  76. $profile['use_rtp_timer'] = "true";
  77. $profile['vad'] = "none";
  78. $profile['candidate_acl'] = "wan.auto";
  79. $profile['local_network_acl'] = "localnet.auto";
  80. }
  81. if ((!isset($_REQUEST['submit'])) || ($_REQUEST['submit'] != $text['button-save'])) {
  82. // If we arent saving a Profile Display the form.
  83. require_once "resources/header.php";
  84. include "profile_edit.php";
  85. require_once "resources/footer.php";
  86. exit;
  87. }
  88. foreach ($_REQUEST as $field => $data){
  89. $request[$field] = check_str($data);
  90. }
  91. // check the data
  92. $error = "";
  93. if (strlen($request['profile_name']) < 1) $error .= $text['message-required'].$text['label-profile_name']."<br />\n";
  94. if (strlen($request['profile_username']) < 1) $error .= $text['message-required'].$text['label-username']."<br />\n";
  95. if (strlen($request['profile_password']) < 1) $error .= $text['message-required'].$text['label-password']."<br />\n";
  96. if (strlen($request['default_exten']) < 1) $error .= $text['message-required'].$text['label-default_exten']."<br />\n";
  97. if (strlen($error) > 0) {
  98. include "errors.php";
  99. $profile = $request;
  100. require_once "resources/header.php";
  101. include "profile_edit.php";
  102. require_once "resources/footer.php";
  103. exit;
  104. }
  105. // Save New Entry
  106. if ($action == "add" && permission_exists('xmpp_add')) {
  107. $xmpp_profile_uuid = uuid();
  108. $sql = "";
  109. $sql .= "insert into v_xmpp (";
  110. $sql .= "domain_uuid, ";
  111. $sql .= "xmpp_profile_uuid, ";
  112. $sql .= "profile_name, ";
  113. $sql .= "username, ";
  114. $sql .= "password, ";
  115. $sql .= "dialplan, ";
  116. $sql .= "context, ";
  117. $sql .= "rtp_ip, ";
  118. $sql .= "ext_rtp_ip, ";
  119. $sql .= "auto_login, ";
  120. $sql .= "sasl_type, ";
  121. $sql .= "xmpp_server, ";
  122. $sql .= "tls_enable, ";
  123. $sql .= "use_rtp_timer, ";
  124. $sql .= "default_exten, ";
  125. $sql .= "vad, ";
  126. $sql .= "avatar, ";
  127. $sql .= "candidate_acl, ";
  128. $sql .= "local_network_acl, ";
  129. $sql .= "description, ";
  130. $sql .= "enabled ";
  131. $sql .= ") values (";
  132. $sql .= "'" . $_SESSION['domain_uuid'] . "', ";
  133. $sql .= "'" . $xmpp_profile_uuid . "', ";
  134. $sql .= "'" . $request['profile_name'] . "', ";
  135. $sql .= "'" . $request['profile_username'] . "', ";
  136. $sql .= "'" . $request['profile_password'] . "', ";
  137. $sql .= "'" . $request['dialplan'] . "', ";
  138. if (if_group("superadmin") && $request['context']) {
  139. $sql .= "'" . $request['context'] . "', ";
  140. }
  141. else {
  142. $sql .= "'" . $_SESSION['context'] . "', ";
  143. }
  144. $sql .= "'" . $request['rtp_ip'] . "', ";
  145. $sql .= "'" . $request['ext_rtp_ip'] . "', ";
  146. $sql .= "'" . $request['auto_login'] . "', ";
  147. $sql .= "'" . $request['sasl_type'] . "', ";
  148. $sql .= "'" . $request['xmpp_server'] . "', ";
  149. $sql .= "'" . $request['tls_enable'] . "', ";
  150. $sql .= "'" . $request['use_rtp_timer'] . "', ";
  151. $sql .= "'" . $request['default_exten'] . "', ";
  152. $sql .= "'" . $request['vad'] . "', ";
  153. $sql .= "'" . $request['avatar'] . "', ";
  154. $sql .= "'" . $request['candidate_acl'] . "', ";
  155. $sql .= "'" . $request['local_network_acl'] . "', ";
  156. $sql .= "'" . $request['description'] . "', ";
  157. $sql .= "'" . $request['enabled'] . "' ";
  158. $sql .= ") ";
  159. $db->exec(check_sql($sql));
  160. }
  161. elseif ($action == "update" && permission_exists('xmpp_edit')) {
  162. $sql = "";
  163. $sql .= "UPDATE v_xmpp SET ";
  164. $sql .= "profile_name = '" . $request['profile_name'] . "', ";
  165. $sql .= "username = '" . $request['profile_username'] . "', ";
  166. $sql .= "password = '" . $request['profile_password'] . "', ";
  167. $sql .= "dialplan = '" . $request['dialplan'] . "', ";
  168. if (if_group("superadmin") && $request['context']) {
  169. $sql .= "context = '" . $request['context'] . "', ";
  170. }
  171. else {
  172. $sql .= "context = '" . $_SESSION["context"] . "', ";
  173. }
  174. $sql .= "rtp_ip = '" . $request['rtp_ip'] . "', ";
  175. $sql .= "ext_rtp_ip = '" . $request['ext_rtp_ip'] . "', ";
  176. $sql .= "auto_login = '" . $request['auto_login'] . "', ";
  177. $sql .= "sasl_type = '" . $request['sasl_type'] . "', ";
  178. $sql .= "xmpp_server = '" . $request['xmpp_server'] . "', ";
  179. $sql .= "tls_enable = '" . $request['tls_enable'] . "', ";
  180. $sql .= "use_rtp_timer = '" . $request['use_rtp_timer'] . "', ";
  181. $sql .= "default_exten = '" . $request['default_exten'] . "', ";
  182. $sql .= "vad = '" . $request['vad'] . "', ";
  183. $sql .= "avatar = '" . $request['avatar'] . "', ";
  184. $sql .= "candidate_acl = '" . $request['candidate_acl'] . "', ";
  185. $sql .= "local_network_acl = '" . $request['local_network_acl'] . "', ";
  186. $sql .= "description = '" . $request['description'] . "', ";
  187. $sql .= "enabled = '" . $request['enabled'] . "' ";
  188. $sql .= "where xmpp_profile_uuid = '" . $request['id'] . "' ";
  189. $db->exec(check_sql($sql));
  190. $xmpp_profile_uuid = $request['id'];
  191. }
  192. if ($request['enabled'] == "true") {
  193. //prepare the xml
  194. include "client_template.php";
  195. $xml = make_xmpp_xml($request);
  196. //write the xml
  197. $filename = $_SESSION['switch']['conf']['dir'] . "/jingle_profiles/" . "v_" . $_SESSION['domain_name'] . "_" . preg_replace("/[^A-Za-z0-9]/", "", $request['profile_name']) . "_" . $xmpp_profile_uuid . ".xml";
  198. $fh = fopen($filename,"w") or die("Unable to open the file");
  199. fwrite($fh, $xml);
  200. unset($file_name);
  201. fclose($fh);
  202. }
  203. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  204. if ($fp) {
  205. //reload the XML Configs
  206. $tmp_cmd = 'api reloadxml';
  207. $response = event_socket_request($fp, $tmp_cmd);
  208. unset($tmp_cmd);
  209. //Tell mod_dingaling to reload is config
  210. $tmp_cmd = 'api dingaling reload';
  211. $response = event_socket_request($fp, $tmp_cmd);
  212. unset($tmp_cmd);
  213. //close the connection
  214. fclose($fp);
  215. }
  216. include "update_complete.php";
  217. ?>