get($_SESSION['domain']['language']['code'], 'core/user_settings'); //system status echo "
\n"; $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; //get the CPU details if (stristr(PHP_OS, 'BSD') || stristr(PHP_OS, 'Linux')) { $result = shell_exec('ps -A -o pcpu'); $percent_cpu = 0; foreach (explode("\n", $result) as $value) { if (is_numeric($value)) { $percent_cpu = $percent_cpu + $value; } } if (stristr(PHP_OS, 'BSD')) { $result = shell_exec("dmesg | grep -i --max-count 1 CPUs | sed 's/[^0-9]*//g'"); $cpu_cores = trim($result); } if (stristr(PHP_OS, 'Linux')) { $result = @trim(shell_exec("grep -P '^processor' /proc/cpuinfo")); $cpu_cores = count(explode("\n", $result)); } if ($cpu_cores > 1) { $percent_cpu = $percent_cpu / $cpu_cores; } $percent_cpu = round($percent_cpu, 2); //uptime $result = shell_exec('uptime'); $load_average = sys_getloadavg(); } //get memory details $memory_details = get_memory_details(); //disk usage if (PHP_OS == 'FreeBSD' || PHP_OS == 'Linux') { $tmp = shell_exec("df -h / 2>&1"); // Added -h for human-readable sizes $tmp = explode("\n", $tmp); $tmp = preg_replace('!\s+!', ' ', $tmp[1]); // multiple > single space $tmp = explode(' ', $tmp); // Extract values (columns may vary slightly by OS) $used_space = $tmp[2] ?? '-'; $total_space = $tmp[1] ?? '-'; $percent_disk_usage = ''; foreach ($tmp as $stat) { if (substr_count($stat, '%') > 0) { $percent_disk_usage = rtrim($stat,'%'); break; } } } //include websocket real-time updates $token = (new token())->create($_SERVER['PHP_SELF']); echo " \n"; subscriber::save_token($token, [system_dashboard_service::get_service_name()]); ?> \n"; echo " ".$text['label-system_status']."\n"; if ($widget_chart_type == "doughnut") { ?>
".round($percent_disk_usage)."%"; } if (!isset($widget_chart_type) || $widget_chart_type == "progress_bar") { //cpu usage if ($widget_row_span > 1) { echo " ".$text['label-processor_usage']."\n"; echo "
\n"; echo "
get('theme', 'dashboard_cpu_usage_chart_main_color') ?? '#03c04a')."; transition: 1.5s;'>".($percent_cpu > 100 ? 100 : round($percent_cpu))."%
\n"; echo "
\n"; echo "
 
\n"; } //disk usage if ($widget_row_span >= 1) { echo " ".$text['label-disk_usage']."\n"; echo "
\n"; echo "
get('theme', 'dashboard_disk_usage_chart_main_color') ?? '#03c04a').";'>".round($percent_disk_usage)."%
\n"; echo "
\n"; echo "
 
