Módulo VPSManager para WHMCS con configuración externa, acceso seguro al panel y métricas Graphite para LX.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

46 line
1.4 KiB

  1. <?php
  2. namespace VPSManager;
  3. require_once __DIR__ . '/Config.php';
  4. class VPSManager
  5. {
  6. public function getParam($name)
  7. {
  8. return isset($this->params[$name]) ? $this->params[$name] : '';
  9. }
  10. public function apiCall($route)
  11. {
  12. if (!in_array($route, ['nodes', 'packs'], true)) {
  13. throw new \InvalidArgumentException('Ruta de API no permitida.');
  14. }
  15. $base = Config::url(Config::load(), 'vpsmanager_api_url', false);
  16. if (!function_exists('curl_init')) {
  17. throw new \RuntimeException('Transporte del módulo no disponible.');
  18. }
  19. $ch = curl_init($base . '/' . $route);
  20. curl_setopt_array($ch, [
  21. CURLOPT_RETURNTRANSFER => true,
  22. CURLOPT_CONNECTTIMEOUT => 3,
  23. CURLOPT_TIMEOUT => 10,
  24. CURLOPT_SSL_VERIFYPEER => true,
  25. CURLOPT_SSL_VERIFYHOST => 2,
  26. CURLOPT_FOLLOWLOCATION => false,
  27. ]);
  28. try {
  29. $body = curl_exec($ch);
  30. $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  31. } finally {
  32. curl_close($ch);
  33. }
  34. if ($body === false || $status < 200 || $status >= 300) {
  35. throw new \RuntimeException('API del módulo no disponible.');
  36. }
  37. $data = json_decode($body, true);
  38. if (!is_array($data)) {
  39. throw new \RuntimeException('Respuesta de API no válida.');
  40. }
  41. return $data;
  42. }
  43. }