From 2782bd1a2c8353920e490285790fd72e1c6ab787 Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Wed, 1 Jul 2020 18:31:44 +0800 Subject: [PATCH] update trojan --- app/Utils/QuantumultX.php | 13 ++++++++++++- app/Utils/Surge.php | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/Utils/QuantumultX.php b/app/Utils/QuantumultX.php index 7221d877..256db12c 100644 --- a/app/Utils/QuantumultX.php +++ b/app/Utils/QuantumultX.php @@ -34,7 +34,18 @@ class QuantumultX public static function buildTrojan($password, $server) { $tlsVerification = $server->allow_insecure ? true : false; - $uri = "trojan={$server->host}:{$server->port}, password={$password}, over-tls=true, tls-host={$server->server_name}, tls-verification={$tlsVerification}, fast-open=false, udp-relay=false, tag={$server->name}"; + $config = [ + "trojan={$server->host}:{$server->port}", + "password={$password}", + "over-tls=true", + $server->server_name ? "tls-host={$server->server_name}" : "", + "tls-verification={$tlsVerification}", + "fast-open=false", + "udp-relay=false", + "tag={$server->name}" + ]; + $config = array_filter($config); + $uri = implode($config, ','); $uri .= "\r\n"; return $uri; } diff --git a/app/Utils/Surge.php b/app/Utils/Surge.php index aeed24a6..811c49d2 100644 --- a/app/Utils/Surge.php +++ b/app/Utils/Surge.php @@ -29,7 +29,17 @@ class Surge public static function buildTrojan($password, $server) { - $uri = "{$server->name} = trojan, {$server->host}, {$server->port}, password={$password}"; + $allowInsecure = $server->allow_insecure ? true : false; + $config = [ + "{$server->name}=trojan", + "{$server->host}", + "{$server->port}", + "password={$password}", + "skip-cert-verify={$allowInsecure}", + $server->server_name ? "sni={$server->server_name}" : "" + ]; + $config = array_filter($config); + $uri = implode($config, ','); $uri .= "\r\n"; return $uri; }