From 96da9967e0de25e9f9cd075cb5b3c664f010cf4c Mon Sep 17 00:00:00 2001 From: frytimo Date: Tue, 28 Jan 2025 13:20:36 -0400 Subject: [PATCH] create system services dashboard item (#7231) * create system services dashboard item * update internationalization language file used in system_services --- app/system/app_languages.php | 106 +++++++++++ app/system/resources/dashboard/config.php | 17 +- .../resources/dashboard/system_services.php | 175 ++++++++++++++++++ 3 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 app/system/resources/dashboard/system_services.php diff --git a/app/system/app_languages.php b/app/system/app_languages.php index 0a9e7eecb2..b74ceafb36 100644 --- a/app/system/app_languages.php +++ b/app/system/app_languages.php @@ -243,6 +243,112 @@ $text['message-unavailable']['zh-cn'] = "不可用"; $text['message-unavailable']['ja-jp'] = "利用不可"; $text['message-unavailable']['ko-kr'] = "없는"; +$text['label-service']['en-us'] = 'Service'; +$text['label-service']['en-gb'] = 'Service'; +$text['label-service']['ar-eg'] = 'خدمة'; +$text['label-service']['de-at'] = 'Service'; +$text['label-service']['de-ch'] = 'Service'; +$text['label-service']['de-de'] = 'Service'; +$text['label-service']['el-gr'] = 'Υπηρεσία'; +$text['label-service']['es-cl'] = 'Servicio'; +$text['label-service']['es-mx'] = 'Servicio'; +$text['label-service']['fr-ca'] = 'Service'; +$text['label-service']['fr-fr'] = 'Service'; +$text['label-service']['he-il'] = 'שֵׁרוּת'; +$text['label-service']['it-it'] = 'Servizio'; +$text['label-service']['ka-ge'] = 'სერვისი'; +$text['label-service']['nl-nl'] = 'Dienst'; +$text['label-service']['pl-pl'] = 'Praca'; +$text['label-service']['pt-br'] = 'Serviço'; +$text['label-service']['pt-pt'] = 'Serviço'; +$text['label-service']['ro-ro'] = 'Serviciu'; +$text['label-service']['ru-ru'] = 'Услуга'; +$text['label-service']['sv-se'] = 'Service'; +$text['label-service']['uk-ua'] = 'Сервіс'; +$text['label-service']['tr-tr'] = 'Hizmet'; +$text['label-service']['zh-cn'] = '服务'; +$text['label-service']['ja-jp'] = 'サービス'; +$text['label-service']['ko-kr'] = '서비스'; + +$text['label-running']['en-us'] = "Running"; +$text['label-running']['en-gb'] = "Running"; +$text['label-running']['ar-eg'] = "فعال"; +$text['label-running']['de-at'] = "Aktiv"; +$text['label-running']['de-ch'] = "Aktiv"; +$text['label-running']['de-de'] = "Aktiv"; +$text['label-running']['el-gr'] = "Τρέξιμο"; +$text['label-running']['es-cl'] = "Corriendo"; +$text['label-running']['es-mx'] = "Corriendo"; +$text['label-running']['fr-ca'] = "Actif"; +$text['label-running']['fr-fr'] = "Actif"; +$text['label-running']['he-il'] = "ריצה"; +$text['label-running']['it-it'] = "Attivo"; +$text['label-running']['ka-ge'] = "გაშვებულია"; +$text['label-running']['nl-nl'] = "Aktief"; +$text['label-running']['pl-pl'] = "Uruchomiony"; +$text['label-running']['pt-br'] = "Em execução"; +$text['label-running']['pt-pt'] = "Em execução"; +$text['label-running']['ro-ro'] = "Alergare"; +$text['label-running']['ru-ru'] = "Запущено"; +$text['label-running']['sv-se'] = "Löpning"; +$text['label-running']['uk-ua'] = "Запущено"; +$text['label-running']['tr-tr'] = "Koşma"; +$text['label-running']['zh-cn'] = "跑步"; +$text['label-running']['ja-jp'] = "ランニング"; +$text['label-running']['ko-kr'] = "달리기"; + +$text['label-yes']['en-us'] = "Yes"; +$text['label-yes']['en-gb'] = "Yes"; +$text['label-yes']['ar-eg'] = "نعم"; +$text['label-yes']['de-at'] = "Ja"; +$text['label-yes']['de-ch'] = "Ja"; +$text['label-yes']['de-de'] = "Ja"; +$text['label-yes']['el-gr'] = "Ναί"; +$text['label-yes']['es-cl'] = "Si"; +$text['label-yes']['es-mx'] = "Si"; +$text['label-yes']['fr-ca'] = "Oui"; +$text['label-yes']['fr-fr'] = "Oui"; +$text['label-yes']['he-il'] = "כן"; +$text['label-yes']['it-it'] = "Si"; +$text['label-yes']['nl-nl'] = "Ja"; +$text['label-yes']['pl-pl'] = "Tak"; +$text['label-yes']['pt-br'] = "Sim"; +$text['label-yes']['pt-pt'] = "Sim"; +$text['label-yes']['ro-ro'] = "da"; +$text['label-yes']['ru-ru'] = "Да"; +$text['label-yes']['sv-se'] = "Ja"; +$text['label-yes']['uk-ua'] = "Так"; +$text['label-yes']['tr-tr'] = "Evet"; +$text['label-yes']['zh-cn'] = "是的"; +$text['label-yes']['ja-jp'] = "はい"; +$text['label-yes']['ko-kr'] = "예"; + +$text['label-no']['en-us'] = "No"; +$text['label-no']['en-gb'] = "No"; +$text['label-no']['ar-eg'] = "لا"; +$text['label-no']['de-at'] = "Nein"; +$text['label-no']['de-ch'] = "Nein"; +$text['label-no']['de-de'] = "Nein"; +$text['label-no']['el-gr'] = "Οχι"; +$text['label-no']['es-cl'] = "No"; +$text['label-no']['es-mx'] = "No"; +$text['label-no']['fr-ca'] = "Non"; +$text['label-no']['fr-fr'] = "Non"; +$text['label-no']['he-il'] = "לא"; +$text['label-no']['it-it'] = "No"; +$text['label-no']['nl-nl'] = "Nee"; +$text['label-no']['pl-pl'] = "Nie"; +$text['label-no']['pt-br'] = "Não "; +$text['label-no']['pt-pt'] = "Não"; +$text['label-no']['ro-ro'] = "Nu"; +$text['label-no']['ru-ru'] = "Нет"; +$text['label-no']['sv-se'] = "Nej"; +$text['label-no']['uk-ua'] = "Ні"; +$text['label-no']['tr-tr'] = "HAYIR"; +$text['label-no']['zh-cn'] = "不"; +$text['label-no']['ja-jp'] = "いいえ"; +$text['label-no']['ko-kr'] = "아니요"; + $text['label-os']['en-us'] = "Operating System"; $text['label-os']['en-gb'] = "Operating System"; $text['label-os']['ar-eg'] = "מערכת הפעלה"; diff --git a/app/system/resources/dashboard/config.php b/app/system/resources/dashboard/config.php index 6cecf9bc94..bdaa3f7d0a 100644 --- a/app/system/resources/dashboard/config.php +++ b/app/system/resources/dashboard/config.php @@ -46,8 +46,8 @@ $y = 0; $array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_group_uuid'] = '41befc82-c65a-499e-9e29-513a3dd7974a'; $array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_uuid'] = 'beade936-846b-4f02-986c-a2de6fa762c2'; $array['dashboard'][$x]['dashboard_groups'][$y]['group_name'] = 'superadmin'; -$x++; +$x++; $array['dashboard'][$x]['dashboard_uuid'] = 'bb76f7fc-669f-41dd-a636-6ddaee5deae1'; $array['dashboard'][$x]['dashboard_name'] = 'System Counts'; $array['dashboard'][$x]['dashboard_path'] = 'system/system_counts'; @@ -61,6 +61,21 @@ $y = 0; $array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_group_uuid'] = 'a772d2a8-7c1f-4453-b77b-2e15b510a78d'; $array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_uuid'] = 'bb76f7fc-669f-41dd-a636-6ddaee5deae1'; $array['dashboard'][$x]['dashboard_groups'][$y]['group_name'] = 'superadmin'; + +$x++; +$array['dashboard'][$x]['dashboard_uuid'] = '2a0a6742-bd2d-449a-88ac-b3ed255c9f8e'; +$array['dashboard'][$x]['dashboard_name'] = 'System Services'; +$array['dashboard'][$x]['dashboard_path'] = 'system/system_services'; +$array['dashboard'][$x]['dashboard_column_span'] = '1'; +$array['dashboard'][$x]['dashboard_row_span'] = '2'; +$array['dashboard'][$x]['dashboard_details_state'] = 'hidden'; +$array['dashboard'][$x]['dashboard_order'] = '110'; +$array['dashboard'][$x]['dashboard_enabled'] = 'true'; +$array['dashboard'][$x]['dashboard_description'] = 'A list of showing the count of active and inactive services'; +$y = 0; +$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_group_uuid'] = '719d8a56-00b2-437e-83c0-a9e5005a53c5'; +$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_uuid'] = '4bd3e11d-f4cd-4e37-8e7b-445e1e4aa7d5'; +$array['dashboard'][$x]['dashboard_groups'][$y]['group_name'] = 'superadmin'; //$y++; //$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_group_uuid'] = '127382ae-0dd1-45eb-869c-56a708220de5'; //$array['dashboard'][$x]['dashboard_groups'][$y]['dashboard_uuid'] = 'bb76f7fc-669f-41dd-a636-6ddaee5deae1'; diff --git a/app/system/resources/dashboard/system_services.php b/app/system/resources/dashboard/system_services.php new file mode 100644 index 0000000000..e83744fe0e --- /dev/null +++ b/app/system/resources/dashboard/system_services.php @@ -0,0 +1,175 @@ + + * Portions created by the Initial Developer are Copyright (C) 2008-2024 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mark J Crane + * Tim Fry + */ + +//includes files + require_once dirname(__DIR__, 4) . "/resources/require.php"; + +//check permissions + require_once "resources/check_auth.php"; + if (permission_exists('xml_cdr_view')) { + //access granted + } + else { + echo "access denied"; + exit; + } + + $dashboard_name = "System Services"; + +//function to parse a FusionPBX service from a .service file + if (!function_exists('get_classname')) { + function get_classname(string $file) { + $parsed = parse_ini_file($file); + $exec_cmd = $parsed['ExecStart']; + $parts = explode(' ', $exec_cmd); + $php_file = $parts[1] ?? ''; + if (!empty($php_file)) { + return $php_file; + } + return ''; + } + } + +//function to check for running process + if (!function_exists('is_running')) { + function is_running(string $name) { + $output = ''; + + //escape for better safety + $name = escapeshellarg($name); + + // Use pgrep to search for the program by its name + $output = shell_exec("ps -aux | grep $name | grep -v grep"); + + // If there is a process id then the program is running + return ($output !== null && strlen($output) > 0); + } + } + +//load installed services + $files = glob(PROJECT_ROOT . '/*/*/resources/service/*.service'); + $services = []; + $total_running = 0; + foreach ($files as $file) { + $service = get_classname($file); + //check if the service name was found + if (!empty($service)) { + $basename = basename($service, '.php'); + //clean up the name + //$basename = ucwords(str_replace('_', ' ', $basename)); + //check if service is running + $services[$basename] = is_running($service); + //keep total count for charts + if ($services[$basename]) { + ++$total_running; + } + } + } + +//track total installed services for charts + $total_services = count($services); + +//add multi-lingual support + $text = (new text())->get($settings->get('domain','language','en-us'), 'core/user_settings'); + +//show the results +echo "
\n"; +echo "
\n"; +echo " System Services\n"; +echo "
\n"; +echo "
\n"; +echo " \n"; + +if ($dashboard_details_state != 'disabled') { +echo "
\n"; +echo " \n"; +echo " \n"; +echo " \n"; +echo " \n"; +echo " \n"; + $row_style[false] = "row_style0"; + $row_style[true] = "row_style1"; + $c = true; + foreach ($services as $name => $enabled) { + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + $c = !$c; + } +echo "
".($text['label-service'] ?? 'Service')."".($text['label-running'] ?? 'Running')."
$name" . ($enabled ? $text['label-yes'] ?? 'Yes' : $text['label-no'] ?? 'No') . "
\n"; +echo "
\n"; +} +echo "
\n";