Fix my PR for the device registered on extensions page. (#1772)

* Fix my PR for the device registered on extensions page.

* Change to registered
This commit is contained in:
Chris Black
2016-07-27 22:03:59 -07:00
committed by FusionPBX
parent e408cc33bf
commit 1cca98951d
5 changed files with 127 additions and 47 deletions

View File

@@ -130,6 +130,9 @@
$apps[$x]['permissions'][$y]['name'] = "extension_absolute_codec_string";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "extension_show_registered";
$y++;
//schema details
$y = 0; //table array index

View File

@@ -910,6 +910,19 @@ $text['label-accountcode']['ro'] = "Cod cont";
$text['label-accountcode']['ar-eg'] = "";
$text['label-accountcode']['he'] = "קוד חשבון";
$text['label-is_registered']['en-us'] = "Registered";
$text['label-is_registered']['es-cl'] = "";
$text['label-is_registered']['pt-pt'] = "";
$text['label-is_registered']['fr-fr'] = "";
$text['label-is_registered']['pt-br'] = "";
$text['label-is_registered']['pl'] = "";
$text['label-is_registered']['uk'] = "";
$text['label-is_registered']['sv-se'] = "";
$text['label-is_registered']['de-at'] = "";
$text['label-is_registered']['ro'] = "";
$text['label-is_registered']['ar-eg'] = "";
$text['label-is_registered']['he'] = "";
$text['header-extensions']['en-us'] = "Extensions";
$text['header-extensions']['es-cl'] = "Extensiones";
$text['header-extensions']['pt-pt'] = "Extensões";

View File

@@ -26,6 +26,8 @@
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/registrations/resources/classes/status_registrations.php";
if (permission_exists('extension_view')) {
//access granted
}
@@ -34,6 +36,20 @@ else {
exit;
}
if (permission_exists('extension_show_registered')) {
//create the event socket connection
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if (!$fp) {
$msg = "<div align='center'>".$text['error-event-socket']."<br /></div>";
}
$registrations = get_registrations('internal');
//order the array
require_once "resources/classes/array_order.php";
$order = new array_order();
$registrations = $order->sort($registrations, 'sip-auth-realm', 'user');
}
//add multi-lingual support
$language = new text;
$text = $language->get();
@@ -150,6 +166,9 @@ require_once "resources/paging.php";
echo th_order_by('user_context', $text['label-user_context'], $order_by, $order);
echo th_order_by('enabled', $text['label-enabled'], $order_by, $order);
echo th_order_by('description', $text['label-description'], $order_by, $order);
if (permission_exists('extension_show_registered')) {
echo th_order_by('description', $text['label-is_registered'], $order_by, $order);
}
echo "<td class='list_control_icon'>\n";
if (permission_exists('extension_add')) {
if ($_SESSION['limit']['extensions']['numeric'] == '' || ($_SESSION['limit']['extensions']['numeric'] != '' && $total_extensions < $_SESSION['limit']['extensions']['numeric'])) {
@@ -186,6 +205,24 @@ require_once "resources/paging.php";
echo " <td valign='top' class='".$row_style[$c]."'>".$row['user_context']."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".ucwords($row['enabled'])."</td>\n";
echo " <td valign='top' class='row_stylebg' width='30%'>".$row['description']."&nbsp;</td>\n";
if (permission_exists('extension_show_registered')) {
echo " <td valign='top' class='".$row_style[$c]."'>";
$found = false;
$found_count = 0;
foreach ($registrations as $arr) {
if (in_array($row['extension'],$arr)) {
$found = true;
$found_count++;
}
}
if ($found) {
echo "Yes ($found_count)";
} else {
echo "No";
}
echo "&nbsp;</td>\n";
}
echo " <td class='list_control_icons'>";
if (permission_exists('extension_edit')) {
echo "<a href='extension_edit.php?id=".$row['extension_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";

View File

@@ -0,0 +1,72 @@
<?php
function get_registrations($sip_profile_name) {
global $_SESSION, $fp;
//get sofia status profile information including registrations
$cmd = "api sofia xmlstatus profile ".$sip_profile_name." reg";
$xml_response = trim(event_socket_request($fp, $cmd));
if ($xml_response == "Invalid Profile!") { $xml_response = "<error_msg>".$text['label-message']."</error_msg>"; }
$xml_response = str_replace("<profile-info>", "<profile_info>", $xml_response);
$xml_response = str_replace("</profile-info>", "</profile_info>", $xml_response);
try {
$xml = new SimpleXMLElement($xml_response);
}
catch(Exception $e) {
echo $e->getMessage();
exit;
}
//build the registration array
if (count($xml->registrations->registration) > 0) {
$registrations = '';
$x = 0;
foreach ($xml->registrations->registration as $row) {
//get the values from xml and set them to the channel array
$registrations[$x]['user'] = $row->{'user'} ?: "&nbsp;";
$user_array = explode('@', $row->{'user'});
$registrations[$x]['call-id'] = $row->{'call-id'} ?: "&nbsp;";
$registrations[$x]['contact'] = $row->{'contact'} ?: "&nbsp;";
$registrations[$x]['sip-auth-user'] = $row->{'sip-auth-user'} ?: "&nbsp;";
$registrations[$x]['agent'] = $row->{'agent'} ?: "&nbsp;";
$registrations[$x]['host'] = $row->{'host'} ?: "&nbsp;";
$registrations[$x]['network-port'] = $row->{'network-port'} ?: "&nbsp;";
$registrations[$x]['sip-auth-realm'] = $row->{'sip-auth-realm'} ?: "&nbsp;";
$registrations[$x]['mwi-account'] = $row->{'mwi-account'} ?: "&nbsp;";
$registrations[$x]['status'] = $row->{'status'} ?: "&nbsp;";
$registrations[$x]['ping-time'] = $row->{'ping-time'} ?: "&nbsp;";
//get network-ip to url or blank
if(isset($row->{'network-ip'})) {
$registrations[$x]['network-ip'] = "<a href='http://".$row->{'network-ip'}."' target='_blank'>".$row->{'network-ip'}."</a>";
}else{
$registrations[$x]['network-ip'] = "&nbsp;";
}
//get the LAN IP address if it exists replace the external ip
$call_id_array = explode('@', $row->{'call-id'});
if (isset($call_id_array[1])) {
$registrations[$x]['lan-ip'] = "<a href='http://".$call_id_array[1]."' target='_blank'>".$call_id_array[1]."</a>";
}else{
$registrations[$x]['lan-ip'] = "&nbsp;";
}
//remove unrelated domains
if (count($_SESSION["domains"]) > 1) {
if (!(permission_exists('registration_all') && $show == "all")) {
if ($registrations[$x]['sip-auth-realm'] == $_SESSION['domain_name']) {}
elseif ($user_array[1] == $_SESSION['domain_name']){}
else {
unset($registrations[$x]);
}
}
}
//increment the array id
$x++;
}
}
return $registrations;
}
?>

View File

@@ -27,6 +27,7 @@
include "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/classes/status_registrations.php";
//check permissions
if (permission_exists("registration_domain") || permission_exists("registration_all") || if_group("superadmin")) {
@@ -88,53 +89,7 @@ require_once "resources/check_auth.php";
exit;
}
//build the registration array
if (count($xml->registrations->registration) > 0) {
$registrations = '';
$x = 0;
foreach ($xml->registrations->registration as $row) {
//get the values from xml and set them to the channel array
$registrations[$x]['user'] = $row->{'user'} ?: "&nbsp;";
$user_array = explode('@', $row->{'user'});
$registrations[$x]['call-id'] = $row->{'call-id'} ?: "&nbsp;";
$registrations[$x]['contact'] = $row->{'contact'} ?: "&nbsp;";
$registrations[$x]['sip-auth-user'] = $row->{'sip-auth-user'} ?: "&nbsp;";
$registrations[$x]['agent'] = $row->{'agent'} ?: "&nbsp;";
$registrations[$x]['host'] = $row->{'host'} ?: "&nbsp;";
$registrations[$x]['network-port'] = $row->{'network-port'} ?: "&nbsp;";
$registrations[$x]['sip-auth-realm'] = $row->{'sip-auth-realm'} ?: "&nbsp;";
$registrations[$x]['mwi-account'] = $row->{'mwi-account'} ?: "&nbsp;";
$registrations[$x]['status'] = $row->{'status'} ?: "&nbsp;";
$registrations[$x]['ping-time'] = $row->{'ping-time'} ?: "&nbsp;";
//get network-ip to url or blank
if(isset($row->{'network-ip'})) {
$registrations[$x]['network-ip'] = "<a href='http://".$row->{'network-ip'}."' target='_blank'>".$row->{'network-ip'}."</a>";
}else{
$registrations[$x]['network-ip'] = "&nbsp;";
}
//get the LAN IP address if it exists replace the external ip
$call_id_array = explode('@', $row->{'call-id'});
if (isset($call_id_array[1])) {
$registrations[$x]['lan-ip'] = "<a href='http://".$call_id_array[1]."' target='_blank'>".$call_id_array[1]."</a>";
}else{
$registrations[$x]['lan-ip'] = "&nbsp;";
}
//remove unrelated domains
if (count($_SESSION["domains"]) > 1) {
if (!(permission_exists('registration_all') && $show == "all")) {
if ($registrations[$x]['sip-auth-realm'] == $_SESSION['domain_name']) {}
elseif ($user_array[1] == $_SESSION['domain_name']){}
else {
unset($registrations[$x]);
}
}
}
//increment the array id
$x++;
}
}
$registrations = get_registrations($sip_profile_name);
//show the registrations
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>\n";