diff --git a/app/system/resources/dashboard/system_services.php b/app/system/resources/dashboard/system_services.php index e885b9e0ad..3fbcdf4c0a 100644 --- a/app/system/resources/dashboard/system_services.php +++ b/app/system/resources/dashboard/system_services.php @@ -18,7 +18,7 @@ * * The Initial Developer of the Original Code is * Mark J Crane - * Portions created by the Initial Developer are Copyright (C) 2008-2024 + * Portions created by the Initial Developer are Copyright (C) 2008-2025 * the Initial Developer. All Rights Reserved. * * Contributor(s): @@ -57,101 +57,101 @@ //function to check for running process: returns [running, pid, etime] if (!function_exists('is_running')) { - function is_running(string $name) { - $name = escapeshellarg($name); - $pid = trim(shell_exec("ps -aux | grep $name | grep -v grep | awk '{print \$2}' | head -n 1")); - if ($pid && is_numeric($pid)) { - $etime = trim(shell_exec("ps -p $pid -o etime= | tr -d '\n'")); - return ['running' => true, 'pid' => $pid, 'etime' => $etime]; - } - return ['running' => false, 'pid' => null, 'etime' => null]; - } - } + function is_running(string $name) { + $name = escapeshellarg($name); + $pid = trim(shell_exec("ps -aux | grep $name | grep -v grep | awk '{print \$2}' | head -n 1")); + if ($pid && is_numeric($pid)) { + $etime = trim(shell_exec("ps -p $pid -o etime= | tr -d '\n'")); + return ['running' => true, 'pid' => $pid, 'etime' => $etime]; + } + return ['running' => false, 'pid' => null, 'etime' => null]; + } + } //function to format etime into friendly display - if (!function_exists('format_etime')) { - function format_etime($etime) { - // Format: [[dd-]hh:]mm:ss - if (empty($etime)) return '-'; + if (!function_exists('format_etime')) { + function format_etime($etime) { + // Format: [[dd-]hh:]mm:ss + if (empty($etime)) return '-'; - $days = 0; $hours = 0; $minutes = 0; $seconds = 0; + $days = 0; $hours = 0; $minutes = 0; $seconds = 0; - // Handle dd-hh:mm:ss - if (preg_match('/^(\d+)-(\d+):(\d+):(\d+)$/', $etime, $m)) { - [$_, $days, $hours, $minutes, $seconds] = $m; - } - // Handle hh:mm:ss - elseif (preg_match('/^(\d+):(\d+):(\d+)$/', $etime, $m)) { - [$_, $hours, $minutes, $seconds] = $m; - } - // Handle mm:ss - elseif (preg_match('/^(\d+):(\d+)$/', $etime, $m)) { - [$_, $minutes, $seconds] = $m; - } + // Handle dd-hh:mm:ss + if (preg_match('/^(\d+)-(\d+):(\d+):(\d+)$/', $etime, $m)) { + [$_, $days, $hours, $minutes, $seconds] = $m; + } + // Handle hh:mm:ss + elseif (preg_match('/^(\d+):(\d+):(\d+)$/', $etime, $m)) { + [$_, $hours, $minutes, $seconds] = $m; + } + // Handle mm:ss + elseif (preg_match('/^(\d+):(\d+)$/', $etime, $m)) { + [$_, $minutes, $seconds] = $m; + } - $out = []; - if ($days) $out[] = $days . 'd'; - if ($hours) $out[] = $hours . 'h'; - if ($minutes) $out[] = $minutes . 'm'; - if ($seconds || empty($out)) $out[] = $seconds . 's'; + $out = []; + if ($days) $out[] = $days . 'd'; + if ($hours) $out[] = $hours . 'h'; + if ($minutes) $out[] = $minutes . 'm'; + if ($seconds || empty($out)) $out[] = $seconds . 's'; - return implode(' ', $out); - } - } + return implode(' ', $out); + } + } //friendly labels - $service_labels = [ - 'email_queue' => 'Email Queue', - 'event_guard' => 'Event Guard', - 'fax_queue' => 'Fax Queue', - 'maintenance_service' => 'Maintenance Service', - 'message_events' => 'Message Events', - 'message_queue' => 'Message Queue', - 'xml_cdr' => 'XML CDR', - 'freeswitch' => 'FreeSWITCH', - 'nginx' => 'Nginx', - 'postgresql' => 'PostgreSQL', - 'event_guard' => 'Event Guard', - 'sshd' => 'SSH Server' - ]; + $service_labels = [ + 'email_queue' => 'Email Queue', + 'event_guard' => 'Event Guard', + 'fax_queue' => 'Fax Queue', + 'maintenance_service' => 'Maintenance Service', + 'message_events' => 'Message Events', + 'message_queue' => 'Message Queue', + 'xml_cdr' => 'XML CDR', + 'freeswitch' => 'FreeSWITCH', + 'nginx' => 'Nginx', + 'postgresql' => 'PostgreSQL', + 'event_guard' => 'Event Guard', + 'sshd' => 'SSH Server' + ]; - $files = glob(PROJECT_ROOT . '/*/*/resources/service/*.service'); - $services = []; - $total_running = 0; + $files = glob(PROJECT_ROOT . '/*/*/resources/service/*.service'); + $services = []; + $total_running = 0; - // load FusionPBX installed services - foreach ($files as $file) { - $service = get_classname($file); - //check if the service name was found - if (!empty($service)) { - $basename = basename($service, '.php'); - $info = is_running($service); - $info['label'] = $service_labels[$basename] ?? ucwords(str_replace('_', ' ', $basename)); - $services[$basename] = $info; - if ($info['running']) $total_running++; - } - } + // load FusionPBX installed services + foreach ($files as $file) { + $service = get_classname($file); + //check if the service name was found + if (!empty($service)) { + $basename = basename($service, '.php'); + $info = is_running($service); + $info['label'] = $service_labels[$basename] ?? ucwords(str_replace('_', ' ', $basename)); + $services[$basename] = $info; + if ($info['running']) $total_running++; + } + } - // Get extra system services from default settings - $extra_services_string = $settings->get('theme', 'dashboard_extra_system_services'); + // Get extra system services from default settings + $extra_services_string = $settings->get('theme', 'dashboard_extra_system_services'); - // Only proceed if the setting is not empty - if (!empty($extra_services_string) && is_string($extra_services_string)) { - // Convert comma-separated list to array - $extra_services = array_filter(array_map('trim', explode(',', $extra_services_string))); + // Only proceed if the setting is not empty + if (!empty($extra_services_string) && is_string($extra_services_string)) { + // Convert comma-separated list to array + $extra_services = array_filter(array_map('trim', explode(',', $extra_services_string))); - // Loop through extra services if array is not empty - if (!empty($extra_services)) { - foreach ($extra_services as $extra) { - if (!isset($services[$extra])) { - $info = is_running($extra); - $info['label'] = $service_labels[$extra] ?? ucwords($extra); - $services[$extra] = $info; - if ($info['running']) $total_running++; - } - } - } - } + // Loop through extra services if array is not empty + if (!empty($extra_services)) { + foreach ($extra_services as $extra) { + if (!isset($services[$extra])) { + $info = is_running($extra); + $info['label'] = $service_labels[$extra] ?? ucwords($extra); + $services[$extra] = $info; + if ($info['running']) $total_running++; + } + } + } + } //track total installed services for charts $total_services = count($services); @@ -161,90 +161,96 @@ //show the results echo "
\n"; -echo "
\n"; -echo " System Services\n"; -echo "
\n"; -echo "
\n"; -echo " \n"; +echo "
\n"; +echo " System Services\n"; +//doughnut chart +if (!isset($dashboard_chart_type) || $dashboard_chart_type == "doughnut") { + echo "
\n"; + echo " \n"; +} +if ($dashboard_chart_type == "number") { + echo " ".$total_services.""; +} +echo "
\n"; if ($dashboard_details_state != 'disabled') { -echo "
\n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo " \n"; + echo "
\n"; + echo "
".($text['label-service'] ?? 'Service')."".($text['label-running'] ?? 'Running')."".($text['label-runtime'] ?? 'Runtime')."
\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 $info) { + $row_style[false] = "row_style0"; + $row_style[true] = "row_style1"; + $c = true; + foreach ($services as $info) { $label = $info['label']; - $status = $info['running'] - ? "Yes" - : "No"; + $status = $info['running'] + ? "Yes" + : "No"; $etime = isset($info['etime']) ? format_etime($info['etime']) : '-'; - $pid = $info['pid'] ?? ''; + $pid = $info['pid'] ?? ''; $tooltip_attr = $pid ? "title='PID: $pid'" : ''; - - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - $c = !$c; - } -echo "
".($text['label-service'] ?? 'Service')."".($text['label-running'] ?? 'Running')."".($text['label-runtime'] ?? 'Runtime')."
$label$status$etime
\n"; -echo "
\n"; + echo " \n"; + echo " $label\n"; + echo " $status\n"; + echo " $etime\n"; + echo " \n"; + $c = !$c; + } + + echo " \n"; + echo "
\n"; } echo "\n";