From 1cca98951d6768d5ee7456c889bb8a87973ebd09 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Wed, 27 Jul 2016 22:03:59 -0700 Subject: [PATCH] Fix my PR for the device registered on extensions page. (#1772) * Fix my PR for the device registered on extensions page. * Change to registered --- app/extensions/app_config.php | 3 + app/extensions/app_languages.php | 13 ++++ app/extensions/extensions.php | 37 ++++++++++ .../classes/status_registrations.php | 72 +++++++++++++++++++ .../status_registrations_inc.php | 49 +------------ 5 files changed, 127 insertions(+), 47 deletions(-) create mode 100644 app/registrations/resources/classes/status_registrations.php diff --git a/app/extensions/app_config.php b/app/extensions/app_config.php index 7573b1e757..87f7a980f2 100644 --- a/app/extensions/app_config.php +++ b/app/extensions/app_config.php @@ -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 diff --git a/app/extensions/app_languages.php b/app/extensions/app_languages.php index 5474833890..8e9fd9f063 100644 --- a/app/extensions/app_languages.php +++ b/app/extensions/app_languages.php @@ -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"; diff --git a/app/extensions/extensions.php b/app/extensions/extensions.php index f8ef4f8da7..13d63a6114 100644 --- a/app/extensions/extensions.php +++ b/app/extensions/extensions.php @@ -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 = "
".$text['error-event-socket']."
"; + } + $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 "\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 " ".$row['user_context']."\n"; echo " ".ucwords($row['enabled'])."\n"; echo " ".$row['description']." \n"; + if (permission_exists('extension_show_registered')) { + echo " "; + $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 " \n"; + } + echo " "; if (permission_exists('extension_edit')) { echo "$v_link_label_edit"; diff --git a/app/registrations/resources/classes/status_registrations.php b/app/registrations/resources/classes/status_registrations.php new file mode 100644 index 0000000000..7ddc98ac4e --- /dev/null +++ b/app/registrations/resources/classes/status_registrations.php @@ -0,0 +1,72 @@ +".$text['label-message'].""; } + $xml_response = str_replace("", "", $xml_response); + $xml_response = str_replace("", "", $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'} ?: " "; + $user_array = explode('@', $row->{'user'}); + $registrations[$x]['call-id'] = $row->{'call-id'} ?: " "; + $registrations[$x]['contact'] = $row->{'contact'} ?: " "; + $registrations[$x]['sip-auth-user'] = $row->{'sip-auth-user'} ?: " "; + $registrations[$x]['agent'] = $row->{'agent'} ?: " "; + $registrations[$x]['host'] = $row->{'host'} ?: " "; + $registrations[$x]['network-port'] = $row->{'network-port'} ?: " "; + $registrations[$x]['sip-auth-realm'] = $row->{'sip-auth-realm'} ?: " "; + $registrations[$x]['mwi-account'] = $row->{'mwi-account'} ?: " "; + $registrations[$x]['status'] = $row->{'status'} ?: " "; + $registrations[$x]['ping-time'] = $row->{'ping-time'} ?: " "; + + //get network-ip to url or blank + if(isset($row->{'network-ip'})) { + $registrations[$x]['network-ip'] = "".$row->{'network-ip'}.""; + }else{ + $registrations[$x]['network-ip'] = " "; + } + //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'] = "".$call_id_array[1].""; + }else{ + $registrations[$x]['lan-ip'] = " "; + } + //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; +} + +?> \ No newline at end of file diff --git a/app/registrations/status_registrations_inc.php b/app/registrations/status_registrations_inc.php index 25bb78210d..ae644e1287 100644 --- a/app/registrations/status_registrations_inc.php +++ b/app/registrations/status_registrations_inc.php @@ -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'} ?: " "; - $user_array = explode('@', $row->{'user'}); - $registrations[$x]['call-id'] = $row->{'call-id'} ?: " "; - $registrations[$x]['contact'] = $row->{'contact'} ?: " "; - $registrations[$x]['sip-auth-user'] = $row->{'sip-auth-user'} ?: " "; - $registrations[$x]['agent'] = $row->{'agent'} ?: " "; - $registrations[$x]['host'] = $row->{'host'} ?: " "; - $registrations[$x]['network-port'] = $row->{'network-port'} ?: " "; - $registrations[$x]['sip-auth-realm'] = $row->{'sip-auth-realm'} ?: " "; - $registrations[$x]['mwi-account'] = $row->{'mwi-account'} ?: " "; - $registrations[$x]['status'] = $row->{'status'} ?: " "; - $registrations[$x]['ping-time'] = $row->{'ping-time'} ?: " "; - - //get network-ip to url or blank - if(isset($row->{'network-ip'})) { - $registrations[$x]['network-ip'] = "".$row->{'network-ip'}.""; - }else{ - $registrations[$x]['network-ip'] = " "; - } - //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'] = "".$call_id_array[1].""; - }else{ - $registrations[$x]['lan-ip'] = " "; - } - //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 "\n";