From 2bc3c9c7aa94e1854eb8710a582a3f8f84354bfe Mon Sep 17 00:00:00 2001 From: v2board Date: Fri, 20 Jan 2023 23:34:19 +0800 Subject: [PATCH] update: fix protocols --- app/Http/Controllers/Client/Protocols/Clash.php | 7 ++++--- app/Http/Controllers/Client/Protocols/ClashMeta.php | 7 ++++--- app/Http/Controllers/Client/Protocols/Stash.php | 7 ++++--- app/Http/Controllers/Client/Protocols/Surfboard.php | 2 +- app/Http/Controllers/Client/Protocols/Surge.php | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Client/Protocols/Clash.php b/app/Http/Controllers/Client/Protocols/Clash.php index ef045af1..3abf5019 100644 --- a/app/Http/Controllers/Client/Protocols/Clash.php +++ b/app/Http/Controllers/Client/Protocols/Clash.php @@ -78,9 +78,10 @@ class Clash $config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies); } // Force the current subscription domain to be a direct rule - $subsDomain = $_SERVER['SERVER_NAME']; - $subsDomainRule = "DOMAIN,{$subsDomain},DIRECT"; - array_unshift($config['rules'], $subsDomainRule); + $subsDomain = $_SERVER['HTTP_HOST']; + if ($subsDomain) { + array_unshift($config['rules'], "DOMAIN,{$subsDomain},DIRECT"); + } $yaml = Yaml::dump($config); $yaml = str_replace('$app_name', config('v2board.app_name', 'V2Board'), $yaml); diff --git a/app/Http/Controllers/Client/Protocols/ClashMeta.php b/app/Http/Controllers/Client/Protocols/ClashMeta.php index e818896f..d5e1a514 100644 --- a/app/Http/Controllers/Client/Protocols/ClashMeta.php +++ b/app/Http/Controllers/Client/Protocols/ClashMeta.php @@ -69,9 +69,10 @@ class ClashMeta $config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies); } // Force the current subscription domain to be a direct rule - $subsDomain = $_SERVER['SERVER_NAME']; - $subsDomainRule = "DOMAIN,{$subsDomain},DIRECT"; - array_unshift($config['rules'], $subsDomainRule); + $subsDomain = $_SERVER['HTTP_HOST']; + if ($subsDomain) { + array_unshift($config['rules'], "DOMAIN,{$subsDomain},DIRECT"); + } $yaml = Yaml::dump($config); $yaml = str_replace('$app_name', config('v2board.app_name', 'V2Board'), $yaml); diff --git a/app/Http/Controllers/Client/Protocols/Stash.php b/app/Http/Controllers/Client/Protocols/Stash.php index 390579a0..21515644 100644 --- a/app/Http/Controllers/Client/Protocols/Stash.php +++ b/app/Http/Controllers/Client/Protocols/Stash.php @@ -76,9 +76,10 @@ class Stash $config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies); } // Force the current subscription domain to be a direct rule - $subsDomain = $_SERVER['SERVER_NAME']; - $subsDomainRule = "DOMAIN,{$subsDomain},DIRECT"; - array_unshift($config['rules'], $subsDomainRule); + $subsDomain = $_SERVER['HTTP_HOST']; + if ($subsDomain) { + array_unshift($config['rules'], "DOMAIN,{$subsDomain},DIRECT"); + } $yaml = Yaml::dump($config); $yaml = str_replace('$app_name', config('v2board.app_name', 'V2Board'), $yaml); diff --git a/app/Http/Controllers/Client/Protocols/Surfboard.php b/app/Http/Controllers/Client/Protocols/Surfboard.php index 10d7b9fb..4a2c17bb 100644 --- a/app/Http/Controllers/Client/Protocols/Surfboard.php +++ b/app/Http/Controllers/Client/Protocols/Surfboard.php @@ -65,7 +65,7 @@ class Surfboard // Subscription link $subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); - $subsDomain = $_SERVER['SERVER_NAME']; + $subsDomain = $_SERVER['HTTP_HOST']; $config = str_replace('$subs_link', $subsURL, $config); $config = str_replace('$subs_domain', $subsDomain, $config); diff --git a/app/Http/Controllers/Client/Protocols/Surge.php b/app/Http/Controllers/Client/Protocols/Surge.php index aaa76490..edb49dda 100644 --- a/app/Http/Controllers/Client/Protocols/Surge.php +++ b/app/Http/Controllers/Client/Protocols/Surge.php @@ -65,7 +65,7 @@ class Surge // Subscription link $subsURL = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}"); - $subsDomain = $_SERVER['SERVER_NAME']; + $subsDomain = $_SERVER['HTTP_HOST']; $subsURL = 'https://' . $subsDomain . '/api/v1/client/subscribe?token=' . $user['token']; $config = str_replace('$subs_link', $subsURL, $config);