### List All cPanel Accounts - PHP Source: https://context7.com/eugenefvdm/whm-api/llms.txt Shows how to retrieve a list of all cPanel accounts on the server. The example iterates through the accounts and displays details. It also demonstrates using magic methods for filtered searches. ```php listAccounts(); if (isset($accounts['data']['acct'])) { foreach ($accounts['data']['acct'] as $account) { echo "Domain: {$account['domain']}\n"; echo "Username: {$account['user']}\n"; echo "Email: {$account['email']}\n"; echo "Disk Used: {$account['diskused']} MB\n"; echo "---\n"; } } // List accounts with search filter using magic method $filtered = $cpanel->listaccts([ 'searchtype' => 'domain', 'search' => 'example.com' ]); ``` -------------------------------- ### Create New cPanel Account - PHP Source: https://context7.com/eugenefvdm/whm-api/llms.txt Provides a code example for creating a new cPanel hosting account. It includes parameters for domain, username, password, and hosting plan, and checks the result for success or failure. ```php createAccount($domain, $username, $password, $plan); if (isset($result['metadata']['result']) && $result['metadata']['result'] == 1) { echo "Account created successfully!\n"; echo "Domain: {$domain}\n"; echo "Username: {$username}\n"; echo "Account details: " . print_r($result['data'], true); } else { echo "Error creating account: " . $result['metadata']['reason'] . "\n"; } ``` -------------------------------- ### Install WHM/cPanel API using Composer Source: https://github.com/eugenefvdm/whm-api/blob/master/README.md This command installs the WHM/cPanel API package using Composer, a dependency manager for PHP. Ensure Composer is installed on your system before running this command. ```shell composer require eugenevdm/whm-api ``` -------------------------------- ### List Email Accounts - PHP Source: https://context7.com/eugenefvdm/whm-api/llms.txt Shows how to retrieve a list of all email accounts associated with a specific cPanel user. The example iterates through the results and displays email details like used and quota. ```php listEmailAccounts($username); if (isset($emails['cpanelresult']['data'])) { foreach ($emails['cpanelresult']['data'] as $email) { if (isset($email['email'])) { echo "Email: {$email['email']}\n"; echo "Disk Used: {$email['diskused']} MB\n"; echo "Disk Quota: {$email['diskquota']} MB\n"; echo "---\n"; } } } ``` -------------------------------- ### Call WHM/cPanel API Functions in PHP Source: https://github.com/eugenefvdm/whm-api/blob/master/README.md This PHP snippet shows how to call various WHM/cPanel API functions. It covers listing accounts with optional search parameters, creating an account (though the function signature seems incomplete in the example), and interacting with cPanel API 2. ```php listaccts(); // passing parameters $accounts = $cpanel->listaccts(['searchtype'=>'domain', 'search'=>'', 'exact', 'search'=>'helloworld.com']); // create account (Domain Name, Username, Password, Plan Slug) createAccount(www.domain_name.com.br, 'user', 'pass', 'plan_basic'); ``` -------------------------------- ### Execute cPanel API (1, 2, UAPI) using WHM API Source: https://context7.com/eugenefvdm/whm-api/llms.txt Provides a universal method to execute actions across cPanel API versions 1, 2, and UAPI. The function takes the API version, module, function, username, and optional parameters. Examples demonstrate fetching bandwidth, deleting an email account, and listing files. ```php execute_action('2', 'Bandwidth', 'getbwdata', $username); // Using UAPI (version 3) to delete email account $deleteEmail = $cpanel->execute_action( '3', 'Email', 'delete_pop', $username, ['email' => 'unwanted@example.com'] ); if (isset($deleteEmail['result']['status']) && $deleteEmail['result']['status'] == 1) { echo "Email deleted successfully\n"; } else { echo "Error: " . $deleteEmail['result']['errors'][0] . "\n"; } // Using cPanel API 1 (version 1) $result = $cpanel->execute_action('1', 'Fileman', 'fileop', $username, [ 'op' => 'list', 'dir' => '/public_html' ]); ?> ``` -------------------------------- ### Access cPanel API 2 Directly using WHM API Source: https://context7.com/eugenefvdm/whm-api/llms.txt Allows direct execution of any cPanel API 2 function by specifying the module, function name, and necessary parameters. Examples show retrieving bandwidth data, removing a cron job, and listing MySQL databases. Requires the cPanel username and relevant parameters. ```php cpanel('Bandwidth', 'getbwdata', $username); if (isset($bandwidthData['cpanelresult']['data'])) { echo "Bandwidth data: " . print_r($bandwidthData['cpanelresult']['data'], true); } // Remove a cron job line $cronResult = $cpanel->cpanel('Cron', 'remove_line', $username, ['line' => 1]); // List MySQL databases $databases = $cpanel->cpanel('Mysql', 'listdbs', $username); ?> ``` -------------------------------- ### Get Defined WHM/cPanel API Configuration in PHP Source: https://github.com/eugenefvdm/whm-api/blob/master/README.md This PHP snippet shows how to retrieve the current configuration settings of a WHM/cPanel API client instance. It provides getter methods for the username, password, authentication type, and host URL that were previously set. ```php getUsername(); // get password $cpanel->getPassword(); // get authentication type $cpanel->getAuthType(); // get host $cpanel->getHost(); ``` -------------------------------- ### Initialize WHM/cPanel Client - PHP Source: https://context7.com/eugenefvdm/whm-api/llms.txt Demonstrates how to create a new Cpanel instance for WHM/cPanel API integration. Supports both hash-based and password-based authentication. Allows configuration of timeouts. ```php 'https://192.168.1.100:2087', 'username' => 'root', 'auth_type' => 'hash', 'password' => 'YOUR_LONG_HASH_KEY_HERE' ]); // Or initialize with password authentication $cpanel = new Cpanel([ 'host' => 'https://example.com:2087', 'username' => 'root', 'auth_type' => 'password', 'password' => 'your_password' ]); // Configure timeouts if needed $cpanel->setTimeout(30) ->setConnectionTimeout(5); ``` -------------------------------- ### Initialize WHM/cPanel API and List Accounts in PHP Source: https://github.com/eugenefvdm/whm-api/blob/master/README.md This PHP snippet demonstrates how to initialize the WHM/cPanel API client with server credentials and then retrieve a list of accounts. It requires the Composer autoloader and specifies connection details like host, username, authentication type, and password or hash. ```php 'https://1.2.3.4:2087', // ip or domain complete with its protocol and port 'username' => 'root', // username of your server, it is usually root 'auth_type' => 'hash', // set 'hash' or 'password' 'password' => 'password', // long hash or your user's password ]); $accounts = $cpanel->listaccts(); // results returned as an array echo print_r($accounts, true); ?> ``` -------------------------------- ### Define WHM/cPanel API Configuration on Constructor in PHP Source: https://github.com/eugenefvdm/whm-api/blob/master/README.md This PHP code illustrates how to set up the WHM/cPanel API connection by providing configuration parameters directly within the constructor of the Cpanel class. Essential parameters include host, username, and password, with an optional authentication type. ```php 'https://1.2.3.4:2087', // required 'username' => 'root', // required 'auth_type' => 'hash', // optional, default 'hash' 'password' => 'password', // required ]); ``` -------------------------------- ### Call WHM API Functions using Magic Methods in PHP Source: https://context7.com/eugenefvdm/whm-api/llms.txt This snippet demonstrates how to instantiate the Cpanel class and call various WHM API functions like listaccts, accountsummary, setupreseller, getlanglist, and listips using PHP magic methods. It requires the cpanel library and server credentials for connection. ```php 'https://192.168.1.100:2087', 'username' => 'root', 'auth_type' => 'hash', 'password' => 'your_hash' ]); // Call listaccts WHM API function $accounts = $cpanel->listaccts(); // Call accountsummary with parameters $summary = $cpanel->accountsummary(['user' => 'cpanel_user']); // Call setupreseller to setup reseller privileges $reseller = $cpanel->setupreseller([ 'user' => 'reseller_user', 'makeowner' => 1 ]); // Call getlanglist to get available languages $languages = $cpanel->getlanglist(); // Call listips to get server IP addresses $ips = $cpanel->listips(); echo "API Response: " . print_r($ips, true); ?> ``` -------------------------------- ### Interact with cPanel API (API 2, UAPI) in PHP Source: https://github.com/eugenefvdm/whm-api/blob/master/README.md This PHP code demonstrates advanced usage of the WHM/cPanel API library, allowing interaction with specific cPanel modules and functions through different API versions. It shows how to retrieve bandwidth data using cPanel API 2 and remove a cron line, as well as delete an email address using UAPI. ```php cpanel('Bandwidth', 'getbwdata', 'username'); // removing cron line $data = $cpanel->cpanel('Cron', 'remove_line', 'username', ['line'=>1]); // get bandwidth data of specific cPanel's user (using cPanel API 2) $data = $cpanel->execute_action('2', 'Bandwidth', 'getbwdata', 'username'); // removing email address (using UAPI) $data = $cpanel->execute_action('3', 'Email', 'delete_pop', 'username', ['email'=>'peter@griffin.com']); ``` -------------------------------- ### WHM API Magic Methods Source: https://context7.com/eugenefvdm/whm-api/llms.txt This section demonstrates how to use magic methods to call various WHM API functions directly as methods on the Cpanel object. ```APIDOC ## WHM API Magic Methods ### Description Call any WHM API function directly as a method on the Cpanel object. The magic method automatically maps to WHM API endpoints. ### Method Various (e.g., POST, GET depending on the underlying WHM API function) ### Endpoint Dynamic based on the WHM API function called. ### Parameters Parameters are passed as an associative array to the magic method. #### Example Usage: ```php 'https://192.168.1.100:2087', 'username' => 'root', 'auth_type' => 'hash', 'password' => 'your_hash' ]); // Call listaccts WHM API function $accounts = $cpanel->listaccts(); // Call accountsummary with parameters $summary = $cpanel->accountsummary(['user' => 'cpanel_user']); // Call setupreseller to setup reseller privileges $reseller = $cpanel->setupreseller([ 'user' => 'reseller_user', 'makeowner' => 1 ]); // Call getlanglist to get available languages $languages = $cpanel->getlanglist(); // Call listips to get server IP addresses $ips = $cpanel->listips(); echo "API Response: " . print_r($ips, true); ?> ``` ### Request Example (Varies based on the specific WHM API function called) ### Response (Varies based on the specific WHM API function called. Typically returns an associative array or JSON object representing the API result.) ``` -------------------------------- ### Add Email Account - PHP Source: https://context7.com/eugenefvdm/whm-api/llms.txt Provides a code snippet for creating a new email account under a specified cPanel user. It includes parameters for the cPanel username, the new email address, and its password. Includes basic error checking. ```php addEmailAccount($cpanelUsername, $emailAddress, $emailPassword); if (isset($result['cpanelresult']['data'][0]['result']) && $result['cpanelresult']['data'][0]['result'] == 1) { echo "Email account created successfully!\n"; echo "Email: {$emailAddress}\n"; } else { echo "Error: " . $result['cpanelresult']['data'][0]['reason'] . "\n"; } } catch (\Exception $e) { echo "Invalid email format: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Delete cPanel Account - PHP Source: https://context7.com/eugenefvdm/whm-api/llms.txt Demonstrates how to delete a cPanel account using the WHM/cPanel API for PHP. Includes error handling for cases where the account deletion might fail. ```php destroyAccount($username); if (isset($result['metadata']['result']) && $result['metadata']['result'] == 1) { echo "Account '{$username}' deleted successfully.\n"; } else { echo "Failed to delete account: " . $result['metadata']['reason'] . "\n"; } } catch (\Exception $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Update WHM API Configuration Dynamically Source: https://context7.com/eugenefvdm/whm-api/llms.txt Allows modification of API connection settings after the initial object instantiation without needing to create a new instance. Methods are provided to change the host, update authorization credentials (username and password/hash), modify the authentication type, and add custom headers. It also includes getters to retrieve the current configuration. ```php 'https://server1.example.com:2087', 'username' => 'root', 'auth_type' => 'hash', 'password' => 'initial_hash' ]); // Switch to different server $cpanel->setHost('https://server2.example.com:2087'); // Update credentials $cpanel->setAuthorization('admin', 'new_hash_or_password'); // Change authentication type $cpanel->setAuthType('password'); // Add custom headers $cpanel->setHeader('X-Custom-Header', 'custom-value'); // Retrieve current configuration echo "Current host: " . $cpanel->getHost() . "\n"; echo "Current username: " . $cpanel->getUsername() . "\n"; echo "Auth type: " . $cpanel->getAuthType() . "\n"; ?> ``` -------------------------------- ### Check Server Connection using WHM API Source: https://context7.com/eugenefvdm/whm-api/llms.txt Verifies the API credentials and server connection status. Returns a status code (1 for success, 0 for failure) and verbose information, including specific error messages for authentication or connection issues. Includes a switch statement to handle different error types. ```php checkConnection(); if ($connectionStatus['status'] === 1) { echo "Connection successful!\n"; echo $connectionStatus['verbose'] . "\n"; } else { echo "Connection failed!\n"; echo "Error: {$connectionStatus['error']}\n"; echo "Details: {$connectionStatus['verbose']}\n"; // Handle specific errors switch ($connectionStatus['error']) { case 'auth_error': echo "Please verify your username and password/hash.\n"; break; case 'conn_error': echo "Check firewall rules (CSF) and hostname/port configuration.\n"; break; case 'unknown': echo "An unexpected error occurred.\n"; break; } } ?> ``` -------------------------------- ### List Email Forwarders using WHM API Source: https://context7.com/eugenefvdm/whm-api/llms.txt Retrieves a list of all email forwarders configured for a specific cPanel account. It iterates through the results and displays the forward address and its destination. Requires the cPanel username. ```php listForwards($username); if (isset($forwarders['cpanelresult']['data'])) { foreach ($forwarders['cpanelresult']['data'] as $forward) { echo "Forward from: {$forward['forward']}\n"; echo "Destination: {$forward['dest']}\n"; echo "---\n"; } } ?> ``` -------------------------------- ### Override WHM/cPanel API Configuration in PHP Source: https://github.com/eugenefvdm/whm-api/blob/master/README.md This PHP code provides methods to dynamically change the configuration of an existing WHM/cPanel API client instance. It allows updating the authorization credentials (username and password/hash), the host URL, and the authentication type after the object has been created. ```php setAuthorization($username, $password); // change host $cpanel->setHost($host); // change authentication type $cpanel->setAuthType($auth_type); ``` -------------------------------- ### Change Email Password using WHM API Source: https://context7.com/eugenefvdm/whm-api/llms.txt Updates the password for an existing email account associated with a cPanel account. Requires cPanel username, email address, and the new password. Handles success and error responses from the API. ```php changeEmailPassword($cpanelUsername, $emailAddress, $newPassword); if (isset($result['cpanelresult']['data'][0]['result']) && $result['cpanelresult']['data'][0]['result'] == 1) { echo "Password updated successfully for {$emailAddress}\n"; } else { echo "Error: " . $result['cpanelresult']['data'][0]['reason'] . "\n"; } } catch (\Exception $e) { echo "Error: " . $e->getMessage() . "\n"; } ?> ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.