Módulo VPSManager para WHMCS con configuración externa, acceso seguro al panel y métricas Graphite para LX.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

49 rindas
2.8 KiB

  1. <?php
  2. namespace VPSManager;
  3. require_once __DIR__ . '/BackupOption.php';
  4. final class BackupAccess
  5. {
  6. // Invoked only by WHMCS module callbacks, never a standalone public endpoint.
  7. // No request service ID, client ID or host is trusted here.
  8. public static function context(array $params): ?array
  9. {
  10. try {
  11. $id = filter_var($params['serviceid'] ?? null, FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
  12. if (!$id || !class_exists('WHMCS\\Authentication\\CurrentUser')) return null;
  13. $current = new \WHMCS\Authentication\CurrentUser();
  14. $client = $current->client();
  15. if (!$client || !$current->isAuthenticatedUser()) return null;
  16. $user = $current->user();
  17. if (!$user) return null;
  18. // Permissions belong to the authenticated user's account relationship.
  19. // WHMCS 8.13 returns an array of Client models for this permission.
  20. $permittedClients = $user->getClientsByPermission('products');
  21. if (!is_array($permittedClients)) return null;
  22. $permitted = false;
  23. foreach ($permittedClients as $permittedClient) {
  24. if ($permittedClient instanceof \WHMCS\User\Client
  25. && (string) $permittedClient->id === (string) $client->id) $permitted = true;
  26. }
  27. if (!$permitted) return null;
  28. $service = \WHMCS\Database\Capsule::table('tblhosting')->where('id', $id)->where('userid', $client->id)->first();
  29. if (!$service) return null;
  30. try { $keys = BackupOption::applicable($service->packageid); }
  31. catch (\Throwable $e) { Backups::diagnostic('OPTION_DEFINITION', $id); return null; }
  32. // Do not even resolve the private mapping before entitlement is established.
  33. if (!Backups::entitled($params, Config::load()['backups'] ?? [], $keys)) return null;
  34. $fields = \WHMCS\Database\Capsule::table('tblcustomfields')
  35. ->where('type', 'product')->where('relid', $service->packageid)
  36. ->where('fieldname', 'backuppc_host')->get();
  37. if (count($fields) !== 1) return ['serviceid' => $id, 'option_keys' => $keys, 'host' => null];
  38. $field = $fields[0];
  39. if ($field->fieldtype !== 'text' || $field->adminonly !== 'on'
  40. || $field->showorder !== '' || $field->showinvoice !== '') return ['serviceid' => $id, 'option_keys' => $keys, 'host' => null];
  41. $values = \WHMCS\Database\Capsule::table('tblcustomfieldsvalues')->where('fieldid', $field->id)->where('relid', $id)->get();
  42. return ['serviceid' => $id, 'option_keys' => $keys, 'host' => count($values) === 1 ? $values[0]->value : null];
  43. } catch (\Throwable $e) {
  44. return null; // Unsupported WHMCS authentication/schema fails closed.
  45. }
  46. }
  47. }