* 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";