Surfboard.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Utils;
  3. class Surfboard
  4. {
  5. public static function buildShadowsocks($password, $server)
  6. {
  7. $config = [
  8. "{$server['name']}=custom",
  9. "{$server['host']}",
  10. "{$server['port']}",
  11. "{$server['cipher']}",
  12. "{$password}",
  13. 'https://raw.githubusercontent.com/Hackl0us/proxy-tool-backup/master/SSEncrypt.module',
  14. 'tfo=true',
  15. 'udp-relay=true'
  16. ];
  17. $config = array_filter($config);
  18. $uri = implode(',', $config);
  19. $uri .= "\r\n";
  20. return $uri;
  21. }
  22. public static function buildVmess($uuid, $server)
  23. {
  24. $config = [
  25. "{$server['name']}=vmess",
  26. "{$server['host']}",
  27. "{$server['port']}",
  28. "username={$uuid}",
  29. 'tfo=true',
  30. 'udp-relay=true'
  31. ];
  32. if ($server['network'] === 'tcp') {
  33. if ($server['tls']) {
  34. $tlsSettings = json_decode($server['tlsSettings'], true);
  35. array_push($config, $server['tls'] ? 'tls=true' : 'tls=false');
  36. if (!empty($tlsSettings['allowInsecure'])) {
  37. array_push($config, $tlsSettings['allowInsecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
  38. }
  39. }
  40. }
  41. if ($server['network'] === 'ws') {
  42. array_push($config, 'ws=true');
  43. if ($server['tls']) {
  44. $tlsSettings = json_decode($server['tlsSettings'], true);
  45. array_push($config, $server['tls'] ? 'tls=true' : 'tls=false');
  46. if (!empty($tlsSettings['allowInsecure'])) {
  47. array_push($config, $tlsSettings['allowInsecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
  48. }
  49. }
  50. if ($server['networkSettings']) {
  51. $wsSettings = json_decode($server['networkSettings'], true);
  52. if (isset($wsSettings['path'])) array_push($config, "ws-path={$wsSettings['path']}");
  53. if (isset($wsSettings['headers']['Host'])) array_push($config, "ws-headers=host:{$wsSettings['headers']['Host']}");
  54. }
  55. }
  56. $uri = implode(',', $config);
  57. $uri .= "\r\n";
  58. return $uri;
  59. }
  60. }