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.

260 lines
8.8 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) 2018 - 2019
  17. the Initial Developer. All Rights Reserved.
  18. */
  19. //includes
  20. require_once "root.php";
  21. require_once "resources/require.php";
  22. require_once "resources/check_auth.php";
  23. //check permissions
  24. if (!permission_exists('bridge_add') && !permission_exists('bridge_edit')) {
  25. echo "access denied";
  26. exit;
  27. }
  28. //add multi-lingual support
  29. $language = new text;
  30. $text = $language->get();
  31. //action add or update
  32. if (is_uuid($_REQUEST["id"])) {
  33. $action = "update";
  34. $bridge_uuid = $_REQUEST["id"];
  35. $id = $_REQUEST["id"];
  36. }
  37. else {
  38. $action = "add";
  39. }
  40. //get http post variables and set them to php variables
  41. if (is_array($_POST)) {
  42. $bridge_uuid = $_POST["bridge_uuid"];
  43. $bridge_name = $_POST["bridge_name"];
  44. $bridge_destination = $_POST["bridge_destination"];
  45. $bridge_enabled = $_POST["bridge_enabled"];
  46. $bridge_description = $_POST["bridge_description"];
  47. }
  48. //process the user data and save it to the database
  49. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  50. //delete the bridge
  51. if (permission_exists('bridge_delete')) {
  52. if ($_POST['action'] == 'delete' && is_uuid($bridge_uuid)) {
  53. //prepare
  54. $array[0]['checked'] = 'true';
  55. $array[0]['uuid'] = $bridge_uuid;
  56. //delete
  57. $obj = new bridges;
  58. $obj->delete($array);
  59. //redirect
  60. header('Location: bridges.php');
  61. exit;
  62. }
  63. }
  64. //get the uuid from the POST
  65. if ($action == "update") {
  66. $bridge_uuid = $_POST["bridge_uuid"];
  67. }
  68. //validate the token
  69. $token = new token;
  70. if (!$token->validate($_SERVER['PHP_SELF'])) {
  71. message::add($text['message-invalid_token'],'negative');
  72. header('Location: bridges.php');
  73. exit;
  74. }
  75. //check for all required data
  76. $msg = '';
  77. if (strlen($bridge_name) == 0) { $msg .= $text['message-required']." ".$text['label-bridge_name']."<br>\n"; }
  78. if (strlen($bridge_destination) == 0) { $msg .= $text['message-required']." ".$text['label-bridge_destination']."<br>\n"; }
  79. if (strlen($bridge_enabled) == 0) { $msg .= $text['message-required']." ".$text['label-bridge_enabled']."<br>\n"; }
  80. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  81. require_once "resources/header.php";
  82. require_once "resources/persist_form_var.php";
  83. echo "<div align='center'>\n";
  84. echo "<table><tr><td>\n";
  85. echo $msg."<br />";
  86. echo "</td></tr></table>\n";
  87. persistformvar($_POST);
  88. echo "</div>\n";
  89. require_once "resources/footer.php";
  90. return;
  91. }
  92. //add the bridge_uuid
  93. if (strlen($bridge_uuid) == 0) {
  94. $bridge_uuid = uuid();
  95. }
  96. //prepare the array
  97. $array['bridges'][0]['bridge_uuid'] = $bridge_uuid;
  98. $array['bridges'][0]['domain_uuid'] = $_SESSION["domain_uuid"];
  99. $array['bridges'][0]['bridge_name'] = $bridge_name;
  100. $array['bridges'][0]['bridge_destination'] = $bridge_destination;
  101. $array['bridges'][0]['bridge_enabled'] = $bridge_enabled;
  102. $array['bridges'][0]['bridge_description'] = $bridge_description;
  103. //save to the data
  104. $database = new database;
  105. $database->app_name = 'bridges';
  106. $database->app_uuid = 'a6a7c4c5-340a-43ce-bcbc-2ed9bab8659d';
  107. $database->save($array);
  108. $message = $database->message;
  109. //clear the destinations session array
  110. if (isset($_SESSION['destinations']['array'])) {
  111. unset($_SESSION['destinations']['array']);
  112. }
  113. //redirect the user
  114. if (isset($action)) {
  115. if ($action == "add") {
  116. $_SESSION["message"] = $text['message-add'];
  117. }
  118. if ($action == "update") {
  119. $_SESSION["message"] = $text['message-update'];
  120. }
  121. header('Location: bridges.php');
  122. return;
  123. }
  124. }
  125. //pre-populate the form
  126. if (is_array($_GET) && $_POST["persistformvar"] != "true") {
  127. $bridge_uuid = $_GET["id"];
  128. $sql = "select * from v_bridges ";
  129. $sql .= "where bridge_uuid = :bridge_uuid ";
  130. $parameters['bridge_uuid'] = $bridge_uuid;
  131. $database = new database;
  132. $row = $database->select($sql, $parameters, 'row');
  133. if (is_array($row) && sizeof($row) != 0) {
  134. $bridge_name = $row["bridge_name"];
  135. $bridge_destination = $row["bridge_destination"];
  136. $bridge_enabled = $row["bridge_enabled"];
  137. $bridge_description = $row["bridge_description"];
  138. }
  139. unset($sql, $parameters, $row);
  140. }
  141. //create token
  142. $object = new token;
  143. $token = $object->create($_SERVER['PHP_SELF']);
  144. //show the header
  145. $document['title'] = $text['title-bridge'];
  146. require_once "resources/header.php";
  147. //show the content
  148. echo "<form name='frm' id='frm' method='post'>\n";
  149. echo "<div class='action_bar' id='action_bar'>\n";
  150. echo " <div class='heading'><b>".$text['title-bridge']."</b></div>\n";
  151. echo " <div class='actions'>\n";
  152. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'bridges.php']);
  153. if ($action == 'update' && permission_exists('bridge_delete')) {
  154. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>'margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]);
  155. }
  156. echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','name'=>'action','value'=>'save']);
  157. echo " </div>\n";
  158. echo " <div style='clear: both;'></div>\n";
  159. echo "</div>\n";
  160. if ($action == 'update' && permission_exists('bridge_delete')) {
  161. echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]);
  162. }
  163. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  164. echo "<tr>\n";
  165. echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  166. echo " ".$text['label-bridge_name']."\n";
  167. echo "</td>\n";
  168. echo "<td width='70%' class='vtable' style='position: relative;' align='left'>\n";
  169. echo " <input class='formfld' type='text' name='bridge_name' maxlength='255' value='".escape($bridge_name)."'>\n";
  170. echo "<br />\n";
  171. echo $text['description-bridge_name']."\n";
  172. echo "</td>\n";
  173. echo "</tr>\n";
  174. echo "<tr>\n";
  175. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  176. echo " ".$text['label-bridge_destination']."\n";
  177. echo "</td>\n";
  178. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  179. echo " <input class='formfld' type='text' name='bridge_destination' maxlength='255' value='".escape($bridge_destination)."'>\n";
  180. echo "<br />\n";
  181. echo $text['description-bridge_destination']."\n";
  182. echo "</td>\n";
  183. echo "</tr>\n";
  184. echo "<tr>\n";
  185. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  186. echo " ".$text['label-bridge_enabled']."\n";
  187. echo "</td>\n";
  188. echo "<td class='vtable' style='position: relative;' align='left'>\n";
  189. echo " <select class='formfld' name='bridge_enabled'>\n";
  190. if ($bridge_enabled == "true") {
  191. echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
  192. }
  193. else {
  194. echo " <option value='true'>".$text['label-true']."</option>\n";
  195. }
  196. if ($bridge_enabled == "false") {
  197. echo " <option value='false' selected='selected'>".$text['label-false']."</option>\n";
  198. }
  199. else {
  200. echo " <option value='false'>".$text['label-false']."</option>\n";
  201. }
  202. echo " </select>\n";
  203. echo "<br />\n";
  204. echo $text['description-bridge_enabled']."\n";
  205. echo "</td>\n";
  206. echo "</tr>\n";
  207. echo "<tr>\n";
  208. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  209. echo " ".$text['label-bridge_description']."\n";
  210. echo "</td>\n";
  211. echo "<td class='vtable' align='left'>\n";
  212. echo " <input class='formfld' type='text' name='bridge_description' maxlength='255' value=\"".escape($bridge_description)."\">\n";
  213. echo "<br />\n";
  214. echo $text['description-bridge_description']."\n";
  215. echo "</td>\n";
  216. echo "</tr>\n";
  217. echo "</table>";
  218. echo "<br /><br />";
  219. if ($action == "update") {
  220. echo "<input type='hidden' name='bridge_uuid' value='".escape($bridge_uuid)."'>\n";
  221. }
  222. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  223. echo "</form>";
  224. //include the footer
  225. require_once "resources/footer.php";
  226. ?>