### WHM Client Initialization Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt This section covers how to install the library via Composer and initialize the WHM client with your server credentials and API token. ```APIDOC ## Installation Install via Composer: ```bash composer require previewtechs/cpanel-whm-api:dev-master ``` ## Initialize WHM Client Authenticate and configure the WHM client connection. ```php 180]); $whmClient->setHttpClient($customClient); ``` ``` -------------------------------- ### Install cPanel/WHM API PHP Library using Composer Source: https://github.com/previewtechnologies/cpanel-whm-api/blob/master/README.md This snippet shows how to install the cPanel/WHM API PHP library using Composer, a dependency manager for PHP. Ensure Composer is installed on your system before running this command. ```bash composer require previewtechs/cpanel-whm-api:dev-master ``` -------------------------------- ### Initialize WHM Client and Accounts Manager Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Initializes the WHM client with server credentials and creates an Accounts manager instance. This setup is crucial for interacting with cPanel/WHM server functionalities. It also demonstrates how to set a custom HTTP client with a specific timeout. ```php 180]); $whmClient->setHttpClient($customClient); ``` -------------------------------- ### Get cPanel/WHM Domain Information with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Lists all domains on the server along with their associated details such as user, owner, IP addresses, SSL port, PHP version, and document root. Requires the PreviewTechs cPanelWHM library. ```php getDomains(); foreach ($domains as $domain) { echo "Domain: " . $domain->getDomain() . "\n"; echo "User: " . $domain->getUser() . "\n"; echo "Owner: " . $domain->getUserOwner() . "\n"; echo "Type: " . $domain->getDomainType() . "\n"; echo "IPv4: " . $domain->getIpv4() . "\n"; echo "IPv6: " . $domain->getIpv6() . "\n"; echo "Port: " . $domain->getPort() . "\n"; echo "SSL Port: " . $domain->getSslPort() . "\n"; echo "PHP Version: " . $domain->getPhpVersion() . "\n"; echo "ModSecurity: " . ($domain->getModSecurityEnabled() ? "Enabled" : "Disabled") . "\n"; echo "Document Root: " . $domain->getDocRoot() . "\n"; echo "---\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Get cPanel/WHM Bandwidth Information with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Retrieves bandwidth usage statistics for accounts, either for the current month or a specific month with optional filtering by reseller, keyword, and search type. Requires the PreviewTechs cPanelWHM library. ```php getBandwidthInfo(); // Get specific month bandwidth with filters $bandwidthData = $accounts->getBandwidthInfo( 10, // Month (1-12) 2024, // Year null, // Reseller username (optional) "example", // Search keyword (optional) "domain" // Search type: "domain", "user", "owner", "ip", "package" ); foreach ($bandwidthData as $account) { echo "User: " . $account['acct'] . "\n"; echo "Bandwidth Used: " . $account['totalbytes'] . " bytes\n"; echo "---\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Get Account Details API Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Retrieve detailed information for a specific cPanel account by providing either the username or the domain name. ```APIDOC ## Get Account Details Retrieve detailed information for a specific account. ### Method ``` GET ``` ### Endpoint ``` /rest/v1/Accounts/details ``` ### Parameters #### Query Parameters - **user** (string) - Optional - The username of the account. - **domain** (string) - Optional - The domain name of the account. *Note: Either `user` or `domain` must be provided.* ### Request Example ```php getDetails("john", null); // Or get details by domain // $account = $accounts->getDetails(null, "example.com"); if ($account) { echo "Username: " . $account->getUser() . "\n"; echo "Domain: " . $account->getDomain() . "\n"; echo "Email: " . $account->getEmail() . "\n"; echo "Plan: " . $account->getPlanName() . "\n"; echo "Owner: " . $account->getOwner() . "\n"; echo "IP Address: " . $account->getIpAddress() . "\n"; echo "Disk Used: " . $account->getDiskUsed() . " MB\n"; echo "Disk Limit: " . $account->getDiskLimit() . " MB\n"; echo "Bandwidth Limit: " . $account->getBandwidthLimit() . " MB\n"; echo "Max FTP: " . $account->getMaxFTP() . "\n"; echo "Max Email: " . $account->getMaxPOP() . "\n"; echo "Max Databases: " . $account->getMaxSQL() . "\n"; echo "Suspended: " . ($account->isSuspended() ? "Yes" : "No") . "\n"; echo "Created: " . $account->getCreatedAt()->format('Y-m-d H:i:s') . "\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` ### Response #### Success Response (200) - **Account** (object) - An object containing detailed information about the cPanel account. - **user** (string) - The username. - **domain** (string) - The primary domain. - **email** (string) - The account's email address. - **plan_name** (string) - The name of the hosting plan. - **owner** (string) - The owner of the account. - **ip_address** (string) - The IP address assigned to the account. - **diskused** (string) - The amount of disk space used (in MB). - **disklimit** (integer) - The disk space limit (in MB). - **bandwidth_limit** (integer) - The bandwidth limit (in MB). - **max_ftp** (integer) - The maximum number of FTP accounts allowed. - **max_pop** (integer) - The maximum number of email accounts allowed. - **max_sql** (integer) - The maximum number of databases allowed. - **suspended** (boolean) - Indicates if the account is suspended. - **created_at** (DateTime) - The date and time the account was created. #### Response Example ```json { "user": "john", "domain": "john.example.com", "email": "john@example.com", "plan_name": "Unlimited Plan", "owner": "root", "ip_address": "192.168.1.100", "diskused": "500", "disklimit": 10240, "bandwidth_limit": 51200, "max_ftp": 5, "max_pop": 10, "max_sql": 5, "suspended": false, "created_at": "2023-01-01 10:00:00" } ``` ``` -------------------------------- ### Get Specific cPanel/WHM Domain User Data with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Retrieves detailed configuration for a specific domain, including server name, user, group, owner, home directory, document root, IP address, and server admin. Requires the PreviewTechs cPanelWHM library. ```php domainDetails("example.com"); if ($domainUser) { echo "Server Name: " . $domainUser->getServerName() . "\n"; echo "User: " . $domainUser->getUser() . "\n"; echo "Group: " . $domainUser->getGroup() . "\n"; echo "Owner: " . $domainUser->getOwner() . "\n"; echo "Home Directory: " . $domainUser->getHomeDirectory() . "\n"; echo "Document Root: " . $domainUser->getDocumentRoot() . "\n"; echo "IP Address: " . $domainUser->getIpAddress() . "\n"; echo "Port: " . $domainUser->getPort() . "\n"; echo "Server Admin: " . $domainUser->getServerAdmin() . "\n"; echo "Server Alias: " . $domainUser->getServerAlias() . "\n"; echo "Has CGI: " . ($domainUser->getHasCGI() ? "Yes" : "No") . "\n"; echo "Script Alias: " . $domainUser->getScriptAlias() . "\n"; echo "Custom Log: " . $domainUser->getCustomLog() . "\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Create New cPanel Account with Resource Limits (PHP) Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Creates a new cPanel account with specified user details and resource limits like disk space, bandwidth, and account quotas. Requires WHM client initialization with API credentials and server details. It throws a ClientExceptions on failure. ```php setUser("newuser"); $newAccount->setDomain("newdomain.com"); $newAccount->setPassword("SecureP@ssw0rd123"); $newAccount->setEmail("admin@newdomain.com"); $newAccount->setPlanName("default"); // Optional: use existing plan $newAccount->setDiskLimit(5000); // MB (use -1 for unlimited) $newAccount->setBandwidthLimit(50000); // MB (use -1 for unlimited) $newAccount->setMaxFTP(10); // -1 for unlimited $newAccount->setMaxSQL(10); // -1 for unlimited $newAccount->setMaxPOP(25); // Email accounts (-1 for unlimited) $newAccount->setMaxSubDomain(10); // -1 for unlimited $newAccount->setMaxAddonDomains(5); // -1 for unlimited $newAccount->setMaxParkedDomains(5); // -1 for unlimited $newAccount->setMaxMailingList(5); // -1 for unlimited $newAccount->setMaxEmailPerHour(100); // -1 for unlimited $newAccount->setCgiEnable(true); $newAccount->setSpamAssassinEnable(true); $newAccount->setFrontPageEnable(false); $newAccount->setLanguagePreference("en"); $newAccount->setMailboxFormat("mdbox"); // or "maildir" try { $result = $accounts->create($newAccount, [ 'featurelist' => "default", // Feature list name 'mxcheck' => "local", // "local", "secondary", "remote", "auto" 'dkim' => 1, // Enable DKIM 'spf' => 1, // Enable SPF 'reseller' => 0 // 1 if reseller account ]); echo "Account created successfully!\n"; echo "Raw output:\n"; print_r($result['raw_output']); } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Account creation failed: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Initialize WHM Client and Search Accounts with PHP Source: https://github.com/previewtechnologies/cpanel-whm-api/blob/master/README.md This PHP code demonstrates how to initialize the WHM client with server credentials and then use it to search for accounts. It requires the Composer autoloader and specific namespaces. ```php searchAccounts()); ``` -------------------------------- ### Configure WHM Client in PHP Source: https://github.com/previewtechnologies/cpanel-whm-api/blob/master/README.md This PHP snippet illustrates the basic configuration required to instantiate the WHM client. You need to provide your WHM username, API token, server hostname or IP, and the WHM port. ```php availableFunctions(); echo "Available API functions:\n"; foreach ($functions as $module => $funcs) { echo "Module: " . $module . "\n"; foreach ($funcs as $func) { echo " - " . $func . "\n"; } } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Search and List cPanel Accounts Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Searches for cPanel accounts based on specified criteria, including pagination and filtering of returned fields. It also shows how to list all accounts without any search parameters. Error handling for API and HTTP exceptions is included. ```php searchAccounts( "john", // Search keyword "user", // Search type: "domain", "owner", "user", "ip", "package" [ 'searchmethod' => "exact", // "exact" or "regex" 'page' => 1, // Page number 'limit' => 25, // Results per page 'want' => "username,domain,diskused,disklimit" // Specific fields to fetch ] ); foreach ($result['accounts'] as $account) { echo "User: " . $account->getUser() . "\n"; echo "Domain: " . $account->getDomain() . "\n"; echo "Disk Used: " . $account->getDiskUsed() . " MB\n"; echo "Disk Limit: " . $account->getDiskLimit() . " MB\n"; echo "---\n"; } echo "Total results: " . $result['count'] . "\n"; echo "Current page: " . $result['page'] . "\n"; // List all accounts without search criteria $allAccounts = $accounts->searchAccounts(); } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } catch (\Http\Client\Exception $e) { echo "HTTP Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Check for .my.cnf File in User's Home Directory Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Verifies the existence of the .my.cnf file in a user's home directory. This file is often used for storing MySQL credentials. Requires WHM client initialization. Outputs whether the file exists or not, or an error message. ```php hasMyCnfInHomeDirectory("username"); if ($hasMyCnf) { echo "User has .my.cnf file in home directory\n"; } else { echo "User does not have .my.cnf file\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### List All cPanel/WHM Users with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Retrieves a list of all cPanel user accounts on the server. This function is useful for auditing or managing user accounts. Requires the PreviewTechs cPanelWHM library. ```php getUsers(); echo "All users on server:\n"; foreach ($users as $username) { echo "- " . $username . "\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Search and List Accounts API Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt This endpoint allows you to search for cPanel accounts using various criteria and supports pagination and filtering for specific fields. ```APIDOC ## Search and List Accounts Search for cPanel accounts with pagination and filters. ### Method ``` POST ``` ### Endpoint ``` /rest/v1/Accounts/search ``` ### Parameters #### Query Parameters - **search** (string) - Optional - The keyword to search for (e.g., username, domain). - **searchtype** (string) - Optional - The type of search: "domain", "owner", "user", "ip", "package". Defaults to "user". - **searchmethod** (string) - Optional - The search method: "exact" or "regex". Defaults to "exact". - **page** (integer) - Optional - The page number for pagination. Defaults to 1. - **limit** (integer) - Optional - The number of results per page. Defaults to 100. - **want** (string) - Optional - A comma-separated list of specific fields to retrieve (e.g., "username,domain,diskused,disklimit"). ### Request Example ```php searchAccounts( "john", // Search keyword "user", // Search type: "domain", "owner", "user", "ip", "package" [ 'searchmethod' => "exact", // "exact" or "regex" 'page' => 1, // Page number 'limit' => 25, // Results per page 'want' => "username,domain,diskused,disklimit" // Specific fields to fetch ] ); foreach ($result['accounts'] as $account) { echo "User: " . $account->getUser() . "\n"; echo "Domain: " . $account->getDomain() . "\n"; echo "Disk Used: " . $account->getDiskUsed() . " MB\n"; echo "Disk Limit: " . $account->getDiskLimit() . " MB\n"; echo "---" . "\n"; } echo "Total results: " . $result['count'] . "\n"; echo "Current page: " . $result['page'] . "\n"; // List all accounts without search criteria $allAccounts = $accounts->searchAccounts(); } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } catch (\Http\Client\Exception $e) { echo "HTTP Error: " . $e->getMessage() . "\n"; } ``` ### Response #### Success Response (200) - **accounts** (array) - An array of Account objects matching the search criteria. - **count** (integer) - The total number of accounts found. - **page** (integer) - The current page number. #### Response Example ```json { "accounts": [ { "user": "john", "domain": "john.example.com", "diskused": "500", "disklimit": "10240" } ], "count": 1, "page": 1 } ``` ``` -------------------------------- ### Change cPanel Account Hosting Plan Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Switches an existing cPanel account to a different hosting plan. This operation modifies the account's resource limits and features. Requires WHM client initialization and the username of the account to modify, along with the target plan name. Outputs the result of the plan change or an error message. ```php changePlan("username", "premium_plan"); echo "Account plan changed successfully!\n"; print_r($result); } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Handle cPanel & WHM API Errors in PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt This snippet demonstrates how to use try-catch blocks to handle various exceptions that may occur when interacting with the cPanel & WHM API using the PHP library. It differentiates between specific API errors, HTTP communication failures, and general exceptions, providing tailored messages for each. ```php getDetails("nonexistent_user"); } catch (ClientExceptions $e) { // Handle WHM API errors (access denied, record not found, invalid arguments) echo "WHM API Error: " . $e->getMessage() . "\n"; // Check exception type if (strpos($e->getMessage(), 'Access denied') !== false) { echo "Authentication failed - check your API token\n"; } elseif (strpos($e->getMessage(), 'not found') !== false) { echo "Resource not found\n"; } } catch (\Http\Client\Exception $e) { // Handle HTTP communication errors echo "HTTP Error: " . $e->getMessage() . "\n"; echo "Check your network connection and server hostname\n"; } catch (\Exception $e) { // Handle other errors echo "Unexpected error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Validate Username Availability for Account Creation Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Checks if a given username is available for creating a new account. This is a crucial step before account provisioning. Requires WHM client initialization. Outputs whether the username is available or an error message if validation fails. ```php validateNewUsername("newusername"); if ($isValid) { echo "Username is available!\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Username validation failed: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Manage Digest Authentication for Web Disk Access Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Checks if digest authentication is enabled for Web Disk access and enables it if disabled. Requires WHM client initialization with API credentials and server details. Outputs the status of digest authentication or success/error messages. ```php hasDigestAuth("username"); if ($hasDigestAuth) { echo "Digest authentication is enabled\n"; } else { echo "Digest authentication is disabled\n"; // Enable digest authentication $accounts->setDigestAuth( "username", "user_password", true // true to enable, false to disable ); echo "Digest authentication enabled successfully!\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Generate cPanel User Session URL Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Creates a one-click login URL for cPanel or Webmail access for a specific user. This is useful for direct access without requiring the user to enter credentials. Requires WHM client initialization, username, service type (e.g., 'cpaneld'), and desired application (e.g., 'home'). Outputs the login URL and session expiration time, or an error message. ```php createUserSession( "username", "cpaneld", // Service: "cpaneld" (cPanel), "webmaild" (Webmail) "home" // App: "home", "email_accounts", "file_manager", etc. ); echo "Login URL: " . $result['data']['url'] . "\n"; echo "Session expires at: " . $result['data']['expires'] . "\n"; } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ?> ``` -------------------------------- ### Retrieve Specific cPanel Account Details Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Retrieves detailed information for a specific cPanel account, either by username or by domain name. The function returns an Account entity object containing comprehensive details about the account's configuration and usage. Includes error handling for API client exceptions. ```php getDetails("john", null); // Or get details by domain // $account = $accounts->getDetails(null, "example.com"); if ($account) { echo "Username: " . $account->getUser() . "\n"; echo "Domain: " . $account->getDomain() . "\n"; echo "Email: " . $account->getEmail() . "\n"; echo "Plan: " . $account->getPlanName() . "\n"; echo "Owner: " . $account->getOwner() . "\n"; echo "IP Address: " . $account->getIpAddress() . "\n"; echo "Disk Used: " . $account->getDiskUsed() . " MB\n"; echo "Disk Limit: " . $account->getDiskLimit() . " MB\n"; echo "Bandwidth Limit: " . $account->getBandwidthLimit() . " MB\n"; echo "Max FTP: " . $account->getMaxFTP() . "\n"; echo "Max Email: " . $account->getMaxPOP() . "\n"; echo "Max Databases: " . $account->getMaxSQL() . "\n"; echo "Suspended: " . ($account->isSuspended() ? "Yes" : "No") . "\n"; echo "Created: " . $account->getCreatedAt()->format('Y-m-d H:i:s') . "\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Modify Existing cPanel Account Settings (PHP) Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Updates settings and resource limits for an existing cPanel account, such as disk quota, bandwidth, and maximum number of POP accounts or FTP accounts. It retrieves the account details first, modifies them, and then applies the changes. Exceptions are caught and reported. ```php getDetails("existinguser"); // Modify properties $account->setDiskLimit(10000); // Increase disk quota to 10GB $account->setBandwidthLimit(-1); // Set unlimited bandwidth $account->setMaxPOP(50); // Increase email accounts $account->setMaxFTP(-1); // Unlimited FTP accounts $account->setMaxSQL(25); // Increase databases $account->setMaxAddonDomains(10); // Apply changes $success = $accounts->modifyAccount($account); if ($success) { echo "Account modified successfully!\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Modification failed: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### List Suspended cPanel Accounts with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Retrieves a list of all suspended cPanel accounts on the server using the WHM API. The function returns details for each suspended account, including username, owner, reason for suspension, lock status, and the suspension timestamp. Requires WHMClient and Accounts. ```php getSuspendedAccounts(); foreach ($suspendedAccounts as $suspended) { echo "User: " . $suspended->getUser() . "\n"; echo "Owner: " . $suspended->getOwner() . "\n"; echo "Reason: " . $suspended->getReason() . "\n"; echo "Locked: " . ($suspended->getIsLocked() ? "Yes" : "No") . "\n"; echo "Suspended at: " . $suspended->getTime()->format('Y-m-d H:i:s') . "\n"; echo "---\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Change cPanel Account Disk Quota (PHP) Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Specifically modifies the disk space allocation for a cPanel account. It takes the username and the new quota in megabytes as parameters. A value of 0 can be used to set unlimited disk space. Errors are handled via exceptions. ```php changeDiskSpaceQuota("username", 15000); echo "Disk quota updated successfully!\n"; } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Suspend and Unsuspend cPanel Accounts with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Allows for suspending and then unsuspending cPanel accounts via the WHM API. When suspending, you can provide a reason and control whether the user can unsuspend their own account. The WHMClient and Accounts classes are required. ```php suspend( "username", "Suspended for policy violation", // Suspension reason true // Disallow unsuspension by user (true/false) ); echo "Account suspended successfully!\n"; // Later: unsuspend account $accounts->unsuspend("username"); echo "Account unsuspended successfully!\n"; } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### List Locked cPanel Accounts with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Fetches a list of all accounts that are currently locked on the cPanel server via the WHM API. This is useful for identifying accounts with restricted access. It utilizes the WHMClient and Accounts classes. ```php getLockedAccounts(); echo "Locked accounts:\n"; foreach ($lockedAccounts as $username) { echo "- " . $username . "\n"; } } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Change cPanel Account Bandwidth Limit (PHP) Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Modifies the bandwidth allocation for a cPanel account. The function accepts the username and the new bandwidth limit in megabytes. Setting the limit to 0 is interpreted as unlimited bandwidth. It returns the result of the operation or an error message. ```php limitBandwidth("username", 100000); echo "Bandwidth limit updated: " . print_r($result, true) . "\n"; } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Force Password Change for cPanel Users with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Forces a password change for specified cPanel users upon their next login using the WHM API. This function allows for batch processing and offers an option to stop the process if any user fails. It requires an array of usernames and a flag to control error handling. Dependencies include WHMClient and Accounts. ```php forcePasswordChange( $usernames, 1 // Stop on failure: 1 = yes, 0 = continue on errors ); echo "Password change forced for users:\n"; print_r($result); } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Change cPanel Account Password with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Updates a cPanel account's password using the WHM API. This function also supports synchronizing the database password and enabling digest authentication. It requires the WHMClient and Accounts classes from the PreviewTechs cPanelWHM library. ```php changePassword( "username", "NewSecureP@ssw0rd456", true, // Enable digest authentication (1) or disable (0), null to skip true // Update database passwords (true/false) ); echo "Password changed successfully!\n"; print_r($result); } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $e) { echo "Error: " . $e->getMessage() . "\n"; } ``` -------------------------------- ### Delete cPanel Account with PHP Source: https://context7.com/previewtechnologies/cpanel-whm-api/llms.txt Removes a cPanel account from the server using the WHM API. This operation can optionally preserve DNS records associated with the account. The function requires the username of the account to be deleted and a boolean flag for keeping DNS. Dependencies include WHMClient and Accounts. ```php remove( "username", false // keepDNS: true to preserve DNS, false to remove ); echo "Account removed successfully!\n"; } catch (\PreviewTechs\cPanelWHM\Exceptions\ClientExceptions $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.