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/cpanel/reset_all_zones.sh
#!/usr/bin/env bash
#
# reset_all_zones.sh
#
# Usage: ./reset_all_zones.sh <cpanel_username>
#
# Requires: 
#   - `uapi` in your PATH (from cPanel)
#   - `whmapi1` in your PATH (from WHM/cPanel)
#   - `jq` for JSON parsing

set -euo pipefail

# Check for jq
if ! command -v jq &>/dev/null; then
  echo "Error: This script requires 'jq' (https://stedolan.github.io/jq/)" >&2
  exit 1
fi

# Validate arguments
if [[ $# -ne 1 ]]; then
  echo "Usage: $0 <cpanel_username>" >&2
  exit 1
fi

CPUSER=$1

# Fetch the list of domains
echo "Fetching domains for cPanel user '$CPUSER'..."
DOMAIN_JSON=$(uapi --output=json --user="$CPUSER" DomainInfo list_domains)

# Verify the call succeeded
STATUS=$(jq -r '.result.status' <<<"$DOMAIN_JSON")
if [[ "$STATUS" -ne 1 ]]; then
  echo "Error: Could not list domains for user '$CPUSER'." >&2
  jq . <<<"$DOMAIN_JSON"
  exit 1
fi

# Extract every domain (main, sub-, parked, addon)
DOMAINS=()
DOMAINS+=( "$(jq -r '.result.data.main_domain' <<<"$DOMAIN_JSON")" )
mapfile -t DOMAINS < <(
  jq -r '.result.data | (.sub_domains[]?, .parked_domains[]?, .addon_domains[]?)' <<<"$DOMAIN_JSON"
)

if [[ "${#DOMAINS[@]}" -eq 0 ]]; then
  echo "No domains found for user '$CPUSER'."
  exit 0
fi

# Loop over and reset each zone
for domain in "${DOMAINS[@]}"; do
  echo "→ Resetting DNS zone for: $domain"
  whmapi1 --output=jsonpretty resetzone domain="$domain" || {
    echo "  [!] Failed to reset zone for $domain" >&2
  }
done

echo "Done."