Add switch status to the dashboard

This commit is contained in:
markjcrane
2022-03-26 14:25:26 -06:00
parent c81bc8750d
commit 67aad6d611
4 changed files with 357 additions and 0 deletions

33
app/switch/app_config.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
//application details
$apps[$x]['name'] = "Switch";
$apps[$x]['uuid'] = "9cc48cb9-22d3-42eb-8bf8-3ca970e364d7";
$apps[$x]['category'] = "Switch";
$apps[$x]['subcategory'] = "";
$apps[$x]['version'] = "1.0";
$apps[$x]['license'] = "";
$apps[$x]['url'] = "http://www.fusionpbx.com";
$apps[$x]['description']['en-us'] = "Switch details such as version, uptime, channels and registrations.";
$apps[$x]['description']['en-gb'] = "Switch details such as version, uptime, channels and registrations.";
$apps[$x]['description']['ar-eg'] = "";
$apps[$x]['description']['de-at'] = "";
$apps[$x]['description']['de-ch'] = "";
$apps[$x]['description']['de-de'] = "";
$apps[$x]['description']['es-cl'] = "";
$apps[$x]['description']['es-mx'] = "";
$apps[$x]['description']['fr-ca'] = "";
$apps[$x]['description']['fr-fr'] = "";
$apps[$x]['description']['he-il'] = "";
$apps[$x]['description']['it-it'] = "";
$apps[$x]['description']['nl-nl'] = "";
$apps[$x]['description']['pl-pl'] = "";
$apps[$x]['description']['pt-br'] = "";
$apps[$x]['description']['pt-pt'] = "";
$apps[$x]['description']['ro-ro'] = "";
$apps[$x]['description']['ru-ru'] = "";
$apps[$x]['description']['sv-se'] = "";
$apps[$x]['description']['uk-ua'] = "";
?>

View File

