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:
@@ -132,13 +132,21 @@ restore_full_account() {
|
|||||||
if [[ "$terminate" == "true" ]] && account_exists "$user"; then
|
if [[ "$terminate" == "true" ]] && account_exists "$user"; then
|
||||||
log_info "Terminating existing account $user before restore..."
|
log_info "Terminating existing account $user before restore..."
|
||||||
local removeacct_output
|
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_error "Failed to terminate account $user"
|
||||||
log_debug "removeacct output: $removeacct_output"
|
log_debug "removeacct output: $removeacct_output"
|
||||||
rm -rf "$restore_dir"
|
rm -rf "$restore_dir"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
log_debug "removeacct output: $removeacct_output"
|
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
|
fi
|
||||||
|
|
||||||
# Run restorepkg (--force to merge into existing account if present)
|
# Run restorepkg (--force to merge into existing account if present)
|
||||||
|
|||||||
Reference in New Issue
Block a user