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: //proc/1284358/root/bigscoots/cpanel/domain_audit.sh
#!/usr/bin/env bash
set -u

# --- ARGUMENT CHECK ---
if [[ $# -lt 2 ]]; then
    echo "ERROR: Missing arguments."
    echo "Usage: bash $0 <NEW_IP> <CLIENT_ID>"
    exit 1
fi

NEW_IP="$1"
CLIENT_ID="$2"

# --- CONFIGURATION ---
ZONEDIR="/var/named"
OUTDIR="/root/migration-audit-$(date +%F)"
REG_TOOL="/bigscoots/tools/registrable-domain"
VENV_DIR="/root/psl-venv"
VENV_PYTHON="$VENV_DIR/bin/python3"

# Bootstrap
if [[ ! -x "$VENV_PYTHON" ]]; then
    yum -y install python3 python3-pip &>/dev/null
    python3 -m venv "$VENV_DIR" &>/dev/null
    "$VENV_DIR/bin/pip" install publicsuffix2 &>/dev/null
fi

mkdir -p "$OUTDIR"
TICKET_BODY="$OUTDIR/${CLIENT_ID}.txt"
: > "$TICKET_BODY"

# --- FUNCTIONS ---
is_local_ip() {
    local ip="$1"
    [[ -z "$ip" ]] && return 1
    hostname -I | grep -q "$ip" && return 0
    return 1
}

get_registrable_domain() {
    "$VENV_PYTHON" "$REG_TOOL" "$1" 2>/dev/null | tr -d '[:space:]'
}

get_php_version() {
    local domain=$1
    local user
    user=$(/scripts/whoowns "$domain" 2>/dev/null)
    [[ -z "$user" ]] && { echo "Unknown"; return; }
    if [[ -f "/var/cpanel/userdata/$user/$domain.php_fpm.yaml" ]]; then
        grep "phpversion:" "/var/cpanel/userdata/$user/$domain.php_fpm.yaml" | awk '{print $2}' | tr -d "'"
    elif [[ -f "/var/cpanel/userdata/$user/$domain" ]]; then
        grep "phpversion:" "/var/cpanel/userdata/$user/$domain" | awk '{print $2}' | tr -d "'"
    else
        echo "System-Default"
    fi
}

# Lists
php_warning_list=""
found_local_ns=""
easy_list=""
cf_list=""
external_list=""
inactive_list=""

echo "Scanning for Client ID: $CLIENT_ID..."

while IFS= read -r -d '' f; do
    D_ZONE=$(basename "$f" .db)
    [[ "$D_ZONE" =~ ^(localhost|rev|hostname|default)$ ]] && continue
    REG_DOMAIN=$(get_registrable_domain "$D_ZONE")
    [[ -n "$REG_DOMAIN" && "$D_ZONE" != "$REG_DOMAIN" ]] && continue

    live_a=$(dig "$D_ZONE" A +short | tail -n1)
    pointing_here=false
    is_local_ip "$live_a" && pointing_here=true
    
    mx_hosts=$(dig "$D_ZONE" MX +short | awk '{print $2}')
    for host in $mx_hosts; do
        mx_ip=$(dig "$host" A +short | tail -n1)
        is_local_ip "$mx_ip" && pointing_here=true
    done

    php_ver=$(get_php_version "$D_ZONE")
    case "$php_ver" in
        *php5*|*php70*|*php7.0*|*php71*|*php7.1*|*php72*|*php7.2*|*php73*|*php7.3*|*php74*|*php7.4*)
            [[ "$pointing_here" == "true" ]] && php_warning_list+="    - $D_ZONE (Using: $php_ver)\n"
            ;;
    esac

    ns_raw=$(dig "$D_ZONE" NS +short | tr '[:upper:]' '[:lower:]' | sed 's/\.$//' | sort -u)
    ns_string=$(echo "$ns_raw" | paste -sd ", " -)
    is_cloudflare=false; uses_local_ns=false
    for ns in $ns_raw; do
        [[ "$ns" == *"cloudflare.com"* ]] && is_cloudflare=true
        ns_ip=$(dig +short "$ns" A | head -n1)
        is_local_ip "$ns_ip" && { uses_local_ns=true; found_local_ns+="    - $ns ($ns_ip)\n"; }
    done

    if [[ "$is_cloudflare" == "true" ]]; then
        cf_list+="    - $D_ZONE\n"
    elif [[ "$pointing_here" == "true" ]]; then
        if [[ "$uses_local_ns" == "true" ]]; then
            easy_list+="    - $D_ZONE (Private NS: $ns_string)\n"
        else
            external_list+="    - $D_ZONE (Managed at: $ns_string)\n"
        fi
    else
        inactive_list+="    - $D_ZONE (Points to: ${live_a:-No Record})\n"
    fi
done < <(find "$ZONEDIR" -maxdepth 1 -type f -name "*.db" -print0)

# --- CONSTRUCT TICKET BODY ---
{
    echo "Hi there,"
    echo ""
    echo "We're reaching out with advance notice about an upcoming infrastructure upgrade designed to improve performance, stability, and long-term reliability for your hosting environment."
    echo ""
    echo "Due to recent changes involving one of our upstream providers, we've been required to retire certain legacy IP addresses on an accelerated timeline. Rather than treating this as a simple move, we're taking the opportunity to migrate affected accounts onto our new infrastructure, which offers faster hardware and greater long-term stability."
    echo ""
    echo "To ensure this migration completes smoothly, we need to have the required DNS changes completed no later than January 20. Without this in place, there is a risk of service interruption once legacy IPs are retired."
    echo ""
    echo "If you'd like more background on the project and why we're making this move, you can read more here: https://www.bigscoots.com/blog/bigscoots-takes-control-of-its-destiny-with-massive-infrastructure-overhaul/"
    echo ""
    echo "Because we do not currently control your DNS, we do need your help. To proceed, we'll need one of the following:"
    echo ""
    echo "  - Option 1: Update and point the A Record for your domain(s) to the following IP: $NEW_IP"
    echo ""
    echo "  - Option 2: Provide us with delegate access / login credentials to your DNS registrar account so that we can update the DNS records for the domains listed in Categories 2 and 3 below."
    echo ""

    if [[ -n "$php_warning_list" ]]; then
        echo "An Important note regarding PHP version:"
        echo ""
        echo "Your site is currently running on a PHP version below 7.4. Our new infrastructure is optimized for modern, supported PHP versions, and PHP 8.1+ is strongly recommended for performance, security, and long-term compatibility."
        echo ""
        echo "If you'd like to continue running a PHP version below 7.4, this will require a CloudLinux license, which is \$15/month, to ensure proper isolation and ongoing compatibility. We're happy to discuss your options here, including upgrading PHP if that's something you'd like assistance with."
        echo ""
    fi

    echo "We appreciate your prompt attention here. Please let us know which option you prefer!"
    echo ""
    echo "---------------------------------------------------------"
    echo "INTERNAL AUDIT DATA (Technical reference for your domains)"
    echo "---------------------------------------------------------"
    echo ""

    if [[ -n "$php_warning_list" ]]; then
        echo "### ⚠️ Legacy PHP Domains Detected:"
        echo "Requires upgrading to at least PHP 8.1; otherwise, a CloudLinux license is required to maintain support for this legacy version."
        echo -e "$php_warning_list" | sort -u
        echo ""
    fi
    if [[ -n "$found_local_ns" ]]; then
        echo "### ⚠️ Nameserver Re-Registration Required:"
        echo "Requires logging into your domain registrar to re-register the IPs assigned to these nameservers to point to the new IP: $NEW_IP"
        echo -e "$found_local_ns" | sort -u
        echo ""
    fi
    if [[ -n "$easy_list" ]]; then
        echo "### ✅ Category 1: Standard Updates"
        echo "No changes necessary on your part; we can handle these DNS changes at the server level."
        echo -e "$easy_list" | sort -u
        echo ""
    fi
    if [[ -n "$cf_list" ]]; then
        echo "### ☁️ Category 2: Cloudflare Managed"
        echo "Requires inviting [email protected] as an administrator to your Cloudflare account or"
        echo "logging into your Cloudflare dashboard to update the 'A' record to point to $NEW_IP."
        echo -e "$cf_list" | sort -u
        echo ""
    fi
    if [[ -n "$external_list" ]]; then
        echo "### 🛠️ Category 3: External DNS"
        echo "Requires logging into the DNS provider listed below to update your 'A' record to point to $NEW_IP."
        echo -e "$external_list" | sort -u
        echo ""
    fi
    if [[ -n "$inactive_list" ]]; then
        echo "### ℹ️ Category 4: Domains Pointed Elsewhere"
        echo "These domains are currently pointed to external services; no action is required unless you intend to point them to this server."
        echo -e "$inactive_list" | sort -u
        echo ""
    fi
} >> "$TICKET_BODY"

echo "Done. Ticket note: $TICKET_BODY"