@@ -0,0 +1,135 @@
<?php
$text['label-switch_status']['en-us'] = "Switch Status";
$text['label-switch_status']['en-gb'] = "Switch Status";
$text['label-switch_status']['ar-eg'] = "";
$text['label-switch_status']['de-at'] = "Switch"; //copied from de-de
$text['label-switch_status']['de-ch'] = "Switch"; //copied from de-de
$text['label-switch_status']['de-de'] = "Switch";
$text['label-switch_status']['el-gr'] = "Switch";
$text['label-switch_status']['es-cl'] = "Switch";
$text['label-switch_status']['es-mx'] = "Switch"; //copied from es-cl
$text['label-switch_status']['fr-ca'] = "Switch"; //copied from fr-fr
$text['label-switch_status']['fr-fr'] = "Switch";
$text['label-switch_status']['he-il'] = "";
$text['label-switch_status']['it-it'] = "Switch";
$text['label-switch_status']['nl-nl'] = "";
$text['label-switch_status']['pl-pl'] = "Switch";
$text['label-switch_status']['pt-br'] = "Switch"; //copied from pt-pt
$text['label-switch_status']['pt-pt'] = "Switch";
$text['label-switch_status']['ro-ro'] = "";
$text['label-switch_status']['ru-ru'] = "FreeSwitch";
$text['label-switch_status']['sv-se'] = "Switch";
$text['label-switch_status']['uk-ua'] = "Switch";
$text['label-channels']['en-us'] = "Channels";
$text['label-channels']['en-gb'] = "Channels";
$text['label-channels']['ar-eg'] = "";
$text['label-channels']['de-at'] = "Kanäle"; //copied from de-de
$text['label-channels']['de-ch'] = "Kanäle"; //copied from de-de
$text['label-channels']['de-de'] = "Kanäle";
$text['label-channels']['el-gr'] = "Κανάλια";
$text['label-channels']['es-cl'] = "Canales";
$text['label-channels']['es-mx'] = "Canales"; //copied from es-cl
$text['label-channels']['fr-ca'] = "Canaux"; //copied from fr-fr
$text['label-channels']['fr-fr'] = "Canaux";
$text['label-channels']['he-il'] = "ערוצים";
$text['label-channels']['it-it'] = "Canali";
$text['label-channels']['nl-nl'] = "";
$text['label-channels']['pl-pl'] = "Kanały";
$text['label-channels']['pt-br'] = "Canais"; //copied from pt-pt
$text['label-channels']['pt-pt'] = "Canais";
$text['label-channels']['ro-ro'] = "Canale";
$text['label-channels']['ru-ru'] = "Каналы";
$text['label-channels']['sv-se'] = "Kanaler";
$text['label-channels']['uk-ua'] = "Канали";
$text['label-registrations']['en-us'] = "Registrations";
$text['label-registrations']['en-gb'] = "Registrations";
$text['label-registrations']['ar-eg'] = "";
$text['label-registrations']['de-at'] = "Registrierungen"; //copied from de-de
$text['label-registrations']['de-ch'] = "Registrierungen"; //copied from de-de
$text['label-registrations']['de-de'] = "Registrierungen";
$text['label-registrations']['el-gr'] = "Συνδέσεις";
$text['label-registrations']['es-cl'] = "Inscripciones";
$text['label-registrations']['es-mx'] = "Inscripciones"; //copied from es-cl
$text['label-registrations']['fr-ca'] = "Enregistrements SIP"; //copied from fr-fr
$text['label-registrations']['fr-fr'] = "Enregistrements SIP";
$text['label-registrations']['he-il'] = "";
$text['label-registrations']['it-it'] = "Registrazioni";
$text['label-registrations']['nl-nl'] = "";
$text['label-registrations']['pl-pl'] = "Rejestracje";
$text['label-registrations']['pt-br'] = "Registros";
$text['label-registrations']['pt-pt'] = "Inscrições";
$text['label-registrations']['ro-ro'] = "";
$text['label-registrations']['ru-ru'] = "Регистрации SIP";
$text['label-registrations']['sv-se'] = "Registreringar";
$text['label-registrations']['uk-ua'] = "Реєстрації";
$text['label-switch_uptime']['en-us'] = "Switch Uptime";
$text['label-switch_uptime']['en-gb'] = "Switch Uptime";
$text['label-switch_uptime']['ar-eg'] = "";
$text['label-switch_uptime']['de-at'] = "Switch Uptime"; //copied from de-de
$text['label-switch_uptime']['de-ch'] = "Switch Uptime"; //copied from de-de
$text['label-switch_uptime']['de-de'] = "Switch Uptime";
$text['label-switch_uptime']['el-gr'] = "Switch Uptime";
$text['label-switch_uptime']['es-cl'] = "Tiempo de actividad Switch";
$text['label-switch_uptime']['es-mx'] = "Tiempo de actividad Switch"; //copied from es-cl
$text['label-switch_uptime']['fr-ca'] = "Switch Uptime"; //copied from fr-fr
$text['label-switch_uptime']['fr-fr'] = "Switch Uptime";
$text['label-switch_uptime']['he-il'] = "";
$text['label-switch_uptime']['it-it'] = "Tempo di attività Switch";
$text['label-switch_uptime']['nl-nl'] = "";
$text['label-switch_uptime']['pl-pl'] = "Switch Uptime";
$text['label-switch_uptime']['pt-br'] = "Tempo de atividade do switch";
$text['label-switch_uptime']['pt-pt'] = "Uptime Switch";
$text['label-switch_uptime']['ro-ro'] = "";
$text['label-switch_uptime']['ru-ru'] = "Время непрерывной работы FreeSwitch";
$text['label-switch_uptime']['sv-se'] = "Switch Uptime";
$text['label-switch_uptime']['uk-ua'] = "Switch Uptime";
$text['label-switch']['en-us'] = "Switch";
$text['label-switch']['en-gb'] = "Switch";
$text['label-switch']['ar-eg'] = "";
$text['label-switch']['de-at'] = "Switch"; //copied from de-de
$text['label-switch']['de-ch'] = "Switch"; //copied from de-de
$text['label-switch']['de-de'] = "Switch";
$text['label-switch']['el-gr'] = "Switch";
$text['label-switch']['es-cl'] = "Switch";
$text['label-switch']['es-mx'] = "Switch"; //copied from es-cl
$text['label-switch']['fr-ca'] = "Switch"; //copied from fr-fr
$text['label-switch']['fr-fr'] = "Switch";
$text['label-switch']['he-il'] = "";
$text['label-switch']['it-it'] = "Switch";
$text['label-switch']['nl-nl'] = "";
$text['label-switch']['pl-pl'] = "Switch";
$text['label-switch']['pt-br'] = "Switch"; //copied from pt-pt
$text['label-switch']['pt-pt'] = "Switch";
$text['label-switch']['ro-ro'] = "";
$text['label-switch']['ru-ru'] = "FreeSwitch";
$text['label-switch']['sv-se'] = "Switch";
$text['label-switch']['uk-ua'] = "Switch";
$text['label-switch']['en-us'] = "Switch";
$text['label-switch']['en-gb'] = "Switch";
$text['label-switch']['ar-eg'] = "";
$text['label-switch']['de-at'] = "Switch"; //copied from de-de
$text['label-switch']['de-ch'] = "Switch"; //copied from de-de
$text['label-switch']['de-de'] = "Switch";
$text['label-switch']['el-gr'] = "Switch";
$text['label-switch']['es-cl'] = "Switch";
$text['label-switch']['es-mx'] = "Switch"; //copied from es-cl
$text['label-switch']['fr-ca'] = "Switch"; //copied from fr-fr
$text['label-switch']['fr-fr'] = "Switch";
$text['label-switch']['he-il'] = "";
$text['label-switch']['it-it'] = "Switch";
$text['label-switch']['nl-nl'] = "";
$text['label-switch']['pl-pl'] = "Switch";
$text['label-switch']['pt-br'] = "Switch"; //copied from pt-pt
$text['label-switch']['pt-pt'] = "Switch";
$text['label-switch']['ro-ro'] = "";
$text['label-switch']['ru-ru'] = "FreeSwitch";
$text['label-switch']['sv-se'] = "Switch";
$text['label-switch']['uk-ua'] = "Switch";
?>

