Quick Installation
- Purchase the module and download
haikhavan_multibrand-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_multibrand/. - 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 Multibrand & White-Label Engine, and assign administrator role access.
Version: 1.0.0
Namespace: Haikhavan\Multibrand\
Entry Point: modules/addons/haikhavan_multibrand/haikhavan_multibrand.php
1. Architecture & File Inventory
modules/addons/haikhavan_multibrand/
├── haikhavan_multibrand.php # Addon config, lifecycle callbacks, Admin & Client dispatchers, autoloader
├── hooks.php # 9 WHMCS hooks (ClientAreaPage/Head/Footer/Navbar, ClientAdd, InvoiceCreation, EmailPreSend, AdminClientProfileTabFields, AdminHomeWidgets)
├── whmcs.json # WHMCS Marketplace 1.0 manifest
├── lib/
│ ├── Database.php # Capsule schema installer (5 tables), AES-256-CBC+HMAC SMTP crypto, settings, audit logger
│ ├── BrandResolver.php # Deterministic brand resolution pipeline (preview query -> session -> Host header -> client map -> default)
│ ├── BrandService.php # Brand CRUD, 1-click Brand Clone, Client assignment & bulk migration, Invoice branding, Email overrides, Revenue Analytics
│ ├── AdminController.php # 6-tab Admin Dashboard & CSRF-protected AJAX JSON router
│ └── ClientController.php # Client Area Brand Portal & CSRF-protected session brand switcher
├── templates/
│ ├── admin/dashboard.php # Admin UI with Canvas analytics chart, brand cards, 5-subtab Brand Editor modal & migration tools
│ └── client/portal.tpl # Smarty Client Area Brand Portal & live switcher cards
└── assets/
├── css/haikhavan_multibrand.css # Zero-CDN enterprise stylesheet
└── js/haikhavan_multibrand.js # Vanilla JS controller & HTML5 Canvas revenue chart
2. Database Schema
All 5 custom tables use WHMCS\Database\Capsule with parameterized queries exclusively.
2.1 mod_hk_mb_brands
Master brand registry storing domain routing, visual identity, scoping arrays, invoicing rules, SEO tags, and encrypted SMTP configuration.
| Column Group | Columns | Notes |
|---|---|---|
| Identity & Routing | id, slug (UNIQUE), name, company_name, domain (INDEX), extra_domains, system_url, is_default, enabled |
Supports exact domains, comma-separated aliases, and wildcard subdomains (*.brand.io) |
| Visual & Theme | logo_url, favicon_url, primary_color, accent_color, graph_color, client_template, order_template, default_language |
Colors sanitized via strict hex regex (/^#[0-9a-fA-F]{3,8}$/) |
| Catalog & Scoping | default_currency_id, allowed_currencies_json, product_groups_json, payment_gateways_json, support_departments_json |
JSON arrays of permitted IDs / gateway sysnames |
| Invoicing & Legal | invoice_prefix, invoice_next_seq, invoice_pay_to, legal_footer, bank_details, tos_url, company_address |
Sequential per-brand invoice numbers ({prefix}{YYYY}-{seq}) |
| Email & SMTP | email_from_name, email_from_address, email_signature, email_header_html, email_footer_html, email_css, smtp_enabled, smtp_host, smtp_port, smtp_encryption, smtp_username, smtp_password_encrypted |
smtp_password_encrypted uses v1: AES-256-CBC + HMAC-SHA256 |
| SEO & Custom Code | seo_title, seo_description, og_image_url, custom_css, custom_header_html, custom_footer_html, notes |
Injected via ClientAreaHeadOutput and ClientAreaFooterOutput |
2.2 mod_hk_mb_client_brands
Maps each WHMCS client (userid UNIQUE) to a brand_id (INDEX), tracking assigned_via (auto | manual | migration) and assigned_at.
2.3 mod_hk_mb_relations
Links WHMCS entities (entity_type ∈ invoice|service|ticket|announcement|knowledgebase|download, entity_id — composite UNIQUE) to a brand_id along with branded_ref (e.g., branded invoice number).
2.4 mod_hk_mb_email_overrides
Stores per-brand WHMCS email template overrides (brand_id, template_name, language, subject_override, body_override, enabled; composite UNIQUE on brand_id + template_name + language).
2.5 mod_hk_mb_audit_log
Immutable trail (actor_type, actor_id, brand_id, action, summary, details_json, remote_ip, created_at).
3. Brand Resolution Pipeline (BrandResolver::resolveActiveBrand)
Brands resolve deterministically per request with in-request memoization:
- Preview Query Override (
?hk_brand=<slug>/?brand=<slug>): Whenenable_preview_queryis enabled, resolves the matching enabled brand and persists it to$_SESSION['hk_mb_preview_brand']. Passing?hk_brand=resetclears the preview session. - Active Session Preview: Reads
$_SESSION['hk_mb_preview_brand']if present. - HTTP Host Header Matching: Normalizes
$_SERVER['HTTP_HOST'](stripping port) and matches againstmod_hk_mb_brands.domainandextra_domains(including wildcard*.domain.tldsuffixes). - Logged-in Client Mapping: Looks up
$_SESSION['uid']inmod_hk_mb_client_brands. - Default Brand Fallback: Selects the enabled brand with
is_default = 1(or lowestid).
4. WHMCS Hooks Inventory (hooks.php)
| Hook Point | Priority | Function |
|---|---|---|
ClientAreaPage |
1 |
Resolves active brand, overrides $companyname, exports $mb_brand Smarty vars, and scopes $departments and $gateways arrays per brand. |
ClientAreaHeadOutput |
1 |
Injects per-brand favicon, <meta name="description">, OpenGraph (og:site_name, og:title, og:description, og:image), CSS variables (--hk-mb-primary, --hk-mb-accent), custom CSS, and custom header HTML. |
ClientAreaFooterOutput |
1 |
Applies navbar white-label logo/title, custom footer HTML, legal/ToS bar, and optional floating Brand Switcher pill. |
ClientAreaPrimaryNavbar |
1 |
Adds Brands navigation entry pointing to index.php?m=haikhavan_multibrand when switcher is enabled. |
ClientAdd |
1 |
Automatically maps newly registered WHMCS clients to the active storefront brand (assigned_via = 'auto'). |
InvoiceCreation |
1 |
Generates sequential branded invoice number ({prefix}{YYYY}-{0000}), updates tblinvoices.invoicenum, increments invoice_next_seq, and inserts a mod_hk_mb_relations row. |
EmailPreSend |
1 |
Resolves recipient's brand, injects branded company_name, company_domain, company_logo_url, signature, From Name/Email, applies matching mod_hk_mb_email_overrides, and logs SMTP routing metadata. |
AdminClientProfileTabFields |
1 |
Displays color-coded Brand badge, domain, invoice prefix, and quick migrate button on Admin Client Profile. |
AdminHomeWidgets |
1 |
Registers Haikhavan Multibrand & White-Label Engine dashboard widget with active brand counts, mapped clients, paid revenue, and per-brand chips. |
5. Security Model
- Authenticated SMTP Encryption at Rest:
Database::encryptSecret()uses AES-256-CBC + HMAC-SHA256 (Encrypt-then-MAC) with domain-separated keys (haikhavan_multibrand_enc_v1,haikhavan_multibrand_mac_v1) derived from WHMCS$cc_encryption_hash. Decryption verifies the HMAC in constant time withhash_equals(). - CSRF Protection: Distinct 192-bit random CSRF tokens for Admin (
$_SESSION['hk_mb_admin_csrf']) and Client ($_SESSION['hk_mb_client_csrf']) verified viahash_equals()on all state-changing AJAX POST actions (returning HTTP403on mismatch). - Color & XSS Sanitization: Hex colors are strictly validated (
BrandResolver::sanitizeColor()), PHP admin templates encode all values viahtmlspecialchars(..., ENT_QUOTES, 'UTF-8'), and Smarty client templates escape all dynamic expressions with|escape.
6. AJAX API Reference
Admin Endpoint (admin/addonmodules.php?module=haikhavan_multibrand&ajax=1)
op |
Method | CSRF | Description |
|---|---|---|---|
get_brand |
GET | No | Fetch hydrated brand configuration by id |
save_brand |
POST | Yes | Create or update brand (handles encrypted SMTP password) |
clone_brand |
POST | Yes | 1-click duplicate brand + email template overrides |
delete_brand |
POST | Yes | Delete brand (blocked safely if clients are still assigned) |
toggle_brand |
POST | Yes | Enable or pause a brand |
set_default_brand |
POST | Yes | Promote a brand to default fallback |
assign_client |
POST | Yes | Assign or migrate single client to target brand |
bulk_migrate_clients |
POST | Yes | Migrate all clients from from_brand_id to to_brand_id |
save_email_override / delete_email_override |
POST | Yes | Manage per-brand email template overrides |
Client Endpoint (index.php?m=haikhavan_multibrand&ajax=1)
op |
Method | CSRF | Description |
|---|---|---|---|
switch_brand |
POST | Yes | Switch active session preview brand (respects enable_brand_switcher) |
clear_preview |
POST | Yes | Clear preview session override and return to default routing |
7. Troubleshooting
- Brand domain not matching in production: Verify the web server virtual host routes the custom domain to the same WHMCS document root and that
mod_hk_mb_brands.domainmatchesHTTP_HOST(withouthttps://or port). - Preview query
?hk_brand=not switching: Ensureenable_preview_queryis enabled in Addon Settings and that the target brand hasenabled = 1. - Cannot delete a brand: Migrate assigned clients to another brand first via Clients & Migrations (single or bulk migrate) before deleting.