Surfboard.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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={$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=false"
  31. ];
  32. if ($server->network === 'tcp') {
  33. if ($server->tls) {
  34. $tlsSettings = json_decode($server->tlsSettings);
  35. array_push($config, $server->tls ? 'tls=true' : 'tls=false');
  36. if (isset($tlsSettings->allowInsecure)) {
  37. array_push($config, $tlsSettings->allowInsecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
  38. }
  39. if (isset($tlsSettings->serverName)) {
  40. array_push($config, "obfs-host={$tlsSettings->serverName}");
  41. }
  42. }
  43. }
  44. if ($server->network === 'ws') {
  45. array_push($config, 'ws=true');
  46. if ($server->tls) {
  47. $tlsSettings = json_decode($server->tlsSettings);
  48. array_push($config, $server->tls ? 'tls=true' : 'tls=false');
  49. if (isset($tlsSettings->allowInsecure)) {
  50. array_push($config, $tlsSettings->allowInsecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false');
  51. }
  52. }
  53. if ($server->networkSettings) {
  54. $wsSettings = json_decode($server->networkSettings);
  55. if (isset($wsSettings->path)) array_push($config, "ws-path={$wsSettings->path}");
  56. if (isset($wsSettings->headers->Host)) array_push($config, "ws-headers=host:{$wsSettings->headers->Host}");
  57. }
  58. }
  59. $uri = implode(',', $config);
  60. $uri .= "\r\n";
  61. return $uri;
  62. }
  63. }