diff --git a/app/Protocols/Clash.php b/app/Protocols/Clash.php index 89d7a50..6d50249 100644 --- a/app/Protocols/Clash.php +++ b/app/Protocols/Clash.php @@ -144,6 +144,13 @@ class Clash implements ProtocolInterface $array['cipher'] = data_get($protocol_settings, 'cipher'); $array['password'] = $uuid; $array['udp'] = true; + if (data_get($protocol_settings, 'obfs') == 'http') { + $array['plugin'] = 'obfs'; + $array['plugin-opts'] = [ + 'mode' => 'http', + 'host' => data_get($protocol_settings, 'obfs.host'), + ]; + } return $array; } diff --git a/app/Protocols/ClashMeta.php b/app/Protocols/ClashMeta.php index a3e58f8..777a930 100644 --- a/app/Protocols/ClashMeta.php +++ b/app/Protocols/ClashMeta.php @@ -153,6 +153,7 @@ class ClashMeta implements ProtocolInterface public static function buildShadowsocks($password, $server) { + $protocol_settings = $server['protocol_settings']; $array = []; $array['name'] = $server['name']; $array['type'] = 'ss'; @@ -161,6 +162,13 @@ class ClashMeta implements ProtocolInterface $array['cipher'] = data_get($server['protocol_settings'], 'cipher'); $array['password'] = data_get($server, 'password', $password); $array['udp'] = true; + if (data_get($protocol_settings, 'obfs') == 'http') { + $array['plugin'] = 'obfs'; + $array['plugin-opts'] = [ + 'mode' => 'http', + 'host' => data_get($protocol_settings, 'obfs.host'), + ]; + } return $array; } diff --git a/app/Protocols/Loon.php b/app/Protocols/Loon.php index 566322d..c4f48ed 100644 --- a/app/Protocols/Loon.php +++ b/app/Protocols/Loon.php @@ -31,12 +31,6 @@ class Loon implements ProtocolInterface foreach ($servers as $item) { if ( $item['type'] === 'shadowsocks' - && in_array(data_get($item['protocol_settings'], 'cipher'), [ - 'aes-128-gcm', - 'aes-192-gcm', - 'aes-256-gcm', - 'chacha20-ietf-poly1305' - ]) ) { $uri .= self::buildShadowsocks($item['password'], $item); } @@ -58,6 +52,10 @@ class Loon implements ProtocolInterface public static function buildShadowsocks($password, $server) { $cipher = data_get($server['protocol_settings'], 'cipher'); + $obfs = data_get($server['protocol_settings'], 'obfs'); + $obfs_host = data_get($server['protocol_settings'], 'obfs_settings.host'); + $obfs_uri = data_get($server['protocol_settings'], 'obfs_settings.path', '/'); + $config = [ "{$server['name']}=Shadowsocks", "{$server['host']}", @@ -67,9 +65,15 @@ class Loon implements ProtocolInterface 'fast-open=false', 'udp=true' ]; + + if ($obfs && $obfs_host) { + $config[] = "obfs-name={$obfs}"; + $config[] = "obfs-host={$obfs_host}"; + $config[] = "obfs-uri={$obfs_uri}"; + } + $config = array_filter($config); - $uri = implode(',', $config); - $uri .= "\r\n"; + $uri = implode(',', $config) . "\r\n"; return $uri; } diff --git a/app/Protocols/Stash.php b/app/Protocols/Stash.php index 2bf99db..12ba561 100644 --- a/app/Protocols/Stash.php +++ b/app/Protocols/Stash.php @@ -5,6 +5,7 @@ namespace App\Protocols; use App\Models\ServerHysteria; use Symfony\Component\Yaml\Yaml; use App\Contracts\ProtocolInterface; +use App\Utils\Helper; use Illuminate\Support\Facades\File; class Stash implements ProtocolInterface @@ -35,12 +36,12 @@ class Stash implements ProtocolInterface $appName = admin_setting('app_name', 'XBoard'); $template = File::exists(base_path(self::CUSTOM_TEMPLATE_FILE)) - ? File::get(base_path(self::CUSTOM_TEMPLATE_FILE)) - : ( - File::exists(base_path(self::CUSTOM_CLASH_TEMPLATE_FILE)) - ? File::get(base_path(self::CUSTOM_CLASH_TEMPLATE_FILE)) - : File::get(base_path(self::DEFAULT_TEMPLATE_FILE)) - ); + ? File::get(base_path(self::CUSTOM_TEMPLATE_FILE)) + : ( + File::exists(base_path(self::CUSTOM_CLASH_TEMPLATE_FILE)) + ? File::get(base_path(self::CUSTOM_CLASH_TEMPLATE_FILE)) + : File::get(base_path(self::DEFAULT_TEMPLATE_FILE)) + ); $config = Yaml::parse($template); $proxy = []; @@ -49,12 +50,6 @@ class Stash implements ProtocolInterface foreach ($servers as $item) { if ( $item['type'] === 'shadowsocks' - && in_array(data_get($item, 'protocol_settings.cipher'), [ - 'aes-128-gcm', - 'aes-192-gcm', - 'aes-256-gcm', - 'chacha20-ietf-poly1305' - ]) ) { array_push($proxy, self::buildShadowsocks($item['password'], $item)); array_push($proxies, $item['name']); @@ -65,9 +60,6 @@ class Stash implements ProtocolInterface } if ( $item['type'] === 'vless' - && in_array(data_get($item['protocol_settings'], 'network'), ['tcp', 'ws', 'grpc', 'http', 'h2']) - && in_array(data_get($item['protocol_settings'], 'tls'), [1, 0]) - && in_array(data_get($item['protocol_settings'], 'flow'), ['xtls-rprx-origin', 'xtls-rprx-direct', 'xtls-rprx-splice']) ) { array_push($proxy, self::buildVless($user['uuid'], $item)); array_push($proxies, $item['name']); @@ -145,6 +137,13 @@ class Stash implements ProtocolInterface $array['cipher'] = data_get($protocol_settings, 'cipher'); $array['password'] = $uuid; $array['udp'] = true; + if (data_get($protocol_settings, 'obfs') == 'http') { + $array['plugin'] = 'obfs'; + $array['plugin-opts'] = [ + 'mode' => 'http', + 'host' => data_get($protocol_settings, 'obfs.host'), + ]; + } return $array; } @@ -202,8 +201,7 @@ class Stash implements ProtocolInterface $array['flow'] = data_get($protocol_settings, 'flow'); $array['udp'] = true; - $fingerprints = ['chrome', 'firefox', 'safari', 'ios', 'edge', 'qq']; //随机客户端指纹 - $array['client-fingerprint'] = $fingerprints[rand(0, count($fingerprints) - 1)]; + $array['client-fingerprint'] = Helper::getRandFingerprint(); switch (data_get($protocol_settings, 'tls')) { case 1: @@ -213,6 +211,12 @@ class Stash implements ProtocolInterface $array['servername'] = $serverName; } break; + case 2: + $array['tls'] = true; + $array['reality-opts']= [ + 'public-key' => data_get($protocol_settings, 'reality_settings.public_key'), + 'short-id' => data_get($protocol_settings, 'reality_settings.short_id') + ]; } switch (data_get($protocol_settings, 'network')) { diff --git a/app/Utils/Helper.php b/app/Utils/Helper.php index d153875..ffb61b1 100644 --- a/app/Utils/Helper.php +++ b/app/Utils/Helper.php @@ -177,7 +177,7 @@ class Helper public static function getRandFingerprint() { $fingerprints = ['chrome', 'firefox', 'safari', 'ios', 'edge', 'qq']; - return \Arr::random($fingerprints); + return Arr::random($fingerprints); } public static function encodeURIComponent($str) {