From f48de9f07d0eac3074ea8efe3c4859cb19a8c3c6 Mon Sep 17 00:00:00 2001 From: Beta Soft Date: Mon, 5 Jul 2021 21:01:28 +0800 Subject: [PATCH] Protocols: fix vmess tls sni field --- .../Controllers/Client/Protocols/Passwall.php | 15 ++++++++++----- app/Http/Controllers/Client/Protocols/SSRPlus.php | 15 ++++++++++----- app/Http/Controllers/Client/Protocols/V2rayN.php | 8 +++++++- app/Http/Controllers/Client/Protocols/V2rayNG.php | 8 +++++++- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Client/Protocols/Passwall.php b/app/Http/Controllers/Client/Protocols/Passwall.php index b967917d..9f5115d8 100644 --- a/app/Http/Controllers/Client/Protocols/Passwall.php +++ b/app/Http/Controllers/Client/Protocols/Passwall.php @@ -22,12 +22,12 @@ class Passwall $uri = ''; foreach ($servers as $item) { - if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); - } if ($item['type'] === 'v2ray') { $uri .= self::buildVmess($user['uuid'], $item); } + if ($item['type'] === 'shadowsocks') { + $uri .= self::buildShadowsocks($user['uuid'], $item); + } if ($item['type'] === 'trojan') { $uri .= self::buildTrojan($user['uuid'], $item); } @@ -35,7 +35,6 @@ class Passwall return base64_encode($uri); } - public static function buildShadowsocks($password, $server) { $name = rawurlencode($server['name']); @@ -61,8 +60,14 @@ class Passwall "host" => "", "path" => "", "tls" => $server['tls'] ? "tls" : "", - "sni" => $server['tls'] ? isset(json_decode($server['tlsSettings'], true)['serverName']) : "" ]; + if ($server['tls']) { + if ($server['tlsSettings']) { + $tlsSettings = json_decode($server['tlsSettings'], true); + if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName'])) + $config['sni'] = $tlsSettings['serverName']; + } + } if ((string)$server['network'] === 'ws') { $wsSettings = json_decode($server['networkSettings'], true); if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; diff --git a/app/Http/Controllers/Client/Protocols/SSRPlus.php b/app/Http/Controllers/Client/Protocols/SSRPlus.php index 3d700ed1..3efa61a3 100644 --- a/app/Http/Controllers/Client/Protocols/SSRPlus.php +++ b/app/Http/Controllers/Client/Protocols/SSRPlus.php @@ -22,12 +22,12 @@ class SSRPlus $uri = ''; foreach ($servers as $item) { - if ($item['type'] === 'shadowsocks') { - $uri .= self::buildShadowsocks($user['uuid'], $item); - } if ($item['type'] === 'v2ray') { $uri .= self::buildVmess($user['uuid'], $item); } + if ($item['type'] === 'shadowsocks') { + $uri .= self::buildShadowsocks($user['uuid'], $item); + } if ($item['type'] === 'trojan') { $uri .= self::buildTrojan($user['uuid'], $item); } @@ -35,7 +35,6 @@ class SSRPlus return base64_encode($uri); } - public static function buildShadowsocks($password, $server) { $name = rawurlencode($server['name']); @@ -61,8 +60,14 @@ class SSRPlus "host" => "", "path" => "", "tls" => $server['tls'] ? "tls" : "", - "sni" => $server['tls'] ? isset(json_decode($server['tlsSettings'], true)['serverName']) : "" ]; + if ($server['tls']) { + if ($server['tlsSettings']) { + $tlsSettings = json_decode($server['tlsSettings'], true); + if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName'])) + $config['sni'] = $tlsSettings['serverName']; + } + } if ((string)$server['network'] === 'ws') { $wsSettings = json_decode($server['networkSettings'], true); if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; diff --git a/app/Http/Controllers/Client/Protocols/V2rayN.php b/app/Http/Controllers/Client/Protocols/V2rayN.php index bd9aa005..e8ab9b39 100644 --- a/app/Http/Controllers/Client/Protocols/V2rayN.php +++ b/app/Http/Controllers/Client/Protocols/V2rayN.php @@ -60,8 +60,14 @@ class V2rayN "host" => "", "path" => "", "tls" => $server['tls'] ? "tls" : "", - "sni" => $server['tls'] ? isset(json_decode($server['tlsSettings'], true)['serverName']) : "" ]; + if ($server['tls']) { + if ($server['tlsSettings']) { + $tlsSettings = json_decode($server['tlsSettings'], true); + if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName'])) + $config['sni'] = $tlsSettings['serverName']; + } + } if ((string)$server['network'] === 'ws') { $wsSettings = json_decode($server['networkSettings'], true); if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; diff --git a/app/Http/Controllers/Client/Protocols/V2rayNG.php b/app/Http/Controllers/Client/Protocols/V2rayNG.php index d765c372..f4658467 100644 --- a/app/Http/Controllers/Client/Protocols/V2rayNG.php +++ b/app/Http/Controllers/Client/Protocols/V2rayNG.php @@ -60,8 +60,14 @@ class V2rayNG "host" => "", "path" => "", "tls" => $server['tls'] ? "tls" : "", - "sni" => $server['tls'] ? isset(json_decode($server['tlsSettings'], true)['serverName']) : "" ]; + if ($server['tls']) { + if ($server['tlsSettings']) { + $tlsSettings = json_decode($server['tlsSettings'], true); + if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName'])) + $config['sni'] = $tlsSettings['serverName']; + } + } if ((string)$server['network'] === 'ws') { $wsSettings = json_decode($server['networkSettings'], true); if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path'];