From 6fd577d2c86aaa7cbc52f8e2bf51abf18185ebea Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Sun, 4 Oct 2020 16:07:19 +0800 Subject: [PATCH] update: support shadowsocks app subscribe --- app/Http/Controllers/Client/ClientController.php | 7 +++++-- app/Utils/Shadowrocket.php | 15 +++++++++++++-- app/Utils/URLSchemes.php | 6 ++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Client/ClientController.php b/app/Http/Controllers/Client/ClientController.php index eb49ff27..0dcc5149 100644 --- a/app/Http/Controllers/Client/ClientController.php +++ b/app/Http/Controllers/Client/ClientController.php @@ -44,7 +44,7 @@ class ClientController extends Controller die($this->surge($user, $servers['vmess'], $servers['trojan'])); } if (strpos($_SERVER['HTTP_USER_AGENT'], 'shadowrocket') !== false) { - die($this->shadowrocket($user, $servers['vmess'], $servers['trojan'])); + die($this->shadowrocket($user, $servers['shadowsocks'], $servers['vmess'], $servers['trojan'])); } } die($this->origin($user, $servers['shadowsocks'], $servers['vmess'], $servers['trojan'])); @@ -71,7 +71,7 @@ class ClientController extends Controller return base64_encode($uri); } - private function shadowrocket($user, $vmess = [], $trojan = []) + private function shadowrocket($user, $shadowsocks = [], $vmess = [], $trojan = []) { $uri = ''; //display remaining traffic and expire date @@ -80,6 +80,9 @@ class ClientController extends Controller $totalTraffic = round($user->transfer_enable / (1024*1024*1024), 2); $expiredDate = date('Y-m-d', $user->expired_at); $uri .= "STATUS=🚀↑:{$upload}GB,↓:{$download}GB,TOT:{$totalTraffic}GB💡Expires:{$expiredDate}\r\n"; + foreach ($shadowsocks as $item) { + $uri .= Shadowrocket::buildShadowsocks($user->uuid, $item); + } foreach ($vmess as $item) { $uri .= Shadowrocket::buildVmess($user->uuid, $item); } diff --git a/app/Utils/Shadowrocket.php b/app/Utils/Shadowrocket.php index 0f0f919c..8104a61c 100644 --- a/app/Utils/Shadowrocket.php +++ b/app/Utils/Shadowrocket.php @@ -5,6 +5,17 @@ namespace App\Utils; class Shadowrocket { + public static function buildShadowsocks($password, $server) + { + $name = rawurlencode($server->name); + $str = str_replace( + ['+', '/', '='], + ['-', '_', ''], + base64_encode("{$server->cipher}:{$password}") + ); + return "ss://{$str}@{$server->host}:{$server->port}#{$name}\r\n"; + } + public static function buildVmess($uuid, $server) { $userinfo = base64_encode('auto:' . $uuid . '@' . $server->host . ':' . $server->port); @@ -31,12 +42,12 @@ class Shadowrocket public static function buildTrojan($password, $server) { - $server->name = rawurlencode($server->name); + $name = rawurlencode($server->name); $query = http_build_query([ 'allowInsecure' => $server->allow_insecure, 'peer' => $server->server_name ]); - $uri = "trojan://{$password}@{$server->host}:{$server->port}?{$query}&tfo=1#{$server->name}"; + $uri = "trojan://{$password}@{$server->host}:{$server->port}?{$query}&tfo=1#{$name}"; $uri .= "\r\n"; return $uri; } diff --git a/app/Utils/URLSchemes.php b/app/Utils/URLSchemes.php index e75395a1..6725157e 100644 --- a/app/Utils/URLSchemes.php +++ b/app/Utils/URLSchemes.php @@ -10,12 +10,13 @@ class URLSchemes { public static function buildShadowsocks(ServerShadowsocks $server, User $user) { + $name = rawurlencode($server->name); $str = str_replace( ['+', '/', '='], ['-', '_', ''], base64_encode("{$server->cipher}:{$user->uuid}") ); - return "ss://{$str}@{$server->host}:{$server->port}#{$server->name}\r\n"; + return "ss://{$str}@{$server->host}:{$server->port}#{$name}\r\n"; } @@ -44,12 +45,13 @@ class URLSchemes public static function buildTrojan(ServerTrojan $server, User $user) { + $name = rawurlencode($server->name); $query = http_build_query([ 'allowInsecure' => $server->allow_insecure, 'peer' => $server->server_name, 'sni' => $server->server_name ]); - $uri = "trojan://{$user->uuid}@{$server->host}:{$server->port}?{$query}#{$server->name}"; + $uri = "trojan://{$user->uuid}@{$server->host}:{$server->port}?{$query}#{$name}"; $uri .= "\r\n"; return $uri; }