diff --git a/lib/system-detect.sh b/lib/system-detect.sh index ab2b060..ea798b1 100755 --- a/lib/system-detect.sh +++ b/lib/system-detect.sh @@ -263,8 +263,8 @@ detect_cloudflare() { fi fi - # Check for railgun - if systemctl is-active --quiet railgun 2>/dev/null || service railgun status 2>/dev/null | grep -q running; then + # Check for railgun - fast process check + if pgrep -x railgun > /dev/null 2>&1; then SYS_CLOUDFLARE_ACTIVE="yes" print_info "Cloudflare Railgun detected" fi @@ -280,8 +280,10 @@ detect_firewall() { # CSF/LFD if [ -f "/etc/csf/csf.conf" ]; then SYS_FIREWALL="csf" - SYS_FIREWALL_VERSION=$(csf -v 2>/dev/null | grep -oP 'v\K[\d.]+' | head -1 || echo "unknown") - if systemctl is-active --quiet lfd 2>/dev/null || service lfd status 2>/dev/null | grep -q running; then + # Fast version check - read from version.txt or parse csf script + SYS_FIREWALL_VERSION=$(head -1 /etc/csf/version.txt 2>/dev/null || grep -oP 'my \$version = "\K[^"]+' /usr/sbin/csf 2>/dev/null | head -1 || echo "unknown") + # Fast check: just check if lfd process is running + if pgrep -x lfd > /dev/null 2>&1; then SYS_FIREWALL_ACTIVE="yes" print_success "Detected CSF ${SYS_FIREWALL_VERSION} (active)" else @@ -310,8 +312,8 @@ detect_firewall() { if command_exists iptables; then SYS_FIREWALL="iptables" SYS_FIREWALL_VERSION=$(iptables --version 2>/dev/null | grep -oP 'v\K[\d.]+' | head -1 || echo "unknown") - # Check if iptables has any rules - if [ "$(iptables -L -n 2>/dev/null | wc -l)" -gt 8 ]; then + # Fast check: just check filter table INPUT chain only (much faster than full -L) + if [ "$(iptables -L INPUT -n 2>/dev/null | wc -l)" -gt 2 ]; then SYS_FIREWALL_ACTIVE="yes" print_success "Detected iptables ${SYS_FIREWALL_VERSION} (active)" else @@ -357,24 +359,26 @@ get_system_resources() { local cpu_used=$(awk "BEGIN {printf \"%.1f\", 100-$cpu_idle}") local load_percent=$(awk "BEGIN {printf \"%.0f\", ($load/$cores)*100}") - # Memory Information - local mem_total=$(free -h | awk '/^Mem:/ {print $2}') - local mem_used=$(free -h | awk '/^Mem:/ {print $3}') + # Memory Information - get all in one call + local mem_info=$(free -h) + local mem_total=$(echo "$mem_info" | awk '/^Mem:/ {print $2}') + local mem_used=$(echo "$mem_info" | awk '/^Mem:/ {print $3}') + local mem_available=$(echo "$mem_info" | awk '/^Mem:/ {print $7}') local mem_percent=$(free | awk '/^Mem:/ {printf "%.0f", $3/$2*100}') - local mem_available=$(free -h | awk '/^Mem:/ {print $7}') - # Swap Information - local swap_total=$(free -h | awk '/^Swap:/ {print $2}') - local swap_used=$(free -h | awk '/^Swap:/ {print $3}') + # Swap Information - from same free call + local swap_total=$(echo "$mem_info" | awk '/^Swap:/ {print $2}') + local swap_used=$(echo "$mem_info" | awk '/^Swap:/ {print $3}') local swap_percent=0 if [ "$swap_total" != "0B" ] && [ -n "$swap_total" ]; then swap_percent=$(free | awk '/^Swap:/ {if($2>0) printf "%.0f", $3/$2*100; else print "0"}') fi - # Disk Information - local disk_root_total=$(df -h / | awk 'NR==2 {print $2}') - local disk_root_used=$(df -h / | awk 'NR==2 {print $3}') - local disk_root_percent=$(df -h / | awk 'NR==2 {print $5}') + # Disk Information - single df call + local disk_info=$(df -h / | awk 'NR==2 {print $2,$3,$5}') + local disk_root_total=$(echo "$disk_info" | awk '{print $1}') + local disk_root_used=$(echo "$disk_info" | awk '{print $2}') + local disk_root_percent=$(echo "$disk_info" | awk '{print $3}') # Uptime local uptime_str=$(uptime -p)