Fix restore: use whmapi1 removeacct instead of /scripts/removeacct

The /scripts/removeacct script was failing with "You do not have
permission to remove that account" even when running as root. Switch
to whmapi1 removeacct which uses the WHM API with proper root
authentication context. Also check the whmapi1 result field since
whmapi1 returns exit code 0 even on logical failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shuki
2026-03-05 03:36:28 +02:00
parent 3b5488f0d7
commit 05db1f2340

View File

@@ -132,13 +132,21 @@ restore_full_account() {
if [[ "$terminate" == "true" ]] && account_exists "$user"; then
log_info "Terminating existing account $user before restore..."
local removeacct_output
if ! removeacct_output=$(/scripts/removeacct "$user" --force 2>&1); then
if ! removeacct_output=$(whmapi1 removeacct user="$user" 2>&1); then
log_error "Failed to terminate account $user"
log_debug "removeacct output: $removeacct_output"
rm -rf "$restore_dir"
return 1
fi
log_debug "removeacct output: $removeacct_output"
# Check whmapi1 result field for failure
if echo "$removeacct_output" | grep -q 'result: 0'; then
local reason
reason=$(echo "$removeacct_output" | grep 'reason:' | sed 's/.*reason: //')
log_error "Failed to terminate account $user: $reason"
rm -rf "$restore_dir"
return 1
fi
fi
# Run restorepkg (--force to merge into existing account if present)