fix: add null/false guards, proper error handling, and VNC popup fix
- 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>
This commit is contained in:
@@ -26,17 +26,17 @@ switch ($vf->validateAction(true)) {
|
|||||||
$whmcsService = Database::getWhmcsService((int)$_GET['serviceID']);
|
$whmcsService = Database::getWhmcsService((int)$_GET['serviceID']);
|
||||||
|
|
||||||
if (!$whmcsService) {
|
if (!$whmcsService) {
|
||||||
$vf->output(['success' => false, 'errors' => 'Service not found.'], true, true, 200);
|
$vf->output(['success' => false, 'errors' => 'Service not found.'], true, true, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($whmcsService->domainstatus == 'Pending' || $whmcsService->domainstatus == 'Terminated' || $whmcsService->domainstatus == 'Cancelled' || $whmcsService->domainstatus == 'Fraud') {
|
if ($whmcsService->domainstatus == 'Pending' || $whmcsService->domainstatus == 'Terminated' || $whmcsService->domainstatus == 'Cancelled' || $whmcsService->domainstatus == 'Fraud') {
|
||||||
$vf->output(['success' => false, 'errors' => 'Server is not Active, Suspended or Completed. Not fetching remote data.'], true, true, 200);
|
$vf->output(['success' => false, 'errors' => 'Server is not Active, Suspended or Completed. Not fetching remote data.'], true, true, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $vf->fetchServerData((int)$_GET['serviceID']);
|
$data = $vf->fetchServerData((int)$_GET['serviceID']);
|
||||||
|
|
||||||
if (!$data) {
|
if (!$data) {
|
||||||
$vf->output(['success' => false, 'errors' => 'No data returned from VirtFusion.'], true, true, 200);
|
$vf->output(['success' => false, 'errors' => 'No data returned from VirtFusion.'], true, true, 502);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,12 +58,21 @@ switch ($vf->validateAction(true)) {
|
|||||||
$service = Database::getSystemService((int)$_GET['serviceID']);
|
$service = Database::getSystemService((int)$_GET['serviceID']);
|
||||||
|
|
||||||
if (!$service) {
|
if (!$service) {
|
||||||
$vf->output(['success' => false, 'errors' => 'Service not found'], true, true, 200);
|
$vf->output(['success' => false, 'errors' => 'Service not found'], true, true, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$whmcsService = Database::getWhmcsService((int)$_GET['serviceID']);
|
$whmcsService = Database::getWhmcsService((int)$_GET['serviceID']);
|
||||||
|
|
||||||
|
if (!$whmcsService) {
|
||||||
|
$vf->output(['success' => false, 'errors' => 'WHMCS service not found'], true, true, 404);
|
||||||
|
}
|
||||||
|
|
||||||
$cp = $vf->getCP($whmcsService->server);
|
$cp = $vf->getCP($whmcsService->server);
|
||||||
|
|
||||||
|
if (!$cp) {
|
||||||
|
$vf->output(['success' => false, 'errors' => 'Control server not found'], true, true, 500);
|
||||||
|
}
|
||||||
|
|
||||||
$request = $vf->initCurl($cp['token']);
|
$request = $vf->initCurl($cp['token']);
|
||||||
|
|
||||||
$data = $request->get($cp['url'] . '/users/' . $whmcsService->userid . '/byExtRelation');
|
$data = $request->get($cp['url'] . '/users/' . $whmcsService->userid . '/byExtRelation');
|
||||||
@@ -72,7 +81,7 @@ switch ($vf->validateAction(true)) {
|
|||||||
$vf->output(['success' => true, 'url' => $cp['base_url'], 'user' => json_decode($data, true)['data']], true, true, 200);
|
$vf->output(['success' => true, 'url' => $cp['base_url'], 'user' => json_decode($data, true)['data']], true, true, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
$vf->output(['success' => false, 'errors' => 'Received HTTP code ' . $request->getRequestInfo('http_code')], true, true, 200);
|
$vf->output(['success' => false, 'errors' => 'Received HTTP code ' . $request->getRequestInfo('http_code')], true, true, 502);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -80,6 +89,5 @@ switch ($vf->validateAction(true)) {
|
|||||||
default:
|
default:
|
||||||
/** No valid action was specified **/
|
/** No valid action was specified **/
|
||||||
|
|
||||||
$vf->output(['success' => false, 'errors' => 'invalid action'], true, true, 200);
|
$vf->output(['success' => false, 'errors' => 'invalid action'], true, true, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ add_hook('ClientAreaFooterOutput', 1, function ($vars) {
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
";
|
";
|
||||||
} catch (\Exception $e) {
|
} catch (\Throwable $e) {
|
||||||
// Silently fail - don't break the checkout page
|
// Silently fail - don't break the checkout page
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ class ConfigureService extends Module
|
|||||||
*/
|
*/
|
||||||
public function fetchPackageId(string $packageName): ?int
|
public function fetchPackageId(string $packageName): ?int
|
||||||
{
|
{
|
||||||
|
if (!$this->cp) return null;
|
||||||
|
|
||||||
$request = $this->initCurl($this->cp['token']);
|
$request = $this->initCurl($this->cp['token']);
|
||||||
|
|
||||||
$response = $request->get(
|
$response = $request->get(
|
||||||
@@ -70,6 +72,8 @@ class ConfigureService extends Module
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->cp) return null;
|
||||||
|
|
||||||
$request = $this->initCurl($this->cp['token']);
|
$request = $this->initCurl($this->cp['token']);
|
||||||
|
|
||||||
$response = $request->get(
|
$response = $request->get(
|
||||||
@@ -90,10 +94,14 @@ class ConfigureService extends Module
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$this->cp) return null;
|
||||||
|
|
||||||
$request = $this->initCurl($this->cp['token']);
|
$request = $this->initCurl($this->cp['token']);
|
||||||
|
|
||||||
$vfUser = $this->getVFUserDetails($user['id']);
|
$vfUser = $this->getVFUserDetails($user['id']);
|
||||||
|
|
||||||
|
if (!$vfUser) return null;
|
||||||
|
|
||||||
$response = $request->get(
|
$response = $request->get(
|
||||||
sprintf("%s/ssh_keys/user/%d", $this->cp['url'], $vfUser['id'])
|
sprintf("%s/ssh_keys/user/%d", $this->cp['url'], $vfUser['id'])
|
||||||
);
|
);
|
||||||
@@ -108,6 +116,8 @@ class ConfigureService extends Module
|
|||||||
*/
|
*/
|
||||||
public function getVFUserDetails(int $id): ?array
|
public function getVFUserDetails(int $id): ?array
|
||||||
{
|
{
|
||||||
|
if (!$this->cp) return null;
|
||||||
|
|
||||||
$request = $this->initCurl($this->cp['token']);
|
$request = $this->initCurl($this->cp['token']);
|
||||||
|
|
||||||
$response = $this->decodeResponseFromJson($request->get(
|
$response = $this->decodeResponseFromJson($request->get(
|
||||||
@@ -124,30 +134,35 @@ class ConfigureService extends Module
|
|||||||
*/
|
*/
|
||||||
public function initServerBuild(int $id, array $vars): bool
|
public function initServerBuild(int $id, array $vars): bool
|
||||||
{
|
{
|
||||||
|
if (!$this->cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($this->cp['token']);
|
$request = $this->initCurl($this->cp['token']);
|
||||||
|
|
||||||
// Generate a random 8 character hostname
|
// Generate a random 8 character hostname
|
||||||
$hostname = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, 8);
|
$hostname = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz'), 0, 8);
|
||||||
|
|
||||||
$inputData = [
|
$inputData = [
|
||||||
"operatingSystemId" => $vars['customfields']['Initial Operating System'],
|
"operatingSystemId" => $vars['customfields']['Initial Operating System'] ?? null,
|
||||||
"name" => $hostname,
|
"name" => $hostname,
|
||||||
"sshKeys" => [
|
"sshKeys" => [
|
||||||
$vars['customfields']['Initial SSH Key']
|
$vars['customfields']['Initial SSH Key'] ?? null
|
||||||
],
|
],
|
||||||
'email' => true
|
'email' => true
|
||||||
];
|
];
|
||||||
|
|
||||||
if (empty($vars['customfields']['Initial SSH Key'])) {
|
if (empty($vars['customfields']['Initial SSH Key'] ?? null)) {
|
||||||
unset($inputData['sshKeys']);
|
unset($inputData['sshKeys']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$request->addOption(CURLOPT_POSTFIELDS, json_encode($inputData));
|
$request->addOption(CURLOPT_POSTFIELDS, json_encode($inputData));
|
||||||
|
|
||||||
$request->post(
|
$response = $request->post(
|
||||||
sprintf("%s/servers/%d/build", $this->cp['url'], $id)
|
sprintf("%s/servers/%d/build", $this->cp['url'], $id)
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
$httpCode = $request->getRequestInfo('http_code');
|
||||||
|
Log::insert(__FUNCTION__, $request->getRequestInfo(), $response);
|
||||||
|
|
||||||
|
return ($httpCode == 200 || $httpCode == 201);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ class Curl
|
|||||||
{
|
{
|
||||||
if ($url === null) {
|
if ($url === null) {
|
||||||
if (!isset($this->customOptions[CURLOPT_URL]) || empty($this->customOptions[CURLOPT_URL])) {
|
if (!isset($this->customOptions[CURLOPT_URL]) || empty($this->customOptions[CURLOPT_URL])) {
|
||||||
exit('empty url');
|
throw new \RuntimeException('Curl: empty URL provided');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->addOption(CURLOPT_CUSTOMREQUEST, $method);
|
$this->addOption(CURLOPT_CUSTOMREQUEST, $method);
|
||||||
|
|||||||
@@ -66,8 +66,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/users/' . (int) $whmcsService->userid . '/serverAuthenticationTokens/' . (int) $service->server_id);
|
$data = $request->post($cp['url'] . '/users/' . (int) $whmcsService->userid . '/serverAuthenticationTokens/' . (int) $service->server_id);
|
||||||
|
|
||||||
@@ -124,7 +127,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->get($cp['url'] . '/servers/' . (int) $service->server_id);
|
$data = $request->get($cp['url'] . '/servers/' . (int) $service->server_id);
|
||||||
|
|
||||||
@@ -156,7 +163,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/power/' . $action);
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/power/' . $action);
|
||||||
|
|
||||||
@@ -191,7 +202,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
|
|
||||||
$buildData = [
|
$buildData = [
|
||||||
@@ -236,7 +251,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
|
|
||||||
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['name' => $newName]));
|
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['name' => $newName]));
|
||||||
@@ -263,7 +282,10 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$product = \WHMCS\Database\Capsule::table('tblproducts')->where('id', $whmcsService->packageid)->first();
|
$product = \WHMCS\Database\Capsule::table('tblproducts')->where('id', $whmcsService->packageid)->first();
|
||||||
if (!$product || !$product->configoption2) {
|
if (!$product || !$product->configoption2) {
|
||||||
@@ -322,7 +344,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->get($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface);
|
$data = $request->get($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface);
|
||||||
|
|
||||||
@@ -350,7 +376,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface . '/enable');
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface . '/enable');
|
||||||
|
|
||||||
@@ -379,7 +409,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface . '/disable');
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface . '/disable');
|
||||||
|
|
||||||
@@ -422,7 +456,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['rulesets' => $rulesetIds]));
|
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['rulesets' => $rulesetIds]));
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface . '/rules');
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface . '/rules');
|
||||||
@@ -463,7 +501,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['rulesets' => []]));
|
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['rulesets' => []]));
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface . '/rules');
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/firewall/' . $interface . '/rules');
|
||||||
@@ -506,7 +548,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/ipv4');
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/ipv4');
|
||||||
|
|
||||||
@@ -539,7 +585,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['address' => $ipAddress]));
|
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['address' => $ipAddress]));
|
||||||
$data = $request->delete($cp['url'] . '/servers/' . (int) $service->server_id . '/ipv4');
|
$data = $request->delete($cp['url'] . '/servers/' . (int) $service->server_id . '/ipv4');
|
||||||
@@ -567,7 +617,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/ipv6');
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/ipv6');
|
||||||
|
|
||||||
@@ -600,7 +654,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['subnet' => $subnet]));
|
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['subnet' => $subnet]));
|
||||||
$data = $request->delete($cp['url'] . '/servers/' . (int) $service->server_id . '/ipv6');
|
$data = $request->delete($cp['url'] . '/servers/' . (int) $service->server_id . '/ipv6');
|
||||||
@@ -635,7 +693,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['planId' => $planId]));
|
$request->addOption(CURLOPT_POSTFIELDS, json_encode(['planId' => $planId]));
|
||||||
|
|
||||||
@@ -672,7 +734,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->get($cp['url'] . '/servers/' . (int) $service->server_id . '/vnc');
|
$data = $request->get($cp['url'] . '/servers/' . (int) $service->server_id . '/vnc');
|
||||||
|
|
||||||
@@ -714,7 +780,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$request->addOption(CURLOPT_POSTFIELDS, json_encode([$resource => $value]));
|
$request->addOption(CURLOPT_POSTFIELDS, json_encode([$resource => $value]));
|
||||||
$data = $request->put($cp['url'] . '/servers/' . (int) $service->server_id . '/modify/' . $resource);
|
$data = $request->put($cp['url'] . '/servers/' . (int) $service->server_id . '/modify/' . $resource);
|
||||||
@@ -780,7 +850,11 @@ class Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($serviceID);
|
$whmcsService = Database::getWhmcsService($serviceID);
|
||||||
|
if (!$whmcsService) return false;
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return false;
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/users/' . $clientID . '/byExtRelation/resetPassword');
|
$data = $request->post($cp['url'] . '/users/' . $clientID . '/byExtRelation/resetPassword');
|
||||||
|
|
||||||
|
|||||||
@@ -183,7 +183,11 @@ class ModuleFunctions extends Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
||||||
|
if (!$whmcsService) return 'WHMCS service record not found.';
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return 'No control server found.';
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->put($cp['url'] . '/servers/' . (int) $service->server_id . '/package/' . (int) $params['configoption2']);
|
$data = $request->put($cp['url'] . '/servers/' . (int) $service->server_id . '/package/' . (int) $params['configoption2']);
|
||||||
$data = json_decode($data);
|
$data = json_decode($data);
|
||||||
@@ -224,8 +228,10 @@ class ModuleFunctions extends Module
|
|||||||
if ($service) {
|
if ($service) {
|
||||||
|
|
||||||
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
||||||
|
if (!$whmcsService) return 'WHMCS service record not found.';
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return 'No control server found.';
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->delete($cp['url'] . '/servers/' . (int) $service->server_id);
|
$data = $request->delete($cp['url'] . '/servers/' . (int) $service->server_id);
|
||||||
@@ -275,8 +281,11 @@ class ModuleFunctions extends Module
|
|||||||
if ($service) {
|
if ($service) {
|
||||||
|
|
||||||
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
||||||
|
if (!$whmcsService) return 'WHMCS service record not found.';
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return 'No control server found.';
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/suspend');
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/suspend');
|
||||||
$data = json_decode($data);
|
$data = json_decode($data);
|
||||||
@@ -319,8 +328,11 @@ class ModuleFunctions extends Module
|
|||||||
if ($service) {
|
if ($service) {
|
||||||
|
|
||||||
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
||||||
|
if (!$whmcsService) return 'WHMCS service record not found.';
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return 'No control server found.';
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->get($cp['url'] . '/servers/' . (int) $service->server_id);
|
$data = $request->get($cp['url'] . '/servers/' . (int) $service->server_id);
|
||||||
$data = json_decode($data);
|
$data = json_decode($data);
|
||||||
@@ -349,8 +361,11 @@ class ModuleFunctions extends Module
|
|||||||
|
|
||||||
if ($service) {
|
if ($service) {
|
||||||
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
$whmcsService = Database::getWhmcsService($params['serviceid']);
|
||||||
|
if (!$whmcsService) return 'WHMCS service record not found.';
|
||||||
|
|
||||||
$cp = $this->getCP($whmcsService->server);
|
$cp = $this->getCP($whmcsService->server);
|
||||||
|
if (!$cp) return 'No control server found.';
|
||||||
|
|
||||||
$request = $this->initCurl($cp['token']);
|
$request = $this->initCurl($cp['token']);
|
||||||
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/unsuspend');
|
$data = $request->post($cp['url'] . '/servers/' . (int) $service->server_id . '/unsuspend');
|
||||||
$data = json_decode($data);
|
$data = json_decode($data);
|
||||||
|
|||||||
@@ -56,14 +56,14 @@ class ServerResource
|
|||||||
$data['primaryNetwork']['mac'] = $server['network']['interfaces'][0]['mac'];
|
$data['primaryNetwork']['mac'] = $server['network']['interfaces'][0]['mac'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($server['network']['interfaces'][0]['ipv4'])) {
|
if (isset($server['network']['interfaces'][0]['ipv4']) && count($server['network']['interfaces'][0]['ipv4'])) {
|
||||||
$data['primaryNetwork']['ipv4'] = [];
|
$data['primaryNetwork']['ipv4'] = [];
|
||||||
foreach ($server['network']['interfaces'][0]['ipv4'] as $ip) {
|
foreach ($server['network']['interfaces'][0]['ipv4'] as $ip) {
|
||||||
$data['primaryNetwork']['ipv4'][] = $ip['address'];
|
$data['primaryNetwork']['ipv4'][] = $ip['address'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($server['network']['interfaces'][0]['ipv6'])) {
|
if (isset($server['network']['interfaces'][0]['ipv6']) && count($server['network']['interfaces'][0]['ipv6'])) {
|
||||||
$data['primaryNetwork']['ipv6'] = [];
|
$data['primaryNetwork']['ipv6'] = [];
|
||||||
foreach ($server['network']['interfaces'][0]['ipv6'] as $ip) {
|
foreach ($server['network']['interfaces'][0]['ipv6'] as $ip) {
|
||||||
$data['primaryNetwork']['ipv6'][] = $ip['subnet'] . '/' . $ip['cidr'];
|
$data['primaryNetwork']['ipv6'][] = $ip['subnet'] . '/' . $ip['cidr'];
|
||||||
|
|||||||
@@ -466,6 +466,9 @@ function vfOpenVnc(serviceId, systemUrl) {
|
|||||||
spinner.show();
|
spinner.show();
|
||||||
alertDiv.hide();
|
alertDiv.hide();
|
||||||
|
|
||||||
|
// Open window immediately in click context to avoid popup blockers
|
||||||
|
var vncWindow = window.open("", "_blank");
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
@@ -474,25 +477,28 @@ function vfOpenVnc(serviceId, systemUrl) {
|
|||||||
if (response.success && response.data) {
|
if (response.success && response.data) {
|
||||||
var data = response.data.data || response.data;
|
var data = response.data.data || response.data;
|
||||||
if (data.url) {
|
if (data.url) {
|
||||||
window.open(data.url, "_blank");
|
vncWindow.location.href = data.url;
|
||||||
} else if (data.host && data.port) {
|
} else if (data.host && data.port) {
|
||||||
// Build noVNC URL if available
|
// Build noVNC URL if available
|
||||||
var vncUrl = "https://" + data.host + ":" + data.port;
|
var vncUrl = "https://" + data.host + ":" + data.port;
|
||||||
if (data.token) {
|
if (data.token) {
|
||||||
vncUrl += "?token=" + encodeURIComponent(data.token);
|
vncUrl += "?token=" + encodeURIComponent(data.token);
|
||||||
}
|
}
|
||||||
window.open(vncUrl, "_blank");
|
vncWindow.location.href = vncUrl;
|
||||||
} else {
|
} else {
|
||||||
|
vncWindow.close();
|
||||||
alertDiv.removeClass("alert-danger").addClass("alert-success");
|
alertDiv.removeClass("alert-danger").addClass("alert-success");
|
||||||
alertDiv.text("VNC session is ready. Check your VirtFusion control panel for access.");
|
alertDiv.text("VNC session is ready. Check your VirtFusion control panel for access.");
|
||||||
alertDiv.show();
|
alertDiv.show();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
vncWindow.close();
|
||||||
alertDiv.removeClass("alert-success").addClass("alert-danger");
|
alertDiv.removeClass("alert-success").addClass("alert-danger");
|
||||||
alertDiv.text(response.errors || "VNC console is not available.");
|
alertDiv.text(response.errors || "VNC console is not available.");
|
||||||
alertDiv.show();
|
alertDiv.show();
|
||||||
}
|
}
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
|
vncWindow.close();
|
||||||
alertDiv.removeClass("alert-success").addClass("alert-danger");
|
alertDiv.removeClass("alert-success").addClass("alert-danger");
|
||||||
alertDiv.text("An error occurred. The server may be powered off.");
|
alertDiv.text("An error occurred. The server may be powered off.");
|
||||||
alertDiv.show();
|
alertDiv.show();
|
||||||
|
|||||||
Reference in New Issue
Block a user