All checks were successful
Publish Release / release (push) Successful in 10s
- Auto-create 'Initial Operating System' and 'Initial SSH Key' custom fields via Database::ensureCustomFields() on module load, eliminating the manual modify.sql step - Delete modify.sql (no longer needed) - Add try/catch blocks around every DB operation and API call across all PHP files per CLAUDE.md error handling rules - Add comprehensive PHPDoc to all classes, methods, and properties - Set up Laravel Pint (laravel/pint) with Laravel-style preset for consistent code formatting across the codebase - Add git pre-commit hook (hooks/pre-commit) that runs Pint on staged PHP files, auto-installed via Composer post-install/post-update scripts - Simplify README installation to a single copy-paste command Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
99 lines
3.3 KiB
PHP
99 lines
3.3 KiB
PHP
<?php
|
|
|
|
require dirname(__DIR__, 3) . '/init.php';
|
|
|
|
/**
|
|
* Admin-facing AJAX API endpoint.
|
|
*
|
|
* Requires WHMCS admin authentication. Provides server data lookup
|
|
* and user impersonation for the admin services tab.
|
|
*/
|
|
|
|
use WHMCS\Module\Server\VirtFusionDirect\Database;
|
|
use WHMCS\Module\Server\VirtFusionDirect\Log;
|
|
use WHMCS\Module\Server\VirtFusionDirect\Module;
|
|
use WHMCS\Module\Server\VirtFusionDirect\ServerResource;
|
|
|
|
$vf = new Module;
|
|
|
|
try {
|
|
|
|
$vf->adminOnly();
|
|
|
|
switch ($vf->validateAction(true)) {
|
|
|
|
/**
|
|
* Get server information.
|
|
*/
|
|
case 'serverData':
|
|
|
|
$serviceID = $vf->validateServiceID(true);
|
|
|
|
$whmcsService = Database::getWhmcsService($serviceID);
|
|
|
|
if (! $whmcsService) {
|
|
$vf->output(['success' => false, 'errors' => 'Service not found.'], true, true, 404);
|
|
break;
|
|
}
|
|
|
|
if (in_array($whmcsService->domainstatus, ['Pending', 'Terminated', 'Cancelled', 'Fraud'], true)) {
|
|
$vf->output(['success' => false, 'errors' => 'Server is not Active, Suspended or Completed. Not fetching remote data.'], true, true, 400);
|
|
break;
|
|
}
|
|
|
|
$data = $vf->fetchServerData($serviceID);
|
|
|
|
if (! $data) {
|
|
$vf->output(['success' => false, 'errors' => 'No data returned from VirtFusion.'], true, true, 502);
|
|
break;
|
|
}
|
|
|
|
$vf->updateWhmcsServiceParamsOnServerObject($serviceID, $data);
|
|
$vf->output(['success' => true, 'data' => (new ServerResource)->process($data)], true, true, 200);
|
|
break;
|
|
|
|
/**
|
|
* Impersonate server owner.
|
|
*/
|
|
case 'impersonateServerOwner':
|
|
|
|
$serviceID = $vf->validateServiceID(true);
|
|
|
|
$service = Database::getSystemService($serviceID);
|
|
if (! $service) {
|
|
$vf->output(['success' => false, 'errors' => 'Service not found'], true, true, 404);
|
|
break;
|
|
}
|
|
|
|
$whmcsService = Database::getWhmcsService($serviceID);
|
|
if (! $whmcsService) {
|
|
$vf->output(['success' => false, 'errors' => 'WHMCS service not found'], true, true, 404);
|
|
break;
|
|
}
|
|
|
|
$cp = $vf->getCP($whmcsService->server);
|
|
if (! $cp) {
|
|
$vf->output(['success' => false, 'errors' => 'Control server not found'], true, true, 500);
|
|
break;
|
|
}
|
|
|
|
$request = $vf->initCurl($cp['token']);
|
|
$data = $request->get($cp['url'] . '/users/' . (int) $whmcsService->userid . '/byExtRelation');
|
|
|
|
if ($request->getRequestInfo('http_code') === 200) {
|
|
$vf->output(['success' => true, 'url' => $cp['base_url'], 'user' => json_decode($data, true)['data']], true, true, 200);
|
|
break;
|
|
}
|
|
|
|
$vf->output(['success' => false, 'errors' => 'Unable to fetch user data'], true, true, 502);
|
|
break;
|
|
|
|
default:
|
|
$vf->output(['success' => false, 'errors' => 'invalid action'], true, true, 400);
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
Log::insert('admin.php', [], $e->getMessage());
|
|
$vf->output(['success' => false, 'errors' => 'An unexpected error occurred'], true, true, 500);
|
|
}
|