From 1926d6a8670cf9be8a14c87ab48aafda457179cb Mon Sep 17 00:00:00 2001 From: xboard Date: Sun, 12 Jan 2025 23:57:24 +0800 Subject: [PATCH] fix: correct know file issues --- app/Protocols/Clash.php | 8 ++++++-- app/Protocols/ClashMeta.php | 8 ++++++-- app/Protocols/General.php | 24 +++++++++++++++--------- app/Protocols/Loon.php | 2 +- app/Protocols/Shadowrocket.php | 20 +++++++++++++------- app/Protocols/SingBox.php | 18 +++++++++++++----- app/Protocols/Stash.php | 16 ++++++++++++---- 7 files changed, 66 insertions(+), 30 deletions(-) diff --git a/app/Protocols/Clash.php b/app/Protocols/Clash.php index ea107c0..00f012d 100644 --- a/app/Protocols/Clash.php +++ b/app/Protocols/Clash.php @@ -153,7 +153,9 @@ class Clash implements ProtocolInterface if (data_get($protocol_settings, 'tls')) { $array['tls'] = true; $array['skip-cert-verify'] = (bool) data_get($protocol_settings, 'tls_settings.allow_insecure'); - $array['servername'] = data_get($protocol_settings, 'tls_settings.server_name'); + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $array['servername'] = $serverName; + } } switch (data_get($protocol_settings, 'network')) { @@ -193,7 +195,9 @@ class Clash implements ProtocolInterface $array['port'] = $server['port']; $array['password'] = $password; $array['udp'] = true; - $array['sni'] = data_get($protocol_settings, 'server_name'); + if ($serverName = data_get($protocol_settings, 'server_name')) { + $array['sni'] = $serverName; + } $array['skip-cert-verify'] = (bool) data_get($protocol_settings, 'allow_insecure'); switch (data_get($protocol_settings, 'network')) { diff --git a/app/Protocols/ClashMeta.php b/app/Protocols/ClashMeta.php index 7d0bc16..21af0bc 100644 --- a/app/Protocols/ClashMeta.php +++ b/app/Protocols/ClashMeta.php @@ -204,7 +204,9 @@ class ClashMeta implements ProtocolInterface case 1: $array['tls'] = true; $array['skip-cert-verify'] = (bool) data_get($protocol_settings, 'tls_settings.allow_insecure', false); - $array['servername'] = data_get($protocol_settings, 'tls_settings.server_name'); + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $array['servername'] = $serverName; + } break; case 2: $array['tls'] = true; @@ -258,9 +260,11 @@ class ClashMeta implements ProtocolInterface 'port' => $server['port'], 'password' => $password, 'udp' => true, - 'sni' => data_get($protocol_settings, 'server_name'), 'skip-cert-verify' => (bool) data_get($protocol_settings, 'allow_insecure', false) ]; + if ($serverName = data_get($protocol_settings, 'server_name')) { + $array['sni'] = $serverName; + } switch (data_get($protocol_settings, 'network')) { case 'grpc': diff --git a/app/Protocols/General.php b/app/Protocols/General.php index 189a9d0..03e0a31 100644 --- a/app/Protocols/General.php +++ b/app/Protocols/General.php @@ -77,8 +77,10 @@ class General implements ProtocolInterface "host" => "", "path" => "", "tls" => $protocol_settings['tls'] ? "tls" : "", - "sni" => data_get($protocol_settings, 'tls_settings.server_name'), ]; + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $config['sni'] = $serverName; + } switch ($protocol_settings['network']) { case 'tcp': @@ -123,7 +125,9 @@ class General implements ProtocolInterface switch ($server['protocol_settings']['tls']) { case 1: $config['security'] = "tls"; - $config['sni'] = data_get($protocol_settings, 'tls_settings.server_name'); + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $config['sni'] = $serverName; + } break; case 2: //reality $config['security'] = "reality"; @@ -175,11 +179,13 @@ class General implements ProtocolInterface { $protocol_settings = $server['protocol_settings']; $name = rawurlencode($server['name']); - $query = http_build_query([ - 'allowInsecure' => $protocol_settings['allow_insecure'], - 'peer' => $protocol_settings['server_name'], - 'sni' => $protocol_settings['server_name'] - ]); + $array = []; + $array['allowInsecure'] = $protocol_settings['allow_insecure']; + if ($serverName = data_get($protocol_settings, 'server_name')) { + $array['peer'] = $serverName; + $array['sni'] = $serverName; + } + $query = http_build_query($array); $uri = "trojan://{$password}@{$server['host']}:{$server['port']}?{$query}#{$name}"; $uri .= "\r\n"; return $uri; @@ -194,8 +200,8 @@ class General implements ProtocolInterface return ''; } - if (data_get($protocol_settings, 'tls.server_name')) { - $params['sni'] = data_get($protocol_settings, 'tls.server_name'); + if ($serverName = data_get($protocol_settings, 'tls.server_name')) { + $params['sni'] = $serverName; $params['security'] = 'tls'; } diff --git a/app/Protocols/Loon.php b/app/Protocols/Loon.php index 7a640e3..7e14798 100644 --- a/app/Protocols/Loon.php +++ b/app/Protocols/Loon.php @@ -145,7 +145,7 @@ class Loon implements ProtocolInterface 'fast-open=false', 'udp=true' ]; - if (!empty($server['allow_insecure'])) { + if (!empty($protocol_settings['allow_insecure'])) { array_push($config, data_get($protocol_settings, 'tls_settings')['allow_insecure'] ? 'skip-cert-verify=true' : 'skip-cert-verify=false'); } $config = array_filter($config); diff --git a/app/Protocols/Shadowrocket.php b/app/Protocols/Shadowrocket.php index 62e2b47..bd73893 100644 --- a/app/Protocols/Shadowrocket.php +++ b/app/Protocols/Shadowrocket.php @@ -145,7 +145,9 @@ class Shadowrocket implements ProtocolInterface case 1: $config['tls'] = 1; $config['allowInsecure'] = (int) data_get($protocol_settings, 'tls_settings.allow_insecure'); - $config['peer'] = data_get($protocol_settings, 'tls_settings.server_name'); + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $config['peer'] = $serverName; + } break; case 2: $config['tls'] = 1; @@ -187,10 +189,10 @@ class Shadowrocket implements ProtocolInterface { $protocol_settings = $server['protocol_settings']; $name = rawurlencode($server['name']); - $params = [ - 'allowInsecure' => data_get($protocol_settings, 'tls.allow_insecure'), - 'peer' => data_get($protocol_settings, 'tls.server_name') - ]; + $params['allowInsecure'] = data_get($protocol_settings, 'tls.allow_insecure'); + if ($serverName = data_get($protocol_settings, 'tls.server_name')) { + $params['peer'] = $serverName; + } switch (data_get($protocol_settings, 'network')) { case 'grpc': $params['obfs'] = 'grpc'; @@ -218,9 +220,11 @@ class Shadowrocket implements ProtocolInterface "upmbps" => data_get($protocol_settings, 'bandwidth.up'), "downmbps" => data_get($protocol_settings, 'bandwidth.down'), "protocol" => 'udp', - "peer" => data_get($protocol_settings, 'tls.server_name'), "fastopen" => 1, ]; + if ($serverName = data_get($protocol_settings, 'tls.server_name')) { + $params['peer'] = $serverName; + } if (data_get($protocol_settings, 'obfs.open')) { $params["obfs"] = "xplus"; $params["obfsParam"] = data_get($protocol_settings, 'obfs_settings.password'); @@ -234,10 +238,12 @@ class Shadowrocket implements ProtocolInterface break; case 2: $params = [ - "peer" => data_get($protocol_settings, 'tls.server_name'), "obfs" => 'none', "fastopen" => 1 ]; + if ($serverName = data_get($protocol_settings, 'tls.server_name')) { + $params['peer'] = $serverName; + } if (data_get($protocol_settings, 'obfs.open')) { $params['obfs'] = data_get($protocol_settings, 'obfs.type'); $params['obfs-password'] = data_get($protocol_settings, 'obfs.password'); diff --git a/app/Protocols/SingBox.php b/app/Protocols/SingBox.php index d0ba5a3..cc6b471 100644 --- a/app/Protocols/SingBox.php +++ b/app/Protocols/SingBox.php @@ -128,9 +128,11 @@ class SingBox implements ProtocolInterface 'tls' => $protocol_settings['tls'] ? [ 'enabled' => true, 'insecure' => (bool) data_get($protocol_settings, 'tls_settings.allow_insecure'), - 'server_name' => data_get($protocol_settings, 'tls_settings.server_name') ] : null ]; + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $array['tls']['server_name'] = $serverName; + } $transport = match ($protocol_settings['network']) { 'tcp' => [ @@ -174,12 +176,14 @@ class SingBox implements ProtocolInterface $tlsConfig = [ 'enabled' => true, 'insecure' => (bool) data_get($protocol_settings, 'tls_settings.allow_insecure'), - 'server_name' => data_get($protocol_settings, 'tls_settings.server_name'), 'utls' => [ 'enabled' => true, 'fingerprint' => Helper::getRandFingerprint() ] ]; + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $tlsConfig['server_name'] = $serverName; + } if ($protocol_settings['tls'] == 2) { $tlsConfig['reality'] = [ 'enabled' => true, @@ -194,7 +198,7 @@ class SingBox implements ProtocolInterface $transport = match ($protocol_settings['network']) { 'tcp' => data_get($protocol_settings, 'network_settings.header.type') == 'http' ? [ 'type' => 'http', - 'path' => data_get($protocol_settings, 'network_settings.header.request.path') + 'path' => \Arr::random(data_get($protocol_settings, 'network_settings.header.request.path', ['/'])) ] : null, 'ws' => array_filter([ 'type' => 'ws', @@ -240,9 +244,11 @@ class SingBox implements ProtocolInterface 'tls' => [ 'enabled' => true, 'insecure' => (bool) data_get($protocol_settings, 'allow_insecure', false), - 'server_name' => data_get($protocol_settings, 'server_name') ] ]; + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $array['tls']['server_name'] = $serverName; + } $transport = match (data_get($protocol_settings, 'network')) { 'grpc' => [ 'type' => 'grpc', @@ -271,9 +277,11 @@ class SingBox implements ProtocolInterface 'tls' => [ 'enabled' => true, 'insecure' => (bool) $protocol_settings['tls']['allow_insecure'], - 'server_name' => $protocol_settings['tls']['server_name'] ] ]; + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $baseConfig['tls']['server_name'] = $serverName; + } $speedConfig = [ 'up_mbps' => $protocol_settings['bandwidth']['up'], 'down_mbps' => $protocol_settings['bandwidth']['down'], diff --git a/app/Protocols/Stash.php b/app/Protocols/Stash.php index c4b3c7e..2b14165 100644 --- a/app/Protocols/Stash.php +++ b/app/Protocols/Stash.php @@ -142,7 +142,9 @@ class Stash implements ProtocolInterface $array['tls'] = data_get($protocol_settings, 'tls'); $array['skip-cert-verify'] = data_get($protocol_settings, 'tls_settings.allow_insecure'); - $array['servername'] = data_get($protocol_settings, 'tls_settings.server_name'); + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $array['servername'] = $serverName; + } switch (data_get($protocol_settings, 'network')) { case 'tcp': @@ -186,7 +188,9 @@ class Stash implements ProtocolInterface case 1: $array['tls'] = true; $array['skip-cert-verify'] = data_get($protocol_settings, 'tls_settings.allow_insecure'); - $array['servername'] = data_get($protocol_settings, 'tls_settings.server_name'); + if ($serverName = data_get($protocol_settings, 'tls_settings.server_name')) { + $array['servername'] = $serverName; + } break; case 2: $array['tls'] = true; @@ -241,7 +245,9 @@ class Stash implements ProtocolInterface $array['ws-opts']['headers'] = data_get($protocol_settings, 'network_settings.headers.Host') ? ['Host' => data_get($protocol_settings, 'network_settings.headers.Host')] : null; break; } - $array['sni'] = data_get($protocol_settings, 'server_name'); + if ($serverName = data_get($protocol_settings, 'server_name')) { + $array['sni'] = $serverName; + } $array['skip-cert-verify'] = data_get($protocol_settings, 'allow_insecure'); return $array; } @@ -255,7 +261,9 @@ class Stash implements ProtocolInterface $array['up-speed'] = data_get($protocol_settings, 'bandwidth.up'); $array['down-speed'] = data_get($protocol_settings, 'bandwidth.down'); $array['skip-cert-verify'] = data_get($protocol_settings, 'tls.allow_insecure'); - $array['sni'] = data_get($protocol_settings, 'tls.server_name') ?? ''; + if ($serverName = data_get($protocol_settings, 'tls.server_name')) { + $array['sni'] = $serverName; + } switch (data_get($protocol_settings, 'version')) { case 1: $array['type'] = 'hysteria';