This commit is contained in:
Yuri
2025-11-13 10:59:35 +01:00
parent dc5e603870
commit dbb00718c0
4 changed files with 283 additions and 9 deletions
+82 -3
View File
@@ -69,7 +69,7 @@ function ArkhostVPSAG_API(array $params) {
);
$data += array(
'hostname' => $params['domain'] ?? 'vps.example.com',
// 'hostname' => removed - let VPSAG generate the hostname automatically
'notify_url' => Setting::getValue('SystemURL') . '/modules/servers/ArkhostVPSAG/callback.php',
'os' => ArkhostVPSAG_GetOption($params, 'osid'),
'billing_term' => $billingCycles[$params['model']['billingcycle']] ?? 1,
@@ -323,6 +323,76 @@ function ArkhostVPSAG_Error($func, $params, Exception $err) {
}
function ArkhostVPSAG_MetaData() {
// Register sidebar hook here to ensure it's always loaded
static $hookRegistered = false;
if (!$hookRegistered) {
$hookRegistered = true;
add_hook('ClientAreaPrimarySidebar', 100, function(\WHMCS\View\Menu\Item $primarySidebar) {
$serviceId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (!$serviceId) return;
try {
$service = Capsule::table('tblhosting')
->join('tblproducts', 'tblhosting.packageid', '=', 'tblproducts.id')
->where('tblhosting.id', $serviceId)
->select('tblhosting.*', 'tblproducts.servertype')
->first();
if (!$service || $service->servertype !== 'ArkhostVPSAG' || $service->domainstatus !== 'Active') {
return;
}
} catch (Exception $e) {
return;
}
$actionsPanel = $primarySidebar->getChild('Service Details Actions');
if (!$actionsPanel) return;
// Load language strings
if (!function_exists('ArkhostVPSAG_Translation')) {
require_once __DIR__ . '/ArkhostVPSAG.php';
}
$_LANG = ArkhostVPSAG_Translation();
// Remove only OUR custom action buttons (created by ClientAreaCustomButtonArray with cog icons)
// They have modop=custom in the URI
$existingChildren = $actionsPanel->getChildren();
foreach ($existingChildren as $childName => $child) {
$uri = $child->getUri();
if ($uri && strpos($uri, 'modop=custom') !== false) {
$actionsPanel->removeChild($childName);
}
}
// Add custom action buttons with proper icons
$actionsPanel->addChild('VPSStart', [
'label' => $_LANG['Start'],
'uri' => 'clientarea.php?action=productdetails&id=' . $serviceId . '&modop=custom&a=Start',
'order' => 10,
'icon' => 'fa-play'
]);
$actionsPanel->addChild('VPSStop', [
'label' => $_LANG['Stop'],
'uri' => 'clientarea.php?action=productdetails&id=' . $serviceId . '&modop=custom&a=Stop',
'order' => 20,
'icon' => 'fa-stop'
]);
$actionsPanel->addChild('VPSRestart', [
'label' => $_LANG['Restart'],
'uri' => 'clientarea.php?action=productdetails&id=' . $serviceId . '&modop=custom&a=Reboot',
'order' => 30,
'icon' => 'fa-sync'
]);
$actionsPanel->addChild('VPSVNC', [
'label' => $_LANG['VNC'],
'uri' => 'clientarea.php?action=productdetails&id=' . $serviceId . '&modop=custom&a=VNC',
'order' => 40,
'icon' => 'fa-desktop',
'attributes' => ['target' => '_blank']
]);
});
}
return array(
'DisplayName' => 'ArkHost - VPSAG',
'APIVersion' => '1.1',
@@ -514,7 +584,7 @@ function ArkhostVPSAG_CreateAccount(array $params) {
function ArkhostVPSAG_SuspendAccount(array $params) {
try {
$params['action'] = 'Disable';
$params['action'] = 'Stop';
ArkhostVPSAG_API($params);
} catch (Exception $err) {
ArkhostVPSAG_Error(__FUNCTION__, $params, $err);
@@ -526,7 +596,7 @@ function ArkhostVPSAG_SuspendAccount(array $params) {
function ArkhostVPSAG_UnsuspendAccount(array $params) {
try {
$params['action'] = 'Enable';
$params['action'] = 'Start';
ArkhostVPSAG_API($params);
} catch (Exception $err) {
ArkhostVPSAG_Error(__FUNCTION__, $params, $err);
@@ -737,6 +807,8 @@ function ArkhostVPSAG_DeliverFile(array $params) {
// This function is required for WHMCS to handle the custom actions
// The hook in MetaData() replaces the sidebar buttons to remove cog icons
function ArkhostVPSAG_ClientAreaCustomButtonArray() {
$_LANG = ArkhostVPSAG_Translation();
@@ -777,6 +849,13 @@ function ArkhostVPSAG_ClientArea(array $params) {
throw new Exception('Unable to retrieve server information from API');
}
// Sync the domain field with VPS hostname so it shows in WHMCS product details
if (isset($serverInfo['hostname']) && !empty($serverInfo['hostname'])) {
Capsule::table('tblhosting')
->where('id', $params['serviceid'])
->update(['domain' => $serverInfo['hostname']]);
}
$params['action'] = 'Operating Systems - Server';
$operatingSystemsTemp = ArkhostVPSAG_API($params);
+73
View File
@@ -0,0 +1,73 @@
<?php
/**
* WHMCS Server Module - VPSAG Hooks
*
* @package WHMCS
* @version 1.4
* @copyright Copyright (c) ArkHost 2025
* @author ArkHost <support@arkhost.com>
* @link https://arkhost.com
*/
use WHMCS\Database\Capsule;
/**
* Hide default WHMCS product details and cog icons for ArkhostVPSAG products
* Injects CSS early to prevent flash of content
*/
add_hook('ClientAreaHeadOutput', 1, function($vars) {
// Only run on product details page
if (!isset($_GET['action']) || $_GET['action'] !== 'productdetails') {
return '';
}
// Get the service ID from the request
$serviceId = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (!$serviceId) {
return '';
}
// Check if this service uses the ArkhostVPSAG module
try {
$service = Capsule::table('tblhosting')
->where('id', $serviceId)
->first();
if (!$service || $service->servertype !== 'ArkhostVPSAG') {
return '';
}
} catch (Exception $e) {
return '';
}
// Inject CSS early in the HEAD to prevent flash
// This works for both active and suspended services
return <<<HTML
<style>
/* Hide WHMCS default product details (Domain, Username, Server Name, IP, Visit Website) for ArkhostVPSAG */
#domain > .row:nth-child(2),
#domain > .row:nth-child(3),
#domain > .row:nth-child(4) {
display: none !important;
}
#domain > br {
display: none !important;
}
#domain > p {
display: none !important;
}
/* Hide cog icons from custom action buttons IMMEDIATELY */
.list-group-item[href*="modop=custom"] i.fa-cog,
.list-group-item[href*="modop=custom"] i.fas.fa-cog,
.list-group-item[href*="modop=custom"] .fa-cog,
.list-group-item[href*="modop=custom"] i.fa-wrench,
a[href*="modop=custom"] i.fa-cog,
a[href*="modop=custom"] i.fas.fa-cog,
a[href*="modop=custom"] .fa-cog {
display: none !important;
}
</style>
HTML;
});
@@ -6,20 +6,38 @@
* @author ArkHost <support@arkhost.com>
*}
<style>
/* Hide WHMCS default product details (Domain, Username, Server Name, IP, Visit Website) */
#domain > .row {
display: none !important;
/* Hide WHMCS default product details except Domain (keep Domain visible to show VPS hostname) */
/* Hide Username, Server Name, IP Address rows using nth-child selectors */
#domain > .row:nth-child(2) {
display: none !important; /* Username */
}
#domain > .row:nth-child(3) {
display: none !important; /* Server Name */
}
#domain > .row:nth-child(4) {
display: none !important; /* IP Address */
}
#domain > br {
display: none !important;
}
#domain > p {
display: none !important;
display: none !important; /* Visit Website button */
}
/* Hide original Domain label - will be replaced with Hostname via JavaScript */
#domain > .row:nth-child(1) .col-sm-5 strong {
visibility: hidden;
position: relative;
}
#domain > .row:nth-child(1) .col-sm-5 strong::after {
visibility: visible;
position: absolute;
left: 0;
content: attr(data-hostname-label);
}
.arkhost-vps-container {
font-family: 'Arial', sans-serif;
margin: 15px 0;
@@ -2105,5 +2123,43 @@
// Wait for WHMCS jQuery to be ready and use it
jQuery(document).ready(function($) {
// WHMCS already loads Bootstrap and Font Awesome - no need to load additional libraries
// Replace "Domain" label with translated "Hostname" label
var hostnameLabel = '{$_LANG.Overview.Hostname|escape:"javascript"}';
$('#domain > .row:nth-child(1) .col-sm-5 strong').attr('data-hostname-label', hostnameLabel);
// Intercept sidebar VPS action button clicks to show confirmation popups
// Use capture phase to intercept before other handlers
$('.list-group-item').each(function() {
var $link = $(this);
var href = $link.attr('href');
if (!href) return;
// Remove any existing click handlers and add our own
if (href.indexOf('modop=custom&a=Start') !== -1) {
$link.off('click').on('click', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
ArkHostVPS_API('Start');
return false;
});
} else if (href.indexOf('modop=custom&a=Stop') !== -1) {
$link.off('click').on('click', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
confirmStop();
return false;
});
} else if (href.indexOf('modop=custom&a=Reboot') !== -1) {
$link.off('click').on('click', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
confirmRestart();
return false;
});
}
});
});
</script>