为ClashVerge增加hysteria1/2的订阅

This commit is contained in:
wyx2685 2023-10-19 02:47:43 +09:00
parent dffe39b6d9
commit 19521a1393
No known key found for this signature in database
GPG Key ID: 8827A30FF1DB1379
2 changed files with 38 additions and 0 deletions

View File

@ -124,6 +124,8 @@ class UniProxyController extends Controller
if ($this->nodeInfo->version == 1) {
$response['obfs'] = $this->nodeInfo->obfs_password ?? null;
} elseif ($this->nodeInfo->version == 2) {
//TODO 处理hy2客户端上下行宽带设置
$response['ignore_client_bandwidth'] = true;
$response['obfs'] = $this->nodeInfo->obfs ?? null;
$response['obfs-password'] = $this->nodeInfo->obfs_password ?? null;
}

View File

@ -52,6 +52,10 @@ class ClashVerge
array_push($proxy, self::buildTrojan($user['uuid'], $item));
array_push($proxies, $item['name']);
}
if ($item['type'] === 'hysteria') {
array_push($proxy, self::buildHysteria($user['uuid'], $item));
array_push($proxies, $item['name']);
}
}
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
@ -243,6 +247,38 @@ class ClashVerge
return $array;
}
public static function buildHysteria($password, $server)
{
$array = [];
$array['name'] = $server['name'];
$array['server'] = $server['host'];
$array['port'] = $server['port'];
$array['udp'] = true;
if (isset($server['server_name'])) $array['sni'] = $server['server_name'];
if ($server['version'] === 2) {
$array['type'] = 'hysteria2';
$array['password'] = $password;
if (isset($server['obfs'])){
$array['obfs'] = $server['obfs'];
$array['obfs-password'] = $server['obfs_password'];
}
} else {
$array['type'] = 'hysteria';
$array['auth_str'] = $password;
if (isset($server['obfs']) && isset($server['obfs_password'])){
$array['obfs'] = $server['obfs_password'];
}
//Todo:完善客户端上下行
$array['up'] = $user->speed_limit ? min($server['down_mbps'], $user->speed_limit) : $server['down_mbps'];
$array['down'] = $user->speed_limit ? min($server['up_mbps'], $user->speed_limit) : $server['up_mbps'];
$array['protocol'] = 'udp';
}
return $array;
}
private function isMatch($exp, $str)
{
return @preg_match($exp, $str);