diff --git a/CHANGELOG.md b/CHANGELOG.md index b14926a..e7d4208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,9 @@ All notable changes to the VirtFusion Direct Provisioning Module for WHMCS. - Change `catch(Exception)` to `catch(Throwable)` in hooks.php for PHP 8.0+ compatibility - Open VNC window before AJAX call to avoid popup blocker - Memory conversion checks key name instead of display name +- Fix TestConnection failing for new/unsaved servers — use `$params` directly instead of database lookup (serverid=0 is falsy) +- Fix traffic "Used" showing `-` instead of `0 GB` when traffic is allocated but no usage reported yet +- Add cache-busting `?v=0.0.19` to JS/CSS includes in overview.tpl to prevent stale browser cache ### Removed - Firewall feature (non-functional — rulesets must be created in VirtFusion admin panel) diff --git a/modules/servers/VirtFusionDirect/VirtFusionDirect.php b/modules/servers/VirtFusionDirect/VirtFusionDirect.php index 12a6227..dd86c9d 100644 --- a/modules/servers/VirtFusionDirect/VirtFusionDirect.php +++ b/modules/servers/VirtFusionDirect/VirtFusionDirect.php @@ -70,15 +70,17 @@ function VirtFusionDirect_ConfigOptions() function VirtFusionDirect_TestConnection(array $params) { try { - $module = new Module(); - $cp = $module->getCP($params['serverid']); + $hostname = trim($params['serverhostname'] ?? ''); + $password = $params['serverpassword'] ?? ''; - if (!$cp) { - return ['success' => false, 'error' => 'Unable to retrieve server configuration. Please verify the server hostname and access hash/password.']; + if (empty($hostname) || empty($password)) { + return ['success' => false, 'error' => 'Server hostname and password are required. Please verify the server configuration.']; } - $request = $module->initCurl($cp['token']); - $data = $request->get($cp['url'] . '/connect'); + $url = 'https://' . $hostname . '/api/v1'; + $module = new Module(); + $request = $module->initCurl($password); + $data = $request->get($url . '/connect'); $httpCode = $request->getRequestInfo('http_code'); @@ -96,7 +98,7 @@ function VirtFusionDirect_TestConnection(array $params) } return ['success' => false, 'error' => 'Unexpected response from VirtFusion API (HTTP ' . $httpCode . '). Please check the server configuration.']; - } catch (\Exception $e) { + } catch (\Throwable $e) { return ['success' => false, 'error' => 'Connection test failed: ' . $e->getMessage()]; } } diff --git a/modules/servers/VirtFusionDirect/lib/ServerResource.php b/modules/servers/VirtFusionDirect/lib/ServerResource.php index 20fe42b..3c00100 100644 --- a/modules/servers/VirtFusionDirect/lib/ServerResource.php +++ b/modules/servers/VirtFusionDirect/lib/ServerResource.php @@ -21,6 +21,8 @@ class ServerResource $trafficUsed = '-'; if (isset($server['usage']['traffic']['used'])) { $trafficUsed = round($server['usage']['traffic']['used'] / 1073741824, 2) . ' GB'; + } elseif (isset($server['settings']['resources']['traffic']) && $server['settings']['resources']['traffic'] > 0) { + $trafficUsed = '0 GB'; } $data = [ diff --git a/modules/servers/VirtFusionDirect/templates/overview.tpl b/modules/servers/VirtFusionDirect/templates/overview.tpl index 4903ed2..250ff9b 100644 --- a/modules/servers/VirtFusionDirect/templates/overview.tpl +++ b/modules/servers/VirtFusionDirect/templates/overview.tpl @@ -1,5 +1,5 @@ - - + + {if $serviceStatus eq 'Active'}