\n"; } //percent memory if ($widget_row_span > 1) { echo " ".$text['label-memory_usage']."\n"; echo "
\n"; echo "
get('theme', 'dashboard_disk_usage_chart_main_color') ?? '#03c04a').";'>".round((int)$memory_details['memory_percent'])."%
\n"; echo "
\n"; } } echo "
\n"; if ($widget_details_state != 'disabled') { echo "
"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; //pbx version echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; // OS Type and Version (for Linux) if (stristr(PHP_OS, 'Linux')) { // Try to get pretty OS name $os_info = ''; if (file_exists('/etc/os-release')) { $os_release = parse_ini_file('/etc/os-release'); $os_info = $os_release['PRETTY_NAME'] ?? ''; } // Fallback to basic uname info elseif (function_exists('php_uname')) { $os_info = php_uname('s') . ' ' . php_uname('r'); // e.g. "Linux 5.10.0" } // Clean up the output $os_info = str_replace('"', '', $os_info); // Remove quotes if present if (!empty($os_info)) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; } } //os uptime if (stristr(PHP_OS, 'Linux')) { $prefix = 'up '; $linux_uptime = shell_exec('uptime -p'); $uptime = substr($linux_uptime, strlen($prefix)); if (!empty($uptime)) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; } } //memory usage if (stristr(PHP_OS, 'Linux')) { // Get memory usage percentage $meminfo = shell_exec('free -b | grep Mem'); if (!empty($meminfo)) { $meminfo = preg_replace('/\s+/', ' ', trim($meminfo)); $parts = explode(' ', $meminfo); $total = $parts[1]; $used = $parts[2]; $percent_memory = round(($used / $total) * 100, 1); // Set style color based on thresholds $style = ($percent_memory > 90) ? "color: red;" : (($percent_memory > 75) ? "color: orange;" : ""); // Format with used/total (e.g. "40% (3.2G/8G)") $total_h = round($total / (1024*1024*1024), 1) . 'G'; $used_h = round($used / (1024*1024*1024), 1) . 'G'; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; } } //swap usage if (stristr(PHP_OS, 'Linux')) { $swapinfo = shell_exec('free -b | grep Swap'); if (!empty($swapinfo)) { $swapinfo = preg_replace('/\s+/', ' ', trim($swapinfo)); $parts = explode(' ', $swapinfo); $swap_total = $parts[1]; $swap_used = $parts[2]; // Only show swap if it exists (total > 0) if ($swap_total > 0) { $percent_swap = round(($swap_used / $swap_total) * 100, 1); $swap_total_h = round($swap_total / (1024*1024*1024), 1) . 'G'; $swap_used_h = round($swap_used / (1024*1024*1024), 1) . 'G'; // Set style color based on thresholds $style = ($percent_swap > 90) ? "color: red;" : (($percent_swap > 75) ? "color: orange;" : ""); echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; } } } //disk usage display if (stristr(PHP_OS, 'Linux') || stristr(PHP_OS, 'FreeBSD')) { if (!empty($percent_disk_usage) && $used_space != '-' && $total_space != '-') { // Set style color based on thresholds $style = ($percent_disk_usage > 90) ? "color: red;" : (($percent_disk_usage > 75) ? "color: orange;" : ""); echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; } } //db connections switch ($db_type) { case 'pgsql': $sql_current = "SELECT count(*) FROM pg_stat_activity"; $sql_max = "SHOW max_connections"; break; case 'mysql': $sql_current = "SHOW STATUS WHERE `variable_name` = 'Threads_connected'"; $sql_max = "SHOW VARIABLES LIKE 'max_connections'"; break; default: unset($sql_current, $sql_max); if (!empty($db_path) && !empty($dbfilename)) { $tmp = shell_exec("lsof " . realpath($db_path) . '/' . $dbfilename); $tmp = explode("\n", $tmp); $connections = sizeof($tmp) - 1; } } if (!empty($sql_current) && !empty($sql_max)) { if (!isset($database)) { $database = new database; } // Get current connections $current_connections = $database->select($sql_current, null, 'column'); // Get max connections (handles both PostgreSQL & MySQL) $max_result = $database->select($sql_max, null, ($db_type == 'pgsql') ? 'column' : 'row'); $max_connections = ($db_type == 'mysql') ? $max_result['Value'] : $max_result; // Format as "current/max" $connections = ($current_connections !== false && $max_connections !== false) ? "Current: " . $current_connections . ", Max: " . $max_connections : "N/A"; unset($sql_current, $sql_max); } if (!empty($connections)) { // Set style color based on thresholds $ratio = $current_connections / $max_connections; $style = ($ratio > 0.9) ? "color: red;" : (($ratio > 0.75) ? "color: orange;" : ""); echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; } //channel count if ($esl == null) { $esl = event_socket::create(); } if ($esl->is_connected()) { $tmp = event_socket::api('status'); $matches = Array(); preg_match("/(\d+)\s+session\(s\)\s+\-\speak/", $tmp, $matches); $channels = !empty($matches[1]) ? $matches[1] : 0; $tr_link = "href='".PROJECT_PATH."/app/calls_active/calls_active.php'"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = ($c) ? 0 : 1; } echo "
".$text['label-item']."".$text['label-value']."
".$text['label-channels']."".$channels."
\n"; echo "
"; //$n++; echo ""; } echo "\n"; ?>