Enhance WHMCS integration with mTLS support and product mapping features. Added mTLS configuration options, updated API endpoints for mTLS status and fingerprint registration, and implemented product validation API. Updated database schema and documentation accordingly.
Some checks failed
CI / Node — lint, typecheck, test, build (push) Failing after 9s
CI / Go — node-agent tests (push) Failing after 8s
CI / Go — edge-gateway build (push) Successful in 18s

This commit is contained in:
smueller
2026-06-30 13:17:12 +02:00
parent 4b20efe4bc
commit 316679a913
34 changed files with 1174 additions and 30 deletions

View File

@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
final class HexaGameCloudMtlsConfig
{
public static function fromAddonSettings(array $vars): array
{
if (empty($vars['use_mtls'])) {
return [];
}
return self::normalize([
'cert' => (string) ($vars['mtls_cert_path'] ?? ''),
'key' => (string) ($vars['mtls_key_path'] ?? ''),
'ca' => (string) ($vars['mtls_ca_path'] ?? ''),
'fingerprint' => (string) ($vars['mtls_cert_fingerprint'] ?? ''),
]);
}
public static function fromServerParams(array $params): array
{
if (empty($params['configoptions']['use_mtls']) && empty($params['configoption5'])) {
return [];
}
return self::normalize([
'cert' => (string) ($params['configoptions']['mtls_cert_path'] ?? $params['configoption5'] ?? ''),
'key' => (string) ($params['configoptions']['mtls_key_path'] ?? $params['configoption6'] ?? ''),
'ca' => (string) ($params['configoptions']['mtls_ca_path'] ?? $params['configoption7'] ?? ''),
'fingerprint' => (string) ($params['configoptions']['mtls_cert_fingerprint'] ?? ''),
]);
}
public static function applyToCurl($ch, array $mtls): void
{
if ($mtls === []) {
return;
}
if (!empty($mtls['cert']) && is_readable($mtls['cert'])) {
curl_setopt($ch, CURLOPT_SSLCERT, $mtls['cert']);
}
if (!empty($mtls['key']) && is_readable($mtls['key'])) {
curl_setopt($ch, CURLOPT_SSLKEY, $mtls['key']);
}
if (!empty($mtls['ca']) && is_readable($mtls['ca'])) {
curl_setopt($ch, CURLOPT_CAINFO, $mtls['ca']);
}
}
public static function fingerprintHeader(array $mtls): array
{
if (empty($mtls['fingerprint'])) {
return [];
}
$fingerprint = strtolower(str_replace(':', '', $mtls['fingerprint']));
return ['X-HGC-Client-Cert-Fingerprint: ' . $fingerprint];
}
private static function normalize(array $input): array
{
if ($input['cert'] === '' && $input['key'] === '' && $input['ca'] === '') {
return [];
}
return $input;
}
}

View File

@@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
use WHMCS\Database\Capsule;
final class HexaGameCloudProductMapping
{
public static function resolvePlanSlug(array $params, string $fallback = 'free'): string
{
$productId = (int) ($params['pid'] ?? 0);
if ($productId <= 0) {
return $params['configoption1'] ?: $fallback;
}
try {
$mapping = Capsule::table('mod_hexagamecloud_product_mappings')
->where('whmcs_product_id', $productId)
->where('is_active', 1)
->first();
if ($mapping && !empty($mapping->plan_slug)) {
return (string) $mapping->plan_slug;
}
} catch (Throwable) {
// Mapping table may not exist before addon activation
}
return $params['configoption1'] ?: $fallback;
}
public static function resolveSoftwareFamily(array $params, string $fallback = 'VANILLA'): string
{
$productId = (int) ($params['pid'] ?? 0);
if ($productId <= 0) {
return $params['configoption3'] ?: $fallback;
}
try {
$mapping = Capsule::table('mod_hexagamecloud_product_mappings')
->where('whmcs_product_id', $productId)
->where('is_active', 1)
->first();
if ($mapping && !empty($mapping->default_software)) {
return (string) $mapping->default_software;
}
} catch (Throwable) {
}
return $params['configoption3'] ?: $fallback;
}
public static function resolveMinecraftVersion(array $params, string $fallback = '1.21.1'): string
{
$productId = (int) ($params['pid'] ?? 0);
if ($productId <= 0) {
return $params['configoption2'] ?: $fallback;
}
try {
$mapping = Capsule::table('mod_hexagamecloud_product_mappings')
->where('whmcs_product_id', $productId)
->where('is_active', 1)
->first();
if ($mapping && !empty($mapping->default_version)) {
return (string) $mapping->default_version;
}
} catch (Throwable) {
}
return $params['configoption2'] ?: $fallback;
}
}