feat(protocols): add support for ss obfs, ss2022, and vless reality

- Clash and Clash Meta: Added support for Shadowsocks (SS) with obfs.
- Loon: Added support for SS2022 and obfs.
- Stash: Added support for SS2022, obfs, and VLESS Reality.
This commit is contained in:
xboard
2025-05-16 06:43:58 +08:00
parent bbeede8dbc
commit e49f88d311
5 changed files with 49 additions and 26 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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')) {

View File

@@ -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) {