QuantumultX.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Utils;
  3. class QuantumultX
  4. {
  5. public static function buildShadowsocks($password, $server)
  6. {
  7. $config = [
  8. "shadowsocks={$server->host}:{$server->port}",
  9. "method={$server->cipher}",
  10. "password={$password}",
  11. "fast-open=true",
  12. "udp-relay=true",
  13. "tag={$server->name}"
  14. ];
  15. $config = array_filter($config);
  16. $uri = implode(',', $config);
  17. $uri .= "\r\n";
  18. return $uri;
  19. }
  20. public static function buildVmess($uuid, $server)
  21. {
  22. $config = [
  23. "vmess={$server->host}:{$server->port}",
  24. "method=chacha20-poly1305",
  25. "password={$uuid}",
  26. "tag={$server->name}"
  27. ];
  28. if ($server->network === 'tcp') {
  29. if ($server->tls) {
  30. $tlsSettings = json_decode($server->tlsSettings);
  31. array_push($config, 'obfs=over-tls');
  32. if (isset($tlsSettings->allowInsecure)) {
  33. // Tips: allowInsecure=false = tls-verification=true
  34. array_push($config, $tlsSettings->allowInsecure ? 'tls-verification=false' : 'tls-verification=true');
  35. }
  36. if (isset($tlsSettings->serverName)) {
  37. array_push($config, "obfs-host={$tlsSettings->serverName}");
  38. }
  39. }
  40. }
  41. if ($server->network === 'ws') {
  42. if ($server->tls) {
  43. $tlsSettings = json_decode($server->tlsSettings);
  44. array_push($config, 'obfs=wss');
  45. if (isset($tlsSettings->allowInsecure)) {
  46. array_push($config, $tlsSettings->allowInsecure ? 'tls-verification=false' : 'tls-verification=true');
  47. }
  48. } else {
  49. array_push($config, 'obfs=ws');
  50. }
  51. if ($server->networkSettings) {
  52. $wsSettings = json_decode($server->networkSettings);
  53. if (isset($wsSettings->path)) array_push($config, "obfs-uri={$wsSettings->path}");
  54. if (isset($wsSettings->headers->Host)) array_push($config, "obfs-host={$wsSettings->headers->Host}");
  55. }
  56. }
  57. $uri = implode(',', $config);
  58. $uri .= "\r\n";
  59. return $uri;
  60. }
  61. public static function buildTrojan($password, $server)
  62. {
  63. $config = [
  64. "trojan={$server->host}:{$server->port}",
  65. "password={$password}",
  66. "over-tls=true",
  67. $server->server_name ? "tls-host={$server->server_name}" : "",
  68. // Tips: allowInsecure=false = tls-verification=true
  69. $server->allow_insecure ? 'tls-verification=false' : 'tls-verification=true',
  70. "fast-open=false",
  71. "udp-relay=false",
  72. "tag={$server->name}"
  73. ];
  74. $config = array_filter($config);
  75. $uri = implode(',', $config);
  76. $uri .= "\r\n";
  77. return $uri;
  78. }
  79. }