Technical Documentation v1.0.0 WHMCS 9.1.x · PHP 8.2–8.4

Haikhavan cPanel Extended & Quota Guard

Complete architecture reference, installation guide, database schema, hooks, and troubleshooting.

Quick Installation

  1. Purchase the module and download haikhavan_cpanel_extended-ioncube-8.2-1.0.0-install.zip from your VPSrv Client Area Downloads.
  2. Upload and extract the ZIP into your WHMCS root directory so files land in modules/addons/haikhavan_cpanel_extended/ and modules/servers/haikhavan_cpanel_extended/.
  3. Verify PHP 8.2–8.4 with ionCube PHP Loader 14+ / 15.5+ is enabled on your server.
  4. Go to System Settings → Addon Modules in WHMCS Admin, click Activate next to Haikhavan cPanel Extended & Quota Guard, and assign administrator role access.

Module Slug: haikhavan_cpanel_extended
Version: 1.0.0
Namespace: Haikhavan\CpanelExtended\
Components: Dual Server Provisioning Module (modules/servers/haikhavan_cpanel_extended/) + Companion Addon (modules/addons/haikhavan_cpanel_extended/)


1. Architecture & File Inventory

modules/
├── servers/haikhavan_cpanel_extended/
│   ├── whmcs.json                         # WHMCS whmcs-servers schema 1.0 manifest
│   ├── haikhavan_cpanel_extended.php             # Server provisioning callbacks (MetaData, ConfigOptions, TestConnection, Create/Suspend/Unsuspend/Terminate, ChangePackage, ChangePassword, AdminCustomButtonArray, UsageUpdate, SSO, ClientArea)
│   └── templates/overview.tpl             # Embedded Product Details ClientArea template
└── addons/haikhavan_cpanel_extended/
    ├── whmcs.json                         # WHMCS whmcs-addons schema 1.0 manifest
    ├── haikhavan_cpanel_extended.php             # Addon entry point (_config, _activate, _deactivate, _upgrade, _output, _clientarea)
    ├── hooks.php                          # 6 WHMCS hooks (Navbar, Sidebar, Admin Services Tab, Admin Home Widget, DailyCronJob, AfterModuleCreate)
    ├── lib/
    │   ├── Database.php                   # 7-table Capsule schema installer, AES-256-CBC+HMAC token encryption, state & audit helpers
    │   ├── WhmApiClient.php               # WHM API v1 / cPanel UAPI HTTP client + complete Sandbox Simulator
    │   ├── QuotaGuardService.php          # 75%/90%/98% Quota Notifications Engine, 6-check Security Hygiene Auditor, Auto-Harden & Fleet Overview
    │   ├── AdminController.php            # CSRF-guarded Admin Fleet & Quota Guard SPA controller
    │   └── ClientController.php           # CSRF-guarded Embedded cPanel Workbench & UAPI AJAX controller
    ├── templates/
    │   ├── admin/dashboard.php            # 5-tab Admin Fleet Load, Accounts, Quota Guard, WHM Servers, Backups & Audit UI
    │   └── client/panel.tpl               # 9-tab Embedded Client Area cPanel Workbench Smarty template
    └── assets/
        ├── css/haikhavan_cpanel_extended.css     # Scoped zero-CDN stylesheet (.hkcp-*)
        └── js/haikhavan_cpanel_extended.js       # Zero-CDN High-DPI Canvas Fleet Bandwidth & Multi-Server Node Load charts

Dual-Module Coexistence Design: Because PHP function names are case-insensitive and both the server module (haikhavan_cpanel_extended_ClientArea) and addon module (haikhavan_cpanel_extended_clientarea) share the slug haikhavan_cpanel_extended, both entry points guard declaration with if (!function_exists(...)) and inspect isset($params['serviceid']) to dispatch cleanly whether WHMCS loads one or both files in the same PHP process.


2. Database Schema (mod_hk_cp_*)

Table Purpose Key Columns & Indexes
mod_hk_cp_servers Multi-server WHM fleet inventory & telemetry id PK, whmcs_server_id INDEX, name, hostname, ip_address, port (2087), username, api_token_encrypted (AES-256-CBC+HMAC), load_1m, load_5m, cpu_pct, ram_pct, disk_used_gb, disk_total_gb, accounts_count, whm_version, status
mod_hk_cp_accounts Managed cPanel accounts linked to Haikhavan id PK, service_id UNIQUE, client_id INDEX, server_id INDEX, domain INDEX, username INDEX, package_name, status, disk_used_mb/disk_limit_mb, bw_used_mb/bw_limit_mb, inodes_used/inodes_limit, emails_used/emails_limit, php_version, php_ini_json, autossl_status, ssl_expiry_date, security_score, security_report_json, state_json
mod_hk_cp_quota_rules Hosting Quota Notifications rules id PK, name, metric INDEX (disk|bandwidth|inodes|email), warn_pct (75), high_pct (90), critical_pct (98), notify_email, open_ticket, auto_suspend_at_critical, upgrade_cta_label, cooldown_hours, enabled INDEX
mod_hk_cp_quota_alerts Triggered quota notifications & resolution state id BIGINT PK, account_id INDEX, service_id INDEX, client_id INDEX, rule_id, metric INDEX, level (warning|high|critical), used_pct, used_label, limit_label, status INDEX, message, triggered_at
mod_hk_cp_quota_history Daily quota & load snapshots (UNIQUE(account_id, recorded_date)) account_id, service_id, recorded_date, disk_used_mb, bw_used_mb, inodes_used, emails_used, load_avg
mod_hk_cp_backups On-demand & scheduled account backup snapshots id PK, account_id INDEX, service_id INDEX, client_id INDEX, backup_type (full|homedir|mysql|email), filename, size_mb, status, created_at
mod_hk_cp_audit_log Immutable operational & security audit log id BIGINT PK, admin_id, client_id, service_id, action INDEX, status, summary, details_json, ip_address, created_at

