feat(ClashMeta): enhance Shadowsocks plugin support

This commit is contained in:
xboard
2026-03-15 11:36:43 +08:00
parent 199c146672
commit 3d082853d7
+29 -15
View File
@@ -194,7 +194,7 @@ class ClashMeta extends AbstractProtocol
->filter() ->filter()
->mapWithKeys(function ($pair) { ->mapWithKeys(function ($pair) {
if (!str_contains($pair, '=')) { if (!str_contains($pair, '=')) {
return []; return [trim($pair) => true];
} }
[$key, $value] = explode('=', $pair, 2); [$key, $value] = explode('=', $pair, 2);
return [trim($key) => trim($value)]; return [trim($key) => trim($value)];
@@ -204,28 +204,42 @@ class ClashMeta extends AbstractProtocol
// 根据插件类型进行字段映射 // 根据插件类型进行字段映射
switch ($plugin) { switch ($plugin) {
case 'obfs': case 'obfs':
$array['plugin-opts'] = [ case 'obfs-local':
'mode' => $parsedOpts['obfs'], $array['plugin'] = 'obfs';
'host' => $parsedOpts['obfs-host'], $array['plugin-opts'] = array_filter([
]; 'mode' => $parsedOpts['obfs'] ?? ($parsedOpts['mode'] ?? 'http'),
'host' => $parsedOpts['obfs-host'] ?? ($parsedOpts['host'] ?? 'www.bing.com'),
// 可选path参数 ]);
if (isset($parsedOpts['path'])) {
$array['plugin-opts']['path'] = $parsedOpts['path'];
}
break; break;
case 'v2ray-plugin': case 'v2ray-plugin':
$array['plugin-opts'] = [ $array['plugin-opts'] = array_filter([
'mode' => $parsedOpts['mode'] ?? 'websocket', 'mode' => $parsedOpts['mode'] ?? 'websocket',
'tls' => isset($parsedOpts['tls']) && $parsedOpts['tls'] == 'true', 'tls' => isset($parsedOpts['tls']) || isset($parsedOpts['server']),
'host' => $parsedOpts['host'] ?? '', 'host' => $parsedOpts['host'] ?? null,
'path' => $parsedOpts['path'] ?? '/', 'path' => $parsedOpts['path'] ?? '/',
]; 'mux' => isset($parsedOpts['mux']) ? true : null,
'headers' => isset($parsedOpts['host']) ? ['Host' => $parsedOpts['host']] : null
], fn($v) => $v !== null);
break;
case 'shadow-tls':
$array['plugin-opts'] = array_filter([
'host' => $parsedOpts['host'] ?? null,
'password' => $parsedOpts['password'] ?? null,
'version' => isset($parsedOpts['version']) ? (int)$parsedOpts['version'] : 2
], fn($v) => $v !== null);
break;
case 'restls':
$array['plugin-opts'] = array_filter([
'host' => $parsedOpts['host'] ?? null,
'password' => $parsedOpts['password'] ?? null,
'restls-script' => $parsedOpts['restls-script'] ?? '123'
], fn($v) => $v !== null);
break; break;
default: default:
// 对于其他插件,直接使用解析出的键值对
$array['plugin-opts'] = $parsedOpts; $array['plugin-opts'] = $parsedOpts;
} }
} }