Security improvements: - Enable SSL/TLS certificate verification by default (was disabled, MITM risk) - Remove error_reporting(0) that silenced all errors - Add input sanitization on all user parameters (int casting, regex filtering) - Return proper HTTP status codes (401, 403, 400, 500) instead of always 200 - Add XSS protection with htmlspecialchars and encodeURIComponent - Add null checks on API response data before property access New features: - Power management: boot, shutdown, restart, and force power off controls - Server rebuild: reinstall with any available OS template from client area - Server rename: change server display name via PATCH API - OS template fetching: client-side endpoint for rebuild OS selection - TestConnection: validate API credentials from WHMCS server settings - ServiceSingleSignOn: native WHMCS SSO integration for VirtFusion panel - Server status badge: visual indicator of server state in overview - Traffic usage display: show bandwidth used vs allocated - Checkout validation: ShoppingCartValidateCheckout hook ensures OS selection Ordering process improvements: - Add default "Select Operating System" placeholder option - Add "No SSH Key (Optional)" default for SSH dropdown - Hide SSH key field/container when no keys available - Wrap hook in try/catch to prevent checkout page breakage - Sanitize template names with htmlspecialchars - Use JSON_HEX_* flags for safe script injection Theme compatibility: - Properly formatted Smarty templates with readable indentation - Dual panel/card CSS classes for Bootstrap 3/4/5 compatibility - Responsive power button layout with mobile breakpoint - Framework-agnostic HTML that works with Six, Twenty-One, Lagom, and custom themes - Suspended service state messaging Code quality: - Readable, unminified JavaScript with JSDoc header - Structured CSS with logical section organization - Improved error messages throughout all provisioning functions - Added PATCH method support to Curl wrapper - Added curl error capture on connection failures - Added connection and request timeouts (10s/30s) - Fixed memory conversion to check key name instead of display name Documentation: - Complete README rewrite with installation, configuration, and troubleshooting guides - API endpoint reference table - Configurable options mapping documentation - Theme override instructions - Security considerations section https://claude.ai/code/session_01TCsJ4WZCGuEX3zqh1tQ2zx
84 lines
3.7 KiB
PHP
84 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace WHMCS\Module\Server\VirtFusionDirect;
|
|
|
|
class ServerResource
|
|
{
|
|
public function process($data)
|
|
{
|
|
$server = json_decode(json_encode($data->data), true);
|
|
|
|
$traffic = '-';
|
|
|
|
if (isset($server['settings']['resources']['traffic'])) {
|
|
if ($server['settings']['resources']['traffic'] > 0) {
|
|
$traffic = $server['settings']['resources']['traffic'] . ' GB';
|
|
} else {
|
|
$traffic = 'Unlimited';
|
|
}
|
|
}
|
|
|
|
$trafficUsed = '-';
|
|
if (isset($server['usage']['traffic']['used'])) {
|
|
$trafficUsed = round($server['usage']['traffic']['used'] / 1073741824, 2) . ' GB';
|
|
}
|
|
|
|
$data = [
|
|
'name' => $server['name'] ?: '-',
|
|
'hostname' => $server['hostname'] ?: '-',
|
|
'memory' => isset($server['settings']['resources']['memory']) ? $server['settings']['resources']['memory'] . ' MB' : '-',
|
|
'traffic' => $traffic,
|
|
'trafficUsed' => $trafficUsed,
|
|
'storage' => isset($server['settings']['resources']['storage']) ? $server['settings']['resources']['storage'] . ' GB' : '-',
|
|
'cpu' => isset($server['settings']['resources']['cpuCores']) ? $server['settings']['resources']['cpuCores'] . ' Core(s)' : '-',
|
|
'status' => isset($server['state']) ? $server['state'] : 'unknown',
|
|
'powerStatus' => isset($server['hypervisor']['settings']['state']) ? $server['hypervisor']['settings']['state'] : 'unknown',
|
|
'username' => isset($server['owner']['email']) ? $server['owner']['email'] : '',
|
|
'password' => '',
|
|
'primaryNetwork' => [
|
|
'ipv4' => ['-'],
|
|
'ipv4Unformatted' => [],
|
|
'ipv6' => ['-'],
|
|
'ipv6Unformatted' => [],
|
|
'mac' => '-',
|
|
],
|
|
'networkSpeed' => [
|
|
'inbound' => isset($server['settings']['resources']['networkSpeedInbound']) ? $server['settings']['resources']['networkSpeedInbound'] . ' Mbps' : '-',
|
|
'outbound' => isset($server['settings']['resources']['networkSpeedOutbound']) ? $server['settings']['resources']['networkSpeedOutbound'] . ' Mbps' : '-',
|
|
],
|
|
];
|
|
|
|
if (array_key_exists('network', $server)) {
|
|
if (array_key_exists('interfaces', $server['network'])) {
|
|
if (count($server['network']['interfaces'])) {
|
|
|
|
if (isset($server['network']['interfaces'][0]['mac'])) {
|
|
$data['primaryNetwork']['mac'] = $server['network']['interfaces'][0]['mac'];
|
|
}
|
|
|
|
if (count($server['network']['interfaces'][0]['ipv4'])) {
|
|
$data['primaryNetwork']['ipv4'] = [];
|
|
foreach ($server['network']['interfaces'][0]['ipv4'] as $ip) {
|
|
$data['primaryNetwork']['ipv4'][] = $ip['address'];
|
|
}
|
|
}
|
|
|
|
if (count($server['network']['interfaces'][0]['ipv6'])) {
|
|
$data['primaryNetwork']['ipv6'] = [];
|
|
foreach ($server['network']['interfaces'][0]['ipv6'] as $ip) {
|
|
$data['primaryNetwork']['ipv6'][] = $ip['subnet'] . '/' . $ip['cidr'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$data['primaryNetwork']['ipv4Unformatted'] = $data['primaryNetwork']['ipv4'];
|
|
$data['primaryNetwork']['ipv6Unformatted'] = $data['primaryNetwork']['ipv6'];
|
|
$data['primaryNetwork']['ipv4'] = implode(', ', $data['primaryNetwork']['ipv4']);
|
|
$data['primaryNetwork']['ipv6'] = implode(', ', $data['primaryNetwork']['ipv6']);
|
|
|
|
return $data;
|
|
}
|
|
}
|