View File

@@ -0,0 +1,16 @@
<?php
$x++;
$array['dashboard'][$x]['dashboard_uuid'] = 'b9d92260-eaf7-4c05-a51e-3083e25516b3';
$array['dashboard'][$x]['dashboard_name'] = 'Switch Status';
$array['dashboard'][$x]['dashboard_path'] = 'app/switch/resources/dashboard/switch_status.php';
$array['dashboard'][$x]['dashboard_order'] = '105';
$array['dashboard'][$x]['dashboard_enabled'] = 'false';
$array['dashboard'][$x]['dashboard_description'] = 'Switch details such as version, uptime, channels and registrations.';
$y = 0;
$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_group_uuid'] = '5469c403-2cc5-4340-99f8-6f0755407de7';
$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_uuid'] = 'b9d92260-eaf7-4c05-a51e-3083e25516b3';
$array['dashboard'][$x]['dashboard_groups'][$y]['group_name'] = 'superadmin';
$x++;
?>

View File

@@ -0,0 +1,173 @@
<?php
//includes
require_once "root.php";
require_once "resources/require.php";
//check permisions
require_once "resources/check_auth.php";
if (permission_exists("registration_all") || if_group("superadmin")) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get($_SESSION['domain']['language']['code'], 'app/switch');
//switch status
echo "<div class='hud_box'>\n";
//set the row style class names
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//connect to event socket
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
//switch version
if ($fp) {
$switch_version = event_socket_request($fp, 'api version');
preg_match("/FreeSWITCH Version (\d+\.\d+\.\d+(?:\.\d+)?).*\(.*?(\d+\w+)\s*\)/", $switch_version, $matches);
$switch_version = $matches[1];
$switch_bits = $matches[2];
}
//switch uptime
if ($fp) {
$tmp = event_socket_request($fp, 'api status');
$tmp = explode("\n", $tmp);
$tmp = $tmp[0];
$tmp = explode(' ', $tmp);
$uptime = (($tmp[1]) ? $tmp[1].'y ' : null);
$uptime .= (($tmp[3]) ? $tmp[3].'d ' : null);
$uptime .= (($tmp[5]) ? $tmp[5].'h ' : null);
$uptime .= (($tmp[7]) ? $tmp[7].'m ' : null);
$uptime .= (($tmp[9]) ? $tmp[9].'s' : null);
if (permission_exists('system_status_sofia_status') || permission_exists('system_status_sofia_status_profile') || if_group("superadmin")) {
$tr_link_sip_status = "href='".PROJECT_PATH."/app/sip_status/sip_status.php'";
}
}
//channel count
if ($fp) {
$tmp = event_socket_request($fp, 'api status');
$matches = Array();
preg_match("/(\d+)\s+session\(s\)\s+\-\speak/", $tmp, $matches);
$channels = $matches[1] ? $matches[1] : 0;
if (permission_exists('call_active_view')) {
$tr_link_channels = "href='".PROJECT_PATH."/app/calls_active/calls_active.php'";
}
}
//registration count
if ($fp && file_exists($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/app/registrations/")) {
$registration = new registrations;
$registrations = $registration->count();
if (permission_exists("registration_all") || if_group("superadmin")) {
$tr_link_registrations = "href='".PROJECT_PATH."/app/registrations/registrations.php'";
}
}
//add doughnut chart
?>
<div style='display: flex; flex-wrap: wrap; justify-content: center; padding-bottom: 20px;'>
<div style='width: 175px; height: 175px;'><canvas id='switch_status_chart'></canvas></div>
</div>
<script>
var switch_status_chart_context = document.getElementById('switch_status_chart').getContext('2d');
const switch_status_chart_data = {
datasets: [{
data: ['<?php echo $registrations; ?>', 0.00001],
backgroundColor: ['<?php echo $_SESSION['dashboard']['switch_status_chart_main_background_color']['text']; ?>',
'<?php echo $_SESSION['dashboard']['missed_calls_chart_sub_background_color']['text']; ?>'],
borderColor: '<?php echo $_SESSION['dashboard']['switch_status_chart_border_color']['text']; ?>',
borderWidth: '<?php echo $_SESSION['dashboard']['switch_status_chart_border_width']['text']; ?>',
cutout: chart_cutout
}]
};
const switch_status_chart_config = {
type: 'doughnut',
data: switch_status_chart_data,
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
chart_counter: {
chart_text: '<?php echo $registrations; ?>'
},
legend: {
display: false
},
title: {
display: true,
text: '<?php echo $text['label-switch_status']; ?>'
}
}
},
plugins: [chart_counter],
};
const switch_status_chart = new Chart(
switch_status_chart_context,
switch_status_chart_config
);
</script>
<?php
//show the content
echo "<div class='hud_details hud_box' id='hud_switch_status_details'>";
echo "<table class='tr_hover' width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
echo "<tr>\n";
echo "<th class='hud_heading' width='50%'>".$text['label-name']."</th>\n";
echo "<th class='hud_heading' style='text-align: right;'>".$text['label-value']."</th>\n";
echo "</tr>\n";
//switch version
if ($switch_version != '') {
echo "<tr class='tr_link' ".$tr_link_sip_status.">\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-switch']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'><a ".$tr_link_sip_status.">".$switch_version." (".$switch_bits.")</a></td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
//switch uptime
if ($uptime != '') {
echo "<tr class='tr_link' ".$tr_link_sip_status.">\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-switch_uptime']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'><a ".$tr_link_sip_status.">".$uptime."</a></td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
}
//switch channels
echo "<tr class='tr_link' ".$tr_link_channels.">\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-channels']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'><a ".$tr_link_channels.">".$channels."</a></td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
//switch registrations
echo "<tr class='tr_link' ".$tr_link_registrations.">\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text'>".$text['label-registrations']."</td>\n";
echo "<td valign='top' class='".$row_style[$c]." hud_text' style='text-align: right;'><a ".$tr_link_registrations.">".$registrations."</a></td>\n";
echo "</tr>\n";
$c = ($c) ? 0 : 1;
echo "</table>\n";
echo "</div>";
$n++;
echo "<span class='hud_expander' onclick=\"$('#hud_switch_status_details').slideToggle('fast');\"><span class='fas fa-ellipsis-h'></span></span>";
echo "</div>\n";
?>