/
home
/
desmarkadmin
/
Upload FileeE
HOME
#!/bin/bash # ANSI color codes RED="\033[91m" RESET="\033[0m" # Function to fetch PHP info using whmapi1 fetch_php_info() { mapfile -t php_info < <(whmapi1 --output=jsonpretty php_get_vhost_versions api.sort.enable=1 api.sort.a.method=lexicographic api.sort.a.field=vhost \ api.columns.enable=1 api.columns.a=account api.columns.b=vhost api.columns.c=documentroot api.columns.d=version api.columns.e=php_fpm api.columns.f=php_fpm_pool_parms | jq -r '.data.versions[] | [.account, .vhost, .documentroot, .version, .php_fpm, .php_fpm_pool_parms.pm_max_children, .php_fpm_pool_parms.pm_max_requests, .php_fpm_pool_parms.pm_process_idle_timeout] | @tsv') } # Function to calculate column widths calculate_column_widths() { max_user_length=0 max_domain_length=0 max_docroot_length=0 max_php_output_length=0 # Include column headers in the width calculations user_header="User" domain_header="Domain" docroot_header="Docroot" php_header="PHP Version - MC/MR/PIT" # Calculate the lengths of each header max_user_length=${#user_header} max_domain_length=${#domain_header} max_docroot_length=${#docroot_header} max_php_output_length=${#php_header} for info in "${php_info[@]}"; do IFS=$'\t' read -r user domain docroot php_version is_fpm pm_max_children pm_max_requests pm_process_idle_timeout <<<"$info" user_length=${#user} domain_length=${#domain} docroot_length=${#docroot} php_output="${php_version}" if [[ "$is_fpm" == "1" ]]; then php_output+="-fpm - ${pm_max_children:-0}/${pm_max_requests:-0}/${pm_process_idle_timeout:-0}" else php_output+="-cgi" fi php_output_length=${#php_output} max_user_length=$((user_length > max_user_length ? user_length : max_user_length)) max_domain_length=$((domain_length > max_domain_length ? domain_length : max_domain_length)) max_docroot_length=$((docroot_length > max_docroot_length ? docroot_length : max_docroot_length)) max_php_output_length=$((php_output_length > max_php_output_length ? php_output_length : max_php_output_length)) done user_width=$((max_user_length + 1)) domain_width=$((max_domain_length + 2)) docroot_width=$((max_docroot_length + 2)) php_output_width=$((max_php_output_length + 2)) total_width=$((user_width + domain_width + docroot_width + php_output_width + 11)) } # Print a horizontal line print_line() { printf "+%${total_width}s+\n" | tr ' ' '-' } # Print the header of the table print_header() { print_line printf "| %-$((${total_width} - 2))s |\n" "PHP Information" print_line printf "| %-*s | %-*s | %-*s | %-*s |\n" \ "$user_width" "$user_header" "$domain_width" "$domain_header" "$docroot_width" "$docroot_header" "$php_output_width" "$php_header" print_line } # Print the footer of the table print_footer() { print_line } # Print rows of data print_rows() { for info in "${php_info[@]}"; do IFS=$'\t' read -r user domain docroot php_version is_fpm pm_max_children pm_max_requests pm_process_idle_timeout <<<"$info" php_version="${php_version//ea-/}" if [[ "$is_fpm" == "1" ]]; then fpm_details=" - ${pm_max_children:-0}/${pm_max_requests:-0}/${pm_process_idle_timeout:-0}" php_output="${php_version}-fpm" else fpm_details="" php_output="${php_version}-cgi" fi if [[ "${php_version//php/}" -le 71 ]]; then color="$RED" else color="" fi printf "| %-*s | %-*s | %-*s | ${color}%-*s${RESET} |\n" \ "$user_width" "$user" "$domain_width" "$domain" "$docroot_width" "$docroot" "$php_output_width" "${php_output}${fpm_details}" done } # Main function main() { fetch_php_info calculate_column_widths print_header print_rows print_footer } # Run the main function main