cPanel Hosting Account Helper
Create private PHP tools for everyday cPanel work: email, domains, databases, SSL, FTP users, files, backups, and account checks.
Object signature
new PhpogCpanelUapiClient($config)
Classification
TypeHosting Helper ObjectUsage levelProductionCategories
- Admin Tools
- APIs and Webhooks
- Developer Utilities
Compatibility
Works with cPanel accounts that allow UAPI token access. Use the simple methods for normal hosting jobs, and use rawUapiRequest() when an advanced allowed cPanel feature needs a direct call.
Constructor parameters
HostcPanel server hostname or URL, usually https://example.com:2083.UsernamecPanel account username used in the Authorization header.API tokencPanel API token. Store this outside public web roots and never echo it.PortSecure cPanel API port when the host does not already include a port.Verify TLS certificateWhether cURL verifies TLS certificates. Keep true in production.Retry limitSmall retry count for transient 408, 429, or 5xx or cURL transport failures.When to use it
Build a private cPanel toolUse this when your own admin panel or cron job needs to manage one cPanel account from PHP.Save time on repeat hosting workGood fits include creating mailboxes, adding forwarders, managing subdomains, creating databases, installing SSL files, and checking account features.Keep the code readableCall simple helper methods for common tasks, then use rawUapiRequest() only when you need an advanced cPanel feature.Protect the public siteKeep login checks, CSRF checks, confirmations, and audit logs in your controller before this object runs a real cPanel action.When not to use it
Server-wide WHM workUse the WHM helper instead when the job creates hosting accounts, changes packages, manages server DNS, or restarts services.Public unauthenticated formsDo not connect these methods directly to anonymous forms. cPanel write actions belong behind private admin access.Assuming every feature is enabledcPanel packages, roles, and server settings can block features even when the PHP code is correct.How it works
Add your private connection settingsPass the cPanel host, username, API token, timeout, and retry settings from private config.Call a task methodUse readable methods for common jobs such as email, domains, databases, SSL, FTP, files, and backups.The object talks to cPanelIt sends the request over HTTPS, keeps certificate checks on, and reads the cPanel response.You get a clean resultThe return value uses a consistent success, message, data, and debug shape so controllers stay simple.Advanced calls stay possiblerawUapiRequest() lets experienced users call allowed cPanel UAPI features that do not need a named helper yet.Integration notes
Keep tokens privateLoad host, username, and token values from private config, not browser-visible files.Use POST for changesCreate, delete, password, quota, SSL, database, and file actions should not run from public GET links.Show normal hosting limits clearlyIf cPanel blocks a feature because of package or role limits, show that as a normal admin message instead of a PHP crash.Use raw calls carefullyWhen staff can choose raw calls, place an allow-list around the module and function names.Safety notes
- Never log or display API tokens, mailbox passwords, private keys, certificate bodies, authorization headers, or raw debug payloads containing secrets.
- Use CSRF checks, admin authentication, and account ownership checks before every POST/controller action that calls this object.
- Use cPanel account tokens with the smallest practical feature scope and rotate them when staff or deployment access changes.
- Do not run destructive methods from public GET links. Put destructive actions behind POST-only controllers and confirmation screens.
- Expect cPanel role, profile, or feature-list errors and present them as operational status, not as fatal PHP errors.
Security notes
- The object redacts secret-like keys in debug snapshots, but callers must still avoid writing raw provider responses containing sensitive account data to public logs.
- TLS verification is enabled by default and should remain enabled against production cPanel servers.
- The raw passthrough method intentionally requires explicit module/function names so the calling controller remains responsible for authorization and audit policy.
Code
<?php
/*
* Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
* Free for personal and internal use. Paid project use requires visible credit
* to Jeffery L. Paris. Corporate use requires a paid license fee unless a
* separate written license states otherwise.
*/
/**
* cPanel Hosting Account Helper for private PHP admin tools.
*
* This object helps PHP projects automate common cPanel account tasks such as email, domains, databases, SSL, FTP, files, backups, and account checks while keeping advanced UAPI access available for experienced developers.
*
* Authentication:
* - Create a cPanel API token inside cPanel or through UAPI.
* - Send calls to the cPanel HTTPS port, usually 2083.
* - The Authorization header format is: cpanel username:APITOKEN
*
* Safety notes:
* - Store tokens outside public web roots and never print them to logs.
* - Use HTTPS with certificate verification enabled in production.
* - Validate all caller-owned input before calling destructive methods.
* - cPanel roles, package limits, feature lists, and server profiles can
* disable functions even when this client sends the correct request.
*
* @package PHPOG\Objects
*/
class PhpogCpanelUapiClient {
/**
* Normalized cPanel host, including scheme and optional port.
*
* @var string
*/
protected $host = '';
/**
* cPanel account username.
*
* @var string
*/
protected $username = '';
/**
* cPanel API token. Never expose this value in public output.
*
* @var string
*/
protected $api_token = '';
/**
* Default secure cPanel port.
*
* @var int
*/
protected $port = 2083;
/**
* Request timeout in seconds.
*
* @var int
*/
protected $timeout_seconds = 30;
/**
* Connection timeout in seconds.
*
* @var int
*/
protected $connect_timeout_seconds = 10;
/**
* Whether cURL should verify TLS certificates.
*
* @var bool
*/
protected $verify_peer = true;
/**
* HTTP user agent sent to cPanel.
*
* @var string
*/
protected $user_agent = 'PHPOG cPanel UAPI Client/1.0';
/**
* Whether diagnostic data should include redacted request snapshots.
*
* @var bool
*/
protected $debug = false;
/**
* Maximum automatic retry count for retryable transient failures.
*
* @var int
*/
protected $max_retries = 1;
/**
* Last redacted request snapshot.
*
* @var array
*/
protected $last_request = array();
/**
* Last normalized response snapshot.
*
* @var array
*/
protected $last_response = array();
/**
* Build a cPanel UAPI client.
*
* Recognized config keys: host, username, api_token, port,
* timeout_seconds, connect_timeout_seconds, verify_peer, user_agent,
* debug, and max_retries.
*
* @param array $config Client configuration values.
*/
public function __construct($config = array()) {
if (!is_array($config)) {
$config = array();
}
if (!empty($config['host'])) {
$this->host = $this->normalizeHost($config['host']);
}
if (!empty($config['username'])) {
$this->username = trim((string)$config['username']);
}
if (!empty($config['api_token'])) {
$this->api_token = trim((string)$config['api_token']);
}
if (!empty($config['port'])) {
$this->port = (int)$config['port'];
}
if (!empty($config['timeout_seconds'])) {
$this->timeout_seconds = (int)$config['timeout_seconds'];
}
if (!empty($config['connect_timeout_seconds'])) {
$this->connect_timeout_seconds = (int)$config['connect_timeout_seconds'];
}
if (isset($config['verify_peer'])) {
$this->verify_peer = (bool)$config['verify_peer'];
}
if (!empty($config['user_agent'])) {
$this->user_agent = trim((string)$config['user_agent']);
}
if (isset($config['debug'])) {
$this->debug = (bool)$config['debug'];
}
if (isset($config['max_retries'])) {
$this->max_retries = (int)$config['max_retries'];
if ($this->max_retries < 0) {
$this->max_retries = 0;
}
}
if ($this->port < 1) {
$this->port = 2083;
}
if ($this->timeout_seconds < 1) {
$this->timeout_seconds = 30;
}
if ($this->connect_timeout_seconds < 1) {
$this->connect_timeout_seconds = 10;
}
}
/**
* Set or replace cPanel credentials.
*
* @param string $host cPanel server host or URL.
* @param string $username cPanel account username.
* @param string $api_token cPanel API token.
* @return $this
*/
public function setCredentials($host, $username, $api_token) {
$this->host = $this->normalizeHost($host);
$this->username = trim((string)$username);
$this->api_token = trim((string)$api_token);
return $this;
}
/**
* Set a runtime option without rebuilding the object.
*
* @param string $name Option name.
* @param mixed $value Option value.
* @return $this
*/
public function setOption($name, $value) {
$name = trim((string)$name);
if ($name === 'port') {
$this->port = (int)$value;
} elseif ($name === 'timeout_seconds') {
$this->timeout_seconds = (int)$value;
} elseif ($name === 'connect_timeout_seconds') {
$this->connect_timeout_seconds = (int)$value;
} elseif ($name === 'verify_peer') {
$this->verify_peer = (bool)$value;
} elseif ($name === 'user_agent') {
$this->user_agent = trim((string)$value);
} elseif ($name === 'debug') {
$this->debug = (bool)$value;
} elseif ($name === 'max_retries') {
$this->max_retries = (int)$value;
}
if ($this->port < 1) {
$this->port = 2083;
}
if ($this->timeout_seconds < 1) {
$this->timeout_seconds = 30;
}
if ($this->connect_timeout_seconds < 1) {
$this->connect_timeout_seconds = 10;
}
if ($this->max_retries < 0) {
$this->max_retries = 0;
}
return $this;
}
/**
* Return the last redacted request snapshot.
*
* @return array Last request data with secrets removed.
*/
public function getLastRequest() {
return $this->last_request;
}
/**
* Return the last normalized response snapshot.
*
* @return array Last response data.
*/
public function getLastResponse() {
return $this->last_response;
}
/**
* Call any cPanel UAPI module/function exposed by the target account.
*
* This is the advanced passthrough. Use it for any documented
* UAPI endpoint that does not yet have a named wrapper in this class.
*
* @param string $module UAPI module name, such as Email or Mysql.
* @param string $function UAPI function name, such as list_pops.
* @param array $parameters UAPI query/body parameters.
* @param string $method HTTP method, usually GET or POST.
* @return array Normalized PHPOG result array.
*/
public function request($module, $function, $parameters = array(), $method = 'GET') {
$result = $this->buildResult();
$module = $this->cleanApiName($module);
$function = $this->cleanApiName($function);
$method = strtoupper(trim((string)$method));
if (empty($module) || empty($function)) {
$result['message'] = 'Missing or invalid cPanel UAPI module/function.';
return $result;
}
if ($method !== 'GET' && $method !== 'POST') {
$result['message'] = 'Unsupported HTTP method for cPanel UAPI call.';
return $result;
}
if (!is_array($parameters)) {
$parameters = array();
}
$credential_check = $this->validateCredentials();
if (!$credential_check['success']) {
return $credential_check;
}
$parameters = $this->normalizeParameters($parameters);
$url = $this->buildEndpointUrl($module, $function, $method, $parameters);
$headers = $this->buildHeaders();
$attempt = 0;
$max_attempts = $this->max_retries + 1;
$response = $this->buildResult();
$this->last_request = array(
'module' => $module,
'function' => $function,
'method' => $method,
'url' => $this->redactUrl($url),
'parameters' => $this->redactArray($parameters)
);
while ($attempt < $max_attempts) {
$attempt++;
$response = $this->sendCurlRequest($url, $headers, $parameters, $method);
if (!$this->shouldRetry($response, $attempt, $max_attempts)) {
break;
}
$this->sleepBeforeRetry($response, $attempt);
}
$response['data']['module'] = $module;
$response['data']['function'] = $function;
$response['data']['attempts'] = $attempt;
$this->last_response = $response;
return $response;
}
/**
* Alias for request() to make passthrough intent explicit.
*
* @param string $module UAPI module name.
* @param string $function UAPI function name.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function rawUapiRequest($module, $function, $parameters = array(), $method = 'GET') {
return $this->request($module, $function, $parameters, $method);
}
/**
* Run a documented cPanel Batch::strict request.
*
* The caller supplies the exact Batch parameters because cPanel's batch
* schema can change and complex commands are easier to audit at the call site.
*
* @param array $parameters Batch parameters.
* @return array Normalized PHPOG result array.
*/
public function strictBatch($parameters = array()) {
return $this->request('Batch', 'strict', $parameters, 'GET');
}
/**
* List cPanel email accounts.
*
* @param array $options Optional UAPI parameters, such as domain or regex.
* @return array Normalized PHPOG result array.
*/
public function listEmailAccounts($options = array()) {
return $this->request('Email', 'list_pops', $options);
}
/**
* Create a cPanel email account.
*
* @param string $email Local mailbox name or full address, depending on server policy.
* @param string $domain Mail domain.
* @param string $password Mailbox password.
* @param int $quota Quota in MB where supported. Zero lets cPanel use its default behavior.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createEmailAccount($email, $domain, $password, $quota = 0, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'email' => $email,
'domain' => $domain,
'password' => $password
));
if ((int)$quota > 0) {
$parameters['quota'] = (int)$quota;
}
return $this->request('Email', 'add_pop', $parameters, 'GET');
}
/**
* Delete a cPanel email account.
*
* @param string $email Local mailbox name or full address.
* @param string $domain Mail domain.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteEmailAccount($email, $domain = '', $options = array()) {
$parameters = $this->mergeParameters($options, array('email' => $email));
if (!empty($domain)) {
$parameters['domain'] = $domain;
}
return $this->request('Email', 'delete_pop', $parameters, 'GET');
}
/**
* Change an email account password.
*
* @param string $email Local mailbox name or full address.
* @param string $domain Mail domain.
* @param string $password New password.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function changeEmailPassword($email, $domain, $password, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'email' => $email,
'domain' => $domain,
'password' => $password
));
return $this->request('Email', 'passwd_pop', $parameters, 'GET');
}
/**
* Change an email account quota.
*
* @param string $email Local mailbox name or full address.
* @param string $domain Mail domain.
* @param int $quota Quota in MB where supported.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function changeEmailQuota($email, $domain, $quota, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'email' => $email,
'domain' => $domain,
'quota' => (int)$quota
));
return $this->request('Email', 'edit_pop_quota', $parameters, 'GET');
}
/**
* Suspend or unsuspend an email account login.
*
* @param string $email Local mailbox name or full address.
* @param string $domain Mail domain.
* @param bool $suspend True to suspend, false to unsuspend.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function setEmailLoginSuspension($email, $domain, $suspend = true, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'email' => $email,
'domain' => $domain
));
if ($suspend) {
return $this->request('Email', 'suspend_login', $parameters, 'GET');
}
return $this->request('Email', 'unsuspend_login', $parameters, 'GET');
}
/**
* Suspend or unsuspend incoming mail for an email account.
*
* @param string $email Local mailbox name or full address.
* @param string $domain Mail domain.
* @param bool $suspend True to suspend, false to unsuspend.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function setEmailIncomingSuspension($email, $domain, $suspend = true, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'email' => $email,
'domain' => $domain
));
if ($suspend) {
return $this->request('Email', 'suspend_incoming', $parameters, 'GET');
}
return $this->request('Email', 'unsuspend_incoming', $parameters, 'GET');
}
/**
* Suspend, hold, release, or unsuspend outgoing mail for an email account.
*
* @param string $email Local mailbox name or full address.
* @param string $domain Mail domain.
* @param string $action One of suspend, unsuspend, hold, or release.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function setEmailOutgoingState($email, $domain, $action, $options = array()) {
$action = strtolower(trim((string)$action));
$parameters = $this->mergeParameters($options, array(
'email' => $email,
'domain' => $domain
));
if ($action === 'unsuspend') {
return $this->request('Email', 'unsuspend_outgoing', $parameters, 'GET');
} elseif ($action === 'hold') {
return $this->request('Email', 'hold_outgoing', $parameters, 'GET');
} elseif ($action === 'release') {
return $this->request('Email', 'release_outgoing', $parameters, 'GET');
}
return $this->request('Email', 'suspend_outgoing', $parameters, 'GET');
}
/**
* List email forwarders.
*
* @param string $domain Optional domain filter.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listForwarders($domain = '', $options = array()) {
$parameters = $this->mergeParameters($options, array());
if (!empty($domain)) {
$parameters['domain'] = $domain;
}
return $this->request('Email', 'list_forwarders', $parameters, 'GET');
}
/**
* Create an email forwarder.
*
* @param string $domain Source domain.
* @param string $email Source local part or address.
* @param string $destination Destination address or cPanel-supported routing value.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createForwarder($domain, $email, $destination, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'domain' => $domain,
'email' => $email,
'fwdopt' => 'fwd',
'fwdemail' => $destination
));
return $this->request('Email', 'add_forwarder', $parameters, 'GET');
}
/**
* Delete an email forwarder.
*
* @param string $address Source address.
* @param string $destination Destination address where required by the server.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteForwarder($address, $destination = '', $options = array()) {
$parameters = $this->mergeParameters($options, array('address' => $address));
if (!empty($destination)) {
$parameters['forwarder'] = $destination;
$parameters['fwdemail'] = $destination;
}
return $this->request('Email', 'delete_forwarder', $parameters, 'GET');
}
/**
* List email autoresponders.
*
* @param string $domain Domain filter.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listAutoresponders($domain = '', $options = array()) {
$parameters = $this->mergeParameters($options, array());
if (!empty($domain)) {
$parameters['domain'] = $domain;
}
return $this->request('Email', 'list_auto_responders', $parameters, 'GET');
}
/**
* Create an email autoresponder with caller-supplied cPanel fields.
*
* @param array $parameters UAPI autoresponder parameters.
* @return array Normalized PHPOG result array.
*/
public function createAutoresponder($parameters = array()) {
return $this->request('Email', 'add_auto_responder', $parameters, 'GET');
}
/**
* Delete an email autoresponder.
*
* @param string $email Email account/local part.
* @param string $domain Mail domain.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteAutoresponder($email, $domain, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'email' => $email,
'domain' => $domain
));
return $this->request('Email', 'delete_auto_responder', $parameters, 'GET');
}
/**
* List domains attached to the cPanel account.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listDomains($options = array()) {
return $this->request('DomainInfo', 'list_domains', $options, 'GET');
}
/**
* Return detailed domain hosting data for the cPanel account.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function getDomainsData($options = array()) {
return $this->request('DomainInfo', 'domains_data', $options, 'GET');
}
/**
* Create a subdomain.
*
* @param string $domain Subdomain label.
* @param string $root_domain Root domain.
* @param string $document_root Optional document root relative to the account home.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createSubdomain($domain, $root_domain, $document_root = '', $options = array()) {
$parameters = $this->mergeParameters($options, array(
'domain' => $domain,
'rootdomain' => $root_domain
));
if (!empty($document_root)) {
$parameters['dir'] = $document_root;
}
return $this->request('SubDomain', 'addsubdomain', $parameters, 'GET');
}
/**
* Delete a subdomain.
*
* @param string $domain Full subdomain or cPanel subdomain value.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteSubdomain($domain, $options = array()) {
$parameters = $this->mergeParameters($options, array('domain' => $domain));
return $this->request('SubDomain', 'delsubdomain', $parameters, 'GET');
}
/**
* List subdomains.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listSubdomains($options = array()) {
return $this->request('SubDomain', 'listsubdomains', $options, 'GET');
}
/**
* Create a MySQL or MariaDB database.
*
* @param string $name Database name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createDatabase($name, $options = array()) {
$parameters = $this->mergeParameters($options, array('name' => $name));
return $this->request('Mysql', 'create_database', $parameters, 'GET');
}
/**
* Delete a MySQL or MariaDB database.
*
* @param string $name Database name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteDatabase($name, $options = array()) {
$parameters = $this->mergeParameters($options, array('name' => $name));
return $this->request('Mysql', 'delete_database', $parameters, 'GET');
}
/**
* List MySQL or MariaDB databases.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listDatabases($options = array()) {
return $this->request('Mysql', 'list_databases', $options, 'GET');
}
/**
* Rename a database using cPanel's documented rename workflow.
*
* @param string $old_name Current database name.
* @param string $new_name New database name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function renameDatabase($old_name, $new_name, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'oldname' => $old_name,
'newname' => $new_name
));
return $this->request('Mysql', 'rename_database', $parameters, 'GET');
}
/**
* Check database integrity.
*
* @param string $name Database name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function checkDatabase($name, $options = array()) {
$parameters = $this->mergeParameters($options, array('name' => $name));
return $this->request('Mysql', 'check_database', $parameters, 'GET');
}
/**
* Repair database tables through cPanel where supported.
*
* @param string $name Database name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function repairDatabase($name, $options = array()) {
$parameters = $this->mergeParameters($options, array('name' => $name));
return $this->request('Mysql', 'repair_database', $parameters, 'GET');
}
/**
* Create a MySQL user.
*
* @param string $name User name.
* @param string $password User password.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createDatabaseUser($name, $password, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'name' => $name,
'password' => $password
));
return $this->request('Mysql', 'create_user', $parameters, 'GET');
}
/**
* Delete a MySQL user.
*
* @param string $name User name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteDatabaseUser($name, $options = array()) {
$parameters = $this->mergeParameters($options, array('name' => $name));
return $this->request('Mysql', 'delete_user', $parameters, 'GET');
}
/**
* Update MySQL user privileges on a database.
*
* @param string $user Database user.
* @param string $database Database name.
* @param string $privileges Comma-separated privilege string or cPanel-supported value.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function updateDatabasePrivileges($user, $database, $privileges, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'user' => $user,
'database' => $database,
'privileges' => $privileges
));
return $this->request('Mysql', 'update_privileges', $parameters, 'GET');
}
/**
* Create a randomly named database and user set where cPanel supports it.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function setupDatabaseAndUser($options = array()) {
return $this->request('Mysql', 'setup_db_and_user', $options, 'GET');
}
/**
* List SSL certificates stored for the cPanel account.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listSslCertificates($options = array()) {
return $this->request('SSL', 'list_certs', $options, 'GET');
}
/**
* Install SSL certificate material for a domain where the account has permission.
*
* @param string $domain Domain name.
* @param string $certificate Certificate text.
* @param string $private_key Private key text.
* @param string $cabundle Optional CA bundle.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function installSsl($domain, $certificate, $private_key, $cabundle = '', $options = array()) {
$parameters = $this->mergeParameters($options, array(
'domain' => $domain,
'cert' => $certificate,
'key' => $private_key
));
if (!empty($cabundle)) {
$parameters['cabundle'] = $cabundle;
}
return $this->request('SSL', 'install_ssl', $parameters, 'POST');
}
/**
* Delete an SSL certificate from cPanel storage where supported.
*
* @param string $id Certificate ID or cPanel-supported lookup value.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteSslCertificate($id, $options = array()) {
$parameters = $this->mergeParameters($options, array('id' => $id));
return $this->request('SSL', 'delete_cert', $parameters, 'GET');
}
/**
* Ask cPanel for the best SSL common name for a domain/service.
*
* @param string $domain Domain name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function getBestSslCommonName($domain, $options = array()) {
$parameters = $this->mergeParameters($options, array('domain' => $domain));
return $this->request('SSL', 'get_cn_name', $parameters, 'GET');
}
/**
* List FTP accounts.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listFtpAccounts($options = array()) {
return $this->request('Ftp', 'list_ftp', $options, 'GET');
}
/**
* Create an FTP account.
*
* @param string $user FTP username.
* @param string $password FTP password.
* @param string $homedir Home directory relative to the account root.
* @param int $quota Quota where supported.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createFtpAccount($user, $password, $homedir, $quota = 0, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'user' => $user,
'pass' => $password,
'homedir' => $homedir
));
if ((int)$quota > 0) {
$parameters['quota'] = (int)$quota;
}
return $this->request('Ftp', 'add_ftp', $parameters, 'GET');
}
/**
* Delete an FTP account.
*
* @param string $user FTP username.
* @param bool $destroy_home Whether cPanel should remove home directory content where supported.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteFtpAccount($user, $destroy_home = false, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'user' => $user,
'destroy' => $this->boolToCpanel($destroy_home)
));
return $this->request('Ftp', 'delete_ftp', $parameters, 'GET');
}
/**
* List files with cPanel Fileman where exposed to the account.
*
* @param string $dir Directory path.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listFiles($dir, $options = array()) {
$parameters = $this->mergeParameters($options, array('dir' => $dir));
return $this->request('Fileman', 'list_files', $parameters, 'GET');
}
/**
* Create a directory with cPanel Fileman where exposed to the account.
*
* @param string $path Parent path.
* @param string $name Directory name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createDirectory($path, $name, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'path' => $path,
'name' => $name
));
return $this->request('Fileman', 'mkdir', $parameters, 'GET');
}
/**
* Request cPanel backup information or backup creation through the Backup module.
*
* @param string $function Backup module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function backupRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('Backup', $function, $parameters, $method);
}
/**
* Return cPanel account resource usage where supported by the server.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function getResourceUsage($options = array()) {
return $this->request('ResourceUsage', 'get_usages', $options, 'GET');
}
/**
* List cPanel API tokens.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listApiTokens($options = array()) {
return $this->request('Tokens', 'list', $options, 'GET');
}
/**
* Create a full-access cPanel API token where account policy allows it.
*
* @param string $name Token name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createFullAccessApiToken($name, $options = array()) {
$parameters = $this->mergeParameters($options, array('name' => $name));
return $this->request('Tokens', 'create_full_access', $parameters, 'GET');
}
/**
* Revoke a cPanel API token where account policy allows it.
*
* @param string $name Token name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function revokeApiToken($name, $options = array()) {
$parameters = $this->mergeParameters($options, array('name' => $name));
return $this->request('Tokens', 'revoke', $parameters, 'GET');
}
/**
* Create a dynamic DNS domain.
*
* @param array $parameters UAPI DynamicDNS parameters.
* @return array Normalized PHPOG result array.
*/
public function createDynamicDns($parameters = array()) {
return $this->request('DynamicDNS', 'create', $parameters, 'GET');
}
/**
* Delete a dynamic DNS domain.
*
* @param array $parameters UAPI DynamicDNS parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteDynamicDns($parameters = array()) {
return $this->request('DynamicDNS', 'delete', $parameters, 'GET');
}
/**
* List dynamic DNS domains.
*
* @param array $parameters UAPI DynamicDNS parameters.
* @return array Normalized PHPOG result array.
*/
public function listDynamicDns($parameters = array()) {
return $this->request('DynamicDNS', 'list', $parameters, 'GET');
}
/**
* Check whether the account has a named cPanel feature enabled.
*
* This is useful before rendering UI controls for mail, FTP, MySQL,
* SSL, subdomain, or file-management actions that may be disabled by
* account package, feature list, role, or server profile.
*
* @param string $feature cPanel feature name.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function hasFeature($feature, $options = array()) {
$parameters = $this->mergeParameters($options, array('feature' => $feature));
return $this->request('Features', 'has_feature', $parameters, 'GET');
}
/**
* Call a cPanel Features UAPI function.
*
* @param string $function Features module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function featureRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('Features', $function, $parameters, $method);
}
/**
* Call a cPanel Email UAPI function directly.
*
* Use this for email filters, domain forwarders, mail-domain discovery,
* default-address settings, mailing features, or new Email module
* functions added after this object was published.
*
* @param string $function Email module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function emailRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('Email', $function, $parameters, $method);
}
/**
* List domains that are available for mail-account operations.
*
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listMailDomains($options = array()) {
return $this->request('Email', 'list_mail_domains', $options, 'GET');
}
/**
* Configure the default address for a domain.
*
* @param string $domain Domain name.
* @param string $destination cPanel-supported destination value.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function setDefaultAddress($domain, $destination, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'domain' => $domain,
'fwdopt' => 'fwd',
'fwdemail' => $destination
));
return $this->request('Email', 'set_default_address', $parameters, 'GET');
}
/**
* Create a domain-level forwarder.
*
* @param string $domain Source domain.
* @param string $destination Destination domain or address accepted by cPanel.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function createDomainForwarder($domain, $destination, $options = array()) {
$parameters = $this->mergeParameters($options, array(
'domain' => $domain,
'destdomain' => $destination
));
return $this->request('Email', 'add_domain_forwarder', $parameters, 'GET');
}
/**
* Delete a domain-level forwarder.
*
* @param string $domain Source domain.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteDomainForwarder($domain, $options = array()) {
$parameters = $this->mergeParameters($options, array('domain' => $domain));
return $this->request('Email', 'delete_domain_forwarder', $parameters, 'GET');
}
/**
* Call a cPanel UserManager UAPI function.
*
* UserManager is cPanel's preferred path for some subaccount and service
* account operations. Pass the exact documented parameter set for the
* target server version.
*
* @param string $function UserManager module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function userManagerRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('UserManager', $function, $parameters, $method);
}
/**
* Create a cPanel subaccount with caller-supplied UserManager fields.
*
* @param array $parameters Exact UserManager::create_user parameters.
* @return array Normalized PHPOG result array.
*/
public function createSubaccount($parameters = array()) {
return $this->request('UserManager', 'create_user', $parameters, 'GET');
}
/**
* List cPanel subaccounts/users where UserManager exposes the function.
*
* @param array $parameters UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function listSubaccounts($parameters = array()) {
return $this->request('UserManager', 'list_users', $parameters, 'GET');
}
/**
* Delete a cPanel subaccount/user.
*
* @param string $username Subaccount username.
* @param string $domain Subaccount domain.
* @param array $options Additional UAPI parameters.
* @return array Normalized PHPOG result array.
*/
public function deleteSubaccount($username, $domain = '', $options = array()) {
$parameters = $this->mergeParameters($options, array('username' => $username));
if (!empty($domain)) {
$parameters['domain'] = $domain;
}
return $this->request('UserManager', 'delete_user', $parameters, 'GET');
}
/**
* Call a mailing-list UAPI function.
*
* Mailing-list endpoint names and availability vary by cPanel version and
* account feature list, so this grouped wrapper keeps calls explicit.
*
* @param string $function MailingLists module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function mailingListRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('MailingLists', $function, $parameters, $method);
}
/**
* Call a domain-redirection UAPI function.
*
* @param string $function Mime/Redirects-compatible function name.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function redirectRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('Mime', $function, $parameters, $method);
}
/**
* Call a cPanel Mysql UAPI function directly.
*
* @param string $function Mysql module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function mysqlRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('Mysql', $function, $parameters, $method);
}
/**
* Call a cPanel SSL UAPI function directly.
*
* @param string $function SSL module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function sslRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('SSL', $function, $parameters, $method);
}
/**
* Call a cPanel FTP UAPI function directly.
*
* @param string $function Ftp module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function ftpRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('Ftp', $function, $parameters, $method);
}
/**
* Call a cPanel Fileman UAPI function directly.
*
* @param string $function Fileman module function.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function filemanRequest($function, $parameters = array(), $method = 'GET') {
return $this->request('Fileman', $function, $parameters, $method);
}
/**
* Call a DNS-related UAPI function.
*
* cPanel's DNS feature surface is version-sensitive. Use this method for
* DNS, DNSSEC, EmailAuth, ZoneEdit-compatible, or provider-specific module
* calls after checking the target server's cPanel documentation/version.
*
* @param string $module DNS-related module name.
* @param string $function UAPI function name.
* @param array $parameters UAPI parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
public function dnsRequest($module, $function, $parameters = array(), $method = 'GET') {
return $this->request($module, $function, $parameters, $method);
}
/**
* Merge default parameters with caller options.
*
* Caller options win so a controller can adapt to provider-specific cPanel
* behavior without modifying this object.
*
* @param array $options Caller parameters.
* @param array $defaults Default parameters.
* @return array Merged parameters.
*/
protected function mergeParameters($options, $defaults) {
if (!is_array($options)) {
$options = array();
}
if (!is_array($defaults)) {
$defaults = array();
}
foreach ($options as $key => $value) {
$defaults[$key] = $value;
}
return $defaults;
}
/**
* Build a standard PHPOG result array.
*
* @return array Standard result.
*/
protected function buildResult() {
return array(
'success' => false,
'message' => '',
'data' => array()
);
}
/**
* Validate required credentials before an outbound API call.
*
* @return array Standard result.
*/
protected function validateCredentials() {
$result = $this->buildResult();
if (empty($this->host)) {
$result['message'] = 'Missing cPanel host.';
return $result;
}
if (empty($this->username)) {
$result['message'] = 'Missing cPanel username.';
return $result;
}
if (empty($this->api_token)) {
$result['message'] = 'Missing cPanel API token.';
return $result;
}
$result['success'] = true;
$result['message'] = 'Credentials are present.';
return $result;
}
/**
* Normalize a host string into a safe HTTPS origin.
*
* @param string $host User-supplied cPanel host.
* @return string Normalized host.
*/
protected function normalizeHost($host) {
$host = trim((string)$host);
$host = str_replace("\0", '', $host);
if (empty($host)) {
return '';
}
if (strpos($host, 'https://') !== 0 && strpos($host, 'http://') !== 0) {
$host = 'https://'.$host;
}
$parts = parse_url($host);
if (empty($parts) || empty($parts['host'])) {
return '';
}
$scheme = 'https';
if (!empty($parts['scheme']) && strtolower($parts['scheme']) === 'http') {
$scheme = 'http';
}
$normalized = $scheme.'://'.$parts['host'];
if (!empty($parts['port'])) {
$normalized .= ':'.(int)$parts['port'];
}
return rtrim($normalized, '/');
}
/**
* Clean module and function names to the UAPI-safe token format.
*
* @param string $name UAPI module or function name.
* @return string Clean name.
*/
protected function cleanApiName($name) {
$name = trim((string)$name);
$name = preg_replace('/[^A-Za-z0-9_]/', '', $name);
return $name;
}
/**
* Convert booleans, arrays, and scalar values for cPanel request transport.
*
* @param array $parameters Caller parameters.
* @return array Normalized parameters.
*/
protected function normalizeParameters($parameters) {
$normalized = array();
foreach ($parameters as $key => $value) {
$key = trim((string)$key);
if ($key === '') {
continue;
}
if (is_bool($value)) {
$normalized[$key] = $this->boolToCpanel($value);
} elseif (is_array($value)) {
$encoded = json_encode($value);
if ($encoded === false) {
$encoded = '[]';
}
$normalized[$key] = $encoded;
} elseif ($value === null) {
$normalized[$key] = '';
} else {
$normalized[$key] = (string)$value;
}
}
return $normalized;
}
/**
* Convert a PHP boolean to cPanel's documented 1/0 boolean format.
*
* @param bool $value Boolean value.
* @return int cPanel boolean value.
*/
protected function boolToCpanel($value) {
if ($value) {
return 1;
}
return 0;
}
/**
* Build the full cPanel UAPI endpoint URL.
*
* @param string $module UAPI module.
* @param string $function UAPI function.
* @param string $method HTTP method.
* @param array $parameters Request parameters.
* @return string Endpoint URL.
*/
protected function buildEndpointUrl($module, $function, $method, $parameters) {
$host = $this->host;
$parts = parse_url($host);
if (!empty($parts) && empty($parts['port'])) {
$host .= ':'.$this->port;
}
$url = rtrim($host, '/').'/execute/'.$module.'/'.$function;
if ($method === 'GET' && !empty($parameters)) {
$url .= '?'.http_build_query($parameters, '', '&');
}
return $url;
}
/**
* Build cPanel API token headers.
*
* @return array HTTP headers.
*/
protected function buildHeaders() {
return array(
'Authorization: cpanel '.$this->username.':'.$this->api_token,
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'User-Agent: '.$this->user_agent
);
}
/**
* Send a cURL request and normalize transport-level errors.
*
* @param string $url Endpoint URL.
* @param array $headers HTTP headers.
* @param array $parameters Request parameters.
* @param string $method HTTP method.
* @return array Normalized PHPOG result array.
*/
protected function sendCurlRequest($url, $headers, $parameters, $method) {
$result = $this->buildResult();
if (!function_exists('curl_init')) {
$result['message'] = 'The PHP cURL extension is not available.';
return $result;
}
$curl = curl_init();
if (!$curl) {
$result['message'] = 'Unable to initialize cURL.';
return $result;
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->connect_timeout_seconds);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout_seconds);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verify_peer);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verify_peer ? 2 : 0);
if ($method === 'POST') {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($parameters, '', '&'));
}
$body = curl_exec($curl);
$curl_error = curl_error($curl);
$curl_errno = curl_errno($curl);
$http_code = (int)curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$content_type = (string)curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
curl_close($curl);
if ($body === false) {
$result['message'] = 'cPanel UAPI transport error.';
$result['data'] = array(
'http_code' => $http_code,
'curl_errno' => $curl_errno,
'curl_error' => $curl_error
);
return $result;
}
return $this->normalizeResponse($body, $http_code, $content_type);
}
/**
* Normalize a cPanel UAPI response into the PHPOG result shape.
*
* @param string $body Raw response body.
* @param int $http_code HTTP status code.
* @param string $content_type Response content type.
* @return array Normalized PHPOG result array.
*/
protected function normalizeResponse($body, $http_code, $content_type) {
$result = $this->buildResult();
$decoded = json_decode((string)$body, true);
$json_error = json_last_error();
$result['data'] = array(
'http_code' => $http_code,
'content_type' => $content_type,
'raw_body' => ''
);
if ($json_error !== JSON_ERROR_NONE || !is_array($decoded)) {
$result['message'] = 'cPanel UAPI returned a non-JSON or invalid JSON response.';
$result['data']['raw_body'] = substr((string)$body, 0, 2000);
return $result;
}
$result['data']['response'] = $decoded;
if ($http_code < 200 || $http_code >= 300) {
$result['message'] = 'cPanel UAPI returned an HTTP error.';
return $result;
}
if (isset($decoded['result']) && is_array($decoded['result'])) {
$uapi_result = $decoded['result'];
$status = 0;
if (isset($uapi_result['status'])) {
$status = (int)$uapi_result['status'];
}
$result['data']['uapi_status'] = $status;
if (!empty($uapi_result['data'])) {
$result['data']['uapi_data'] = $uapi_result['data'];
}
if (!empty($uapi_result['errors'])) {
$result['data']['errors'] = $uapi_result['errors'];
}
if (!empty($uapi_result['messages'])) {
$result['data']['messages'] = $uapi_result['messages'];
}
if ($status === 1) {
$result['success'] = true;
$result['message'] = 'cPanel UAPI request completed.';
return $result;
}
$result['message'] = $this->extractErrorMessage($uapi_result);
return $result;
}
$result['success'] = true;
$result['message'] = 'cPanel UAPI HTTP request completed.';
return $result;
}
/**
* Extract a public-safe error message from a UAPI result array.
*
* @param array $uapi_result UAPI result node.
* @return string Error message.
*/
protected function extractErrorMessage($uapi_result) {
if (!is_array($uapi_result)) {
return 'cPanel UAPI request failed.';
}
if (!empty($uapi_result['errors'])) {
if (is_array($uapi_result['errors'])) {
return implode(' ', array_map('strval', $uapi_result['errors']));
}
return (string)$uapi_result['errors'];
}
if (!empty($uapi_result['messages'])) {
if (is_array($uapi_result['messages'])) {
return implode(' ', array_map('strval', $uapi_result['messages']));
}
return (string)$uapi_result['messages'];
}
return 'cPanel UAPI request failed.';
}
/**
* Determine whether a failed request should be retried.
*
* @param array $response Normalized response.
* @param int $attempt Current attempt count.
* @param int $max_attempts Maximum attempts.
* @return bool True when another attempt should be made.
*/
protected function shouldRetry($response, $attempt, $max_attempts) {
if ($attempt >= $max_attempts) {
return false;
}
if (!is_array($response) || !empty($response['success'])) {
return false;
}
$http_code = 0;
if (!empty($response['data']['http_code'])) {
$http_code = (int)$response['data']['http_code'];
}
if (in_array($http_code, array(408, 425, 429, 500, 502, 503, 504), true)) {
return true;
}
if (!empty($response['data']['curl_errno'])) {
return true;
}
return false;
}
/**
* Pause briefly before retrying a transient cPanel call.
*
* @param array $response Normalized response.
* @param int $attempt Current attempt count.
* @return void
*/
protected function sleepBeforeRetry($response, $attempt) {
$delay = (int)pow(2, max(0, (int)$attempt - 1));
if ($delay < 1) {
$delay = 1;
}
if ($delay > 5) {
$delay = 5;
}
sleep($delay);
}
/**
* Redact sensitive query values from a URL.
*
* @param string $url URL to redact.
* @return string Redacted URL.
*/
protected function redactUrl($url) {
$parts = parse_url((string)$url);
if (empty($parts) || empty($parts['query'])) {
return (string)$url;
}
parse_str($parts['query'], $query);
$query = $this->redactArray($query);
$redacted = '';
if (!empty($parts['scheme'])) {
$redacted .= $parts['scheme'].'://';
}
if (!empty($parts['host'])) {
$redacted .= $parts['host'];
}
if (!empty($parts['port'])) {
$redacted .= ':'.$parts['port'];
}
if (!empty($parts['path'])) {
$redacted .= $parts['path'];
}
$redacted .= '?'.http_build_query($query, '', '&');
return $redacted;
}
/**
* Redact sensitive values from debug arrays.
*
* @param array $values Values to redact.
* @return array Redacted values.
*/
protected function redactArray($values) {
if (!is_array($values)) {
return array();
}
$redacted = array();
foreach ($values as $key => $value) {
$key_string = strtolower((string)$key);
if ($this->isSensitiveKey($key_string)) {
$redacted[$key] = '[redacted]';
} elseif (is_array($value)) {
$redacted[$key] = $this->redactArray($value);
} else {
$redacted[$key] = $value;
}
}
return $redacted;
}
/**
* Determine whether a key is likely to contain a secret.
*
* @param string $key Lowercase key name.
* @return bool True when the key should be redacted.
*/
protected function isSensitiveKey($key) {
$sensitive_fragments = array(
'pass',
'password',
'token',
'secret',
'key',
'authorization',
'auth',
'cert',
'cabundle'
);
foreach ($sensitive_fragments as $fragment) {
if (strpos($key, $fragment) !== false) {
return true;
}
}
return false;
}
}