New features implemented: - Firewall management: enable/disable, status display, apply rules - IP address management: add/remove IPv4 and IPv6 with client UI - VNC console access integration (VirtFusion v6.1.0+) - Backup plan assignment/removal via API - Resource modification: in-place memory/CPU/traffic changes - UsageUpdate cron: automated bandwidth and disk usage sync to WHMCS - Dry run validation: test server creation config before provisioning - Admin "Validate Server Config" button for dry run testing Client area additions: - Firewall panel with enable/disable/apply controls and status badge - Network panel with IPv4/IPv6 listing, add, and remove buttons - VNC Console panel with browser-based access - All panels load asynchronously with spinner indicators Comprehensive README rewrite with: - Table of contents, requirements matrix, step-by-step installation - Detailed configuration guide for all features - Theme compatibility documentation (Six, Twenty-One, Lagom) - Complete API endpoints reference organized by category - UsageUpdate cron documentation with data format details - Troubleshooting tables for common issues - Known issues section covering version requirements - Security architecture documentation - File structure reference https://claude.ai/code/session_01TCsJ4WZCGuEX3zqh1tQ2zx
253 lines
8.0 KiB
PHP
253 lines
8.0 KiB
PHP
<?php
|
|
|
|
if (!defined("WHMCS")) {
|
|
die("This file cannot be accessed directly");
|
|
}
|
|
|
|
use WHMCS\Module\Server\VirtFusionDirect\ModuleFunctions;
|
|
use WHMCS\Module\Server\VirtFusionDirect\Module;
|
|
use WHMCS\Module\Server\VirtFusionDirect\Database;
|
|
|
|
function VirtFusionDirect_MetaData()
|
|
{
|
|
return [
|
|
'DisplayName' => 'VirtFusion Direct Provisioning',
|
|
'APIVersion' => '1.1',
|
|
'RequiresServer' => true,
|
|
'ServiceSingleSignOnLabel' => 'Login to VirtFusion Panel',
|
|
'AdminSingleSignOnLabel' => false,
|
|
];
|
|
}
|
|
|
|
function VirtFusionDirect_ConfigOptions()
|
|
{
|
|
return [
|
|
"defaultHypervisorGroupId" => [
|
|
"FriendlyName" => "Hypervisor Group ID",
|
|
"Type" => "text",
|
|
"Size" => "20",
|
|
"Description" => "The default hypervisor group ID for server placement.",
|
|
"Default" => "1",
|
|
],
|
|
"packageID" => [
|
|
"FriendlyName" => "Package ID",
|
|
"Type" => "text",
|
|
"Size" => "20",
|
|
"Description" => "The VirtFusion package ID that defines server resources.",
|
|
"Default" => "1",
|
|
],
|
|
"defaultIPv4" => [
|
|
"FriendlyName" => "Default IPv4",
|
|
"Type" => "dropdown",
|
|
"Options" => "0,1,2,3,4,5,6,7,8,9,10",
|
|
"Description" => "The default number of IPv4 addresses to assign to each server.",
|
|
"Default" => "1",
|
|
],
|
|
];
|
|
}
|
|
|
|
function VirtFusionDirect_TestConnection(array $params)
|
|
{
|
|
try {
|
|
$module = new Module();
|
|
$cp = $module->getCP($params['serverid']);
|
|
|
|
if (!$cp) {
|
|
return ['success' => false, 'error' => 'Unable to retrieve server configuration. Please verify the server hostname and access hash/password.'];
|
|
}
|
|
|
|
$request = $module->initCurl($cp['token']);
|
|
$data = $request->get($cp['url'] . '/connect');
|
|
|
|
$httpCode = $request->getRequestInfo('http_code');
|
|
|
|
if ($httpCode == 200) {
|
|
return ['success' => true, 'error' => ''];
|
|
}
|
|
|
|
if ($httpCode == 401) {
|
|
return ['success' => false, 'error' => 'Authentication failed. Please verify your API token is correct and has not expired.'];
|
|
}
|
|
|
|
if ($httpCode == 0) {
|
|
$curlError = $request->getRequestInfo('curl_error');
|
|
return ['success' => false, 'error' => 'Connection failed: ' . ($curlError ?: 'Unable to reach the VirtFusion server. Verify the hostname and that SSL certificates are valid.')];
|
|
}
|
|
|
|
return ['success' => false, 'error' => 'Unexpected response from VirtFusion API (HTTP ' . $httpCode . '). Please check the server configuration.'];
|
|
} catch (\Exception $e) {
|
|
return ['success' => false, 'error' => 'Connection test failed: ' . $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
function VirtFusionDirect_AdminCustomButtonArray()
|
|
{
|
|
return [
|
|
"Update Server Object" => "updateServerObject",
|
|
"Validate Server Config" => "validateServerConfig",
|
|
];
|
|
}
|
|
|
|
function VirtFusionDirect_ServiceSingleSignOn(array $params)
|
|
{
|
|
try {
|
|
$module = new Module();
|
|
$token = $module->fetchLoginTokens($params['serviceid']);
|
|
|
|
if ($token) {
|
|
return ['success' => true, 'redirectTo' => $token];
|
|
}
|
|
|
|
return ['success' => false, 'errorMsg' => 'Unable to generate a login token. The server may not be active or the VirtFusion API may be unreachable.'];
|
|
} catch (\Exception $e) {
|
|
return ['success' => false, 'errorMsg' => $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Service functions
|
|
*/
|
|
function VirtFusionDirect_CreateAccount(array $params)
|
|
{
|
|
return (new ModuleFunctions())->createAccount($params);
|
|
}
|
|
|
|
function VirtFusionDirect_SuspendAccount(array $params)
|
|
{
|
|
return (new ModuleFunctions())->suspendAccount($params);
|
|
}
|
|
|
|
function VirtFusionDirect_UnsuspendAccount(array $params)
|
|
{
|
|
return (new ModuleFunctions())->unsuspendAccount($params);
|
|
}
|
|
|
|
function VirtFusionDirect_TerminateAccount(array $params)
|
|
{
|
|
return (new ModuleFunctions())->terminateAccount($params);
|
|
}
|
|
|
|
function VirtFusionDirect_updateServerObject(array $params)
|
|
{
|
|
return (new ModuleFunctions())->updateServerObject($params);
|
|
}
|
|
|
|
/**
|
|
* Allows changing of the package of a server
|
|
*
|
|
* @param array $params
|
|
* @return string
|
|
*/
|
|
function VirtFusionDirect_ChangePackage(array $params)
|
|
{
|
|
return (new ModuleFunctions())->changePackage($params);
|
|
}
|
|
|
|
function VirtFusionDirect_AdminServicesTabFields(array $params)
|
|
{
|
|
return (new ModuleFunctions())->adminServicesTabFields($params);
|
|
}
|
|
|
|
function VirtFusionDirect_AdminServicesTabFieldsSave(array $params)
|
|
{
|
|
(new ModuleFunctions())->adminServicesTabFieldsSave($params);
|
|
}
|
|
|
|
function VirtFusionDirect_ClientArea(array $params)
|
|
{
|
|
return (new ModuleFunctions())->clientArea($params);
|
|
}
|
|
|
|
/**
|
|
* Validates server configuration via dry run without creating the server.
|
|
*
|
|
* @param array $params
|
|
* @return string 'success' or error message
|
|
*/
|
|
function VirtFusionDirect_validateServerConfig(array $params)
|
|
{
|
|
return (new ModuleFunctions())->validateServerConfig($params);
|
|
}
|
|
|
|
/**
|
|
* Usage Update - called by WHMCS daily cron to sync bandwidth and disk usage.
|
|
*
|
|
* Updates tblhosting with disk and bandwidth usage data from VirtFusion.
|
|
* Fields updated: diskused, disklimit, bwused, bwlimit, lastupdate
|
|
*
|
|
* @param array $params Server access credentials
|
|
* @return string 'success' or error message
|
|
*/
|
|
function VirtFusionDirect_UsageUpdate(array $params)
|
|
{
|
|
try {
|
|
$module = new Module();
|
|
$cp = $module->getCP($params['serverid']);
|
|
|
|
if (!$cp) {
|
|
return 'No control server found for usage update.';
|
|
}
|
|
|
|
$services = \WHMCS\Database\Capsule::table('tblhosting')
|
|
->where('server', $params['serverid'])
|
|
->where('domainstatus', 'Active')
|
|
->get();
|
|
|
|
foreach ($services as $service) {
|
|
try {
|
|
$systemService = Database::getSystemService($service->id);
|
|
if (!$systemService) {
|
|
continue;
|
|
}
|
|
|
|
$request = $module->initCurl($cp['token']);
|
|
$data = $request->get($cp['url'] . '/servers/' . (int) $systemService->server_id);
|
|
|
|
if ($request->getRequestInfo('http_code') != 200) {
|
|
continue;
|
|
}
|
|
|
|
$serverData = json_decode($data, true);
|
|
if (!isset($serverData['data'])) {
|
|
continue;
|
|
}
|
|
|
|
$server = $serverData['data'];
|
|
$update = [];
|
|
|
|
// Disk usage (WHMCS expects MB)
|
|
if (isset($server['usage']['storage']['used'])) {
|
|
$update['diskused'] = round($server['usage']['storage']['used'] / 1048576);
|
|
}
|
|
if (isset($server['settings']['resources']['storage'])) {
|
|
$update['disklimit'] = (int) $server['settings']['resources']['storage'] * 1024;
|
|
}
|
|
|
|
// Bandwidth usage (WHMCS expects MB)
|
|
if (isset($server['usage']['traffic']['used'])) {
|
|
$update['bwused'] = round($server['usage']['traffic']['used'] / 1048576);
|
|
}
|
|
if (isset($server['settings']['resources']['traffic'])) {
|
|
$trafficGB = (int) $server['settings']['resources']['traffic'];
|
|
$update['bwlimit'] = $trafficGB > 0 ? $trafficGB * 1024 : 0;
|
|
}
|
|
|
|
if (!empty($update)) {
|
|
$update['lastupdate'] = date('Y-m-d H:i:s');
|
|
\WHMCS\Database\Capsule::table('tblhosting')
|
|
->where('id', $service->id)
|
|
->update($update);
|
|
}
|
|
} catch (\Exception $e) {
|
|
// Log but continue processing other services
|
|
\WHMCS\Module\Server\VirtFusionDirect\Log::insert('UsageUpdate:service:' . $service->id, [], $e->getMessage());
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return 'success';
|
|
} catch (\Exception $e) {
|
|
return 'Usage update failed: ' . $e->getMessage();
|
|
}
|
|
}
|