- Add isset() guards before count() on ipv4/ipv6 arrays in ServerResource to prevent PHP 8.0+ TypeError - Add null checks after getWhmcsService() and getCP() in 18 Module methods and 5 ModuleFunctions methods to prevent fatal null dereference errors - Add null guards for $whmcsService and $cp in admin.php impersonateServerOwner - Fix HTTP status codes throughout admin.php (404, 400, 500, 502 instead of 200) - Guard ConfigureService methods against $this->cp === false - Use null coalescing for customfields access in initServerBuild - Check API response code in initServerBuild instead of always returning true - Replace exit() with RuntimeException in Curl.php - Change catch(Exception) to catch(Throwable) in hooks.php for PHP 8.0+ - Open VNC window before AJAX call to avoid popup blocker Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
84 lines
3.8 KiB
PHP
84 lines
3.8 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 (isset($server['network']['interfaces'][0]['ipv4']) && count($server['network']['interfaces'][0]['ipv4'])) {
|
|
$data['primaryNetwork']['ipv4'] = [];
|
|
foreach ($server['network']['interfaces'][0]['ipv4'] as $ip) {
|
|
$data['primaryNetwork']['ipv4'][] = $ip['address'];
|
|
}
|
|
}
|
|
|
|
if (isset($server['network']['interfaces'][0]['ipv6']) && 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;
|
|
}
|
|
}
|