From c326d0ab5c21e7f7aafc7583196786e85f77cafa Mon Sep 17 00:00:00 2001 From: Beta Soft Date: Sun, 4 Oct 2020 23:24:57 +0800 Subject: [PATCH] subs: add Surfboard Shadowsocks support Signed-off-by: Beta Soft --- .../Controllers/Client/ClientController.php | 31 ++++----- app/Utils/Surfboard.php | 69 +++++++++++++++++++ 2 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 app/Utils/Surfboard.php diff --git a/app/Http/Controllers/Client/ClientController.php b/app/Http/Controllers/Client/ClientController.php index 0dcc5149..52512808 100644 --- a/app/Http/Controllers/Client/ClientController.php +++ b/app/Http/Controllers/Client/ClientController.php @@ -8,6 +8,7 @@ use App\Utils\Clash; use App\Utils\QuantumultX; use App\Utils\Shadowrocket; use App\Utils\Surge; +use App\Utils\Surfboard; use App\Utils\URLSchemes; use Illuminate\Http\Request; use App\Models\Server; @@ -38,7 +39,7 @@ class ClientController extends Controller die($this->clash($user, $servers['shadowsocks'], $servers['vmess'], $servers['trojan'])); } if (strpos($_SERVER['HTTP_USER_AGENT'], 'surfboard') !== false) { - die($this->surfboard($user, $servers['vmess'])); + die($this->surfboard($user, $servers['shadowsocks'], $servers['vmess'])); } if (strpos($_SERVER['HTTP_USER_AGENT'], 'surge') !== false) { die($this->surge($user, $servers['vmess'], $servers['trojan'])); @@ -155,29 +156,21 @@ class ClientController extends Controller return $config; } - private function surfboard($user, $vmess = []) + private function surfboard($user, $shadowsocks = [], $vmess = []) { $proxies = ''; $proxyGroup = ''; + + foreach ($shadowsocks as $item) { + // [Proxy] + $proxies .= Surfboard::buildShadowsocks($user->uuid, $item); + // [Proxy Group] + $proxyGroup .= $item->name . ', '; + } + foreach ($vmess as $item) { // [Proxy] - $proxies .= $item->name . ' = vmess, ' . $item->host . ', ' . $item->port . ', username=' . $user->uuid; - if ($item->tls) { - $tlsSettings = json_decode($item->tlsSettings); - $proxies .= ', tls=' . ($item->tls ? "true" : "false"); - if (isset($tlsSettings->allowInsecure)) { - $proxies .= ', skip-cert-verify=' . ($tlsSettings->allowInsecure ? "true" : "false"); - } - } - if ($item->network == 'ws') { - $proxies .= ', ws=true'; - if ($item->networkSettings) { - $wsSettings = json_decode($item->networkSettings); - if (isset($wsSettings->path)) $proxies .= ', ws-path=' . $wsSettings->path; - if (isset($wsSettings->headers->Host)) $proxies .= ', ws-headers=host:' . $wsSettings->headers->Host; - } - } - $proxies .= "\r\n"; + $proxies .= Surfboard::buildVmess($user->uuid, $item); // [Proxy Group] $proxyGroup .= $item->name . ', '; } diff --git a/app/Utils/Surfboard.php b/app/Utils/Surfboard.php new file mode 100644 index 00000000..aa453f96 --- /dev/null +++ b/app/Utils/Surfboard.php @@ -0,0 +1,69 @@ +name}=custom", + "{$server->host}", + "{$server->port}", + "{$server->cipher}", + "password={$password}", + "https://raw.githubusercontent.com/Hackl0us/proxy-tool-backup/master/SSEncrypt.module", + "tfo=true", + "udp-relay=true" + ]; + $config = array_filter($config); + $uri = implode(',', $config); + $uri .= "\r\n"; + return $uri; + } + + public static function buildVmess($uuid, $server) + { + $config = [ + "{$server->name}=vmess", + "{$server->host}", + "{$server->port}", + "username={$uuid}", + "tfo=true", + "udp-relay=false" + ]; + if ($server->network === 'tcp') { + if ($server->tls) { + $tlsSettings = json_decode($server->tlsSettings); + array_push($config, $server->tls ? 'tls=true' : 'tls=false'); + if (isset($tlsSettings->allowInsecure)) { + array_push($config, $tlsSettings->allowInsecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false'); + } + if (isset($tlsSettings->serverName)) { + array_push($config, "obfs-host={$tlsSettings->serverName}"); + } + } + } + + if ($server->network === 'ws') { + array_push($config, 'ws=true'); + if ($server->tls) { + $tlsSettings = json_decode($server->tlsSettings); + array_push($config, $server->tls ? 'tls=true' : 'tls=false'); + if (isset($tlsSettings->allowInsecure)) { + array_push($config, $tlsSettings->allowInsecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false'); + } + } + if ($server->networkSettings) { + $wsSettings = json_decode($server->networkSettings); + if (isset($wsSettings->path)) array_push($config, "ws-path={$wsSettings->path}"); + if (isset($wsSettings->headers->Host)) array_push($config, "ws-headers=host:{$wsSettings->headers->Host}"); + } + } + + $uri = implode(',', $config); + $uri .= "\r\n"; + return $uri; + } +}