Quick Installation
- Purchase the module and download
haikhavan_dcim-ioncube-8.2-1.0.0-install.zipfrom your VPSrv Client Area Downloads. - Upload and extract the ZIP into your WHMCS root directory so files land in
modules/addons/haikhavan_dcim/andmodules/servers/haikhavan_dcim/. - Verify PHP 8.2–8.4 with ionCube PHP Loader 14+ / 15.5+ is enabled on your server.
- Go to System Settings → Addon Modules in WHMCS Admin, click Activate next to Haikhavan Dedicated Servers, 42U DCIM, S3 & WireGuard VPN, and assign administrator role access.
Version: 1.0.0 | Namespace: Haikhavan\Dcim\ | Target Runtime: WHMCS 9.1.2 / PHP 8.2–8.4
1. Architecture & File Inventory
haikhavan_dcim is architected as a dual Server Module + Companion Addon sharing a single PSR-4 library under modules/addons/haikhavan_dcim/lib/. Every entry-point function in both haikhavan_dcim.php files is wrapped in if (!function_exists(...)) guards, and haikhavan_dcim_ClientArea / haikhavan_dcim_clientarea inspect $params['serviceid'] dynamically so dual-loading in either order never collides in PHP's case-insensitive function table.
| Path | Responsibility |
|---|---|
modules/servers/haikhavan_dcim/haikhavan_dcim.php |
WHMCS Server Module (MetaData, ConfigOptions, TestConnection, CreateAccount, SuspendAccount, UnsuspendAccount, TerminateAccount, ChangePackage, AdminCustomButtonArray, UsageUpdate, ServiceSingleSignOn, AdminSingleSignOn, ClientArea) |
modules/servers/haikhavan_dcim/templates/clientarea.tpl |
Embedded service ClientArea view for dedicated, colocation, S3 & WireGuard services |
modules/servers/haikhavan_dcim/whmcs.json |
Schema 1.0 server module manifest |
modules/addons/haikhavan_dcim/haikhavan_dcim.php |
WHMCS Addon Module entry point (config, activate, deactivate, upgrade, output, clientarea) |
modules/addons/haikhavan_dcim/hooks.php |
5 WHMCS hooks (ClientAreaPrimaryNavbar, ClientAreaPrimarySidebar, AdminHomeWidgets, AdminClientServicesTabFields, DailyCronJob) |
modules/addons/haikhavan_dcim/whmcs.json |
Schema 1.0 addon module manifest |
modules/addons/haikhavan_dcim/lib/Crypto.php |
AES-256-CBC + HMAC-SHA256 Encrypt-then-MAC vault (HKDF subkeys from $cc_encryption_hash), Curve25519 WireGuard keypair generator, S3 keypair generator, formula-safe CSV sanitizer |
modules/addons/haikhavan_dcim/lib/Database.php |
Idempotent schema builder for 8 mod_hk_dcim_* tables, addon config reader, starter inventory seeder, rack PDU kW recalculator, sandbox cleaner, audit logger |
modules/addons/haikhavan_dcim/lib/Drivers/DriverInterface.php |
Pluggable driver contract |
modules/addons/haikhavan_dcim/lib/Drivers/LocalSandboxDriver.php |
Deterministic in-process simulator for all 4 pillars |
modules/addons/haikhavan_dcim/lib/Drivers/DcimApiDriver.php |
Haikhavan DCIM REST API v1 (apikey header) |
modules/addons/haikhavan_dcim/lib/Drivers/RedfishIpmiDriver.php |
DMTF Redfish v1 / IPMI / Dell iDRAC / HPE iLO OOB driver |
modules/addons/haikhavan_dcim/lib/Drivers/S3StorageDriver.php |
S3-compatible object storage adapter (VHI S3 / Ceph RGW / MinIO) |
modules/addons/haikhavan_dcim/lib/Drivers/MikroTikWireGuardDriver.php |
MikroTik RouterOS v7 REST API (/rest/interface/wireguard/peers) |
modules/addons/haikhavan_dcim/lib/Drivers/DriverFactory.php |
Driver resolver honoring Sandbox override |
modules/addons/haikhavan_dcim/lib/DcimOrchestrator.php |
42U Rack Elevation Map builder, OOB power/PXE/KVM workflows, 95th-percentile calculator, IPMI sensor polling, S3 key rotation, WireGuard .conf renderer, fleet KPIs |
modules/addons/haikhavan_dcim/lib/AdminController.php |
6-tab Admin Studio + 15 CSRF-guarded AJAX ops + .conf & CSV streaming downloads |
modules/addons/haikhavan_dcim/lib/ClientController.php |
Client Portal & Server ClientArea controller with auth, ownership, and CSRF guards |
modules/addons/haikhavan_dcim/templates/admin/dashboard.php |
Admin Studio UI (Zero-CDN) |
modules/addons/haikhavan_dcim/templates/client/portal.tpl |
Client Hub UI (Zero-CDN Smarty template) |
modules/addons/haikhavan_dcim/assets/css/haikhavan_dcim.css |
Scoped dark/light styling + 42U cabinet elevation CSS |
modules/addons/haikhavan_dcim/assets/js/haikhavan_dcim.js |
Vanilla JS AJAX client, Rack Inspector, Modals, and HTML5 Canvas charts |
2. Database Schema (mod_hk_dcim_*)
All queries use WHMCS\Database\Capsule with parameterized bindings.
mod_hk_dcim_racks
| Column | Type | Null | Default | Notes / Indexes |
|---|---|---|---|---|
id |
INT UNSIGNED |
NO | AI | Primary Key |
rack_code |
VARCHAR(40) |
NO | — | UNIQUE (e.g. FRA1-R01) |
datacenter |
VARCHAR(40) |
NO | — | Indexed facility code |
row_aisle |
VARCHAR(40) |
NO | Row A / Cage 01 |
Physical location |
total_u |
TINYINT UNSIGNED |
NO | 42 |
Cabinet U height (12–48) |
pdu_capacity_kw |
DECIMAL(6,2) |
NO | 8.80 |
Max A+B PDU feed kW |
pdu_draw_kw |
DECIMAL(6,2) |
NO | 0.00 |
Aggregated live power draw |
ambient_temp_c |
DECIMAL(5,2) |
NO | 21.50 |
Cabinet intake temp °C |
status |
VARCHAR(24) |
NO | active |
Indexed (active, maintenance) |
notes |
VARCHAR(255) |
NO | '' |
Cabinet notes |
is_sandbox |
TINYINT(1) |
NO | 0 |
Indexed sandbox flag |
created_at / updated_at |
TIMESTAMP |
YES | NULL | Timestamps |
mod_hk_dcim_assets
Stores bare-metal servers, colocation enclosures, ToR switches, and burn-in bays. Key columns: id (PK), service_id (IDX), client_id (IDX), rack_id (IDX), u_start, u_size, hostname (IDX), asset_type (IDX), driver, vendor, model, cpu_spec, ram_gb, storage_spec, primary_ip, bmc_ip, bmc_credentials_enc (TEXT, AES-256-CBC+HMAC), os_template, power_state (IDX), switch_port, port_speed_gbps, pdu_outlet, pdu_watts, commit_mbps, overage_rate, rdns_ptr, custom_iso_url, is_sandbox (IDX), created_at, updated_at.
mod_hk_dcim_telemetry
Stores time-series bandwidth & PDU readings: id (PK), asset_id (IDX), sample_label, in_mbps, out_mbps, p95_mbps, pdu_watts, packet_loss_pct, is_sandbox (IDX), recorded_at (IDX).
mod_hk_dcim_sensors
Stores IPMI/Redfish hardware health probes: id (PK), asset_id (IDX), sensor_type (IDX: temp|psu|fan|smart), sensor_name, reading_value, unit, threshold_warn, threshold_crit, severity (IDX: ok|warning|critical), acknowledged (IDX), is_sandbox (IDX), checked_at.
mod_hk_dcim_kvm_sessions
Stores zero-trust ephemeral KVM console tickets: id (PK), asset_id (IDX), client_id (IDX), ticket_token_hash (UNIQUE SHA-256), console_protocol (novnc|html5-redfish|sol-ssh), expires_at (IDX), revoked, created_by, is_sandbox (IDX), created_at.
mod_hk_dcim_s3_accounts
Stores S3 buckets & rotated credentials: id (PK), service_id (IDX), client_id (IDX), account_label, endpoint_url, bucket_name (UNIQUE), region, access_key (IDX), secret_key_enc (AES-256-CBC+HMAC), quota_gb, used_gb, ops_limit_kpm, egress_gb, policy_preset, cors_enabled, versioning_enabled, status (IDX), is_sandbox (IDX), last_rotated_at, created_at, updated_at.
mod_hk_dcim_wg_peers
Stores MikroTik RouterOS WireGuard peers: id (PK), service_id (IDX), client_id (IDX), router_node, wg_interface, peer_name, public_key (UNIQUE), private_key_enc (AES-256-CBC+HMAC), preshared_key_enc (AES-256-CBC+HMAC), allowed_ips, endpoint_host, endpoint_port, dns_servers, mtu, persistent_keepalive, rx_bytes, tx_bytes, status (IDX), last_handshake_at, is_sandbox (IDX), created_at, updated_at.
mod_hk_dcim_audit_logs
Immutable operational log: id (PK), actor_type, actor_id, module_area (IDX), action (IDX), target_ref, driver, status, details_json, ip_address, is_sandbox (IDX), created_at (IDX).
3. Security Model
- Authenticated Encryption at Rest (
Crypto.php): BMC passwords, S3 Secret Access Keys, WireGuard Private Keys, and WireGuard Preshared Keys are encrypted using AES-256-CBC + HMAC-SHA256 (Encrypt-then-MAC) with distinct HKDF-derived encryption and MAC subkeys rooted in WHMCS$cc_encryption_hash. Decryption verifies MAC integrity in constant time viahash_equals(). - Zero-Trust Ephemeral KVM Tickets: Raw console tokens are returned once at issuance and persisted only as SHA-256 hashes (
ticket_token_hash) with a strict 900-second expiry; raw BMC IPs are never exposed in Client Area responses. - CSRF Protection: Separate per-session 256-bit CSRF tokens (
haikhavan_dcim_admin_csrfandhaikhavan_dcim_client_csrf) verified viahash_equals()on every POST/AJAX mutation; missing or invalid tokens return HTTP403. - Authentication & Ownership Enforcement: Unauthenticated Client AJAX calls return HTTP
401. Every client read/write/download operation checksWHERE id = ? AND client_id = $_SESSION['uid'], preventing IDOR across assets, S3 buckets, and WireGuard.confdownloads. - Formula-Safe CSV & Strict Output Escaping: All PHP admin output uses
htmlspecialchars(..., ENT_QUOTES, 'UTF-8'), all Smarty.tploutput uses|escape, and CSV cells neutralize leading=,+,-,@,\t,\rformula characters.
4. External API Integrations
| Driver | Protocol & Endpoint | Authentication | Timeouts |
|---|---|---|---|
dcim_api |
REST JSON (GET /api/v1/system/status, POST /api/v1/devices/{id}/power) |
apikey: <key> header |
4s connect / 8s total |
redfish_ipmi |
DMTF Redfish v1 (GET /redfish/v1/, POST .../ComputerSystem.Reset, .../Manager.Reset) |
HTTP Basic over TLS | 4s connect / 8s total |
s3_compatible |
S3-Compatible HTTPS Endpoint (VHI S3 / Ceph RGW / MinIO) | Access/Secret Admin Keys | 4s connect / 6s total |
mikrotik_wireguard |
MikroTik RouterOS v7 REST (GET /rest/interface/wireguard, PUT /rest/interface/wireguard/peers) |
HTTP Basic over TLS | 4s connect / 8s total |
local_sandbox |
In-process deterministic simulator | N/A | < 5ms |
5. WHMCS Hooks Inventory (hooks.php)
| Hook Point | Priority | Purpose |
|---|---|---|
ClientAreaPrimaryNavbar |
1 |
Adds DCIM, S3 & VPN (index.php?m=haikhavan_dcim) to the client navbar when authenticated |
ClientAreaPrimarySidebar |
1 |
Injects quick resource counts & anchor links for Servers/Colo, S3 Buckets, and WireGuard Peers |
AdminHomeWidgets |
1 |
Registers HaikhavanDcimFleetHomeWidget showing 42U Rack Utilization %, PDU kW Draw, 95th Overage $, and open IPMI alerts |
AdminClientServicesTabFields |
1 |
Displays Rack U position, vendor/model, power state, 95th-percentile Mbps, and PDU Watts inside Admin Service Details |
DailyCronJob |
1 |
Runs fleet-wide IPMI sensor polling, appends fresh 95th telemetry samples, and revokes expired KVM sessions |
6. Controller & AJAX API Reference
Admin AJAX (POST addonmodules.php?module=haikhavan_dcim&hkdcim_ajax=<op>, requires csrf_token)
power_action(asset_id,power_action:on|off|cycle|bmc_reset|rescue|pdu_cycle)pxe_reinstall(asset_id,os_template, optionalssh_key)issue_kvm(asset_id,protocol:novnc|html5-redfish|sol-ssh)save_rack(rack_code,datacenter,row_aisle,total_u,pdu_capacity_kw,notes)create_asset(rack_id,client_id,hostname,asset_type,u_start,u_size,model,pdu_watts)poll_sensors(optionalasset_id)ack_sensor(sensor_id)s3_create(client_id,account_label,bucket_name,region,quota_gb,policy_preset)s3_rotate_keys(account_id)wg_create_peer(client_id,peer_name,router_node,wg_interface,endpoint_host,allowed_ips)wg_toggle_peer(peer_id) /wg_delete_peer(peer_id)test_driver(driver)seed_sandbox/clear_sandbox- Downloads (
GET):hkdcim_download=wg_conf&peer_id=<id>,hkdcim_download=telemetry_csv
Client AJAX (POST index.php?m=haikhavan_dcim&hkdcim_client_ajax=<op>, requires session uid + csrf_token)
power_action,pxe_reinstall,issue_kvm,update_rdns,mount_iso,s3_rotate_keys,s3_update_policy,wg_create_peer,wg_revoke_peer- Client Download (
GET, ownership-checked):index.php?m=haikhavan_dcim&hkdcim_download=wg_conf&peer_id=<id>
7. 95th-Percentile Calculation & Troubleshooting
- 95th Formula: For each telemetry window $S = {s_1, \dots, s_N}$ where $s_i = \max(\text{in_mbps}i, \text{out_mbps}i)$, samples are sorted ascending and $P{95} = S[\lceil 0.95 \times N \rceil - 1]$. Billable overage is $\max(0, P{95} - \text{commit_mbps}) \times \text{overage_rate}$.
- Troubleshooting:
- HTTP 403 on AJAX calls: Reload the page to refresh the session CSRF token.
- Driver Test fails with cURL error: Verify outbound TLS connectivity and credentials in Addon Settings, or enable Sandbox Simulator Mode for offline testing.
- Dual-load check: Both
modules/addons/haikhavan_dcim/haikhavan_dcim.phpandmodules/servers/haikhavan_dcim/haikhavan_dcim.phpsharefunction_existsguards and can safely coexist in WHMCS 9.1.2.