Módulo VPSManager para WHMCS con configuración externa, acceso seguro al panel y métricas Graphite para LX.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

44 lines
1.6 KiB

  1. <?php
  2. namespace VPSManager;
  3. final class Config
  4. {
  5. public static function load(): array
  6. {
  7. $path = getenv('O6H_VPSMANAGER_CONFIG') ?: '/etc/open6hosting/whmcs-vpsmanager.php';
  8. if (!is_file($path) || !is_readable($path)) {
  9. throw new \RuntimeException('Configuración del módulo no disponible.');
  10. }
  11. // Private PHP configuration is trusted administrator-controlled code.
  12. ob_start();
  13. try {
  14. $config = (static function ($file) { return include $file; })($path);
  15. } catch (\Throwable $e) {
  16. throw new \RuntimeException('Configuración del módulo no válida.');
  17. } finally {
  18. ob_end_clean();
  19. }
  20. if (!is_array($config)) {
  21. throw new \RuntimeException('Configuración del módulo no válida.');
  22. }
  23. return $config;
  24. }
  25. public static function url(array $config, string $key, bool $httpsOnly = true): string
  26. {
  27. $url = $config[$key] ?? null;
  28. if (!is_string($url) || !filter_var($url, FILTER_VALIDATE_URL)) {
  29. throw new \RuntimeException('URL de configuración no válida.');
  30. }
  31. $parts = parse_url($url);
  32. $allowed = $httpsOnly ? ['https'] : ['https', 'http'];
  33. if (!$parts || !in_array($parts['scheme'] ?? '', $allowed, true)
  34. || isset($parts['user']) || isset($parts['pass'])
  35. || isset($parts['query']) || isset($parts['fragment'])
  36. || preg_match('/[\x00-\x20\x7f]/', $url)) {
  37. throw new \RuntimeException('URL de configuración no válida.');
  38. }
  39. return rtrim($url, '/');
  40. }
  41. }