Added changes done by BlinkohHost.

See https://github.com/BlinkohHost/virtfusion-whmcs-module
This commit is contained in:
2023-09-10 20:36:22 -04:00
parent e5570785db
commit 07f3c69977
2 changed files with 49 additions and 2 deletions

View File

@@ -83,9 +83,16 @@ function VirtFusionDirect_updateServerObject(array $params)
return (new ModuleFunctions())->updateServerObject($params); return (new ModuleFunctions())->updateServerObject($params);
} }
/**
* Allows changing of the package of a server
*
* @author https://github.com/BlinkohHost/virtfusion-whmcs-module
* @param array $params
* @return string
*/
function VirtFusionDirect_ChangePackage(array $params) function VirtFusionDirect_ChangePackage(array $params)
{ {
return 'success'; return (new ModuleFunctions())->changePackage($params);
} }
function VirtFusionDirect_AdminServicesTabFields(array $params) function VirtFusionDirect_AdminServicesTabFields(array $params)
@@ -101,4 +108,4 @@ function VirtFusionDirect_AdminServicesTabFieldsSave(array $params)
function VirtFusionDirect_ClientArea(array $params) function VirtFusionDirect_ClientArea(array $params)
{ {
return (new ModuleFunctions())->clientArea($params); return (new ModuleFunctions())->clientArea($params);
} }

View File

@@ -181,6 +181,46 @@ class ModuleFunctions extends Module
} }
} }
// This function was implemented by Zander Scott / awildboop of Blinkoh, LLC
// Please read this function thoroughly before use to ensure security & integrity
/**
* Allows changing of the package of a server
*
* @author https://github.com/BlinkohHost/virtfusion-whmcs-module
* @param $params
* @return string
*/
public function changePackage($params)
{
$service = Database::getSystemService($params['serviceid']);
if ($service) {
$whmcsService = Database::getWhmcsService($params['serviceid']);
$cp = $this->getCP($whmcsService->server);
$request = $this->initCurl($cp['token']);
$data = $request->put($cp['url'] . '/servers/' . $service->server_id . '/package/' . $params['configoption2']);
$data = json_decode($data);
Log::insert(__FUNCTION__, $request->getRequestInfo(), $data);
switch ($request->getRequestInfo('http_code')) {
case 204:
return 'success';
case 404:
return '404 was returned from the web service without the msg property. The service may be currently unavailable.';
case 423:
if (property_exists($data, 'msg')) {
return $data->msg;
}
default:
return 'Update package request failed. The web service reported HTTP code ' . $request->getRequestInfo('http_code');
}
}
return 'Service not found.';
}
/** /**
* *
* TERMINATE SERVER * TERMINATE SERVER