Módulo VPSManager para WHMCS con configuración externa, acceso seguro al panel y métricas Graphite para LX.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
2.0 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() || !$client->hasPermission('products')) return null;
  16. $service = \WHMCS\Database\Capsule::table('tblhosting')->where('id', $id)->where('userid', $client->id)->first();
  17. if (!$service) return null;
  18. try { $keys = BackupOption::applicable($service->packageid); }
  19. catch (\Throwable $e) { Backups::diagnostic('OPTION_DEFINITION', $id); return null; }
  20. $fields = \WHMCS\Database\Capsule::table('tblcustomfields')
  21. ->where('type', 'product')->where('relid', $service->packageid)
  22. ->where('fieldname', 'backuppc_host')->get();
  23. if (count($fields) !== 1) return ['serviceid' => $id, 'option_keys' => $keys, 'host' => null];
  24. $field = $fields[0];
  25. if ($field->fieldtype !== 'text' || $field->adminonly !== 'on'
  26. || $field->showorder !== '' || $field->showinvoice !== '') return ['serviceid' => $id, 'option_keys' => $keys, 'host' => null];
  27. $values = \WHMCS\Database\Capsule::table('tblcustomfieldsvalues')->where('fieldid', $field->id)->where('relid', $id)->get();
  28. return ['serviceid' => $id, 'option_keys' => $keys, 'host' => count($values) === 1 ? $values[0]->value : null];
  29. } catch (\Throwable $e) {
  30. return null; // Unsupported WHMCS authentication/schema fails closed.
  31. }
  32. }
  33. }