Surfboard.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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['tls']) {
  33. array_push($config, 'tls=true');
  34. if ($server['tlsSettings']) {
  35. $tlsSettings = json_decode($server['tlsSettings'], true);
  36. if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
  37. array_push($config, 'skip-cert-verify=' . ($tlsSettings['allowInsecure'] ? 'true' : 'false'));
  38. if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
  39. array_push($config, "sni={$tlsSettings['serverName']}");
  40. }
  41. }
  42. if ($server['network'] === 'ws') {
  43. array_push($config, 'ws=true');
  44. if ($server['networkSettings']) {
  45. $wsSettings = json_decode($server['networkSettings'], true);
  46. if (isset($wsSettings['path']) && !empty($wsSettings['path']))
  47. array_push($config, "ws-path={$wsSettings['path']}");
  48. if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
  49. array_push($config, "ws-headers=Host:{$wsSettings['headers']['Host']}");
  50. }
  51. }
  52. $uri = implode(',', $config);
  53. $uri .= "\r\n";
  54. return $uri;
  55. }
  56. }