From e57dee4f5cfdba4c91dca946e6062502bf2da59d Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Sun, 5 Jul 2026 01:12:19 +0100 Subject: [PATCH] Recover DirectAdmin account deletion from false-negative API errors (#3894) * Recover DirectAdmin account deletion from false-negative API errors Some DirectAdmin servers return an error for the account-delete request even though the deletion already succeeded server-side, leaving the order stuck in FOSSBilling and forcing users to rely on "Force delete". cancelAccount() now verifies whether the account still exists before failing, and only rethrows the original error if it does. Fixes #3725 * Verify account existence via user list, not a fallible per-user check The delete-verification check must not confuse a genuine transport, auth, or permission failure with a successful deletion. Switch from a per-user API_SHOW_USER_CONFIG lookup (which can fail for reasons unrelated to whether the account still exists) to API_SHOW_USERS, a reseller/admin-scoped listing call, and only treat the account as deleted when the list confirms it's actually gone. If the verification call itself errors, assume the account still exists so the original deletion failure is preserved. --- src/library/Server/Manager/Directadmin.php | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/library/Server/Manager/Directadmin.php b/src/library/Server/Manager/Directadmin.php index 5c62d38ee..a91576963 100644 --- a/src/library/Server/Manager/Directadmin.php +++ b/src/library/Server/Manager/Directadmin.php @@ -85,11 +85,15 @@ class Server_Manager_Directadmin extends Server_Manager * Cancels an account on the DirectAdmin server. * This method sends a request to the server to delete the account. * + * Some DirectAdmin servers return an error for this request even though the + * deletion already succeeded, so on failure we double check whether the + * account still exists before giving up. + * * @param Server_Account $account the account to be cancelled * * @return bool returns true if the account is successfully cancelled * - * @throws Server_Exception if there is an error while sending the request to the server + * @throws Server_Exception if there is an error while sending the request to the server and the account still exists */ public function cancelAccount(Server_Account $account): bool { @@ -99,11 +103,40 @@ class Server_Manager_Directadmin extends Server_Manager 'select0' => $account->getUsername(), ]; - $this->request('API_SELECT_USERS', $fields); + try { + $this->request('API_SELECT_USERS', $fields); + } catch (Server_Exception $e) { + if ($this->accountExists($account)) { + throw $e; + } + + $this->getLog()->info("Deletion of {$account->getUsername()} reported an error, but the account no longer exists on the server."); + } return true; } + /** + * Checks whether an account still exists on the DirectAdmin server. + * If the check itself fails, the account is assumed to still exist so a + * transport, authentication, or permission error is never mistaken for a + * successful deletion. + * + * @param Server_Account $account the account to check + * + * @return bool true if the account still exists, false otherwise + */ + private function accountExists(Server_Account $account): bool + { + try { + $users = $this->request('API_SHOW_USERS'); + } catch (Server_Exception) { + return true; + } + + return in_array($account->getUsername(), $users['list'] ?? [], true); + } + /** * Returns the port number for the DirectAdmin server. * If the port is set in the configuration, verify that it's a valid port number (1 - 65535).