3. Server Module Callbacks (modules/servers/haikhavan_cpanel_extended/haikhavan_cpanel_extended.php)

  • haikhavan_cpanel_extended_MetaData() — APIVersion 1.1, ports 2086/2087, Service & Admin SSO labels.
  • haikhavan_cpanel_extended_ConfigOptions() — Package, Disk MB, Bandwidth MB, Inodes, Max Emails, Default PHP, AutoSSL, App Installer.
  • haikhavan_cpanel_extended_TestConnection($params) — WHM API v1 version ping (or Sandbox verification).
  • haikhavan_cpanel_extended_CreateAccount / SuspendAccount / UnsuspendAccount / TerminateAccount / ChangePackage / ChangePassword — Full WHM lifecycle + local mod_hk_cp_accounts synchronization.
  • haikhavan_cpanel_extended_AdminCustomButtonArray() — Run Quota Scan, Security Hygiene Audit, On-Demand Backup, Renew AutoSSL.
  • haikhavan_cpanel_extended_UsageUpdate($params) — Updates WHMCS tblhosting.diskusage/disklimit/bwusage/bwlimit and runs QuotaGuardService::evaluateAccount().
  • haikhavan_cpanel_extended_ServiceSingleSignOn / AdminSingleSignOn — WHM create_user_session / Sandbox SSO redirect.
  • haikhavan_cpanel_extended_ClientArea($params) — Returns tabOverviewReplacementTemplate => templates/overview.tpl embedding the full 9-tab cPanel workbench natively inside Product Details.

4. Quota Guard Engine & Security Hygiene Scoring

4.1 Hosting Quota Notifications (QuotaGuardService::evaluateAccount)

Evaluates percentage utilization across disk, bandwidth, inodes, and email against enabled rules (warn_pct=75, high_pct=90, critical_pct=98), deduplicating alerts per (account_id, metric, level) over cooldown_hours. Surfaces active alerts directly at the top of the Client Area panel with a 1-click upgrade.php?type=package&id=<service_id> CTA, and optionally executes localAPI('ModuleSuspend') at critical thresholds when auto_suspend_at_critical=1.

4.2 Account Security & Hygiene Audit (QuotaGuardService::runSecurityAudit)

Computes a 0–100 score (Grades A+, A, B, C, D) across 6 controls:

  1. PHP Runtime EOL Check (-22 pts if PHP < 8.1)
  2. SSL / AutoSSL Validity & Expiry (-25 pts expired/inactive, -10 pts < 15 days)
  3. Outbound Email Authentication (SPF & DMARC) (-10 to -18 pts if missing)
  4. File Permissions & display_errors (-15 pts open 0777 perms, -8 pts display_errors=On)
  5. Backup Recency (-10 pts if no verified snapshot within 7 days)
  6. Quota Headroom (-10 pts if peak disk or inode usage >= 90%)

1-Click Auto-Harden (autoHardenAccount) automatically upgrades EOL PHP to 8.3, sets display_errors=Off, repairs open permissions, enforces SPF/DMARC, renews AutoSSL (+90d), and recalculates the score.


5. Security, Hooks & AJAX API

  • Token Encryption: WHM API tokens are encrypted at rest with AES-256-CBC + HMAC-SHA256 Encrypt-then-MAC (v1:) keyed via WHMCS $cc_encryption_hash.
  • CSRF & Tenant Ownership: Every Admin (hkcp_admin_csrf / X-HK-CP-CSRF) and Client (hkcp_client_csrf / X-HK-CP-CSRF) POST operation enforces timing-safe hash_equals() validation (HTTP 403 on mismatch). Client UAPI operations strictly verify mod_hk_cp_accounts.client_id === $_SESSION['uid'].
  • WHMCS Hooks: ClientAreaPrimaryNavbar, ClientAreaPrimarySidebar, AdminClientServicesTabFields, AdminHomeWidgets, DailyCronJob, AfterModuleCreate.
  • Admin AJAX Ops: seed_demo, sync_fleet, save_server, delete_server, save_quota_rule, delete_quota_rule, alert_status, run_audit, auto_harden, create_backup, run_autossl.
  • Client AJAX Ops: add_email, delete_email, webmail_sso, add_forwarder, add_domain, add_redirect, create_db, delete_db, add_ftp, add_cron, delete_cron, update_php, run_autossl, create_backup, restore_backup, install_app, run_audit, auto_harden.