File: //proc/1284358/root/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."