HEX
Server: nginx/1.29.3
System: Linux 11979.bigscoots-wpo.com 6.8.0-88-generic #89-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 01:02:46 UTC 2025 x86_64
User: nginx (1068)
PHP: 7.4.33
Disabled: exec,system,passthru,shell_exec,proc_open,proc_close,popen,show_source,cmd# Do not modify this line # 1684243876
Upload Files
File: //bigscoots/wpo/cloudflare/bs-cache-audit.sh
#!/bin/bash

# Load common BigScoots functions
source /bigscoots/includes/common.sh

LC_ALL=C
TARGET_DOMAIN=$1

# --- Function to process a single site ---
process_site() {
    local d=$1
    local domain=$2

    # Generate skip list for THIS specific site
    SKIP_LIST=$(skip_all_plugins_except bigscoots-cache --path="$d")

    # Run the WP-CLI command
    csv=$(wp bs_cache status --format=csv --path="$d" --skip-themes --skip-plugins="$SKIP_LIST" --allow-root 2>/dev/null)

    if [[ -z "$csv" ]]; then
        printf "%-35s | %s\n" "$domain" "PLUGIN NOT ACTIVE / NOT FOUND"
        return
    fi

    # Parse values using awk
    cache=$(echo "$csv" | awk -F',' '$2 ~ /Plugin Cache Status/ {gsub(/^"|"$|[[:space:]]+/, "", $3); print $3}')
    setup=$(echo "$csv" | awk -F',' '$2 ~ /Plugin Setup Mode/ {gsub(/^"|"$|[[:space:]]+/, "", $3); print $3}')
    rule=$(echo "$csv" | awk -F',' '$2 ~ /Cache Rule Status/ {gsub(/^"|"$|[[:space:]]+/, "", $3); print $3}')
    hit=$(echo "$csv" | awk -F',' '$2 ~ /Home Page Cache Status/ {gsub(/^"|"$|[[:space:]]+/, "", $3); print $3}')

    printf "%-35s | %-20s | %-20s | %-20s | %-20s\n" \
      "$domain" "${cache:-N/A}" "${setup:-N/A}" "${rule:-N/A}" "${hit:-N/A}"
}

# --- Header ---
printf "%-35s | %-20s | %-20s | %-20s | %-20s\n" "Site" "Cache" "Setup" "Rules" "Home"
printf "%-35s-+-%-20s-+-%-20s-+-%-20s-+-%-20s\n" \
  "$(printf '%.0s-' {1..35})" "$(printf '%.0s-' {1..20})" "$(printf '%.0s-' {1..20})" "$(printf '%.0s-' {1..20})" "$(printf '%.0s-' {1..20})"

# --- Execution Logic ---
if [[ -n "$TARGET_DOMAIN" ]]; then
    # Direct Path Mode: Zero scanning, instant execution
    SITE_PATH="/home/nginx/domains/$TARGET_DOMAIN/public"
    
    if [[ -f "$SITE_PATH/wp-config.php" ]]; then
        process_site "$SITE_PATH" "$TARGET_DOMAIN"
    else
        echo "Error: WordPress not found at $SITE_PATH"
        exit 1
    fi
else
    # Global Mode: Use find_wp_installs for discovery
    find_wp_installs | while read -r d; do
        domain=$(basename "$(dirname "$d")")
        
        # Skip staging sites in global scan
        [[ "$domain" == *.bigscoots-staging.com ]] && continue
        
        process_site "$d" "$domain"
    done
fi