call_acl_edit.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. 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 <[email protected]>
  20. Luis Daniel Lucio Quiroz <[email protected]>
  21. Igor Olhovskiy <[email protected]>
  22. Call ACL is written on Call Block base by Gerrit Visser <[email protected]>
  23. */
  24. //includes
  25. require_once "root.php";
  26. require_once "resources/require.php";
  27. require_once "resources/check_auth.php";
  28. //check permissions
  29. if (permission_exists('call_acl_edit') || permission_exists('call_acl_add')) {
  30. //access granted
  31. } else {
  32. echo "access denied";
  33. exit;
  34. }
  35. //add multi-lingual support
  36. $language = new text;
  37. $text = $language->get();
  38. //action add or update
  39. if (isset($_REQUEST["id"])) {
  40. $action = "update";
  41. $call_acl_uuid = check_str($_REQUEST["id"]);
  42. } else {
  43. $action = "add";
  44. }
  45. //get http post variables and set them to php variables
  46. if (count($_POST) > 0) {
  47. $call_acl_order = check_str($_POST["call_acl_order"]);
  48. $call_acl_name = check_str($_POST["call_acl_name"]);
  49. $call_acl_source = check_str($_POST["call_acl_source"]);
  50. $call_acl_destination = check_str($_POST["call_acl_destination"]);
  51. $call_acl_action = check_str($_POST["call_acl_action"]);
  52. $call_acl_enabled = check_str($_POST["call_acl_enabled"]);
  53. }
  54. //handle the http post
  55. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  56. $msg = '';
  57. //check for all required data
  58. if (strlen($call_acl_name) == 0) {
  59. $msg .= $text['label-call_acl_name']."<br>\n";
  60. }
  61. if (strlen($call_acl_source) == 0) {
  62. $msg .= $text['label-call_acl_source']."<br>\n";
  63. }
  64. if (strlen($call_acl_destination) == 0) {
  65. $msg .= $text['label-call_acl_destination']."<br>\n";
  66. }
  67. if (strlen($call_acl_order) == 0) {
  68. $msg .= $text['label-call_acl_order']."<br>\n";
  69. }
  70. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  71. require_once "resources/header.php";
  72. require_once "resources/persist_form_var.php";
  73. echo "<div align='center'>\n";
  74. echo "<table><tr><td>\n";
  75. echo $msg."<br />";
  76. echo "</td></tr></table>\n";
  77. persistformvar($_POST);
  78. echo "</div>\n";
  79. require_once "resources/footer.php";
  80. return;
  81. }
  82. //add or update the database
  83. if (($_POST["persistformvar"] != "true") > 0) {
  84. if ($action == "add") {
  85. $call_acl_uuid = uuid();
  86. $sql = "INSERT INTO v_call_acl";
  87. $sql .= " (";
  88. $sql .= "domain_uuid, ";
  89. $sql .= "call_acl_uuid, ";
  90. $sql .= "call_acl_order, ";
  91. $sql .= "call_acl_name, ";
  92. $sql .= "call_acl_source, ";
  93. $sql .= "call_acl_destination, ";
  94. $sql .= "call_acl_action, ";
  95. $sql .= "call_acl_enabled ";
  96. $sql .= ") ";
  97. $sql .= "VALUES ";
  98. $sql .= "(";
  99. $sql .= "'".$_SESSION['domain_uuid']."', ";
  100. $sql .= "'$call_acl_uuid', ";
  101. $sql .= "'$call_acl_order', ";
  102. $sql .= "'$call_acl_name', ";
  103. $sql .= "'$call_acl_source', ";
  104. $sql .= "'$call_acl_destination', ";
  105. $sql .= "'$call_acl_action', ";
  106. $sql .= "'$call_acl_enabled'";
  107. $sql .= ")";
  108. $db->exec(check_sql($sql));
  109. unset($sql);
  110. messages::add($text['label-add-complete']);
  111. header("Location: call_acl.php");
  112. return;
  113. } //if ($action == "add")
  114. if ($action == "update") {
  115. $sql = "UPDATE v_call_acl SET ";
  116. $sql .= "call_acl_order = '$call_acl_order', ";
  117. $sql .= "call_acl_name = '$call_acl_name', ";
  118. $sql .= "call_acl_source = '$call_acl_source', ";
  119. $sql .= "call_acl_destination = '$call_acl_destination', ";
  120. $sql .= "call_acl_action = '$call_acl_action', ";
  121. $sql .= "call_acl_enabled = '$call_acl_enabled' ";
  122. $sql .= "WHERE domain_uuid = '".$_SESSION['domain_uuid']."' ";
  123. $sql .= "AND call_acl_uuid = '$call_acl_uuid'";
  124. $db->exec(check_sql($sql));
  125. unset($sql);
  126. messages::add($text['label-update-complete']);
  127. header("Location: call_acl.php");
  128. return;
  129. } //if ($action == "update")
  130. } //if ($_POST["persistformvar"] != "true")
  131. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  132. //pre-populate the form
  133. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  134. $call_acl_uuid = $_GET["id"];
  135. $sql = "SELECT * FROM v_call_acl ";
  136. $sql .= "WHERE domain_uuid = '".$_SESSION['domain_uuid']."' ";
  137. $sql .= "AND call_acl_uuid = '$call_acl_uuid' ";
  138. $prep_statement = $db->prepare(check_sql($sql));
  139. $prep_statement->execute();
  140. $result = $prep_statement->fetchAll();
  141. foreach ($result as &$row) {
  142. $call_acl_order = $row["call_acl_order"];
  143. $call_acl_name = $row["call_acl_name"];
  144. $call_acl_source = $row["call_acl_source"];
  145. $call_acl_destination = $row["call_acl_destination"];
  146. $call_acl_action = $row["call_acl_action"];
  147. $call_acl_enabled = $row["call_acl_enabled"];
  148. break; //limit to 1 row ? Should be only 1 result at all
  149. }
  150. unset ($prep_statement, $sql);
  151. }
  152. // Get maximum order number
  153. $call_acl_order_max = isset($_SESSION['call_acl']['max_order']['numeric']) ? (int)$_SESSION['call_acl']['max_order']['numeric'] : 20;
  154. if (!$call_acl_order_max) {
  155. $call_acl_order_max = 20;
  156. }
  157. //show the header
  158. require_once "resources/header.php";
  159. //show the content
  160. echo "<form method='post' name='frm' action=''>\n";
  161. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  162. echo "<tr>\n";
  163. if ($action == "add") {
  164. echo "<td align='left' width='30%' nowrap='nowrap'><b>".$text['label-edit-add']."</b></td>\n";
  165. }
  166. if ($action == "update") {
  167. echo "<td align='left' width='30%' nowrap='nowrap'><b>".$text['label-edit-edit']."</b></td>\n";
  168. }
  169. echo "<td width='70%' align='right'>";
  170. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='call_acl.php'\" value='".$text['button-back']."'>";
  171. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  172. echo "</td>\n";
  173. echo "</tr>\n";
  174. echo "<tr>\n";
  175. echo "<td align='left' colspan='2'>\n";
  176. if ($action == "add") {
  177. echo $text['label-add-note']."<br /><br />\n";
  178. }
  179. if ($action == "update") {
  180. echo $text['label-edit-note']."<br /><br />\n";
  181. }
  182. echo "</td>\n";
  183. echo "</tr>\n";
  184. // Show order TODO
  185. echo "<tr>\n";
  186. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  187. echo " ".$text['label-call_acl_order']."\n";
  188. echo "</td>\n";
  189. echo "<td class='vtable' align='left'>\n";
  190. echo "<select name='call_acl_order' class='formfld'>\n";
  191. for ($i = 0; $i <= $call_acl_order_max; $i++) {
  192. $selected = ($i == $call_acl_order) ? "selected" : "";
  193. echo "<option value='$i' ".$selected.">$i</option>\n";
  194. }
  195. echo " </select>\n";
  196. echo "<br />\n";
  197. echo $text['description-call_acl_order']."\n";
  198. echo "<br />\n";
  199. echo "</td>\n";
  200. echo "</tr>\n";
  201. // Show name
  202. echo "<tr>\n";
  203. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  204. echo " ".$text['label-call_acl_name']."\n";
  205. echo "</td>\n";
  206. echo "<td class='vtable' align='left'>\n";
  207. echo " <input class='formfld' type='text' name='call_acl_name' maxlength='255' value=\"".escape($call_acl_name)."\" required='required'>\n";
  208. echo "<br />\n";
  209. echo $text['description-call_acl_name']."\n";
  210. echo "</td>\n";
  211. echo "</tr>\n";
  212. // Show source
  213. echo "<tr>\n";
  214. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  215. echo " ".$text['label-call_acl_source']."\n";
  216. echo "</td>\n";
  217. echo "<td class='vtable' align='left'>\n";
  218. echo " <input class='formfld' type='text' name='call_acl_source' maxlength='255' value=\"".escape($call_acl_source)."\" required='required'>\n";
  219. echo "<br />\n";
  220. echo $text['description-call_acl_source']."\n";
  221. echo "</td>\n";
  222. echo "</tr>\n";
  223. // Show destination
  224. echo "<tr>\n";
  225. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  226. echo " ".$text['label-call_acl_destination']."\n";
  227. echo "</td>\n";
  228. echo "<td class='vtable' align='left'>\n";
  229. echo " <input class='formfld' type='text' name='call_acl_destination' maxlength='255' value=\"".escape($call_acl_destination)."\" required='required'>\n";
  230. echo "<br />\n";
  231. echo $text['description-call_acl_destination']."\n";
  232. echo "</td>\n";
  233. echo "</tr>\n";
  234. // Show action
  235. echo "<tr>\n";
  236. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  237. echo " ".$text['label-call_acl_action']."\n";
  238. echo "</td>\n";
  239. echo "<td class='vtable' align='left'>\n";
  240. echo " <select class='formfld' name='call_acl_action'>\n";
  241. if ($call_acl_action == "reject") {
  242. echo " <option value='allow'>".$text['label-allow']."</option>\n";
  243. echo " <option value='reject' selected='selected'>".$text['label-reject']."</option>\n";
  244. } else {
  245. echo " <option value='allow' selected='selected'>".$text['label-allow']."</option>\n";
  246. echo " <option value='reject'>".$text['label-reject']."</option>\n";
  247. }
  248. echo " </select>\n";
  249. echo "<br />\n";
  250. echo $text['description-call_acl_action']."\n";
  251. echo "\n";
  252. echo "</td>\n";
  253. echo "</tr>\n";
  254. // Show enabled
  255. echo "<tr>\n";
  256. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  257. echo " ".$text['label-call_acl_enabled']."\n";
  258. echo "</td>\n";
  259. echo "<td class='vtable' align='left'>\n";
  260. echo " <select class='formfld' name='call_acl_enabled'>\n";
  261. echo " <option value='true' ".(($call_acl_enabled == "true") ? "selected" : null).">".$text['label-true']."</option>\n";
  262. echo " <option value='false' ".(($call_acl_enabled == "false") ? "selected" : null).">".$text['label-false']."</option>\n";
  263. echo " </select>\n";
  264. echo "<br />\n";
  265. echo $text['description-call_acl_enabled']."\n";
  266. echo "\n";
  267. echo "</td>\n";
  268. echo "</tr>\n";
  269. echo " <tr>\n";
  270. echo " <td colspan='2' align='right'>\n";
  271. if ($action == "update") {
  272. echo " <input type='hidden' name='id' value='".escape($call_acl_uuid)."'>\n";
  273. }
  274. echo " <br>";
  275. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  276. echo " </td>\n";
  277. echo " </tr>";
  278. echo "</table>";
  279. echo "<br><br>";
  280. echo "</form>";
  281. echo "<table>";
  282. echo "<tr>";
  283. echo "<td>";
  284. echo $text['description-call_acl_templates'];
  285. echo "</td>";
  286. echo "</tr>";
  287. echo "</table>";
  288. //include the footer
  289. require_once "resources/footer.php";
  290. ?>