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.

251 lines
9.0 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-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <markjcrane@fusionpbx.com>
  20. */
  21. //includes
  22. include "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (permission_exists('call_active_view')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //add multi-lingual support
  34. $language = new text;
  35. $text = $language->get();
  36. //get the HTTP values and set as variables
  37. $show = trim($_REQUEST["show"]);
  38. if ($show != "all") { $show = ''; }
  39. //include theme config for button images
  40. include_once("themes/".$_SESSION['domain']['template']['name']."/config.php");
  41. //set the command
  42. $switch_cmd = 'show channels as json';
  43. //create the event socket connection
  44. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  45. //send the event socket command and get the array
  46. if ($fp) {
  47. $json = trim(event_socket_request($fp, 'api '.$switch_cmd));
  48. $results = json_decode($json, "true");
  49. }
  50. //build a new array with domain_name
  51. $rows = array();
  52. if (isset($results["rows"])) {
  53. foreach ($results["rows"] as &$row) {
  54. //get the domain
  55. if (strlen($row['context']) > 0 && $row['context'] != "public" && $row['context'] != "default") {
  56. if (substr_count($row['context'], '@') > 0) {
  57. $context_array = explode('@', $row['context']);
  58. $row['domain_name'] = $context_array[1];
  59. }
  60. else {
  61. $row['domain_name'] = $row['context'];
  62. }
  63. }
  64. else if (substr_count($row['presence_id'], '@') > 0) {
  65. $presence_id_array = explode('@', $row['presence_id']);
  66. $row['domain_name'] = $presence_id_array[1];
  67. }
  68. //add the row to the array
  69. if (($show == 'all' && permission_exists('call_active_all'))) {
  70. $rows[] = $row;
  71. }
  72. else {
  73. if ($row['domain_name'] == $_SESSION['domain_name']) {
  74. $rows[] = $row;
  75. }
  76. }
  77. }
  78. unset($results);
  79. }
  80. $num_rows = @sizeof($rows);
  81. //if the connnection is available then run it and return the results
  82. if (!$fp) {
  83. $msg = "<div align='center'>".$text['confirm-socket']."<br /></div>";
  84. echo "<div align='center'>\n";
  85. echo "<table width='40%'>\n";
  86. echo "<tr>\n";
  87. echo "<th align='left'>".$text['label-message']."</th>\n";
  88. echo "</tr>\n";
  89. echo "<tr>\n";
  90. echo "<td class='row_style1'><strong>$msg</strong></td>\n";
  91. echo "</tr>\n";
  92. echo "</table>\n";
  93. echo "</div>\n";
  94. }
  95. else {
  96. //create token
  97. $object = new token;
  98. $token = $object->create('/app/calls_active/calls_active_inc.php');
  99. //show content
  100. echo "<div class='action_bar' id='action_bar'>\n";
  101. echo " <div class='heading'><b>".$text['title']." (".$num_rows.")</b></div>\n";
  102. echo " <div class='actions'>\n";
  103. echo " <span id='refresh_state'>".button::create(['type'=>'button','title'=>$text['label-refresh_pause'],'icon'=>'sync-alt fa-spin','onclick'=>'refresh_stop()'])."</span>";
  104. if (permission_exists('call_active_hangup') && $rows) {
  105. echo button::create(['type'=>'button','label'=>$text['label-hangup'],'icon'=>'phone-slash','id'=>'btn_delete','onclick'=>"refresh_stop(); modal_open('modal-hangup','btn_hangup');"]);
  106. }
  107. if (permission_exists('call_active_all')) {
  108. if ($show == "all") {
  109. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'link'=>'calls_active.php','onmouseover'=>'refresh_stop()','onmouseout'=>'refresh_start()']);
  110. }
  111. else {
  112. echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'calls_active.php?show=all','onmouseover'=>'refresh_stop()','onmouseout'=>'refresh_start()']);
  113. }
  114. }
  115. echo " </div>\n";
  116. echo " <div style='clear: both;'></div>\n";
  117. echo "</div>\n";
  118. if (permission_exists('call_active_hangup') && $rows) {
  119. echo modal::create(['id'=>'modal-hangup','type'=>'general','message'=>$text['confirm-hangups'],'actions'=>button::create(['type'=>'button','label'=>$text['label-hangup'],'icon'=>'check','id'=>'btn_hangup','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('hangup'); list_form_submit('form_list');"])]);
  120. }
  121. echo $text['description']."\n";
  122. echo "<br /><br />\n";
  123. //show the results
  124. echo "<div id='cmd_reponse'></div>\n";
  125. echo "<form id='form_list' method='post' action='calls_exec.php'>\n";
  126. echo "<input type='hidden' id='action' name='action' value=''>\n";
  127. echo "<table class='list'>\n";
  128. echo "<tr class='list-header'>\n";
  129. if (permission_exists('call_active_hangup')) {
  130. echo " <th class='checkbox'>\n";
  131. echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='if (this.checked) { refresh_stop(); } else { refresh_start(); } list_all_toggle();' ".($rows ?: "style='visibility: hidden;'").">\n";
  132. echo " </th>\n";
  133. }
  134. echo " <th>".$text['label-profile']."</th>\n";
  135. echo " <th>".$text['label-created']."</th>\n";
  136. if ($show == 'all') {
  137. echo " <th>".$text['label-domain']."</th>\n";
  138. }
  139. echo " <th>".$text['label-number']."</th>\n";
  140. echo " <th>".$text['label-cid-name']."</th>\n";
  141. echo " <th>".$text['label-cid-number']."</th>\n";
  142. echo " <th>".$text['label-destination']."</th>\n";
  143. echo " <th>".$text['label-app']."</th>\n";
  144. echo " <th>".$text['label-codec']."</th>\n";
  145. echo " <th>".$text['label-secure']."</th>\n";
  146. if (permission_exists('call_active_hangup')) {
  147. echo " <td class='action-button'>&nbsp;</td>\n";
  148. }
  149. echo "</tr>\n";
  150. if (is_array($rows)) {
  151. $x = 0;
  152. foreach ($rows as &$row) {
  153. //set the php variables
  154. foreach ($row as $key => $value) {
  155. $$key = $value;
  156. }
  157. //get the sip profile
  158. $name_array = explode("/", $name);
  159. $sip_profile = $name_array[1];
  160. $sip_uri = $name_array[2];
  161. //get the number
  162. $temp_array = explode("@", $sip_uri);
  163. $tmp_number = $temp_array[0];
  164. $tmp_number = str_replace("sip:", "", $tmp_number);
  165. //remove the '+' because it breaks the call recording
  166. $cid_num = str_replace("+", "", $cid_num);
  167. //replace gateway uuid with name
  168. if (is_array($_SESSION['gateways']) && sizeof($_SESSION['gateways']) > 0) {
  169. foreach ($_SESSION['gateways'] as $gateway_uuid => $gateway_name) {
  170. $application_data = str_replace($gateway_uuid, $gateway_name, $application_data);
  171. }
  172. }
  173. // reduce too long app data
  174. if(strlen($application_data) > 512) {
  175. $application_data = substr($application_data, 0, 512) . '...';
  176. }
  177. //send the html
  178. echo "<tr class='list-row'>\n";
  179. if (permission_exists('call_active_hangup')) {
  180. echo " <td class='checkbox'>\n";
  181. echo " <input type='checkbox' name='calls[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (this.checked) { refresh_stop(); } else { document.getElementById('checkbox_all').checked = false; }\">\n";
  182. echo " <input type='hidden' name='calls[$x][uuid]' value='".escape($uuid)."' />\n";
  183. echo " </td>\n";
  184. }
  185. echo " <td>".escape($sip_profile)."&nbsp;</td>\n";
  186. echo " <td>".escape($created)."&nbsp;</td>\n";
  187. if ($show == 'all') {
  188. echo " <td>".escape($domain_name)."&nbsp;</td>\n";
  189. }
  190. echo " <td>".escape($tmp_number)."&nbsp;</td>\n";
  191. echo " <td>".escape($cid_name)."&nbsp;</td>\n";
  192. echo " <td>".escape($cid_num)."&nbsp;</td>\n";
  193. echo " <td>".escape($dest)."&nbsp;</td>\n";
  194. echo " <td>".(strlen($application) > 0 ? escape($application).":".escape($application_data) : null)."&nbsp;</td>\n";
  195. echo " <td>".escape($read_codec).":".escape($read_rate)." / ".escape($write_codec).":".escape($write_rate)."&nbsp;</td>\n";
  196. echo " <td>".escape($secure)."&nbsp;</td>\n";
  197. if (permission_exists('call_active_hangup')) {
  198. echo " <td class='action-button'>";
  199. echo button::create(['type'=>'button','title'=>$text['label-hangup'],'icon'=>'phone-slash','onclick'=>"if (confirm('".$text['confirm-hangup']."')) { list_self_check('checkbox_".$x."'); list_action_set('hangup'); list_form_submit('form_list'); } else { this.blur(); return false; }",'onmouseover'=>'refresh_stop()','onmouseout'=>'refresh_start()']);
  200. echo " </td>\n";
  201. }
  202. echo "</tr>\n";
  203. //increment counter
  204. $x++;
  205. }
  206. unset($rows);
  207. }
  208. echo "</table>\n";
  209. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  210. echo "</form>\n";
  211. }
  212. ?>