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.
 
 
 
 
 
 

36 lines
2.0 KiB

  1. <?php
  2. namespace VPSManager;
  3. require_once __DIR__ . '/Config.php';
  4. final class BackupHttp
  5. {
  6. // Private server configuration only; no URL, action or arbitrary query arguments.
  7. public static function getHostSummary(array $config, string $host): string
  8. {
  9. if (!Backups::validHost($host) || !function_exists('curl_init')) throw new \RuntimeException('TRANSPORT');
  10. $endpoint = Config::url($config, 'endpoint');
  11. $user = $config['username'] ?? null; $password = $config['password'] ?? null;
  12. if (!is_string($user) || !is_string($password) || $user === '' || $password === ''
  13. || strpos($user, ':') !== false || preg_match('/[\x00-\x1f\x7f]/', $user . $password)) throw new \RuntimeException('AUTH_CONFIG');
  14. $url = $endpoint . '?' . http_build_query(['host' => $host], '', '&', PHP_QUERY_RFC3986);
  15. $ch = curl_init($url); $body = '';
  16. if ($ch === false) throw new \RuntimeException('TRANSPORT');
  17. try {
  18. curl_setopt_array($ch, [
  19. CURLOPT_HTTPGET => true, CURLOPT_FOLLOWLOCATION => false, CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
  20. CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2,
  21. CURLOPT_CONNECTTIMEOUT => Backups::limit($config, 'connect_timeout_seconds', 2, 1, 10),
  22. CURLOPT_TIMEOUT => Backups::limit($config, 'timeout_seconds', 5, 1, 30),
  23. CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERNAME => $user, CURLOPT_PASSWORD => $password,
  24. CURLOPT_WRITEFUNCTION => static function ($ch, string $chunk) use (&$body, $config): int {
  25. if (strlen($body) + strlen($chunk) > Backups::limit($config, 'max_response_bytes', 2097152, 1024, 2097152)) return 0;
  26. $body .= $chunk;
  27. return strlen($chunk);
  28. },
  29. ]);
  30. if (curl_exec($ch) === false || curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) throw new \RuntimeException('HTTP');
  31. return $body;
  32. } finally { curl_close($ch); }
  33. }
  34. }