fix: TestConnection for unsaved servers, traffic display, and cache-busting
- Use $params['serverhostname']/serverpassword directly in TestConnection instead of database lookup (serverid=0 is falsy for new servers) - Default traffic "Used" to 0 GB when allocated but no usage reported - Add ?v=0.0.19 cache-busting to JS/CSS includes in overview.tpl Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<link href="{$systemURL}modules/servers/VirtFusionDirect/templates/css/module.css" rel="stylesheet">
|
||||
<script src="{$systemURL}modules/servers/VirtFusionDirect/templates/js/module.js"></script>
|
||||
<link href="{$systemURL}modules/servers/VirtFusionDirect/templates/css/module.css?v=0.0.19" rel="stylesheet">
|
||||
<script src="{$systemURL}modules/servers/VirtFusionDirect/templates/js/module.js?v=0.0.19"></script>
|
||||
|
||||
{if $serviceStatus eq 'Active'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user