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:
@@ -466,6 +466,9 @@ function vfOpenVnc(serviceId, systemUrl) {
|
||||
spinner.show();
|
||||
alertDiv.hide();
|
||||
|
||||
// Open window immediately in click context to avoid popup blockers
|
||||
var vncWindow = window.open("", "_blank");
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
@@ -474,25 +477,28 @@ function vfOpenVnc(serviceId, systemUrl) {
|
||||
if (response.success && response.data) {
|
||||
var data = response.data.data || response.data;
|
||||
if (data.url) {
|
||||
window.open(data.url, "_blank");
|
||||
vncWindow.location.href = data.url;
|
||||
} else if (data.host && data.port) {
|
||||
// Build noVNC URL if available
|
||||
var vncUrl = "https://" + data.host + ":" + data.port;
|
||||
if (data.token) {
|
||||
vncUrl += "?token=" + encodeURIComponent(data.token);
|
||||
}
|
||||
window.open(vncUrl, "_blank");
|
||||
vncWindow.location.href = vncUrl;
|
||||
} else {
|
||||
vncWindow.close();
|
||||
alertDiv.removeClass("alert-danger").addClass("alert-success");
|
||||
alertDiv.text("VNC session is ready. Check your VirtFusion control panel for access.");
|
||||
alertDiv.show();
|
||||
}
|
||||
} else {
|
||||
vncWindow.close();
|
||||
alertDiv.removeClass("alert-success").addClass("alert-danger");
|
||||
alertDiv.text(response.errors || "VNC console is not available.");
|
||||
alertDiv.show();
|
||||
}
|
||||
}).fail(function () {
|
||||
vncWindow.close();
|
||||
alertDiv.removeClass("alert-success").addClass("alert-danger");
|
||||
alertDiv.text("An error occurred. The server may be powered off.");
|
||||
alertDiv.show();
|
||||
|
||||
Reference in New Issue
Block a user